unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Kevin Ryde <user42@zip.com.au>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 8304@debbugs.gnu.org
Subject: bug#8304: 23.2; ad-read-advised-function default to func at point
Date: Sun, 22 May 2011 10:29:07 +1000	[thread overview]
Message-ID: <87ipt3h92k.fsf@blah.blah> (raw)
In-Reply-To: <jwvr5a01qvl.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 21 Mar 2011 10:40:38 -0400")

[-- Attachment #1: Type: text/plain, Size: 925 bytes --]

Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
> Actually, I don't think the docstring should document what `default' will
> default to.

Oh, well, it has done, and if you're using it programmatically then you
will likely want to know.  I shortened it per below.

> Actually, AFAICT the `default' argument is never used.

No doubt it's in emulation of completing-read, so you can offer a
particular default in context.  Seems like a good thing on the whole.

> Comments should start with a capital and end with a "." or some other
> appropriate punctuation.

You must have more trouble getting any comments, then getting sensible
comments, then getting more or less grammatical comments, without
worrying about full stops!



2011-05-22  Kevin Ryde  <user42@zip.com.au>

	* emacs-lisp/advice.el (ad-read-advised-function): Use
	`function-called-at-point' as the default default, if it has
	advice and passes PREDICATE.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: advice.el.read-default-2.diff --]
[-- Type: text/x-diff, Size: 1370 bytes --]

--- advice.el.~1.68.~	2009-10-08 11:00:28.000000000 +1100
+++ advice.el	2011-05-22 10:19:27.000000000 +1000
@@ -2200,16 +2200,27 @@
 ;; @@ Interactive input functions:
 ;; ===============================
 
+(declare-function 'function-called-at-point "help")
+
 (defun ad-read-advised-function (&optional prompt predicate default)
   "Read name of advised function with completion from the minibuffer.
 An optional PROMPT will be used to prompt for the function.  PREDICATE
 plays the same role as for `try-completion' (which see).  DEFAULT will
-be returned on empty input (defaults to the first advised function for
-which PREDICATE returns non-nil)."
+be returned on empty input (defaults to the first advised function or
+function at point for which PREDICATE returns non-nil)."
   (if (null ad-advised-functions)
       (error "ad-read-advised-function: There are no advised functions"))
   (setq default
 	(or default
+	    ;; Prefer func name at point, if it's in ad-advised-functions etc.
+	    (let ((function (progn
+			      (require 'help)
+			      (function-called-at-point))))
+	      (and function
+		   (assoc (symbol-name function) ad-advised-functions)
+		   (or (null predicate)
+		       (funcall predicate function))
+		   function))
 	    (ad-do-advised-functions (function)
 	      (if (or (null predicate)
 		      (funcall predicate function))

[-- Attachment #3: Type: text/plain, Size: 106 bytes --]



-- 
Restaurant jargon elucidated for the layman:
"Special" -- almost gone bad and has to be sold today.

  reply	other threads:[~2011-05-22  0:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-20 23:52 bug#8304: 23.2; ad-read-advised-function default to func at point Kevin Ryde
2011-03-21 14:40 ` Stefan Monnier
2011-05-22  0:29   ` Kevin Ryde [this message]
2011-05-23 14:40     ` Stefan Monnier

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87ipt3h92k.fsf@blah.blah \
    --to=user42@zip.com.au \
    --cc=8304@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).