dired模式下,当鼠标点击一个文件或者目录时,调用的是dired-mouse-find-file-other-window,这感觉很别扭,很不方便
参考了/usr/local/share/emacs/22.1/lisp下面的dired.el文件
修改dired-mouse-find-file-other-window函数里的两行,将下面的代码添加到.emacs里,即实现了在当前buffer中打开该文件或目录
---------------------------------------------------------------
(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)
(find-file file)))
(select-window window)
(find-file (file-name-sans-versions file t)))))
(add-hook 'dired-mode-hook
'(lambda ()
(define-key dired-mode-map [mouse-2] 'dired-mouse-find-file)))
----------------------------------------------------------------
或者直接修改dired.el文件,然后删掉dired.elc,再在emacs中用byte-compile-file编译就可以了,这样不用去改.emacs
阅读(887) | 评论(0) | 转发(0) |