From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Joe Bloggs Newsgroups: gmane.emacs.help Subject: Re: parametrized function definition Date: Wed, 09 Jul 2008 15:44:13 +0100 Message-ID: <87hcazjewy.fsf@DEBLAP1.BeNet> References: <87zlosz4n6.fsf@DEBLAP1.BeNet> <48746376.1000306@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1215658243 20299 80.91.229.12 (10 Jul 2008 02:50:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 10 Jul 2008 02:50:43 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jul 10 04:51:30 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 1KGmFl-0005mn-GM for geh-help-gnu-emacs@m.gmane.org; Thu, 10 Jul 2008 04:51:29 +0200 Original-Received: from localhost ([127.0.0.1]:36351 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KGmEu-0003MM-3e for geh-help-gnu-emacs@m.gmane.org; Wed, 09 Jul 2008 22:50:36 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail Original-NNTP-Posting-Date: Wed, 09 Jul 2008 09:44:13 -0500 Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:AZ2YI4o+8VO1AwflbMNoD2nwNFY= Original-Lines: 43 X-Usenet-Provider: http://www.giganews.com Original-X-Trace: sv3-PZURq5ozE/J/VfCQ4wUzCmQjAxxIpbwoqAWNfY66635GYMkkAM8wWS9NU0XHaJIUgaUdD/6vo12cBjK!gaHNN6h1r3uMng4XEBLHwYKCPxNm9jcCEJ9udTgzZAmjSQDlEd1b Original-X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.39 Original-Xref: news.stanford.edu gnu.emacs.help:159994 X-Mailman-Approved-At: Wed, 09 Jul 2008 22:50:08 -0400 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:55362 Archived-At: Thien-Thi Nguyen writes: > () "Lennart Borgman (gmail)" > () Wed, 09 Jul 2008 09:06:30 +0200 > > > (defun set-local-key-insert () > > "set a local key to insert some text" > > (interactive) > > (let (keystring textinsert) > > (setq keystring (read-key-sequence "Key combination to bind: ")) > > (setq textinsert (read-string "Text to insert: ")) > > (local-set-key (read-kbd-macro keystring) > > (lambda () (interactive) > > (insert textinsert))))) > > You can remove textinsert from let and make it a defvar instead. > > (defvar textinsert nil) > > Yes, but that would defeat the presumed intention of using `textinsert' > as a local variable. Practically, this means `set-local-key-insert' > invocations clobber previous invocations' state (last invocation wins). > > Probably OP wants `lexical-let'. > > thi lexical-let did the job, thanks: (require 'cl) (defun set-local-key-insert () "set a local key to insert some text" (interactive) (let (keystring) (setq keystring (read-key-sequence "Key combination to bind: ")) (lexical-let (textinsert) (setq textinsert (read-string "Text to insert: ")) (local-set-key (read-kbd-macro keystring) (lambda () (interactive) (insert textinsert))) ) ) )