From: "Denis Bueno" <dbueno@gmail.com>
To: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Interactively finding file in a list of directories
Date: Fri, 9 Mar 2007 10:52:13 -0500 [thread overview]
Message-ID: <6dbd4d000703090752q5067f8e3i69d74d07d9cb51fd@mail.gmail.com> (raw)
All-
I'm seeking advice on how to improve a bit of code I've written. As
the subject says, I would like to be able to visit a file by its name
but search a set of default directories, rather than having to specify
the directory. (This ability exists in Eclipse under the name "Find
resource.")
For example, assume there are 4 different files all named "find.jsp"
in different directories, and I would like to find a particular one. I
would do M-x find-resource, type "find", hit TAB, it I would see a
list that looks something like:
,----
| foobar/find.jsp
| baz/find.jsp
| duh/find.jsp
| blah/find.jsp
`----
I would then C-x o to the completion buffer, hit Return on the file I
want, and Emacs will visit it.
I have some code that works as a first approximation, but it has a few bugs:
1. (the major problem) The completion folds all results which have
the same filename. Assuming the above example, the completion buffer
displays "find.jsp" but I have no idea which actual file that
corresponds to. There are no other listings of "find.jsp" in the
completion buffer.
2. It doesn't handle suffixes properly. Assuming there were a file
"baz/find.txt" in the filesystem of previous example, it would be
listed.
Does anyone have any advice on how I can fix the above bugs?
-Denis
;; --- `find-resource' kind of like in Eclipse.
;; BUGS: for some reason the completing buffer shows filenames that have an
;; extension *not* in `find-resource-suffixes'.
(defvar find-resource-paths
(list "~/")
"*List of paths to search when using `find-resource'; format it
like `load-path'.")
;(make-variable-buffer-local 'find-resource-paths)
(defvar find-resource-suffixes
(list "")
"*List of file suffixes used when doing completion in `find-resource'.")
(defun find-resource-add-path (path)
"Add a path used by `find-resource'."
(interactive "DPath: ")
(add-to-list 'find-resource-paths path))
(defun find-resource (filename)
"Find a file `filename' in `find-resource-paths', using
`find-resource-suffixes', and visit it. The structure of
`find-resource' cribbed from `load-library'."
(interactive
(list (completing-read "Find resource: "
'locate-file-completion
(cons find-resource-paths
find-resource-suffixes))))
(let ((f (locate-file filename
find-resource-paths
(cons "" find-resource-suffixes))))
(if f (find-file f)
(message "Could not find `%S' after completing completing-read (bug)"
filename))))
next reply other threads:[~2007-03-09 15:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-09 15:52 Denis Bueno [this message]
2007-03-09 16:20 ` Interactively finding file in a list of directories Drew Adams
2007-03-09 20:51 ` Peter Dyballa
2007-03-09 21:25 ` Drew Adams
2007-03-09 22:13 ` Denis Bueno
2007-03-09 22:59 ` Peter Dyballa
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=6dbd4d000703090752q5067f8e3i69d74d07d9cb51fd@mail.gmail.com \
--to=dbueno@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).