unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: William Xu <william.xwl@gmail.com>
To: 21973@debbugs.gnu.org
Subject: bug#21973: [External] : bug#21973: 24.5; feature proposal: make dired header clickable
Date: Sun, 24 Oct 2021 13:09:28 +0200	[thread overview]
Message-ID: <87fssqk7br.fsf@gmail.com> (raw)
In-Reply-To: <CACzMC-ChsgWzHkx7=CMwD1bL-iwGzEwKCh5pQb7TgWsny47=xg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 624 bytes --]

Drew Adams <drew.adams@oracle.com> writes:

> Looked at this only quickly.
>
> +1.  It's a good idea to make dir-listing headers
> into, essentially, clickable/RETable breadcrumbs.
>
> I can't speak to whether the patch sent is the
> best/right way to do it - don't have time now to
> look into it.
>
> But this should be done (maybe optionally, i.e.,
> under user control) for each dir header in the
> buffer.  That is, do it for inserted subdir
> headers, as well as for the first (top-level)
> dir header.

I've revised the patch to support also subdir headers in the buffer,
using dired-after-readin-hook. 

-- 
William

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-Dired-path-segments-jumpable-by-mouse-click-bug.patch --]
[-- Type: text/x-diff, Size: 2832 bytes --]

From cdae3738782a356dda632d1b78d5f5b45bdc89a0 Mon Sep 17 00:00:00 2001
From: William Xu <william.xwl@gmail.com>
Date: Sun, 24 Oct 2021 13:03:54 +0200
Subject: [PATCH] Make Dired path segments jumpable by mouse click (bug#21973)

* lisp/dired.el (dired-readin): Call dired-make-path-jumpable.
(dired-make-path-jumpable, dired-jump-to-path-segment): New functions.
---
 lisp/dired.el | 42 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/lisp/dired.el b/lisp/dired.el
index 4652589122..216c082e7b 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -272,7 +272,7 @@ dired-before-readin-hook
   :group 'dired
   :type 'hook)
 
-(defcustom dired-after-readin-hook nil
+(defcustom dired-after-readin-hook '(dired-make-path-jumpable)
   "Hook run after each time a file or directory is read by Dired.
 After each listing of a file or directory, this hook is run
 with the buffer narrowed to the listing."
@@ -1643,6 +1643,46 @@ dired-insert-set-properties
 			       'invisible 'dired-hide-details-link))))
       (forward-line 1))))
 
+(defun dired-make-path-jumpable ()
+  "Make dired path line at top jumpable."
+  (let ((inhibit-read-only t))
+    (save-excursion
+      (goto-char (point-min))
+      (while (re-search-forward "^  /" nil t 1)
+        (let ((bound (line-end-position))
+              (segment-start (point))
+              segment-end)
+          (while (search-forward "/" bound t 1)
+            (setq segment-end (1- (point)))
+            (add-text-properties segment-start segment-end
+                                 `(mouse-face
+                                   highlight
+                                   help-echo "mouse-1: goto here"
+                                   keymap ,(let ((map (make-sparse-keymap)))
+                                             (define-key map [down-mouse-1] 'dired-jump-to-path-segment)
+                                             map)))
+            (setq segment-start (point))))))))
+
+(defun dired-jump-to-path-segment (event)
+  "Jump to the directory from a segment of the dired path."
+  (interactive "e")
+  (let* ((ev (event-end event))
+         (window (posn-window ev))
+         (pos (posn-point ev)))
+    (with-current-buffer (window-buffer window)
+      (let (beg end)
+        (save-excursion
+          (goto-char pos)
+          (when (search-forward "/" (line-end-position) t 1)
+            (setq end (point))
+            (while (search-backward "/" (line-beginning-position) t 1)
+              (setq beg (point)))))
+        (when beg
+          (let ((dir (buffer-substring-no-properties beg end)))
+            (if (member dir (mapcar 'car dired-subdir-alist))
+                (dired-goto-subdir dir)
+              (dired dir))))))))
+
 \f
 ;;; Reverting a dired buffer
 
-- 
2.25.1


  reply	other threads:[~2021-10-24 11:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-21 20:03 bug#21973: 24.5; feature proposal: make dired header clickable William Xu
2021-10-23  0:00 ` Stefan Kangas
2021-10-23 15:45   ` William Xu
2021-10-23 16:37     ` bug#21973: [External] : " Drew Adams
2021-10-24 11:09       ` William Xu [this message]
2021-10-24 14:07         ` Lars Ingebrigtsen
2021-10-24 19:05           ` Juri Linkov
2021-10-24 19:20             ` Lars Ingebrigtsen
2021-10-24 21:31         ` Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fssqk7br.fsf@gmail.com \
    --to=william.xwl@gmail.com \
    --cc=21973@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).