help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to bind mouse-1 to find-file in dired?


From: Piet van Oostrum
Subject: Re: How to bind mouse-1 to find-file in dired?
Date: Wed, 20 Feb 2008 17:17:34 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.90 (darwin)

>>>>> Arne Schmitz <address@hidden> (AS) wrote:

>AS> I want to get rid of dired-find-file-other-window. I tried the following in
>AS> my .emacs:

>AS> (eval-after-load "dired" '(progn (define-key dired-mode-map
>AS> (kbd "<mouse-1>") 'dired-find-file)))

>AS> But this does not seem to work. What should I do?

You can't just bind a mouse event to dired-find-file; you need a function
that  finds out where the mouse clicked.
I have just cut and pasted something from my .emacs. I hope I didn't forget
anything (actually I myself bind mouse-2 and then I have
mouse-1-click-follows-link set)

(defun dired-mouse-find-file (event)
  "In Dired, visit the file or directory name you click on."
  (interactive "e")
  (let (window pos file)
    (save-excursion
      (setq window (posn-window (event-end event))
            pos (posn-point (event-end event)))
      (if (not (windowp window))
          (error "No file chosen"))
      (set-buffer (window-buffer window))
      (goto-char pos)
      (setq file (dired-get-file-for-visit)))
    (if (file-directory-p file)
        (or (and (cdr dired-subdir-alist)
                 (dired-goto-subdir file))
            (progn
              (select-window window)
              (dired file)))
      (select-window window)
      (find-file (file-name-sans-versions file t)))))

(defun set-my-dired-keys-hook ()
  "My favorite dired keys."
  (local-set-key [mouse-1] 'dired-mouse-find-file)
; other keybindings if desired
)

(add-hook 'dired-mode-hook 'set-my-dired-keys-hook)

-- 
Piet van Oostrum <address@hidden>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: address@hidden


reply via email to

[Prev in Thread] Current Thread [Next in Thread]