1 ;;; icicles-mcmd.el --- Minibuffer commands for Icicles
3 ;; Filename: icicles-mcmd.el
4 ;; Description: Minibuffer commands for Icicles
6 ;; Maintainer: Drew Adams (concat "drew.adams" "@" "oracle" ".com")
7 ;; Copyright (C) 1996-2015, Drew Adams, all rights reserved.
8 ;; Created: Mon Feb 27 09:25:04 2006
9 ;; Last-Updated: Wed Jan 21 09:01:17 2015 (-0800)
12 ;; URL: http://www.emacswiki.org/icicles-mcmd.el
13 ;; Doc URL: http://www.emacswiki.org/Icicles
14 ;; Keywords: internal, extensions, help, abbrev, local, minibuffer,
15 ;; keys, apropos, completion, matching, regexp, command
16 ;; Compatibility: GNU Emacs: 20.x, 21.x, 22.x, 23.x, 24.x, 25.x
18 ;; Features that might be required by this library:
20 ;; `apropos', `apropos+', `apropos-fn+var', `avoid', `bookmark',
21 ;; `bookmark+', `bookmark+-1', `bookmark+-bmu', `bookmark+-key',
22 ;; `bookmark+-lit', `cl', `cmds-menu', `cus-theme', `doremi',
23 ;; `el-swank-fuzzy', `ffap', `ffap-', `fit-frame', `frame-fns',
24 ;; `fuzzy', `fuzzy-match', `help+20', `hexrgb', `icicles-fn',
25 ;; `icicles-opt', `icicles-var', `image-dired', `info', `info+20',
26 ;; `kmacro', `levenshtein', `menu-bar', `menu-bar+', `misc-cmds',
27 ;; `misc-fns', `mouse3', `mwheel', `naked', `package', `pp', `pp+',
28 ;; `regexp-opt', `ring', `second-sel', `strings', `thingatpt',
29 ;; `thingatpt+', `unaccent', `w32browser-dlgopen', `wid-edit',
30 ;; `wid-edit+', `widget'.
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
36 ;; This is a helper library for library `icicles.el'. It defines
37 ;; commands to be used mainly in the minibuffer or buffer
38 ;; `*Completions*' (and a few non-interactive functions used in those
39 ;; commands). For top-level commands, see `icicles-cmd1.el' and
40 ;; `icicles-cmd2.el'. For Icicles documentation, see
41 ;; `icicles-doc1.el' and `icicles-doc2.el'.
43 ;; Commands defined here - (+) means a multi-command:
45 ;; `cycle-icicle-expand-to-common-match',
46 ;; `cycle-icicle-image-file-thumbnail',
47 ;; `cycle-icicle-incremental-completion',
48 ;; `cycle-icicle-sort-order',
49 ;; `cycle-icicle-S-TAB-completion-method',
50 ;; `cycle-icicle-TAB-completion-method',
51 ;; `icicle-abort-recursive-edit', `icicle-add-file-to-fileset',
52 ;; `icicle-add/update-saved-completion-set',
53 ;; `icicle-all-candidates-action',
54 ;; `icicle-all-candidates-alt-action',
55 ;; `icicle-all-candidates-list-action',
56 ;; `icicle-all-candidates-list-alt-action',
57 ;; `icicle-apropos-complete', `icicle-apropos-complete-and-exit',
58 ;; `icicle-apropos-complete-and-narrow',
59 ;; `icicle-apropos-complete-and-widen',
60 ;; `icicle-apropos-complete-no-display',
61 ;; `icicle-backward-char-magic',
62 ;; `icicle-backward-delete-char-untabify',
63 ;; `icicle-backward-kill-paragraph',
64 ;; `icicle-backward-kill-sentence', `icicle-backward-kill-sexp',
65 ;; `icicle-backward-kill-word', `icicle-beginning-of-line+',
66 ;; `icicle-candidate-action', `icicle-candidate-alt-action',
67 ;; `icicle-candidate-read-fn-invoke',
68 ;; `icicle-candidate-set-complement',
69 ;; `icicle-candidate-set-define',
70 ;; `icicle-candidate-set-difference',
71 ;; `icicle-candidate-set-intersection',
72 ;; `icicle-candidate-set-retrieve',
73 ;; `icicle-candidate-set-retrieve-from-variable',
74 ;; `icicle-candidate-set-retrieve-more',
75 ;; `icicle-candidate-set-retrieve-persistent',
76 ;; `icicle-candidate-set-save', `icicle-candidate-set-save-more',
77 ;; `icicle-candidate-set-save-more-selected',
78 ;; `icicle-candidate-set-save-persistently',
79 ;; `icicle-candidate-set-save-selected',
80 ;; `icicle-candidate-set-save-to-variable',
81 ;; `icicle-candidate-set-swap', `icicle-candidate-set-truncate',
82 ;; `icicle-candidate-set-union',
83 ;; `icicle-change-alternative-sort-order',
84 ;; `icicle-change-history-variable', `icicle-change-sort-order',
85 ;; `icicle-choose-completion',
86 ;; `icicle-complete-current-candidate-as-input',
87 ;; `icicle-completing-read+insert',
88 ;; `icicle-Completions-mouse-3-menu',
89 ;; `icicle-cycle-expand-to-common-match',
90 ;; `icicle-cycle-image-file-thumbnail',
91 ;; `icicle-cycle-incremental-completion',
92 ;; `icicle-delete-backward-char', `icicle-delete-candidate-object',
93 ;; `icicle-delete-char', `icicle-delete-windows-on',
94 ;; `icicle-describe-file', `icicle-digit-argument',
95 ;; `icicle-dispatch-C-^', `icicle-dispatch-C-.',
96 ;; `icicle-dispatch-C-M-/', `icicle-dispatch-C-x.',
97 ;; `icicle-dispatch-M-_', `icicle-dispatch-M-comma',
98 ;; `icicle-dispatch-M-q',
99 ;; `icicle-display-candidates-in-Completions',
100 ;; `icicle-doremi-candidate-width-factor+',
101 ;; `icicle-doremi-increment-max-candidates+',
102 ;; `icicle-doremi-increment-swank-prefix-length+',
103 ;; `icicle-doremi-increment-swank-timeout+',
104 ;; `icicle-doremi-inter-candidates-min-spaces+',
105 ;; `icicle-doremi-zoom-Completions+', `icicle-end-of-line+',
106 ;; `icicle-erase-minibuffer',
107 ;; `icicle-erase-minibuffer-or-history-element',
108 ;; `icicle-exit-minibuffer', `icicle-file-all-tags-narrow',
109 ;; `icicle-file-all-tags-regexp-narrow',
110 ;; `icicle-file-some-tags-narrow',
111 ;; `icicle-file-some-tags-regexp-narrow',
112 ;; `icicle-forward-char-magic', `icicle-goto/kill-failed-input',
113 ;; `icicle-help-on-candidate',
114 ;; `icicle-help-on-next-apropos-candidate',
115 ;; `icicle-help-on-next-prefix-candidate',
116 ;; `icicle-help-on-previous-apropos-candidate',
117 ;; `icicle-help-on-previous-prefix-candidate',
118 ;; `icicle-help-string-completion',
119 ;; `icicle-help-string-non-completion', `icicle-history',
120 ;; `icicle-insert-completion', `icicle-insert-dot-command',
121 ;; (+)`icicle-insert-history-element',
122 ;; `icicle-insert-key-description',
123 ;; `icicle-insert-list-join-string',
124 ;; `icicle-insert-newline-in-minibuffer',
125 ;; `icicle-insert-string-at-point',
126 ;; `icicle-insert-string-from-variable', `icicle-isearch-complete',
127 ;; (+)`icicle-isearch-history-complete',
128 ;; (+)`icicle-isearch-history-insert',
129 ;; `icicle-keep-only-buffer-cands-for-derived-mode',
130 ;; `icicle-keep-only-buffer-cands-for-mode',
131 ;; `icicle-keep-only-buffer-cands-for-visible',
132 ;; `icicle-keep-only-past-inputs', `icicle-kill-line',
133 ;; `icicle-kill-paragraph', `icicle-kill-region',
134 ;; `icicle-kill-region-wimpy', `icicle-kill-sentence',
135 ;; `icicle-kill-sexp', `icicle-kill-word', `icicle-make-directory',
136 ;; `icicle-minibuffer-complete-and-exit', `icicle-minibuffer-help',
137 ;; `icicle-mouse-candidate-action',
138 ;; `icicle-mouse-candidate-alt-action',
139 ;; `icicle-mouse-candidate-read-fn-invoke',
140 ;; `icicle-mouse-candidate-set-save',
141 ;; `icicle-mouse-candidate-set-save-more',
142 ;; `icicle-mouse-choose-completion',
143 ;; `icicle-mouse-help-on-candidate',
144 ;; `icicle-mouse-remove-candidate',
145 ;; `icicle-mouse-save/unsave-candidate',
146 ;; `icicle-mouse-save-then-kill', `icicle-mouse-yank-secondary',
147 ;; `icicle-move-to-next-completion',
148 ;; `icicle-move-to-previous-completion', `icicle-multi-inputs-act',
149 ;; `icicle-multi-inputs-save', `icicle-narrow-candidates',
150 ;; `icicle-narrow-candidates-with-predicate',
151 ;; `icicle-negative-argument', `icicle-next-apropos-candidate',
152 ;; `icicle-next-apropos-candidate-action',
153 ;; `icicle-next-apropos-candidate-alt-action',
154 ;; `icicle-next-candidate-per-mode',
155 ;; `icicle-next-candidate-per-mode-action',
156 ;; `icicle-next-candidate-per-mode-alt-action',
157 ;; `icicle-next-history-element', `icicle-next-line',
158 ;; `icicle-next-prefix-candidate',
159 ;; `icicle-next-prefix-candidate-action',
160 ;; `icicle-next-prefix-candidate-alt-action',
161 ;; `icicle-next-S-TAB-completion-method',
162 ;; `icicle-next-TAB-completion-method',
163 ;; `icicle-ORIG-choose-completion', `icicle-ORIG-exit-minibuffer',
164 ;; `icicle-ORIG-minibuffer-complete-and-exit',
165 ;; `icicle-ORIG-mouse-choose-completion',
166 ;; `icicle-ORIG-next-history-element', `icicle-ORIG-sit-for',
167 ;; `icicle-ORIG-switch-to-completions', `icicle-other-history',
168 ;; `icicle-plus-saved-sort',
169 ;; `icicle-pp-eval-expression-in-minibuffer',
170 ;; `icicle-prefix-complete', `icicle-prefix-complete-no-display',
171 ;; `icicle-prefix-word-complete',
172 ;; `icicle-previous-apropos-candidate',
173 ;; `icicle-previous-apropos-candidate-action',
174 ;; `icicle-previous-apropos-candidate-alt-action',
175 ;; `icicle-previous-candidate-per-mode',
176 ;; `icicle-previous-candidate-per-mode-action',
177 ;; `icicle-previous-candidate-per-mode-alt-action',
178 ;; `icicle-previous-line', `icicle-previous-prefix-candidate',
179 ;; `icicle-previous-prefix-candidate-action',
180 ;; `icicle-previous-prefix-candidate-alt-action',
181 ;; `icicle-read+insert-file-name',
182 ;; `icicle-recomplete-from-original-domain',
183 ;; `icicle-regexp-quote-input', `icicle-remove-candidate',
184 ;; `icicle-remove-buffer-cands-for-derived-mode',
185 ;; `icicle-remove-buffer-cands-for-mode',
186 ;; `icicle-remove-buffer-cands-for-visible',
187 ;; `icicle-remove-Completions-window', `icicle-resolve-file-name',
188 ;; `icicle-retrieve-last-input', `icicle-retrieve-next-input',
189 ;; `icicle-retrieve-previous-input', `icicle-reverse-sort-order',
190 ;; (+)`icicle-roundup', `icicle-save-predicate-to-variable',
191 ;; `icicle-save/unsave-candidate',
192 ;; `icicle-scroll-Completions-backward',
193 ;; `icicle-scroll-Completions-forward', `icicle-scroll-backward',
194 ;; `icicle-scroll-forward', `icicle-search-define-replacement',
195 ;; `icicle-self-insert', `icicle-sit-for',
196 ;; `icicle-sort-alphabetical', `icicle-sort-by-abbrev-frequency',
197 ;; `icicle-sort-by-directories-first',
198 ;; `icicle-sort-by-directories-last', `icicle-sort-by-file-type',
199 ;; `icicle-sort-by-last-file-access-time',
200 ;; `icicle-sort-by-last-file-modification-time',
201 ;; `icicle-sort-by-last-use', `icicle-sort-by-last-use-as-input',
202 ;; `icicle-sort-by-last-use\,-dirs-first',
203 ;; `icicle-sort-by-previous-use-alphabetically',
204 ;; `icicle-sort-by-2nd-parts-alphabetically',
205 ;; `icicle-sort-case-insensitive',
206 ;; `icicle-sort-extra-candidates-first',
207 ;; `icicle-sort-proxy-candidates-first',
208 ;; `icicle-sort-special-candidates-first',
209 ;; `icicle-sort-turned-OFF', `icicle-switch-to-Completions-buf',
210 ;; `icicle-switch-to-completions',
211 ;; `icicle-switch-to/from-minibuffer', `icicle-toggle-.',
212 ;; `icicle-toggle-~-for-home-dir',
213 ;; `icicle-toggle-alternative-sorting',
214 ;; `icicle-toggle-angle-brackets', `icicle-toggle-annotation',
215 ;; `icicle-toggle-case-sensitivity', `icicle-toggle-C-for-actions',
216 ;; `icicle-toggle-completions-format', `icicle-toggle-dot',
217 ;; `icicle-toggle-expand-directory',
218 ;; `icicle-toggle-expand-to-common-match',
219 ;; `icicle-toggle-hiding-common-match',
220 ;; `icicle-toggle-hiding-non-matching-lines',
221 ;; `icicle-toggle-highlight-all-current',
222 ;; `icicle-toggle-highlight-historical-candidates',
223 ;; `icicle-toggle-highlight-saved-candidates',
224 ;; `icicle-toggle-icomplete-mode',
225 ;; `icicle-toggle-ignored-extensions',
226 ;; `icicle-toggle-ignored-space-prefix',
227 ;; `icicle-toggle-ignoring-comments',
228 ;; `icicle-toggle-include-cached-files',
229 ;; `icicle-toggle-include-recent-files',
230 ;; `icicle-toggle-literal-replacement',
231 ;; `icicle-toggle-network-drives-as-remote',
232 ;; `icicle-toggle-proxy-candidates', `icicle-toggle-regexp-quote',
233 ;; `icicle-toggle-remote-file-testing',
234 ;; `icicle-toggle-search-cleanup',
235 ;; `icicle-toggle-search-complementing-domain',
236 ;; `icicle-toggle-search-replace-common-match',
237 ;; `icicle-toggle-search-replace-whole',
238 ;; `icicle-toggle-search-whole-word',
239 ;; `icicle-toggle-show-multi-completion', `icicle-toggle-sorting',
240 ;; `icicle-toggle-transforming',
241 ;; `icicle-toggle-WYSIWYG-Completions', `icicle-top-level',
242 ;; `icicle-transpose-chars', `icicle-transpose-sexps',
243 ;; `icicle-transpose-words', `icicle-universal-argument',
244 ;; `icicle-universal-argument-minus',
245 ;; `icicle-universal-argument-more',
246 ;; `icicle-universal-argument-other-key', `icicle-up-directory',
247 ;; `icicle-use-interactive-command-history',
248 ;; `icicle-widen-candidates', `icicle-yank', `icicle-yank-pop',
249 ;; `icicle-yank-secondary', `toggle-icicle-.',
250 ;; `toggle-icicle-~-for-home-dir',
251 ;; `toggle-icicle-alternative-sorting',
252 ;; `toggle-icicle-angle-brackets', `toggle-icicle-annotation',
253 ;; `toggle-icicle-case-sensitivity', `toggle-icicle-C-for-actions',
254 ;; `toggle-icicle-completions-format', `toggle-icicle-dot',
255 ;; `toggle-icicle-expand-directory',
256 ;; `toggle-icicle-expand-to-common-match',
257 ;; `toggle-icicle-hiding-common-match',
258 ;; `toggle-icicle-hiding-non-matching-lines',
259 ;; `toggle-icicle-highlight-all-current',
260 ;; `toggle-icicle-highlight-historical-candidates',
261 ;; `toggle-icicle-highlight-saved-candidates',
262 ;; `toggle-icicle-icomplete-mode',
263 ;; `toggle-icicle-ignored-extensions',
264 ;; `toggle-icicle-ignored-space-prefix',
265 ;; `toggle-icicle-include-cached-files',
266 ;; `toggle-icicle-include-recent-files',
267 ;; `toggle-icicle-incremental-completion',
268 ;; `toggle-icicle-literal-replacement',
269 ;; `toggle-icicle-network-drives-as-remote',
270 ;; `toggle-icicle-proxy-candidates', `toggle-icicle-regexp-quote',
271 ;; `toggle-icicle-remote-file-testing',
272 ;; `toggle-icicle-search-cleanup',
273 ;; `toggle-icicle-search-complementing-domain',
274 ;; `toggle-icicle-search-replace-common-match',
275 ;; `toggle-icicle-search-replace-whole',
276 ;; `toggle-icicle-search-whole-word',
277 ;; `toggle-icicle-show-multi-completion', `toggle-icicle-sorting',
278 ;; `toggle-icicle-transforming',
279 ;; `toggle-icicle-WYSIWYG-Completions'.
281 ;; Non-interactive functions defined here:
283 ;; `icicle-all-candidates-action-1', `icicle-all-exif-data',
284 ;; `icicle-anychar-regexp', `icicle-apply-to-saved-candidate',
285 ;; `icicle-apropos-complete-1', `icicle-apropos-complete-2',
286 ;; `icicle-autofile-action',
287 ;; `icicle-backward-delete-char-untabify-magic',
288 ;; `icicle-bind-buffer-candidate-keys',
289 ;; `icicle-bind-file-candidate-keys', `icicle-candidate-action-1',
290 ;; `icicle-candidate-set-retrieve-1',
291 ;; `icicle-candidate-set-save-1',
292 ;; `icicle-candidate-set-save-selected-1', `icicle-cand-preds',
293 ;; `icicle-column-wise-cand-nb',
294 ;; `icicle-isearch-complete-past-string',
295 ;; `icicle-Completions-popup-choice',
296 ;; `icicle-Completions-popup-choice-1', `icicle-convert-dots',
297 ;; `icicle-current-completion-in-Completions',
298 ;; `icicle-current-sort-functions', `icicle-current-sort-order',
299 ;; `icicle-delete-backward-char-magic',
300 ;; `icicle-delete-candidate-object-1', `icicle-delete-char-magic',
301 ;; `icicle-delete-current-candidate-object',
302 ;; `icicle-ensure-overriding-map-is-bound',
303 ;; `icicle-help-on-candidate-symbol',
304 ;; `icicle-input-is-a-completion-p',
305 ;; `icicle-insert-candidate-action', `icicle-insert-dot',
306 ;; `icicle-insert-input', `icicle-insert-thing',
307 ;; `icicle-keep/remove-buffer-cands-for-visible',
308 ;; `icicle-looking-at-p', `icicle-looking-at-literally-p',
309 ;; `icicle-looking-back-at-literally-p',
310 ;; `icicle-markers-to-readable',
311 ;; `icicle-maybe-multi-completion-completing-p',
312 ;; `icicle-mouse-candidate-action-1', `icicle-nb-Completions-cols',
313 ;; `icicle-nb-of-cand-at-Completions-pos',
314 ;; `icicle-nb-of-cand-in-Completions-horiz',
315 ;; `icicle-prefix-complete-1', `icicle-prefix-complete-2',
316 ;; `icicle-raise-Completions-frame',
317 ;; `icicle-remove-cand-from-lists',
318 ;; `icicle-remove-candidate-display-others',
319 ;; `icicle-replace-input-w-parent-dir',
320 ;; `icicle-retrieve-candidates-from-set',
321 ;; `icicle-row-wise-cand-nb', `icicle-signum',
322 ;; `icicle-split-input', `icicle-substitute-keymap-vars',
323 ;; `icicle-successive-action', `icicle-transform-sole-candidate',
324 ;; `icicle-transpose-chars-magic',
325 ;; `icicle-unbind-buffer-candidate-keys',
326 ;; `icicle-unbind-file-candidate-keys',
327 ;; `icicle-universal-argument--mode' (Emacs 24.4+),
328 ;; `icicle-upcase-if-ignore-case', `icicle-update-and-next'.
330 ;; Internal variables defined here:
332 ;; `overriding-map-is-bound', `saved-overriding-map'.
335 ;; ***** NOTE: These EMACS PRIMITIVES have been REDEFINED HERE:
337 ;; `exit-minibuffer' - Remove *Completion* window and
338 ;; input mismatch highlighting
339 ;; `minibuffer-complete-and-exit' - Use Icicles prefix completion
342 ;; ***** NOTE: The following function defined in `mouse.el' has
343 ;; been REDEFINED HERE:
345 ;; `choose-completion' - Don't iconify frame or bury buffer.
346 ;; `mouse-choose-completion' - Return the number of the completion.
349 ;; ***** NOTE: The following function defined in `simple.el' has
350 ;; been REDEFINED HERE:
352 ;; `switch-to-completions' - Always selects `*Completions*' window.
355 ;; Key bindings made by Icicles: See "Key Bindings" in
356 ;; `icicles-doc2.el'.
358 ;; For descriptions of changes to this file, see `icicles-chg.el'.
362 ;; If you have library `linkd.el' and Emacs 22 or later, load
363 ;; `linkd.el' and turn on `linkd-mode' now. It lets you easily
364 ;; navigate around the sections of this doc. Linkd mode will
365 ;; highlight this Index, as well as the cross-references and section
366 ;; headings throughout this file. You can get `linkd.el' here:
367 ;; http://dto.freeshell.org/notebook/Linkd.html.
369 ;; (@> "Redefined standard commands")
370 ;; (@> "Icicles commands")
371 ;; (@> "Minibuffer editing commands")
372 ;; (@> "Commands to sort completion candidates")
373 ;; (@> "Other commands to be used mainly in the minibuffer")
375 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
377 ;; This program is free software; you can redistribute it and/or
378 ;; modify it under the terms of the GNU General Public License as
379 ;; published by the Free Software Foundation; either version 2, or (at
380 ;; your option) any later version.
382 ;; This program is distributed in the hope that it will be useful,
383 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
384 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
385 ;; GNU General Public License for more details.
387 ;; You should have received a copy of the GNU General Public License
388 ;; along with this program; see the file COPYING. If not, write to
389 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
390 ;; Floor, Boston, MA 02110-1301, USA.
392 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
396 (eval-when-compile (require 'cl)) ;; case, flet, lexical-let, loop
397 ;; plus, for Emacs < 21: dolist, push
398 (eval-when-compile (require 'filesets nil t)) ; Emacs 22+.
399 ;; filesets-data, filesets-entry-get-files, filesets-entry-mode, filesets-entry-set-files,
400 ;; filesets-files-equalp, filesets-init, filesets-member, filesets-set-config
403 (or (condition-case nil
404 (load-library "icicles-mac") ; Use load-library to ensure latest .elc.
406 (require 'icicles-mac))) ; Require, so can load separately if not on `load-path'.
407 ;; icicle-assoc-delete-all, icicle-define-sort-command
408 (require 'icicles-opt) ; (This is required anyway by `icicles-var.el'.)
409 ;; icicle-act-before-cycle-flag, icicle-add-proxy-candidates-flag, icicle-alternative-sort-comparer,
410 ;; icicle-anychar-regexp, icicle-buffer-ignore-space-prefix-flag, icicle-dot-string-internal,
411 ;; icicle-move-Completions-frame, icicle-Completions-mouse-3-menu-entries, icicle-current-TAB-method,
412 ;; icicle-default-cycling-mode, icicle-default-thing-insertion, icicle-delete-candidate-object,
413 ;; icicle-expand-input-to-common-match, icicle-hide-common-match-in-Completions-flag,
414 ;; icicle-hide-non-matching-lines-flag, icicle-incremental-completion, icicle-input-string, icicle-kbd,
415 ;; icicle-key-descriptions-use-<>-flag, icicle-regexp-quote-flag, icicle-saved-completion-sets,
416 ;; icicle-search-cleanup-flag, icicle-search-highlight-all-current-flag, icicle-sort-comparer,
417 ;; icicle-sort-orders-alist, icicle-TAB-shows-candidates-flag, icicle-thing-at-point-functions,
418 ;; icicle-transform-function
419 (eval-and-compile (require 'icicles-var)) ; (This is required anyway by `icicles-fn.el'.)
420 ;; lacarte-menu-items-alist, icicle-abs-file-candidates, icicle-acting-on-next/prev,
421 ;; icicle-all-candidates-list-action-fn, icicle-all-candidates-list-alt-action-fn,
422 ;; icicle-allowed-sort-predicate, icicle-apropos-complete-match-fn, icicle-buffer-name-input-p,
423 ;; icicle-bufflist, icicle-candidate-action-fn, icicle-candidate-alt-action-fn, icicle-candidate-help-fn,
424 ;; icicle-candidate-nb, icicle-candidates-alist, icicle-cands-to-narrow, icicle-cmd-reading-input,
425 ;; icicle-command-abbrev-history, icicle-complete-keys-alist, icicle-completing-keys-p,
426 ;; icicle-completing-p, icicle-completing-read+insert-candidates, icicle-completion-candidates,
427 ;; icicle-compute-narrowing-regexp-p, icicle-confirm-exit-commands,
428 ;; icicle-current-completion-candidate-overlay, icicle-current-completion-mode, icicle-current-input,
429 ;; icicle-current-raw-input, icicle-cycling-p, icicle-default-thing-insertion-flipped-p,
430 ;; icicle-edit-update-p, icicle-extra-candidates-dir-insert-p, icicle-full-cand-fn,
431 ;; icicle-general-help-string, icicle-get-alist-candidate-function, icicle-hist-var,
432 ;; icicle-ignored-extensions, icicle-ignored-extensions-regexp, icicle-incremental-completion-p,
433 ;; icicle-inhibit-sort-p, icicle-input-completion-fail-overlay, icicle-input-fail-pos,
434 ;; icicle-insert-string-at-pt-end, icicle-insert-string-at-pt-start,
435 ;; icicle-last-apropos-complete-match-fn, icicle-last-completion-candidate,
436 ;; icicle-last-completion-command, icicle-last-input, icicle-last-sort-comparer,
437 ;; icicle-last-top-level-command, icicle-last-transform-function, icicle-list-use-nth-parts,
438 ;; icicle-minibuffer-message-ok-p, icicle-mode-line-help, icicle-multi-completing-p,
439 ;; icicle-multi-inputs-action-fn, icicle-must-pass-after-match-predicate, icicle-narrow-regexp,
440 ;; icicle-nb-of-other-cycle-candidates, icicle-next-apropos-complete-cycles-p,
441 ;; icicle-next-prefix-complete-cycles-p, icicle-orig-buff, icicle-orig-must-pass-after-match-pred,
442 ;; icicle-orig-window, icicle-other-window, icicle-pref-arg, icicle-pre-minibuffer-buffer,
443 ;; icicle-previous-raw-file-name-inputs, icicle-previous-raw-non-file-name-inputs,
444 ;; icicle-progressive-completing-p, icicle-require-match-p, icicle-reverse-sort-p,
445 ;; icicle-saved-candidates-variables-obarray, icicle-saved-completion-candidates,
446 ;; icicle-saved-completion-candidates-internal, icicle-saved-ignored-extensions,
447 ;; icicle-saved-proxy-candidates, icicle-scroll-Completions-reverse-p, icicle-search-complement-domain-p,
448 ;; icicle-searching-p, icicle-search-replacement, icicle-successive-grab-count,
449 ;; icicle-thing-at-pt-fns-pointer, icicle-universal-argument-map, icicle-use-candidates-only-once-alt-p,
450 ;; icicle-whole-candidate-as-text-prop-p
451 (require 'icicles-fn)
452 ;; icicle-minibuf-input-sans-dir, icicle-read-regexp, icicle-scan-fn-or-regexp, icicle-string-match-p,
453 ;; icicle-toggle-icicle-mode-twice, icicle-unlist
455 (require 'doremi nil t) ;; (no error if not found):
456 ;; doremi, doremi(-boost)-(up|down)-keys, doremi-limit, doremi-wrap
457 (when (> emacs-major-version 22) (require 'help-fns+ nil t)) ;; (no error if not found):
458 ;; help-commands-to-key-buttons
460 (eval-when-compile (require 'fit-frame nil t)) ;; (no error if not found): fit-frame
462 (when (> emacs-major-version 21) (require 'linkd nil t))) ;; (no error if not found): linkd-mode
464 ;; Byte-compiling this file, you will likely get some byte-compiler warning messages.
465 ;; These are probably benign - ignore them. Icicles is designed to work with multiple
466 ;; versions of Emacs, and that fact provokes compiler warnings. If you get byte-compiler
467 ;; errors (not warnings), then please report a bug, using `M-x icicle-send-bug-report'.
469 ;; Some defvars to quiet byte-compiler a bit:
471 (when (< emacs-major-version 22)
472 (defvar icicle-Info-highlight-visited-nodes) ; In `icicles-opt.el' (for Emacs 22+)
473 (defvar read-file-name-completion-ignore-case) ; In `minibuffer.el'
474 (defvar read-file-name-predicate)
475 (defvar tooltip-mode))
477 (when (< emacs-major-version 23)
478 (defvar read-buffer-completion-ignore-case)
479 (defvar mouse-drag-copy-region))
481 (defvar completion-base-position) ; Emacs 23.2+.
482 (defvar count) ; Here.
483 (defvar doremi-boost-down-keys) ; In `doremi.el'
484 (defvar doremi-boost-up-keys) ; In `doremi.el'
485 (defvar doremi-down-keys) ; In `doremi.el'
486 (defvar doremi-up-keys) ; In `doremi.el'
487 (defvar filesets-data) ; In `filesets.el'.
488 (defvar icicle-cand-preds) ; Here.
489 (defvar icicle-ido-like-mode) ; In `icicles-cmd2.el' (implicit)
490 (defvar icicle-Info-hist-list) ; In `icicles-cmd2.el'
491 (defvar ignore-comments-flag) ; In `hide-comnt.el'.
492 (defvar minibuffer-confirm-exit-commands) ; In `minibuffer.el' in Emacs 23+.
493 (defvar minibuffer-local-filename-completion-map) ; In Emacs 22+.
494 (defvar minibuffer-local-filename-must-match-map) ; In Emacs 23.2 (but not Emacs 24+).
495 (defvar minibuffer-local-must-match-filename-map) ; In Emacs 22+.
496 (defvar overriding-map-is-bound) ; In Emacs 22-23.
497 (defvar recentf-list) ; In `recentf.el' (Emacs 21+).
498 (defvar saved-overriding-map) ; In Emacs 22-23.
499 (defvar to-insert) ; Here.
500 (defvar universal-argument-num-events) ; Emacs 22-24.3.
502 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
504 ;;(@* "Redefined standard commands")
506 ;;; Redefined standard commands --------------------------------------
509 ;; REPLACE ORIGINAL `next-history-element' in `simple.el',
510 ;; saving it for restoration when you toggle `icicle-mode'.
512 ;; Selects minibuffer contents and leaves point at its beginning.
514 (unless (fboundp 'icicle-ORIG-next-history-element)
515 (defalias 'icicle-ORIG-next-history-element (symbol-function 'next-history-element)))
517 (defun icicle-next-history-element (arg) ; Bound to `M-n' in minibuffer.
518 "Insert the next element of the minibuffer history in the minibuffer.
519 With argument N, it uses the Nth following element."
521 (icicle-ORIG-next-history-element (prefix-numeric-value arg))
522 (when (and icicle-mode (memq icicle-default-value '(preselect-start preselect-end)))
523 (icicle-select-minibuffer-contents)
524 (setq deactivate-mark nil)))
527 ;; REPLACE ORIGINAL `exit-minibuffer' (built-in function),
528 ;; saving it for restoration when you toggle `icicle-mode'.
530 ;; Remove input mismatch highlighting.
531 ;; Remove *Completion* window.
533 (unless (fboundp 'icicle-ORIG-exit-minibuffer)
534 (defalias 'icicle-ORIG-exit-minibuffer (symbol-function 'exit-minibuffer)))
536 (defun icicle-exit-minibuffer () ; Bound to `C-m' (`RET') in minibuffer.
537 "Terminate this minibuffer argument.
538 Remove `*Completions*' window. Remove Icicles minibuffer faces."
539 ;; This removal lets users retrieve candidates that have other faces, and saves input-history space.
541 (when (active-minibuffer-window)
542 (with-current-buffer (window-buffer (minibuffer-window))
543 (let ((pos (icicle-minibuffer-prompt-end))
544 (icy-minibuf-faces '(icicle-input-completion-fail icicle-input-completion-fail-lax
545 icicle-whitespace-highlight icicle-match-highlight-minibuffer
546 icicle-complete-input))
548 (while (< pos (point-max))
549 (let ((faces (get-text-property pos 'face)))
550 (when (or (and (consp faces) (cdr faces) (atom (cdr faces))) ; (background-color . "abc")
551 (and faces (atom faces))) ; face name
552 (setq faces (list faces))) ; No-op: (foo (background-color . "abc") (:foreground "abc"))
553 (setq keep-faces (icicle-set-union keep-faces
554 (icicle-set-difference faces icy-minibuf-faces))))
556 ;; If KEEP-FACES is (), use `remove-text-properties' instead of just `put-text-property',
557 ;; so we do not add a nil `face' property.
559 (put-text-property (icicle-minibuffer-prompt-end) (point-max) 'face keep-faces)
560 (remove-text-properties (icicle-minibuffer-prompt-end) (point-max) '(face nil))))
561 ;; $$$$$ (let ((pos (icicle-minibuffer-prompt-end)))
562 ;; (while (< pos (point-max))
563 ;; (when (memq (get-text-property pos 'face)
564 ;; '(icicle-input-completion-fail icicle-input-completion-fail-lax))
565 ;; (remove-text-properties pos (point-max) '(face))
566 ;; (setq pos (point-max)))
567 ;; (setq pos (1+ pos))))
569 (icicle-remove-Completions-window)
570 (icicle-ORIG-exit-minibuffer))
573 ;; REPLACE ORIGINAL `minibuffer-complete-and-exit' (built-in function),
574 ;; saving it for restoration when you toggle `icicle-mode'.
576 ;; Use Icicles completion.
578 (unless (fboundp 'icicle-ORIG-minibuffer-complete-and-exit)
579 (defalias 'icicle-ORIG-minibuffer-complete-and-exit (symbol-function 'minibuffer-complete-and-exit)))
581 ;; Bound to `C-m' (`RET') in must-match minibuffer completion maps.
582 (defun icicle-minibuffer-complete-and-exit ()
583 "If the minibuffer contents is a valid completion, then exit.
584 Otherwise try to complete it."
586 (let ((last-cmd last-command))
587 (cond ((string= "" (if (icicle-file-name-input-p) ; Empty input - exit.
588 (icicle-minibuf-input-sans-dir)
589 (icicle-input-from-minibuffer)))
590 (icicle-exit-minibuffer))
591 ;; This case serves when property `icicle-display-string' is used.
592 ;; What's returned is the replacement display string, not the original candidate.
593 ;; If you want to get the original candidate back, you'll need to search the obarray for a
594 ;; symbol that has this `icicle-display-string' value. Or put the symbol on the display
595 ;; string as a text property.
596 ((icicle-input-is-a-completion-p) (icicle-exit-minibuffer))
597 ((eq minibuffer-completion-confirm 'confirm) ; User wants it anyway? - Emacs 23+.
598 (if (eq last-cmd this-command)
599 (icicle-exit-minibuffer)
600 (minibuffer-message "Confirm")
602 ((eq minibuffer-completion-confirm 'confirm-after-completion) ; Emacs 23+.
603 ;; Similar to `confirm', but only if trying to exit immediately
604 ;; after completing (this catches most minibuffer typos).
605 (if (not (memq last-cmd (and (boundp 'minibuffer-confirm-exit-commands)
606 (append icicle-confirm-exit-commands
607 minibuffer-confirm-exit-commands))))
608 (icicle-exit-minibuffer)
609 (minibuffer-message "Confirm")
612 (setq icicle-current-input (icicle-input-from-minibuffer))
613 (let* (;; Bind these first two to suppress (a) the throw or (b) the message, highlighting,
614 ;; mode-line help, and the wait involved in completing again.
615 (icicle-prefix-complete-and-exit-p t)
616 (icicle-apropos-complete-and-exit-p t)
619 ;; If we're not using `icicle-candidates-alist', complete the input again.
620 ;; If we're using `icicle-candidates-alist', try filtering it against just the
622 ;; If the input is already complete, then we're done. If not, then filtering
623 ;; will give nil and we will just continue to display the candidates. If there
624 ;; are multiple matches, then the user can either cycle or complete again.
625 (if (not icicle-candidates-alist)
626 (if (eq icicle-current-completion-mode 'apropos)
627 (icicle-apropos-complete-no-display 'nomsg)
628 (icicle-prefix-complete-no-display 'nomsg))
629 (icicle-filter-alist icicle-candidates-alist (list icicle-current-input)))))
630 (cond ((and (eq icicle-require-match-p t) ; Don't exit if non-nil and non-t.
631 (icicle-input-is-a-completion-p))
632 (icicle-exit-minibuffer))
634 (icicle-display-candidates-in-Completions))))))))
636 ;;; $$$$$$ Should probably rename it. It's no longer necessarily about apropos completion.
637 (defun icicle-apropos-complete-and-exit () ; Bound to `S-return' (`S-RET') in minibuffer completion maps.
638 "If minibuffer content is a valid completion or has a single match, exit.
639 If the content is not complete, try to complete it. If completion
640 leads to a valid completion, then exit.
642 This differs from `icicle-minibuffer-complete-and-exit' (bound to
643 `RET' in must-match minibuffer maps) in these ways:
645 * If there is only one completion, this completes the input, rather
646 than accepting it uncompleted.
647 * This does not bother with the various special cases: empty input or
648 non-nil `minibuffer-completion-confirm' values."
650 (setq icicle-current-input (icicle-input-from-minibuffer))
651 (let* (;; Bind these first two to suppress (a) the throw or (b) the message, highlighting,
652 ;; mode-line help, and the wait involved in completing again.
653 (icicle-prefix-complete-and-exit-p t)
654 (icicle-apropos-complete-and-exit-p t)
656 ;; If we're not using `icicle-candidates-alist', complete the input again.
657 ;; If we're using `icicle-candidates-alist', try filtering it against just the
659 ;; If the input is already complete, then we're done. If not, then filtering
660 ;; will give nil and we will just continue to display the candidates. If there
661 ;; are multiple matches, then the user can either cycle or complete again.
662 (if (not icicle-candidates-alist)
663 (if (eq icicle-current-completion-mode 'apropos)
664 (icicle-apropos-complete-no-display 'nomsg)
665 (icicle-prefix-complete-no-display 'nomsg))
666 (icicle-filter-alist icicle-candidates-alist (list icicle-current-input)))))
667 (when (and candidates (null (cdr candidates))) (icicle-ORIG-exit-minibuffer)))) ; Single candidate.
670 ;; REPLACE ORIGINAL `choose-completion' in `simple.el',
671 ;; saving it for restoration when you toggle `icicle-mode'.
673 ;; Return the number of the completion.
674 ;; Do not remove text properties from candidate.
675 ;; Respect `icicle-extra-candidates' and `icicle-extra-candidates-dir-insert-p'.
676 ;; Adjust to `icicle-start-of-candidates-in-Completions'.
677 ;; Do not use `completion-list-insert-choice-function'.
678 ;; Do not iconify frame or bury buffer (in Emacs 23-24.2 code).
679 ;; Do not quit *Completions* window (Emacs 24.3+).
681 (unless (fboundp 'icicle-ORIG-choose-completion)
682 (defalias 'icicle-ORIG-choose-completion (symbol-function 'choose-completion)))
684 (if (or (> emacs-major-version 23)
685 (and (= emacs-major-version 23) (> emacs-minor-version 1))) ; Emacs 23.2+
686 (defun icicle-choose-completion (&optional event)
687 "Choose the completion at point.
688 Return the number of the candidate: 0 for first, 1 for second, ..."
689 (interactive (list last-nonmenu-event))
690 ;; In case this is run via the mouse, give temporary modes such as Isearch a chance to turn off.
691 (run-hooks 'mouse-leave-buffer-hook)
692 (with-current-buffer (window-buffer (posn-window (event-start event)))
693 (let ((buffer completion-reference-buffer)
694 (base-size completion-base-size)
697 (goto-char (posn-point (event-start event)))
699 (cond ((and (not (eobp)) (get-text-property (point) 'mouse-face))
702 ((and (>= (point) (icicle-start-of-candidates-in-Completions))
703 (get-text-property (max (point-min) (1- (point))) 'mouse-face))
704 (setq end (max (point-min) (1- (point)))
706 (t (icicle-user-error "No candidate here")))
707 (setq beg (previous-single-property-change beg 'mouse-face)
708 end (or (next-single-property-change end 'mouse-face) (point-max)))
709 (buffer-substring beg end)))))
710 (unless (or (not (member choice icicle-extra-candidates)) icicle-extra-candidates-dir-insert-p)
712 (setq icicle-candidate-nb (icicle-nb-of-cand-at-Completions-pos
713 (posn-point (event-start event))))
714 (unless (buffer-live-p buffer) (icicle-user-error "Destination buffer is dead"))
715 (when (and (icicle-file-name-input-p) insert-default-directory
716 (or (not (member choice icicle-extra-candidates))
717 icicle-extra-candidates-dir-insert-p))
718 (let ((dir (icicle-file-name-directory-w-default icicle-current-input)))
719 (with-current-buffer buffer
720 (icicle-clear-minibuffer)
722 (setq choice (concat dir choice)
724 ;; $$$$$$$$ (icicle-choose-completion-string choice buffer base-size))
725 (with-current-buffer buffer (icicle-choose-completion-string choice buffer base-size)))
726 icicle-candidate-nb))
728 (defun icicle-choose-completion () ; Emacs < 23.2.
729 "Choose the completion that point is in or next to."
731 (let ((buffer completion-reference-buffer)
732 (base-size completion-base-size)
734 (when (and (not (eobp)) (get-text-property (point) 'mouse-face))
737 (when (and (>= (point) (icicle-start-of-candidates-in-Completions))
738 (get-text-property (max (point-min) (1- (point))) 'mouse-face))
739 (setq end (max (point-min) (1- (point)))
741 (unless beg (icicle-user-error "No completion here"))
742 (setq beg (previous-single-property-change beg 'mouse-face)
743 end (or (next-single-property-change end 'mouse-face) (point-max))
744 ;; $$$$ choice (buffer-substring-no-properties beg end))
745 choice (buffer-substring beg end))
746 ;; (let ((owindow (selected-window)))
747 ;; (if (and (one-window-p t 'selected-frame) (window-dedicated-p (selected-window)))
748 ;; (iconify-frame (selected-frame)) ; Iconify special buffer's frame
749 ;; (or (window-dedicated-p (selected-window)) (bury-buffer)))
750 ;; (select-window owindow))
751 (unless (or (not (member choice icicle-extra-candidates))
752 icicle-extra-candidates-dir-insert-p)
754 (unless (buffer-live-p buffer) (icicle-user-error "Destination buffer is dead"))
755 (icicle-choose-completion-string choice buffer base-size))))
758 ;; REPLACE ORIGINAL `mouse-choose-completion' in `mouse.el',
759 ;; saving it for restoration when you toggle `icicle-mode'.
761 ;; Return the number of the completion.
762 ;; Don't strip text properties.
764 (when (and (fboundp 'mouse-choose-completion) (not (fboundp 'icicle-ORIG-mouse-choose-completion)))
765 (defalias 'icicle-ORIG-mouse-choose-completion (symbol-function 'mouse-choose-completion)))
767 (unless (or (> emacs-major-version 23) (and (= emacs-major-version 23) ; < Emacs 23.2
768 (> emacs-minor-version 1)))
769 (defun icicle-mouse-choose-completion (event) ; Bound to `mouse-2' in `*Completions*'.
770 "Click a completion candidate in buffer `*Completions*', to choose it.
771 Return the number of the candidate: 0 for first, 1 for second, ..."
773 ;; $$$$$ (unless (active-minibuffer-window) (icicle-user-error "Minibuffer is not active"))
774 ;; Give temporary modes such as isearch a chance to turn off.
775 (run-hooks 'mouse-leave-buffer-hook)
776 (let ((buffer (window-buffer))
777 ;; $$$$$$ (icicle-orig-buff buffer)
779 (with-current-buffer (window-buffer (posn-window (event-start event)))
781 (when completion-reference-buffer (setq buffer completion-reference-buffer))
782 (setq base-size completion-base-size)
784 (goto-char (posn-point (event-start event)))
786 (when (and (not (eobp)) (get-text-property (point) 'mouse-face))
789 (unless beg (icicle-user-error "No completion here"))
790 (setq beg (previous-single-property-change beg 'mouse-face)
791 end (or (next-single-property-change end 'mouse-face) (point-max)))
792 ;; $$$$$$ (setq choice (buffer-substring-no-properties beg end)))))
793 (setq choice (buffer-substring beg end))))))
794 ;; $$$$$ (if (eq icicle-orig-buff (get-buffer "*Completions*"))
795 ;; (icicle-remove-Completions-window)
796 ;; (save-selected-window (icicle-remove-Completions-window)))
797 (setq icicle-candidate-nb (icicle-nb-of-cand-at-Completions-pos (posn-point (event-start event))))
798 (unless (buffer-live-p buffer) (icicle-user-error "Destination buffer is dead"))
799 (when (and (icicle-file-name-input-p) insert-default-directory
800 (or (not (member choice icicle-extra-candidates))
801 icicle-extra-candidates-dir-insert-p))
802 (let ((dir (icicle-file-name-directory-w-default icicle-current-input)))
803 (with-current-buffer buffer
804 (icicle-clear-minibuffer)
806 (setq choice (concat dir choice)
808 (icicle-choose-completion-string choice buffer base-size))
809 icicle-candidate-nb))
811 (defun icicle-nb-of-cand-at-Completions-pos (position)
812 "Return number of candidate at POSITION in `*Completions*'.
813 POSITION is a buffer position."
814 (let ((hor-nb (icicle-nb-of-cand-in-Completions-horiz position)))
816 (with-current-buffer (get-buffer "*Completions*")
818 (if (memq icicle-completions-format '(horizontal nil))
820 (let* ((cols (icicle-nb-Completions-cols))
821 (nb-cands (length icicle-completion-candidates))
822 (rows (/ nb-cands cols)))
823 (unless (zerop (% nb-cands cols)) (setq rows (1+ rows)))
824 (icicle-column-wise-cand-nb hor-nb nb-cands rows cols)))))))
826 (defun icicle-nb-of-cand-in-Completions-horiz (position)
827 "Return number of horizontal candidate at POSITION in `*Completions*'.
828 POSITION is a buffer position."
829 (let ((compl-buf (get-buffer "*Completions*")))
830 (unless compl-buf (error "No `*Completions*' buffer"))
831 (save-window-excursion
832 (set-buffer compl-buf)
834 ;; If in a completion, move to its start, and set POSITION there.
835 (let ((prop (get-text-property (max (point-min) (1- (point))) 'mouse-face)))
836 (when (and prop (eq prop (get-text-property (point) 'mouse-face)))
837 (goto-char (previous-single-property-change (point) 'mouse-face nil
838 (icicle-start-of-candidates-in-Completions)))))
839 (setq position (point))
841 (let ((cand-nb (/ (length icicle-completion-candidates) 2))
843 (icicle-completions-format 'horizontal)
845 (goto-char (point-min))
846 (icicle-move-to-next-completion cand-nb t)
847 (while (/= (point) position)
848 (setq delta (max 1 (/ (abs (- cand-nb last-nb)) 2))
850 (cond ((< (point) position)
851 (icicle-move-to-next-completion delta t)
852 (setq cand-nb (+ cand-nb delta)))
854 (icicle-move-to-next-completion (- delta) t)
855 (setq cand-nb (- cand-nb delta)))))
856 (set-buffer-modified-p nil)
859 (defun icicle-nb-Completions-cols ()
860 "Return the number of candidate columns in `*Completions*'."
861 (let* ((start (icicle-start-of-candidates-in-Completions))
862 (eol (save-excursion (goto-char start) (line-end-position)))
867 (while (< (point) eol)
868 (setq mousef (next-single-property-change (point) 'mouse-face nil eol))
871 (setq mouse-chgs (1+ mouse-chgs)))))
872 ;; Handle the case where the `while' loop is skipped so `mouse-chgs' is still 0.
873 (max 1 (/ (1+ mouse-chgs) 2)))) ; Return # of columns.
875 (defun icicle-column-wise-cand-nb (horiz-nb nb-cands rows cols)
876 "Column-wise number of horizontal candidate number HORIZ-NB."
877 (let ((row-lim (- rows (- (* rows cols) nb-cands)))
878 (row (/ horiz-nb cols))
879 (col (mod horiz-nb cols))
881 (setq nb (+ row (* col rows)))
882 (when (>= row row-lim)
884 horiz-nb (- horiz-nb row-lim)
885 row (/ horiz-nb cols)
886 col (mod horiz-nb cols)
887 nb (+ row (* col rows))))
890 (defun icicle-row-wise-cand-nb (vert-nb nb-cands rows cols)
891 "Row-wise number of vertical candidate number VERT-NB."
892 (let* ((row (mod vert-nb rows))
893 (col (/ vert-nb rows))
894 (nb (+ col (* row cols)))
895 (lim (- rows (- (* rows cols) nb-cands))))
896 (when (> row lim) (setq nb (- nb (- row lim))))
900 ;; REPLACE ORIGINAL `switch-to-completions' defined in `simple.el',
901 ;; saving it for restoration when you toggle `icicle-mode'.
903 ;; Selects `*Completions*' window even if on another frame.
905 (unless (fboundp 'icicle-ORIG-switch-to-completions)
906 (defalias 'icicle-ORIG-switch-to-completions (symbol-function 'switch-to-completions)))
908 (defun icicle-switch-to-completions ()
909 "Select the completion list window, `*Completions*'."
911 ;; Make sure we have a completions window.
912 (or (get-buffer-window "*Completions*") (minibuffer-completion-help))
913 (let ((window (get-buffer-window "*Completions*" 0))) ; Added 0 arg.
915 (select-window window)
916 (goto-char (icicle-start-of-candidates-in-Completions)))))
918 ;; The branch that deletes a history element is based on Juri Linkov's
919 ;; `delete-history-element', proposed for Emacs 22 but rejected by RMS.
921 (defun icicle-erase-minibuffer-or-history-element () ; Bound to `M-k' in minibuffer.
922 "`icicle-erase-minibuffer' or, if using history, delete history element."
924 (if (not (memq last-command '(previous-history-element next-history-element
925 icicle-erase-minibuffer-or-history-element
926 previous-matching-history-element next-matching-history-element)))
927 (icicle-erase-minibuffer)
928 (let* ((curr-pos (1- minibuffer-history-position))
929 (current (nth curr-pos (and (boundp minibuffer-history-variable)
930 (symbol-value minibuffer-history-variable)))))
931 (cond ((= minibuffer-history-position 1)
932 (set minibuffer-history-variable (and (boundp minibuffer-history-variable)
933 (cdr (symbol-value minibuffer-history-variable)))))
934 ((> minibuffer-history-position 1)
935 (setcdr (nthcdr (- minibuffer-history-position 2)
936 (and (boundp minibuffer-history-variable)
937 (symbol-value minibuffer-history-variable)))
938 (nthcdr minibuffer-history-position
939 (and (boundp minibuffer-history-variable)
940 (symbol-value minibuffer-history-variable))))))
942 (cond ((memq last-command '(next-history-element next-matching-history-element))
943 (next-history-element 1)
944 (setq this-command 'next-history-element))
945 ((memq last-command '(previous-history-element previous-matching-history-element))
946 (next-history-element 1)
947 (previous-history-element 1)
948 (setq this-command 'previous-history-element)))
949 (error (icicle-condition-case-no-debug nil
950 (cond ((memq last-command '(next-history-element next-matching-history-element))
951 (previous-history-element 1)
952 (setq this-command 'previous-history-element))
954 '(previous-history-element previous-matching-history-element))
955 (next-history-element 1)
956 (setq this-command 'next-history-element)))
958 (when (and current (wholenump curr-pos))
959 (icicle-msg-maybe-in-minibuffer "Deleted `%s'"
960 (icicle-propertize current 'face 'icicle-msg-emphasis))))))
962 ;;(@* "Icicles commands")
964 ;;; Icicles commands -------------------------------------------------
967 ;;(@* "Minibuffer editing commands")
969 ;;; Minibuffer editing commands . . . . . . . . . . . . . . . . . . .
971 ;;; All except `icicle-erase-minibuffer' are bound in the minibuffer to whatever the same
972 ;;; command without `icicle-' is bound to globally.
975 ;; Same as `bmkp-looking-at-p' in `bookmark+-bmu.el'.
976 ;; Do not `defalias' to Emacs `looking-at-p' because it is a `defsubst'.
977 (defun icicle-looking-at-p (regexp)
978 "Like `looking-at', but this saves and restores the match data."
979 (save-match-data (looking-at regexp)))
981 (defun icicle-looking-at-literally-p (string)
982 "Return non-nil if STRING immediately precedes point."
983 (save-match-data (looking-at (regexp-quote string))))
985 (defun icicle-looking-back-at-literally-p (string)
986 "Return non-nil if STRING immediately precedes point. STRING is
987 matched literally - not as a regexp. In this the function is like
988 `icicle-looking-at-literally-p', not `icicle-looking-at-p'.
989 Saves and restores the match data."
990 (let ((len (length string)))
991 (save-excursion (save-match-data
992 (search-backward string (max (- (point) len) (icicle-minibuffer-prompt-end)) t)))))
994 ;; Used only in `icicle-transpose-chars-magic'.
995 (defun icicle-forward-char-magic (&optional n)
996 "Move forward N chars (backward if N is negative).
997 Handles Icicles dots (`.') and `icicle-list-join-string'."
999 (let ((len-dot (length icicle-anychar-regexp))
1000 (len-join (length icicle-list-join-string)))
1002 (narrow-to-region (icicle-minibuffer-prompt-end) (point-max))
1003 (condition-case nil ; Ignore errors, e.g. `beginning-of-buffer' from `(forward-char -1)'.
1004 (dotimes (i (abs n))
1005 (or (save-match-data
1007 (search-forward icicle-anychar-regexp (min (+ (point) len-dot) (point-max)) t)
1008 (search-backward icicle-anychar-regexp (max (- (point) len-dot) (point-min)) t)))
1011 (search-forward icicle-list-join-string (min (+ (point) len-join) (point-max)) t)
1012 (search-backward icicle-list-join-string (max (- (point) len-join) (point-min)) t)))
1013 (forward-char (if (wholenump n) 1 -1))))
1017 (defun icicle-backward-char-magic (&optional n)
1018 "Move backward N chars (forward if N is negative).
1019 Handles Icicles dots (`.') and `icicle-list-join-string'."
1021 (icicle-forward-char-magic (- n)))
1024 ;; Make delete-selection mode recognize it, so region is deleted.
1025 (put 'icicle-backward-delete-char-untabify 'delete-selection 'supersede)
1027 (defun icicle-backward-delete-char-untabify (n &optional killflag)
1028 "`backward-delete-char-untabify' + update `*Completions*' with matches.
1029 Handles Icicles dots (`.') and `icicle-list-join-string'."
1030 (interactive "*p\nP")
1031 (icicle-call-then-update-Completions #'icicle-backward-delete-char-untabify-magic n killflag))
1033 (defun icicle-backward-delete-char-untabify-magic (n killflag)
1034 "`backward-delete-char-untabify', but also handle magic chars.
1035 That is, handle dots (`.') and `icicle-list-join-string'."
1036 (let ((len-dot (length icicle-anychar-regexp))
1037 (len-join (length icicle-list-join-string)))
1038 (dotimes (i (abs n))
1039 (cond ((icicle-looking-back-at-literally-p icicle-anychar-regexp)
1040 (backward-delete-char-untabify len-dot killflag))
1041 ((icicle-looking-back-at-literally-p icicle-list-join-string)
1042 (backward-delete-char-untabify len-join killflag))
1044 (backward-delete-char-untabify 1 killflag))))))
1047 ;; Make delete-selection mode recognize it, so region is deleted.
1048 (put 'icicle-delete-backward-char 'delete-selection 'supersede)
1050 (defun icicle-delete-backward-char (n &optional killflag) ; Bound to `DEL' in minibuffer.
1051 "`delete-backward-char' and update `*Completions*' with input matches.
1052 Handles Icicles dots (`.') and `icicle-list-join-string'."
1053 (interactive "*p\nP")
1054 (icicle-call-then-update-Completions #'icicle-delete-backward-char-magic n killflag))
1056 (defun icicle-delete-backward-char-magic (n killflag)
1057 "`delete-backward-char', but also handle dots (`.') and join string."
1058 (let ((len-dot (length icicle-anychar-regexp))
1059 (len-join (length icicle-list-join-string)))
1060 (dotimes (i (abs n))
1061 (cond ((icicle-looking-back-at-literally-p icicle-anychar-regexp)
1062 (delete-char (- len-dot) killflag))
1063 ((icicle-looking-back-at-literally-p icicle-list-join-string)
1064 (delete-char (- len-join) killflag))
1066 (delete-char -1 killflag))))))
1069 ;; Make delete-selection mode recognize it, so region is deleted.
1070 (put 'icicle-delete-char 'delete-selection 'supersede)
1072 (defun icicle-delete-char (n &optional killflag) ; Bound to `C-d' in minibuffer.
1073 "`delete-char' and update `*Completions*' with input matches.
1074 Handles Icicles dots (`.') and `icicle-list-join-string'."
1075 (interactive "*p\nP")
1076 (icicle-call-then-update-Completions #'icicle-delete-char-magic n killflag))
1078 (defun icicle-delete-char-magic (n killflag)
1079 "`delete-char', but also handle dot (`.') and `icicle-list-join-string'."
1080 (let ((len-dot (length icicle-anychar-regexp))
1081 (len-join (length icicle-list-join-string)))
1082 (dotimes (i (abs n))
1083 (cond ((icicle-looking-at-literally-p icicle-anychar-regexp)
1084 (delete-char len-dot killflag))
1085 ((icicle-looking-at-literally-p icicle-list-join-string)
1086 (delete-char len-join killflag))
1088 (delete-char 1 killflag))))))
1090 (defun icicle-backward-kill-word (arg) ; Bound to `M-DEL' (`M-backspace') in minibuffer.
1091 "`backward-kill-word' and update `*Completions*' with input matches.
1092 See description of `backward-kill-word'."
1094 (icicle-call-then-update-Completions #'backward-kill-word arg))
1096 (defun icicle-kill-word (arg) ; Bound to `M-d' in minibuffer.
1097 "`kill-word' and update `*Completions*' with regexp input matches.
1098 See description of `kill-word'."
1100 (icicle-call-then-update-Completions #'kill-word arg))
1102 (defun icicle-backward-kill-sexp (arg) ; Bound to `C-M-backspace' in minibuffer.
1103 "`backward-kill-sexp' and update `*Completions*' with input matches.
1104 See description of `backward-kill-sexp'."
1106 (icicle-call-then-update-Completions #'backward-kill-sexp arg))
1108 (defun icicle-kill-sexp (arg) ; Bound to `C-M-delete' and `C-M-k' in minibuffer.
1109 "`kill-sexp' and update `*Completions*' with regexp input matches.
1110 See description of `kill-sexp'."
1112 (icicle-call-then-update-Completions #'kill-sexp arg))
1114 (defun icicle-backward-kill-sentence (arg) ; Bound to `C-x DEL' in minibuffer.
1115 "`backward-kill-sentence' and update `*Completions*' with input matches.
1116 See description of `backward-kill-sentence'."
1118 (icicle-call-then-update-Completions #'backward-kill-sentence arg))
1120 (defun icicle-kill-sentence (arg)
1121 "`kill-sentence' and update `*Completions*' with regexp input matches.
1122 See description of `kill-sentence'."
1124 (icicle-call-then-update-Completions #'kill-sentence arg))
1126 (defun icicle-backward-kill-paragraph (arg) ; Bound to `C-backspace' in minibuffer, except for files.
1127 "`backward-kill-paragraph' and update `*Completions*' with input matches.
1128 See description of `backward-kill-paragraph'."
1130 (icicle-call-then-update-Completions #'backward-kill-paragraph arg))
1132 (defun icicle-kill-paragraph (arg) ; Bound to `C-delete' in minibuffer.
1133 "`kill-paragraph' and update `*Completions*' with regexp input matches.
1134 See description of `kill-paragraph'."
1136 (icicle-call-then-update-Completions #'kill-paragraph arg))
1138 (defun icicle-kill-line (arg) ; Bound to `C-k' and `deleteline' in minibuffer.
1139 "`kill-line' and update `*Completions*' with regexp input matches.
1140 See description of `kill-line'."
1142 (icicle-call-then-update-Completions #'kill-line arg))
1144 (defun icicle-kill-region (beg end) ; Bound to `C-w' in minibuffer.
1145 ;; Don't bother with Emacs 22 optional 3rd arg.
1146 "`kill-region' and update `*Completions*' with regexp input matches.
1147 See description of `kill-region'."
1149 (icicle-call-then-update-Completions #'kill-region beg end))
1151 (when (fboundp 'kill-region-wimpy)
1152 (defun icicle-kill-region-wimpy (beg end) ; Bound to `C-w' in minibuffer.
1153 "`kill-region-wimpy' and update `*Completions*' with input matches.
1154 See description of `kill-region-wimpy'."
1156 (icicle-call-then-update-Completions #'kill-region-wimpy beg end)))
1158 (defun icicle-complete-current-candidate-as-input ()
1159 "Complete the current candidate as if it were your input pattern.
1160 Use this to descend into a directory candidate, replacing the current
1161 set of candidates by the contents of that directory.
1163 If not completing file names or the current candidate does not name a
1164 directory, then this just makes the candidate the sole candidate."
1166 (when (interactive-p) (icicle-barf-if-outside-Completions-and-minibuffer))
1167 (when (eq (current-buffer) (get-buffer "*Completions*")) (icicle-insert-completion))
1168 (setq icicle-cycling-p nil)
1170 (funcall (or icicle-last-completion-command (if (eq icicle-current-completion-mode 'prefix)
1171 #'icicle-prefix-complete
1172 #'icicle-apropos-complete))))
1174 (defun icicle-dispatch-C-M-/ ()
1175 "Do the right thing for `C-M-/'.
1176 If the minibuffer is active then invoke
1177 `icicle-complete-current-candidate-as-input'.
1178 Otherwise, invoke `icicle-dabbrev-completion' (or
1179 `dabbrev-completion')."
1181 (call-interactively (if (active-minibuffer-window)
1182 #'icicle-complete-current-candidate-as-input
1183 (if (fboundp 'icicle-dabbrev-completion)
1184 'icicle-dabbrev-completion
1185 'dabbrev-completion))))
1187 (defun icicle-make-directory (dir) ; Bound to `C-c +' in minibuffer, for file-name completion.
1188 "Create a directory."
1190 (let ((candidates icicle-completion-candidates)
1191 (minibuffer-completion-confirm minibuffer-completion-confirm) ; `read-directory-name' messes it.
1192 (enable-recursive-minibuffers t))
1195 (if (fboundp 'read-directory-name) #'read-directory-name #'read-file-name)
1196 "Create directory: " default-directory (icicle-file-name-directory-w-default
1197 (icicle-input-from-minibuffer))))
1198 (setq icicle-completion-candidates candidates))))
1199 (setq dir (directory-file-name (expand-file-name dir)))
1200 (let ((candidates icicle-completion-candidates)
1201 (minibuffer-completion-confirm minibuffer-completion-confirm) ; `read-directory-name' messes it.
1202 (enable-recursive-minibuffers t))
1203 (while (file-exists-p dir) ; This will cause Tramp to access if remote, but that's OK here.
1204 (message "%s already exists" dir) (sit-for 1)
1206 (setq dir (funcall (if (fboundp 'read-directory-name) #'read-directory-name #'read-file-name)
1207 "Create directory: " default-directory (icicle-file-name-directory-w-default
1208 (icicle-input-from-minibuffer))))
1209 (setq icicle-completion-candidates candidates))))
1210 ;;(setq dir (directory-file-name (expand-file-name dir)))
1211 (if (not (y-or-n-p (format "Really create %s? " (file-name-as-directory dir))))
1212 (message "Directory creation canceled")
1213 (make-directory dir 'PARENTS-TOO)
1214 (unless (file-accessible-directory-p dir) (error "Could not create %s" (file-name-as-directory dir)))
1215 (message "Created %s" (file-name-as-directory dir))))
1217 (defun icicle-up-directory () ; Bound to `C-backspace' in minibuffer, for file-name completion.
1218 "Replace minibuffer input with parent directory, then upate `*Completions*'."
1220 (icicle-call-then-update-Completions #'icicle-replace-input-w-parent-dir))
1222 (defun icicle-replace-input-w-parent-dir ()
1223 "Replace minibuffer input with the parent directory."
1225 (goto-char (point-max))
1226 (let ((directoryp (equal ?/ (char-before)))
1227 (bob (icicle-minibuffer-prompt-end)))
1228 (while (and (> (point) bob) (not (equal ?/ (char-before)))) (delete-char -1))
1231 (while (and (> (point) bob) (not (equal ?/ (char-before)))) (delete-char -1)))))
1233 (defun icicle-file-all-tags-narrow () ; Bound to `C-x C-t *' in minibuffer, for file-name completion.
1234 "Narrow file-name candidates to those with all of the tags you specify.
1235 You are prompted for the tags.
1236 You can add and remove tags for a file during completion, using
1237 `C-x a +' and `C-x a -', respectively.
1238 See also top-level command `icicle-find-file-tagged'."
1240 (unless icicle-completion-candidates
1241 (icicle-user-error "No completion candidates. Did you use `TAB' or `S-TAB'?"))
1242 (unless (require 'bookmark+ nil t) (icicle-user-error "You need library `Bookmark+' for this command"))
1243 (let* ((candidates icicle-completion-candidates)
1244 (enable-recursive-minibuffers t)
1245 (tags (bmkp-read-tags-completing nil nil current-prefix-arg))
1247 (let* ((bmk (bmkp-get-autofile-bookmark ff))
1248 (btgs (and bmk (bmkp-get-tags bmk))))
1249 (and btgs (bmkp-every (lambda (tag) (bmkp-has-tag-p bmk tag))
1251 (setq icicle-completion-candidates candidates)
1252 (icicle-narrow-candidates-with-predicate pred)))
1254 (defun icicle-file-all-tags-regexp-narrow () ; Bound to `C-x C-t % *' in minibuf, for file-name completion.
1255 "Narrow file-name candidates to those with all tags matching a regexp.
1256 You are prompted for the regexp.
1257 You can add and remove tags for a file during completion, using
1258 `C-x a +' and `C-x a -', respectively.
1259 See also top-level command `icicle-find-file-all-tags-regexp'."
1261 (unless icicle-completion-candidates
1262 (icicle-user-error "No completion candidates. Did you use `TAB' or `S-TAB'?"))
1263 (unless (require 'bookmark+ nil t) (icicle-user-error "You need library `Bookmark+' for this command"))
1264 (bookmark-maybe-load-default-file)
1265 (let* ((candidates icicle-completion-candidates)
1266 (enable-recursive-minibuffers t)
1267 (regexp (icicle-read-regexp "Regexp for tags: "))
1269 (let* ((bmk (bmkp-get-autofile-bookmark ff))
1270 (btgs (and bmk (bmkp-get-tags bmk))))
1271 (and btgs (bmkp-every
1273 (string-match ',regexp (bmkp-tag-name tag)))
1275 (setq icicle-completion-candidates candidates)
1276 (icicle-narrow-candidates-with-predicate pred)))
1278 (defun icicle-file-some-tags-narrow () ; Bound to `C-x C-t +' in minibuffer, for file-name completion.
1279 "Narrow file-name candidates to those with some of the tags you specify.
1280 You are prompted for the tags.
1281 You can add and remove tags for a file during completion, using
1282 `C-x a +' and `C-x a -', respectively.
1283 See also top-level command `icicle-find-file-tagged'."
1285 (unless icicle-completion-candidates
1286 (icicle-user-error "No completion candidates. Did you use `TAB' or `S-TAB'?"))
1287 (unless (require 'bookmark+ nil t) (icicle-user-error "You need library `Bookmark+' for this command"))
1288 (let* ((candidates icicle-completion-candidates)
1289 (enable-recursive-minibuffers t)
1290 (tags (bmkp-read-tags-completing nil nil current-prefix-arg))
1292 (let* ((bmk (bmkp-get-autofile-bookmark ff))
1293 (btgs (and bmk (bmkp-get-tags bmk))))
1294 (and btgs (bmkp-some (lambda (tag) (bmkp-has-tag-p bmk tag))
1296 (setq icicle-completion-candidates candidates)
1297 (icicle-narrow-candidates-with-predicate pred)))
1299 (defun icicle-file-some-tags-regexp-narrow () ; Bound to `C-x C-t % +' in minibuf, for file-name completion.
1300 "Narrow file-name candidates to those with some tags matching a regexp.
1301 You are prompted for the regexp.
1302 You can add and remove tags for a file during completion, using
1303 `C-x a +' and `C-x a -', respectively.
1304 See also top-level command `icicle-find-file-some-tags-regexp'."
1306 (unless icicle-completion-candidates
1307 (icicle-user-error "No completion candidates. Did you use `TAB' or `S-TAB'?"))
1308 (unless (require 'bookmark+ nil t) (icicle-user-error "You need library `Bookmark+' for this command"))
1309 (bookmark-maybe-load-default-file)
1310 (let* ((candidates icicle-completion-candidates)
1311 (enable-recursive-minibuffers t)
1312 (regexp (icicle-read-regexp "Regexp for tags: "))
1314 (let* ((bmk (bmkp-get-autofile-bookmark ff))
1315 (btgs (and bmk (bmkp-get-tags bmk))))
1316 (and btgs (bmkp-some
1318 (string-match ',regexp (bmkp-tag-name tag)))
1320 (setq icicle-completion-candidates candidates)
1321 (icicle-narrow-candidates-with-predicate pred)))
1323 ;;; (defun icicle-kill-failed-input () ; Bound to `C-M-l' in minibuffer during completion.
1324 ;;; "Kill (delete) the part of the input that does not complete.
1325 ;;; Repeat to delete more."
1327 ;;; (goto-char (max (point-min) (1- (point))))
1328 ;;; (while (and (not (bobp))
1329 ;;; (memq (get-text-property (point) 'face)
1330 ;;; '(icicle-input-completion-fail icicle-input-completion-fail-lax)))
1332 ;;; (backward-char 1))
1333 ;;; (unless (eobp) (forward-char))
1334 ;;; (icicle-highlight-input-noncompletion))
1336 (defun icicle-goto/kill-failed-input () ; Bound to `C-M-l' in minibuffer during completion.
1337 "Go to start of input portion that does not complete. Repeat to kill.
1338 Kill (delete) the part of the input that does not complete.
1339 Repeat to delete more."
1341 (if (eq last-command this-command)
1342 (unless (eobp) (kill-line))
1343 (when (and (overlayp icicle-input-completion-fail-overlay)
1344 (overlay-start icicle-input-completion-fail-overlay))
1345 (goto-char (overlay-start icicle-input-completion-fail-overlay)))))
1347 (defun icicle-transpose-chars (arg) ; Bound to `C-t' in minibuffer.
1348 "`transpose-chars' and update `*Completions*' with regexp input matches.
1349 Handles Icicles dots (`.') and `icicle-list-join-string'."
1351 (icicle-call-then-update-Completions #'icicle-transpose-chars-magic arg))
1353 (defun icicle-transpose-chars-magic (arg)
1354 "`transpose-chars', but handle dots (`.') and `icicle-list-join-string'."
1355 (and (null arg) (eolp) (icicle-forward-char-magic -1))
1356 (transpose-subr 'icicle-forward-char-magic (prefix-numeric-value arg)))
1358 (defun icicle-transpose-words (arg) ; Bound to `M-t' in minibuffer.
1359 "`transpose-words' and update `*Completions*' with regexp input matches.
1360 See description of `transpose-words'."
1362 (icicle-call-then-update-Completions #'transpose-words arg))
1364 (defun icicle-transpose-sexps (arg) ; Bound to `C-M-t' in minibuffer.
1365 "`transpose-sexps' and update `*Completions*' with regexp input matches.
1366 See description of `transpose-sexps'."
1368 (icicle-call-then-update-Completions #'transpose-sexps arg))
1370 (defun icicle-yank (arg) ; Bound to `C-y' and `S-insert' in minibuffer.
1371 "`yank' and update `*Completions*' with regexp input matches.
1372 See description of `yank'."
1374 (icicle-call-then-update-Completions #'yank arg))
1376 (defun icicle-yank-pop (arg) ; Bound to `M-y' and `M-insert' in minibuffer.
1377 "`yank-pop' and update `*Completions*' with regexp input matches.
1378 See description of `yank-pop'."
1380 (icicle-call-then-update-Completions #'yank-pop arg))
1382 (eval-after-load "second-sel"
1383 '(progn (defun icicle-yank-secondary () ; Bound to `C-M-y' in minibuffer.
1384 "Insert the secondary selection at point.
1385 Move point to the end of the inserted text. Does not change mark."
1387 (icicle-call-then-update-Completions #'yank-secondary))
1389 ;; Tell `delete-selection-mode' to replace active region by yanked secondary selection.
1390 (put 'icicle-yank-secondary 'delete-selection 'yank)))
1393 ;; Tell `delete-selection-mode' to replace active region by yanked secondary selection.
1394 (put 'icicle-mouse-yank-secondary 'delete-selection 'yank)
1396 (defun icicle-mouse-yank-secondary (event) ; Bound to `M-mouse-2' in minibuffer.
1397 "Insert the secondary selection where you click.
1398 Move point to the end of the inserted text.
1399 If `mouse-yank-at-point' is non-nil, insert at point
1400 regardless of where you click."
1402 (if (fboundp 'yank-secondary) ; In `mouse+.el'.
1403 (icicle-call-then-update-Completions #'mouse-yank-secondary event current-prefix-arg)
1404 (icicle-call-then-update-Completions #'mouse-yank-secondary event)))
1407 ;; Make delete-selection mode recognize self-insertion, so it replaces region text.
1408 (if (or (> emacs-major-version 24) (and (= emacs-major-version 24) (> emacs-minor-version 2)))
1409 (put 'icicle-self-insert 'delete-selection
1410 (lambda () (not (run-hook-with-args-until-success 'self-insert-uses-region-functions))))
1411 (put 'icicle-self-insert 'delete-selection t))
1413 (defun icicle-self-insert (ch) ;; Bound in minibuffer to stuff bound globally to `self-insert-command'.
1414 "Insert char CH and update `*Completions*' with regexp input matches.
1415 See description of `self-insert-command'."
1417 (if executing-kbd-macro
1418 (funcall #'self-insert-command ch)
1419 (icicle-call-then-update-Completions #'self-insert-command ch)))
1421 (defun icicle-insert-a-space ()
1423 For convenience in the minibuffer - does the same thing as `C-q SPC'.
1424 To use this, bind it to some key sequence in keymaps
1425 `minibuffer-local-completion-map',
1426 `minibuffer-local-filename-completion-map', and
1427 `minibuffer-local-must-match-map'."
1428 (interactive) (insert ?\ ))
1430 (defun icicle-insert-dot-command (&optional arg) ; Bound to `.' in minibuffer during completion.
1431 "Insert `icicle-dot-string': either `.' or `icicle-anychar-regexp'.
1432 With a numeric prefix argument, insert the dot that many times.
1434 With a plain prefix arg (`C-u'), insert the opposite kind of dot
1435 \(once) from what is indicated by the current value of
1436 `icicle-dot-string'."
1438 (when (interactive-p) (icicle-barf-if-outside-minibuffer))
1440 (let ((opposite (if (string= icicle-dot-string-internal ".")
1441 (icicle-anychar-regexp)
1443 (add-text-properties
1444 0 1 '(icicle-user-plain-dot t rear-nonsticky (icicle-user-plain-dot))
1447 (if executing-kbd-macro
1449 (icicle-call-then-update-Completions (lambda () (insert opposite)))))
1450 (setq arg (prefix-numeric-value arg))
1451 (if executing-kbd-macro
1452 (funcall #'icicle-insert-dot arg)
1453 (icicle-call-then-update-Completions #'icicle-insert-dot arg))))
1455 (defun icicle-insert-dot (n)
1456 "Insert `icicle-dot-string' N times."
1458 (if (not (string= icicle-dot-string-internal "."))
1459 (insert (icicle-anychar-regexp))
1461 (add-text-properties (max (point-min) (1- (point))) (point)
1462 '(icicle-user-plain-dot t rear-nonsticky t)))))
1464 (defun icicle-anychar-regexp ()
1465 "Return a regexp that matches any single character, including newline.
1466 The value returned is like that of constant `icicle-anychar-regexp',
1467 but the `display' string is unique for each call."
1468 (let ((strg (copy-sequence "\\(.\\|[\n]\\)")))
1469 (set-text-properties 0 (length strg)
1470 (if icicle-dot-show-regexp-flag
1471 '(face highlight rear-nonsticky t)
1472 `(display ,(copy-sequence ".") face highlight rear-nonsticky t))
1476 (defun icicle-erase-minibuffer () ; Bound to `M-S-backspace', `M-S-delete' in minibuffer.
1477 "Delete all user input in the minibuffer, then update completions."
1479 (icicle-call-then-update-Completions #'icicle-clear-minibuffer))
1481 ;;(@* "Commands to sort completion candidates")
1483 ;;; Commands to sort completion candidates . . . . . . . . . . . . . .
1485 ;; We don't bother to define a command for the sort functions `icicle-prefix-keys-first-p' and
1486 ;; `icicle-command-names-alphabetic-p'. They are bound in `icicle-complete-keys'.
1488 ;; The order here defines the reverse order of `icicle-sort-orders-alist'.
1489 ;; The first here is also the default sort order. Entries are traversed by `C-,' in
1490 ;; `icicle-sort-orders-alist' order.
1492 (icicle-define-sort-command "alphabetical" ; `icicle-sort-alphabetical'
1493 icicle-case-string-less-p
1494 "Sort completion candidates alphabetically.
1495 Ignore letter case if `completion-ignore-case' or `case-fold-search'
1498 (icicle-define-sort-command "special candidates first" ; `icicle-sort-special-candidates-first'
1499 icicle-special-candidates-first-p
1500 "Sort completion candidates by putting special candidates first.
1501 Otherwise, sorting is alphabetical. Ignore letter case if
1502 `completion-ignore-case' or `case-fold-search' is non-nil.")
1504 (icicle-define-sort-command "extra candidates first" ; `icicle-sort-extra-candidates-first'
1505 icicle-extra-candidates-first-p
1506 "Sort completion candidates by putting extra candidates first.
1507 Otherwise, sorting is alphabetical. Ignore letter case if
1508 `completion-ignore-case' or `case-fold-search' is non-nil.
1509 An extra candidate is one that is a member of
1510 `icicle-extra-candidates'.")
1512 (icicle-define-sort-command "proxy candidates first" ; `icicle-sort-proxy-candidates-first'
1513 icicle-proxy-candidate-first-p
1514 "Sort completion candidates by putting proxy candidates first.
1515 Otherwise, sorting is alphabetical. Ignore letter case if
1516 `completion-ignore-case' or `case-fold-search' is non-nil.")
1518 (icicle-define-sort-command "case insensitive" ; `icicle-sort-case-insensitive'
1519 icicle-case-insensitive-string-less-p
1520 "Sort completion candidates alphabetically, but case-insenstively.")
1522 (icicle-define-sort-command "by 2nd parts alphabetically" ; `icicle-sort-by-2nd-parts-alphabetically'
1523 icicle-2nd-part-string-less-p
1524 "Sort multi-completion candidates alphabetically by their second parts.
1525 After that, sort alphabetically by the first parts. Ignore letter
1526 case if `completion-ignore-case' or `case-fold-search' is non-nil.")
1528 (icicle-define-sort-command "by last use" ; `icicle-sort-by-last-use'
1529 icicle-latest-use-first-p
1530 "Sort file-name completion candidates in order of last use.
1531 \"Use\" here refers, first, to use as your input, second, to access.")
1533 (icicle-define-sort-command "by last file access time"
1534 icicle-latest-access-first-p ; `icicle-sort-by-last-file-access-time'
1535 "Sort file-name completion candidates in order of last access.
1536 If not doing file-name completion, then sort alphabetically.")
1538 (icicle-define-sort-command "by last file modification time"
1539 icicle-latest-modification-first-p ; `icicle-sort-by-last-file-modification-time'
1540 "Sort file-name completion candidates in order of last modification.
1541 If not doing file-name completion, then sort alphabetically.")
1543 (icicle-define-sort-command "by file type" ; `icicle-sort-by-file-type'
1544 icicle-file-type-less-p
1545 "Sort file-name completion candidates by file type.
1546 Directories sort first, alphabetically.
1547 Then sort by file type (extension), alphabetically.
1548 Sort names that have the same extension alphabetically.
1549 If not doing file-name completion, sort candidates alphabetically.")
1551 (icicle-define-sort-command "by last use, dirs first" ; `icicle-sort-by-last-use\,-dirs-first'
1552 icicle-dirs-and-latest-use-first-p
1553 "Sort file-name completion candidates by last use, directories first.
1554 If not doing file-name completion, then sort only by last use.
1555 \"Use\" here refers, first, to use as your input, second, to access.")
1557 (icicle-define-sort-command "by directories first" ; `icicle-sort-by-directories-first'
1559 "Sort file-name completion candidates so that directories are first.
1560 If not doing file-name completion, then sort alphabetically.")
1562 (icicle-define-sort-command "by directories last" ; `icicle-sort-by-directories-last'
1564 "Sort file-name completion candidates so that directories are last.
1565 If not doing file-name completion, then sort alphabetically.")
1567 (icicle-define-sort-command "by last use as input" ; `icicle-sort-by-last-use-as-input'
1568 icicle-latest-input-first-p
1569 "Sort completion candidates in order of last use as minibuffer input.")
1571 (icicle-define-sort-command "by previous use alphabetically"
1572 icicle-historical-alphabetic-p ; `icicle-sort-by-previous-use-alphabetically'
1573 "Sort completion candidates by previous use and alphabetically.
1574 Candidates matching previous inputs are available first. Candidates
1575 are in two groups, each of which is sorted alphabetically separately:
1576 those matching previous inputs, followed by those that have not yet
1579 (icicle-define-sort-command "by abbrev frequency" ; `icicle-sort-by-abbrev-frequency'
1580 icicle-command-abbrev-used-more-p
1581 "Sort abbrev completion candidates by frequency of use
1582 Otherwise, sort alphabetically. Ignore letter case if
1583 `completion-ignore-case' or `case-fold-search' is non-nil.")
1585 (icicle-define-sort-command "turned OFF" nil ; `icicle-sort-turned-OFF'
1586 "Do not sort completion candidates.")
1588 (defun icicle-dispatch-M-_ () ; Bound to `M-_' in minibuffer.
1589 "Do the right thing for `M-_'.
1590 During Icicles search, call `icicle-toggle-search-replace-whole'.
1591 Otherwise, call `icicle-toggle-ignored-space-prefix'.
1592 Bound to `M-_' in the minibuffer."
1594 (if icicle-searching-p (icicle-toggle-search-replace-whole) (icicle-toggle-ignored-space-prefix)))
1597 ;;; (defun icicle-dispatch-C-comma ()
1598 ;;; "Do the right thing for `C-,'.
1599 ;;; When candidate sorting is possible, call `icicle-change-sort-order'.
1600 ;;; When searching, call `icicle-toggle-search-replace-whole'.
1601 ;;; Otherwise, do nothing.
1603 ;;; Bound to `C-,' in the minibuffer."
1605 ;;; (cond (icicle-searching-p (icicle-toggle-search-replace-whole))
1606 ;;; (icicle-inhibit-sort-p (message "Cannot sort candidates now"))
1607 ;;; (t (call-interactively #'icicle-change-sort-order))))
1609 ;; Top-level commands. Could instead be in `icicles-cmd2.el'.
1611 (defalias 'toggle-icicle-ignoring-comments 'icicle-toggle-ignoring-comments)
1612 (defun icicle-toggle-ignoring-comments () ; Bound to `C-M-;' in minibuffer.
1613 "Toggle the value of option `icicle-ignore-comments-flag'.
1614 If option `ignore-comments-flag' is defined (in library
1615 `hide-comnt.el') then it too is toggled.
1616 Bound to `C-M-;' in the minibuffer."
1618 (setq icicle-ignore-comments-flag (not icicle-ignore-comments-flag))
1619 (when (boundp 'ignore-comments-flag) (setq ignore-comments-flag (not ignore-comments-flag)))
1620 (icicle-msg-maybe-in-minibuffer
1621 "Ignoring comments is now %s" (icicle-propertize (if icicle-ignore-comments-flag "ON" "OFF")
1622 'face 'icicle-msg-emphasis)))
1624 ;; Top-level commands. Could instead be in `icicles-cmd2.el'.
1626 (defalias 'toggle-icicle-search-replace-common-match 'icicle-toggle-search-replace-common-match)
1627 (defun icicle-toggle-search-replace-common-match () ; Bound to `M-;' in minibuffer.
1628 "Toggle the value of `icicle-search-replace-common-match-flag'.
1629 Note that that option has no effect if the value of option
1630 `icicle-expand-input-to-common-match' does not imply expansion.
1631 Bound to `M-;' in the minibuffer."
1633 (setq icicle-search-replace-common-match-flag (not icicle-search-replace-common-match-flag))
1634 (icicle-msg-maybe-in-minibuffer
1635 "Replacing expanded common match is now %s"
1636 (icicle-propertize (if icicle-search-replace-common-match-flag "ON" "OFF")
1637 'face 'icicle-msg-emphasis)))
1639 ;; Top-level commands. Could instead be in `icicles-cmd2.el'.
1641 (defalias 'toggle-icicle-search-replace-whole 'icicle-toggle-search-replace-whole)
1642 (defun icicle-toggle-search-replace-whole ()
1643 "Toggle the value of `icicle-search-replace-whole-candidate-flag'.
1644 Bound to `M-_' in the minibuffer when searching."
1646 (setq icicle-search-replace-whole-candidate-flag (not icicle-search-replace-whole-candidate-flag))
1647 (icicle-msg-maybe-in-minibuffer
1648 "Replacing whole search context is now %s"
1649 (icicle-propertize (if icicle-search-replace-whole-candidate-flag "ON" "OFF")
1650 'face 'icicle-msg-emphasis)))
1652 ;; Top-level commands. Could instead be in `icicles-cmd2.el'.
1654 (defalias 'toggle-icicle-dot 'icicle-toggle-dot)
1655 (defalias 'toggle-icicle-. 'icicle-toggle-dot)
1656 (defalias 'icicle-toggle-. 'icicle-toggle-dot)
1657 (defun icicle-toggle-dot () ; Bound to `C-M-.' in minibuffer.
1658 "Toggle `icicle-dot-string' between `.' and `icicle-anychar-regexp'.
1659 Bound to `C-M-.' in the minibuffer."
1661 (setq icicle-dot-string (if (string= icicle-dot-string ".") (icicle-anychar-regexp) "."))
1662 (icicle-msg-maybe-in-minibuffer
1663 (cond ((string= icicle-dot-string ".")
1664 (icicle-convert-dots (equal icicle-current-input icicle-last-input) t)
1665 (format "`%s' now matches any char %s newline"
1666 (icicle-propertize "." 'face 'icicle-msg-emphasis)
1667 (icicle-propertize "EXCEPT" 'face 'icicle-msg-emphasis)))
1669 (icicle-convert-dots (equal icicle-current-input icicle-last-input))
1670 (format "`%s' now matches any char, including %s"
1671 (icicle-propertize "." 'face 'icicle-msg-emphasis)
1672 (icicle-propertize "NEWLINE" 'face 'icicle-msg-emphasis)))))
1673 (setq icicle-dot-string-internal icicle-dot-string))
1675 (defun icicle-convert-dots (&optional no-confirm-p plainp)
1676 "Convert existing dots.
1677 Optional arg NO-CONFIRM-P means don't ask user for confirmation.
1678 Optional arg PLAINP means convert to plain `.'.
1679 Otherwise, convert to `icicle-anychar-regexp'."
1682 (when (and (goto-char (icicle-minibuffer-prompt-end))
1683 (search-forward icicle-anychar-regexp nil t))
1684 (goto-char (icicle-minibuffer-prompt-end))
1685 (while (search-forward icicle-anychar-regexp nil t)
1686 (replace-match "." nil t))))
1688 (when (and (goto-char (icicle-minibuffer-prompt-end)) (search-forward "." nil t))
1689 (goto-char (icicle-minibuffer-prompt-end))
1691 (while (search-forward "." nil t)
1692 ;; If we hit a plain dot inserted by user explicitly, ask if we should convert all such.
1693 (when (and (not allp)
1694 (get-text-property (match-beginning 0) 'icicle-user-plain-dot)
1696 (y-or-n-p "Should all dots (`.') in current input match newlines too? "))
1698 (when (or allp (not (get-text-property (match-beginning 0) 'icicle-user-plain-dot)))
1699 (replace-match (icicle-anychar-regexp) nil t))))))))
1701 ;; Top-level commands. Could instead be in `icicles-cmd2.el'.
1702 (when (require 'image-dired nil t) ; Emacs 22+.
1703 (defalias 'cycle-icicle-image-file-thumbnail 'icicle-cycle-image-file-thumbnail)
1704 (defun icicle-cycle-image-file-thumbnail () ; Bound to `C-x t' in minibuffer.
1705 "Toggle `icicle-image-files-in-Completions'.
1706 This has no effect if you do not have library `image-dired.el' (Emacs 23+).
1707 Bound to `C-x t' in the minibuffer."
1709 (if (not (require 'image-dired nil t))
1710 (message "No-op: this command requires library `image-dired.el'")
1711 (setq icicle-image-files-in-Completions (case icicle-image-files-in-Completions
1715 (icicle-complete-again-update)
1716 (icicle-msg-maybe-in-minibuffer
1717 (case icicle-image-files-in-Completions
1718 ((nil) (format "Image files in `*Completions*': showing only %s Next: only IMAGES"
1719 (icicle-propertize "NAMES" 'face 'icicle-msg-emphasis)))
1720 (image-only (format "Image files in `*Completions*': showing only %s Next: IMAGES and NAMES"
1721 (icicle-propertize "IMAGES" 'face 'icicle-msg-emphasis)))
1722 (t (format "Image files in `*Completions*': showing %s Next: only NAMES"
1723 (concat (icicle-propertize "IMAGES" 'face 'icicle-msg-emphasis)
1725 (icicle-propertize "NAMES" 'face 'icicle-msg-emphasis)))))))))
1727 ;; This works hand in hand with `icicle-maybe-sort-maybe-truncate'. Update both together.
1729 (defun icicle-doremi-increment-max-candidates+ (&optional increment) ; `C-x #' in minibuffer
1730 "Change `icicle-max-candidates' incrementally.
1731 Use `up', `down' or the mouse wheel to increase or decrease. You can
1732 use the `Meta' key (e.g. `M-up') to increment in larger steps.
1733 You can use a numeric prefix arg to specify the increment.
1734 A plain prefix arg (`C-u') resets `icicle-max-candidates' to nil,
1737 (cond ((consp increment)
1738 (setq icicle-max-candidates 'RESET) ; `icicle-maybe-sort-maybe-truncate' will reset to nil.
1739 (icicle-msg-maybe-in-minibuffer "No longer any limit on number of candidates"))
1741 (setq increment (prefix-numeric-value increment))
1742 (unless (require 'doremi nil t)
1743 (icicle-user-error "You need library `doremi.el' for this command"))
1744 (let ((mini (active-minibuffer-window)))
1746 (save-selected-window
1747 (select-window (minibuffer-window))
1748 (unless icicle-completion-candidates (message "Hit `TAB' or `S-TAB'"))
1749 (let ((enable-recursive-minibuffers t)
1750 (nb-cands (length icicle-completion-candidates)))
1751 (when (or (not (integerp icicle-max-candidates)) ; Not `RESET' or nil.
1752 (> icicle-max-candidates nb-cands))
1753 (setq icicle-max-candidates nb-cands))
1754 (when (zerop icicle-max-candidates) (setq icicle-max-candidates 10))
1755 (doremi (lambda (new-val)
1756 (setq icicle-max-candidates (setq new-val (doremi-limit new-val 2 nil)))
1757 (unless (input-pending-p)
1758 (let ((icicle-edit-update-p t)
1759 (icicle-last-input nil))
1760 (funcall (or icicle-last-completion-command
1761 (if (eq icicle-current-completion-mode 'prefix)
1762 #'icicle-prefix-complete
1763 #'icicle-apropos-complete)))
1764 (run-hooks 'icicle-update-input-hook)))
1766 icicle-max-candidates
1768 (setq unread-command-events ()))
1769 (unless mini (icicle-remove-Completions-window)))))))
1771 (defun icicle-doremi-increment-swank-timeout+ () ; Bound to `C-x 1' in minibuffer (swank only)
1772 "Change `icicle-swank-timeout' incrementally.
1773 Use `up', `down' or the mouse wheel to increase or decrease. You can
1774 use the `Meta' key (e.g. `M-up') to increment in larger steps."
1776 (icicle-doremi-increment-variable+ 'icicle-swank-timeout 1000))
1778 (defun icicle-doremi-increment-swank-prefix-length+ () ; Bound to `C-x 2' in minibuffer (swank only)
1779 "Change `icicle-swank-prefix-length' incrementally.
1780 Use `up', `down' or the mouse wheel to increase or decrease. You can
1781 use the `Meta' key (e.g. `M-up') to increment in larger steps."
1783 (icicle-doremi-increment-variable+ 'icicle-swank-prefix-length 1))
1785 ;; Top-level commands. Could instead be in `icicles-cmd2.el'.
1787 (defalias 'cycle-icicle-TAB-completion-method 'icicle-next-TAB-completion-method)
1788 (defun icicle-next-TAB-completion-method (temporary-p) ; Bound to `C-(' in minibuffer.
1789 "Cycle to the next `TAB' completion method.
1790 Bound to \\<minibuffer-local-completion-map>`\\[icicle-next-TAB-completion-method]' \
1792 Option `icicle-TAB-completion-methods' determines the TAB completion
1793 methods that are available.
1795 With a prefix argument, the newly chosen method is used only for the
1796 current command. More precisely, the previously active method is
1797 restored as soon as you return to the top level."
1799 (unless icicle-current-TAB-method ; nil means the same as the default (first).
1800 (setq icicle-current-TAB-method (car icicle-TAB-completion-methods)))
1802 (unless (get 'icicle-last-top-level-command 'icicle-current-TAB-method)
1803 (put 'icicle-last-top-level-command 'icicle-current-TAB-method icicle-current-TAB-method))
1804 (put 'icicle-last-top-level-command 'icicle-current-TAB-method nil))
1806 (let ((now (memq icicle-current-TAB-method icicle-TAB-completion-methods))
1808 (setq icicle-current-TAB-method (or (cadr now) (car icicle-TAB-completion-methods))
1809 following (or (cadr (memq icicle-current-TAB-method
1810 icicle-TAB-completion-methods))
1811 (car icicle-TAB-completion-methods)))
1812 ;; Skip any method that is not currently supported.
1813 (while (or (and (eq icicle-current-TAB-method 'fuzzy) (not (featurep 'fuzzy-match)))
1814 (and (eq icicle-current-TAB-method 'vanilla) (not (boundp 'completion-styles)))
1815 (and (eq icicle-current-TAB-method 'swank) (not (featurep 'el-swank-fuzzy))))
1816 (setq now (memq icicle-current-TAB-method icicle-TAB-completion-methods)
1817 icicle-current-TAB-method (or (cadr now) (car icicle-TAB-completion-methods))))
1818 ;; Skip any method that is not currently supported.
1819 (while (or (and (eq following 'fuzzy) (not (featurep 'fuzzy-match)))
1820 (and (eq following 'vanilla) (not (boundp 'completion-styles)))
1821 (and (eq following 'swank) (not (featurep 'el-swank-fuzzy))))
1822 (setq following (or (cadr (memq icicle-current-TAB-method icicle-TAB-completion-methods))
1823 (car icicle-TAB-completion-methods))))
1824 ;; $$$$$$ Inhibiting sorting is not correct for file-name completion, and sorting would not be
1825 ;; restored when change back to non-fuzzy.
1826 ;; (when (eq 'fuzzy icicle-current-TAB-method) (setq icicle-inhibit-sort-p t))
1827 (icicle-msg-maybe-in-minibuffer
1828 "TAB completion is %s %s Next: %s"
1829 (icicle-propertize (icicle-upcase (symbol-name icicle-current-TAB-method))
1830 'face 'icicle-msg-emphasis)
1831 (if temporary-p (concat "for " (icicle-propertize "this command" 'face 'icicle-msg-emphasis)) "now.")
1832 (if temporary-p "" (icicle-upcase (symbol-name following)))))
1833 (cond ((and (eq icicle-current-TAB-method 'swank) (fboundp 'doremi))
1834 (define-key minibuffer-local-completion-map (icicle-kbd "C-x 1")
1835 'icicle-doremi-increment-swank-timeout+)
1836 (define-key minibuffer-local-must-match-map (icicle-kbd "C-x 1")
1837 'icicle-doremi-increment-swank-timeout+)
1838 (define-key minibuffer-local-completion-map (icicle-kbd "C-x 2")
1839 'icicle-doremi-increment-swank-prefix-length+)
1840 (define-key minibuffer-local-must-match-map (icicle-kbd "C-x 2")
1841 'icicle-doremi-increment-swank-prefix-length+))
1843 (define-key minibuffer-local-completion-map (icicle-kbd "C-x 1") nil)
1844 (define-key minibuffer-local-must-match-map (icicle-kbd "C-x 1") nil)
1845 (define-key minibuffer-local-completion-map (icicle-kbd "C-x 2") nil)
1846 (define-key minibuffer-local-must-match-map (icicle-kbd "C-x 2") nil))))
1848 ;; Top-level commands. Could instead be in `icicles-cmd2.el'.
1850 (defalias 'cycle-icicle-S-TAB-completion-method 'icicle-next-S-TAB-completion-method)
1851 (defun icicle-next-S-TAB-completion-method (temporary-p) ; Bound to `M-(' in minibuffer.
1852 "Cycle to the next `S-TAB' completion method.
1853 Bound to `M-(' in the minibuffer.
1854 Option `icicle-S-TAB-completion-methods-alist' customizes the
1855 available TAB completion methods.
1857 With a prefix argument, the newly chosen method is used only for the
1858 current command. More precisely, the previously active method is
1859 restored as soon as you return to the top level."
1862 (unless (get 'icicle-last-top-level-command 'icicle-apropos-complete-match-fn)
1863 (put 'icicle-last-top-level-command 'icicle-apropos-complete-match-fn
1864 icicle-apropos-complete-match-fn))
1865 (put 'icicle-last-top-level-command 'icicle-apropos-complete-match-fn nil))
1866 (let ((entry (rassq icicle-apropos-complete-match-fn icicle-S-TAB-completion-methods-alist))
1868 (setq icicle-apropos-complete-match-fn (or (cdadr (member
1869 entry icicle-S-TAB-completion-methods-alist))
1870 (cdar icicle-S-TAB-completion-methods-alist))
1871 following (or (caadr (member
1872 (rassq icicle-apropos-complete-match-fn
1873 icicle-S-TAB-completion-methods-alist)
1874 icicle-S-TAB-completion-methods-alist))
1875 (caar icicle-S-TAB-completion-methods-alist))
1876 icicle-last-apropos-complete-match-fn icicle-apropos-complete-match-fn) ; Backup copy.
1877 (icicle-msg-maybe-in-minibuffer
1878 "S-TAB completion is %s%s %s Next: %s"
1879 (icicle-propertize (icicle-upcase (car (rassq icicle-apropos-complete-match-fn
1880 icicle-S-TAB-completion-methods-alist)))
1881 'face 'icicle-msg-emphasis)
1882 (if (memq icicle-apropos-complete-match-fn
1883 '(icicle-levenshtein-match icicle-levenshtein-strict-match))
1884 (icicle-propertize (format " (%d)" icicle-levenshtein-distance) 'face 'icicle-msg-emphasis)
1886 (if temporary-p (concat "for " (icicle-propertize "this command" 'face 'icicle-msg-emphasis)) "now.")
1887 (if temporary-p "" (icicle-upcase following)))))
1888 ;; (icicle-complete-again-update) ; No - too slow for some completion methods.
1890 ;; Top-level commands. Could instead be in `icicles-cmd2.el'.
1892 (defalias 'cycle-icicle-sort-order 'icicle-change-sort-order)
1893 (defun icicle-change-sort-order (&optional arg alternativep) ; Bound to `C-,' in minibuffer.
1894 "Choose a sort order using completion or by cycling to the next one.
1895 With a numeric prefix arg, just reverse the current sort order.
1897 Option `icicle-change-sort-order-completion' determines whether to use
1898 completion or cycling to choose the new sort order, as follows:
1900 - nil means cycle to the next order; do not use completion to choose
1903 - An integer means use completion if there are currently more than
1904 that number of sort orders to choose from. Otherwise, cycle next.
1906 - Any other non-nil value means use completion.
1908 However, a plain prefix argument (`C-u') flips the behavior defined
1909 thus between cycling and completion. That is, if the option would
1910 normally lead to completion then `C-u' causes cycling instead, and
1913 This command updates `icicle-sort-comparer'. Non-interactively,
1914 optional arg ALTERNATIVEP means change the current alternative sort
1915 order instead, updating `icicle-alternative-sort-comparer'.
1917 NOTE: If sorting has been turned off automatically for the current
1918 minibuffer invocation because there are more candidates than
1919 `icicle-sorting-max-candidates', this does not turn sorting back on.
1920 The newly chosen sort order takes effect only when sorting is turned
1921 on again (e.g. because there are fewer candidates)."
1923 (setq icicle-sort-orders-alist (delq nil icicle-sort-orders-alist)) ; Purge any nil entries.
1924 (if (and (interactive-p) icicle-inhibit-sort-p)
1925 (icicle-msg-maybe-in-minibuffer "Cannot sort candidates now")
1926 (if (and arg (not (consp arg)))
1927 (icicle-reverse-sort-order)
1928 (let* ((following-order nil)
1929 (use-completion-p (if (integerp icicle-change-sort-order-completion)
1930 (> (length (icicle-current-sort-functions))
1931 icicle-change-sort-order-completion)
1932 icicle-change-sort-order-completion))
1933 (use-completion-p (or (and (not arg) use-completion-p) ; Use completion.
1934 (and arg (not use-completion-p))))
1936 (cond (use-completion-p
1937 (setq next-order (let ((icicle-whole-candidate-as-text-prop-p nil)
1938 (icicle-must-pass-after-match-predicate nil)
1939 (icicle-show-Completions-initially-flag t)
1940 (enable-recursive-minibuffers t)
1941 (icicle-default-value t) ; Put current in prompt.
1942 (icicle-default-in-prompt-format-function
1943 (lambda (def) (format " (NOW: %s)" def))))
1944 (save-selected-window
1946 (format "New %ssort order: " (if alternativep "alternative " ""))
1947 (icicle-current-sort-functions)
1949 (car (rassoc (if alternativep
1950 icicle-alternative-sort-comparer
1951 icicle-sort-comparer)
1952 icicle-sort-orders-alist))))))
1953 (when (if alternativep icicle-alternative-sort-comparer icicle-sort-comparer)
1954 (setq icicle-last-sort-comparer (if alternativep ; Save current as last.
1955 icicle-alternative-sort-comparer
1956 icicle-sort-comparer)))
1957 (set (if alternativep 'icicle-alternative-sort-comparer 'icicle-sort-comparer)
1958 (cdr (assoc next-order icicle-sort-orders-alist))))
1959 (t ; Cycle to next sort order.
1960 (let ((orders (mapcar #'car (icicle-current-sort-functions))))
1961 (setq next-order (or (cadr (memq (icicle-current-sort-order alternativep) orders))
1963 following-order (or (cadr (memq next-order orders)) (car orders)))
1964 (when (if alternativep icicle-alternative-sort-comparer icicle-sort-comparer)
1965 (setq icicle-last-sort-comparer (if alternativep ; Save current as last.
1966 icicle-alternative-sort-comparer
1967 icicle-sort-comparer)))
1968 (set (if alternativep 'icicle-alternative-sort-comparer 'icicle-sort-comparer)
1969 (cdr (assoc next-order icicle-sort-orders-alist))))))
1970 (icicle-complete-again-update)
1971 (icicle-msg-maybe-in-minibuffer
1972 "%sorting is now %s. Reverse: `C-9 C-,'%s"
1973 (if alternativep "Alternative s" "S")
1974 (icicle-propertize (concat next-order (and icicle-reverse-sort-p ", REVERSED"))
1975 'face 'icicle-msg-emphasis)
1976 (if following-order (format ". Next: %s" following-order) "")))
1977 (when (fboundp 'completion--flush-all-sorted-completions) ; E.g., so Icomplete+ recomputes order.
1978 (completion--flush-all-sorted-completions)))))
1980 (defun icicle-current-sort-functions ()
1981 "Subset of `icicle-sort-orders-alist' that is currently appropriate.
1982 For some common kinds of completion, remove simple sort functions (not
1983 multi-sort comparers) that are not pertinent for the current kind of
1985 (icicle-remove-if (lambda (pred)
1986 (setq pred (cdr pred))
1988 (symbolp pred) ; Do not handle multi-sort comparers.
1989 (not (eq pred icicle-allowed-sort-predicate))
1990 (or (and (get pred 'icicle-proxy-sort-predicate)
1991 (not icicle-add-proxy-candidates-flag))
1992 (and (get pred 'icicle-file-name-sort-predicate)
1993 (not (or (icicle-file-name-input-p) icicle-abs-file-candidates)))
1994 ;; Not really needed yet, because we only add such sorts dynamically.
1995 (and (get pred 'icicle-buffer-name-sort-predicate) ; Better than nothing.
1996 (not (eq minibuffer-history-variable 'buffer-name-history)))
1997 (and (get pred 'icicle-command-sort-predicate)
1998 (not (and (eq minibuffer-completion-table obarray)
1999 ;; But this will fail if predicate is more complex.
2000 ;; So be sure to bind `icicle-allowed-sort-predicate'
2001 ;; in that case, to avoid this restriction.
2002 (eq minibuffer-completion-predicate 'commandp))))
2003 ;; Sort order for multi-completions. `minibuffer-completion-table'
2004 ;; could be a function (e.g. `icicle-describe-opt-of-type-complete')
2005 ;; or it could be a list of multi-completions.
2006 (and (get pred 'icicle-multi-completion-sort-predicate)
2007 (not (icicle-maybe-multi-completion-completing-p))))))
2008 icicle-sort-orders-alist))
2010 (defun icicle-maybe-multi-completion-completing-p ()
2011 "Returns non-nil if we might currently be multi-completion completing.
2012 Note: If `minibuffer-completion-table' is a function, multi-completion
2013 is possible but not sure. Return non-nil in that case."
2014 (or (functionp minibuffer-completion-table) icicle-list-use-nth-parts))
2016 (defun icicle-dispatch-M-comma () ; Bound to `M-,' in minibuffer.
2017 "Do the right thing for `M-,'.
2018 If sorting is possible, call `icicle-change-alternative-sort-order'.
2019 If using `icicle-search', call `icicle-search-define-replacement'.
2020 Otherwise, do nothing.
2022 Bound to `M-,' in the minibuffer."
2024 (cond (icicle-searching-p (icicle-search-define-replacement))
2025 (icicle-inhibit-sort-p (message "Cannot sort candidates now"))
2026 (t (icicle-change-alternative-sort-order))))
2028 ;; Free vars here: `icicle-scan-fn-or-regexp' is bound in `icicle-search'.
2030 (defun icicle-search-define-replacement () ; Bound to `M-,' in minibuffer during `icicle-search'.
2031 "Prompt user and set new value of `icicle-search-replacement'.
2032 Bound to `M-,' in the minibuffer."
2034 (save-selected-window
2035 (icicle-remove-Completions-window)) ; Prevent incremental completion kicking in from the get-go.
2036 (setq icicle-search-replacement
2037 (let ((enable-recursive-minibuffers t)
2038 (icicle-incremental-completion t) ; Override current upgrade to `always'.
2039 (icicle-completion-candidates icicle-completion-candidates)
2040 (icicle-current-input icicle-current-input)
2041 (icicle-candidate-nb icicle-candidate-nb)
2042 (icicle-update-input-hook nil))
2043 (icicle-completing-read-history "Replacement string: " 'icicle-search-replacement-history)))
2044 ;; Just a sanity check. Cannot really test equivalence of two regexps.
2045 (while (if icicle-search-replace-whole-candidate-flag
2046 (equal icicle-search-replacement icicle-scan-fn-or-regexp)
2047 (equal icicle-search-replacement icicle-current-input))
2048 (setq icicle-search-replacement
2049 (let ((enable-recursive-minibuffers t)
2050 (icicle-incremental-completion t) ; Override current upgrade to `always'.
2051 (icicle-completion-candidates icicle-completion-candidates)
2052 (icicle-current-input icicle-current-input)
2053 (icicle-candidate-nb icicle-candidate-nb)
2054 (icicle-update-input-hook nil))
2055 (icicle-completing-read-history "Replacement = replaced. Replacement string: "
2056 'icicle-search-replacement-history)))))
2058 (defun icicle-change-alternative-sort-order (&optional arg) ; Bound to `M-,' in minibuffer (not search).
2059 "Choose an alternative sort order.
2060 Similar to command `icicle-change-sort-order', but change the
2061 alternative sort order, not the current sort order."
2063 (if (and (interactive-p) icicle-inhibit-sort-p)
2064 (icicle-msg-maybe-in-minibuffer "Cannot sort candidates now")
2065 (icicle-change-sort-order arg t)))
2067 (defun icicle-current-sort-order (alternativep)
2068 "Current sort order, or nil if sorting is inactive.
2069 If ALTERNATIVEP is non-nil, the alternative sort order is returned."
2070 (car (rassq (if alternativep icicle-alternative-sort-comparer icicle-sort-comparer)
2071 icicle-sort-orders-alist)))
2073 (defun icicle-reverse-sort-order ()
2074 "Reverse the current sort order."
2076 (if (and (interactive-p) icicle-inhibit-sort-p)
2077 (icicle-msg-maybe-in-minibuffer "Cannot sort candidates now")
2078 (setq icicle-reverse-sort-p (not icicle-reverse-sort-p))
2079 (icicle-display-candidates-in-Completions icicle-reverse-sort-p)
2080 (icicle-complete-again-update)
2081 (icicle-msg-maybe-in-minibuffer
2082 "Sort order is %s" (icicle-propertize (concat (icicle-current-sort-order nil)
2083 (and icicle-reverse-sort-p ", REVERSED"))
2084 'face 'icicle-msg-emphasis))))
2086 (defun icicle-plus-saved-sort () ; Bound to `C-M-+' during completion.
2087 "Sort candidates by combining their current order with the saved order."
2089 (let ((icicle-sort-comparer 'icicle-merge-saved-order-less-p)
2090 (cands (copy-sequence icicle-completion-candidates)))
2091 (setq icicle-completion-candidates
2092 (if (or (icicle-file-name-input-p) icicle-abs-file-candidates)
2093 (icicle-strip-ignored-files-and-sort cands)
2094 (icicle-maybe-sort-maybe-truncate cands))))
2095 (when (get-buffer-window "*Completions*" 0) (icicle-display-candidates-in-Completions))
2096 (when (interactive-p) (icicle-msg-maybe-in-minibuffer "Added in the saved sort order")))
2099 ;;(@* "Other commands to be used mainly in the minibuffer")
2101 ;;; Other commands to be used mainly in the minibuffer . . . . . . . .
2104 ;; Used as a command only in `icicle-Info-index', currently. Used mainly as a utility function - the main
2105 ;; function for displaying completion candidates. This was in `icicles-fn.el' originally.
2107 (defun icicle-display-candidates-in-Completions (&optional reverse-p no-display-p)
2108 "Refresh the current set of completion candidates in `*Completions*'.
2109 REVERSE-P non-nil means display the candidates in reverse order.
2110 NO-DISPLAY-P non-nil means do not display the candidates; just
2111 recompute them. If the value is `no-msg', then do not show a
2112 minibuffer message indicating that candidates were updated.
2113 By default, this is bound to `C-x C-M-l' during completion."
2115 ;; FREE var used here (bound in `icicle-Info-index'): `icicle-Info-hist-list'.
2117 ;;$$ ;; Pred is special if `minibuffer-completion-table' is a function.
2118 ;; (when (and (not (functionp minibuffer-completion-table))
2119 ;; (functionp minibuffer-completion-predicate))
2120 ;; (setq icicle-completion-candidates
2121 ;; (icicle-remove-if-not
2123 ;; (funcall minibuffer-completion-predicate
2124 ;; (if (arrayp minibuffer-completion-table) (intern cand) (list cand))))
2125 ;; icicle-completion-candidates)))
2127 ;; $$$ (case icicle-incremental-completion
2128 ;; ((t always) (setq icicle-incremental-completion-p 'always))
2129 ;; ((nil) (setq icicle-incremental-completion-p nil)))
2131 ;; $$$$$ (unless (input-pending-p) ; Do nothing if user hit a key.
2133 ;; Upgrade `icicle-incremental-completion-p' if we are redisplaying, so that completions will
2134 ;; be updated by `icicle-call-then-update-Completions' when you edit.
2136 (setq icicle-incremental-completion-p icicle-incremental-completion)
2137 (when (and (eq t icicle-incremental-completion-p) (get-buffer-window "*Completions*" 0))
2138 (setq icicle-incremental-completion-p 'always))
2139 (let ((nb-cands (length icicle-completion-candidates)))
2140 ;; $$$$$$ Could use this binding to prevent frame fitting, to allow room for images.
2141 ;; But that is not really the solution. Really should fit the frame or window in such a way
2142 ;; that it takes image sizes into account. Might need to wait for a fix to Emacs bug #7822.
2143 ;; (autofit-frames-flag (not icicle-image-files-in-Completions)))
2144 (cond ((eq no-display-p 'no-msg)) ; No-op.
2146 (icicle-msg-maybe-in-minibuffer
2147 "Candidates updated (%s matching): %s" icicle-current-completion-mode
2148 (icicle-propertize (format "%d" nb-cands) 'face 'icicle-msg-emphasis)))
2149 ((null icicle-completion-candidates)
2150 (save-selected-window (icicle-remove-Completions-window))
2151 (icicle-msg-maybe-in-minibuffer
2152 (if (eq 'apropos icicle-current-completion-mode)
2153 (let ((typ (car (rassq icicle-apropos-complete-match-fn
2154 icicle-S-TAB-completion-methods-alist))))
2155 (concat "No " typ (and typ " ") "completions"))
2156 (case (icicle-current-TAB-method)
2157 (fuzzy "No fuzzy completions")
2158 (swank "No swank (fuzzy symbol) completions")
2159 (vanilla "No vanilla completions")
2160 (t "No prefix completions")))))
2162 (when (> nb-cands icicle-incremental-completion-threshold)
2163 (message "Displaying completion candidates..."))
2164 ;; Display `*Completions*' now, so we can get its window's width.
2165 ;; We don't wait for `with-output-to-temp-buffer' to display it, because displaying it
2166 ;; might lead to splitting the display window, which would change its width.
2167 ;; We need to know the width in order to calculate the proper candidate formatting.
2168 (when (consp icicle-completion-candidates)
2169 (let ((fit-frame-inhibit-fitting-flag t)
2170 (comp-buf (get-buffer-create "*Completions*")))
2171 (unless (get-buffer-window comp-buf 'visible)
2172 (save-selected-window (display-buffer comp-buf t 0)
2173 (deactivate-mark))))) ; Remove any leftover mouse selection.
2174 (with-output-to-temp-buffer "*Completions*"
2175 ;; Each candidate in `icicle-completion-candidates' is a string, regardless of the
2176 ;; original type of candidate used (e.g. symbol, string, alist candidate,...). Here,
2177 ;; provided `icicle-fancy-cands-internal-p' is non-nil, we transform these candidates,
2178 ;; replacing each by a string that takes into account symbol properties
2179 ;; `icicle-display-string' and `icicle-special-candidate'.
2181 ;; Because `icicle-completion-candidates' is affected, changes to the candidate strings
2182 ;; (e.g. propertizing) are also reflected in the completion return value chosen by the
2183 ;; user. It is not only the display in `*Completions*' that is affected.
2185 ;; The symbol whose properties are used is the one in the current obarray that is named
2186 ;; by the string candidate to be transformed. If there is no such symbol, then no
2187 ;; transformation occurs. Unless `minibuffer-completion-table' is an obarray, the
2188 ;; global obarray is used to get the symbol.
2190 ;; 1. If the symbol has an `icicle-display-string' property, then that property value
2191 ;; must be a string (possibly propertized). We replace the candidate by that string.
2193 ;; 2. If the symbol has an `icicle-special-candidate' property, then we transfer the
2194 ;; property to the candidate string as a set of text properties. (If the value is
2195 ;; not a plist, and `icicle-special-candidate-regexp' is nil, then just apply face
2196 ;; `icicle-special-candidate'.) The effect is similar to using
2197 ;; `icicle-special-candidate-regexp', but the completion return value is also
2199 (when icicle-fancy-cands-internal-p
2200 (setq icicle-completion-candidates
2201 (mapcar (lambda (cand)
2202 (let* ((symb (intern-soft
2203 cand (and (arrayp minibuffer-completion-table)
2204 minibuffer-completion-table)))
2205 (display-strg (and symb
2206 (stringp (get symb 'icicle-display-string))
2207 (get symb 'icicle-display-string)))
2208 (new-cand (or display-strg cand))
2209 (spec-prop (and symb (get symb 'icicle-special-candidate))))
2210 ;; Apply `icicle-special-candidate' property's value.
2211 ;; If the value is a plist, then apply the properties as text props.
2212 ;; Else (the value is t), apply face `icicle-special-candidate'.
2214 (setq new-cand (copy-sequence new-cand))
2215 (if (consp spec-prop)
2216 (add-text-properties 0 (length new-cand) spec-prop new-cand)
2217 (unless icicle-special-candidate-regexp
2218 (add-text-properties 0 (length new-cand)
2219 '(face icicle-special-candidate)
2222 icicle-completion-candidates)))
2223 (icicle-display-completion-list (if reverse-p
2224 (reverse icicle-completion-candidates)
2225 icicle-completion-candidates)
2229 (save-window-excursion
2230 (with-current-buffer (get-buffer "*Completions*")
2231 (let* ((buffer-read-only nil)
2233 (filep (or (icicle-file-name-input-p) icicle-abs-file-candidates))
2234 (dir (and filep icicle-last-input
2235 (icicle-file-name-directory icicle-last-input)))
2236 (histvar (and (symbolp minibuffer-history-variable)
2237 (boundp minibuffer-history-variable)
2238 minibuffer-history-variable))
2241 ;; Need (or DIR default-directory) instead of DIR
2242 ;; because Emacs 20 `expand-file-name' crashes.
2243 (let ((default-directory (or dir default-directory)))
2244 (mapcar #'expand-file-name (symbol-value histvar)))
2245 (symbol-value histvar))))
2247 ;; Don't bother with buffer completion, `read-buffer-completion-ignore-case'.
2248 (if (and filep (boundp 'read-file-name-completion-ignore-case))
2249 read-file-name-completion-ignore-case
2250 completion-ignore-case)))
2251 (when (fboundp 'remove-images) (remove-images (point-min) (point-max)))
2252 (goto-char (icicle-start-of-candidates-in-Completions))
2254 (let* ((beg (point))
2255 (end (next-single-property-change beg 'mouse-face nil eob))
2256 (next (next-single-property-change end 'mouse-face nil eob))
2259 ;; Highlight candidate specially if it is a proxy candidate.
2260 (let ((candidate (icicle-current-completion-in-Completions)))
2261 ;;$$$ (when dir (setq candidate (expand-file-name candidate dir)))
2262 (when (member candidate icicle-proxy-candidates)
2263 (setq faces (cons 'icicle-proxy-candidate faces))
2264 (if (not icicle-proxy-candidate-regexp)
2265 (add-text-properties beg end (cons 'face (list faces)))
2267 (when (string-match icicle-proxy-candidate-regexp candidate)
2268 (add-text-properties (+ beg (match-beginning 0)) (+ beg (match-end 0))
2269 (cons 'face (list faces))))))))
2271 ;; Highlight candidate specially if it is an extra candidate.
2272 (let ((candidate (icicle-current-completion-in-Completions)))
2273 ;;$$$ (when dir (setq candidate (expand-file-name candidate dir)))
2275 (when (member candidate icicle-extra-candidates)
2276 (setq faces (cons 'icicle-extra-candidate faces))
2277 (add-text-properties beg end (cons 'face (list faces))))))
2279 ;; Highlight candidate specially if it is a special candidate.
2280 (let ((candidate (icicle-current-completion-in-Completions)))
2281 ;;$$$ (when dir (setq candidate (expand-file-name candidate dir)))
2283 (when (and icicle-special-candidate-regexp
2284 (string-match icicle-special-candidate-regexp candidate))
2285 (setq faces (cons 'icicle-special-candidate faces))
2286 (add-text-properties (+ beg (match-beginning 0)) (+ beg (match-end 0))
2287 (cons 'face (list faces))))))
2289 ;; Highlight candidate (`*-historical-candidate') if it was used previously.
2290 (when icicle-highlight-historical-candidates-flag
2291 (let ((candidate (icicle-current-completion-in-Completions)))
2292 (when (and (consp hist) (not (member candidate icicle-hist-cands-no-highlight)))
2293 ;; Need (or DIR default-directory) instead of DIR
2294 ;; because Emacs 20 `expand-file-name' crashes.
2295 (let ((default-directory (or dir default-directory)))
2296 (when (member (if filep
2297 (expand-file-name (icicle-transform-multi-completion
2301 (add-text-properties
2302 beg end `(face ,(setq faces (cons 'icicle-historical-candidate faces)))))))))
2304 ;; Highlight Info index-entry cand (using face `icicle-historical-candidate-other')
2305 ;; if its node has been visited.
2307 ;; FREE var here (bound in `icicle-Info-index'): `icicle-Info-hist-list'.
2308 (when (and (> emacs-major-version 21)
2309 (memq icicle-last-top-level-command '(Info-index icicle-Info-index))
2310 (boundp 'icicle-Info-hist-list) (consp icicle-Info-hist-list)
2311 (or (eq this-command 'icicle-display-candidates-in-Completions)
2312 (and icicle-highlight-historical-candidates-flag
2313 icicle-Info-highlight-visited-nodes
2314 (or (not (numberp icicle-Info-highlight-visited-nodes))
2315 (<= nb-cands icicle-Info-highlight-visited-nodes)))))
2316 (message "Highlighting topics in all visited nodes...")
2317 (let ((candidate (icicle-current-completion-in-Completions)))
2318 (when (or (assoc candidate icicle-Info-index-cache)
2319 (icicle-some (mapcar 'cadr icicle-Info-hist-list)
2321 #'icicle-Info-node-is-indexed-by-topic))
2322 (add-text-properties
2323 beg end `(face ,(setq faces (cons 'icicle-historical-candidate-other faces)))))))
2325 ;; Highlight, inside the candidate, the expanded common match.
2326 (when (and icicle-current-input (not (string= "" icicle-current-input)))
2329 (narrow-to-region beg end) ; Restrict to the completion candidate.
2330 (when (re-search-forward (regexp-quote (icicle-minibuf-input-sans-dir
2331 icicle-current-input))
2333 (setq faces (cons 'icicle-common-match-highlight-Completions faces))
2334 (put-text-property (match-beginning 0) (point) 'face faces)))))
2336 ;; Hide match for `icicle-current-input' (expanded common match, if available),
2337 ;; if `icicle-hide-common-match-in-Completions-flag' is non-nil.
2340 (narrow-to-region beg end) ; Restrict to the completion candidate.
2341 (when (and icicle-hide-common-match-in-Completions-flag icicle-common-match-string)
2342 (when (re-search-forward (regexp-quote icicle-common-match-string) nil t)
2343 (if (> emacs-major-version 20)
2344 (put-text-property (match-beginning 0) (point) 'display "...")
2345 (put-text-property (match-beginning 0) (point) 'invisible t))))))
2347 ;; Highlight, inside the candidate, what the input expression matches.
2348 (unless (and icicle-current-raw-input (string= "" icicle-current-raw-input)
2349 icicle-apropos-complete-match-fn)
2352 (narrow-to-region beg end) ; Restrict to the completion candidate.
2353 (let ((fn (if (and (eq 'prefix icicle-current-completion-mode)
2354 (not (memq (icicle-current-TAB-method) '(fuzzy swank))))
2355 ;; $$$$$$ What is best for `vanilla' (Emacs 23) completion?
2357 (case icicle-apropos-complete-match-fn
2358 (icicle-scatter-match
2359 (lambda (input bound noerr)
2360 (re-search-forward (icicle-scatter input) bound noerr)))
2361 (icicle-levenshtein-match
2362 (if (= icicle-levenshtein-distance 1)
2363 (lambda (input bound noerr)
2364 (re-search-forward (icicle-levenshtein-one-regexp input)
2366 're-search-forward))
2367 (otherwise 're-search-forward)))))
2369 (when (and (funcall fn (icicle-minibuf-input-sans-dir icicle-current-raw-input)
2371 (not (eq (match-beginning 0) (point))))
2372 (setq faces (cons 'icicle-match-highlight-Completions faces))
2373 (put-text-property (match-beginning 0) (point) 'face faces)))
2375 ;; If `icicle-hide-non-matching-lines-flag' then hide all lines
2376 ;; of candidate that do not match current input.
2377 (let ((candidate (icicle-current-completion-in-Completions))
2378 (input (icicle-minibuf-input-sans-dir
2379 icicle-current-raw-input))
2381 (when (and icicle-hide-non-matching-lines-flag
2382 (string-match "\n" candidate)
2383 (not (string= "\n" candidate)))
2386 (unless (funcall fn input (line-end-position) t)
2387 (if (> emacs-major-version 20)
2388 (put-text-property (line-beginning-position)
2389 (min (1+ (line-end-position)) (point-max))
2391 (put-text-property (line-beginning-position)
2392 (min (1+ (line-end-position)) (point-max))
2394 (forward-line 1))))))))
2396 ;; Highlight candidate if it has been saved.
2397 (when (and icicle-highlight-saved-candidates-flag icicle-saved-completion-candidates)
2398 (let ((candidate (icicle-current-completion-in-Completions)))
2399 (when (member candidate icicle-saved-completion-candidates)
2400 (let ((ov (make-overlay beg end)))
2401 (push ov icicle-saved-candidate-overlays)
2402 (overlay-put ov 'face 'icicle-saved-candidate)
2403 (overlay-put ov 'priority '10)))))
2405 ;; Treat `icicle-candidate-properties-alist'.
2406 ;; A `face' prop will unfortunately wipe out any `face' prop we just applied.
2407 (when icicle-candidate-properties-alist
2410 (narrow-to-region beg end) ; Restrict to the completion candidate.
2411 (let* ((candidate (buffer-substring (point-min) (point-max)))
2416 (join (concat "\\(" icicle-list-join-string "\\|\\'\\)"))
2417 (len-cand (length candidate))
2418 (len-join (length icicle-list-join-string))
2421 (while (and (or first
2422 (not (= end (match-beginning 0)))
2423 (< (+ end len-join) len-cand))
2424 (string-match join candidate (if (and (not first)
2425 (= end (match-beginning 0))
2431 end (or (match-beginning 0) len-cand))
2432 (let* ((entry (assq partnum
2433 icicle-candidate-properties-alist))
2434 (properties (cadr entry))
2435 (propertize-join-string (car (cddr entry))))
2437 (add-text-properties (+ start orig-pt) (+ end orig-pt) properties))
2438 (when propertize-join-string
2439 (add-text-properties (+ end orig-pt) (+ end orig-pt len-join)
2441 (setq partnum (1+ partnum)
2442 start (match-end 0))))))))
2444 ;; Thumbnail image for an image file or image-file bookmark (Bookmark+): Maybe show it
2445 ;; in `*Completions*'; maybe show it only in `*Completions*' mouseover tooltip.
2446 (when (or (and icicle-image-files-in-Completions
2447 (if (fboundp 'display-graphic-p) (display-graphic-p) window-system)
2448 (or (and filep (fboundp 'image-file-name-regexp))
2449 (and icicle-show-multi-completion-flag
2450 (symbolp icicle-last-top-level-command)
2451 (string-match "^icicle-bookmark-"
2452 (symbol-name icicle-last-top-level-command)))))
2453 (and (boundp 'tooltip-mode) tooltip-mode icicle-image-preview-in-tooltip))
2455 (if (and icicle-show-multi-completion-flag
2456 (symbolp icicle-last-top-level-command)
2457 ;; We could alternatively put a property on such symbols and
2458 ;; test that. But just matching the cmd name is OK so far.
2459 (string-match "^icicle-bookmark-"
2460 (symbol-name icicle-last-top-level-command)))
2461 ;; This is bound by the bookmark commands to `(1)': bookmark name.
2462 ;; The file name is part #2, so we rebind this here.
2463 (let ((icicle-list-use-nth-parts '(2)))
2464 (icicle-transform-multi-completion
2465 (icicle-current-completion-in-Completions)))
2466 (icicle-transform-multi-completion
2467 (icicle-current-completion-in-Completions)))))
2468 (when (and (require 'image-dired nil t)
2469 (icicle-string-match-p (image-file-name-regexp) image-file))
2470 (let* ((thumb-img (image-dired-get-thumbnail-image image-file))
2471 (thumb-img (and thumb-img
2472 (append (image-dired-get-thumbnail-image image-file)
2475 ;; In `tooltip-mode', show image preview on mouseover,
2476 ;; unless it is a thumbnail and `*Completions*' already shows thumbnails.
2477 (when (and (boundp 'tooltip-mode) tooltip-mode
2478 (or (not icicle-image-files-in-Completions)
2479 (not (numberp icicle-image-preview-in-tooltip))))
2480 (with-current-buffer "*Completions*"
2482 (point) (+ (point) (length (icicle-current-completion-in-Completions)))
2483 'help-echo 'icicle-mouseover-help)))
2484 (when icicle-image-files-in-Completions
2485 (let ((img-ov (overlays-in (point) (min (point-max) (1+ (point))))))
2487 (delete-overlay (car img-ov))
2488 (put-image thumb-img beg)
2489 (setq img-ov (loop for ov in (overlays-in
2490 (point) (min (point-max) (1+ (point))))
2491 when (overlay-get ov 'put-image) collect ov into ovs
2492 finally return (car ovs)))
2493 (overlay-put img-ov 'image-file image-file)
2494 (overlay-put img-ov 'thumb-img thumb-img)
2495 (overlay-put img-ov 'image-size (image-size thumb-img))))
2496 ;; `image-only'. Replace file name with a space.
2497 ;; And hide mouse-face highlighting, as it just confuses.
2498 (when (eq 'image-only icicle-image-files-in-Completions)
2499 (with-current-buffer "*Completions*"
2501 (point) (+ (point) (length (icicle-current-completion-in-Completions)))
2502 'mouse-face 'default))
2503 (let ((name-ov (overlays-in end end)))
2505 (delete-overlay (car name-ov))
2506 (setq name-ov (make-overlay beg end))
2507 (overlay-put name-ov 'display " "))))))))))
2510 ;; Remove all newlines for images-only display.
2511 (when (eq icicle-image-files-in-Completions 'image-only)
2512 (save-excursion (goto-char (icicle-start-of-candidates-in-Completions))
2513 (while (and (re-search-forward "$") (not (eobp))) (delete-char 1)))))
2514 (set-buffer-modified-p nil)
2515 (setq buffer-read-only t))))
2517 ;; Put lighter, number of candidates, completion mode, and sort order in mode line.
2518 (with-current-buffer (get-buffer "*Completions*")
2519 (set (make-local-variable 'mode-line-format)
2520 (format " %s%s%s, sorting %s%s"
2521 (icicle-propertize (format "%d" nb-cands) 'face 'icicle-mode-line-help)
2522 (if (and icicle-max-candidates
2523 (integerp icicle-max-candidates) ; Not `RESET'.
2524 (< icicle-max-candidates icicle-nb-candidates-before-truncation))
2525 (format "%s candidates shown"
2526 (icicle-propertize (format "/%d" icicle-nb-candidates-before-truncation)
2527 'face 'icicle-mode-line-help))
2529 (if (memq icicle-current-completion-mode '(prefix apropos))
2530 (format ", %s completion"
2532 (cond ((eq 'apropos icicle-current-completion-mode)
2533 ;; If nil, COLLECTION arg is probably a fn and we set it to nil
2534 ;; to prevent automatic input matching in
2535 ;; `icicle-unsorted-apropos-candidates', because COLLECTION fn
2536 ;; does everything. So here we treat nil like `apropos'.
2537 (if icicle-apropos-complete-match-fn
2538 (or (car (rassq icicle-apropos-complete-match-fn
2539 icicle-S-TAB-completion-methods-alist))
2542 ((eq 'prefix icicle-current-completion-mode)
2543 (case (icicle-current-TAB-method)
2545 (swank "swank (fuzzy symbol)")
2548 'face 'icicle-mode-line-help))
2550 (icicle-propertize (or (car (rassoc icicle-sort-comparer icicle-sort-orders-alist))
2552 'face 'icicle-mode-line-help)
2553 (if (and icicle-reverse-sort-p icicle-sort-comparer)
2554 (icicle-propertize " (reversed)" 'face 'icicle-mode-line-help)
2556 (let* ((lighter (cadr (assoc 'icicle-mode minor-mode-alist)))
2557 (regexp (and lighter (concat (regexp-quote icicle-lighter-truncation) "$")))
2560 (setq lighter (concat lighter " ")
2561 props (text-properties-at 0 lighter))
2562 (when (string-match regexp lighter) (setq lighter (substring lighter 0 (match-beginning 0))))
2563 (add-text-properties 0 (length lighter) props lighter))
2564 (setq mode-line-format (concat lighter mode-line-format)))
2565 (goto-char (icicle-start-of-candidates-in-Completions))
2566 (set-window-point (get-buffer-window "*Completions*" 0) (point))
2567 (icicle-fit-completions-window))
2569 ;; Use the same font family as the starting buffer. This is particularly for picking up
2570 ;; the proper font for Unicode chars in `*Completions*'. Emacs 23+ only.
2571 ;; But skip this if using `oneonone.el', since `1on1-display-*Completions*-frame' does it.
2572 (when (and (not (fboundp '1on1-display-*Completions*-frame))
2573 (get-buffer-window "*Completions*" 'visible)
2574 icicle-pre-minibuffer-buffer
2575 (> emacs-major-version 22))
2576 (save-window-excursion
2577 (select-window (get-buffer-window "*Completions*" 'visible))
2578 (when (one-window-p t) ; $$$$$ Also this? (window-dedicated-p (selected-window))
2579 (let* ((orig-win (get-buffer-window icicle-pre-minibuffer-buffer 'visible))
2580 (orig-font-fam (and (window-live-p orig-win)
2581 (save-window-excursion (select-window orig-win)
2582 (face-attribute 'default :family)))))
2583 (when orig-font-fam (set-face-attribute 'default (selected-frame) :family orig-font-fam))))))
2584 (message nil))))) ; Clear out any "Looking for..."
2587 ;; $$ Probably need to do something to work around problem of Windows
2588 ;; selecting the new frame, when `pop-up-frames' is non-nil. Need to
2589 ;; redirect focus back to the frame with the minibuffer. Leave it as
2590 ;; is, for now, in hopes Emacs will eventually fix this.
2592 (defun icicle-minibuffer-help () ; Bound to `M-?' in the minibuffer.
2593 "Describe Icicles minibuffer and *Completion* buffer bindings."
2595 (let ((cur-buf (current-buffer))
2596 (icicles-cmd-p (or icicle-candidate-action-fn icicle-multi-completing-p)))
2597 (icicle-with-help-window "*Help*"
2598 (help-setup-xref (list #'icicle-minibuffer-help) (interactive-p))
2599 (when (icicle-completing-p)
2600 (princ (format "You are completing input%s.%s"
2602 (format " for an Icicles %scommand%s"
2603 (if icicle-candidate-action-fn "multi-" "")
2604 (if icicle-multi-completing-p " that uses multi-\ncompletion" ""))
2606 (if (and icicles-cmd-p (not icicle-multi-completing-p)) "\n" " ")))
2607 (princ "To show help on individual candidates:\n")
2609 Current candidate C-M-RET, C-M-mouse-2
2610 Next, previous candidate C-M-down, C-M-up,
2611 C-M- plus mouse wheel
2612 prefix-match candidate C-M-end, C-M-home
2613 apropos-match candidate C-M-next, C-M-prior\n\n")
2614 (when icicle-candidate-action-fn
2615 (princ "To act on individual candidates:
2616 Current candidate C-RET, C-mouse-2
2617 Next, previous candidate C-down, C-up,
2619 prefix-match candidate C-end, C-home
2620 apropos-match candidate C-next, C-prior
2621 All candidates at once C-! (each) or M-! (list)
2622 Delete object named by candidate S-delete
2623 Object-action: apply a fn to candidate M-RET"))
2624 (when icicle-candidate-alt-action-fn
2625 (princ "\n\nFor alt action, use `C-S-' instead of `C-', but use `C-|' or `M-|',\n\
2626 instead of `C-!' or `M-!', to act on all.\n")))
2627 (if icicle-completing-p
2628 (with-current-buffer standard-output
2629 (insert (concat "\n" (icicle-help-string-completion))))
2630 (princ (icicle-help-string-non-completion))))
2631 ;; Don't bother to do this for Emacs 21.3. Its `help-insert-xref-button' signature is different.
2632 (when (and (> emacs-major-version 21)
2633 (require 'help-mode nil t)
2634 (fboundp 'help-insert-xref-button)) ; In `help-mode.el'.
2636 (with-current-buffer (get-buffer "*Help*")
2637 (let ((buffer-read-only nil))
2638 (goto-char (point-min))
2639 (help-insert-xref-button "[Icicles Help on the Web]" 'icicle-help-button)
2641 (help-insert-xref-button "[Icicles Doc, Part 1]" 'icicle-commentary1-button)
2643 (help-insert-xref-button "[Icicles Options & Faces]" 'icicle-customize-button)
2645 (help-insert-xref-button "[Icicles Doc, Part 2]" 'icicle-commentary2-button)
2647 (goto-char (point-max))
2648 (insert (make-string 70 ?_))
2650 (if (fboundp 'help-commands-to-key-buttons) ; In `help-fns.el'.
2651 #'help-commands-to-key-buttons
2652 #'substitute-command-keys)
2653 "\n\nSend an Icicles bug report: `\\[icicle-send-bug-report]'.\n\n"))
2654 (help-insert-xref-button "[Icicles Help on the Web]" 'icicle-help-button)
2656 (help-insert-xref-button "[Icicles Doc, Part 1]" 'icicle-commentary1-button)
2658 (help-insert-xref-button "[Icicles Options & Faces]" 'icicle-customize-button)
2660 (help-insert-xref-button "[Icicles Doc, Part 2]" 'icicle-commentary2-button)
2662 (goto-char (point-min))))))
2663 (when (memq cur-buf (list (window-buffer (minibuffer-window)) (get-buffer "*Completions*")))
2664 (select-window (minibuffer-window))
2665 (select-frame-set-input-focus (selected-frame)))))
2667 (defun icicle-help-string-completion ()
2668 "Update the bindings within the Icicles completion help string."
2669 (icicle-S-iso-lefttab-to-S-TAB
2671 (if (fboundp 'help-commands-to-key-buttons) ; In `help-fns+.el'.
2672 #'help-commands-to-key-buttons
2673 #'substitute-command-keys)
2675 (format "\\<minibuffer-local-completion-map>
2677 Icicles Minibuffer Completion
2678 -----------------------------
2680 Completion indicators:
2682 Mode line `Icy' lighter (additive):
2683 red = Completion available (use `TAB' or `S-TAB' to complete)
2684 + = Multi-command completion (use `C-RET' to act on candidate)
2685 || = Multi-completion candidates (use `C-M-j' to separate parts)
2686 ... = `icicle-max-candidates' shown (use `C-x #' to change)
2688 Prompt prefix (exclusive):
2689 . = Simple completion
2690 + = Multi-command completion
2692 You can complete your minibuffer input in several ways.
2693 These are the main Icicles actions and their minibuffer key bindings:
2695 * Show Icicles minibuffer help (this). \\[icicle-minibuffer-help]
2696 For help on individual completion candidates, see \"Show help on
2697 individual completion candidates\", below.
2699 * Abandon or commit your input.
2700 Abandon input \\[icicle-abort-recursive-edit]
2701 Commit input to Emacs RET
2702 Complete partial input, then commit \\<minibuffer-local-must-match-map>\
2703 \\[icicle-apropos-complete-and-exit]\\<minibuffer-local-completion-map>
2705 * Toggle/cycle Icicles options on the fly. Key: \tCurrently:
2706 Highlighting of past inputs \\[icicle-toggle-highlight-historical-candidates]\t%S
2707 Highlighting of saved candidates \\[icicle-toggle-highlight-saved-candidates]\t%S
2708 Showing candidates with WYSIWYG \\[icicle-toggle-WYSIWYG-Completions]\t%S
2709 Removal of duplicate candidates \\[icicle-toggle-transforming]\t%s
2710 Sort order \\[icicle-change-sort-order]\t%s
2711 Alternative sort order \\[icicle-dispatch-M-comma]\t%s
2712 Swap alternative/normal sort \\[icicle-toggle-alternative-sorting]
2713 Case sensitivity \\[icicle-toggle-case-sensitivity]\t%S
2714 `.' matching newlines too (any char) \\[icicle-toggle-dot]\t%S
2715 Escaping of special regexp chars \\[icicle-toggle-regexp-quote]\t%S
2716 Incremental completion \\[icicle-cycle-incremental-completion]\t%s
2717 Input expansion to common match (toggle)\\[icicle-toggle-expand-to-common-match]\t%S
2718 Input expansion to common match (cycle) \\[icicle-cycle-expand-to-common-match]\t%s
2719 Hiding common match in `*Completions*' \\[icicle-dispatch-C-x.]\t%S
2720 Hiding no-match lines in `*Completions*' C-u \\[icicle-dispatch-C-x.]\t%s
2721 Horizontal/vertical candidate layout \\[icicle-toggle-completions-format]\t%s
2722 S-TAB completion method \\[icicle-next-S-TAB-completion-method]\t%s
2723 TAB completion method \\[icicle-next-TAB-completion-method]\t%s
2724 Showing image-file thumbnails (E22+) C-x t\t%s
2725 Showing candidate annotations \\[icicle-toggle-annotation]\t%S
2726 Inclusion of proxy candidates \\[icicle-toggle-proxy-candidates]\t%S
2727 Ignoring certain file extensions \\[icicle-dispatch-C-.]\t%S
2728 Expansion of directory candidates \\[icicle-toggle-expand-directory]\t%S
2729 Checking for remote file names \\[icicle-dispatch-C-^]\t%S"
2730 (if icicle-highlight-historical-candidates-flag 'yes 'no)
2731 (if icicle-highlight-saved-candidates-flag 'yes 'no)
2732 (if icicle-WYSIWYG-Completions-flag 'yes 'no)
2733 (cond ((not icicle-transform-function) "no")
2734 ((or (eq icicle-transform-function 'icicle-remove-duplicates)
2735 (and icicle-extra-candidates
2736 (eq icicle-transform-function 'icicle-remove-dups-if-extras)))
2738 ((eq 'icicle-remove-dups-if-extras icicle-transform-function)
2739 "yes in general, but not now")
2740 (t icicle-transform-function))
2741 (icicle-current-sort-order nil)
2742 (icicle-current-sort-order 'ALTERNATIVE)
2743 (if case-fold-search 'no 'yes)
2744 (if (string= icicle-dot-string icicle-anychar-regexp) 'yes 'no)
2745 (if icicle-regexp-quote-flag 'yes 'no)
2746 (case icicle-incremental-completion
2748 ((t) "yes, if *Completions* showing")
2749 (t "yes, always (eager)"))
2750 (if (eq icicle-expand-input-to-common-match 0) 'no 'yes)
2751 (case icicle-expand-input-to-common-match
2753 (1 "explicit completion")
2754 (2 "only one completion")
2755 (3 "`TAB' or only one")
2757 (if icicle-hide-common-match-in-Completions-flag 'yes 'no)
2758 (if icicle-hide-non-matching-lines-flag 'yes 'no)
2759 icicle-completions-format
2760 (car (rassq icicle-apropos-complete-match-fn icicle-S-TAB-completion-methods-alist))
2761 (icicle-current-TAB-method)
2762 (case icicle-image-files-in-Completions
2764 (image "image only")
2765 (t "image and name"))
2766 (if icicle-show-annotations-flag 'yes 'no)
2767 (if icicle-add-proxy-candidates-flag 'yes 'no)
2768 (if completion-ignored-extensions 'yes 'no)
2769 (if icicle-find-file-expand-directory-flag 'yes 'no)
2770 (if icicle-test-for-remote-files-flag 'yes 'no))
2772 (and (memq system-type '(ms-dos windows-nt cygwin)) ; MS Windows only.
2773 (format "\\<minibuffer-local-completion-map>
2774 Considering network drives as remote \\[icicle-toggle-network-drives-as-remote]\t%S"
2775 (if icicle-network-drive-means-remote-flag 'yes 'no)))
2777 (format "\\<minibuffer-local-completion-map>
2778 Ignoring space prefix for buffer names \\[icicle-dispatch-M-_]\t%S
2779 Using `C-' for multi-command actions \\[icicle-toggle-C-for-actions]\t%S
2780 Using `~' for your home directory \\[icicle-toggle-~-for-home-dir]\t%S
2781 `icicle-search' all-current highlights \\[icicle-dispatch-C-^]\t%S
2782 Whole-word searching \\[icicle-dispatch-M-q]\t%S
2783 Removal of `icicle-search' highlighting \\[icicle-dispatch-C-.]\t%S
2784 Replacement of whole search hit \\[icicle-dispatch-M-_]\t%S
2785 Replacement of expanded common match \\[icicle-toggle-search-replace-common-match]\t%S
2786 Searching complements of contexts \\[icicle-toggle-search-complementing-domain]\t%S
2788 * Regexp-quote input, then apropos-complete \\[icicle-regexp-quote-input]
2790 * Change the set of completion candidates. Modify your input.
2791 Edit your input (just edit in minibuffer)
2792 Erase your input (clear minibuffer) \\[icicle-erase-minibuffer-or-history-element]
2793 Goto/kill non-matching portion of input \\[icicle-goto/kill-failed-input]
2794 Retrieve previous completion inputs \\[icicle-retrieve-previous-input], \
2795 \\[icicle-retrieve-next-input]
2796 Match another regexp (chaining) \\[icicle-narrow-candidates]
2797 Satisfy another predicate (chaining) \\[icicle-narrow-candidates-with-predicate]
2798 Remove a candidate from set of matches delete, S-mouse-2
2799 Yank text at cursor into minibuffer \\[icicle-insert-string-at-point]
2800 Insert text (string) from a variable \\[icicle-insert-string-from-variable]
2801 Insert `icicle-list-join-string' \\[icicle-insert-list-join-string]
2802 Insert previously entered input(s) \\[icicle-insert-history-element]
2803 Insert completion candidates(s) \\[icicle-roundup]
2804 Insert key description (key completion) \\[icicle-dispatch-M-q]
2806 * Complete your current input in the minibuffer.
2807 Apropos (regexp) completion \\[icicle-apropos-complete]
2808 Without displaying candidates \\[icicle-apropos-complete-no-display]
2809 Complete and match another regexp \\[icicle-apropos-complete-and-narrow]
2811 As much as possible \\[icicle-prefix-complete]
2812 Without displaying candidates \\[icicle-prefix-complete-no-display]
2813 A word at a time \\[icicle-prefix-word-complete]
2814 Complete and commit \\<minibuffer-local-must-match-map>\
2815 \\[icicle-apropos-complete-and-exit]\\<minibuffer-local-completion-map>
2816 Complete search string using past input \\[icicle-apropos-complete]
2818 * Display/navigate completions for current input (in `*Completions*').
2819 Show completion candidates
2820 Prefix completion \\[icicle-prefix-complete] (repeat)
2821 Apropos completion \\[icicle-apropos-complete]
2822 Move between minibuffer and list \\<completion-list-mode-map>\
2823 \\[icicle-insert-completion]
2824 Cycle among completion candidates right, left, \
2825 \\[icicle-move-to-next-completion], \\[icicle-move-to-previous-completion]
2826 Within a `*Completions*' column down, up
2827 Choose a completion candidate \\[choose-completion], \
2828 \\[mouse-choose-completion]\\<minibuffer-local-completion-map>
2830 * Cycle among input candidates.
2831 Completion candidates
2832 Current mode down, up, mouse wheel
2833 Prefix completion end, home
2834 Apropos completion next, prior
2835 Minibuffer history items \\[next-history-element], \
2836 \\[previous-history-element]
2837 Completion history items \\[icicle-retrieve-previous-input], \
2838 \\[icicle-retrieve-next-input]
2840 * Show help on individual completion candidates.
2841 Current candidate C-M-RET, C-M-mouse-2
2842 Next, previous candidate C-M-down, C-M-up,
2843 C-M- plus mouse wheel
2844 prefix-match candidate C-M-end, C-M-home
2845 apropos-match candidate C-M-next, C-M-prior
2847 * Choose a previous input from the minibuffer history.
2848 Complete to insert a previous input \\[icicle-insert-history-element]
2849 Complete against history items \\[icicle-history], \
2850 \\[icicle-keep-only-past-inputs]
2851 Restrict candidates to history items \\[icicle-keep-only-past-inputs]
2852 Change to another history \\[icicle-other-history]
2853 List history items first in Completions \\[icicle-toggle-alternative-sorting]
2854 Cycle among minibuffer history items \\[next-history-element], \
2855 \\[previous-history-element]
2857 * Delete history entries
2858 Delete current entry (cycling) \\[icicle-erase-minibuffer-or-history-element]
2859 Delete any or all entries \\[icicle-clear-current-history]
2861 * Multi-commands: Act on completion candidates.
2862 For alternative action, use `C-S-' instead of `C-', but
2863 `C-|' and `M-|' are alternative action versions of `C-!' and `M-!'.
2864 Current candidate C-RET, C-mouse-2
2865 Next, previous candidate C-down, C-up,
2867 prefix-match candidate C-end, C-home
2868 apropos-match candidate C-next, C-prior
2869 Act on each matching candidate, in turn C-!
2870 Act on the list of matching candidates M-!
2871 Delete object named by candidate S-delete
2872 Remove candidate from set of matches delete, S-mouse-2
2873 Save candidate (add to those saved) insert, M-S-mouse-2
2874 Object-action: apply a fn to candidate M-RET
2876 * Act on multiple minibuffer inputs \\[icicle-multi-inputs-act]
2878 * Search and replace (e.g. `C-c `'). See also `icicle-search'.
2879 Use action keys (prefix `C-') to navigate.
2880 Use alternative action keys (prefix `C-S-') to replace matches.
2881 Toggle input highlighting at all hits \\[icicle-dispatch-C-^]
2882 Toggle whole-word searching \\[icicle-dispatch-M-q]
2883 Toggle `.' matching newlines too \\[icicle-toggle-dot]
2884 Toggle escaping of special regexp chars \\[icicle-toggle-regexp-quote]
2885 Toggle removal of search highlighting \\[icicle-dispatch-C-.]
2888 Redefine the replacement string \\[icicle-dispatch-M-comma]
2889 Toggle literal replacement \\[icicle-toggle-literal-replacement]
2890 Toggle replacement of whole search hit \\[icicle-dispatch-M-_]
2891 Toggle replacement of common match \\[icicle-toggle-search-replace-common-match]
2893 * Perform set operations on candidate sets.
2894 Remove candidate from current set delete, S-mouse-2
2895 Add current candidate to saved set insert, M-S-mouse-2
2896 Retrieve saved candidates from...
2897 `icicle-saved-completion-candidates' \\[icicle-candidate-set-retrieve]
2898 another variable \\[icicle-candidate-set-retrieve-from-variable]
2899 a cache file \\[icicle-candidate-set-retrieve-persistent]
2900 Retrieve more saved candidates \\[icicle-candidate-set-retrieve-more]
2901 Save candidates in current set to...
2902 `icicle-saved-completion-candidates' \\[icicle-candidate-set-save]
2903 another variable \\[icicle-candidate-set-save-to-variable]
2904 a cache file \\[icicle-candidate-set-save-persistently]
2905 Save more candidates to current set \\[icicle-candidate-set-save-more]
2906 Save, save more selected candidates \\[icicle-candidate-set-save-selected], \
2907 \\[icicle-candidate-set-save-more-selected] with region
2908 Save multiple minibuffer inputs \\[icicle-multi-inputs-save]
2909 Clear all saved candidates \\[icicle-candidate-set-save-selected] \
2911 Add new or update existing saved set
2912 \\[icicle-add/update-saved-completion-set]
2913 Remove a saved completion set
2914 \\[icicle-remove-saved-completion-set]
2915 Swap current and saved sets \\[icicle-candidate-set-swap]
2916 Define current set by evaluating sexp \\[icicle-candidate-set-define]
2917 Restrict candidates to history items \\[icicle-keep-only-past-inputs]
2918 Set complement \\[icicle-candidate-set-complement]
2919 Set difference \\[icicle-candidate-set-difference]
2920 Set union \\[icicle-candidate-set-union]
2921 Set intersection \\[icicle-candidate-set-intersection]
2922 Set intersection using regexp \\[icicle-narrow-candidates]
2923 Set intersection using predicate \\[icicle-narrow-candidates-with-predicate]
2924 Save current predicate to a variable \\[icicle-save-predicate-to-variable]
2925 Insert string variable as input \\[icicle-insert-string-from-variable]
2927 * Adjust Icicles options incrementally on the fly (uses Do Re Mi).
2928 `icicle-candidate-width-factor' \\[icicle-doremi-candidate-width-factor+]
2929 `icicle-max-candidates' \\[icicle-doremi-increment-max-candidates+]
2930 `icicle-swank-timeout' C-x 1
2931 `icicle-swank-prefix-length' C-x 2
2932 `icicle-inter-candidates-min-spaces' \\[icicle-doremi-inter-candidates-min-spaces+]
2933 Zoom `*Completions*' (not an option) C-x - (Emacs 23+)
2935 Remember: You can always input any character (e.g. \\[icicle-prefix-complete]) that is bound
2936 to a command by preceding it with \\<global-map>\\[quoted-insert].
2938 Though it has no direct connection with completion, you can use \
2939 `\\<minibuffer-local-completion-map>\\[icicle-pp-eval-expression-in-minibuffer]'
2940 in the minibuffer at any time to evaluate an Emacs-Lisp expression.
2941 This calls `icicle-pp-eval-expression-in-minibuffer', which displays
2942 the result in the echo area or a popup buffer, *Pp Eval Output*.
2943 It also provides some of the Emacs-Lisp key bindings during expression
2945 (if icicle-buffer-ignore-space-prefix-flag 'yes 'no)
2946 (if icicle-use-C-for-actions-flag 'yes 'no)
2947 (if icicle-use-~-for-home-dir-flag 'yes 'no)
2948 (if icicle-search-highlight-all-current-flag 'yes 'no)
2949 (if icicle-search-whole-word-flag 'yes 'no)
2950 (if icicle-search-cleanup-flag 'yes 'no)
2951 (if icicle-search-replace-whole-candidate-flag 'yes 'no)
2952 (if icicle-search-replace-common-match-flag 'yes 'no)
2953 (if icicle-search-complement-domain-p 'yes 'no))
2954 icicle-general-help-string
2957 These are all of the minibuffer bindings during completion:
2959 \\{minibuffer-local-completion-map}"))))
2961 (defun icicle-help-string-non-completion ()
2962 "Description of Icicles minibuffer bindings when not completing input."
2963 (icicle-S-iso-lefttab-to-S-TAB
2964 (substitute-command-keys
2965 (concat "\\<minibuffer-local-completion-map>\
2966 Icicles Minibuffer Input when Not Completing
2967 --------------------------------------------
2969 These are the main Icicles minibuffer key bindings when completion is
2972 * Show this help. \\[icicle-minibuffer-help]
2974 * Abandon your input. \\[icicle-abort-recursive-edit]
2976 * Commit your input to Emacs. RET
2978 * Modify your input.
2979 Edit your input (just edit in minibuffer)
2980 Erase your input (clear minibuffer) \\[icicle-erase-minibuffer-or-history-element]
2981 Yank text at cursor into minibuffer \\[icicle-insert-string-at-point]
2982 Insert text (string) from a variable \\[icicle-insert-string-from-variable]
2983 Insert previously entered input(s) \\[icicle-insert-history-element]
2984 Insert completion candidates(s) \\[icicle-roundup]
2986 * Act on multiple minibuffer inputs \\[icicle-multi-inputs-act]
2988 * Save multiple inputs for later completion \\[icicle-multi-inputs-save]
2990 * Choose a previous input from the minibuffer history.
2991 Complete to insert a previous input \\[icicle-insert-history-element]
2992 Cycle among minibuffer history items \\[next-history-element], \
2993 \\[previous-history-element]
2995 * Delete history entries
2996 Delete current entry (cycling) \\[icicle-erase-minibuffer-or-history-element]
2997 Delete any or all entries \\[icicle-clear-current-history]
2999 * Evaluate an Emacs-Lisp sexp on the fly \\[icicle-pp-eval-expression-in-minibuffer]
3001 Remember: You can always input any character that is bound to a
3002 command by preceding it with \\<global-map>\\[quoted-insert]."
3003 icicle-general-help-string
3006 These are the minibuffer bindings when not completing input:
3008 \\{minibuffer-local-map}"))))
3010 (when (and (> emacs-major-version 21)
3011 (require 'help-mode nil t)
3012 (get 'help-xref 'button-category-symbol)) ; In `button.el'
3013 (define-button-type 'icicle-help-button
3014 :supertype 'help-xref
3015 'help-function (lambda () (browse-url "http://www.emacswiki.org/cgi-bin/wiki/Icicles"))
3017 (purecopy "mouse-2, RET: Icicles documentation on the Emacs Wiki (requires Internet access)"))
3018 (define-button-type 'icicle-commentary1-button
3019 :supertype 'help-xref
3020 'help-function (lambda ()
3021 (finder-commentary "icicles-doc1")
3022 (when (require 'linkd nil t) (linkd-mode 1))
3023 (when (require 'fit-frame nil t) (fit-frame)))
3024 'help-echo (purecopy "mouse-2, RET: Icicles documentation, Part 1 (no Internet needed)"))
3025 (define-button-type 'icicle-commentary2-button
3026 :supertype 'help-xref
3027 'help-function (lambda ()
3028 (finder-commentary "icicles-doc2")
3029 (when (require 'linkd nil t) (linkd-mode 1))
3030 (when (require 'fit-frame nil t) (fit-frame)))
3031 'help-echo (purecopy "mouse-2, RET: Icicles documentation, Part 2 (no Internet needed)"))
3032 (define-button-type 'icicle-customize-button
3033 :supertype 'help-xref
3034 'help-function (lambda () (customize-group-other-window 'Icicles))
3035 'help-echo (purecopy "mouse-2, RET: Customize/Browse Icicles Options & Faces")))
3038 ;; This is just the macro expansion of the following:
3039 ;; `(def-completion-wrapper icicle-abort-recursive-edit :minibuffer-separator)'.
3040 ;; Taken from the definition of `def-completion-wrapper' in `completion.el'.
3041 (put 'icicle-abort-recursive-edit 'completion-function 'use-completion-minibuffer-separator)
3043 (defun icicle-abort-recursive-edit () ; Bound to `C-]',`C-g' in minibuf, `C-g',`q' in `*Completions*'.
3044 "Abort recursive edit or minibuffer input, or just deactivate region.
3045 If called from the minibuffer, the region is active there, and
3046 `delete-selection-mode' is turned on, then just deactivate the region.
3048 Otherwise, call `abort-recursive-edit' after killing buffer
3049 `*Completions*' or (if called from the minibuffer) after removing its
3052 By default, Icicle mode remaps all key sequences that are normally
3053 bound to `abort-recursive-edit' to `icicle-abort-recursive-edit'. If
3054 you do not want this remapping, then customize option
3055 `icicle-top-level-key-bindings'."
3057 (if (and mark-active (boundp 'delete-selection-mode) delete-selection-mode
3058 (eq (selected-window) (minibuffer-window)) (active-minibuffer-window))
3060 (if (not (active-minibuffer-window))
3061 (when (get-buffer "*Completions*") (kill-buffer (get-buffer "*Completions*")))
3062 (when (and (boundp '1on1-fit-minibuffer-frame-flag) ; In `oneonone.el'.
3063 1on1-fit-minibuffer-frame-flag (require 'fit-frame nil t))
3064 (1on1-fit-minibuffer-frame 'RESET))
3065 (icicle-remove-Completions-window 'FORCE))
3066 (abort-recursive-edit)))
3068 (unless (fboundp 'save&set-overriding-map) ; Only Emacs 20-23 use `ensure-overriding-map-is-bound'.
3069 (defun icicle-ensure-overriding-map-is-bound ()
3070 "Set `overriding-terminal-local-map' to `icicle-universal-argument-map'."
3071 (if (not (boundp 'overriding-map-is-bound)) ; Emacs 20, 21.
3072 (setq overriding-terminal-local-map icicle-universal-argument-map)
3073 (unless overriding-map-is-bound ; Emacs 22+.
3074 (setq saved-overriding-map overriding-terminal-local-map
3075 overriding-terminal-local-map icicle-universal-argument-map
3076 overriding-map-is-bound t)))))
3078 (defun icicle-digit-argument (arg) ; Bound to `C-<0-9>', `M-<0-9>', `C-M-<0-9>' in minibuffer.
3079 "`digit-argument', but also echo the prefix."
3081 (let* ((char (if (integerp last-command-event)
3083 (icicle-get-safe last-command-event 'ascii-character)))
3084 (digit (- (logand char ?\177) ?0)))
3085 (setq prefix-arg (cond ((integerp arg) (+ (* arg 10) (if (< arg 0) (- digit) digit)))
3086 ;; Treat -0 as just -, so that -01 will work.
3087 ((eq arg '-) (if (zerop digit) '- (- digit)))
3089 (if (fboundp 'universal-argument--mode)
3090 (icicle-universal-argument--mode)
3091 (setq universal-argument-num-events (length (this-command-keys)))
3092 (if (fboundp 'save&set-overriding-map) ; Emacs 24.1 to 24.3.
3093 (save&set-overriding-map icicle-universal-argument-map)
3094 (icicle-ensure-overriding-map-is-bound)))
3095 (icicle-msg-maybe-in-minibuffer "prefix %S" prefix-arg))
3097 (defun icicle-negative-argument (arg) ; Bound to `M--', `C-M--' in minibuffer.
3098 "`negative-argument', but also echo the prefix."
3100 (setq prefix-arg (cond ((integerp arg) (- arg))
3103 (if (fboundp 'universal-argument--mode)
3104 (icicle-universal-argument--mode)
3105 (setq universal-argument-num-events (length (this-command-keys)))
3106 (if (fboundp 'save&set-overriding-map) ; Emacs 24.1 to 24.3.
3107 (save&set-overriding-map icicle-universal-argument-map)
3108 (icicle-ensure-overriding-map-is-bound)))
3109 (icicle-msg-maybe-in-minibuffer "prefix %S" prefix-arg))
3111 (when (fboundp 'universal-argument--mode) ; Emacs 24.4+.
3112 (defun icicle-universal-argument--mode ()
3113 "Like `universal-argument--mode', but use `icicle-universal-argument-map'."
3114 (let ((fun (if (fboundp 'set-transient-map) ; Make it work also for Emacs 24.3.50 snapshots
3115 #'set-transient-map ; prior to the renaming of `set-temporary-overlay-map'.
3116 #'set-temporary-overlay-map)))
3117 (funcall fun icicle-universal-argument-map))))
3119 (defun icicle-universal-argument () ; Bound to `C-u' in minibuffer.
3120 "`universal-argument', but also echo the prefix."
3122 (cond ((fboundp 'universal-argument--mode) ; Emacs 24.4+.
3123 (setq prefix-arg (list 4))
3124 (icicle-universal-argument--mode))
3126 (setq prefix-arg (list 4)
3127 universal-argument-num-events (length (this-command-keys)))
3128 (if (fboundp 'save&set-overriding-map)
3129 (save&set-overriding-map icicle-universal-argument-map) ; Emacs 24.1 to 24.3.
3130 (icicle-ensure-overriding-map-is-bound)))) ; Emacs < 24.1.
3131 (icicle-msg-maybe-in-minibuffer "prefix %S" prefix-arg))
3133 (defun icicle-universal-argument-more (arg)
3134 "`universal-argument-more', but also echo the prefix."
3136 (universal-argument-more arg)
3137 (icicle-msg-maybe-in-minibuffer "prefix %S" prefix-arg))
3139 (when (fboundp 'universal-argument-other-key) ; Emacs < 24.4.
3140 (defun icicle-universal-argument-other-key (arg)
3141 "`universal-argument-other-key', but also echo the prefix."
3143 (universal-argument-other-key arg)
3144 (icicle-msg-maybe-in-minibuffer "prefix %S" prefix-arg)))
3146 (unless (fboundp 'universal-argument--mode)
3147 (defun icicle-universal-argument-minus (arg) ; Emacs < 24.4.
3148 "`universal-argument-minus', but also echo the prefix."
3150 (universal-argument-minus arg)
3151 (icicle-msg-maybe-in-minibuffer "prefix %S" prefix-arg)))
3154 ;; REPLACE ORIGINAL `sit-for' in `subr.el',
3155 ;; saving it for restoration when you toggle `icicle-mode'.
3157 ;; 1. Ensure that `sit-for' after `C-u' in the minibuffer is immediately interrupted by user input.
3158 ;; This fix is not needed for Emacs < 23.
3160 ;; 2. Bind `inhibit-quit' to t, so `C-g' is handled after `sit-for', by `icicle-abort-recursive-edit'.
3162 (unless (fboundp 'icicle-ORIG-sit-for)
3163 (defalias 'icicle-ORIG-sit-for (symbol-function 'sit-for)))
3165 (when (> emacs-major-version 22)
3166 (defun icicle-sit-for (seconds &optional nodisp obsolete)
3167 "Perform redisplay, then wait for SECONDS seconds or until input is available.
3168 SECONDS may be a floating-point value.
3169 \(On operating systems that do not support waiting for fractions of a
3170 second, floating-point values are rounded down to the nearest integer.)
3172 If optional arg NODISP is t, don't redisplay, just wait for input.
3173 Redisplay does not happen if input is available before it starts.
3175 Value is t if waited the full time with no input arriving, and nil otherwise.
3177 An obsolete, but still supported form is
3178 \(sit-for SECONDS &optional MILLISECONDS NODISP)
3179 where the optional arg MILLISECONDS specifies an additional wait period,
3180 in milliseconds; this was useful when Emacs was built without
3181 floating point support."
3182 (if (numberp nodisp)
3183 (setq seconds (+ seconds (* 1e-3 nodisp))
3185 (when obsolete (setq nodisp obsolete)))
3186 (cond (noninteractive
3192 (or nodisp (redisplay)))
3194 (or nodisp (redisplay))
3195 (let* ((inhibit-quit t)
3196 (read (read-event nil nil seconds)))
3199 ;; If last command was a prefix arg, e.g. C-u, push this event onto
3200 ;; `unread-command-events' as (t . EVENT) so it will be added to
3201 ;; `this-command-keys' by `read-key-sequence'.
3202 (when (memq overriding-terminal-local-map
3203 (list universal-argument-map icicle-universal-argument-map))
3204 (setq read (cons t read)))
3205 (push read unread-command-events)
3208 (defun icicle-retrieve-next-input (&optional arg) ; Bound to `C-S-l' (`C-L') in minibuffer.
3209 "Retrieve next minibuffer input.
3210 Like `icicle-retrieve-previous-input', but traverses history toward
3213 You can use this command only from the minibuffer (`\\<minibuffer-local-completion-map>\
3214 \\[icicle-retrieve-next-input]')."
3216 (icicle-retrieve-previous-input arg 'interactive-p)) ; Must be `interactive-p'.
3218 (defun icicle-retrieve-previous-input (&optional arg reversep allow-empty-p) ; `C-l' in minibuffer.
3219 "Retrieve previous minibuffer input.
3220 The possible inputs were not necessarily those entered with `RET'.
3221 With a negative prefix arg, this just empties the completion history.
3223 Use completion if `icicle-C-l-uses-completion-flag' is non-nil and no
3224 prefix arg is used, or if it is nil and a prefix arg is used, or if
3225 `icicle-retrieve-previous-input' is not used interactively.
3226 Otherwise, just cycle to the previous input.
3229 Non-nil argument REVERSEP means reverse the history order: return the
3230 next, not the previous, input.
3231 Non-nil ALLOW-EMPTY-P means the retrieved input can be \"\".
3233 You can use this command only from buffer *Completions or from the
3234 minibuffer (`\\<minibuffer-local-completion-map>\
3235 \\[icicle-retrieve-previous-input]')."
3237 (let ((interactive-p (or (interactive-p) (eq reversep 'interactive-p)))
3238 (prev-inputs-var (if (icicle-file-name-input-p)
3239 'icicle-previous-raw-file-name-inputs
3240 'icicle-previous-raw-non-file-name-inputs))
3241 ;; `irpi-was-cycling-p' is used to remember, for the second `C-l' in a row, that the first
3242 ;; `C-l' came after cycling. In that case, the second `C-l' restores the current raw input.
3243 (irpi-was-cycling-p icicle-cycling-p))
3244 (when interactive-p (icicle-barf-if-outside-Completions-and-minibuffer))
3245 (cond ((wholenump (prefix-numeric-value arg))
3247 (save-selected-window
3248 (select-window (minibuffer-window))
3249 (icicle-clear-minibuffer)
3252 (symbol-value prev-inputs-var)
3253 (icicle-remove-if (lambda (x) (string= "" x)) ; Exclude "".
3254 (symbol-value prev-inputs-var)))))
3256 (if (and interactive-p (or (and icicle-C-l-uses-completion-flag (not arg))
3257 (and (not icicle-C-l-uses-completion-flag) arg)))
3258 (let ((icicle-whole-candidate-as-text-prop-p nil)
3259 (enable-recursive-minibuffers t)
3260 (icicle-show-Completions-initially-flag t))
3261 (prog1 (completing-read
3262 "Retrieve input: " (mapcar #'list prev-inputs) nil t)
3263 (setq icicle-last-input nil)))
3264 (if (or (not interactive-p)
3265 (not (memq last-command '(icicle-retrieve-next-input
3266 icicle-retrieve-previous-input))))
3267 ;; We use this one, to exclude common-match expansions from completion
3268 ;; history, and to save the typed input only when you complete.
3269 (let ((try (if icicle-cycling-p
3271 icicle-current-raw-input)))
3272 (if (or allow-empty-p (not (equal "" try))) try (car prev-inputs)))
3274 ;; You can use this one instead, if you want to include common-match
3275 ;; expansions and save the typed input even when you don't complete.
3276 ;; (or icicle-last-input icicle-current-raw-input)
3278 (let ((next (member icicle-current-raw-input prev-inputs)))
3279 (unless next (setq next prev-inputs))
3282 (inputs prev-inputs))
3283 (while (and (consp inputs) (not (eq inputs next)))
3284 (push (pop inputs) res))
3286 (car (last prev-inputs)))
3287 ;; If we were cycling before the first `C-l', then need to pick up the
3288 ;; current raw input. Otherwise, we need to pick up the previous one.
3289 (prog1 (if irpi-was-cycling-p (car next) (cadr next))
3290 (setq irpi-was-cycling-p nil))))))) ; So third `C-l' acts normally.
3292 ;; $$$$ (when input (icicle-call-then-update-Completions #'insert input))))
3293 ;; $$$$$$ (when input (insert input))))
3295 ;;; $$$$$$ REPLACED by previous line only.
3297 (setq icicle-current-raw-input input)
3299 (icicle-highlight-initial-whitespace input) ; (e.g. user typo).
3300 (icicle-place-cursor input 'deactivate-mark))))
3302 ;;; (let ((icicle-edit-update-p t))
3303 ;;; (funcall (or icicle-last-completion-command 'icicle-apropos-complete))
3304 ;;; ;; Restore raw input. Cycling resets it to "", so `icicle-save-or-restore-input'
3305 ;;; ;; doesn't use out-of-date raw input (cycling does not necessarily follow completion
3306 ;;; ;; or completion of the same kind).
3307 ;;; (setq icicle-current-raw-input input))
3309 (setq icicle-current-raw-input input ; So we can keep cycling.
3310 icicle-last-input nil ; So `TAB' expands it - `icicle-save-or-restore-input'.
3311 icicle-cycling-p irpi-was-cycling-p))) ; Let next `C-l' know the state.
3313 (set prev-inputs-var nil)
3314 (setq icicle-current-raw-input "")
3315 (icicle-msg-maybe-in-minibuffer "Cleared completion history")))))
3317 ;; $$ No longer bound. Now we bind `icicle-retrieve-previous-input', instead, to `C-l'.
3319 (defun icicle-retrieve-last-input ()
3320 "Put the last real input into the minibuffer.
3321 Use this to replace a completion candidate inserted during cycling or
3322 because of input expansion due to the value of option
3323 `icicle-expand-input-to-common-match'.
3325 If you are cycling and expansion is also in effect, then use this
3326 twice in succession: once to restore the expanded common match string,
3327 and a second time to restore your unexpanded original input.
3329 You can use this command only from buffer `*Completions' or from the
3332 (when (interactive-p) (icicle-barf-if-outside-Completions-and-minibuffer))
3333 (save-selected-window
3334 (select-window (minibuffer-window))
3335 (icicle-clear-minibuffer)
3336 (if (and (eq last-command 'icicle-retrieve-last-input)
3337 (or (and (eq icicle-current-completion-mode 'apropos)
3338 (eq icicle-expand-input-to-common-match 4))
3339 (and (eq icicle-current-completion-mode 'prefix)
3340 (memq icicle-expand-input-to-common-match '(3 4)))))
3341 (insert icicle-current-raw-input)
3342 (insert icicle-current-input))
3343 ;;$$$ (when (interactive-p) (setq icicle-last-completion-command nil))
3344 (let ((input (if (and (eq last-command this-command)
3345 (or (and (eq icicle-current-completion-mode 'apropos)
3346 (eq icicle-expand-input-to-common-match 4))
3347 (and (eq icicle-current-completion-mode 'prefix)
3348 (memq icicle-expand-input-to-common-match '(3 4)))))
3349 icicle-current-raw-input
3350 icicle-current-input)))
3351 (icicle-highlight-initial-whitespace input) ; Highlight initial whitespace (e.g. user typo).
3352 (icicle-place-cursor input 'deactivate-mark))))
3354 ;; $$ No longer used. It was originally used in `icicle-retrieve-last-input'.
3355 (defun icicle-insert-input (input)
3356 "Insert INPUT. Prepend the directory if appropriate."
3357 (insert (if (and (icicle-file-name-input-p)
3358 insert-default-directory
3359 (or (not (member input icicle-extra-candidates))
3360 icicle-extra-candidates-dir-insert-p))
3361 (icicle-expand-file-or-dir-name input (icicle-file-name-directory input))
3364 (icicle-define-command icicle-insert-history-element ; Bound to `M-o' in minibuffer.
3365 "Use completion to insert previously entered inputs in the minibuffer.
3366 Insert a space character after each (but see below, to prevent this).
3367 Always available for any minibuffer input, not just during completion.
3368 With a non-negative prefix arg, wrap candidate to insert with \"...\".
3369 With a non-positive prefix arg, do not append a space char.
3371 If you use a prefix argument also for an individual candidate
3372 insertion action then that overrides any prefix argument or lack
3373 thereof that you used for this command. For example, with no prefix
3374 argument, \\<minibuffer-local-map>`\\[icicle-insert-history-element]' \
3375 does not wrap candidates with \"...\", but if you use,
3376 e.g., `C-u C-RET' then that candidate is so wrapped."
3377 icicle-insert-candidate-action ; Action function
3378 "Choose past input (`C-g' to end): " ; `completing-read' args
3379 (mapcar #'list hist-val) nil nil nil nil nil nil
3380 ((enable-recursive-minibuffers t) ; Bindings
3381 (hist-val (and (boundp minibuffer-history-variable)
3382 (consp (symbol-value minibuffer-history-variable))
3383 (symbol-value minibuffer-history-variable)))
3384 (hist-val (and hist-val (icicle-remove-duplicates hist-val)))
3385 (icicle-pref-arg (and current-prefix-arg (prefix-numeric-value current-prefix-arg)))
3389 (when (interactive-p) (icicle-barf-if-outside-minibuffer))
3390 (when (and (consp hist-val) (not (stringp (car hist-val)))) ; Convert, e.g. `comand-history'.
3391 (setq hist-val (mapcar #'prin1-to-string hist-val)))
3392 ;; $$$$$$ (icicle-clear-minibuffer)
3396 (apply #'insert (nreverse to-insert))
3397 (when (and icicle-mode (memq icicle-default-value '(preselect-start preselect-end)))
3398 (icicle-select-minibuffer-contents)
3399 (setq deactivate-mark nil))))
3401 (icicle-define-command icicle-roundup ; Bound to `M-r' in minibuffer.
3402 "Insert one or more completion candidates in the minibuffer.
3403 Insert a space character after each (but see below, to prevent this).
3404 With a non-negative prefix arg, wrap candidate to insert with \"...\".
3405 With a non-positive prefix arg, do not append a space char.
3407 If you use a prefix argument also for an individual candidate
3408 insertion action then that overrides any prefix argument or lack
3409 thereof that you used for this command. For example, with no prefix
3410 argument, \\<minibuffer-local-map>`\\[icicle-roundup]' \
3411 does not wrap candidates with \"...\", but if you use,
3412 e.g., `C-u C-RET' then that candidate is so wrapped."
3413 icicle-insert-candidate-action ; Action function
3414 "Roundup - choose (`C-g' to end): " ; `completing-read' args
3415 (and icicle-completion-candidates (mapcar #'list icicle-completion-candidates))
3416 nil nil nil nil nil nil
3417 ((enable-recursive-minibuffers t) ; Bindings
3418 (icicle-pref-arg (and current-prefix-arg (prefix-numeric-value current-prefix-arg)))
3422 (when (interactive-p) (icicle-barf-if-outside-minibuffer))
3423 (unless icicle-completion-candidates
3424 (icicle-user-error "No completion candidates - did you hit `TAB' or `S-TAB'?"))
3425 (icicle-clear-minibuffer))
3428 (apply #'insert (nreverse to-insert))
3429 (when (and icicle-mode (memq icicle-default-value '(preselect-start preselect-end)))
3430 (icicle-select-minibuffer-contents)
3431 (setq deactivate-mark nil))))
3433 (defun icicle-insert-candidate-action (cand)
3434 "Action function for `icicle-insert-history-element' and `icicle-roundup'."
3435 ;; FREE here: TO-INSERT, COUNT.
3436 (unless (equal cand "")
3437 (let ((prefix-arg (if current-prefix-arg (prefix-numeric-value current-prefix-arg) icicle-pref-arg)))
3438 (push (if (and prefix-arg (natnump prefix-arg)) (format "\"%s\"" cand) cand) to-insert)
3439 (unless (and prefix-arg (<= prefix-arg 0)) (push " " to-insert))
3440 (message "Inserted: %s%s"
3441 (icicle-propertize (format "%d" (setq count (1+ count))) 'face 'icicle-msg-emphasis)
3442 (if (not prefix-arg)
3444 (format " [%s]" (concat (and (natnump prefix-arg) "\"...\"-wrapped")
3445 (and (zerop prefix-arg) " and ")
3446 (and (<= prefix-arg 0) "NOT `SPC'-separated"))))))))
3448 (defun icicle-insert-string-at-point (&optional arg) ; Bound to `M-.' in minibuffer.
3449 "Insert text at the cursor into the minibuffer.
3450 Each time this command is called, some text at or near the cursor is
3451 inserted into the minibuffer. One of two things happens, depending on
3452 the value of option `icicle-default-thing-insertion' and whether or
3455 See the doc for option `icicle-thing-at-point-functions' for a
3456 complete description of its behavior. What follows is an overview.
3458 `icicle-thing-at-point-functions' is a cons of two parts - call them
3459 ALTERNATIVES and FORWARD-THING.
3461 If ALTERNATIVES is not nil and one of the following is true:
3462 - FORWARD-THING is nil
3463 - the value of `icicle-default-thing-insertion' is `alternatives' and
3464 you have not used plain `C-u' in this series of `M-.'
3465 - the value of `icicle-default-thing-insertion' is `more-of-the-same'
3466 and you have used plain `C-u' in this series of `M-.'
3467 then the next function in ALTERNATIVES is used to retrieve the text to
3470 If FORWARD-THING is not nil and one of the following is true:
3471 - ALTERNATIVES is nil
3472 - the value of `icicle-default-thing-insertion' is `more-of-the-same'
3473 and you have not used `C-u' in this series of `M-.'
3474 - the value of `icicle-default-thing-insertion' is `alternatives' and
3475 you have used `C-u' in this series of `M-.'
3476 then function FORWARD-THING is used to retrieve the text to be
3479 If you use a numeric prefix arg (not just plain `C-u'), the behavior
3482 * If a function in ALTERNATIVES is used (see above), then the text
3483 that is grabbed at or near point is read as a Lisp sexp and
3484 evaluated, and the value is inserted instead of the grabbed text.
3486 Yes, this means you need to know when the particular ALTERNATIVES
3487 function that you want is coming up next, and use, say, `C-9' just
3488 before hitting `M-.' for that alternative. So if, e.g., you want to
3489 evaluate the active region and insert the value, then you use
3490 `M-. C-9 M-.', since it is the second `M-.' that grabs the region.
3492 * If the FORWARD-THING is being used, then the prefix arg determines
3493 the number of things to grab, and the direction of grabbing.: A
3494 negative argument grabs text to the left of the cursor; a positive
3495 argument grabs text to the right.
3497 You can use this command only from the minibuffer (`\\<minibuffer-local-completion-map>\
3498 \\[icicle-insert-string-at-point]')."
3500 (when (interactive-p) (icicle-barf-if-outside-minibuffer))
3501 (when (consp icicle-thing-at-point-functions) ; Option should always be a cons cell.
3502 (unless (eq last-command this-command) (setq icicle-default-thing-insertion-flipped-p nil))
3503 (let ((alt-fns (car icicle-thing-at-point-functions))
3504 (fwd-thing-fn (cdr icicle-thing-at-point-functions))
3505 (flipped (or icicle-default-thing-insertion-flipped-p ; Already flipped.
3506 (setq icicle-default-thing-insertion-flipped-p (consp arg)))))
3508 ;; Use alternative text-grabbing functions successively.
3509 ((and alt-fns (or (if (eq 'alternatives icicle-default-thing-insertion)
3510 (not flipped) ; Normal behavior for `alternatives'.
3511 flipped) ; Flipped behavior for `more-of-the-same'.
3512 (not fwd-thing-fn))) ; No alternative.
3513 (setq icicle-successive-grab-count 1 ; In this mode, reset other mode's accumulator.
3514 icicle-thing-at-pt-fns-pointer
3515 (if (eq last-command this-command) ; If repeated, get next text-grabbing function.
3516 (mod (1+ icicle-thing-at-pt-fns-pointer) (length alt-fns))
3519 (alt-fn (nth icicle-thing-at-pt-fns-pointer alt-fns)))
3520 (save-excursion (with-current-buffer icicle-pre-minibuffer-buffer
3521 (setq thing (funcall alt-fn))))
3522 (setq thing (or thing "nil"))
3523 (when (and arg (atom arg)) ; Numeric prefix arg.
3524 (setq thing (condition-case err
3525 (format "%s" (eval (car (read-from-string thing))))
3527 (icicle-insert-thing thing)
3528 (icicle-msg-maybe-in-minibuffer (format "`%s'" alt-fn))))
3530 ;; Use same text-grabbing function successively.
3531 ((and fwd-thing-fn (or (if (eq 'alternatives icicle-default-thing-insertion)
3532 flipped ; Flipped behavior for `alternatives'.
3533 (not flipped)) ; Normal behavior for `more-of-the-same'.
3534 (not alt-fns))) ; No alternative.
3535 (if (and arg (atom arg))
3537 ;; Explicit numeric arg. If it doesn't change direction, then increment
3538 ;; existing count. Otherwise, set count absolutely.
3539 (if (eq last-command this-command)
3540 (if (= (icicle-signum icicle-successive-grab-count) ; Repeated `M-.'.
3541 (icicle-signum (prefix-numeric-value arg)))
3542 (setq icicle-successive-grab-count ; Same direction - increment count.
3543 (* (icicle-signum icicle-successive-grab-count)
3544 (+ (abs icicle-successive-grab-count)
3545 (abs (prefix-numeric-value arg)))))
3546 (setq icicle-successive-grab-count (prefix-numeric-value arg))) ; New dir - set.
3547 (setq icicle-successive-grab-count (prefix-numeric-value arg))) ; First `M-.' - set.
3549 ;; No explicit numeric arg.
3550 ;; If first `M-.' or plain `C-u', set count. Otherwise, increment count.
3551 (if (eq last-command this-command)
3552 (setq icicle-successive-grab-count ; Repeated `M-.'.
3554 ;; We're here from plain `C-u' with `alternatives' - use 1, not 4.
3555 (if (wholenump icicle-successive-grab-count) 1 -1)
3556 (if (wholenump icicle-successive-grab-count) ; Increment count.
3557 (+ icicle-successive-grab-count (abs (prefix-numeric-value arg)))
3558 (- icicle-successive-grab-count (abs (prefix-numeric-value arg))))))
3559 (setq icicle-successive-grab-count 1))) ; First `M-.' - reset count.
3562 (with-current-buffer (cadr (buffer-list))
3563 (setq things (buffer-substring-no-properties
3565 (save-excursion (funcall fwd-thing-fn icicle-successive-grab-count)
3567 (icicle-insert-thing things)))))))
3569 (defun icicle-signum (num)
3570 "Return 1 if NUM is positive, -1 if negative, 0 if zero."
3571 (cond ((< num 0) -1) ((> num 0) 1) (t 0)))
3573 (defun icicle-insert-thing (text &optional no-replace-p)
3574 "Insert TEXT in the minibuffer.
3575 TEXT replaces the last text that was inserted, if this command repeats
3576 the last and NO-REPLACE-P is nil."
3577 (when (and (stringp text) (not (string= "" text)))
3578 (remove-text-properties 0 (length text) '(face nil) text)
3579 (when (and (eq last-command this-command)
3581 icicle-insert-string-at-pt-start) ; Ensure that we've defined the ends.
3582 (delete-region icicle-insert-string-at-pt-start icicle-insert-string-at-pt-end))
3583 (setq icicle-insert-string-at-pt-start (point))
3585 (setq icicle-insert-string-at-pt-end (point))))
3587 (defun icicle-insert-string-from-variable (askp) ; Bound to `C-=' in minibuffer.
3588 "Insert text into the minibuffer from a variable.
3589 By default, the variable is user option `icicle-input-string'. To
3590 insert from a different variable, use a prefix argument. You are then
3591 prompted for the variable to use. Completion candidates for this
3592 include all string-valued variables.
3594 You can use command `icicle-save-string-to-variable' to save a string
3595 to a variable. Typically, you store a regexp or part of a regexp in
3596 the variable. This command is bound in the minibuffer to `C-=', by
3597 default. This is especially useful when used with command
3600 Some regexps that you might want to assign to variables:
3602 \"[A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+\" ; Email address
3603 \"\\\\([0-9]+\\\.[0-9]+\\\.[0-9]+\\\.[0-9]+\\\\)\" ; IP address
3604 \"[0-9]\\\\\\\={4\\\\}-[0-9]\\\\\\\={2\\\\}-[0-9]\\\\\\\={2\\\\}\" ; Date: 2006-04-14, Time:
3605 \"^[ \\\=\\t]*[0-9]?[0-9]\\\\([:.]?[0-9][0-9]\\\\)?\\\\(am\\\\|pm\\\\|AM\\\\|PM\\\\)?\"
3606 \"`\\\\(\\\\sw\\\\sw+\\\\)'\" ; Words inside `_'
3607 \"\\\\*.*\\\\*\" ; Special buffer name: *_*
3609 Standard Emacs Lisp libraries are full of regexps that you can assign
3610 to variables for use with `C-='.
3611 See `align.el' for regexps for programming languages.
3612 See `url-dav.el' for regexps matching iso8601 dates.
3613 See `rmail.el', `sendmail.el', and `mh-show.el' for regexps matching
3616 Imenu regexps occurring as parts of different values of
3617 `imenu-generic-expression' for different buffer types can be used as
3618 variable values for `C-='. They all work fine with `icicle-search',
3619 turning it into a browser or navigator for the given mode.
3621 See, for example, `generic-x.el' and `lisp-mode.el'. Here is a regexp
3622 for Javascript function definitions from `generic-x.el':
3624 \"^function\\\\s-+\\\\([A-Za-z0-9_]+\\\\)\"
3626 And `lisp-imenu-generic-expression' (in `lisp-mode.el') provides
3627 regexps for Lisp function, variable, and type definitions. Here is
3628 the variable-definition regexp:
3630 \"^\\\\s-*(\\\\(def\\\\(c\\\\(onst\\\\(ant\\\\)?\\\\|ustom\\\\)\\\\|ine-symbol-macro\\\\|
3631 parameter\\\\|var\\\\)\\\\)\\\\s-+\\\\(\\\\(\\\\sw\\\\|\\\\s_\\\\)+\\\\)\"
3633 Command `icicle-imenu' exploits this to automatically let you browse
3634 definitions. It is a specialization of `icicle-search' for Imenu.
3636 For more useful regexps, grep for `font-lock-keywords' in Emacs `lisp'
3637 directory and subdirs.
3639 You can use this command only from the minibuffer (`\\<minibuffer-local-completion-map>\
3640 \\[icicle-insert-string-from-variable]')."
3642 (when (interactive-p) (icicle-barf-if-outside-Completions-and-minibuffer))
3643 (save-selected-window
3644 (select-window (minibuffer-window))
3646 (let* ((icicle-whole-candidate-as-text-prop-p nil)
3647 ;; If we didn't use this here we'd at least have to bind it to
3648 ;; `orig-must-pass-after-match-predicate', because of `icicle-execute-extended-command'.
3649 (icicle-must-pass-after-match-predicate (lambda (s)
3650 (let ((sym (intern-soft s)))
3651 (and sym (boundp (intern s))
3653 (icicle-var-is-of-type-p
3654 sym '(string color regexp)
3657 (enable-recursive-minibuffers t)
3659 (intern (completing-read "Insert text from variable: " obarray nil nil nil
3660 (if (boundp 'variable-name-history)
3661 'variable-name-history
3662 'icicle-variable-name-history))))
3663 ;; Make sure we use the buffer-local value of the variable, if there is one.
3665 (with-current-buffer (cadr (buffer-list)) (symbol-value var))))
3666 (icicle-insert-thing text 'no-replace))
3667 (icicle-insert-thing icicle-input-string 'no-replace))))
3669 (defun icicle-insert-list-join-string () ; Bound to `C-M-j' in minibuffer during completion.
3670 "Insert `icicle-list-join-string' in the minibuffer.
3671 Then, if `1on1-fit-minibuffer-frame-flag' is defined and non-nil, fit
3672 a standalone minibuffer frame to the new minibuffer contents.
3673 You need library `fit-frame.el' for the frame-fitting part."
3675 (icicle-insert-thing icicle-list-join-string 'no-replace)
3676 (let ((len (length icicle-list-join-string)))
3677 (when (and (string= "\C-j" (substring icicle-list-join-string (1- len) len))
3678 (boundp '1on1-fit-minibuffer-frame-flag) ; In `oneonone.el'.
3679 1on1-fit-minibuffer-frame-flag
3680 (require 'fit-frame nil t))
3681 (1on1-fit-minibuffer-frame))))
3683 (defun icicle-dispatch-M-q (&optional arg) ; Bound to `M-q' in minibuffer.
3684 "Do the right thing for `M-q'.
3685 If searching, call `icicle-toggle-search-whole-word'.
3686 Otherwise, call `icicle-insert-key-description'.
3687 Bound to `M-q' in the minibuffer."
3688 (interactive "P") ; Argument is ignored for `icicle-toggle-search-whole-word'.
3689 (cond (icicle-searching-p (icicle-toggle-search-whole-word))
3690 (t (icicle-insert-key-description arg))))
3692 ;; Top-level commands. Could instead be in `icicles-cmd2.el'.
3694 (defalias 'toggle-icicle-search-whole-word 'icicle-toggle-search-whole-word)
3695 (defun icicle-toggle-search-whole-word () ; Bound to `M-q' in minibuffer during Icicles search.
3696 "Toggle the value of `icicle-search-whole-word-flag'.
3697 The new value takes effect for the next Icicles search command.
3698 Bound to `M-q' in the minibuffer when searching."
3700 (setq icicle-search-whole-word-flag (not icicle-search-whole-word-flag))
3701 (icicle-msg-maybe-in-minibuffer
3702 "Whole-word searching is now %s, starting with next search"
3703 (icicle-propertize (if icicle-search-whole-word-flag "ON" "OFF") 'face 'icicle-msg-emphasis)))
3705 (defun icicle-insert-key-description (toggle-angle-brackets-p) ; Bound to `M-q' in minibuffer.
3706 "Read key and insert its description.
3707 For example, if the key read is ^F, then \"C-f\" is inserted.
3709 For Emacs 21+, `icicle-key-descriptions-use-<>-flag' determines
3710 whether angle brackets (`<', `>') are used for named