anything用起来很舒服,但我现在想加入一个长期希望的功能:让其不光能搜索当前文件目录下的文件,也能搜索某一个或几个指定目录下的文件。
我现在的配置如下:其中anything-c-source-files-in-current-dir+ 使其搜索当前文件的目录。
(require 'anything-config)
(global-set-key (kbd "<f12>")
(lambda() (interactive)
(anything
:prompt "Switch to: "
:candidate-number-limit 15 ;; up to 15 of each
:sources
'( anything-c-source-buffers ;; buffers
anything-c-source-bookmarks ;; bookmarks
anything-c-source-files-in-current-dir+ ;; current dir
anything-c-source-recentf ;; recent files
))))
加入额外搜索的指定目录,如:c\users\xyz\,如何做呢?我找了很多资料,最为相近的一个实现如下(
http://emacswiki.org/emacs/AnythingSources#toc14, 相应代码见后),但弄了很久没有成功。其中path怎么写实在不知道,试了各种方法无果。。。
谢谢大家。
File Search
This one searches for a matching file recursively, either in your project (please implement ‘my-get-source-directory’) or down from the default directory. The search uses ‘find’ and starts when the input is 4 or more characters.
Currently it skips ‘.svn’ directories.
(defun my-get-source-directory (path)
"Please imlement me. Currently returns `path' inchanged."
path)
(defvar my-anything-c-source-file-search
'((name . "File Search")
(init . (lambda ()
(setq anything-default-directory
default-directory)))
(candidates . (lambda ()
(let ((args
(format "'%s' \\( -path \\*/.svn \\) -prune -o -iregex '.*%s.*' -print"
(my-get-source-directory anything-default-directory)
anything-pattern)))
(start-process-shell-command "file-search-process" nil
"find" args))))
(type . file)
(requires-pattern . 4)
(delayed))
"Source for searching matching files recursively.")
--
[36m※ 修改:·nightrain 于 May 18 17:42:32 2012 修改本文·[FROM: 166.111.224.*] [m
[m [35m※ 来源:·水木社区
http://newsmth.net·[FROM: 166.111.224.*] [m