Make dired directory components clickable

* 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).
This commit is contained in:
William Xu 2021-10-24 16:15:12 +02:00 committed by Lars Ingebrigtsen
parent 03d7dcb461
commit 860e8c524b
2 changed files with 47 additions and 7 deletions

View file

@ -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'.

View 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)))))))
;;; Reverting a dired buffer