From: Richard M. Stallman Date: Sun, 5 Apr 1998 19:10:02 +0000 (+0000) Subject: (help-highlight-face): Use underline. X-Git-Tag: emacs-20.3~1703 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=400a1b1f841ff44e197d530f9871cfa5843c428e;p=emacs.git (help-highlight-face): Use underline. (help-mode-maybe): Ensure read-only. (help-xref-button): Obey help-highlight-p. (help-follow): Remove check for args being a list. (help-mode): Doc fix. (help-highlight-p): Put in help group. (help-make-xrefs): Insert button label in scope of inhibit-read-only binding. (help-mode-map, help-make-xrefs): Define TAB, RET correctly. Make hyperlinks for cross-reference info intuited from *Help* buffer. (help-font-lock-keywords): Removed. (help-mode-map): Define keys for navigating hyperlinks. (help-xref-stack, help-xref-stack-item): New permanent-local variables. (help-mode): Set font-lock-defaults to nil. (help-mode-maybe): Invoke help-make-xrefs in Help mode. (help-setup-xref): New function. (describe-key, describe-mode, describe-function, describe-variable): Call it. (view-lossage, describe-bindings): Nullify help-xref-stack, help-xref-stack-item. (help-highlight-p): New option. (help-highlight-face): New variable. (help-back-label, help-xref-symbol-regexp, help-xref-info-regexp): New variables. (help-setup-xref, help-make-xrefs, help-xref-button, help-xref-interned, help-xref-mode, help-follow-mouse, help-xref-go-back, help-go-back, help-follow, help-next-ref): New functions. --- diff --git a/lisp/help.el b/lisp/help.el index b16adbdd8e2..bef91749235 100644 --- a/lisp/help.el +++ b/lisp/help.el @@ -1,6 +1,6 @@ ;;; help.el --- help commands for Emacs -;; Copyright (C) 1985, 1986, 1993, 1994 Free Software Foundation, Inc. +;; Copyright (C) 1985, 1986, 1993, 1994, 1998 Free Software Foundation, Inc. ;; Maintainer: FSF ;; Keywords: help, internal @@ -91,27 +91,47 @@ (define-key help-map "q" 'help-quit) -(defvar help-font-lock-keywords - (eval-when-compile - (let ((name-char "[-+a-zA-Z0-9_*]") (sym-char "[-+a-zA-Z0-9_:*]")) - (list - ;; - ;; The symbol itself. - (list (concat "\\`\\(" name-char "+\\)\\(\\(:\\)\\|\\('\\)\\)") - '(1 (if (match-beginning 3) - font-lock-function-name-face - font-lock-variable-name-face))) - ;; - ;; Words inside `' which tend to be symbol names. - (list (concat "`\\(" sym-char sym-char "+\\)'") - 1 'font-lock-constant-face t) - ;; - ;; CLisp `:' keywords as builtins. - (list (concat "\\<:" sym-char "+\\>") 0 'font-lock-builtin-face t)))) - "Default expressions to highlight in Help mode.") +(define-key help-mode-map [mouse-2] 'help-follow-mouse) +(define-key help-mode-map "\C-c\C-b" 'help-go-back) +(define-key help-mode-map "\C-c\C-c" 'help-follow) +(define-key help-mode-map "\t" 'help-next-ref) +(define-key help-mode-map [backtab] 'help-previous-ref) +;; Documentation only, since we use minor-mode-overriding-map-alist. +(define-key help-mode-map "\r" 'help-follow) + +;; Font-locking is incompatible with the new xref stuff. +;(defvar help-font-lock-keywords +; (eval-when-compile +; (let ((name-char "[-+a-zA-Z0-9_*]") (sym-char "[-+a-zA-Z0-9_:*]")) +; (list +; ;; +; ;; The symbol itself. +; (list (concat "\\`\\(" name-char "+\\)\\(\\(:\\)\\|\\('\\)\\)") +; '(1 (if (match-beginning 3) +; font-lock-function-name-face +; font-lock-variable-name-face))) +; ;; +; ;; Words inside `' which tend to be symbol names. +; (list (concat "`\\(" sym-char sym-char "+\\)'") +; 1 'font-lock-constant-face t) +; ;; +; ;; CLisp `:' keywords as references. +; (list (concat "\\<:" sym-char "+\\>") 0 'font-lock-builtin-face t)))) +; "Default expressions to highlight in Help mode.") + +(defvar help-xref-stack nil + "A stack of ways by which to return to help buffers after following xrefs. +Used by `help-follow' and `help-xref-go-back'.") +(put 'help-xref-stack 'permanent-local t) + +(defvar help-xref-stack-item nil + "An item for `help-follow' in this buffer to push onto `help-xref-stack'.") +(put 'help-xref-stack-item 'permanent-local t) + +(setq-default help-xref-stack nil help-xref-stack-item nil) (defun help-mode () - "Major mode for viewing help text. + "Major mode for viewing help text and navigating references in it. Entry to this mode runs the normal hook `help-mode-hook'. Commands: \\{help-mode-map}" @@ -121,15 +141,22 @@ Commands: (setq mode-name "Help") (setq major-mode 'help-mode) (make-local-variable 'font-lock-defaults) - (setq font-lock-defaults '(help-font-lock-keywords)) + (setq font-lock-defaults nil) ; font-lock would defeat xref (view-mode) (make-local-variable 'view-no-disable-on-exit) (setq view-no-disable-on-exit t) + ;; `help-make-xrefs' would be run here if not invoked from + ;; `help-mode-maybe'. (run-hooks 'help-mode-hook)) (defun help-mode-maybe () (if (eq major-mode 'fundamental-mode) (help-mode)) + (when (eq major-mode 'help-mode) + ;; View mode's read-only status of existing *Help* buffer is lost + ;; by with-output-to-temp-buffer. + (toggle-read-only 1) + (help-make-xrefs (current-buffer))) (setq view-return-to-alist (list (cons (selected-window) help-return-method)))) @@ -320,7 +347,8 @@ If FUNCTION is nil, applies `message' to it, thus printing it." (let ((doc (documentation defn))) (if doc (progn (terpri) - (princ doc)) + (princ doc) + (help-setup-xref (cons #'describe-key key) (interactive-p))) (princ "not documented"))) (print-help-return-message))))))) @@ -364,6 +392,7 @@ followed by the major mode, which is described on the last page.\n\f\n")) (princ mode-name) (princ " mode:\n") (princ (documentation major-mode)) + (help-setup-xref (cons #'help-xref-mode (current-buffer)) (interactive-p)) (print-help-return-message))) ;; So keyboard macro definitions are documented correctly @@ -448,6 +477,8 @@ With numeric argument display information on correspondingly older changes." (while (progn (move-to-column 50) (not (eobp))) (search-forward " " nil t) (insert "\n"))) + (setq help-xref-stack nil + help-xref-stack-item nil) (print-help-return-message))) (defalias 'help 'help-for-help) @@ -616,7 +647,8 @@ C-w Display information on absence of warranty for GNU Emacs." (let ((doc (documentation function))) (if doc (progn (terpri) - (princ doc)) + (princ doc) + (help-setup-xref (cons #'describe-function function) (interactive-p))) (princ "not documented")))) (print-help-return-message) (save-excursion @@ -696,6 +728,7 @@ Returns the documentation as a string, also." (terpri) (let ((doc (documentation-property variable 'variable-documentation))) (princ (or doc "not documented as a variable."))) + (help-setup-xref (cons #'describe-variable variable) (interactive-p)) (print-help-return-message) (save-excursion (set-buffer standard-output) @@ -710,6 +743,8 @@ We put that list in a buffer, and display the buffer. The optional argument PREFIX, if non-nil, should be a key sequence; then we display only bindings that start with that prefix." (interactive "P") + (setq help-xref-stack nil + help-xref-stack-item nil) (describe-bindings-internal nil prefix)) (defun where-is (definition &optional insert) @@ -788,4 +823,255 @@ is used instead of `load-path'." (message "No library %s in search path" library))) result)) + +;;; Grokking cross-reference information in doc strings and +;;; hyperlinking it. + +;; This may have some scope for extension and the same or something +;; similar should be done for widget doc strings, which currently use +;; another mechanism. + +(defcustom help-highlight-p t + "*If non-nil, `help-make-xrefs' highlight cross-references. +Under a window system it highlights them with face defined by +`help-highlight-face'. On a character terminal highlighted +references look like cross-references in info mode." + :group 'help + :version "20.3" + :type 'boolean) + +(defcustom help-highlight-face 'underline + "Face used by `help-make-xrefs' to highlight cross-references. +Must be previously-defined." + :group 'help + :version "20.3" + :type 'symbol) + +(defvar help-back-label "[back]" + "Label to use by `help-make-xrefs' for the go-back reference.") + +(defvar help-xref-symbol-regexp + (concat "\\(\\<\\(\\(variable\\|option\\)\\|" + "\\(function\\|command\\)\\|" + "\\(symbol\\)\\)\\s-+\\)?" + ;; Note starting with word-syntax character: + "`\\(\\sw\\(\\sw\\|\\s_\\)+\\)'") + "Regexp matching doc string references to symbols. + +The words preceding the quoted symbol can be used in doc strings to +distinguish references to variables, functions and symbols.") + +(defvar help-xref-info-regexp + "\\