aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2008-06-10 22:01:59 +0000
committerStefan Monnier2008-06-10 22:01:59 +0000
commiteee6de732346d59d60a2e297851e86c05acf30d6 (patch)
tree23e42c0b535c56524bf2c74d739fb7eac69be31e
parentd63ddb2c6781f0ad8f05674dd03eb4d778b4d69f (diff)
downloademacs-eee6de732346d59d60a2e297851e86c05acf30d6.tar.gz
emacs-eee6de732346d59d60a2e297851e86c05acf30d6.zip
(completion--merge-suffix): New function.
(completion-basic-try-completion): Use it. (completion-pcm--find-all-completions): Add argument `filter'. (completion-pcm--filename-try-filter, completion-pcm--merge-try): New funs. (completion-pcm-try-completion): Use them.
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/minibuffer.el133
2 files changed, 103 insertions, 37 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 9df575e34bf..20782cbd7aa 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,12 @@
12008-06-10 Stefan Monnier <monnier@iro.umontreal.ca> 12008-06-10 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * minibuffer.el (completion--merge-suffix): New function.
4 (completion-basic-try-completion): Use it.
5 (completion-pcm--find-all-completions): Add argument `filter'.
6 (completion-pcm--filename-try-filter, completion-pcm--merge-try):
7 New functions.
8 (completion-pcm-try-completion): Use them.
9
3 * xt-mouse.el (turn-on-xterm-mouse-tracking, turn-off-xterm-mouse-tracking): 10 * xt-mouse.el (turn-on-xterm-mouse-tracking, turn-off-xterm-mouse-tracking):
4 Use terminal-list. 11 Use terminal-list.
5 12
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 2be39d23dde..706de22e772 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -36,10 +36,9 @@
36 36
37;;; Bugs: 37;;; Bugs:
38 38
39;; - completion-ignored-extensions is ignored by partial-completion because 39;; - completion-all-sorted-completions list all the completions, whereas
40;; pcm merges the `all' output to synthesize a `try' output and 40;; it should only lists the ones that `try-completion' would consider.
41;; read-file-name-internal's `all' output doesn't obey 41;; E.g. it should honor completion-ignored-extensions.
42;; completion-ignored-extensions.
43;; - choose-completion can't automatically figure out the boundaries 42;; - choose-completion can't automatically figure out the boundaries
44;; corresponding to the displayed completions. `base-size' gives the left 43;; corresponding to the displayed completions. `base-size' gives the left
45;; boundary, but not the righthand one. So we need to add 44;; boundary, but not the righthand one. So we need to add
@@ -47,10 +46,12 @@
47 46
48;;; Todo: 47;;; Todo:
49 48
49;; - make lisp-complete-symbol and sym-comp use it.
50;; - add support for ** to pcm. 50;; - add support for ** to pcm.
51;; - Make read-file-name-predicate obsolete. 51;; - Make read-file-name-predicate obsolete.
52;; - Add vc-file-name-completion-table to read-file-name-internal. 52;; - Add vc-file-name-completion-table to read-file-name-internal.
53;; - A feature like completing-help.el. 53;; - A feature like completing-help.el.
54;; - make lisp/complete.el obsolete.
54;; - Make the `hide-spaces' arg of all-completions obsolete? 55;; - Make the `hide-spaces' arg of all-completions obsolete?
55 56
56;;; Code: 57;;; Code:
@@ -282,8 +283,12 @@ If ARGS are provided, then pass MESSAGE through `format'."
282 (concat " [" message "]"))) 283 (concat " [" message "]")))
283 (when args (setq message (apply 'format message args))) 284 (when args (setq message (apply 'format message args)))
284 (let ((ol (make-overlay (point-max) (point-max) nil t t)) 285 (let ((ol (make-overlay (point-max) (point-max) nil t t))
285 ;; A quit during sit-for should be (re-)read as 286 ;; A quit during sit-for normally only interrupts the sit-for,
286 ;; abort-recursive-edit 287 ;; but since minibuffer-message is used at the end of a command,
288 ;; at a time when the command has virtually finished already, a C-g
289 ;; should really cause an abort-recursive-edit instead (i.e. as if
290 ;; the C-g had been typed at top-level). Binding inhibit-quit here
291 ;; is an attempt to get that behavior.
287 (inhibit-quit t)) 292 (inhibit-quit t))
288 (unwind-protect 293 (unwind-protect
289 (progn 294 (progn
@@ -570,6 +575,10 @@ input if confirmed."
570 (when (and (stringp compl) 575 (when (and (stringp compl)
571 ;; If it weren't for this piece of paranoia, I'd replace 576 ;; If it weren't for this piece of paranoia, I'd replace
572 ;; the whole thing with a call to do-completion. 577 ;; the whole thing with a call to do-completion.
578 ;; This is important, e.g. when the current minibuffer's
579 ;; content is a directory which only contains a single
580 ;; file, so `try-completion' actually completes to
581 ;; that file.
573 (= (length string) (length compl))) 582 (= (length string) (length compl)))
574 (goto-char end) 583 (goto-char end)
575 (insert compl) 584 (insert compl)
@@ -1220,7 +1229,7 @@ Like `internal-complete-buffer', but removes BUFFER from the completion list."
1220 (not (equal (if (consp name) (car name) name) except))) 1229 (not (equal (if (consp name) (car name) name) except)))
1221 nil))) 1230 nil)))
1222 1231
1223;;; Old-style completion, used in Emacs-21. 1232;;; Old-style completion, used in Emacs-21 and Emacs-22.
1224 1233
1225(defun completion-emacs21-try-completion (string table pred point) 1234(defun completion-emacs21-try-completion (string table pred point)
1226 (let ((completion (try-completion string table pred))) 1235 (let ((completion (try-completion string table pred)))
@@ -1230,11 +1239,9 @@ Like `internal-complete-buffer', but removes BUFFER from the completion list."
1230 1239
1231(defun completion-emacs21-all-completions (string table pred point) 1240(defun completion-emacs21-all-completions (string table pred point)
1232 (completion-hilit-commonality 1241 (completion-hilit-commonality
1233 (all-completions string table pred t) 1242 (all-completions string table pred)
1234 (length string))) 1243 (length string)))
1235 1244
1236;;; Basic completion, used in Emacs-22.
1237
1238(defun completion-emacs22-try-completion (string table pred point) 1245(defun completion-emacs22-try-completion (string table pred point)
1239 (let ((suffix (substring string point)) 1246 (let ((suffix (substring string point))
1240 (completion (try-completion (substring string 0 point) table pred))) 1247 (completion (try-completion (substring string 0 point) table pred)))
@@ -1257,26 +1264,36 @@ Like `internal-complete-buffer', but removes BUFFER from the completion list."
1257 1264
1258(defun completion-emacs22-all-completions (string table pred point) 1265(defun completion-emacs22-all-completions (string table pred point)
1259 (completion-hilit-commonality 1266 (completion-hilit-commonality
1260 (all-completions (substring string 0 point) table pred t) 1267 (all-completions (substring string 0 point) table pred)
1261 point)) 1268 point))
1262 1269
1270;;; Basic completion.
1271
1272(defun completion--merge-suffix (completion point suffix)
1273 "Merge end of COMPLETION with beginning of SUFFIX.
1274Simple generalization of the \"merge trailing /\" done in Emacs-22.
1275Return the new suffix."
1276 (if (and (not (zerop (length suffix)))
1277 (string-match "\\(.+\\)\n\\1" (concat completion "\n" suffix)
1278 ;; Make sure we don't compress things to less
1279 ;; than we started with.
1280 point)
1281 ;; Just make sure we didn't match some other \n.
1282 (eq (match-end 1) (length completion)))
1283 (substring suffix (- (match-end 1) (match-beginning 1)))
1284 ;; Nothing to merge.
1285 suffix))
1286
1263(defun completion-basic-try-completion (string table pred point) 1287(defun completion-basic-try-completion (string table pred point)
1264 (let ((suffix (substring string point)) 1288 (let* ((beforepoint (substring string 0 point))
1265 (completion (try-completion (substring string 0 point) table pred))) 1289 (afterpoint (substring string point))
1290 (completion (try-completion beforepoint table pred)))
1266 (if (not (stringp completion)) 1291 (if (not (stringp completion))
1267 completion 1292 completion
1268 ;; Merge end of completion with beginning of suffix. 1293 (cons
1269 ;; Simple generalization of the "merge trailing /" done in Emacs-22. 1294 (concat completion
1270 (when (and (not (zerop (length suffix))) 1295 (completion--merge-suffix completion point afterpoint))
1271 (string-match "\\(.+\\)\n\\1" (concat completion "\n" suffix) 1296 (length completion)))))
1272 ;; Make sure we don't compress things to less
1273 ;; than we started with.
1274 point)
1275 ;; Just make sure we didn't match some other \n.
1276 (eq (match-end 1) (length completion)))
1277 (setq suffix (substring suffix (- (match-end 1) (match-beginning 1)))))
1278
1279 (cons (concat completion suffix) (length completion)))))
1280 1297
1281(defalias 'completion-basic-all-completions 'completion-emacs22-all-completions) 1298(defalias 'completion-basic-all-completions 'completion-emacs22-all-completions)
1282 1299
@@ -1417,7 +1434,13 @@ PATTERN is as returned by `completion-pcm--string->pattern'."
1417 completions) 1434 completions)
1418 base-size)))) 1435 base-size))))
1419 1436
1420(defun completion-pcm--find-all-completions (string table pred point) 1437(defun completion-pcm--find-all-completions (string table pred point
1438 &optional filter)
1439 "Find all completions for STRING at POINT in TABLE, satisfying PRED.
1440POINT is a position inside STRING.
1441FILTER is a function applied to the return value, that can be used, e.g. to
1442filter out additional entries (because TABLE migth not obey PRED)."
1443 (unless filter (setq filter 'identity))
1421 (let* ((beforepoint (substring string 0 point)) 1444 (let* ((beforepoint (substring string 0 point))
1422 (afterpoint (substring string point)) 1445 (afterpoint (substring string point))
1423 (bounds (completion-boundaries beforepoint table pred afterpoint)) 1446 (bounds (completion-boundaries beforepoint table pred afterpoint))
@@ -1428,7 +1451,9 @@ PATTERN is as returned by `completion-pcm--string->pattern'."
1428 (let* ((relpoint (- point (car bounds))) 1451 (let* ((relpoint (- point (car bounds)))
1429 (pattern (completion-pcm--string->pattern string relpoint)) 1452 (pattern (completion-pcm--string->pattern string relpoint))
1430 (all (condition-case err 1453 (all (condition-case err
1431 (completion-pcm--all-completions prefix pattern table pred) 1454 (funcall filter
1455 (completion-pcm--all-completions
1456 prefix pattern table pred))
1432 (error (unless firsterror (setq firsterror err)) nil)))) 1457 (error (unless firsterror (setq firsterror err)) nil))))
1433 (when (and (null all) 1458 (when (and (null all)
1434 (> (car bounds) 0) 1459 (> (car bounds) 0)
@@ -1438,7 +1463,7 @@ PATTERN is as returned by `completion-pcm--string->pattern'."
1438 (let ((substring (substring prefix 0 -1))) 1463 (let ((substring (substring prefix 0 -1)))
1439 (destructuring-bind (subpat suball subprefix subsuffix) 1464 (destructuring-bind (subpat suball subprefix subsuffix)
1440 (completion-pcm--find-all-completions 1465 (completion-pcm--find-all-completions
1441 substring table pred (length substring)) 1466 substring table pred (length substring) filter)
1442 (let ((sep (aref prefix (1- (length prefix)))) 1467 (let ((sep (aref prefix (1- (length prefix))))
1443 ;; Text that goes between the new submatches and the 1468 ;; Text that goes between the new submatches and the
1444 ;; completion substring. 1469 ;; completion substring.
@@ -1478,9 +1503,10 @@ PATTERN is as returned by `completion-pcm--string->pattern'."
1478 (dolist (submatch suball) 1503 (dolist (submatch suball)
1479 (setq all (nconc (mapcar 1504 (setq all (nconc (mapcar
1480 (lambda (s) (concat submatch between s)) 1505 (lambda (s) (concat submatch between s))
1481 (completion-pcm--all-completions 1506 (funcall filter
1482 (concat subprefix submatch between) 1507 (completion-pcm--all-completions
1483 pattern table pred)) 1508 (concat subprefix submatch between)
1509 pattern table pred)))
1484 all))) 1510 all)))
1485 ;; FIXME: This can come in handy for try-completion, 1511 ;; FIXME: This can come in handy for try-completion,
1486 ;; but isn't right for all-completions, since it lists 1512 ;; but isn't right for all-completions, since it lists
@@ -1564,10 +1590,36 @@ PATTERN is as returned by `completion-pcm--string->pattern'."
1564 pattern 1590 pattern
1565 "")) 1591 ""))
1566 1592
1567(defun completion-pcm-try-completion (string table pred point) 1593;; We want to provide the functionality of `try', but we use `all'
1568 (destructuring-bind (pattern all prefix suffix) 1594;; and then merge it. In most cases, this works perfectly, but
1569 (completion-pcm--find-all-completions string table pred point) 1595;; if the completion table doesn't consider the same completions in
1596;; `try' as in `all', then we have a problem. The most common such
1597;; case is for filename completion where completion-ignored-extensions
1598;; is only obeyed by the `try' code. We paper over the difference
1599;; here. Note that it is not quite right either: if the completion
1600;; table uses completion-table-in-turn, this filtering may take place
1601;; too late to correctly fallback from the first to the
1602;; second alternative.
1603(defun completion-pcm--filename-try-filter (all)
1604 "Filter to adjust `all' file completion to the behavior of `try'."
1570 (when all 1605 (when all
1606 (let ((try ())
1607 (re (concat "\\(?:\\`\\.\\.?/\\|"
1608 (regexp-opt completion-ignored-extensions)
1609 "\\)\\'")))
1610 (dolist (f all)
1611 (unless (string-match re f) (push f try)))
1612 (or try all))))
1613
1614
1615(defun completion-pcm--merge-try (pattern all prefix suffix)
1616 (cond
1617 ((not (consp all)) all)
1618 ((and (not (consp (cdr all))) ;Only one completion.
1619 ;; Ignore completion-ignore-case here.
1620 (equal (completion-pcm--pattern->string pattern) (car all)))
1621 t)
1622 (t
1571 (let* ((mergedpat (completion-pcm--merge-completions all pattern)) 1623 (let* ((mergedpat (completion-pcm--merge-completions all pattern))
1572 ;; `mergedpat' is in reverse order. Place new point (by 1624 ;; `mergedpat' is in reverse order. Place new point (by
1573 ;; order of preference) either at the old point, or at 1625 ;; order of preference) either at the old point, or at
@@ -1579,11 +1631,18 @@ PATTERN is as returned by `completion-pcm--string->pattern'."
1579 (newpos (length (completion-pcm--pattern->string pointpat))) 1631 (newpos (length (completion-pcm--pattern->string pointpat)))
1580 ;; Do it afterwards because it changes `pointpat' by sideeffect. 1632 ;; Do it afterwards because it changes `pointpat' by sideeffect.
1581 (merged (completion-pcm--pattern->string (nreverse mergedpat)))) 1633 (merged (completion-pcm--pattern->string (nreverse mergedpat))))
1582 (if (and (> (length merged) 0) (> (length suffix) 0) 1634
1583 (eq (aref merged (1- (length merged))) (aref suffix 0))) 1635 (setq suffix (completion--merge-suffix merged newpos suffix))
1584 (setq suffix (substring suffix 1)))
1585 (cons (concat prefix merged suffix) (+ newpos (length prefix))))))) 1636 (cons (concat prefix merged suffix) (+ newpos (length prefix)))))))
1586 1637
1638(defun completion-pcm-try-completion (string table pred point)
1639 (destructuring-bind (pattern all prefix suffix)
1640 (completion-pcm--find-all-completions
1641 string table pred point
1642 (if minibuffer-completing-file-name
1643 'completion-pcm--filename-try-filter))
1644 (completion-pcm--merge-try pattern all prefix suffix)))
1645
1587 1646
1588(provide 'minibuffer) 1647(provide 'minibuffer)
1589 1648