1 |
;;; help-mode.el --- `help-mode' used by *Help* buffers |
;;; help-mode.el --- `help-mode' used by *Help* buffers |
2 |
|
|
3 |
;; Copyright (C) 1985, 1986, 1993, 1994, 1998, 1999, 2000, 2001 |
;; Copyright (C) 1985, 1986, 1993, 1994, 1998, 1999, 2000, 2001, 2002 |
4 |
;; Free Software Foundation, Inc. |
;; Free Software Foundation, Inc. |
5 |
|
|
6 |
;; Maintainer: FSF |
;; Maintainer: FSF |
31 |
;;; Code: |
;;; Code: |
32 |
|
|
33 |
(require 'button) |
(require 'button) |
34 |
(eval-when-compile (require 'view)) |
(require 'view) |
35 |
|
|
36 |
(defvar help-mode-map (make-sparse-keymap) |
(defvar help-mode-map (make-sparse-keymap) |
37 |
"Keymap for help mode.") |
"Keymap for help mode.") |
147 |
:supertype 'help-xref |
:supertype 'help-xref |
148 |
'help-function (lambda (fun file) |
'help-function (lambda (fun file) |
149 |
(require 'find-func) |
(require 'find-func) |
150 |
;; Don't use find-function-noselect because it follows |
;; Don't use find-function-noselect because it follows |
151 |
;; aliases (which fails for built-in functions). |
;; aliases (which fails for built-in functions). |
152 |
(let* ((location (find-function-search-for-symbol |
(let ((location |
153 |
fun nil file))) |
(if (bufferp file) (cons file fun) |
154 |
|
(find-function-search-for-symbol fun nil file)))) |
155 |
(pop-to-buffer (car location)) |
(pop-to-buffer (car location)) |
156 |
(goto-char (cdr location)))) |
(goto-char (cdr location)))) |
157 |
'help-echo (purecopy "mouse-2, RET: find function's definition")) |
'help-echo (purecopy "mouse-2, RET: find function's definition")) |
177 |
(use-local-map help-mode-map) |
(use-local-map help-mode-map) |
178 |
(setq mode-name "Help") |
(setq mode-name "Help") |
179 |
(setq major-mode 'help-mode) |
(setq major-mode 'help-mode) |
|
(make-local-variable 'font-lock-defaults) |
|
|
(setq font-lock-defaults nil) ; font-lock would defeat xref |
|
180 |
(view-mode) |
(view-mode) |
181 |
(make-local-variable 'view-no-disable-on-exit) |
(make-local-variable 'view-no-disable-on-exit) |
182 |
(setq view-no-disable-on-exit t) |
(setq view-no-disable-on-exit t) |
198 |
(list (cons (selected-window) help-return-method)))) |
(list (cons (selected-window) help-return-method)))) |
199 |
|
|
200 |
|
|
201 |
;;; Grokking cross-reference information in doc strings and |
;; Grokking cross-reference information in doc strings and |
202 |
;;; hyperlinking it. |
;; hyperlinking it. |
203 |
|
|
204 |
;; This may have some scope for extension and the same or something |
;; This may have some scope for extension and the same or something |
205 |
;; similar should be done for widget doc strings, which currently use |
;; similar should be done for widget doc strings, which currently use |
206 |
;; another mechanism. |
;; another mechanism. |
207 |
|
|
|
(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'." |
|
|
: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 'face) |
|
|
|
|
208 |
(defvar help-back-label (purecopy "[back]") |
(defvar help-back-label (purecopy "[back]") |
209 |
"Label to use by `help-make-xrefs' for the go-back reference.") |
"Label to use by `help-make-xrefs' for the go-back reference.") |
210 |
|
|
221 |
The words preceding the quoted symbol can be used in doc strings to |
The words preceding the quoted symbol can be used in doc strings to |
222 |
distinguish references to variables, functions and symbols.") |
distinguish references to variables, functions and symbols.") |
223 |
|
|
224 |
(defconst help-xref-mule-regexp nil |
(defvar help-xref-mule-regexp nil |
225 |
"Regexp matching doc string references to MULE-related keywords. |
"Regexp matching doc string references to MULE-related keywords. |
226 |
|
|
227 |
It is usually nil, and is temporarily bound to an appropriate regexp |
It is usually nil, and is temporarily bound to an appropriate regexp |
246 |
because we want to record the \"previous\" position of point so we can |
because we want to record the \"previous\" position of point so we can |
247 |
restore it properly when going back." |
restore it properly when going back." |
248 |
(with-current-buffer (help-buffer) |
(with-current-buffer (help-buffer) |
249 |
(if interactive-p |
(when help-xref-stack-item |
250 |
;; Why do we want to prevent the user from going back ?? -stef |
(push (cons (point) help-xref-stack-item) help-xref-stack)) |
251 |
(setq help-xref-stack nil) |
(when interactive-p |
252 |
(when help-xref-stack-item |
(let ((tail (nthcdr 10 help-xref-stack))) |
253 |
(push (cons (point) help-xref-stack-item) help-xref-stack))) |
;; Truncate the stack. |
254 |
|
(if tail (setcdr tail nil)))) |
255 |
(setq help-xref-stack-item item))) |
(setq help-xref-stack-item item))) |
256 |
|
|
257 |
(defvar help-xref-following nil |
(defvar help-xref-following nil |
263 |
(current-buffer) |
(current-buffer) |
264 |
(get-buffer-create "*Help*")))) |
(get-buffer-create "*Help*")))) |
265 |
|
|
266 |
|
(defvar help-xref-override-view-map |
267 |
|
(let ((map (make-sparse-keymap))) |
268 |
|
(set-keymap-parent map view-mode-map) |
269 |
|
(define-key map "\r" nil) |
270 |
|
map) |
271 |
|
"Replacement keymap for `view-mode' in help buffers.") |
272 |
|
|
273 |
;;;###autoload |
;;;###autoload |
274 |
(defun help-make-xrefs (&optional buffer) |
(defun help-make-xrefs (&optional buffer) |
275 |
"Parse and hyperlink documentation cross-references in the given BUFFER. |
"Parse and hyperlink documentation cross-references in the given BUFFER. |
276 |
|
|
277 |
Find cross-reference information in a buffer and, if |
Find cross-reference information in a buffer and activate such cross |
278 |
`help-highlight-p' is non-nil, highlight it with face defined by |
references for selection with `help-follow'. Cross-references have |
279 |
`help-highlight-face'; activate such cross references for selection |
the canonical form `...' and the type of reference may be |
280 |
with `help-follow'. Cross-references have the canonical form `...' |
disambiguated by the preceding word(s) used in |
281 |
and the type of reference may be disambiguated by the preceding |
`help-xref-symbol-regexp'. |
|
word(s) used in `help-xref-symbol-regexp'. |
|
282 |
|
|
283 |
If the variable `help-xref-mule-regexp' is non-nil, find also |
If the variable `help-xref-mule-regexp' is non-nil, find also |
284 |
cross-reference information related to multilingual environment |
cross-reference information related to multilingual environment |
415 |
(current-buffer)))) |
(current-buffer)))) |
416 |
;; View mode steals RET from us. |
;; View mode steals RET from us. |
417 |
(set (make-local-variable 'minor-mode-overriding-map-alist) |
(set (make-local-variable 'minor-mode-overriding-map-alist) |
418 |
(list (cons 'view-mode |
(list (cons 'view-mode help-xref-override-view-map))) |
|
(let ((map (make-sparse-keymap))) |
|
|
(set-keymap-parent map view-mode-map) |
|
|
(define-key map "\r" 'help-follow) |
|
|
map)))) |
|
419 |
(set-buffer-modified-p old-modified)))) |
(set-buffer-modified-p old-modified)))) |
420 |
|
|
421 |
;;;###autoload |
;;;###autoload |
443 |
;;;###autoload |
;;;###autoload |
444 |
(defun help-xref-on-pp (from to) |
(defun help-xref-on-pp (from to) |
445 |
"Add xrefs for symbols in `pp's output between FROM and TO." |
"Add xrefs for symbols in `pp's output between FROM and TO." |
446 |
(let ((ost (syntax-table))) |
(if (> (- to from) 5000) nil |
447 |
(unwind-protect |
(with-syntax-table emacs-lisp-mode-syntax-table |
448 |
(save-excursion |
(save-excursion |
449 |
(save-restriction |
(save-restriction |
450 |
(set-syntax-table emacs-lisp-mode-syntax-table) |
(narrow-to-region from to) |
451 |
(narrow-to-region from to) |
(goto-char (point-min)) |
452 |
(goto-char (point-min)) |
(condition-case nil |
453 |
(condition-case nil |
(while (not (eobp)) |
454 |
(while (not (eobp)) |
(cond |
455 |
(cond |
((looking-at "\"") (forward-sexp 1)) |
456 |
((looking-at "\"") (forward-sexp 1)) |
((looking-at "#<") (search-forward ">" nil 'move)) |
457 |
((looking-at "#<") (search-forward ">" nil 'move)) |
((looking-at "\\(\\(\\sw\\|\\s_\\)+\\)") |
458 |
((looking-at "\\(\\(\\sw\\|\\s_\\)+\\)") |
(let* ((sym (intern-soft (match-string 1))) |
459 |
(let* ((sym (intern-soft (match-string 1))) |
(type (cond ((fboundp sym) 'help-function) |
460 |
(type (cond ((fboundp sym) 'help-function) |
((or (memq sym '(t nil)) |
461 |
((or (memq sym '(t nil)) |
(keywordp sym)) |
462 |
(keywordp sym)) |
nil) |
463 |
nil) |
((and sym (boundp sym)) |
464 |
((and sym (boundp sym)) |
'help-variable)))) |
465 |
'help-variable)))) |
(when type (help-xref-button 1 type sym))) |
466 |
(when type (help-xref-button 1 type sym))) |
(goto-char (match-end 1))) |
467 |
(goto-char (match-end 1))) |
(t (forward-char 1)))) |
468 |
(t (forward-char 1)))) |
(error nil))))))) |
|
(error nil)))) |
|
|
(set-syntax-table ost)))) |
|
469 |
|
|
470 |
|
|
471 |
;; Additional functions for (re-)creating types of help buffers. |
;; Additional functions for (re-)creating types of help buffers. |
520 |
(help-setup-xref (list #'help-xref-interned symbol) nil))))))) |
(help-setup-xref (list #'help-xref-interned symbol) nil))))))) |
521 |
|
|
522 |
|
|
523 |
;;; Navigation/hyperlinking with xrefs |
;; Navigation/hyperlinking with xrefs |
524 |
|
|
525 |
(defun help-follow-mouse (click) |
(defun help-follow-mouse (click) |
526 |
"Follow the cross-reference that you CLICK on." |
"Follow the cross-reference that you CLICK on." |