(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:
parent
f65520cad4
commit
8f81c2b02f
2 changed files with 112 additions and 110 deletions
|
@ -1445,21 +1445,29 @@ it is displayed along with the global value."
|
|||
(format-message "`%s'" rep)
|
||||
rep)))
|
||||
(start (point)))
|
||||
(if (< (+ (length print-rep) (point) (- line-beg)) 68)
|
||||
(insert " " print-rep)
|
||||
(terpri)
|
||||
(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)))))
|
||||
;; Remove trailing newline.
|
||||
(and (= (char-before) ?\n) (delete-char -1)))
|
||||
(let (beg)
|
||||
(if (< (+ (length print-rep) (point) (- line-beg)) 68)
|
||||
(progn
|
||||
(setq beg (1+ (point)))
|
||||
(insert " " print-rep))
|
||||
(terpri)
|
||||
(setq beg (point))
|
||||
(let ((buf (current-buffer)))
|
||||
(with-temp-buffer
|
||||
(lisp-data-mode)
|
||||
(insert print-rep)
|
||||
(pp-buffer)
|
||||
(font-lock-ensure)
|
||||
(let ((pp-buffer (current-buffer)))
|
||||
(with-current-buffer buf
|
||||
(insert-buffer-substring pp-buffer))))))
|
||||
;; Remove trailing newline.
|
||||
(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
|
||||
|
|
|
@ -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,99 +589,95 @@ 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)
|
||||
;; The following should probably be abstracted out.
|
||||
(unwind-protect
|
||||
(progn
|
||||
;; Info references
|
||||
(with-syntax-table help-mode-syntax-table
|
||||
;; The following should probably be abstracted out.
|
||||
;; Info references
|
||||
(save-excursion
|
||||
(while (re-search-forward help-xref-info-regexp nil t)
|
||||
(let ((data (match-string 2)))
|
||||
(save-match-data
|
||||
(unless (string-match "^([^)]+)" data)
|
||||
(setq data (concat "(emacs)" data)))
|
||||
(setq data ;; possible newlines if para filled
|
||||
(replace-regexp-in-string "[ \t\n]+" " " data t t)))
|
||||
(help-xref-button 2 'help-info data))))
|
||||
;; Man references
|
||||
(save-excursion
|
||||
(while (re-search-forward help-xref-man-regexp nil t)
|
||||
(help-xref-button 1 'help-man (match-string 1))))
|
||||
;; Customization groups.
|
||||
(save-excursion
|
||||
(while (re-search-forward
|
||||
help-xref-customization-group-regexp nil t)
|
||||
(help-xref-button 1 'help-customization-group
|
||||
(intern (match-string 1)))))
|
||||
;; URLs
|
||||
(save-excursion
|
||||
(while (re-search-forward help-xref-url-regexp nil t)
|
||||
(let ((data (match-string 1)))
|
||||
(help-xref-button 1 'help-url data))))
|
||||
;; Mule related keywords. Do this before trying
|
||||
;; `help-xref-symbol-regexp' because some of Mule
|
||||
;; keywords have variable or function definitions.
|
||||
(if help-xref-mule-regexp
|
||||
(save-excursion
|
||||
(while (re-search-forward help-xref-info-regexp nil t)
|
||||
(let ((data (match-string 2)))
|
||||
(save-match-data
|
||||
(unless (string-match "^([^)]+)" data)
|
||||
(setq data (concat "(emacs)" data)))
|
||||
(setq data ;; possible newlines if para filled
|
||||
(replace-regexp-in-string "[ \t\n]+" " " data t t)))
|
||||
(help-xref-button 2 'help-info data))))
|
||||
;; Man references
|
||||
(save-excursion
|
||||
(while (re-search-forward help-xref-man-regexp nil t)
|
||||
(help-xref-button 1 'help-man (match-string 1))))
|
||||
;; Customization groups.
|
||||
(save-excursion
|
||||
(while (re-search-forward
|
||||
help-xref-customization-group-regexp nil t)
|
||||
(help-xref-button 1 'help-customization-group
|
||||
(intern (match-string 1)))))
|
||||
;; URLs
|
||||
(save-excursion
|
||||
(while (re-search-forward help-xref-url-regexp nil t)
|
||||
(let ((data (match-string 1)))
|
||||
(help-xref-button 1 'help-url data))))
|
||||
;; Mule related keywords. Do this before trying
|
||||
;; `help-xref-symbol-regexp' because some of Mule
|
||||
;; keywords have variable or function definitions.
|
||||
(if help-xref-mule-regexp
|
||||
(save-excursion
|
||||
(while (re-search-forward help-xref-mule-regexp nil t)
|
||||
(let* ((data (match-string 7))
|
||||
(sym (intern-soft data)))
|
||||
(cond
|
||||
((match-string 3) ; coding system
|
||||
(and sym (coding-system-p sym)
|
||||
(help-xref-button 6 'help-coding-system sym)))
|
||||
((match-string 4) ; input method
|
||||
(and (assoc data input-method-alist)
|
||||
(help-xref-button 7 'help-input-method data)))
|
||||
((or (match-string 5) (match-string 6)) ; charset
|
||||
(and sym (charsetp sym)
|
||||
(help-xref-button 7 'help-character-set sym)))
|
||||
((assoc data input-method-alist)
|
||||
(help-xref-button 7 'help-input-method data))
|
||||
((and sym (coding-system-p sym))
|
||||
(help-xref-button 7 'help-coding-system sym))
|
||||
((and sym (charsetp sym))
|
||||
(help-xref-button 7 'help-character-set sym)))))))
|
||||
;; Quoted symbols
|
||||
(save-excursion
|
||||
(while (re-search-forward help-xref-symbol-regexp nil t)
|
||||
(when-let* ((sym (intern-soft (match-string 9))))
|
||||
(if (match-string 8)
|
||||
(delete-region (match-beginning 8)
|
||||
(match-end 8))
|
||||
(cond
|
||||
((match-string 3) ; `variable' &c
|
||||
(and (or (boundp sym) ; `variable' doesn't ensure
|
||||
; it's actually bound
|
||||
(get sym 'variable-documentation))
|
||||
(help-xref-button 9 'help-variable sym)))
|
||||
((match-string 4) ; `function' &c
|
||||
(and (fboundp sym) ; similarly
|
||||
(help-xref-button 9 'help-function sym)))
|
||||
((match-string 5) ; `face'
|
||||
(and (facep sym)
|
||||
(help-xref-button 9 'help-face sym)))
|
||||
((match-string 6)) ; nothing for `symbol'
|
||||
((match-string 7)
|
||||
(help-xref-button 9 'help-function-def sym))
|
||||
((cl-some (lambda (x) (funcall (nth 1 x) sym))
|
||||
describe-symbol-backends)
|
||||
(help-xref-button 9 'help-symbol sym)))))))
|
||||
;; An obvious case of a key substitution:
|
||||
(save-excursion
|
||||
(while (re-search-forward
|
||||
;; Assume command name is only word and symbol
|
||||
;; characters to get things like `use M-x foo->bar'.
|
||||
;; Command required to end with word constituent
|
||||
;; to avoid `.' at end of a sentence.
|
||||
"\\<M-x\\s-+\\(\\sw\\(\\sw\\|\\s_\\)*\\sw\\)" nil t)
|
||||
(let ((sym (intern-soft (match-string 1))))
|
||||
(if (fboundp sym)
|
||||
(help-xref-button 1 'help-function sym))))))
|
||||
(set-syntax-table stab))
|
||||
(while (re-search-forward help-xref-mule-regexp nil t)
|
||||
(let* ((data (match-string 7))
|
||||
(sym (intern-soft data)))
|
||||
(cond
|
||||
((match-string 3) ; coding system
|
||||
(and sym (coding-system-p sym)
|
||||
(help-xref-button 6 'help-coding-system sym)))
|
||||
((match-string 4) ; input method
|
||||
(and (assoc data input-method-alist)
|
||||
(help-xref-button 7 'help-input-method data)))
|
||||
((or (match-string 5) (match-string 6)) ; charset
|
||||
(and sym (charsetp sym)
|
||||
(help-xref-button 7 'help-character-set sym)))
|
||||
((assoc data input-method-alist)
|
||||
(help-xref-button 7 'help-input-method data))
|
||||
((and sym (coding-system-p sym))
|
||||
(help-xref-button 7 'help-coding-system sym))
|
||||
((and sym (charsetp sym))
|
||||
(help-xref-button 7 'help-character-set sym)))))))
|
||||
;; Quoted symbols
|
||||
(save-excursion
|
||||
(while (re-search-forward help-xref-symbol-regexp nil t)
|
||||
(when-let* ((sym (intern-soft (match-string 9))))
|
||||
(if (match-string 8)
|
||||
(delete-region (match-beginning 8)
|
||||
(match-end 8))
|
||||
(cond
|
||||
((match-string 3) ; `variable' &c
|
||||
(and (or (boundp sym) ; `variable' doesn't ensure
|
||||
; it's actually bound
|
||||
(get sym 'variable-documentation))
|
||||
(help-xref-button 9 'help-variable sym)))
|
||||
((match-string 4) ; `function' &c
|
||||
(and (fboundp sym) ; similarly
|
||||
(help-xref-button 9 'help-function sym)))
|
||||
((match-string 5) ; `face'
|
||||
(and (facep sym)
|
||||
(help-xref-button 9 'help-face sym)))
|
||||
((match-string 6)) ; nothing for `symbol'
|
||||
((match-string 7)
|
||||
(help-xref-button 9 'help-function-def sym))
|
||||
((cl-some (lambda (x) (funcall (nth 1 x) sym))
|
||||
describe-symbol-backends)
|
||||
(help-xref-button 9 'help-symbol sym)))))))
|
||||
;; An obvious case of a key substitution:
|
||||
(save-excursion
|
||||
(while (re-search-forward
|
||||
;; Assume command name is only word and symbol
|
||||
;; characters to get things like `use M-x foo->bar'.
|
||||
;; Command required to end with word constituent
|
||||
;; to avoid `.' at end of a sentence.
|
||||
"\\<M-x\\s-+\\(\\sw\\(\\sw\\|\\s_\\)*\\sw\\)" nil t)
|
||||
(let ((sym (intern-soft (match-string 1))))
|
||||
(if (fboundp sym)
|
||||
(help-xref-button 1 'help-function sym))))))
|
||||
;; Delete extraneous newlines at the end of the docstring
|
||||
(goto-char (point-max))
|
||||
(while (and (not (bobp)) (bolp))
|
||||
|
|
Loading…
Add table
Reference in a new issue