aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2001-10-08 00:19:58 +0000
committerStefan Monnier2001-10-08 00:19:58 +0000
commitb0fbf754224ee5e14ac3a704924c54eea47d0732 (patch)
tree68a5533b115e0cd6b3ec52d568e289dbf339c3a3
parent82345a9abcf6184f744061f96cb378ff955b6ee8 (diff)
downloademacs-b0fbf754224ee5e14ac3a704924c54eea47d0732.tar.gz
emacs-b0fbf754224ee5e14ac3a704924c54eea47d0732.zip
(help-mode): Use define-derived-mode.
(describe-mode): Add optional `buffer' arg. Use it instead of going through help-xref-mode. Avoid doubling the word `minor' when prettifying. (describe-function-1): List the corresponding key bindings. (describe-variable): Say if the var is automatically buffer-local. If the source is `loaddefs.el', look for the real source. (help-xref-mode): Remove.
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/help.el149
2 files changed, 88 insertions, 70 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index db7ed9dd41f..47aedaf8738 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,14 @@
12001-10-07 Stefan Monnier <monnier@cs.yale.edu> 12001-10-07 Stefan Monnier <monnier@cs.yale.edu>
2 2
3 * help.el (help-mode): Use define-derived-mode.
4 (describe-mode): Add optional `buffer' arg.
5 Use it instead of going through help-xref-mode.
6 Avoid doubling the word `minor' when prettifying.
7 (describe-function-1): List the corresponding key bindings.
8 (describe-variable): Say if the var is automatically buffer-local.
9 If the source is `loaddefs.el', look for the real source.
10 (help-xref-mode): Remove.
11
3 * emacs-lisp/bytecomp.el (byte-compile-file): Return success when 12 * emacs-lisp/bytecomp.el (byte-compile-file): Return success when
4 the file says no-byte-compile. 13 the file says no-byte-compile.
5 14
diff --git a/lisp/help.el b/lisp/help.el
index c8189d04783..e27b1c1d700 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -120,10 +120,6 @@ The format is (FUNCTION ARGS...).")
120 120
121(setq-default help-xref-stack nil help-xref-stack-item nil) 121(setq-default help-xref-stack nil help-xref-stack-item nil)
122 122
123(defcustom help-mode-hook nil
124 "Hook run by `help-mode'."
125 :type 'hook
126 :group 'help)
127 123
128 124
129;; Button types used by help 125;; Button types used by help
@@ -174,9 +170,9 @@ The format is (FUNCTION ARGS...).")
174 'action #'help-button-action) 170 'action #'help-button-action)
175 171
176(define-button-type 'help-variable-def 172(define-button-type 'help-variable-def
177 'help-function (lambda (arg) 173 'help-function (lambda (var &optional file)
178 (let ((location 174 (let ((location
179 (find-variable-noselect arg))) 175 (find-variable-noselect var file)))
180 (pop-to-buffer (car location)) 176 (pop-to-buffer (car location))
181 (goto-char (cdr location)))) 177 (goto-char (cdr location))))
182 'help-echo (purecopy"mouse-2, RET: find variable's definition") 178 'help-echo (purecopy"mouse-2, RET: find variable's definition")
@@ -189,22 +185,15 @@ The format is (FUNCTION ARGS...).")
189 (button-get button 'help-args))) 185 (button-get button 'help-args)))
190 186
191 187
192(defun help-mode () 188(define-derived-mode help-mode nil "Help"
193 "Major mode for viewing help text and navigating references in it. 189 "Major mode for viewing help text and navigating references in it.
194Entry to this mode runs the normal hook `help-mode-hook'. 190Entry to this mode runs the normal hook `help-mode-hook'.
195Commands: 191Commands:
196\\{help-mode-map}" 192\\{help-mode-map}"
197 (interactive)
198 (kill-all-local-variables)
199 (use-local-map help-mode-map)
200 (setq mode-name "Help")
201 (setq major-mode 'help-mode)
202 (make-local-variable 'font-lock-defaults)
203 (setq font-lock-defaults nil) ; font-lock would defeat xref 193 (setq font-lock-defaults nil) ; font-lock would defeat xref
204 (view-mode) 194 (view-mode)
205 (make-local-variable 'view-no-disable-on-exit) 195 (make-local-variable 'view-no-disable-on-exit)
206 (setq view-no-disable-on-exit t) 196 (setq view-no-disable-on-exit t))
207 (run-hooks 'help-mode-hook))
208 197
209(defun help-mode-setup () 198(defun help-mode-setup ()
210 (help-mode) 199 (help-mode)
@@ -407,15 +396,15 @@ If FUNCTION is nil, applies `message' to it, thus printing it."
407 (describe-function-1 defn nil (interactive-p)) 396 (describe-function-1 defn nil (interactive-p))
408 (print-help-return-message))))))) 397 (print-help-return-message)))))))
409 398
410(defun describe-mode () 399(defun describe-mode (&optional buffer)
411 "Display documentation of current major mode and minor modes. 400 "Display documentation of current major mode and minor modes.
412The major mode description comes first, followed by the minor modes, 401The major mode description comes first, followed by the minor modes,
413each on a separate page. 402each on a separate page.
414
415For this to work correctly for a minor mode, the mode's indicator variable 403For this to work correctly for a minor mode, the mode's indicator variable
416\(listed in `minor-mode-alist') must also be a function whose documentation 404\(listed in `minor-mode-alist') must also be a function whose documentation
417describes the minor mode." 405describes the minor mode."
418 (interactive) 406 (interactive)
407 (when buffer (set-buffer buffer))
419 (with-output-to-temp-buffer "*Help*" 408 (with-output-to-temp-buffer "*Help*"
420 (when minor-mode-alist 409 (when minor-mode-alist
421 (princ "The major mode is described first. 410 (princ "The major mode is described first.
@@ -423,7 +412,7 @@ For minor modes, see following pages.\n\n"))
423 (princ mode-name) 412 (princ mode-name)
424 (princ " mode:\n") 413 (princ " mode:\n")
425 (princ (documentation major-mode)) 414 (princ (documentation major-mode))
426 (help-setup-xref (list #'help-xref-mode (current-buffer)) (interactive-p)) 415 (help-setup-xref (list #'describe-mode (current-buffer)) (interactive-p))
427 (let ((minor-modes minor-mode-alist)) 416 (let ((minor-modes minor-mode-alist))
428 (while minor-modes 417 (while minor-modes
429 (let* ((minor-mode (car (car minor-modes))) 418 (let* ((minor-mode (car (car minor-modes)))
@@ -435,7 +424,8 @@ For minor modes, see following pages.\n\n"))
435 (symbol-value minor-mode) 424 (symbol-value minor-mode)
436 (fboundp minor-mode)) 425 (fboundp minor-mode))
437 (let ((pretty-minor-mode minor-mode)) 426 (let ((pretty-minor-mode minor-mode))
438 (if (string-match "-mode$" (symbol-name minor-mode)) 427 (if (string-match "\\(-minor\\)?-mode\\'"
428 (symbol-name minor-mode))
439 (setq pretty-minor-mode 429 (setq pretty-minor-mode
440 (capitalize 430 (capitalize
441 (substring (symbol-name minor-mode) 431 (substring (symbol-name minor-mode)
@@ -551,8 +541,7 @@ To record all your input on a file, use `open-dribble-file'."
551 (prin1-to-string key nil)))) 541 (prin1-to-string key nil))))
552 (recent-keys) 542 (recent-keys)
553 " ")) 543 " "))
554 (save-excursion 544 (with-current-buffer standard-output
555 (set-buffer standard-output)
556 (goto-char (point-min)) 545 (goto-char (point-min))
557 (while (progn (move-to-column 50) (not (eobp))) 546 (while (progn (move-to-column 50) (not (eobp)))
558 (search-forward " " nil t) 547 (search-forward " " nil t)
@@ -689,19 +678,19 @@ It can also be nil, if the definition is not associated with any file."
689 obarray 'fboundp t nil nil (symbol-name fn))) 678 obarray 'fboundp t nil nil (symbol-name fn)))
690 (list (if (equal val "") 679 (list (if (equal val "")
691 fn (intern val))))) 680 fn (intern val)))))
692 (if function 681 (if (null function)
693 (with-output-to-temp-buffer "*Help*" 682 (message "You didn't specify a function")
694 (prin1 function) 683 (with-output-to-temp-buffer "*Help*"
695 ;; Use " is " instead of a colon so that 684 (prin1 function)
696 ;; it is easier to get out the function name using forward-sexp. 685 ;; Use " is " instead of a colon so that
697 (princ " is ") 686 ;; it is easier to get out the function name using forward-sexp.
698 (describe-function-1 function nil (interactive-p)) 687 (princ " is ")
699 (print-help-return-message) 688 (describe-function-1 function nil (interactive-p))
689 (print-help-return-message)
700 (save-excursion 690 (save-excursion
701 (set-buffer standard-output) 691 (set-buffer standard-output)
702 ;; Return the text we displayed. 692 ;; Return the text we displayed.
703 (buffer-string))) 693 (buffer-string)))))
704 (message "You didn't specify a function")))
705 694
706(defun describe-function-1 (function parens interactive-p) 695(defun describe-function-1 (function parens interactive-p)
707 (let* ((def (if (symbolp function) 696 (let* ((def (if (symbolp function)
@@ -775,6 +764,15 @@ It can also be nil, if the definition is not associated with any file."
775 (if need-close (princ ")")) 764 (if need-close (princ ")"))
776 (princ ".") 765 (princ ".")
777 (terpri) 766 (terpri)
767 (when (commandp function)
768 (let ((keys (where-is-internal
769 function overriding-local-map nil nil)))
770 (when keys
771 (princ "It is bound to ")
772 ;; FIXME: This list can be very long (f.ex. for self-insert-command).
773 (princ (mapconcat 'key-description keys ", "))
774 (princ ".")
775 (terpri))))
778 ;; Handle symbols aliased to other symbols. 776 ;; Handle symbols aliased to other symbols.
779 (setq def (indirect-function def)) 777 (setq def (indirect-function def))
780 ;; If definition is a macro, find the function inside it. 778 ;; If definition is a macro, find the function inside it.
@@ -919,43 +917,49 @@ it is displayed along with the global value."
919 (goto-char from) 917 (goto-char from)
920 (delete-char -1))))))) 918 (delete-char -1)))))))
921 (terpri) 919 (terpri)
922 (if (local-variable-p variable) 920 (when (local-variable-p variable)
923 (progn 921 (princ (format "Local in buffer %s; " (buffer-name)))
924 (princ (format "Local in buffer %s; " (buffer-name))) 922 (if (not (default-boundp variable))
925 (if (not (default-boundp variable)) 923 (princ "globally void")
926 (princ "globally void") 924 (let ((val (default-value variable)))
927 (let ((val (default-value variable))) 925 (with-current-buffer standard-output
928 (with-current-buffer standard-output 926 (princ "global value is ")
929 (princ "global value is ") 927 (terpri)
930 (terpri) 928 ;; Fixme: pp can take an age if you happen to
931 ;; Fixme: pp can take an age if you happen to 929 ;; ask for a very large expression. We should
932 ;; ask for a very large expression. We should 930 ;; probably print it raw once and check it's a
933 ;; probably print it raw once and check it's a 931 ;; sensible size before prettyprinting. -- fx
934 ;; sensible size before prettyprinting. -- fx 932 (let ((from (point)))
935 (let ((from (point)))
936 (pp val) 933 (pp val)
937 (help-xref-on-pp from (point)) 934 (help-xref-on-pp from (point))
938 (if (< (point) (+ from 20)) 935 (if (< (point) (+ from 20))
939 (save-excursion 936 (save-excursion
940 (goto-char from) 937 (goto-char from)
941 (delete-char -1))))))) 938 (delete-char -1)))))))
942 (terpri))) 939 (terpri))
943 (terpri) 940 (terpri)
944 (with-current-buffer standard-output 941 (with-current-buffer standard-output
945 (if (> (count-lines (point-min) (point-max)) 10) 942 (when (> (count-lines (point-min) (point-max)) 10)
946 (progn 943 ;; Note that setting the syntax table like below
947 ;; Note that setting the syntax table like below 944 ;; makes forward-sexp move over a `'s' at the end
948 ;; makes forward-sexp move over a `'s' at the end 945 ;; of a symbol.
949 ;; of a symbol. 946 (set-syntax-table emacs-lisp-mode-syntax-table)
950 (set-syntax-table emacs-lisp-mode-syntax-table) 947 (goto-char (point-min))
951 (goto-char (point-min)) 948 (if valvoid
952 (if valvoid 949 (forward-line 1)
953 (forward-line 1) 950 (forward-sexp 1)
954 (forward-sexp 1) 951 (delete-region (point) (progn (end-of-line) (point)))
955 (delete-region (point) (progn (end-of-line) (point))) 952 (insert " value is shown below.\n\n")
956 (insert " value is shown below.\n\n") 953 (save-excursion
957 (save-excursion 954 (insert "\n\nValue:"))))
958 (insert "\n\nValue:")))))) 955 ;; Add a note for variables that have been make-var-buffer-local.
956 (when (and (local-variable-if-set-p variable)
957 (or (not (local-variable-p variable))
958 (with-temp-buffer
959 (local-variable-if-set-p variable))))
960 (save-excursion
961 (forward-line -1)
962 (insert "Automatically becomes buffer-local when set in any fashion.\n"))))
959 (princ "Documentation:") 963 (princ "Documentation:")
960 (terpri) 964 (terpri)
961 (let ((doc (documentation-property variable 'variable-documentation))) 965 (let ((doc (documentation-property variable 'variable-documentation)))
@@ -974,7 +978,7 @@ it is displayed along with the global value."
974 (terpri) 978 (terpri)
975 (terpri) 979 (terpri)
976 (princ (concat "You can " customize-label " this variable.")) 980 (princ (concat "You can " customize-label " this variable."))
977 (with-current-buffer "*Help*" 981 (with-current-buffer standard-output
978 (save-excursion 982 (save-excursion
979 (re-search-backward 983 (re-search-backward
980 (concat "\\(" customize-label "\\)") nil t) 984 (concat "\\(" customize-label "\\)") nil t)
@@ -983,14 +987,25 @@ it is displayed along with the global value."
983 ;; change the format of the buffer's initial line in case 987 ;; change the format of the buffer's initial line in case
984 ;; anything expects the current format.) 988 ;; anything expects the current format.)
985 (let ((file-name (symbol-file variable))) 989 (let ((file-name (symbol-file variable)))
990 (when (equal file-name "loaddefs.el")
991 ;; Find the real def site of the preloaded variable.
992 (let ((location (ignore-errors
993 (find-variable-noselect variable file-name))))
994 (when location
995 (with-current-buffer (car location)
996 (goto-char (cdr location))
997 (when (re-search-backward
998 "^;;; Generated autoloads from \\(.*\\)" nil t)
999 (setq file-name (match-string 1)))))))
986 (when file-name 1000 (when file-name
987 (princ "\n\nDefined in `") 1001 (princ "\n\nDefined in `")
988 (princ file-name) 1002 (princ file-name)
989 (princ "'.") 1003 (princ "'.")
990 (with-current-buffer "*Help*" 1004 (with-current-buffer standard-output
991 (save-excursion 1005 (save-excursion
992 (re-search-backward "`\\([^`']+\\)'" nil t) 1006 (re-search-backward "`\\([^`']+\\)'" nil t)
993 (help-xref-button 1 'help-variable-def variable))))) 1007 (help-xref-button 1 'help-variable-def
1008 variable file-name)))))
994 1009
995 (print-help-return-message) 1010 (print-help-return-message)
996 (save-excursion 1011 (save-excursion
@@ -1355,12 +1370,6 @@ help buffer."
1355 " is also a " "variable." "\n\n")) 1370 " is also a " "variable." "\n\n"))
1356 (help-setup-xref (list #'help-xref-interned symbol) nil)))))) 1371 (help-setup-xref (list #'help-xref-interned symbol) nil))))))
1357 1372
1358(defun help-xref-mode (buffer)
1359 "Do a `describe-mode' for the specified BUFFER."
1360 (save-excursion
1361 (set-buffer buffer)
1362 (describe-mode)))
1363
1364 1373
1365;;; Navigation/hyperlinking with xrefs 1374;;; Navigation/hyperlinking with xrefs
1366 1375
@@ -1441,7 +1450,7 @@ buffers on if ARG is positive or off otherwise.
1441This makes the window the right height for its contents, but never 1450This makes the window the right height for its contents, but never
1442more than `temp-buffer-max-height' nor less than `window-min-height'. 1451more than `temp-buffer-max-height' nor less than `window-min-height'.
1443This applies to `help', `apropos' and `completion' buffers, and some others." 1452This applies to `help', `apropos' and `completion' buffers, and some others."
1444 nil nil nil :global t :group 'help 1453 :global t :group 'help
1445 (if temp-buffer-resize-mode 1454 (if temp-buffer-resize-mode
1446 ;; `help-make-xrefs' may add a `back' button and thus increase the 1455 ;; `help-make-xrefs' may add a `back' button and thus increase the
1447 ;; text size, so `resize-temp-buffer-window' must be run *after* it. 1456 ;; text size, so `resize-temp-buffer-window' must be run *after* it.