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

1 Answer 1

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))))
2
  • 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, 2015 at 2:11
  • Oh, right; should be OK now. (I copy+pasted from a different command and winged the last part. ;-))
    – Drew
    Jun 25, 2015 at 3:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.