comparison lisp/help-fns.el @ 65470:a6481386d6b6

(describe-variable): Rearrange to put source link in a predictable place.
author Richard M. Stallman <rms@gnu.org>
date Mon, 12 Sep 2005 15:35:22 +0000
parents 41bb365f41c4
children e444511e983e 94f174e5569d
comparison
equal deleted inserted replaced
65469:ba050fdb5000 65470:a6481386d6b6
520 (message "You did not specify a variable") 520 (message "You did not specify a variable")
521 (save-excursion 521 (save-excursion
522 (let* ((valvoid (not (with-current-buffer buffer (boundp variable)))) 522 (let* ((valvoid (not (with-current-buffer buffer (boundp variable))))
523 ;; Extract the value before setting up the output buffer, 523 ;; Extract the value before setting up the output buffer,
524 ;; in case `buffer' *is* the output buffer. 524 ;; in case `buffer' *is* the output buffer.
525 (val (unless valvoid (buffer-local-value variable buffer)))) 525 (val (unless valvoid (buffer-local-value variable buffer)))
526 val-start-pos)
526 (help-setup-xref (list #'describe-variable variable buffer) 527 (help-setup-xref (list #'describe-variable variable buffer)
527 (interactive-p)) 528 (interactive-p))
528 (with-output-to-temp-buffer (help-buffer) 529 (with-output-to-temp-buffer (help-buffer)
529 (with-current-buffer buffer 530 (with-current-buffer buffer
530 (prin1 variable) 531 (prin1 variable)
531 (if valvoid
532 (princ " is void")
533 (with-current-buffer standard-output
534 (princ "'s value is ")
535 (terpri)
536 (let ((from (point)))
537 (pp val)
538 ;; Hyperlinks in variable's value are quite frequently
539 ;; inappropriate e.g C-h v <RET> features <RET>
540 ;; (help-xref-on-pp from (point))
541 (if (< (point) (+ from 20))
542 (delete-region (1- from) from)))))
543 (terpri)
544 (when (local-variable-p variable)
545 (princ (format "%socal in buffer %s; "
546 (if (get variable 'permanent-local)
547 "Permanently l" "L")
548 (buffer-name)))
549 (if (not (default-boundp variable))
550 (princ "globally void")
551 (let ((val (default-value variable)))
552 (with-current-buffer standard-output
553 (princ "global value is ")
554 (terpri)
555 ;; Fixme: pp can take an age if you happen to
556 ;; ask for a very large expression. We should
557 ;; probably print it raw once and check it's a
558 ;; sensible size before prettyprinting. -- fx
559 (let ((from (point)))
560 (pp val)
561 ;; See previous comment for this function.
562 ;; (help-xref-on-pp from (point))
563 (if (< (point) (+ from 20))
564 (delete-region (1- from) from))))))
565 (terpri))
566 (terpri)
567 (with-current-buffer standard-output
568 (when (> (count-lines (point-min) (point-max)) 10)
569 ;; Note that setting the syntax table like below
570 ;; makes forward-sexp move over a `'s' at the end
571 ;; of a symbol.
572 (set-syntax-table emacs-lisp-mode-syntax-table)
573 (goto-char (point-min))
574 (if valvoid
575 (forward-line 1)
576 (forward-sexp 1)
577 (delete-region (point) (progn (end-of-line) (point)))
578 (save-excursion
579 (insert "\n\nValue:")
580 (set (make-local-variable 'help-button-cache)
581 (point-marker)))
582 (insert " value is shown ")
583 (insert-button "below"
584 'action help-button-cache
585 'follow-link t
586 'help-echo "mouse-2, RET: show value")
587 (insert ".\n\n")))
588 ;; Add a note for variables that have been make-var-buffer-local.
589 (when (and (local-variable-if-set-p variable)
590 (or (not (local-variable-p variable))
591 (with-temp-buffer
592 (local-variable-if-set-p variable))))
593 (save-excursion
594 (forward-line -1)
595 (insert "Automatically becomes buffer-local when set in any fashion.\n"))))
596 ;; Mention if it's an alias
597 (let* ((alias (condition-case nil
598 (indirect-variable variable)
599 (error variable)))
600 (obsolete (get variable 'byte-obsolete-variable))
601 (doc (or (documentation-property variable 'variable-documentation)
602 (documentation-property alias 'variable-documentation))))
603 (unless (eq alias variable)
604 (princ (format "This variable is an alias for `%s'." alias))
605 (terpri)
606 (terpri))
607 (when obsolete
608 (princ "This variable is obsolete")
609 (if (cdr obsolete) (princ (format " since %s" (cdr obsolete))))
610 (princ ";") (terpri)
611 (princ (if (stringp (car obsolete)) (car obsolete)
612 (format "use `%s' instead." (car obsolete))))
613 (terpri)
614 (terpri))
615 (princ (or doc "Not documented as a variable.")))
616 ;; Make a link to customize if this variable can be customized.
617 (if (custom-variable-p variable)
618 (let ((customize-label "customize"))
619 (terpri)
620 (terpri)
621 (princ (concat "You can " customize-label " this variable."))
622 (with-current-buffer standard-output
623 (save-excursion
624 (re-search-backward
625 (concat "\\(" customize-label "\\)") nil t)
626 (help-xref-button 1 'help-customize-variable variable)))))
627 ;; Make a hyperlink to the library if appropriate. (Don't 532 ;; Make a hyperlink to the library if appropriate. (Don't
628 ;; change the format of the buffer's initial line in case 533 ;; change the format of the buffer's initial line in case
629 ;; anything expects the current format.) 534 ;; anything expects the current format.)
630 (let ((file-name (symbol-file variable 'defvar))) 535 (let ((file-name (symbol-file variable 'defvar)))
631 (when (equal file-name "loaddefs.el") 536 (when (equal file-name "loaddefs.el")
645 ;; It's a variable not defined in Elisp but in C. 550 ;; It's a variable not defined in Elisp but in C.
646 (setq file-name 551 (setq file-name
647 (if (get-buffer " *DOC*") 552 (if (get-buffer " *DOC*")
648 (help-C-file-name variable 'var) 553 (help-C-file-name variable 'var)
649 'C-source))) 554 'C-source)))
650 (when file-name 555 (if file-name
651 (princ "\n\nDefined in `") 556 (progn
652 (princ (if (eq file-name 'C-source) "C source code" file-name)) 557 (princ " is a variable defined in `")
653 (princ "'.") 558 (princ (if (eq file-name 'C-source) "C source code" file-name))
654 (with-current-buffer standard-output 559 (princ "'.\n")
655 (save-excursion 560 (with-current-buffer standard-output
656 (re-search-backward "`\\([^`']+\\)'" nil t) 561 (save-excursion
657 (help-xref-button 1 'help-variable-def 562 (re-search-backward "`\\([^`']+\\)'" nil t)
658 variable file-name))))) 563 (help-xref-button 1 'help-variable-def
659 564 variable file-name)))
565 (if valvoid
566 (princ "It is void as a variable.\n")
567 (princ "Its ")))
568 (if valvoid
569 (princ " is void as a variable.\n")
570 (princ "'s "))))
571 (if valvoid
572 nil
573 (with-current-buffer standard-output
574 (setq val-start-pos (point))
575 (princ "value is ")
576 (terpri)
577 (let ((from (point)))
578 (pp val)
579 ;; Hyperlinks in variable's value are quite frequently
580 ;; inappropriate e.g C-h v <RET> features <RET>
581 ;; (help-xref-on-pp from (point))
582 (if (< (point) (+ from 20))
583 (delete-region (1- from) from)))))
584 (terpri)
585
586 (when (local-variable-p variable)
587 (princ (format "%socal in buffer %s; "
588 (if (get variable 'permanent-local)
589 "Permanently l" "L")
590 (buffer-name)))
591 (if (not (default-boundp variable))
592 (princ "globally void")
593 (let ((val (default-value variable)))
594 (with-current-buffer standard-output
595 (princ "global value is ")
596 (terpri)
597 ;; Fixme: pp can take an age if you happen to
598 ;; ask for a very large expression. We should
599 ;; probably print it raw once and check it's a
600 ;; sensible size before prettyprinting. -- fx
601 (let ((from (point)))
602 (pp val)
603 ;; See previous comment for this function.
604 ;; (help-xref-on-pp from (point))
605 (if (< (point) (+ from 20))
606 (delete-region (1- from) from)))))))
607 ;; Add a note for variables that have been make-var-buffer-local.
608 (when (and (local-variable-if-set-p variable)
609 (or (not (local-variable-p variable))
610 (with-temp-buffer
611 (local-variable-if-set-p variable))))
612 (princ "\nAutomatically becomes buffer-local when set in any fashion.\n"))
613 (terpri)
614
615 ;; If the value is large, move it to the end.
616 (with-current-buffer standard-output
617 (when (> (count-lines (point-min) (point-max)) 10)
618 ;; Note that setting the syntax table like below
619 ;; makes forward-sexp move over a `'s' at the end
620 ;; of a symbol.
621 (set-syntax-table emacs-lisp-mode-syntax-table)
622 (goto-char val-start-pos)
623 (delete-region (point) (progn (end-of-line) (point)))
624 (save-excursion
625 (insert "\n\nValue:")
626 (set (make-local-variable 'help-button-cache)
627 (point-marker)))
628 (insert "value is shown ")
629 (insert-button "below"
630 'action help-button-cache
631 'follow-link t
632 'help-echo "mouse-2, RET: show value")
633 (insert ".\n\n")))
634
635 ;; Mention if it's an alias
636 (let* ((alias (condition-case nil
637 (indirect-variable variable)
638 (error variable)))
639 (obsolete (get variable 'byte-obsolete-variable))
640 (doc (or (documentation-property variable 'variable-documentation)
641 (documentation-property alias 'variable-documentation))))
642 (unless (eq alias variable)
643 (princ (format "\nThis variable is an alias for `%s'.\n" alias)))
644 (when obsolete
645 (princ "\nThis variable is obsolete")
646 (if (cdr obsolete) (princ (format " since %s" (cdr obsolete))))
647 (princ ";") (terpri)
648 (princ (if (stringp (car obsolete)) (car obsolete)
649 (format "use `%s' instead." (car obsolete))))
650 (terpri))
651 (princ "Documentation:\n")
652 (princ (or doc "Not documented as a variable.")))
653 ;; Make a link to customize if this variable can be customized.
654 (if (custom-variable-p variable)
655 (let ((customize-label "customize"))
656 (terpri)
657 (terpri)
658 (princ (concat "You can " customize-label " this variable."))
659 (with-current-buffer standard-output
660 (save-excursion
661 (re-search-backward
662 (concat "\\(" customize-label "\\)") nil t)
663 (help-xref-button 1 'help-customize-variable variable)))))
660 (print-help-return-message) 664 (print-help-return-message)
661 (save-excursion 665 (save-excursion
662 (set-buffer standard-output) 666 (set-buffer standard-output)
663 ;; Return the text we displayed. 667 ;; Return the text we displayed.
664 (buffer-string)))))))) 668 (buffer-string))))))))