unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Looking for interactive `locate-file'
@ 2007-03-06  1:53 Denis Bueno
  2007-03-06  2:37 ` Stefan Monnier
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Denis Bueno @ 2007-03-06  1:53 UTC (permalink / raw)
  To: emacs-devel

Dear list-

I would like to be able to interactive find a file inside a list of
paths, interactively, and in a way that supports some basic pattern
matching. (For reference, the reason I want this is that Eclipse has
it, and I find it quite useful.) Currently, I have a first
approximation [1], but, it sucks. All it does is ask for a (possibly
non-existent) filename, then look for that in a default list of paths.

I want to set up a list of directories pertaining to a particular
project. Then when I M-x find-resource, I want it to ask for the
filename and look in those paths for it -- interactively, listing all
matches as I type. So if I were to type "type*.jsp", a results buffer
would list all the files matching that pattern.

Has anyone written something like what I'm looking for, before?

-Denis

[1]

;; make sure you put some directories in here:
(defvar *project-paths* '())

(defun find-resource (filename)
  "Find `filename' in *project-paths*, if it can be found in any
directory there. If not, returns nil."
  (interactive "FFilename: ")
  (let ((file (locate-file filename *project-paths*)))
    (if file (find-file file)
      (message (concat "`" filename "' not found.")))))

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Looking for interactive `locate-file'
  2007-03-06  1:53 Looking for interactive `locate-file' Denis Bueno
@ 2007-03-06  2:37 ` Stefan Monnier
  2007-03-06  3:32   ` Denis Bueno
  2007-03-06 11:37 ` Johan Bockgård
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2007-03-06  2:37 UTC (permalink / raw)
  To: Denis Bueno; +Cc: emacs-devel

> I would like to be able to interactive find a file inside a list of
> paths, interactively, and in a way that supports some basic pattern
> matching. (For reference, the reason I want this is that Eclipse has
> it, and I find it quite useful.) Currently, I have a first
> approximation [1], but, it sucks. All it does is ask for a (possibly
> non-existent) filename, then look for that in a default list of paths.

> I want to set up a list of directories pertaining to a particular
> project. Then when I M-x find-resource, I want it to ask for the
> filename and look in those paths for it -- interactively, listing all
> matches as I type. So if I were to type "type*.jsp", a results buffer
> would list all the files matching that pattern.

> Has anyone written something like what I'm looking for, before?

Have you tried M-x load-library while using partial-completion-mode?
It sounds fairly close to what you describe,


        Stefan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Looking for interactive `locate-file'
  2007-03-06  2:37 ` Stefan Monnier
@ 2007-03-06  3:32   ` Denis Bueno
  2007-03-06 14:32     ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Denis Bueno @ 2007-03-06  3:32 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On 3/5/07, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> Have you tried M-x load-library while using partial-completion-mode?
> It sounds fairly close to what you describe,

`load-library' seems to be a lisp thing -- that is, it seems designed
to load .el/.elc files. Is that correct? Should I consider it a more
general tool?

I turned on `partial-completion-mode'. I hadn't heard about it before.
Definitely a big step in the right direction.

Thanks for the help.

-Denis

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Looking for interactive `locate-file'
  2007-03-06  1:53 Looking for interactive `locate-file' Denis Bueno
  2007-03-06  2:37 ` Stefan Monnier
@ 2007-03-06 11:37 ` Johan Bockgård
  2007-03-06 14:29 ` Drew Adams
  2007-03-06 16:23 ` Stuart D. Herring
  3 siblings, 0 replies; 7+ messages in thread
From: Johan Bockgård @ 2007-03-06 11:37 UTC (permalink / raw)
  To: emacs-devel

"Denis Bueno" <dbueno@gmail.com> writes:

> Has anyone written something like what I'm looking for, before?

Something:

(info "(emacs)File Name Cache")
(info "(emacs)File Conveniences")
(info "(emacs)Filesets")

-- 
Johan Bockgård

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: Looking for interactive `locate-file'
  2007-03-06  1:53 Looking for interactive `locate-file' Denis Bueno
  2007-03-06  2:37 ` Stefan Monnier
  2007-03-06 11:37 ` Johan Bockgård
@ 2007-03-06 14:29 ` Drew Adams
  2007-03-06 16:23 ` Stuart D. Herring
  3 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2007-03-06 14:29 UTC (permalink / raw)
  To: Denis Bueno, Help-Gnu-Emacs; +Cc: emacs-devel

> I would like to be able to interactive find a file inside a list of
> paths, interactively, and in a way that supports some basic pattern
> matching. (For reference, the reason I want this is that Eclipse has
> it, and I find it quite useful.) Currently, I have a first
> approximation [1], but, it sucks. All it does is ask for a (possibly
> non-existent) filename, then look for that in a default list of paths.
> 
> I want to set up a list of directories pertaining to a particular
> project. Then when I M-x find-resource, I want it to ask for the
> filename and look in those paths for it -- interactively, listing all
> matches as I type. So if I were to type "type*.jsp", a results buffer
> would list all the files matching that pattern.
> 
> Has anyone written something like what I'm looking for, before?

Yes. http://www.emacswiki.org/cgi-bin/wiki/LocateFilesAnywhere

P.S. help-gnu-emacs@gnu.org is probably the right list for this.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Looking for interactive `locate-file'
  2007-03-06  3:32   ` Denis Bueno
@ 2007-03-06 14:32     ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2007-03-06 14:32 UTC (permalink / raw)
  To: Denis Bueno; +Cc: emacs-devel

>> Have you tried M-x load-library while using partial-completion-mode?
>> It sounds fairly close to what you describe,

> `load-library' seems to be a lisp thing -- that is, it seems designed
> to load .el/.elc files. Is that correct? Should I consider it a more
> general tool?

No, but if its behavior is like the behavior you're looking after, then it's
probably a good idea to take a look at its code, right?


        Stefan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Looking for interactive `locate-file'
  2007-03-06  1:53 Looking for interactive `locate-file' Denis Bueno
                   ` (2 preceding siblings ...)
  2007-03-06 14:29 ` Drew Adams
@ 2007-03-06 16:23 ` Stuart D. Herring
  3 siblings, 0 replies; 7+ messages in thread
From: Stuart D. Herring @ 2007-03-06 16:23 UTC (permalink / raw)
  To: Denis Bueno; +Cc: emacs-devel

> Dear list-
>
> I would like to be able to interactive find a file inside a list of
> paths, interactively, and in a way that supports some basic pattern
> matching. (For reference, the reason I want this is that Eclipse has
> it, and I find it quite useful.) Currently, I have a first
> approximation [1], but, it sucks. All it does is ask for a (possibly
> non-existent) filename, then look for that in a default list of paths.

What I have written is an improvement on this approximation: it does
recursive searches and automatically figures out where GCC keeps its
include files.

;; Should these be organized by extension or so?
(defvar common-file-locations
  (eval-when-compile
    (nconc
     (let ((str (shell-command-to-string "g++ -v -xc++ /dev/null")))
       (and
        (string-match "^#include <...> search starts
here:\n\\(\\(?:.*\n\\)*?\\)End of search list." str)
        (split-string (match-string 1 str) " *\n *\\|^ *")))
     '("/etc" "~")))
  "Directories in which to find common files.")

(defun locate-common-file (name &optional noisy)
  "Return full file name ending in NAME, or nil if not found.
NAME is a relative file name.
Looks in `common-file-locations', then looks in all directories they contain.
The current directory is considered to be the first element of the list.
If called interactively (NOISY is numeric), print the name.
If NOISY is otherwise non-nil, print messages during search."
  (interactive "sCommon file: \np")
  (let* ((places (cons default-directory common-file-locations))
         (ret (save-match-data
                (catch 'file
                  (dolist (dir places)
                    (let ((full (expand-file-name name dir)))
                      (if (file-regular-p full) (throw 'file full))))
                  (dolist (dir places)
                    (if noisy (message "Searching %s..." dir))
                    (locate-common-file-0 name dir)) nil))))
    (if (numberp noisy) (if ret (message "%s is %s" name ret)
                          (message "%s not found" name)))
    ret))

(defun locate-common-file-0 (name dir)
  "Throw full name of file in DIR ending in NAME to `file'.
Return normally if not found."
  (setq dir (file-name-as-directory dir))
  (let ((full (expand-file-name name dir)))
    (if (file-regular-p full) (throw 'file full)))
  (dolist (entry (directory-files dir t))
    (or (file-symlink-p entry)
        (string-match "\\.\\.?" (file-name-nondirectory entry))
        (and (file-directory-p entry) (file-readable-p entry)
             (locate-common-file-0 name entry)))))

Then I have this command to call it, whose utility is in its default value:

(defvar common-file-characters "a-zA-Z0-9-_+./"
  "Characters composing common file names, for use with `find-common-file'.
The default is chosen to be useful with #include directives.")

(defun find-common-file (name)
  "Visit common file NAME.
See `locate-common-file'."
  (interactive
   (list
    (let ((def (buffer-substring
                (point-after (skip-chars-backward common-file-characters))
                (point-after (skip-chars-forward common-file-characters))))
          val)
      (if (zerop (length def)) (setq def nil))
      (setq val (read-string
                 (if def (format "Common file: (default %s) " def)
                   "Common file: ") nil def))
      (if (zerop (length val)) def val))))
  (find-file (or (locate-common-file name t)
                 (error "Cannot find common file: %s" name))))

Together it makes header files (my original application) a cinch, but it
works on lots of other things too.  Obviously it doesn't deal with file
name patterns, but I've found it useful.  (If others do, too, I'll
probably post it at the EmacsWiki page Drew mentioned.)

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-03-06 16:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-06  1:53 Looking for interactive `locate-file' Denis Bueno
2007-03-06  2:37 ` Stefan Monnier
2007-03-06  3:32   ` Denis Bueno
2007-03-06 14:32     ` Stefan Monnier
2007-03-06 11:37 ` Johan Bockgård
2007-03-06 14:29 ` Drew Adams
2007-03-06 16:23 ` Stuart D. Herring

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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