From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marc Mientki Newsgroups: gmane.emacs.help Subject: Re: using mouse to select a file in dired Date: Tue, 05 Oct 2010 10:20:09 +0200 Organization: http://onet.pl Message-ID: References: <313632af-2a72-49a3-85b8-5fb4eccb57a7@l20g2000yqm.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1291868865 8086 80.91.229.12 (9 Dec 2010 04:27:45 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 9 Dec 2010 04:27:45 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 09 05:27:41 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PQY6W-0001vG-Rn for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 05:27:41 +0100 Original-Received: from localhost ([127.0.0.1]:53782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQY4G-0000P3-2M for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 23:25:20 -0500 Original-Path: usenet.stanford.edu!goblin2!goblin.stu.neva.ru!news.nask.pl!news.nask.org.pl!news.onet.pl!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 153 Original-NNTP-Posting-Host: port-83-236-194-74.static.qsc.de Original-X-Trace: news.onet.pl 1286266810 25338 83.236.194.74 (5 Oct 2010 08:20:10 GMT) Original-X-Complaints-To: niusy@onet.pl Original-NNTP-Posting-Date: Tue, 5 Oct 2010 08:20:10 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4 In-Reply-To: <313632af-2a72-49a3-85b8-5fb4eccb57a7@l20g2000yqm.googlegroups.com> Original-Xref: usenet.stanford.edu gnu.emacs.help:181641 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:76642 Archived-At: Am 04.10.2010 21:42, schrieb Ray Voith: > When I am in a dired and click on an entry, it opens it in > another window. > I prefer that it open it in the same window that the dired is in. How > can I set up to do this? Hmmm... let's see... You click on a file in dired and Emacs do something not exactly what you want. So we first look what happens when we cklick on a file in dired. We type 'C-h k' and than simply click on some file in dired buffer. We get this in a new buffer: -- BEGIN ---------------------------------------------------------- at that spot runs the command mouse-drag-region, which is an interactive compiled Lisp function in `mouse.el'. It is bound to . (mouse-drag-region START-EVENT) Set the region to the text that the mouse is dragged over. Highlight the drag area as you move the mouse. This must be bound to a button-down mouse event. In Transient Mark mode, the highlighting remains as long as the mark remains active. Otherwise, it remains until the next input event. If the click is in the echo area, display the `*Messages*' buffer. ----------------- up-event (short click) ---------------- at that spot is remapped to , which runs the command dired-mouse-find-file-other-window, which is an interactive compiled Lisp function in `dired.el'. It is bound to . (dired-mouse-find-file-other-window EVENT) In Dired, visit the file or directory name you click on. ----------------- up-event (long click) ---------------- Pressing at that spot for longer than 450 milli-seconds runs the command mouse-set-point, which is an interactive compiled Lisp function in `mouse.el'. It is bound to , , , , . (mouse-set-point EVENT) Move point to the position clicked on with the mouse. This should be bound to a mouse click event type. -- END ------------------------------------------------------------ We look around for something suspicious and find an interesting hint to the function dired-mouse-find-file-other-window in file dired.el. This 'dired.el' is a link to the right place in the file so we go on it with TAB and land in dired.el on definition of dired-mouse-find-file-other-window. Actually, the name says the whole story - "-OTHER-WINDOW". Unfortunately there is no function like dired-mouse-find-file. The function dired-find-file is no alternative because it handles no events and we need event handling due to mouse operation. So there is no simple solution like replacement of the keybinding of [mouse-2] to another existing function. But what it does not exist, you have to do it himself. So let's look at the function definition: -- BEGIN ---------------------------------------------------------- (defun dired-mouse-find-file-other-window (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-other-window file))) (select-window window) (find-file-other-window (file-name-sans-versions file t))))) -- END ------------------------------------------------------------ As we can see most important story plays at the end. There is a distinction, if we click on a directory or a file - (if (file-directory-p file) ...). But no matter where we click, the operation is executed in a new window - dired-other-window or find-file-other-window. So the simplest solution is to replace this both function to version that do the same job without window change. Fortunately, there are similar correspondences. We take dired in place of dired-other-window and find-file in place of find-file-other-window and name the new function properly: -- BEGIN ---------------------------------------------------------- (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))))) -- END ------------------------------------------------------------ The last step is to bind this new function to the right event in the right key map. As seen above, the event was 'mouse-2'. The name of the key-map we also learn in dired.el. We search simply for 'dired-mouse-find-file-other-window' and find: (defvar dired-mode-map ;; This looks ugly when substitute-command-keys uses C-d instead d: ;; (define-key dired-mode-map "\C-d" 'dired-flag-file-deletion) (let ((map (make-keymap))) (suppress-keymap map) (define-key map [mouse-2] 'dired-mouse-find-file-other-window) ... So all we need is: (define-key dired-mode-map [mouse-2] 'dired-mouse-find-file) Short test and it works! :-) HTH regards Marc