From: Deniz Dogan <deniz@dogan.se>
To: help-gnu-emacs@gnu.org
Subject: Re: browse select text, text at point
Date: Thu, 07 Jul 2011 10:24:22 +0200 [thread overview]
Message-ID: <4E156D36.3000903@dogan.se> (raw)
In-Reply-To: <87zkkrkxg9.fsf@zemblan.newkuwait.org>
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
next prev parent reply other threads:[~2011-07-07 8:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-06 12:19 browse select text, text at point smclean0640
2011-07-06 13:43 ` Deniz Dogan
2011-07-06 17:35 ` Andreas Röhler
2011-07-06 19:59 ` Deniz Dogan
2011-07-07 7:07 ` Andreas Röhler
2011-07-07 7:28 ` Deniz Dogan
2011-07-06 15:26 ` Drew Adams
2011-07-08 12:05 ` Stuart McLean
2011-07-06 19:42 ` Thamer Mahmoud
2011-07-07 8:24 ` Deniz Dogan [this message]
2011-07-07 9:24 ` Jonathan Groll
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E156D36.3000903@dogan.se \
--to=deniz@dogan.se \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).