diff options
| author | Stefan Monnier | 2011-04-13 21:16:11 -0300 |
|---|---|---|
| committer | Stefan Monnier | 2011-04-13 21:16:11 -0300 |
| commit | e240cc21882f0af6826018218f5b451d7d03313d (patch) | |
| tree | 72e5a45bf13a5f94cfa0925950be2e9fa63b4cd8 | |
| parent | c2bd2ab02856f36d41c88f5e054f4444a6366d5e (diff) | |
| download | emacs-e240cc21882f0af6826018218f5b451d7d03313d.tar.gz emacs-e240cc21882f0af6826018218f5b451d7d03313d.zip | |
* lisp/minibuffer.el (completion-in-region-mode-predicate)
(completion-in-region-mode--predicate): New vars.
(completion-in-region, completion-in-region--postch)
(completion-in-region-mode): Use them.
(completion--capf-wrapper): Also return the hook function.
(completion-at-point, completion-help-at-point):
Adjust and provide a predicate.
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/minibuffer.el | 86 |
2 files changed, 63 insertions, 33 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index cb3aebb2682..0fd851c544b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,4 +1,12 @@ | |||
| 1 | 2011-04-13 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2011-04-14 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | |||
| 3 | * minibuffer.el (completion-in-region-mode-predicate) | ||
| 4 | (completion-in-region-mode--predicate): New vars. | ||
| 5 | (completion-in-region, completion-in-region--postch) | ||
| 6 | (completion-in-region-mode): Use them. | ||
| 7 | (completion--capf-wrapper): Also return the hook function. | ||
| 8 | (completion-at-point, completion-help-at-point): | ||
| 9 | Adjust and provide a predicate. | ||
| 2 | 10 | ||
| 3 | Preserve arg names for advice of subr and lexical functions (bug#8457). | 11 | Preserve arg names for advice of subr and lexical functions (bug#8457). |
| 4 | * help-fns.el (help-function-arglist): Consolidate the subr and | 12 | * help-fns.el (help-function-arglist): Consolidate the subr and |
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index d6e11b5a7c5..0d26d6bdcf6 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el | |||
| @@ -58,6 +58,10 @@ | |||
| 58 | 58 | ||
| 59 | ;;; Todo: | 59 | ;;; Todo: |
| 60 | 60 | ||
| 61 | ;; - completion-insert-complete-hook (called after inserting a complete | ||
| 62 | ;; completion), typically used for "complete-abbrev" where it would expand | ||
| 63 | ;; the abbrev. Tho we'd probably want to provide it from the | ||
| 64 | ;; completion-table. | ||
| 61 | ;; - extend `boundaries' to provide various other meta-data about the | 65 | ;; - extend `boundaries' to provide various other meta-data about the |
| 62 | ;; output of `all-completions': | 66 | ;; output of `all-completions': |
| 63 | ;; - preferred sorting order when displayed in *Completions*. | 67 | ;; - preferred sorting order when displayed in *Completions*. |
| @@ -1254,12 +1258,22 @@ and PREDICATE, either by calling NEXT-FUN or by doing it themselves.") | |||
| 1254 | 1258 | ||
| 1255 | (defvar completion-in-region--data nil) | 1259 | (defvar completion-in-region--data nil) |
| 1256 | 1260 | ||
| 1261 | (defvar completion-in-region-mode-predicate nil | ||
| 1262 | "Predicate to tell `completion-in-region-mode' when to exit. | ||
| 1263 | It is called with no argument and should return nil when | ||
| 1264 | `completion-in-region-mode' should exit (and hence pop down | ||
| 1265 | the *Completions* buffer).") | ||
| 1266 | |||
| 1267 | (defvar completion-in-region-mode--predicate nil | ||
| 1268 | "Copy of the value of `completion-in-region-mode-predicate'. | ||
| 1269 | This holds the value `completion-in-region-mode-predicate' had when | ||
| 1270 | we entered `completion-in-region-mode'.") | ||
| 1271 | |||
| 1257 | (defun completion-in-region (start end collection &optional predicate) | 1272 | (defun completion-in-region (start end collection &optional predicate) |
| 1258 | "Complete the text between START and END using COLLECTION. | 1273 | "Complete the text between START and END using COLLECTION. |
| 1259 | Return nil if there is no valid completion, else t. | 1274 | Return nil if there is no valid completion, else t. |
| 1260 | Point needs to be somewhere between START and END." | 1275 | Point needs to be somewhere between START and END." |
| 1261 | (assert (<= start (point)) (<= (point) end)) | 1276 | (assert (<= start (point)) (<= (point) end)) |
| 1262 | ;; FIXME: undisplay the *Completions* buffer once the completion is done. | ||
| 1263 | (with-wrapper-hook | 1277 | (with-wrapper-hook |
| 1264 | ;; FIXME: Maybe we should use this hook to provide a "display | 1278 | ;; FIXME: Maybe we should use this hook to provide a "display |
| 1265 | ;; completions" operation as well. | 1279 | ;; completions" operation as well. |
| @@ -1268,9 +1282,10 @@ Point needs to be somewhere between START and END." | |||
| 1268 | (minibuffer-completion-predicate predicate) | 1282 | (minibuffer-completion-predicate predicate) |
| 1269 | (ol (make-overlay start end nil nil t))) | 1283 | (ol (make-overlay start end nil nil t))) |
| 1270 | (overlay-put ol 'field 'completion) | 1284 | (overlay-put ol 'field 'completion) |
| 1271 | (completion-in-region-mode 1) | 1285 | (when completion-in-region-mode-predicate |
| 1272 | (setq completion-in-region--data | 1286 | (completion-in-region-mode 1) |
| 1273 | (list (current-buffer) start end collection)) | 1287 | (setq completion-in-region--data |
| 1288 | (list (current-buffer) start end collection))) | ||
| 1274 | (unwind-protect | 1289 | (unwind-protect |
| 1275 | (call-interactively 'minibuffer-complete) | 1290 | (call-interactively 'minibuffer-complete) |
| 1276 | (delete-overlay ol))))) | 1291 | (delete-overlay ol))))) |
| @@ -1299,13 +1314,8 @@ Point needs to be somewhere between START and END." | |||
| 1299 | (save-excursion | 1314 | (save-excursion |
| 1300 | (goto-char (nth 2 completion-in-region--data)) | 1315 | (goto-char (nth 2 completion-in-region--data)) |
| 1301 | (line-end-position))) | 1316 | (line-end-position))) |
| 1302 | (let ((comp-data (run-hook-wrapped | 1317 | (when completion-in-region-mode--predicate |
| 1303 | 'completion-at-point-functions | 1318 | (funcall completion-in-region-mode--predicate)))) |
| 1304 | ;; Only use the known-safe functions. | ||
| 1305 | #'completion--capf-wrapper 'safe))) | ||
| 1306 | (eq (car comp-data) | ||
| 1307 | ;; We're still in the same completion field. | ||
| 1308 | (nth 1 completion-in-region--data))))) | ||
| 1309 | (completion-in-region-mode -1))) | 1319 | (completion-in-region-mode -1))) |
| 1310 | 1320 | ||
| 1311 | ;; (defalias 'completion-in-region--prech 'completion-in-region--postch) | 1321 | ;; (defalias 'completion-in-region--prech 'completion-in-region--postch) |
| @@ -1320,9 +1330,12 @@ Point needs to be somewhere between START and END." | |||
| 1320 | (delq (assq 'completion-in-region-mode minor-mode-overriding-map-alist) | 1330 | (delq (assq 'completion-in-region-mode minor-mode-overriding-map-alist) |
| 1321 | minor-mode-overriding-map-alist)) | 1331 | minor-mode-overriding-map-alist)) |
| 1322 | (if (null completion-in-region-mode) | 1332 | (if (null completion-in-region-mode) |
| 1323 | (unless (equal "*Completions*" (buffer-name (window-buffer))) | 1333 | (unless (or (equal "*Completions*" (buffer-name (window-buffer))) |
| 1334 | (null completion-in-region-mode--predicate)) | ||
| 1324 | (minibuffer-hide-completions)) | 1335 | (minibuffer-hide-completions)) |
| 1325 | ;; (add-hook 'pre-command-hook #'completion-in-region--prech) | 1336 | ;; (add-hook 'pre-command-hook #'completion-in-region--prech) |
| 1337 | (set (make-local-variable 'completion-in-region-mode--predicate) | ||
| 1338 | completion-in-region-mode-predicate) | ||
| 1326 | (add-hook 'post-command-hook #'completion-in-region--postch) | 1339 | (add-hook 'post-command-hook #'completion-in-region--postch) |
| 1327 | (push `(completion-in-region-mode . ,completion-in-region-mode-map) | 1340 | (push `(completion-in-region-mode . ,completion-in-region-mode-map) |
| 1328 | minor-mode-overriding-map-alist))) | 1341 | minor-mode-overriding-map-alist))) |
| @@ -1366,7 +1379,7 @@ Currently supported properties are: | |||
| 1366 | (message | 1379 | (message |
| 1367 | "Completion function %S uses a deprecated calling convention" fun) | 1380 | "Completion function %S uses a deprecated calling convention" fun) |
| 1368 | (push fun completion--capf-misbehave-funs)))) | 1381 | (push fun completion--capf-misbehave-funs)))) |
| 1369 | res))) | 1382 | (if res (cons fun res))))) |
| 1370 | 1383 | ||
| 1371 | (defun completion-at-point () | 1384 | (defun completion-at-point () |
| 1372 | "Perform completion on the text around point. | 1385 | "Perform completion on the text around point. |
| @@ -1374,18 +1387,20 @@ The completion method is determined by `completion-at-point-functions'." | |||
| 1374 | (interactive) | 1387 | (interactive) |
| 1375 | (let ((res (run-hook-wrapped 'completion-at-point-functions | 1388 | (let ((res (run-hook-wrapped 'completion-at-point-functions |
| 1376 | #'completion--capf-wrapper 'all))) | 1389 | #'completion--capf-wrapper 'all))) |
| 1377 | (cond | 1390 | (pcase res |
| 1378 | ((functionp res) (funcall res)) | 1391 | (`(,_ . ,(and (pred functionp) f)) (funcall f)) |
| 1379 | ((consp res) | 1392 | (`(,hookfun . (,start ,end ,collection . ,plist)) |
| 1380 | (let* ((plist (nthcdr 3 res)) | 1393 | (let* ((completion-annotate-function |
| 1381 | (start (nth 0 res)) | ||
| 1382 | (end (nth 1 res)) | ||
| 1383 | (completion-annotate-function | ||
| 1384 | (or (plist-get plist :annotation-function) | 1394 | (or (plist-get plist :annotation-function) |
| 1385 | completion-annotate-function))) | 1395 | completion-annotate-function)) |
| 1386 | (completion-in-region start end (nth 2 res) | 1396 | (completion-in-region-mode-predicate |
| 1397 | (lambda () | ||
| 1398 | ;; We're still in the same completion field. | ||
| 1399 | (eq (car (funcall hookfun)) start)))) | ||
| 1400 | (completion-in-region start end collection | ||
| 1387 | (plist-get plist :predicate)))) | 1401 | (plist-get plist :predicate)))) |
| 1388 | (res)))) ;Maybe completion already happened and the function returned t. | 1402 | ;; Maybe completion already happened and the function returned t. |
| 1403 | (_ (cdr res))))) | ||
| 1389 | 1404 | ||
| 1390 | (defun completion-help-at-point () | 1405 | (defun completion-help-at-point () |
| 1391 | "Display the completions on the text around point. | 1406 | "Display the completions on the text around point. |
| @@ -1394,29 +1409,36 @@ The completion method is determined by `completion-at-point-functions'." | |||
| 1394 | (let ((res (run-hook-wrapped 'completion-at-point-functions | 1409 | (let ((res (run-hook-wrapped 'completion-at-point-functions |
| 1395 | ;; Ignore misbehaving functions. | 1410 | ;; Ignore misbehaving functions. |
| 1396 | #'completion--capf-wrapper 'optimist))) | 1411 | #'completion--capf-wrapper 'optimist))) |
| 1397 | (cond | 1412 | (pcase res |
| 1398 | ((functionp res) | 1413 | (`(,_ . ,(and (pred functionp) f)) |
| 1399 | (message "Don't know how to show completions for %S" res)) | 1414 | (message "Don't know how to show completions for %S" f)) |
| 1400 | ((consp res) | 1415 | (`(,hookfun . (,start ,end ,collection . ,plist)) |
| 1401 | (let* ((plist (nthcdr 3 res)) | 1416 | (let* ((minibuffer-completion-table collection) |
| 1402 | (minibuffer-completion-table (nth 2 res)) | ||
| 1403 | (minibuffer-completion-predicate (plist-get plist :predicate)) | 1417 | (minibuffer-completion-predicate (plist-get plist :predicate)) |
| 1404 | (completion-annotate-function | 1418 | (completion-annotate-function |
| 1405 | (or (plist-get plist :annotation-function) | 1419 | (or (plist-get plist :annotation-function) |
| 1406 | completion-annotate-function)) | 1420 | completion-annotate-function)) |
| 1407 | (ol (make-overlay (nth 0 res) (nth 1 res) nil nil t))) | 1421 | (completion-in-region-mode-predicate |
| 1422 | (lambda () | ||
| 1423 | ;; We're still in the same completion field. | ||
| 1424 | (eq (car (funcall hookfun)) start))) | ||
| 1425 | (ol (make-overlay start end nil nil t))) | ||
| 1408 | ;; FIXME: We should somehow (ab)use completion-in-region-function or | 1426 | ;; FIXME: We should somehow (ab)use completion-in-region-function or |
| 1409 | ;; introduce a corresponding hook (plus another for word-completion, | 1427 | ;; introduce a corresponding hook (plus another for word-completion, |
| 1410 | ;; and another for force-completion, maybe?). | 1428 | ;; and another for force-completion, maybe?). |
| 1411 | (overlay-put ol 'field 'completion) | 1429 | (overlay-put ol 'field 'completion) |
| 1430 | (completion-in-region-mode 1) | ||
| 1431 | (setq completion-in-region--data | ||
| 1432 | (list (current-buffer) start end collection)) | ||
| 1412 | (unwind-protect | 1433 | (unwind-protect |
| 1413 | (call-interactively 'minibuffer-completion-help) | 1434 | (call-interactively 'minibuffer-completion-help) |
| 1414 | (delete-overlay ol)))) | 1435 | (delete-overlay ol)))) |
| 1415 | (res | 1436 | (`(,hookfun . ,_) |
| 1416 | ;; The hook function already performed completion :-( | 1437 | ;; The hook function already performed completion :-( |
| 1417 | ;; Not much we can do at this point. | 1438 | ;; Not much we can do at this point. |
| 1439 | (message "%s already performed completion!" hookfun) | ||
| 1418 | nil) | 1440 | nil) |
| 1419 | (t (message "Nothing to complete at point"))))) | 1441 | (_ (message "Nothing to complete at point"))))) |
| 1420 | 1442 | ||
| 1421 | ;;; Key bindings. | 1443 | ;;; Key bindings. |
| 1422 | 1444 | ||