]> code.delx.au - gnu-emacs/blobdiff - lisp/help-fns.el
Merge from origin/emacs-25
[gnu-emacs] / lisp / help-fns.el
index 6e8a108b5068d9767e73e25b531638ec168c34b2..040152a2c9fc249ccc433d6eec7e6130d25d87de 100644 (file)
@@ -699,17 +699,23 @@ it is displayed along with the global value."
   (interactive
    (let ((v (variable-at-point))
         (enable-recursive-minibuffers t)
+         (orig-buffer (current-buffer))
         val)
-     (setq val (completing-read (if (symbolp v)
-                                   (format
-                                    "Describe variable (default %s): " v)
-                                 "Describe variable: ")
-                               obarray
-                               (lambda (vv)
-                                  (or (get vv 'variable-documentation)
-                                      (and (boundp vv) (not (keywordp vv)))))
-                               t nil nil
-                               (if (symbolp v) (symbol-name v))))
+     (setq val (completing-read
+                (if (symbolp v)
+                    (format
+                     "Describe variable (default %s): " v)
+                  "Describe variable: ")
+                obarray
+                (lambda (vv)
+                  ;; In case the variable only exists in the buffer
+                  ;; the command we switch back to that buffer before
+                  ;; we examine the variable.
+                  (with-current-buffer orig-buffer
+                    (or (get vv 'variable-documentation)
+                        (and (boundp vv) (not (keywordp vv))))))
+                t nil nil
+                (if (symbolp v) (symbol-name v))))
      (list (if (equal val "")
               v (intern val)))))
   (let (file-name)
@@ -758,9 +764,8 @@ it is displayed along with the global value."
            (unless valvoid
              (with-current-buffer standard-output
                (setq val-start-pos (point))
-               (princ "value is ")
-               (let ((from (point))
-                     (line-beg (line-beginning-position))
+               (princ "value is")
+               (let ((line-beg (line-beginning-position))
                      (print-rep
                       (let ((rep
                              (let ((print-quoted t))
@@ -769,17 +774,17 @@ it is displayed along with the global value."
                             (format-message "`%s'" rep)
                           rep))))
                  (if (< (+ (length print-rep) (point) (- line-beg)) 68)
-                     (insert print-rep)
+                     (insert " " print-rep)
                    (terpri)
                    (pp val)
-                   (if (< (point) (+ 68 (line-beginning-position 0)))
-                       (delete-region from (1+ from))
-                     (delete-region (1- from) from)))
+                    ;; Remove trailing newline.
+                    (delete-char -1))
                  (let* ((sv (get variable 'standard-value))
                         (origval (and (consp sv)
                                       (condition-case nil
                                           (eval (car sv))
-                                        (error :help-eval-error)))))
+                                        (error :help-eval-error))))
+                         from)
                    (when (and (consp sv)
                                (not (equal origval val))
                                (not (equal origval :help-eval-error)))
@@ -910,29 +915,35 @@ if it is given a local binding.\n"))))
                                             (buffer-file-name buffer)))
                                       (dir-locals-find-file
                                        (buffer-file-name buffer))))
-                          (dir-file t))
+                          (is-directory nil))
                      (princ (substitute-command-keys
                              "  This variable's value is directory-local"))
-                     (if (null file)
-                         (princ ".\n")
-                       (princ ", set ")
-                        (if (consp file) ; result from cache
-                            ;; If the cache element has an mtime, we
-                            ;; assume it came from a file.
-                            (if (nth 2 file)
-                                (setq file (expand-file-name
-                                            dir-locals-file (car file)))
-                              ;; Otherwise, assume it was set directly.
-                              (setq file (car file)
-                                    dir-file nil)))
-                       (princ (substitute-command-keys
-                                (if dir-file
-                                    "by the file\n  `"
-                                  "for the directory\n  `")))
+                      (when (consp file) ; result from cache
+                        ;; If the cache element has an mtime, we
+                        ;; assume it came from a file.
+                        (if (nth 2 file)
+                            ;; (car file) is a directory.
+                            (setq file (dir-locals--all-files (car file)))
+                          ;; Otherwise, assume it was set directly.
+                          (setq file (car file)
+                                is-directory t)))
+                      (if (null file)
+                          (princ ".\n")
+                        (princ ", set ")
+                        (princ (substitute-command-keys
+                                (cond
+                                 (is-directory "for the directory\n  `")
+                                 ;; Many files matched.
+                                 ((and (consp file) (cdr file))
+                                  (setq file (file-name-directory (car file)))
+                                  (format "by one of the\n  %s files in the directory\n  `"
+                                          dir-locals-file))
+                                 (t (setq file (car file))
+                                    "by the file\n  `"))))
                        (with-current-buffer standard-output
                          (insert-text-button
                           file 'type 'help-dir-local-var-def
-                          'help-args (list variable file)))
+                             'help-args (list variable file)))
                        (princ (substitute-command-keys "'.\n"))))
                  (princ (substitute-command-keys
                          "  This variable's value is file-local.\n"))))
@@ -1098,7 +1109,13 @@ BUFFER should be a buffer or a buffer name."
       (if (or (not (vectorp docs)) (/= (length docs) 95))
          (error "Invalid first extra slot in this category table\n"))
       (with-current-buffer standard-output
-       (insert "Legend of category mnemonics (see the tail for the longer description)\n")
+        (setq-default help-button-cache (make-marker))
+       (insert "Legend of category mnemonics ")
+        (insert-button "(longer descriptions at the bottom)"
+                       'action help-button-cache
+                       'follow-link t
+                       'help-echo "mouse-2, RET: show full legend")
+        (insert "\n")
        (let ((pos (point)) (items 0) lines n)
          (dotimes (i 95)
            (if (aref docs i) (setq items (1+ items))))
@@ -1125,6 +1142,7 @@ BUFFER should be a buffer or a buffer name."
                "character(s)\tcategory mnemonics\n"
                "------------\t------------------")
        (describe-vector table 'help-describe-category-set)
+        (set-marker help-button-cache (point))
        (insert "Legend of category mnemonics:\n")
        (dotimes (i 95)
          (let ((elt (aref docs i)))