* define-advice, advise, defnadvice, advice-advise you name it
@ 2014-11-16 21:11 Leo Liu
2014-11-16 22:20 ` Nic Ferrier
0 siblings, 1 reply; 4+ messages in thread
From: Leo Liu @ 2014-11-16 21:11 UTC (permalink / raw)
To: emacs-devel
Hi folks,
Stefan has agreed to add a macro as follows:
(defmacro define-advice (symbol args &rest body)
"Define an advice and add it to function named SYMBOL.
See `advice-add' and `add-function' for explanation on the
arguments. Note if NAME is nil the advice is anonymous;
otherwise it is named `SYMBOL@NAME'.
\(fn SYMBOL (WHERE LAMBDA-LIST &optional NAME DEPTH) &rest BODY)"
(declare (indent 2) (doc-string 3) (debug (sexp sexp body)))
(or (listp args) (signal 'wrong-type-argument (list 'listp args)))
(or (<= 2 (length args) 4)
(signal 'wrong-number-of-arguments (list 2 4 (length args))))
(let* ((where (nth 0 args))
(lambda-list (nth 1 args))
(name (nth 2 args))
(depth (nth 3 args))
(props (and depth `((depth . ,depth))))
(advice (cond ((null name) `(lambda ,lambda-list ,@body))
((or (stringp name) (symbolp name))
(intern (format "%s@%s" symbol name)))
(t (error "Unrecognized name spec `%S'" name)))))
`(prog1 ,@(and (symbolp advice) `((defun ,advice ,lambda-list ,@body)))
(advice-add ',symbol ,where #',advice ,@(and props `(',props))))))
`advise' is out because it is not in the `advice' namespace;
`defnadvice' is inferior to define-advice;
`advice-advise' is odd
So far we can accept define-advice but feel something lacking due to:
given primitives "define-foo", "foo-add" and "foo-remove", it really
sounds like the first defines something that you can then pass to the
second and the third.
So does anyone have something that sounds advicey and macroish?
Thanks,
Leo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: define-advice, advise, defnadvice, advice-advise you name it
2014-11-16 21:11 define-advice, advise, defnadvice, advice-advise you name it Leo Liu
@ 2014-11-16 22:20 ` Nic Ferrier
2014-11-17 4:27 ` Stefan Monnier
0 siblings, 1 reply; 4+ messages in thread
From: Nic Ferrier @ 2014-11-16 22:20 UTC (permalink / raw)
To: Leo Liu; +Cc: emacs-devel
Leo Liu <sdl.web@gmail.com> writes:
> (defmacro define-advice (symbol args &rest body)
> "Define an advice and add it to function named SYMBOL.
> See `advice-add' and `add-function' for explanation on the
> arguments. Note if NAME is nil the advice is anonymous;
> otherwise it is named `SYMBOL@NAME'.
>
> \(fn SYMBOL (WHERE LAMBDA-LIST &optional NAME DEPTH) &rest BODY)"
> (declare (indent 2) (doc-string 3) (debug (sexp sexp body)))
> (or (listp args) (signal 'wrong-type-argument (list 'listp args)))
> (or (<= 2 (length args) 4)
> (signal 'wrong-number-of-arguments (list 2 4 (length args))))
> (let* ((where (nth 0 args))
> (lambda-list (nth 1 args))
> (name (nth 2 args))
> (depth (nth 3 args))
> (props (and depth `((depth . ,depth))))
> (advice (cond ((null name) `(lambda ,lambda-list ,@body))
> ((or (stringp name) (symbolp name))
> (intern (format "%s@%s" symbol name)))
> (t (error "Unrecognized name spec `%S'" name)))))
> `(prog1 ,@(and (symbolp advice) `((defun ,advice ,lambda-list ,@body)))
> (advice-add ',symbol ,where #',advice ,@(and props `(',props))))))
>
>
> So does anyone have something that sounds advicey and macroish?
push-advice?
Nic
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: define-advice, advise, defnadvice, advice-advise you name it
2014-11-16 22:20 ` Nic Ferrier
@ 2014-11-17 4:27 ` Stefan Monnier
2014-11-18 12:52 ` Daniel Colascione
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2014-11-17 4:27 UTC (permalink / raw)
To: Nic Ferrier; +Cc: Leo Liu, emacs-devel
> push-advice?
This sounds like an alias for advice-add: the name does not hint at the
fact that it's a macro that takes a "body" argument rather than
a function that takes another function as argument.
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: define-advice, advise, defnadvice, advice-advise you name it
2014-11-17 4:27 ` Stefan Monnier
@ 2014-11-18 12:52 ` Daniel Colascione
0 siblings, 0 replies; 4+ messages in thread
From: Daniel Colascione @ 2014-11-18 12:52 UTC (permalink / raw)
To: Stefan Monnier, Nic Ferrier; +Cc: Leo Liu, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 286 bytes --]
On 11/16/2014 08:27 PM, Stefan Monnier wrote:
>> push-advice?
>
> This sounds like an alias for advice-add: the name does not hint at the
> fact that it's a macro that takes a "body" argument rather than
> a function that takes another function as argument.
`advice-add!' ?
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-11-18 12:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-16 21:11 define-advice, advise, defnadvice, advice-advise you name it Leo Liu
2014-11-16 22:20 ` Nic Ferrier
2014-11-17 4:27 ` Stefan Monnier
2014-11-18 12:52 ` Daniel Colascione
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.