]> git.eshelyaron.com Git - emacs.git/commitdiff
Make dired directory components clickable
authorWilliam Xu <william.xwl@gmail.com>
Sun, 24 Oct 2021 14:15:12 +0000 (16:15 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 24 Oct 2021 14:15:17 +0000 (16:15 +0200)
* lisp/dired.el (dired-readin): Use it.

* lisp/dired.el (dired-make-directory-clickable): New user option.

* lisp/dired.el (dired--make-directory-clickable): New function
(bug#21973).

etc/NEWS
lisp/dired.el

index 294181635e7ac3fe1fb9a0b96b931600ddc416b1..602d13eefad8a6f946b1198fcea87d5cea821584 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -136,13 +136,6 @@ function which returns a string.  For the first two cases, the length
 of the resulting name is controlled by 'eww-buffer-name-length'.  By
 default, no automatic renaming is performed.
 
-** image-dired
-
----
-*** New command for the thumbnail buffer.
-The new command 'image-dired-unmark-all-marks' has been added with a
-binding in the menu.
-
 ** info-look
 
 ---
@@ -198,6 +191,20 @@ external "exiftool" command to be available.  The user options
 `image-dired-cmd-read-exif-data-program' and
 `image-dired-cmd-read-exif-data-options' are now obsolete.
 
+---
+*** New command for the thumbnail buffer.
+The new command 'image-dired-unmark-all-marks' has been added with a
+binding in the menu.
+
+** Dired
+
+---
+*** New user option 'dired-make-directory-clickable'.
+If non-nil (which is the default), hitting 'RET' or 'mouse-1' on
+the directory components at the directory displayed at the start of
+the buffer will take you to that directory.
+
+
 ** Exif
 
 *** New function 'exif-field'.
index 46525891224f6efaaa6f16e31de68b243328583d..ced18114c4641899b2677339985a656f92c4e97e 100644 (file)
@@ -35,6 +35,7 @@
 ;;; Code:
 
 (eval-when-compile (require 'subr-x))
+(eval-when-compile (require 'cl-lib))
 ;; When bootstrapping dired-loaddefs has not been generated.
 (require 'dired-loaddefs nil t)
 
@@ -281,6 +282,11 @@ with the buffer narrowed to the listing."
 ;; Note this can't simply be run inside function `dired-ls' as the hook
 ;; functions probably depend on the dired-subdir-alist to be OK.
 
+(defcustom dired-make-directory-clickable t
+  "When non-nil, make the directory at the start of the dired buffer clickable."
+  :version "29.1"
+  :type 'boolean)
+
 (defcustom dired-initial-position-hook nil
   "This hook is used to position the point.
 It is run by the function `dired-initial-position'."
@@ -1326,6 +1332,8 @@ wildcards, erases the buffer, and builds the subdir-alist anew
            (set-visited-file-modtime (file-attribute-modification-time
                                        attributes))))
       (set-buffer-modified-p nil)
+      (when dired-make-directory-clickable
+        (dired--make-directory-clickable))
       ;; No need to narrow since the whole buffer contains just
       ;; dired-readin's output, nothing else.  The hook can
       ;; successfully use dired functions (e.g. dired-get-filename)
@@ -1643,6 +1651,31 @@ see `dired-use-ls-dired' for more details.")
                               'invisible 'dired-hide-details-link))))
       (forward-line 1))))
 
+(defun dired--make-directory-clickable ()
+  (save-excursion
+    (goto-char (point-min))
+    (while (re-search-forward "^  /" nil t 1)
+      (let ((bound (line-end-position))
+            (segment-start (point))
+            (inhibit-read-only t)
+            (dir "/"))
+        (while (search-forward "/" bound t 1)
+          (setq dir (concat dir (buffer-substring segment-start (point))))
+          (add-text-properties
+           segment-start (1- (point))
+           `( mouse-face highlight
+              help-echo "mouse-1: goto this directory"
+              keymap ,(let* ((current-dir dir)
+                             (click (lambda ()
+                                      (interactive)
+                                      (if (assoc current-dir dired-subdir-alist)
+                                          (dired-goto-subdir current-dir)
+                                        (dired current-dir)))))
+                        (define-keymap
+                          [down-mouse-1] click
+                          ["RET"] click))))
+          (setq segment-start (point)))))))
+
 \f
 ;;; Reverting a dired buffer