Sorry, I'm trying out yasnippet, and it expanded something in the code accidentally. Here is the right bits: (defun my-visit-file (arg) "Visit a file using completion. If there is only one window with nothing in it, then do not split the current window. " (interactive "P") (let ((insert-default-directory t) my-file) (when (equal arg '(4)) (setq insert-default-directory nil)) (setq my-file (read-file-name "my-visit-file: ")) (if (and (one-window-p) (zerop (buffer-size))) (find-file my-file) (find-file-ther-window my-file)))) (define-abbrev-table 'global-abbrev-table '(("spec" "/path/to/special/dir" nil 0))) On Tue, Jan 4, 2011 at 12:42 PM, Le Wang wrote: > On Tue, Jan 4, 2011 at 2:55 AM, Steven W. Orr wrote: > >> So, if you made it this far, here's the recap: >> >> 1. Does anything already exist that smells like what I want? >> > > Yes, abbrev (see below). I don't use them heavily myself, but here is a > tutorial: http://xahlee.org/emacs/emacs_abbrev_mode.html > > >> 2. Can I fix my-visit-file so that a C-u will prevent the default prompt >> from >> being the current directory of the file I'm starting from? (But I do still >> want filename completion.) >> > > Read the filename yourself, so you can have control: > > (defun my-visit-file (arg) > "Visit a file using completion. If there is only one window with > nothing in it, then do not split the current window. " > (interactive "P") > (let ((insert-default-directory t) > my-file) > (when (equal arg '(4)) > (setq insert-default-directory nil)) > (setq my-file (read-file-name "my-visit-file: ")) > (if (and (one-window-p) (zerop (buffer-size))) > (find-file my-file) > (find-file-(or )ther-window my-file)))) > > (define-abbrev-table 'global-abbrev-table > '(("spec" "/path/to/special/dir" nil 0))) > > > You can read the doc on `read-file-name' and `insert-default-directory' for > yourself. I've also added an abbrev table entry for "spec". So, if you > my-find-file, "spec", ae, it should expand do what you want. > > You can bind expansion to a shorter chord if you like. > > -- > Le > -- Le