]> git.eshelyaron.com Git - emacs.git/commitdiff
(describe-variable): Rearrange to put source link in a predictable place.
authorRichard M. Stallman <rms@gnu.org>
Mon, 12 Sep 2005 15:35:22 +0000 (15:35 +0000)
committerRichard M. Stallman <rms@gnu.org>
Mon, 12 Sep 2005 15:35:22 +0000 (15:35 +0000)
lisp/help-fns.el

index ae7a60cf55e72e9be688c19f5011b19b373ff592..2974e65bf888022c629db9344734b80e3c7e8c5f 100644 (file)
@@ -522,16 +522,57 @@ it is displayed along with the global value."
       (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 (unless valvoid (buffer-local-value variable buffer)))
+            val-start-pos)
        (help-setup-xref (list #'describe-variable variable buffer)
                         (interactive-p))
        (with-output-to-temp-buffer (help-buffer)
          (with-current-buffer buffer
            (prin1 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)))
+             (if file-name
+                 (progn
+                   (princ " is a variable defined in `")
+                   (princ (if (eq file-name 'C-source) "C source code" file-name))
+                   (princ "'.\n")
+                   (with-current-buffer standard-output
+                     (save-excursion
+                       (re-search-backward "`\\([^`']+\\)'" nil t)
+                       (help-xref-button 1 'help-variable-def
+                                         variable file-name)))
+                   (if valvoid
+                       (princ "It is void as a variable.\n")
+                     (princ "Its ")))
+               (if valvoid
+                   (princ " is void as a variable.\n")
+                 (princ "'s "))))
            (if valvoid
-               (princ " is void")
+               nil
              (with-current-buffer standard-output
-               (princ "'s value is ")
+               (setq val-start-pos (point))
+               (princ "value is ")
                (terpri)
                (let ((from (point)))
                  (pp val)
@@ -541,6 +582,7 @@ it is displayed along with the global value."
                  (if (< (point) (+ from 20))
                      (delete-region (1- from) from)))))
            (terpri)
+
            (when (local-variable-p variable)
              (princ (format "%socal in buffer %s; "
                             (if (get variable 'permanent-local)
@@ -561,38 +603,35 @@ 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))))))
-             (terpri))
+                         (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)
+
+           ;; If the value is large, move it to the end.
            (with-current-buffer standard-output
              (when (> (count-lines (point-min) (point-max)) 10)
                ;; Note that setting the syntax table like below
                ;; makes forward-sexp move over a `'s' at the end
                ;; of a symbol.
                (set-syntax-table emacs-lisp-mode-syntax-table)
-               (goto-char (point-min))
-               (if valvoid
-                   (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))))
+               (goto-char val-start-pos)
+               (delete-region (point) (progn (end-of-line) (point)))
                (save-excursion
-                 (forward-line -1)
-                 (insert "Automatically becomes buffer-local when set in any fashion.\n"))))
+                 (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")))
+
            ;; Mention if it's an alias
             (let* ((alias (condition-case nil
                              (indirect-variable variable)
@@ -601,17 +640,15 @@ it is displayed along with the global value."
                    (doc (or (documentation-property variable 'variable-documentation)
                             (documentation-property alias 'variable-documentation))))
               (unless (eq alias variable)
-                (princ (format "This variable is an alias for `%s'." alias))
-                (terpri)
-                (terpri))
+                (princ (format "\nThis variable is an alias for `%s'.\n" alias)))
               (when obsolete
-                (princ "This variable is obsolete")
+                (princ "\nThis variable is obsolete")
                 (if (cdr obsolete) (princ (format " since %s" (cdr obsolete))))
                 (princ ";") (terpri)
                 (princ (if (stringp (car obsolete)) (car obsolete)
                          (format "use `%s' instead." (car obsolete))))
-                (terpri)
                 (terpri))
+             (princ "Documentation:\n")
               (princ (or doc "Not documented as a variable.")))
            ;; Make a link to customize if this variable can be customized.
            (if (custom-variable-p variable)
@@ -624,39 +661,6 @@ it is displayed along with the global value."
                      (re-search-backward
                       (concat "\\(" customize-label "\\)") nil t)
                      (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)))))
-
            (print-help-return-message)
            (save-excursion
              (set-buffer standard-output)