From: Kevin Rodgers <kevin.d.rodgers@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Looking for CDPATH functionality in emacs.
Date: Mon, 03 Jan 2011 22:55:23 -0700 [thread overview]
Message-ID: <ifucno$bkf$1@dough.gmane.org> (raw)
In-Reply-To: <4D221B85.5040702@syslang.net>
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
next prev parent reply other threads:[~2011-01-04 5:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-03 18:55 Looking for CDPATH functionality in emacs Steven W. Orr
2011-01-03 19:08 ` Thien-Thi Nguyen
2011-01-03 19:20 ` Drew Adams
2011-01-03 20:16 ` Peter Dyballa
2011-01-04 4:42 ` Le Wang
2011-01-04 9:43 ` Le Wang
2011-01-04 5:55 ` Kevin Rodgers [this message]
2011-01-06 0:37 ` DevZero
[not found] <mailman.12.1294080915.3992.help-gnu-emacs@gnu.org>
2011-01-06 9:40 ` Stefan Kamphausen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='ifucno$bkf$1@dough.gmane.org' \
--to=kevin.d.rodgers@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).