[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
codesearch.el 1.0 --- Search for code via Google Code Search
From: |
Jürgen Hötzel |
Subject: |
codesearch.el 1.0 --- Search for code via Google Code Search |
Date: |
Thu, 28 Jun 2007 00:28:01 +0200 |
User-agent: |
Mutt/1.5.14 (2007-02-12) |
;;; codesearch.el --- allowing users to search for open-source code on
;;; the Internet from within Emacs via Google Code Search
;; Copyright (C) 2007 Juergen Hoetzel
;; Author: Juergen Hoetzel <address@hidden>
;; Keywords: languages, tools, comm, docs
;; Version: 1.0
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; codesearch.el is tested with GNU Emacs 22.1 on GNU/Linux and
;; Windows
;; The latest version of this package should be available from
;; <URL:http://www.hoetzel.info/Hacking/emacs/codesearch.el>.
;; To use this mode, put codesearch.el somewhere on your load-path.
;; Then add this to your .emacs:
;;
;; (require 'codesearch)
;;
;;; Code:
(provide 'codesearch)
(defvar codesearch-history nil "Google Code Search history.")
(defvar codesearch-special-chars (string-to-list "$^\\\[\](){}*+")
"Escape these character in querystring, because the have
special meaning as regular expression")
(defvar codesearch-url-format-string
"http://www.google.com/codesearch?as_q=%s&as_lang=%s"
"Format string for codesearch URL.")
(defun codesearch-mode-to-lang (mode)
"map emacs mode to variable in Code Search querystring (list is
far from complete)."
(cond ((or (eq mode 'lisp-mode)
(eq mode 'emacs-lisp-mode)
(eq mode 'scheme-mode)
(eq mode 'lisp-interaction-mode))
"lisp")
((eq mode 'ada-mode)
"ada")
((eq mode 'c-mode)
"c")
((eq mode 'c++-mode)
"c++")
((eq mode 'fortran-mode)
"fortran")
((eq mode 'java-mode)
"java")
((eq mode 'lua-mode)
"lua")
((eq mode 'objc-mode)
"objectivec")
((eq mode 'pascal-mode)
"pascal")
((eq mode 'perl-mode)
"perl")
((eq mode 'php-mode)
"php")
((eq mode 'prolog-mode)
"prolog")
((eq mode 'python-mode)
"python")
((eq mode 'scheme-mode)
"scheme")
((or (eq mode 'sh-mode)
(eq mode 'shell-mode))
"shell")
((eq mode 'sql-mode)
"sql")
((eq mode 'tcl-mode)
"tcl")
((eq mode 'vhdl-mode)
"vhdl")
(t
"")))
(defun codesearch-re-escape (re)
"Looks for Code Search special characters and escape them, i.e. \\"
(replace-regexp-in-string
(regexp-opt-charset codesearch-special-chars) "\\\\\\&" re))
(defun codesearch(searchstring)
"Code Search current word, or with optional prefix arg, on
current region"
(interactive
(let* ((default-entry
(codesearch-re-escape
(if current-prefix-arg
(buffer-substring (region-beginning) (region-end))
(current-word))))
(input
(read-string
"Code Search: " default-entry 'codesearch-history default-entry)))
(if (string= input "")
(error "No search string specified"))
(list input)))
;; identification of lang
(let* ((lang (codesearch-mode-to-lang major-mode))
(url (format codesearch-url-format-string searchstring lang)))
(require 'browse-url)
(browse-url url)))
;;; codesearch.el ends here