diff options
| author | Karl Heuer | 1995-12-19 22:01:53 +0000 |
|---|---|---|
| committer | Karl Heuer | 1995-12-19 22:01:53 +0000 |
| commit | 26a4a227ac02f64280967676cf3e60de32d023cb (patch) | |
| tree | 811b8abdc156c9272a62018c938bc9ac45be6bc7 | |
| parent | ef818feb0df318b44ad717752ab729b58dd0ae59 (diff) | |
| download | emacs-26a4a227ac02f64280967676cf3e60de32d023cb.tar.gz emacs-26a4a227ac02f64280967676cf3e60de32d023cb.zip | |
(apropos-match-face): Use `secondary-selection' rather
than `highlight' to distinguish it from mouse-face highlighting of
hyperlinks.
(apropos-mode-map): Rename from `apropos-local-map'.
(apropos-mode): Set it rather than have a local-map that made RET
locally unusable when copied to other buffer.
(apropos-print): Use it. When there is only one property, show
what it is. Remove superfluous `save-excursion', thus making help
commands' return-message be correct.
(apropos-print, apropos-describe-plist): `print-help-return-message'
like help commands.
| -rw-r--r-- | lisp/apropos.el | 240 |
1 files changed, 127 insertions, 113 deletions
diff --git a/lisp/apropos.el b/lisp/apropos.el index 3d20b6e2981..ef26b9878fa 100644 --- a/lisp/apropos.el +++ b/lisp/apropos.el | |||
| @@ -81,18 +81,18 @@ text-property list for efficiency.") | |||
| 81 | "*Face for property name in apropos output or `nil'. | 81 | "*Face for property name in apropos output or `nil'. |
| 82 | This looks good, but slows down the commands several times.") | 82 | This looks good, but slows down the commands several times.") |
| 83 | 83 | ||
| 84 | (defvar apropos-match-face (if window-system 'highlight) | 84 | (defvar apropos-match-face (if window-system 'secondary-selection) |
| 85 | "*Face for matching part in apropos-documentation/value output or `nil'. | 85 | "*Face for matching part in apropos-documentation/value output or `nil'. |
| 86 | This looks good, but slows down the commands several times.") | 86 | This looks good, but slows down the commands several times.") |
| 87 | 87 | ||
| 88 | 88 | ||
| 89 | (defvar apropos-local-map | 89 | (defvar apropos-mode-map |
| 90 | (let ((map (make-sparse-keymap))) | 90 | (let ((map (make-sparse-keymap))) |
| 91 | (define-key map "\C-m" 'apropos-follow) | 91 | (define-key map "\C-m" 'apropos-follow) |
| 92 | (define-key map [mouse-2] 'apropos-mouse-follow) | 92 | (define-key map [mouse-2] 'apropos-mouse-follow) |
| 93 | (define-key map [down-mouse-2] nil) | 93 | (define-key map [down-mouse-2] nil) |
| 94 | map) | 94 | map) |
| 95 | "Local map active when displaying apropos output.") | 95 | "Keymap used in Apropos mode.") |
| 96 | 96 | ||
| 97 | 97 | ||
| 98 | (defvar apropos-regexp nil | 98 | (defvar apropos-regexp nil |
| @@ -107,6 +107,17 @@ This looks good, but slows down the commands several times.") | |||
| 107 | (defvar apropos-item () | 107 | (defvar apropos-item () |
| 108 | "Current item in or for apropos-accumulator.") | 108 | "Current item in or for apropos-accumulator.") |
| 109 | 109 | ||
| 110 | (defun apropos-mode () | ||
| 111 | "Major mode for following hyperlinks in output of apropos commands. | ||
| 112 | |||
| 113 | \\{apropos-mode-map}" | ||
| 114 | (interactive) | ||
| 115 | (kill-all-local-variables) | ||
| 116 | (use-local-map apropos-mode-map) | ||
| 117 | (setq major-mode 'apropos-mode | ||
| 118 | mode-name "Apropos")) | ||
| 119 | |||
| 120 | |||
| 110 | ;; For auld lang syne: | 121 | ;; For auld lang syne: |
| 111 | ;;;###autoload | 122 | ;;;###autoload |
| 112 | (fset 'command-apropos 'apropos-command) | 123 | (fset 'command-apropos 'apropos-command) |
| @@ -122,7 +133,7 @@ variables." | |||
| 122 | "(regexp): ")) | 133 | "(regexp): ")) |
| 123 | current-prefix-arg)) | 134 | current-prefix-arg)) |
| 124 | (let ((message | 135 | (let ((message |
| 125 | (let ((standard-output (get-buffer-create "*Help*"))) | 136 | (let ((standard-output (get-buffer-create "*Apropos*"))) |
| 126 | (print-help-return-message 'identity)))) | 137 | (print-help-return-message 'identity)))) |
| 127 | (or do-all (setq do-all apropos-do-all)) | 138 | (or do-all (setq do-all apropos-do-all)) |
| 128 | (setq apropos-accumulator | 139 | (setq apropos-accumulator |
| @@ -186,9 +197,9 @@ Returns list of symbols and documentation found." | |||
| 186 | (string-match "\n" doc)) | 197 | (string-match "\n" doc)) |
| 187 | "(not documented)")) | 198 | "(not documented)")) |
| 188 | (if (setq doc (symbol-plist symbol)) | 199 | (if (setq doc (symbol-plist symbol)) |
| 189 | (if (eq (setq doc (/ (length doc) 2)) 1) | 200 | (if (eq (/ (length doc) 2) 1) |
| 190 | "1 property" | 201 | (format "1 property (%s)" (car doc)) |
| 191 | (concat doc " properties"))))) | 202 | (concat (/ (length doc) 2) " properties"))))) |
| 192 | (setq p (cdr p))))) | 203 | (setq p (cdr p))))) |
| 193 | nil)) | 204 | nil)) |
| 194 | 205 | ||
| @@ -220,7 +231,7 @@ Returns list of symbols and values found." | |||
| 220 | 231 | ||
| 221 | ;;;###autoload | 232 | ;;;###autoload |
| 222 | (defun apropos-documentation (apropos-regexp &optional do-all) | 233 | (defun apropos-documentation (apropos-regexp &optional do-all) |
| 223 | "Show symbols whose names or documentation contain matches for REGEXP. | 234 | "Show symbols whose documentation contain matches for REGEXP. |
| 224 | With optional prefix ARG or if `apropos-do-all' is non-nil, also use | 235 | With optional prefix ARG or if `apropos-do-all' is non-nil, also use |
| 225 | documentation that is not stored in the documentation file and show key | 236 | documentation that is not stored in the documentation file and show key |
| 226 | bindings. | 237 | bindings. |
| @@ -238,11 +249,10 @@ Returns list of symbols and documentation found." | |||
| 238 | (mapatoms | 249 | (mapatoms |
| 239 | (lambda (symbol) | 250 | (lambda (symbol) |
| 240 | (setq f (apropos-safe-documentation symbol) | 251 | (setq f (apropos-safe-documentation symbol) |
| 241 | v (get symbol 'variable-documentation) | 252 | v (get symbol 'variable-documentation)) |
| 242 | v (if (integerp v) nil v)) | 253 | (if (integerp v) (setq v)) |
| 243 | (or (string-match apropos-regexp (symbol-name symbol)) | 254 | (setq f (apropos-documentation-internal f) |
| 244 | (setq f (apropos-documentation-internal f) | 255 | v (apropos-documentation-internal v)) |
| 245 | v (apropos-documentation-internal v))) | ||
| 246 | (if (or f v) | 256 | (if (or f v) |
| 247 | (if (setq apropos-item | 257 | (if (setq apropos-item |
| 248 | (cdr (assq symbol apropos-accumulator))) | 258 | (cdr (assq symbol apropos-accumulator))) |
| @@ -254,7 +264,7 @@ Returns list of symbols and documentation found." | |||
| 254 | (setq apropos-accumulator | 264 | (setq apropos-accumulator |
| 255 | (cons (list symbol f v) | 265 | (cons (list symbol f v) |
| 256 | apropos-accumulator))))))) | 266 | apropos-accumulator))))))) |
| 257 | (apropos-print do-all nil t)) | 267 | (apropos-print nil nil t)) |
| 258 | (kill-buffer standard-input)))) | 268 | (kill-buffer standard-input)))) |
| 259 | 269 | ||
| 260 | 270 | ||
| @@ -307,57 +317,64 @@ Returns list of symbols and documentation found." | |||
| 307 | ;; Finds all documentation related to APROPOS-REGEXP in internal-doc-file-name. | 317 | ;; Finds all documentation related to APROPOS-REGEXP in internal-doc-file-name. |
| 308 | 318 | ||
| 309 | (defun apropos-documentation-check-doc-file () | 319 | (defun apropos-documentation-check-doc-file () |
| 310 | (let (type symbol beg end) | 320 | (let (type symbol (sepa 2) sepb beg end) |
| 321 | (insert ?\^_) | ||
| 322 | (backward-char) | ||
| 311 | (insert-file-contents (concat doc-directory internal-doc-file-name)) | 323 | (insert-file-contents (concat doc-directory internal-doc-file-name)) |
| 312 | (while (re-search-forward apropos-regexp nil t) | 324 | (forward-char) |
| 313 | (setq beg (match-beginning 0) | 325 | (while (save-excursion |
| 314 | end (point)) | 326 | (setq sepb (search-forward "\^_")) |
| 315 | (search-backward "\C-_") | 327 | (not (eobp))) |
| 316 | (if (> (point) beg) | 328 | (beginning-of-line 2) |
| 317 | () | 329 | (if (save-restriction |
| 318 | (or (setq type (if (eq ?F (char-after (1+ (point)))) | 330 | (narrow-to-region (point) (1- sepb)) |
| 319 | 1 ;function documentation | 331 | (re-search-forward apropos-regexp nil t)) |
| 320 | 2) ;variable documentation | 332 | (progn |
| 321 | symbol (prog2 | 333 | (setq beg (match-beginning 0) |
| 322 | (forward-char 2) | 334 | end (point)) |
| 323 | (read)) | 335 | (goto-char (1+ sepa)) |
| 324 | beg (- beg (point) 1) | 336 | (or (setq type (if (eq ?F (preceding-char)) |
| 325 | end (- end (point) 1) | 337 | 1 ; function documentation |
| 326 | doc (buffer-substring | 338 | 2) ; variable documentation |
| 327 | (1+ (point)) | 339 | symbol (read) |
| 328 | (if (search-forward "\C-_" nil 'move) | 340 | beg (- beg (point) 1) |
| 329 | (1- (point)) | 341 | end (- end (point) 1) |
| 330 | (point))) | 342 | doc (buffer-substring (1+ (point)) (1- sepb)) |
| 331 | apropos-item (assq symbol apropos-accumulator)) | 343 | apropos-item (assq symbol apropos-accumulator)) |
| 332 | (setq apropos-item (list symbol nil nil) | 344 | (setq apropos-item (list symbol nil nil) |
| 333 | apropos-accumulator (cons apropos-item apropos-accumulator))) | 345 | apropos-accumulator (cons apropos-item |
| 334 | (and apropos-match-face | 346 | apropos-accumulator))) |
| 335 | (>= beg 0) | 347 | (if apropos-match-face |
| 336 | (put-text-property beg end 'face apropos-match-face doc)) | 348 | (put-text-property beg end 'face apropos-match-face doc)) |
| 337 | (setcar (nthcdr type apropos-item) doc))))) | 349 | (setcar (nthcdr type apropos-item) doc))) |
| 350 | (setq sepa (goto-char sepb))))) | ||
| 338 | 351 | ||
| 339 | (defun apropos-documentation-check-elc-file (file) | 352 | (defun apropos-documentation-check-elc-file (file) |
| 340 | (if (member file apropos-files-scanned) | 353 | (if (member file apropos-files-scanned) |
| 341 | nil | 354 | nil |
| 342 | (let (symbol doc beg end end1 this-is-a-variable) | 355 | (let (symbol doc beg end this-is-a-variable) |
| 343 | (setq apropos-files-scanned (cons file apropos-files-scanned)) | 356 | (setq apropos-files-scanned (cons file apropos-files-scanned)) |
| 344 | (erase-buffer) | 357 | (erase-buffer) |
| 345 | (insert-file-contents file) | 358 | (insert-file-contents file) |
| 346 | (while (search-forward "\n#@" nil t) | 359 | (while (search-forward "\n#@" nil t) |
| 347 | ;; Read the comment length, and advance over it. | 360 | ;; Read the comment length, and advance over it. |
| 348 | (setq end (read) | 361 | (setq end (read) |
| 349 | beg (point) | 362 | beg (1+ (point)) |
| 350 | end (+ (point) end 1)) | 363 | end (+ (point) end -1)) |
| 351 | (if (re-search-forward apropos-regexp end t) | 364 | (forward-char) |
| 365 | (if (save-restriction | ||
| 366 | ;; match ^ and $ relative to doc string | ||
| 367 | (narrow-to-region beg end) | ||
| 368 | (re-search-forward apropos-regexp nil t)) | ||
| 352 | (progn | 369 | (progn |
| 353 | (goto-char end) | 370 | (goto-char (+ end 2)) |
| 354 | (setq doc (buffer-substring (1+ beg) (- end 2)) | 371 | (setq doc (buffer-substring beg end) |
| 355 | end1 (- (match-end 0) beg 1) | 372 | end (- (match-end 0) beg) |
| 356 | beg (- (match-beginning 0) beg 1) | 373 | beg (- (match-beginning 0) beg) |
| 357 | this-is-a-variable (looking-at "(defvar\\|(defconst") | 374 | this-is-a-variable (looking-at "(def\\(var\\|const\\) ") |
| 358 | symbol (progn | 375 | symbol (progn |
| 359 | (skip-chars-forward "(a-z") | 376 | (skip-chars-forward "(a-z") |
| 360 | (forward-char 1) | 377 | (forward-char) |
| 361 | (read)) | 378 | (read)) |
| 362 | symbol (if (consp symbol) | 379 | symbol (if (consp symbol) |
| 363 | (nth 1 symbol) | 380 | (nth 1 symbol) |
| @@ -371,12 +388,11 @@ Returns list of symbols and documentation found." | |||
| 371 | apropos-accumulator (cons apropos-item | 388 | apropos-accumulator (cons apropos-item |
| 372 | apropos-accumulator))) | 389 | apropos-accumulator))) |
| 373 | (if apropos-match-face | 390 | (if apropos-match-face |
| 374 | (put-text-property beg end1 'face apropos-match-face | 391 | (put-text-property beg end 'face apropos-match-face |
| 375 | doc)) | 392 | doc)) |
| 376 | (setcar (nthcdr (if this-is-a-variable 2 1) | 393 | (setcar (nthcdr (if this-is-a-variable 2 1) |
| 377 | apropos-item) | 394 | apropos-item) |
| 378 | doc))))) | 395 | doc))))))))) |
| 379 | (goto-char end))))) | ||
| 380 | 396 | ||
| 381 | 397 | ||
| 382 | 398 | ||
| @@ -416,7 +432,7 @@ found." | |||
| 416 | (funcall doc-fn apropos-accumulator)) | 432 | (funcall doc-fn apropos-accumulator)) |
| 417 | (setq apropos-accumulator | 433 | (setq apropos-accumulator |
| 418 | (sort apropos-accumulator (lambda (a b) | 434 | (sort apropos-accumulator (lambda (a b) |
| 419 | (string-lessp (car a) (car b))))) | 435 | (string-lessp (car a) (car b))))) |
| 420 | (and apropos-label-face | 436 | (and apropos-label-face |
| 421 | (symbolp apropos-label-face) | 437 | (symbolp apropos-label-face) |
| 422 | (setq apropos-label-face `(face ,apropos-label-face | 438 | (setq apropos-label-face `(face ,apropos-label-face |
| @@ -425,60 +441,59 @@ found." | |||
| 425 | (let ((p apropos-accumulator) | 441 | (let ((p apropos-accumulator) |
| 426 | (old-buffer (current-buffer)) | 442 | (old-buffer (current-buffer)) |
| 427 | symbol item point1 point2) | 443 | symbol item point1 point2) |
| 428 | (save-excursion | 444 | (set-buffer standard-output) |
| 429 | (set-buffer standard-output) | 445 | (apropos-mode) |
| 430 | (if window-system | 446 | (if window-system |
| 431 | (insert (substitute-command-keys | 447 | (insert (substitute-command-keys |
| 432 | "Click \\<apropos-local-map>\\[apropos-mouse-follow] to get full documentation.\n"))) | 448 | "Click \\[apropos-mouse-follow] to get full documentation.\n"))) |
| 433 | (insert (substitute-command-keys | 449 | (insert (substitute-command-keys |
| 434 | "In this buffer, type \\<apropos-local-map>\\[apropos-follow] to get full documentation.\n\n")) | 450 | "In this buffer, type \\[apropos-follow] to get full documentation.\n\n")) |
| 435 | (use-local-map apropos-local-map) | 451 | (while (consp p) |
| 436 | (while (consp p) | 452 | (or (not spacing) (bobp) (terpri)) |
| 437 | (or (not spacing) (bobp) (terpri)) | 453 | (setq apropos-item (car p) |
| 438 | (setq apropos-item (car p) | 454 | symbol (car apropos-item) |
| 439 | symbol (car apropos-item) | 455 | p (cdr p) |
| 440 | p (cdr p) | 456 | point1 (point)) |
| 441 | point1 (point)) | 457 | (princ symbol) ; print symbol name |
| 442 | (princ symbol) ;print symbol name | 458 | (setq point2 (point)) |
| 443 | (setq point2 (point)) | 459 | ;; don't calculate key-bindings unless needed |
| 444 | ;; don't calculate key-bindings unless needed | 460 | (and do-keys |
| 445 | (and do-keys | 461 | (commandp symbol) |
| 446 | (commandp symbol) | 462 | (indent-to 30 1) |
| 447 | (indent-to 30 1) | 463 | (insert |
| 448 | (insert | 464 | (if (setq item (save-excursion |
| 449 | (if (setq item (save-excursion | 465 | (set-buffer old-buffer) |
| 450 | (set-buffer old-buffer) | 466 | (where-is-internal symbol))) |
| 451 | (where-is-internal symbol))) | 467 | (mapconcat |
| 452 | (mapconcat | 468 | (if apropos-keybinding-face |
| 453 | (if apropos-keybinding-face | 469 | (lambda (key) |
| 454 | (lambda (key) | 470 | (setq key (key-description key)) |
| 455 | (setq key (key-description key)) | 471 | (put-text-property 0 (length key) |
| 456 | (put-text-property 0 (length key) | 472 | 'face apropos-keybinding-face |
| 457 | 'face apropos-keybinding-face | 473 | key) |
| 458 | key) | 474 | key) |
| 459 | key) | 475 | 'key-description) |
| 460 | 'key-description) | 476 | item ", ") |
| 461 | item ", ") | 477 | "(not bound to any keys)"))) |
| 462 | "(not bound to any keys)"))) | 478 | (terpri) |
| 463 | (terpri) | 479 | ;; only now so we don't propagate text attributes all over |
| 464 | ;; only now so we don't propagate text attributes all over | 480 | (put-text-property point1 point2 'item |
| 465 | (put-text-property point1 point2 'item | 481 | (if (eval `(or ,@(cdr apropos-item))) |
| 466 | (if (eval `(or ,@(cdr apropos-item))) | 482 | (car apropos-item) |
| 467 | (car apropos-item) | 483 | apropos-item)) |
| 468 | apropos-item)) | 484 | (if apropos-symbol-face |
| 469 | (if apropos-symbol-face | 485 | (put-text-property point1 point2 'face apropos-symbol-face)) |
| 470 | (put-text-property point1 point2 'face apropos-symbol-face)) | 486 | (apropos-print-doc 'describe-function 1 |
| 471 | (apropos-print-doc 'describe-function 1 | 487 | (if (commandp symbol) |
| 472 | (if (commandp symbol) | 488 | "Command" |
| 473 | "Command" | 489 | (if (apropos-macrop symbol) |
| 474 | (if (apropos-macrop symbol) | 490 | "Macro" |
| 475 | "Macro" | 491 | "Function")) |
| 476 | "Function")) | 492 | do-keys) |
| 477 | do-keys) | 493 | (apropos-print-doc 'describe-variable 2 |
| 478 | (apropos-print-doc 'describe-variable 2 | 494 | "Variable" do-keys) |
| 479 | "Variable" do-keys) | 495 | (apropos-print-doc 'apropos-describe-plist 3 |
| 480 | (apropos-print-doc 'apropos-describe-plist 3 | 496 | "Plist" nil))))) |
| 481 | "Plist" nil)))))) | ||
| 482 | (prog1 apropos-accumulator | 497 | (prog1 apropos-accumulator |
| 483 | (setq apropos-accumulator ()))) ; permit gc | 498 | (setq apropos-accumulator ()))) ; permit gc |
| 484 | 499 | ||
| @@ -511,7 +526,7 @@ found." | |||
| 511 | 526 | ||
| 512 | (defun apropos-mouse-follow (event) | 527 | (defun apropos-mouse-follow (event) |
| 513 | (interactive "e") | 528 | (interactive "e") |
| 514 | (let ((other (if (eq (current-buffer) (get-buffer "*Help*")) | 529 | (let ((other (if (eq (current-buffer) (get-buffer "*Apropos*")) |
| 515 | () | 530 | () |
| 516 | (current-buffer)))) | 531 | (current-buffer)))) |
| 517 | (save-excursion | 532 | (save-excursion |
| @@ -520,8 +535,6 @@ found." | |||
| 520 | (or (and (not (eobp)) (get-text-property (point) 'mouse-face)) | 535 | (or (and (not (eobp)) (get-text-property (point) 'mouse-face)) |
| 521 | (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face)) | 536 | (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face)) |
| 522 | (error "There is nothing to follow here")) | 537 | (error "There is nothing to follow here")) |
| 523 | ;; somehow when clicking with the point in another window, undoes badly | ||
| 524 | (undo-boundary) | ||
| 525 | (apropos-follow other)))) | 538 | (apropos-follow other)))) |
| 526 | 539 | ||
| 527 | 540 | ||
| @@ -557,6 +570,7 @@ found." | |||
| 557 | (if apropos-symbol-face | 570 | (if apropos-symbol-face |
| 558 | (put-text-property 8 (- (point) 14) 'face apropos-symbol-face)) | 571 | (put-text-property 8 (- (point) 14) 'face apropos-symbol-face)) |
| 559 | (insert (apropos-format-plist symbol "\n ")) | 572 | (insert (apropos-format-plist symbol "\n ")) |
| 560 | (princ ")"))) | 573 | (princ ")") |
| 574 | (print-help-return-message))) | ||
| 561 | 575 | ||
| 562 | ;;; apropos.el ends here | 576 | ;;; apropos.el ends here |