Commit 4e1ede6c authored by Stefan Monnier's avatar Stefan Monnier
Browse files

(help-xref-on-pp): Use match-string.

(describe-variable): New arg BUFFER.
Store the current buffer in the help-xref-stack.
(temp-buffer-resize-mode): Use define-minor-mode.
parent 60dd7e0e
...@@ -151,7 +151,7 @@ Commands: ...@@ -151,7 +151,7 @@ Commands:
(add-hook 'temp-buffer-setup-hook 'help-mode-setup) (add-hook 'temp-buffer-setup-hook 'help-mode-setup)
(defun help-mode-finish () (defun help-mode-finish ()
(when (eq major-mode 'help-mode) (when (eq major-mode 'help-mode)
;; View mode's read-only status of existing *Help* buffer is lost ;; View mode's read-only status of existing *Help* buffer is lost
;; by with-output-to-temp-buffer. ;; by with-output-to-temp-buffer.
(toggle-read-only 1) (toggle-read-only 1)
...@@ -790,9 +790,7 @@ Return 0 if there is no such symbol." ...@@ -790,9 +790,7 @@ Return 0 if there is no such symbol."
((looking-at "\"") (forward-sexp 1)) ((looking-at "\"") (forward-sexp 1))
((looking-at "#<") (search-forward ">" nil 'move)) ((looking-at "#<") (search-forward ">" nil 'move))
((looking-at "\\(\\(\\sw\\|\\s_\\)+\\)") ((looking-at "\\(\\(\\sw\\|\\s_\\)+\\)")
(let* ((sym (intern-soft (let* ((sym (intern-soft (match-string 1)))
(buffer-substring (match-beginning 1)
(match-end 1))))
(fn (cond ((fboundp sym) #'describe-function) (fn (cond ((fboundp sym) #'describe-function)
((or (memq sym '(t nil)) ((or (memq sym '(t nil))
(keywordp sym)) (keywordp sym))
...@@ -804,10 +802,12 @@ Return 0 if there is no such symbol." ...@@ -804,10 +802,12 @@ Return 0 if there is no such symbol."
(t (forward-char 1)))))) (t (forward-char 1))))))
(set-syntax-table ost)))) (set-syntax-table ost))))
(defun describe-variable (variable) (defun describe-variable (variable &optional buffer)
"Display the full documentation of VARIABLE (a symbol). "Display the full documentation of VARIABLE (a symbol).
Returns the documentation as a string, also." Returns the documentation as a string, also.
(interactive If VARIABLE has a buffer-local value in BUFFER (default to the current buffer),
it is displayed along with the global value."
(interactive
(let ((v (variable-at-point)) (let ((v (variable-at-point))
(enable-recursive-minibuffers t) (enable-recursive-minibuffers t)
val) val)
...@@ -819,8 +819,11 @@ Returns the documentation as a string, also." ...@@ -819,8 +819,11 @@ Returns the documentation as a string, also."
(if (symbolp v) (symbol-name v)))) (if (symbolp v) (symbol-name v))))
(list (if (equal val "") (list (if (equal val "")
v (intern val))))) v (intern val)))))
(if (symbolp variable) (unless (bufferp buffer) (setq buffer (current-buffer)))
(let (valvoid) (if (not (symbolp variable))
(message "You did not specify a variable")
(let (valvoid)
(with-current-buffer buffer
(with-output-to-temp-buffer "*Help*" (with-output-to-temp-buffer "*Help*"
(prin1 variable) (prin1 variable)
(if (not (boundp variable)) (if (not (boundp variable))
...@@ -853,8 +856,7 @@ Returns the documentation as a string, also." ...@@ -853,8 +856,7 @@ Returns the documentation as a string, also."
(help-xref-on-pp from (point)))))) (help-xref-on-pp from (point))))))
(terpri))) (terpri)))
(terpri) (terpri)
(save-current-buffer (with-current-buffer standard-output
(set-buffer standard-output)
(if (> (count-lines (point-min) (point-max)) 10) (if (> (count-lines (point-min) (point-max)) 10)
(progn (progn
;; Note that setting the syntax table like below ;; Note that setting the syntax table like below
...@@ -873,8 +875,9 @@ Returns the documentation as a string, also." ...@@ -873,8 +875,9 @@ Returns the documentation as a string, also."
(terpri) (terpri)
(let ((doc (documentation-property variable 'variable-documentation))) (let ((doc (documentation-property variable 'variable-documentation)))
(princ (or doc "not documented as a variable."))) (princ (or doc "not documented as a variable.")))
(help-setup-xref (list #'describe-variable variable) (interactive-p)) (help-setup-xref (list #'describe-variable variable (current-buffer))
(interactive-p))
;; Make a link to customize if this variable can be customized. ;; Make a link to customize if this variable can be customized.
;; Note, it is not reliable to test only for a custom-type property ;; Note, it is not reliable to test only for a custom-type property
;; because those are only present after the var's definition ;; because those are only present after the var's definition
...@@ -888,7 +891,7 @@ Returns the documentation as a string, also." ...@@ -888,7 +891,7 @@ Returns the documentation as a string, also."
(princ (concat "You can " customize-label " this variable.")) (princ (concat "You can " customize-label " this variable."))
(with-current-buffer "*Help*" (with-current-buffer "*Help*"
(save-excursion (save-excursion
(re-search-backward (re-search-backward
(concat "\\(" customize-label "\\)") nil t) (concat "\\(" customize-label "\\)") nil t)
(help-xref-button 1 (lambda (v) (help-xref-button 1 (lambda (v)
(if help-xref-stack (if help-xref-stack
...@@ -919,8 +922,7 @@ Returns the documentation as a string, also." ...@@ -919,8 +922,7 @@ Returns the documentation as a string, also."
(save-excursion (save-excursion
(set-buffer standard-output) (set-buffer standard-output)
;; Return the text we displayed. ;; Return the text we displayed.
(buffer-string)))) (buffer-string)))))))
(message "You did not specify a variable")))
(defun describe-bindings (&optional prefix buffer) (defun describe-bindings (&optional prefix buffer)
"Show a list of all defined keys, and their definitions. "Show a list of all defined keys, and their definitions.
...@@ -1201,7 +1203,7 @@ that." ...@@ -1201,7 +1203,7 @@ that."
(help-xref-button (help-xref-button
7 #'describe-face sym))))))) 7 #'describe-face sym)))))))
;; An obvious case of a key substitution: ;; An obvious case of a key substitution:
(save-excursion (save-excursion
(while (re-search-forward (while (re-search-forward
;; Assume command name is only word characters ;; Assume command name is only word characters
;; and dashes to get things like `use M-x foo.'. ;; and dashes to get things like `use M-x foo.'.
...@@ -1217,7 +1219,7 @@ that." ...@@ -1217,7 +1219,7 @@ that."
(goto-char (point-min)) (goto-char (point-min))
;; Find a header and the column at which the command ;; Find a header and the column at which the command
;; name will be found. ;; name will be found.
(while (re-search-forward "^key +binding\n\\(-+ +\\)-+\n\n" (while (re-search-forward "^key +binding\n\\(-+ +\\)-+\n\n"
nil t) nil t)
(let ((col (- (match-end 1) (match-beginning 1)))) (let ((col (- (match-end 1) (match-beginning 1))))
(while (while
...@@ -1232,7 +1234,7 @@ that." ...@@ -1232,7 +1234,7 @@ that."
(looking-at "\\(\\sw\\|-\\)+$")) (looking-at "\\(\\sw\\|-\\)+$"))
(let ((sym (intern-soft (match-string 0)))) (let ((sym (intern-soft (match-string 0))))
(if (fboundp sym) (if (fboundp sym)
(help-xref-button (help-xref-button
0 #'describe-function sym 0 #'describe-function sym
"mouse-2, RET: describe this function")))) "mouse-2, RET: describe this function"))))
(zerop (forward-line))))))))) (zerop (forward-line)))))))))
...@@ -1427,23 +1429,6 @@ For the cross-reference format, see `help-make-xrefs'." ...@@ -1427,23 +1429,6 @@ For the cross-reference format, see `help-make-xrefs'."
;;; Automatic resizing of temporary buffers. ;;; Automatic resizing of temporary buffers.
(defcustom temp-buffer-resize-mode nil
"Non-nil means resize windows displaying temporary buffers.
This makes the window the right height for its contents, but never
more than `temp-buffer-max-height' nor less than `window-min-height'.
This applies to `help', `apropos' and `completion' buffers, and some others.
Setting this variable directly does not take effect;
use either \\[customize] or the function `temp-buffer-resize-mode'."
:get (lambda (symbol)
(and (memq 'resize-temp-buffer-window temp-buffer-show-hook) t))
:set (lambda (symbol value)
(temp-buffer-resize-mode (if value 1 -1)))
:initialize 'custom-initialize-default
:type 'boolean
:group 'help
:version "20.4")
(defcustom temp-buffer-max-height (lambda (buffer) (/ (- (frame-height) 2) 2)) (defcustom temp-buffer-max-height (lambda (buffer) (/ (- (frame-height) 2) 2))
"*Maximum height of a window displaying a temporary buffer. "*Maximum height of a window displaying a temporary buffer.
This is the maximum height (in text lines) which `resize-temp-buffer-window' This is the maximum height (in text lines) which `resize-temp-buffer-window'
...@@ -1455,25 +1440,19 @@ positive number." ...@@ -1455,25 +1440,19 @@ positive number."
:group 'help :group 'help
:version "20.4") :version "20.4")
(defun temp-buffer-resize-mode (arg) (define-minor-mode temp-buffer-resize-mode
"Toggle the mode which that makes windows smaller for temporary buffers. "Toggle the mode which makes windows smaller for temporary buffers.
With prefix argument ARG, turn the resizing of windows displaying temporary With prefix argument ARG, turn the resizing of windows displaying temporary
buffers on if ARG is positive or off otherwise. buffers on if ARG is positive or off otherwise.
See the documentation of the variable `temp-buffer-resize-mode' for This makes the window the right height for its contents, but never
more information." more than `temp-buffer-max-height' nor less than `window-min-height'.
(interactive "P") This applies to `help', `apropos' and `completion' buffers, and some others."
(let ((turn-it-on nil nil nil :global t :group 'help
(if (null arg) (if temp-buffer-resize-mode
(not (memq 'resize-temp-buffer-window temp-buffer-show-hook)) ;; `help-mode-maybe' may add a `back' button and thus increase the
(> (prefix-numeric-value arg) 0)))) ;; text size, so `resize-temp-buffer-window' must be run *after* it.
(if turn-it-on (add-hook 'temp-buffer-show-hook 'resize-temp-buffer-window 'append)
(progn (remove-hook 'temp-buffer-show-hook 'resize-temp-buffer-window))))
;; `help-mode-maybe' may add a `back' button and thus increase the
;; text size, so `resize-temp-buffer-window' must be run *after* it.
(add-hook 'temp-buffer-show-hook 'resize-temp-buffer-window 'append)
(setq temp-buffer-resize-mode t))
(remove-hook 'temp-buffer-show-hook 'resize-temp-buffer-window)
(setq temp-buffer-resize-mode nil))))
(defun resize-temp-buffer-window () (defun resize-temp-buffer-window ()
"Resize the current window to fit its contents. "Resize the current window to fit its contents.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment