Mercurial > emacs
annotate lisp/minibuffer.el @ 95312:a9b4031fa99f
(x_set_frame_alpha): Fix type mismatch.
author | Andreas Schwab <schwab@suse.de> |
---|---|
date | Mon, 26 May 2008 11:37:42 +0000 |
parents | 451f4028c096 |
children | 119c6508d4f8 |
rev | line source |
---|---|
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1 ;;; minibuffer.el --- Minibuffer completion functions |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
3 ;; Copyright (C) 2008 Free Software Foundation, Inc. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
4 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
5 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca> |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
6 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
7 ;; This file is part of GNU Emacs. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
8 |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94607
diff
changeset
|
9 ;; GNU Emacs is free software: you can redistribute it and/or modify |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
10 ;; it under the terms of the GNU General Public License as published by |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
11 ;; the Free Software Foundation, either version 3 of the License, or |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
12 ;; (at your option) any later version. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
13 |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94607
diff
changeset
|
14 ;; GNU Emacs is distributed in the hope that it will be useful, |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
17 ;; GNU General Public License for more details. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
18 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
19 ;; You should have received a copy of the GNU General Public License |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94607
diff
changeset
|
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
21 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
22 ;;; Commentary: |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
23 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
24 ;; Names with "--" are for functions and variables that are meant to be for |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
25 ;; internal use only. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
26 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
27 ;; Functional completion tables have an extended calling conventions: |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
28 ;; - If completion-all-completions-with-base-size is set, then all-completions |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
29 ;; should return the base-size in the last cdr. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
30 ;; - The `action' can be (additionally to nil, t, and lambda) of the form |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
31 ;; (boundaries . SUFFIX) in which case it should return |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
32 ;; (boundaries START . END). See `completion-boundaries'. |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
33 ;; Any other return value should be ignored (so we ignore values returned |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
34 ;; from completion tables that don't know about this new `action' form). |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
35 ;; See `completion-boundaries'. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
36 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
37 ;;; Bugs: |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
38 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
39 ;; - completion-ignored-extensions is ignored by partial-completion because |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
40 ;; pcm merges the `all' output to synthesize a `try' output and |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
41 ;; read-file-name-internal's `all' output doesn't obey |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
42 ;; completion-ignored-extensions. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
43 ;; - choose-completion can't automatically figure out the boundaries |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
44 ;; corresponding to the displayed completions. `base-size' gives the left |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
45 ;; boundary, but not the righthand one. So we need to add |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
46 ;; completion-extra-size (and also completion-no-auto-exit). |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
47 |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
48 ;;; Todo: |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
49 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
50 ;; - add support for ** to pcm. |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
51 ;; - Make read-file-name-predicate obsolete. |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
52 ;; - Add vc-file-name-completion-table to read-file-name-internal. |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
53 ;; - A feature like completing-help.el. |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
54 ;; - Make the `hide-spaces' arg of all-completions obsolete? |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
55 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
56 ;;; Code: |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
57 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
58 (eval-when-compile (require 'cl)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
60 (defvar completion-all-completions-with-base-size nil |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
61 "If non-nil, `all-completions' may return the base-size in the last cdr. |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
62 The base-size is the length of the prefix that is elided from each |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
63 element in the returned list of completions. See `completion-base-size'.") |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
64 |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
65 ;;; Completion table manipulation |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
66 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
67 ;; New completion-table operation. |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
68 (defun completion-boundaries (string table pred suffix) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
69 "Return the boundaries of the completions returned by TABLE for STRING. |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
70 STRING is the string on which completion will be performed. |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
71 SUFFIX is the string after point. |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
72 The result is of the form (START . END) where START is the position |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
73 in STRING of the beginning of the completion field and END is the position |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
74 in SUFFIX of the end of the completion field. |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
75 I.e. START is the same as the `completion-base-size'. |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
76 E.g. for simple completion tables, the result is always (0 . (length SUFFIX)) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
77 and for file names the result is the positions delimited by |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
78 the closest directory separators." |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
79 (let ((boundaries (if (functionp table) |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
80 (funcall table string pred (cons 'boundaries suffix))))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
81 (if (not (eq (car-safe boundaries) 'boundaries)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
82 (setq boundaries nil)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
83 (cons (or (cadr boundaries) 0) |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
84 (or (cddr boundaries) (length suffix))))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
85 |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
86 (defun completion--some (fun xs) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
87 "Apply FUN to each element of XS in turn. |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
88 Return the first non-nil returned value. |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
89 Like CL's `some'." |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
90 (let ((firsterror nil) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
91 res) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
92 (while (and (not res) xs) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
93 (condition-case err |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
94 (setq res (funcall fun (pop xs))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
95 (error (unless firsterror (setq firsterror err)) nil))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
96 (or res |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
97 (if firsterror (signal (car firsterror) (cdr firsterror)))))) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
98 |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
99 (defun apply-partially (fun &rest args) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
100 "Do a \"curried\" partial application of FUN to ARGS. |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
101 ARGS is a list of the first N arguments to pass to FUN. |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
102 The result is a new function that takes the remaining arguments, |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
103 and calls FUN." |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
104 (lexical-let ((fun fun) (args1 args)) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
105 (lambda (&rest args2) (apply fun (append args1 args2))))) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
106 |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
107 (defun complete-with-action (action table string pred) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
108 "Perform completion ACTION. |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
109 STRING is the string to complete. |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
110 TABLE is the completion table, which should not be a function. |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
111 PRED is a completion predicate. |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
112 ACTION can be one of nil, t or `lambda'." |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
113 (cond |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
114 ((functionp table) (funcall table string pred action)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
115 ((eq (car-safe action) 'boundaries) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
116 (cons 'boundaries (completion-boundaries string table pred (cdr action)))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
117 (t |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
118 (funcall |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
119 (cond |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
120 ((null action) 'try-completion) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
121 ((eq action t) 'all-completions) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
122 (t 'test-completion)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
123 string table pred)))) |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
124 |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
125 (defun completion-table-dynamic (fun) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
126 "Use function FUN as a dynamic completion table. |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
127 FUN is called with one argument, the string for which completion is required, |
94202
987535788e11
(completion-table-dynamic): Fix typo, and reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94182
diff
changeset
|
128 and it should return an alist containing all the intended possible completions. |
987535788e11
(completion-table-dynamic): Fix typo, and reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94182
diff
changeset
|
129 This alist may be a full list of possible completions so that FUN can ignore |
987535788e11
(completion-table-dynamic): Fix typo, and reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94182
diff
changeset
|
130 the value of its argument. If completion is performed in the minibuffer, |
987535788e11
(completion-table-dynamic): Fix typo, and reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94182
diff
changeset
|
131 FUN will be called in the buffer from which the minibuffer was entered. |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
132 |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
133 The result of the `dynamic-completion-table' form is a function |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
134 that can be used as the ALIST argument to `try-completion' and |
94202
987535788e11
(completion-table-dynamic): Fix typo, and reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94182
diff
changeset
|
135 `all-completions'. See Info node `(elisp)Programmed Completion'." |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
136 (lexical-let ((fun fun)) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
137 (lambda (string pred action) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
138 (with-current-buffer (let ((win (minibuffer-selected-window))) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
139 (if (window-live-p win) (window-buffer win) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
140 (current-buffer))) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
141 (complete-with-action action (funcall fun string) string pred))))) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
142 |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
143 (defmacro lazy-completion-table (var fun) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
144 "Initialize variable VAR as a lazy completion table. |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
145 If the completion table VAR is used for the first time (e.g., by passing VAR |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
146 as an argument to `try-completion'), the function FUN is called with no |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
147 arguments. FUN must return the completion table that will be stored in VAR. |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
148 If completion is requested in the minibuffer, FUN will be called in the buffer |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
149 from which the minibuffer was entered. The return value of |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
150 `lazy-completion-table' must be used to initialize the value of VAR. |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
151 |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
152 You should give VAR a non-nil `risky-local-variable' property." |
94017
f2ded84f543c
(lazy-completion-table): Fix debug spec.
Johan Bockgård <bojohan@gnu.org>
parents:
94013
diff
changeset
|
153 (declare (debug (symbolp lambda-expr))) |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
154 (let ((str (make-symbol "string"))) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
155 `(completion-table-dynamic |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
156 (lambda (,str) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
157 (when (functionp ,var) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
158 (setq ,var (,fun))) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
159 ,var)))) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
160 |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
161 (defun completion-table-with-context (prefix table string pred action) |
94180
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
162 ;; TODO: add `suffix' maybe? |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
163 ;; Notice that `pred' may not be a function in some abusive cases. |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
164 (when (functionp pred) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
165 (setq pred |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
166 (lexical-let ((pred pred)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
167 ;; Predicates are called differently depending on the nature of |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
168 ;; the completion table :-( |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
169 (cond |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
170 ((vectorp table) ;Obarray. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
171 (lambda (sym) (funcall pred (concat prefix (symbol-name sym))))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
172 ((hash-table-p table) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
173 (lambda (s v) (funcall pred (concat prefix s)))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
174 ((functionp table) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
175 (lambda (s) (funcall pred (concat prefix s)))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
176 (t ;Lists and alists. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
177 (lambda (s) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
178 (funcall pred (concat prefix (if (consp s) (car s) s))))))))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
179 (if (eq (car-safe action) 'boundaries) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
180 (let* ((len (length prefix)) |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
181 (bound (completion-boundaries string table pred (cdr action)))) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
182 (list* 'boundaries (+ (car bound) len) (cdr bound))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
183 (let ((comp (complete-with-action action table string pred))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
184 (cond |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
185 ;; In case of try-completion, add the prefix. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
186 ((stringp comp) (concat prefix comp)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
187 ;; In case of non-empty all-completions, |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
188 ;; add the prefix size to the base-size. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
189 ((consp comp) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
190 (let ((last (last comp))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
191 (when completion-all-completions-with-base-size |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
192 (setcdr last (+ (or (cdr last) 0) (length prefix)))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
193 comp)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
194 (t comp))))) |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
195 |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
196 (defun completion-table-with-terminator (terminator table string pred action) |
94180
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
197 (cond |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
198 ((eq action nil) |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
199 (let ((comp (try-completion string table pred))) |
94077
28e2f73174d6
(completion-table-with-terminator): Those completions
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94069
diff
changeset
|
200 (if (eq comp t) |
28e2f73174d6
(completion-table-with-terminator): Those completions
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94069
diff
changeset
|
201 (concat string terminator) |
28e2f73174d6
(completion-table-with-terminator): Those completions
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94069
diff
changeset
|
202 (if (and (stringp comp) |
94180
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
203 (eq (try-completion comp table pred) t)) |
94077
28e2f73174d6
(completion-table-with-terminator): Those completions
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94069
diff
changeset
|
204 (concat comp terminator) |
94180
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
205 comp)))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
206 ((eq action t) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
207 ;; FIXME: We generally want the `try' and `all' behaviors to be |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
208 ;; consistent so pcm can merge the `all' output to get the `try' output, |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
209 ;; but that sometimes clashes with the need for `all' output to look |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
210 ;; good in *Completions*. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
211 ;; (let* ((all (all-completions string table pred)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
212 ;; (last (last all)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
213 ;; (base-size (cdr last))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
214 ;; (when all |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
215 ;; (setcdr all nil) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
216 ;; (nconc (mapcar (lambda (s) (concat s terminator)) all) base-size))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
217 (all-completions string table pred)) |
94180
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
218 ;; completion-table-with-terminator is always used for |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
219 ;; "sub-completions" so it's only called if the terminator is missing, |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
220 ;; in which case `test-completion' should return nil. |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
221 ((eq action 'lambda) nil))) |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
222 |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
223 (defun completion-table-with-predicate (table pred1 strict string pred2 action) |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
224 "Make a completion table equivalent to TABLE but filtered through PRED1. |
94736
3a7862f514d0
(completion-table-with-predicate): Don't use `iff' in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94678
diff
changeset
|
225 PRED1 is a function of one argument which returns non-nil if and only if the |
94180
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
226 argument is an element of TABLE which should be considered for completion. |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
227 STRING, PRED2, and ACTION are the usual arguments to completion tables, |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
228 as described in `try-completion', `all-completions', and `test-completion'. |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
229 If STRICT is t, the predicate always applies; if nil it only applies if |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
230 it does not reduce the set of possible completions to nothing. |
94180
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
231 Note: TABLE needs to be a proper completion table which obeys predicates." |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
232 (cond |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
233 ((and (not strict) (eq action 'lambda)) |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
234 ;; Ignore pred1 since it doesn't really have to apply anyway. |
94182
0be1624297ac
(completion-table-with-predicate): Typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94180
diff
changeset
|
235 (test-completion string table pred2)) |
94180
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
236 (t |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
237 (or (complete-with-action action table string |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
238 (if (null pred2) pred1 |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
239 (lexical-let ((pred1 pred2) (pred2 pred2)) |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
240 (lambda (x) |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
241 ;; Call `pred1' first, so that `pred2' |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
242 ;; really can't tell that `x' is in table. |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
243 (if (funcall pred1 x) (funcall pred2 x)))))) |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
244 ;; If completion failed and we're not applying pred1 strictly, try |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
245 ;; again without pred1. |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
246 (and (not strict) |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
247 (complete-with-action action table string pred2)))))) |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
248 |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
249 (defun completion-table-in-turn (&rest tables) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
250 "Create a completion table that tries each table in TABLES in turn." |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
251 (lexical-let ((tables tables)) |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
252 (lambda (string pred action) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
253 (completion--some (lambda (table) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
254 (complete-with-action action table string pred)) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
255 tables)))) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
256 |
94180
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
257 ;; (defmacro complete-in-turn (a b) `(completion-table-in-turn ,a ,b)) |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
258 ;; (defmacro dynamic-completion-table (fun) `(completion-table-dynamic ,fun)) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
259 (define-obsolete-function-alias |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
260 'complete-in-turn 'completion-table-in-turn "23.1") |
94180
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
261 (define-obsolete-function-alias |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
262 'dynamic-completion-table 'completion-table-dynamic "23.1") |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
263 |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
264 ;;; Minibuffer completion |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
265 |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
266 (defgroup minibuffer nil |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
267 "Controlling the behavior of the minibuffer." |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
268 :link '(custom-manual "(emacs)Minibuffer") |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
269 :group 'environment) |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
270 |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
271 (defun minibuffer-message (message &rest args) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
272 "Temporarily display MESSAGE at the end of the minibuffer. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
273 The text is displayed for `minibuffer-message-timeout' seconds, |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
274 or until the next input event arrives, whichever comes first. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
275 Enclose MESSAGE in [...] if this is not yet the case. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
276 If ARGS are provided, then pass MESSAGE through `format'." |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
277 ;; Clear out any old echo-area message to make way for our new thing. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
278 (message nil) |
94091
14fafab62797
(minibuffer-message): Make sure we can put-text-property.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94077
diff
changeset
|
279 (setq message (if (and (null args) (string-match "\\[.+\\]" message)) |
14fafab62797
(minibuffer-message): Make sure we can put-text-property.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94077
diff
changeset
|
280 ;; Make sure we can put-text-property. |
14fafab62797
(minibuffer-message): Make sure we can put-text-property.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94077
diff
changeset
|
281 (copy-sequence message) |
14fafab62797
(minibuffer-message): Make sure we can put-text-property.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94077
diff
changeset
|
282 (concat " [" message "]"))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
283 (when args (setq message (apply 'format message args))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
284 (let ((ol (make-overlay (point-max) (point-max) nil t t))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
285 (unwind-protect |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
286 (progn |
94069
a91b57e652cd
(minibuffer-message): Put cursor at the right place.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94068
diff
changeset
|
287 (unless (zerop (length message)) |
a91b57e652cd
(minibuffer-message): Put cursor at the right place.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94068
diff
changeset
|
288 ;; The current C cursor code doesn't know to use the overlay's |
a91b57e652cd
(minibuffer-message): Put cursor at the right place.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94068
diff
changeset
|
289 ;; marker's stickiness to figure out whether to place the cursor |
a91b57e652cd
(minibuffer-message): Put cursor at the right place.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94068
diff
changeset
|
290 ;; before or after the string, so let's spoon-feed it the pos. |
a91b57e652cd
(minibuffer-message): Put cursor at the right place.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94068
diff
changeset
|
291 (put-text-property 0 1 'cursor t message)) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
292 (overlay-put ol 'after-string message) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
293 (sit-for (or minibuffer-message-timeout 1000000))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
294 (delete-overlay ol)))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
295 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
296 (defun minibuffer-completion-contents () |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
297 "Return the user input in a minibuffer before point as a string. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
298 That is what completion commands operate on." |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
299 (buffer-substring (field-beginning) (point))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
300 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
301 (defun delete-minibuffer-contents () |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
302 "Delete all user input in a minibuffer. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
303 If the current buffer is not a minibuffer, erase its entire contents." |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
304 (delete-field)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
305 |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
306 (defcustom completion-auto-help t |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
307 "Non-nil means automatically provide help for invalid completion input. |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
308 If the value is t the *Completion* buffer is displayed whenever completion |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
309 is requested but cannot be done. |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
310 If the value is `lazy', the *Completions* buffer is only displayed after |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
311 the second failed attempt to complete." |
93942
187008494f10
(completion-auto-help): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents:
93937
diff
changeset
|
312 :type '(choice (const nil) (const t) (const lazy)) |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
313 :group 'minibuffer) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
314 |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
315 (defvar completion-styles-alist |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
316 '((basic completion-basic-try-completion completion-basic-all-completions) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
317 (emacs22 completion-emacs22-try-completion completion-emacs22-all-completions) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
318 (emacs21 completion-emacs21-try-completion completion-emacs21-all-completions) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
319 (partial-completion |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
320 completion-pcm-try-completion completion-pcm-all-completions)) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
321 "List of available completion styles. |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
322 Each element has the form (NAME TRY-COMPLETION ALL-COMPLETIONS) |
94375
f8b940834bbb
(completion-pcm-word-delimiters): Add :group.
Juanma Barranquero <lekktu@gmail.com>
parents:
94352
diff
changeset
|
323 where NAME is the name that should be used in `completion-styles', |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
324 TRY-COMPLETION is the function that does the completion, and |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
325 ALL-COMPLETIONS is the function that lists the completions.") |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
326 |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
327 (defcustom completion-styles '(basic partial-completion) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
328 "List of completion styles to use." |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
329 :type `(repeat (choice ,@(mapcar (lambda (x) (list 'const (car x))) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
330 completion-styles-alist))) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
331 :group 'minibuffer |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
332 :version "23.1") |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
333 |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
334 (defun completion-try-completion (string table pred point) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
335 "Try to complete STRING using completion table TABLE. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
336 Only the elements of table that satisfy predicate PRED are considered. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
337 POINT is the position of point within STRING. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
338 The return value can be either nil to indicate that there is no completion, |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
339 t to indicate that STRING is the only possible completion, |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
340 or a pair (STRING . NEWPOINT) of the completed result string together with |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
341 a new position for point." |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
342 ;; The property `completion-styles' indicates that this functional |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
343 ;; completion-table claims to take care of completion styles itself. |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
344 ;; [I.e. It will most likely call us back at some point. ] |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
345 (if (and (symbolp table) (get table 'completion-styles)) |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
346 ;; Extended semantics for functional completion-tables: |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
347 ;; They accept a 4th argument `point' and when called with action=nil |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
348 ;; and this 4th argument (a position inside `string'), they should |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
349 ;; return instead of a string a pair (STRING . NEWPOINT). |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
350 (funcall table string pred nil point) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
351 (completion--some (lambda (style) |
94068
f2cff391663b
(minibuffer-try-completion, minibuffer-all-completions): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94062
diff
changeset
|
352 (funcall (nth 1 (assq style completion-styles-alist)) |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
353 string table pred point)) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
354 completion-styles))) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
355 |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
356 (defun completion-all-completions (string table pred point) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
357 "List the possible completions of STRING in completion table TABLE. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
358 Only the elements of table that satisfy predicate PRED are considered. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
359 POINT is the position of point within STRING. |
94375
f8b940834bbb
(completion-pcm-word-delimiters): Add :group.
Juanma Barranquero <lekktu@gmail.com>
parents:
94352
diff
changeset
|
360 The return value is a list of completions and may contain the base-size |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
361 in the last `cdr'." |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
362 (let ((completion-all-completions-with-base-size t)) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
363 ;; The property `completion-styles' indicates that this functional |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
364 ;; completion-table claims to take care of completion styles itself. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
365 ;; [I.e. It will most likely call us back at some point. ] |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
366 (if (and (symbolp table) (get table 'completion-styles)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
367 ;; Extended semantics for functional completion-tables: |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
368 ;; They accept a 4th argument `point' and when called with action=t |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
369 ;; and this 4th argument (a position inside `string'), they may |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
370 ;; return BASE-SIZE in the last `cdr'. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
371 (funcall table string pred t point) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
372 (completion--some (lambda (style) |
94068
f2cff391663b
(minibuffer-try-completion, minibuffer-all-completions): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94062
diff
changeset
|
373 (funcall (nth 2 (assq style completion-styles-alist)) |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
374 string table pred point)) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
375 completion-styles)))) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
376 |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
377 (defun minibuffer--bitset (modified completions exact) |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
378 (logior (if modified 4 0) |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
379 (if completions 2 0) |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
380 (if exact 1 0))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
381 |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
382 (defun completion--do-completion (&optional try-completion-function) |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
383 "Do the completion and return a summary of what happened. |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
384 M = completion was performed, the text was Modified. |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
385 C = there were available Completions. |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
386 E = after completion we now have an Exact match. |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
387 |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
388 MCE |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
389 000 0 no possible completion |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
390 001 1 was already an exact and unique completion |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
391 010 2 no completion happened |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
392 011 3 was already an exact completion |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
393 100 4 ??? impossible |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
394 101 5 ??? impossible |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
395 110 6 some completion happened |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
396 111 7 completed to an exact completion" |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
397 (let* ((beg (field-beginning)) |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
398 (end (field-end)) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
399 (string (buffer-substring beg end)) |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
400 (comp (funcall (or try-completion-function |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
401 'completion-try-completion) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
402 string |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
403 minibuffer-completion-table |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
404 minibuffer-completion-predicate |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
405 (- (point) beg)))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
406 (cond |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
407 ((null comp) |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
408 (ding) (minibuffer-message "No match") (minibuffer--bitset nil nil nil)) |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
409 ((eq t comp) (minibuffer--bitset nil nil t)) ;Exact and unique match. |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
410 (t |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
411 ;; `completed' should be t if some completion was done, which doesn't |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
412 ;; include simply changing the case of the entered string. However, |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
413 ;; for appearance, the string is rewritten if the case changes. |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
414 (let* ((comp-pos (cdr comp)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
415 (completion (car comp)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
416 (completed (not (eq t (compare-strings completion nil nil |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
417 string nil nil t)))) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
418 (unchanged (eq t (compare-strings completion nil nil |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
419 string nil nil nil)))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
420 (unless unchanged |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
421 |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
422 ;; Insert in minibuffer the chars we got. |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
423 (goto-char end) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
424 (insert completion) |
94486
ca90422b8114
(completion--do-completion): Move point even if the completion makes no change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94465
diff
changeset
|
425 (delete-region beg end)) |
ca90422b8114
(completion--do-completion): Move point even if the completion makes no change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94465
diff
changeset
|
426 ;; Move point. |
ca90422b8114
(completion--do-completion): Move point even if the completion makes no change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94465
diff
changeset
|
427 (goto-char (+ beg comp-pos)) |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
428 |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
429 (if (not (or unchanged completed)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
430 ;; The case of the string changed, but that's all. We're not sure |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
431 ;; whether this is a unique completion or not, so try again using |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
432 ;; the real case (this shouldn't recurse again, because the next |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
433 ;; time try-completion will return either t or the exact string). |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
434 (completion--do-completion try-completion-function) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
435 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
436 ;; It did find a match. Do we match some possibility exactly now? |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
437 (let ((exact (test-completion completion |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
438 minibuffer-completion-table |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
439 minibuffer-completion-predicate))) |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
440 (unless completed |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
441 ;; Show the completion table, if requested. |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
442 (cond |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
443 ((not exact) |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
444 (if (case completion-auto-help |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
445 (lazy (eq this-command last-command)) |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
446 (t completion-auto-help)) |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
447 (minibuffer-completion-help) |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
448 (minibuffer-message "Next char not unique"))) |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
449 ;; If the last exact completion and this one were the same, |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
450 ;; it means we've already given a "Complete but not unique" |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
451 ;; message and the user's hit TAB again, so now we give him help. |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
452 ((eq this-command last-command) |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
453 (if completion-auto-help (minibuffer-completion-help))))) |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
454 |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
455 (minibuffer--bitset completed t exact)))))))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
456 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
457 (defun minibuffer-complete () |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
458 "Complete the minibuffer contents as far as possible. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
459 Return nil if there is no valid completion, else t. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
460 If no characters can be completed, display a list of possible completions. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
461 If you repeat this command after it displayed such a list, |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
462 scroll the window of possible completions." |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
463 (interactive) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
464 ;; If the previous command was not this, |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
465 ;; mark the completion buffer obsolete. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
466 (unless (eq this-command last-command) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
467 (setq minibuffer-scroll-window nil)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
468 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
469 (let ((window minibuffer-scroll-window)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
470 ;; If there's a fresh completion window with a live buffer, |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
471 ;; and this command is repeated, scroll that window. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
472 (if (window-live-p window) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
473 (with-current-buffer (window-buffer window) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
474 (if (pos-visible-in-window-p (point-max) window) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
475 ;; If end is in view, scroll up to the beginning. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
476 (set-window-start window (point-min) nil) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
477 ;; Else scroll down one screen. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
478 (scroll-other-window)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
479 nil) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
480 |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
481 (case (completion--do-completion) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
482 (#b000 nil) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
483 (#b001 (goto-char (field-end)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
484 (minibuffer-message "Sole completion") |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
485 t) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
486 (#b011 (goto-char (field-end)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
487 (minibuffer-message "Complete, but not unique") |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
488 t) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
489 (t t))))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
490 |
95172
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
491 (defvar completion-all-sorted-completions nil) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
492 (make-variable-buffer-local 'completion-all-sorted-completions) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
493 |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
494 (defun completion--flush-all-sorted-completions (&rest ignore) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
495 (setq completion-all-sorted-completions nil)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
496 |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
497 (defun completion-all-sorted-completions () |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
498 (or completion-all-sorted-completions |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
499 (let* ((start (field-beginning)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
500 (end (field-end)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
501 (all (completion-all-completions (buffer-substring start end) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
502 minibuffer-completion-table |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
503 minibuffer-completion-predicate |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
504 (- (point) start))) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
505 (last (last all)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
506 (base-size (or (cdr last) 0))) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
507 (when last |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
508 (setcdr last nil) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
509 ;; Prefer shorter completions. |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
510 (setq all (sort all (lambda (c1 c2) (< (length c1) (length c2))))) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
511 ;; Prefer recently used completions. |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
512 (let ((hist (symbol-value minibuffer-history-variable))) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
513 (setq all (sort all (lambda (c1 c2) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
514 (> (length (member c1 hist)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
515 (length (member c2 hist))))))) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
516 ;; Cache the result. This is not just for speed, but also so that |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
517 ;; repeated calls to minibuffer-force-complete can cycle through |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
518 ;; all possibilities. |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
519 (add-hook 'after-change-functions |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
520 'completion--flush-all-sorted-completions nil t) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
521 (setq completion-all-sorted-completions |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
522 (nconc all base-size)))))) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
523 |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
524 (defun minibuffer-force-complete () |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
525 "Complete the minibuffer to an exact match. |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
526 Repeated uses step through the possible completions." |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
527 (interactive) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
528 ;; FIXME: Need to deal with the extra-size issue here as well. |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
529 (let* ((start (field-beginning)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
530 (end (field-end)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
531 (all (completion-all-sorted-completions))) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
532 (if (not (consp all)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
533 (minibuffer-message (if all "No more completions" "No completions")) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
534 (goto-char end) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
535 (insert (car all)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
536 (delete-region (+ start (cdr (last all))) end) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
537 ;; If completing file names, (car all) may be a directory, so we'd now |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
538 ;; have a new set of possible completions and might want to reset |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
539 ;; completion-all-sorted-completions to nil, but we prefer not to, |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
540 ;; so that repeated calls minibuffer-force-complete still cycle |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
541 ;; through the previous possible completions. |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
542 (setq completion-all-sorted-completions (cdr all))))) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
543 |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
544 (defun minibuffer-complete-and-exit () |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
545 "If the minibuffer contents is a valid completion then exit. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
546 Otherwise try to complete it. If completion leads to a valid completion, |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
547 a repetition of this command will exit. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
548 If `minibuffer-completion-confirm' is equal to `confirm', then do not |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
549 try to complete, but simply ask for confirmation and accept any |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
550 input if confirmed." |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
551 (interactive) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
552 (let ((beg (field-beginning)) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
553 (end (field-end))) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
554 (cond |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
555 ;; Allow user to specify null string |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
556 ((= beg end) (exit-minibuffer)) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
557 ((test-completion (buffer-substring beg end) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
558 minibuffer-completion-table |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
559 minibuffer-completion-predicate) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
560 (when completion-ignore-case |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
561 ;; Fixup case of the field, if necessary. |
94242
3530bf3c1687
(minibuffer-complete-and-exit): Fix last change.
Juanma Barranquero <lekktu@gmail.com>
parents:
94218
diff
changeset
|
562 (let* ((string (buffer-substring beg end)) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
563 (compl (try-completion |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
564 string |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
565 minibuffer-completion-table |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
566 minibuffer-completion-predicate))) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
567 (when (and (stringp compl) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
568 ;; If it weren't for this piece of paranoia, I'd replace |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
569 ;; the whole thing with a call to do-completion. |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
570 (= (length string) (length compl))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
571 (goto-char end) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
572 (insert compl) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
573 (delete-region beg end)))) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
574 (exit-minibuffer)) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
575 |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
576 ((eq minibuffer-completion-confirm 'confirm-only) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
577 ;; The user is permitted to exit with an input that's rejected |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
578 ;; by test-completion, but at the condition to confirm her choice. |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
579 (if (eq last-command this-command) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
580 (exit-minibuffer) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
581 (minibuffer-message "Confirm") |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
582 nil)) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
583 |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
584 (t |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
585 ;; Call do-completion, but ignore errors. |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
586 (case (condition-case nil |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
587 (completion--do-completion) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
588 (error 1)) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
589 ((#b001 #b011) (exit-minibuffer)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
590 (#b111 (if (not minibuffer-completion-confirm) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
591 (exit-minibuffer) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
592 (minibuffer-message "Confirm") |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
593 nil)) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
594 (t nil)))))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
595 |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
596 (defun completion--try-word-completion (string table predicate point) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
597 (let ((comp (completion-try-completion string table predicate point))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
598 (if (not (consp comp)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
599 comp |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
600 |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
601 ;; If completion finds next char not unique, |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
602 ;; consider adding a space or a hyphen. |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
603 (when (= (length string) (length (car comp))) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
604 (let ((exts '(" " "-")) |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
605 (before (substring string 0 point)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
606 (after (substring string point)) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
607 ;; If the user hasn't entered any text yet, then she |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
608 ;; presumably hits SPC to see the *completions*, but |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
609 ;; partial-completion will often find a " " or a "-" to match. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
610 ;; So disable partial-completion in that situation. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
611 (completion-styles |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
612 (or (and (equal string "") |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
613 (remove 'partial-completion completion-styles)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
614 completion-styles)) |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
615 tem) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
616 (while (and exts (not (consp tem))) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
617 (setq tem (completion-try-completion |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
618 (concat before (pop exts) after) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
619 table predicate (1+ point)))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
620 (if (consp tem) (setq comp tem)))) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
621 |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
622 ;; Completing a single word is actually more difficult than completing |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
623 ;; as much as possible, because we first have to find the "current |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
624 ;; position" in `completion' in order to find the end of the word |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
625 ;; we're completing. Normally, `string' is a prefix of `completion', |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
626 ;; which makes it trivial to find the position, but with fancier |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
627 ;; completion (plus env-var expansion, ...) `completion' might not |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
628 ;; look anything like `string' at all. |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
629 (let* ((comppoint (cdr comp)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
630 (completion (car comp)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
631 (before (substring string 0 point)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
632 (combined (concat before "\n" completion))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
633 ;; Find in completion the longest text that was right before point. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
634 (when (string-match "\\(.+\\)\n.*?\\1" combined) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
635 (let* ((prefix (match-string 1 before)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
636 ;; We used non-greedy match to make `rem' as long as possible. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
637 (rem (substring combined (match-end 0))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
638 ;; Find in the remainder of completion the longest text |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
639 ;; that was right after point. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
640 (after (substring string point)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
641 (suffix (if (string-match "\\`\\(.+\\).*\n.*\\1" |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
642 (concat after "\n" rem)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
643 (match-string 1 after)))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
644 ;; The general idea is to try and guess what text was inserted |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
645 ;; at point by the completion. Problem is: if we guess wrong, |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
646 ;; we may end up treating as "added by completion" text that was |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
647 ;; actually painfully typed by the user. So if we then cut |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
648 ;; after the first word, we may throw away things the |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
649 ;; user wrote. So let's try to be as conservative as possible: |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
650 ;; only cut after the first word, if we're reasonably sure that |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
651 ;; our guess is correct. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
652 ;; Note: a quick survey on emacs-devel seemed to indicate that |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
653 ;; nobody actually cares about the "word-at-a-time" feature of |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
654 ;; minibuffer-complete-word, whose real raison-d'être is that it |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
655 ;; tries to add "-" or " ". One more reason to only cut after |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
656 ;; the first word, if we're really sure we're right. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
657 (when (and (or suffix (zerop (length after))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
658 (string-match (concat |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
659 ;; Make submatch 1 as small as possible |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
660 ;; to reduce the risk of cutting |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
661 ;; valuable text. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
662 ".*" (regexp-quote prefix) "\\(.*?\\)" |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
663 (if suffix (regexp-quote suffix) "\\'")) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
664 completion) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
665 ;; The new point in `completion' should also be just |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
666 ;; before the suffix, otherwise something more complex |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
667 ;; is going on, and we're not sure where we are. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
668 (eq (match-end 1) comppoint) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
669 ;; (match-beginning 1)..comppoint is now the stretch |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
670 ;; of text in `completion' that was completed at point. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
671 (string-match "\\W" completion (match-beginning 1)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
672 ;; Is there really something to cut? |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
673 (> comppoint (match-end 0))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
674 ;; Cut after the first word. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
675 (let ((cutpos (match-end 0))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
676 (setq completion (concat (substring completion 0 cutpos) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
677 (substring completion comppoint))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
678 (setq comppoint cutpos))))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
679 |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
680 (cons completion comppoint))))) |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
681 |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
682 |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
683 (defun minibuffer-complete-word () |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
684 "Complete the minibuffer contents at most a single word. |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
685 After one word is completed as much as possible, a space or hyphen |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
686 is added, provided that matches some possible completion. |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
687 Return nil if there is no valid completion, else t." |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
688 (interactive) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
689 (case (completion--do-completion 'completion--try-word-completion) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
690 (#b000 nil) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
691 (#b001 (goto-char (field-end)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
692 (minibuffer-message "Sole completion") |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
693 t) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
694 (#b011 (goto-char (field-end)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
695 (minibuffer-message "Complete, but not unique") |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
696 t) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
697 (t t))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
698 |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
699 (defun completion--insert-strings (strings) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
700 "Insert a list of STRINGS into the current buffer. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
701 Uses columns to keep the listing readable but compact. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
702 It also eliminates runs of equal strings." |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
703 (when (consp strings) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
704 (let* ((length (apply 'max |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
705 (mapcar (lambda (s) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
706 (if (consp s) |
94561
bbc1b1a5633e
(completion--insert-strings): Use string-width rather than length.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94558
diff
changeset
|
707 (+ (string-width (car s)) |
bbc1b1a5633e
(completion--insert-strings): Use string-width rather than length.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94558
diff
changeset
|
708 (string-width (cadr s))) |
bbc1b1a5633e
(completion--insert-strings): Use string-width rather than length.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94558
diff
changeset
|
709 (string-width s))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
710 strings))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
711 (window (get-buffer-window (current-buffer) 0)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
712 (wwidth (if window (1- (window-width window)) 79)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
713 (columns (min |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
714 ;; At least 2 columns; at least 2 spaces between columns. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
715 (max 2 (/ wwidth (+ 2 length))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
716 ;; Don't allocate more columns than we can fill. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
717 ;; Windows can't show less than 3 lines anyway. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
718 (max 1 (/ (length strings) 2)))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
719 (colwidth (/ wwidth columns)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
720 (column 0) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
721 (laststring nil)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
722 ;; The insertion should be "sensible" no matter what choices were made |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
723 ;; for the parameters above. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
724 (dolist (str strings) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
725 (unless (equal laststring str) ; Remove (consecutive) duplicates. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
726 (setq laststring str) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
727 (unless (bolp) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
728 (insert " \t") |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
729 (setq column (+ column colwidth)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
730 ;; Leave the space unpropertized so that in the case we're |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
731 ;; already past the goal column, there is still |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
732 ;; a space displayed. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
733 (set-text-properties (- (point) 1) (point) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
734 ;; We can't just set tab-width, because |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
735 ;; completion-setup-function will kill all |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
736 ;; local variables :-( |
94607
e0e6649ed314
(completion--insert-strings): Don't delete past
Andreas Schwab <schwab@suse.de>
parents:
94561
diff
changeset
|
737 `(display (space :align-to ,column))) |
e0e6649ed314
(completion--insert-strings): Don't delete past
Andreas Schwab <schwab@suse.de>
parents:
94561
diff
changeset
|
738 (when (< wwidth (+ (max colwidth |
e0e6649ed314
(completion--insert-strings): Don't delete past
Andreas Schwab <schwab@suse.de>
parents:
94561
diff
changeset
|
739 (if (consp str) |
e0e6649ed314
(completion--insert-strings): Don't delete past
Andreas Schwab <schwab@suse.de>
parents:
94561
diff
changeset
|
740 (+ (string-width (car str)) |
e0e6649ed314
(completion--insert-strings): Don't delete past
Andreas Schwab <schwab@suse.de>
parents:
94561
diff
changeset
|
741 (string-width (cadr str))) |
e0e6649ed314
(completion--insert-strings): Don't delete past
Andreas Schwab <schwab@suse.de>
parents:
94561
diff
changeset
|
742 (string-width str))) |
e0e6649ed314
(completion--insert-strings): Don't delete past
Andreas Schwab <schwab@suse.de>
parents:
94561
diff
changeset
|
743 column)) |
e0e6649ed314
(completion--insert-strings): Don't delete past
Andreas Schwab <schwab@suse.de>
parents:
94561
diff
changeset
|
744 (delete-char -2) (insert "\n") (setq column 0))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
745 (if (not (consp str)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
746 (put-text-property (point) (progn (insert str) (point)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
747 'mouse-face 'highlight) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
748 (put-text-property (point) (progn (insert (car str)) (point)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
749 'mouse-face 'highlight) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
750 (put-text-property (point) (progn (insert (cadr str)) (point)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
751 'mouse-face nil))))))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
752 |
94464
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
753 (defvar completion-common-substring nil) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
754 (make-obsolete-variable 'completion-common-substring nil "23.1") |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
755 |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
756 (defvar completion-setup-hook nil |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
757 "Normal hook run at the end of setting up a completion list buffer. |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
758 When this hook is run, the current buffer is the one in which the |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
759 command to display the completion list buffer was run. |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
760 The completion list buffer is available as the value of `standard-output'. |
94464
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
761 See also `display-completion-list'.") |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
762 |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
763 (defface completions-first-difference |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
764 '((t (:inherit bold))) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
765 "Face put on the first uncommon character in completions in *Completions* buffer." |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
766 :group 'completion) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
767 |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
768 (defface completions-common-part |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
769 '((t (:inherit default))) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
770 "Face put on the common prefix substring in completions in *Completions* buffer. |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
771 The idea of `completions-common-part' is that you can use it to |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
772 make the common parts less visible than normal, so that the rest |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
773 of the differing parts is, by contrast, slightly highlighted." |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
774 :group 'completion) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
775 |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
776 (defun completion-hilit-commonality (completions prefix-len) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
777 (when completions |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
778 (let* ((last (last completions)) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
779 (base-size (cdr last)) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
780 (com-str-len (- prefix-len (or base-size 0)))) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
781 ;; Remove base-size during mapcar, and add it back later. |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
782 (setcdr last nil) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
783 (nconc |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
784 (mapcar |
94558
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
785 (lambda (elem) |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
786 (let ((str |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
787 ;; Don't modify the string itself, but a copy, since the |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
788 ;; the string may be read-only or used for other purposes. |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
789 ;; Furthermore, since `completions' may come from |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
790 ;; display-completion-list, `elem' may be a list. |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
791 (if (consp elem) |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
792 (car (setq elem (cons (copy-sequence (car elem)) |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
793 (cdr elem)))) |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
794 (setq elem (copy-sequence elem))))) |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
795 (put-text-property 0 com-str-len |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
796 'font-lock-face 'completions-common-part |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
797 str) |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
798 (if (> (length str) com-str-len) |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
799 (put-text-property com-str-len (1+ com-str-len) |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
800 'font-lock-face 'completions-first-difference |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
801 str))) |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
802 elem) |
94464
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
803 completions) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
804 base-size)))) |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
805 |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
806 (defun display-completion-list (completions &optional common-substring) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
807 "Display the list of completions, COMPLETIONS, using `standard-output'. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
808 Each element may be just a symbol or string |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
809 or may be a list of two strings to be printed as if concatenated. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
810 If it is a list of two strings, the first is the actual completion |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
811 alternative, the second serves as annotation. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
812 `standard-output' must be a buffer. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
813 The actual completion alternatives, as inserted, are given `mouse-face' |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
814 properties of `highlight'. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
815 At the end, this runs the normal hook `completion-setup-hook'. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
816 It can find the completion buffer in `standard-output'. |
94464
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
817 The obsolete optional second arg COMMON-SUBSTRING is a string. |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
818 It is used to put faces, `completions-first-difference' and |
94202
987535788e11
(completion-table-dynamic): Fix typo, and reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94182
diff
changeset
|
819 `completions-common-part' on the completion buffer. The |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
820 `completions-common-part' face is put on the common substring |
94464
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
821 specified by COMMON-SUBSTRING." |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
822 (if common-substring |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
823 (setq completions (completion-hilit-commonality |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
824 completions (length common-substring)))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
825 (if (not (bufferp standard-output)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
826 ;; This *never* (ever) happens, so there's no point trying to be clever. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
827 (with-temp-buffer |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
828 (let ((standard-output (current-buffer)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
829 (completion-setup-hook nil)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
830 (display-completion-list completions)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
831 (princ (buffer-string))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
832 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
833 (with-current-buffer standard-output |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
834 (goto-char (point-max)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
835 (if (null completions) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
836 (insert "There are no possible completions of what you have typed.") |
93942
187008494f10
(completion-auto-help): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents:
93937
diff
changeset
|
837 |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
838 (insert "Possible completions are:\n") |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
839 (let ((last (last completions))) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
840 ;; Get the base-size from the tail of the list. |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
841 (set (make-local-variable 'completion-base-size) (or (cdr last) 0)) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
842 (setcdr last nil)) ;Make completions a properly nil-terminated list. |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
843 (completion--insert-strings completions)))) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
844 |
94464
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
845 ;; The hilit used to be applied via completion-setup-hook, so there |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
846 ;; may still be some code that uses completion-common-substring. |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
847 (let ((completion-common-substring common-substring)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
848 (run-hooks 'completion-setup-hook)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
849 nil) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
850 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
851 (defun minibuffer-completion-help () |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
852 "Display a list of possible completions of the current minibuffer contents." |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
853 (interactive) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
854 (message "Making completion list...") |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
855 (let* ((string (field-string)) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
856 (completions (completion-all-completions |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
857 string |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
858 minibuffer-completion-table |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
859 minibuffer-completion-predicate |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
860 (- (point) (field-beginning))))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
861 (message nil) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
862 (if (and completions |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
863 (or (consp (cdr completions)) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
864 (not (equal (car completions) string)))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
865 (with-output-to-temp-buffer "*Completions*" |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
866 (let* ((last (last completions)) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
867 (base-size (cdr last))) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
868 ;; Remove the base-size tail because `sort' requires a properly |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
869 ;; nil-terminated list. |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
870 (when last (setcdr last nil)) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
871 (display-completion-list (nconc (sort completions 'string-lessp) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
872 base-size)))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
873 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
874 ;; If there are no completions, or if the current input is already the |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
875 ;; only possible completion, then hide (previous&stale) completions. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
876 (let ((window (and (get-buffer "*Completions*") |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
877 (get-buffer-window "*Completions*" 0)))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
878 (when (and (window-live-p window) (window-dedicated-p window)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
879 (condition-case () |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
880 (delete-window window) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
881 (error (iconify-frame (window-frame window)))))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
882 (ding) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
883 (minibuffer-message |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
884 (if completions "Sole completion" "No completions"))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
885 nil)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
886 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
887 (defun exit-minibuffer () |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
888 "Terminate this minibuffer argument." |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
889 (interactive) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
890 ;; If the command that uses this has made modifications in the minibuffer, |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
891 ;; we don't want them to cause deactivation of the mark in the original |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
892 ;; buffer. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
893 ;; A better solution would be to make deactivate-mark buffer-local |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
894 ;; (or to turn it into a list of buffers, ...), but in the mean time, |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
895 ;; this should do the trick in most cases. |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
896 (setq deactivate-mark nil) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
897 (throw 'exit nil)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
898 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
899 (defun self-insert-and-exit () |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
900 "Terminate minibuffer input." |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
901 (interactive) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
902 (if (characterp last-command-char) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
903 (call-interactively 'self-insert-command) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
904 (ding)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
905 (exit-minibuffer)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
906 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
907 ;;; Key bindings. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
908 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
909 (let ((map minibuffer-local-map)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
910 (define-key map "\C-g" 'abort-recursive-edit) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
911 (define-key map "\r" 'exit-minibuffer) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
912 (define-key map "\n" 'exit-minibuffer)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
913 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
914 (let ((map minibuffer-local-completion-map)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
915 (define-key map "\t" 'minibuffer-complete) |
95172
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
916 ;; M-TAB is already abused for many other purposes, so we should find |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
917 ;; another binding for it. |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
918 ;; (define-key map "\e\t" 'minibuffer-force-complete) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
919 (define-key map " " 'minibuffer-complete-word) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
920 (define-key map "?" 'minibuffer-completion-help)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
921 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
922 (let ((map minibuffer-local-must-match-map)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
923 (define-key map "\r" 'minibuffer-complete-and-exit) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
924 (define-key map "\n" 'minibuffer-complete-and-exit)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
925 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
926 (let ((map minibuffer-local-filename-completion-map)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
927 (define-key map " " nil)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
928 (let ((map minibuffer-local-must-match-filename-map)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
929 (define-key map " " nil)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
930 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
931 (let ((map minibuffer-local-ns-map)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
932 (define-key map " " 'exit-minibuffer) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
933 (define-key map "\t" 'exit-minibuffer) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
934 (define-key map "?" 'self-insert-and-exit)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
935 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
936 ;;; Completion tables. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
937 |
93945
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
938 (defun minibuffer--double-dollars (str) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
939 (replace-regexp-in-string "\\$" "$$" str)) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
940 |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
941 (defun completion--make-envvar-table () |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
942 (mapcar (lambda (enventry) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
943 (substring enventry 0 (string-match "=" enventry))) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
944 process-environment)) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
945 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
946 (defconst completion--embedded-envvar-re |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
947 (concat "\\(?:^\\|[^$]\\(?:\\$\\$\\)*\\)" |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
948 "$\\([[:alnum:]_]*\\|{\\([^}]*\\)\\)\\'")) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
949 |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
950 (defun completion--embedded-envvar-table (string pred action) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
951 (if (eq (car-safe action) 'boundaries) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
952 ;; Compute the boundaries of the subfield to which this |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
953 ;; completion applies. |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
954 (let ((suffix (cdr action))) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
955 (if (string-match completion--embedded-envvar-re string) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
956 (list* 'boundaries |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
957 (or (match-beginning 2) (match-beginning 1)) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
958 (when (string-match "[^[:alnum:]_]" suffix) |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
959 (match-beginning 0))))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
960 (when (string-match completion--embedded-envvar-re string) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
961 (let* ((beg (or (match-beginning 2) (match-beginning 1))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
962 (table (completion--make-envvar-table)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
963 (prefix (substring string 0 beg))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
964 (if (eq (aref string (1- beg)) ?{) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
965 (setq table (apply-partially 'completion-table-with-terminator |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
966 "}" table))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
967 (completion-table-with-context |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
968 prefix table (substring string beg) pred action))))) |
94055
ec343c7600a2
(completion--embedded-envvar-table, read-file-name-internal):
Juanma Barranquero <lekktu@gmail.com>
parents:
94017
diff
changeset
|
969 |
94218
701d10a19a8f
(completion--file-name-table): Accept both the old `dir' or the new `pred' arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94211
diff
changeset
|
970 (defun completion--file-name-table (string pred action) |
94202
987535788e11
(completion-table-dynamic): Fix typo, and reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94182
diff
changeset
|
971 "Internal subroutine for `read-file-name'. Do not call this." |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
972 (cond |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
973 ((and (zerop (length string)) (eq 'lambda action)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
974 nil) ; FIXME: why? |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
975 ((eq (car-safe action) 'boundaries) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
976 ;; FIXME: Actually, this is not always right in the presence of |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
977 ;; envvars, but there's not much we can do, I think. |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
978 (let ((start (length (file-name-directory string))) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
979 (end (string-match "/" (cdr action)))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
980 (list* 'boundaries start end))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
981 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
982 (t |
94218
701d10a19a8f
(completion--file-name-table): Accept both the old `dir' or the new `pred' arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94211
diff
changeset
|
983 (let* ((dir (if (stringp pred) |
701d10a19a8f
(completion--file-name-table): Accept both the old `dir' or the new `pred' arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94211
diff
changeset
|
984 ;; It used to be that `pred' was abused to pass `dir' |
701d10a19a8f
(completion--file-name-table): Accept both the old `dir' or the new `pred' arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94211
diff
changeset
|
985 ;; as an argument. |
701d10a19a8f
(completion--file-name-table): Accept both the old `dir' or the new `pred' arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94211
diff
changeset
|
986 (prog1 (expand-file-name pred) (setq pred nil)) |
701d10a19a8f
(completion--file-name-table): Accept both the old `dir' or the new `pred' arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94211
diff
changeset
|
987 default-directory)) |
701d10a19a8f
(completion--file-name-table): Accept both the old `dir' or the new `pred' arg.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94211
diff
changeset
|
988 (str (condition-case nil |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
989 (substitute-in-file-name string) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
990 (error string))) |
93945
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
991 (name (file-name-nondirectory str)) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
992 (specdir (file-name-directory str)) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
993 (realdir (if specdir (expand-file-name specdir dir) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
994 (file-name-as-directory dir)))) |
94055
ec343c7600a2
(completion--embedded-envvar-table, read-file-name-internal):
Juanma Barranquero <lekktu@gmail.com>
parents:
94017
diff
changeset
|
995 |
93945
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
996 (cond |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
997 ((null action) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
998 (let ((comp (file-name-completion name realdir |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
999 read-file-name-predicate))) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1000 (if (stringp comp) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1001 ;; Requote the $s before returning the completion. |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1002 (minibuffer--double-dollars (concat specdir comp)) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1003 ;; Requote the $s before checking for changes. |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1004 (setq str (minibuffer--double-dollars str)) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1005 (if (string-equal string str) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1006 comp |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1007 ;; If there's no real completion, but substitute-in-file-name |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1008 ;; changed the string, then return the new string. |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1009 str)))) |
94055
ec343c7600a2
(completion--embedded-envvar-table, read-file-name-internal):
Juanma Barranquero <lekktu@gmail.com>
parents:
94017
diff
changeset
|
1010 |
93945
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1011 ((eq action t) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
1012 (let ((all (file-name-all-completions name realdir)) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1013 ;; FIXME: Actually, this is not always right in the presence |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1014 ;; of envvars, but there's not much we can do, I think. |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
1015 (base-size (length (file-name-directory string)))) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
1016 |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
1017 ;; Check the predicate, if necessary. |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
1018 (unless (memq read-file-name-predicate '(nil file-exists-p)) |
93945
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1019 (let ((comp ()) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1020 (pred |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1021 (if (eq read-file-name-predicate 'file-directory-p) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1022 ;; Brute-force speed up for directory checking: |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1023 ;; Discard strings which don't end in a slash. |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1024 (lambda (s) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1025 (let ((len (length s))) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1026 (and (> len 0) (eq (aref s (1- len)) ?/)))) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1027 ;; Must do it the hard (and slow) way. |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1028 read-file-name-predicate))) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1029 (let ((default-directory realdir)) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1030 (dolist (tem all) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1031 (if (funcall pred tem) (push tem comp)))) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
1032 (setq all (nreverse comp)))) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
1033 |
94077
28e2f73174d6
(completion-table-with-terminator): Those completions
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94069
diff
changeset
|
1034 (if (and completion-all-completions-with-base-size (consp all)) |
28e2f73174d6
(completion-table-with-terminator): Those completions
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94069
diff
changeset
|
1035 ;; Add base-size, but only if the list is non-empty. |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1036 (nconc all base-size) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1037 all))) |
93945
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1038 |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1039 (t |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1040 ;; Only other case actually used is ACTION = lambda. |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1041 (let ((default-directory dir)) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1042 (funcall (or read-file-name-predicate 'file-exists-p) str)))))))) |
93945
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1043 |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
1044 (defalias 'read-file-name-internal |
94055
ec343c7600a2
(completion--embedded-envvar-table, read-file-name-internal):
Juanma Barranquero <lekktu@gmail.com>
parents:
94017
diff
changeset
|
1045 (completion-table-in-turn 'completion--embedded-envvar-table |
94077
28e2f73174d6
(completion-table-with-terminator): Those completions
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94069
diff
changeset
|
1046 'completion--file-name-table) |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
1047 "Internal subroutine for `read-file-name'. Do not call this.") |
93945
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1048 |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1049 (defvar read-file-name-function nil |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1050 "If this is non-nil, `read-file-name' does its work by calling this function.") |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1051 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1052 (defvar read-file-name-predicate nil |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1053 "Current predicate used by `read-file-name-internal'.") |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1054 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1055 (defcustom read-file-name-completion-ignore-case |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1056 (if (memq system-type '(ms-dos windows-nt darwin macos vax-vms axp-vms)) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1057 t nil) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1058 "Non-nil means when reading a file name completion ignores case." |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1059 :group 'minibuffer |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1060 :type 'boolean |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1061 :version "22.1") |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1062 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1063 (defcustom insert-default-directory t |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1064 "Non-nil means when reading a filename start with default dir in minibuffer. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1065 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1066 When the initial minibuffer contents show a name of a file or a directory, |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1067 typing RETURN without editing the initial contents is equivalent to typing |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1068 the default file name. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1069 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1070 If this variable is non-nil, the minibuffer contents are always |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1071 initially non-empty, and typing RETURN without editing will fetch the |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1072 default name, if one is provided. Note however that this default name |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1073 is not necessarily the same as initial contents inserted in the minibuffer, |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1074 if the initial contents is just the default directory. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1075 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1076 If this variable is nil, the minibuffer often starts out empty. In |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1077 that case you may have to explicitly fetch the next history element to |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1078 request the default name; typing RETURN without editing will leave |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1079 the minibuffer empty. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1080 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1081 For some commands, exiting with an empty minibuffer has a special meaning, |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1082 such as making the current buffer visit no file in the case of |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1083 `set-visited-file-name'." |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1084 :group 'minibuffer |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1085 :type 'boolean) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1086 |
94315
755dd4bba830
(x-file-dialog): Declare as function.
Glenn Morris <rgm@gnu.org>
parents:
94304
diff
changeset
|
1087 ;; Not always defined, but only called if next-read-file-uses-dialog-p says so. |
755dd4bba830
(x-file-dialog): Declare as function.
Glenn Morris <rgm@gnu.org>
parents:
94304
diff
changeset
|
1088 (declare-function x-file-dialog "xfns.c" |
755dd4bba830
(x-file-dialog): Declare as function.
Glenn Morris <rgm@gnu.org>
parents:
94304
diff
changeset
|
1089 (prompt dir &optional default-filename mustmatch only-dir-p)) |
755dd4bba830
(x-file-dialog): Declare as function.
Glenn Morris <rgm@gnu.org>
parents:
94304
diff
changeset
|
1090 |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1091 (defun read-file-name (prompt &optional dir default-filename mustmatch initial predicate) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1092 "Read file name, prompting with PROMPT and completing in directory DIR. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1093 Value is not expanded---you must call `expand-file-name' yourself. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1094 Default name to DEFAULT-FILENAME if user exits the minibuffer with |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1095 the same non-empty string that was inserted by this function. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1096 (If DEFAULT-FILENAME is omitted, the visited file name is used, |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1097 except that if INITIAL is specified, that combined with DIR is used.) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1098 If the user exits with an empty minibuffer, this function returns |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1099 an empty string. (This can only happen if the user erased the |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1100 pre-inserted contents or if `insert-default-directory' is nil.) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1101 Fourth arg MUSTMATCH non-nil means require existing file's name. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1102 Non-nil and non-t means also require confirmation after completion. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1103 Fifth arg INITIAL specifies text to start with. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1104 If optional sixth arg PREDICATE is non-nil, possible completions and |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1105 the resulting file name must satisfy (funcall PREDICATE NAME). |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1106 DIR should be an absolute directory name. It defaults to the value of |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1107 `default-directory'. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1108 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1109 If this command was invoked with the mouse, use a file dialog box if |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1110 `use-dialog-box' is non-nil, and the window system or X toolkit in use |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1111 provides a file dialog box. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1112 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1113 See also `read-file-name-completion-ignore-case' |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1114 and `read-file-name-function'." |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1115 (unless dir (setq dir default-directory)) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1116 (unless (file-name-absolute-p dir) (setq dir (expand-file-name dir))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1117 (unless default-filename |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1118 (setq default-filename (if initial (expand-file-name initial dir) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1119 buffer-file-name))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1120 ;; If dir starts with user's homedir, change that to ~. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1121 (setq dir (abbreviate-file-name dir)) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1122 ;; Likewise for default-filename. |
94301
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1123 (if default-filename |
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1124 (setq default-filename (abbreviate-file-name default-filename))) |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1125 (let ((insdef (cond |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1126 ((and insert-default-directory (stringp dir)) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1127 (if initial |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1128 (cons (minibuffer--double-dollars (concat dir initial)) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1129 (length (minibuffer--double-dollars dir))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1130 (minibuffer--double-dollars dir))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1131 (initial (cons (minibuffer--double-dollars initial) 0))))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1132 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1133 (if read-file-name-function |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1134 (funcall read-file-name-function |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1135 prompt dir default-filename mustmatch initial predicate) |
94301
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1136 (let ((completion-ignore-case read-file-name-completion-ignore-case) |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1137 (minibuffer-completing-file-name t) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1138 (read-file-name-predicate (or predicate 'file-exists-p)) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1139 (add-to-history nil)) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1140 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1141 (let* ((val |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1142 (if (not (next-read-file-uses-dialog-p)) |
94301
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1143 ;; We used to pass `dir' to `read-file-name-internal' by |
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1144 ;; abusing the `predicate' argument. It's better to |
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1145 ;; just use `default-directory', but in order to avoid |
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1146 ;; changing `default-directory' in the current buffer, |
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1147 ;; we don't let-bind it. |
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1148 (lexical-let ((dir (file-name-as-directory |
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1149 (expand-file-name dir)))) |
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1150 (minibuffer-with-setup-hook |
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1151 (lambda () (setq default-directory dir)) |
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1152 (completing-read prompt 'read-file-name-internal |
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1153 nil mustmatch insdef 'file-name-history |
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1154 default-filename))) |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1155 ;; If DIR contains a file name, split it. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1156 (let ((file (file-name-nondirectory dir))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1157 (when (and default-filename (not (zerop (length file)))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1158 (setq default-filename file) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1159 (setq dir (file-name-directory dir))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1160 (if default-filename |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1161 (setq default-filename |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1162 (expand-file-name default-filename dir))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1163 (setq add-to-history t) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1164 (x-file-dialog prompt dir default-filename mustmatch |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1165 (eq predicate 'file-directory-p))))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1166 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1167 (replace-in-history (eq (car-safe file-name-history) val))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1168 ;; If completing-read returned the inserted default string itself |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1169 ;; (rather than a new string with the same contents), |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1170 ;; it has to mean that the user typed RET with the minibuffer empty. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1171 ;; In that case, we really want to return "" |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1172 ;; so that commands such as set-visited-file-name can distinguish. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1173 (when (eq val default-filename) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1174 ;; In this case, completing-read has not added an element |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1175 ;; to the history. Maybe we should. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1176 (if (not replace-in-history) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1177 (setq add-to-history t)) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1178 (setq val "")) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1179 (unless val (error "No file name specified")) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1180 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1181 (if (and default-filename |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1182 (string-equal val (if (consp insdef) (car insdef) insdef))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1183 (setq val default-filename)) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1184 (setq val (substitute-in-file-name val)) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1185 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1186 (if replace-in-history |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1187 ;; Replace what Fcompleting_read added to the history |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1188 ;; with what we will actually return. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1189 (let ((val1 (minibuffer--double-dollars val))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1190 (if history-delete-duplicates |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1191 (setcdr file-name-history |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1192 (delete val1 (cdr file-name-history)))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1193 (setcar file-name-history val1)) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1194 (if add-to-history |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1195 ;; Add the value to the history--but not if it matches |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1196 ;; the last value already there. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1197 (let ((val1 (minibuffer--double-dollars val))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1198 (unless (and (consp file-name-history) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1199 (equal (car file-name-history) val1)) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1200 (setq file-name-history |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1201 (cons val1 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1202 (if history-delete-duplicates |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1203 (delete val1 file-name-history) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1204 file-name-history))))))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1205 val))))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1206 |
94247
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1207 (defun internal-complete-buffer-except (&optional buffer) |
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1208 "Perform completion on all buffers excluding BUFFER. |
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1209 Like `internal-complete-buffer', but removes BUFFER from the completion list." |
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1210 (lexical-let ((except (if (stringp buffer) buffer (buffer-name buffer)))) |
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1211 (apply-partially 'completion-table-with-predicate |
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1212 'internal-complete-buffer |
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1213 (lambda (name) |
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1214 (not (equal (if (consp name) (car name) name) except))) |
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1215 nil))) |
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1216 |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1217 ;;; Old-style completion, used in Emacs-21. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1218 |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1219 (defun completion-emacs21-try-completion (string table pred point) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1220 (let ((completion (try-completion string table pred))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1221 (if (stringp completion) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1222 (cons completion (length completion)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1223 completion))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1224 |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1225 (defun completion-emacs21-all-completions (string table pred point) |
94464
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1226 (completion-hilit-commonality |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1227 (all-completions string table pred t) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1228 (length string))) |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1229 |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1230 ;;; Basic completion, used in Emacs-22. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1231 |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1232 (defun completion-emacs22-try-completion (string table pred point) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1233 (let ((suffix (substring string point)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1234 (completion (try-completion (substring string 0 point) table pred))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1235 (if (not (stringp completion)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1236 completion |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1237 ;; Merge a trailing / in completion with a / after point. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1238 ;; We used to only do it for word completion, but it seems to make |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1239 ;; sense for all completions. |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1240 ;; Actually, claiming this feature was part of Emacs-22 completion |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1241 ;; is pushing it a bit: it was only done in minibuffer-completion-word, |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1242 ;; which was (by default) not bound during file completion, where such |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1243 ;; slashes are most likely to occur. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1244 (if (and (not (zerop (length completion))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1245 (eq ?/ (aref completion (1- (length completion)))) |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1246 (not (zerop (length suffix))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1247 (eq ?/ (aref suffix 0))) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1248 ;; This leaves point after the / . |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1249 (setq suffix (substring suffix 1))) |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1250 (cons (concat completion suffix) (length completion))))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1251 |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1252 (defun completion-emacs22-all-completions (string table pred point) |
94464
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1253 (completion-hilit-commonality |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1254 (all-completions (substring string 0 point) table pred t) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1255 point)) |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1256 |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1257 (defun completion-basic-try-completion (string table pred point) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1258 (let ((suffix (substring string point)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1259 (completion (try-completion (substring string 0 point) table pred))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1260 (if (not (stringp completion)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1261 completion |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1262 ;; Merge end of completion with beginning of suffix. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1263 ;; Simple generalization of the "merge trailing /" done in Emacs-22. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1264 (when (and (not (zerop (length suffix))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1265 (string-match "\\(.+\\)\n\\1" (concat completion "\n" suffix) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1266 ;; Make sure we don't compress things to less |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1267 ;; than we started with. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1268 point) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1269 ;; Just make sure we didn't match some other \n. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1270 (eq (match-end 1) (length completion))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1271 (setq suffix (substring suffix (- (match-end 1) (match-beginning 1))))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1272 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1273 (cons (concat completion suffix) (length completion))))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1274 |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1275 (defalias 'completion-basic-all-completions 'completion-emacs22-all-completions) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1276 |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1277 ;;; Partial-completion-mode style completion. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1278 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1279 ;; BUGS: |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1280 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1281 ;; - "minibuffer-s- TAB" with minibuffer-selected-window ends up with |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1282 ;; "minibuffer--s-" which matches other options. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1283 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1284 (defvar completion-pcm--delim-wild-regex nil) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1285 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1286 (defun completion-pcm--prepare-delim-re (delims) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1287 (setq completion-pcm--delim-wild-regex (concat "[" delims "*]"))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1288 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1289 (defcustom completion-pcm-word-delimiters "-_. " |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1290 "A string of characters treated as word delimiters for completion. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1291 Some arcane rules: |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1292 If `]' is in this string, it must come first. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1293 If `^' is in this string, it must not come first. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1294 If `-' is in this string, it must come first or right after `]'. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1295 In other words, if S is this string, then `[S]' must be a valid Emacs regular |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1296 expression (not containing character ranges like `a-z')." |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1297 :set (lambda (symbol value) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1298 (set-default symbol value) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1299 ;; Refresh other vars. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1300 (completion-pcm--prepare-delim-re value)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1301 :initialize 'custom-initialize-reset |
94375
f8b940834bbb
(completion-pcm-word-delimiters): Add :group.
Juanma Barranquero <lekktu@gmail.com>
parents:
94352
diff
changeset
|
1302 :group 'minibuffer |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1303 :type 'string) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1304 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1305 (defun completion-pcm--pattern-trivial-p (pattern) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1306 (and (stringp (car pattern)) (null (cdr pattern)))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1307 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1308 (defun completion-pcm--string->pattern (string &optional point) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1309 "Split STRING into a pattern. |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1310 A pattern is a list where each element is either a string |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1311 or a symbol chosen among `any', `star', `point'." |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1312 (if (and point (< point (length string))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1313 (let ((prefix (substring string 0 point)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1314 (suffix (substring string point))) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1315 (append (completion-pcm--string->pattern prefix) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1316 '(point) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1317 (completion-pcm--string->pattern suffix))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1318 (let ((pattern nil) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1319 (p 0) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1320 (p0 0)) |
94375
f8b940834bbb
(completion-pcm-word-delimiters): Add :group.
Juanma Barranquero <lekktu@gmail.com>
parents:
94352
diff
changeset
|
1321 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1322 (while (setq p (string-match completion-pcm--delim-wild-regex string p)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1323 (push (substring string p0 p) pattern) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1324 (if (eq (aref string p) ?*) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1325 (progn |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1326 (push 'star pattern) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1327 (setq p0 (1+ p))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1328 (push 'any pattern) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1329 (setq p0 p)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1330 (incf p)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1331 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1332 ;; An empty string might be erroneously added at the beginning. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1333 ;; It should be avoided properly, but it's so easy to remove it here. |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1334 (delete "" (nreverse (cons (substring string p0) pattern)))))) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1335 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1336 (defun completion-pcm--pattern->regex (pattern &optional group) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1337 (let ((re |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1338 (concat "\\`" |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1339 (mapconcat |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1340 (lambda (x) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1341 (case x |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1342 ((star any point) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1343 (if (if (consp group) (memq x group) group) |
94465
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1344 "\\(.*?\\)" ".*?")) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1345 (t (regexp-quote x)))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1346 pattern |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1347 "")))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1348 ;; Avoid pathological backtracking. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1349 (while (string-match "\\.\\*\\?\\(?:\\\\[()]\\)*\\(\\.\\*\\?\\)" re) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1350 (setq re (replace-match "" t t re 1))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1351 re)) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1352 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1353 (defun completion-pcm--all-completions (prefix pattern table pred) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1354 "Find all completions for PATTERN in TABLE obeying PRED. |
94375
f8b940834bbb
(completion-pcm-word-delimiters): Add :group.
Juanma Barranquero <lekktu@gmail.com>
parents:
94352
diff
changeset
|
1355 PATTERN is as returned by `completion-pcm--string->pattern'." |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1356 ;; Find an initial list of possible completions. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1357 (if (completion-pcm--pattern-trivial-p pattern) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1358 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1359 ;; Minibuffer contains no delimiters -- simple case! |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1360 (let* ((all (all-completions (concat prefix (car pattern)) table pred)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1361 (last (last all))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1362 (if last (setcdr last nil)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1363 all) |
94375
f8b940834bbb
(completion-pcm-word-delimiters): Add :group.
Juanma Barranquero <lekktu@gmail.com>
parents:
94352
diff
changeset
|
1364 |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1365 ;; Use all-completions to do an initial cull. This is a big win, |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1366 ;; since all-completions is written in C! |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1367 (let* (;; Convert search pattern to a standard regular expression. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1368 (regex (completion-pcm--pattern->regex pattern)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1369 (completion-regexp-list (cons regex completion-regexp-list)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1370 (compl (all-completions |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1371 (concat prefix (if (stringp (car pattern)) (car pattern) "")) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1372 table pred)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1373 (last (last compl))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1374 (when last |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1375 (if (and (numberp (cdr last)) (/= (cdr last) (length prefix))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1376 (message "Inconsistent base-size returned by completion table %s" |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1377 table)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1378 (setcdr last nil)) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1379 (if (not (functionp table)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1380 ;; The internal functions already obeyed completion-regexp-list. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1381 compl |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1382 (let ((case-fold-search completion-ignore-case) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1383 (poss ())) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1384 (dolist (c compl) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1385 (when (string-match regex c) (push c poss))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1386 poss))))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1387 |
94465
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1388 (defun completion-pcm--hilit-commonality (pattern completions) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1389 (when completions |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1390 (let* ((re (completion-pcm--pattern->regex pattern '(point))) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1391 (last (last completions)) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1392 (base-size (cdr last))) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1393 ;; Remove base-size during mapcar, and add it back later. |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1394 (setcdr last nil) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1395 (nconc |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1396 (mapcar |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1397 (lambda (str) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1398 ;; Don't modify the string itself. |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1399 (setq str (copy-sequence str)) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1400 (unless (string-match re str) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1401 (error "Internal error: %s does not match %s" re str)) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1402 (let ((pos (or (match-beginning 1) (match-end 0)))) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1403 (put-text-property 0 pos |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1404 'font-lock-face 'completions-common-part |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1405 str) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1406 (if (> (length str) pos) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1407 (put-text-property pos (1+ pos) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1408 'font-lock-face 'completions-first-difference |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1409 str))) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1410 str) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1411 completions) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1412 base-size)))) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1413 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1414 (defun completion-pcm--find-all-completions (string table pred point) |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1415 (let* ((beforepoint (substring string 0 point)) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1416 (afterpoint (substring string point)) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1417 (bounds (completion-boundaries beforepoint table pred afterpoint)) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1418 (prefix (substring beforepoint 0 (car bounds))) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1419 (suffix (substring afterpoint (cdr bounds))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1420 firsterror) |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1421 (setq string (substring string (car bounds) (+ point (cdr bounds)))) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1422 (let* ((relpoint (- point (car bounds))) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1423 (pattern (completion-pcm--string->pattern string relpoint)) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1424 (all (condition-case err |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1425 (completion-pcm--all-completions prefix pattern table pred) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1426 (error (unless firsterror (setq firsterror err)) nil)))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1427 (when (and (null all) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1428 (> (car bounds) 0) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1429 (null (ignore-errors (try-completion prefix table pred)))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1430 ;; The prefix has no completions at all, so we should try and fix |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1431 ;; that first. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1432 (let ((substring (substring prefix 0 -1))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1433 (destructuring-bind (subpat suball subprefix subsuffix) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1434 (completion-pcm--find-all-completions |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1435 substring table pred (length substring)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1436 (let ((sep (aref prefix (1- (length prefix)))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1437 ;; Text that goes between the new submatches and the |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1438 ;; completion substring. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1439 (between nil)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1440 ;; Eliminate submatches that don't end with the separator. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1441 (dolist (submatch (prog1 suball (setq suball ()))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1442 (when (eq sep (aref submatch (1- (length submatch)))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1443 (push submatch suball))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1444 (when suball |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1445 ;; Update the boundaries and corresponding pattern. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1446 ;; We assume that all submatches result in the same boundaries |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1447 ;; since we wouldn't know how to merge them otherwise anyway. |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1448 ;; FIXME: COMPLETE REWRITE!!! |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1449 (let* ((newbeforepoint |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1450 (concat subprefix (car suball) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1451 (substring string 0 relpoint))) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1452 (leftbound (+ (length subprefix) (length (car suball)))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1453 (newbounds (completion-boundaries |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1454 newbeforepoint table pred afterpoint))) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1455 (unless (or (and (eq (cdr bounds) (cdr newbounds)) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1456 (eq (car newbounds) leftbound)) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1457 ;; Refuse new boundaries if they step over |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1458 ;; the submatch. |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1459 (< (car newbounds) leftbound)) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1460 ;; The new completed prefix does change the boundaries |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1461 ;; of the completed substring. |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1462 (setq suffix (substring afterpoint (cdr newbounds))) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1463 (setq string |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1464 (concat (substring newbeforepoint (car newbounds)) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1465 (substring afterpoint 0 (cdr newbounds)))) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1466 (setq between (substring newbeforepoint leftbound |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1467 (car newbounds))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1468 (setq pattern (completion-pcm--string->pattern |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1469 string |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1470 (- (length newbeforepoint) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1471 (car newbounds))))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1472 (dolist (submatch suball) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1473 (setq all (nconc (mapcar |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1474 (lambda (s) (concat submatch between s)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1475 (completion-pcm--all-completions |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1476 (concat subprefix submatch between) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1477 pattern table pred)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1478 all))) |
95192
042486c3318c
(completion-pcm--find-all-completions): Don't add pseudo-completions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95172
diff
changeset
|
1479 ;; FIXME: This can come in handy for try-completion, |
042486c3318c
(completion-pcm--find-all-completions): Don't add pseudo-completions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95172
diff
changeset
|
1480 ;; but isn't right for all-completions, since it lists |
042486c3318c
(completion-pcm--find-all-completions): Don't add pseudo-completions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95172
diff
changeset
|
1481 ;; invalid completions. |
042486c3318c
(completion-pcm--find-all-completions): Don't add pseudo-completions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95172
diff
changeset
|
1482 ;; (unless all |
042486c3318c
(completion-pcm--find-all-completions): Don't add pseudo-completions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95172
diff
changeset
|
1483 ;; ;; Even though we found expansions in the prefix, none |
042486c3318c
(completion-pcm--find-all-completions): Don't add pseudo-completions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95172
diff
changeset
|
1484 ;; ;; leads to a valid completion. |
042486c3318c
(completion-pcm--find-all-completions): Don't add pseudo-completions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95172
diff
changeset
|
1485 ;; ;; Let's keep the expansions, tho. |
042486c3318c
(completion-pcm--find-all-completions): Don't add pseudo-completions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95172
diff
changeset
|
1486 ;; (dolist (submatch suball) |
042486c3318c
(completion-pcm--find-all-completions): Don't add pseudo-completions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95172
diff
changeset
|
1487 ;; (push (concat submatch between newsubstring) all))) |
042486c3318c
(completion-pcm--find-all-completions): Don't add pseudo-completions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95172
diff
changeset
|
1488 )) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1489 (setq pattern (append subpat (list 'any (string sep)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1490 (if between (list between)) pattern)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1491 (setq prefix subprefix))))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1492 (if (and (null all) firsterror) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1493 (signal (car firsterror) (cdr firsterror)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1494 (list pattern all prefix suffix))))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1495 |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1496 (defun completion-pcm-all-completions (string table pred point) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1497 (destructuring-bind (pattern all &optional prefix suffix) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1498 (completion-pcm--find-all-completions string table pred point) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1499 (completion-pcm--hilit-commonality pattern all))) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1500 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1501 (defun completion-pcm--merge-completions (strs pattern) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1502 "Extract the commonality in STRS, with the help of PATTERN." |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1503 (cond |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1504 ((null (cdr strs)) (list (car strs))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1505 (t |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1506 (let ((re (completion-pcm--pattern->regex pattern 'group)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1507 (ccs ())) ;Chopped completions. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1508 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1509 ;; First chop each string into the parts corresponding to each |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1510 ;; non-constant element of `pattern', using regexp-matching. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1511 (let ((case-fold-search completion-ignore-case)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1512 (dolist (str strs) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1513 (unless (string-match re str) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1514 (error "Internal error: %s doesn't match %s" str re)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1515 (let ((chopped ()) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1516 (i 1)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1517 (while (match-beginning i) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1518 (push (match-string i str) chopped) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1519 (setq i (1+ i))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1520 ;; Add the text corresponding to the implicit trailing `any'. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1521 (push (substring str (match-end 0)) chopped) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1522 (push (nreverse chopped) ccs)))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1523 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1524 ;; Then for each of those non-constant elements, extract the |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1525 ;; commonality between them. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1526 (let ((res ())) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1527 ;; Make the implicit `any' explicit. We could make it explicit |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1528 ;; everywhere, but it would slow down regexp-matching a little bit. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1529 (dolist (elem (append pattern '(any))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1530 (if (stringp elem) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1531 (push elem res) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1532 (let ((comps ())) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1533 (dolist (cc (prog1 ccs (setq ccs nil))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1534 (push (car cc) comps) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1535 (push (cdr cc) ccs)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1536 (let* ((prefix (try-completion "" comps)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1537 (unique (or (and (eq prefix t) (setq prefix "")) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1538 (eq t (try-completion prefix comps))))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1539 (unless (equal prefix "") (push prefix res)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1540 ;; If there's only one completion, `elem' is not useful |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1541 ;; any more: it can only match the empty string. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1542 ;; FIXME: in some cases, it may be necessary to turn an |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1543 ;; `any' into a `star' because the surrounding context has |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1544 ;; changed such that string->pattern wouldn't add an `any' |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1545 ;; here any more. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1546 (unless unique (push elem res)))))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1547 ;; We return it in reverse order. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1548 res))))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1549 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1550 (defun completion-pcm--pattern->string (pattern) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1551 (mapconcat (lambda (x) (cond |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1552 ((stringp x) x) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1553 ((eq x 'star) "*") |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1554 ((eq x 'any) "") |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1555 ((eq x 'point) ""))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1556 pattern |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1557 "")) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1558 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1559 (defun completion-pcm-try-completion (string table pred point) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1560 (destructuring-bind (pattern all prefix suffix) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1561 (completion-pcm--find-all-completions string table pred point) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1562 (when all |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1563 (let* ((mergedpat (completion-pcm--merge-completions all pattern)) |
94486
ca90422b8114
(completion--do-completion): Move point even if the completion makes no change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94465
diff
changeset
|
1564 ;; `mergedpat' is in reverse order. Place new point (by |
ca90422b8114
(completion--do-completion): Move point even if the completion makes no change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94465
diff
changeset
|
1565 ;; order of preference) either at the old point, or at |
ca90422b8114
(completion--do-completion): Move point even if the completion makes no change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94465
diff
changeset
|
1566 ;; the last place where there's something to choose, or |
ca90422b8114
(completion--do-completion): Move point even if the completion makes no change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94465
diff
changeset
|
1567 ;; at the very end. |
ca90422b8114
(completion--do-completion): Move point even if the completion makes no change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94465
diff
changeset
|
1568 (pointpat (or (memq 'point mergedpat) (memq 'any mergedpat) |
94487
432e68e359fa
(completion-pcm-try-completion): Typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94486
diff
changeset
|
1569 mergedpat)) |
94486
ca90422b8114
(completion--do-completion): Move point even if the completion makes no change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94465
diff
changeset
|
1570 ;; New pos from the start. |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1571 (newpos (length (completion-pcm--pattern->string pointpat))) |
94486
ca90422b8114
(completion--do-completion): Move point even if the completion makes no change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94465
diff
changeset
|
1572 ;; Do it afterwards because it changes `pointpat' by sideeffect. |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1573 (merged (completion-pcm--pattern->string (nreverse mergedpat)))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1574 (if (and (> (length merged) 0) (> (length suffix) 0) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1575 (eq (aref merged (1- (length merged))) (aref suffix 0))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1576 (setq suffix (substring suffix 1))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1577 (cons (concat prefix merged suffix) (+ newpos (length prefix))))))) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1578 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1579 |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1580 (provide 'minibuffer) |
94144 | 1581 |
1582 ;; arch-tag: ef8a0a15-1080-4790-a754-04017c02f08f | |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1583 ;;; minibuffer.el ends here |