Mercurial > emacs
annotate lisp/minibuffer.el @ 111498:d9d916379aff
* lisp/progmodes/modula2.el: Use SMIE and skeleton.
(m2-mode-syntax-table): (*..*) can be nested.
Add //...\n. Fix paren syntax.
(m2-mode-map): Remove LF and TAB bindings.
(m2-indent): Add safety property.
(m2-smie-grammar): New var.
(m2-smie-refine-colon, m2-smie-refine-of, m2-smie-backward-token)
(m2-smie-forward-token, m2-smie-refine-semi, m2-smie-rules): New funs.
(m2-mode): Use define-derived-mode.
(m2-newline, m2-tab): Remove.
(m2-begin, m2-case, m2-definition, m2-else, m2-for, m2-header)
(m2-if, m2-loop, m2-module, m2-or, m2-procedure, m2-with, m2-record)
(m2-stdio, m2-type, m2-until, m2-var, m2-while, m2-export)
(m2-import): Use define-skeleton.
* test/indent/modula2.mod: New file.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 11 Nov 2010 16:06:15 -0500 |
parents | 132f2dfd549f |
children | 4ed7d6375e3b |
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 |
106815 | 3 ;; Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. |
93885
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> |
110015
280c8ae2476d
Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents:
109044
diff
changeset
|
6 ;; Package: emacs |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
7 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
9 |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94607
diff
changeset
|
10 ;; 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
|
11 ;; 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
|
12 ;; 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
|
13 ;; (at your option) any later version. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
14 |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94607
diff
changeset
|
15 ;; 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
|
16 ;; 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
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
18 ;; GNU General Public License for more details. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
19 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
20 ;; 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
|
21 ;; 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
|
22 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
23 ;;; Commentary: |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
24 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
25 ;; 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
|
26 ;; internal use only. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
27 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
28 ;; Functional completion tables have an extended calling conventions: |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
29 ;; - 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
|
30 ;; (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
|
31 ;; (boundaries START . END). See `completion-boundaries'. |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
32 ;; 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
|
33 ;; 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
|
34 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
35 ;;; Bugs: |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
36 |
95799
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
37 ;; - completion-all-sorted-completions list all the completions, whereas |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
38 ;; it should only lists the ones that `try-completion' would consider. |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
39 ;; E.g. it should honor completion-ignored-extensions. |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
40 ;; - choose-completion can't automatically figure out the boundaries |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
41 ;; corresponding to the displayed completions because we only |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
42 ;; provide the start info but not the end info in |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
43 ;; completion-base-position. |
105763
5041ae86859e
(all-completions): Declare the 4th arg obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105733
diff
changeset
|
44 ;; - quoting is problematic. E.g. the double-dollar quoting used in |
111386
93e249d6d27c
* lisp/minibuffer.el (minibuffer-completion-help): Specify the end of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111041
diff
changeset
|
45 ;; substitute-in-file-name (and hence read-file-name-internal) bumps |
105763
5041ae86859e
(all-completions): Declare the 4th arg obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105733
diff
changeset
|
46 ;; into various bugs: |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
47 ;; - choose-completion doesn't know how to quote the text it inserts. |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
48 ;; E.g. it fails to double the dollars in file-name completion, or |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
49 ;; to backslash-escape spaces and other chars in comint completion. |
105763
5041ae86859e
(all-completions): Declare the 4th arg obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105733
diff
changeset
|
50 ;; - when completing ~/tmp/fo$$o, the highligting in *Completions* |
5041ae86859e
(all-completions): Declare the 4th arg obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105733
diff
changeset
|
51 ;; is off by one position. |
5041ae86859e
(all-completions): Declare the 4th arg obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105733
diff
changeset
|
52 ;; - all code like PCM which relies on all-completions to match |
5041ae86859e
(all-completions): Declare the 4th arg obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105733
diff
changeset
|
53 ;; its argument gets confused because all-completions returns unquoted |
5041ae86859e
(all-completions): Declare the 4th arg obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105733
diff
changeset
|
54 ;; texts (as desired for *Completions* output). |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
55 ;; - C-x C-f ~/*/sr ? should not list "~/./src". |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
56 ;; - minibuffer-force-complete completes ~/src/emacs/t<!>/lisp/minibuffer.el |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
57 ;; to ~/src/emacs/trunk/ and throws away lisp/minibuffer.el. |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
58 |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
59 ;;; Todo: |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
60 |
106453
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
61 ;; - extend `boundaries' to provide various other meta-data about the |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
62 ;; output of `all-completions': |
107250
13dafa175b9c
Fix in-buffer completion when after-change-functions modify the buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107089
diff
changeset
|
63 ;; - preferred sorting order when displayed in *Completions*. |
13dafa175b9c
Fix in-buffer completion when after-change-functions modify the buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107089
diff
changeset
|
64 ;; - annotations/text-properties to add when displayed in *Completions*. |
106453
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
65 ;; - quoting/unquoting (so we can complete files names with envvars |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
66 ;; and backslashes, and all-completion can list names without |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
67 ;; quoting backslashes and dollars). |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
68 ;; - indicate how to turn all-completion's output into |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
69 ;; try-completion's output: e.g. completion-ignored-extensions. |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
70 ;; maybe that could be merged with the "quote" operation above. |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
71 ;; - completion hook to run when the completion is |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
72 ;; selected/inserted (maybe this should be provided some other |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
73 ;; way, e.g. as text-property, so `try-completion can also return it?) |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
74 ;; both for when it's inserted via TAB or via choose-completion. |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
75 ;; - indicate that `all-completions' doesn't do prefix-completion |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
76 ;; but just returns some list that relates in some other way to |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
77 ;; the provided string (as is the case in filecache.el), in which |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
78 ;; case partial-completion (for example) doesn't make any sense |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
79 ;; and neither does the completions-first-difference highlight. |
108500
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
80 ;; - indicate how to display the completions in *Completions* (turn |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
81 ;; \n into something else, add special boundaries between |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
82 ;; completions). E.g. when completing from the kill-ring. |
106453
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
83 |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
84 ;; - make partial-completion-mode obsolete: |
104719
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
85 ;; - (?) <foo.h> style completion for file names. |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
86 ;; This can't be done identically just by tweaking completion, |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
87 ;; because partial-completion-mode's behavior is to expand <string.h> |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
88 ;; to /usr/include/string.h only when exiting the minibuffer, at which |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
89 ;; point the completion code is actually not involved normally. |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
90 ;; Partial-completion-mode does it via a find-file-not-found-function. |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
91 ;; - special code for C-x C-f <> to visit the file ref'd at point |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
92 ;; via (require 'foo) or #include "foo". ffap seems like a better |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
93 ;; place for this feature (supplemented with major-mode-provided |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
94 ;; functions to find the file ref'd at point). |
104719
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
95 |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
96 ;; - case-sensitivity currently confuses two issues: |
104719
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
97 ;; - whether or not a particular completion table should be case-sensitive |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
98 ;; (i.e. whether strings that differ only by case are semantically |
104719
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
99 ;; equivalent) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
100 ;; - whether the user wants completion to pay attention to case. |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
101 ;; e.g. we may want to make it possible for the user to say "first try |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
102 ;; completion case-sensitively, and if that fails, try to ignore case". |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
103 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
104 ;; - add support for ** to pcm. |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
105 ;; - 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
|
106 ;; - A feature like completing-help.el. |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
107 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
108 ;;; Code: |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
109 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
110 (eval-when-compile (require 'cl)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
111 |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
112 ;;; Completion table manipulation |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
113 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
114 ;; New completion-table operation. |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
115 (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
|
116 "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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 in SUFFIX of the end of the completion field. |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
122 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
|
123 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
|
124 the closest directory separators." |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
125 (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
|
126 (funcall table string pred (cons 'boundaries suffix))))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
127 (if (not (eq (car-safe boundaries) 'boundaries)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
128 (setq boundaries nil)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
129 (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
|
130 (or (cddr boundaries) (length suffix))))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
131 |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
132 (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
|
133 "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
|
134 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
|
135 Like CL's `some'." |
110842
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
136 (lexical-let ((firsterror nil) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
137 res) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
138 (while (and (not res) xs) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
139 (condition-case err |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
140 (setq res (funcall fun (pop xs))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
141 (error (unless firsterror (setq firsterror err)) nil))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
142 (or res |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
143 (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
|
144 |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
145 (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
|
146 "Perform completion ACTION. |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
147 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
|
148 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
|
149 PRED is a completion predicate. |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
150 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
|
151 (cond |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
152 ((functionp table) (funcall table string pred action)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
153 ((eq (car-safe action) 'boundaries) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
154 (cons 'boundaries (completion-boundaries string table pred (cdr action)))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
155 (t |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
156 (funcall |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
157 (cond |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
158 ((null action) 'try-completion) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
159 ((eq action t) 'all-completions) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
160 (t 'test-completion)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
161 string table pred)))) |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
162 |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
163 (defun completion-table-dynamic (fun) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
164 "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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 |
97550
dc32b170fe16
(completion-table-dynamic): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
97544
diff
changeset
|
171 The result of the `completion-table-dynamic' form is a function |
95426
92edde3e7af6
(completion-table-dynamic): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
95394
diff
changeset
|
172 that can be used as the COLLECTION argument to `try-completion' and |
94202
987535788e11
(completion-table-dynamic): Fix typo, and reflow docstring.
Juanma Barranquero <lekktu@gmail.com>
parents:
94182
diff
changeset
|
173 `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
|
174 (lexical-let ((fun fun)) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
175 (lambda (string pred action) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
176 (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
|
177 (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
|
178 (current-buffer))) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
179 (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
|
180 |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
181 (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
|
182 "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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 `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
|
189 |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
190 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
|
191 (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
|
192 (let ((str (make-symbol "string"))) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
193 `(completion-table-dynamic |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
194 (lambda (,str) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
195 (when (functionp ,var) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
196 (setq ,var (,fun))) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
197 ,var)))) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
198 |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
199 (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
|
200 ;; TODO: add `suffix' maybe? |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
201 ;; 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
|
202 (when (functionp pred) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
203 (setq pred |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
204 (lexical-let ((pred pred)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
205 ;; 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
|
206 ;; the completion table :-( |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
207 (cond |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
208 ((vectorp table) ;Obarray. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
209 (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
|
210 ((hash-table-p table) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
211 (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
|
212 ((functionp table) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
213 (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
|
214 (t ;Lists and alists. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
215 (lambda (s) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
216 (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
|
217 (if (eq (car-safe action) 'boundaries) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
218 (let* ((len (length prefix)) |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
219 (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
|
220 (list* 'boundaries (+ (car bound) len) (cdr bound))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
221 (let ((comp (complete-with-action action table string pred))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
222 (cond |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
223 ;; In case of try-completion, add the prefix. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
224 ((stringp comp) (concat prefix comp)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
225 (t comp))))) |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
226 |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
227 (defun completion-table-with-terminator (terminator table string pred action) |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
228 "Construct a completion table like TABLE but with an extra TERMINATOR. |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
229 This is meant to be called in a curried way by first passing TERMINATOR |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
230 and TABLE only (via `apply-partially'). |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
231 TABLE is a completion table, and TERMINATOR is a string appended to TABLE's |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
232 completion if it is complete. TERMINATOR is also used to determine the |
105711
834e4fdbe74a
(completion-table-with-terminator): Allow to specify the terminator-regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105697
diff
changeset
|
233 completion suffix's boundary. |
834e4fdbe74a
(completion-table-with-terminator): Allow to specify the terminator-regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105697
diff
changeset
|
234 TERMINATOR can also be a cons cell (TERMINATOR . TERMINATOR-REGEXP) |
834e4fdbe74a
(completion-table-with-terminator): Allow to specify the terminator-regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105697
diff
changeset
|
235 in which case TERMINATOR-REGEXP is a regular expression whose submatch |
834e4fdbe74a
(completion-table-with-terminator): Allow to specify the terminator-regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105697
diff
changeset
|
236 number 1 should match TERMINATOR. This is used when there is a need to |
834e4fdbe74a
(completion-table-with-terminator): Allow to specify the terminator-regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105697
diff
changeset
|
237 distinguish occurrences of the TERMINATOR strings which are really terminators |
834e4fdbe74a
(completion-table-with-terminator): Allow to specify the terminator-regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105697
diff
changeset
|
238 from others (e.g. escaped)." |
94180
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
239 (cond |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
240 ((eq (car-safe action) 'boundaries) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
241 (let* ((suffix (cdr action)) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
242 (bounds (completion-boundaries string table pred suffix)) |
105711
834e4fdbe74a
(completion-table-with-terminator): Allow to specify the terminator-regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105697
diff
changeset
|
243 (terminator-regexp (if (consp terminator) |
834e4fdbe74a
(completion-table-with-terminator): Allow to specify the terminator-regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105697
diff
changeset
|
244 (cdr terminator) (regexp-quote terminator))) |
834e4fdbe74a
(completion-table-with-terminator): Allow to specify the terminator-regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105697
diff
changeset
|
245 (max (string-match terminator-regexp suffix))) |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
246 (list* 'boundaries (car bounds) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
247 (min (cdr bounds) (or max (length suffix)))))) |
94180
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
248 ((eq action nil) |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
249 (let ((comp (try-completion string table pred))) |
105711
834e4fdbe74a
(completion-table-with-terminator): Allow to specify the terminator-regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105697
diff
changeset
|
250 (if (consp terminator) (setq terminator (car terminator))) |
94077
28e2f73174d6
(completion-table-with-terminator): Those completions
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94069
diff
changeset
|
251 (if (eq comp t) |
28e2f73174d6
(completion-table-with-terminator): Those completions
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94069
diff
changeset
|
252 (concat string terminator) |
28e2f73174d6
(completion-table-with-terminator): Those completions
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94069
diff
changeset
|
253 (if (and (stringp comp) |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
254 ;; FIXME: Try to avoid this second call, especially since |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
255 ;; it may be very inefficient (because `comp' made us |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
256 ;; jump to a new boundary, so we complete in that |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
257 ;; boundary with an empty start string). |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
258 ;; completion-boundaries might help. |
94180
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
259 (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
|
260 (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
|
261 comp)))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
262 ((eq action t) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
263 ;; 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
|
264 ;; 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
|
265 ;; 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
|
266 ;; good in *Completions*. |
100623
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
267 ;; (mapcar (lambda (s) (concat s terminator)) |
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
268 ;; (all-completions string table pred)))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
269 (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
|
270 ;; 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
|
271 ;; "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
|
272 ;; 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
|
273 ((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
|
274 |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
275 (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
|
276 "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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 (cond |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
285 ((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
|
286 ;; 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
|
287 (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
|
288 (t |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
289 (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
|
290 (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
|
291 (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
|
292 (lambda (x) |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
293 ;; 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
|
294 ;; 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
|
295 (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
|
296 ;; 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
|
297 ;; again without pred1. |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
298 (and (not strict) |
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
299 (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
|
300 |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
301 (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
|
302 "Create a completion table that tries each table in TABLES in turn." |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
303 ;; FIXME: the boundaries may come from TABLE1 even when the completion list |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
304 ;; is returned by TABLE2 (because TABLE1 returned an empty list). |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
305 (lexical-let ((tables tables)) |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
306 (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
|
307 (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
|
308 (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
|
309 tables)))) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
310 |
94180
114d8f4904d0
* minibuffer.el (completion-table-with-context): Add support for `pred'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94172
diff
changeset
|
311 ;; (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
|
312 ;; (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
|
313 (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
|
314 '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
|
315 (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
|
316 '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
|
317 |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
318 ;;; Minibuffer completion |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
319 |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
320 (defgroup minibuffer nil |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
321 "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
|
322 :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
|
323 :group 'environment) |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
324 |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
325 (defun minibuffer-message (message &rest args) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
326 "Temporarily display MESSAGE at the end of the minibuffer. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
327 The text is displayed for `minibuffer-message-timeout' seconds, |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
328 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
|
329 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
|
330 If ARGS are provided, then pass MESSAGE through `format'." |
104719
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
331 (if (not (minibufferp (current-buffer))) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
332 (progn |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
333 (if args |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
334 (apply 'message message args) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
335 (message "%s" message)) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
336 (prog1 (sit-for (or minibuffer-message-timeout 1000000)) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
337 (message nil))) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
338 ;; Clear out any old echo-area message to make way for our new thing. |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
339 (message nil) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
340 (setq message (if (and (null args) (string-match-p "\\` *\\[.+\\]\\'" message)) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
341 ;; Make sure we can put-text-property. |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
342 (copy-sequence message) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
343 (concat " [" message "]"))) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
344 (when args (setq message (apply 'format message args))) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
345 (let ((ol (make-overlay (point-max) (point-max) nil t t)) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
346 ;; A quit during sit-for normally only interrupts the sit-for, |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
347 ;; but since minibuffer-message is used at the end of a command, |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
348 ;; at a time when the command has virtually finished already, a C-g |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
349 ;; should really cause an abort-recursive-edit instead (i.e. as if |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
350 ;; the C-g had been typed at top-level). Binding inhibit-quit here |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
351 ;; is an attempt to get that behavior. |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
352 (inhibit-quit t)) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
353 (unwind-protect |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
354 (progn |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
355 (unless (zerop (length message)) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
356 ;; The current C cursor code doesn't know to use the overlay's |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
357 ;; marker's stickiness to figure out whether to place the cursor |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
358 ;; before or after the string, so let's spoon-feed it the pos. |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
359 (put-text-property 0 1 'cursor t message)) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
360 (overlay-put ol 'after-string message) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
361 (sit-for (or minibuffer-message-timeout 1000000))) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
362 (delete-overlay ol))))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
363 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
364 (defun minibuffer-completion-contents () |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
365 "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
|
366 That is what completion commands operate on." |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
367 (buffer-substring (field-beginning) (point))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
368 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
369 (defun delete-minibuffer-contents () |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
370 "Delete all user input in a minibuffer. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
371 If the current buffer is not a minibuffer, erase its entire contents." |
99232
63548ee8ae9f
(delete-minibuffer-contents): Delete all minibuffer contents instead
Chong Yidong <cyd@stupidchicken.com>
parents:
98907
diff
changeset
|
372 ;; We used to do `delete-field' here, but when file name shadowing |
63548ee8ae9f
(delete-minibuffer-contents): Delete all minibuffer contents instead
Chong Yidong <cyd@stupidchicken.com>
parents:
98907
diff
changeset
|
373 ;; is on, the field doesn't cover the entire minibuffer contents. |
63548ee8ae9f
(delete-minibuffer-contents): Delete all minibuffer contents instead
Chong Yidong <cyd@stupidchicken.com>
parents:
98907
diff
changeset
|
374 (delete-region (minibuffer-prompt-end) (point-max))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
375 |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
376 (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
|
377 "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
|
378 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
|
379 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
|
380 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
|
381 the second failed attempt to complete." |
93942
187008494f10
(completion-auto-help): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents:
93937
diff
changeset
|
382 :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
|
383 :group 'minibuffer) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
384 |
105950
e411fa8e0abf
* progmodes/grep.el (grep-regexp-alist):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105930
diff
changeset
|
385 (defconst completion-styles-alist |
104785
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
386 '((emacs21 |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
387 completion-emacs21-try-completion completion-emacs21-all-completions |
107977
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
388 "Simple prefix-based completion. |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
389 I.e. when completing \"foo_bar\" (where _ is the position of point), |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
390 it will consider all completions candidates matching the glob |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
391 pattern \"foobar*\".") |
104785
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
392 (emacs22 |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
393 completion-emacs22-try-completion completion-emacs22-all-completions |
107977
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
394 "Prefix completion that only operates on the text before point. |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
395 I.e. when completing \"foo_bar\" (where _ is the position of point), |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
396 it will consider all completions candidates matching the glob |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
397 pattern \"foo*\" and will add back \"bar\" to the end of it.") |
104785
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
398 (basic |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
399 completion-basic-try-completion completion-basic-all-completions |
107977
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
400 "Completion of the prefix before point and the suffix after point. |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
401 I.e. when completing \"foo_bar\" (where _ is the position of point), |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
402 it will consider all completions candidates matching the glob |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
403 pattern \"foo*bar*\".") |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
404 (partial-completion |
104785
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
405 completion-pcm-try-completion completion-pcm-all-completions |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
406 "Completion of multiple words, each one taken as a prefix. |
107977
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
407 I.e. when completing \"l-co_h\" (where _ is the position of point), |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
408 it will consider all completions candidates matching the glob |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
409 pattern \"l*-co*h*\". |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
410 Furthermore, for completions that are done step by step in subfields, |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
411 the method is applied to all the preceding fields that do not yet match. |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
412 E.g. C-x C-f /u/mo/s TAB could complete to /usr/monnier/src. |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
413 Additionally the user can use the char \"*\" as a glob pattern.") |
107983
781bff25a517
(completion-styles-alist): Fix up last merge and document `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107978
diff
changeset
|
414 (substring |
781bff25a517
(completion-styles-alist): Fix up last merge and document `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107978
diff
changeset
|
415 completion-substring-try-completion completion-substring-all-completions |
781bff25a517
(completion-styles-alist): Fix up last merge and document `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107978
diff
changeset
|
416 "Completion of the string taken as a substring. |
781bff25a517
(completion-styles-alist): Fix up last merge and document `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107978
diff
changeset
|
417 I.e. when completing \"foo_bar\" (where _ is the position of point), |
781bff25a517
(completion-styles-alist): Fix up last merge and document `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107978
diff
changeset
|
418 it will consider all completions candidates matching the glob |
781bff25a517
(completion-styles-alist): Fix up last merge and document `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107978
diff
changeset
|
419 pattern \"*foo*bar*\".") |
104785
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
420 (initials |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
421 completion-initials-try-completion completion-initials-all-completions |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
422 "Completion of acronyms and initialisms. |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
423 E.g. can complete M-x lch to list-command-history |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
424 and C-x C-f ~/sew to ~/src/emacs/work.")) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
425 "List of available completion styles. |
104785
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
426 Each element has the form (NAME TRY-COMPLETION ALL-COMPLETIONS DOC): |
94375
f8b940834bbb
(completion-pcm-word-delimiters): Add :group.
Juanma Barranquero <lekktu@gmail.com>
parents:
94352
diff
changeset
|
427 where NAME is the name that should be used in `completion-styles', |
104785
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
428 TRY-COMPLETION is the function that does the completion (it should |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
429 follow the same calling convention as `completion-try-completion'), |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
430 ALL-COMPLETIONS is the function that lists the completions (it should |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
431 follow the calling convention of `completion-all-completions'), |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
432 and DOC describes the way this style of completion works.") |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
433 |
107977
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
434 (defcustom completion-styles |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
435 ;; First, use `basic' because prefix completion has been the standard |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
436 ;; for "ever" and works well in most cases, so using it first |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
437 ;; ensures that we obey previous behavior in most cases. |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
438 '(basic |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
439 ;; Then use `partial-completion' because it has proven to |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
440 ;; be a very convenient extension. |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
441 partial-completion |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
442 ;; Finally use `emacs22' so as to maintain (in many/most cases) |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
443 ;; the previous behavior that when completing "foobar" with point |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
444 ;; between "foo" and "bar" the completion try to complete "foo" |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
445 ;; and simply add "bar" to the end of the result. |
17966fd41dcf
(completion-styles): Improve docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107517
diff
changeset
|
446 emacs22) |
104342
867af630a71e
(completion--do-completion): Move point for the #b001 case as well (bug#4176).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104122
diff
changeset
|
447 "List of completion styles to use. |
867af630a71e
(completion--do-completion): Move point for the #b001 case as well (bug#4176).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104122
diff
changeset
|
448 The available styles are listed in `completion-styles-alist'." |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
449 :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
|
450 completion-styles-alist))) |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
451 :group 'minibuffer |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
452 :version "23.1") |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
453 |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
454 (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
|
455 "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
|
456 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
|
457 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
|
458 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
|
459 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
|
460 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
|
461 a new position for point." |
104785
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
462 (completion--some (lambda (style) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
463 (funcall (nth 1 (assq style completion-styles-alist)) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
464 string table pred point)) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
465 completion-styles)) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
466 |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
467 (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
|
468 "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
|
469 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
|
470 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
|
471 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
|
472 in the last `cdr'." |
106453
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
473 ;; FIXME: We need to additionally return the info needed for the |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
474 ;; second part of completion-base-position. |
104785
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
475 (completion--some (lambda (style) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
476 (funcall (nth 2 (assq style completion-styles-alist)) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
477 string table pred point)) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
478 completion-styles)) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
479 |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
480 (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
|
481 (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
|
482 (if completions 2 0) |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
483 (if exact 1 0))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
484 |
107250
13dafa175b9c
Fix in-buffer completion when after-change-functions modify the buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107089
diff
changeset
|
485 (defun completion--replace (beg end newtext) |
13dafa175b9c
Fix in-buffer completion when after-change-functions modify the buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107089
diff
changeset
|
486 "Replace the buffer text between BEG and END with NEWTEXT. |
13dafa175b9c
Fix in-buffer completion when after-change-functions modify the buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107089
diff
changeset
|
487 Moves point to the end of the new text." |
110832
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
488 ;; Maybe this should be in subr.el. |
107250
13dafa175b9c
Fix in-buffer completion when after-change-functions modify the buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107089
diff
changeset
|
489 ;; You'd think this is trivial to do, but details matter if you want |
13dafa175b9c
Fix in-buffer completion when after-change-functions modify the buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107089
diff
changeset
|
490 ;; to keep markers "at the right place" and be robust in the face of |
13dafa175b9c
Fix in-buffer completion when after-change-functions modify the buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107089
diff
changeset
|
491 ;; after-change-functions that may themselves modify the buffer. |
110832
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
492 (let ((prefix-len 0)) |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
493 ;; Don't touch markers in the shared prefix (if any). |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
494 (while (and (< prefix-len (length newtext)) |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
495 (< (+ beg prefix-len) end) |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
496 (eq (char-after (+ beg prefix-len)) |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
497 (aref newtext prefix-len))) |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
498 (setq prefix-len (1+ prefix-len))) |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
499 (unless (zerop prefix-len) |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
500 (setq beg (+ beg prefix-len)) |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
501 (setq newtext (substring newtext prefix-len)))) |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
502 (let ((suffix-len 0)) |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
503 ;; Don't touch markers in the shared suffix (if any). |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
504 (while (and (< suffix-len (length newtext)) |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
505 (< beg (- end suffix-len)) |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
506 (eq (char-before (- end suffix-len)) |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
507 (aref newtext (- (length newtext) suffix-len 1)))) |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
508 (setq suffix-len (1+ suffix-len))) |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
509 (unless (zerop suffix-len) |
0eedefa853ee
* lisp/minibuffer.el (completion--replace): Better preserve markers.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108320
diff
changeset
|
510 (setq end (- end suffix-len)) |
111041
41b4a4c75ab9
* lisp/minibuffer.el (completion--replace): Move point where it belongs
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110842
diff
changeset
|
511 (setq newtext (substring newtext 0 (- suffix-len)))) |
41b4a4c75ab9
* lisp/minibuffer.el (completion--replace): Move point where it belongs
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110842
diff
changeset
|
512 (goto-char beg) |
41b4a4c75ab9
* lisp/minibuffer.el (completion--replace): Move point where it belongs
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110842
diff
changeset
|
513 (insert newtext) |
41b4a4c75ab9
* lisp/minibuffer.el (completion--replace): Move point where it belongs
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110842
diff
changeset
|
514 (delete-region (point) (+ (point) (- end beg))) |
41b4a4c75ab9
* lisp/minibuffer.el (completion--replace): Move point where it belongs
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110842
diff
changeset
|
515 (forward-char suffix-len))) |
107250
13dafa175b9c
Fix in-buffer completion when after-change-functions modify the buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107089
diff
changeset
|
516 |
108500
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
517 (defcustom completion-cycle-threshold nil |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
518 "Number of completion candidates below which cycling is used. |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
519 Depending on this setting `minibuffer-complete' may use cycling, |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
520 like `minibuffer-force-complete'. |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
521 If nil, cycling is never used. |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
522 If t, cycling is always used. |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
523 If an integer, cycling is used as soon as there are fewer completion |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
524 candidates than this number." |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
525 :type '(choice (const :tag "No cycling" nil) |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
526 (const :tag "Always cycle" t) |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
527 (integer :tag "Threshold"))) |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
528 |
111212
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
529 (defvar completion-all-sorted-completions nil) |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
530 (make-variable-buffer-local 'completion-all-sorted-completions) |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
531 (defvar completion-cycling nil) |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
532 |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
533 (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
|
534 "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
|
535 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
|
536 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
|
537 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
|
538 |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
539 MCE |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
540 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
|
541 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
|
542 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
|
543 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
|
544 100 4 ??? impossible |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
545 101 5 ??? impossible |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
546 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
|
547 111 7 completed to an exact completion" |
110842
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
548 (lexical-let* |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
549 ((beg (field-beginning)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
550 (end (field-end)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
551 (string (buffer-substring beg end)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
552 (comp (funcall (or try-completion-function |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
553 'completion-try-completion) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
554 string |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
555 minibuffer-completion-table |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
556 minibuffer-completion-predicate |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
557 (- (point) beg)))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
558 (cond |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
559 ((null comp) |
104344
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
560 (minibuffer-hide-completions) |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
561 (ding) (minibuffer-message "No match") (minibuffer--bitset nil nil nil)) |
104342
867af630a71e
(completion--do-completion): Move point for the #b001 case as well (bug#4176).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104122
diff
changeset
|
562 ((eq t comp) |
104344
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
563 (minibuffer-hide-completions) |
104342
867af630a71e
(completion--do-completion): Move point for the #b001 case as well (bug#4176).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104122
diff
changeset
|
564 (goto-char (field-end)) |
111212
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
565 (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
|
566 (t |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
567 ;; `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
|
568 ;; 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
|
569 ;; for appearance, the string is rewritten if the case changes. |
110842
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
570 (lexical-let* |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
571 ((comp-pos (cdr comp)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
572 (completion (car comp)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
573 (completed (not (eq t (compare-strings completion nil nil |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
574 string nil nil t)))) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
575 (unchanged (eq t (compare-strings completion nil nil |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
576 string nil nil nil)))) |
107250
13dafa175b9c
Fix in-buffer completion when after-change-functions modify the buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107089
diff
changeset
|
577 (if unchanged |
110842
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
578 (goto-char end) |
107250
13dafa175b9c
Fix in-buffer completion when after-change-functions modify the buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107089
diff
changeset
|
579 ;; Insert in minibuffer the chars we got. |
13dafa175b9c
Fix in-buffer completion when after-change-functions modify the buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107089
diff
changeset
|
580 (completion--replace beg end completion)) |
13dafa175b9c
Fix in-buffer completion when after-change-functions modify the buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107089
diff
changeset
|
581 ;; Move point to its completion-mandated destination. |
13dafa175b9c
Fix in-buffer completion when after-change-functions modify the buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107089
diff
changeset
|
582 (forward-char (- comp-pos (length completion))) |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
583 |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
584 (if (not (or unchanged completed)) |
111212
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
585 ;; The case of the string changed, but that's all. We're not sure |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
586 ;; whether this is a unique completion or not, so try again using |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
587 ;; the real case (this shouldn't recurse again, because the next |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
588 ;; time try-completion will return either t or the exact string). |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
589 (completion--do-completion try-completion-function) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
590 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
591 ;; 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
|
592 (let ((exact (test-completion completion |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
593 minibuffer-completion-table |
108500
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
594 minibuffer-completion-predicate)) |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
595 (comps |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
596 ;; Check to see if we want to do cycling. We do it |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
597 ;; here, after having performed the normal completion, |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
598 ;; so as to take advantage of the difference between |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
599 ;; try-completion and all-completions, for things |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
600 ;; like completion-ignored-extensions. |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
601 (when (and completion-cycle-threshold |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
602 ;; Check that the completion didn't make |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
603 ;; us jump to a different boundary. |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
604 (or (not completed) |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
605 (< (car (completion-boundaries |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
606 (substring completion 0 comp-pos) |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
607 minibuffer-completion-table |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
608 minibuffer-completion-predicate |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
609 "")) |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
610 comp-pos))) |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
611 (completion-all-sorted-completions)))) |
111212
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
612 (completion--flush-all-sorted-completions) |
108500
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
613 (cond |
111212
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
614 ((and (consp (cdr comps)) ;; There's something to cycle. |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
615 (not (ignore-errors |
108500
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
616 ;; This signal an (intended) error if comps is too |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
617 ;; short or if completion-cycle-threshold is t. |
111212
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
618 (consp (nthcdr completion-cycle-threshold comps))))) |
108500
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
619 ;; Fewer than completion-cycle-threshold remaining |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
620 ;; completions: let's cycle. |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
621 (setq completed t exact t) |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
622 (setq completion-all-sorted-completions comps) |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
623 (minibuffer-force-complete)) |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
624 (completed |
111212
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
625 ;; We could also decide to refresh the completions, |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
626 ;; if they're displayed (and assuming there are |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
627 ;; completions left). |
108500
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
628 (minibuffer-hide-completions)) |
111212
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
629 ;; Show the completion table, if requested. |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
630 ((not exact) |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
631 (if (case completion-auto-help |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
632 (lazy (eq this-command last-command)) |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
633 (t completion-auto-help)) |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
634 (minibuffer-completion-help) |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
635 (minibuffer-message "Next char not unique"))) |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
636 ;; If the last exact completion and this one were the same, it |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
637 ;; means we've already given a "Next char not unique" message |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
638 ;; and the user's hit TAB again, so now we give him help. |
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
639 ((eq this-command last-command) |
108500
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
640 (if completion-auto-help (minibuffer-completion-help)))) |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
641 |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
642 (minibuffer--bitset completed t exact)))))))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
643 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
644 (defun minibuffer-complete () |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
645 "Complete the minibuffer contents as far as possible. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
646 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
|
647 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
|
648 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
|
649 scroll the window of possible completions." |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
650 (interactive) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
651 ;; If the previous command was not this, |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
652 ;; mark the completion buffer obsolete. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
653 (unless (eq this-command last-command) |
111212
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
654 (completion--flush-all-sorted-completions) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
655 (setq minibuffer-scroll-window nil)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
656 |
108500
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
657 (cond |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
658 ;; 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
|
659 ;; and this command is repeated, scroll that window. |
108500
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
660 ((window-live-p minibuffer-scroll-window) |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
661 (let ((window minibuffer-scroll-window)) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
662 (with-current-buffer (window-buffer window) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
663 (if (pos-visible-in-window-p (point-max) window) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
664 ;; 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
|
665 (set-window-start window (point-min) nil) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
666 ;; Else scroll down one screen. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
667 (scroll-other-window)) |
108500
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
668 nil))) |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
669 ;; If we're cycling, keep on cycling. |
111212
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
670 ((and completion-cycling completion-all-sorted-completions) |
108500
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
671 (minibuffer-force-complete) |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
672 t) |
9f927f4deab4
Allow the default completion to cycle.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108486
diff
changeset
|
673 (t (case (completion--do-completion) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
674 (#b000 nil) |
104342
867af630a71e
(completion--do-completion): Move point for the #b001 case as well (bug#4176).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104122
diff
changeset
|
675 (#b001 (minibuffer-message "Sole completion") |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
676 t) |
104342
867af630a71e
(completion--do-completion): Move point for the #b001 case as well (bug#4176).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104122
diff
changeset
|
677 (#b011 (minibuffer-message "Complete, but not unique") |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
678 t) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
679 (t t))))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
680 |
95172
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
681 (defun completion--flush-all-sorted-completions (&rest ignore) |
111212
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
682 (setq completion-cycling nil) |
95172
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
683 (setq completion-all-sorted-completions nil)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
684 |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
685 (defun completion-all-sorted-completions () |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
686 (or completion-all-sorted-completions |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
687 (let* ((start (field-beginning)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
688 (end (field-end)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
689 (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
|
690 minibuffer-completion-table |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
691 minibuffer-completion-predicate |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
692 (- (point) start))) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
693 (last (last all)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
694 (base-size (or (cdr last) 0))) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
695 (when last |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
696 (setcdr last nil) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
697 ;; Prefer shorter completions. |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
698 (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
|
699 ;; Prefer recently used completions. |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
700 (let ((hist (symbol-value minibuffer-history-variable))) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
701 (setq all (sort all (lambda (c1 c2) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
702 (> (length (member c1 hist)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
703 (length (member c2 hist))))))) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
704 ;; 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
|
705 ;; 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
|
706 ;; all possibilities. |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
707 (add-hook 'after-change-functions |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
708 'completion--flush-all-sorted-completions nil t) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
709 (setq completion-all-sorted-completions |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
710 (nconc all base-size)))))) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
711 |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
712 (defun minibuffer-force-complete () |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
713 "Complete the minibuffer to an exact match. |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
714 Repeated uses step through the possible completions." |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
715 (interactive) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
716 ;; FIXME: Need to deal with the extra-size issue here as well. |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
717 ;; FIXME: ~/src/emacs/t<M-TAB>/lisp/minibuffer.el completes to |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
718 ;; ~/src/emacs/trunk/ and throws away lisp/minibuffer.el. |
95172
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
719 (let* ((start (field-beginning)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
720 (end (field-end)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
721 (all (completion-all-sorted-completions))) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
722 (if (not (consp all)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
723 (minibuffer-message (if all "No more completions" "No completions")) |
111212
4c0e52d5ae12
* lisp/minibuffer.el (completion-cycling): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111047
diff
changeset
|
724 (setq completion-cycling t) |
95172
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
725 (goto-char end) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
726 (insert (car all)) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
727 (delete-region (+ start (cdr (last all))) end) |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
728 ;; 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
|
729 ;; 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
|
730 ;; 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
|
731 ;; 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
|
732 ;; through the previous possible completions. |
105174
13f171fbff05
(minibuffer-force-complete): Cycle the list, rather
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104792
diff
changeset
|
733 (let ((last (last all))) |
13f171fbff05
(minibuffer-force-complete): Cycle the list, rather
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104792
diff
changeset
|
734 (setcdr last (cons (car all) (cdr last))) |
13f171fbff05
(minibuffer-force-complete): Cycle the list, rather
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104792
diff
changeset
|
735 (setq completion-all-sorted-completions (cdr all)))))) |
95172
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
736 |
100044
f42890851326
Add and use minibuffer-confirm-exit-commands variable
Miles Bader <miles@gnu.org>
parents:
100022
diff
changeset
|
737 (defvar minibuffer-confirm-exit-commands |
100052
766018471339
(minibuffer-confirm-exit-commands): Add PC-complete and
Chong Yidong <cyd@stupidchicken.com>
parents:
100044
diff
changeset
|
738 '(minibuffer-complete minibuffer-complete-word PC-complete PC-complete-word) |
100044
f42890851326
Add and use minibuffer-confirm-exit-commands variable
Miles Bader <miles@gnu.org>
parents:
100022
diff
changeset
|
739 "A list of commands which cause an immediately following |
f42890851326
Add and use minibuffer-confirm-exit-commands variable
Miles Bader <miles@gnu.org>
parents:
100022
diff
changeset
|
740 `minibuffer-complete-and-exit' to ask for extra confirmation.") |
f42890851326
Add and use minibuffer-confirm-exit-commands variable
Miles Bader <miles@gnu.org>
parents:
100022
diff
changeset
|
741 |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
742 (defun minibuffer-complete-and-exit () |
99883
494c4c7bcf01
(minibuffer-complete-and-exit): Change `confirm-only' value of
Chong Yidong <cyd@stupidchicken.com>
parents:
99232
diff
changeset
|
743 "Exit if the minibuffer contains a valid completion. |
494c4c7bcf01
(minibuffer-complete-and-exit): Change `confirm-only' value of
Chong Yidong <cyd@stupidchicken.com>
parents:
99232
diff
changeset
|
744 Otherwise, try to complete the minibuffer contents. If |
494c4c7bcf01
(minibuffer-complete-and-exit): Change `confirm-only' value of
Chong Yidong <cyd@stupidchicken.com>
parents:
99232
diff
changeset
|
745 completion leads to a valid completion, a repetition of this |
494c4c7bcf01
(minibuffer-complete-and-exit): Change `confirm-only' value of
Chong Yidong <cyd@stupidchicken.com>
parents:
99232
diff
changeset
|
746 command will exit. |
494c4c7bcf01
(minibuffer-complete-and-exit): Change `confirm-only' value of
Chong Yidong <cyd@stupidchicken.com>
parents:
99232
diff
changeset
|
747 |
494c4c7bcf01
(minibuffer-complete-and-exit): Change `confirm-only' value of
Chong Yidong <cyd@stupidchicken.com>
parents:
99232
diff
changeset
|
748 If `minibuffer-completion-confirm' is `confirm', do not try to |
494c4c7bcf01
(minibuffer-complete-and-exit): Change `confirm-only' value of
Chong Yidong <cyd@stupidchicken.com>
parents:
99232
diff
changeset
|
749 complete; instead, ask for confirmation and accept any input if |
494c4c7bcf01
(minibuffer-complete-and-exit): Change `confirm-only' value of
Chong Yidong <cyd@stupidchicken.com>
parents:
99232
diff
changeset
|
750 confirmed. |
494c4c7bcf01
(minibuffer-complete-and-exit): Change `confirm-only' value of
Chong Yidong <cyd@stupidchicken.com>
parents:
99232
diff
changeset
|
751 If `minibuffer-completion-confirm' is `confirm-after-completion', |
494c4c7bcf01
(minibuffer-complete-and-exit): Change `confirm-only' value of
Chong Yidong <cyd@stupidchicken.com>
parents:
99232
diff
changeset
|
752 do not try to complete; instead, ask for confirmation if the |
102614
ac174f1dba45
(minibuffer-complete-and-exit): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102601
diff
changeset
|
753 preceding minibuffer command was a member of |
ac174f1dba45
(minibuffer-complete-and-exit): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102601
diff
changeset
|
754 `minibuffer-confirm-exit-commands', and accept the input |
ac174f1dba45
(minibuffer-complete-and-exit): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102601
diff
changeset
|
755 otherwise." |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
756 (interactive) |
110842
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
757 (lexical-let ((beg (field-beginning)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
758 (end (field-end))) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
759 (cond |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
760 ;; Allow user to specify null string |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
761 ((= beg end) (exit-minibuffer)) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
762 ((test-completion (buffer-substring beg end) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
763 minibuffer-completion-table |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
764 minibuffer-completion-predicate) |
106453
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
765 ;; FIXME: completion-ignore-case has various slightly |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
766 ;; incompatible meanings. E.g. it can reflect whether the user |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
767 ;; wants completion to pay attention to case, or whether the |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
768 ;; string will be used in a context where case is significant. |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
769 ;; E.g. usually try-completion should obey the first, whereas |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
770 ;; test-completion should obey the second. |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
771 (when completion-ignore-case |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
772 ;; 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
|
773 (let* ((string (buffer-substring beg end)) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
774 (compl (try-completion |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
775 string |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
776 minibuffer-completion-table |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
777 minibuffer-completion-predicate))) |
106453
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
778 (when (and (stringp compl) (not (equal string compl)) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
779 ;; 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
|
780 ;; the whole thing with a call to do-completion. |
95799
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
781 ;; This is important, e.g. when the current minibuffer's |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
782 ;; content is a directory which only contains a single |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
783 ;; file, so `try-completion' actually completes to |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
784 ;; that file. |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
785 (= (length string) (length compl))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
786 (goto-char end) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
787 (insert compl) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
788 (delete-region beg end)))) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
789 (exit-minibuffer)) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
790 |
106453
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
791 ((memq minibuffer-completion-confirm '(confirm confirm-after-completion)) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
792 ;; The user is permitted to exit with an input that's rejected |
99883
494c4c7bcf01
(minibuffer-complete-and-exit): Change `confirm-only' value of
Chong Yidong <cyd@stupidchicken.com>
parents:
99232
diff
changeset
|
793 ;; by test-completion, after confirming her choice. |
106453
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
794 (if (or (eq last-command this-command) |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
795 ;; For `confirm-after-completion' we only ask for confirmation |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
796 ;; if trying to exit immediately after typing TAB (this |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
797 ;; catches most minibuffer typos). |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
798 (and (eq minibuffer-completion-confirm 'confirm-after-completion) |
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
799 (not (memq last-command minibuffer-confirm-exit-commands)))) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
800 (exit-minibuffer) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
801 (minibuffer-message "Confirm") |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
802 nil)) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
803 |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
804 (t |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
805 ;; Call do-completion, but ignore errors. |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
806 (case (condition-case nil |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
807 (completion--do-completion) |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
808 (error 1)) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
809 ((#b001 #b011) (exit-minibuffer)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
810 (#b111 (if (not minibuffer-completion-confirm) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
811 (exit-minibuffer) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
812 (minibuffer-message "Confirm") |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
813 nil)) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
814 (t nil)))))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
815 |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
816 (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
|
817 (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
|
818 (if (not (consp comp)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
819 comp |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
820 |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
821 ;; If completion finds next char not unique, |
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
822 ;; 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
|
823 (when (= (length string) (length (car comp))) |
102958
ca1d2b3eaecc
(completion--try-word-completion): Don't disable
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102614
diff
changeset
|
824 ;; Mark the added char with the `completion-word' property, so it |
ca1d2b3eaecc
(completion--try-word-completion): Don't disable
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102614
diff
changeset
|
825 ;; can be handled specially by completion styles such as |
ca1d2b3eaecc
(completion--try-word-completion): Don't disable
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102614
diff
changeset
|
826 ;; partial-completion. |
ca1d2b3eaecc
(completion--try-word-completion): Don't disable
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102614
diff
changeset
|
827 ;; We used to remove `partial-completion' from completion-styles |
ca1d2b3eaecc
(completion--try-word-completion): Don't disable
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102614
diff
changeset
|
828 ;; instead, but it was too blunt, leading to situations where SPC |
ca1d2b3eaecc
(completion--try-word-completion): Don't disable
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102614
diff
changeset
|
829 ;; was the only insertable char at point but minibuffer-complete-word |
ca1d2b3eaecc
(completion--try-word-completion): Don't disable
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102614
diff
changeset
|
830 ;; refused inserting it. |
ca1d2b3eaecc
(completion--try-word-completion): Don't disable
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102614
diff
changeset
|
831 (let ((exts (mapcar (lambda (str) (propertize str 'completion-try-word t)) |
ca1d2b3eaecc
(completion--try-word-completion): Don't disable
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
102614
diff
changeset
|
832 '(" " "-"))) |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
833 (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
|
834 (after (substring string point)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
835 tem) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
836 (while (and exts (not (consp tem))) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
837 (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
|
838 (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
|
839 table predicate (1+ point)))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
840 (if (consp tem) (setq comp tem)))) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
841 |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
842 ;; 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
|
843 ;; 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
|
844 ;; 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
|
845 ;; 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
|
846 ;; 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
|
847 ;; completion (plus env-var expansion, ...) `completion' might not |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
848 ;; 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
|
849 (let* ((comppoint (cdr comp)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
850 (completion (car comp)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
851 (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
|
852 (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
|
853 ;; 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
|
854 (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
|
855 (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
|
856 ;; 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
|
857 (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
|
858 ;; 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
|
859 ;; 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
|
860 (after (substring string point)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
861 (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
|
862 (concat after "\n" rem)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
863 (match-string 1 after)))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
864 ;; 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
|
865 ;; 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
|
866 ;; 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
|
867 ;; 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
|
868 ;; 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
|
869 ;; 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
|
870 ;; 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
|
871 ;; our guess is correct. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
872 ;; 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
|
873 ;; 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
|
874 ;; 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
|
875 ;; 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
|
876 ;; 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
|
877 (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
|
878 (string-match (concat |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
879 ;; 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
|
880 ;; 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
|
881 ;; valuable text. |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
882 ".*" (regexp-quote prefix) "\\(.*?\\)" |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
883 (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
|
884 completion) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
885 ;; 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
|
886 ;; 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
|
887 ;; 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
|
888 (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
|
889 ;; (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
|
890 ;; 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
|
891 (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
|
892 ;; 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
|
893 (> comppoint (match-end 0))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
894 ;; 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
|
895 (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
|
896 (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
|
897 (substring completion comppoint))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
898 (setq comppoint cutpos))))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
899 |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
900 (cons completion comppoint))))) |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
901 |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
902 |
93937
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
903 (defun minibuffer-complete-word () |
dfe13eac745b
* minibuffer.el (minibuffer): Move group from cus-edit.el.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93885
diff
changeset
|
904 "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
|
905 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
|
906 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
|
907 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
|
908 (interactive) |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
909 (case (completion--do-completion 'completion--try-word-completion) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
910 (#b000 nil) |
104342
867af630a71e
(completion--do-completion): Move point for the #b001 case as well (bug#4176).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104122
diff
changeset
|
911 (#b001 (minibuffer-message "Sole completion") |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
912 t) |
104342
867af630a71e
(completion--do-completion): Move point for the #b001 case as well (bug#4176).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104122
diff
changeset
|
913 (#b011 (minibuffer-message "Complete, but not unique") |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
914 t) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
915 (t t))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
916 |
104344
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
917 (defface completions-annotations '((t :inherit italic)) |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
918 "Face to use for annotations in the *Completions* buffer.") |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
919 |
109044
f0d32dbd0fcf
* lisp/minibuffer.el (completions-format): Change default from nil to
Juri Linkov <juri@jurta.org>
parents:
108831
diff
changeset
|
920 (defcustom completions-format 'horizontal |
106122
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
921 "Define the appearance and sorting of completions. |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
922 If the value is `vertical', display completions sorted vertically |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
923 in columns in the *Completions* buffer. |
109044
f0d32dbd0fcf
* lisp/minibuffer.el (completions-format): Change default from nil to
Juri Linkov <juri@jurta.org>
parents:
108831
diff
changeset
|
924 If the value is `horizontal', display completions sorted |
106122
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
925 horizontally in alphabetical order, rather than down the screen." |
109044
f0d32dbd0fcf
* lisp/minibuffer.el (completions-format): Change default from nil to
Juri Linkov <juri@jurta.org>
parents:
108831
diff
changeset
|
926 :type '(choice (const horizontal) (const vertical)) |
106122
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
927 :group 'minibuffer |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
928 :version "23.2") |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
929 |
94211
81b6ecd7be01
(completion-try-completion): Change magic symbol
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94202
diff
changeset
|
930 (defun completion--insert-strings (strings) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
931 "Insert a list of STRINGS into the current buffer. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
932 Uses columns to keep the listing readable but compact. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
933 It also eliminates runs of equal strings." |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
934 (when (consp strings) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
935 (let* ((length (apply 'max |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
936 (mapcar (lambda (s) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
937 (if (consp s) |
94561
bbc1b1a5633e
(completion--insert-strings): Use string-width rather than length.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94558
diff
changeset
|
938 (+ (string-width (car s)) |
bbc1b1a5633e
(completion--insert-strings): Use string-width rather than length.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94558
diff
changeset
|
939 (string-width (cadr s))) |
bbc1b1a5633e
(completion--insert-strings): Use string-width rather than length.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94558
diff
changeset
|
940 (string-width s))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
941 strings))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
942 (window (get-buffer-window (current-buffer) 0)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
943 (wwidth (if window (1- (window-width window)) 79)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
944 (columns (min |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
945 ;; 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
|
946 (max 2 (/ wwidth (+ 2 length))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
947 ;; Don't allocate more columns than we can fill. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
948 ;; Windows can't show less than 3 lines anyway. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
949 (max 1 (/ (length strings) 2)))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
950 (colwidth (/ wwidth columns)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
951 (column 0) |
106122
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
952 (rows (/ (length strings) columns)) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
953 (row 0) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
954 (laststring nil)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
955 ;; 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
|
956 ;; for the parameters above. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
957 (dolist (str strings) |
101327
b0eef2ac5a59
(completion--insert-strings): Fix up computation of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101162
diff
changeset
|
958 (unless (equal laststring str) ; Remove (consecutive) duplicates. |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
959 (setq laststring str) |
101327
b0eef2ac5a59
(completion--insert-strings): Fix up computation of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101162
diff
changeset
|
960 (let ((length (if (consp str) |
b0eef2ac5a59
(completion--insert-strings): Fix up computation of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101162
diff
changeset
|
961 (+ (string-width (car str)) |
b0eef2ac5a59
(completion--insert-strings): Fix up computation of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101162
diff
changeset
|
962 (string-width (cadr str))) |
b0eef2ac5a59
(completion--insert-strings): Fix up computation of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101162
diff
changeset
|
963 (string-width str)))) |
106122
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
964 (cond |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
965 ((eq completions-format 'vertical) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
966 ;; Vertical format |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
967 (when (> row rows) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
968 (forward-line (- -1 rows)) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
969 (setq row 0 column (+ column colwidth))) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
970 (when (> column 0) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
971 (end-of-line) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
972 (while (> (current-column) column) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
973 (if (eobp) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
974 (insert "\n") |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
975 (forward-line 1) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
976 (end-of-line))) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
977 (insert " \t") |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
978 (set-text-properties (- (point) 1) (point) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
979 `(display (space :align-to ,column))))) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
980 (t |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
981 ;; Horizontal format |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
982 (unless (bolp) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
983 (if (< wwidth (+ (max colwidth length) column)) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
984 ;; No space for `str' at point, move to next line. |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
985 (progn (insert "\n") (setq column 0)) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
986 (insert " \t") |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
987 ;; Leave the space unpropertized so that in the case we're |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
988 ;; already past the goal column, there is still |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
989 ;; a space displayed. |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
990 (set-text-properties (- (point) 1) (point) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
991 ;; We can't just set tab-width, because |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
992 ;; completion-setup-function will kill all |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
993 ;; local variables :-( |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
994 `(display (space :align-to ,column))) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
995 nil)))) |
101327
b0eef2ac5a59
(completion--insert-strings): Fix up computation of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101162
diff
changeset
|
996 (if (not (consp str)) |
b0eef2ac5a59
(completion--insert-strings): Fix up computation of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101162
diff
changeset
|
997 (put-text-property (point) (progn (insert str) (point)) |
b0eef2ac5a59
(completion--insert-strings): Fix up computation of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101162
diff
changeset
|
998 'mouse-face 'highlight) |
b0eef2ac5a59
(completion--insert-strings): Fix up computation of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101162
diff
changeset
|
999 (put-text-property (point) (progn (insert (car str)) (point)) |
b0eef2ac5a59
(completion--insert-strings): Fix up computation of
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101162
diff
changeset
|
1000 'mouse-face 'highlight) |
104344
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1001 (add-text-properties (point) (progn (insert (cadr str)) (point)) |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1002 '(mouse-face nil |
106122
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
1003 face completions-annotations))) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
1004 (cond |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
1005 ((eq completions-format 'vertical) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
1006 ;; Vertical format |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
1007 (if (> column 0) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
1008 (forward-line) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
1009 (insert "\n")) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
1010 (setq row (1+ row))) |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
1011 (t |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
1012 ;; Horizontal format |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
1013 ;; Next column to align to. |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
1014 (setq column (+ column |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
1015 ;; Round up to a whole number of columns. |
4ff55285a1c0
(completions-format): New defcustom.
Juri Linkov <juri@jurta.org>
parents:
106109
diff
changeset
|
1016 (* colwidth (ceiling length colwidth)))))))))))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1017 |
94464
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1018 (defvar completion-common-substring nil) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1019 (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
|
1020 |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
1021 (defvar completion-setup-hook nil |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
1022 "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
|
1023 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
|
1024 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
|
1025 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
|
1026 See also `display-completion-list'.") |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1027 |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1028 (defface completions-first-difference |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1029 '((t (:inherit bold))) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1030 "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
|
1031 :group 'completion) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1032 |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1033 (defface completions-common-part |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1034 '((t (:inherit default))) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1035 "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
|
1036 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
|
1037 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
|
1038 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
|
1039 :group 'completion) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1040 |
100623
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1041 (defun completion-hilit-commonality (completions prefix-len base-size) |
94464
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1042 (when completions |
100623
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1043 (let ((com-str-len (- prefix-len (or base-size 0)))) |
94464
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1044 (nconc |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1045 (mapcar |
94558
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
1046 (lambda (elem) |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
1047 (let ((str |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
1048 ;; 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
|
1049 ;; 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
|
1050 ;; Furthermore, since `completions' may come from |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
1051 ;; 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
|
1052 (if (consp elem) |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
1053 (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
|
1054 (cdr elem)))) |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
1055 (setq elem (copy-sequence elem))))) |
100929
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1056 (put-text-property 0 |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1057 ;; If completion-boundaries returns incorrect |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1058 ;; values, all-completions may return strings |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1059 ;; that don't contain the prefix. |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1060 (min com-str-len (length str)) |
94558
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
1061 'font-lock-face 'completions-common-part |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
1062 str) |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
1063 (if (> (length str) com-str-len) |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
1064 (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
|
1065 'font-lock-face 'completions-first-difference |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
1066 str))) |
9802c49152d9
(completion-hilit-commonality): Revert last change:
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94487
diff
changeset
|
1067 elem) |
94464
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1068 completions) |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1069 base-size)))) |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
1070 |
97478
6c4680239c3f
(display-completion-list): Revert last change. Only default base-size
Chong Yidong <cyd@stupidchicken.com>
parents:
97476
diff
changeset
|
1071 (defun display-completion-list (completions &optional common-substring) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1072 "Display the list of completions, COMPLETIONS, using `standard-output'. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1073 Each element may be just a symbol or string |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1074 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
|
1075 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
|
1076 alternative, the second serves as annotation. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1077 `standard-output' must be a buffer. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1078 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
|
1079 properties of `highlight'. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1080 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
|
1081 It can find the completion buffer in `standard-output'. |
97476
354026fc6299
(completion-boundaries): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
97179
diff
changeset
|
1082 |
97544
abca40c62d44
(display-completion-list): Re-state the obsolescence of `common-substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
97478
diff
changeset
|
1083 The obsolete optional arg COMMON-SUBSTRING, if non-nil, should be a string |
97476
354026fc6299
(completion-boundaries): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
97179
diff
changeset
|
1084 specifying a common substring for adding the faces |
354026fc6299
(completion-boundaries): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
97179
diff
changeset
|
1085 `completions-first-difference' and `completions-common-part' to |
97478
6c4680239c3f
(display-completion-list): Revert last change. Only default base-size
Chong Yidong <cyd@stupidchicken.com>
parents:
97476
diff
changeset
|
1086 the completions buffer." |
94464
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1087 (if common-substring |
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1088 (setq completions (completion-hilit-commonality |
100623
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1089 completions (length common-substring) |
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1090 ;; We don't know the base-size. |
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1091 nil))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1092 (if (not (bufferp standard-output)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1093 ;; 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
|
1094 (with-temp-buffer |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1095 (let ((standard-output (current-buffer)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1096 (completion-setup-hook nil)) |
97478
6c4680239c3f
(display-completion-list): Revert last change. Only default base-size
Chong Yidong <cyd@stupidchicken.com>
parents:
97476
diff
changeset
|
1097 (display-completion-list completions common-substring)) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1098 (princ (buffer-string))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1099 |
105601
68686d39c93a
Replace completion-base-size by completion-base-position to fix bugs
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105597
diff
changeset
|
1100 (with-current-buffer standard-output |
68686d39c93a
Replace completion-base-size by completion-base-position to fix bugs
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105597
diff
changeset
|
1101 (goto-char (point-max)) |
68686d39c93a
Replace completion-base-size by completion-base-position to fix bugs
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105597
diff
changeset
|
1102 (if (null completions) |
68686d39c93a
Replace completion-base-size by completion-base-position to fix bugs
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105597
diff
changeset
|
1103 (insert "There are no possible completions of what you have typed.") |
68686d39c93a
Replace completion-base-size by completion-base-position to fix bugs
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105597
diff
changeset
|
1104 (insert "Possible completions are:\n") |
68686d39c93a
Replace completion-base-size by completion-base-position to fix bugs
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105597
diff
changeset
|
1105 (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
|
1106 |
94464
66b02cd7b956
* minibuffer.el (completion-common-substring): Mark obsolete.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94427
diff
changeset
|
1107 ;; 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
|
1108 ;; may still be some code that uses completion-common-substring. |
97476
354026fc6299
(completion-boundaries): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
97179
diff
changeset
|
1109 (with-no-warnings |
354026fc6299
(completion-boundaries): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
97179
diff
changeset
|
1110 (let ((completion-common-substring common-substring)) |
354026fc6299
(completion-boundaries): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
97179
diff
changeset
|
1111 (run-hooks 'completion-setup-hook))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1112 nil) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1113 |
104719
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1114 (defvar completion-annotate-function |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1115 nil |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1116 ;; Note: there's a lot of scope as for when to add annotations and |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1117 ;; what annotations to add. E.g. completing-help.el allowed adding |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1118 ;; the first line of docstrings to M-x completion. But there's |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1119 ;; a tension, since such annotations, while useful at times, can |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1120 ;; actually drown the useful information. |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1121 ;; So completion-annotate-function should be used parsimoniously, or |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1122 ;; else only used upon a user's request (e.g. we could add a command |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1123 ;; to completion-list-mode to add annotations to the current |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1124 ;; completions). |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1125 "Function to add annotations in the *Completions* buffer. |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1126 The function takes a completion and should either return nil, or a string that |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1127 will be displayed next to the completion. The function can access the |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1128 completion table and predicates via `minibuffer-completion-table' and related |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1129 variables.") |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1130 |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1131 (defun minibuffer-completion-help () |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1132 "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
|
1133 (interactive) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1134 (message "Making completion list...") |
110842
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1135 (lexical-let* ((start (field-beginning)) |
111386
93e249d6d27c
* lisp/minibuffer.el (minibuffer-completion-help): Specify the end of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111041
diff
changeset
|
1136 (end (field-end)) |
110842
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1137 (string (field-string)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1138 (completions (completion-all-completions |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1139 string |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1140 minibuffer-completion-table |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1141 minibuffer-completion-predicate |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1142 (- (point) (field-beginning))))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1143 (message nil) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1144 (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
|
1145 (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
|
1146 (not (equal (car completions) string)))) |
106132
57f23ca20a76
* window.el (display-buffer-mark-dedicated): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106122
diff
changeset
|
1147 (let* ((last (last completions)) |
57f23ca20a76
* window.el (display-buffer-mark-dedicated): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106122
diff
changeset
|
1148 (base-size (cdr last)) |
57f23ca20a76
* window.el (display-buffer-mark-dedicated): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106122
diff
changeset
|
1149 ;; If the *Completions* buffer is shown in a new |
57f23ca20a76
* window.el (display-buffer-mark-dedicated): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106122
diff
changeset
|
1150 ;; window, mark it as softly-dedicated, so bury-buffer in |
57f23ca20a76
* window.el (display-buffer-mark-dedicated): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106122
diff
changeset
|
1151 ;; minibuffer-hide-completions will know whether to |
57f23ca20a76
* window.el (display-buffer-mark-dedicated): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106122
diff
changeset
|
1152 ;; delete the window or not. |
57f23ca20a76
* window.el (display-buffer-mark-dedicated): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106122
diff
changeset
|
1153 (display-buffer-mark-dedicated 'soft)) |
57f23ca20a76
* window.el (display-buffer-mark-dedicated): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106122
diff
changeset
|
1154 (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
|
1155 ;; 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
|
1156 ;; nil-terminated list. |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
1157 (when last (setcdr last nil)) |
104719
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1158 (setq completions (sort completions 'string-lessp)) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1159 (when completion-annotate-function |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1160 (setq completions |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1161 (mapcar (lambda (s) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1162 (let ((ann |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1163 (funcall completion-annotate-function s))) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1164 (if ann (list s ann) s))) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1165 completions))) |
105601
68686d39c93a
Replace completion-base-size by completion-base-position to fix bugs
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105597
diff
changeset
|
1166 (with-current-buffer standard-output |
106132
57f23ca20a76
* window.el (display-buffer-mark-dedicated): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106122
diff
changeset
|
1167 (set (make-local-variable 'completion-base-position) |
111386
93e249d6d27c
* lisp/minibuffer.el (minibuffer-completion-help): Specify the end of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111041
diff
changeset
|
1168 (list (+ start base-size) |
93e249d6d27c
* lisp/minibuffer.el (minibuffer-completion-help): Specify the end of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111041
diff
changeset
|
1169 ;; FIXME: We should pay attention to completion |
93e249d6d27c
* lisp/minibuffer.el (minibuffer-completion-help): Specify the end of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111041
diff
changeset
|
1170 ;; boundaries here, but currently |
93e249d6d27c
* lisp/minibuffer.el (minibuffer-completion-help): Specify the end of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111041
diff
changeset
|
1171 ;; completion-all-completions does not give us the |
93e249d6d27c
* lisp/minibuffer.el (minibuffer-completion-help): Specify the end of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111041
diff
changeset
|
1172 ;; necessary information. |
93e249d6d27c
* lisp/minibuffer.el (minibuffer-completion-help): Specify the end of the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
111041
diff
changeset
|
1173 end))) |
105601
68686d39c93a
Replace completion-base-size by completion-base-position to fix bugs
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105597
diff
changeset
|
1174 (display-completion-list completions))) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1175 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1176 ;; 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
|
1177 ;; only possible completion, then hide (previous&stale) completions. |
105969
6a8befbb8e39
(minibuffer-completion-help): Use minibuffer-hide-completions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105950
diff
changeset
|
1178 (minibuffer-hide-completions) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1179 (ding) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1180 (minibuffer-message |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1181 (if completions "Sole completion" "No completions"))) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1182 nil)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1183 |
104344
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1184 (defun minibuffer-hide-completions () |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1185 "Get rid of an out-of-date *Completions* buffer." |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1186 ;; FIXME: We could/should use minibuffer-scroll-window here, but it |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1187 ;; can also point to the minibuffer-parent-window, so it's a bit tricky. |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1188 (let ((win (get-buffer-window "*Completions*" 0))) |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1189 (if win (with-selected-window win (bury-buffer))))) |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1190 |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1191 (defun exit-minibuffer () |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1192 "Terminate this minibuffer argument." |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1193 (interactive) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1194 ;; 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
|
1195 ;; 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
|
1196 ;; buffer. |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1197 ;; 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
|
1198 ;; (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
|
1199 ;; 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
|
1200 (setq deactivate-mark nil) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1201 (throw 'exit nil)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1202 |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1203 (defun self-insert-and-exit () |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1204 "Terminate minibuffer input." |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1205 (interactive) |
101010
4efc7ca085ce
Replace last-command-char with last-command-event.
Glenn Morris <rgm@gnu.org>
parents:
100929
diff
changeset
|
1206 (if (characterp last-command-event) |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1207 (call-interactively 'self-insert-command) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1208 (ding)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1209 (exit-minibuffer)) |
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1210 |
106109
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1211 (defvar completion-in-region-functions nil |
107514
408aeb71a781
* lisp/minibuffer.el (completion-in-region-functions): Fix docstring typos.
Juanma Barranquero <lekktu@gmail.com>
parents:
107250
diff
changeset
|
1212 "Wrapper hook around `completion-in-region'. |
106109
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1213 The functions on this special hook are called with 5 arguments: |
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1214 NEXT-FUN START END COLLECTION PREDICATE. |
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1215 NEXT-FUN is a function of four arguments (START END COLLECTION PREDICATE) |
107517
ed16fdd2685a
Fix typos in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
107514
diff
changeset
|
1216 that performs the default operation. The other four arguments are like |
107514
408aeb71a781
* lisp/minibuffer.el (completion-in-region-functions): Fix docstring typos.
Juanma Barranquero <lekktu@gmail.com>
parents:
107250
diff
changeset
|
1217 the ones passed to `completion-in-region'. The functions on this hook |
106109
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1218 are expected to perform completion on START..END using COLLECTION |
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1219 and PREDICATE, either by calling NEXT-FUN or by doing it themselves.") |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1220 |
106109
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1221 (defun completion-in-region (start end collection &optional predicate) |
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1222 "Complete the text between START and END using COLLECTION. |
106452
4543cbad36da
(completion-in-region): Improve docstring.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106413
diff
changeset
|
1223 Return nil if there is no valid completion, else t. |
106109
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1224 Point needs to be somewhere between START and END." |
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1225 (assert (<= start (point)) (<= (point) end)) |
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1226 ;; FIXME: undisplay the *Completions* buffer once the completion is done. |
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1227 (with-wrapper-hook |
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1228 completion-in-region-functions (start end collection predicate) |
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1229 (let ((minibuffer-completion-table collection) |
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1230 (minibuffer-completion-predicate predicate) |
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1231 (ol (make-overlay start end nil nil t))) |
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1232 (overlay-put ol 'field 'completion) |
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1233 (unwind-protect |
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1234 (call-interactively 'minibuffer-complete) |
42ca82b4620b
* abbrev.el (abbrev-with-wrapper-hook): (re)move...
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105969
diff
changeset
|
1235 (delete-overlay ol))))) |
95575
d34a432d5863
* keymap.c (Vminibuffer_local_filename_must_match_map):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95426
diff
changeset
|
1236 |
108166
15deb8699a13
* minibuffer.el (tags-completion-at-point-function): New function.
Chong Yidong <cyd@stupidchicken.com>
parents:
108159
diff
changeset
|
1237 (defvar completion-at-point-functions '(tags-completion-at-point-function) |
106482
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106453
diff
changeset
|
1238 "Special hook to find the completion table for the thing at point. |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106453
diff
changeset
|
1239 It is called without any argument and should return either nil, |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106453
diff
changeset
|
1240 or a function of no argument to perform completion (discouraged), |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106453
diff
changeset
|
1241 or a list of the form (START END COLLECTION &rest PROPS) where |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106453
diff
changeset
|
1242 START and END delimit the entity to complete and should include point, |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106453
diff
changeset
|
1243 COLLECTION is the completion table to use to complete it, and |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106453
diff
changeset
|
1244 PROPS is a property list for additional information. |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106453
diff
changeset
|
1245 Currently supported properties are: |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106453
diff
changeset
|
1246 `:predicate' a predicate that completion candidates need to satisfy. |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106453
diff
changeset
|
1247 `:annotation-function' the value to use for `completion-annotate-function'.") |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106453
diff
changeset
|
1248 |
108375 | 1249 (defun completion-at-point (&optional arg) |
108159
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1250 "Perform completion on the text around point. |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1251 The completion method is determined by `completion-at-point-functions'. |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1252 |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1253 With a prefix argument, this command does completion within |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1254 the collection of symbols listed in the index of the manual for the |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1255 language you are using." |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1256 (interactive "P") |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1257 (if arg |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1258 (info-complete-symbol) |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1259 (let ((res (run-hook-with-args-until-success |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1260 'completion-at-point-functions))) |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1261 (cond |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1262 ((functionp res) (funcall res)) |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1263 (res |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1264 (let* ((plist (nthcdr 3 res)) |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1265 (start (nth 0 res)) |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1266 (end (nth 1 res)) |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1267 (completion-annotate-function |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1268 (or (plist-get plist :annotation-function) |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1269 completion-annotate-function))) |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1270 (completion-in-region start end (nth 2 res) |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1271 (plist-get plist :predicate)))))))) |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1272 |
108375 | 1273 (define-obsolete-function-alias 'complete-symbol 'completion-at-point "24.1") |
106482
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106453
diff
changeset
|
1274 |
106545
82c7a7ac0c67
(minibuffer-local-must-match-filename-map): Re-instate the varalias that was
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106482
diff
changeset
|
1275 ;;; Key bindings. |
82c7a7ac0c67
(minibuffer-local-must-match-filename-map): Re-instate the varalias that was
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106482
diff
changeset
|
1276 |
82c7a7ac0c67
(minibuffer-local-must-match-filename-map): Re-instate the varalias that was
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106482
diff
changeset
|
1277 (define-obsolete-variable-alias 'minibuffer-local-must-match-filename-map |
82c7a7ac0c67
(minibuffer-local-must-match-filename-map): Re-instate the varalias that was
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106482
diff
changeset
|
1278 'minibuffer-local-filename-must-match-map "23.1") |
106482
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106453
diff
changeset
|
1279 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1280 (let ((map minibuffer-local-map)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1281 (define-key map "\C-g" 'abort-recursive-edit) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1282 (define-key map "\r" 'exit-minibuffer) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1283 (define-key map "\n" 'exit-minibuffer)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1284 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1285 (let ((map minibuffer-local-completion-map)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1286 (define-key map "\t" 'minibuffer-complete) |
95172
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
1287 ;; 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
|
1288 ;; another binding for it. |
894bae45bf1b
(completion-all-sorted-completions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95145
diff
changeset
|
1289 ;; (define-key map "\e\t" 'minibuffer-force-complete) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1290 (define-key map " " 'minibuffer-complete-word) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1291 (define-key map "?" 'minibuffer-completion-help)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1292 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1293 (let ((map minibuffer-local-must-match-map)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1294 (define-key map "\r" 'minibuffer-complete-and-exit) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1295 (define-key map "\n" 'minibuffer-complete-and-exit)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1296 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1297 (let ((map minibuffer-local-filename-completion-map)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1298 (define-key map " " nil)) |
95575
d34a432d5863
* keymap.c (Vminibuffer_local_filename_must_match_map):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95426
diff
changeset
|
1299 (let ((map minibuffer-local-filename-must-match-map)) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1300 (define-key map " " nil)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1301 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1302 (let ((map minibuffer-local-ns-map)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1303 (define-key map " " 'exit-minibuffer) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1304 (define-key map "\t" 'exit-minibuffer) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1305 (define-key map "?" 'self-insert-and-exit)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1306 |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1307 ;;; Completion tables. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1308 |
93945
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1309 (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
|
1310 (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
|
1311 |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
1312 (defun completion--make-envvar-table () |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
1313 (mapcar (lambda (enventry) |
101162
64a6da0f9aa2
* minibuffer.el (minibuffer-message): Fix regexp so it doesn't exclude
Juanma Barranquero <lekktu@gmail.com>
parents:
101010
diff
changeset
|
1314 (substring enventry 0 (string-match-p "=" enventry))) |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
1315 process-environment)) |
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
1316 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1317 (defconst completion--embedded-envvar-re |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1318 (concat "\\(?:^\\|[^$]\\(?:\\$\\$\\)*\\)" |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1319 "$\\([[:alnum:]_]*\\|{\\([^}]*\\)\\)\\'")) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1320 |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
1321 (defun completion--embedded-envvar-table (string pred action) |
105733
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1322 "Completion table for envvars embedded in a string. |
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1323 The envvar syntax (and escaping) rules followed by this table are the |
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1324 same as `substitute-in-file-name'." |
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1325 ;; We ignore `pred', because the predicates passed to us via |
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1326 ;; read-file-name-internal are not 100% correct and fail here: |
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1327 ;; e.g. we get predicates like file-directory-p there, whereas the filename |
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1328 ;; completed needs to be passed through substitute-in-file-name before it |
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1329 ;; can be passed to file-directory-p. |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1330 (when (string-match completion--embedded-envvar-re string) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1331 (let* ((beg (or (match-beginning 2) (match-beginning 1))) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1332 (table (completion--make-envvar-table)) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1333 (prefix (substring string 0 beg))) |
105733
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1334 (cond |
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1335 ((eq action 'lambda) |
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1336 ;; This table is expected to be used in conjunction with some |
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1337 ;; other table that provides the "main" completion. Let the |
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1338 ;; other table handle the test-completion case. |
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1339 nil) |
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1340 ((eq (car-safe action) 'boundaries) |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1341 ;; Only return boundaries if there's something to complete, |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1342 ;; since otherwise when we're used in |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1343 ;; completion-table-in-turn, we could return boundaries and |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1344 ;; let some subsequent table return a list of completions. |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1345 ;; FIXME: Maybe it should rather be fixed in |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1346 ;; completion-table-in-turn instead, but it's difficult to |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1347 ;; do it efficiently there. |
105733
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1348 (when (try-completion (substring string beg) table nil) |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1349 ;; Compute the boundaries of the subfield to which this |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1350 ;; completion applies. |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1351 (let ((suffix (cdr action))) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1352 (list* 'boundaries |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1353 (or (match-beginning 2) (match-beginning 1)) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1354 (when (string-match "[^[:alnum:]_]" suffix) |
105733
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1355 (match-beginning 0)))))) |
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1356 (t |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1357 (if (eq (aref string (1- beg)) ?{) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1358 (setq table (apply-partially 'completion-table-with-terminator |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1359 "}" table))) |
104719
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1360 ;; Even if file-name completion is case-insensitive, we want |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1361 ;; envvar completion to be case-sensitive. |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1362 (let ((completion-ignore-case nil)) |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1363 (completion-table-with-context |
105733
1528571f6bfd
(completion--embedded-envvar-table): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105711
diff
changeset
|
1364 prefix table (substring string beg) nil action))))))) |
94055
ec343c7600a2
(completion--embedded-envvar-table, read-file-name-internal):
Juanma Barranquero <lekktu@gmail.com>
parents:
94017
diff
changeset
|
1365 |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1366 (defun completion-file-name-table (string pred action) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1367 "Completion table for file names." |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1368 (ignore-errors |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1369 (cond |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1370 ((eq (car-safe action) 'boundaries) |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
1371 (let ((start (length (file-name-directory string))) |
101162
64a6da0f9aa2
* minibuffer.el (minibuffer-message): Fix regexp so it doesn't exclude
Juanma Barranquero <lekktu@gmail.com>
parents:
101010
diff
changeset
|
1372 (end (string-match-p "/" (cdr action)))) |
108831
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1373 (list* 'boundaries |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1374 ;; if `string' is "C:" in w32, (file-name-directory string) |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1375 ;; returns "C:/", so `start' is 3 rather than 2. |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1376 ;; Not quite sure what is The Right Fix, but clipping it |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1377 ;; back to 2 will work for this particular case. We'll |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1378 ;; see if we can come up with a better fix when we bump |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1379 ;; into more such problematic cases. |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1380 (min start (length string)) end))) |
95426
92edde3e7af6
(completion-table-dynamic): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
95394
diff
changeset
|
1381 |
108831
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1382 ((eq action 'lambda) |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1383 (if (zerop (length string)) |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1384 nil ;Not sure why it's here, but it probably doesn't harm. |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1385 (funcall (or pred 'file-exists-p) string))) |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1386 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1387 (t |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1388 (let* ((name (file-name-nondirectory string)) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1389 (specdir (file-name-directory string)) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1390 (realdir (or specdir default-directory))) |
94055
ec343c7600a2
(completion--embedded-envvar-table, read-file-name-internal):
Juanma Barranquero <lekktu@gmail.com>
parents:
94017
diff
changeset
|
1391 |
93945
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1392 (cond |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1393 ((null action) |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1394 (let ((comp (file-name-completion name realdir pred))) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1395 (if (stringp comp) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1396 (concat specdir comp) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1397 comp))) |
94055
ec343c7600a2
(completion--embedded-envvar-table, read-file-name-internal):
Juanma Barranquero <lekktu@gmail.com>
parents:
94017
diff
changeset
|
1398 |
93945
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1399 ((eq action t) |
100623
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1400 (let ((all (file-name-all-completions name realdir))) |
94062
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
1401 |
9fefa536be58
* minibuffer.el (completion-all-completion-with-base-size): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94055
diff
changeset
|
1402 ;; Check the predicate, if necessary. |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1403 (unless (memq pred '(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
|
1404 (let ((comp ()) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1405 (pred |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1406 (if (eq pred 'file-directory-p) |
93945
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1407 ;; 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
|
1408 ;; 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
|
1409 (lambda (s) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1410 (let ((len (length s))) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1411 (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
|
1412 ;; Must do it the hard (and slow) way. |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1413 pred))) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1414 (let ((default-directory (expand-file-name realdir))) |
93945
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1415 (dolist (tem all) |
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1416 (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
|
1417 (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
|
1418 |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1419 all)))))))) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1420 |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1421 (defvar read-file-name-predicate nil |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1422 "Current predicate used by `read-file-name-internal'.") |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1423 (make-obsolete-variable 'read-file-name-predicate |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1424 "use the regular PRED argument" "23.2") |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1425 |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1426 (defun completion--file-name-table (string pred action) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1427 "Internal subroutine for `read-file-name'. Do not call this. |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1428 This is a completion table for file names, like `completion-file-name-table' |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1429 except that it passes the file name through `substitute-in-file-name'." |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1430 (cond |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1431 ((eq (car-safe action) 'boundaries) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1432 ;; For the boundaries, we can't really delegate to |
108831
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1433 ;; substitute-in-file-name+completion-file-name-table and then fix |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1434 ;; them up (as we do for the other actions), because it would |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1435 ;; require us to track the relationship between `str' and |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1436 ;; `string', which is difficult. And in any case, if |
108831
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1437 ;; substitute-in-file-name turns "fo-$TO-ba" into "fo-o/b-ba", |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1438 ;; there's no way for us to return proper boundaries info, because |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1439 ;; the boundary is not (yet) in `string'. |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1440 ;; |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1441 ;; FIXME: Actually there is a way to return correct boundaries |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1442 ;; info, at the condition of modifying the all-completions |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1443 ;; return accordingly. But for now, let's not bother. |
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1444 (completion-file-name-table string pred action)) |
93945
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1445 |
108831
c8b4b7099b45
* lisp/minibuffer.el (completion-file-name-table): Don't return a boundary
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108500
diff
changeset
|
1446 (t |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1447 (let* ((default-directory |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1448 (if (stringp pred) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1449 ;; It used to be that `pred' was abused to pass `dir' |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1450 ;; as an argument. |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1451 (prog1 (file-name-as-directory (expand-file-name pred)) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1452 (setq pred nil)) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1453 default-directory)) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1454 (str (condition-case nil |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1455 (substitute-in-file-name string) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1456 (error string))) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1457 (comp (completion-file-name-table |
108159
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1458 str |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1459 (with-no-warnings (or pred read-file-name-predicate)) |
56d11bda8235
Unify complete-symbol with completion-at-point.
Chong Yidong <cyd@stupidchicken.com>
parents:
107983
diff
changeset
|
1460 action))) |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1461 |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1462 (cond |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1463 ((stringp comp) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1464 ;; Requote the $s before returning the completion. |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1465 (minibuffer--double-dollars comp)) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1466 ((and (null action) comp |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1467 ;; Requote the $s before checking for changes. |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1468 (setq str (minibuffer--double-dollars str)) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1469 (not (string-equal string str))) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1470 ;; If there's no real completion, but substitute-in-file-name |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1471 ;; changed the string, then return the new string. |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1472 str) |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1473 (t comp)))))) |
93945
76ebfa5df8a2
* minibuffer.el (minibuffer--double-dollars, read-file-name-internal):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93944
diff
changeset
|
1474 |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
1475 (defalias 'read-file-name-internal |
94055
ec343c7600a2
(completion--embedded-envvar-table, read-file-name-internal):
Juanma Barranquero <lekktu@gmail.com>
parents:
94017
diff
changeset
|
1476 (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
|
1477 'completion--file-name-table) |
94013
bd1b8b62427b
* minibuffer.el (complete-with-action, lazy-completion-table):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
93945
diff
changeset
|
1478 "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
|
1479 |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1480 (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
|
1481 "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
|
1482 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1483 (defcustom read-file-name-completion-ignore-case |
97179
e99e1b5c726e
(read-file-name-completion-ignore-case): Add cygwin to the list.
Chong Yidong <cyd@stupidchicken.com>
parents:
97142
diff
changeset
|
1484 (if (memq system-type '(ms-dos windows-nt darwin cygwin)) |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1485 t nil) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1486 "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
|
1487 :group 'minibuffer |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1488 :type 'boolean |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1489 :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
|
1490 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1491 (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
|
1492 "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
|
1493 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1494 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
|
1495 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
|
1496 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
|
1497 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1498 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
|
1499 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
|
1500 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
|
1501 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
|
1502 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
|
1503 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1504 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
|
1505 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
|
1506 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
|
1507 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
|
1508 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1509 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
|
1510 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
|
1511 `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
|
1512 :group 'minibuffer |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1513 :type 'boolean) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1514 |
94315
755dd4bba830
(x-file-dialog): Declare as function.
Glenn Morris <rgm@gnu.org>
parents:
94304
diff
changeset
|
1515 ;; 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
|
1516 (declare-function x-file-dialog "xfns.c" |
755dd4bba830
(x-file-dialog): Declare as function.
Glenn Morris <rgm@gnu.org>
parents:
94304
diff
changeset
|
1517 (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
|
1518 |
106239
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1519 (defun read-file-name-defaults (&optional dir initial) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1520 (let ((default |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1521 (cond |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1522 ;; With non-nil `initial', use `dir' as the first default. |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1523 ;; Essentially, this mean reversing the normal order of the |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1524 ;; current directory name and the current file name, i.e. |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1525 ;; 1. with normal file reading: |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1526 ;; 1.1. initial input is the current directory |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1527 ;; 1.2. the first default is the current file name |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1528 ;; 2. with non-nil `initial' (e.g. for `find-alternate-file'): |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1529 ;; 2.2. initial input is the current file name |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1530 ;; 2.1. the first default is the current directory |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1531 (initial (abbreviate-file-name dir)) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1532 ;; In file buffers, try to get the current file name |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1533 (buffer-file-name |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1534 (abbreviate-file-name buffer-file-name)))) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1535 (file-name-at-point |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1536 (run-hook-with-args-until-success 'file-name-at-point-functions))) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1537 (when file-name-at-point |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1538 (setq default (delete-dups |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1539 (delete "" (delq nil (list file-name-at-point default)))))) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1540 ;; Append new defaults to the end of existing `minibuffer-default'. |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1541 (append |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1542 (if (listp minibuffer-default) minibuffer-default (list minibuffer-default)) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1543 (if (listp default) default (list default))))) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1544 |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1545 (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
|
1546 "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
|
1547 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
|
1548 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
|
1549 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
|
1550 (If DEFAULT-FILENAME is omitted, the visited file name is used, |
105930
45b3f4e55e6e
(read-file-name): Support a list of default values
Juri Linkov <juri@jurta.org>
parents:
105824
diff
changeset
|
1551 except that if INITIAL is specified, that combined with DIR is used. |
45b3f4e55e6e
(read-file-name): Support a list of default values
Juri Linkov <juri@jurta.org>
parents:
105824
diff
changeset
|
1552 If DEFAULT-FILENAME is a list of file names, the first file name is used.) |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1553 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
|
1554 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
|
1555 pre-inserted contents or if `insert-default-directory' is nil.) |
102601
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1556 |
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1557 Fourth arg MUSTMATCH can take the following values: |
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1558 - nil means that the user can exit with any input. |
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1559 - t means that the user is not allowed to exit unless |
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1560 the input is (or completes to) an existing file. |
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1561 - `confirm' means that the user can exit with any input, but she needs |
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1562 to confirm her choice if the input is not an existing file. |
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1563 - `confirm-after-completion' means that the user can exit with any |
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1564 input, but she needs to confirm her choice if she called |
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1565 `minibuffer-complete' right before `minibuffer-complete-and-exit' |
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1566 and the input is not an existing file. |
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1567 - anything else behaves like t except that typing RET does not exit if it |
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1568 does non-null completion. |
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1569 |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1570 Fifth arg INITIAL specifies text to start with. |
102601
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1571 |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1572 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
|
1573 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
|
1574 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
|
1575 `default-directory'. |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1576 |
102601
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1577 If this command was invoked with the mouse, use a graphical file |
68c67342e3bf
(read-file-name): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents:
102579
diff
changeset
|
1578 dialog if `use-dialog-box' is non-nil, and the window system or X |
105824
06f1348e3279
* minibuffer.el (read-file-name): Don't use file dialogs for
Chong Yidong <cyd@stupidchicken.com>
parents:
105763
diff
changeset
|
1579 toolkit in use provides a file dialog box, and DIR is not a |
06f1348e3279
* minibuffer.el (read-file-name): Don't use file dialogs for
Chong Yidong <cyd@stupidchicken.com>
parents:
105763
diff
changeset
|
1580 remote file. For graphical file dialogs, any the special values |
06f1348e3279
* minibuffer.el (read-file-name): Don't use file dialogs for
Chong Yidong <cyd@stupidchicken.com>
parents:
105763
diff
changeset
|
1581 of MUSTMATCH; `confirm' and `confirm-after-completion' are |
06f1348e3279
* minibuffer.el (read-file-name): Don't use file dialogs for
Chong Yidong <cyd@stupidchicken.com>
parents:
105763
diff
changeset
|
1582 treated as equivalent to nil. |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1583 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1584 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
|
1585 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
|
1586 (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
|
1587 (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
|
1588 (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
|
1589 (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
|
1590 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
|
1591 ;; 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
|
1592 (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
|
1593 ;; 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
|
1594 (if default-filename |
105930
45b3f4e55e6e
(read-file-name): Support a list of default values
Juri Linkov <juri@jurta.org>
parents:
105824
diff
changeset
|
1595 (setq default-filename |
45b3f4e55e6e
(read-file-name): Support a list of default values
Juri Linkov <juri@jurta.org>
parents:
105824
diff
changeset
|
1596 (if (consp default-filename) |
45b3f4e55e6e
(read-file-name): Support a list of default values
Juri Linkov <juri@jurta.org>
parents:
105824
diff
changeset
|
1597 (mapcar 'abbreviate-file-name default-filename) |
45b3f4e55e6e
(read-file-name): Support a list of default values
Juri Linkov <juri@jurta.org>
parents:
105824
diff
changeset
|
1598 (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
|
1599 (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
|
1600 ((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
|
1601 (if initial |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1602 (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
|
1603 (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
|
1604 (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
|
1605 (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
|
1606 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1607 (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
|
1608 (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
|
1609 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
|
1610 (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
|
1611 (minibuffer-completing-file-name t) |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1612 (pred (or predicate 'file-exists-p)) |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1613 (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
|
1614 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1615 (let* ((val |
105824
06f1348e3279
* minibuffer.el (read-file-name): Don't use file dialogs for
Chong Yidong <cyd@stupidchicken.com>
parents:
105763
diff
changeset
|
1616 (if (or (not (next-read-file-uses-dialog-p)) |
06f1348e3279
* minibuffer.el (read-file-name): Don't use file dialogs for
Chong Yidong <cyd@stupidchicken.com>
parents:
105763
diff
changeset
|
1617 ;; Graphical file dialogs can't handle remote |
06f1348e3279
* minibuffer.el (read-file-name): Don't use file dialogs for
Chong Yidong <cyd@stupidchicken.com>
parents:
105763
diff
changeset
|
1618 ;; files (Bug#99). |
06f1348e3279
* minibuffer.el (read-file-name): Don't use file dialogs for
Chong Yidong <cyd@stupidchicken.com>
parents:
105763
diff
changeset
|
1619 (file-remote-p dir)) |
94301
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1620 ;; 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
|
1621 ;; 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
|
1622 ;; 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
|
1623 ;; 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
|
1624 ;; 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
|
1625 (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
|
1626 (expand-file-name dir)))) |
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1627 (minibuffer-with-setup-hook |
106239
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1628 (lambda () |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1629 (setq default-directory dir) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1630 ;; When the first default in `minibuffer-default' |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1631 ;; duplicates initial input `insdef', |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1632 ;; reset `minibuffer-default' to nil. |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1633 (when (equal (or (car-safe insdef) insdef) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1634 (or (car-safe minibuffer-default) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1635 minibuffer-default)) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1636 (setq minibuffer-default |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1637 (cdr-safe minibuffer-default))) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1638 ;; On the first request on `M-n' fill |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1639 ;; `minibuffer-default' with a list of defaults |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1640 ;; relevant for file-name reading. |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1641 (set (make-local-variable 'minibuffer-default-add-function) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1642 (lambda () |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1643 (with-current-buffer |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1644 (window-buffer (minibuffer-selected-window)) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
1645 (read-file-name-defaults dir initial))))) |
94301
9060af7294b9
(read-file-name): Don't let-bind default-directory.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94300
diff
changeset
|
1646 (completing-read prompt 'read-file-name-internal |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1647 pred mustmatch insdef |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1648 'file-name-history default-filename))) |
102455
03ed2dba14f6
(read-file-name): Only split dir name when
Jason Rumney <jasonr@gnu.org>
parents:
101999
diff
changeset
|
1649 ;; If DEFAULT-FILENAME not supplied and DIR contains |
03ed2dba14f6
(read-file-name): Only split dir name when
Jason Rumney <jasonr@gnu.org>
parents:
101999
diff
changeset
|
1650 ;; a file name, split it. |
104122
9fb3df55079f
(read-file-name): Treat confirm options to
Jason Rumney <jasonr@gnu.org>
parents:
102958
diff
changeset
|
1651 (let ((file (file-name-nondirectory dir)) |
9fb3df55079f
(read-file-name): Treat confirm options to
Jason Rumney <jasonr@gnu.org>
parents:
102958
diff
changeset
|
1652 ;; When using a dialog, revert to nil and non-nil |
9fb3df55079f
(read-file-name): Treat confirm options to
Jason Rumney <jasonr@gnu.org>
parents:
102958
diff
changeset
|
1653 ;; interpretation of mustmatch. confirm options |
9fb3df55079f
(read-file-name): Treat confirm options to
Jason Rumney <jasonr@gnu.org>
parents:
102958
diff
changeset
|
1654 ;; need to be interpreted as nil, otherwise |
9fb3df55079f
(read-file-name): Treat confirm options to
Jason Rumney <jasonr@gnu.org>
parents:
102958
diff
changeset
|
1655 ;; it is impossible to create new files using |
9fb3df55079f
(read-file-name): Treat confirm options to
Jason Rumney <jasonr@gnu.org>
parents:
102958
diff
changeset
|
1656 ;; dialogs with the default settings. |
9fb3df55079f
(read-file-name): Treat confirm options to
Jason Rumney <jasonr@gnu.org>
parents:
102958
diff
changeset
|
1657 (dialog-mustmatch |
105697
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1658 (not (memq mustmatch |
136cf2d23c90
* minibuffer.el (completion-table-with-terminator): Properly implement
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105664
diff
changeset
|
1659 '(nil confirm confirm-after-completion))))) |
102455
03ed2dba14f6
(read-file-name): Only split dir name when
Jason Rumney <jasonr@gnu.org>
parents:
101999
diff
changeset
|
1660 (when (and (not default-filename) |
03ed2dba14f6
(read-file-name): Only split dir name when
Jason Rumney <jasonr@gnu.org>
parents:
101999
diff
changeset
|
1661 (not (zerop (length file)))) |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1662 (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
|
1663 (setq dir (file-name-directory dir))) |
105930
45b3f4e55e6e
(read-file-name): Support a list of default values
Juri Linkov <juri@jurta.org>
parents:
105824
diff
changeset
|
1664 (when default-filename |
45b3f4e55e6e
(read-file-name): Support a list of default values
Juri Linkov <juri@jurta.org>
parents:
105824
diff
changeset
|
1665 (setq default-filename |
45b3f4e55e6e
(read-file-name): Support a list of default values
Juri Linkov <juri@jurta.org>
parents:
105824
diff
changeset
|
1666 (expand-file-name (if (consp default-filename) |
45b3f4e55e6e
(read-file-name): Support a list of default values
Juri Linkov <juri@jurta.org>
parents:
105824
diff
changeset
|
1667 (car default-filename) |
45b3f4e55e6e
(read-file-name): Support a list of default values
Juri Linkov <juri@jurta.org>
parents:
105824
diff
changeset
|
1668 default-filename) |
45b3f4e55e6e
(read-file-name): Support a list of default values
Juri Linkov <juri@jurta.org>
parents:
105824
diff
changeset
|
1669 dir))) |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1670 (setq add-to-history t) |
104122
9fb3df55079f
(read-file-name): Treat confirm options to
Jason Rumney <jasonr@gnu.org>
parents:
102958
diff
changeset
|
1671 (x-file-dialog prompt dir default-filename |
9fb3df55079f
(read-file-name): Treat confirm options to
Jason Rumney <jasonr@gnu.org>
parents:
102958
diff
changeset
|
1672 dialog-mustmatch |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1673 (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
|
1674 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1675 (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
|
1676 ;; 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
|
1677 ;; (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
|
1678 ;; 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
|
1679 ;; 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
|
1680 ;; so that commands such as set-visited-file-name can distinguish. |
105930
45b3f4e55e6e
(read-file-name): Support a list of default values
Juri Linkov <juri@jurta.org>
parents:
105824
diff
changeset
|
1681 (when (consp default-filename) |
45b3f4e55e6e
(read-file-name): Support a list of default values
Juri Linkov <juri@jurta.org>
parents:
105824
diff
changeset
|
1682 (setq default-filename (car 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
|
1683 (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
|
1684 ;; 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
|
1685 ;; 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
|
1686 (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
|
1687 (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
|
1688 (setq val "")) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1689 (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
|
1690 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1691 (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
|
1692 (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
|
1693 (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
|
1694 (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
|
1695 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1696 (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
|
1697 ;; Replace what Fcompleting_read added to the history |
105664
6a6fcf3e8e4d
* minibuffer.el (read-file-name): Check for repeat before putting
Chong Yidong <cyd@stupidchicken.com>
parents:
105601
diff
changeset
|
1698 ;; with what we will actually return. As an exception, |
6a6fcf3e8e4d
* minibuffer.el (read-file-name): Check for repeat before putting
Chong Yidong <cyd@stupidchicken.com>
parents:
105601
diff
changeset
|
1699 ;; if that's the same as the second item in |
6a6fcf3e8e4d
* minibuffer.el (read-file-name): Check for repeat before putting
Chong Yidong <cyd@stupidchicken.com>
parents:
105601
diff
changeset
|
1700 ;; file-name-history, it's really a repeat (Bug#4657). |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1701 (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
|
1702 (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
|
1703 (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
|
1704 (delete val1 (cdr file-name-history)))) |
105664
6a6fcf3e8e4d
* minibuffer.el (read-file-name): Check for repeat before putting
Chong Yidong <cyd@stupidchicken.com>
parents:
105601
diff
changeset
|
1705 (if (string= val1 (cadr file-name-history)) |
6a6fcf3e8e4d
* minibuffer.el (read-file-name): Check for repeat before putting
Chong Yidong <cyd@stupidchicken.com>
parents:
105601
diff
changeset
|
1706 (pop file-name-history) |
6a6fcf3e8e4d
* minibuffer.el (read-file-name): Check for repeat before putting
Chong Yidong <cyd@stupidchicken.com>
parents:
105601
diff
changeset
|
1707 (setcar file-name-history val1))) |
94300
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1708 (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
|
1709 ;; 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
|
1710 ;; 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
|
1711 (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
|
1712 (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
|
1713 (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
|
1714 (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
|
1715 (cons val1 |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1716 (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
|
1717 (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
|
1718 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
|
1719 val))))) |
b47239d57d36
* lisp/minibuffer.el (read-file-name-function, read-file-name-predicate)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94247
diff
changeset
|
1720 |
94247
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1721 (defun internal-complete-buffer-except (&optional buffer) |
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1722 "Perform completion on all buffers excluding BUFFER. |
101999
efada72951fb
* minibuffer.el (internal-complete-buffer-except): Doc fix. (Bug#2315)
Juanma Barranquero <lekktu@gmail.com>
parents:
101327
diff
changeset
|
1723 BUFFER nil or omitted means use the current buffer. |
94247
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1724 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
|
1725 (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
|
1726 (apply-partially 'completion-table-with-predicate |
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1727 'internal-complete-buffer |
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1728 (lambda (name) |
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1729 (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
|
1730 nil))) |
57c8f6a6456a
(internal-complete-buffer-except): New function.
Juri Linkov <juri@jurta.org>
parents:
94242
diff
changeset
|
1731 |
95799
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1732 ;;; Old-style completion, used in Emacs-21 and Emacs-22. |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1733 |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1734 (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
|
1735 (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
|
1736 (if (stringp completion) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1737 (cons completion (length completion)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1738 completion))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1739 |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1740 (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
|
1741 (completion-hilit-commonality |
95799
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1742 (all-completions string table pred) |
100623
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1743 (length string) |
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1744 (car (completion-boundaries string table pred "")))) |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1745 |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1746 (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
|
1747 (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
|
1748 (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
|
1749 (if (not (stringp completion)) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1750 completion |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1751 ;; 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
|
1752 ;; 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
|
1753 ;; sense for all completions. |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1754 ;; 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
|
1755 ;; 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
|
1756 ;; 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
|
1757 ;; 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
|
1758 (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
|
1759 (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
|
1760 (not (zerop (length suffix))) |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1761 (eq ?/ (aref suffix 0))) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1762 ;; This leaves point after the / . |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1763 (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
|
1764 (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
|
1765 |
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1766 (defun completion-emacs22-all-completions (string table pred point) |
100623
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1767 (let ((beforepoint (substring string 0 point))) |
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1768 (completion-hilit-commonality |
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1769 (all-completions beforepoint table pred) |
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1770 point |
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1771 (car (completion-boundaries beforepoint table pred ""))))) |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1772 |
95799
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1773 ;;; Basic completion. |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1774 |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1775 (defun completion--merge-suffix (completion point suffix) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1776 "Merge end of COMPLETION with beginning of SUFFIX. |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1777 Simple generalization of the \"merge trailing /\" done in Emacs-22. |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1778 Return the new suffix." |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1779 (if (and (not (zerop (length suffix))) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1780 (string-match "\\(.+\\)\n\\1" (concat completion "\n" suffix) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1781 ;; Make sure we don't compress things to less |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1782 ;; than we started with. |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1783 point) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1784 ;; Just make sure we didn't match some other \n. |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1785 (eq (match-end 1) (length completion))) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1786 (substring suffix (- (match-end 1) (match-beginning 1))) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1787 ;; Nothing to merge. |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1788 suffix)) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1789 |
107461
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
1790 (defun completion-basic--pattern (beforepoint afterpoint bounds) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
1791 (delete |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
1792 "" (list (substring beforepoint (car bounds)) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
1793 'point |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
1794 (substring afterpoint 0 (cdr bounds))))) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
1795 |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1796 (defun completion-basic-try-completion (string table pred point) |
110842
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1797 (lexical-let* |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1798 ((beforepoint (substring string 0 point)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1799 (afterpoint (substring string point)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1800 (bounds (completion-boundaries beforepoint table pred afterpoint))) |
96294
f12e581d977f
(completion-basic-try-completion): Use the text after
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95799
diff
changeset
|
1801 (if (zerop (cdr bounds)) |
f12e581d977f
(completion-basic-try-completion): Use the text after
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95799
diff
changeset
|
1802 ;; `try-completion' may return a subtly different result |
f12e581d977f
(completion-basic-try-completion): Use the text after
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95799
diff
changeset
|
1803 ;; than `all+merge', so try to use it whenever possible. |
f12e581d977f
(completion-basic-try-completion): Use the text after
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95799
diff
changeset
|
1804 (let ((completion (try-completion beforepoint table pred))) |
f12e581d977f
(completion-basic-try-completion): Use the text after
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95799
diff
changeset
|
1805 (if (not (stringp completion)) |
f12e581d977f
(completion-basic-try-completion): Use the text after
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95799
diff
changeset
|
1806 completion |
f12e581d977f
(completion-basic-try-completion): Use the text after
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95799
diff
changeset
|
1807 (cons |
f12e581d977f
(completion-basic-try-completion): Use the text after
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95799
diff
changeset
|
1808 (concat completion |
f12e581d977f
(completion-basic-try-completion): Use the text after
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95799
diff
changeset
|
1809 (completion--merge-suffix completion point afterpoint)) |
f12e581d977f
(completion-basic-try-completion): Use the text after
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95799
diff
changeset
|
1810 (length completion)))) |
110842
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1811 (lexical-let* |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1812 ((suffix (substring afterpoint (cdr bounds))) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1813 (prefix (substring beforepoint 0 (car bounds))) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1814 (pattern (delete |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1815 "" (list (substring beforepoint (car bounds)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1816 'point |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1817 (substring afterpoint 0 (cdr bounds))))) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1818 (all (completion-pcm--all-completions prefix pattern table pred))) |
96294
f12e581d977f
(completion-basic-try-completion): Use the text after
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95799
diff
changeset
|
1819 (if minibuffer-completing-file-name |
f12e581d977f
(completion-basic-try-completion): Use the text after
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95799
diff
changeset
|
1820 (setq all (completion-pcm--filename-try-filter all))) |
f12e581d977f
(completion-basic-try-completion): Use the text after
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95799
diff
changeset
|
1821 (completion-pcm--merge-try pattern all prefix suffix))))) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1822 |
96294
f12e581d977f
(completion-basic-try-completion): Use the text after
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95799
diff
changeset
|
1823 (defun completion-basic-all-completions (string table pred point) |
110842
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1824 (lexical-let* |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1825 ((beforepoint (substring string 0 point)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1826 (afterpoint (substring string point)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1827 (bounds (completion-boundaries beforepoint table pred afterpoint)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1828 (suffix (substring afterpoint (cdr bounds))) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1829 (prefix (substring beforepoint 0 (car bounds))) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1830 (pattern (delete |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1831 "" (list (substring beforepoint (car bounds)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1832 'point |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1833 (substring afterpoint 0 (cdr bounds))))) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1834 (all (completion-pcm--all-completions prefix pattern table pred))) |
100623
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1835 (completion-hilit-commonality all point (car bounds)))) |
94304
bc48ced5cf89
(completion-try-completion): Add `point' argument. Change return value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94301
diff
changeset
|
1836 |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1837 ;;; Partial-completion-mode style completion. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1838 |
104344
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1839 (defvar completion-pcm--delim-wild-regex nil |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1840 "Regular expression matching delimiters controlling the partial-completion. |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1841 Typically, this regular expression simply matches a delimiter, meaning |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1842 that completion can add something at (match-beginning 0), but if it has |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1843 a submatch 1, then completion can add something at (match-end 1). |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1844 This is used when the delimiter needs to be of size zero (e.g. the transition |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1845 from lowercase to uppercase characters).") |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1846 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1847 (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
|
1848 (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
|
1849 |
106453
eaa5eba6d613
(minibuffer-complete-and-exit): Don't replace the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106452
diff
changeset
|
1850 (defcustom completion-pcm-word-delimiters "-_./: " |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1851 "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
|
1852 Some arcane rules: |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1853 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
|
1854 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
|
1855 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
|
1856 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
|
1857 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
|
1858 :set (lambda (symbol value) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1859 (set-default symbol value) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1860 ;; Refresh other vars. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1861 (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
|
1862 :initialize 'custom-initialize-reset |
94375
f8b940834bbb
(completion-pcm-word-delimiters): Add :group.
Juanma Barranquero <lekktu@gmail.com>
parents:
94352
diff
changeset
|
1863 :group 'minibuffer |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1864 :type 'string) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1865 |
108378
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1866 (defcustom completion-pcm-complete-word-inserts-delimiters nil |
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1867 "Treat the SPC or - inserted by `minibuffer-complete-word' as delimiters. |
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1868 Those chars are treated as delimiters iff this variable is non-nil. |
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1869 I.e. if non-nil, M-x SPC will just insert a \"-\" in the minibuffer, whereas |
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1870 if nil, it will list all possible commands in *Completions* because none of |
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1871 the commands start with a \"-\" or a SPC." |
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1872 :type 'boolean) |
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1873 |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1874 (defun completion-pcm--pattern-trivial-p (pattern) |
100929
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1875 (and (stringp (car pattern)) |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1876 ;; It can be followed by `point' and "" and still be trivial. |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1877 (let ((trivial t)) |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1878 (dolist (elem (cdr pattern)) |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1879 (unless (member elem '(point "")) |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1880 (setq trivial nil))) |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1881 trivial))) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1882 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1883 (defun completion-pcm--string->pattern (string &optional point) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1884 "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
|
1885 A pattern is a list where each element is either a string |
108378
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1886 or a symbol chosen among `any', `star', `point', `prefix'." |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1887 (if (and point (< point (length string))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1888 (let ((prefix (substring string 0 point)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1889 (suffix (substring string point))) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1890 (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
|
1891 '(point) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1892 (completion-pcm--string->pattern suffix))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1893 (let ((pattern nil) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1894 (p 0) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1895 (p0 0)) |
94375
f8b940834bbb
(completion-pcm-word-delimiters): Add :group.
Juanma Barranquero <lekktu@gmail.com>
parents:
94352
diff
changeset
|
1896 |
104344
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1897 (while (and (setq p (string-match completion-pcm--delim-wild-regex |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1898 string p)) |
108378
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1899 (or completion-pcm-complete-word-inserts-delimiters |
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1900 ;; If the char was added by minibuffer-complete-word, |
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1901 ;; then don't treat it as a delimiter, otherwise |
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1902 ;; "M-x SPC" ends up inserting a "-" rather than listing |
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1903 ;; all completions. |
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1904 (not (get-text-property p 'completion-try-word string)))) |
104344
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1905 ;; Usually, completion-pcm--delim-wild-regex matches a delimiter, |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1906 ;; meaning that something can be added *before* it, but it can also |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1907 ;; match a prefix and postfix, in which case something can be added |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1908 ;; in-between (e.g. match [[:lower:]][[:upper:]]). |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1909 ;; This is determined by the presence of a submatch-1 which delimits |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1910 ;; the prefix. |
ffa2f09da5b2
(minibuffer-hide-completions): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104342
diff
changeset
|
1911 (if (match-end 1) (setq p (match-end 1))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1912 (push (substring string p0 p) pattern) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1913 (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
|
1914 (progn |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1915 (push 'star pattern) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1916 (setq p0 (1+ p))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1917 (push 'any pattern) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1918 (setq p0 p)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1919 (incf p)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1920 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1921 ;; 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
|
1922 ;; 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
|
1923 (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
|
1924 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1925 (defun completion-pcm--pattern->regex (pattern &optional group) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1926 (let ((re |
104719
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1927 (concat "\\`" |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1928 (mapconcat |
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1929 (lambda (x) |
108378
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1930 (cond |
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
1931 ((stringp x) (regexp-quote x)) |
108486
7b8ec1ad0223
* minibuffer.el (completion-pcm--pattern->regex): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108378
diff
changeset
|
1932 ((if (consp group) (memq x group) group) "\\(.*?\\)") |
7b8ec1ad0223
* minibuffer.el (completion-pcm--pattern->regex): Fix last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108378
diff
changeset
|
1933 (t ".*?"))) |
104719
8f0f04f98654
(minibuffer-message): If the current buffer is not
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104344
diff
changeset
|
1934 pattern |
97966
52f84cb577bb
(completion-pcm--pattern->regex): Undo last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
97934
diff
changeset
|
1935 "")))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1936 ;; Avoid pathological backtracking. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1937 (while (string-match "\\.\\*\\?\\(?:\\\\[()]\\)*\\(\\.\\*\\?\\)" re) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1938 (setq re (replace-match "" t t re 1))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1939 re)) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1940 |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1941 (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
|
1942 "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
|
1943 PATTERN is as returned by `completion-pcm--string->pattern'." |
100623
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1944 ;; (assert (= (car (completion-boundaries prefix table pred "")) |
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1945 ;; (length prefix))) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1946 ;; 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
|
1947 (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
|
1948 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1949 ;; Minibuffer contains no delimiters -- simple case! |
100623
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1950 (all-completions (concat prefix (car pattern)) table pred) |
94375
f8b940834bbb
(completion-pcm-word-delimiters): Add :group.
Juanma Barranquero <lekktu@gmail.com>
parents:
94352
diff
changeset
|
1951 |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1952 ;; 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
|
1953 ;; 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
|
1954 (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
|
1955 (regex (completion-pcm--pattern->regex pattern)) |
97966
52f84cb577bb
(completion-pcm--pattern->regex): Undo last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
97934
diff
changeset
|
1956 (case-fold-search completion-ignore-case) |
52f84cb577bb
(completion-pcm--pattern->regex): Undo last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
97934
diff
changeset
|
1957 (completion-regexp-list (cons regex completion-regexp-list)) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1958 (compl (all-completions |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
1959 (concat prefix (if (stringp (car pattern)) (car pattern) "")) |
100623
5a144164af93
(completion-all-completions-with-base-size): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100052
diff
changeset
|
1960 table pred))) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1961 (if (not (functionp table)) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1962 ;; 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
|
1963 compl |
97966
52f84cb577bb
(completion-pcm--pattern->regex): Undo last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
97934
diff
changeset
|
1964 (let ((poss ())) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1965 (dolist (c compl) |
101162
64a6da0f9aa2
* minibuffer.el (minibuffer-message): Fix regexp so it doesn't exclude
Juanma Barranquero <lekktu@gmail.com>
parents:
101010
diff
changeset
|
1966 (when (string-match-p regex c) (push c poss))) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1967 poss))))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
1968 |
94465
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1969 (defun completion-pcm--hilit-commonality (pattern completions) |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1970 (when completions |
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1971 (let* ((re (completion-pcm--pattern->regex pattern '(point))) |
100929
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1972 (case-fold-search completion-ignore-case)) |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1973 (mapcar |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1974 (lambda (str) |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1975 ;; Don't modify the string itself. |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1976 (setq str (copy-sequence str)) |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1977 (unless (string-match re str) |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1978 (error "Internal error: %s does not match %s" re str)) |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1979 (let ((pos (or (match-beginning 1) (match-end 0)))) |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1980 (put-text-property 0 pos |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1981 'font-lock-face 'completions-common-part |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1982 str) |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1983 (if (> (length str) pos) |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1984 (put-text-property pos (1+ pos) |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1985 'font-lock-face 'completions-first-difference |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1986 str))) |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1987 str) |
2677429036c3
(completion-hilit-commonality): Don't presume
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
100908
diff
changeset
|
1988 completions)))) |
94465
e2562e0fe05e
(completion-hilit-commonality): Remove leftover code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94464
diff
changeset
|
1989 |
95799
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1990 (defun completion-pcm--find-all-completions (string table pred point |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1991 &optional filter) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1992 "Find all completions for STRING at POINT in TABLE, satisfying PRED. |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1993 POINT is a position inside STRING. |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1994 FILTER is a function applied to the return value, that can be used, e.g. to |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1995 filter out additional entries (because TABLE migth not obey PRED)." |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
1996 (unless filter (setq filter 'identity)) |
110842
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1997 (lexical-let* |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1998 ((beforepoint (substring string 0 point)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
1999 (afterpoint (substring string point)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
2000 (bounds (completion-boundaries beforepoint table pred afterpoint)) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
2001 (prefix (substring beforepoint 0 (car bounds))) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
2002 (suffix (substring afterpoint (cdr bounds))) |
e4f63401c6eb
Use lexical-let to avoid false matches in var completion (Bug#7056).
Chong Yidong <cyd@stupidchicken.com>
parents:
110832
diff
changeset
|
2003 firsterror) |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
2004 (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
|
2005 (let* ((relpoint (- point (car bounds))) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
2006 (pattern (completion-pcm--string->pattern string relpoint)) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2007 (all (condition-case err |
95799
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2008 (funcall filter |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2009 (completion-pcm--all-completions |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2010 prefix pattern table pred)) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2011 (error (unless firsterror (setq firsterror err)) nil)))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2012 (when (and (null all) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2013 (> (car bounds) 0) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2014 (null (ignore-errors (try-completion prefix table pred)))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2015 ;; 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
|
2016 ;; that first. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2017 (let ((substring (substring prefix 0 -1))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2018 (destructuring-bind (subpat suball subprefix subsuffix) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2019 (completion-pcm--find-all-completions |
95799
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2020 substring table pred (length substring) filter) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2021 (let ((sep (aref prefix (1- (length prefix)))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2022 ;; Text that goes between the new submatches and the |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2023 ;; completion substring. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2024 (between nil)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2025 ;; Eliminate submatches that don't end with the separator. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2026 (dolist (submatch (prog1 suball (setq suball ()))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2027 (when (eq sep (aref submatch (1- (length submatch)))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2028 (push submatch suball))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2029 (when suball |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2030 ;; Update the boundaries and corresponding pattern. |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2031 ;; 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
|
2032 ;; 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
|
2033 ;; FIXME: COMPLETE REWRITE!!! |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
2034 (let* ((newbeforepoint |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
2035 (concat subprefix (car suball) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
2036 (substring string 0 relpoint))) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
2037 (leftbound (+ (length subprefix) (length (car suball)))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2038 (newbounds (completion-boundaries |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
2039 newbeforepoint table pred afterpoint))) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
2040 (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
|
2041 (eq (car newbounds) leftbound)) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2042 ;; Refuse new boundaries if they step over |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2043 ;; the submatch. |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
2044 (< (car newbounds) leftbound)) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2045 ;; The new completed prefix does change the boundaries |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2046 ;; of the completed substring. |
95228
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
2047 (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
|
2048 (setq string |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
2049 (concat (substring newbeforepoint (car newbounds)) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
2050 (substring afterpoint 0 (cdr newbounds)))) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
2051 (setq between (substring newbeforepoint leftbound |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2052 (car newbounds))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2053 (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
|
2054 string |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
2055 (- (length newbeforepoint) |
451f4028c096
* minibuffer.el (completion-boundaries): Change calling convention, so
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95192
diff
changeset
|
2056 (car newbounds))))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2057 (dolist (submatch suball) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2058 (setq all (nconc (mapcar |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2059 (lambda (s) (concat submatch between s)) |
95799
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2060 (funcall filter |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2061 (completion-pcm--all-completions |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2062 (concat subprefix submatch between) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2063 pattern table pred))) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2064 all))) |
95192
042486c3318c
(completion-pcm--find-all-completions): Don't add pseudo-completions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95172
diff
changeset
|
2065 ;; 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
|
2066 ;; 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
|
2067 ;; invalid completions. |
042486c3318c
(completion-pcm--find-all-completions): Don't add pseudo-completions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95172
diff
changeset
|
2068 ;; (unless all |
042486c3318c
(completion-pcm--find-all-completions): Don't add pseudo-completions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95172
diff
changeset
|
2069 ;; ;; 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
|
2070 ;; ;; 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
|
2071 ;; ;; 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
|
2072 ;; (dolist (submatch suball) |
042486c3318c
(completion-pcm--find-all-completions): Don't add pseudo-completions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95172
diff
changeset
|
2073 ;; (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
|
2074 )) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2075 (setq pattern (append subpat (list 'any (string sep)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2076 (if between (list between)) pattern)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2077 (setq prefix subprefix))))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2078 (if (and (null all) firsterror) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2079 (signal (car firsterror) (cdr firsterror)) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2080 (list pattern all prefix suffix))))) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2081 |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2082 (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
|
2083 (destructuring-bind (pattern all &optional prefix suffix) |
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2084 (completion-pcm--find-all-completions string table pred point) |
95394
119c6508d4f8
(completion-pcm-all-completions): Add the base-size.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95228
diff
changeset
|
2085 (when all |
119c6508d4f8
(completion-pcm-all-completions): Add the base-size.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95228
diff
changeset
|
2086 (nconc (completion-pcm--hilit-commonality pattern all) |
119c6508d4f8
(completion-pcm-all-completions): Add the base-size.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95228
diff
changeset
|
2087 (length prefix))))) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2088 |
108251
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2089 (defun completion--sreverse (str) |
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2090 "Like `reverse' but for a string STR rather than a list." |
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2091 (apply 'string (nreverse (mapcar 'identity str)))) |
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2092 |
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2093 (defun completion--common-suffix (strs) |
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2094 "Return the common suffix of the strings STRS." |
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2095 (completion--sreverse |
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2096 (try-completion |
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2097 "" |
108296
d46fdf06e110
* files.el (auto-save-mode): Move to simple.el to fix bootstrap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108281
diff
changeset
|
2098 (mapcar 'completion--sreverse strs)))) |
108251
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2099 |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2100 (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
|
2101 "Extract the commonality in STRS, with the help of PATTERN." |
105597
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2102 ;; When completing while ignoring case, we want to try and avoid |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2103 ;; completing "fo" to "foO" when completing against "FOO" (bug#4219). |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2104 ;; So we try and make sure that the string we return is all made up |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2105 ;; of text from the completions rather than part from the |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2106 ;; completions and part from the input. |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2107 ;; FIXME: This reduces the problems of inconsistent capitalization |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2108 ;; but it doesn't fully fix it: we may still end up completing |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2109 ;; "fo-ba" to "foo-BAR" or "FOO-bar" when completing against |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2110 ;; '("foo-barr" "FOO-BARD"). |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2111 (cond |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2112 ((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
|
2113 (t |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2114 (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
|
2115 (ccs ())) ;Chopped completions. |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2116 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2117 ;; 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
|
2118 ;; 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
|
2119 (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
|
2120 (dolist (str strs) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2121 (unless (string-match re str) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2122 (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
|
2123 (let ((chopped ()) |
105597
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2124 (last 0) |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2125 (i 1) |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2126 next) |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2127 (while (setq next (match-end i)) |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2128 (push (substring str last next) chopped) |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2129 (setq last next) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2130 (setq i (1+ i))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2131 ;; Add the text corresponding to the implicit trailing `any'. |
105597
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2132 (push (substring str last) chopped) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2133 (push (nreverse chopped) ccs)))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2134 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2135 ;; 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
|
2136 ;; commonality between them. |
105597
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2137 (let ((res ()) |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2138 (fixed "")) |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2139 ;; Make the implicit trailing `any' explicit. |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2140 (dolist (elem (append pattern '(any))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2141 (if (stringp elem) |
105597
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2142 (setq fixed (concat fixed elem)) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2143 (let ((comps ())) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2144 (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
|
2145 (push (car cc) comps) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2146 (push (cdr cc) ccs)) |
105597
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2147 ;; Might improve the likelihood to avoid choosing |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2148 ;; different capitalizations in different parts. |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2149 ;; In practice, it doesn't seem to make any difference. |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2150 (setq ccs (nreverse ccs)) |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2151 (let* ((prefix (try-completion fixed comps)) |
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2152 (unique (or (and (eq prefix t) (setq prefix fixed)) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2153 (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
|
2154 (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
|
2155 ;; 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
|
2156 ;; 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
|
2157 ;; 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
|
2158 ;; `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
|
2159 ;; 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
|
2160 ;; here any more. |
108251
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2161 (unless unique |
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2162 (push elem res) |
108378
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
2163 (when (memq elem '(star point prefix)) |
108251
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2164 ;; Extract common suffix additionally to common prefix. |
108378
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
2165 ;; Only do it for `point', `star', and `prefix' since for |
108251
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2166 ;; `any' it could lead to a merged completion that |
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2167 ;; doesn't itself match the candidates. |
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2168 (let ((suffix (completion--common-suffix comps))) |
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2169 (assert (stringp suffix)) |
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2170 (unless (equal suffix "") |
275d802c8570
Extract common suffix for * in partial-completion.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108179
diff
changeset
|
2171 (push suffix res))))) |
105597
117859152fa5
(completion-pcm--merge-completions): Make sure the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105589
diff
changeset
|
2172 (setq fixed ""))))) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2173 ;; 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
|
2174 res))))) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2175 |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2176 (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
|
2177 (mapconcat (lambda (x) (cond |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2178 ((stringp x) x) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2179 ((eq x 'star) "*") |
108378
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
2180 (t ""))) ;any, point, prefix. |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2181 pattern |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2182 "")) |
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2183 |
95799
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2184 ;; We want to provide the functionality of `try', but we use `all' |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2185 ;; and then merge it. In most cases, this works perfectly, but |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2186 ;; if the completion table doesn't consider the same completions in |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2187 ;; `try' as in `all', then we have a problem. The most common such |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2188 ;; case is for filename completion where completion-ignored-extensions |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2189 ;; is only obeyed by the `try' code. We paper over the difference |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2190 ;; here. Note that it is not quite right either: if the completion |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2191 ;; table uses completion-table-in-turn, this filtering may take place |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2192 ;; too late to correctly fallback from the first to the |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2193 ;; second alternative. |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2194 (defun completion-pcm--filename-try-filter (all) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2195 "Filter to adjust `all' file completion to the behavior of `try'." |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2196 (when all |
95799
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2197 (let ((try ()) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2198 (re (concat "\\(?:\\`\\.\\.?/\\|" |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2199 (regexp-opt completion-ignored-extensions) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2200 "\\)\\'"))) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2201 (dolist (f all) |
101162
64a6da0f9aa2
* minibuffer.el (minibuffer-message): Fix regexp so it doesn't exclude
Juanma Barranquero <lekktu@gmail.com>
parents:
101010
diff
changeset
|
2202 (unless (string-match-p re f) (push f try))) |
95799
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2203 (or try all)))) |
101162
64a6da0f9aa2
* minibuffer.el (minibuffer-message): Fix regexp so it doesn't exclude
Juanma Barranquero <lekktu@gmail.com>
parents:
101010
diff
changeset
|
2204 |
95799
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2205 |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2206 (defun completion-pcm--merge-try (pattern all prefix suffix) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2207 (cond |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2208 ((not (consp all)) all) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2209 ((and (not (consp (cdr all))) ;Only one completion. |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2210 ;; Ignore completion-ignore-case here. |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2211 (equal (completion-pcm--pattern->string pattern) (car all))) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2212 t) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2213 (t |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2214 (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
|
2215 ;; `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
|
2216 ;; 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
|
2217 ;; 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
|
2218 ;; at the very end. |
106413
ab53cadac0b6
(completion-pcm--merge-try): Also consider placing point after a star, if
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106239
diff
changeset
|
2219 (pointpat (or (memq 'point mergedpat) |
ab53cadac0b6
(completion-pcm--merge-try): Also consider placing point after a star, if
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106239
diff
changeset
|
2220 (memq 'any mergedpat) |
ab53cadac0b6
(completion-pcm--merge-try): Also consider placing point after a star, if
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106239
diff
changeset
|
2221 (memq 'star mergedpat) |
108378
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
2222 ;; Not `prefix'. |
94487
432e68e359fa
(completion-pcm-try-completion): Typo.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94486
diff
changeset
|
2223 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
|
2224 ;; 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
|
2225 (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
|
2226 ;; 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
|
2227 (merged (completion-pcm--pattern->string (nreverse mergedpat)))) |
95799
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2228 |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2229 (setq suffix (completion--merge-suffix merged newpos suffix)) |
95145
096cfec41046
(completion-boundaries): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94736
diff
changeset
|
2230 (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
|
2231 |
95799
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2232 (defun completion-pcm-try-completion (string table pred point) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2233 (destructuring-bind (pattern all prefix suffix) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2234 (completion-pcm--find-all-completions |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2235 string table pred point |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2236 (if minibuffer-completing-file-name |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2237 'completion-pcm--filename-try-filter)) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2238 (completion-pcm--merge-try pattern all prefix suffix))) |
b0653ad2932d
(completion--merge-suffix): New function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
95671
diff
changeset
|
2239 |
107461
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2240 ;;; Substring completion |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2241 ;; Mostly derived from the code of `basic' completion. |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2242 |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2243 (defun completion-substring--all-completions (string table pred point) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2244 (let* ((beforepoint (substring string 0 point)) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2245 (afterpoint (substring string point)) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2246 (bounds (completion-boundaries beforepoint table pred afterpoint)) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2247 (suffix (substring afterpoint (cdr bounds))) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2248 (prefix (substring beforepoint 0 (car bounds))) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2249 (basic-pattern (completion-basic--pattern |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2250 beforepoint afterpoint bounds)) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2251 (pattern (if (not (stringp (car basic-pattern))) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2252 basic-pattern |
108378
addaf0e91db3
* minibuffer.el (completion-pcm-complete-word-inserts-delimiters):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
108375
diff
changeset
|
2253 (cons 'prefix basic-pattern))) |
107461
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2254 (all (completion-pcm--all-completions prefix pattern table pred))) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2255 (list all pattern prefix suffix (car bounds)))) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2256 |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2257 (defun completion-substring-try-completion (string table pred point) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2258 (destructuring-bind (all pattern prefix suffix carbounds) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2259 (completion-substring--all-completions string table pred point) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2260 (if minibuffer-completing-file-name |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2261 (setq all (completion-pcm--filename-try-filter all))) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2262 (completion-pcm--merge-try pattern all prefix suffix))) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2263 |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2264 (defun completion-substring-all-completions (string table pred point) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2265 (destructuring-bind (all pattern prefix suffix carbounds) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2266 (completion-substring--all-completions string table pred point) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2267 (when all |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2268 (nconc (completion-pcm--hilit-commonality pattern all) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2269 (length prefix))))) |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2270 |
7cf379c501e1
Add a new completion style `substring'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107250
diff
changeset
|
2271 ;; Initials completion |
104785
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2272 ;; Complete /ums to /usr/monnier/src or lch to list-command-history. |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2273 |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2274 (defun completion-initials-expand (str table pred) |
107089
d9f5c24a36cb
Make `initials' completion work for /hh -> /home/horn again (bug#5524).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106815
diff
changeset
|
2275 (let ((bounds (completion-boundaries str table pred ""))) |
d9f5c24a36cb
Make `initials' completion work for /hh -> /home/horn again (bug#5524).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106815
diff
changeset
|
2276 (unless (or (zerop (length str)) |
d9f5c24a36cb
Make `initials' completion work for /hh -> /home/horn again (bug#5524).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106815
diff
changeset
|
2277 ;; Only check within the boundaries, since the |
d9f5c24a36cb
Make `initials' completion work for /hh -> /home/horn again (bug#5524).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106815
diff
changeset
|
2278 ;; boundary char (e.g. /) might be in delim-regexp. |
d9f5c24a36cb
Make `initials' completion work for /hh -> /home/horn again (bug#5524).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106815
diff
changeset
|
2279 (string-match completion-pcm--delim-wild-regex str |
d9f5c24a36cb
Make `initials' completion work for /hh -> /home/horn again (bug#5524).
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
106815
diff
changeset
|
2280 (car bounds))) |
104785
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2281 (if (zerop (car bounds)) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2282 (mapconcat 'string str "-") |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2283 ;; If there's a boundary, it's trickier. The main use-case |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2284 ;; we consider here is file-name completion. We'd like |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2285 ;; to expand ~/eee to ~/e/e/e and /eee to /e/e/e. |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2286 ;; But at the same time, we don't want /usr/share/ae to expand |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2287 ;; to /usr/share/a/e just because we mistyped "ae" for "ar", |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2288 ;; so we probably don't want initials to touch anything that |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2289 ;; looks like /usr/share/foo. As a heuristic, we just check that |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2290 ;; the text before the boundary char is at most 1 char. |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2291 ;; This allows both ~/eee and /eee and not much more. |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2292 ;; FIXME: It sadly also disallows the use of ~/eee when that's |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2293 ;; embedded within something else (e.g. "(~/eee" in Info node |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2294 ;; completion or "ancestor:/eee" in bzr-revision completion). |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2295 (when (< (car bounds) 3) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2296 (let ((sep (substring str (1- (car bounds)) (car bounds)))) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2297 ;; FIXME: the above string-match checks the whole string, whereas |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2298 ;; we end up only caring about the after-boundary part. |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2299 (concat (substring str 0 (car bounds)) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2300 (mapconcat 'string (substring str (car bounds)) sep)))))))) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2301 |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2302 (defun completion-initials-all-completions (string table pred point) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2303 (let ((newstr (completion-initials-expand string table pred))) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2304 (when newstr |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2305 (completion-pcm-all-completions newstr table pred (length newstr))))) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2306 |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2307 (defun completion-initials-try-completion (string table pred point) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2308 (let ((newstr (completion-initials-expand string table pred))) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2309 (when newstr |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2310 (completion-pcm-try-completion newstr table pred (length newstr))))) |
7c703efbce29
(completion-try-completion, completion-all-completions):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
104719
diff
changeset
|
2311 |
106239
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
2312 |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
2313 ;; Miscellaneous |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
2314 |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
2315 (defun minibuffer-insert-file-name-at-point () |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
2316 "Get a file name at point in original buffer and insert it to minibuffer." |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
2317 (interactive) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
2318 (let ((file-name-at-point |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
2319 (with-current-buffer (window-buffer (minibuffer-selected-window)) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
2320 (run-hook-with-args-until-success 'file-name-at-point-functions)))) |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
2321 (when file-name-at-point |
0ac473df1bd1
Provide additional default values (file name at point or at the
Juri Linkov <juri@jurta.org>
parents:
106132
diff
changeset
|
2322 (insert file-name-at-point)))) |
94352
add0e6cf4336
(completion-table-with-context): Fix `pred' for the
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
94315
diff
changeset
|
2323 |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2324 (provide 'minibuffer) |
94144 | 2325 |
2326 ;; arch-tag: ef8a0a15-1080-4790-a754-04017c02f08f | |
93885
6c6216b3b878
* lisp/minibuffer.el: New file.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2327 ;;; minibuffer.el ends here |