3

Is it possible to combine the following two functions so that the combined function will work with the keyboard keys (e.g., [return]) and also work with the mouse buttons? If so, how please?

Background: The functions are custom creations for an addition to dired-mode that propertizes the dired heading directory (i.e., the path at the top of the dired buffer) with links to open new dired buffers -- e.g., bredcrumbs -- Dired heading directory with text-properties to jump to parent directories

(defun dired-follow-link-with-mouse (event)
"Follow the link in the dired directory heading, causing a new
dired buffer to be opened."
(interactive "e")
  (mouse-set-point event)
  (let ((path (get-text-property (point) 'breadcrumb)))
    (dired path)))

(defun dired-follow-link-without-mouse ()
"Follow the link in the dired directory heading, causing a new
dired buffer to be opened."
(interactive)
  (let ((path (get-text-property (point) 'breadcrumb)))
    (dired path)))

(defvar dired-mouse-map
  (let ((map (make-sparse-keymap)))
    (define-key map [mouse-2] 'dired-follow-link-with-mouse)
    (define-key map [return] 'dired-follow-link-without-mouse)
    (define-key map [follow-link] 'mouse-face)
      map)
  "Keymap for mouse when in `dired-mode'.")
lawlist
  • 18,826
  • 5
  • 37
  • 118

1 Answers1

3

Yes.

(defun dired-follow-link-with-mouse (event)
"Follow the link in the dired directory heading, causing a new
dired buffer to be opened."
  (interactive (list last-nonmenu-event))
  (run-hooks 'mouse-leave-buffer-hook)
  (with-current-buffer (window-buffer (posn-window (event-start event)))
    (let ((path  (get-text-property (posn-point (event-start event)) 'breadcrumb)))
      (dired path))))
Drew
  • 75,699
  • 9
  • 109
  • 225
  • I believe we need to add `posn-point` to line 7, and place a closing parentheses at the end of the function, and that should be a wrap ... :) Thank you very much for your help -- greatly appreciated. – lawlist Jun 25 '15 at 02:11
  • Oh, right; should be OK now. (I copy+pasted from a different command and winged the last part. ;-)) – Drew Jun 25 '15 at 03:52