combile switching buffer and open files/directories

Tamas Patrovics posted timid.el a couple days ago, and I find it really useful:

The original goal was to help open history files with find-file. However yesterday he make it possible to use with iswitchb-buffer: The history file list also shows up there.

First of all I rebind some keys cause I don’t like move my finger from the main keyboard area to the arrow keys:

;;; easy open files
(require ‘timid)
(setq timid-keys
(list (cons (kbd "<C-return>") ‘timid-select-file)
(cons (kbd "C-p") ‘timid-previous-line)
(cons (kbd "C-n") ‘timid-next-line)
(cons (kbd "M-v") ‘timid-previous-page)
(cons (kbd "C-v") ‘timid-next-page)))
(timid-mode t)

I also rebind timid-select-file to C-return so I can hit RET for what’s the current in mini-buffer, and C-return for what’s the current in the \*timid\* buffer.

The current timid.el use file-name-history, which is a list of file names entered in the minibuffer. However I’m a heavy dired user. So I over write it like this:

;; overwrite
(defun timid-iswitchb-setup ()
"Setup timid to work with iswitchb."
(interactive)
(require ‘iswitchb)
(put ‘iswitchb-buffer ‘timid-pattern-function ‘timid-iswitchb-get-pattern)
(put ‘iswitchb-buffer ‘timid-candidates-variable ‘recentf-list)
(put ‘iswitchb-buffer ‘timid-visit-file-function ‘timid-iswitchb-visit-file)
(put ‘iswitchb-buffer ‘timid-search-delay 0.5)
(put ‘iswitchb-buffer ‘timid-completion t))
(timid-iswitchb-setup)

The recentf-list contains files I opened with both the minibuffer and dired.

(require ‘recentf)

And, well, recentf only record file names. I want it to remember my dired buffers too. Cause I switch-buffer to a dired buffer often, and it’s nice to open it if it’s not openned already:

;; also save directories openned with dired
(defsubst ddliu-recentf-add-directory (dirname)
"Add or move FILENAME at the beginning of the recent list.
Does nothing if the name satisfies any of the `recentf-exclude’
regexps or predicates."

(when (recentf-include-p dirname)
(recentf-push dirname)))

(defun ddliu-recentf-track-opened-directory ()
“Insert the name of the file just opened or written into the recent list.”
(and dired-directory
(ddliu-recentf-add-directory dired-directory))
;; Must return nil because it is run from `write-file-functions’.
nil)

(setq recentf-used-hooks
‘(
(find-file-hook recentf-track-opened-file)
(write-file-functions recentf-track-opened-file)
(kill-buffer-hook recentf-track-closed-file)
(kill-emacs-hook recentf-save-list)
(dired-after-readin-hook ddliu-recentf-track-opened-directory)
)
)

;; this need to be after the recentf-used-hooks overwrite above
(recentf-mode 1)
Now with lots of history infos

(setq recentf-max-saved-items 2000)

I don’t need to remember if I’ve openned a file/directory: just C-x b and type the name. If it’s not openned already, the timid buffer will show up and I can open it immediately.

One thing is that I’m a ido.el user. The current code of timid.el only support iswitchb.el. Although it is possible to write ido support code, I don’t have the time to dive in ido code right. Anyway, with all the handy things, it’s not a bad idea to use ido for file open only:

(ido-mode ‘files)

Tags:

Post a Comment

You could use <code type="name"> to get your code colorized

Your email is never published nor shared. Required fields are marked *

Close
E-mail It