Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1265765
  • 博文数量: 264
  • 博客积分: 10772
  • 博客等级: 上将
  • 技术积分: 2325
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-25 11:54
文章分类

全部博文(264)

文章存档

2012年(4)

2011年(51)

2010年(31)

2009年(57)

2008年(51)

2007年(70)

分类: LINUX

2007-11-20 18:41:56

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
 
阅读(893) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~