522 |
(let* ((valvoid (not (with-current-buffer buffer (boundp variable)))) |
(let* ((valvoid (not (with-current-buffer buffer (boundp variable)))) |
523 |
;; Extract the value before setting up the output buffer, |
;; Extract the value before setting up the output buffer, |
524 |
;; in case `buffer' *is* the output buffer. |
;; in case `buffer' *is* the output buffer. |
525 |
(val (unless valvoid (buffer-local-value variable buffer)))) |
(val (unless valvoid (buffer-local-value variable buffer))) |
526 |
|
val-start-pos) |
527 |
(help-setup-xref (list #'describe-variable variable buffer) |
(help-setup-xref (list #'describe-variable variable buffer) |
528 |
(interactive-p)) |
(interactive-p)) |
529 |
(with-output-to-temp-buffer (help-buffer) |
(with-output-to-temp-buffer (help-buffer) |
530 |
(with-current-buffer buffer |
(with-current-buffer buffer |
531 |
(prin1 variable) |
(prin1 variable) |
532 |
|
;; Make a hyperlink to the library if appropriate. (Don't |
533 |
|
;; change the format of the buffer's initial line in case |
534 |
|
;; anything expects the current format.) |
535 |
|
(let ((file-name (symbol-file variable 'defvar))) |
536 |
|
(when (equal file-name "loaddefs.el") |
537 |
|
;; Find the real def site of the preloaded variable. |
538 |
|
(let ((location |
539 |
|
(condition-case nil |
540 |
|
(find-variable-noselect variable file-name) |
541 |
|
(error nil)))) |
542 |
|
(when location |
543 |
|
(with-current-buffer (car location) |
544 |
|
(goto-char (cdr location)) |
545 |
|
(when (re-search-backward |
546 |
|
"^;;; Generated autoloads from \\(.*\\)" nil t) |
547 |
|
(setq file-name (match-string 1))))))) |
548 |
|
(when (and (null file-name) |
549 |
|
(integerp (get variable 'variable-documentation))) |
550 |
|
;; It's a variable not defined in Elisp but in C. |
551 |
|
(setq file-name |
552 |
|
(if (get-buffer " *DOC*") |
553 |
|
(help-C-file-name variable 'var) |
554 |
|
'C-source))) |
555 |
|
(if file-name |
556 |
|
(progn |
557 |
|
(princ " is a variable defined in `") |
558 |
|
(princ (if (eq file-name 'C-source) "C source code" file-name)) |
559 |
|
(princ "'.\n") |
560 |
|
(with-current-buffer standard-output |
561 |
|
(save-excursion |
562 |
|
(re-search-backward "`\\([^`']+\\)'" nil t) |
563 |
|
(help-xref-button 1 'help-variable-def |
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 |
(if valvoid |
572 |
(princ " is void") |
nil |
573 |
(with-current-buffer standard-output |
(with-current-buffer standard-output |
574 |
(princ "'s value is ") |
(setq val-start-pos (point)) |
575 |
|
(princ "value is ") |
576 |
(terpri) |
(terpri) |
577 |
(let ((from (point))) |
(let ((from (point))) |
578 |
(pp val) |
(pp val) |
582 |
(if (< (point) (+ from 20)) |
(if (< (point) (+ from 20)) |
583 |
(delete-region (1- from) from))))) |
(delete-region (1- from) from))))) |
584 |
(terpri) |
(terpri) |
585 |
|
|
586 |
(when (local-variable-p variable) |
(when (local-variable-p variable) |
587 |
(princ (format "%socal in buffer %s; " |
(princ (format "%socal in buffer %s; " |
588 |
(if (get variable 'permanent-local) |
(if (get variable 'permanent-local) |
603 |
;; See previous comment for this function. |
;; See previous comment for this function. |
604 |
;; (help-xref-on-pp from (point)) |
;; (help-xref-on-pp from (point)) |
605 |
(if (< (point) (+ from 20)) |
(if (< (point) (+ from 20)) |
606 |
(delete-region (1- from) from)))))) |
(delete-region (1- from) from))))))) |
607 |
(terpri)) |
;; 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) |
(terpri) |
614 |
|
|
615 |
|
;; If the value is large, move it to the end. |
616 |
(with-current-buffer standard-output |
(with-current-buffer standard-output |
617 |
(when (> (count-lines (point-min) (point-max)) 10) |
(when (> (count-lines (point-min) (point-max)) 10) |
618 |
;; Note that setting the syntax table like below |
;; Note that setting the syntax table like below |
619 |
;; makes forward-sexp move over a `'s' at the end |
;; makes forward-sexp move over a `'s' at the end |
620 |
;; of a symbol. |
;; of a symbol. |
621 |
(set-syntax-table emacs-lisp-mode-syntax-table) |
(set-syntax-table emacs-lisp-mode-syntax-table) |
622 |
(goto-char (point-min)) |
(goto-char val-start-pos) |
623 |
(if valvoid |
(delete-region (point) (progn (end-of-line) (point))) |
|
(forward-line 1) |
|
|
(forward-sexp 1) |
|
|
(delete-region (point) (progn (end-of-line) (point))) |
|
|
(save-excursion |
|
|
(insert "\n\nValue:") |
|
|
(set (make-local-variable 'help-button-cache) |
|
|
(point-marker))) |
|
|
(insert " value is shown ") |
|
|
(insert-button "below" |
|
|
'action help-button-cache |
|
|
'follow-link t |
|
|
'help-echo "mouse-2, RET: show value") |
|
|
(insert ".\n\n"))) |
|
|
;; Add a note for variables that have been make-var-buffer-local. |
|
|
(when (and (local-variable-if-set-p variable) |
|
|
(or (not (local-variable-p variable)) |
|
|
(with-temp-buffer |
|
|
(local-variable-if-set-p variable)))) |
|
624 |
(save-excursion |
(save-excursion |
625 |
(forward-line -1) |
(insert "\n\nValue:") |
626 |
(insert "Automatically becomes buffer-local when set in any fashion.\n")))) |
(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 |
;; Mention if it's an alias |
636 |
(let* ((alias (condition-case nil |
(let* ((alias (condition-case nil |
637 |
(indirect-variable variable) |
(indirect-variable variable) |
640 |
(doc (or (documentation-property variable 'variable-documentation) |
(doc (or (documentation-property variable 'variable-documentation) |
641 |
(documentation-property alias 'variable-documentation)))) |
(documentation-property alias 'variable-documentation)))) |
642 |
(unless (eq alias variable) |
(unless (eq alias variable) |
643 |
(princ (format "This variable is an alias for `%s'." alias)) |
(princ (format "\nThis variable is an alias for `%s'.\n" alias))) |
|
(terpri) |
|
|
(terpri)) |
|
644 |
(when obsolete |
(when obsolete |
645 |
(princ "This variable is obsolete") |
(princ "\nThis variable is obsolete") |
646 |
(if (cdr obsolete) (princ (format " since %s" (cdr obsolete)))) |
(if (cdr obsolete) (princ (format " since %s" (cdr obsolete)))) |
647 |
(princ ";") (terpri) |
(princ ";") (terpri) |
648 |
(princ (if (stringp (car obsolete)) (car obsolete) |
(princ (if (stringp (car obsolete)) (car obsolete) |
649 |
(format "use `%s' instead." (car obsolete)))) |
(format "use `%s' instead." (car obsolete)))) |
|
(terpri) |
|
650 |
(terpri)) |
(terpri)) |
651 |
|
(princ "Documentation:\n") |
652 |
(princ (or doc "Not documented as a variable."))) |
(princ (or doc "Not documented as a variable."))) |
653 |
;; Make a link to customize if this variable can be customized. |
;; Make a link to customize if this variable can be customized. |
654 |
(if (custom-variable-p variable) |
(if (custom-variable-p variable) |
661 |
(re-search-backward |
(re-search-backward |
662 |
(concat "\\(" customize-label "\\)") nil t) |
(concat "\\(" customize-label "\\)") nil t) |
663 |
(help-xref-button 1 'help-customize-variable variable))))) |
(help-xref-button 1 'help-customize-variable variable))))) |
|
;; Make a hyperlink to the library if appropriate. (Don't |
|
|
;; change the format of the buffer's initial line in case |
|
|
;; anything expects the current format.) |
|
|
(let ((file-name (symbol-file variable 'defvar))) |
|
|
(when (equal file-name "loaddefs.el") |
|
|
;; Find the real def site of the preloaded variable. |
|
|
(let ((location |
|
|
(condition-case nil |
|
|
(find-variable-noselect variable file-name) |
|
|
(error nil)))) |
|
|
(when location |
|
|
(with-current-buffer (car location) |
|
|
(goto-char (cdr location)) |
|
|
(when (re-search-backward |
|
|
"^;;; Generated autoloads from \\(.*\\)" nil t) |
|
|
(setq file-name (match-string 1))))))) |
|
|
(when (and (null file-name) |
|
|
(integerp (get variable 'variable-documentation))) |
|
|
;; It's a variable not defined in Elisp but in C. |
|
|
(setq file-name |
|
|
(if (get-buffer " *DOC*") |
|
|
(help-C-file-name variable 'var) |
|
|
'C-source))) |
|
|
(when file-name |
|
|
(princ "\n\nDefined in `") |
|
|
(princ (if (eq file-name 'C-source) "C source code" file-name)) |
|
|
(princ "'.") |
|
|
(with-current-buffer standard-output |
|
|
(save-excursion |
|
|
(re-search-backward "`\\([^`']+\\)'" nil t) |
|
|
(help-xref-button 1 'help-variable-def |
|
|
variable file-name))))) |
|
|
|
|
664 |
(print-help-return-message) |
(print-help-return-message) |
665 |
(save-excursion |
(save-excursion |
666 |
(set-buffer standard-output) |
(set-buffer standard-output) |