2001-07-16 12:23:00 +00:00
|
|
|
|
;;; apropos.el --- apropos commands for users and programmers
|
1992-05-30 23:54:21 +00:00
|
|
|
|
|
2005-08-06 22:13:43 +00:00
|
|
|
|
;; Copyright (C) 1989, 1994, 1995, 2001, 2002, 2003, 2004,
|
2008-01-07 02:45:14 +00:00
|
|
|
|
;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
1992-07-22 04:22:30 +00:00
|
|
|
|
|
1992-07-16 21:47:34 +00:00
|
|
|
|
;; Author: Joe Wells <jbw@bigbird.bu.edu>
|
1998-12-14 03:14:15 +00:00
|
|
|
|
;; Rewritten: Daniel Pfeiffer <occitan@esperanto.org>
|
1993-03-18 21:29:42 +00:00
|
|
|
|
;; Keywords: help
|
1992-07-16 21:47:34 +00:00
|
|
|
|
|
1991-07-31 02:49:11 +00:00
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
2008-05-06 08:06:51 +00:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1991-07-31 02:49:11 +00:00
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 08:06:51 +00:00
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
1991-07-31 02:49:11 +00:00
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 08:06:51 +00:00
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
1991-07-31 02:49:11 +00:00
|
|
|
|
|
1992-07-16 21:47:34 +00:00
|
|
|
|
;;; Commentary:
|
1991-07-31 02:49:11 +00:00
|
|
|
|
|
|
|
|
|
;; The ideas for this package were derived from the C code in
|
|
|
|
|
;; src/keymap.c and elsewhere. The functions in this file should
|
|
|
|
|
;; always be byte-compiled for speed. Someone should rewrite this in
|
|
|
|
|
;; C (as part of src/keymap.c) for speed.
|
|
|
|
|
|
|
|
|
|
;; The idea for super-apropos is based on the original implementation
|
|
|
|
|
;; by Lynn Slater <lrs@esl.com>.
|
|
|
|
|
|
|
|
|
|
;; History:
|
|
|
|
|
;; Fixed bug, current-local-map can return nil.
|
|
|
|
|
;; Change, doesn't calculate key-bindings unless needed.
|
|
|
|
|
;; Added super-apropos capability, changed print functions.
|
1995-07-07 18:53:58 +00:00
|
|
|
|
;;; Made fast-apropos and super-apropos share code.
|
|
|
|
|
;;; Sped up fast-apropos again.
|
1991-07-31 02:49:11 +00:00
|
|
|
|
;; Added apropos-do-all option.
|
1995-07-07 18:53:58 +00:00
|
|
|
|
;;; Added fast-command-apropos.
|
1991-07-31 02:49:11 +00:00
|
|
|
|
;; Changed doc strings to comments for helping functions.
|
1995-07-07 18:53:58 +00:00
|
|
|
|
;;; Made doc file buffer read-only, buried it.
|
1991-07-31 02:49:11 +00:00
|
|
|
|
;; Only call substitute-command-keys if do-all set.
|
|
|
|
|
|
1995-07-22 15:17:54 +00:00
|
|
|
|
;; Optionally use configurable faces to make the output more legible.
|
|
|
|
|
;; Differentiate between command, function and macro.
|
1995-07-07 18:53:58 +00:00
|
|
|
|
;; Apropos-command (ex command-apropos) does cmd and optionally user var.
|
|
|
|
|
;; Apropos shows all 3 aspects of symbols (fn, var and plist)
|
|
|
|
|
;; Apropos-documentation (ex super-apropos) now finds all it should.
|
|
|
|
|
;; New apropos-value snoops through all values and optionally plists.
|
|
|
|
|
;; Reading DOC file doesn't load nroff.
|
|
|
|
|
;; Added hypertext following of documentation, mouse-2 on variable gives value
|
|
|
|
|
;; from buffer in active window.
|
|
|
|
|
|
1992-07-16 21:47:34 +00:00
|
|
|
|
;;; Code:
|
|
|
|
|
|
2001-10-09 12:09:25 +00:00
|
|
|
|
(require 'button)
|
2004-03-26 15:27:56 +00:00
|
|
|
|
(eval-when-compile (require 'cl))
|
2001-10-09 12:09:25 +00:00
|
|
|
|
|
1997-07-24 07:43:07 +00:00
|
|
|
|
(defgroup apropos nil
|
2005-07-04 01:46:37 +00:00
|
|
|
|
"Apropos commands for users and programmers."
|
1999-08-16 23:04:07 +00:00
|
|
|
|
:group 'help
|
1997-07-24 07:43:07 +00:00
|
|
|
|
:prefix "apropos")
|
|
|
|
|
|
1995-07-07 18:53:58 +00:00
|
|
|
|
;; I see a degradation of maybe 10-20% only.
|
1997-07-24 07:43:07 +00:00
|
|
|
|
(defcustom apropos-do-all nil
|
2008-06-08 03:48:22 +00:00
|
|
|
|
"Whether the apropos commands should do more.
|
1997-07-24 07:43:07 +00:00
|
|
|
|
|
|
|
|
|
Slows them down more or less. Set this non-nil if you have a fast machine."
|
|
|
|
|
:group 'apropos
|
|
|
|
|
:type 'boolean)
|
1995-07-07 18:53:58 +00:00
|
|
|
|
|
|
|
|
|
|
1999-09-17 19:43:09 +00:00
|
|
|
|
(defcustom apropos-symbol-face 'bold
|
2008-06-08 03:48:22 +00:00
|
|
|
|
"Face for symbol name in Apropos output, or nil for none."
|
1997-07-24 07:43:07 +00:00
|
|
|
|
:group 'apropos
|
|
|
|
|
:type 'face)
|
1995-07-22 15:17:54 +00:00
|
|
|
|
|
1999-09-17 19:43:09 +00:00
|
|
|
|
(defcustom apropos-keybinding-face 'underline
|
2008-06-08 03:48:22 +00:00
|
|
|
|
"Face for lists of keybinding in Apropos output, or nil for none."
|
1997-07-24 07:43:07 +00:00
|
|
|
|
:group 'apropos
|
|
|
|
|
:type 'face)
|
1995-07-22 15:17:54 +00:00
|
|
|
|
|
2008-06-08 03:48:22 +00:00
|
|
|
|
(defcustom apropos-label-face '(italic variable-pitch)
|
|
|
|
|
"Face for label (`Command', `Variable' ...) in Apropos output.
|
1999-09-17 19:43:09 +00:00
|
|
|
|
A value of nil means don't use any special font for them, and also
|
|
|
|
|
turns off mouse highlighting."
|
1997-07-24 07:43:07 +00:00
|
|
|
|
:group 'apropos
|
|
|
|
|
:type 'face)
|
1995-07-22 15:17:54 +00:00
|
|
|
|
|
1999-09-17 19:43:09 +00:00
|
|
|
|
(defcustom apropos-property-face 'bold-italic
|
2008-06-08 03:48:22 +00:00
|
|
|
|
"Face for property name in apropos output, or nil for none."
|
1997-07-24 07:43:07 +00:00
|
|
|
|
:group 'apropos
|
|
|
|
|
:type 'face)
|
1995-07-22 15:17:54 +00:00
|
|
|
|
|
2004-12-16 07:16:58 +00:00
|
|
|
|
(defcustom apropos-match-face 'match
|
2008-06-08 03:48:22 +00:00
|
|
|
|
"Face for matching text in Apropos documentation/value, or nil for none.
|
1999-09-17 19:43:09 +00:00
|
|
|
|
This applies when you look for matches in the documentation or variable value
|
2005-11-12 00:10:40 +00:00
|
|
|
|
for the pattern; the part that matches gets displayed in this font."
|
1997-07-24 07:43:07 +00:00
|
|
|
|
:group 'apropos
|
|
|
|
|
:type 'face)
|
1995-07-07 18:53:58 +00:00
|
|
|
|
|
2003-07-14 21:49:02 +00:00
|
|
|
|
(defcustom apropos-sort-by-scores nil
|
2008-06-08 03:48:22 +00:00
|
|
|
|
"Non-nil means sort matches by scores; best match is shown first.
|
2005-11-12 00:10:40 +00:00
|
|
|
|
This applies to all `apropos' commands except `apropos-documentation'.
|
|
|
|
|
If value is `verbose', the computed score is shown for each match."
|
2003-07-12 21:57:50 +00:00
|
|
|
|
:group 'apropos
|
2005-11-12 00:10:40 +00:00
|
|
|
|
:type '(choice (const :tag "off" nil)
|
|
|
|
|
(const :tag "on" t)
|
|
|
|
|
(const :tag "show scores" verbose)))
|
|
|
|
|
|
|
|
|
|
(defcustom apropos-documentation-sort-by-scores t
|
2008-12-03 05:48:14 +00:00
|
|
|
|
"Non-nil means sort matches by scores; best match is shown first.
|
2005-11-12 00:10:40 +00:00
|
|
|
|
This applies to `apropos-documentation' only.
|
|
|
|
|
If value is `verbose', the computed score is shown for each match."
|
|
|
|
|
:group 'apropos
|
|
|
|
|
:type '(choice (const :tag "off" nil)
|
|
|
|
|
(const :tag "on" t)
|
|
|
|
|
(const :tag "show scores" verbose)))
|
1991-07-31 02:49:11 +00:00
|
|
|
|
|
1995-12-19 22:01:53 +00:00
|
|
|
|
(defvar apropos-mode-map
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(let ((map (make-sparse-keymap)))
|
2001-10-07 11:35:09 +00:00
|
|
|
|
(set-keymap-parent map button-buffer-map)
|
|
|
|
|
;; Use `apropos-follow' instead of just using the button
|
|
|
|
|
;; definition of RET, so that users can use it anywhere in an
|
|
|
|
|
;; apropos item, not just on top of a button.
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(define-key map "\C-m" 'apropos-follow)
|
1998-05-02 05:05:55 +00:00
|
|
|
|
(define-key map " " 'scroll-up)
|
|
|
|
|
(define-key map "\177" 'scroll-down)
|
|
|
|
|
(define-key map "q" 'quit-window)
|
1995-07-07 18:53:58 +00:00
|
|
|
|
map)
|
1995-12-19 22:01:53 +00:00
|
|
|
|
"Keymap used in Apropos mode.")
|
1995-04-03 21:38:06 +00:00
|
|
|
|
|
2000-06-07 15:38:54 +00:00
|
|
|
|
(defvar apropos-mode-hook nil
|
2008-06-08 03:48:22 +00:00
|
|
|
|
"Hook run when mode is turned on.")
|
1995-07-07 18:53:58 +00:00
|
|
|
|
|
2005-11-10 03:18:51 +00:00
|
|
|
|
(defvar apropos-pattern nil
|
2005-11-12 00:10:40 +00:00
|
|
|
|
"Apropos pattern as entered by user.")
|
|
|
|
|
|
|
|
|
|
(defvar apropos-pattern-quoted nil
|
2006-10-13 19:32:50 +00:00
|
|
|
|
"Apropos pattern passed through `regexp-quote'.")
|
2005-11-12 00:10:40 +00:00
|
|
|
|
|
|
|
|
|
(defvar apropos-words ()
|
|
|
|
|
"Current list of apropos words extracted from `apropos-pattern'.")
|
1995-07-22 15:17:54 +00:00
|
|
|
|
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(defvar apropos-all-words ()
|
|
|
|
|
"Current list of words and synonyms.")
|
2002-05-23 10:20:12 +00:00
|
|
|
|
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(defvar apropos-regexp nil
|
|
|
|
|
"Regexp used in current apropos run.")
|
|
|
|
|
|
|
|
|
|
(defvar apropos-all-words-regexp nil
|
2002-05-23 10:20:12 +00:00
|
|
|
|
"Regexp matching apropos-all-words.")
|
|
|
|
|
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(defvar apropos-files-scanned ()
|
1996-01-04 23:27:11 +00:00
|
|
|
|
"List of elc files already scanned in current run of `apropos-documentation'.")
|
1995-07-22 15:17:54 +00:00
|
|
|
|
|
|
|
|
|
(defvar apropos-accumulator ()
|
|
|
|
|
"Alist of symbols already found in current apropos run.")
|
1995-07-07 18:53:58 +00:00
|
|
|
|
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(defvar apropos-item ()
|
2000-06-20 09:58:07 +00:00
|
|
|
|
"Current item in or for `apropos-accumulator'.")
|
2001-10-07 11:35:09 +00:00
|
|
|
|
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(defvar apropos-synonyms '(
|
|
|
|
|
("find" "open" "edit")
|
|
|
|
|
("kill" "cut")
|
2006-03-24 13:28:23 +00:00
|
|
|
|
("yank" "paste")
|
|
|
|
|
("region" "selection"))
|
2002-05-23 10:20:12 +00:00
|
|
|
|
"List of synonyms known by apropos.
|
2006-11-06 02:41:31 +00:00
|
|
|
|
Each element is a list of words where the first word is the standard Emacs
|
2002-05-23 10:20:12 +00:00
|
|
|
|
term, and the rest of the words are alternative terms.")
|
|
|
|
|
|
2001-10-07 11:35:09 +00:00
|
|
|
|
|
|
|
|
|
;;; Button types used by apropos
|
|
|
|
|
|
|
|
|
|
(define-button-type 'apropos-symbol
|
|
|
|
|
'face apropos-symbol-face
|
2001-10-08 06:58:32 +00:00
|
|
|
|
'help-echo "mouse-2, RET: Display more help on this symbol"
|
2004-12-17 15:17:22 +00:00
|
|
|
|
'follow-link t
|
2008-07-31 22:15:18 +00:00
|
|
|
|
'action #'apropos-symbol-button-display-help)
|
2001-10-07 11:35:09 +00:00
|
|
|
|
|
|
|
|
|
(defun apropos-symbol-button-display-help (button)
|
|
|
|
|
"Display further help for the `apropos-symbol' button BUTTON."
|
|
|
|
|
(button-activate
|
|
|
|
|
(or (apropos-next-label-button (button-start button))
|
|
|
|
|
(error "There is nothing to follow for `%s'" (button-label button)))))
|
|
|
|
|
|
2001-10-08 06:58:32 +00:00
|
|
|
|
(define-button-type 'apropos-function
|
|
|
|
|
'apropos-label "Function"
|
2008-06-10 02:44:48 +00:00
|
|
|
|
'apropos-short-label "f"
|
2004-12-17 15:17:22 +00:00
|
|
|
|
'help-echo "mouse-2, RET: Display more help on this function"
|
|
|
|
|
'follow-link t
|
2001-10-08 06:58:32 +00:00
|
|
|
|
'action (lambda (button)
|
2004-12-17 15:17:22 +00:00
|
|
|
|
(describe-function (button-get button 'apropos-symbol))))
|
|
|
|
|
|
2001-10-08 06:58:32 +00:00
|
|
|
|
(define-button-type 'apropos-macro
|
|
|
|
|
'apropos-label "Macro"
|
2008-06-10 02:44:48 +00:00
|
|
|
|
'apropos-short-label "m"
|
2004-12-17 15:17:22 +00:00
|
|
|
|
'help-echo "mouse-2, RET: Display more help on this macro"
|
|
|
|
|
'follow-link t
|
2001-10-08 06:58:32 +00:00
|
|
|
|
'action (lambda (button)
|
2004-12-17 15:17:22 +00:00
|
|
|
|
(describe-function (button-get button 'apropos-symbol))))
|
|
|
|
|
|
2001-10-08 06:58:32 +00:00
|
|
|
|
(define-button-type 'apropos-command
|
|
|
|
|
'apropos-label "Command"
|
2008-06-10 02:44:48 +00:00
|
|
|
|
'apropos-short-label "c"
|
2004-12-17 15:17:22 +00:00
|
|
|
|
'help-echo "mouse-2, RET: Display more help on this command"
|
|
|
|
|
'follow-link t
|
2001-10-08 06:58:32 +00:00
|
|
|
|
'action (lambda (button)
|
2004-12-17 15:17:22 +00:00
|
|
|
|
(describe-function (button-get button 'apropos-symbol))))
|
2002-01-05 19:02:27 +00:00
|
|
|
|
|
2001-10-08 06:58:32 +00:00
|
|
|
|
;; We used to use `customize-variable-other-window' instead for a
|
|
|
|
|
;; customizable variable, but that is slow. It is better to show an
|
|
|
|
|
;; ordinary help buffer and let the user click on the customization
|
|
|
|
|
;; button in that buffer, if he wants to.
|
|
|
|
|
;; Likewise for `customize-face-other-window'.
|
|
|
|
|
(define-button-type 'apropos-variable
|
|
|
|
|
'apropos-label "Variable"
|
2008-06-10 02:44:48 +00:00
|
|
|
|
'apropos-short-label "v"
|
2001-10-08 06:58:32 +00:00
|
|
|
|
'help-echo "mouse-2, RET: Display more help on this variable"
|
2004-12-17 15:17:22 +00:00
|
|
|
|
'follow-link t
|
2001-10-08 06:58:32 +00:00
|
|
|
|
'action (lambda (button)
|
|
|
|
|
(describe-variable (button-get button 'apropos-symbol))))
|
|
|
|
|
|
|
|
|
|
(define-button-type 'apropos-face
|
|
|
|
|
'apropos-label "Face"
|
2008-06-10 02:44:48 +00:00
|
|
|
|
'apropos-short-label "F"
|
2001-10-08 06:58:32 +00:00
|
|
|
|
'help-echo "mouse-2, RET: Display more help on this face"
|
2004-12-17 15:17:22 +00:00
|
|
|
|
'follow-link t
|
2001-10-08 06:58:32 +00:00
|
|
|
|
'action (lambda (button)
|
|
|
|
|
(describe-face (button-get button 'apropos-symbol))))
|
|
|
|
|
|
|
|
|
|
(define-button-type 'apropos-group
|
|
|
|
|
'apropos-label "Group"
|
2008-06-10 02:44:48 +00:00
|
|
|
|
'apropos-short-label "g"
|
2001-10-08 06:58:32 +00:00
|
|
|
|
'help-echo "mouse-2, RET: Display more help on this group"
|
2004-12-17 15:17:22 +00:00
|
|
|
|
'follow-link t
|
2001-10-08 06:58:32 +00:00
|
|
|
|
'action (lambda (button)
|
2002-10-20 21:03:54 +00:00
|
|
|
|
(customize-group-other-window
|
2001-10-08 06:58:32 +00:00
|
|
|
|
(button-get button 'apropos-symbol))))
|
|
|
|
|
|
|
|
|
|
(define-button-type 'apropos-widget
|
|
|
|
|
'apropos-label "Widget"
|
2008-06-10 02:44:48 +00:00
|
|
|
|
'apropos-short-label "w"
|
2001-10-08 06:58:32 +00:00
|
|
|
|
'help-echo "mouse-2, RET: Display more help on this widget"
|
2004-12-17 15:17:22 +00:00
|
|
|
|
'follow-link t
|
2001-10-08 06:58:32 +00:00
|
|
|
|
'action (lambda (button)
|
|
|
|
|
(widget-browse-other-window (button-get button 'apropos-symbol))))
|
|
|
|
|
|
|
|
|
|
(define-button-type 'apropos-plist
|
|
|
|
|
'apropos-label "Plist"
|
2008-06-10 02:44:48 +00:00
|
|
|
|
'apropos-short-label "p"
|
2001-10-08 06:58:32 +00:00
|
|
|
|
'help-echo "mouse-2, RET: Display more help on this plist"
|
2004-12-17 15:17:22 +00:00
|
|
|
|
'follow-link t
|
2001-10-08 06:58:32 +00:00
|
|
|
|
'action (lambda (button)
|
|
|
|
|
(apropos-describe-plist (button-get button 'apropos-symbol))))
|
2001-10-07 11:35:09 +00:00
|
|
|
|
|
2008-06-08 04:32:43 +00:00
|
|
|
|
(define-button-type 'apropos-library
|
|
|
|
|
'help-echo "mouse-2, RET: Display more help on this library"
|
|
|
|
|
'follow-link t
|
|
|
|
|
'action (lambda (button)
|
|
|
|
|
(apropos-library (button-get button 'apropos-symbol))))
|
|
|
|
|
|
2001-10-07 11:35:09 +00:00
|
|
|
|
(defun apropos-next-label-button (pos)
|
2001-11-16 18:30:25 +00:00
|
|
|
|
"Return the next apropos label button after POS, or nil if there's none.
|
2001-10-07 11:35:09 +00:00
|
|
|
|
Will also return nil if more than one `apropos-symbol' button is encountered
|
|
|
|
|
before finding a label."
|
2001-10-08 06:13:07 +00:00
|
|
|
|
(let* ((button (next-button pos t))
|
2001-10-07 11:35:09 +00:00
|
|
|
|
(already-hit-symbol nil)
|
2001-10-08 16:37:44 +00:00
|
|
|
|
(label (and button (button-get button 'apropos-label)))
|
|
|
|
|
(type (and button (button-get button 'type))))
|
2001-10-07 11:35:09 +00:00
|
|
|
|
(while (and button
|
2001-10-08 16:37:44 +00:00
|
|
|
|
(not label)
|
|
|
|
|
(or (not (eq type 'apropos-symbol))
|
2001-10-07 11:35:09 +00:00
|
|
|
|
(not already-hit-symbol)))
|
2001-10-08 16:37:44 +00:00
|
|
|
|
(when (eq type 'apropos-symbol)
|
2001-10-07 11:35:09 +00:00
|
|
|
|
(setq already-hit-symbol t))
|
|
|
|
|
(setq button (next-button (button-start button)))
|
|
|
|
|
(when button
|
2001-10-08 16:37:44 +00:00
|
|
|
|
(setq label (button-get button 'apropos-label))
|
|
|
|
|
(setq type (button-get button 'type))))
|
|
|
|
|
(and label button)))
|
2001-10-07 11:35:09 +00:00
|
|
|
|
|
1995-07-22 15:17:54 +00:00
|
|
|
|
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(defun apropos-words-to-regexp (words wild)
|
|
|
|
|
"Make regexp matching any two of the words in WORDS."
|
|
|
|
|
(concat "\\("
|
|
|
|
|
(mapconcat 'identity words "\\|")
|
2003-08-02 20:36:51 +00:00
|
|
|
|
"\\)"
|
2003-02-04 11:26:42 +00:00
|
|
|
|
(if (cdr words)
|
2003-08-02 20:36:51 +00:00
|
|
|
|
(concat wild
|
|
|
|
|
"\\("
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(mapconcat 'identity words "\\|")
|
|
|
|
|
"\\)")
|
|
|
|
|
"")))
|
|
|
|
|
|
2005-11-12 00:10:40 +00:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun apropos-read-pattern (subject)
|
|
|
|
|
"Read an apropos pattern, either a word list or a regexp.
|
|
|
|
|
Returns the user pattern, either a list of words which are matched
|
|
|
|
|
literally, or a string which is used as a regexp to search for.
|
|
|
|
|
|
|
|
|
|
SUBJECT is a string that is included in the prompt to identify what
|
|
|
|
|
kind of objects to search."
|
|
|
|
|
(let ((pattern
|
|
|
|
|
(read-string (concat "Apropos " subject " (word list or regexp): "))))
|
|
|
|
|
(if (string-equal (regexp-quote pattern) pattern)
|
|
|
|
|
;; Split into words
|
|
|
|
|
(split-string pattern "[ \t]+")
|
|
|
|
|
pattern)))
|
|
|
|
|
|
|
|
|
|
(defun apropos-parse-pattern (pattern)
|
|
|
|
|
"Rewrite a list of words to a regexp matching all permutations.
|
2005-11-29 23:52:59 +00:00
|
|
|
|
If PATTERN is a string, that means it is already a regexp.
|
|
|
|
|
This updates variables `apropos-pattern', `apropos-pattern-quoted',
|
|
|
|
|
`apropos-regexp', `apropos-words', and `apropos-all-words-regexp'."
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(setq apropos-words nil
|
|
|
|
|
apropos-all-words nil)
|
|
|
|
|
(if (consp pattern)
|
2002-05-23 10:20:12 +00:00
|
|
|
|
;; We don't actually make a regexp matching all permutations.
|
|
|
|
|
;; Instead, for e.g. "a b c", we make a regexp matching
|
|
|
|
|
;; any combination of two or more words like this:
|
|
|
|
|
;; (a|b|c).*(a|b|c) which may give some false matches,
|
|
|
|
|
;; but as long as it also gives the right ones, that's ok.
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(let ((words pattern))
|
|
|
|
|
(setq apropos-pattern (mapconcat 'identity pattern " ")
|
|
|
|
|
apropos-pattern-quoted (regexp-quote apropos-pattern))
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(dolist (word words)
|
|
|
|
|
(let ((syn apropos-synonyms) (s word) (a word))
|
|
|
|
|
(while syn
|
|
|
|
|
(if (member word (car syn))
|
|
|
|
|
(progn
|
|
|
|
|
(setq a (mapconcat 'identity (car syn) "\\|"))
|
|
|
|
|
(if (member word (cdr (car syn)))
|
|
|
|
|
(setq s a))
|
|
|
|
|
(setq syn nil))
|
|
|
|
|
(setq syn (cdr syn))))
|
|
|
|
|
(setq apropos-words (cons s apropos-words)
|
|
|
|
|
apropos-all-words (cons a apropos-all-words))))
|
2005-11-29 23:52:59 +00:00
|
|
|
|
(setq apropos-all-words-regexp
|
|
|
|
|
(apropos-words-to-regexp apropos-all-words ".+"))
|
|
|
|
|
(setq apropos-regexp
|
|
|
|
|
(apropos-words-to-regexp apropos-words ".*?")))
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(setq apropos-pattern-quoted (regexp-quote pattern)
|
|
|
|
|
apropos-all-words-regexp pattern
|
2005-11-29 23:52:59 +00:00
|
|
|
|
apropos-pattern pattern
|
|
|
|
|
apropos-regexp pattern)))
|
2005-11-12 00:10:40 +00:00
|
|
|
|
|
2002-05-23 10:20:12 +00:00
|
|
|
|
|
|
|
|
|
(defun apropos-calc-scores (str words)
|
|
|
|
|
"Return apropos scores for string STR matching WORDS.
|
|
|
|
|
Value is a list of offsets of the words into the string."
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(let (scores i)
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(if words
|
|
|
|
|
(dolist (word words scores)
|
|
|
|
|
(if (setq i (string-match word str))
|
|
|
|
|
(setq scores (cons i scores))))
|
|
|
|
|
;; Return list of start and end position of regexp
|
2005-11-16 22:11:47 +00:00
|
|
|
|
(and (string-match apropos-pattern str)
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(list (match-beginning 0) (match-end 0))))))
|
2002-05-23 10:20:12 +00:00
|
|
|
|
|
|
|
|
|
(defun apropos-score-str (str)
|
|
|
|
|
"Return apropos score for string STR."
|
|
|
|
|
(if str
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(let* ((l (length str))
|
|
|
|
|
(score (- (/ l 10))))
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(dolist (s (apropos-calc-scores str apropos-all-words) score)
|
2002-05-23 10:24:14 +00:00
|
|
|
|
(setq score (+ score 1000 (/ (* (- l s) 1000) l)))))
|
2002-05-23 10:20:12 +00:00
|
|
|
|
0))
|
|
|
|
|
|
|
|
|
|
(defun apropos-score-doc (doc)
|
|
|
|
|
"Return apropos score for documentation string DOC."
|
2005-02-11 16:09:50 +00:00
|
|
|
|
(let ((l (length doc)))
|
|
|
|
|
(if (> l 0)
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(let ((score 0) i)
|
|
|
|
|
(when (setq i (string-match apropos-pattern-quoted doc))
|
|
|
|
|
(setq score 10000))
|
2005-02-11 16:09:50 +00:00
|
|
|
|
(dolist (s (apropos-calc-scores doc apropos-all-words) score)
|
|
|
|
|
(setq score (+ score 50 (/ (* (- l s) 50) l)))))
|
|
|
|
|
0)))
|
2003-02-04 11:26:42 +00:00
|
|
|
|
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(defun apropos-score-symbol (symbol &optional weight)
|
|
|
|
|
"Return apropos score for SYMBOL."
|
|
|
|
|
(setq symbol (symbol-name symbol))
|
|
|
|
|
(let ((score 0)
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(l (length symbol)))
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(dolist (s (apropos-calc-scores symbol apropos-words) (* score (or weight 3)))
|
|
|
|
|
(setq score (+ score (- 60 l) (/ (* (- l s) 60) l))))))
|
|
|
|
|
|
2002-05-23 20:21:30 +00:00
|
|
|
|
(defun apropos-true-hit (str words)
|
|
|
|
|
"Return t if STR is a genuine hit.
|
|
|
|
|
This may fail if only one of the keywords is matched more than once.
|
|
|
|
|
This requires that at least 2 keywords (unless only one was given)."
|
|
|
|
|
(or (not str)
|
|
|
|
|
(not words)
|
|
|
|
|
(not (cdr words))
|
|
|
|
|
(> (length (apropos-calc-scores str words)) 1)))
|
|
|
|
|
|
|
|
|
|
(defun apropos-false-hit-symbol (symbol)
|
|
|
|
|
"Return t if SYMBOL is not really matched by the current keywords."
|
|
|
|
|
(not (apropos-true-hit (symbol-name symbol) apropos-words)))
|
|
|
|
|
|
|
|
|
|
(defun apropos-false-hit-str (str)
|
|
|
|
|
"Return t if STR is not really matched by the current keywords."
|
|
|
|
|
(not (apropos-true-hit str apropos-words)))
|
|
|
|
|
|
|
|
|
|
(defun apropos-true-hit-doc (doc)
|
|
|
|
|
"Return t if DOC is really matched by the current keywords."
|
|
|
|
|
(apropos-true-hit doc apropos-all-words))
|
|
|
|
|
|
2000-10-04 23:30:51 +00:00
|
|
|
|
(define-derived-mode apropos-mode fundamental-mode "Apropos"
|
1995-12-19 22:01:53 +00:00
|
|
|
|
"Major mode for following hyperlinks in output of apropos commands.
|
|
|
|
|
|
2000-10-04 23:30:51 +00:00
|
|
|
|
\\{apropos-mode-map}")
|
1995-12-19 22:01:53 +00:00
|
|
|
|
|
2008-06-10 02:44:48 +00:00
|
|
|
|
(defvar apropos-multi-type t
|
|
|
|
|
"If non-nil, this apropos query concerns multiple types.
|
|
|
|
|
This is used to decide whether to print the result's type or not.")
|
|
|
|
|
|
1997-11-24 04:55:48 +00:00
|
|
|
|
;;;###autoload
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(defun apropos-variable (pattern &optional do-all)
|
|
|
|
|
"Show user variables that match PATTERN.
|
|
|
|
|
PATTERN can be a word, a list of words (separated by spaces),
|
|
|
|
|
or a regexp (using some regexp special characters). If it is a word,
|
|
|
|
|
search for matches for that word as a substring. If it is a list of words,
|
|
|
|
|
search for matches for any two (or more) of those words.
|
|
|
|
|
|
|
|
|
|
With \\[universal-argument] prefix, or if `apropos-do-all' is non-nil, also show
|
1998-05-24 23:11:14 +00:00
|
|
|
|
normal variables."
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(interactive (list (apropos-read-pattern
|
|
|
|
|
(if (or current-prefix-arg apropos-do-all)
|
|
|
|
|
"variable" "user option"))
|
1998-05-24 23:11:14 +00:00
|
|
|
|
current-prefix-arg))
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(apropos-command pattern nil
|
1998-06-01 21:46:44 +00:00
|
|
|
|
(if (or do-all apropos-do-all)
|
1998-05-24 23:11:14 +00:00
|
|
|
|
#'(lambda (symbol)
|
|
|
|
|
(and (boundp symbol)
|
|
|
|
|
(get symbol 'variable-documentation)))
|
|
|
|
|
'user-variable-p)))
|
1995-12-19 22:01:53 +00:00
|
|
|
|
|
1995-07-22 15:17:54 +00:00
|
|
|
|
;; For auld lang syne:
|
|
|
|
|
;;;###autoload
|
2002-08-24 14:26:06 +00:00
|
|
|
|
(defalias 'command-apropos 'apropos-command)
|
1991-07-31 02:49:11 +00:00
|
|
|
|
;;;###autoload
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(defun apropos-command (pattern &optional do-all var-predicate)
|
|
|
|
|
"Show commands (interactively callable functions) that match PATTERN.
|
|
|
|
|
PATTERN can be a word, a list of words (separated by spaces),
|
2005-11-10 03:18:51 +00:00
|
|
|
|
or a regexp (using some regexp special characters). If it is a word,
|
|
|
|
|
search for matches for that word as a substring. If it is a list of words,
|
|
|
|
|
search for matches for any two (or more) of those words.
|
|
|
|
|
|
2005-11-12 00:10:40 +00:00
|
|
|
|
With \\[universal-argument] prefix, or if `apropos-do-all' is non-nil, also show
|
1998-05-24 23:19:37 +00:00
|
|
|
|
noninteractive functions.
|
1998-05-24 23:11:14 +00:00
|
|
|
|
|
1998-05-24 23:19:37 +00:00
|
|
|
|
If VAR-PREDICATE is non-nil, show only variables, and only those that
|
2005-11-12 00:10:40 +00:00
|
|
|
|
satisfy the predicate VAR-PREDICATE.
|
|
|
|
|
|
|
|
|
|
When called from a Lisp program, a string PATTERN is used as a regexp,
|
|
|
|
|
while a list of strings is used as a word list."
|
|
|
|
|
(interactive (list (apropos-read-pattern
|
|
|
|
|
(if (or current-prefix-arg apropos-do-all)
|
|
|
|
|
"command or function" "command"))
|
1995-07-22 15:17:54 +00:00
|
|
|
|
current-prefix-arg))
|
2005-11-29 23:52:59 +00:00
|
|
|
|
(apropos-parse-pattern pattern)
|
2007-12-06 03:59:38 +00:00
|
|
|
|
(let ((message
|
1995-12-19 22:01:53 +00:00
|
|
|
|
(let ((standard-output (get-buffer-create "*Apropos*")))
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(print-help-return-message 'identity))))
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(or do-all (setq do-all apropos-do-all))
|
|
|
|
|
(setq apropos-accumulator
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(apropos-internal apropos-regexp
|
1998-06-01 21:46:44 +00:00
|
|
|
|
(or var-predicate
|
2008-03-26 03:31:42 +00:00
|
|
|
|
;; We used to use `functionp' here, but this
|
|
|
|
|
;; rules out macros. `fboundp' rules in
|
|
|
|
|
;; keymaps, but it seems harmless.
|
|
|
|
|
(if do-all 'fboundp 'commandp))))
|
1997-12-21 01:46:14 +00:00
|
|
|
|
(let ((tem apropos-accumulator))
|
|
|
|
|
(while tem
|
2002-05-23 20:21:30 +00:00
|
|
|
|
(if (or (get (car tem) 'apropos-inhibit)
|
|
|
|
|
(apropos-false-hit-symbol (car tem)))
|
1997-12-21 01:46:14 +00:00
|
|
|
|
(setq apropos-accumulator (delq (car tem) apropos-accumulator)))
|
|
|
|
|
(setq tem (cdr tem))))
|
1998-06-20 22:27:06 +00:00
|
|
|
|
(let ((p apropos-accumulator)
|
2002-05-23 10:20:12 +00:00
|
|
|
|
doc symbol score)
|
1998-06-20 22:27:06 +00:00
|
|
|
|
(while p
|
|
|
|
|
(setcar p (list
|
|
|
|
|
(setq symbol (car p))
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(setq score (apropos-score-symbol symbol))
|
1998-06-20 22:27:06 +00:00
|
|
|
|
(unless var-predicate
|
2008-03-26 03:31:42 +00:00
|
|
|
|
(if (fboundp symbol)
|
2008-08-30 20:14:11 +00:00
|
|
|
|
(if (setq doc (condition-case nil
|
|
|
|
|
(documentation symbol t)
|
|
|
|
|
(error 'error)))
|
|
|
|
|
;; Eg alias to undefined function.
|
|
|
|
|
(if (eq doc 'error)
|
|
|
|
|
"(documentation error)"
|
2003-02-04 11:26:42 +00:00
|
|
|
|
(setq score (+ score (apropos-score-doc doc)))
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(substring doc 0 (string-match "\n" doc)))
|
1998-06-20 22:27:06 +00:00
|
|
|
|
"(not documented)")))
|
|
|
|
|
(and var-predicate
|
|
|
|
|
(funcall var-predicate symbol)
|
|
|
|
|
(if (setq doc (documentation-property
|
|
|
|
|
symbol 'variable-documentation t))
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(progn
|
|
|
|
|
(setq score (+ score (apropos-score-doc doc)))
|
|
|
|
|
(substring doc 0
|
|
|
|
|
(string-match "\n" doc)))))))
|
|
|
|
|
(setcar (cdr (car p)) score)
|
1998-06-20 22:27:06 +00:00
|
|
|
|
(setq p (cdr p))))
|
2008-06-10 02:44:48 +00:00
|
|
|
|
(and (let ((apropos-multi-type do-all))
|
|
|
|
|
(apropos-print t nil nil t))
|
1998-06-20 22:27:06 +00:00
|
|
|
|
message
|
2005-09-18 12:25:02 +00:00
|
|
|
|
(message "%s" message))))
|
1995-07-07 18:53:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
2003-01-13 08:07:18 +00:00
|
|
|
|
(defun apropos-documentation-property (symbol property raw)
|
|
|
|
|
"Like (documentation-property SYMBOL PROPERTY RAW) but handle errors."
|
|
|
|
|
(condition-case ()
|
|
|
|
|
(let ((doc (documentation-property symbol property raw)))
|
|
|
|
|
(if doc (substring doc 0 (string-match "\n" doc))
|
|
|
|
|
"(not documented)"))
|
|
|
|
|
(error "(error retrieving documentation)")))
|
|
|
|
|
|
2003-01-14 20:47:21 +00:00
|
|
|
|
|
|
|
|
|
;;;###autoload
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(defun apropos (pattern &optional do-all)
|
2005-12-26 21:21:04 +00:00
|
|
|
|
"Show all meaningful Lisp symbols whose names match PATTERN.
|
|
|
|
|
Symbols are shown if they are defined as functions, variables, or
|
|
|
|
|
faces, or if they have nonempty property lists.
|
|
|
|
|
|
2005-11-12 00:10:40 +00:00
|
|
|
|
PATTERN can be a word, a list of words (separated by spaces),
|
2005-11-10 03:18:51 +00:00
|
|
|
|
or a regexp (using some regexp special characters). If it is a word,
|
|
|
|
|
search for matches for that word as a substring. If it is a list of words,
|
|
|
|
|
search for matches for any two (or more) of those words.
|
|
|
|
|
|
2005-12-26 21:22:55 +00:00
|
|
|
|
With \\[universal-argument] prefix, or if `apropos-do-all' is non-nil,
|
|
|
|
|
consider all symbols (if they match PATTERN).
|
|
|
|
|
|
|
|
|
|
Returns list of symbols and documentation found."
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(interactive (list (apropos-read-pattern "symbol")
|
|
|
|
|
current-prefix-arg))
|
2005-11-29 23:52:59 +00:00
|
|
|
|
(apropos-parse-pattern pattern)
|
2004-03-26 15:27:56 +00:00
|
|
|
|
(apropos-symbols-internal
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(apropos-internal apropos-regexp
|
2005-12-26 21:22:55 +00:00
|
|
|
|
(and (not do-all)
|
|
|
|
|
(not apropos-do-all)
|
|
|
|
|
(lambda (symbol)
|
|
|
|
|
(or (fboundp symbol)
|
|
|
|
|
(boundp symbol)
|
|
|
|
|
(facep symbol)
|
|
|
|
|
(symbol-plist symbol)))))
|
2004-03-26 15:27:56 +00:00
|
|
|
|
(or do-all apropos-do-all)))
|
|
|
|
|
|
2008-06-08 04:32:43 +00:00
|
|
|
|
(defun apropos-library-button (sym)
|
|
|
|
|
(if (null sym)
|
|
|
|
|
"<nothing>"
|
|
|
|
|
(let ((name (copy-sequence (symbol-name sym))))
|
|
|
|
|
(make-text-button name nil
|
|
|
|
|
'type 'apropos-library
|
|
|
|
|
'face apropos-symbol-face
|
|
|
|
|
'apropos-symbol name)
|
|
|
|
|
name)))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun apropos-library (file)
|
|
|
|
|
"List the variables and functions defined by library FILE.
|
|
|
|
|
FILE should be one of the libraries currently loaded and should
|
|
|
|
|
thus be found in `load-history'."
|
|
|
|
|
(interactive
|
|
|
|
|
(let ((libs
|
|
|
|
|
(nconc (delq nil
|
|
|
|
|
(mapcar
|
|
|
|
|
(lambda (l)
|
|
|
|
|
(setq l (file-name-nondirectory l))
|
|
|
|
|
(while
|
|
|
|
|
(not (equal (setq l (file-name-sans-extension l))
|
|
|
|
|
l)))
|
|
|
|
|
l)
|
|
|
|
|
(mapcar 'car load-history)))
|
|
|
|
|
(mapcar 'car load-history))))
|
|
|
|
|
(list (completing-read "Describe library: " libs nil t))))
|
|
|
|
|
(let ((symbols nil)
|
|
|
|
|
;; (autoloads nil)
|
|
|
|
|
(provides nil)
|
|
|
|
|
(requires nil)
|
|
|
|
|
(lh-entry (assoc file load-history)))
|
|
|
|
|
(unless lh-entry
|
|
|
|
|
;; `file' may be the "shortname".
|
|
|
|
|
(let ((lh load-history)
|
|
|
|
|
(re (concat "\\(?:\\`\\|[\\/]\\)" (regexp-quote file)
|
|
|
|
|
"\\(\\.\\|\\'\\)")))
|
|
|
|
|
(while (and lh (null lh-entry))
|
|
|
|
|
(if (string-match re (caar lh))
|
|
|
|
|
(setq lh-entry (car lh))
|
|
|
|
|
(setq lh (cdr lh)))))
|
|
|
|
|
(unless lh-entry (error "Unknown library `%s'" file)))
|
|
|
|
|
(dolist (x (cdr lh-entry))
|
|
|
|
|
(case (car-safe x)
|
|
|
|
|
;; (autoload (push (cdr x) autoloads))
|
|
|
|
|
(require (push (cdr x) requires))
|
|
|
|
|
(provide (push (cdr x) provides))
|
|
|
|
|
(t (push (or (cdr-safe x) x) symbols))))
|
|
|
|
|
(let ((apropos-pattern "")) ;Dummy binding for apropos-symbols-internal.
|
|
|
|
|
(apropos-symbols-internal
|
|
|
|
|
symbols apropos-do-all
|
|
|
|
|
(concat
|
|
|
|
|
(format "Library `%s' provides: %s\nand requires: %s"
|
|
|
|
|
file
|
|
|
|
|
(mapconcat 'apropos-library-button
|
|
|
|
|
(or provides '(nil)) " and ")
|
|
|
|
|
(mapconcat 'apropos-library-button
|
|
|
|
|
(or requires '(nil)) " and ")))))))
|
|
|
|
|
|
2004-03-26 15:27:56 +00:00
|
|
|
|
(defun apropos-symbols-internal (symbols keys &optional text)
|
|
|
|
|
;; Filter out entries that are marked as apropos-inhibit.
|
|
|
|
|
(let ((all nil))
|
|
|
|
|
(dolist (symbol symbols)
|
|
|
|
|
(unless (get symbol 'apropos-inhibit)
|
|
|
|
|
(push symbol all)))
|
|
|
|
|
(setq symbols all))
|
|
|
|
|
(let ((apropos-accumulator
|
|
|
|
|
(mapcar
|
|
|
|
|
(lambda (symbol)
|
|
|
|
|
(let (doc properties)
|
|
|
|
|
(list
|
|
|
|
|
symbol
|
|
|
|
|
(apropos-score-symbol symbol)
|
|
|
|
|
(when (fboundp symbol)
|
|
|
|
|
(if (setq doc (condition-case nil
|
|
|
|
|
(documentation symbol t)
|
|
|
|
|
(void-function
|
|
|
|
|
"(alias for undefined function)")
|
|
|
|
|
(error
|
|
|
|
|
"(can't retrieve function documentation)")))
|
|
|
|
|
(substring doc 0 (string-match "\n" doc))
|
|
|
|
|
"(not documented)"))
|
|
|
|
|
(when (boundp symbol)
|
|
|
|
|
(apropos-documentation-property
|
2003-01-13 08:07:18 +00:00
|
|
|
|
symbol 'variable-documentation t))
|
1998-06-20 22:27:06 +00:00
|
|
|
|
(when (setq properties (symbol-plist symbol))
|
|
|
|
|
(setq doc (list (car properties)))
|
|
|
|
|
(while (setq properties (cdr (cdr properties)))
|
|
|
|
|
(setq doc (cons (car properties) doc)))
|
|
|
|
|
(mapconcat #'symbol-name (nreverse doc) " "))
|
|
|
|
|
(when (get symbol 'widget-type)
|
2003-01-13 08:07:18 +00:00
|
|
|
|
(apropos-documentation-property
|
|
|
|
|
symbol 'widget-documentation t))
|
2004-03-26 15:27:56 +00:00
|
|
|
|
(when (facep symbol)
|
|
|
|
|
(apropos-documentation-property
|
|
|
|
|
symbol 'face-documentation t))
|
|
|
|
|
(when (get symbol 'custom-group)
|
2003-01-13 08:07:18 +00:00
|
|
|
|
(apropos-documentation-property
|
2004-03-26 15:27:56 +00:00
|
|
|
|
symbol 'group-documentation t)))))
|
|
|
|
|
symbols)))
|
|
|
|
|
(apropos-print keys nil text)))
|
1995-07-07 18:53:58 +00:00
|
|
|
|
|
|
|
|
|
|
1991-07-31 02:49:11 +00:00
|
|
|
|
;;;###autoload
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(defun apropos-value (pattern &optional do-all)
|
2005-12-26 21:21:04 +00:00
|
|
|
|
"Show all symbols whose value's printed representation matches PATTERN.
|
2005-11-12 00:10:40 +00:00
|
|
|
|
PATTERN can be a word, a list of words (separated by spaces),
|
2005-11-10 03:18:51 +00:00
|
|
|
|
or a regexp (using some regexp special characters). If it is a word,
|
|
|
|
|
search for matches for that word as a substring. If it is a list of words,
|
|
|
|
|
search for matches for any two (or more) of those words.
|
|
|
|
|
|
2005-11-12 00:10:40 +00:00
|
|
|
|
With \\[universal-argument] prefix, or if `apropos-do-all' is non-nil, also looks
|
1995-07-07 18:53:58 +00:00
|
|
|
|
at the function and at the names and values of properties.
|
1995-07-22 15:17:54 +00:00
|
|
|
|
Returns list of symbols and values found."
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(interactive (list (apropos-read-pattern "value")
|
|
|
|
|
current-prefix-arg))
|
2005-11-29 23:52:59 +00:00
|
|
|
|
(apropos-parse-pattern pattern)
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(or do-all (setq do-all apropos-do-all))
|
|
|
|
|
(setq apropos-accumulator ())
|
|
|
|
|
(let (f v p)
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(mapatoms
|
|
|
|
|
(lambda (symbol)
|
|
|
|
|
(setq f nil v nil p nil)
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(or (memq symbol '(apropos-regexp
|
|
|
|
|
apropos-pattern apropos-all-words-regexp
|
2002-05-23 10:20:12 +00:00
|
|
|
|
apropos-words apropos-all-words
|
|
|
|
|
do-all apropos-accumulator
|
|
|
|
|
symbol f v p))
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(setq v (apropos-value-internal 'boundp symbol 'symbol-value)))
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(if do-all
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(setq f (apropos-value-internal 'fboundp symbol 'symbol-function)
|
|
|
|
|
p (apropos-format-plist symbol "\n " t)))
|
2002-05-23 20:21:30 +00:00
|
|
|
|
(if (apropos-false-hit-str v)
|
|
|
|
|
(setq v nil))
|
|
|
|
|
(if (apropos-false-hit-str f)
|
|
|
|
|
(setq f nil))
|
|
|
|
|
(if (apropos-false-hit-str p)
|
|
|
|
|
(setq p nil))
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(if (or f v p)
|
2003-02-04 11:26:42 +00:00
|
|
|
|
(setq apropos-accumulator (cons (list symbol
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(+ (apropos-score-str f)
|
|
|
|
|
(apropos-score-str v)
|
|
|
|
|
(apropos-score-str p))
|
|
|
|
|
f v p)
|
1995-07-22 15:17:54 +00:00
|
|
|
|
apropos-accumulator))))))
|
2008-06-10 02:44:48 +00:00
|
|
|
|
(let ((apropos-multi-type do-all))
|
|
|
|
|
(apropos-print nil "\n----------------\n")))
|
1995-07-07 18:53:58 +00:00
|
|
|
|
|
|
|
|
|
|
1995-07-22 15:17:54 +00:00
|
|
|
|
;;;###autoload
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(defun apropos-documentation (pattern &optional do-all)
|
2005-12-26 21:21:04 +00:00
|
|
|
|
"Show symbols whose documentation contains matches for PATTERN.
|
2005-11-12 00:10:40 +00:00
|
|
|
|
PATTERN can be a word, a list of words (separated by spaces),
|
2005-11-10 03:18:51 +00:00
|
|
|
|
or a regexp (using some regexp special characters). If it is a word,
|
|
|
|
|
search for matches for that word as a substring. If it is a list of words,
|
|
|
|
|
search for matches for any two (or more) of those words.
|
|
|
|
|
|
2005-11-12 00:10:40 +00:00
|
|
|
|
With \\[universal-argument] prefix, or if `apropos-do-all' is non-nil, also use
|
1995-07-22 15:17:54 +00:00
|
|
|
|
documentation that is not stored in the documentation file and show key
|
|
|
|
|
bindings.
|
|
|
|
|
Returns list of symbols and documentation found."
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(interactive (list (apropos-read-pattern "documentation")
|
|
|
|
|
current-prefix-arg))
|
2005-11-29 23:52:59 +00:00
|
|
|
|
(apropos-parse-pattern pattern)
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(or do-all (setq do-all apropos-do-all))
|
|
|
|
|
(setq apropos-accumulator () apropos-files-scanned ())
|
|
|
|
|
(let ((standard-input (get-buffer-create " apropos-temp"))
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(apropos-sort-by-scores apropos-documentation-sort-by-scores)
|
2002-05-23 10:20:12 +00:00
|
|
|
|
f v sf sv)
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(unwind-protect
|
|
|
|
|
(save-excursion
|
|
|
|
|
(set-buffer standard-input)
|
|
|
|
|
(apropos-documentation-check-doc-file)
|
|
|
|
|
(if do-all
|
|
|
|
|
(mapatoms
|
|
|
|
|
(lambda (symbol)
|
|
|
|
|
(setq f (apropos-safe-documentation symbol)
|
1995-12-19 22:01:53 +00:00
|
|
|
|
v (get symbol 'variable-documentation))
|
|
|
|
|
(if (integerp v) (setq v))
|
|
|
|
|
(setq f (apropos-documentation-internal f)
|
|
|
|
|
v (apropos-documentation-internal v))
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(setq sf (apropos-score-doc f)
|
|
|
|
|
sv (apropos-score-doc v))
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(if (or f v)
|
|
|
|
|
(if (setq apropos-item
|
|
|
|
|
(cdr (assq symbol apropos-accumulator)))
|
|
|
|
|
(progn
|
|
|
|
|
(if f
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(progn
|
|
|
|
|
(setcar (nthcdr 1 apropos-item) f)
|
|
|
|
|
(setcar apropos-item (+ (car apropos-item) sf))))
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(if v
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(progn
|
|
|
|
|
(setcar (nthcdr 2 apropos-item) v)
|
|
|
|
|
(setcar apropos-item (+ (car apropos-item) sv)))))
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(setq apropos-accumulator
|
2003-02-04 11:26:42 +00:00
|
|
|
|
(cons (list symbol
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(+ (apropos-score-symbol symbol 2) sf sv)
|
|
|
|
|
f v)
|
1995-07-22 15:17:54 +00:00
|
|
|
|
apropos-accumulator)))))))
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(apropos-print nil "\n----------------\n" nil t))
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(kill-buffer standard-input))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun apropos-value-internal (predicate symbol function)
|
|
|
|
|
(if (funcall predicate symbol)
|
|
|
|
|
(progn
|
|
|
|
|
(setq symbol (prin1-to-string (funcall function symbol)))
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(if (string-match apropos-regexp symbol)
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(progn
|
|
|
|
|
(if apropos-match-face
|
|
|
|
|
(put-text-property (match-beginning 0) (match-end 0)
|
|
|
|
|
'face apropos-match-face
|
|
|
|
|
symbol))
|
|
|
|
|
symbol)))))
|
|
|
|
|
|
|
|
|
|
(defun apropos-documentation-internal (doc)
|
|
|
|
|
(if (consp doc)
|
|
|
|
|
(apropos-documentation-check-elc-file (car doc))
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(if (and doc
|
|
|
|
|
(string-match apropos-all-words-regexp doc)
|
|
|
|
|
(apropos-true-hit-doc doc))
|
|
|
|
|
(when apropos-match-face
|
|
|
|
|
(setq doc (substitute-command-keys (copy-sequence doc)))
|
|
|
|
|
(if (or (string-match apropos-pattern-quoted doc)
|
|
|
|
|
(string-match apropos-all-words-regexp doc))
|
|
|
|
|
(put-text-property (match-beginning 0)
|
|
|
|
|
(match-end 0)
|
|
|
|
|
'face apropos-match-face doc))
|
|
|
|
|
doc))))
|
1995-07-22 15:17:54 +00:00
|
|
|
|
|
|
|
|
|
(defun apropos-format-plist (pl sep &optional compare)
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(setq pl (symbol-plist pl))
|
|
|
|
|
(let (p p-out)
|
|
|
|
|
(while pl
|
|
|
|
|
(setq p (format "%s %S" (car pl) (nth 1 pl)))
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(if (or (not compare) (string-match apropos-regexp p))
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(if apropos-property-face
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(put-text-property 0 (length (symbol-name (car pl)))
|
1995-07-22 15:17:54 +00:00
|
|
|
|
'face apropos-property-face p))
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(setq p nil))
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(if p
|
|
|
|
|
(progn
|
|
|
|
|
(and compare apropos-match-face
|
|
|
|
|
(put-text-property (match-beginning 0) (match-end 0)
|
|
|
|
|
'face apropos-match-face
|
|
|
|
|
p))
|
|
|
|
|
(setq p-out (concat p-out (if p-out sep) p))))
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(setq pl (nthcdr 2 pl)))
|
|
|
|
|
p-out))
|
|
|
|
|
|
1991-07-31 02:49:11 +00:00
|
|
|
|
|
2005-11-12 00:10:40 +00:00
|
|
|
|
;; Finds all documentation related to APROPOS-REGEXP in internal-doc-file-name.
|
1995-07-07 18:53:58 +00:00
|
|
|
|
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(defun apropos-documentation-check-doc-file ()
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(let (type symbol (sepa 2) sepb)
|
1995-12-19 22:01:53 +00:00
|
|
|
|
(insert ?\^_)
|
|
|
|
|
(backward-char)
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(insert-file-contents (concat doc-directory internal-doc-file-name))
|
1995-12-19 22:01:53 +00:00
|
|
|
|
(forward-char)
|
|
|
|
|
(while (save-excursion
|
|
|
|
|
(setq sepb (search-forward "\^_"))
|
|
|
|
|
(not (eobp)))
|
|
|
|
|
(beginning-of-line 2)
|
|
|
|
|
(if (save-restriction
|
|
|
|
|
(narrow-to-region (point) (1- sepb))
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(re-search-forward apropos-all-words-regexp nil t))
|
1995-12-19 22:01:53 +00:00
|
|
|
|
(progn
|
|
|
|
|
(goto-char (1+ sepa))
|
2002-05-23 20:21:30 +00:00
|
|
|
|
(setq type (if (eq ?F (preceding-char))
|
|
|
|
|
2 ; function documentation
|
|
|
|
|
3) ; variable documentation
|
|
|
|
|
symbol (read)
|
|
|
|
|
doc (buffer-substring (1+ (point)) (1- sepb)))
|
|
|
|
|
(when (apropos-true-hit-doc doc)
|
|
|
|
|
(or (and (setq apropos-item (assq symbol apropos-accumulator))
|
|
|
|
|
(setcar (cdr apropos-item)
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(apropos-score-doc doc)))
|
2003-02-04 11:26:42 +00:00
|
|
|
|
(setq apropos-item (list symbol
|
2002-05-23 20:21:30 +00:00
|
|
|
|
(+ (apropos-score-symbol symbol 2)
|
|
|
|
|
(apropos-score-doc doc))
|
|
|
|
|
nil nil)
|
|
|
|
|
apropos-accumulator (cons apropos-item
|
|
|
|
|
apropos-accumulator)))
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(when apropos-match-face
|
|
|
|
|
(setq doc (substitute-command-keys doc))
|
|
|
|
|
(if (or (string-match apropos-pattern-quoted doc)
|
|
|
|
|
(string-match apropos-all-words-regexp doc))
|
|
|
|
|
(put-text-property (match-beginning 0)
|
|
|
|
|
(match-end 0)
|
|
|
|
|
'face apropos-match-face doc)))
|
2002-05-23 20:21:30 +00:00
|
|
|
|
(setcar (nthcdr type apropos-item) doc))))
|
1995-12-19 22:01:53 +00:00
|
|
|
|
(setq sepa (goto-char sepb)))))
|
1995-07-22 15:17:54 +00:00
|
|
|
|
|
|
|
|
|
(defun apropos-documentation-check-elc-file (file)
|
|
|
|
|
(if (member file apropos-files-scanned)
|
|
|
|
|
nil
|
1995-12-19 22:01:53 +00:00
|
|
|
|
(let (symbol doc beg end this-is-a-variable)
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(setq apropos-files-scanned (cons file apropos-files-scanned))
|
|
|
|
|
(erase-buffer)
|
|
|
|
|
(insert-file-contents file)
|
|
|
|
|
(while (search-forward "\n#@" nil t)
|
|
|
|
|
;; Read the comment length, and advance over it.
|
|
|
|
|
(setq end (read)
|
1995-12-19 22:01:53 +00:00
|
|
|
|
beg (1+ (point))
|
|
|
|
|
end (+ (point) end -1))
|
|
|
|
|
(forward-char)
|
|
|
|
|
(if (save-restriction
|
|
|
|
|
;; match ^ and $ relative to doc string
|
|
|
|
|
(narrow-to-region beg end)
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(re-search-forward apropos-all-words-regexp nil t))
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(progn
|
1995-12-19 22:01:53 +00:00
|
|
|
|
(goto-char (+ end 2))
|
|
|
|
|
(setq doc (buffer-substring beg end)
|
|
|
|
|
end (- (match-end 0) beg)
|
2002-05-23 20:21:30 +00:00
|
|
|
|
beg (- (match-beginning 0) beg))
|
|
|
|
|
(when (apropos-true-hit-doc doc)
|
|
|
|
|
(setq this-is-a-variable (looking-at "(def\\(var\\|const\\) ")
|
|
|
|
|
symbol (progn
|
|
|
|
|
(skip-chars-forward "(a-z")
|
|
|
|
|
(forward-char)
|
|
|
|
|
(read))
|
|
|
|
|
symbol (if (consp symbol)
|
|
|
|
|
(nth 1 symbol)
|
|
|
|
|
symbol))
|
|
|
|
|
(if (if this-is-a-variable
|
|
|
|
|
(get symbol 'variable-documentation)
|
|
|
|
|
(and (fboundp symbol) (apropos-safe-documentation symbol)))
|
|
|
|
|
(progn
|
|
|
|
|
(or (and (setq apropos-item (assq symbol apropos-accumulator))
|
|
|
|
|
(setcar (cdr apropos-item)
|
|
|
|
|
(+ (cadr apropos-item) (apropos-score-doc doc))))
|
|
|
|
|
(setq apropos-item (list symbol
|
|
|
|
|
(+ (apropos-score-symbol symbol 2)
|
|
|
|
|
(apropos-score-doc doc))
|
|
|
|
|
nil nil)
|
|
|
|
|
apropos-accumulator (cons apropos-item
|
|
|
|
|
apropos-accumulator)))
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(when apropos-match-face
|
|
|
|
|
(setq doc (substitute-command-keys doc))
|
|
|
|
|
(if (or (string-match apropos-pattern-quoted doc)
|
|
|
|
|
(string-match apropos-all-words-regexp doc))
|
|
|
|
|
(put-text-property (match-beginning 0)
|
|
|
|
|
(match-end 0)
|
|
|
|
|
'face apropos-match-face doc)))
|
2002-05-23 20:21:30 +00:00
|
|
|
|
(setcar (nthcdr (if this-is-a-variable 3 2)
|
|
|
|
|
apropos-item)
|
|
|
|
|
doc))))))))))
|
1995-07-22 15:17:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun apropos-safe-documentation (function)
|
2000-06-20 09:58:07 +00:00
|
|
|
|
"Like `documentation', except it avoids calling `get_doc_string'.
|
1991-07-31 02:49:11 +00:00
|
|
|
|
Will return nil instead."
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(while (and function (symbolp function))
|
1991-07-31 02:49:11 +00:00
|
|
|
|
(setq function (if (fboundp function)
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(symbol-function function))))
|
1993-06-08 01:32:42 +00:00
|
|
|
|
(if (eq (car-safe function) 'macro)
|
|
|
|
|
(setq function (cdr function)))
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(setq function (if (byte-code-function-p function)
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(if (> (length function) 4)
|
|
|
|
|
(aref function 4))
|
|
|
|
|
(if (eq (car-safe function) 'autoload)
|
|
|
|
|
(nth 2 function)
|
|
|
|
|
(if (eq (car-safe function) 'lambda)
|
|
|
|
|
(if (stringp (nth 2 function))
|
|
|
|
|
(nth 2 function)
|
|
|
|
|
(if (stringp (nth 3 function))
|
|
|
|
|
(nth 3 function)))))))
|
|
|
|
|
(if (integerp function)
|
|
|
|
|
nil
|
|
|
|
|
function))
|
|
|
|
|
|
2008-06-10 02:44:48 +00:00
|
|
|
|
(defcustom apropos-compact-layout nil
|
|
|
|
|
"If non-nil, use a single line per binding."
|
|
|
|
|
:type 'boolean)
|
1995-07-22 15:17:54 +00:00
|
|
|
|
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(defun apropos-print (do-keys spacing &optional text nosubst)
|
1998-06-20 22:27:06 +00:00
|
|
|
|
"Output result of apropos searching into buffer `*Apropos*'.
|
|
|
|
|
The value of `apropos-accumulator' is the list of items to output.
|
2003-02-04 11:26:42 +00:00
|
|
|
|
Each element should have the format
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(SYMBOL SCORE FN-DOC VAR-DOC [PLIST-DOC WIDGET-DOC FACE-DOC GROUP-DOC]).
|
1998-06-20 22:27:06 +00:00
|
|
|
|
The return value is the list that was in `apropos-accumulator', sorted
|
|
|
|
|
alphabetically by symbol name; but this function also sets
|
2001-12-22 01:36:48 +00:00
|
|
|
|
`apropos-accumulator' to nil before returning.
|
|
|
|
|
|
2004-03-26 15:27:56 +00:00
|
|
|
|
If SPACING is non-nil, it should be a string; separate items with that string.
|
|
|
|
|
If non-nil TEXT is a string that will be printed as a heading."
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(if (null apropos-accumulator)
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(message "No apropos matches for `%s'" apropos-pattern)
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(setq apropos-accumulator
|
2003-07-12 21:57:50 +00:00
|
|
|
|
(sort apropos-accumulator
|
|
|
|
|
(lambda (a b)
|
|
|
|
|
;; Don't sort by score if user can't see the score.
|
|
|
|
|
;; It would be confusing. -- rms.
|
2003-07-14 21:49:02 +00:00
|
|
|
|
(if apropos-sort-by-scores
|
2003-07-12 21:57:50 +00:00
|
|
|
|
(or (> (cadr a) (cadr b))
|
|
|
|
|
(and (= (cadr a) (cadr b))
|
|
|
|
|
(string-lessp (car a) (car b))))
|
|
|
|
|
(string-lessp (car a) (car b))))))
|
1995-11-10 17:08:38 +00:00
|
|
|
|
(with-output-to-temp-buffer "*Apropos*"
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(let ((p apropos-accumulator)
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(old-buffer (current-buffer))
|
2001-10-07 11:35:09 +00:00
|
|
|
|
symbol item)
|
1995-12-19 22:01:53 +00:00
|
|
|
|
(set-buffer standard-output)
|
|
|
|
|
(apropos-mode)
|
2000-05-25 16:51:21 +00:00
|
|
|
|
(if (display-mouse-p)
|
2002-05-04 14:51:46 +00:00
|
|
|
|
(insert
|
|
|
|
|
"If moving the mouse over text changes the text's color, "
|
|
|
|
|
"you can click\n"
|
|
|
|
|
"mouse-2 (second button from right) on that text to "
|
|
|
|
|
"get more information.\n"))
|
2001-09-28 06:18:36 +00:00
|
|
|
|
(insert "In this buffer, go to the name of the command, or function,"
|
2001-09-28 06:11:25 +00:00
|
|
|
|
" or variable,\n"
|
|
|
|
|
(substitute-command-keys
|
|
|
|
|
"and type \\[apropos-follow] to get full documentation.\n\n"))
|
2004-03-26 15:27:56 +00:00
|
|
|
|
(if text (insert text "\n\n"))
|
2008-06-08 03:48:22 +00:00
|
|
|
|
(dolist (apropos-item p)
|
2001-12-22 01:36:48 +00:00
|
|
|
|
(when (and spacing (not (bobp)))
|
|
|
|
|
(princ spacing))
|
2008-06-08 03:48:22 +00:00
|
|
|
|
(setq symbol (car apropos-item))
|
2005-11-12 00:10:40 +00:00
|
|
|
|
;; Insert dummy score element for backwards compatibility with 21.x
|
|
|
|
|
;; apropos-item format.
|
|
|
|
|
(if (not (numberp (cadr apropos-item)))
|
|
|
|
|
(setq apropos-item
|
|
|
|
|
(cons (car apropos-item)
|
|
|
|
|
(cons nil (cdr apropos-item)))))
|
2001-10-07 11:35:09 +00:00
|
|
|
|
(insert-text-button (symbol-name symbol)
|
|
|
|
|
'type 'apropos-symbol
|
2008-07-31 22:15:18 +00:00
|
|
|
|
'skip apropos-multi-type
|
2001-10-07 11:35:09 +00:00
|
|
|
|
;; Can't use default, since user may have
|
|
|
|
|
;; changed the variable!
|
|
|
|
|
;; Just say `no' to variables containing faces!
|
|
|
|
|
'face apropos-symbol-face)
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(if (and (eq apropos-sort-by-scores 'verbose)
|
|
|
|
|
(cadr apropos-item))
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(insert " (" (number-to-string (cadr apropos-item)) ") "))
|
1996-01-27 22:45:19 +00:00
|
|
|
|
;; Calculate key-bindings if we want them.
|
2008-06-10 02:44:48 +00:00
|
|
|
|
(unless apropos-compact-layout
|
|
|
|
|
(and do-keys
|
|
|
|
|
(commandp symbol)
|
|
|
|
|
(not (eq symbol 'self-insert-command))
|
|
|
|
|
(indent-to 30 1)
|
|
|
|
|
(if (let ((keys
|
|
|
|
|
(with-current-buffer old-buffer
|
|
|
|
|
(where-is-internal symbol)))
|
|
|
|
|
filtered)
|
|
|
|
|
;; Copy over the list of key sequences,
|
|
|
|
|
;; omitting any that contain a buffer or a frame.
|
|
|
|
|
;; FIXME: Why omit keys that contain buffers and
|
|
|
|
|
;; frames? This looks like a bad workaround rather
|
|
|
|
|
;; than a proper fix. Does anybod know what problem
|
|
|
|
|
;; this is trying to address? --Stef
|
|
|
|
|
(dolist (key keys)
|
|
|
|
|
(let ((i 0)
|
|
|
|
|
loser)
|
|
|
|
|
(while (< i (length key))
|
|
|
|
|
(if (or (framep (aref key i))
|
|
|
|
|
(bufferp (aref key i)))
|
|
|
|
|
(setq loser t))
|
|
|
|
|
(setq i (1+ i)))
|
|
|
|
|
(or loser
|
|
|
|
|
(push key filtered))))
|
|
|
|
|
(setq item filtered))
|
|
|
|
|
;; Convert the remaining keys to a string and insert.
|
|
|
|
|
(insert
|
|
|
|
|
(mapconcat
|
|
|
|
|
(lambda (key)
|
|
|
|
|
(setq key (condition-case ()
|
|
|
|
|
(key-description key)
|
|
|
|
|
(error)))
|
|
|
|
|
(if apropos-keybinding-face
|
|
|
|
|
(put-text-property 0 (length key)
|
|
|
|
|
'face apropos-keybinding-face
|
|
|
|
|
key))
|
|
|
|
|
key)
|
|
|
|
|
item ", "))
|
|
|
|
|
(insert "M-x ... RET")
|
|
|
|
|
(when apropos-keybinding-face
|
|
|
|
|
(put-text-property (- (point) 11) (- (point) 8)
|
|
|
|
|
'face apropos-keybinding-face)
|
|
|
|
|
(put-text-property (- (point) 3) (point)
|
|
|
|
|
'face apropos-keybinding-face))))
|
|
|
|
|
(terpri))
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(apropos-print-doc 2
|
1995-12-19 22:01:53 +00:00
|
|
|
|
(if (commandp symbol)
|
2001-10-08 06:58:32 +00:00
|
|
|
|
'apropos-command
|
1995-12-19 22:01:53 +00:00
|
|
|
|
(if (apropos-macrop symbol)
|
2001-10-08 06:58:32 +00:00
|
|
|
|
'apropos-macro
|
|
|
|
|
'apropos-function))
|
2005-11-12 00:10:40 +00:00
|
|
|
|
(not nosubst))
|
|
|
|
|
(apropos-print-doc 3 'apropos-variable (not nosubst))
|
2002-05-23 10:20:12 +00:00
|
|
|
|
(apropos-print-doc 7 'apropos-group t)
|
|
|
|
|
(apropos-print-doc 6 'apropos-face t)
|
|
|
|
|
(apropos-print-doc 5 'apropos-widget t)
|
|
|
|
|
(apropos-print-doc 4 'apropos-plist nil))
|
2008-06-10 02:44:48 +00:00
|
|
|
|
(set (make-local-variable 'truncate-partial-width-windows) t)
|
|
|
|
|
(set (make-local-variable 'truncate-lines) t)
|
1998-06-20 22:27:06 +00:00
|
|
|
|
(setq buffer-read-only t))))
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(prog1 apropos-accumulator
|
|
|
|
|
(setq apropos-accumulator ()))) ; permit gc
|
|
|
|
|
|
|
|
|
|
(defun apropos-macrop (symbol)
|
2004-10-27 17:46:33 +00:00
|
|
|
|
"Return t if SYMBOL is a Lisp macro."
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(and (fboundp symbol)
|
|
|
|
|
(consp (setq symbol
|
|
|
|
|
(symbol-function symbol)))
|
|
|
|
|
(or (eq (car symbol) 'macro)
|
|
|
|
|
(if (eq (car symbol) 'autoload)
|
|
|
|
|
(memq (nth 4 symbol)
|
|
|
|
|
'(macro t))))))
|
1995-07-07 18:53:58 +00:00
|
|
|
|
|
1995-07-22 15:17:54 +00:00
|
|
|
|
|
2001-10-08 06:58:32 +00:00
|
|
|
|
(defun apropos-print-doc (i type do-keys)
|
2008-06-08 03:48:22 +00:00
|
|
|
|
(when (stringp (setq i (nth i apropos-item)))
|
2008-06-10 02:44:48 +00:00
|
|
|
|
(if apropos-compact-layout
|
|
|
|
|
(insert (propertize "\t" 'display '(space :align-to 32)) " ")
|
|
|
|
|
(insert " "))
|
2008-07-31 22:15:18 +00:00
|
|
|
|
(if (null apropos-multi-type)
|
|
|
|
|
;; If the query is only for a single type, there's no point
|
|
|
|
|
;; writing it over and over again. Insert a blank button, and
|
|
|
|
|
;; put the 'apropos-label property there (needed by
|
|
|
|
|
;; apropos-symbol-button-display-help).
|
|
|
|
|
(insert-text-button
|
|
|
|
|
" " 'type type 'skip t
|
|
|
|
|
'face 'default 'apropos-symbol (car apropos-item))
|
2008-06-10 02:44:48 +00:00
|
|
|
|
(insert-text-button
|
|
|
|
|
(if apropos-compact-layout
|
2008-12-03 21:57:10 +00:00
|
|
|
|
(format "<%s>" (button-type-get type 'apropos-short-label))
|
|
|
|
|
(button-type-get type 'apropos-label))
|
2008-06-10 02:44:48 +00:00
|
|
|
|
'type type
|
|
|
|
|
;; Can't use the default button face, since user may have changed the
|
|
|
|
|
;; variable! Just say `no' to variables containing faces!
|
|
|
|
|
'face apropos-label-face
|
|
|
|
|
'apropos-symbol (car apropos-item))
|
|
|
|
|
(insert (if apropos-compact-layout " " ": ")))
|
2008-07-31 22:15:18 +00:00
|
|
|
|
(insert (if do-keys (substitute-command-keys i) i))
|
2008-06-08 03:48:22 +00:00
|
|
|
|
(or (bolp) (terpri))))
|
1995-07-07 18:53:58 +00:00
|
|
|
|
|
2001-10-07 11:35:09 +00:00
|
|
|
|
(defun apropos-follow ()
|
|
|
|
|
"Invokes any button at point, otherwise invokes the nearest label button."
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(interactive)
|
2001-10-07 11:35:09 +00:00
|
|
|
|
(button-activate
|
|
|
|
|
(or (apropos-next-label-button (line-beginning-position))
|
|
|
|
|
(error "There is nothing to follow here"))))
|
1995-07-07 18:53:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun apropos-describe-plist (symbol)
|
|
|
|
|
"Display a pretty listing of SYMBOL's plist."
|
2004-03-26 15:27:56 +00:00
|
|
|
|
(help-setup-xref (list 'apropos-describe-plist symbol) (interactive-p))
|
2007-11-10 09:55:10 +00:00
|
|
|
|
(with-help-window (help-buffer)
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(set-buffer standard-output)
|
|
|
|
|
(princ "Symbol ")
|
|
|
|
|
(prin1 symbol)
|
|
|
|
|
(princ "'s plist is\n (")
|
1995-07-22 15:17:54 +00:00
|
|
|
|
(if apropos-symbol-face
|
2004-03-26 15:27:56 +00:00
|
|
|
|
(put-text-property (+ (point-min) 7) (- (point) 14)
|
|
|
|
|
'face apropos-symbol-face))
|
1995-07-07 18:53:58 +00:00
|
|
|
|
(insert (apropos-format-plist symbol "\n "))
|
2007-11-10 09:55:10 +00:00
|
|
|
|
(princ ")")))
|
1991-07-31 02:49:11 +00:00
|
|
|
|
|
2001-10-07 11:35:09 +00:00
|
|
|
|
|
1997-06-22 18:57:55 +00:00
|
|
|
|
(provide 'apropos)
|
|
|
|
|
|
2008-04-10 14:10:46 +00:00
|
|
|
|
;; arch-tag: d56fa2ac-e56b-4ce3-84ff-852f9c0dc66e
|
1992-05-30 23:54:21 +00:00
|
|
|
|
;;; apropos.el ends here
|