|
From: | Emanuel Berg |
Subject: | Re: ~`symbol-function' to get code as list even when byte-compiled? |
Date: | Tue, 26 May 2015 02:01:52 +0200 |
User-agent: | Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
"Pascal J. Bourguignon" <pjb@informatimago.com> writes: > Then you can just write: > > ;;;; -*- mode:emacs-lisp;lexical-binding:t;coding:utf-8 -*- > (defun add-one-shot-meat (hook fun) > (let ((name (gensym))) > (setf (symbol-function name) > (lambda () > (remove-hook hook name) > (funcall fun))) > (add-hook hook name))) > > and use add-one-shot-meat instead of add-hook. That's exactly right! I knew this could be done without macros. Only, I had to change "gensym" into `cl-gensym' and add the "unused" argument to the lambda as with `w3m-display-hook', "each function is called with a url string as the argument". The byte-compiler then said Warning: Unused lexical argument `unused' so I made "use" of it to keep the compiler quiet. ;;;; -*- lexical-binding:t -*- (defun add-one-shot-hook (hook fun) (let ((name (cl-gensym))) (setf (symbol-function name) (lambda (&rest unused) (progn unused (remove-hook hook name) (funcall fun) ))) (add-hook hook name) )) I guess I like it fine - so far... -- underground experts united http://user.it.uu.se/~embe8573
[Prev in Thread] | Current Thread | [Next in Thread] |