From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: John Mastro Newsgroups: gmane.emacs.help Subject: Re: hydra: Have hint shown immediately Date: Wed, 29 Apr 2015 17:06:40 -0700 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1430352442 21638 80.91.229.3 (30 Apr 2015 00:07:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 30 Apr 2015 00:07:22 +0000 (UTC) To: Florian Lindner , "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Apr 30 02:07:21 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Ync0d-0006vi-NE for geh-help-gnu-emacs@m.gmane.org; Thu, 30 Apr 2015 02:07:19 +0200 Original-Received: from localhost ([::1]:41469 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ync0c-0001EM-Uf for geh-help-gnu-emacs@m.gmane.org; Wed, 29 Apr 2015 20:07:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60074) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ync0Q-0001BN-Uo for help-gnu-emacs@gnu.org; Wed, 29 Apr 2015 20:07:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ync0Q-0006x9-08 for help-gnu-emacs@gnu.org; Wed, 29 Apr 2015 20:07:06 -0400 Original-Received: from mail-ob0-x232.google.com ([2607:f8b0:4003:c01::232]:34902) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ync0P-0006vj-RW for help-gnu-emacs@gnu.org; Wed, 29 Apr 2015 20:07:05 -0400 Original-Received: by obcux3 with SMTP id ux3so32614515obc.2 for ; Wed, 29 Apr 2015 17:07:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=gK/05StK0womBLkWWvv7eu0GV6uMyErAipt5vnnCLr4=; b=uXIqPxxbHTsMpcPifZxyfZ+RB6/XxojEoFQktL1ZuYZeKkXqH0+i5McB15Ukx0CAJr vCn6K7e13tPxAARykbsMFarVa2vOHMr/2OtJSITOhLrVp1KvcE7vOK5HVWsmh+o0TTqB BRegdPlV5eY6VJxEIfHpYP8/SGADrrg2NMjlU9KmVfaGbKqjQDDuX1Dv64Td+hx9O+xp JBcsaGhBChAQTY/1IMH4p3/spI5N2VdvV8dVVDRjI5yU6VmMt0PE/DTxYdFVOt81aN7h QiZeGndL7Lje98kSwF36jUz3R+n+2XnOqxg7CgP4k0EgpLYq0voAHQcLmNR0C2VblVLX WbdQ== X-Received: by 10.202.85.197 with SMTP id j188mr1256942oib.80.1430352420515; Wed, 29 Apr 2015 17:07:00 -0700 (PDT) Original-Received: by 10.76.107.19 with HTTP; Wed, 29 Apr 2015 17:06:40 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c01::232 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:104085 Archived-At: Hi Florian, > (defun flo/start-search (url) > (interactive) > (browse-url (replace-regexp-in-string > (regexp-quote "%s") > (if (region-active-p) > (buffer-substring (region-beginning) (region-end)) > (read-string "Search for: " (thing-at-point 'symbol) > "searches" nil t) > ) > url) > ) > ) > > > interactive is just for testing, it will vanish probably. Since this is my > first elisp "program" please criticise! I don't know the answer regarding Hydra, but I can offer some subjective, mostly cosmetic feedback on `flo/start-search'. As a talking piece, here's something very similar which will hopefully show a couple small idioms that you may find useful: (defun flo/start-search (url) (interactive) (let ((default (if (use-region-p) (buffer-substring-no-properties (region-beginning) (region-end)) (thing-at-point 'symbol)))) (browse-url (format url (read-string (if default (format "Search for (default %s): " default) "Search for: ") nil nil default))))) The main differences are: 1. Pass the default to `read-string' as argument DEFAULT rather than INITIAL-INPUT. Show the default in the prompt so you can tell it's available. The benefit is that you can still just hit RET to use the default, but you don't need to delete the default if you want to search for something else. 2. Use `format' to add the search term to the URL, rather than `replace-regexp-in-string'. 3. Prefer `use-region-p' over `region-active-p'. 4. Don't leave trailing parens. I know it can seem a bit weird at first, but I promise it's worth getting used to. Keep having fun with Emacs! -- john