diff options
| author | Dmitry Gutov | 2024-10-29 04:27:00 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2024-10-29 04:28:22 +0200 |
| commit | c0cb369ab188ea7ae0d3271d19c0cecce7be0329 (patch) | |
| tree | fbbc9d1aadc3ea00c663fad0d82868da09ded65b | |
| parent | a6626a00dc4b459e57d700e5bb7524cd3e0a55f8 (diff) | |
| download | emacs-c0cb369ab188ea7ae0d3271d19c0cecce7be0329.tar.gz emacs-c0cb369ab188ea7ae0d3271d19c0cecce7be0329.zip | |
project--completing-read-strict: Move some common processing here
* lisp/progmodes/project.el (project--completing-read-strict):
Add new optional argument, COMMON-PARENT-DIRECTORY. Move the
absolute->relative processing of MB-DEFAULT and the contents of
HIST here.
(project--read-file-cpd-relative): From here. So that
'project--read-file-absolute' can also benefit from those
conversions.
(project--read-file-absolute): Pass the new argument.
(project-read-file-name-function): Update value tags.
| -rw-r--r-- | lisp/progmodes/project.el | 87 |
1 files changed, 48 insertions, 39 deletions
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index aae4b708b7b..cf1c94a6d20 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el | |||
| @@ -1146,9 +1146,9 @@ for VCS directories listed in `vc-directory-exclusion-list'." | |||
| 1146 | (defcustom project-read-file-name-function #'project--read-file-cpd-relative | 1146 | (defcustom project-read-file-name-function #'project--read-file-cpd-relative |
| 1147 | "Function to call to read a file name from a list. | 1147 | "Function to call to read a file name from a list. |
| 1148 | For the arguments list, see `project--read-file-cpd-relative'." | 1148 | For the arguments list, see `project--read-file-cpd-relative'." |
| 1149 | :type '(choice (const :tag "Read with completion from relative names" | 1149 | :type '(choice (const :tag "Read with completion from relative file names" |
| 1150 | project--read-file-cpd-relative) | 1150 | project--read-file-cpd-relative) |
| 1151 | (const :tag "Read with completion from absolute names" | 1151 | (const :tag "Read with completion from file names" |
| 1152 | project--read-file-absolute) | 1152 | project--read-file-absolute) |
| 1153 | (function :tag "Custom function" nil)) | 1153 | (function :tag "Custom function" nil)) |
| 1154 | :group 'project | 1154 | :group 'project |
| @@ -1198,47 +1198,34 @@ by the user at will." | |||
| 1198 | (file-name-absolute-p (car all-files))) | 1198 | (file-name-absolute-p (car all-files))) |
| 1199 | prompt | 1199 | prompt |
| 1200 | (concat prompt (format " in %s" common-parent-directory)))) | 1200 | (concat prompt (format " in %s" common-parent-directory)))) |
| 1201 | (mb-default (mapcar (lambda (mb-default) | ||
| 1202 | (if (and common-parent-directory | ||
| 1203 | mb-default | ||
| 1204 | (file-name-absolute-p mb-default)) | ||
| 1205 | (file-relative-name | ||
| 1206 | mb-default common-parent-directory) | ||
| 1207 | mb-default)) | ||
| 1208 | (if (listp mb-default) mb-default (list mb-default)))) | ||
| 1209 | (substrings (mapcar (lambda (s) (substring s cpd-length)) all-files)) | 1201 | (substrings (mapcar (lambda (s) (substring s cpd-length)) all-files)) |
| 1210 | (new-collection (project--file-completion-table substrings)) | 1202 | (new-collection (project--file-completion-table substrings)) |
| 1211 | (abs-cpd (expand-file-name common-parent-directory)) | 1203 | (relname (project--completing-read-strict prompt |
| 1212 | (abs-cpd-length (length abs-cpd)) | 1204 | new-collection |
| 1213 | (relname (cl-letf* ((non-essential t) ;Avoid new Tramp connections. | 1205 | predicate |
| 1214 | ((symbol-value hist) | 1206 | hist mb-default |
| 1215 | (mapcan | 1207 | (unless (equal common-parent-directory "") |
| 1216 | (lambda (s) | 1208 | common-parent-directory))) |
| 1217 | (setq s (expand-file-name s)) | ||
| 1218 | (and (string-prefix-p abs-cpd s) | ||
| 1219 | (not (eq abs-cpd-length (length s))) | ||
| 1220 | (list (substring s abs-cpd-length)))) | ||
| 1221 | (symbol-value hist)))) | ||
| 1222 | (project--completing-read-strict prompt | ||
| 1223 | new-collection | ||
| 1224 | predicate | ||
| 1225 | hist mb-default))) | ||
| 1226 | (absname (expand-file-name relname common-parent-directory))) | 1209 | (absname (expand-file-name relname common-parent-directory))) |
| 1227 | absname)) | 1210 | absname)) |
| 1228 | 1211 | ||
| 1229 | (defun project--read-file-absolute (prompt | 1212 | (defun project--read-file-absolute (prompt |
| 1230 | all-files &optional predicate | 1213 | all-files &optional predicate |
| 1231 | hist mb-default) | 1214 | hist mb-default) |
| 1232 | (let* ((new-prompt (if (file-name-absolute-p (car all-files)) | 1215 | (let* ((names-absolute (file-name-absolute-p (car all-files))) |
| 1216 | (new-prompt (if names-absolute | ||
| 1233 | prompt | 1217 | prompt |
| 1234 | (concat prompt " in " default-directory))) | 1218 | (concat prompt " in " default-directory))) |
| 1235 | ;; FIXME: Map relative names to absolute? | 1219 | ;; TODO: The names are intentionally not absolute in many cases. |
| 1220 | ;; Probably better to rename this function. | ||
| 1236 | (ct (project--file-completion-table all-files)) | 1221 | (ct (project--file-completion-table all-files)) |
| 1237 | (file | 1222 | (file |
| 1238 | (project--completing-read-strict new-prompt | 1223 | (project--completing-read-strict new-prompt |
| 1239 | ct | 1224 | ct |
| 1240 | predicate | 1225 | predicate |
| 1241 | hist mb-default))) | 1226 | hist mb-default |
| 1227 | (unless names-absolute | ||
| 1228 | default-directory)))) | ||
| 1242 | (unless (file-name-absolute-p file) | 1229 | (unless (file-name-absolute-p file) |
| 1243 | (setq file (expand-file-name file))) | 1230 | (setq file (expand-file-name file))) |
| 1244 | file)) | 1231 | file)) |
| @@ -1297,17 +1284,39 @@ directories listed in `vc-directory-exclusion-list'." | |||
| 1297 | 1284 | ||
| 1298 | (defun project--completing-read-strict (prompt | 1285 | (defun project--completing-read-strict (prompt |
| 1299 | collection &optional predicate | 1286 | collection &optional predicate |
| 1300 | hist mb-default) | 1287 | hist mb-default |
| 1301 | (minibuffer-with-setup-hook | 1288 | common-parent-directory) |
| 1302 | (lambda () | 1289 | (cl-letf* ((mb-default (mapcar (lambda (mb-default) |
| 1303 | (setq-local minibuffer-default-add-function | 1290 | (if (and common-parent-directory |
| 1304 | (lambda () | 1291 | mb-default |
| 1305 | (let ((minibuffer-default mb-default)) | 1292 | (file-name-absolute-p mb-default)) |
| 1306 | (minibuffer-default-add-completions))))) | 1293 | (file-relative-name |
| 1307 | (completing-read (format "%s: " prompt) | 1294 | mb-default common-parent-directory) |
| 1308 | collection predicate 'confirm | 1295 | mb-default)) |
| 1309 | nil | 1296 | (if (listp mb-default) mb-default (list mb-default)))) |
| 1310 | hist))) | 1297 | (abs-cpd (expand-file-name (or common-parent-directory ""))) |
| 1298 | (abs-cpd-length (length abs-cpd)) | ||
| 1299 | (non-essential t) ;Avoid new Tramp connections. | ||
| 1300 | ((symbol-value hist) | ||
| 1301 | (if common-parent-directory | ||
| 1302 | (mapcan | ||
| 1303 | (lambda (s) | ||
| 1304 | (setq s (expand-file-name s)) | ||
| 1305 | (and (string-prefix-p abs-cpd s) | ||
| 1306 | (not (eq abs-cpd-length (length s))) | ||
| 1307 | (list (substring s abs-cpd-length)))) | ||
| 1308 | (symbol-value hist)) | ||
| 1309 | (symbol-value hist)))) | ||
| 1310 | (minibuffer-with-setup-hook | ||
| 1311 | (lambda () | ||
| 1312 | (setq-local minibuffer-default-add-function | ||
| 1313 | (lambda () | ||
| 1314 | (let ((minibuffer-default mb-default)) | ||
| 1315 | (minibuffer-default-add-completions))))) | ||
| 1316 | (completing-read (format "%s: " prompt) | ||
| 1317 | collection predicate 'confirm | ||
| 1318 | nil | ||
| 1319 | hist)))) | ||
| 1311 | 1320 | ||
| 1312 | ;;;###autoload | 1321 | ;;;###autoload |
| 1313 | (defun project-find-dir () | 1322 | (defun project-find-dir () |