(describe-variable): Fix bug#73872

* lisp/help-fns.el (describe-variable): Put a `syntax-table` property
on the printed value for better navigation.  Remove `set-syntax-table`
since `lisp-data-mode` already did it.
(describe-variable): Remove `set-syntax-table`, not needed any more.

* lisp/help-mode.el (help-mode-syntax-table): `;` shouldn't start a comment.
(help-make-xrefs): Use `with-syntax-table`.
This commit is contained in:
Stefan Monnier 2025-01-02 14:58:10 -05:00
parent f65520cad4
commit 8f81c2b02f
2 changed files with 112 additions and 110 deletions

View file

@ -1445,21 +1445,29 @@ it is displayed along with the global value."
(format-message "`%s'" rep)
rep)))
(start (point)))
(let (beg)
(if (< (+ (length print-rep) (point) (- line-beg)) 68)
(insert " " print-rep)
(progn
(setq beg (1+ (point)))
(insert " " print-rep))
(terpri)
(setq beg (point))
(let ((buf (current-buffer)))
(with-temp-buffer
(lisp-data-mode)
(set-syntax-table emacs-lisp-mode-syntax-table)
(insert print-rep)
(pp-buffer)
(font-lock-ensure)
(let ((pp-buffer (current-buffer)))
(with-current-buffer buf
(insert-buffer-substring pp-buffer)))))
(insert-buffer-substring pp-buffer))))))
;; Remove trailing newline.
(and (= (char-before) ?\n) (delete-char -1)))
(and (= (char-before) ?\n) (delete-char -1))
;; Put a `syntax-table' property on the data, as
;; a kind of poor man's multi-major-mode support here.
(put-text-property beg (point)
'syntax-table
lisp-data-mode-syntax-table))
(help-fns--editable-variable start (point)
variable val buffer)
(let* ((sv (get variable 'standard-value))
@ -1523,10 +1531,6 @@ it is displayed along with the global value."
;; If the value is large, move it to the end.
(with-current-buffer standard-output
(when (> (count-lines (point-min) (point-max)) 10)
;; Note that setting the syntax table like below
;; makes forward-sexp move over a `'s' at the end
;; of a symbol.
(set-syntax-table emacs-lisp-mode-syntax-table)
(goto-char val-start-pos)
(when (looking-at "value is") (replace-match ""))
(save-excursion

View file

@ -143,6 +143,8 @@ The format is (FUNCTION ARGS...).")
;; break when a quoted string contains punctuation.
(modify-syntax-entry ? "( " table)
(modify-syntax-entry ? ") " table)
;; `;' doesn't start a comment.
(modify-syntax-entry ?\; "." table)
table)
"Syntax table used in `help-mode'.")
@ -587,13 +589,10 @@ that."
;; Skip the first bit, which has already been buttonized.
(forward-paragraph)
(let ((old-modified (buffer-modified-p)))
(let ((stab (syntax-table))
(case-fold-search t)
(let ((case-fold-search t)
(inhibit-read-only t))
(set-syntax-table help-mode-syntax-table)
(with-syntax-table help-mode-syntax-table
;; The following should probably be abstracted out.
(unwind-protect
(progn
;; Info references
(save-excursion
(while (re-search-forward help-xref-info-regexp nil t)
@ -679,7 +678,6 @@ that."
(let ((sym (intern-soft (match-string 1))))
(if (fboundp sym)
(help-xref-button 1 'help-function sym))))))
(set-syntax-table stab))
;; Delete extraneous newlines at the end of the docstring
(goto-char (point-max))
(while (and (not (bobp)) (bolp))