From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: hydra: Have hint shown immediately Date: 3 May 2015 19:52:03 GMT Message-ID: References: NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1430682923 20481 80.91.229.3 (3 May 2015 19:55:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 3 May 2015 19:55:23 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun May 03 21:55:17 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 1Yozyv-00046U-5J for geh-help-gnu-emacs@m.gmane.org; Sun, 03 May 2015 21:55:17 +0200 Original-Received: from localhost ([::1]:60162 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yozyu-00021T-Ce for geh-help-gnu-emacs@m.gmane.org; Sun, 03 May 2015 15:55:16 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 75 Original-X-Trace: individual.net 4ZPz/wRN8iuG/ZulqnUAcgj19eUs3/VC+ljZmCEXoPOt8BtSoh Cancel-Lock: sha1:xe0HN7+Imt6bKJ2OyHfgRMrMhys= Mail-Copies-To: nobody X-Editor: Emacs of course! User-Agent: slrn/pre1.0.0-18 (Linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:211885 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:104169 Archived-At: Florian Lindner wrote: > (defhydra hydra-google (global-map "C-c /" :color blue) > "Search Engines" > ("c" (lambda () > (interactive) > (flo/start-search > "http://en.cppreference.com/mwiki/index.php?title=Special:Search&search=%s")) > "C++ Reference") > ("g" (lambda () > (interactive) > (flo/start-search "https://google.de/#q=%s")) > "Google") > ) > > flo/start-search looks like that: > > (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! Well, one thing: don't put closing parens on their own line: (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))) When you read Lisp code, try and ignore the parens, just look at the indentation. > > My question: How can I make the hydra menu to be shown as soon as I press C- > c /? Becaue I exit the hydra after pressing the key I'll never see the menu > and forget option when more search engines are aded. You can do that by binding the hydra with `define-key' (or `global-set-key') rather than passing it a key map: (defhydra hydra-google (:color blue) "Search Engines" ("c" (flo/start-search "http://en.cppreference.com/mwiki/index.php?title=Special:Search&search=%s") "C++ Reference") ("g" (flo/start-search "https://google.de/#q=%s") "Google")) (define-key global-map "C-c /" #'hydra-google/body) Note also that if you pass a single sexp as CMD in a hydra head, it is automatically wrapped in a lambda, so you can get rid of the explicit lambdas in your hydra. -- Joost Kremers joostkremers@fastmail.fm Selbst in die Unterwelt dringt durch Spalten Licht EN:SiS(9)