From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: weber Newsgroups: gmane.emacs.help Subject: Re: parametrized function definition Date: Wed, 9 Jul 2008 05:46:42 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <87zlosz4n6.fsf@DEBLAP1.BeNet> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1215610858 24400 80.91.229.12 (9 Jul 2008 13:40:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 9 Jul 2008 13:40:58 +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 09 15:41:45 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KGZvH-0003jt-0t for geh-help-gnu-emacs@m.gmane.org; Wed, 09 Jul 2008 15:41:31 +0200 Original-Received: from localhost ([127.0.0.1]:59868 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KGZuP-0000GI-K9 for geh-help-gnu-emacs@m.gmane.org; Wed, 09 Jul 2008 09:40:37 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!k37g2000hsf.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 44 Original-NNTP-Posting-Host: 201.21.217.171 Original-X-Trace: posting.google.com 1215607602 3962 127.0.0.1 (9 Jul 2008 12:46:42 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 9 Jul 2008 12:46:42 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k37g2000hsf.googlegroups.com; posting-host=201.21.217.171; posting-account=7GrjgQoAAAD6slWURausdJnhFDkmQYC8 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0,gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 stargate.datacom:3128 (squid/2.6.STABLE5) Original-Xref: news.stanford.edu gnu.emacs.help:159990 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:55340 Archived-At: On Jul 8, 2:07=A0pm, Joe Bloggs wrote: > Hi, I am trying to write a function that allows me to quickly bind a key = combination > to insert arbitrary text: > > (defun set-local-key-insert () > =A0 "set a local key to insert some text" > =A0 (interactive) > =A0 (let (keystring textinsert) > =A0 =A0 (setq keystring (read-key-sequence "Key combination to bind: ")) > =A0 =A0 (setq textinsert (read-string "Text to insert: ")) > =A0 =A0 (local-set-key (read-kbd-macro keystring) (lambda () (interactive= ) (insert textinsert))) > =A0 =A0 ) > =A0 ) > > However, this doesn't work since textinsert is not evaluated until the fu= nction is called with the keybinding. How can I get this to work properly? = I am new to elisp so I imagine it's very simple. > > Thanks. Hi Joe. You have to use some special syntax to that textinsert is evaluated (so your lambda will insert the contents of textinsert, and not the symbol textinsert) I also rewrote your let, because it looks nicer this way, but you can keep the setqs you if want :) (defun set-local-key-insert () "set a local key to insert some text" (interactive) (let ((keystring (read-key-sequence "Key combination to bind: ")) (textinsert (read-string "Text to insert: "))) (local-set-key (read-kbd-macro keystring) `(lambda () (interactive) (insert ,textinsert))))) The significant changes are the backquote before the lambda, and the comma before textinsert. Take a look at the help for this function with C-h f ` HTH weber