From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thamer Mahmoud Newsgroups: gmane.emacs.help Subject: Re: browse select text, text at point Date: Wed, 06 Jul 2011 22:42:30 +0300 Message-ID: <87zkkrkxg9.fsf@zemblan.newkuwait.org> References: <86mxgrlhys.fsf@S0106001636ac5854.gv.shawcable.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1309984757 16263 80.91.229.12 (6 Jul 2011 20:39:17 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 6 Jul 2011 20:39:17 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jul 06 22:39:13 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QeYsK-0006PP-QE for geh-help-gnu-emacs@m.gmane.org; Wed, 06 Jul 2011 22:39:12 +0200 Original-Received: from localhost ([::1]:32893 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeYsJ-0004cW-GV for geh-help-gnu-emacs@m.gmane.org; Wed, 06 Jul 2011 16:39:11 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:55823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeXzi-0005Pw-F0 for help-gnu-emacs@gnu.org; Wed, 06 Jul 2011 15:42:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QeXzh-0002LI-8Y for help-gnu-emacs@gnu.org; Wed, 06 Jul 2011 15:42:46 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:35150) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeXzg-0002L8-Qt for help-gnu-emacs@gnu.org; Wed, 06 Jul 2011 15:42:45 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QeXze-0002Wl-Qj for help-gnu-emacs@gnu.org; Wed, 06 Jul 2011 21:42:42 +0200 Original-Received: from 178.61.79.211 ([178.61.79.211]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 06 Jul 2011 21:42:42 +0200 Original-Received: from thamer.mahmoud by 178.61.79.211 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 06 Jul 2011 21:42:42 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 42 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 178.61.79.211 Cancel-Lock: sha1:9Oy4b5Fybo/DZL96D8EmPFkNsX8= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 80.91.229.12 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:81512 Archived-At: 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