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: Deniz Dogan
Subject: Re: browse select text, text at point
Date: Thu, 07 Jul 2011 10:24:22 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11

On 2011-07-06 21:42, Thamer Mahmoud wrote:
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)))


It would make more sense to use `use-region-p' here.

(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)


Deniz



reply via email to

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