aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2000-10-05 22:27:38 +0000
committerStefan Monnier2000-10-05 22:27:38 +0000
commit4e1ede6c01245a650513a72a30eab1246a072a66 (patch)
treef14a8f70acd09e47d3ee71f88fa32e06158a5c4e
parent60dd7e0e1cb294fc6e4b7a724f3b9d717a7ae8d8 (diff)
downloademacs-4e1ede6c01245a650513a72a30eab1246a072a66.tar.gz
emacs-4e1ede6c01245a650513a72a30eab1246a072a66.zip
(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.
-rw-r--r--lisp/help.el85
1 files changed, 32 insertions, 53 deletions
diff --git a/lisp/help.el b/lisp/help.el
index 469979d91d6..7ebd131f6f7 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -151,7 +151,7 @@ Commands:
151(add-hook 'temp-buffer-setup-hook 'help-mode-setup) 151(add-hook 'temp-buffer-setup-hook 'help-mode-setup)
152 152
153(defun help-mode-finish () 153(defun help-mode-finish ()
154 (when (eq major-mode 'help-mode) 154 (when (eq major-mode 'help-mode)
155 ;; View mode's read-only status of existing *Help* buffer is lost 155 ;; View mode's read-only status of existing *Help* buffer is lost
156 ;; by with-output-to-temp-buffer. 156 ;; by with-output-to-temp-buffer.
157 (toggle-read-only 1) 157 (toggle-read-only 1)
@@ -790,9 +790,7 @@ Return 0 if there is no such symbol."
790 ((looking-at "\"") (forward-sexp 1)) 790 ((looking-at "\"") (forward-sexp 1))
791 ((looking-at "#<") (search-forward ">" nil 'move)) 791 ((looking-at "#<") (search-forward ">" nil 'move))
792 ((looking-at "\\(\\(\\sw\\|\\s_\\)+\\)") 792 ((looking-at "\\(\\(\\sw\\|\\s_\\)+\\)")
793 (let* ((sym (intern-soft 793 (let* ((sym (intern-soft (match-string 1)))
794 (buffer-substring (match-beginning 1)
795 (match-end 1))))
796 (fn (cond ((fboundp sym) #'describe-function) 794 (fn (cond ((fboundp sym) #'describe-function)
797 ((or (memq sym '(t nil)) 795 ((or (memq sym '(t nil))
798 (keywordp sym)) 796 (keywordp sym))
@@ -804,10 +802,12 @@ Return 0 if there is no such symbol."
804 (t (forward-char 1)))))) 802 (t (forward-char 1))))))
805 (set-syntax-table ost)))) 803 (set-syntax-table ost))))
806 804
807(defun describe-variable (variable) 805(defun describe-variable (variable &optional buffer)
808 "Display the full documentation of VARIABLE (a symbol). 806 "Display the full documentation of VARIABLE (a symbol).
809Returns the documentation as a string, also." 807Returns the documentation as a string, also.
810 (interactive 808If VARIABLE has a buffer-local value in BUFFER (default to the current buffer),
809it is displayed along with the global value."
810 (interactive
811 (let ((v (variable-at-point)) 811 (let ((v (variable-at-point))
812 (enable-recursive-minibuffers t) 812 (enable-recursive-minibuffers t)
813 val) 813 val)
@@ -819,8 +819,11 @@ Returns the documentation as a string, also."
819 (if (symbolp v) (symbol-name v)))) 819 (if (symbolp v) (symbol-name v))))
820 (list (if (equal val "") 820 (list (if (equal val "")
821 v (intern val))))) 821 v (intern val)))))
822 (if (symbolp variable) 822 (unless (bufferp buffer) (setq buffer (current-buffer)))
823 (let (valvoid) 823 (if (not (symbolp variable))
824 (message "You did not specify a variable")
825 (let (valvoid)
826 (with-current-buffer buffer
824 (with-output-to-temp-buffer "*Help*" 827 (with-output-to-temp-buffer "*Help*"
825 (prin1 variable) 828 (prin1 variable)
826 (if (not (boundp variable)) 829 (if (not (boundp variable))
@@ -853,8 +856,7 @@ Returns the documentation as a string, also."
853 (help-xref-on-pp from (point)))))) 856 (help-xref-on-pp from (point))))))
854 (terpri))) 857 (terpri)))
855 (terpri) 858 (terpri)
856 (save-current-buffer 859 (with-current-buffer standard-output
857 (set-buffer standard-output)
858 (if (> (count-lines (point-min) (point-max)) 10) 860 (if (> (count-lines (point-min) (point-max)) 10)
859 (progn 861 (progn
860 ;; Note that setting the syntax table like below 862 ;; Note that setting the syntax table like below
@@ -873,8 +875,9 @@ Returns the documentation as a string, also."
873 (terpri) 875 (terpri)
874 (let ((doc (documentation-property variable 'variable-documentation))) 876 (let ((doc (documentation-property variable 'variable-documentation)))
875 (princ (or doc "not documented as a variable."))) 877 (princ (or doc "not documented as a variable.")))
876 (help-setup-xref (list #'describe-variable variable) (interactive-p)) 878 (help-setup-xref (list #'describe-variable variable (current-buffer))
877 879 (interactive-p))
880
878 ;; Make a link to customize if this variable can be customized. 881 ;; Make a link to customize if this variable can be customized.
879 ;; Note, it is not reliable to test only for a custom-type property 882 ;; Note, it is not reliable to test only for a custom-type property
880 ;; because those are only present after the var's definition 883 ;; because those are only present after the var's definition
@@ -888,7 +891,7 @@ Returns the documentation as a string, also."
888 (princ (concat "You can " customize-label " this variable.")) 891 (princ (concat "You can " customize-label " this variable."))
889 (with-current-buffer "*Help*" 892 (with-current-buffer "*Help*"
890 (save-excursion 893 (save-excursion
891 (re-search-backward 894 (re-search-backward
892 (concat "\\(" customize-label "\\)") nil t) 895 (concat "\\(" customize-label "\\)") nil t)
893 (help-xref-button 1 (lambda (v) 896 (help-xref-button 1 (lambda (v)
894 (if help-xref-stack 897 (if help-xref-stack
@@ -919,8 +922,7 @@ Returns the documentation as a string, also."
919 (save-excursion 922 (save-excursion
920 (set-buffer standard-output) 923 (set-buffer standard-output)
921 ;; Return the text we displayed. 924 ;; Return the text we displayed.
922 (buffer-string)))) 925 (buffer-string)))))))
923 (message "You did not specify a variable")))
924 926
925(defun describe-bindings (&optional prefix buffer) 927(defun describe-bindings (&optional prefix buffer)
926 "Show a list of all defined keys, and their definitions. 928 "Show a list of all defined keys, and their definitions.
@@ -1201,7 +1203,7 @@ that."
1201 (help-xref-button 1203 (help-xref-button
1202 7 #'describe-face sym))))))) 1204 7 #'describe-face sym)))))))
1203 ;; An obvious case of a key substitution: 1205 ;; An obvious case of a key substitution:
1204 (save-excursion 1206 (save-excursion
1205 (while (re-search-forward 1207 (while (re-search-forward
1206 ;; Assume command name is only word characters 1208 ;; Assume command name is only word characters
1207 ;; and dashes to get things like `use M-x foo.'. 1209 ;; and dashes to get things like `use M-x foo.'.
@@ -1217,7 +1219,7 @@ that."
1217 (goto-char (point-min)) 1219 (goto-char (point-min))
1218 ;; Find a header and the column at which the command 1220 ;; Find a header and the column at which the command
1219 ;; name will be found. 1221 ;; name will be found.
1220 (while (re-search-forward "^key +binding\n\\(-+ +\\)-+\n\n" 1222 (while (re-search-forward "^key +binding\n\\(-+ +\\)-+\n\n"
1221 nil t) 1223 nil t)
1222 (let ((col (- (match-end 1) (match-beginning 1)))) 1224 (let ((col (- (match-end 1) (match-beginning 1))))
1223 (while 1225 (while
@@ -1232,7 +1234,7 @@ that."
1232 (looking-at "\\(\\sw\\|-\\)+$")) 1234 (looking-at "\\(\\sw\\|-\\)+$"))
1233 (let ((sym (intern-soft (match-string 0)))) 1235 (let ((sym (intern-soft (match-string 0))))
1234 (if (fboundp sym) 1236 (if (fboundp sym)
1235 (help-xref-button 1237 (help-xref-button
1236 0 #'describe-function sym 1238 0 #'describe-function sym
1237 "mouse-2, RET: describe this function")))) 1239 "mouse-2, RET: describe this function"))))
1238 (zerop (forward-line))))))))) 1240 (zerop (forward-line)))))))))
@@ -1427,23 +1429,6 @@ For the cross-reference format, see `help-make-xrefs'."
1427 1429
1428;;; Automatic resizing of temporary buffers. 1430;;; Automatic resizing of temporary buffers.
1429 1431
1430(defcustom temp-buffer-resize-mode nil
1431 "Non-nil means resize windows displaying temporary buffers.
1432This makes the window the right height for its contents, but never
1433more than `temp-buffer-max-height' nor less than `window-min-height'.
1434This applies to `help', `apropos' and `completion' buffers, and some others.
1435
1436Setting this variable directly does not take effect;
1437use either \\[customize] or the function `temp-buffer-resize-mode'."
1438 :get (lambda (symbol)
1439 (and (memq 'resize-temp-buffer-window temp-buffer-show-hook) t))
1440 :set (lambda (symbol value)
1441 (temp-buffer-resize-mode (if value 1 -1)))
1442 :initialize 'custom-initialize-default
1443 :type 'boolean
1444 :group 'help
1445 :version "20.4")
1446
1447(defcustom temp-buffer-max-height (lambda (buffer) (/ (- (frame-height) 2) 2)) 1432(defcustom temp-buffer-max-height (lambda (buffer) (/ (- (frame-height) 2) 2))
1448 "*Maximum height of a window displaying a temporary buffer. 1433 "*Maximum height of a window displaying a temporary buffer.
1449This is the maximum height (in text lines) which `resize-temp-buffer-window' 1434This is the maximum height (in text lines) which `resize-temp-buffer-window'
@@ -1455,25 +1440,19 @@ positive number."
1455 :group 'help 1440 :group 'help
1456 :version "20.4") 1441 :version "20.4")
1457 1442
1458(defun temp-buffer-resize-mode (arg) 1443(define-minor-mode temp-buffer-resize-mode
1459 "Toggle the mode which that makes windows smaller for temporary buffers. 1444 "Toggle the mode which makes windows smaller for temporary buffers.
1460With prefix argument ARG, turn the resizing of windows displaying temporary 1445With prefix argument ARG, turn the resizing of windows displaying temporary
1461buffers on if ARG is positive or off otherwise. 1446buffers on if ARG is positive or off otherwise.
1462See the documentation of the variable `temp-buffer-resize-mode' for 1447This makes the window the right height for its contents, but never
1463more information." 1448more than `temp-buffer-max-height' nor less than `window-min-height'.
1464 (interactive "P") 1449This applies to `help', `apropos' and `completion' buffers, and some others."
1465 (let ((turn-it-on 1450 nil nil nil :global t :group 'help
1466 (if (null arg) 1451 (if temp-buffer-resize-mode
1467 (not (memq 'resize-temp-buffer-window temp-buffer-show-hook)) 1452 ;; `help-mode-maybe' may add a `back' button and thus increase the
1468 (> (prefix-numeric-value arg) 0)))) 1453 ;; text size, so `resize-temp-buffer-window' must be run *after* it.
1469 (if turn-it-on 1454 (add-hook 'temp-buffer-show-hook 'resize-temp-buffer-window 'append)
1470 (progn 1455 (remove-hook 'temp-buffer-show-hook 'resize-temp-buffer-window))))
1471 ;; `help-mode-maybe' may add a `back' button and thus increase the
1472 ;; text size, so `resize-temp-buffer-window' must be run *after* it.
1473 (add-hook 'temp-buffer-show-hook 'resize-temp-buffer-window 'append)
1474 (setq temp-buffer-resize-mode t))
1475 (remove-hook 'temp-buffer-show-hook 'resize-temp-buffer-window)
1476 (setq temp-buffer-resize-mode nil))))
1477 1456
1478(defun resize-temp-buffer-window () 1457(defun resize-temp-buffer-window ()
1479 "Resize the current window to fit its contents. 1458 "Resize the current window to fit its contents.