help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: browse select text, text at point


From: Jonathan Groll
Subject: Re: browse select text, text at point
Date: Thu, 07 Jul 2011 11:24:32 +0200
User-agent: Wanderlust/2.15.6 (Almost Unreal) Emacs/24.0 Mule/6.0 (HANACHIRUSATO)

On Wed, 06 Jul 2011 22:42:30 +0300, Thamer Mahmoud <address@hidden> wrote:

> address@hidden 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)
> 

Almost there - think it'll need some string escaping, as a search on
"google+ emacs client" dropped the "+".

Cheers,
Jonathan
--
jjg: Jonathan J. Groll : groll co za
has_one { :blog => "http://bloggroll.com"; }
Sent from my computer device which runs on free software



reply via email to

[Prev in Thread] Current Thread [Next in Thread]