From 28bfd4db69c357b708e7b711c947122faf499368 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 20 Jun 2022 02:27:00 +0200 Subject: [PATCH] Allow removing quotes around links in *Help* buffers * doc/emacs/help.texi (Help Mode): Document it. * lisp/help-mode.el (help-clean-buttons): New user option (help-xref-button): Use it. --- doc/emacs/help.texi | 5 +++++ etc/NEWS | 4 ++++ lisp/help-mode.el | 30 +++++++++++++++++++++++++----- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/doc/emacs/help.texi b/doc/emacs/help.texi index 11ee9dc2b2f..d206dee3859 100644 --- a/doc/emacs/help.texi +++ b/doc/emacs/help.texi @@ -542,6 +542,11 @@ previous hyperlink. These commands act cyclically; for instance, typing @key{TAB} at the last hyperlink moves back to the first hyperlink. +@vindex help-clean-buttons + By default, many links in the help buffer are displayed surrounded +by quote characters. If the @code{help-clean-buttons} user option is +non-@code{nil}, these quote characters are removed from the buffer. + @kindex n @r{(Help mode)} @kindex p @r{(Help mode)} @findex help-goto-next-page diff --git a/etc/NEWS b/etc/NEWS index 1a90cf15c09..bf154b4b9e8 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -581,6 +581,10 @@ or ':scream:'. ** Help +*** New user option 'help-clean-buttons'. +If non-nil, link buttons in *Help* will have any surrounding quotes +removed. + --- *** 'M-x apropos-variable' output now includes values of variables. diff --git a/lisp/help-mode.el b/lisp/help-mode.el index a50524253ba..a1b03700dbf 100644 --- a/lisp/help-mode.el +++ b/lisp/help-mode.el @@ -543,6 +543,12 @@ Each element has the form (NAME TESTFUN DESCFUN) where: and a frame), inserts the description of that symbol in the current buffer and returns that text as well.") +(defcustom help-clean-buttons nil + "If non-nil, remove quotes around link buttons." + :version "29.1" + :type 'boolean + :group 'help) + ;;;###autoload (defun help-make-xrefs (&optional buffer) "Parse and hyperlink documentation cross-references in the given BUFFER. @@ -691,12 +697,26 @@ that." MATCH-NUMBER is the subexpression of interest in the last matched regexp. TYPE is the type of button to use. Any remaining arguments are passed to the button's help-function when it is invoked. -See `help-make-xrefs'." +See `help-make-xrefs'. + +This function heeds the `help-clean-buttons' variable and will +remove quotes surrounding the match if non-nil." ;; Don't mung properties we've added specially in some instances. - (unless (button-at (match-beginning match-number)) - (make-text-button (match-beginning match-number) - (match-end match-number) - 'type type 'help-args args))) + (let ((beg (match-beginning match-number)) + (end (match-end match-number))) + (unless (button-at beg) + (make-text-button beg end 'type type 'help-args args) + (when (and help-clean-buttons + (> beg (point-min)) + (save-excursion + (goto-char (1- beg)) + (looking-at "['`‘]")) + (< end (point-max)) + (save-excursion + (goto-char end) + (looking-at "['’]"))) + (delete-region end (1+ end)) + (delete-region (1- beg) beg))))) ;;;###autoload (defun help-insert-xref-button (string type &rest args) -- 2.39.2