From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: Syntax to use (let...) in key binding Date: Tue, 03 Mar 2015 00:49:26 +0100 Organization: Aioe.org NNTP Server Message-ID: <878uffrmd5.fsf@debian.uxu> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1425340221 20690 80.91.229.3 (2 Mar 2015 23:50:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 2 Mar 2015 23:50:21 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 03 00:50: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 1YSa6N-0003Pg-AD for geh-help-gnu-emacs@m.gmane.org; Tue, 03 Mar 2015 00:50:19 +0100 Original-Received: from localhost ([::1]:60625 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSa6M-0002yG-Ht for geh-help-gnu-emacs@m.gmane.org; Mon, 02 Mar 2015 18:50:18 -0500 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!feeder3.cambriumusenet.nl!feed.tweaknews.nl!138.195.8.3.MISMATCH!news.ecp.fr!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 58 Original-NNTP-Posting-Host: feB02bRejf23rfBm51Mt7Q.user.speranza.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:RZppjkexCzOCTg91yoTmuxR1usA= Mail-Copies-To: never Original-Xref: usenet.stanford.edu gnu.emacs.help:210712 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:102989 Archived-At: torys.anderson@gmail.com (Tory S. Anderson) writes: > ... (global-set-key [f10] '(let ((b "*Bookmark > List*")) (if (get-buffer b) '(switch-to-buffer b) > 'bookmark-bmenu-list))) > > This results in: command-execute: Wrong type > argument: commandp, (let ((b "*Bookmark List*")) (if > (get-buffer b) (quote (switch-to-buffer b)) (quote > bookmark-bmenu-list))) > > Is the "let" not returning a command like I want it > to? debug-on-error doesn't seem to be helping me > understand this. There are two ways to do that. The best way is to write a defun. It must be (interactive) else you can't access it with a keydown (it isn't a "command") or from M-x for that matter. So: (defun my-defun () (interactive) ; ... do stuff ) Then you can use `define-key' or `global-set-key' as below, just substitute keymap, key, and function (command) name: (define-key w3m-mode-map "g" 'w3m-goto-url-kill-current) (global-set-key "\r" 'newline-and-indent) The second way to do it is to use a so called anonymous (inline) function, with lambda: (global-set-key "\C-^" (lambda () (interactive) (message "hello"))) (Hold the control key and hit '6' to try after evaluating.) Lambdas make for compact code but it can get out of hand pretty quickly if you need to add more code. Better to do a proper defun so you can use it from code (Elisp) and the M-x interface as well. But whatever you do, don't quote that lambda... or else! Small last note: F10 isn't a good key for a shortcut because you have to leave typing position (left hand: asfd and right hand: jkl;) and reach to hit it (F10), then reset. Speed kills! -- underground experts united