all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* make project--find-in-file generic, add interactive filename to project-find-file
@ 2016-01-28  1:04 Stephen Leake
  2016-01-28  9:21 ` Dmitry Gutov
  0 siblings, 1 reply; 32+ messages in thread
From: Stephen Leake @ 2016-01-28  1:04 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 530 bytes --]

Any objections to the attached patch?

Having a "filename" parameter for `project-find-file' is useful with
comments like:

 // see file "fancy_hack.c" for more details

Put point on "fancy_hack.c", M-x project-find-file (or your favorite key
binding), and the file comes up.


Making `project--find-file-in' generic allows my ede and ada-mode
backends to override the default implementation.


The change in xref just provides a missing doc string for a function
that is used by the default project--find-file-in.

-- 
-- Stephe

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: project-find-file-patch.diff --]
[-- Type: text/x-patch, Size: 3681 bytes --]

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 85f3907..becccbb 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -154,6 +154,15 @@ project--find-in-directory
     vc-directory-exclusion-list)
    grep-find-ignored-files))
 
+(cl-defgeneric project--find-file-in (filename dirs project)
+  "Complete FILENAME (a string or nil) in directories DIRS; visit the file.
+If non-nil, DIRS is a list of absolute directories; it should be some
+subset of the project roots and external roots. If nil, the backend
+uses all the directories it knows about.
+PROJECT is used to find the project ignores and other project meta-data."
+  ;; dispatch on PROJECT
+  )
+
 (defgroup project-vc nil
   "Project implementation using the VC package."
   :version "25.1"
@@ -312,31 +321,34 @@ project--find-regexp-in
     (xref--show-xrefs xrefs nil)))
 
 ;;;###autoload
-(defun project-find-file ()
-  "Visit a file in the current project's roots.
-
-This is like `find-file', but it limits the file-name completion
-candidates to the files within the current project roots."
-  (interactive)
+(defun project-find-file (filename)
+  "Visit FILENAME in the current project's roots.
+FILENAME defaults to the filename at point (nil if none
+recognized).
+FILENAME is completed with the files within the current project
+roots."
+  (interactive (list (when current-prefix-arg (thing-at-point 'filename))))
   (let* ((pr (project-current t))
          (dirs (project-roots pr)))
-    (project--find-file-in dirs pr)))
+    (project--find-file-in filename dirs pr)))
 
 ;;;###autoload
-(defun project-or-external-find-file ()
-  "Visit a file in the current project's roots or external roots.
-
-This is like `find-file', but it limits the file-name completion
-candidates to the files within the current project roots and external roots."
-  (interactive)
+(defun project-or-external-find-file (filename)
+  "Visit FILENAME in the current project's roots or external roots.
+FILENAME defaults to the filename at point (nil if none
+recognized).
+FILENAME is completed with the files within the current project
+roots and external roots."
+  (interactive (list (when current-prefix-arg (thing-at-point 'filename))))
   (let* ((pr (project-current t))
          (dirs (append
                 (project-roots pr)
                 (project-external-roots pr))))
-    (project--find-file-in dirs pr)))
+    (project--find-file-in filename dirs pr)))
 
-;; FIXME: Uniquely abbreviate the roots?
-(defun project--find-file-in (dirs project)
+  ;; FIXME: Uniquely abbreviate the roots?
+(cl-defmethod project--find-file-in (filename dirs project)
+  "Default implementation using `find-program'."
   (require 'xref)
   (let* ((all-files
           (cl-mapcan
@@ -357,7 +369,7 @@ project--find-file-in
                    (t
                     (complete-with-action action all-files string pred))))))
     (find-file
-     (completing-read "Find file: " table nil t))))
+     (completing-read "Find file: " table nil t filename))))
 
 (provide 'project)
 ;;; project.el ends here
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 267853d..ad7d6bb 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -948,6 +948,9 @@ xref--rgrep-command
    (xref--find-ignores-arguments ignores dir)))
 
 (defun xref--find-ignores-arguments (ignores dir)
+  "Convert IGNORES and DIR to a list of arguments for 'find'.
+IGNORES is a list of glob patterns.  DIR is an absolute
+directory, used as the root of the ignore globs."
   ;; `shell-quote-argument' quotes the tilde as well.
   (cl-assert (not (string-match-p "\\`~" dir)))
   (when ignores

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

end of thread, other threads:[~2016-02-01 13:40 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-28  1:04 make project--find-in-file generic, add interactive filename to project-find-file Stephen Leake
2016-01-28  9:21 ` Dmitry Gutov
2016-01-28 10:11   ` Stephen Leake
2016-01-28 10:36     ` Dmitry Gutov
2016-01-28 13:14       ` Stefan Monnier
2016-01-28 19:32         ` Dmitry Gutov
2016-01-28 21:11           ` Stefan Monnier
2016-01-28 21:22             ` Dmitry Gutov
2016-01-28 22:44               ` Stefan Monnier
2016-01-29  2:10                 ` Dmitry Gutov
2016-01-29  2:57                   ` Stefan Monnier
2016-01-29  4:20                     ` Dmitry Gutov
2016-01-29 14:05                       ` Stefan Monnier
2016-01-29 21:53                         ` Dmitry Gutov
2016-01-31  6:18                           ` Stefan Monnier
2016-01-31 14:02                             ` Dmitry Gutov
2016-01-31 14:23                               ` Stefan Monnier
2016-02-01  8:08                                 ` Dmitry Gutov
2016-02-01 13:40                                   ` Stefan Monnier
2016-01-29  2:05             ` Dmitry Gutov
2016-01-29  2:55               ` Stefan Monnier
2016-01-29  4:11                 ` Dmitry Gutov
2016-01-29 14:03                   ` Stefan Monnier
2016-01-29 21:35                     ` Dmitry Gutov
2016-01-30  2:07                       ` Stefan Monnier
2016-01-30 23:32               ` Juri Linkov
2016-01-31  0:40                 ` Dmitry Gutov
2016-01-28 11:06     ` Stephen Leake
2016-01-28 11:11       ` Stephen Leake
2016-01-29  2:18       ` Dmitry Gutov
2016-01-29 23:55         ` Stephen Leake
2016-01-30  0:15           ` Dmitry Gutov

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.