Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions helpful.el
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,48 @@ may contain duplicates."
(when (autoloadp fn-obj)
(autoload-do-load fn-obj)))))

;; backward-compatible with emacs 25
(unless (fboundp 'advice--where)
(defun advice--where (f)
(let ((bytecode (aref f 1))
(where nil))
(dolist (elem advice--where-alist)
(if (eq bytecode (cadr elem)) (setq where (car elem))))
where)))

(defun helpful--advise-info (function)
(let* ((flist (indirect-function function))
(docfun nil)
(docstring nil))
(if (eq 'macro (car-safe flist)) (setq flist (cdr flist)))
(while (advice--p flist)
(let ((doc (aref flist 4))
(where (advice--where flist)))
;; Hack attack! For advices installed before calling
;; Snarf-documentation, the integer offset into the DOC file will not
;; be installed in the "core unadvised function" but in the advice
;; object instead! So here we try to undo the damage.
(if (integerp doc) (setq docfun flist))
(setq docstring
(concat
docstring
(propertize (format "%s advice: " where)
'face 'warning)
(let ((fun (advice--car flist)))
(if (symbolp fun) (format-message "`%S'" fun)
(let* ((name (cdr (assq 'name (advice--props flist))))
(doc (documentation fun t))
(usage (help-split-fundoc doc function)))
(if usage (setq doc (cdr usage)))
(if name
(if doc
(format "%s\n%s" name doc)
(format "%s" name))
(or doc "No documentation")))))
"\n")))
(setq flist (advice--cdr flist)))
docstring))

(defun helpful-update ()
"Update the current *Helpful* buffer to the latest
state of the current symbol."
Expand Down Expand Up @@ -2108,8 +2150,10 @@ state of the current symbol."
(helpful--insert-section-break)
(insert
(helpful--heading "Advice")
(format "This %s is advised."
(if (macrop helpful--sym) "macro" "function"))))
(format "This %s is advised.\n"
(if (macrop helpful--sym) "macro" "function"))
(helpful--advise-info helpful--sym)
))

(let ((can-edebug
(helpful--can-edebug-p helpful--sym helpful--callable-p buf pos))
Expand Down
11 changes: 11 additions & 0 deletions test/helpful-unit-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@
(helpful--docstring #'test-foo t)
"Docstring here.")))

(ert-deftest helpful--advice-info ()
"Advice docstring."
(should
(equal
(helpful--advise-info #'test-foo-advised)
":around advice: ‘ad-Advice-test-foo-advised’\n"))
(should
(equal
(helpful--advise-info #'test-foo)
nil)))

(ert-deftest helpful--docstring-symbol ()
"Correctly handle quotes around symbols."
;; We should replace quoted symbols with links, so the punctuation
Expand Down