6085 comments
2357 subscribers
6224 on Twitter
Subscribe! Feed reader E-mail

Emacs, file-cache, and ido

(require 'filecache)
(require 'ido)
(defun file-cache-ido-find-file (file)
  "Using ido, interactively open file from file cache'.
First select a file, matched using ido-switch-buffer against the contents
in `file-cache-alist'. If the file exist in more than one
directory, select directory. Lastly the file is opened."
  (interactive (list (file-cache-ido-read "File: "
                                          (mapcar
                                           (lambda (x)
                                             (car x))
                                           file-cache-alist))))
  (let* ((record (assoc file file-cache-alist)))
    (find-file
     (expand-file-name
      file
      (if (= (length record) 2)
          (car (cdr record))
        (file-cache-ido-read
         (format "Find %s in dir: " file) (cdr record)))))))

(defun file-cache-ido-read (prompt choices)
  (let ((ido-make-buffer-list-hook
	 (lambda ()
	   (setq ido-temp-list choices))))
    (ido-read-buffer prompt)))
(add-to-list 'file-cache-filter-regexps "docs/html")
(add-to-list 'file-cache-filter-regexps "\\.svn-base$")
(add-to-list 'file-cache-filter-regexps "\\.dump$")
(defmacro sacha/file-cache-setup-tree (prefix shortcut directories)
  "Set up the file-cache tree for PREFIX using the keyboard SHORTCUT.
DIRECTORIES should be a list of directory names."
  `(let ((file-cache-alist nil)
	 (directories ,directories))
     (file-cache-clear-cache)
     (while directories
       (file-cache-add-directory-using-find (car directories))
       (setq directories (cdr directories)))
     (setq ,(intern (concat "sacha/file-cache-" prefix "-alist")) file-cache-alist)
     (defun ,(intern (concat "sacha/file-cache-ido-find-" prefix)) ()
       (interactive)
       (let ((file-cache-alist ,(intern (concat "sacha/file-cache-" prefix "-alist"))))
	 (call-interactively 'file-cache-ido-find-file)))
     (global-set-key (kbd ,shortcut)
		     (quote ,(intern (concat "sacha/file-cache-ido-find-" prefix))))))
Short URL: http://sachachua.com/blog/p/5572
  • le

    (sacha/file-cache-setup-tree
    “test”
    “C-c p”
    ‘(“c:/test”
    “~/elisp”))

    I ran the above code and got the below error, what can I do next?

    Filecache: file Access denied – C:/TEST does not exist
    Filecache: file File not found – -NAME does not exist
    Filecache: file File not found – -PRINT does not exist
    Filecache: file File not found – -NAME does not exist



    Filecache: file File not found – -PRINT does not exist

  • le

    The error is because I’m on winxp.

    Use this these linux utils for windows, and you should be fine:

    http://www.gnu.org/software/coreutils/

  • http://sachachua.com Sacha Chua

    Thanks for sharing the problem and its solution! =D

On This Day...

  • 2013: Cooking: Warm lentil salad with sausages — “Eat more healthily” is a popular New Year’s resolution. It’s on our list too – a push towards eating more [...]
  • 2012: LEGO and Indiana Jones: nuking the fridge got a lot more fun — W- picked up the LEGO Indiana Jones game to round out our collection, and we’ve all been enjoying it. The [...]
  • 2011: Moving my book notes online — I moved more of my book notes online, reasoning that a braindump is better than occasional whining about the lack [...]
  • 2010: On pen and paper — A friend of mine wanted to know my notebook preferences, so here’s what I do in terms of pen and [...]
  • 2010: Offline and online conversations — Do you miss the serendipity of hallway conversations at conferences and events? Online conversations can be more powerful than offline ones. [...]
  • 2009: AutoHotkey scripts for switching to windows — Muscle memory helps you be more efficient. Here’s some AutoHotkey code I use to toggle Chrome (F10), Windows Live Writer [...]
  • 2008: Teaching the attitude — J- was getting frustrated by the game of chess she was playing with her dad. She couldn’t see any good [...]
  • 2007: Neko — One of the little joys of being home is spending time with my cat, whom no one else loves, but stays [...]
  • 2007: On hold — You think that of all people, Simon and I would be able to find some way to talk for free (or [...]
  • 2007: You know, things aren’t so bad — There are lots of positive things to focus on. =) I just have to have faith that if I keep learning [...]
  • 2007: All that is precious — If I listen to the quiet stirrings of my heart, to the restlessness that prevents me from spending days here like [...]
  • 2005: One #emacs day – 0. 2005.01.05 and 1. 2005.01.06 — ([[EmacsDay#note1][EmacsDay:1]]”[[EmacsTips#note20][EmacsTips:20]]) (Technically, one and a half, because this is the first entry) Here are interesting tidbits from irc://irc.freenode.net/#emacs Code - M-x column-number-mode makes [...]
  • 2005: Physics in the City, Eastwood, Jan 15 — As Rick posted on PLUG: The organizers of the Physics in the City on Jan. 15 at Eastwood City have lined up [...]
  • 2005: The Command Line in 2004 — http://home.earthlink.net/~android606/commandline/index.html Garrett Birkel wrote an interesting response to Neal Stephenson’s “In the Beginning was the Command Line”. On Technorati: geek
  • 2005: 43Folders: Snapshots of a Dream Productivity App — Hooks and more hooks – As I’ve repeated until I’m hoarse, apps like Quicksilver change the way you use your Mac. [...]

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging