Skip to content

Instantly share code, notes, and snippets.

@ryseto
Last active December 9, 2015 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryseto/4347294 to your computer and use it in GitHub Desktop.
Save ryseto/4347294 to your computer and use it in GitHub Desktop.
(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)))
@ryseto
Copy link
Author

ryseto commented Dec 20, 2012

@ryseto
Copy link
Author

ryseto commented Dec 20, 2012

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