aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2003-05-04 00:32:46 +0000
committerStefan Monnier2003-05-04 00:32:46 +0000
commit24c22ecf5ad24f291978473fe562f40f564e836a (patch)
tree59da096e77e3c3a72bc5bb63e2b8c93647cde7b2
parent95734598cd99ef979c4a2067306d835c67186aad (diff)
downloademacs-24c22ecf5ad24f291978473fe562f40f564e836a.tar.gz
emacs-24c22ecf5ad24f291978473fe562f40f564e836a.zip
(ad-get-enabled-advices, ad-special-forms)
(ad-arglist, ad-subr-arglist): Use push and match-string. (ad-make-advised-docstring): Extract & reinsert the usage info.
-rw-r--r--lisp/emacs-lisp/advice.el55
1 files changed, 24 insertions, 31 deletions
diff --git a/lisp/emacs-lisp/advice.el b/lisp/emacs-lisp/advice.el
index 1900dff4d6b..a211e1ebba1 100644
--- a/lisp/emacs-lisp/advice.el
+++ b/lisp/emacs-lisp/advice.el
@@ -2116,7 +2116,7 @@ Redefining advices affect the construction of an advised definition."
2116 (let (enabled-advices) 2116 (let (enabled-advices)
2117 (ad-dolist (advice (ad-get-advice-info-field function class)) 2117 (ad-dolist (advice (ad-get-advice-info-field function class))
2118 (if (ad-advice-enabled advice) 2118 (if (ad-advice-enabled advice)
2119 (setq enabled-advices (cons advice enabled-advices)))) 2119 (push advice enabled-advices)))
2120 (reverse enabled-advices))) 2120 (reverse enabled-advices)))
2121 2121
2122 2122
@@ -2475,7 +2475,7 @@ will clear the cache."
2475 with-output-to-temp-buffer))) 2475 with-output-to-temp-buffer)))
2476 ;; track-mouse could be void in some configurations. 2476 ;; track-mouse could be void in some configurations.
2477 (if (fboundp 'track-mouse) 2477 (if (fboundp 'track-mouse)
2478 (setq tem (cons 'track-mouse tem))) 2478 (push 'track-mouse tem))
2479 (mapcar 'symbol-function tem))) 2479 (mapcar 'symbol-function tem)))
2480 2480
2481(defmacro ad-special-form-p (definition) 2481(defmacro ad-special-form-p (definition)
@@ -2545,8 +2545,7 @@ supplied to make subr arglist lookup more efficient."
2545 ;; otherwise get it from its printed representation: 2545 ;; otherwise get it from its printed representation:
2546 (setq name (format "%s" definition)) 2546 (setq name (format "%s" definition))
2547 (string-match "^#<subr \\([^>]+\\)>$" name) 2547 (string-match "^#<subr \\([^>]+\\)>$" name)
2548 (ad-subr-arglist 2548 (ad-subr-arglist (intern (match-string 1 name)))))))
2549 (intern (substring name (match-beginning 1) (match-end 1))))))))
2550 2549
2551;; Store subr-args as `((arg1 arg2 ...))' so I can distinguish 2550;; Store subr-args as `((arg1 arg2 ...))' so I can distinguish
2552;; a defined empty arglist `(nil)' from an undefined arglist: 2551;; a defined empty arglist `(nil)' from an undefined arglist:
@@ -2583,19 +2582,9 @@ that property, or otherwise use `(&rest ad-subr-args)'."
2583 (ad-define-subr-args 2582 (ad-define-subr-args
2584 subr-name 2583 subr-name
2585 (cdr (car (read-from-string 2584 (cdr (car (read-from-string
2586 (downcase 2585 (downcase (match-string 1 doc))))))
2587 (substring doc
2588 (match-beginning 1)
2589 (match-end 1)))))))
2590 (ad-get-subr-args subr-name))
2591 ;; this is the old format used before Emacs 19.24:
2592 ((string-match
2593 "[\n\t ]*\narguments: ?\\((.*)\\)\n?\\'" doc)
2594 (ad-define-subr-args
2595 subr-name
2596 (car (read-from-string
2597 doc (match-beginning 1) (match-end 1))))
2598 (ad-get-subr-args subr-name)) 2586 (ad-get-subr-args subr-name))
2587 ;; This is actually an error.
2599 (t '(&rest ad-subr-args))))))) 2588 (t '(&rest ad-subr-args)))))))
2600 2589
2601(defun ad-docstring (definition) 2590(defun ad-docstring (definition)
@@ -2999,33 +2988,37 @@ Example: `(ad-map-arglists '(a &rest args) '(w x y z))' will return
2999 (capitalize (symbol-name class)) 2988 (capitalize (symbol-name class))
3000 (ad-advice-name advice))))))) 2989 (ad-advice-name advice)))))))
3001 2990
2991(require 'help-fns) ;For help-split-fundoc and help-add-fundoc-usage.
2992
3002(defun ad-make-advised-docstring (function &optional style) 2993(defun ad-make-advised-docstring (function &optional style)
3003 ;;"Constructs a documentation string for the advised FUNCTION. 2994 "Construct a documentation string for the advised FUNCTION.
3004 ;;It concatenates the original documentation with the documentation 2995It concatenates the original documentation with the documentation
3005 ;;strings of the individual pieces of advice which will be formatted 2996strings of the individual pieces of advice which will be formatted
3006 ;;according to STYLE. STYLE can be `plain' or `freeze', everything else 2997according to STYLE. STYLE can be `plain' or `freeze', everything else
3007 ;;will be interpreted as `default'. The order of the advice documentation 2998will be interpreted as `default'. The order of the advice documentation
3008 ;;strings corresponds to before/around/after and the individual ordering 2999strings corresponds to before/around/after and the individual ordering
3009 ;;in any of these classes." 3000in any of these classes."
3010 (let* ((origdef (ad-real-orig-definition function)) 3001 (let* ((origdef (ad-real-orig-definition function))
3011 (origtype (symbol-name (ad-definition-type origdef))) 3002 (origtype (symbol-name (ad-definition-type origdef)))
3012 (origdoc 3003 (origdoc
3013 ;; Retrieve raw doc, key substitution will be taken care of later: 3004 ;; Retrieve raw doc, key substitution will be taken care of later:
3014 (ad-real-documentation origdef t)) 3005 (ad-real-documentation origdef t))
3015 paragraphs advice-docstring) 3006 (usage (help-split-fundoc origdoc function))
3007 paragraphs advice-docstring ad-usage)
3008 (if usage (setq origdoc (cdr usage) usage (car usage)))
3016 (if origdoc (setq paragraphs (list origdoc))) 3009 (if origdoc (setq paragraphs (list origdoc)))
3017 (if (not (eq style 'plain)) 3010 (unless (eq style 'plain)
3018 (setq paragraphs (cons (concat "This " origtype " is advised.") 3011 (push (concat "This " origtype " is advised.") paragraphs))
3019 paragraphs)))
3020 (ad-dolist (class ad-advice-classes) 3012 (ad-dolist (class ad-advice-classes)
3021 (ad-dolist (advice (ad-get-enabled-advices function class)) 3013 (ad-dolist (advice (ad-get-enabled-advices function class))
3022 (setq advice-docstring 3014 (setq advice-docstring
3023 (ad-make-single-advice-docstring advice class style)) 3015 (ad-make-single-advice-docstring advice class style))
3024 (if advice-docstring 3016 (if advice-docstring
3025 (setq paragraphs (cons advice-docstring paragraphs))))) 3017 (push advice-docstring paragraphs))))
3026 (if paragraphs 3018 (setq origdoc (if paragraphs
3027 ;; separate paragraphs with blank lines: 3019 ;; separate paragraphs with blank lines:
3028 (mapconcat 'identity (nreverse paragraphs) "\n\n")))) 3020 (mapconcat 'identity (nreverse paragraphs) "\n\n")))
3021 (help-add-fundoc-usage origdoc usage)))
3029 3022
3030(defun ad-make-plain-docstring (function) 3023(defun ad-make-plain-docstring (function)
3031 (ad-make-advised-docstring function 'plain)) 3024 (ad-make-advised-docstring function 'plain))