apropos.el 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. ;;; apropos.el --- apropos commands for users and programmers
  2. ;; Copyright (C) 1989, 1994-1995, 2001-2015 Free Software Foundation,
  3. ;; Inc.
  4. ;; Author: Joe Wells <jbw@bigbird.bu.edu>
  5. ;; Daniel Pfeiffer <occitan@esperanto.org> (rewrite)
  6. ;; Keywords: help
  7. ;; Package: emacs
  8. ;; This file is part of GNU Emacs.
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;; Commentary:
  20. ;; The ideas for this package were derived from the C code in
  21. ;; src/keymap.c and elsewhere. The functions in this file should
  22. ;; always be byte-compiled for speed. Someone should rewrite this in
  23. ;; C (as part of src/keymap.c) for speed.
  24. ;; The idea for super-apropos is based on the original implementation
  25. ;; by Lynn Slater <lrs@esl.com>.
  26. ;; History:
  27. ;; Fixed bug, current-local-map can return nil.
  28. ;; Change, doesn't calculate key-bindings unless needed.
  29. ;; Added super-apropos capability, changed print functions.
  30. ;; Made fast-apropos and super-apropos share code.
  31. ;; Sped up fast-apropos again.
  32. ;; Added apropos-do-all option.
  33. ;; Added fast-command-apropos.
  34. ;; Changed doc strings to comments for helping functions.
  35. ;; Made doc file buffer read-only, buried it.
  36. ;; Only call substitute-command-keys if do-all set.
  37. ;; Optionally use configurable faces to make the output more legible.
  38. ;; Differentiate between command, function and macro.
  39. ;; Apropos-command (ex command-apropos) does cmd and optionally user var.
  40. ;; Apropos shows all 3 aspects of symbols (fn, var and plist)
  41. ;; Apropos-documentation (ex super-apropos) now finds all it should.
  42. ;; New apropos-value snoops through all values and optionally plists.
  43. ;; Reading DOC file doesn't load nroff.
  44. ;; Added hypertext following of documentation, mouse-2 on variable gives value
  45. ;; from buffer in active window.
  46. ;;; Code:
  47. (require 'button)
  48. (defgroup apropos nil
  49. "Apropos commands for users and programmers."
  50. :group 'help
  51. :prefix "apropos")
  52. ;; I see a degradation of maybe 10-20% only.
  53. (defcustom apropos-do-all nil
  54. "Non nil means apropos commands will search more extensively.
  55. This may be slower. This option affects the following commands:
  56. `apropos-user-option' will search all variables, not just user options.
  57. `apropos-command' will also search non-interactive functions.
  58. `apropos' will search all symbols, not just functions, variables, faces,
  59. and those with property lists.
  60. `apropos-value' will also search in property lists and functions.
  61. `apropos-documentation' will search all documentation strings, not just
  62. those in the etc/DOC documentation file.
  63. This option only controls the default behavior. Each of the above
  64. commands also has an optional argument to request a more extensive search.
  65. Additionally, this option makes the function `apropos-library'
  66. include key-binding information in its output."
  67. :group 'apropos
  68. :type 'boolean)
  69. (defface apropos-symbol
  70. '((t (:inherit bold)))
  71. "Face for the symbol name in Apropos output."
  72. :group 'apropos
  73. :version "24.3")
  74. (defface apropos-keybinding
  75. '((t (:inherit underline)))
  76. "Face for lists of keybinding in Apropos output."
  77. :group 'apropos
  78. :version "24.3")
  79. (defface apropos-property
  80. '((t (:inherit font-lock-builtin-face)))
  81. "Face for property name in Apropos output, or nil for none."
  82. :group 'apropos
  83. :version "24.3")
  84. (defface apropos-function-button
  85. '((t (:inherit (font-lock-function-name-face button))))
  86. "Button face indicating a function, macro, or command in Apropos."
  87. :group 'apropos
  88. :version "24.3")
  89. (defface apropos-variable-button
  90. '((t (:inherit (font-lock-variable-name-face button))))
  91. "Button face indicating a variable in Apropos."
  92. :group 'apropos
  93. :version "24.3")
  94. (defface apropos-user-option-button
  95. '((t (:inherit (font-lock-variable-name-face button))))
  96. "Button face indicating a user option in Apropos."
  97. :group 'apropos
  98. :version "24.4")
  99. (defface apropos-misc-button
  100. '((t (:inherit (font-lock-constant-face button))))
  101. "Button face indicating a miscellaneous object type in Apropos."
  102. :group 'apropos
  103. :version "24.3")
  104. (defcustom apropos-match-face 'match
  105. "Face for matching text in Apropos documentation/value, or nil for none.
  106. This applies when you look for matches in the documentation or variable value
  107. for the pattern; the part that matches gets displayed in this font."
  108. :type '(choice (const nil) face)
  109. :group 'apropos
  110. :version "24.3")
  111. (defcustom apropos-sort-by-scores nil
  112. "Non-nil means sort matches by scores; best match is shown first.
  113. This applies to all `apropos' commands except `apropos-documentation'.
  114. If value is `verbose', the computed score is shown for each match."
  115. :group 'apropos
  116. :type '(choice (const :tag "off" nil)
  117. (const :tag "on" t)
  118. (const :tag "show scores" verbose)))
  119. (defcustom apropos-documentation-sort-by-scores t
  120. "Non-nil means sort matches by scores; best match is shown first.
  121. This applies to `apropos-documentation' only.
  122. If value is `verbose', the computed score is shown for each match."
  123. :group 'apropos
  124. :type '(choice (const :tag "off" nil)
  125. (const :tag "on" t)
  126. (const :tag "show scores" verbose)))
  127. (defvar apropos-mode-map
  128. (let ((map (copy-keymap button-buffer-map)))
  129. (set-keymap-parent map special-mode-map)
  130. ;; Use `apropos-follow' instead of just using the button
  131. ;; definition of RET, so that users can use it anywhere in an
  132. ;; apropos item, not just on top of a button.
  133. (define-key map "\C-m" 'apropos-follow)
  134. map)
  135. "Keymap used in Apropos mode.")
  136. (defvar apropos-mode-hook nil
  137. "Hook run when mode is turned on.")
  138. (defvar apropos-pattern nil
  139. "Apropos pattern as entered by user.")
  140. (defvar apropos-pattern-quoted nil
  141. "Apropos pattern passed through `regexp-quote'.")
  142. (defvar apropos-words ()
  143. "Current list of apropos words extracted from `apropos-pattern'.")
  144. (defvar apropos-all-words ()
  145. "Current list of words and synonyms.")
  146. (defvar apropos-regexp nil
  147. "Regexp used in current apropos run.")
  148. (defvar apropos-all-words-regexp nil
  149. "Regexp matching `apropos-all-words'.")
  150. (defvar apropos-files-scanned ()
  151. "List of elc files already scanned in current run of `apropos-documentation'.")
  152. (defvar apropos-accumulator ()
  153. "Alist of symbols already found in current apropos run.
  154. Each element has the form
  155. (SYMBOL SCORE FUN-DOC VAR-DOC PLIST WIDGET-DOC FACE-DOC CUS-GROUP-DOC)
  156. where SYMBOL is the symbol name, SCORE is its relevance score (a
  157. number), FUN-DOC is the function docstring, VAR-DOC is the
  158. variable docstring, PLIST is the list of the symbols names in the
  159. property list, WIDGET-DOC is the widget docstring, FACE-DOC is
  160. the face docstring, and CUS-GROUP-DOC is the custom group
  161. docstring. Each docstring is either nil or a string.")
  162. (defvar apropos-item ()
  163. "Current item in or for `apropos-accumulator'.")
  164. (defvar apropos-synonyms '(
  165. ("find" "open" "edit")
  166. ("kill" "cut")
  167. ("yank" "paste")
  168. ("region" "selection"))
  169. "List of synonyms known by apropos.
  170. Each element is a list of words where the first word is the standard Emacs
  171. term, and the rest of the words are alternative terms.")
  172. ;;; Button types used by apropos
  173. (define-button-type 'apropos-symbol
  174. 'face 'apropos-symbol
  175. 'help-echo "mouse-2, RET: Display more help on this symbol"
  176. 'follow-link t
  177. 'action #'apropos-symbol-button-display-help)
  178. (defun apropos-symbol-button-display-help (button)
  179. "Display further help for the `apropos-symbol' button BUTTON."
  180. (button-activate
  181. (or (apropos-next-label-button (button-start button))
  182. (error "There is nothing to follow for `%s'" (button-label button)))))
  183. (define-button-type 'apropos-function
  184. 'apropos-label "Function"
  185. 'apropos-short-label "f"
  186. 'face 'apropos-function-button
  187. 'help-echo "mouse-2, RET: Display more help on this function"
  188. 'follow-link t
  189. 'action (lambda (button)
  190. (describe-function (button-get button 'apropos-symbol))))
  191. (define-button-type 'apropos-macro
  192. 'apropos-label "Macro"
  193. 'apropos-short-label "m"
  194. 'face 'apropos-function-button
  195. 'help-echo "mouse-2, RET: Display more help on this macro"
  196. 'follow-link t
  197. 'action (lambda (button)
  198. (describe-function (button-get button 'apropos-symbol))))
  199. (define-button-type 'apropos-command
  200. 'apropos-label "Command"
  201. 'apropos-short-label "c"
  202. 'face 'apropos-function-button
  203. 'help-echo "mouse-2, RET: Display more help on this command"
  204. 'follow-link t
  205. 'action (lambda (button)
  206. (describe-function (button-get button 'apropos-symbol))))
  207. ;; We used to use `customize-variable-other-window' instead for a
  208. ;; customizable variable, but that is slow. It is better to show an
  209. ;; ordinary help buffer and let the user click on the customization
  210. ;; button in that buffer, if he wants to.
  211. ;; Likewise for `customize-face-other-window'.
  212. (define-button-type 'apropos-variable
  213. 'apropos-label "Variable"
  214. 'apropos-short-label "v"
  215. 'face 'apropos-variable-button
  216. 'help-echo "mouse-2, RET: Display more help on this variable"
  217. 'follow-link t
  218. 'action (lambda (button)
  219. (describe-variable (button-get button 'apropos-symbol))))
  220. (define-button-type 'apropos-user-option
  221. 'apropos-label "User option"
  222. 'apropos-short-label "o"
  223. 'face 'apropos-user-option-button
  224. 'help-echo "mouse-2, RET: Display more help on this user option"
  225. 'follow-link t
  226. 'action (lambda (button)
  227. (describe-variable (button-get button 'apropos-symbol))))
  228. (define-button-type 'apropos-face
  229. 'apropos-label "Face"
  230. 'apropos-short-label "F"
  231. 'face '(font-lock-variable-name-face button)
  232. 'help-echo "mouse-2, RET: Display more help on this face"
  233. 'follow-link t
  234. 'action (lambda (button)
  235. (describe-face (button-get button 'apropos-symbol))))
  236. (define-button-type 'apropos-group
  237. 'apropos-label "Group"
  238. 'apropos-short-label "g"
  239. 'face 'apropos-misc-button
  240. 'help-echo "mouse-2, RET: Display more help on this group"
  241. 'follow-link t
  242. 'action (lambda (button)
  243. (customize-group-other-window
  244. (button-get button 'apropos-symbol))))
  245. (define-button-type 'apropos-widget
  246. 'apropos-label "Widget"
  247. 'apropos-short-label "w"
  248. 'face 'apropos-misc-button
  249. 'help-echo "mouse-2, RET: Display more help on this widget"
  250. 'follow-link t
  251. 'action (lambda (button)
  252. (widget-browse-other-window (button-get button 'apropos-symbol))))
  253. (define-button-type 'apropos-plist
  254. 'apropos-label "Properties"
  255. 'apropos-short-label "p"
  256. 'face 'apropos-misc-button
  257. 'help-echo "mouse-2, RET: Display more help on this plist"
  258. 'follow-link t
  259. 'action (lambda (button)
  260. (apropos-describe-plist (button-get button 'apropos-symbol))))
  261. (define-button-type 'apropos-library
  262. 'help-echo "mouse-2, RET: Display more help on this library"
  263. 'follow-link t
  264. 'action (lambda (button)
  265. (apropos-library (button-get button 'apropos-symbol))))
  266. (defun apropos-next-label-button (pos)
  267. "Return the next apropos label button after POS, or nil if there's none.
  268. Will also return nil if more than one `apropos-symbol' button is encountered
  269. before finding a label."
  270. (let* ((button (next-button pos t))
  271. (already-hit-symbol nil)
  272. (label (and button (button-get button 'apropos-label)))
  273. (type (and button (button-get button 'type))))
  274. (while (and button
  275. (not label)
  276. (or (not (eq type 'apropos-symbol))
  277. (not already-hit-symbol)))
  278. (when (eq type 'apropos-symbol)
  279. (setq already-hit-symbol t))
  280. (setq button (next-button (button-start button)))
  281. (when button
  282. (setq label (button-get button 'apropos-label))
  283. (setq type (button-get button 'type))))
  284. (and label button)))
  285. (defun apropos-words-to-regexp (words wild)
  286. "Make regexp matching any two of the words in WORDS.
  287. WILD should be a subexpression matching wildcards between matches."
  288. (setq words (delete-dups (copy-sequence words)))
  289. (if (null (cdr words))
  290. (car words)
  291. (mapconcat
  292. (lambda (w)
  293. (concat "\\(?:" w "\\)" ;; parens for synonyms
  294. wild "\\(?:"
  295. (mapconcat 'identity
  296. (delq w (copy-sequence words))
  297. "\\|")
  298. "\\)"))
  299. words
  300. "\\|")))
  301. ;;;###autoload
  302. (defun apropos-read-pattern (subject)
  303. "Read an apropos pattern, either a word list or a regexp.
  304. Returns the user pattern, either a list of words which are matched
  305. literally, or a string which is used as a regexp to search for.
  306. SUBJECT is a string that is included in the prompt to identify what
  307. kind of objects to search."
  308. (let ((pattern
  309. (read-string (concat "Search for " subject " (word list or regexp): "))))
  310. (if (string-equal (regexp-quote pattern) pattern)
  311. ;; Split into words
  312. (or (split-string pattern "[ \t]+" t)
  313. (user-error "No word list given"))
  314. pattern)))
  315. (defun apropos-parse-pattern (pattern)
  316. "Rewrite a list of words to a regexp matching all permutations.
  317. If PATTERN is a string, that means it is already a regexp.
  318. This updates variables `apropos-pattern', `apropos-pattern-quoted',
  319. `apropos-regexp', `apropos-words', and `apropos-all-words-regexp'."
  320. (setq apropos-words nil
  321. apropos-all-words nil)
  322. (if (consp pattern)
  323. ;; We don't actually make a regexp matching all permutations.
  324. ;; Instead, for e.g. "a b c", we make a regexp matching
  325. ;; any combination of two or more words like this:
  326. ;; (a|b|c).*(a|b|c) which may give some false matches,
  327. ;; but as long as it also gives the right ones, that's ok.
  328. (let ((words pattern))
  329. (setq apropos-pattern (mapconcat 'identity pattern " ")
  330. apropos-pattern-quoted (regexp-quote apropos-pattern))
  331. (dolist (word words)
  332. (let ((syn apropos-synonyms) (s word) (a word))
  333. (while syn
  334. (if (member word (car syn))
  335. (progn
  336. (setq a (mapconcat 'identity (car syn) "\\|"))
  337. (if (member word (cdr (car syn)))
  338. (setq s a))
  339. (setq syn nil))
  340. (setq syn (cdr syn))))
  341. (setq apropos-words (cons s apropos-words)
  342. apropos-all-words (cons a apropos-all-words))))
  343. (setq apropos-all-words-regexp
  344. (apropos-words-to-regexp apropos-all-words ".+"))
  345. (setq apropos-regexp
  346. (apropos-words-to-regexp apropos-words ".*?")))
  347. (setq apropos-pattern-quoted (regexp-quote pattern)
  348. apropos-all-words-regexp pattern
  349. apropos-pattern pattern
  350. apropos-regexp pattern)))
  351. (defun apropos-calc-scores (str words)
  352. "Return apropos scores for string STR matching WORDS.
  353. Value is a list of offsets of the words into the string."
  354. (let (scores i)
  355. (if words
  356. (dolist (word words scores)
  357. (if (setq i (string-match word str))
  358. (setq scores (cons i scores))))
  359. ;; Return list of start and end position of regexp
  360. (and (string-match apropos-pattern str)
  361. (list (match-beginning 0) (match-end 0))))))
  362. (defun apropos-score-str (str)
  363. "Return apropos score for string STR."
  364. (if str
  365. (let* ((l (length str))
  366. (score (- (/ l 10))))
  367. (dolist (s (apropos-calc-scores str apropos-all-words) score)
  368. (setq score (+ score 1000 (/ (* (- l s) 1000) l)))))
  369. 0))
  370. (defun apropos-score-doc (doc)
  371. "Return apropos score for documentation string DOC."
  372. (let ((l (length doc)))
  373. (if (> l 0)
  374. (let ((score 0))
  375. (when (string-match apropos-pattern-quoted doc)
  376. (setq score 10000))
  377. (dolist (s (apropos-calc-scores doc apropos-all-words) score)
  378. (setq score (+ score 50 (/ (* (- l s) 50) l)))))
  379. 0)))
  380. (defun apropos-score-symbol (symbol &optional weight)
  381. "Return apropos score for SYMBOL."
  382. (setq symbol (symbol-name symbol))
  383. (let ((score 0)
  384. (l (length symbol)))
  385. (dolist (s (apropos-calc-scores symbol apropos-words) (* score (or weight 3)))
  386. (setq score (+ score (- 60 l) (/ (* (- l s) 60) l))))))
  387. (defun apropos-true-hit (str words)
  388. "Return t if STR is a genuine hit.
  389. This may fail if only one of the keywords is matched more than once.
  390. This requires at least two keywords (unless only one was given)."
  391. (or (not str)
  392. (not words)
  393. (not (cdr words))
  394. (> (length (apropos-calc-scores str words)) 1)))
  395. (defun apropos-false-hit-symbol (symbol)
  396. "Return t if SYMBOL is not really matched by the current keywords."
  397. (not (apropos-true-hit (symbol-name symbol) apropos-words)))
  398. (defun apropos-false-hit-str (str)
  399. "Return t if STR is not really matched by the current keywords."
  400. (not (apropos-true-hit str apropos-words)))
  401. (defun apropos-true-hit-doc (doc)
  402. "Return t if DOC is really matched by the current keywords."
  403. (apropos-true-hit doc apropos-all-words))
  404. (define-derived-mode apropos-mode special-mode "Apropos"
  405. "Major mode for following hyperlinks in output of apropos commands.
  406. \\{apropos-mode-map}")
  407. (defvar apropos-multi-type t
  408. "If non-nil, this apropos query concerns multiple types.
  409. This is used to decide whether to print the result's type or not.")
  410. ;;;###autoload
  411. (defun apropos-user-option (pattern &optional do-all)
  412. "Show user options that match PATTERN.
  413. PATTERN can be a word, a list of words (separated by spaces),
  414. or a regexp (using some regexp special characters). If it is a word,
  415. search for matches for that word as a substring. If it is a list of words,
  416. search for matches for any two (or more) of those words.
  417. With \\[universal-argument] prefix, or if `apropos-do-all' is non-nil, also show
  418. variables, not just user options."
  419. (interactive (list (apropos-read-pattern
  420. (if (or current-prefix-arg apropos-do-all)
  421. "variable" "user option"))
  422. current-prefix-arg))
  423. (apropos-command pattern nil
  424. (if (or do-all apropos-do-all)
  425. #'(lambda (symbol)
  426. (and (boundp symbol)
  427. (get symbol 'variable-documentation)))
  428. 'custom-variable-p)))
  429. ;;;###autoload
  430. (defun apropos-variable (pattern &optional do-not-all)
  431. "Show variables that match PATTERN.
  432. When DO-NOT-ALL is non-nil, show user options only, i.e. behave
  433. like `apropos-user-option'."
  434. (interactive (list (apropos-read-pattern
  435. (if current-prefix-arg "user option" "variable"))
  436. current-prefix-arg))
  437. (let ((apropos-do-all (if do-not-all nil t)))
  438. (apropos-user-option pattern)))
  439. ;; For auld lang syne:
  440. ;;;###autoload
  441. (defalias 'command-apropos 'apropos-command)
  442. ;;;###autoload
  443. (defun apropos-command (pattern &optional do-all var-predicate)
  444. "Show commands (interactively callable functions) that match PATTERN.
  445. PATTERN can be a word, a list of words (separated by spaces),
  446. or a regexp (using some regexp special characters). If it is a word,
  447. search for matches for that word as a substring. If it is a list of words,
  448. search for matches for any two (or more) of those words.
  449. With \\[universal-argument] prefix, or if `apropos-do-all' is non-nil, also show
  450. noninteractive functions.
  451. If VAR-PREDICATE is non-nil, show only variables, and only those that
  452. satisfy the predicate VAR-PREDICATE.
  453. When called from a Lisp program, a string PATTERN is used as a regexp,
  454. while a list of strings is used as a word list."
  455. (interactive (list (apropos-read-pattern
  456. (if (or current-prefix-arg apropos-do-all)
  457. "command or function" "command"))
  458. current-prefix-arg))
  459. (apropos-parse-pattern pattern)
  460. (let ((message
  461. (let ((standard-output (get-buffer-create "*Apropos*")))
  462. (help-print-return-message 'identity))))
  463. (or do-all (setq do-all apropos-do-all))
  464. (setq apropos-accumulator
  465. (apropos-internal apropos-regexp
  466. (or var-predicate
  467. ;; We used to use `functionp' here, but this
  468. ;; rules out macros. `fboundp' rules in
  469. ;; keymaps, but it seems harmless.
  470. (if do-all 'fboundp 'commandp))))
  471. (let ((tem apropos-accumulator))
  472. (while tem
  473. (if (or (get (car tem) 'apropos-inhibit)
  474. (apropos-false-hit-symbol (car tem)))
  475. (setq apropos-accumulator (delq (car tem) apropos-accumulator)))
  476. (setq tem (cdr tem))))
  477. (let ((p apropos-accumulator)
  478. doc symbol score)
  479. (while p
  480. (setcar p (list
  481. (setq symbol (car p))
  482. (setq score (apropos-score-symbol symbol))
  483. (unless var-predicate
  484. (if (fboundp symbol)
  485. (if (setq doc (condition-case nil
  486. (documentation symbol t)
  487. (error 'error)))
  488. ;; Eg alias to undefined function.
  489. (if (eq doc 'error)
  490. "(documentation error)"
  491. (setq score (+ score (apropos-score-doc doc)))
  492. (substring doc 0 (string-match "\n" doc)))
  493. "(not documented)")))
  494. (and var-predicate
  495. (funcall var-predicate symbol)
  496. (if (setq doc (documentation-property
  497. symbol 'variable-documentation t))
  498. (progn
  499. (setq score (+ score (apropos-score-doc doc)))
  500. (substring doc 0
  501. (string-match "\n" doc)))))))
  502. (setcar (cdr (car p)) score)
  503. (setq p (cdr p))))
  504. (and (let ((apropos-multi-type do-all))
  505. (apropos-print t nil nil t))
  506. message
  507. (message "%s" message))))
  508. ;;;###autoload
  509. (defun apropos-documentation-property (symbol property raw)
  510. "Like (documentation-property SYMBOL PROPERTY RAW) but handle errors."
  511. (condition-case ()
  512. (let ((doc (documentation-property symbol property raw)))
  513. (if doc (substring doc 0 (string-match "\n" doc))
  514. "(not documented)"))
  515. (error "(error retrieving documentation)")))
  516. ;;;###autoload
  517. (defun apropos (pattern &optional do-all)
  518. "Show all meaningful Lisp symbols whose names match PATTERN.
  519. Symbols are shown if they are defined as functions, variables, or
  520. faces, or if they have nonempty property lists.
  521. PATTERN can be a word, a list of words (separated by spaces),
  522. or a regexp (using some regexp special characters). If it is a word,
  523. search for matches for that word as a substring. If it is a list of words,
  524. search for matches for any two (or more) of those words.
  525. With \\[universal-argument] prefix, or if `apropos-do-all' is non-nil,
  526. consider all symbols (if they match PATTERN).
  527. Returns list of symbols and documentation found."
  528. (interactive (list (apropos-read-pattern "symbol")
  529. current-prefix-arg))
  530. (apropos-parse-pattern pattern)
  531. (apropos-symbols-internal
  532. (apropos-internal apropos-regexp
  533. (and (not do-all)
  534. (not apropos-do-all)
  535. (lambda (symbol)
  536. (or (fboundp symbol)
  537. (boundp symbol)
  538. (facep symbol)
  539. (symbol-plist symbol)))))
  540. (or do-all apropos-do-all)))
  541. (defun apropos-library-button (sym)
  542. (if (null sym)
  543. "<nothing>"
  544. (let ((name (copy-sequence (symbol-name sym))))
  545. (make-text-button name nil
  546. 'type 'apropos-library
  547. 'face 'apropos-symbol
  548. 'apropos-symbol name)
  549. name)))
  550. ;;;###autoload
  551. (defun apropos-library (file)
  552. "List the variables and functions defined by library FILE.
  553. FILE should be one of the libraries currently loaded and should
  554. thus be found in `load-history'. If `apropos-do-all' is non-nil,
  555. the output includes key-bindings of commands."
  556. (interactive
  557. (let* ((libs (delq nil (mapcar 'car load-history)))
  558. (libs
  559. (nconc (delq nil
  560. (mapcar
  561. (lambda (l)
  562. (setq l (file-name-nondirectory l))
  563. (while
  564. (not (equal (setq l (file-name-sans-extension l))
  565. l)))
  566. l)
  567. libs))
  568. libs)))
  569. (list (completing-read "Describe library: " libs nil t))))
  570. (let ((symbols nil)
  571. ;; (autoloads nil)
  572. (provides nil)
  573. (requires nil)
  574. (lh-entry (assoc file load-history)))
  575. (unless lh-entry
  576. ;; `file' may be the "shortname".
  577. (let ((lh load-history)
  578. (re (concat "\\(?:\\`\\|[\\/]\\)" (regexp-quote file)
  579. "\\(\\.\\|\\'\\)")))
  580. (while (and lh (null lh-entry))
  581. (if (and (caar lh) (string-match re (caar lh)))
  582. (setq lh-entry (car lh))
  583. (setq lh (cdr lh)))))
  584. (unless lh-entry (error "Unknown library `%s'" file)))
  585. (dolist (x (cdr lh-entry))
  586. (pcase (car-safe x)
  587. ;; (autoload (push (cdr x) autoloads))
  588. (`require (push (cdr x) requires))
  589. (`provide (push (cdr x) provides))
  590. (_ (push (or (cdr-safe x) x) symbols))))
  591. (let ((apropos-pattern "")) ;Dummy binding for apropos-symbols-internal.
  592. (apropos-symbols-internal
  593. symbols apropos-do-all
  594. (concat
  595. (format-message
  596. "Library `%s' provides: %s\nand requires: %s"
  597. file
  598. (mapconcat 'apropos-library-button
  599. (or provides '(nil)) " and ")
  600. (mapconcat 'apropos-library-button
  601. (or requires '(nil)) " and ")))))))
  602. (defun apropos-symbols-internal (symbols keys &optional text)
  603. ;; Filter out entries that are marked as apropos-inhibit.
  604. (let ((all nil))
  605. (dolist (symbol symbols)
  606. (unless (get symbol 'apropos-inhibit)
  607. (push symbol all)))
  608. (setq symbols all))
  609. (let ((apropos-accumulator
  610. (mapcar
  611. (lambda (symbol)
  612. (let (doc properties)
  613. (list
  614. symbol
  615. (apropos-score-symbol symbol)
  616. (when (fboundp symbol)
  617. (if (setq doc (condition-case nil
  618. (documentation symbol t)
  619. (void-function
  620. "(alias for undefined function)")
  621. (error
  622. "(can't retrieve function documentation)")))
  623. (substring doc 0 (string-match "\n" doc))
  624. "(not documented)"))
  625. (when (boundp symbol)
  626. (apropos-documentation-property
  627. symbol 'variable-documentation t))
  628. (when (setq properties (symbol-plist symbol))
  629. (setq doc (list (car properties)))
  630. (while (setq properties (cdr (cdr properties)))
  631. (setq doc (cons (car properties) doc)))
  632. (mapconcat (lambda (p) (format "%s" p)) (nreverse doc) " "))
  633. (when (get symbol 'widget-type)
  634. (apropos-documentation-property
  635. symbol 'widget-documentation t))
  636. (when (facep symbol)
  637. (let ((alias (get symbol 'face-alias)))
  638. (if alias
  639. (if (facep alias)
  640. (format-message
  641. "%slias for the face `%s'."
  642. (if (get symbol 'obsolete-face) "Obsolete a" "A")
  643. alias)
  644. ;; Never happens in practice because fails
  645. ;; (facep symbol) test.
  646. "(alias for undefined face)")
  647. (apropos-documentation-property
  648. symbol 'face-documentation t))))
  649. (when (get symbol 'custom-group)
  650. (apropos-documentation-property
  651. symbol 'group-documentation t)))))
  652. symbols)))
  653. (apropos-print keys nil text)))
  654. ;;;###autoload
  655. (defun apropos-value (pattern &optional do-all)
  656. "Show all symbols whose value's printed representation matches PATTERN.
  657. PATTERN can be a word, a list of words (separated by spaces),
  658. or a regexp (using some regexp special characters). If it is a word,
  659. search for matches for that word as a substring. If it is a list of words,
  660. search for matches for any two (or more) of those words.
  661. With \\[universal-argument] prefix, or if `apropos-do-all' is non-nil, also looks
  662. at function definitions (arguments, documentation and body) and at the
  663. names and values of properties.
  664. Returns list of symbols and values found."
  665. (interactive (list (apropos-read-pattern "value")
  666. current-prefix-arg))
  667. (apropos-parse-pattern pattern)
  668. (or do-all (setq do-all apropos-do-all))
  669. (setq apropos-accumulator ())
  670. (let (f v p)
  671. (mapatoms
  672. (lambda (symbol)
  673. (setq f nil v nil p nil)
  674. (or (memq symbol '(apropos-regexp
  675. apropos-pattern apropos-all-words-regexp
  676. apropos-words apropos-all-words
  677. do-all apropos-accumulator
  678. symbol f v p))
  679. (setq v (apropos-value-internal 'boundp symbol 'symbol-value)))
  680. (if do-all
  681. (setq f (apropos-value-internal 'fboundp symbol 'symbol-function)
  682. p (apropos-format-plist symbol "\n " t)))
  683. (if (apropos-false-hit-str v)
  684. (setq v nil))
  685. (if (apropos-false-hit-str f)
  686. (setq f nil))
  687. (if (apropos-false-hit-str p)
  688. (setq p nil))
  689. (if (or f v p)
  690. (setq apropos-accumulator (cons (list symbol
  691. (+ (apropos-score-str f)
  692. (apropos-score-str v)
  693. (apropos-score-str p))
  694. f v p)
  695. apropos-accumulator))))))
  696. (let ((apropos-multi-type do-all))
  697. (apropos-print nil "\n----------------\n")))
  698. ;;;###autoload
  699. (defun apropos-documentation (pattern &optional do-all)
  700. "Show symbols whose documentation contains matches for PATTERN.
  701. PATTERN can be a word, a list of words (separated by spaces),
  702. or a regexp (using some regexp special characters). If it is a word,
  703. search for matches for that word as a substring. If it is a list of words,
  704. search for matches for any two (or more) of those words.
  705. Note that by default this command only searches in the file specified by
  706. `internal-doc-file-name'; i.e., the etc/DOC file. With \\[universal-argument] prefix,
  707. or if `apropos-do-all' is non-nil, it searches all currently defined
  708. documentation strings.
  709. Returns list of symbols and documentation found."
  710. ;; The doc used to say that DO-ALL includes key-bindings info in the
  711. ;; output, but I cannot see that that is true.
  712. (interactive (list (apropos-read-pattern "documentation")
  713. current-prefix-arg))
  714. (apropos-parse-pattern pattern)
  715. (or do-all (setq do-all apropos-do-all))
  716. (setq apropos-accumulator () apropos-files-scanned ())
  717. (let ((standard-input (get-buffer-create " apropos-temp"))
  718. (apropos-sort-by-scores apropos-documentation-sort-by-scores)
  719. f v sf sv)
  720. (unwind-protect
  721. (with-current-buffer standard-input
  722. (apropos-documentation-check-doc-file)
  723. (if do-all
  724. (mapatoms
  725. (lambda (symbol)
  726. (setq f (apropos-safe-documentation symbol)
  727. v (get symbol 'variable-documentation))
  728. (if (integerp v) (setq v))
  729. (setq f (apropos-documentation-internal f)
  730. v (apropos-documentation-internal v))
  731. (setq sf (apropos-score-doc f)
  732. sv (apropos-score-doc v))
  733. (if (or f v)
  734. (if (setq apropos-item
  735. (cdr (assq symbol apropos-accumulator)))
  736. (progn
  737. (if f
  738. (progn
  739. (setcar (nthcdr 1 apropos-item) f)
  740. (setcar apropos-item (+ (car apropos-item) sf))))
  741. (if v
  742. (progn
  743. (setcar (nthcdr 2 apropos-item) v)
  744. (setcar apropos-item (+ (car apropos-item) sv)))))
  745. (setq apropos-accumulator
  746. (cons (list symbol
  747. (+ (apropos-score-symbol symbol 2) sf sv)
  748. f v)
  749. apropos-accumulator)))))))
  750. (apropos-print nil "\n----------------\n" nil t))
  751. (kill-buffer standard-input))))
  752. (defun apropos-value-internal (predicate symbol function)
  753. (if (funcall predicate symbol)
  754. (progn
  755. (setq symbol (prin1-to-string (funcall function symbol)))
  756. (if (string-match apropos-regexp symbol)
  757. (progn
  758. (if apropos-match-face
  759. (put-text-property (match-beginning 0) (match-end 0)
  760. 'face apropos-match-face
  761. symbol))
  762. symbol)))))
  763. (defun apropos-documentation-internal (doc)
  764. (if (consp doc)
  765. (apropos-documentation-check-elc-file (car doc))
  766. (if (and doc
  767. (string-match apropos-all-words-regexp doc)
  768. (apropos-true-hit-doc doc))
  769. (when apropos-match-face
  770. (setq doc (substitute-command-keys (copy-sequence doc)))
  771. (if (or (string-match apropos-pattern-quoted doc)
  772. (string-match apropos-all-words-regexp doc))
  773. (put-text-property (match-beginning 0)
  774. (match-end 0)
  775. 'face apropos-match-face doc))
  776. doc))))
  777. (defun apropos-format-plist (pl sep &optional compare)
  778. (setq pl (symbol-plist pl))
  779. (let (p p-out)
  780. (while pl
  781. (setq p (format "%s %S" (car pl) (nth 1 pl)))
  782. (if (or (not compare) (string-match apropos-regexp p))
  783. (put-text-property 0 (length (symbol-name (car pl)))
  784. 'face 'apropos-property p)
  785. (setq p nil))
  786. (if p
  787. (progn
  788. (and compare apropos-match-face
  789. (put-text-property (match-beginning 0) (match-end 0)
  790. 'face apropos-match-face
  791. p))
  792. (setq p-out (concat p-out (if p-out sep) p))))
  793. (setq pl (nthcdr 2 pl)))
  794. p-out))
  795. ;; Finds all documentation related to APROPOS-REGEXP in internal-doc-file-name.
  796. (defun apropos-documentation-check-doc-file ()
  797. (let (type symbol (sepa 2) sepb doc)
  798. (insert ?\^_)
  799. (backward-char)
  800. (insert-file-contents (concat doc-directory internal-doc-file-name))
  801. (forward-char)
  802. (while (save-excursion
  803. (setq sepb (search-forward "\^_"))
  804. (not (eobp)))
  805. (beginning-of-line 2)
  806. (if (save-restriction
  807. (narrow-to-region (point) (1- sepb))
  808. (re-search-forward apropos-all-words-regexp nil t))
  809. (progn
  810. (goto-char (1+ sepa))
  811. (setq type (if (eq ?F (preceding-char))
  812. 2 ; function documentation
  813. 3) ; variable documentation
  814. symbol (read)
  815. doc (buffer-substring (1+ (point)) (1- sepb)))
  816. (when (and (apropos-true-hit-doc doc)
  817. ;; The DOC file lists all built-in funcs and vars.
  818. ;; If any are not currently bound, they can
  819. ;; only be platform-specific stuff (eg NS) not
  820. ;; in use on the current platform.
  821. ;; So we exclude them.
  822. (cond ((= 3 type) (boundp symbol))
  823. ((= 2 type) (fboundp symbol))))
  824. (or (and (setq apropos-item (assq symbol apropos-accumulator))
  825. (setcar (cdr apropos-item)
  826. (apropos-score-doc doc)))
  827. (setq apropos-item (list symbol
  828. (+ (apropos-score-symbol symbol 2)
  829. (apropos-score-doc doc))
  830. nil nil)
  831. apropos-accumulator (cons apropos-item
  832. apropos-accumulator)))
  833. (when apropos-match-face
  834. (setq doc (substitute-command-keys doc))
  835. (if (or (string-match apropos-pattern-quoted doc)
  836. (string-match apropos-all-words-regexp doc))
  837. (put-text-property (match-beginning 0)
  838. (match-end 0)
  839. 'face apropos-match-face doc)))
  840. (setcar (nthcdr type apropos-item) doc))))
  841. (setq sepa (goto-char sepb)))))
  842. (defun apropos-documentation-check-elc-file (file)
  843. (if (member file apropos-files-scanned)
  844. nil
  845. (let (symbol doc beg end this-is-a-variable)
  846. (setq apropos-files-scanned (cons file apropos-files-scanned))
  847. (erase-buffer)
  848. (insert-file-contents file)
  849. (while (search-forward "\n#@" nil t)
  850. ;; Read the comment length, and advance over it.
  851. (setq end (read)
  852. beg (1+ (point))
  853. end (+ (point) end -1))
  854. (forward-char)
  855. (if (save-restriction
  856. ;; match ^ and $ relative to doc string
  857. (narrow-to-region beg end)
  858. (re-search-forward apropos-all-words-regexp nil t))
  859. (progn
  860. (goto-char (+ end 2))
  861. (setq doc (buffer-substring beg end)
  862. end (- (match-end 0) beg)
  863. beg (- (match-beginning 0) beg))
  864. (when (apropos-true-hit-doc doc)
  865. (setq this-is-a-variable (looking-at "(def\\(var\\|const\\) ")
  866. symbol (progn
  867. (skip-chars-forward "(a-z")
  868. (forward-char)
  869. (read))
  870. symbol (if (consp symbol)
  871. (nth 1 symbol)
  872. symbol))
  873. (if (if this-is-a-variable
  874. (get symbol 'variable-documentation)
  875. (and (fboundp symbol) (apropos-safe-documentation symbol)))
  876. (progn
  877. (or (and (setq apropos-item (assq symbol apropos-accumulator))
  878. (setcar (cdr apropos-item)
  879. (+ (cadr apropos-item) (apropos-score-doc doc))))
  880. (setq apropos-item (list symbol
  881. (+ (apropos-score-symbol symbol 2)
  882. (apropos-score-doc doc))
  883. nil nil)
  884. apropos-accumulator (cons apropos-item
  885. apropos-accumulator)))
  886. (when apropos-match-face
  887. (setq doc (substitute-command-keys doc))
  888. (if (or (string-match apropos-pattern-quoted doc)
  889. (string-match apropos-all-words-regexp doc))
  890. (put-text-property (match-beginning 0)
  891. (match-end 0)
  892. 'face apropos-match-face doc)))
  893. (setcar (nthcdr (if this-is-a-variable 3 2)
  894. apropos-item)
  895. doc))))))))))
  896. (defun apropos-safe-documentation (function)
  897. "Like `documentation', except it avoids calling `get_doc_string'.
  898. Will return nil instead."
  899. (while (and function (symbolp function))
  900. (setq function (symbol-function function)))
  901. (if (eq (car-safe function) 'macro)
  902. (setq function (cdr function)))
  903. (setq function (if (byte-code-function-p function)
  904. (if (> (length function) 4)
  905. (aref function 4))
  906. (if (autoloadp function)
  907. (nth 2 function)
  908. (if (eq (car-safe function) 'lambda)
  909. (if (stringp (nth 2 function))
  910. (nth 2 function)
  911. (if (stringp (nth 3 function))
  912. (nth 3 function)))))))
  913. (if (integerp function)
  914. nil
  915. function))
  916. (defcustom apropos-compact-layout nil
  917. "If non-nil, use a single line per binding."
  918. :type 'boolean)
  919. (defun apropos-print (do-keys spacing &optional text nosubst)
  920. "Output result of apropos searching into buffer `*Apropos*'.
  921. The value of `apropos-accumulator' is the list of items to output.
  922. Each element should have the format
  923. (SYMBOL SCORE FN-DOC VAR-DOC [PLIST-DOC WIDGET-DOC FACE-DOC GROUP-DOC]).
  924. The return value is the list that was in `apropos-accumulator', sorted
  925. alphabetically by symbol name; but this function also sets
  926. `apropos-accumulator' to nil before returning.
  927. If SPACING is non-nil, it should be a string; separate items with that string.
  928. If non-nil, TEXT is a string that will be printed as a heading."
  929. (if (null apropos-accumulator)
  930. (message "No apropos matches for `%s'" apropos-pattern)
  931. (setq apropos-accumulator
  932. (sort apropos-accumulator
  933. (lambda (a b)
  934. (if apropos-sort-by-scores
  935. (or (> (cadr a) (cadr b))
  936. (and (= (cadr a) (cadr b))
  937. (string-lessp (car a) (car b))))
  938. (string-lessp (car a) (car b))))))
  939. (with-output-to-temp-buffer "*Apropos*"
  940. (let ((p apropos-accumulator)
  941. (old-buffer (current-buffer))
  942. (inhibit-read-only t)
  943. (button-end 0)
  944. symbol item)
  945. (set-buffer standard-output)
  946. (apropos-mode)
  947. (insert (substitute-command-keys "Type \\[apropos-follow] on ")
  948. (if apropos-multi-type "a type label" "an entry")
  949. " to view its full documentation.\n\n")
  950. (if text (insert text "\n\n"))
  951. (dolist (apropos-item p)
  952. (when (and spacing (not (bobp)))
  953. (princ spacing))
  954. (setq symbol (car apropos-item))
  955. ;; Insert dummy score element for backwards compatibility with 21.x
  956. ;; apropos-item format.
  957. (if (not (numberp (cadr apropos-item)))
  958. (setq apropos-item
  959. (cons (car apropos-item)
  960. (cons nil (cdr apropos-item)))))
  961. (when (= (point) button-end) (terpri))
  962. (insert-text-button (symbol-name symbol)
  963. 'type 'apropos-symbol
  964. 'skip apropos-multi-type
  965. 'face 'apropos-symbol)
  966. (setq button-end (point))
  967. (if (and (eq apropos-sort-by-scores 'verbose)
  968. (cadr apropos-item))
  969. (insert " (" (number-to-string (cadr apropos-item)) ") "))
  970. ;; Calculate key-bindings if we want them.
  971. (unless apropos-compact-layout
  972. (and do-keys
  973. (commandp symbol)
  974. (not (eq symbol 'self-insert-command))
  975. (indent-to 30 1)
  976. (if (let ((keys
  977. (with-current-buffer old-buffer
  978. (where-is-internal symbol)))
  979. filtered)
  980. ;; Copy over the list of key sequences,
  981. ;; omitting any that contain a buffer or a frame.
  982. ;; FIXME: Why omit keys that contain buffers and
  983. ;; frames? This looks like a bad workaround rather
  984. ;; than a proper fix. Does anybody know what problem
  985. ;; this is trying to address? --Stef
  986. (dolist (key keys)
  987. (let ((i 0)
  988. loser)
  989. (while (< i (length key))
  990. (if (or (framep (aref key i))
  991. (bufferp (aref key i)))
  992. (setq loser t))
  993. (setq i (1+ i)))
  994. (or loser
  995. (push key filtered))))
  996. (setq item filtered))
  997. ;; Convert the remaining keys to a string and insert.
  998. (insert
  999. (mapconcat
  1000. (lambda (key)
  1001. (setq key (condition-case ()
  1002. (key-description key)
  1003. (error)))
  1004. (put-text-property 0 (length key)
  1005. 'face 'apropos-keybinding
  1006. key)
  1007. key)
  1008. item ", "))
  1009. (insert "M-x ... RET")
  1010. (put-text-property (- (point) 11) (- (point) 8)
  1011. 'face 'apropos-keybinding)
  1012. (put-text-property (- (point) 3) (point)
  1013. 'face 'apropos-keybinding)))
  1014. (terpri))
  1015. (apropos-print-doc 2
  1016. (if (commandp symbol)
  1017. 'apropos-command
  1018. (if (macrop symbol)
  1019. 'apropos-macro
  1020. 'apropos-function))
  1021. (not nosubst))
  1022. (apropos-print-doc 3
  1023. (if (custom-variable-p symbol)
  1024. 'apropos-user-option
  1025. 'apropos-variable)
  1026. (not nosubst))
  1027. (apropos-print-doc 7 'apropos-group t)
  1028. (apropos-print-doc 6 'apropos-face t)
  1029. (apropos-print-doc 5 'apropos-widget t)
  1030. (apropos-print-doc 4 'apropos-plist nil))
  1031. (set (make-local-variable 'truncate-partial-width-windows) t)
  1032. (set (make-local-variable 'truncate-lines) t))))
  1033. (prog1 apropos-accumulator
  1034. (setq apropos-accumulator ()))) ; permit gc
  1035. (defun apropos-print-doc (i type do-keys)
  1036. (let ((doc (nth i apropos-item)))
  1037. (when (stringp doc)
  1038. (if apropos-compact-layout
  1039. (insert (propertize "\t" 'display '(space :align-to 32)) " ")
  1040. (insert " "))
  1041. (if apropos-multi-type
  1042. (let ((button-face (button-type-get type 'face)))
  1043. (unless (consp button-face)
  1044. (setq button-face (list button-face)))
  1045. (insert-text-button
  1046. (if apropos-compact-layout
  1047. (format "<%s>" (button-type-get type 'apropos-short-label))
  1048. (button-type-get type 'apropos-label))
  1049. 'type type
  1050. 'apropos-symbol (car apropos-item))
  1051. (insert (if apropos-compact-layout " " ": ")))
  1052. ;; If the query is only for a single type, there's no point
  1053. ;; writing it over and over again. Insert a blank button, and
  1054. ;; put the 'apropos-label property there (needed by
  1055. ;; apropos-symbol-button-display-help).
  1056. (insert-text-button
  1057. " " 'type type 'skip t
  1058. 'face 'default 'apropos-symbol (car apropos-item)))
  1059. (let ((opoint (point))
  1060. (ocol (current-column)))
  1061. (cond ((equal doc "")
  1062. (setq doc "(not documented)"))
  1063. (do-keys
  1064. (setq doc (substitute-command-keys doc))))
  1065. (insert doc)
  1066. (if (equal doc "(not documented)")
  1067. (put-text-property opoint (point) 'font-lock-face 'shadow))
  1068. ;; The labeling buttons might make the line too long, so fill it if
  1069. ;; necessary.
  1070. (let ((fill-column (+ 5 (if (integerp emacs-lisp-docstring-fill-column)
  1071. emacs-lisp-docstring-fill-column
  1072. fill-column)))
  1073. (fill-prefix (make-string ocol ?\s)))
  1074. (fill-region opoint (point) nil t)))
  1075. (or (bolp) (terpri)))))
  1076. (defun apropos-follow ()
  1077. "Invokes any button at point, otherwise invokes the nearest label button."
  1078. (interactive)
  1079. (button-activate
  1080. (or (apropos-next-label-button (line-beginning-position))
  1081. (error "There is nothing to follow here"))))
  1082. (defun apropos-describe-plist (symbol)
  1083. "Display a pretty listing of SYMBOL's plist."
  1084. (help-setup-xref (list 'apropos-describe-plist symbol)
  1085. (called-interactively-p 'interactive))
  1086. (with-help-window (help-buffer)
  1087. (set-buffer standard-output)
  1088. (princ "Symbol ")
  1089. (prin1 symbol)
  1090. (princ (substitute-command-keys "'s plist is\n ("))
  1091. (put-text-property (+ (point-min) 7) (- (point) 14)
  1092. 'face 'apropos-symbol)
  1093. (insert (apropos-format-plist symbol "\n "))
  1094. (princ ")")))
  1095. (provide 'apropos)
  1096. ;;; apropos.el ends here