;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
;;; Commentary:
(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-reference-face t)
+ ;;
+ ;; CLisp `:' keywords as references.
+ (list (concat "\\<:" sym-char "+\\>") 0 'font-lock-reference-face t))))
+ "Default expressions to highlight in Help mode.")
+
(defun help-mode ()
"Major mode for viewing help text.
Entry to this mode runs the normal hook `help-mode-hook'.
(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 '(help-font-lock-keywords))
+ (view-mode)
(run-hooks 'help-mode-hook))
(defun help-quit ()
(and (symbolp type)
(memq 'down (event-modifiers type))
(read-event)))
- (let ((defn (key-binding key)))
- (if (or (null defn) (integerp defn))
- (message "%s is undefined" (key-description key))
- (message "%s runs the command %s"
- (key-description key)
- (if (symbolp defn) defn (prin1-to-string defn))))))
+ (save-excursion
+ (let ((modifiers (event-modifiers (aref key 0)))
+ window position)
+ ;; For a mouse button event, go to the button it applies to
+ ;; to get the right key bindings. And go to the right place
+ ;; in case the keymap depends on where you clicked.
+ (if (or (memq 'click modifiers) (memq 'down modifiers)
+ (memq 'drag modifiers))
+ (setq window (posn-window (event-start (aref key 0)))
+ position (posn-point (event-start (aref key 0)))))
+ (if (windowp window)
+ (progn
+ (set-buffer (window-buffer window))
+ (goto-char position)))
+ ;; Ok, now look up the key and name the command.
+ (let ((defn (key-binding key)))
+ (if (or (null defn) (integerp defn))
+ (message "%s is undefined" (key-description key))
+ (message (if (windowp window)
+ "%s at that spot runs the command %s"
+ "%s runs the command %s")
+ (key-description key)
+ (if (symbolp defn) defn (prin1-to-string defn))))))))
(defun print-help-return-message (&optional function)
"Display or return message saying how to restore windows after help command.
;; it's no use mentioning a command to scroll, so don't.
(if (or (member (buffer-name standard-output)
special-display-buffer-names)
+ (assoc (buffer-name standard-output)
+ special-display-buffer-names)
(memq t (mapcar '(lambda (elt)
+ (if (consp elt)
+ (setq elt (car elt)))
(string-match elt (buffer-name standard-output)))
special-display-regexps)))
nil
(if (or (member (buffer-name standard-output)
same-window-buffer-names)
+ (assoc (buffer-name standard-output)
+ same-window-buffer-names)
(memq t (mapcar '(lambda (elt)
+ (if (consp elt)
+ (setq elt (car elt)))
(string-match elt (buffer-name standard-output)))
same-window-regexps)))
;; Say how to scroll this window.
(and (symbolp type)
(memq 'down (event-modifiers type))
(read-event)))
- (let ((defn (key-binding key)))
- (if (or (null defn) (integerp defn))
- (message "%s is undefined" (key-description key))
- (with-output-to-temp-buffer "*Help*"
- (prin1 defn)
- (princ ":\n")
- (if (documentation defn)
- (princ (documentation defn))
- (princ "not documented"))
- (save-excursion
- (set-buffer standard-output)
- (help-mode))
- (print-help-return-message)))))
+ (save-excursion
+ (let ((modifiers (event-modifiers (aref key 0)))
+ window position)
+ ;; For a mouse button event, go to the button it applies to
+ ;; to get the right key bindings. And go to the right place
+ ;; in case the keymap depends on where you clicked.
+ (if (or (memq 'click modifiers) (memq 'down modifiers)
+ (memq 'drag modifiers))
+ (setq window (posn-window (event-start (aref key 0)))
+ position (posn-point (event-start (aref key 0)))))
+ (if (windowp window)
+ (progn
+ (set-buffer (window-buffer window))
+ (goto-char position)))
+ (let ((defn (key-binding key)))
+ (if (or (null defn) (integerp defn))
+ (message "%s is undefined" (key-description key))
+ (with-output-to-temp-buffer "*Help*"
+ (princ (key-description key))
+ (if (windowp window)
+ (princ " at that spot"))
+ (princ " runs the command ")
+ (prin1 defn)
+ (princ ":\n")
+ (let ((doc (documentation defn)))
+ (if doc
+ (progn (terpri)
+ (princ doc))
+ (princ "not documented")))
+ (save-excursion
+ (set-buffer standard-output)
+ (help-mode))
+ (print-help-return-message)))))))
(defun describe-mode ()
"Display documentation of current major mode and minor modes.
(interactive)
(with-output-to-temp-buffer "*Help*"
(let ((minor-modes minor-mode-alist)
+ (first t)
(locals (buffer-local-variables)))
(while minor-modes
(let* ((minor-mode (car (car minor-modes)))
0 (match-beginning 0)))))
(while (and indicator (symbolp indicator))
(setq indicator (symbol-value indicator)))
- (princ (format "%s minor mode (indicator%s):\n"
- pretty-minor-mode indicator))
+ (if first
+ (princ "The minor modes are described first,
+followed by the major mode, which is described on the last page.\n\f\n"))
+ (setq first nil)
+ (princ (format "%s minor mode (%s):\n"
+ pretty-minor-mode
+ (if indicator
+ (format "indicator%s" indicator)
+ "no indicator")))
(princ (documentation minor-mode))
- (princ "\n\n"))))
+ (princ "\n\f\n"))))
(setq minor-modes (cdr minor-modes))))
(princ mode-name)
(princ " mode:\n")
(and (symbolp obj) (fboundp obj) obj))))
(error nil))
(condition-case ()
- (save-excursion
- (forward-sexp -1)
- (skip-chars-forward "'")
- (let ((obj (read (current-buffer))))
- (and (symbolp obj) (fboundp obj) obj)))
+ (let ((stab (syntax-table)))
+ (unwind-protect
+ (save-excursion
+ (set-syntax-table emacs-lisp-mode-syntax-table)
+ (or (not (zerop (skip-syntax-backward "_w")))
+ (eq (char-syntax (following-char)) ?w)
+ (eq (char-syntax (following-char)) ?_)
+ (forward-sexp -1))
+ (skip-chars-forward "'")
+ (let ((obj (read (current-buffer))))
+ (and (symbolp obj) (fboundp obj) obj)))
+ (set-syntax-table stab)))
(error nil))))
(defun describe-function-find-file (function)
(prin1 function)
(princ ": ")
(let* ((def (symbol-function function))
+ file-name
(beg (if (commandp def) "an interactive " "a ")))
(princ (cond ((or (stringp def)
(vectorp def))
((eq (car-safe def) 'mocklisp)
"a mocklisp function")
((eq (car-safe def) 'autoload)
+ (setq file-name (nth 1 def))
(format "%s autoloaded Lisp %s"
(if (commandp def) "an interactive" "an")
(if (nth 4 def) "macro" "function")
-;;; Including the file name made this line too long.
-;;; (nth 1 def)
))
(t "")))
- (let ((file (describe-function-find-file function)))
- (if file
- (progn
- (princ " in `")
- ;; We used to add .el to the file name,
- ;; but that's completely wrong when the user used load-file.
- (princ file)
- (princ "'"))))
+ (or file-name
+ (setq file-name (describe-function-find-file function)))
+ (if file-name
+ (progn
+ (princ " in `")
+ ;; We used to add .el to the file name,
+ ;; but that's completely wrong when the user used load-file.
+ (princ file-name)
+ (princ "'")))
(princ ".")
(terpri)
(let ((arglist (cond ((byte-code-function-p def)
(intern (upcase (symbol-name arg)))))
arglist)))
(terpri))))
- (if (documentation function)
- (progn (terpri)
- (princ (documentation function)))
- (princ "not documented"))
- )
+ (let ((doc (documentation function)))
+ (if doc
+ (progn (terpri)
+ (princ doc))
+ (princ "not documented"))))
(print-help-return-message)
(save-excursion
(set-buffer standard-output)
(defun variable-at-point ()
(condition-case ()
- (save-excursion
- (forward-sexp -1)
- (skip-chars-forward "'")
- (let ((obj (read (current-buffer))))
- (and (symbolp obj) (boundp obj) obj)))
+ (let ((stab (syntax-table)))
+ (unwind-protect
+ (save-excursion
+ (set-syntax-table emacs-lisp-mode-syntax-table)
+ (or (not (zerop (skip-syntax-backward "_w")))
+ (eq (char-syntax (following-char)) ?w)
+ (eq (char-syntax (following-char)) ?_)
+ (forward-sexp -1))
+ (skip-chars-forward "'")
+ (let ((obj (read (current-buffer))))
+ (and (symbolp obj) (boundp obj) obj)))
+ (set-syntax-table stab)))
(error nil)))
(defun describe-variable (variable)
(princ "Documentation:")
(terpri)
(let ((doc (documentation-property variable 'variable-documentation)))
- (if doc
- (princ (substitute-command-keys doc))
- (princ "not documented as a variable.")))
+ (princ (or doc "not documented as a variable.")))
(print-help-return-message)
(save-excursion
(set-buffer standard-output)
(message "%s is not on any key" definition)))
nil)
-(defun locate-library (library &optional nosuffix)
- "Show the full path name of Emacs library LIBRARY.
+(defun locate-library (library &optional nosuffix path)
+ "Show the precise file name of Emacs library LIBRARY.
This command searches the directories in `load-path' like `M-x load-library'
to find the file that `M-x load-library RET LIBRARY RET' would load.
Optional second arg NOSUFFIX non-nil means don't add suffixes `.elc' or `.el'
-to the specified name LIBRARY (a la calling `load' instead of `load-library')."
+to the specified name LIBRARY.
+
+If the optional third arg PATH is specified, that list of directories
+is used instead of `load-path'."
(interactive "sLocate library: ")
(catch 'answer
(mapcar
(progn
(message "Library is file %s" try)
(throw 'answer try)))))
- (if nosuffix '("") '(".elc" ".el" ""))))
- load-path)
+ (if nosuffix
+ '("")
+ (let ((basic '(".elc" ".el" ""))
+ (compressed '(".Z" ".gz" "")))
+ ;; If autocompression mode is on,
+ ;; consider all combinations of library suffixes
+ ;; and compression suffixes.
+ (if (rassq 'jka-compr-handler file-name-handler-alist)
+ (apply 'nconc
+ (mapcar '(lambda (compelt)
+ (mapcar '(lambda (baselt)
+ (concat baselt compelt))
+ basic))
+ compressed))
+ basic)))))
+ (or path load-path))
(message "No library %s in search path" library)
nil))