Last active
December 9, 2015 23:58
-
-
Save ryseto/4347294 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-key global-map (kbd "C-c w") 'MyTool-lookup-dictionary-osx) | |
(define-key global-map (kbd "C-c g") 'MyTool-search-google) | |
(define-key global-map (kbd "C-c G") 'MyTool-search-googlescholar) | |
(defun MyTool-search-google() | |
"Search by google" | |
(interactive) | |
(let* ((str (string-word-or-region))) | |
(browse-url | |
(concat "http://google.com/search?q=\"" str "\"")))) | |
(defun MyTool-search-googlescholar() | |
"Search string by google scholar" | |
(interactive) | |
(let* ((str (string-word-or-region))) | |
(browse-url | |
(concat "http://scholar.google.com/scholar?q=\"" str "\"")))) | |
(defun MyTool-lookup-dictionary-osx() | |
"Look up the word by Dictionary.app of Mac OS X" | |
(interactive) | |
(let* ((str (url-hexify-string (string-word-or-region)))) | |
(browse-url (concat "dict://" str )))) | |
(defun string-word-or-region () | |
"If region is selected, this returns the string of the region. If not, this returns the string of the word on which the cursor is." | |
(let ((editable (not buffer-read-only)) | |
(pt (save-excursion (mouse-set-point last-nonmenu-event))) | |
beg end) | |
(if (and mark-active | |
(<= (region-beginning) pt) (<= pt (region-end)) ) | |
(setq beg (region-beginning) | |
end (region-end)) | |
(save-excursion | |
(goto-char pt) | |
(backward-char 1) | |
(setq end (progn (forward-word) (point))) | |
(setq beg (progn (backward-word) (point))))) | |
(buffer-substring-no-properties beg end))) |
Searching by Google scholar by using URL `http://scholar.google.com/scholar?q="...."' may be also useful.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original code: http://sakito.jp/mac/dictionary.html