Re: Tool for inserting code for keybindings. (elisp)
- From: Joost Kremers <joostkremers@xxxxxxxxx>
- Date: 16 Dec 2007 13:36:10 GMT
apatheticagnostic wrote:
Without further ado, here's the code.
(defun with-nil-var (var &rest body)
"Set var to nil in body, and return it to it's older value
afterwards.
This exists because of the variable print-level, and me not being sure
if emacs has a bunch of other variables that users would probably not
appreciate having clobbered."
(let ((old-var (make-symbol "old")))
`(let ((,old-var ,var))
(setf ,var nil)
,@body
(setf ,var ,old-var))))
(defun with-safe-print-level (&rest body)
"Set print-level to nil in body, and restore its value afterwards."
(with-nil-var print-level body))
this one should certainly be a macro. by defining it as a function, the
body of the code is going to be executed *before* with-safe-print-level is
called: the result of BODY is going to be passed as an argument, not the
body code itself.
but more importantly, you don't need all this. lisp already has a special
form that does this: let.
(progn
(insert (format "\n\nPRINT-LEVEL is now %s\n" print-level))
(let ((print-level 20))
(insert (format "\nPRINT-LEVEL is now %s\n" print-level)))
(insert (format "\nPRINT-LEVEL is now %s\n" print-level)))
execute that code in the *scratch* buffer, and you'll see that after the
let, print-level has its old value again.
--
Joost Kremers joostkremers@xxxxxxxxx
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
.
- Follow-Ups:
- Re: Tool for inserting code for keybindings. (elisp)
- From: apatheticagnostic
- Re: Tool for inserting code for keybindings. (elisp)
- References:
- Tool for inserting code for keybindings. (elisp)
- From: apatheticagnostic
- Tool for inserting code for keybindings. (elisp)
- Prev by Date: Re: Tool for inserting code for keybindings. (elisp)
- Next by Date: Re: Tool for inserting code for keybindings. (elisp)
- Previous by thread: Re: Tool for inserting code for keybindings. (elisp)
- Next by thread: Re: Tool for inserting code for keybindings. (elisp)
- Index(es):
Relevant Pages
|