From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jonathan Groll Newsgroups: gmane.emacs.help Subject: Re: browse select text, text at point Date: Thu, 07 Jul 2011 11:24:32 +0200 Message-ID: <87k4bua1f3.wl%lists@groll.co.za> References: <86mxgrlhys.fsf@S0106001636ac5854.gv.shawcable.net> <87zkkrkxg9.fsf@zemblan.newkuwait.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-Trace: dough.gmane.org 1310033416 7047 80.91.229.12 (7 Jul 2011 10:10:16 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 7 Jul 2011 10:10:16 +0000 (UTC) To: Thamer Mahmoud , help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jul 07 12:10:11 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 1QelX6-0001Rl-8X for geh-help-gnu-emacs@m.gmane.org; Thu, 07 Jul 2011 12:10:08 +0200 Original-Received: from localhost ([::1]:57626 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QelX4-0001LH-Gu for geh-help-gnu-emacs@m.gmane.org; Thu, 07 Jul 2011 06:10:06 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:46783) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QekpD-0001a8-9e for help-gnu-emacs@gnu.org; Thu, 07 Jul 2011 05:24:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qekp9-0001Zg-IG for help-gnu-emacs@gnu.org; Thu, 07 Jul 2011 05:24:46 -0400 Original-Received: from mail.groll.co.za ([166.84.7.40]:34117) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qekp8-0001Y5-KL for help-gnu-emacs@gnu.org; Thu, 07 Jul 2011 05:24:42 -0400 Original-Received: from mail.groll.co.za.groll.co.za (localhost [127.0.0.1]) by mail.groll.co.za (Postfix) with ESMTP id 18EB660CB5; Thu, 7 Jul 2011 11:24:32 +0200 (SAST) In-Reply-To: <87zkkrkxg9.fsf@zemblan.newkuwait.org> User-Agent: Wanderlust/2.15.6 (Almost Unreal) Emacs/24.0 Mule/6.0 (HANACHIRUSATO) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) X-Received-From: 166.84.7.40 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:81516 Archived-At: On Wed, 06 Jul 2011 22:42:30 +0300, 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))) > > (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