all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: William Xu <william.xwl@gmail.com>
To: 21973@debbugs.gnu.org
Subject: bug#21973: 24.5; feature proposal: make dired header clickable
Date: Sat, 23 Oct 2021 17:45:10 +0200	[thread overview]
Message-ID: <87fssr68zd.fsf@gmail.com> (raw)
In-Reply-To: <CACzMC-ChsgWzHkx7=CMwD1bL-iwGzEwKCh5pQb7TgWsny47=xg@mail.gmail.com>

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

Stefan Kangas <stefan@marxist.se> writes:

> I didn't read your patch in detail, but the feature sounds like a good
> idea.  Could you perhaps write it up as a patch?

Done. 

-- 
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: 2909 bytes --]

From 7a6ddf62541b65876cbc210fe7e49197ab8908a3 Mon Sep 17 00:00:00 2001
From: William Xu <william.xwl@gmail.com>
Date: Sat, 23 Oct 2021 17:07:21 +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 | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/lisp/dired.el b/lisp/dired.el
index 4652589122..ba9fa21f89 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1317,10 +1317,11 @@ dired-readin
 	  (erase-buffer)
 	  (dired-readin-insert))
 	(goto-char (point-min))
-	;; Must first make alist buffer local and set it to nil because
+        ;; Must first make alist buffer local and set it to nil because
 	;; dired-build-subdir-alist will call dired-clear-alist first
 	(setq-local dired-subdir-alist nil)
 	(dired-build-subdir-alist))
+      (dired-make-path-jumpable)
       (let ((attributes (file-attributes dirname)))
 	(if (eq (car attributes) t)
 	    (set-visited-file-modtime (file-attribute-modification-time
@@ -1643,6 +1644,43 @@ 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))
+      (let ((bound (line-end-position))
+            segment-start segment-end)
+        (when (search-forward "/" bound t 1)
+          (setq segment-start (point))
+          (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)
+      (save-excursion
+        (goto-char pos)
+        (when (search-forward "/" (line-end-position) t 1)
+          (let ((end (point))
+                beg)
+            (while (search-backward "/" (line-beginning-position) t 1)
+              (setq beg (point)))
+            (when beg
+              (dired (buffer-substring-no-properties beg end)))))))))
+
 \f
 ;;; Reverting a dired buffer
 
-- 
2.25.1


  reply	other threads:[~2021-10-23 15:45 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 [this message]
2021-10-23 16:37     ` bug#21973: [External] : " Drew Adams
2021-10-24 11:09       ` William Xu
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

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

  git send-email \
    --in-reply-to=87fssr68zd.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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.