开发者

Emacs dired mode and Isearch

开发者 https://www.devze.com 2023-01-31 07:00 出处:网络
I recently discovered some of the power and easy of use of dired mode of Emacs. But in Krusader, I just begin press first letter(s) of folder/file, and press enter, and so I go deep, then search for

I recently discovered some of the power and easy of use of dired mode of Emacs. But in Krusader, I just begin press first letter(s) of folder/file, and press enter, and so I go deep, then search for another fo开发者_JAVA技巧lder, focus, press enter until I found the file I should open.

How I do it in dired now:

  • press Ctrl+S for isearch
  • press the letters for finding folder
  • press enter (or some other combination) once to escape I-search
  • press enter to enter folder or open file (for opening file I know I have other letters as well)

I really need to make this easier. So the main thing I want is when I press enter once, to:

  • escape Isearch
  • enter folder (or open file)

Of course the second main thing would be to BE by default in some isearch mode with dired, to just navigate by typing, and only when press ESC to be in that dired mode where single letters have commands meanings. I'm not sure if this second main thing is easy possible or recommended for dired. But the main thing I believe should be doable with a few smart Lisp lines, which I don't know :)

Thank you guys,

Stefan


Here's one way to do the main thing:

(add-hook 'isearch-mode-end-hook 
  (lambda ()
    (when (and (eq major-mode 'dired-mode)
           (not isearch-mode-end-hook-quit))
      (dired-find-file))))


For the second main thing:

(defadvice dired (after activate)
  (isearch-forward))

(ad-activate 'dired)


(defadvice dired-find-file (after activate)
  (isearch-forward))

(ad-activate 'dired-find-file)


(defadvice dired-up-directory (after activate)
   (isearch-forward))

(ad-activate 'dired-up-directory)


Piggy-backing on madalu's answer, you can get close to the second main thing by stringing isearches together:

(add-hook 'isearch-mode-end-hook 
  (lambda ()
    (when (and (eq major-mode 'dired-mode)
               (not isearch-mode-end-hook-quit))
      (dired-find-file)
      (isearch-forward-regexp))))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号