aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/help-mode.el
diff options
context:
space:
mode:
authorStefan Monnier2009-11-15 05:16:51 +0000
committerStefan Monnier2009-11-15 05:16:51 +0000
commit589888fe21ff05f4dfd5e4de576dfc833f0d01dc (patch)
tree103ffad6ee2dd7fc3123c2b13d74aa932521d862 /lisp/help-mode.el
parent8d720a006679b8f443757cb8c8cc32fe676a4fb7 (diff)
downloademacs-589888fe21ff05f4dfd5e4de576dfc833f0d01dc.tar.gz
emacs-589888fe21ff05f4dfd5e4de576dfc833f0d01dc.zip
(help-make-xrefs): Undo the last revert, and replace it with a real fix.
Diffstat (limited to 'lisp/help-mode.el')
-rw-r--r--lisp/help-mode.el326
1 files changed, 163 insertions, 163 deletions
diff --git a/lisp/help-mode.el b/lisp/help-mode.el
index 7c032b81cf2..d6f968dd203 100644
--- a/lisp/help-mode.el
+++ b/lisp/help-mode.el
@@ -413,170 +413,170 @@ A special reference `back' is made to return back through a stack of
413help buffers. Variable `help-back-label' specifies the text for 413help buffers. Variable `help-back-label' specifies the text for
414that." 414that."
415 (interactive "b") 415 (interactive "b")
416 (save-excursion 416 (with-current-buffer (or buffer (current-buffer))
417 (set-buffer (or buffer (current-buffer))) 417 (save-excursion
418 (goto-char (point-min)) 418 (goto-char (point-min))
419 ;; Skip the header-type info, though it might be useful to parse 419 ;; Skip the header-type info, though it might be useful to parse
420 ;; it at some stage (e.g. "function in `library'"). 420 ;; it at some stage (e.g. "function in `library'").
421 (forward-paragraph) 421 (forward-paragraph)
422 (let ((old-modified (buffer-modified-p))) 422 (let ((old-modified (buffer-modified-p)))
423 (let ((stab (syntax-table)) 423 (let ((stab (syntax-table))
424 (case-fold-search t) 424 (case-fold-search t)
425 (inhibit-read-only t)) 425 (inhibit-read-only t))
426 (set-syntax-table emacs-lisp-mode-syntax-table) 426 (set-syntax-table emacs-lisp-mode-syntax-table)
427 ;; The following should probably be abstracted out. 427 ;; The following should probably be abstracted out.
428 (unwind-protect 428 (unwind-protect
429 (progn 429 (progn
430 ;; Info references 430 ;; Info references
431 (save-excursion 431 (save-excursion
432 (while (re-search-forward help-xref-info-regexp nil t) 432 (while (re-search-forward help-xref-info-regexp nil t)
433 (let ((data (match-string 2))) 433 (let ((data (match-string 2)))
434 (save-match-data 434 (save-match-data
435 (unless (string-match "^([^)]+)" data) 435 (unless (string-match "^([^)]+)" data)
436 (setq data (concat "(emacs)" data)))) 436 (setq data (concat "(emacs)" data))))
437 (help-xref-button 2 'help-info data)))) 437 (help-xref-button 2 'help-info data))))
438 ;; URLs 438 ;; URLs
439 (save-excursion 439 (save-excursion
440 (while (re-search-forward help-xref-url-regexp nil t) 440 (while (re-search-forward help-xref-url-regexp nil t)
441 (let ((data (match-string 1))) 441 (let ((data (match-string 1)))
442 (help-xref-button 1 'help-url data)))) 442 (help-xref-button 1 'help-url data))))
443 ;; Mule related keywords. Do this before trying 443 ;; Mule related keywords. Do this before trying
444 ;; `help-xref-symbol-regexp' because some of Mule 444 ;; `help-xref-symbol-regexp' because some of Mule
445 ;; keywords have variable or function definitions. 445 ;; keywords have variable or function definitions.
446 (if help-xref-mule-regexp 446 (if help-xref-mule-regexp
447 (save-excursion 447 (save-excursion
448 (while (re-search-forward help-xref-mule-regexp nil t) 448 (while (re-search-forward help-xref-mule-regexp nil t)
449 (let* ((data (match-string 7)) 449 (let* ((data (match-string 7))
450 (sym (intern-soft data))) 450 (sym (intern-soft data)))
451 (cond 451 (cond
452 ((match-string 3) ; coding system 452 ((match-string 3) ; coding system
453 (and sym (coding-system-p sym) 453 (and sym (coding-system-p sym)
454 (help-xref-button 6 'help-coding-system sym))) 454 (help-xref-button 6 'help-coding-system sym)))
455 ((match-string 4) ; input method 455 ((match-string 4) ; input method
456 (and (assoc data input-method-alist) 456 (and (assoc data input-method-alist)
457 (help-xref-button 7 'help-input-method data))) 457 (help-xref-button 7 'help-input-method data)))
458 ((or (match-string 5) (match-string 6)) ; charset 458 ((or (match-string 5) (match-string 6)) ; charset
459 (and sym (charsetp sym) 459 (and sym (charsetp sym)
460 (help-xref-button 7 'help-character-set sym))) 460 (help-xref-button 7 'help-character-set sym)))
461 ((assoc data input-method-alist) 461 ((assoc data input-method-alist)
462 (help-xref-button 7 'help-character-set data)) 462 (help-xref-button 7 'help-character-set data))
463 ((and sym (coding-system-p sym)) 463 ((and sym (coding-system-p sym))
464 (help-xref-button 7 'help-coding-system sym)) 464 (help-xref-button 7 'help-coding-system sym))
465 ((and sym (charsetp sym)) 465 ((and sym (charsetp sym))
466 (help-xref-button 7 'help-character-set sym))))))) 466 (help-xref-button 7 'help-character-set sym)))))))
467 ;; Quoted symbols 467 ;; Quoted symbols
468 (save-excursion 468 (save-excursion
469 (while (re-search-forward help-xref-symbol-regexp nil t) 469 (while (re-search-forward help-xref-symbol-regexp nil t)
470 (let* ((data (match-string 8)) 470 (let* ((data (match-string 8))
471 (sym (intern-soft data))) 471 (sym (intern-soft data)))
472 (if sym 472 (if sym
473 (cond 473 (cond
474 ((match-string 3) ; `variable' &c 474 ((match-string 3) ; `variable' &c
475 (and (or (boundp sym) ; `variable' doesn't ensure 475 (and (or (boundp sym) ; `variable' doesn't ensure
476 ; it's actually bound 476 ; it's actually bound
477 (get sym 'variable-documentation)) 477 (get sym 'variable-documentation))
478 (help-xref-button 8 'help-variable sym))) 478 (help-xref-button 8 'help-variable sym)))
479 ((match-string 4) ; `function' &c 479 ((match-string 4) ; `function' &c
480 (and (fboundp sym) ; similarly 480 (and (fboundp sym) ; similarly
481 (help-xref-button 8 'help-function sym))) 481 (help-xref-button 8 'help-function sym)))
482 ((match-string 5) ; `face' 482 ((match-string 5) ; `face'
483 (and (facep sym) 483 (and (facep sym)
484 (help-xref-button 8 'help-face sym))) 484 (help-xref-button 8 'help-face sym)))
485 ((match-string 6)) ; nothing for `symbol' 485 ((match-string 6)) ; nothing for `symbol'
486 ((match-string 7) 486 ((match-string 7)
487;;; this used: 487 ;; this used:
488;;; #'(lambda (arg) 488 ;; #'(lambda (arg)
489;;; (let ((location 489 ;; (let ((location
490;;; (find-function-noselect arg))) 490 ;; (find-function-noselect arg)))
491;;; (pop-to-buffer (car location)) 491 ;; (pop-to-buffer (car location))
492;;; (goto-char (cdr location)))) 492 ;; (goto-char (cdr location))))
493 (help-xref-button 8 'help-function-def sym)) 493 (help-xref-button 8 'help-function-def sym))
494 ((and 494 ((and
495 (facep sym) 495 (facep sym)
496 (save-match-data (looking-at "[ \t\n]+face\\W"))) 496 (save-match-data (looking-at "[ \t\n]+face\\W")))
497 (help-xref-button 8 'help-face sym)) 497 (help-xref-button 8 'help-face sym))
498 ((and (or (boundp sym) 498 ((and (or (boundp sym)
499 (get sym 'variable-documentation)) 499 (get sym 'variable-documentation))
500 (fboundp sym)) 500 (fboundp sym))
501 ;; We can't intuit whether to use the 501 ;; We can't intuit whether to use the
502 ;; variable or function doc -- supply both. 502 ;; variable or function doc -- supply both.
503 (help-xref-button 8 'help-symbol sym)) 503 (help-xref-button 8 'help-symbol sym))
504 ((and 504 ((and
505 (or (boundp sym) 505 (or (boundp sym)
506 (get sym 'variable-documentation)) 506 (get sym 'variable-documentation))
507 (or 507 (or
508 (documentation-property 508 (documentation-property
509 sym 'variable-documentation) 509 sym 'variable-documentation)
510 (condition-case nil 510 (condition-case nil
511 (documentation-property 511 (documentation-property
512 (indirect-variable sym) 512 (indirect-variable sym)
513 'variable-documentation) 513 'variable-documentation)
514 (cyclic-variable-indirection nil)))) 514 (cyclic-variable-indirection nil))))
515 (help-xref-button 8 'help-variable sym)) 515 (help-xref-button 8 'help-variable sym))
516 ((fboundp sym) 516 ((fboundp sym)
517 (help-xref-button 8 'help-function sym))))))) 517 (help-xref-button 8 'help-function sym)))))))
518 ;; An obvious case of a key substitution: 518 ;; An obvious case of a key substitution:
519 (save-excursion 519 (save-excursion
520 (while (re-search-forward 520 (while (re-search-forward
521 ;; Assume command name is only word and symbol 521 ;; Assume command name is only word and symbol
522 ;; characters to get things like `use M-x foo->bar'. 522 ;; characters to get things like `use M-x foo->bar'.
523 ;; Command required to end with word constituent 523 ;; Command required to end with word constituent
524 ;; to avoid `.' at end of a sentence. 524 ;; to avoid `.' at end of a sentence.
525 "\\<M-x\\s-+\\(\\sw\\(\\sw\\|\\s_\\)*\\sw\\)" nil t) 525 "\\<M-x\\s-+\\(\\sw\\(\\sw\\|\\s_\\)*\\sw\\)" nil t)
526 (let ((sym (intern-soft (match-string 1)))) 526 (let ((sym (intern-soft (match-string 1))))
527 (if (fboundp sym) 527 (if (fboundp sym)
528 (help-xref-button 1 'help-function sym))))) 528 (help-xref-button 1 'help-function sym)))))
529 ;; Look for commands in whole keymap substitutions: 529 ;; Look for commands in whole keymap substitutions:
530 (save-excursion 530 (save-excursion
531 ;; Make sure to find the first keymap. 531 ;; Make sure to find the first keymap.
532 (goto-char (point-min)) 532 (goto-char (point-min))
533 ;; Find a header and the column at which the command 533 ;; Find a header and the column at which the command
534 ;; name will be found. 534 ;; name will be found.
535 535
536 ;; If the keymap substitution isn't the last thing in 536 ;; If the keymap substitution isn't the last thing in
537 ;; the doc string, and if there is anything on the 537 ;; the doc string, and if there is anything on the same
538 ;; same line after it, this code won't recognize the end of it. 538 ;; line after it, this code won't recognize the end of it.
539 (while (re-search-forward "^key +binding\n\\(-+ +\\)-+\n\n" 539 (while (re-search-forward "^key +binding\n\\(-+ +\\)-+\n\n"
540 nil t) 540 nil t)
541 (let ((col (- (match-end 1) (match-beginning 1)))) 541 (let ((col (- (match-end 1) (match-beginning 1))))
542 (while 542 (while
543 (and (not (eobp)) 543 (and (not (eobp))
544 ;; Stop at a pair of blank lines. 544 ;; Stop at a pair of blank lines.
545 (not (looking-at "\n\\s-*\n"))) 545 (not (looking-at "\n\\s-*\n")))
546 ;; Skip a single blank line. 546 ;; Skip a single blank line.
547 (and (eolp) (forward-line)) 547 (and (eolp) (forward-line))
548 (end-of-line) 548 (end-of-line)
549 (skip-chars-backward "^ \t\n") 549 (skip-chars-backward "^ \t\n")
550 (if (and (>= (current-column) col) 550 (if (and (>= (current-column) col)
551 (looking-at "\\(\\sw\\|\\s_\\)+$")) 551 (looking-at "\\(\\sw\\|\\s_\\)+$"))
552 (let ((sym (intern-soft (match-string 0)))) 552 (let ((sym (intern-soft (match-string 0))))
553 (if (fboundp sym) 553 (if (fboundp sym)
554 (help-xref-button 0 'help-function sym)))) 554 (help-xref-button 0 'help-function sym))))
555 (forward-line)))))) 555 (forward-line))))))
556 (set-syntax-table stab)) 556 (set-syntax-table stab))
557 ;; Delete extraneous newlines at the end of the docstring 557 ;; Delete extraneous newlines at the end of the docstring
558 (goto-char (point-max)) 558 (goto-char (point-max))
559 (while (and (not (bobp)) (bolp)) 559 (while (and (not (bobp)) (bolp))
560 (delete-char -1)) 560 (delete-char -1))
561 (insert "\n") 561 (insert "\n")
562 (when (or help-xref-stack help-xref-forward-stack) 562 (when (or help-xref-stack help-xref-forward-stack)
563 (insert "\n")) 563 (insert "\n"))
564 ;; Make a back-reference in this buffer if appropriate. 564 ;; Make a back-reference in this buffer if appropriate.
565 (when help-xref-stack 565 (when help-xref-stack
566 (help-insert-xref-button help-back-label 'help-back 566 (help-insert-xref-button help-back-label 'help-back
567 (current-buffer))) 567 (current-buffer)))
568 ;; Make a forward-reference in this buffer if appropriate. 568 ;; Make a forward-reference in this buffer if appropriate.
569 (when help-xref-forward-stack 569 (when help-xref-forward-stack
570 (when help-xref-stack 570 (when help-xref-stack
571 (insert "\t")) 571 (insert "\t"))
572 (help-insert-xref-button help-forward-label 'help-forward 572 (help-insert-xref-button help-forward-label 'help-forward
573 (current-buffer))) 573 (current-buffer)))
574 (when (or help-xref-stack help-xref-forward-stack) 574 (when (or help-xref-stack help-xref-forward-stack)
575 (insert "\n"))) 575 (insert "\n")))
576 ;; View mode steals RET from us. 576 ;; View mode steals RET from us.
577 (set (make-local-variable 'minor-mode-overriding-map-alist) 577 (set (make-local-variable 'minor-mode-overriding-map-alist)
578 (list (cons 'view-mode help-xref-override-view-map))) 578 (list (cons 'view-mode help-xref-override-view-map)))
579 (set-buffer-modified-p old-modified)))) 579 (set-buffer-modified-p old-modified)))))
580 580
581;;;###autoload 581;;;###autoload
582(defun help-xref-button (match-number type &rest args) 582(defun help-xref-button (match-number type &rest args)