apropos.el 43 KB

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