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