diff options
| author | Dmitry Gutov | 2015-11-10 02:41:06 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2015-11-10 02:41:06 +0200 |
| commit | 1c72afb7aa48c2ea06103113ef70ccea0c1c961d (patch) | |
| tree | 3e79438a2959c541159a326e70ebc6816e2ceb30 | |
| parent | e4c190b28d658d92f8c19799b19f8263650687e0 (diff) | |
| download | emacs-1c72afb7aa48c2ea06103113ef70ccea0c1c961d.tar.gz emacs-1c72afb7aa48c2ea06103113ef70ccea0c1c961d.zip | |
Fold `project-ask-user' into `project-current'
* lisp/progmodes/project.el (project-find-functions): Remove
`project-ask-user'.
(project-ask-user): Remove function and the corresponding
`project-roots' implementation.
(project-current): Add a new argument, MAYBE-PROMPT. Prompt the
user in case there's no project in the current directory. Update
all callers.
| -rw-r--r-- | lisp/progmodes/elisp-mode.el | 2 | ||||
| -rw-r--r-- | lisp/progmodes/etags.el | 2 | ||||
| -rw-r--r-- | lisp/progmodes/project.el | 34 |
3 files changed, 22 insertions, 16 deletions
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index 298c7a7b53f..29257cdd4ab 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el | |||
| @@ -809,7 +809,7 @@ non-nil result supercedes the xrefs produced by | |||
| 809 | (cl-mapcan | 809 | (cl-mapcan |
| 810 | (lambda (dir) | 810 | (lambda (dir) |
| 811 | (xref-collect-references symbol dir)) | 811 | (xref-collect-references symbol dir)) |
| 812 | (let ((pr (project-current))) | 812 | (let ((pr (project-current t))) |
| 813 | (append | 813 | (append |
| 814 | (project-roots pr) | 814 | (project-roots pr) |
| 815 | (project-library-roots pr))))) | 815 | (project-library-roots pr))))) |
diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el index 2d7537a9bea..38c5cc2bdb6 100644 --- a/lisp/progmodes/etags.el +++ b/lisp/progmodes/etags.el | |||
| @@ -2098,7 +2098,7 @@ for \\[find-tag] (which see)." | |||
| 2098 | (cl-mapcan | 2098 | (cl-mapcan |
| 2099 | (lambda (dir) | 2099 | (lambda (dir) |
| 2100 | (xref-collect-references symbol dir)) | 2100 | (xref-collect-references symbol dir)) |
| 2101 | (let ((pr (project-current))) | 2101 | (let ((pr (project-current t))) |
| 2102 | (append | 2102 | (append |
| 2103 | (project-roots pr) | 2103 | (project-roots pr) |
| 2104 | (project-library-roots pr))))) | 2104 | (project-library-roots pr))))) |
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 9cdeb392f09..0da6084a1e3 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el | |||
| @@ -31,8 +31,7 @@ | |||
| 31 | 31 | ||
| 32 | (require 'cl-generic) | 32 | (require 'cl-generic) |
| 33 | 33 | ||
| 34 | (defvar project-find-functions (list #'project-try-vc | 34 | (defvar project-find-functions (list #'project-try-vc) |
| 35 | #'project-ask-user) | ||
| 36 | "Special hook to find the project containing a given directory. | 35 | "Special hook to find the project containing a given directory. |
| 37 | Each functions on this hook is called in turn with one | 36 | Each functions on this hook is called in turn with one |
| 38 | argument (the directory) and should return either nil to mean | 37 | argument (the directory) and should return either nil to mean |
| @@ -67,9 +66,22 @@ The directory names should be absolute. Used in the default | |||
| 67 | implementation of `project-library-roots'.") | 66 | implementation of `project-library-roots'.") |
| 68 | 67 | ||
| 69 | ;;;###autoload | 68 | ;;;###autoload |
| 70 | (defun project-current (&optional dir) | 69 | (defun project-current (&optional maybe-prompt dir) |
| 71 | "Return the project instance in DIR or `default-directory'." | 70 | "Return the project instance in DIR or `default-directory'. |
| 71 | When no project found in DIR, and MAYBE-PROMPT is non-nil, ask | ||
| 72 | the user for a different directory to look in." | ||
| 72 | (unless dir (setq dir default-directory)) | 73 | (unless dir (setq dir default-directory)) |
| 74 | (let ((pr (project--find-in-directory dir))) | ||
| 75 | (cond | ||
| 76 | (pr) | ||
| 77 | (maybe-prompt | ||
| 78 | (setq dir (read-directory-name "Choose the project directory: " dir nil t) | ||
| 79 | pr (project--find-in-directory dir)) | ||
| 80 | (unless pr | ||
| 81 | (user-error "No project found in `%s'" dir)))) | ||
| 82 | pr)) | ||
| 83 | |||
| 84 | (defun project--find-in-directory (dir) | ||
| 73 | (run-hook-with-args-until-success 'project-find-functions dir)) | 85 | (run-hook-with-args-until-success 'project-find-functions dir)) |
| 74 | 86 | ||
| 75 | ;; FIXME: Add MODE argument, like in `ede-source-paths'? | 87 | ;; FIXME: Add MODE argument, like in `ede-source-paths'? |
| @@ -165,12 +177,6 @@ The file names can be absolute, or relative to the project root." | |||
| 165 | (project--value-in-dir 'project-vc-ignores root) | 177 | (project--value-in-dir 'project-vc-ignores root) |
| 166 | (cl-call-next-method)))) | 178 | (cl-call-next-method)))) |
| 167 | 179 | ||
| 168 | (defun project-ask-user (dir) | ||
| 169 | (cons 'user (read-directory-name "Project root: " dir nil t))) | ||
| 170 | |||
| 171 | (cl-defmethod project-roots ((project (head user))) | ||
| 172 | (list (cdr project))) | ||
| 173 | |||
| 174 | (defun project-combine-directories (&rest lists-of-dirs) | 180 | (defun project-combine-directories (&rest lists-of-dirs) |
| 175 | "Return a sorted and culled list of directory names. | 181 | "Return a sorted and culled list of directory names. |
| 176 | Appends the elements of LISTS-OF-DIRS together, removes | 182 | Appends the elements of LISTS-OF-DIRS together, removes |
| @@ -193,8 +199,8 @@ whose is already in the list." | |||
| 193 | (defun project-subtract-directories (files dirs) | 199 | (defun project-subtract-directories (files dirs) |
| 194 | "Return a list of elements from FILES that are outside of DIRS. | 200 | "Return a list of elements from FILES that are outside of DIRS. |
| 195 | DIRS must contain directory names." | 201 | DIRS must contain directory names." |
| 196 | (cl-set-difference files dirs | 202 | ;; Sidestep the issue of expanded/abbreviated file names here. |
| 197 | :test (lambda (file dir) (string-prefix-p dir file)))) | 203 | (cl-set-difference files dirs :test #'file-in-directory-p)) |
| 198 | 204 | ||
| 199 | (defun project--value-in-dir (var dir) | 205 | (defun project--value-in-dir (var dir) |
| 200 | (with-temp-buffer | 206 | (with-temp-buffer |
| @@ -212,7 +218,7 @@ DIRS must contain directory names." | |||
| 212 | With \\[universal-argument] prefix, you can specify the directory | 218 | With \\[universal-argument] prefix, you can specify the directory |
| 213 | to search in, and the file name pattern to search for." | 219 | to search in, and the file name pattern to search for." |
| 214 | (interactive (list (project--read-regexp))) | 220 | (interactive (list (project--read-regexp))) |
| 215 | (let* ((pr (project-current)) | 221 | (let* ((pr (project-current t)) |
| 216 | (dirs (if current-prefix-arg | 222 | (dirs (if current-prefix-arg |
| 217 | (list (read-directory-name "Base directory: " | 223 | (list (read-directory-name "Base directory: " |
| 218 | nil default-directory t)) | 224 | nil default-directory t)) |
| @@ -225,7 +231,7 @@ to search in, and the file name pattern to search for." | |||
| 225 | With \\[universal-argument] prefix, you can specify the file name | 231 | With \\[universal-argument] prefix, you can specify the file name |
| 226 | pattern to search for." | 232 | pattern to search for." |
| 227 | (interactive (list (project--read-regexp))) | 233 | (interactive (list (project--read-regexp))) |
| 228 | (let* ((pr (project-current)) | 234 | (let* ((pr (project-current t)) |
| 229 | (dirs (append | 235 | (dirs (append |
| 230 | (project-roots pr) | 236 | (project-roots pr) |
| 231 | (project-library-roots pr)))) | 237 | (project-library-roots pr)))) |