[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: browse select text, text at point
From: |
Thamer Mahmoud |
Subject: |
Re: browse select text, text at point |
Date: |
Wed, 06 Jul 2011 22:42:30 +0300 |
smclean0640@gmail.com writes:
> I am wondering whether anyone in the group knows a package that will
> accomplish the following:
> - I am on a word, say "limousine", by pressing a keystroke I can browse
> this word in google (or a chosen search engine) with my default browser,
> - I have selected a region of text and I want to search that text in my
> default browser.
>
The following code should handle both words at point and region. Just do
"M-x google" or "C-c g" + ENTER.
(defun tma-word-or-region-at-point ()
"Return the word or region at point."
(if mark-active
(buffer-substring (region-beginning) (region-end))
(word-at-point)))
(defun tma-interactive-with-default ()
"Allow a user to enter a search word or phrase, but give a sane default."
(list (let* ((default-entry (tma-word-or-region-at-point))
(input (read-string
(format "Search%s: "
(if (string= default-entry "")
""
(format " (default %s)" default-entry))))))
(if (string= input "")
(if (string= default-entry "")
(error "User must provide word or region.")
default-entry)
input))))
(defun google (word)
"Use google to search for word or region."
(interactive
(tma-interactive-with-default))
(browse-url (concat "http://www.google.com/search?q=" word)))
(global-set-key (kbd "C-c g") 'google)
--
Thamer
RE: browse select text, text at point, Drew Adams, 2011/07/06
Re: browse select text, text at point,
Thamer Mahmoud <=