(setq-default help-xref-stack nil help-xref-stack-item nil)
-
+(defcustom help-mode-hook nil
+ "Hook run by `help-mode'."
+ :type 'hook
+ :group 'help)
\f
;; Button types used by help
(button-get button 'help-function)
(button-get button 'help-args)))
-;; Make some button types that all use the same naming conventions
-(dolist (help-type '("function" "variable" "face"
- "coding-system" "input-method" "character-set"))
- (define-button-type (intern (purecopy (concat "help-" help-type)))
- :supertype 'help-xref
- 'help-function (intern (concat "describe-" help-type))
- 'help-echo (purecopy (concat "mouse-2, RET: describe this " help-type))))
+;; These 6 calls to define-button-type were generated in a dolist
+;; loop, but that is bad because it means these button types don't
+;; have an easily found definition.
+
+(define-button-type 'help-function
+ :supertype 'help-xref
+ 'help-function 'describe-function
+ 'help-echo (purecopy "mouse-2, RET: describe this function"))
+
+(define-button-type 'help-variable
+ :supertype 'help-xref
+ 'help-function 'describe-variable
+ 'help-echo (purecopy "mouse-2, RET: describe this variable"))
+
+(define-button-type 'help-face
+ :supertype 'help-xref
+ 'help-function 'describe-face
+ 'help-echo (purecopy "mouse-2, RET: describe this face"))
+
+(define-button-type 'help-coding-system
+ :supertype 'help-xref
+ 'help-function 'describe-coding-system
+ 'help-echo (purecopy "mouse-2, RET: describe this coding system"))
+
+(define-button-type 'help-input-method
+ :supertype 'help-xref
+ 'help-function 'describe-input-method
+ 'help-echo (purecopy "mouse-2, RET: describe this input method"))
+
+(define-button-type 'help-character-set
+ :supertype 'help-xref
+ 'help-function 'describe-character-set
+ 'help-echo (purecopy "mouse-2, RET: describe this character set"))
;; make some more ideosyncratic button types
\f
;;;###autoload
-(define-derived-mode help-mode nil "Help"
+(defun help-mode ()
"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}"
+ (interactive)
+ (kill-all-local-variables)
+ (use-local-map help-mode-map)
+ (setq mode-name "Help")
+ (setq major-mode 'help-mode)
+ (make-local-variable 'font-lock-defaults)
(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))
+ (setq view-no-disable-on-exit t)
+ (run-hooks 'help-mode-hook))
;;;###autoload
(defun help-mode-setup ()
(set-syntax-table emacs-lisp-mode-syntax-table)
(narrow-to-region from to)
(goto-char (point-min))
- (while (not (eobp))
- (cond
- ((looking-at "\"") (forward-sexp 1))
- ((looking-at "#<") (search-forward ">" nil 'move))
- ((looking-at "\\(\\(\\sw\\|\\s_\\)+\\)")
- (let* ((sym (intern-soft (match-string 1)))
- (type (cond ((fboundp sym) 'help-function)
- ((or (memq sym '(t nil))
- (keywordp sym))
- nil)
- ((and sym (boundp sym))
- 'help-variable))))
- (when type (help-xref-button 1 type sym)))
- (goto-char (match-end 1)))
- (t (forward-char 1))))))
+ (condition-case nil
+ (while (not (eobp))
+ (cond
+ ((looking-at "\"") (forward-sexp 1))
+ ((looking-at "#<") (search-forward ">" nil 'move))
+ ((looking-at "\\(\\(\\sw\\|\\s_\\)+\\)")
+ (let* ((sym (intern-soft (match-string 1)))
+ (type (cond ((fboundp sym) 'help-function)
+ ((or (memq sym '(t nil))
+ (keywordp sym))
+ nil)
+ ((and sym (boundp sym))
+ 'help-variable))))
+ (when type (help-xref-button 1 type sym)))
+ (goto-char (match-end 1)))
+ (t (forward-char 1))))
+ (error nil))))
(set-syntax-table ost))))
\f
(sdoc
;; We now have a help buffer on the variable.
;; Insert the function and face text before it.
- (when (or fdoc facedoc)
+ (when (or fdoc facedoc)
(goto-char (point-min))
(let ((inhibit-read-only t))
(when fdoc
(insert fdoc "\n\n")
- (when facedoc
- (insert (make-string 30 ?-) "\n\n" (symbol-name symbol)
+ (when facedoc
+ (insert (make-string 30 ?-) "\n\n" (symbol-name symbol)
" is also a " "face." "\n\n")))
(when facedoc
(insert facedoc "\n\n"))
method (cadr item)
args (cddr item))))
(apply method args)
- ;; FIXME: are we sure we're in the right buffer ?
- (goto-char position)))
+ (with-current-buffer buffer
+ (if (get-buffer-window buffer)
+ (set-window-point (get-buffer-window buffer) position)
+ (goto-char position)))))
(defun help-go-back ()
"Invoke the [back] button (if any) in the Help mode buffer."
(provide 'help-mode)
;;; help-mode.el ends here
-
-