all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: describe-function and advised C functions
Date: Wed, 04 Dec 2013 21:38:07 -0500	[thread overview]
Message-ID: <jwv1u1sghxk.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <8761r4n242.fsf@tsdh.uni-koblenz.de> (Tassilo Horn's message of "Wed, 04 Dec 2013 15:05:01 +0100")

> Yeah.  Here's a patch that removes all ad-* function usages in
> help-fns.el which also fixes the original regression.  It's a bit hairy,

Thanks.  It looks pretty good, see nitpicks below.  It's pretty messy
over all, to some extent because reality is messy, but also because the
existing code is already messy, what with def, function, real-function,
real-def and no clear description of how they differ from each other.

> BTW, why are the advice annotations in the *Help* buffer fontified for
> `load', `append', and `concat-seqs', but not for `scheme-mode' and
> `quack-mode'.

I don't know, but I suspect the reason is not a good one.

> -  (let* ((advised (and (symbolp function) (featurep 'advice)
> -		       (ad-get-advice-info function)))
> +  (let* ((advised (and (symbolp function)
> +		       (featurep 'nadvice)
> +		       (advice--p (advice--symbol-function function))))

Looks fine.

>  	 ;; If the function is advised, use the symbol that has the
>  	 ;; real definition, if that symbol is already set up.
>  	 (real-function
>  	  (or (and advised
> -		   (let ((origname (cdr (assq 'origname advised))))
> -		     (and (fboundp origname) origname)))
> +		   (let* ((f function)
> +			  (advised-fn (advice--cdr (advice--symbol-function f))))
> +		     (while (advice--p advised-fn)
> +		       (setq f advised-fn)
> +		       (setq advised-fn (advice--cdr (if (symbolp f)
> +							 (advice--symbol-function f)
> +						       f))))
> +		     advised-fn))

Here `f' is unnecessary (you can always replace it either with
`function' or with `advised-fn').
Doesn't this break the 80-columns limit?
Also, the (symbolp f) test is always nil since (advice--p
advised-fn) can't be true at the same time.

More important, for an advised macro, your `real-definition' will be
a function (either a lambda expression or a byte-code-function-p).

> +	 (aliased (or (symbolp def)
> +		      ;; advised & aliased
> +		      (and (symbolp function)
> +			   (symbolp real-function)
> +			   (not (eq function real-function)))))

Please capitalize and punctuate your comments.
Also, why not use replace the `and' with

   (and advised (symbolp real-function))

> +	 (real-def (cond
> +		    (aliased (let ((f real-function))
> +			       (while (and (fboundp f)
> +					   (symbolp (symbol-function f)))
> +				 (setq f (symbol-function f)))
> +			       f))
> +		    ((subrp def) (intern (subr-name def)))
> +		    (t def)))

Why do we need `subr-name'?

> @@ -567,14 +577,14 @@
>      ;; Print what kind of function-like object FUNCTION is.
>      (princ (cond ((or (stringp def) (vectorp def))
>  		  "a keyboard macro")
> +		 (aliased
> +		  (format "an alias for `%s'" real-def))
>  		 ((subrp def)
>  		  (if (eq 'unevalled (cdr (subr-arity def)))
>  		      (concat beg "special form")
>  		    (concat beg "built-in function")))
>  		 ((byte-code-function-p def)
>  		  (concat beg "compiled Lisp function"))
> -		 (aliased
> -		  (format "an alias for `%s'" real-def))
>  		 ((eq (car-safe def) 'lambda)
>  		  (concat beg "Lisp function"))
>  		 ((eq (car-safe def) 'macro)

Hmm... Why was this move necessary?  You'll probably want to add
a comment explaining it.


        Stefan



  parent reply	other threads:[~2013-12-05  2:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-03  9:14 describe-function and advised C functions Tassilo Horn
2013-12-03 13:51 ` Stefan Monnier
2013-12-04 10:54   ` Tassilo Horn
2013-12-04 14:05     ` Tassilo Horn
2013-12-04 19:18       ` Johan Bockgård
2013-12-05  2:38       ` Stefan Monnier [this message]
2013-12-05  9:52         ` Tassilo Horn
2013-12-07 17:08           ` Tassilo Horn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv1u1sghxk.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.