help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: parametrized function definition


From: Joe Bloggs
Subject: Re: parametrized function definition
Date: Wed, 09 Jul 2008 15:44:13 +0100
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux)


Thien-Thi Nguyen <address@hidden> writes:

> () "Lennart Borgman (gmail)" <address@hidden>
> () 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)))
      )
    )
  )


reply via email to

[Prev in Thread] Current Thread [Next in Thread]