unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#21973: 24.5; feature proposal: make dired header clickable
@ 2015-11-21 20:03 William Xu
  2021-10-23  0:00 ` Stefan Kangas
  0 siblings, 1 reply; 9+ messages in thread
From: William Xu @ 2015-11-21 20:03 UTC (permalink / raw)
  To: 21973

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

Sometimes when we are in some deep directory, it would be really
convenient to be able to jump to an arbitrary parent directory shown by
dired header.  e.g., a dired header line may be:

  /this/is/a/really/long/project/dir/curr:

If i want to open dired with `/this/is/a/really', i could simply click
at `really', without having to `^' a few times carefully.

I have something like below in my config file.  But it should be easy to
integrate it with `dired-insert-directory' in dired.el.

---------------------------------8<-------------------------------------
(defun xwl-dired-jump-to-parent (event)
  (interactive "e")
  (let (window pos file)
    (save-excursion
      (setq window (posn-window (event-end event))
            pos (posn-point (event-end event)))
      (with-current-buffer (window-buffer window)
        (goto-char pos)
        (when (search-forward "/" (line-end-position) t 1)
          (let ((beg 3)
                (end (point)))
            (dired (buffer-substring beg end))))))))

(defun xwl-dired-make-header-jumpable ()
  "Click on dired header will jump to that directory directly."
  (let ((inhibit-read-only t))
    (save-excursion
      (goto-char (point-min))
      (let ((bound (line-end-position))
            start end)
        (when (search-forward "/" bound t 1)
          (setq start (point))
          (while (search-forward "/" bound t 1)
            (setq end (1- (point)))
            (add-text-properties start end
                                 `(mouse-face
                                   highlight
                                   help-echo "mouse-1: goto here"
                                   keymap ,(let ((map (make-sparse-keymap)))
                                             (define-key map [down-mouse-1]
'xwl-dired-jump-to-parent)
                                             map)))
            (setq start (point))))))))

(add-hook 'dired-after-readin-hook 'xwl-dired-make-header-jumpable)
---------------------------------8<-------------------------------------

In GNU Emacs 24.5.2 (x86_64-apple-darwin14.5.0, Carbon Version 157 AppKit
1404.13)
 of 2015-11-08 on ULMMAC029
Repository revision: 232183c1fbb3665a51cfb1e9dbd380127bb4a971
Windowing system distributor `Apple Inc.', version 10.11.1
Configured using:
 `configure --with-mac'

- William

[-- Attachment #2: Type: text/html, Size: 3278 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-10-24 21:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).