diff options
| author | Daniel Martín <mardani29@yahoo.es> | 2019-12-30 13:11:57 +0100 |
|---|---|---|
| committer | Wilfred Hughes <me@wilfred.me.uk> | 2020-01-01 13:46:10 +0000 |
| commit | 982dd49c9c7e63fa94b56824f50dea4186081f8e (patch) | |
| tree | 994baa30ea87e0860790473de8bb53dbb412b2b9 | |
| parent | edddccbebd82dde0a18662a0995bfe930112458c (diff) | |
Improve link creation from Info manual references
* helpful.el (helpful--propertize-info): Follow Emacs convention for
function documentation. Consider lowercase "info" and angular
quotation marks in docstrings. Default to the Emacs manual if there's
no manual reference (ie. see the `blink-cursor-mode' variable).
* test/helpful-unit-test.el (helpful--format-docstring--info): Add new
testcases for the now covered cases.
| -rw-r--r-- | helpful.el | 37 | ||||
| -rw-r--r-- | test/helpful-unit-test.el | 21 |
2 files changed, 46 insertions, 12 deletions
@@ -788,22 +788,35 @@ bound) or else highlight." 'face 'font-lock-constant-face))))) (defun helpful--propertize-info (docstring) - "Convert info references in docstrings to buttons." + "Convert info references in DOCSTRING to buttons." (replace-regexp-in-string - ;; Replace all text of the form `foo'. - (rx "Info " - (group - (or "anchor" "node") - (+ whitespace)) - "`" - (group (+ (not (in "'")))) - "'") + ;; Replace all text that looks like a link to an Info page. + (rx (seq (group + bow + (any "Ii") + "nfo" + (one-or-more whitespace)) + (group + (or "node" "anchor") + (one-or-more whitespace)) + (any "'`‘") + (group + (one-or-more + (not (any "'’")))) + (any "'’"))) (lambda (it) + ;; info-name matches "[Ii]nfo ". + ;; space matches "node " or "anchor ". ;; info-node has the form "(cl)Loop Facility". - (let ((space (match-string 1 it)) - (info-node (match-string 2 it))) + (let ((info-name (match-string 1 it)) + (space (match-string 2 it)) + (info-node (match-string 3 it))) + ;; If the docstring doesn't specify a manual, assume the Emacs manual. + (save-match-data + (unless (string-match "^([^)]+)" info-node) + (setq info-node (concat "(emacs)" info-node)))) (concat - "Info " + info-name space (helpful--button info-node diff --git a/test/helpful-unit-test.el b/test/helpful-unit-test.el index d296423..0250980 100644 --- a/test/helpful-unit-test.el +++ b/test/helpful-unit-test.el @@ -317,6 +317,27 @@ symbol (not a form)." (should (string-equal formatted "Info node (elisp)foo \nbar")) (should + (get-text-property paren-position 'button formatted))) + ;; Some docstrings use "info" (lowercase). + (let* ((formatted (helpful--format-docstring "info node `(elisp)foo'")) + (paren-position (s-index-of "(" formatted))) + (should + (string-equal formatted "info node (elisp)foo")) + (should + (get-text-property paren-position 'button formatted))) + ;; Some docstrings use angular quotation marks. + (let* ((formatted (helpful--format-docstring "Info node ‘(elisp)foo’")) + (paren-position (s-index-of "(" formatted))) + (should + (string-equal formatted "Info node (elisp)foo")) + (should + (get-text-property paren-position 'button formatted))) + ;; If there's no manual information, assume it is part of the Emacs manual. + (let* ((formatted (helpful--format-docstring "Info node ‘foo’")) + (paren-position (s-index-of "(" formatted))) + (should + (string-equal formatted "Info node (emacs)foo")) + (should (get-text-property paren-position 'button formatted)))) (ert-deftest helpful--format-docstring--url () |
