all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Piet van Oostrum <piet@cs.uu.nl>
To: help-gnu-emacs@gnu.org
Subject: Re: How to bind mouse-1 to find-file in dired?
Date: Wed, 20 Feb 2008 17:17:34 +0100	[thread overview]
Message-ID: <m24pc3k3fl.fsf@cochabamba.cs.uu.nl> (raw)
In-Reply-To: 622r53F1uskpiU1@mid.dfncis.de

>>>>> Arne Schmitz <arne.schmitz@gmx.net> (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 <piet@cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet@vanoostrum.org


      parent reply	other threads:[~2008-02-20 16:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-20 14:18 How to bind mouse-1 to find-file in dired? Arne Schmitz
2008-02-20 15:55 ` Johan Bockgård
2008-02-20 16:28   ` Arne Schmitz
2008-02-21  3:12     ` Kevin Rodgers
     [not found]     ` <mailman.7724.1203563559.18990.help-gnu-emacs@gnu.org>
2008-02-21 10:59       ` Arne Schmitz
2008-02-24 15:33         ` Kevin Rodgers
2008-02-20 16:17 ` Piet van Oostrum [this message]

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=m24pc3k3fl.fsf@cochabamba.cs.uu.nl \
    --to=piet@cs.uu.nl \
    --cc=help-gnu-emacs@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.