* cus-start.el (all): Undo previous change.
[bpt/emacs.git] / lisp / help-fns.el
index 9235462..eee0794 100644 (file)
@@ -10,7 +10,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -446,10 +446,11 @@ If ANY-SYMBOL is non-nil, don't insist the symbol be bound."
       0))
 
 ;;;###autoload
-(defun describe-variable (variable &optional buffer)
+(defun describe-variable (variable &optional buffer frame)
   "Display the full documentation of VARIABLE (a symbol).
 Returns the documentation as a string, also.
-If VARIABLE has a buffer-local value in BUFFER (default to the current buffer),
+If VARIABLE has a buffer-local value in BUFFER or FRAME
+\(default to the current buffer and current frame),
 it is displayed along with the global value."
   (interactive
    (let ((v (variable-at-point))
@@ -468,14 +469,19 @@ it is displayed along with the global value."
      (list (if (equal val "")
               v (intern val)))))
   (unless (buffer-live-p buffer) (setq buffer (current-buffer)))
+  (unless (frame-live-p frame) (setq frame (selected-frame)))
   (if (not (symbolp variable))
       (message "You did not specify a variable")
     (save-excursion
-      (let* ((valvoid (not (with-current-buffer buffer (boundp variable))))
-            ;; Extract the value before setting up the output buffer,
-            ;; in case `buffer' *is* the output buffer.
-            (val (unless valvoid (buffer-local-value variable buffer)))
-            val-start-pos)
+      (let ((valvoid (not (with-current-buffer buffer (boundp variable))))
+           val val-start-pos locus)
+       ;; Extract the value before setting up the output buffer,
+       ;; in case `buffer' *is* the output buffer.
+       (unless valvoid
+         (with-selected-frame frame
+           (with-current-buffer buffer
+             (setq val (symbol-value variable)
+                   locus (variable-binding-locus variable)))))
        (help-setup-xref (list #'describe-variable variable buffer)
                         (interactive-p))
        (with-output-to-temp-buffer (help-buffer)
@@ -537,11 +543,13 @@ it is displayed along with the global value."
                      (delete-region (1- from) from)))))
            (terpri)
 
-           (when (local-variable-p variable)
-             (princ (format "%socal in buffer %s; "
-                            (if (get variable 'permanent-local)
-                                "Permanently l" "L")
-                            (buffer-name)))
+           (when locus
+             (if (bufferp locus)
+                 (princ (format "%socal in buffer %s; "
+                                (if (get variable 'permanent-local)
+                                    "Permanently l" "L")
+                                (buffer-name)))
+               (princ (format "It is a frame-local variable; ")))
              (if (not (default-boundp variable))
                  (princ "globally void")
                (let ((val (default-value variable)))
@@ -557,14 +565,8 @@ it is displayed along with the global value."
                      ;; See previous comment for this function.
                      ;; (help-xref-on-pp from (point))
                      (if (< (point) (+ from 20))
-                         (delete-region (1- from) from)))))))
-           ;; 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))))
-             (princ "\nAutomatically becomes buffer-local when set in any fashion.\n"))
-           (terpri)
+                         (delete-region (1- from) from))))))
+              (terpri))
 
            ;; If the value is large, move it to the end.
            (with-current-buffer standard-output
@@ -589,35 +591,49 @@ it is displayed along with the global value."
                               'follow-link t
                               'help-echo "mouse-2, RET: show value")
                (insert ".\n")))
+            (terpri)
 
-           ;; Mention if it's an alias
             (let* ((alias (condition-case nil
                              (indirect-variable variable)
                            (error variable)))
                    (obsolete (get variable 'byte-obsolete-variable))
                   (safe-var (get variable 'safe-local-variable))
                    (doc (or (documentation-property variable 'variable-documentation)
-                            (documentation-property alias 'variable-documentation))))
+                            (documentation-property alias 'variable-documentation)))
+                   (extra-line nil))
+              ;; 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))))
+                (setq extra-line t)
+                (princ "  Automatically becomes buffer-local when set in any fashion.\n"))
+
+              ;; Mention if it's an alias
               (unless (eq alias variable)
-                (princ (format "\nThis variable is an alias for `%s'.\n" alias)))
-             (if (or obsolete safe-var)
-                 (terpri))
+                (setq extra-line t)
+                (princ (format "  This variable is an alias for `%s'.\n" alias)))
 
               (when obsolete
-                (princ "This variable is obsolete")
+                (setq extra-line t)
+                (princ "  This variable is obsolete")
                 (if (cdr obsolete) (princ (format " since %s" (cdr obsolete))))
-                (princ ";") (terpri)
+                (princ ";\n  ")
                 (princ (if (stringp (car obsolete)) (car obsolete)
                          (format "use `%s' instead." (car obsolete))))
                 (terpri))
              (when safe-var
-               (princ "This variable is safe as a file local variable ")
-               (princ "if its value\nsatisfies the predicate ")
+                (setq extra-line t)
+               (princ "  This variable is safe as a file local variable ")
+               (princ "if its value\n  satisfies the predicate ")
                (princ (if (byte-code-function-p safe-var)
                           "which is byte-compiled expression.\n"
                         (format "`%s'.\n" safe-var))))
-             (princ "\nDocumentation:\n")
-              (princ (or doc "Not documented as a variable.")))
+
+              (if extra-line (terpri))
+             (princ "Documentation:\n")
+             (with-current-buffer standard-output
+               (insert (or doc "Not documented as a variable."))))
            ;; Make a link to customize if this variable can be customized.
            (if (custom-variable-p variable)
                (let ((customize-label "customize"))