help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Looking for CDPATH functionality in emacs.


From: Kevin Rodgers
Subject: Re: Looking for CDPATH functionality in emacs.
Date: Mon, 03 Jan 2011 22:55:23 -0700
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7

On 1/3/11 11:55 AM, Steven W. Orr wrote:
This is a bit long, so all I can do is apologise.

I have a number of directories that I use frequently. From the bash side of
things I set the CDPATH variable in bash to :d1:d2:d3 and then I can just go
to places inside d[123] and it just works. I also have the bash variable
cdable_vars set to allow me to say

d4=/path/to/d4

followed by

cd d4

and it all works peachy keen.

What I'd like to do in emacs is to be able to visit a file in some directory
that I favor (somehow) so that it will automagically find it without having to
slog through the whole path to get there.

I did find file-cache-find-directory which looks like it's half of what I
want. But that has two problems:

1. I added this to my .emacs

(file-cache-add-directory "/path/to/special/dir")

I saw no special behavior when I ran this, either from my .emacs or 
interactively.

According to filecache.el:

;; FINDING FILES USING THE CACHE:
;;
;; You can use the file-cache with any function that expects a filename as
;; an argument. For example:
;;
;; 1) Invoke a function which expects a filename as an argument:
;;    M-x find-file
;;
;; 2) Begin typing a file name.
;;
;; 3) Invoke `file-cache-minibuffer-complete' (bound by default to
;; C-TAB) to complete on the filename using the cache.
;;
;; 4) When you have found a unique completion, the minibuffer contents
;; will change to the full name of that file.
;;
;; If there are a number of directories which contain the completion,
;; invoking `file-cache-minibuffer-complete' repeatedly will cycle through
;; them.
;;
;; 5) You can then edit the minibuffer contents, or press RETURN.
;;
;; It is much easier to simply try it than trying to explain it :)

2. I normally visit files using my own my-visit-file function:

(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 "Fmy-visit-file :")
   (if (and (one-window-p) (zerop (buffer-size)))
       (find-file arg t)
       (find-file-other-window arg t)))

I use this function so that if I visit a file from an empty buffer, I won't
end up with two windows.

Actually, that is Emacs' default behavior.  Using M-x my-visit-file
only behaves differently than M-x find-file when you have more than one
window or the current is not empty: in that case, it behaves like
M-x find-file-other-window.

The problem is that if I had run file-cache-add-directory, the find-file
function starts in the directory of where the current buffer is. I'd like to
make it so that if I supplied a C-u to my-visit-file then it would *not* start
from that current directory. Instead, it should give me a prompt as if I had
done a C-a C-k to get rid of the directory.

Reading a file name via (interactive "F...") always starts from the current
buffer's default directory, regardless of whether file-cache-add-directory
has been run.

If you want to make my-find-file behave differently when reading its ARG,
depending on whether a prefix arg was supplied, then change the interactive
form to use a lisp expression that respects current-prefix-arg (instead of a
string specifier).

So, if you made it this far, here's the recap:

1. Does anything already exist that smells like what I want?

Use filecache as it is documented.

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.)

(interactive (list (if current-prefix-arg
                       (read-file-name "My file: " "/")
                     (read-file-name "My file: "))))

3. Does anyone have a better idea?

:-)

--
Kevin Rodgers
Denver, Colorado, USA




reply via email to

[Prev in Thread] Current Thread [Next in Thread]