C-x C-f 自动跳转到访问过的文件

在陈斌的配置中,C-x C-f 打开一个文件~/1/1.org之后,再打开~/2/2.org。然后C-x C-f,输入1,虽然是在2文件夹下,但是它会自动去匹配刚才打开的那个文件1.org,这个是怎么实现的?

不清楚,考虑看下 C-x C-f 所绑定的函数。


C-x C-f runs the command ido-find-file, which is an interactive
autoloaded compiled Lisp function in ‘ido.el’.

It is bound to , x f, <open>, C-x C-f, <menu-bar> <file> <new-file>.


:around advice: ‘ad-Advice-ido-find-file’

Edit file with name obtained via minibuffer.
The file is displayed according to ‘ido-default-file-method’ -- the
default is to show it in the same window, unless it is already visible
in another frame.

The file name is selected interactively by typing a substring.  As you
type in a string, all of the filenames matching the string are displayed
if substring-matching is used (default).  Look at ‘ido-enable-prefix’ and
‘ido-toggle-prefix’.  When you have found the filename you want, it can
then be selected.  As you type, most keys have their normal keybindings,
except for the following: 

RET	Select the file at the front of the list of matches.
	If the list is empty, possibly prompt to create new file.

C-j	Use the current input string verbatim.

C-s	Put the first element at the end of the list.
C-r	Put the last element at the start of the list.
TAB	Complete a common suffix to the current string that matches
	all files.  If there is only one match, select that file.
	If there is no common suffix, show a list of all matching files
	in a separate window.
C-d	Open the specified directory in Dired mode.
C-e	Edit input string (including directory).
M-p	Go to previous directory in work directory history.
M-n	Go to next directory in work directory history.
M-s	Search for file in the work directory history.
M-k	Remove current directory from the work directory history.
M-o	Cycle to previous file in work file history.
C-M-o	Cycle to next file in work file history.
M-f	Prompt for a file and use find to locate it.
M-d	Prompt for a directory and use find to locate it.
M-m	Prompt for a directory to create in current directory.
C-x C-f	Fallback to non-Ido version of current command.
C-t	Toggle regexp searching.
C-p	Toggle between substring and prefix matching.
C-c	Toggle case-sensitive searching of file names.
M-l	Toggle literal reading of this file.
?	Show list of matching files in separate window.
C-a	Toggle ignoring files listed in ‘ido-ignore-files’.



;; Use C-f during file selection to switch to regular find-file
(require 'flx-ido)
(ido-mode 'file)  ; use 'buffer rather than t to use only buffer switching
(flx-ido-mode 1)
;; disable ido faces to see flx highlights.
(setq ido-enable-flex-matching t)
(setq ido-use-faces nil)
(setq ido-use-filename-at-point nil)
(setq ido-auto-merge-work-directories-length 0)
(setq ido-use-virtual-buffers t)
;; @see https://github.com/lewang/flx
(setq flx-ido-threshold 10000)
;; Allow the same buffer to be open in different frames
(setq ido-default-buffer-method 'selected-window)

;; disable ido for certain commands,
;; @see http://stackoverflow.com/questions/6771664/disable-ido-mode-for-specific-commands
(defadvice ido-read-buffer (around ido-read-buffer-possibly-ignore activate)
  "Check to see if use wanted to avoid using ido"
  (if (eq (get this-command 'ido) 'ignore)
      (let ((read-buffer-function nil))
        (run-hook-with-args 'ido-before-fallback-functions 'read-buffer)
        (setq ad-return-value (apply 'read-buffer (ad-get-args 0))))
(put 'shell 'ido 'ignore)
(put 'ffap-alternate-file 'ido 'ignore)
(put 'tmm-menubar 'ido 'ignore)
(put 'dired-do-copy 'ido 'ignore)
(put 'dired-do-rename 'ido 'ignore)
(put 'vc-copy-file-and-rename-buffer 'ido 'ignore)
(put 'dired-create-directory 'ido 'ignore)
(put 'copy-file-and-rename-buffer 'ido 'ignore)
(put 'rename-file-and-buffer 'ido 'ignore)
(put 'w3m-goto-url 'ido 'ignore)
(put 'ido-find-file 'ido 'ignore)
(put 'ido-edit-input 'ido 'ignore)
(put 'read-file-name 'ido 'ignore)
(put 'dired-create-directory 'ido 'ignore)
(put 'minibuffer-completion-help 'ido 'ignore)
(put 'minibuffer-complete 'ido 'ignore)
(put 'c-set-offset 'ido 'ignore)
(put 'rgrep 'ido 'ignore)
(put 'dired-create-directory 'ido 'ignore)

(provide 'init-ido)