initial commit
[emacs-init.git] / auto-install / icicles-mode.el
1 ;;; icicles-mode.el --- Icicle Mode definition for Icicles
2 ;;
3 ;; Filename: icicles-mode.el
4 ;; Description: Icicle Mode definition for Icicles
5 ;; Author: Drew Adams
6 ;; Maintainer: Drew Adams
7 ;; Copyright (C) 1996-2011, Drew Adams, all rights reserved.
8 ;; Created: Mon Feb 27 10:21:10 2006
9 ;; Version: 22.0
10 ;; Last-Updated: Thu Sep  8 14:32:31 2011 (-0700)
11 ;;           By: dradams
12 ;;     Update #: 7595
13 ;; URL: http://www.emacswiki.org/cgi-bin/wiki/icicles-mode.el
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
17 ;;
18 ;; Features that might be required by this library:
19 ;;
20 ;;   `advice', `advice-preload', `apropos', `apropos+',
21 ;;   `apropos-fn+var', `avoid', `backquote', `bookmark', `bookmark+',
22 ;;   `bookmark+-1', `bookmark+-bmu', `bookmark+-key',
23 ;;   `bookmark+-lit', `bookmark+-mac', `bytecomp', `cl', `cus-edit',
24 ;;   `cus-face', `cus-load', `cus-start', `custom', `dired',
25 ;;   `dired+', `dired-aux', `dired-x', `doremi', `easymenu',
26 ;;   `ediff-diff', `ediff-help', `ediff-init', `ediff-merg',
27 ;;   `ediff-mult', `ediff-util', `ediff-wind', `el-swank-fuzzy',
28 ;;   `ffap', `ffap-', `fit-frame', `frame-cmds', `frame-fns',
29 ;;   `fuzzy', `fuzzy-match', `help+20', `hexrgb', `icicles-cmd1',
30 ;;   `icicles-cmd2', `icicles-face', `icicles-fn', `icicles-mac',
31 ;;   `icicles-mcmd', `icicles-opt', `icicles-var', `image-dired',
32 ;;   `info', `info+', `kmacro', `levenshtein', `menu-bar',
33 ;;   `menu-bar+', `misc-cmds', `misc-fns', `mkhtml',
34 ;;   `mkhtml-htmlize', `mouse3', `mwheel', `pp', `pp+', `regexp-opt',
35 ;;   `ring', `ring+', `second-sel', `strings', `thingatpt',
36 ;;   `thingatpt+', `unaccent', `w32-browser', `w32browser-dlgopen',
37 ;;   `wid-edit', `wid-edit+', `widget'.
38 ;;
39 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
40 ;;
41 ;;; Commentary:
42 ;;
43 ;;  This is a helper library for library `icicles.el'.  It defines the
44 ;;  command `icicle-mode'.  For Icicles documentation, see
45 ;;  `icicles-doc1.el' and `icicles-doc2.el'.
46 ;;
47 ;;  Commands defined here:
48 ;;
49 ;;    `icicle-handle-switch-frame', `icicle-mode', `icy-mode',
50 ;;    `icicle-skip-this-command', `old-bbdb-complete-name',
51 ;;    `old-comint-dynamic-complete',
52 ;;    `old-comint-dynamic-complete-filename',
53 ;;    `old-comint-replace-by-expanded-filename',
54 ;;    `old-dired-read-shell-command', `old-ess-complete-object-name',
55 ;;    `old-gud-gdb-complete-command', `old-read-shell-command',
56 ;;    `orig-read-file-name'.
57 ;;
58 ;;  Non-interactive functions defined here:
59 ;;
60 ;;    `icicle-activate-mark', `icicle-add-menu-item-to-cmd-history',
61 ;;    `icicle-bind-completion-keys', `icicle-bind-isearch-keys',
62 ;;    `icicle-bind-key-completion-keys-for-map-var',
63 ;;    `icicle-bind-key-completion-keys-in-keymaps-from',
64 ;;    `icicle-bind-other-keymap-keys',
65 ;;    `icicle-cancel-Help-redirection', `icicle-define-cycling-keys',
66 ;;    `icicle-define-icicle-maps', `icicle-define-minibuffer-maps',
67 ;;    `icicle-minibuffer-setup', `icicle-rebind-global',
68 ;;    `icicle-redefine-standard-functions',
69 ;;    `icicle-redefine-standard-options',
70 ;;    `icicle-redefine-std-completion-fns',
71 ;;    `icicle-restore-completion-keys',
72 ;;    `icicle-restore-other-keymap-keys',
73 ;;    `icicle-restore-region-face',
74 ;;    `icicle-restore-standard-functions',
75 ;;    `icicle-restore-standard-options',
76 ;;    `icicle-restore-std-completion-fns',
77 ;;    `icicle-run-icicle-post-command-hook',
78 ;;    `icicle-run-icicle-pre-command-hook',
79 ;;    `icicle-select-minibuffer-contents', `icicle-set-calling-cmd',
80 ;;    `icicle-S-iso-lefttab-to-S-TAB', `icicle-top-level-prep',
81 ;;    `icicle-unbind-isearch-keys',
82 ;;    `icicle-unbind-key-completion-keys-for-map-var',
83 ;;    `icicle-unbind-key-completion-keys-in-keymaps-from',
84 ;;    `icicle-undo-std-completion-faces', `icicle-unmap',
85 ;;    `icicle-update-ignored-extensions-regexp'.
86 ;;
87 ;;  User options defined here (in Custom group `Icicles'):
88 ;;
89 ;;    `icicle-mode', `icicle-mode-hook'.
90 ;;
91 ;;  Internal variables defined here:
92 ;;
93 ;;    `icicle-bookmark-menu-map', `icicle-custom-menu-map',
94 ;;    `icicle-describe-menu-map', `icicle-edit-menu-map',
95 ;;    `icicle-file-menu-map', `icicle-frames-menu-map',
96 ;;    `icicle-info-menu-map', `icicle-mode-map',
97 ;;    `icicle-options-menu-map', `icicle-search-menu-map',
98 ;;    `icicle-search-tags-menu-map'.
99 ;;
100 ;;  For descriptions of changes to this file, see `icicles-chg.el'.
101  
102 ;;(@> "Index")
103 ;;
104 ;;  If you have library `linkd.el' and Emacs 22 or later, load
105 ;;  `linkd.el' and turn on `linkd-mode' now.  It lets you easily
106 ;;  navigate around the sections of this doc.  Linkd mode will
107 ;;  highlight this Index, as well as the cross-references and section
108 ;;  headings throughout this file.  You can get `linkd.el' here:
109 ;;  http://dto.freeshell.org/notebook/Linkd.html.
110 ;;
111 ;;  (@> "User Options (alphabetical)")
112 ;;  (@> "Internal variables (alphabetical)")
113 ;;  (@> "Icicle mode command")
114 ;;  (@> "Other Icicles functions that define Icicle mode")
115  
116 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
117 ;;
118 ;; This program is free software; you can redistribute it and/or modify
119 ;; it under the terms of the GNU General Public License as published by
120 ;; the Free Software Foundation; either version 2, or (at your option)
121 ;; any later version.
122 ;;
123 ;; This program is distributed in the hope that it will be useful,
124 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
125 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
126 ;; GNU General Public License for more details.
127 ;;
128 ;; You should have received a copy of the GNU General Public License
129 ;; along with this program; see the file COPYING.  If not, write to the
130 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth
131 ;; ;; Floor, Boston, MA 02110-1301, USA.
132 ;;
133 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
134 ;;
135 ;;; Code:
136
137 ;;;###autoload (autoload 'icicle-mode "icicles" "Toggle Icicle mode." t nil)
138 ;;;###autoload (autoload 'icy-mode    "icicles" "Toggle Icicle mode." t nil)
139
140 (eval-when-compile (require 'cl)) ;; pushnew, case
141                                   ;; plus, for Emacs < 21: push, dolist
142
143 (require 'advice)
144   ;; ad-activate, ad-copy-advice-info, ad-deactivate, ad-disable-advice, ad-enable-advice,
145   ;; ad-find-some-advice, ad-get-arg, ad-is-active, ad-set-advice-info
146
147 (require 'icicles-opt)                  ; (This is required anyway by `icicles-var.el'.)
148   ;; icicle-buffer-configs, icicle-buffer-extras, icicle-change-region-background-flag,
149   ;; icicle-default-cycling-mode, icicle-incremental-completion-flag,
150   ;; icicle-default-value, icicle-kmacro-ring-max, icicle-minibuffer-setup-hook,
151   ;; icicle-modal-cycle-down-keys, icicle-modal-cycle-up-keys,
152   ;; icicle-functions-to-redefine, icicle-regexp-search-ring-max,
153   ;; icicle-region-background, icicle-search-ring-max, icicle-show-Completions-initially-flag,
154   ;; icicle-top-level-key-bindings, icicle-touche-pas-aux-menus-flag,
155   ;; icicle-word-completion-keys, icicle-yank-function
156 (require 'icicles-fn)                   ; (This is required anyway by `icicles-cmd1.el'.)
157   ;; assq-delete-all, icicle-completing-p, icicle-isearch-complete-past-string,
158   ;; icicle-toggle-icicle-mode-twice, icicle-unhighlight-lighter
159 (require 'icicles-var)                  ; (This is required anyway by `icicles-fn.el'.)
160   ;; icicle-candidate-action-fn, icicle-candidate-nb, icicle-cmd-calling-for-completion,
161   ;; icicle-completing-p, icicle-completion-candidates,
162   ;; icicle-current-completion-mode, icicle-default-directory, icicle-ignored-extensions,
163   ;; icicle-ignored-extensions-regexp, icicle-incremental-completion-p, icicle-initial-value,
164   ;; icicle-last-completion-candidate, icicle-last-completion-command, icicle-last-input,
165   ;; icicle-menu-map, icicle-pre-minibuffer-buffer, icicle-minor-mode-map-entry,
166   ;; icicle-saved-completion-candidates, icicle-saved-kmacro-ring-max,
167   ;; icicle-saved-regexp-search-ring-max, icicle-saved-region-background,
168   ;; icicle-saved-search-ring-max, icicle-search-current-overlay, icicle-search-overlays,
169   ;; icicle-search-refined-overlays
170 (require 'icicles-cmd1)                 ; (This is required anyway by `icicles-cmd2.el'.)
171   ;; icicle-add-buffer-candidate, icicle-add-buffer-config, icicle-bbdb-complete-name,
172   ;; icicle-customize-face, icicle-customize-face-other-window, icicle-dabbrev-completion,
173   ;; icicle-select-bookmarked-region
174 (require 'icicles-cmd2)
175   ;; icicle-imenu, icicle-occur, icicle-search, icicle-search-bookmark,
176   ;; icicle-search-bookmarks-together, icicle-search-buffer, icicle-search-file,
177   ;; icicle-search-w-isearch-string
178
179 ;; Use `condition-case' because if `mb-depth.el' can't be found, `mb-depth+.el' is not provided.
180 (when (>= emacs-major-version 22) (condition-case nil (require 'mb-depth+ nil t) (error nil)))
181   ;; (no error if not found): minibuffer-depth-indicate-mode
182
183 (require 'dired+ nil t) ;; (no error if not found):
184                         ;; diredp-menu-bar-operate-menu, diredp-menu-bar-subdir-menu
185 (require 'dired) ;; dired-mode-map
186 (require 'menu-bar+ nil t) ;; (no error if not found):
187   ;; menu-bar-apropos-menu, menu-bar-describe-menu, menu-bar-edit-menu,
188   ;; menu-bar-file-menu, menu-bar-frames-menu, menu-bar-options-menu, menu-bar-search-tags-menu
189
190 ;; `icicle-apropos-complete' is used here.  It is defined in `icicles-mcmd.el'.
191 ;; `icicle-file-name-input-p' is used here.  It is defined in `icicles-fn.el'.
192
193 ;;; Defvars to quiet byte-compiler:
194 (when (< emacs-major-version 22)
195   (defvar kmacro-ring-max)
196   (defvar minibuffer-local-filename-completion-map)
197   (defvar minibuffer-local-must-match-filename-map)
198   (defvar minibuffer-local-filename-must-match-map)
199   (defvar mouse-wheel-down-event)
200   (defvar mouse-wheel-up-event)
201   (defvar read-file-name-function))
202
203 (defvar Buffer-menu-mode-map)           ; In `buff-menu.el'.
204 (defvar comint-mode-map)                ; In `comint.el'.
205 (defvar crm-local-completion-map)       ; In `crm.el'.
206 (defvar crm-local-must-match-map)       ; In `crm.el'.
207 (defvar dired-mode-map)                 ; In `dired.el'.
208 (defvar gud-minibuffer-local-map)       ; In `gud.el'.
209 (defvar ibuffer-mode-map)               ; In `ibuffer.el'.
210 (defvar ibuffer-mode-operate-map)       ; In `ibuffer.el'.
211 (defvar icicle-crm-local-completion-map) ; In `icicles-fn.el' after load `crm.el'.
212 (defvar icicle-crm-local-must-match-map) ; In `icicles-fn.el' after load `crm.el'.
213 (defvar icicle-kmacro-ring-max)         ; In `icicles-opt.el' for Emacs 22+.
214 (defvar icicle-saved-kmacro-ring-max)   ; In `icicles-var.el' for Emacs 22+.
215 (defvar ielm-map)                       ; In `ielm.el'.
216 (defvar inferior-tcl-mode-map)          ; In `tcl.el'.
217 (defvar Info-mode-map)                  ; In `info.el'.
218 (defvar isearch-mode-map)               ; In `isearch.el'.
219 (defvar old-crm-local-completion-map)   ; In `icicles-fn.el' after load `crm.el'.
220 (defvar old-crm-local-must-match-map)   ; In `icicles-fn.el' after load `crm.el'.
221 (defvar savehist-minibuffer-history-variables) ; In `savehist.el'
222 (defvar shell-mode-map)                 ; In `shell.el'.
223 (defvar sh-mode-map)                    ; In `sh-script.el'.
224
225 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
226  
227 ;;(@* "User Options (alphabetical)")
228
229 ;;; User Options (alphabetical) --------------------------------------
230
231 ;; Emacs 20 only
232 (unless (fboundp 'define-minor-mode)
233   (defcustom icicle-mode nil
234     "*Toggle minibuffer input completion and cycling.
235 Setting this variable directly does not take effect;
236 use either \\[customize] or command `icy-mode' (aka `icicle-mode')."
237     :set (lambda (symbol value) (icicle-mode (if value 1 -1)))
238     :initialize 'custom-initialize-default
239     :type 'boolean :group 'Icicles-Miscellaneous :require 'icicles))
240
241 ;;;###autoload
242 (defcustom icicle-mode-hook nil
243   "*Functions run after entering and exiting Icicle mode."
244   :type 'hook :group 'Icicles-Miscellaneous)
245  
246 ;;(@* "Internal variables (alphabetical)")
247
248 ;;; Internal variables (alphabetical) --------------------------------
249
250 (defvar icicle-mode-map nil
251   "Keymap for Icicle mode.  These are top-level key bindings.
252 See also `icicle-define-minibuffer-maps' for minibuffer bindings and
253 bindings in `*Completions*'.")
254  
255 ;;(@* "Icicle mode command")
256
257 ;;; Icicle mode command ----------------------------------------------
258
259 ;; Main command.  Inspired from `icomplete-mode'.
260 ;;;###autoload
261 (defalias 'icy-mode 'icicle-mode)
262 (when (fboundp 'define-minor-mode)      ; Emacs 21+ ------------
263   (when (> emacs-major-version 22)
264     (defadvice call-interactively (after icicle-save-to-history disable activate)
265       "Save command to `icicle-interactive-history'."
266       ;; If command's input is not a parameterized (e.g. mouse) event, record it.
267       (let* ((fn   (ad-get-arg 0))
268              (int  (interactive-form fn)))
269         (when (and (symbolp fn) (consp int) (or (not (stringp (cadr int)))
270                                                 (string= (cadr int) "")
271                                                 (not (eq ?e (aref (cadr int) 0)))))
272           (pushnew (symbol-name fn) icicle-interactive-history))))
273     (when (boundp 'savehist-save-hook)  ; Do not save `icicle-interactive-history' (too large).
274       (add-hook 'savehist-save-hook
275                 (lambda () (setq savehist-minibuffer-history-variables
276                                  (delq 'icicle-interactive-history
277                                        savehist-minibuffer-history-variables))))))
278   (when (> emacs-major-version 21)
279     (defadvice describe-face (before icicle-respect-WYSIWYG activate)
280       "`read-face-name' respects `icicle-WYSIWYG-Completions-flag'.
281 If non-nil, then it does not use `completing-read-multiple' (which
282 cannot take advantage of WYSIWYG)."
283       (interactive (list (read-face-name "Describe face" "= `default' face"
284                                          (not icicle-WYSIWYG-Completions-flag))))))
285
286   (eval '(define-minor-mode icicle-mode
287           "Icicle mode: Toggle minibuffer input completion and cycling.
288 Non-nil prefix ARG turns mode on if ARG > 0, else turns it off.
289 Icicle mode is a global minor mode.  It binds keys in the minibuffer.
290
291 The following top-level commands are also available in Icicle mode.
292 In many cases there are also `other-window' versions.
293
294 `clear-option' (alias)                 - Set binary option(s) to nil
295 `icicle-add-buffer-candidate'          - Add always-candidate buffer
296 `icicle-add-buffer-config'             - To `icicle-buffer-configs'
297 `icicle-add-entry-to-saved-completion-set' - Add completion to a set
298 `icicle-add/update-saved-completion-set' - To
299                                         `icicle-saved-completion-sets'
300 `icicle-apply'                         - Apply function to alist items
301 `icicle-apropos'                       - `apropos', but shows matches
302 `icicle-apropos-command'               - Enhanced `apropos-command'
303 `icicle-apropos-variable'              - Enhanced `apropos-variable'
304 `icicle-apropos-zippy'                 - Show matching Zippy quotes
305 `icicle-bookmark'                      - Jump to a bookmark
306 `icicle-bookmark-all-tags'             - Jump to tagged bookmark
307 `icicle-bookmark-all-tags-regexp'      - Jump to tagged bookmark
308 `icicle-bookmark-bookmark-list'        - Jump to a bookmark list
309 `icicle-bookmark-desktop'              - Jump to a desktop bookmark
310 `icicle-bookmark-dired'                - Jump to a Dired bookmark
311 `icicle-bookmark-file'                 - Jump to a file bookmark
312 `icicle-bookmark-file-all-tags'        - Jump to tagged file bookmark
313 `icicle-bookmark-file-all-tags-regexp'
314 `icicle-bookmark-file-some-tags'
315 `icicle-bookmark-file-some-tags-regexp'
316 `icicle-bookmark-file-this-dir-all-tags'
317 `icicle-bookmark-file-this-dir-all-tags-regexp'
318 `icicle-bookmark-file-this-dir-some-tags'
319 `icicle-bookmark-file-this-dir-some-tags-regexp'
320 `icicle-bookmark-gnus'                 - Jump to a Gnus bookmark
321 `icicle-bookmark-info'                 - Jump to an Info bookmark
322 `icicle-bookmark-local-file'           - Jump to local-file bookmark
323 `icicle-bookmark-man'                  - Jump to a `man'-page bookmark
324 `icicle-bookmark-non-file'             - Jump to a buffer bookmark
325 `icicle-bookmark-region'               - Jump to a region bookmark
326 `icicle-bookmark-remote-file'          - Jump to a remote file
327 `icicle-bookmark-some-tags'            - Jump to tagged bookmark
328 `icicle-bookmark-some-tags-regexp'     - Jump to tagged bookmark
329 `icicle-bookmark-specific-buffers'     - Jump to a bookmarked buffer
330 `icicle-bookmark-specific-files'       - Jump to a bookmarked file
331 `icicle-bookmark-this-buffer'          - Jump to bookmark for this buf
332 `icicle-bookmark-url'                  - Jump to a URL bookmark
333 `icicle-bookmark-w3m'                  - Jump to a W3M (URL) bookmark
334 `icicle-buffer'                        - Switch to buffer
335 `icicle-buffer-config'                 - Pick `icicle-buffer' options
336 `icicle-buffer-list'                   - Choose a list of buffer names
337 `icicle-change-alternative-sort-order' - Choose an alternative sort
338 `icicle-change-sort-order'             - Choose a sort order
339 `icicle-clear-current-history'         - Clear current history entries
340 `icicle-clear-history'                 - Clear entries from a history
341 `icicle-color-theme'                   - Change color theme
342 `icicle-comint-command'                - Reuse shell etc. command
343 `icicle-comint-dynamic-complete'       - Text completion in shell
344 `icicle-comint-search'                 - Reuse shell etc. command
345 `icicle-command-abbrev'                - Multi-command `M-x' + abbrevs
346 `icicle-compilation-search'            - `icicle-search' and show hits
347 `icicle-complete-keys'                 - Complete keys
348 `icicle-complete-thesaurus-entry'      - Complete word using thesaurus
349 `icicle-completing-yank'               - `yank' using completion
350 `icicle-customize-face'                - Multi-`customize-face'
351 `icicle-customize-icicles-group'       - Customize options and faces
352 `icicle-delete-file'                   - Delete file/directory
353 `icicle-delete-window'                 - Delete window (`C-u': buffer)
354 `icicle-delete-windows'                - Delete all windows for buffer
355 `icicle-dired'                         - Multi-command Dired
356 `icicle-doc'                           - Show doc for fn, var, or face
357 `icicle-doremi-candidate-width-factor+' - +/- candidate column width
358 `icicle-doremi-increment-max-candidates+' - +/- max number candidates
359 `icicle-doremi-increment-swank-prefix-length+' - +/- swank prefix
360 `icicle-doremi-increment-swank-timeout+' - +/- swank completion msec
361 `icicle-doremi-increment-variable+'    - Increment var using Do Re Mi
362 `icicle-doremi-inter-candidates-min-spaces+' - +/- candidate spacing
363 `icicle-doremi-zoom-Completions+'      - +/- `*Completions*' text size
364 `icicle-execute-extended-command'      - Multi-command `M-x'
365 `icicle-execute-named-keyboard-macro'  - Execute named keyboard macro
366 `icicle-face-list'                     - Choose a list of face names
367 `icicle-file-list'                     - Choose a list of file names
368 `icicle-file'                          - Visit file/directory
369 `icicle-find-file'                     -       same: relative only
370 `icicle-find-file-absolute'            -       same: absolute only
371 `icicle-find-file-all-tags'            - Visit tagged file
372 `icicle-find-file-all-tags-regexp'
373 `icicle-find-file-some-tags'
374 `icicle-find-file-some-tags-regexp'
375 `icicle-find-file-in-tags-table'       - File in Emacs tags table
376 `icicle-find-file-tagged'              - Visit tagged file
377 `icicle-find-first-tag'                - Visit definition with tag
378 `icicle-find-tag'                      - Visit definition with tag
379 `icicle-font'                          - Change font of frame
380 `icicle-frame-bg'                      - Change background of frame
381 `icicle-frame-fg'                      - Change foreground of frame
382 `icicle-fundoc'                        - Show function description
383 `icicle-goto-global-marker'            - Go to a global marker
384 `icicle-goto-marker'                   - Go to a marker in this buffer
385 `icicle-imenu*'                        - Navigate among Imenu entries
386 `icicle-increment-option'              - Increment numeric option
387 `icicle-increment-variable'            - Increment numeric variable
388 `icicle-Info-goto-node'                - Multi-cmd `Info-goto-node'
389 `icicle-Info-index'                    - Multi-command `Info-index'
390 `icicle-Info-menu'                     - Multi-command `Info-menu'
391 `icicle-Info-virtual-book'             - Open a virtual Info book
392 `icicle-insert-buffer'                 - Multi-command `insert-buffer'
393 `icicle-insert-thesaurus-entry'        - Insert thesaurus entry(s)
394 `icicle-keyword-list'                  - Choose a list of keywords
395 `icicle-kill-buffer'                   - Kill buffer
396 `icicle-kmacro'                        - Execute a keyboard macro
397 `icicle-locate-file'                   - Visit file(s) in a directory
398 `icicle-minibuffer-help'               - Show Icicles minibuffer help
399 `icicle-mode' or `icy-mode'            - Toggle Icicle mode
400 `icicle-next-S-TAB-completion-method'  - Next S-TAB completion method
401 `icicle-next-TAB-completion-method'    - Next TAB completion method
402 `icicle-occur'                         - Incremental `occur'
403 `icicle-other-window-or-frame'         - Other window/frame or select
404 `icicle-plist'                         - Show symbols, property lists
405 `icicle-recent-file'                   - Open recently used file(s)
406 `icicle-recompute-shell-command-candidates' - Update from search path
407 `icicle-remove-buffer-candidate'       - Remove always-candidate buf
408 `icicle-remove-buffer-config'          - From `icicle-buffer-configs'
409 `icicle-remove-entry-from-saved-completion-set' - From a saved set
410 `icicle-remove-file-from-recentf-list' - Remove from recent files list
411 `icicle-remove-saved-completion-set'   - From
412                                         `icicle-saved-completion-sets'
413 `icicle-reset-option-to-nil'           - Set binary option(s) to nil
414 `icicle-save-string-to-variable'       - Save text for use with `C-='
415 `icicle-search'                        - Search with regexps & cycling
416 `icicle-search-all-tags-bookmark'      - Search tagged bookmarks 
417 `icicle-search-all-tags-regexp-bookmark'
418 `icicle-search-bookmark'               - Search bookmarks separately
419 `icicle-search-bookmark-list-bookmark' - Search bookmark lists
420 `icicle-search-bookmarks-together'     - Search bookmarks together
421 `icicle-search-char-property'          - Search for overlay/text props
422 `icicle-search-dired-bookmark'         - Search Dired bookmarks
423 `icicle-search-dired-marked'           - Search marked files in Dired
424 `icicle-search-file'                   - Search multiple files
425 `icicle-search-file-bookmark'          - Search bookmarked files
426 `icicle-search-gnus-bookmark'          - Search bookmarked Gnus msgs
427 `icicle-search-ibuffer-marked'         - Search marked bufs in Ibuffer
428 `icicle-search-info-bookmark'          - Search bookmarked Info nodes
429 `icicle-search-keywords'               - Search with regexp keywords
430 `icicle-search-local-file-bookmark'    - Search bookmarked local files
431 `icicle-search-man-bookmark'           - Search bookmarked `man' pages
432 `icicle-search-non-file-bookmark'      - Search bookmarked buffers
433 `icicle-search-overlay-property'       - Search for overlay properties
434 `icicle-search-pages'                  - Search Emacs pages
435 `icicle-search-paragraphs'             - Search Emacs paragraphs
436 `icicle-search-region-bookmark'        - Search bookmarked regions
437 `icicle-search-remote-file-bookmark'   - Search remote bookmarks
438 `icicle-search-sentences'              - Search sentences as contexts
439 `icicle-search-some-tags-bookmark'     - Search tagged bookmarks 
440 `icicle-search-some-tags-regexp-bookmark'
441 `icicle-search-text-property'          - Search for faces etc.
442 `icicle-search-url-bookmark'           - Search bookmarked URLs
443 `icicle-search-word'                   - Whole-word search
444 `icicle-select-bookmarked-region'      - Select bookmarked regions
445 `icicle-select-frame'                  - Select a frame by name
446 `icicle-select-window'                 - Select window by buffer name
447 `icicle-send-bug-report'               - Send Icicles bug report
448 `icicle-set-option-to-t'               - Set binary option(s) to t
449 `icicle-tag-a-file'                    - Tag a file a la delicious
450 `icicle-toggle-~-for-home-dir'         - Toggle using `~' for $HOME
451 `icicle-toggle-alternative-sorting'    - Swap alternative sort
452 `icicle-toggle-angle-brackets'         - Toggle using angle brackets
453 `icicle-toggle-C-for-actions'          - Toggle using `C-' for actions
454 `icicle-toggle-case-sensitivity'       - Toggle case sensitivity
455 `icicle-toggle-dot'                    - Toggle `.' matching newlines
456 `icicle-toggle-expand-to-common-match' - Toggle input ECM expansion
457 `icicle-toggle-hiding-common-match'    - Toggle match, `*Completions*'
458 `icicle-toggle-hiding-non-matching-lines'- Toggle no-match lines
459 `icicle-toggle-highlight-all-current'  - Toggle max search highlight
460 `icicle-toggle-highlight-historical-candidates'
461                                        - Toggle past-input highlight
462 `icicle-toggle-highlight-saved-candidates'
463                                        - Toggle highlighting saved
464 `icicle-toggle-ignored-extensions'     - Toggle ignored files
465 `icicle-toggle-ignored-space-prefix'   - Toggle ignoring space prefix
466 `icicle-toggle-ignoring-comments'      - Toggle ignoring comments
467 `icicle-toggle-incremental-completion' - Toggle apropos icompletion
468 `icicle-toggle-option'                 - Toggle binary user option
469 `icicle-toggle-proxy-candidates'       - Toggle proxy candidates
470 `icicle-toggle-regexp-quote'           - Toggle regexp escaping
471 `icicle-toggle-search-cleanup'         - Toggle search highlighting
472 `icicle-toggle-search-complementing-domain' - Toggle complement search
473 `icicle-toggle-search-replace-common-match' - Toggle ECM replacement
474 `icicle-toggle-search-replace-whole'   - Toggle replacing whole hit
475 `icicle-toggle-search-whole-word'      - Toggle whole-word searching
476 `icicle-toggle-show-multi-completion'  - Toggle multi-completions
477 `icicle-toggle-sorting'                - Toggle sorting of completions
478 `icicle-toggle-transforming'           - Toggle duplicate removal
479 `icicle-toggle-WYSIWYG-Completions'   - Toggle WYSIWYG `*Completions*'
480 `icicle-untag-a-file'                  - Remove some tags from a file
481 `icicle-vardoc'                        - Show variable description
482 `icicle-where-is'                      - `where-is' multi-command
483 `icicle-yank-maybe-completing'         - `yank' maybe using completion
484 `toggle' (alias)                       - Toggle binary user option
485
486 For more information, use `\\<minibuffer-local-completion-map>\\[icicle-minibuffer-help]' \
487 when the minibuffer is active.
488
489 Note: Depending on your platform, if you use Icicles in a text
490 terminal (that is, without a window system/manager), then you might
491 need to change some of the key bindings, if some of the default
492 bindings are not available to you."
493           :global t :group 'Icicles-Miscellaneous :lighter " Icy" :init-value nil
494           (cond (icicle-mode
495                  ;; (when (interactive-p)
496                  ;;   (unless (or window-system (and (fboundp 'daemonp) (daemonp)))
497                  ;;     (with-output-to-temp-buffer "*Attention*"
498                  ;;       (princ "You are using Icicles in a text terminal (no window ")
499                  ;;       (princ "system/manager).\n\nIcicles makes use of many keys that are ")
500                  ;;      (princ "unavailable when running\nEmacs in a text terminal.  You will ")
501                  ;;       (princ "want to rebind those keys.\n")
502                  ;;       (princ "See the Icicles doc, section Key Bindings.\n"))
503                  ;;  (message "Icicles uses keys that might not be suitable for a text terminal")
504                  ;;     (sit-for 5)))
505                  (icicle-define-icicle-maps)
506                  (icicle-bind-other-keymap-keys)
507                  (add-hook 'minibuffer-setup-hook       'icicle-minibuffer-setup)
508                  (add-hook 'minibuffer-exit-hook        'icicle-cancel-Help-redirection)
509                  (add-hook 'minibuffer-exit-hook        'icicle-restore-region-face)
510                  (add-hook 'minibuffer-exit-hook        'icicle-unhighlight-lighter)
511                  (add-hook 'icicle-post-command-hook    'icicle-activate-mark 'append)
512                  (add-hook 'completion-setup-hook       'icicle-set-calling-cmd 'append)
513                  (when icicle-customize-save-flag
514                    (add-hook 'kill-emacs-hook           'icicle-command-abbrev-save))
515                  (add-hook 'comint-mode-hook            'icicle-comint-hook-fn)
516                  (add-hook 'compilation-mode-hook       'icicle-compilation-hook-fn)
517                  (add-hook 'compilation-minor-mode-hook 'icicle-compilation-hook-fn)
518                  ;; $$$$$$ Do this only in `icicle-display-candidates-in-Completions' now.
519                  ;; $$$$$$ (add-hook 'temp-buffer-show-hook       'icicle-fit-completions-window)
520                  (icicle-undo-std-completion-faces)
521                  (icicle-redefine-std-completion-fns)
522                  (icicle-redefine-standard-functions)
523                  (icicle-redefine-standard-options)
524                  (when (ad-find-some-advice 'describe-face 'before 'icicle-respect-WYSIWYG)
525                    (ad-enable-advice 'describe-face 'before 'icicle-respect-WYSIWYG))
526                  (when (fboundp 'minibuffer-depth-indicate-mode) ; In `mb-depth(+).el'
527                    (minibuffer-depth-indicate-mode 99))
528                  (if icicle-menu-items-to-history-flag
529                      (add-hook 'pre-command-hook 'icicle-add-menu-item-to-cmd-history)
530                    (remove-hook 'pre-command-hook 'icicle-add-menu-item-to-cmd-history))
531                  (when (> emacs-major-version 22)
532                    (when icicle-populate-interactive-history-flag
533                      (ad-enable-advice 'call-interactively 'after 'icicle-save-to-history))
534                    (ad-activate 'call-interactively))
535                  (dolist (fn  icicle-inhibit-advice-functions)
536                    (when (and (fboundp fn) (ad-is-active fn))
537                      (push (cons fn (ad-copy-advice-info fn)) icicle-advice-info-list)
538                      (ad-deactivate fn))))
539                 (t
540                  (makunbound 'icicle-mode-map)
541                  (icicle-restore-other-keymap-keys)
542                  (remove-hook 'minibuffer-setup-hook    'icicle-minibuffer-setup)
543                  (remove-hook 'minibuffer-exit-hook     'icicle-cancel-Help-redirection)
544                  (remove-hook 'minibuffer-exit-hook     'icicle-restore-region-face)
545                  (remove-hook 'icicle-post-command-hook 'icicle-activate-mark)
546                  ;; The pre- and post-command hooks are local to the minibuffer,
547                  ;; So they are added in `icicle-minibuffer-setup', not here.
548                  ;; Nevertheless, they are removed here when Icicle mode is exited.
549                  (remove-hook 'pre-command-hook         'icicle-top-level-prep)
550                  (remove-hook 'pre-command-hook         'icicle-run-icicle-pre-command-hook t)
551                  (remove-hook 'post-command-hook        'icicle-run-icicle-post-command-hook t)
552                  (remove-hook 'completion-setup-hook    'icicle-set-calling-cmd)
553                  (remove-hook 'kill-emacs-hook          'icicle-command-abbrev-save)
554                  (remove-hook 'comint-mode-hook         'icicle-comint-hook-fn)
555                  (remove-hook 'compilation-mode-hook    'icicle-compilation-hook-fn)
556                  (remove-hook 'compilation-minor-mode-hook 'icicle-compilation-hook-fn)
557                  ;; $$$$$$ Do this only in `icicle-display-candidates-in-Completions' now.
558                  ;; $$$$$$ (remove-hook 'temp-buffer-show-hook    'icicle-fit-completions-window)
559
560                  ;; $$ Should restore standard completion faces here.
561                  (icicle-restore-std-completion-fns)
562                  (icicle-restore-standard-functions)
563                  (icicle-restore-standard-options)
564                  (when (ad-find-some-advice 'describe-face 'before 'icicle-respect-WYSIWYG)
565                    (ad-disable-advice 'describe-face 'before 'icicle-respect-WYSIWYG))
566                  (when (fboundp 'minibuffer-depth-indicate-mode)
567                    (minibuffer-depth-indicate-mode -99))
568                  (remove-hook 'pre-command-hook 'icicle-add-menu-item-to-cmd-history)
569                  (when (> emacs-major-version 22)
570                    (ad-disable-advice 'call-interactively 'after 'icicle-save-to-history)
571                    (ad-activate 'call-interactively))
572                  (dolist (fn  icicle-inhibit-advice-functions)
573                    (let ((info  (memq fn icicle-advice-info-list)))
574                      (when (and (fboundp fn) info)
575                        (ad-set-advice-info fn info)
576                        (when (ad-is-active fn) (ad-activate fn)))))))
577           (unless (eq icicle-guess-commands-in-path 'load)
578             (setq icicle-shell-command-candidates-cache  ())) ; Reset - toggle Icy to update.
579           (message "Turning %s Icicle mode..." (if icicle-mode "ON" "OFF"))
580           (icicle-define-minibuffer-maps icicle-mode)
581           (run-hooks 'icicle-mode-hook)
582           (message "Turning %s Icicle mode...done" (if icicle-mode "ON" "OFF")))))
583
584 (unless (fboundp 'define-minor-mode)    ; Emacs 20 ------------
585   (defun icicle-mode (&optional arg)
586     "Icicle mode: Toggle minibuffer input completion and cycling.
587 Non-nil prefix ARG turns mode on if ARG > 0, else turns it off.
588 Icicle mode is a global minor mode.  It binds keys in the minibuffer.
589
590 The following top-level commands are also available in Icicle mode.
591 In many cases there are also `other-window' versions.
592
593 `clear-option' (alias)                 - Set binary option(s) to nil
594 `icicle-add-buffer-candidate'          - Add always-candidate buffer
595 `icicle-add-buffer-config'             - To `icicle-buffer-configs'
596 `icicle-add-entry-to-saved-completion-set' - Add completion to a set
597 `icicle-add/update-saved-completion-set' - To
598                                         `icicle-saved-completion-sets'
599 `icicle-apply'                         - Apply function to alist items
600 `icicle-apropos'                       - `apropos', but shows matches
601 `icicle-apropos-command'               - Enhanced `apropos-command'
602 `icicle-apropos-variable'              - Enhanced `apropos-variable'
603 `icicle-apropos-zippy'                 - Show matching Zippy quotes
604 `icicle-bookmark'                      - Jump to a bookmark
605 `icicle-bookmark-all-tags'             - Jump to tagged bookmark
606 `icicle-bookmark-all-tags-regexp'      - Jump to tagged bookmark
607 `icicle-bookmark-bookmark-list'        - Jump to a bookmark list
608 `icicle-bookmark-desktop'              - Jump to a desktop bookmark
609 `icicle-bookmark-dired'                - Jump to a Dired bookmark
610 `icicle-bookmark-file'                 - Jump to a file bookmark
611 `icicle-bookmark-file-all-tags'        - Jump to tagged file bookmark
612 `icicle-bookmark-file-all-tags-regexp'
613 `icicle-bookmark-file-some-tags'
614 `icicle-bookmark-file-some-tags-regexp'
615 `icicle-bookmark-file-this-dir-all-tags'
616 `icicle-bookmark-file-this-dir-all-tags-regexp'
617 `icicle-bookmark-file-this-dir-some-tags'
618 `icicle-bookmark-file-this-dir-some-tags-regexp'
619 `icicle-bookmark-gnus'                 - Jump to a Gnus bookmark
620 `icicle-bookmark-info'                 - Jump to an Info bookmark
621 `icicle-bookmark-local-file'           - Jump to local-file bookmark
622 `icicle-bookmark-man'                  - Jump to a `man'-page bookmark
623 `icicle-bookmark-non-file'             - Jump to a buffer bookmark
624 `icicle-bookmark-region'               - Jump to a region bookmark
625 `icicle-bookmark-remote-file'          - Jump to a remote file
626 `icicle-bookmark-some-tags'            - Jump to tagged bookmark
627 `icicle-bookmark-some-tags-regexp'     - Jump to tagged bookmark
628 `icicle-bookmark-specific-buffers'     - Jump to a bookmarked buffer
629 `icicle-bookmark-specific-files'       - Jump to a bookmarked file
630 `icicle-bookmark-this-buffer'          - Jump to bookmark for this buf
631 `icicle-bookmark-url'                  - Jump to a URL bookmark
632 `icicle-bookmark-w3m'                  - Jump to a W3M (URL) bookmark
633 `icicle-buffer'                        - Switch to buffer
634 `icicle-buffer-config'                 - Pick `icicle-buffer' options
635 `icicle-buffer-list'                   - Choose a list of buffer names
636 `icicle-change-alternative-sort-order' - Choose an alternative sort
637 `icicle-change-sort-order'             - Choose a sort order
638 `icicle-clear-current-history'         - Clear current history entries
639 `icicle-clear-history'                 - Clear entries from a history
640 `icicle-color-theme'                   - Change color theme
641 `icicle-comint-command'                - Reuse shell etc. command
642 `icicle-comint-dynamic-complete'       - Text completion in shell
643 `icicle-comint-search'                 - Reuse shell etc. command
644 `icicle-command-abbrev'                - Multi-command `M-x' + abbrevs
645 `icicle-compilation-search'            - `icicle-search' and show hits
646 `icicle-complete-thesaurus-entry'      - Complete word using thesaurus
647 `icicle-completing-yank'               - `yank' using completion
648 `icicle-customize-face'                - Multi-`customize-face'
649 `icicle-customize-icicles-group'       - Customize options and faces
650 `icicle-delete-file'                   - Delete file/directory
651 `icicle-delete-window'                 - Delete window (`C-u': buffer)
652 `icicle-delete-windows'                - Delete all windows for buffer
653 `icicle-dired'                         - Multi-command Dired
654 `icicle-doc'                           - Show doc for fn, var, or face
655 `icicle-doremi-candidate-width-factor+' - +/- candidate column width
656 `icicle-doremi-increment-max-candidates+' - +/- max number candidates
657 `icicle-doremi-increment-swank-prefix-length+' - +/- swank prefix
658 `icicle-doremi-increment-swank-timeout+' - +/- swank completion msec
659 `icicle-doremi-increment-variable+'    - Increment var using Do Re Mi
660 `icicle-doremi-inter-candidates-min-spaces+' - +/- candidate spacing
661 `icicle-doremi-zoom-Completions+'      - +/- `*Completions*' text size
662 `icicle-execute-extended-command'      - Multi-command `M-x'
663 `icicle-execute-named-keyboard-macro'  - Execute named keyboard macro
664 `icicle-face-list'                     - Choose a list of face names
665 `icicle-file-list'                     - Choose a list of file names
666 `icicle-file'                          - Visit file/directory
667 `icicle-find-file'                     -       same: relative only
668 `icicle-find-file-absolute'            -       same: absolute only
669 `icicle-find-file-all-tags'            - Visit tagged file
670 `icicle-find-file-all-tags-regexp'
671 `icicle-find-file-some-tags'
672 `icicle-find-file-some-tags-regexp'
673 `icicle-find-file-in-tags-table'       - File in Emacs tags table
674 `icicle-find-file-tagged'              - Visit tagged file
675 `icicle-find-first-tag'                - Visit definition with tag
676 `icicle-find-tag'                      - Visit definition with tag
677 `icicle-font'                          - Change font of frame
678 `icicle-frame-bg'                      - Change background of frame
679 `icicle-frame-fg'                      - Change foreground of frame
680 `icicle-fundoc'                        - Show function description
681 `icicle-goto-global-marker'            - Go to a global marker
682 `icicle-goto-marker'                   - Go to a marker in this buffer
683 `icicle-imenu*'                        - Navigate among Imenu entries
684 `icicle-increment-option'              - Increment numeric option
685 `icicle-increment-variable'            - Increment numeric variable
686 `icicle-Info-goto-node'                - Multi-cmd `Info-goto-node'
687 `icicle-Info-index'                    - Multi-command `Info-index'
688 `icicle-Info-menu'                     - Multi-command `Info-menu'
689 `icicle-insert-buffer'                 - Multi-command `insert-buffer'
690 `icicle-insert-thesaurus-entry'        - Insert thesaurus entry(s)
691 `icicle-keyword-list'                  - Choose a list of keywords
692 `icicle-kill-buffer'                   - Kill buffer
693 `icicle-locate-file'                   - Visit file(s) in a directory
694 `icicle-minibuffer-help'               - Show Icicles minibuffer help
695 `icicle-mode' or `icy-mode'            - Toggle Icicle mode
696 `icicle-next-S-TAB-completion-method'  - Next S-TAB completion method
697 `icicle-next-TAB-completion-method'    - Next TAB completion method
698 `icicle-occur'                         - Incremental `occur'
699 `icicle-other-window-or-frame'         - Other window/frame or select
700 `icicle-plist'                         - Show symbols, property lists
701 `icicle-recent-file'                   - Open recently used file(s)
702 `icicle-recompute-shell-command-candidates' - Update from search path
703 `icicle-remove-buffer-candidate'       - Remove always-candidate buf
704 `icicle-remove-buffer-config'          - From `icicle-buffer-configs'
705 `icicle-remove-entry-from-saved-completion-set' - From a saved set
706 `icicle-remove-file-from-recentf-list' - Remove from recent files list
707 `icicle-remove-saved-completion-set'   - From
708                                         `icicle-saved-completion-sets'
709 `icicle-reset-option-to-nil'           - Set binary option(s) to nil
710 `icicle-save-string-to-variable'       - Save text for use with `C-='
711 `icicle-search'                        - Search with regexps & cycling
712 `icicle-search-bookmark'               - Search bookmarks separately
713 `icicle-search-all-tags-bookmark'      - Search tagged bookmarks 
714 `icicle-search-all-tags-regexp-bookmark'
715 `icicle-search-bookmark-list-bookmark' - Search bookmark lists
716 `icicle-search-bookmarks-together'     - Search bookmarks together
717 `icicle-search-char-property'          - Search for overlay/text props
718 `icicle-search-dired-bookmark'         - Search Dired bookmarks
719 `icicle-search-dired-marked'           - Search marked files in Dired
720 `icicle-search-file'                   - Search multiple files
721 `icicle-search-file-bookmark'          - Search bookmarked files
722 `icicle-search-gnus-bookmark'          - Search bookmarked Gnus msgs
723 `icicle-search-ibuffer-marked'         - Search marked bufs in Ibuffer
724 `icicle-search-info-bookmark'          - Search bookmarked Info nodes
725 `icicle-search-keywords'               - Search with regexp keywords
726 `icicle-search-local-file-bookmark'    - Search bookmarked local files
727 `icicle-search-man-bookmark'           - Search bookmarked `man' pages
728 `icicle-search-non-file-bookmark'      - Search bookmarked buffers
729 `icicle-search-overlay-property'       - Search for overlay properties
730 `icicle-search-pages'                  - Search Emacs pages
731 `icicle-search-paragraphs'             - Search Emacs paragraphs
732 `icicle-search-region-bookmark'        - Search bookmarked regions
733 `icicle-search-remote-file-bookmark'   - Search remote bookmarks
734 `icicle-search-sentences'              - Search sentences as contexts
735 `icicle-search-some-tags-bookmark'     - Search tagged bookmarks 
736 `icicle-search-some-tags-regexp-bookmark'
737 `icicle-search-text-property'          - Search for faces etc.
738 `icicle-search-url-bookmark'           - Search bookmarked URLs
739 `icicle-search-word'                   - Whole-word search
740 `icicle-select-bookmarked-region'      - Select bookmarked regions
741 `icicle-select-frame'                  - Select a frame by name
742 `icicle-select-window'                 - Select window by buffer name
743 `icicle-send-bug-report'               - Send Icicles bug report
744 `icicle-set-option-to-t'               - Set binary option(s) to t
745 `icicle-tag-a-file'                    - Tag a file a la delicious
746 `icicle-toggle-~-for-home-dir'         - Toggle using `~' for $HOME
747 `icicle-toggle-alternative-sorting'    - Swap alternative sort
748 `icicle-toggle-angle-brackets'         - Toggle using angle brackets
749 `icicle-toggle-C-for-actions'          - Toggle using `C-' for actions
750 `icicle-toggle-case-sensitivity'       - Toggle case sensitivity
751 `icicle-toggle-dot'                    - Toggle `.' matching newlines
752 `icicle-toggle-expand-to-common-match' - Toggle input ECM expansion
753 `icicle-toggle-hiding-common-match'    - Toggle match, `*Completions*'
754 `icicle-toggle-hiding-non-matching-lines'- Toggle no-match lines
755 `icicle-toggle-highlight-all-current'  - Toggle max search highlight
756 `icicle-toggle-highlight-historical-candidates'
757                                        - Toggle past-input highlight
758 `icicle-toggle-highlight-saved-candidates'
759                                        - Toggle highlighting saved
760 `icicle-toggle-ignored-extensions'     - Toggle ignored files
761 `icicle-toggle-ignored-space-prefix'   - Toggle ignoring space prefix
762 `icicle-toggle-ignoring-comments'      - Toggle ignoring comments
763 `icicle-toggle-incremental-completion' - Toggle apropos icompletion
764 `icicle-toggle-option'                 - Toggle binary user option
765 `icicle-toggle-proxy-candidates'       - Toggle proxy candidates
766 `icicle-toggle-regexp-quote'           - Toggle regexp escaping
767 `icicle-toggle-search-cleanup'         - Toggle search highlighting
768 `icicle-toggle-search-complementing-domain' - Toggle complement search
769 `icicle-toggle-search-replace-common-match' - Toggle ECM replacement
770 `icicle-toggle-search-replace-whole'   - Toggle replacing whole hit
771 `icicle-toggle-search-whole-word'      - Toggle whole-word searching
772 `icicle-toggle-show-multi-completion'  - Toggle multi-completions
773 `icicle-toggle-sorting'                - Toggle sorting of completions
774 `icicle-toggle-transforming'           - Toggle duplicate removal
775 `icicle-toggle-WYSIWYG-Completions'   - Toggle WYSIWYG `*Completions*'
776 `icicle-untag-a-file'                  - Remove some tags from a file
777 `icicle-vardoc'                        - Show variable description
778 `icicle-where-is'                      - `where-is' multi-command
779 `icicle-yank-maybe-completing'         - `yank' maybe using completion
780 `toggle' (alias)                       - Toggle binary user option
781
782 For more information, use `\\<minibuffer-local-completion-map>\\[icicle-minibuffer-help]' \
783 when the minibuffer is active.
784
785 Note: Depending on your platform, if you use Icicles in a text
786 terminal (that is, without a window system/manager), then you might
787 need to change some of the key bindings, if some of the default
788 bindings are not available to you."
789     (interactive "P")
790     (setq icicle-mode  (if arg (> (prefix-numeric-value arg) 0) (not icicle-mode)))
791     (icicle-define-minibuffer-maps icicle-mode)
792     (cond (icicle-mode
793            ;; (when (interactive-p)
794            ;;   (unless (or window-system (and (fboundp 'daemonp) (daemonp)))
795            ;;     (with-output-to-temp-buffer "*Attention*"
796            ;;       (princ "You are using Icicles in a text terminal (no window ")
797            ;;       (princ "system/manager).\n\nIcicles makes use of many keys that are ")
798            ;;       (princ "unavailable when running\nEmacs in a text terminal.  You will ")
799            ;;       (princ "want to rebind those keys.\n")
800            ;;       (princ "See the Icicles doc, section Key Bindings.\n"))
801            ;;     (message "Icicles uses keys that might not be suitable for a text terminal")
802            ;;     (sit-for 5)))
803            (icicle-define-icicle-maps)
804            (icicle-bind-other-keymap-keys)
805            ;; This is not really necessary after the first time - no great loss.
806            (add-hook 'minibuffer-setup-hook       'icicle-minibuffer-setup)
807            (add-hook 'minibuffer-exit-hook        'icicle-cancel-Help-redirection)
808            (add-hook 'minibuffer-exit-hook        'icicle-restore-region-face)
809            (add-hook 'minibuffer-exit-hook        'icicle-unhighlight-lighter)
810            (add-hook 'icicle-post-command-hook    'icicle-activate-mark 'append)
811            (add-hook 'completion-setup-hook       'icicle-set-calling-cmd 'append)
812            (when icicle-customize-save-flag
813              (add-hook 'kill-emacs-hook           'icicle-command-abbrev-save))
814            (add-hook 'comint-mode-hook            'icicle-comint-hook-fn)
815            (add-hook 'compilation-mode-hook       'icicle-compilation-hook-fn)
816            (add-hook 'compilation-minor-mode-hook 'icicle-compilation-hook-fn)
817            ;; $$$$$$ Do this only in `icicle-display-candidates-in-Completions' now.
818            ;; $$$$$$ (add-hook 'temp-buffer-show-hook       'icicle-fit-completions-window)
819            (icicle-redefine-std-completion-fns)
820            (icicle-redefine-standard-functions)
821            (icicle-redefine-standard-options)
822            (if icicle-menu-items-to-history-flag
823                (add-hook 'pre-command-hook 'icicle-add-menu-item-to-cmd-history)
824              (remove-hook 'pre-command-hook 'icicle-add-menu-item-to-cmd-history))
825            (dolist (fn  icicle-inhibit-advice-functions)
826              (when (and (fboundp fn) (ad-is-active fn))
827                (push (cons fn (ad-copy-advice-info fn)) icicle-advice-info-list)
828                (ad-deactivate fn)))
829            (run-hooks 'icicle-mode-hook)
830            (message "Icicle mode is now ON"))
831           (t
832            (makunbound 'icicle-mode-map)
833            (icicle-restore-other-keymap-keys)
834            (remove-hook 'minibuffer-setup-hook    'icicle-minibuffer-setup)
835            (remove-hook 'minibuffer-exit-hook     'icicle-cancel-Help-redirection)
836            (remove-hook 'minibuffer-exit-hook     'icicle-restore-region-face)
837            (remove-hook 'icicle-post-command-hook 'icicle-activate-mark)
838            ;; The pre- and post-command hooks are local to the minibuffer,
839            ;; So they are added in `icicle-minibuffer-setup', not here.
840            ;; Nevertheless, they are removed here when Icicle mode is exited.
841            (remove-hook 'pre-command-hook         'icicle-top-level-prep)
842            (remove-hook 'pre-command-hook         'icicle-run-icicle-pre-command-hook t)
843            (remove-hook 'post-command-hook        'icicle-run-icicle-post-command-hook t)
844            (remove-hook 'completion-setup-hook    'icicle-set-calling-cmd)
845            (remove-hook 'kill-emacs-hook          'icicle-command-abbrev-save)
846            (remove-hook 'comint-mode-hook         'icicle-comint-hook-fn)
847            (remove-hook 'compilation-mode-hook    'icicle-compilation-hook-fn)
848            (remove-hook 'compilation-minor-mode-hook 'icicle-compilation-hook-fn)
849            ;; $$$$$$ Do this only in `icicle-display-candidates-in-Completions' now.
850            ;; $$$$$$ (remove-hook 'temp-buffer-show-hook    'icicle-fit-completions-window)
851            (icicle-restore-std-completion-fns)
852            (icicle-restore-standard-functions)
853            (icicle-restore-standard-options)
854            (unless (eq icicle-guess-commands-in-path 'load)
855              (setq icicle-shell-command-candidates-cache  ())) ; Reset - toggle Icy to update.
856            (remove-hook 'pre-command-hook 'icicle-add-menu-item-to-cmd-history)
857            (dolist (fn  icicle-inhibit-advice-functions)
858              (let ((info  (memq fn icicle-advice-info-list)))
859                (when (and (fboundp fn) info)
860                  (ad-set-advice-info fn info)
861                  (when (ad-is-active fn) (ad-activate fn)))))
862            (run-hooks 'icicle-mode-hook)
863            (message "Icicle mode is now OFF")))
864
865     (add-to-list 'minor-mode-alist '(icicle-mode " Icy"))))
866
867 (defun icicle-add-menu-item-to-cmd-history ()
868   "Add `this-command' to command history, if it is a menu item.
869 Menu items that are not associated with a command symbol are ignored.
870 Used on `pre-command-hook'."
871   (condition-case nil                   ; Just in case, since this is on `pre-command-hook'.
872       (when (and (> (length (this-command-keys-vector)) 0)
873                  (equal '(menu-bar) (elt (this-command-keys-vector) 0))
874                  ;; Exclude uninterned symbols such as `menu-function-356'.
875                  (symbolp this-command) (or (< emacs-major-version 21) (intern-soft this-command)))
876         (pushnew (symbol-name this-command) extended-command-history))
877     (error nil)))
878
879 (defun icicle-top-level-prep ()
880   "Do top-level stuff.  Used in `pre-command-hook'."
881   ;; Reset `icicle-current-TAB-method' and `icicle-apropos-complete-match-fn' if temporary.
882   ;; Save this top-level command as `icicle-last-top-level-command'
883   ;; Reset `icicle-candidates-alist' to ().
884   (when (= 0 (recursion-depth))
885     (let ((TAB-method  (get 'icicle-last-top-level-command 'icicle-current-TAB-method))
886           (apropos-fn  (get 'icicle-last-top-level-command 'icicle-apropos-complete-match-fn)))
887       (when TAB-method (setq icicle-current-TAB-method  TAB-method))
888       (when apropos-fn (setq icicle-apropos-complete-match-fn apropos-fn)))
889     (setq icicle-last-top-level-command   this-command
890           icicle-candidates-alist         ())))
891
892 (defun icicle-define-icicle-maps ()
893   "Define `icicle-mode-map' and `icicle-menu-map'."
894   (setq icicle-mode-map  (make-sparse-keymap)) ; Recreate it each time, to capture latest bindings.
895
896   ;; Define `Icicles' menu-bar menu.  Create it only once: sacrifice any new bindings for speed.
897   (unless icicle-menu-map
898     (setq icicle-menu-map  (make-sparse-keymap "Icicles"))
899     (define-key icicle-menu-map [icicle-mode] '(menu-item "Turn Off Icicle Mode" icicle-mode))
900     (define-key icicle-menu-map [icicle-abort]
901       '(menu-item "Cancel Minibuffer" icicle-abort-recursive-edit
902         :enable (active-minibuffer-window)))
903     (define-key icicle-menu-map [icicle-report-bug]
904       '(menu-item "Send Bug Report" icicle-send-bug-report))
905     (define-key icicle-menu-map [icicle-customize-icicles-group]
906       '(menu-item "Customize Icicles" icicle-customize-icicles-group))
907     (define-key icicle-menu-map [icicle-help]
908       '(menu-item "Help" icicle-minibuffer-help
909         :help "Display help for minibuffer input and completion"
910         :keys "C-? in minibuf"))
911     (define-key icicle-menu-map [icicle-separator-last] '("--"))
912
913     (when (and (not icicle-touche-pas-aux-menus-flag) ; `Bookmark+' menu.
914                (boundp 'bmkp-bmenu-menubar-menu)) ; In `bookmark+-bmu.el'.
915       (defvar icicle-bookmark+-menu-map (make-sparse-keymap)
916         "Icicles submenu for `Bookmark+' menu.")
917       (define-key bmkp-bmenu-menubar-menu [icicles]
918         (list 'menu-item "Icicles" icicle-bookmark+-menu-map :visible 'icicle-mode))
919       (define-key icicle-bookmark+-menu-map [icicle-search-bookmark-list-marked]
920         '(menu-item "Search & Replace in Marked Files..." icicle-search-bookmark-list-marked
921           :visible icicle-mode :enable (eq major-mode 'bookmark-bmenu-mode)))
922       (define-key icicle-bookmark+-menu-map [icicle-bookmark-save-marked-files-more]
923         '(menu-item "Saved Marked Files as More Candidates..." icicle-bookmark-save-marked-files-more
924           :visible icicle-mode :enable (eq major-mode 'bookmark-bmenu-mode)))
925       (define-key icicle-bookmark+-menu-map [icicle-bookmark-save-marked-files]
926         '(menu-item "Saved Marked Files as Candidates..." icicle-bookmark-save-marked-files
927           :visible icicle-mode :enable (eq major-mode 'bookmark-bmenu-mode)))
928       (define-key icicle-bookmark+-menu-map [icicle-bookmark-save-marked-files-as-project]
929         '(menu-item "Save Marked Files as Project" icicle-bookmark-save-marked-files-as-project
930           :visible icicle-mode :enable (eq major-mode 'bookmark-bmenu-mode))))
931
932     (unless icicle-touche-pas-aux-menus-flag ; Use Dired's `Multiple' or `Operate' menu.
933       (defvar icicle-dired-multiple-menu-map (make-sparse-keymap)
934         "Icicles submenu for Dired's `Multiple' (or `Operate') menu.")
935       (if (boundp 'diredp-menu-bar-operate-menu) ; In `dired+.el'.
936           (define-key diredp-menu-bar-operate-menu [icicles]
937             (list 'menu-item "Icicles" icicle-dired-multiple-menu-map :visible 'icicle-mode))
938         (define-key dired-mode-map [menu-bar operate icicles]
939           (list 'menu-item "Icicles" icicle-dired-multiple-menu-map :visible 'icicle-mode)))
940       (define-key icicle-dired-multiple-menu-map [icicle-search-dired-marked]
941         '(menu-item "Search (and Replace)..." icicle-search-dired-marked
942           :visible icicle-mode :enable (eq major-mode 'dired-mode)))
943       (define-key icicle-dired-multiple-menu-map [icicle-dired-save-marked-more]
944         '(menu-item "Save as More Completion Candidates" icicle-dired-save-marked-more
945           :visible icicle-mode :enable (eq major-mode 'dired-mode)))
946       (define-key icicle-dired-multiple-menu-map [icicle-dired-save-marked]
947         '(menu-item "Save as Completion Candidates" icicle-dired-save-marked
948           :visible icicle-mode :enable (eq major-mode 'dired-mode)))
949       (define-key icicle-dired-multiple-menu-map [icicle-dired-save-marked-as-project]
950         '(menu-item "Save as Project" icicle-dired-save-marked-as-project
951           :visible icicle-mode :enable (eq major-mode 'dired-mode))))
952
953     (unless icicle-touche-pas-aux-menus-flag ; Use Dired's `Dir' or `Subdir' menu.
954       (defvar icicle-dired-dir-menu-map (make-sparse-keymap)
955         "Icicles submenu for Dired's `Dir' (or `Subdir') menu.")
956       (if (boundp 'diredp-menu-bar-subdir-menu) ; In `dired+.el'.
957           (define-key diredp-menu-bar-subdir-menu [icicles]
958             (list 'menu-item "Icicles" icicle-dired-dir-menu-map :visible 'icicle-mode))
959         (define-key dired-mode-map [menu-bar subdir icicles]
960           (list 'menu-item "Icicles" icicle-dired-dir-menu-map :visible 'icicle-mode)))
961       (define-key icicle-dired-dir-menu-map [icicle-dired-saved-file-candidates-other-window]
962         '(menu-item "Open Dired for Chosen Files..."
963           icicle-dired-saved-file-candidates-other-window
964           :visible icicle-mode
965           :enable (and icicle-saved-completion-candidates (eq major-mode 'dired-mode))))
966       (define-key icicle-dired-dir-menu-map [icicle-dired-project-other-window]
967         '(menu-item "Open Dired for Project..." icicle-dired-project-other-window
968           :visible icicle-mode
969           :enable (and icicle-saved-completion-sets (eq major-mode 'dired-mode)))))
970
971     (cond ((and (not icicle-touche-pas-aux-menus-flag)
972                 (boundp 'Info-mode-menu)) ; Use `Info' menu, if available.
973            (defvar icicle-info-menu-map (make-sparse-keymap)
974              "Icicles submenu for `Info' menu.")
975            (define-key Info-mode-menu [icicles]
976              (list 'menu-item "Icicles" icicle-info-menu-map :visible 'icicle-mode))
977            (when (fboundp 'icicle-Info-virtual-book)
978              (define-key icicle-info-menu-map [icicle-Info-virtual-book]
979                '(menu-item "Virtual Book" icicle-Info-virtual-book :visible icicle-mode
980                  :enable (eq major-mode 'Info-mode))))
981            (define-key icicle-info-menu-map [icicle-Info-goto-node]
982              '(menu-item "+ Go to Node..." icicle-Info-goto-node :visible icicle-mode
983                :enable (eq major-mode 'Info-mode) :keys "g"))
984            (define-key icicle-info-menu-map [icicle-Info-menu]
985              '(menu-item "+ Go to Menu Node..." icicle-Info-menu :visible icicle-mode
986                :enable (eq major-mode 'Info-mode) :keys "m"))
987            (define-key icicle-info-menu-map [icicle-Info-index]
988              '(menu-item "+ Look Up in Index..." icicle-Info-index :visible icicle-mode
989                :enable (eq major-mode 'Info-mode) :keys "i")))
990           (t
991            (when (fboundp 'icicle-Info-virtual-book)
992              (define-key icicle-menu-map [icicle-Info-virtual-book]
993                '(menu-item "Virtual Book" icicle-Info-virtual-book
994                  :enable (eq major-mode 'Info-mode))))
995            (define-key icicle-menu-map [icicle-Info-goto-node]
996              '(menu-item "+ Go to Node..." icicle-Info-goto-node
997                :enable (eq major-mode 'Info-mode)))
998            (define-key icicle-menu-map [icicle-Info-menu]
999              '(menu-item "+ Go to Menu Node..." icicle-Info-menu
1000                :enable (eq major-mode 'Info-mode)))
1001            (define-key icicle-menu-map [icicle-Info-index]
1002              '(menu-item "+ Look Up in Index..." icicle-Info-index
1003                :enable (eq major-mode 'Info-mode)))
1004            (define-key icicle-menu-map [icicle-separator-Info]
1005              '(menu-item "--" icicle-separator-Info :visible icicle-mode
1006                :enable (eq major-mode 'Info-mode)))))
1007
1008     (cond ((and (not icicle-touche-pas-aux-menus-flag)
1009                 (boundp 'menu-bar-frames-menu)) ; Use `Frames' menu, defined in `menu-bar+.el'.
1010            (defvar icicle-frames-menu-map (make-sparse-keymap)
1011              "Icicles submenu for `Frames' menu.")
1012            (define-key menu-bar-frames-menu [icicles]
1013              (list 'menu-item "Icicles" icicle-frames-menu-map :visible 'icicle-mode))
1014            (define-key icicle-frames-menu-map [icicle-font]
1015              '(menu-item "+ Change Font" icicle-font :visible icicle-mode
1016                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))))
1017            (define-key icicle-frames-menu-map [icicle-frame-fg]
1018              '(menu-item "+ Change Foreground..." icicle-frame-fg :visible icicle-mode
1019                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))))
1020            (define-key icicle-frames-menu-map [icicle-frame-bg]
1021              '(menu-item "+ Change Background..." icicle-frame-bg :visible icicle-mode
1022                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame))))))
1023           (t
1024            (define-key icicle-menu-map [icicle-font]
1025              '(menu-item "+ Change Font of Frame..." icicle-font
1026                :enable (and icicle-mode
1027                         (not (window-minibuffer-p (frame-selected-window menu-updating-frame))))))
1028            (define-key icicle-menu-map [icicle-frame-fg]
1029              '(menu-item "+ Change Foreground of Frame..." icicle-frame-fg
1030                :enable (and icicle-mode
1031                         (not (window-minibuffer-p (frame-selected-window menu-updating-frame))))))
1032            (define-key icicle-menu-map [icicle-frame-bg]
1033              '(menu-item "+ Change Background of Frame..." icicle-frame-bg
1034                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))))
1035            (define-key icicle-menu-map [icicle-separator-frame] '("--"))))
1036
1037     (cond ((and (not icicle-touche-pas-aux-menus-flag)
1038                 (boundp 'menu-bar-describe-menu)) ; Use `Describe' menu, if available.
1039            (defvar icicle-describe-menu-map (make-sparse-keymap)
1040              "Icicles submenu for `Describe' menu.")
1041            (define-key menu-bar-describe-menu [icicles]
1042              (list 'menu-item "Icicles" icicle-describe-menu-map :visible 'icicle-mode))
1043            (define-key icicle-describe-menu-map [icicle-plist]
1044              '(menu-item "+ Symbol with Property List..." icicle-plist :visible icicle-mode))
1045            (define-key icicle-describe-menu-map [icicle-doc]
1046              '(menu-item "+ Doc of Fun, Var, or Face..." icicle-doc :visible icicle-mode))
1047            (define-key icicle-describe-menu-map [icicle-fundoc]
1048              '(menu-item "+ Function with Name, Doc..." icicle-fundoc :visible icicle-mode))
1049            (define-key icicle-describe-menu-map [icicle-vardoc]
1050              '(menu-item "+ Variable with Name, Doc..." icicle-vardoc :visible icicle-mode))
1051            (define-key icicle-describe-menu-map [icicle-describe-option-of-type]
1052              '(menu-item "+ Option of Type..." icicle-describe-option-of-type
1053                :visible icicle-mode))
1054            (define-key icicle-describe-menu-map [icicle-where-is]
1055              '(menu-item "+ Where Is..." icicle-where-is :visible icicle-mode)))
1056           (t
1057            (define-key icicle-menu-map [icicle-plist]
1058              '(menu-item "+ Symbol with Property List..." icicle-plist))
1059            (define-key icicle-menu-map [icicle-doc]
1060              '(menu-item "+ Doc of Fun, Var, or Face..." icicle-doc))
1061            (define-key icicle-menu-map [icicle-fundoc]
1062              '(menu-item "+ Describe Function with Name, Doc..." icicle-fundoc))
1063            (define-key icicle-menu-map [icicle-vardoc]
1064              '(menu-item "+ Describe Variable with Name, Doc..." icicle-vardoc))
1065            (define-key icicle-menu-map [icicle-describe-option-of-type]
1066              '(menu-item "+ Option of Type..." icicle-describe-option-of-type))
1067            (define-key icicle-menu-map [icicle-where-is]
1068              '(menu-item "+ Where Is..." icicle-where-is))
1069            (define-key icicle-menu-map [icicle-separator-doc] '("--"))))
1070
1071     (define-key icicle-menu-map [icicle-apply]
1072       '(menu-item "+ Apply Function to Alist Items..." icicle-apply))
1073     (define-key icicle-menu-map [icicle-save-string-to-variable]
1074       '(menu-item "Save String to Variable..." icicle-save-string-to-variable))
1075     (define-key icicle-menu-map [icicle-color-theme]
1076       '(menu-item "+ Choose Color Theme..." icicle-color-theme
1077         :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))))
1078     (define-key icicle-menu-map [icicle-remove-saved-completion-set]
1079       '(menu-item "+ Remove Saved Candidate Set..." icicle-remove-saved-completion-set
1080         :enable icicle-saved-completion-sets))
1081     (define-key icicle-menu-map [icicle-add/update-saved-completion-set]
1082       '(menu-item "Add/Update Saved Candidate Set..." icicle-add/update-saved-completion-set))
1083     (when (fboundp 'icicle-kmacro)
1084       (define-key icicle-menu-map [icicle-kmacro]
1085         '(menu-item "+ Execute Nth Keyboard Macro..." icicle-kmacro
1086           :enable (or (kmacro-ring-head) kmacro-ring))))
1087     (define-key icicle-menu-map [icicle-execute-named-keyboard-macro]
1088       '(menu-item "+ Execute Named Keyboard Macro..." icicle-execute-named-keyboard-macro))
1089     (define-key icicle-menu-map [icicle-separator-misc] '("--"))
1090     (define-key icicle-menu-map [icicle-imenu]
1091       '(menu-item "+ Imenu..." icicle-imenu
1092         :enable imenu-generic-expression))
1093     (define-key icicle-menu-map [icicle-goto-global-marker]
1094       '(menu-item "+ Go To Global Marker..." icicle-goto-global-marker
1095         :enable (consp (icicle-markers global-mark-ring)) :keys "C-- C-x C-SPC"))
1096     (define-key icicle-menu-map [icicle-goto-marker]
1097       '(menu-item "+ Go To Marker..." icicle-goto-marker
1098         :enable (mark t) :keys "C-- C-SPC"))
1099     (define-key icicle-menu-map [icicle-separator-goto] '("--"))
1100     (define-key icicle-menu-map [icicle-search-bookmarks-together]
1101       '(menu-item "+ Search Bookmarks Together..." icicle-search-bookmarks-together
1102         :enable (featurep 'bookmark+) :keys "C-u C-`"))
1103     (define-key icicle-menu-map [icicle-search-bookmark]
1104       '(menu-item "+ Search Bookmarks Separately..." icicle-search-bookmark
1105         :enable (featurep 'bookmark+)))
1106     (define-key icicle-menu-map [icicle-select-bookmarked-region]
1107       '(menu-item "+ Select Bookmarked Region..." icicle-select-bookmarked-region
1108         :enable (featurep 'bookmark+) :keys "C-u C-x C-x"))
1109     (define-key icicle-menu-map [icicle-separator-region] '("--"))
1110
1111     (cond ((and (not icicle-touche-pas-aux-menus-flag)
1112                 (boundp 'menu-bar-apropos-menu)) ; Use `Apropos' menu, if available.
1113            (defvar icicle-apropos-menu-map (make-sparse-keymap)
1114              "Icicles submenu for `Apropos' menu.")
1115            (define-key menu-bar-apropos-menu [icicles]
1116              (list 'menu-item "Icicles" icicle-apropos-menu-map :visible 'icicle-mode))
1117            (define-key icicle-apropos-menu-map [icicle-apropos-zippy]
1118              '(menu-item "Zippy..." icicle-apropos-zippy :visible icicle-mode))
1119            (cond ((fboundp 'apropos-option)
1120                   (define-key icicle-apropos-menu-map [icicle-apropos]
1121                     '(menu-item "Symbols..." icicle-apropos :visible icicle-mode))
1122                   (define-key icicle-apropos-menu-map [icicle-apropos-function]
1123                     '(menu-item "Functions..." icicle-apropos-function :visible icicle-mode))
1124                   (define-key icicle-apropos-menu-map [icicle-apropos-variable]
1125                     '(menu-item "Variables..." icicle-apropos-variable :visible icicle-mode))
1126                   (define-key icicle-apropos-menu-map [icicle-apropos-option]
1127                     '(menu-item "Options..." icicle-apropos-option :visible icicle-mode))
1128                   (define-key icicle-apropos-menu-map [icicle-apropos-command]
1129                     '(menu-item "Commands..." icicle-apropos-command :visible icicle-mode)))
1130                  (t
1131                   (define-key icicle-apropos-menu-map [icicle-apropos-variable]
1132                     '(menu-item "Variables..." icicle-apropos-variable
1133                       :visible icicle-mode))))
1134            (define-key icicle-apropos-menu-map [icicle-apropos-command]
1135              '(menu-item "Commands..." icicle-apropos-command :visible icicle-mode)))
1136           (t
1137            (define-key icicle-menu-map [icicle-apropos-zippy]
1138              '(menu-item "Apropos Zippy..." icicle-apropos-zippy))
1139            (cond ((fboundp 'apropos-option)
1140                   (define-key icicle-menu-map [icicle-apropos]
1141                     '(menu-item "Apropos..." icicle-apropos))
1142                   (define-key icicle-menu-map [icicle-apropos-function]
1143                     '(menu-item "Apropos Functions..." icicle-apropos-function))
1144                   (define-key icicle-menu-map [icicle-apropos-variable]
1145                     '(menu-item "Apropos Variables..." icicle-apropos-variable))
1146                   (define-key icicle-menu-map [icicle-apropos-option]
1147                     '(menu-item "Apropos Options..." icicle-apropos-option))
1148                   (define-key icicle-menu-map [icicle-apropos-command]
1149                     '(menu-item "Apropos Commands..." icicle-apropos-command)))
1150                  (t
1151                   (define-key icicle-menu-map [icicle-apropos-variable]
1152                     '(menu-item "Apropos Variables..." icicle-apropos-variable))
1153                   (define-key icicle-menu-map [icicle-apropos-command]
1154                     '(menu-item "Apropos Commands..." icicle-apropos-command))))
1155            (define-key icicle-menu-map [icicle-separator-apropos] '("--"))))
1156
1157     (cond ((and (not icicle-touche-pas-aux-menus-flag)
1158                 (boundp 'menu-bar-options-menu)) ; Use `Options' menu, if available.
1159            (defvar icicle-options-menu-map (make-sparse-keymap)
1160              "Icicles submenu for `Options' menu.")
1161            (define-key menu-bar-options-menu [icicles]
1162              (list 'menu-item "Icicles" icicle-options-menu-map :visible 'icicle-mode))
1163            (define-key icicle-options-menu-map [icicle-set-option-to-t]
1164              '(menu-item "+ Turn On Any Option..." icicle-set-option-to-t :visible icicle-mode
1165                :help "Set boolean option to `t' (C-u: any user option, C--: any var)"))
1166            (define-key icicle-options-menu-map [icicle-reset-option-to-nil]
1167              '(menu-item "+ Turn Off Any Option..." icicle-reset-option-to-nil :visible icicle-mode
1168                :help "Reset an option to `nil' (C-u: reset any variable)"))
1169            (define-key icicle-options-menu-map [icicle-toggle-option]
1170              '(menu-item "+ Toggle Any Option..." icicle-toggle-option :visible icicle-mode
1171                :help "Toggle boolean option (C-u: any user option, C--: any var)"))
1172            (define-key icicle-options-menu-map [icicle-separator-options-general] '("--"))
1173            (define-key icicle-options-menu-map [icicle-toggle-search-cleanup]
1174              '(menu-item "Toggle Icicle-Search Highlighting Cleanup" icicle-toggle-search-cleanup
1175                :visible icicle-mode :keys "C-." :help "Toggle option `icicle-search-cleanup-flag'"))
1176            (define-key icicle-options-menu-map [icicle-toggle-search-replace-common-match]
1177              '(menu-item "Toggle Replacing Longest Common Match"
1178                icicle-toggle-search-replace-common-match :visible icicle-mode
1179                :enable icicle-searching-p :keys "M-;"
1180                :help "Toggle option `icicle-search-replace-common-match-flag'"))
1181            (define-key icicle-options-menu-map [icicle-toggle-search-replace-whole]
1182              '(menu-item "Toggle Replacing Whole Search Hit"
1183                icicle-toggle-search-replace-whole :visible icicle-mode
1184                :enable icicle-searching-p :keys "M-_"
1185                :help "Toggle option `icicle-search-replace-whole-candidate-flag'"))
1186            (define-key icicle-options-menu-map [icicle-toggle-search-whole-word]
1187              '(menu-item "Toggle Whole-Word Searching (Icicles Search)"
1188                icicle-toggle-search-whole-word :visible icicle-mode
1189                :enable icicle-searching-p :keys "M-q"
1190                :help "Toggle `icicle-search-whole-word-flag'"))
1191            (define-key icicle-options-menu-map [icicle-toggle-search-complementing-domain]
1192              '(menu-item "Toggle Searching Complement"
1193                icicle-toggle-search-complementing-domain :visible icicle-mode :keys "C-M-~"
1194                :help "Toggle `icicle-search-complement-domain-p'"))
1195            (define-key icicle-options-menu-map [icicle-toggle-highlight-all-current]
1196              '(menu-item "Toggle All-Current Icicle-Search Highlighting"
1197                icicle-toggle-highlight-all-current :visible icicle-mode
1198                :enable icicle-searching-p :keys "C-^"
1199                :help "Toggle option `icicle-search-highlight-all-current-flag'"))
1200            (define-key icicle-options-menu-map [icicle-separator-options-search] '("--"))
1201            (define-key icicle-options-menu-map [icicle-toggle-regexp-quote]
1202              '(menu-item "Toggle Escaping Special Chars" icicle-toggle-regexp-quote
1203                :visible icicle-mode :keys "C-`"
1204                :help "Toggle option `icicle-regexp-quote-flag'"))
1205            (define-key icicle-options-menu-map [icicle-toggle-dot]
1206              '(menu-item "Toggle `.' Matching Newlines Too" icicle-toggle-dot
1207                :visible icicle-mode :keys "C-M-."
1208                :help "Toggle `icicle-dot-string' between `.' and `icicle-anychar-regexp'"))
1209            (define-key icicle-options-menu-map [icicle-toggle-incremental-completion]
1210              '(menu-item "Toggle Incremental Completion"
1211                icicle-toggle-incremental-completion :visible icicle-mode :keys "C-#"
1212                :help "Toggle option `icicle-incremental-completion-flag'"))
1213            (define-key icicle-options-menu-map [icicle-toggle-show-multi-completion]
1214              '(menu-item "Toggle Showing Multi-Completions"
1215                icicle-toggle-show-multi-completion :visible icicle-mode
1216                :help "Toggle option `icicle-show-multi-completion-flag'"))
1217            (define-key icicle-options-menu-map [icicle-toggle-hiding-non-matching-lines]
1218              '(menu-item "Toggle Hiding Non-Matching Lines"
1219                icicle-toggle-hiding-non-matching-lines :visible icicle-mode :keys "C-u C-x ."
1220                :help "Toggle option `icicle-hide-non-matching-lines-flag'"))
1221            (define-key icicle-options-menu-map [icicle-toggle-hiding-common-match]
1222              '(menu-item "Toggle Hiding Common Match"
1223                icicle-toggle-hiding-common-match :visible icicle-mode :keys "C-x ."
1224                :help "Toggle option `icicle-hide-common-match-in-Completions-flag'"))
1225            (define-key icicle-options-menu-map [icicle-toggle-expand-to-common-match]
1226              '(menu-item "Toggle Longest Common Match"
1227                icicle-toggle-expand-to-common-match :visible icicle-mode :keys "C-;"
1228                :help "Toggle option `icicle-expand-input-to-common-match-flag'"))
1229            (define-key icicle-options-menu-map [icicle-toggle-ignoring-comments]
1230              '(menu-item "Toggle Ignoring Comments" icicle-toggle-ignoring-comments
1231                :visible icicle-mode :keys "C-M-;"
1232                :help "Toggle option `icicle-ignore-comments-flag'"))
1233            (define-key icicle-options-menu-map [icicle-toggle-ignored-space-prefix]
1234              '(menu-item "Toggle Ignoring Space Prefix" icicle-toggle-ignored-space-prefix
1235                :visible icicle-mode :keys "M-_"
1236                :help "Toggle option `icicle-ignore-space-prefix-flag'"))
1237            (define-key icicle-options-menu-map [icicle-toggle-ignored-extensions]
1238              '(menu-item "Toggle Ignored File Extensions" icicle-toggle-ignored-extensions
1239                :visible icicle-mode :keys "C-."
1240                :help "Toggle respect of `completion-ignored-extensions'"))
1241            (define-key icicle-options-menu-map [icicle-toggle-remote-file-testing]
1242              '(menu-item "Toggle Remote File Handling" icicle-toggle-remote-file-testing
1243                :visible icicle-mode :enable (not icicle-searching-p) :keys "C-^"
1244                :help "Toggle option `icicle-test-for-remote-files-flag'"))
1245            (define-key icicle-options-menu-map [icicle-toggle-angle-brackets]
1246              '(menu-item "Toggle Angle Brackets" icicle-toggle-angle-brackets
1247                :visible icicle-mode :help "Toggle option `icicle-key-descriptions-use-<>-flag'"))
1248            (define-key icicle-options-menu-map [icicle-toggle-highlight-saved-candidates]
1249              '(menu-item "Toggle Highlighting Saved Candidates"
1250                icicle-toggle-highlight-saved-candidates :visible icicle-mode :keys "S-pause"
1251                :help "Toggle option `icicle-highlight-saved-candidates-flag'"))
1252            (define-key icicle-options-menu-map [icicle-toggle-highlight-historical-candidates]
1253              '(menu-item "Toggle Highlighting Past Inputs"
1254                icicle-toggle-highlight-historical-candidates :visible icicle-mode :keys "C-pause"
1255                :help "Toggle option `icicle-highlight-historical-candidates-flag'"))
1256            (define-key icicle-options-menu-map [icicle-toggle-case-sensitivity]
1257              '(menu-item "Toggle Case Sensitivity" icicle-toggle-case-sensitivity
1258                :visible icicle-mode :keys "C-A"
1259                :help "Toggle `case-fold-search', `completion-ignore-case' (C-u: file & buffer too)"))
1260            (define-key icicle-options-menu-map [icicle-toggle-proxy-candidates]
1261              '(menu-item "Toggle Including Proxy Candidates" icicle-toggle-proxy-candidates
1262                :visible icicle-mode :keys "C-M-_"
1263                :help "Toggle option `icicle-add-proxy-candidates-flag'"))
1264            (define-key icicle-options-menu-map [icicle-toggle-transforming]
1265              '(menu-item "Toggle Duplicate Removal" icicle-toggle-transforming
1266                :visible icicle-mode :keys "C-$"
1267                :help "Toggle use of `icicle-transform-function' (default: remove dups)"))
1268            (define-key icicle-options-menu-map [icicle-toggle-C-for-actions]
1269              '(menu-item "Toggle Using `C-' for Actions" icicle-toggle-C-for-actions
1270                :visible icicle-mode :keys "M-g"
1271                :help "Toggle option `icicle-use-C-for-actions-flag'"))
1272            (define-key icicle-options-menu-map [icicle-toggle-~-for-home-dir]
1273              '(menu-item "Toggle Using `~' for $HOME" icicle-toggle-~-for-home-dir
1274                :visible icicle-mode :keys "M-~"
1275                :help "Toggle option `icicle-use-~-for-home-dir-flag'"))
1276            (define-key icicle-options-menu-map [icicle-toggle-WYSIWYG-Completions]
1277              '(menu-item "Toggle WYSIWYG For `*Completions*'" icicle-toggle-WYSIWYG-Completions
1278                :visible icicle-mode :help "Toggle option `icicle-WYSIWYG-Completions-flag'"))
1279            (define-key icicle-options-menu-map [icicle-next-TAB-completion-method]
1280              '(menu-item "Next `TAB' Completion Method"
1281                icicle-next-TAB-completion-method :visible icicle-mode :keys "C-("
1282                :help "Cycle to the next `TAB' completion method (C-u: ONE-OFF)"))
1283            (define-key icicle-options-menu-map [icicle-next-S-TAB-completion-method]
1284              '(menu-item "Next `S-TAB' Completion Method" icicle-next-S-TAB-completion-method
1285                :visible icicle-mode :keys "M-("
1286                :help "Cycle to the next `S-TAB' completion method (C-u: ONE-OFF)"))
1287            (define-key icicle-options-menu-map [icicle-separator-options-sort] '("--"))
1288            (define-key icicle-options-menu-map [icicle-toggle-alternative-sorting]
1289              '(menu-item "Swap Alternative Sort" icicle-toggle-alternative-sorting
1290                :visible icicle-mode :keys "C-M-,"
1291                :help "Swap current sort order for current alternative sort order"))
1292            (define-key icicle-options-menu-map [icicle-change-alternative-sort-order]
1293              '(menu-item "Change Alternative Sort Order"
1294                icicle-change-alternative-sort-order :visible icicle-mode :keys "M-,"
1295                :help "Choose alt sort order (C-9: reverse, C-u: cyle/complete)"))
1296            (define-key icicle-options-menu-map [icicle-change-sort-order]
1297              '(menu-item "Change Sort Order" icicle-change-sort-order :visible icicle-mode
1298                :enable (not icicle-inhibit-sort-p) :keys "C-,"
1299                :help "Choose sort order (C-9: reverse, C-u: cyle/complete)"))
1300            (when (fboundp 'doremi)
1301              (define-key icicle-options-menu-map [icicle-separator-options-doremi]
1302                '(menu-item "--" nil :visible (or (get-buffer-window "*Completions*" 'visible)
1303                                               (eq (icicle-current-TAB-method) 'swank)
1304                                               (active-minibuffer-window))))
1305              (when (fboundp 'text-scale-increase) ; Emacs 23+.
1306                (define-key icicle-options-menu-map [icicle-doremi-zoom-Completions+]
1307                  '(menu-item "`*Completions*' Zoom Factor - Do Re Mi"
1308                    icicle-doremi-zoom-Completions+
1309                    :visible (and icicle-mode (get-buffer-window "*Completions*" 'visible))
1310                    :keys "C-x -" :help "Zoom text in `*Completions*' incrementally")))
1311              (define-key icicle-options-menu-map [icicle-doremi-inter-candidates-min-spaces+]
1312                '(menu-item "Inter-Candidate Spacing - Do Re Mi"
1313                  icicle-doremi-inter-candidates-min-spaces+
1314                  :visible (and icicle-mode (get-buffer-window "*Completions*" 'visible))
1315                  :keys "C-x |" :help "Change `icicle-inter-candidates-min-spaces' incrementally"))
1316              (define-key icicle-options-menu-map [icicle-doremi-candidate-width-factor+]
1317                '(menu-item "Candidate Column Width - Do Re Mi"
1318                  icicle-doremi-candidate-width-factor+
1319                  :visible (and icicle-mode (get-buffer-window "*Completions*" 'visible))
1320                  :keys "C-x w" :help "Change `icicle-candidate-width-factor' incrementally"))
1321              (define-key icicle-options-menu-map [icicle-doremi-increment-swank-prefix-length+]
1322                '(menu-item "Swank Min Match Chars - Do Re Mi"
1323                  icicle-doremi-increment-swank-prefix-length+
1324                  :visible (and icicle-mode (eq (icicle-current-TAB-method) 'swank)) :keys "C-x 2"
1325                  :help "Change `icicle-swank-prefix-length' incrementally"))
1326              (define-key icicle-options-menu-map [icicle-doremi-increment-swank-timeout+]
1327                '(menu-item "Swank Timeout - Do Re Mi"
1328                  icicle-doremi-increment-swank-timeout+
1329                  :visible (and icicle-mode (eq (icicle-current-TAB-method) 'swank)) :keys "C-x 1"
1330                  :help "Change `icicle-swank-timeout' incrementally"))
1331              (define-key icicle-options-menu-map [icicle-doremi-increment-max-candidates+]
1332                '(menu-item "Max # of Completions - Do Re Mi"
1333                  icicle-doremi-increment-max-candidates+
1334                  :visible (and icicle-mode (active-minibuffer-window)) :keys "C-x #"
1335                  :help "Change `icicle-max-candidates' incrementally"))))
1336           (t
1337            (define-key icicle-menu-map [icicle-set-option-to-t]
1338              '(menu-item "+ Turn On Any Option..." icicle-set-option-to-t
1339                :help "Set boolean option to `t' (C-u: any user option, C--: any var)"))
1340            (define-key icicle-menu-map [icicle-reset-option-to-nil]
1341              '(menu-item "+ Turn Off Any Option..." icicle-reset-option-to-nil
1342                :help "Reset an option to `nil' (C-u: reset any variable)"))
1343            (define-key icicle-menu-map [icicle-toggle-option]
1344              '(menu-item "+ Toggle Any Option..." icicle-toggle-option
1345                :help "Toggle boolean option (C-u: any user option, C--: any var)"))
1346            (define-key icicle-menu-map [icicle-toggle-C-for-actions]
1347              '(menu-item "Toggle Using `C-' for Actions" icicle-toggle-C-for-actions :keys "M-g"
1348                :help "Toggle option `icicle-use-C-for-actions-flag'"))
1349            (define-key icicle-menu-map [icicle-toggle-~-for-home-dir]
1350              '(menu-item "Toggle Using `~' for $HOME" icicle-toggle-~-for-home-dir :keys "M-~"
1351                :help "Toggle option `icicle-use-~-for-home-dir-flag'"))
1352            (define-key icicle-menu-map [icicle-toggle-WYSIWYG-Completions]
1353              '(menu-item "Toggle WYSIWYG For `*Completions*'" icicle-toggle-WYSIWYG-Completions
1354                :help "Toggle option `icicle-WYSIWYG-Completions-flag'"))
1355            (define-key icicle-menu-map [icicle-next-TAB-completion-method]
1356              '(menu-item "Next `TAB' Completion Method" icicle-next-TAB-completion-method
1357                :keys "C-(" :help "Cycle to the next `TAB' completion method (C-u: ONE-OFF)"))
1358            (define-key icicle-menu-map [icicle-next-S-TAB-completion-method]
1359              '(menu-item "Next `S-TAB' Completion Method" icicle-next-S-TAB-completion-method
1360                :keys "M-(" :help "Cycle to the next `S-TAB' completion method (C-u: ONE-OFF)"))
1361            (define-key icicle-menu-map [icicle-toggle-search-cleanup]
1362              '(menu-item "Toggle Icicle-Search Highlighting Cleanup" icicle-toggle-search-cleanup
1363                :keys "C-." :help "Toggle option `icicle-search-cleanup-flag'"))
1364            (define-key icicle-menu-map [icicle-toggle-search-replace-common-match]
1365              '(menu-item "Toggle Replacing Longest Common Match"
1366                icicle-toggle-search-replace-common-match :enable icicle-searching-p :keys "M-;"
1367                :help "Toggle option `icicle-search-replace-common-match-flag'"))
1368            (define-key icicle-menu-map [icicle-toggle-search-replace-whole]
1369              '(menu-item "Toggle Replacing Whole Search Hit" icicle-toggle-search-replace-whole
1370                :enable icicle-searching-p :keys "M-_"
1371                :help "Toggle option `icicle-search-replace-whole-candidate-flag'"))
1372            (define-key icicle-menu-map [icicle-toggle-search-whole-word]
1373              '(menu-item "Toggle Whole-Word Searching (Icicles Search)"
1374                icicle-toggle-search-whole-word
1375                :enable icicle-searching-p :keys "M-q"
1376                :help "Toggle `icicle-search-whole-word-flag'"))
1377            (define-key icicle-menu-map [icicle-toggle-regexp-quote]
1378              '(menu-item "Toggle Escaping Special Chars" icicle-toggle-regexp-quote :keys "C-`"
1379                :help "Toggle option `icicle-regexp-quote-flag'"))
1380            (define-key icicle-menu-map [icicle-toggle-dot]
1381              '(menu-item "Toggle `.' Matching Newlines Too" icicle-toggle-dot :keys "C-M-."
1382                :help "Toggle `icicle-dot-string' between `.' and `icicle-anychar-regexp'"))
1383            (define-key icicle-menu-map [icicle-toggle-incremental-completion]
1384              '(menu-item "Toggle Incremental Completion" icicle-toggle-incremental-completion
1385                :keys "C-#" :help "Toggle option `icicle-incremental-completion-flag'"))
1386            (define-key icicle-menu-map [icicle-toggle-show-multi-completion]
1387              '(menu-item "Toggle Showing Multi-Completions" icicle-toggle-show-multi-completion
1388                :help "Toggle option `icicle-show-multi-completion-flag'"))
1389            (define-key icicle-menu-map [icicle-toggle-hiding-non-matching-lines]
1390              '(menu-item "Toggle Hiding Non-Matching Lines"
1391                icicle-toggle-hiding-non-matching-lines
1392                :keys "C-u C-x ." :help "Toggle option `icicle-hide-non-matching-lines-flag'"))
1393            (define-key icicle-menu-map [icicle-toggle-hiding-common-match]
1394              '(menu-item "Toggle Hiding Common Match" icicle-toggle-hiding-common-match
1395                :keys "C-x ." :help "Toggle option `icicle-hide-common-match-in-Completions-flag'"))
1396            (define-key icicle-menu-map [icicle-toggle-expand-to-common-match]
1397              '(menu-item "Toggle Longest Common Match" icicle-toggle-expand-to-common-match
1398                :keys "C-;" :help "Toggle option `icicle-expand-input-to-common-match-flag'"))
1399            (define-key icicle-menu-map [icicle-toggle-ignoring-comments]
1400              '(menu-item "Toggle Ignoring Comments" icicle-toggle-ignoring-comments
1401                :keys "C-M-;" :help "Toggle option `icicle-ignore-comments-flag'"))
1402            (define-key icicle-menu-map [icicle-toggle-ignored-space-prefix]
1403              '(menu-item "Toggle Ignoring Space Prefix" icicle-toggle-ignored-space-prefix
1404                :keys "M-_" :help "Toggle option `icicle-ignore-space-prefix-flag'"))
1405            (define-key icicle-menu-map [icicle-toggle-ignored-extensions]
1406              '(menu-item "Toggle Ignored File Extensions" icicle-toggle-ignored-extensions
1407                :keys "C-." :help "Toggle respect of `completion-ignored-extensions'"))
1408            (define-key icicle-menu-map [icicle-toggle-remote-file-testing]
1409              '(menu-item "Toggle Remote File Handling" icicle-toggle-remote-file-testing
1410                :enable (not icicle-searching-p) :keys "C-^"
1411                :help "Toggle option `icicle-test-for-remote-files-flag'"))
1412            (define-key icicle-menu-map [icicle-toggle-angle-brackets]
1413              '(menu-item "Toggle Angle Brackets" icicle-toggle-angle-brackets
1414                :help "Toggle option `icicle-key-descriptions-use-<>-flag'"))
1415            (define-key icicle-menu-map [icicle-toggle-highlight-saved-candidates]
1416              '(menu-item "Toggle Highlighting Saved Candidates"
1417                icicle-toggle-highlight-saved-candidates :keys "S-pause"
1418                :help "Toggle option `icicle-highlight-saved-candidates-flag'"))
1419            (define-key icicle-menu-map [icicle-toggle-highlight-historical-candidates]
1420              '(menu-item "Toggle Highlighting Past Inputs"
1421                icicle-toggle-highlight-historical-candidates :keys "C-pause"
1422                :help "Toggle option `icicle-highlight-historical-candidates-flag'"))
1423            (define-key icicle-menu-map [icicle-toggle-case-sensitivity]
1424              '(menu-item "Toggle Case Sensitivity" icicle-toggle-case-sensitivity :keys "C-A"
1425                :help "Toggle `case-fold-search', `completion-ignore-case' (C-u: file & buffer too)"))
1426            (define-key icicle-menu-map [icicle-toggle-proxy-candidates]
1427              '(menu-item "Toggle Including Proxy Candidates" icicle-toggle-proxy-candidates
1428                :keys "C-M-_" :help "Toggle option `icicle-add-proxy-candidates-flag'"))
1429            (define-key icicle-menu-map [icicle-toggle-transforming]
1430              '(menu-item "Toggle Duplicate Removal" icicle-toggle-transforming :keys "C-$"
1431                :help "Toggle use of `icicle-transform-function' (default: remove dups)"))
1432            (define-key icicle-menu-map [icicle-toggle-alternative-sorting]
1433              '(menu-item "Swap Alternative Sort" icicle-toggle-alternative-sorting :keys "C-M-,"
1434                :help "Swap current sort order for current alternative sort order"))
1435            (define-key icicle-menu-map [icicle-change-alternative-sort-order]
1436              '(menu-item "Change Alternative Sort Order" icicle-change-alternative-sort-order
1437                :keys "M-," :help "Choose alt sort order (C-9: reverse, C-u: cyle/complete)"))
1438            (define-key icicle-menu-map [icicle-change-sort-order]
1439              '(menu-item "Change Sort Order" icicle-change-sort-order
1440                :enable (not icicle-inhibit-sort-p) :keys "C-,"
1441                :help "Choose sort order (C-9: reverse, C-u: cyle/complete)"))
1442            (when (fboundp 'doremi)
1443              (when (fboundp 'text-scale-increase) ; Emacs 23+.
1444                (define-key icicle-menu-map [icicle-doremi-zoom-Completions+]
1445                  '(menu-item "`*Completions*' Zoom Factor - Do Re Mi"
1446                    icicle-doremi-zoom-Completions+
1447                    :visible (get-buffer-window "*Completions*" 'visible) :keys "C-x -"
1448                    :help "Zoom text in `*Completions*' incrementally")))
1449              (define-key icicle-menu-map [icicle-doremi-inter-candidates-min-spaces+]
1450                '(menu-item "Inter-Candidate Spacing - Do Re Mi"
1451                  icicle-doremi-inter-candidates-min-spaces+
1452                  :visible (get-buffer-window "*Completions*" 'visible) :keys "C-x |"
1453                   :help "Change `icicle-inter-candidates-min-spaces' incrementally"))
1454              (define-key icicle-menu-map [icicle-doremi-candidate-width-factor+]
1455                '(menu-item "Candidate Column Width - Do Re Mi"
1456                  icicle-doremi-candidate-width-factor+
1457                  :visible (get-buffer-window "*Completions*" 'visible) :keys "C-x w"
1458                  :help "Change `icicle-candidate-width-factor' incrementally"))
1459              (define-key icicle-menu-map [icicle-doremi-increment-swank-prefix-length+]
1460                '(menu-item "Swank Min Match Chars - Do Re Mi"
1461                  icicle-doremi-increment-swank-prefix-length+
1462                  :visible (eq (icicle-current-TAB-method) 'swank) :keys "C-x 2"
1463                  :help "Change `icicle-swank-prefix-length' incrementally"))
1464              (define-key icicle-menu-map [icicle-doremi-increment-swank-timeout+]
1465                '(menu-item "Swank Timeout - Do Re Mi"
1466                  icicle-doremi-increment-swank-timeout+
1467                  :visible  (eq (icicle-current-TAB-method) 'swank) :keys "C-x 1"
1468                  :help "Change `icicle-swank-timeout' incrementally"))
1469              (define-key icicle-menu-map [icicle-doremi-increment-max-candidates+]
1470                '(menu-item "Max # of Completions - Do Re Mi"
1471                  icicle-doremi-increment-max-candidates+
1472                  :visible (active-minibuffer-window) :keys "C-x #"
1473                  :help "Change `icicle-max-candidates' incrementally")))
1474            (define-key icicle-menu-map [icicle-separator-toggle] '("--"))))
1475
1476     (cond ((and (not icicle-touche-pas-aux-menus-flag)
1477                 (boundp 'menu-bar-custom-menu)) ; Use `Customize' menu, if available.
1478            (defvar icicle-custom-menu-map (make-sparse-keymap)
1479              "Icicles submenu for `Customize' menu.")
1480            (define-key menu-bar-custom-menu [icicles]
1481              (list 'menu-item "Icicles" icicle-custom-menu-map :visible 'icicle-mode))
1482            (define-key icicle-custom-menu-map [icicle-customize-apropos-groups]
1483              '(menu-item "Groups Matching Regexp..." icicle-customize-apropos-groups
1484                :visible icicle-mode :help "Customize all user groups matching a regexp"))
1485            (define-key icicle-custom-menu-map [icicle-customize-apropos-faces]
1486              '(menu-item "Faces Matching Regexp..." icicle-customize-apropos-faces
1487                :visible icicle-mode :help "Customize all user faces matching a regexp"))
1488            (define-key icicle-custom-menu-map [icicle-customize-face]
1489              '(menu-item "+ Face..." icicle-customize-face :visible icicle-mode
1490                 :help "Customize a face"))
1491            (define-key icicle-custom-menu-map [icicle-customize-apropos-options]
1492              '(menu-item "Options Matching Regexp..." icicle-customize-apropos-options
1493                :visible icicle-mode :help "Customize all user options matching a regexp"))
1494            (define-key icicle-custom-menu-map [icicle-customize-apropos]
1495              '(menu-item "Settings Matching Regexp..." icicle-customize-apropos
1496                :visible icicle-mode :help "Customize all user settings matching a regexp")))
1497           (t
1498            (define-key icicle-menu-map [icicle-separator-customize] '("--"))
1499            (define-key icicle-menu-map [icicle-customize-apropos-groups]
1500              '(menu-item "Groups Matching Regexp..." icicle-customize-apropos-groups
1501                 :help "Customize all customization groups matching a regexp"))
1502            (define-key icicle-menu-map [icicle-customize-apropos-faces]
1503              '(menu-item "Faces Matching Regexp..." icicle-customize-apropos-faces
1504                 :help "Customize all faces matching a regexp"))
1505            (define-key icicle-menu-map [icicle-customize-face]
1506              '(menu-item "+ Face..." icicle-customize-face :help "Customize a face"))
1507            (define-key icicle-menu-map [icicle-customize-apropos-options]
1508              '(menu-item "Options Matching Regexp..." icicle-customize-apropos-options
1509                 :help "Customize all user options matching a regexp"))
1510            (define-key icicle-menu-map [icicle-customize-apropos]
1511              '(menu-item "Settings Matching Regexp..." icicle-customize-apropos
1512                 :help "Customize all user settings matching a regexp"))))
1513
1514     (cond ((and (not icicle-touche-pas-aux-menus-flag)
1515                 (boundp 'menu-bar-edit-menu)) ; Use `Edit' menu, if available.
1516            (defvar icicle-edit-menu-map (make-sparse-keymap)
1517              "Icicles submenu for `Edit' menu.")
1518            (define-key menu-bar-edit-menu [icicles]
1519              (list 'menu-item "Icicles" icicle-edit-menu-map :visible 'icicle-mode))
1520            (define-key icicle-edit-menu-map [icicle-complete-thesaurus-entry]
1521              '(menu-item "Complete with Thesaurus..." icicle-complete-thesaurus-entry
1522                :visible icicle-mode
1523                :enable (and (not buffer-read-only) (boundp 'synonyms-obarray))))
1524            (define-key icicle-edit-menu-map [icicle-insert-thesaurus-entry]
1525              '(menu-item "+ Insert Thesaurus Entry..." icicle-insert-thesaurus-entry
1526                :visible icicle-mode
1527                :enable (and (not buffer-read-only) (boundp 'synonyms-obarray))))
1528            (define-key icicle-edit-menu-map [icicle-completing-yank]
1529              '(menu-item "+ Paste Copied Text..." icicle-completing-yank :visible icicle-mode
1530                :enable (not buffer-read-only) :keys "C-- C-y")))
1531           (t
1532            (define-key icicle-menu-map [icicle-separator-edit] '("--"))
1533            (define-key icicle-menu-map [icicle-complete-thesaurus-entry]
1534              '(menu-item "Complete with Thesaurus..." icicle-complete-thesaurus-entry
1535                :enable (and (not buffer-read-only) (boundp 'synonyms-obarray))
1536                :help "Complete a word to an entry from a thesaurus"))
1537            (define-key icicle-menu-map [icicle-insert-thesaurus-entry]
1538              '(menu-item "+ Insert Thesaurus Entry..." icicle-insert-thesaurus-entry
1539                :enable (and (not buffer-read-only) (boundp 'synonyms-obarray))
1540                :help "Insert an entry from a thesaurus"))
1541            (define-key icicle-menu-map [icicle-completing-yank]
1542              '(menu-item "+ Paste Copied Text..." icicle-completing-yank
1543                :enable (not buffer-read-only) :keys "C-- C-y"
1544                :help "Yank an entry from the `kill-ring', choosing it using completion"))))
1545
1546     (cond ((and (not icicle-touche-pas-aux-menus-flag)
1547                 (boundp 'menu-bar-file-menu)) ; Use `File' menu, if available.
1548            (defvar icicle-file-menu-map (make-sparse-keymap)
1549              "Icicles submenu for `File' menu.")
1550            (define-key menu-bar-file-menu [icicles]
1551              (list 'menu-item "Icicles" icicle-file-menu-map :visible 'icicle-mode))
1552            (define-key icicle-file-menu-map [icicle-kill-buffer]
1553              '(menu-item "+ Kill Buffer..." icicle-kill-buffer :visible icicle-mode :keys "C-x k"
1554                :help "Kill a buffer (C-0: same-mode, C-9: file, C-- this-frame"))
1555            (define-key icicle-file-menu-map [icicle-delete-file]
1556              '(menu-item "+ Delete File..." icicle-delete-file :visible icicle-mode
1557                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1558                :help "Delete a file or directory"))
1559            (when (featurep 'recentf)
1560              (define-key icicle-file-menu-map [icicle-remove-file-from-recentf-list]
1561                '(menu-item "+ Remove from Recent Files List..."
1562                  icicle-remove-file-from-recentf-list :visible icicle-mode
1563                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1564                  :help "Remove file from `recentf-list' - the list of recently used files"))
1565              (define-key icicle-file-menu-map [icicle-recent-file-other-window]
1566                '(menu-item "+ Open Recent File (Other Window)..."
1567                  icicle-recent-file-other-window :visible icicle-mode
1568                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1569                  :help "Open a recently used file in another window"))
1570              (define-key icicle-file-menu-map [icicle-recent-file]
1571                '(menu-item "+ Open Recent File..." icicle-recent-file :visible icicle-mode
1572                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1573                  :help "Open a recently used file")))
1574            (define-key icicle-file-menu-map [icicle-dired-saved-file-candidates-other-window]
1575              '(menu-item "Open Dired for Chosen Files..."
1576                icicle-dired-saved-file-candidates-other-window :visible icicle-mode
1577                :enable (and icicle-saved-completion-candidates
1578                         (not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
1579                :help "Open Dired on a set of files & directories of your choice"))
1580            (define-key icicle-file-menu-map [icicle-dired-project-other-window]
1581              '(menu-item "Open Dired for Project..." icicle-dired-project-other-window
1582                :visible icicle-mode
1583                :enable (and icicle-saved-completion-sets
1584                         (not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
1585                :help "Open Dired on a saved project in another window"))
1586            (define-key icicle-file-menu-map [icicle-locate-file-other-window]
1587              '(menu-item "+ Open File Under Directory (Other Window)..."
1588                icicle-locate-file-other-window :visible icicle-mode
1589                :help "Visit a file within a directory or its subdirectories, in another window"))
1590            (define-key icicle-file-menu-map [icicle-locate-file]
1591              '(menu-item "+ Open File Under Directory..." icicle-locate-file :visible icicle-mode
1592                :help "Visit a file within a directory or its subdirectories"))
1593            (define-key icicle-file-menu-map [icicle-file-other-window]
1594              '(menu-item "+ Open File or Directory (Other Window)..." icicle-file-other-window
1595                :visible icicle-mode
1596                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1597                :help "Visit a file or directory in another window"))
1598            (define-key icicle-file-menu-map [icicle-file]
1599              '(menu-item "+ Open File or Directory..." icicle-file :visible icicle-mode
1600                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1601                :help "Visit a file or directory (C-u absolute, C-- absolute by date)")))
1602           (t
1603            (define-key icicle-menu-map [icicle-kill-buffer]
1604              '(menu-item "+ Kill Buffer..." icicle-kill-buffer
1605                :help "Kill a buffer (C-0: same-mode, C-9: file, C-- this-frame"))
1606            (define-key icicle-menu-map [icicle-delete-file]
1607              '(menu-item "+ Delete File..." icicle-delete-file
1608                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1609                :help "Delete a file or directory"))
1610            (when (featurep 'recentf)
1611              (define-key icicle-menu-map [icicle-remove-file-from-recentf-list]
1612                '(menu-item "+ Remove from Recent Files List..."
1613                  icicle-remove-file-from-recentf-list
1614                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1615                  :help "Remove file from `recentf-list' - the list of recently used files"))
1616              (define-key icicle-menu-map [icicle-recent-file-other-window]
1617                '(menu-item "+ Open Recent File (Other Window)..." icicle-recent-file-other-window
1618                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1619                  :help "Open a recently used file in another window"))
1620              (define-key icicle-menu-map [icicle-recent-file]
1621                '(menu-item "+ Open Recent File..." icicle-recent-file
1622                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1623                  :help "Open a recently used file")))
1624            (define-key icicle-menu-map [icicle-dired-saved-file-candidates-other-window]
1625              '(menu-item "Open Dired for Chosen Files..."
1626                icicle-dired-saved-file-candidates-other-window
1627                :enable (and icicle-saved-completion-candidates
1628                         (not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
1629                :help "Open Dired on a set of files & directories of your choice"))
1630            (define-key icicle-menu-map [icicle-dired-project-other-window]
1631              '(menu-item "Open Dired for Project..." icicle-dired-project-other-window
1632                :enable (and icicle-saved-completion-sets
1633                         (not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
1634                :help "Open Dired on a saved project in another window"))
1635            (define-key icicle-menu-map [icicle-locate-file-other-window]
1636              '(menu-item "+ Open File Under Directory (Other Window)..."
1637                icicle-locate-file-other-window
1638                :help "Visit a file within a directory or its subdirectories, in another window"))
1639            (define-key icicle-menu-map [icicle-locate-file]
1640              '(menu-item "+ Open File Under Directory..." icicle-locate-file
1641                :help "Visit a file within a directory or its subdirectories"))
1642            (define-key icicle-menu-map [icicle-file-other-window]
1643              '(menu-item "+ Open File or Directory (Other Window)..."
1644                icicle-file-other-window
1645                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1646                :help "Visit a file or directory in another window"))
1647            (define-key icicle-menu-map [icicle-file]
1648              '(menu-item "+ Open File or Directory ..." icicle-file
1649                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1650                :help "Visit a file or directory (C-u absolute, C-- absolute by date)"))))
1651     (define-key icicle-menu-map [icicle-buffer-list]
1652       '(menu-item "+ Buffer List..." icicle-buffer-list :help "Choose a list of buffer names"))
1653     (define-key icicle-menu-map [icicle-remove-buffer-config]
1654       '(menu-item "+ Remove Buffer Configuration..." icicle-remove-buffer-config
1655         :enable icicle-buffer-configs
1656         :help "Remove buffer configuration from `icicle-buffer-configs'"))
1657     (define-key icicle-menu-map [icicle-add-buffer-config]
1658       '(menu-item "New Buffer Configuration..." icicle-add-buffer-config
1659         :help "Add buffer configuration to `icicle-buffer-configs'"))
1660     (define-key icicle-menu-map [icicle-buffer-config]
1661       '(menu-item "+ Choose Buffer Configuration..." icicle-buffer-config
1662         :enable icicle-buffer-configs
1663         :help "Choose a configuration of user options for `icicle-buffer'"))
1664     (define-key icicle-menu-map [icicle-remove-buffer-candidate]
1665       '(menu-item "+ Don't Always Include Buffer..." icicle-remove-buffer-candidate
1666         :enable icicle-buffer-extras :help "Remove buffer as an always-show completion candidate"))
1667     (define-key icicle-menu-map [icicle-add-buffer-candidate]
1668       '(menu-item "+ Always Include Buffer..." icicle-add-buffer-candidate
1669         :help "Add buffer as an always-show completion candidate"))
1670     (define-key icicle-menu-map [icicle-kill-buffer]
1671       '(menu-item "+ Kill Buffer..." icicle-kill-buffer
1672         :help "Kill a buffer (C-0: same-mode, C-9: file, C-- this-frame"))
1673     (define-key icicle-menu-map [icicle-insert-buffer]
1674       '(menu-item "+ Insert Buffer..." icicle-insert-buffer
1675         :help "Multi-command version of `insert-buffer'"))
1676     (define-key icicle-menu-map [icicle-delete-windows]
1677       '(menu-item "+ Delete Windows on Buffer..." icicle-delete-windows :keys "C-u C-x 0"
1678         :help "Delete windows showing a buffer, anywhere"))
1679     (define-key icicle-menu-map [icicle-buffer-other-window]
1680       '(menu-item "+ Switch to Buffer (Other Window)..." icicle-buffer-other-window
1681         :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))))
1682     (define-key icicle-menu-map [icicle-buffer]
1683       '(menu-item "+ Switch to Buffer..." icicle-buffer
1684         :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1685         :help "Switch to a buffer (C-0: same mode, C-9: file buffer, C--: same frame"))
1686
1687     (cond ((and (not icicle-touche-pas-aux-menus-flag)
1688                 (boundp 'menu-bar-bookmark-map)) ; Use `Bookmarks' menu, if available.
1689            (require 'bookmark)          ; `bookmark-buffer-name' is not autoloaded.
1690            (defvar icicle-bookmark-menu-map (make-sparse-keymap)
1691              "Icicles submenu for `Bookmarks' menu.")
1692            (define-key menu-bar-bookmark-map [icicles]
1693              (list 'menu-item "Icicles" icicle-bookmark-menu-map :visible 'icicle-mode))
1694            (define-key icicle-bookmark-menu-map [icicle-goto-global-marker]
1695              '(menu-item "+ Go To Global Marker..." icicle-goto-global-marker :visible icicle-mode
1696                :enable (consp (icicle-markers global-mark-ring)) :keys "C-- C-x C-SPC"
1697                :help "Go to a global marker, choosing it by its line"))
1698            (define-key icicle-bookmark-menu-map [icicle-goto-marker]
1699              '(menu-item "+ Go To Marker..." icicle-goto-marker :visible icicle-mode
1700                :enable (consp (icicle-markers mark-ring)) :keys "C-- C-SPC"
1701                :help "Go to a marker in this buffer, choosing it by its line"))
1702            (define-key icicle-bookmark-menu-map [icicle-separator-goto] '("--"))
1703            (when (featurep 'bookmark+)
1704              (define-key icicle-bookmark-menu-map [icicle-bookmark-all-tags-regexp-other-window]
1705                '(menu-item "All Tags Matching Regexp..." icicle-bookmark-all-tags-regexp-other-window
1706                  :visible icicle-mode
1707                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1708                  :help "Jump to a bookmark that has each tag matching a regexp that you enter"))
1709              (define-key icicle-bookmark-menu-map [icicle-bookmark-some-tags-regexp-other-window]
1710                '(menu-item "Any Tag Matching Regexp..." icicle-bookmark-some-tags-regexp-other-window
1711                  :visible icicle-mode
1712                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1713                  :help "Jump to a bookmark with at least one tag matching a regexp"))
1714              (define-key icicle-bookmark-menu-map [icicle-bookmark-all-tags-other-window]
1715                '(menu-item "All Tags in Set..." icicle-bookmark-all-tags-other-window
1716                  :visible icicle-mode
1717                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1718                  :help "Jump to a bookmark that has all of a set of tags that you enter"))
1719              (define-key icicle-bookmark-menu-map [icicle-bookmark-some-tags-other-window]
1720                '(menu-item "Any Tag in Set..." icicle-bookmark-some-tags-other-window
1721                  :visible icicle-mode
1722                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1723                  :help "Jump to a bookmark that has some of a set of tags that you enter"))
1724              (define-key icicle-bookmark-menu-map [icicle-bookmark-file-all-tags-regexp-other-window]
1725                '(menu-item "File, All Tags Matching Regexp..."
1726                  icicle-bookmark-file-all-tags-regexp-other-window :visible icicle-mode
1727                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1728                  :help "Jump to a file or dir bookmark where each tag matches a regexp"))
1729              (define-key icicle-bookmark-menu-map
1730                  [icicle-bookmark-file-some-tags-regexp-other-window]
1731                '(menu-item "File, Any Tag Matching Regexp..."
1732                  icicle-bookmark-file-some-tags-regexp-other-window :visible icicle-mode
1733                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1734                  :help "Jump to a file or dir bookmark where at least one tag matches a regexp"))
1735              (define-key icicle-bookmark-menu-map [icicle-bookmark-file-all-tags-other-window]
1736                '(menu-item "File, All Tags in Set..." icicle-bookmark-file-all-tags-other-window
1737                  :visible icicle-mode
1738                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1739                  :help "Jump to a file or dir bookmark that has all of a set of tags"))
1740              (define-key icicle-bookmark-menu-map [icicle-bookmark-file-some-tags-other-window]
1741                '(menu-item "File, Any Tag in Set..." icicle-bookmark-file-some-tags-other-window
1742                  :visible icicle-mode
1743                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1744                  :help "Jump to a file or dir bookmark that has some of a set of tags"))
1745              (define-key icicle-bookmark-menu-map [icicle-separator-bookmark-tags] '("--"))
1746              (define-key icicle-bookmark-menu-map [icicle-bookmark-non-file-other-window]
1747                '(menu-item "+ Jump to Buffer (Non-File) Bookmark..."
1748                  icicle-bookmark-non-file-other-window :visible icicle-mode
1749                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1750                  :help "Jump to a buffer (i.e., a non-file) bookmark"))
1751              (define-key icicle-bookmark-menu-map [icicle-bookmark-region-other-window]
1752                '(menu-item "+ Jump to Region Bookmark..." icicle-bookmark-region-other-window
1753                  :visible icicle-mode
1754                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1755                  :help "Jump to a bookmark and activate its recorded region"))
1756              (define-key icicle-bookmark-menu-map [icicle-bookmark-url-other-window]
1757                '(menu-item "+ Jump to URL Bookmark..." icicle-bookmark-url-other-window
1758                  :visible icicle-mode
1759                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1760                  :help "Jump to a URL bookmark"))
1761              (define-key icicle-bookmark-menu-map [icicle-bookmark-gnus-other-window]
1762                '(menu-item "+ Jump to Gnus Bookmark..." icicle-bookmark-gnus-other-window
1763                  :visible icicle-mode
1764                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1765                  :help "Jump to a Gnus bookmark"))
1766              (define-key icicle-bookmark-menu-map [icicle-bookmark-man-other-window]
1767                '(menu-item "+ Jump to `man' Bookmark..." icicle-bookmark-man-other-window
1768                  :visible icicle-mode
1769                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1770                  :help "Jump to a `man'-page bookmark"))
1771              (define-key icicle-bookmark-menu-map [icicle-bookmark-info-other-window]
1772                '(menu-item "+ Jump to Info Bookmark..." icicle-bookmark-info-other-window
1773                  :visible icicle-mode
1774                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1775                  :help "Jump to an Info bookmark"))
1776              (define-key icicle-bookmark-menu-map [icicle-bookmark-remote-file-other-window]
1777                '(menu-item "+ Jump to Remote-File Bookmark..."
1778                  icicle-bookmark-remote-file-other-window :visible icicle-mode
1779                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1780                  :help "Jump to a remote-file bookmark"))
1781              (define-key icicle-bookmark-menu-map [icicle-bookmark-local-file-other-window]
1782                '(menu-item "+ Jump to Local-File Bookmark..."
1783                  icicle-bookmark-local-file-other-window :visible icicle-mode
1784                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1785                  :help "Jump to a local-file bookmark"))
1786              (define-key icicle-bookmark-menu-map [icicle-bookmark-file-other-window]
1787                '(menu-item "+ Jump to File Bookmark..." icicle-bookmark-file-other-window
1788                  :visible icicle-mode
1789                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1790                  :help "Jump to a file bookmark"))
1791              (define-key icicle-bookmark-menu-map [icicle-bookmark-dired-other-window]
1792                '(menu-item "+ Jump to Dired Bookmark..." icicle-bookmark-dired-other-window
1793                  :visible icicle-mode
1794                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1795                  :help "Jump to a Dired bookmark"))
1796              (define-key icicle-bookmark-menu-map [icicle-bookmark-bookmark-list]
1797                '(menu-item "+ Jump to Bookmark-List Bookmark..."
1798                  icicle-bookmark-bookmark-list :visible icicle-mode
1799                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1800                  :help "Jump to a bookmark-list bookmark"))
1801              (define-key icicle-bookmark-menu-map [icicle-bookmark-desktop]
1802                '(menu-item "+ Jump to Desktop Bookmark..." icicle-bookmark-desktop
1803                  :visible icicle-mode
1804                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1805                  :help "Jump to an Emacs desktop bookmark"))
1806              )
1807            (define-key icicle-bookmark-menu-map [icicle-bookmark-other-window]
1808              '(menu-item "+ Jump to Bookmark..." icicle-bookmark-other-window :visible icicle-mode
1809                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1810                :help "Jump to a bookmark (C-u: reverse `icicle-bookmark-refresh-cache-flag')"))
1811            (define-key icicle-bookmark-menu-map [icicle-bookmark]
1812              '(menu-item "+ Jump to Bookmark (Same Window)..." icicle-bookmark :visible icicle-mode
1813                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1814                :help "Jump to a bookmark (C-u: reverse `icicle-bookmark-refresh-cache-flag')")))
1815           (t
1816            (when (featurep 'bookmark+)
1817              (define-key icicle-menu-map [icicle-bookmark-non-file-other-window]
1818                '(menu-item "+ Jump to Buffer (Non-File) Bookmark..."
1819                  icicle-bookmark-non-file-other-window
1820                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1821                  :help "Jump to a buffer (i.e., a non-file) bookmark"))
1822              (define-key icicle-menu-map [icicle-bookmark-region-other-window]
1823                '(menu-item "+ Jump to Region Bookmark..." icicle-bookmark-region-other-window
1824                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1825                  :help "Jump to a bookmark and activate its recorded region"))
1826              (define-key icicle-menu-map [icicle-bookmark-url-other-window]
1827                '(menu-item "+ Jump to URL Bookmark..." icicle-bookmark-url-other-window
1828                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1829                  :help "Jump to a URL bookmark"))
1830              (define-key icicle-menu-map [icicle-bookmark-gnus-other-window]
1831                '(menu-item "+ Jump to Gnus Bookmark..." icicle-bookmark-gnus-other-window
1832                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1833                  :help "Jump to a Gnus bookmark"))
1834              (define-key icicle-menu-map [icicle-bookmark-man-other-window]
1835                '(menu-item "+ Jump to `man' Bookmark..." icicle-bookmark-man-other-window
1836                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1837                  :help "Jump to a `man'-page bookmark"))
1838              (define-key icicle-menu-map [icicle-bookmark-info-other-window]
1839                '(menu-item "+ Jump to Info Bookmark..." icicle-bookmark-info-other-window
1840                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1841                  :help "Jump to an Info bookmark"))
1842              (define-key icicle-menu-map [icicle-bookmark-remote-file-other-window]
1843                '(menu-item "+ Jump to Remote-File Bookmark..."
1844                  icicle-bookmark-remote-file-other-window
1845                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1846                  :help "Jump to a remote-file bookmark"))
1847              (define-key icicle-menu-map [icicle-bookmark-local-file-other-window]
1848                '(menu-item "+ Jump to Local-File Bookmark..."
1849                  icicle-bookmark-local-file-other-window
1850                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1851                  :help "Jump to a local-file bookmark"))
1852              (define-key icicle-menu-map [icicle-bookmark-file-other-window]
1853                '(menu-item "+ Jump to File Bookmark..." icicle-bookmark-file-other-window
1854                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1855                  :help "Jump to a file bookmark"))
1856              (define-key icicle-menu-map [icicle-bookmark-dired-other-window]
1857                '(menu-item "+ Jump to Dired Bookmark..." icicle-bookmark-dired-other-window
1858                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1859                  :help "Jump to a Dired bookmark"))
1860              (define-key icicle-menu-map [icicle-bookmark-bookmark-list]
1861                '(menu-item "+ Jump to Bookmark-List Bookmark..."
1862                  icicle-bookmark-bookmark-list
1863                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1864                  :help "Jump to a bookmark-list bookmark"))
1865              (define-key icicle-menu-map [icicle-bookmark-desktop]
1866                '(menu-item "+ Jump to Desktop Bookmark..." icicle-bookmark-desktop
1867                  :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1868                  :help "Jump to an Emacs desktop bookmark"))
1869              )
1870            (define-key icicle-menu-map [icicle-bookmark-other-window]
1871              '(menu-item "+ Jump To Bookmark..." icicle-bookmark-other-window
1872                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1873                :help "Jump to a bookmark (C-u: reverse `icicle-bookmark-refresh-cache-flag')"))
1874            (define-key icicle-menu-map [icicle-bookmark]
1875              '(menu-item "+ Jump To Bookmark (Same Window)..." icicle-bookmark
1876                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1877                :help "Jump to a bookmark (C-u: reverse `icicle-bookmark-refresh-cache-flag')"))
1878            (define-key icicle-menu-map [icicle-separator-bookmark] '("--"))))
1879
1880     (cond ((and (not icicle-touche-pas-aux-menus-flag)
1881                 (boundp 'menu-bar-search-tags-menu)) ; Use `Tags' menu, defined in `menu-bar+.el'.
1882            (defvar icicle-search-tags-menu-map (make-sparse-keymap)
1883              "Icicles submenu for `Tags' submenu of `Search' menu.")
1884            (define-key menu-bar-search-tags-menu [icicles]
1885              (list 'menu-item "Icicles" icicle-search-tags-menu-map :visible 'icicle-mode))
1886            (define-key icicle-search-tags-menu-map [icicle-tags-search]
1887              '(menu-item "+ Search Tagged Files ..." icicle-tags-search :visible icicle-mode
1888                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1889                :help "Search all source files listed in tags tables for matches for a regexp"))
1890            (define-key icicle-search-tags-menu-map [icicle-pop-tag-mark]
1891              '(menu-item "+ Back (Pop Tag Mark)" icicle-pop-tag-mark :visible icicle-mode
1892                :enable (and (boundp 'find-tag-marker-ring)
1893                         (not (ring-empty-p find-tag-marker-ring))
1894                         (not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
1895                :help "Pop back to where `M-.' was last invoked"))
1896            (define-key icicle-search-tags-menu-map [icicle-find-first-tag-other-window]
1897              '(menu-item "+ Find First Tag ..." icicle-find-first-tag-other-window
1898                :visible icicle-mode
1899                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1900                :help "Find first tag in current tags table whose name matches your input"))
1901            (define-key icicle-search-tags-menu-map [icicle-find-tag]
1902              '(menu-item "+ Find Tag ..." icicle-find-tag :visible icicle-mode
1903                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1904                :help "Navigate among all tags that match a regexp")))
1905           ((and (not icicle-touche-pas-aux-menus-flag) ; Use `Search' menu, if no `Tags' menu.
1906                 (boundp 'menu-bar-search-menu))
1907            (defvar icicle-search-menu-map (make-sparse-keymap)
1908              "Icicles submenu for `Search' menu.")
1909            (define-key menu-bar-search-menu [icicles]
1910              (list 'menu-item "Icicles" icicle-search-menu-map :visible 'icicle-mode))
1911            (defvar icicle-search-tags-menu-map (make-sparse-keymap)
1912              "Icicles submenu for `Tags' submenu of `Search' menu.")
1913            (define-key icicle-search-menu-map [icicles-tags]
1914              (list 'menu-item "Tags" icicle-search-tags-menu-map :visible 'icicle-mode))
1915            (define-key icicle-search-tags-menu-map [icicle-tags-search]
1916              '(menu-item "+ Search Tagged Files ..." icicle-tags-search :visible icicle-mode
1917                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1918                :help "Search all source files listed in tags tables for matches for a regexp"))
1919            (define-key icicle-search-tags-menu-map [icicle-pop-tag-mark]
1920              '(menu-item "+ Back (Pop Tag Mark)" icicle-pop-tag-mark :visible icicle-mode
1921                :enable (and (boundp 'find-tag-marker-ring)
1922                         (not (ring-empty-p find-tag-marker-ring))
1923                         (not (window-minibuffer-p (frame-selected-window menu-updating-frame))))
1924                :help "Pop back to where `M-.' was last invoked"))
1925            (define-key icicle-search-tags-menu-map [icicle-find-first-tag-other-window]
1926              '(menu-item "+ Find First Tag ..." icicle-find-first-tag-other-window
1927                :visible icicle-mode
1928                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1929                :help "Find first tag in current tags table whose name matches your input"))
1930            (define-key icicle-search-tags-menu-map [icicle-find-tag]
1931              '(menu-item "+ Find Tag ..." icicle-find-tag :visible icicle-mode
1932                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1933                :help "Navigate among all tags that match a regexp")))
1934           (t
1935            (define-key icicle-menu-map [icicle-tags-search]
1936              '(menu-item "+ Search Tagged Files ..." icicle-tags-search
1937                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1938                :help "Search all source files listed in tags tables for matches for a regexp"))
1939            (define-key icicle-menu-map [icicle-pop-tag-mark]
1940              '(menu-item "+ Back (Pop Tag Mark)" icicle-pop-tag-mark
1941                :enable (and (boundp 'find-tag-marker-ring)
1942                         (not (ring-empty-p find-tag-marker-ring))
1943                         (not (window-minibuffer-p
1944                               (frame-selected-window menu-updating-frame))))
1945                :help "Pop back to where `M-.' was last invoked"))
1946            (define-key icicle-menu-map [icicle-find-first-tag-other-window]
1947              '(menu-item "Find First Tag ..." icicle-find-first-tag-other-window
1948                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1949                :help "Find first tag in current tags table whose name matches your input"))
1950            (define-key icicle-menu-map [icicle-find-tag]
1951              '(menu-item "Find Tag ..." icicle-find-tag
1952                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1953                :help "Navigate among all tags that match a regexp"))))
1954
1955     (cond ((and (not icicle-touche-pas-aux-menus-flag)
1956                 (boundp 'menu-bar-search-menu)) ; Use `Search' menu, if available.
1957            (defvar icicle-search-menu-map (make-sparse-keymap)
1958              "Icicles submenu for `Search' menu.")
1959            (define-key menu-bar-search-menu [icicles]
1960              (list 'menu-item "Icicles" icicle-search-menu-map :visible 'icicle-mode))
1961            (define-key icicle-search-menu-map [icicle-goto-global-marker]
1962              '(menu-item "+ Go To Global Marker..." icicle-goto-global-marker :visible icicle-mode
1963                :enable (consp (icicle-markers global-mark-ring)) :keys "C-- C-x C-SPC"
1964                :help "Go to a global marker, choosing it by its line"))
1965            (define-key icicle-search-menu-map [icicle-goto-marker]
1966              '(menu-item "+ Go To Marker..." icicle-goto-marker :visible icicle-mode
1967                :enable (consp (icicle-markers mark-ring)) :keys "C-- C-SPC"
1968                :help "Go to a marker in this buffer, choosing it by its line"))
1969            (define-key icicle-search-menu-map [icicle-separator-goto] '("--"))
1970            (define-key icicle-search-menu-map [icicle-search-highlight-cleanup]
1971              '(menu-item "Remove Icicle-Search Highlighting..." icicle-search-highlight-cleanup
1972                :visible icicle-mode
1973                :enable (or icicle-search-overlays (overlayp icicle-search-current-overlay)
1974                         (overlayp icicle-search-refined-overlays) icicle-search-refined-overlays)
1975                :help "Remove all highlighting from the last use of `icicle-search'"))
1976            (define-key icicle-search-menu-map [icicle-compilation-search]
1977              '(menu-item "+ Search Compilation/Grep Hits (Regexp)..."
1978                icicle-compilation-search :visible icicle-mode
1979                :enable (and (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
1980                         (condition-case nil (eq (current-buffer) (compilation-find-buffer))
1981                           (error nil)))
1982                :keys "C-`" :help "Icicles search, showing the matching compilation-buffer hit"))
1983            (define-key icicle-search-menu-map [icicle-grep-saved-file-candidates]
1984              '(menu-item "Grep Saved File-Name Candidates..."
1985                icicle-grep-saved-file-candidates :visible icicle-mode
1986                :enable icicle-saved-completion-candidates
1987                :help "Run `grep' on the set of completion candidates saved using `C-M->'"))
1988            (define-key icicle-search-menu-map [icicle-imenu-non-interactive-function]
1989              '(menu-item "+ Search Non-Command Fn Definition (Regexp)..."
1990                icicle-imenu-non-interactive-function :visible icicle-mode
1991                :enable (eq major-mode 'emacs-lisp-mode)
1992                :help "Go to an Emacs non-interactive function definition with `icicle-search'"))
1993            (define-key icicle-search-menu-map [icicle-imenu-command]
1994              '(menu-item "+ Search Command Definition (Regexp)..." icicle-imenu-command
1995                :visible icicle-mode
1996                :enable (eq major-mode 'emacs-lisp-mode)
1997                :help "Go to an Emacs command definition using `icicle-search'"))
1998            (define-key icicle-search-menu-map [icicle-imenu]
1999              '(menu-item "+ Search Definition (Regexp)..." icicle-imenu :visible icicle-mode
2000                :enable imenu-generic-expression :help "Go to an Imenu entry using `icicle-search'"))
2001            (define-key icicle-search-menu-map [icicle-tags-search]
2002              '(menu-item "+ Search Tagged Files ..." icicle-tags-search :visible icicle-mode
2003                :help "Search all source files listed in tags tables for matches for a regexp"))
2004            (define-key icicle-search-menu-map [icicle-search-bookmarks-together]
2005              '(menu-item "+ Search Bookmarks Together..." icicle-search-bookmarks-together
2006                :visible (and icicle-mode (featurep 'bookmark+)) :keys "C-u C-`"
2007                :help "Search bookmarked regions (together)"))
2008            (define-key icicle-search-menu-map [icicle-search-bookmark]
2009              '(menu-item "+ Search Bookmarks Separately..." icicle-search-bookmark
2010                :visible (and icicle-mode (featurep 'bookmark+))
2011                :help "Search bookmarked text"))
2012            (define-key icicle-search-menu-map [icicle-search-file]
2013              '(menu-item "+ Search Files (Regexp)..." icicle-search-file :visible icicle-mode
2014                :help "Search multiple files completely"))
2015            (define-key icicle-search-menu-map [icicle-search-buffer]
2016              '(menu-item "+ Search Buffers (Regexp)..." icicle-search-buffer :visible icicle-mode
2017                :help "Search multiple buffers completely"))
2018            (define-key icicle-search-menu-map [icicle-search-text-property]
2019              '(menu-item "+ Search Text Property..." icicle-search-text-property
2020                :visible icicle-mode
2021                :help "Search for text that has a property with a certain value"))
2022            (define-key icicle-search-menu-map [icicle-search-word]
2023              '(menu-item "+ Search for Word..." icicle-search-word :visible icicle-mode
2024                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
2025                :help "Whole-word Icicles search"))
2026            (define-key icicle-search-menu-map [icicle-search-keywords]
2027              '(menu-item "+ Search with Keywords (Regexps)..." icicle-search-keywords
2028                :visible icicle-mode
2029                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
2030                :help "Search with one or more keywords, which can each be a regexp"))
2031            (define-key icicle-search-menu-map [icicle-search]
2032              '(menu-item "+ Search (Regexp)..." icicle-search :visible icicle-mode
2033                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
2034                :keys "C-`"
2035                :help "Search for matches, with completion, cycling, and hit replacement"))
2036            (define-key icicle-search-menu-map [icicle-occur]
2037              '(menu-item "+ Occur (Regexp)..." icicle-occur :visible icicle-mode
2038                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
2039                :help "`icicle-search' with a regexp of \".*\".  An `occur' with icompletion")))
2040           (t
2041            (define-key icicle-menu-map [icicle-search-highlight-cleanup]
2042              '(menu-item "Remove Icicle-Search Highlighting..." icicle-search-highlight-cleanup
2043                :enable (or icicle-search-overlays (overlayp icicle-search-current-overlay)
2044                         (overlayp icicle-search-refined-overlays)
2045                         icicle-search-refined-overlays)
2046                :help "Remove all highlighting from the last use of `icicle-search'"))
2047            (define-key icicle-menu-map [icicle-compilation-search]
2048              '(menu-item "+ Search Compilation/Grep Hits (Regexp)..." icicle-compilation-search
2049                :enable (and (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
2050                         (condition-case nil (eq (current-buffer) (compilation-find-buffer))
2051                           (error nil)))
2052                :help "Icicles search, showing the matching compilation-buffer hit"))
2053            (define-key icicle-menu-map [icicle-grep-saved-file-candidates]
2054              '(menu-item "Grep Saved File-Name Candidates..."
2055                icicle-grep-saved-file-candidates :enable icicle-saved-completion-candidates
2056                :help "Run `grep' on the set of completion candidates saved using `C-M->'"))
2057            (define-key icicle-menu-map [icicle-imenu-non-interactive-function]
2058              '(menu-item "Search Non-Command Fn Definition (Regexp)..."
2059                icicle-imenu-non-interactive-function :enable (eq major-mode 'emacs-lisp-mode)
2060                :help "Go to an Emacs non-interactive function definition with `icicle-search'"))
2061            (define-key icicle-menu-map [icicle-imenu-command]
2062              '(menu-item "Search Command Definition (Regexp)..." icicle-imenu-command
2063                :enable (eq major-mode 'emacs-lisp-mode)
2064                :help "Go to an Emacs command definition using `icicle-search'"))
2065            (define-key icicle-menu-map [icicle-imenu]
2066              '(menu-item "+ Search Definition (Regexp)..." icicle-imenu
2067                :enable imenu-generic-expression :help "Go to an Imenu entry using `icicle-search'"))
2068            (define-key icicle-menu-map [icicle-tags-search]
2069              '(menu-item "+ Search Tagged Files ..." icicle-tags-search
2070                :help "Search all source files listed in tags tables for matches for a regexp"))
2071            (define-key icicle-menu-map [icicle-search-bookmarks-together]
2072              '(menu-item "+ Search Bookmarks Together..." icicle-search-bookmarks-together
2073                :visible (featurep 'bookmark+) :keys "C-u C-`"
2074                :help "Search bookmarked regions (together)"))
2075            (define-key icicle-menu-map [icicle-search-bookmark]
2076              '(menu-item "+ Search Bookmarks Separately..." icicle-search-bookmark
2077                :visible (featurep 'bookmark+) :help "Search bookmarked text"))
2078            (define-key icicle-menu-map [icicle-search-file]
2079              '(menu-item "+ Search Files (Regexp)..." icicle-search-file
2080                :help "Search multiple files completely"))
2081            (define-key icicle-menu-map [icicle-search-buffer]
2082              '(menu-item "+ Search Buffers (Regexp)..." icicle-search-buffer
2083                :help "Search multiple buffers completely"))
2084            (define-key icicle-menu-map [icicle-search-text-property]
2085              '(menu-item "+ Search Text Property..." icicle-search-text-property
2086                :help "Search for text that has a property with a certain value"))
2087            (define-key icicle-menu-map [icicle-search-word]
2088              '(menu-item "+ Search for Word..." icicle-search-word
2089                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
2090                :help "Whole-word Icicles search"))
2091            (define-key icicle-menu-map [icicle-search-keywords]
2092              '(menu-item "+ Search with Keywords (Regexps)..." icicle-search-keywords
2093                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
2094                :help "Search with one or more keywords, which can each be a regexp"))
2095            (define-key icicle-menu-map [icicle-search]
2096              '(menu-item "+ Search (Regexp)..." icicle-search
2097                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
2098                :help "Search for matches, with completion, cycling, and hit replacement"))
2099            (define-key icicle-menu-map [icicle-occur]
2100              '(menu-item "+ Occur (Regexp)..." icicle-occur
2101                :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame)))
2102                :help "`icicle-search' with a regexp of \".*\".  An `occur' with icompletion")))))
2103
2104   ;; Install `Icicles' menu-bar menu.
2105   (define-key icicle-mode-map [menu-bar icicles] (cons "Icicles" icicle-menu-map))
2106
2107   ;; Optional `icicle-mode-map' bindings - governed by `icicle-top-level-key-bindings'.
2108   (icicle-bind-top-level-commands)
2109
2110   ;; Install or update `icicle-mode-map'.
2111   (if icicle-minor-mode-map-entry
2112       (setcdr icicle-minor-mode-map-entry icicle-mode-map)
2113     (setq icicle-minor-mode-map-entry  (cons 'icicle-mode icicle-mode-map))
2114     (add-to-list 'minor-mode-map-alist icicle-minor-mode-map-entry)))
2115
2116 (defun icicle-S-iso-lefttab-to-S-TAB (strg)
2117   "Return string STRG, but with \"S-iso-lefttab\" replaced by \"S-TAB\"."
2118   (replace-regexp-in-string "S-iso-lefttab" "S-TAB" strg))
2119
2120 (defun icicle-bind-other-keymap-keys ()
2121   "Bind some keys in maps other than minibuffer maps and `icicle-mode-map'"
2122
2123   ;; Bind Isearch keys.
2124   (icicle-bind-isearch-keys)
2125
2126   ;; Bind keys in Comint mode.
2127   (when (boundp 'comint-mode-map)
2128     (define-key comint-mode-map "\C-c\C-i"         'icicle-comint-command)
2129     (define-key comint-mode-map [(control ?c) tab] 'icicle-comint-command))
2130
2131   ;; Bind keys in Shell mode.
2132   (when (and (boundp 'shell-mode-map) (memq 'comint-dynamic-complete icicle-functions-to-redefine))
2133     (define-key shell-mode-map "\t" 'icicle-comint-dynamic-complete))
2134
2135   ;; Bind keys in Shell Script mode.
2136   (when (and (boundp 'sh-mode-map) (memq 'comint-dynamic-complete icicle-functions-to-redefine))
2137     (icicle-remap 'comint-dynamic-complete 'icicle-comint-dynamic-complete sh-mode-map))
2138
2139   ;; Bind keys in Ielm mode.
2140   (when (and (boundp 'ielm-map) (memq 'comint-dynamic-complete icicle-functions-to-redefine))
2141     (define-key ielm-map "\t" 'icicle-comint-dynamic-complete))
2142
2143   ;; Bind keys in Tcl mode.
2144   (when (and (boundp 'inferior-tcl-mode-map) (memq 'comint-dynamic-complete
2145                                                    icicle-functions-to-redefine))
2146     (define-key inferior-tcl-mode-map "\t" 'icicle-comint-dynamic-complete))
2147
2148   ;; Bind keys in GUD (Debugger) mode.
2149   (when (and (boundp 'gud-minibuffer-local-map) (memq 'comint-dynamic-complete-filename
2150                                                       icicle-functions-to-redefine))
2151     (define-key gud-minibuffer-local-map "\t" 'icicle-comint-dynamic-complete-filename))
2152
2153   ;; Bind some keys in `bookmark-bmenu-mode' mode (*Bookmark List*) - requires Bookmark+.
2154   (when (and (featurep 'bookmark+) (boundp 'bookmark-bmenu-mode-map))
2155     (unless (lookup-key bookmark-bmenu-mode-map [(control meta ?>)]) ; *Bookmark List* `C-M->'
2156       (define-key bookmark-bmenu-mode-map [(control meta ?>)] 'icicle-bookmark-save-marked-files))
2157     (unless (lookup-key bookmark-bmenu-mode-map [(control ?>)]) ; *Bookmark List* `C->'
2158       (define-key bookmark-bmenu-mode-map [(control ?>)] 'icicle-bookmark-save-marked-files-more))
2159     (unless (lookup-key bookmark-bmenu-mode-map [(control meta ?})]) ; *Bookmark List* `C-M-}'
2160       (define-key bookmark-bmenu-mode-map [(control meta ?})]
2161         'icicle-bookmark-save-marked-files-to-variable))
2162     (unless (lookup-key bookmark-bmenu-mode-map [(control ?})]) ; *Bookmark List* `C-}'
2163       (define-key bookmark-bmenu-mode-map [(control ?})]
2164         'icicle-bookmark-save-marked-files-as-project))
2165     (let ((defn  (lookup-key bookmark-bmenu-mode-map "\M-si"))) ; *Bookmark List* `M-s i'
2166       (unless (and defn  (not (integerp defn)))
2167         (define-key bookmark-bmenu-mode-map "\M-si" 'icicle-search-dired-marked))))    
2168
2169   ;; Bind some keys in Dired mode.
2170   (when (boundp 'dired-mode-map)
2171     (unless (lookup-key dired-mode-map [(control meta ?<)]) ; Dired `C-M-<'
2172       (define-key dired-mode-map [(control meta ?<)]
2173         'icicle-dired-saved-file-candidates-other-window))
2174     (unless (lookup-key dired-mode-map [(control ?{)]) ; Dired `C-{'
2175       (define-key dired-mode-map [(control ?{)] 'icicle-dired-project-other-window))
2176     (unless (lookup-key dired-mode-map [(control meta ?>)]) ; Dired `C-M->'
2177       (define-key dired-mode-map [(control meta ?>)] 'icicle-dired-save-marked))
2178     (unless (lookup-key dired-mode-map [(control ?>)]) ; Dired `C->'
2179       (define-key dired-mode-map [(control ?>)] 'icicle-dired-save-marked-more))
2180     (unless (lookup-key dired-mode-map [(control meta ?})]) ; Dired `C-M-}'
2181       (define-key dired-mode-map [(control meta ?})] 'icicle-dired-save-marked-to-variable))
2182     (unless (lookup-key dired-mode-map [(control ?})]) ; Dired `C-}'
2183       (define-key dired-mode-map [(control ?})] 'icicle-dired-save-marked-as-project))
2184     (let ((defn  (lookup-key dired-mode-map "\M-si"))) ; Dired `M-s i'
2185       (unless (and defn  (not (integerp defn)))
2186         (define-key dired-mode-map "\M-si" 'icicle-search-dired-marked))))
2187
2188   ;; Bind keys in Ibuffer mode.
2189   (when (boundp 'ibuffer-mode-map)
2190     (let ((defn  (lookup-key ibuffer-mode-map "\M-si"))) ; Ibuffer `M-s i'
2191       (unless (and defn  (not (integerp defn)))
2192         (define-key ibuffer-mode-map "\M-si" 'icicle-search-ibuffer-marked))
2193       (unless icicle-touche-pas-aux-menus-flag ; Use Ibuffer's `Operate' menu.
2194         (define-key ibuffer-mode-operate-map [icicle-search-ibuffer-marked]
2195           '(menu-item "Icicles Search (and Replace)..." icicle-search-ibuffer-marked
2196             :visible icicle-mode :enable (eq major-mode 'ibuffer-mode))))))
2197
2198   ;; Bind keys in Buffer Menu mode.
2199   (when (boundp 'Buffer-menu-mode-map)
2200     (let ((defn  (lookup-key Buffer-menu-mode-map "\M-si"))) ; Buffer-Menu `M-s i'
2201       (unless (and defn  (not (integerp defn)))
2202         (define-key Buffer-menu-mode-map "\M-si" 'icicle-search-buff-menu-marked))))
2203
2204   ;; Bind `S-TAB' in major maps, for key completion.
2205   (when (fboundp 'map-keymap)           ; Emacs 22+.
2206     (icicle-bind-key-completion-keys-in-keymaps-from (current-global-map))
2207     (mapcar #'icicle-bind-key-completion-keys-for-map-var icicle-keymaps-for-key-completion))
2208
2209   ;; Prevent `this-command' from being set to `handle-switch-frame'.
2210   (define-key global-map [handle-switch-frame] 'icicle-skip-this-command)
2211   (define-key global-map [switch-frame] 'icicle-handle-switch-frame))
2212
2213 ;;;###autoload
2214 (defun icicle-bind-isearch-keys ()
2215   "Bind Icicles Isearch commands."
2216   (dolist (key icicle-search-from-isearch-keys)
2217     (define-key isearch-mode-map key 'icicle-search-w-isearch-string)) ; In `icicles-cmd2.el'.
2218   (dolist (key icicle-isearch-complete-keys)
2219     (define-key isearch-mode-map key 'icicle-isearch-complete))
2220   (cond ((fboundp 'isearch-moccur)      ; In `moccur.el'.
2221          (define-key isearch-mode-map (kbd "C-o") 'isearch-moccur))
2222         ((fboundp 'isearch-occur)       ; In `occur-schroeder.el'.
2223          (define-key isearch-mode-map (kbd "C-o") 'isearch-occur))))
2224
2225 (defun icicle-bind-key-completion-keys-for-map-var (keymap-var)
2226   "Bind `S-TAB' in keymaps accessible from keymap KEYMAP-VAR.
2227 KEYMAP-VAR should be bound to a keymap that has at least one prefix
2228 keymap.  If KEYMAP-VAR is not bound to a keymap, it is ignored."
2229   (let ((temp  keymap-var))
2230     (when (boundp temp)
2231       (setq temp  (symbol-value temp))
2232       (when (keymapp temp) (icicle-bind-key-completion-keys-in-keymaps-from temp)))))
2233
2234 (defun icicle-bind-key-completion-keys-in-keymaps-from (map)
2235   "Bind keys in `icicle-key-complete-keys' to `icicle-complete-keys'.
2236 Each key in `icicle-complete-keys' is bound in all keymaps accessible
2237 from keymap MAP."
2238   (dolist (key+map  (accessible-keymaps map))
2239     (let ((map  (cdr key+map)))
2240       ;; We could try to exclude menu maps, by testing (not (keymap-prompt map)).
2241       ;; But we want to include at least some menu maps - those, such as `facemenu-keymap',
2242       ;; that are bound to keyboard keys. (when (and (keymapp map) (not (keymap-prompt map)))...)
2243       (when (keymapp map)
2244         (dolist (key  icicle-key-complete-keys)
2245           (when (or icicle-complete-key-anyway-flag (not (lookup-key map key)))
2246             (condition-case nil (define-key map key 'icicle-complete-keys) (error nil))))))))
2247
2248 (defun icicle-restore-other-keymap-keys ()
2249   "Restore some bindings changed by `icicle-bind-other-keymap-keys'."
2250
2251   ;; Unbind Isearch keys.
2252   (icicle-unbind-isearch-keys)
2253
2254   ;; Unbind keys in Comint mode.
2255   (when (boundp 'comint-mode-map)
2256     (define-key comint-mode-map "\C-c\C-i"         nil)
2257     (define-key comint-mode-map [(control ?c) tab] nil))
2258
2259   ;; Unbind keys in Shell mode.
2260   (when (and (boundp 'shell-mode-map) (memq 'icicle-comint-dynamic-complete
2261                                             icicle-functions-to-redefine))
2262     (define-key shell-mode-map "\t" (if (> emacs-major-version 23)
2263                                         'completion-at-point
2264                                       'comint-dynamic-complete)))
2265
2266   ;; Unbind keys in Shell Script mode.
2267   (when (and (boundp 'sh-mode-map) (memq 'icicle-comint-dynamic-complete
2268                                          icicle-functions-to-redefine))
2269     (icicle-unmap 'comint-dynamic-complete sh-mode-map 'icicle-comint-dynamic-complete))
2270
2271   ;; Unbind keys in Ielm mode.
2272   (when (and (boundp 'ielm-map) (memq 'icicle-comint-dynamic-complete
2273                                       icicle-functions-to-redefine))
2274     (define-key ielm-map "\t" 'comint-dynamic-complete))
2275
2276   ;; Unbind keys in Tcl mode.
2277   (when (and (boundp 'inferior-tcl-mode-map) (memq 'icicle-comint-dynamic-complete
2278                                                    icicle-functions-to-redefine))
2279     (define-key inferior-tcl-mode-map "\t" 'comint-dynamic-complete))
2280
2281   ;; Bind keys in GUD (Debugger) mode.
2282   (when (and (boundp 'gud-minibuffer-local-map) (memq 'icicle-comint-dynamic-complete-filename
2283                                                       icicle-functions-to-redefine))
2284     (define-key gud-minibuffer-local-map "\t" 'comint-dynamic-complete-filename))
2285
2286   ;; Unbind keys in `bookmark-bmenu-mode' mode (*Bookmark List*) - requires Bookmark+.
2287   (when (and (featurep 'bookmark+) (boundp 'bookmark-bmenu-mode-map))
2288     (define-key bookmark-bmenu-mode-map [(control meta ?>)] nil)
2289     (define-key bookmark-bmenu-mode-map [(control ?>)] nil)
2290     (define-key bookmark-bmenu-mode-map [(control meta ?})] nil)
2291     (define-key bookmark-bmenu-mode-map [(control ?})] nil)
2292     (define-key bookmark-bmenu-mode-map "\M-si" nil))
2293
2294   ;; Unbind keys in Dired mode.
2295   (when (boundp 'dired-mode-map)
2296     (define-key dired-mode-map [(control meta ?<)] nil)
2297     (define-key dired-mode-map [(control ?{)]      nil)
2298     (define-key dired-mode-map [(control meta ?>)] nil)
2299     (define-key dired-mode-map [(control ?>)]      nil)
2300     (define-key dired-mode-map [(control meta ?})] nil)
2301     (define-key dired-mode-map [(control ?})]      nil)
2302     (define-key dired-mode-map "\M-si"             nil))
2303
2304   ;; Unbind keys in Ibuffer mode.
2305   (when (boundp 'ibuffer-mode-map)
2306     (define-key ibuffer-mode-map "\M-si" nil))
2307
2308   ;; Unbind keys in Buffer Menu mode.
2309   (when (boundp 'Buffer-menu-mode-map)
2310     (define-key Buffer-menu-mode-map "\M-si" nil))
2311
2312   ;; Unbind `S-TAB' in major maps.
2313   (when (fboundp 'map-keymap)           ; Emacs 22+.
2314     (icicle-unbind-key-completion-keys-in-keymaps-from (current-global-map))
2315     (mapcar #'icicle-unbind-key-completion-keys-for-map-var icicle-keymaps-for-key-completion))
2316
2317   ;; Restore prevention of `this-command' being `handle-switch-frame'.
2318   (define-key global-map [handle-switch-frame] nil)
2319   (define-key global-map [switch-frame] 'handle-switch-frame))
2320
2321 (defun icicle-unbind-isearch-keys ()
2322   "Unbind Icicles Isearch commands."
2323   (dolist (key icicle-search-from-isearch-keys) (define-key isearch-mode-map key nil))
2324   (dolist (key icicle-isearch-complete-keys) (define-key isearch-mode-map key nil))
2325   (define-key isearch-mode-map "\M-\t" 'isearch-complete)
2326   (when (fboundp 'isearch-moccur)       ; Restore `moccur.el' binding.
2327     (define-key isearch-mode-map (kbd "M-o") 'isearch-moccur))
2328   (define-key isearch-mode-map (kbd "C-o") nil))
2329
2330 (defun icicle-unbind-key-completion-keys-for-map-var (keymap-var)
2331   "Unbind `S-TAB' in keymaps accessible from keymap KEYMAP-VAR.
2332 KEYMAP-VAR should be bound to a keymap that has at least one prefix
2333 keymap.  If KEYMAP-VAR is not bound to a keymap, it is ignored."
2334   (let ((temp  keymap-var))
2335     (when (boundp temp)
2336       (setq temp  (symbol-value temp))
2337       (when (keymapp temp) (icicle-unbind-key-completion-keys-in-keymaps-from temp)))))
2338
2339 (defun icicle-unbind-key-completion-keys-in-keymaps-from (map)
2340   "Unbind `icicle-key-complete-keys' in keymaps accessible from MAP."
2341   (dolist (key+map (accessible-keymaps map))
2342     (let ((map  (cdr key+map)))
2343       (when (and (keymapp map) (not (stringp (car-safe (last map))))) ; Try to exclude menu maps.
2344         (dolist (key icicle-key-complete-keys)
2345           (when (eq (lookup-key map key) 'icicle-complete-keys)
2346             (condition-case nil (define-key map key nil) (error nil))))))))
2347  
2348 ;;(@* "Other Icicles functions that define Icicle mode")
2349
2350 ;;; Other Icicles functions that define Icicle mode ------------------
2351
2352 ;;;###autoload
2353 (defun icicle-skip-this-command ()
2354   "Prevent `handle-switch-frame' from being added to `this-command'."
2355   (interactive)
2356   (setq this-command  last-command))
2357
2358 ;;;###autoload
2359 (defun icicle-handle-switch-frame (event)
2360   "Call `handle-switch-frame', but don't add it to `this-command'."
2361   (interactive "e")
2362   (handle-switch-frame event)
2363   (setq this-command  last-command))
2364
2365 (defun icicle-define-minibuffer-maps (turn-on-p)
2366   "Define keymaps for the minibuffer and buffer `*Completions*'."
2367   (cond
2368     (turn-on-p                          ; TURN IT ON ********************************
2369
2370      ;; `minibuffer-local-map': default minibuffer map.
2371      (let ((map  minibuffer-local-map))
2372
2373        ;; Menu-bar `Minibuf' menu.
2374        (define-key map [menu-bar minibuf quit] ; Replace `keyboard-escape-quit'
2375          '(menu-item "Quit" icicle-abort-recursive-edit
2376            :help "Cancel minibuffer input or recursive edit"))
2377        (define-key map [menu-bar minibuf return]
2378          '(menu-item "Enter" exit-minibuffer
2379            :help "Terminate input and exit minibuffer" :keys "RET"))
2380        (define-key map [menu-bar minibuf separator-help] '("--"))
2381        (define-key map [menu-bar minibuf completion-help]
2382          '(menu-item "Icicles Help" icicle-minibuffer-help
2383            :help "Display help for minibuffer input and completion"))
2384        (define-key map [menu-bar minibuf separator-last] '("--"))
2385        (define-key map [menu-bar minibuf icicle-toggle-search-complementing-domain]
2386          '(menu-item "Toggle Searching Complement"
2387            icicle-toggle-search-complementing-domain
2388            :help "Toggle `icicle-search-complement-domain-p'" :keys "C-M-~"))
2389        (define-key map [menu-bar minibuf icicle-toggle-highlight-all-current]
2390          '(menu-item "Toggle All-Current Icicle-Search Highlighting"
2391            icicle-toggle-highlight-all-current :enable icicle-searching-p
2392            :help "Toggle `icicle-search-highlight-all-current-flag'" :keys "C-^"))
2393        (define-key map [menu-bar minibuf icicle-regexp-quote-input]
2394          '(menu-item "Regexp-Quote Input" icicle-regexp-quote-input
2395            :enable (with-current-buffer (window-buffer (minibuffer-window))
2396                      (not (zerop (buffer-size))))
2397            :help "Regexp-quote current input or its active region, then apropos-complete"
2398            :keys "M-%"))
2399        (define-key map [menu-bar minibuf separator-set2] '("--"))
2400        (define-key map [menu-bar minibuf icicle-clear-current-history]
2401          '(menu-item "Clear History Entries" icicle-clear-current-history
2402            :help "Clear current minibuffer history of selected entries"))
2403        (define-key map [menu-bar minibuf icicle-erase-minibuffer]
2404          '(menu-item "Delete from History" icicle-erase-minibuffer-or-history-element
2405            :visible (memq last-command
2406                      '(previous-history-element next-history-element
2407                        icicle-erase-minibuffer-or-history-element
2408                        previous-matching-history-element next-matching-history-element))
2409            :help "Delete current history element (in minibuffer now)" :keys "M-k"))
2410        (define-key map [menu-bar minibuf icicle-delete-history-element]
2411          '(menu-item "Clear (Erase) Minibuffer" icicle-erase-minibuffer-or-history-element
2412            :visible (not (memq last-command
2413                           '(previous-history-element next-history-element
2414                             icicle-erase-minibuffer-or-history-element
2415                             previous-matching-history-element next-matching-history-element)))
2416            :help "Erase the Minibuffer" :keys "M-k"))
2417        (define-key map [menu-bar minibuf icicle-insert-list-join-string]
2418          '(menu-item "Insert Join-String" icicle-insert-list-join-string
2419            :help "Insert `icicle-list-join-string' into the minibuffer"))
2420        (define-key map [menu-bar minibuf icicle-insert-key-description]
2421          '(menu-item "Insert Key Description" icicle-insert-key-description
2422            :visible (not icicle-searching-p) :keys "M-q"
2423            :help "Read key and insert its description - e.g., reading ^F inserts `C-f'"))
2424        (define-key map [menu-bar minibuf icicle-insert-history-element]
2425          '(menu-item "Insert Past Input using Completion" icicle-insert-history-element
2426            :enable (consp (symbol-value minibuffer-history-variable))
2427            :help "Use completion to insert a previous input into the minibuffer"))
2428        (define-key map [menu-bar minibuf icicle-insert-string-from-a-var]
2429          '(menu-item "Insert String from a Variable..." icicle-insert-string-from-variable
2430            :visible current-prefix-arg :keys "C-="
2431            :help "Read a variable name and insert its string value into the minibuffer"))
2432        (define-key map [menu-bar minibuf icicle-insert-string-from-std-var]
2433          '(menu-item "Insert `icicle-input-string'" icicle-insert-string-from-variable
2434            :visible (not current-prefix-arg) :keys "C-="
2435            :help "Insert text from variable `icicle-input-string' into the minibuffer"))
2436        (define-key map [menu-bar minibuf icicle-insert-string-at-point]
2437          '(menu-item "Insert Text from Point" icicle-insert-string-at-point
2438            :help "Insert text at or near the cursor into the minibuffer"))
2439        (define-key map [menu-bar minibuf icicle-completing-read+insert]
2440          '(menu-item "Insert On-Demand Completion" icicle-completing-read+insert
2441            :visible (consp icicle-completing-read+insert-candidates)
2442            :help "Read and insert something using (lax) completion"))
2443        (define-key map [menu-bar minibuf icicle-read+insert-file-name]
2444          '(menu-item "Insert File Name" icicle-read+insert-file-name
2445            :help "Read and insert a file name using (lax) completion"))
2446
2447        (define-key map [(control ??)]            'icicle-minibuffer-help) ; `C-?'
2448        (define-key map [(control ?g)]            'icicle-abort-recursive-edit) ; `C-g'
2449        (define-key map [M-S-backspace]           'icicle-erase-minibuffer) ; `M-S-backspace'
2450        (define-key map [M-S-delete]              'icicle-erase-minibuffer) ; `M-S-delete'
2451        (define-key map [(meta ?.)]               'icicle-insert-string-at-point) ; `M-.'
2452        (define-key map "\C-x\C-f"                'icicle-resolve-file-name) ; `C-x C-f'
2453        (define-key map [(control ?=)]            'icicle-insert-string-from-variable) ; `C-='
2454        (define-key map [(meta ?o)]               'icicle-insert-history-element) ; `M-o'
2455        (define-key map [(meta ?i)]               'icicle-clear-current-history) ; `M-i'
2456        (define-key map [(meta ?k)]               'icicle-erase-minibuffer-or-history-element) ; `M-k'
2457        (define-key map [(meta ?:)]               'icicle-pp-eval-expression-in-minibuffer) ; `M-:'
2458        (define-key map [(control ?a)]            'icicle-beginning-of-line+) ; `C-a'
2459        (define-key map [(control ?e)]            'icicle-end-of-line+) ; `C-e'
2460        (define-key map [(control meta ?v)]       'icicle-scroll-forward) ; `C-M-v'
2461        (define-key map [(control meta shift ?v)] 'icicle-scroll-backward) ; `C-M-S-v' (aka `C-M-V')
2462        (dolist (key  icicle-completing-read+insert-keys)
2463          (define-key map key 'icicle-completing-read+insert)) ; `C-M-S-c'
2464        (dolist (key  icicle-read+insert-file-name-keys)
2465          (define-key map key 'icicle-read+insert-file-name)) ; `C-M-S-f'
2466        (define-key map "\n"                      'icicle-insert-newline-in-minibuffer) ; `C-j'
2467        (when (fboundp 'yank-secondary)  ; In `second-sel.el'.
2468          (define-key map "\C-\M-y" 'icicle-yank-secondary))) ; `C-M-y'
2469
2470      ;; `minibuffer-local-ns-map': default minibuffer map when spaces are not allowed.
2471      ;; In Emacs 22+, local is parent of local-ns.
2472      (unless (eq minibuffer-local-map (keymap-parent minibuffer-local-ns-map))
2473        (let ((map  minibuffer-local-ns-map))
2474          (define-key map [menu-bar minibuf quit] ; Replace `keyboard-escape-quit'
2475            '(menu-item "Quit" icicle-abort-recursive-edit
2476              :help "Cancel minibuffer input or recursive edit"))
2477          (define-key map [menu-bar minibuf return]
2478            '(menu-item "Enter" exit-minibuffer
2479              :help "Terminate input and exit minibuffer" :keys "RET"))
2480          (define-key map [menu-bar minibuf separator-help] '("--"))
2481          (define-key map [menu-bar minibuf completion-help]
2482            '(menu-item "Icicles Help" icicle-minibuffer-help
2483              :help "Display help for minibuffer input and completion"))
2484          (define-key map [menu-bar minibuf separator-last] '("--"))
2485          (define-key map [menu-bar minibuf icicle-toggle-search-complementing-domain]
2486            '(menu-item "Toggle Searching Complement"
2487              icicle-toggle-search-complementing-domain
2488              :help "Toggle `icicle-search-complement-domain-p'" :keys "C-M-~"))
2489          (define-key map [menu-bar minibuf icicle-toggle-highlight-all-current]
2490            '(menu-item "Toggle All-Current Icicle-Search Highlighting"
2491              icicle-toggle-highlight-all-current :enable icicle-searching-p
2492              :help "Toggle `icicle-search-highlight-all-current-flag'" :keys "C-^"))
2493          (define-key map [menu-bar minibuf icicle-regexp-quote-input]
2494            '(menu-item "Regexp-Quote Input" icicle-regexp-quote-input
2495              :enable (with-current-buffer (window-buffer (minibuffer-window))
2496                        (not (zerop (buffer-size))))
2497              :help "Regexp-quote current input or its active region, then apropos-complete"
2498              :keys "M-%"))
2499          (define-key map [menu-bar minibuf separator-set2] '("--"))
2500          (define-key map [menu-bar minibuf icicle-clear-current-history]
2501            '(menu-item "Clear History Entries" icicle-clear-current-history
2502              :help "Clear current minibuffer history of selected entries"))
2503          (define-key map [menu-bar minibuf icicle-erase-minibuffer]
2504            '(menu-item "Delete from History" icicle-erase-minibuffer-or-history-element
2505              :visible (memq last-command
2506                        '(previous-history-element next-history-element
2507                          icicle-erase-minibuffer-or-history-element
2508                          previous-matching-history-element next-matching-history-element))
2509              :help "Delete current history element (in minibuffer now)" :keys "M-k"))
2510          (define-key map [menu-bar minibuf icicle-delete-history-element]
2511            '(menu-item "Clear (Erase) Minibuffer" icicle-erase-minibuffer-or-history-element
2512              :visible (not (memq last-command
2513                             '(previous-history-element next-history-element
2514                               icicle-erase-minibuffer-or-history-element
2515                               previous-matching-history-element next-matching-history-element)))
2516              :help "Erase the Minibuffer" :keys "M-k"))
2517          (define-key map [menu-bar minibuf icicle-insert-list-join-string]
2518            '(menu-item "Insert Join-String" icicle-insert-list-join-string
2519              :help "Insert `icicle-list-join-string' into the minibuffer"))
2520          (define-key map [menu-bar minibuf icicle-insert-key-description]
2521            '(menu-item "Insert Key Description" icicle-insert-key-description
2522              :visible (not icicle-searching-p) :keys "M-q"
2523              :help "Read key and insert its description - e.g., reading ^F inserts `C-f'"))
2524          (define-key map [menu-bar minibuf icicle-insert-history-element]
2525            '(menu-item "Insert Past Input using Completion" icicle-insert-history-element
2526              :enable (consp (symbol-value minibuffer-history-variable))
2527              :help "Use completion to insert a previous input into the minibuffer"))
2528          (define-key map [menu-bar minibuf icicle-insert-string-from-a-var]
2529            '(menu-item "Insert String from a Variable..." icicle-insert-string-from-variable
2530              :visible current-prefix-arg :keys "C-="
2531              :help "Read a variable name and insert its string value into the minibuffer"))
2532          (define-key map [menu-bar minibuf icicle-insert-string-from-std-var]
2533            '(menu-item "Insert `icicle-input-string'" icicle-insert-string-from-variable
2534              :visible (not current-prefix-arg) :keys "C-="
2535              :help "Insert text from variable `icicle-input-string' into the minibuffer"))
2536          (define-key map [menu-bar minibuf icicle-insert-string-at-point]
2537            '(menu-item "Insert Text from Point" icicle-insert-string-at-point
2538              :help "Insert text at or near the cursor into the minibuffer"))
2539          (define-key map [menu-bar minibuf icicle-completing-read+insert]
2540            '(menu-item "Insert On-Demand Completion" icicle-completing-read+insert
2541              :visible (consp icicle-completing-read+insert-candidates)
2542              :help "Read and insert something using (lax) completion"))
2543          (define-key map [menu-bar minibuf icicle-read+insert-file-name]
2544            '(menu-item "Insert File Name" icicle-read+insert-file-name
2545              :help "Read and insert a file name using (lax) completion"))
2546
2547          (define-key map [(control ??)]            'icicle-minibuffer-help) ; `C-?'
2548          (define-key map [(control ?g)]            'icicle-abort-recursive-edit) ; `C-g'
2549          (define-key map [M-S-backspace]           'icicle-erase-minibuffer) ; `M-S-backspace'
2550          (define-key map [M-S-delete]              'icicle-erase-minibuffer) ; `M-S-delete'
2551          (define-key map [(meta ?.)]               'icicle-insert-string-at-point) ; `M-.'
2552          (define-key map "\C-x\C-f"                'icicle-resolve-file-name) ; `C-x C-f'
2553          (define-key map [(control ?=)]            'icicle-insert-string-from-variable) ; `C-='
2554          (define-key map [(meta ?o)]               'icicle-insert-history-element) ; `M-o'
2555          (define-key map [(meta ?i)]               'icicle-clear-current-history) ; `M-i'
2556          (define-key map [(meta ?k)]           'icicle-erase-minibuffer-or-history-element) ; `M-k'
2557          (define-key map [(meta ?:)]              'icicle-pp-eval-expression-in-minibuffer) ; `M-:'
2558          (define-key map [(control ?a)]            'icicle-beginning-of-line+) ; `C-a'
2559          (define-key map [(control ?e)]            'icicle-end-of-line+) ; `C-e'
2560          (define-key map [(control meta ?v)]       'icicle-scroll-forward) ; `C-M-v'
2561          (define-key map [(control meta shift ?v)] 'icicle-scroll-backward) ; `C-M-S-v' (aka `C-M-V')
2562          (dolist (key  icicle-completing-read+insert-keys)
2563            (define-key map key 'icicle-completing-read+insert)) ; `C-M-S-c'
2564          (dolist (key  icicle-read+insert-file-name-keys)
2565            (define-key map key 'icicle-read+insert-file-name)) ; `C-M-S-f'
2566          (define-key map "\n"                      'icicle-insert-newline-in-minibuffer) ; `C-j'
2567          (when (fboundp 'yank-secondary) ; In `second-sel.el'.
2568            (define-key map "\C-\M-y" 'icicle-yank-secondary)))) ; `C-M-y'
2569
2570      ;; `minibuffer-local-isearch-map': minibuffer map for editing isearch strings.
2571      ;; In Emacs 21+, local is parent of local-isearch.
2572      (unless (eq minibuffer-local-map (keymap-parent minibuffer-local-isearch-map))
2573        (let ((map  minibuffer-local-isearch-map))
2574          (define-key map [menu-bar minibuf quit] ; Replace `keyboard-escape-quit'
2575            '(menu-item "Quit" icicle-abort-recursive-edit
2576              :help "Cancel minibuffer input or recursive edit"))
2577          (define-key map [menu-bar minibuf return]
2578            '(menu-item "Enter" exit-minibuffer
2579              :help "Terminate input and exit minibuffer" :keys "RET"))
2580          (define-key map [menu-bar minibuf separator-help] '("--"))
2581          (define-key map [menu-bar minibuf completion-help]
2582            '(menu-item "Icicles Help" icicle-minibuffer-help
2583              :help "Display help for minibuffer input and completion"))
2584          (define-key map [menu-bar minibuf separator-last] '("--"))
2585          (define-key map [menu-bar minibuf icicle-toggle-search-complementing-domain]
2586            '(menu-item "Toggle Searching Complement"
2587              icicle-toggle-search-complementing-domain
2588              :help "Toggle `icicle-search-complement-domain-p'" :keys "C-M-~"))
2589          (define-key map [menu-bar minibuf icicle-toggle-highlight-all-current]
2590            '(menu-item "Toggle All-Current Icicle-Search Highlighting"
2591              icicle-toggle-highlight-all-current :enable icicle-searching-p
2592              :help "Toggle `icicle-search-highlight-all-current-flag'" :keys "C-^"))
2593          (define-key map [menu-bar minibuf icicle-regexp-quote-input]
2594            '(menu-item "Regexp-Quote Input" icicle-regexp-quote-input
2595              :enable (with-current-buffer (window-buffer (minibuffer-window))
2596                        (not (zerop (buffer-size))))
2597              :help "Regexp-quote current input or its active region, then apropos-complete"
2598              :keys "M-%"))
2599          (define-key map [menu-bar minibuf separator-set2] '("--"))
2600          (define-key map [menu-bar minibuf icicle-clear-current-history]
2601            '(menu-item "Clear History Entries" icicle-clear-current-history
2602              :help "Clear current minibuffer history of selected entries"))
2603          (define-key map [menu-bar minibuf icicle-erase-minibuffer]
2604            '(menu-item "Delete from History" icicle-erase-minibuffer-or-history-element
2605              :visible (memq last-command
2606                        '(previous-history-element next-history-element
2607                          icicle-erase-minibuffer-or-history-element
2608                          previous-matching-history-element next-matching-history-element))
2609              :help "Delete current history element (in minibuffer now)" :keys "M-k"))
2610          (define-key map [menu-bar minibuf icicle-delete-history-element]
2611            '(menu-item "Clear (Erase) Minibuffer" icicle-erase-minibuffer-or-history-element
2612              :visible (not (memq last-command
2613                             '(previous-history-element next-history-element
2614                               icicle-erase-minibuffer-or-history-element
2615                               previous-matching-history-element next-matching-history-element)))
2616              :help "Erase the Minibuffer" :keys "M-k"))
2617          (define-key map [menu-bar minibuf icicle-insert-list-join-string]
2618            '(menu-item "Insert Join-String" icicle-insert-list-join-string
2619              :help "Insert `icicle-list-join-string' into the minibuffer"))
2620          (define-key map [menu-bar minibuf icicle-insert-key-description]
2621            '(menu-item "Insert Key Description" icicle-insert-key-description
2622              :visible (not icicle-searching-p) :keys "M-q"
2623              :help "Read key and insert its description - e.g., reading ^F inserts `C-f'"))
2624          (define-key map [menu-bar minibuf icicle-insert-history-element]
2625            '(menu-item "Insert Past Input using Completion" icicle-insert-history-element
2626              :enable (consp (symbol-value minibuffer-history-variable))
2627              :help "Use completion to insert a previous input into the minibuffer"))
2628          (define-key map [menu-bar minibuf icicle-insert-string-from-a-var]
2629            '(menu-item "Insert String from a Variable..." icicle-insert-string-from-variable
2630              :visible current-prefix-arg :keys "C-="
2631              :help "Read a variable name and insert its string value into the minibuffer"))
2632          (define-key map [menu-bar minibuf icicle-insert-string-from-std-var]
2633            '(menu-item "Insert `icicle-input-string'" icicle-insert-string-from-variable
2634              :visible (not current-prefix-arg) :keys "C-="
2635              :help "Insert text from variable `icicle-input-string' into the minibuffer"))
2636          (define-key map [menu-bar minibuf icicle-insert-string-at-point]
2637            '(menu-item "Insert Text from Point" icicle-insert-string-at-point
2638              :help "Insert text at or near the cursor into the minibuffer"))
2639          (define-key map [menu-bar minibuf icicle-completing-read+insert]
2640            '(menu-item "Insert On-Demand Completion" icicle-completing-read+insert
2641              :visible (consp icicle-completing-read+insert-candidates)
2642              :help "Read and insert something using (lax) completion"))
2643          (define-key map [menu-bar minibuf icicle-read+insert-file-name]
2644            '(menu-item "Insert File Name" icicle-read+insert-file-name
2645              :help "Read and insert a file name using (lax) completion"))
2646
2647          (define-key map [(control ??)]            'icicle-minibuffer-help) ; `C-?'
2648          (define-key map [(control ?g)]            'icicle-abort-recursive-edit) ; `C-g'
2649          (define-key map [M-S-backspace]           'icicle-erase-minibuffer) ; `M-S-backspace'
2650          (define-key map [M-S-delete]              'icicle-erase-minibuffer) ; `M-S-delete'
2651          (define-key map [(meta ?.)]               'icicle-insert-string-at-point) ; `M-.'
2652          (define-key map "\C-x\C-f"                'icicle-resolve-file-name) ; `C-x C-f'
2653          (define-key map [(control ?=)]            'icicle-insert-string-from-variable) ; `C-='
2654          (define-key map [(meta ?o)]               'icicle-insert-history-element) ; `M-o'
2655          (define-key map [(meta ?i)]               'icicle-clear-current-history) ; `M-i'
2656          (define-key map [(meta ?k)]           'icicle-erase-minibuffer-or-history-element) ; `M-k'
2657          (define-key map [(meta ?:)]              'icicle-pp-eval-expression-in-minibuffer) ; `M-:'
2658          (define-key map [(control ?a)]            'icicle-beginning-of-line+) ; `C-a'
2659          (define-key map [(control ?e)]            'icicle-end-of-line+) ; `C-e'
2660          (define-key map [(control meta ?v)]       'icicle-scroll-forward) ; `C-M-v'
2661          (define-key map [(control meta shift ?v)] 'icicle-scroll-backward) ; `C-M-S-v' (aka `C-M-V')
2662          (dolist (key  icicle-completing-read+insert-keys)
2663            (define-key map key 'icicle-completing-read+insert)) ; `C-M-S-c'
2664          (dolist (key  icicle-read+insert-file-name-keys)
2665            (define-key map key 'icicle-read+insert-file-name)) ; `C-M-S-f'
2666          (define-key map "\n"                      'icicle-insert-newline-in-minibuffer) ; `C-j'
2667          (when (fboundp 'yank-secondary) ; In `second-sel.el'.
2668            (define-key map "\C-\M-y" 'icicle-yank-secondary)))) ; `C-M-y'
2669
2670      ;; `minibuffer-local-completion-map': completion map.
2671      (icicle-bind-completion-keys minibuffer-local-completion-map)
2672
2673      ;; `minibuffer-local-must-match-map': must-match map.
2674      ;; In Emacs 22+, local-completion is parent of local-must-match
2675      (if (not (eq minibuffer-local-completion-map (keymap-parent minibuffer-local-must-match-map)))
2676          (icicle-bind-completion-keys minibuffer-local-must-match-map)
2677        (define-key minibuffer-local-must-match-map [(control ?g)]
2678          'icicle-abort-recursive-edit)  ; `C-g' - need it anyway, even if inherit completion map.
2679        (dolist (key  icicle-completing-read+insert-keys)
2680          (define-key minibuffer-local-must-match-map key 'icicle-completing-read+insert)) ; `C-M-S-c'
2681        (dolist (key  icicle-read+insert-file-name-keys)
2682          (define-key minibuffer-local-must-match-map key 'icicle-read+insert-file-name)) ; `C-M-S-f'
2683        ;; Override the binding of `C-j' to `minibuffer-complete-and-exit'.
2684        (define-key minibuffer-local-must-match-map "\n"
2685          'icicle-insert-newline-in-minibuffer)) ; `C-j' (newline)
2686      (define-key minibuffer-local-must-match-map [S-return] ; `S-RET'
2687        'icicle-apropos-complete-and-exit)
2688
2689      ;; `completion-list-mode-map': map for `*Completions*' buffer.
2690      ;; Abort on `C-g' or `q'.  Switch to minibuffer on `C-insert'.  Do not allow normal input.
2691      (let ((map  completion-list-mode-map))
2692        (define-key map [(control ??)]     'icicle-minibuffer-help) ; `C-?'
2693        (define-key map [(control ?g)]     'icicle-abort-recursive-edit) ; `C-g'
2694        (define-key map "q"                'icicle-abort-recursive-edit) ; `q'
2695        (define-key map [(control insert)] 'icicle-insert-completion) ; `C-insert'
2696        (define-key map [down]             'icicle-next-line) ; `down'
2697        (define-key map [up]               'icicle-previous-line) ; `up'
2698        (define-key map [right]            'icicle-move-to-next-completion) ; `right'
2699        (define-key map [left]             'icicle-move-to-previous-completion) ; `left'
2700        (dolist (key icicle-previous-candidate-keys)
2701          (define-key map key 'icicle-move-to-previous-completion)) ; `S-TAB'
2702        (define-key map [(control ?i)]     'icicle-move-to-next-completion) ; `TAB'
2703        (define-key map [tab]              'icicle-move-to-next-completion) ; `TAB'
2704        (when (boundp 'mouse-wheel-down-event) ; Emacs 22+ -  `wheel-down', `wheel-up'
2705          (define-key map (vector mouse-wheel-down-event) 'icicle-scroll-Completions-backward)
2706          (define-key map (vector mouse-wheel-up-event) 'icicle-scroll-Completions-forward))
2707        (define-key map [S-down-mouse-2]   'icicle-mouse-remove-candidate) ; `S-mouse-2'
2708        (define-key map [S-mouse-2]        'ignore)
2709        (define-key map [C-S-down-mouse-2] 'icicle-mouse-candidate-alt-action) ; `C-S-mouse-2'
2710        (define-key map [C-S-mouse-2]      'ignore)
2711        (define-key map [C-down-mouse-2]   'icicle-mouse-candidate-action) ; `C-mouse-2'
2712        (define-key map [C-mouse-2]        'ignore)
2713        (define-key map [C-M-return]       'icicle-help-on-candidate) ; `C-M-RET'
2714        (define-key map [C-M-down-mouse-2] 'icicle-mouse-help-on-candidate) ; `C-M-mouse-2'
2715        (define-key map [C-M-mouse-2]      'ignore)
2716        (define-key map [M-S-down-mouse-2] 'icicle-mouse-save/unsave-candidate) ; `M-S-mouse-2'
2717        (define-key map [M-S-mouse-2]      'ignore)
2718        (define-key map [M-down-mouse-2]   'icicle-mouse-candidate-read-fn-invoke) ; `M-mouse-2'
2719        (define-key map [M-mouse-2]        'ignore)
2720        (define-key map [C-down-mouse-3]   'icicle-Completions-mouse-3-menu) ; `C-mouse-3'
2721        (define-key map [C-mouse-3]        'ignore)
2722        (define-key map [M-down-mouse-3]   'icicle-mouse-candidate-set-save-more) ; `M-mouse-3'
2723        (define-key map [M-mouse-3]        'ignore)
2724        (define-key map [M-S-down-mouse-3] 'icicle-mouse-candidate-set-save) ; `M-S-mouse-3'
2725        (define-key map [M-S-mouse-3]      'ignore)
2726        (define-key map [mouse-3]          'icicle-mouse-save-then-kill) ; `mouse-3'
2727        (define-key map [(control ?>)]     'icicle-candidate-set-save-more) ; `C->'
2728        (define-key map [(control meta ?>)] 'icicle-candidate-set-save) ; `C-M->'
2729        (define-key map [(control ?\))]    'icicle-candidate-set-save-more-selected) ; `C-)'
2730        (define-key map [(control meta ?\))] 'icicle-candidate-set-save-selected) ; `C-M-)'
2731        (define-key map [(control meta ?<)] 'icicle-candidate-set-retrieve) ; `C-M-<'
2732        (define-key map [(control ?l)]      'icicle-retrieve-previous-input) ; `C-l'
2733        (define-key map [(control ?a)]      'icicle-beginning-of-line+) ; `C-a'
2734        (define-key map [(control ?e)]      'icicle-end-of-line+) ; `C-e'
2735        ;; (suppress-keymap map) ; Inhibit character self-insertion.
2736        ))
2737
2738     (t                                  ; TURN IT OFF *******************************
2739
2740      ;; `minibuffer-local-map': default minibuffer map.
2741      (let ((map  minibuffer-local-map))
2742
2743        ;; Menu-bar `Minibuf' menu.
2744        (define-key map [menu-bar minibuf quit]
2745          '(menu-item "Quit" keyboard-escape-quit :help "Abort input and exit minibuffer"))
2746        (define-key map [menu-bar minibuf return]
2747          '(menu-item "Enter" exit-minibuffer
2748            :help "Terminate input and exit minibuffer" :keys "RET"))
2749        (define-key map [menu-bar minibuf separator-help]                            nil)
2750        (define-key map [menu-bar minibuf completion-help]                           nil)
2751        (define-key map [menu-bar minibuf separator-last]                            nil)
2752        (define-key map [menu-bar minibuf icicle-toggle-search-complementing-domain] nil)
2753        (define-key map [menu-bar minibuf icicle-toggle-highlight-all-current]       nil)
2754        (define-key map [menu-bar minibuf icicle-regexp-quote-input]                 nil)
2755        (define-key map [menu-bar minibuf separator-set2]                            nil)
2756        (define-key map [menu-bar minibuf icicle-clear-current-history]              nil)
2757        (define-key map [menu-bar minibuf icicle-erase-minibuffer]                   nil)
2758        (define-key map [menu-bar minibuf icicle-delete-history-element]             nil)
2759        (define-key map [menu-bar minibuf icicle-insert-list-join-string]            nil)
2760        (define-key map [menu-bar minibuf icicle-insert-key-description]             nil)
2761        (define-key map [menu-bar minibuf icicle-insert-history-element]             nil)
2762        (define-key map [menu-bar minibuf icicle-insert-string-from-a-var]           nil)
2763        (define-key map [menu-bar minibuf icicle-insert-string-from-std-var]         nil)
2764        (define-key map [menu-bar minibuf icicle-insert-string-at-point]             nil)
2765        (define-key map [menu-bar minibuf icicle-completing-read+insert]             nil)
2766        (define-key map [menu-bar minibuf icicle-read+insert-file-name]              nil)
2767
2768        (define-key map [(control ??)]            nil) ; `C-?'
2769        (define-key map [(control ?g)]            (if (and (fboundp 'minibuffer-keyboard-quit)
2770                                                           delete-selection-mode)
2771                                                      'minibuffer-keyboard-quit
2772                                                    'abort-recursive-edit)) ; `C-g'
2773        (define-key map [M-S-backspace]           nil) ; `M-S-DEL'
2774        (define-key map [M-S-delete]              nil) ; `M-S-delete'
2775        (define-key map [(meta ?.)]               nil) ; `M-.'
2776        (define-key map "\C-x\C-f"                nil) ; `C-x C-f'
2777        (define-key map [(control ?=)]            nil) ; `C-='
2778        (define-key map [(meta ?o)]               nil) ; `M-o'
2779        (define-key map [(meta ?i)]               nil) ; `M-i'
2780        (define-key map [(meta ?k)]               nil) ; `M-k'
2781        (define-key map [(meta ?:)]               nil) ; `M-:'
2782        (define-key map [(control ?a)]            nil) ; `C-a'
2783        (define-key map [(control ?e)]            nil) ; `C-e'
2784        (define-key map [(control meta ?v)]       nil) ; `C-M-v'
2785        (define-key map [(control meta shift ?v)] nil) ; `C-M-S-v' (aka `C-M-V')
2786        (dolist (key  icicle-completing-read+insert-keys) (define-key map key nil)) ; `C-M-S-c'
2787        (dolist (key  icicle-read+insert-file-name-keys) (define-key map key nil)) ; `C-M-S-f'
2788        (define-key map "\n"                      'exit-minibuffer) ; `C-j'
2789        (define-key map "\C-\M-y"                 nil)) ; `C-M-y'
2790
2791      ;; `minibuffer-local-ns-map': default minibuffer map when spaces are not allowed.
2792      ;; In Emacs 22+, local is parent of local-ns.
2793      (unless (eq minibuffer-local-map (keymap-parent minibuffer-local-ns-map))
2794        (let ((map  minibuffer-local-ns-map))
2795          (define-key map [menu-bar minibuf quit]
2796            '(menu-item "Quit" keyboard-escape-quit :help "Abort input and exit minibuffer"))
2797          (define-key map [menu-bar minibuf return]
2798            '(menu-item "Enter" exit-minibuffer
2799              :help "Terminate input and exit minibuffer" :keys "RET"))
2800          (define-key map [menu-bar minibuf separator-help]                            nil)
2801          (define-key map [menu-bar minibuf completion-help]                           nil)
2802          (define-key map [menu-bar minibuf separator-last]                            nil)
2803          (define-key map [menu-bar minibuf icicle-toggle-search-complementing-domain] nil)
2804          (define-key map [menu-bar minibuf icicle-toggle-highlight-all-current]       nil)
2805          (define-key map [menu-bar minibuf icicle-regexp-quote-input]                 nil)
2806          (define-key map [menu-bar minibuf separator-set2]                            nil)
2807          (define-key map [menu-bar minibuf icicle-clear-current-history]              nil)
2808          (define-key map [menu-bar minibuf icicle-erase-minibuffer]                   nil)
2809          (define-key map [menu-bar minibuf icicle-delete-history-element]             nil)
2810          (define-key map [menu-bar minibuf icicle-insert-list-join-string]            nil)
2811          (define-key map [menu-bar minibuf icicle-insert-key-description]             nil)
2812          (define-key map [menu-bar minibuf icicle-insert-history-element]             nil)
2813          (define-key map [menu-bar minibuf icicle-insert-string-from-a-var]           nil)
2814          (define-key map [menu-bar minibuf icicle-insert-string-from-std-var]         nil)
2815          (define-key map [menu-bar minibuf icicle-insert-string-at-point]             nil)
2816          (define-key map [menu-bar minibuf icicle-completing-read+insert]             nil)
2817          (define-key map [menu-bar minibuf icicle-read+insert-file-name]              nil)
2818
2819          (define-key map [(control ??)]            nil) ; `C-?'
2820          (define-key map [(control ?g)]            (if (and (fboundp 'minibuffer-keyboard-quit)
2821                                                             delete-selection-mode)
2822                                                        'minibuffer-keyboard-quit
2823                                                      'abort-recursive-edit)) ; `C-g'
2824          (define-key map [M-S-backspace]           nil) ; `M-S-DEL'
2825          (define-key map [M-S-delete]              nil) ; `M-S-delete'
2826          (define-key map [(meta ?.)]               nil) ; `M-.'
2827          (define-key map "\C-x\C-f"                nil) ; `C-x C-f'
2828          (define-key map [(control ?=)]            nil) ; `C-='
2829          (define-key map [(meta ?o)]               nil) ; `M-o'
2830          (define-key map [(meta ?i)]               nil) ; `M-i'
2831          (define-key map [(meta ?k)]               nil) ; `M-k'
2832          (define-key map [(meta ?:)]               nil) ; `M-:'
2833          (define-key map [(control ?a)]            nil) ; `C-a'
2834          (define-key map [(control ?e)]            nil) ; `C-e'
2835          (define-key map [(control meta ?v)]       nil) ; `C-M-v'
2836          (define-key map [(control meta shift ?v)] nil) ; `C-M-S-v' (aka `C-M-V')
2837          (dolist (key  icicle-completing-read+insert-keys) (define-key map key nil)) ; `C-M-S-c'
2838          (dolist (key  icicle-read+insert-file-name-keys) (define-key map key nil)) ; `C-M-S-f'
2839          (define-key map "\n"                      'exit-minibuffer) ; `C-j'
2840          (define-key map "\C-\M-y"                 nil))) ; `C-M-y'
2841
2842      ;; `minibuffer-local-isearch-map': minibuffer map for editing isearch strings.
2843      ;; In Emacs 21+, local is parent of local-isearch
2844      (unless (eq minibuffer-local-map (keymap-parent minibuffer-local-isearch-map))
2845        (let ((map  minibuffer-local-isearch-map))
2846          (define-key map [menu-bar minibuf quit]
2847            '(menu-item "Quit" keyboard-escape-quit :help "Abort input and exit minibuffer"))
2848          (define-key map [menu-bar minibuf return]
2849            '(menu-item "Enter" exit-minibuffer
2850              :help "Terminate input and exit minibuffer" :keys "RET"))
2851          (define-key map [menu-bar minibuf separator-help]                            nil)
2852          (define-key map [menu-bar minibuf completion-help]                           nil)
2853          (define-key map [menu-bar minibuf separator-last]                            nil)
2854          (define-key map [menu-bar minibuf icicle-toggle-search-complementing-domain] nil)
2855          (define-key map [menu-bar minibuf icicle-toggle-highlight-all-current]       nil)
2856          (define-key map [menu-bar minibuf icicle-regexp-quote-input]                 nil)
2857          (define-key map [menu-bar minibuf separator-set2]                            nil)
2858          (define-key map [menu-bar minibuf icicle-clear-current-history]              nil)
2859          (define-key map [menu-bar minibuf icicle-erase-minibuffer]                   nil)
2860          (define-key map [menu-bar minibuf icicle-delete-history-element]             nil)
2861          (define-key map [menu-bar minibuf icicle-insert-list-join-string]            nil)
2862          (define-key map [menu-bar minibuf icicle-insert-key-description]             nil)
2863          (define-key map [menu-bar minibuf icicle-insert-history-element]             nil)
2864          (define-key map [menu-bar minibuf icicle-insert-string-from-a-var]           nil)
2865          (define-key map [menu-bar minibuf icicle-insert-string-from-std-var]         nil)
2866          (define-key map [menu-bar minibuf icicle-insert-string-at-point]             nil)
2867          (define-key map [menu-bar minibuf icicle-completing-read+insert]             nil)
2868          (define-key map [menu-bar minibuf icicle-read+insert-file-name]              nil)
2869
2870          (define-key map [(control ??)]            nil) ; `C-?'
2871          (define-key map [(control ?g)]            (if (and (fboundp 'minibuffer-keyboard-quit)
2872                                                             delete-selection-mode)
2873                                                        'minibuffer-keyboard-quit
2874                                                      'abort-recursive-edit)) ; `C-g'
2875          (define-key map [M-S-backspace]           nil) ; `M-S-DEL'
2876          (define-key map [M-S-delete]              nil) ; `M-S-delete'
2877          (define-key map [(meta ?.)]               nil) ; `M-.'
2878          (define-key map "\C-x\C-f"                nil) ; `C-x C-f'
2879          (define-key map [(control ?=)]            nil) ; `C-='
2880          (define-key map [(meta ?o)]               nil) ; `M-o'
2881          (define-key map [(meta ?i)]               nil) ; `M-i'
2882          (define-key map [(meta ?k)]               nil) ; `M-k'
2883          (define-key map [(meta ?:)]               nil) ; `M-:'
2884          (define-key map [(control ?a)]            nil) ; `C-a'
2885          (define-key map [(control ?e)]            nil) ; `C-e'
2886          (define-key map [(control meta ?v)]       nil) ; `C-M-v'
2887          (define-key map [(control meta shift ?v)] nil) ; `C-M-S-v' (aka `C-M-V')
2888          (dolist (key  icicle-completing-read+insert-keys) (define-key map key nil)) ; `C-M-S-c'
2889          (dolist (key  icicle-read+insert-file-name-keys) (define-key map key nil)) ; `C-M-S-f'
2890          (define-key map "\n"                      'exit-minibuffer))) ; `C-j'
2891
2892      ;; `minibuffer-local-completion-map': completion map.
2893      (icicle-restore-completion-keys minibuffer-local-completion-map)
2894
2895      ;; `minibuffer-local-must-match-map': must-match map.
2896      ;; In Emacs 22+, local-completion is parent of local-must-match
2897      (if (not (eq minibuffer-local-completion-map (keymap-parent minibuffer-local-must-match-map)))
2898          (icicle-restore-completion-keys minibuffer-local-must-match-map)
2899        (define-key minibuffer-local-must-match-map [(control ?g)]
2900          (if (and (fboundp 'minibuffer-keyboard-quit)
2901                   delete-selection-mode)
2902              'minibuffer-keyboard-quit
2903            'abort-recursive-edit))  ; `C-g' - need it anyway, even if inherit completion map.
2904        (dolist (key  icicle-completing-read+insert-keys)
2905          (define-key minibuffer-local-must-match-map key nil))
2906        (dolist (key  icicle-read+insert-file-name-keys)
2907          (define-key minibuffer-local-must-match-map key nil))
2908        (define-key minibuffer-local-must-match-map "\n" 'minibuffer-complete-and-exit)) ; `C-j'
2909      (define-key minibuffer-local-must-match-map [S-return] nil)
2910
2911      ;; `completion-list-mode-map': map for `*Completions*' buffer.
2912      (let ((map  completion-list-mode-map))
2913        (define-key map [(control ?g)]       nil)
2914        (define-key map "q"                  nil)
2915        (define-key map [(control insert)]   nil)
2916        (dolist (key icicle-prefix-cycle-next-keys)     (define-key map key nil))
2917        (dolist (key icicle-prefix-cycle-previous-keys) (define-key map key nil))
2918        (dolist (key icicle-previous-candidate-keys)   (define-key map key nil))
2919        (define-key map [(control ?i)]       nil)
2920        (define-key map [tab]                nil)
2921        (define-key map [S-down-mouse-2]     nil)
2922        (define-key map [S-mouse-2]          nil)
2923        (define-key map [C-S-down-mouse-2]   nil)
2924        (define-key map [C-S-mouse-2]        nil)
2925        (define-key map [C-down-mouse-2]     nil)
2926        (define-key map [C-mouse-2]          nil)
2927        (define-key map [C-M-return]         nil)
2928        (define-key map [C-M-down-mouse-2]   nil)
2929        (define-key map [C-M-mouse-2]        nil)
2930        (define-key map [M-S-down-mouse-2]   nil)
2931        (define-key map [M-S-mouse-2]        nil)
2932        (define-key map [M-down-mouse-2]     nil)
2933        (define-key map [M-mouse-2]          nil)
2934        (define-key map [C-down-mouse-3]     nil)
2935        (define-key map [M-down-mouse-3]     nil)
2936        (define-key map [M-mouse-3]          nil)
2937        (define-key map [M-S-down-mouse-3]   nil)
2938        (define-key map [M-S-mouse-3]        nil)
2939        (define-key map [mouse-3]            nil)
2940        (define-key map [C-mouse-3]          nil)
2941        (define-key map [(control ?>)]       nil)
2942        (define-key map [(control meta ?>)]  nil)
2943        (define-key map [(control ?\))]      nil)
2944        (define-key map [(control meta ?\))] nil)
2945        (define-key map [(control meta ?<)]  nil)
2946        (define-key map [(control ?l)]       nil)
2947        (define-key map [(control ?a)]       nil)
2948        (define-key map [(control ?e)]       nil)
2949        (define-key map [down]               nil)
2950        (define-key map [up]                 nil)
2951        ;; Do these last:
2952        (define-key map [right]              'next-completion)
2953        (define-key map [left]               'previous-completion))))
2954   (when (and (interactive-p) turn-on-p)
2955     (message (substitute-command-keys
2956               "Use `\\<minibuffer-local-completion-map>\
2957 \\[icicle-minibuffer-help]' in minibuffer for help."))))
2958
2959 (defun icicle-unmap (command map current)
2960   "In MAP, unbind any keys that are bound to COMMAND.
2961 If command remapping is available, remap COMMAND to nil in MAP,
2962 unbinding it.
2963 Otherwise, bind COMMAND to whatever CURRENT is bound to in MAP."
2964   (if (fboundp 'command-remapping)
2965       (define-key map (vector 'remap command) nil)
2966     (substitute-key-definition current command map)))
2967
2968 (defun icicle-rebind-global (old new map)
2969   "Bind command NEW in MAP to all keys currently bound globally to OLD."
2970   (substitute-key-definition old new map (current-global-map)))
2971
2972 (defun icicle-bind-completion-keys (map)
2973   "Bind keys for minibuffer completion map MAP.
2974 MAP is `minibuffer-local-completion-map' or
2975 `minibuffer-local-must-match-map'."
2976
2977   ;; Menu-bar `Minibuf' menu.
2978
2979   ;; In Emacs 22+, local is parent of local-completion
2980   (unless (eq minibuffer-local-map (keymap-parent minibuffer-local-completion-map))
2981     (define-key map [menu-bar minibuf quit] ; Replace `keyboard-escape-quit'
2982       '(menu-item "Quit" icicle-abort-recursive-edit
2983         :help "Cancel minibuffer input or recursive edit"))
2984     (define-key map [menu-bar minibuf return]
2985       '(menu-item "Enter" exit-minibuffer
2986         :help "Terminate input and exit minibuffer" :keys "RET"))
2987     (define-key map [menu-bar minibuf separator-help] '("--"))
2988     (define-key map [menu-bar minibuf completion-help]
2989       '(menu-item "Icicles Help" icicle-minibuffer-help
2990         :help "Display help for minibuffer input and completion"))
2991     (define-key map [menu-bar minibuf separator-last] '("--"))
2992     (define-key map [menu-bar minibuf icicle-toggle-search-complementing-domain]
2993         '(menu-item "Toggle Searching Complement"
2994           icicle-toggle-search-complementing-domain
2995           :help "Toggle `icicle-search-complement-domain-p'" :keys "C-M-~"))
2996     (define-key map [menu-bar minibuf icicle-toggle-highlight-all-current]
2997       '(menu-item "Toggle All-Current Icicle-Search Highlighting"
2998         icicle-toggle-highlight-all-current :enable icicle-searching-p
2999         :help "Toggle `icicle-search-highlight-all-current-flag'" :keys "C-^"))
3000     (define-key map [menu-bar minibuf icicle-regexp-quote-input]
3001       '(menu-item "Regexp-Quote Input" icicle-regexp-quote-input
3002         :enable (with-current-buffer (window-buffer (minibuffer-window)) (not (zerop (buffer-size))))
3003         :help "Regexp-quote current input or its active region, then apropos-complete"
3004         :keys "M-%"))
3005     (define-key map [menu-bar minibuf separator-set2] '("--"))
3006     (define-key map [menu-bar minibuf icicle-clear-current-history]
3007       '(menu-item "Clear History Entries" icicle-clear-current-history
3008         :help "Clear current minibuffer history of selected entries"))
3009     (define-key map [menu-bar minibuf icicle-erase-minibuffer]
3010       '(menu-item "Delete from History" icicle-erase-minibuffer-or-history-element
3011         :visible (memq last-command
3012                   '(previous-history-element next-history-element
3013                     icicle-erase-minibuffer-or-history-element
3014                     previous-matching-history-element next-matching-history-element))
3015         :help "Delete current history element (in minibuffer now)" :keys "M-k"))
3016     (define-key map [menu-bar minibuf icicle-delete-history-element]
3017       '(menu-item "Clear (Erase) Minibuffer" icicle-erase-minibuffer-or-history-element
3018         :visible (not (memq last-command
3019                        '(previous-history-element next-history-element
3020                          icicle-erase-minibuffer-or-history-element
3021                          previous-matching-history-element next-matching-history-element)))
3022         :help "Erase the Minibuffer" :keys "M-k"))
3023     (define-key map [menu-bar minibuf icicle-insert-list-join-string]
3024       '(menu-item "Insert Join-String" icicle-insert-list-join-string
3025         :help "Insert `icicle-list-join-string' into the minibuffer"))
3026     (define-key map [menu-bar minibuf icicle-insert-key-description]
3027       '(menu-item "Insert Key Description" icicle-insert-key-description
3028         :visible (not icicle-searching-p) :keys "M-q"
3029         :help "Read key and insert its description - e.g., reading ^F inserts `C-f'"))
3030     (define-key map [menu-bar minibuf icicle-insert-history-element]
3031       '(menu-item "Insert Past Input using Completion" icicle-insert-history-element
3032         :help "Use completion to insert a previous input into the minibuffer"))
3033     (define-key map [menu-bar minibuf icicle-insert-string-from-a-var]
3034       '(menu-item "Insert String from a Variable..." icicle-insert-string-from-variable
3035         :visible current-prefix-arg :keys "C-="
3036         :help "Read a variable name and insert its string value into the minibuffer"))
3037     (define-key map [menu-bar minibuf icicle-insert-string-from-std-var]
3038       '(menu-item "Insert `icicle-input-string'" icicle-insert-string-from-variable
3039         :visible (not current-prefix-arg) :keys "C-="
3040         :help "Insert text from variable `icicle-input-string' into the minibuffer"))
3041     (define-key map [menu-bar minibuf icicle-insert-string-at-point]
3042       '(menu-item "Insert Text from Point" icicle-insert-string-at-point
3043         :help "Insert text at or near the cursor into the minibuffer"))
3044     (define-key map [menu-bar minibuf icicle-completing-read+insert]
3045       '(menu-item "Insert On-Demand Completion" icicle-completing-read+insert
3046         :visible (consp icicle-completing-read+insert-candidates)
3047         :help "Read and insert something using (lax) completion"))
3048     (define-key map [menu-bar minibuf icicle-read+insert-file-name]
3049       '(menu-item "Insert File Name" icicle-read+insert-file-name
3050         :help "Read and insert a file name using (lax) completion"))
3051     )
3052   (define-key map [menu-bar minibuf icicle-goto/kill-failed-input]
3053     '(menu-item "Cursor to Mismatch (Repeat: Kill)" icicle-goto/kill-failed-input
3054       :enable (and (overlayp icicle-input-completion-fail-overlay)
3055                (overlay-start icicle-input-completion-fail-overlay))
3056       :help "Put cursor where input fails to complete - repeat to kill mismatch"))
3057   (define-key map [menu-bar minibuf icicle-retrieve-next-input]
3058     '(menu-item "Restore Next Completion Input" icicle-retrieve-next-input
3059       :enable (consp (symbol-value (if (icicle-file-name-input-p)
3060                                        'icicle-previous-raw-file-name-inputs
3061                                      'icicle-previous-raw-non-file-name-inputs)))
3062       :help "Cycle forward to insert a previous completion input in the minibuffer (`C-u': \
3063 complete)"))
3064   (define-key map [menu-bar minibuf icicle-retrieve-previous-input]
3065     '(menu-item "Restore Previous Completion Input" icicle-retrieve-previous-input
3066       :enable (consp (symbol-value (if (icicle-file-name-input-p)
3067                                        'icicle-previous-raw-file-name-inputs
3068                                      'icicle-previous-raw-non-file-name-inputs)))
3069       :help "Cycle backward to insert a previous completion input in the minibuffer (`C-u': \
3070 complete)"))
3071   (define-key map [menu-bar minibuf separator-C-l] '("--"))
3072   (define-key map [menu-bar minibuf ?\?] nil)
3073   (define-key map [menu-bar minibuf space] nil)
3074   (define-key map [menu-bar minibuf tab] nil)
3075   (define-key map [menu-bar minibuf alt-action-list-all]
3076     '(menu-item "Alt Act on List of Candidates" icicle-all-candidates-list-alt-action
3077       :help "Apply the alternative action to the list of matching completion candidates"
3078       :enable icicle-all-candidates-list-alt-action-fn))
3079   (define-key map [menu-bar minibuf alt-action-all]
3080     '(menu-item "Alt Act on Each Candidate" icicle-all-candidates-alt-action
3081       :help "Apply the alternative action to each matching completion candidates"
3082       :enable icicle-candidate-alt-action-fn))
3083   (define-key map [menu-bar minibuf action-list-all]
3084     '(menu-item "Act on List of Candidates" icicle-all-candidates-list-action
3085       :help "Apply the command action to the list of matching completion candidates"
3086       :enable icicle-all-candidates-list-action-fn))
3087   (define-key map [menu-bar minibuf action-all]
3088     '(menu-item "Act on Each Candidate" icicle-all-candidates-action
3089       :help "Apply the command action to each matching completion candidates"
3090       :enable icicle-candidate-action-fn))
3091   (define-key map [menu-bar minibuf separator-actions] '("--"))
3092   (define-key map [menu-bar minibuf set-define]
3093     '(menu-item "Define Candidates by Lisp Sexp" icicle-candidate-set-define
3094       :help "Define the set of current completion candidates by evaluating a sexp"))
3095   (define-key map [menu-bar minibuf icicle-keep-only-past-inputs]
3096     '(menu-item "Keep Only Previously Entered" icicle-keep-only-past-inputs
3097       :enable (and icicle-completion-candidates (consp (symbol-value minibuffer-history-variable)))
3098       :help "Removed candidates that you have not previously chosen and entered"))
3099   (define-key map [menu-bar minibuf set-union]
3100     '(menu-item "Add (Union) Saved Candidate Set" icicle-candidate-set-union
3101       :enable icicle-saved-completion-candidates
3102       :help "Set union between the current and saved completion candidates"))
3103   (define-key map [menu-bar minibuf set-difference]
3104     '(menu-item "Subtract Saved Candidate Set" icicle-candidate-set-difference
3105       :enable icicle-saved-completion-candidates
3106       :help "Set difference between the current and saved completion candidates"))
3107   (define-key map [menu-bar minibuf set-intersection]
3108     '(menu-item "Intersect Saved Candidate Set" icicle-candidate-set-intersection
3109       :enable icicle-saved-completion-candidates
3110       :help "Set intersection between the current and saved candidates"))
3111   (define-key map [menu-bar minibuf icicle-save-predicate-to-variable]
3112     '(menu-item "Save Predicate to Variable" icicle-save-predicate-to-variable
3113       :help "Save the current completion predicate to a variable"))
3114   (define-key map [menu-bar minibuf icicle-narrow-candidates-with-predicate]
3115     '(menu-item "Satisfy Also Predicate..." icicle-narrow-candidates-with-predicate
3116       :help "Match another input pattern (narrow completions set)"
3117       :enable icicle-completion-candidates))
3118   (define-key map [menu-bar minibuf icicle-narrow-candidates]
3119     '(menu-item "Match Also Regexp..." icicle-narrow-candidates
3120       :enable icicle-completion-candidates
3121       :help "Match another input pattern (narrow completions set)"))
3122   (define-key map [menu-bar minibuf icicle-widen-candidates]
3123     '(menu-item "Match Alternative..." icicle-widen-candidates
3124       :enable icicle-completion-candidates
3125       :help "Match alternative input pattern (widen completions set)"))
3126   (define-key map [menu-bar minibuf set-complement]
3127     '(menu-item "Complement Candidates" icicle-candidate-set-complement
3128       :help "Complement the set of current completion candidates"))
3129   (define-key map [menu-bar minibuf separator-set1] '("--"))
3130   (define-key map [menu-bar minibuf set-swap]
3131     '(menu-item "Swap Saved and Current Sets" icicle-candidate-set-swap
3132       :enable icicle-saved-completion-candidates
3133       :help "Swap the saved and current sets of completion candidates"))
3134   (define-key map [menu-bar minibuf icicle-candidate-set-save-more-selected]
3135     '(menu-item "Save More Selected (Region) Candidates"
3136       icicle-candidate-set-save-more-selected
3137       :help "Add the candidates in the region to the saved candidates"))
3138   (define-key map [menu-bar minibuf icicle-candidate-set-save-selected]
3139     '(menu-item "Save Selected (Region) Candidates"
3140       icicle-candidate-set-save-selected
3141       :help "Save the candidates in the region, for later recall"))
3142   (define-key map [menu-bar minibuf icicle-candidate-set-save-more]
3143     '(menu-item "Save More Candidates" icicle-candidate-set-save-more
3144       :help "Add current completion candidates to saved candidates set"))
3145   (define-key map [menu-bar minibuf set-save-to-cache-file]
3146     '(menu-item "    to Cache File..." icicle-candidate-set-save-persistently
3147       :help "Save current completion candidates to a cache file, for later recall"))
3148   (define-key map [menu-bar minibuf set-save-to-variable]
3149     '(menu-item "    to Variable..." icicle-candidate-set-save-to-variable
3150       :help "Save current completion candidates to a variable, for later recall"))
3151   (define-key map [menu-bar minibuf set-save]
3152     '(menu-item "Save Candidates" icicle-candidate-set-save
3153       :help "Save the set of current completion candidates, for later recall"))
3154   (define-key map [menu-bar minibuf icicle-candidate-set-retrieve-more]
3155     '(menu-item "Retrieve More Saved Candidates"
3156       icicle-candidate-set-retrieve-more
3157       :help "Add saved candidates to current completion candidates"))
3158   (define-key map [menu-bar minibuf set-retrieve-from-cache-file]
3159     '(menu-item "    from Cache File..."
3160       icicle-candidate-set-retrieve-persistent
3161       :help "Retrieve saved completion candidates from a cache file, making them current"))
3162   (define-key map [menu-bar minibuf set-retrieve-from-variable]
3163     '(menu-item "    from Variable..." icicle-candidate-set-retrieve-from-variable
3164       :help "Retrieve saved completion candidates from variable, making them current"))
3165   (define-key map [menu-bar minibuf set-retrieve]
3166     '(menu-item "Retrieve Saved Candidates" icicle-candidate-set-retrieve
3167       :enable icicle-saved-completion-candidates
3168       :help "Retrieve the saved set of completion candidates, making it current"))
3169   (define-key map [menu-bar minibuf separator-complete] '("--"))
3170   (define-key map [menu-bar minibuf word-complete]
3171     '(menu-item "Word-Complete" icicle-prefix-word-complete
3172       :help "Complete at most one word of prefix"))
3173   (define-key map [menu-bar minibuf prefix-complete]
3174     '(menu-item "Prefix-Complete" icicle-prefix-complete
3175       :help "Complete prefix as far as possible"))
3176   (define-key map [menu-bar minibuf apropos-complete]
3177     '(menu-item "Apropos-Complete" icicle-apropos-complete :keys "S-TAB"
3178       :help "Complete regular expression as far as possible and list completions"))
3179
3180   ;; Remap some commands for completion.
3181   (icicle-remap 'self-insert-command           'icicle-self-insert map (current-global-map))
3182   (icicle-remap 'universal-argument            'icicle-universal-argument ; `C-u'
3183                 map (current-global-map))
3184   (icicle-remap 'negative-argument             'icicle-negative-argument ; `M--'
3185                 map (current-global-map))
3186   (icicle-remap 'digit-argument                'icicle-digit-argument ; `C-9'
3187                 map (current-global-map))
3188   (icicle-remap 'backward-delete-char-untabify 'icicle-backward-delete-char-untabify ; `DEL'
3189                 map (current-global-map))
3190   (icicle-remap 'delete-backward-char          'icicle-delete-backward-char ; `DEL'
3191                 map (current-global-map))
3192   (icicle-remap 'delete-char                   'icicle-delete-char ; `C-d', `deletechar'
3193                 map (current-global-map))
3194   (icicle-remap 'backward-kill-word            'icicle-backward-kill-word ; `M-DEL'
3195                 map (current-global-map))
3196   (icicle-remap 'kill-word                     'icicle-kill-word ; `M-d'
3197                 map (current-global-map))
3198   (icicle-remap 'backward-kill-sexp            'icicle-backward-kill-sexp ; `C-M-backspace'
3199                 map (current-global-map))
3200   (icicle-remap 'kill-sexp                     'icicle-kill-sexp ; `C-M-k', `C-M-delete'
3201                 map (current-global-map))
3202   (icicle-remap 'backward-kill-sentence        'icicle-backward-kill-sentence ; `C-x DEL'
3203                 map (current-global-map))
3204   (icicle-remap 'backward-kill-paragraph       'icicle-backward-kill-paragraph ; `C-backspace'
3205                 map (current-global-map))
3206   (icicle-remap 'kill-paragraph                'icicle-kill-paragraph ; `C-delete'
3207                 map (current-global-map))
3208   (icicle-remap 'kill-line                     'icicle-kill-line ; `C-k', `deleteline'
3209                 map (current-global-map))
3210   (icicle-remap 'reposition-window             'icicle-goto/kill-failed-input ; `C-M-l'
3211                 map (current-global-map))
3212   (icicle-remap 'transpose-chars               'icicle-transpose-chars ; `C-t'
3213                 map (current-global-map))
3214   (icicle-remap 'transpose-words               'icicle-transpose-words ; `M-t'
3215                 map (current-global-map))
3216   (icicle-remap 'transpose-sexps               'icicle-transpose-sexps ; `C-M-t'
3217                 map (current-global-map))
3218   (icicle-remap 'yank-pop                      'icicle-yank-pop ; `M-y', `M-insert'
3219                 map (current-global-map))
3220   (icicle-remap 'mouse-yank-secondary          'icicle-mouse-yank-secondary ; `M-mouse-2'
3221                 map (current-global-map))
3222
3223   ;; Bind additional keys.
3224   (dolist (key icicle-word-completion-keys)
3225     (define-key map key 'icicle-prefix-word-complete)) ; `M-SPC'
3226   (dolist (key icicle-apropos-complete-keys)
3227     (define-key map key 'icicle-apropos-complete)) ; `S-TAB'
3228   (dolist (key icicle-prefix-complete-keys) (define-key map key 'icicle-prefix-complete)) ; `TAB'
3229   (dolist (key icicle-apropos-complete-no-display-keys)
3230     (define-key map key 'icicle-apropos-complete-no-display)) ; `C-M-S-TAB'
3231   (dolist (key icicle-prefix-complete-no-display-keys)
3232     (define-key map key 'icicle-prefix-complete-no-display)) ; `C-M-TAB'
3233
3234   (icicle-define-cycling-keys map)      ;     `up',     `down',     `prior',     `next',
3235                                         ;   `C-up',   `C-down',   `C-prior',   `C-next',
3236                                         ; `C-M-up', `C-M-down', `C-M-prior', `C-M-next',
3237                                         ; `C-S-up', `C-S-down', `C-S-prior', `C-S-next',
3238   (define-key map [(control help)]           'icicle-help-on-candidate) ; `C-help'
3239   (define-key map [(control meta help)]      'icicle-help-on-candidate) ; `C-M-help'
3240   (define-key map [(control f1)]             'icicle-help-on-candidate) ; `C-f1'
3241   (define-key map [(control meta f1)]        'icicle-help-on-candidate) ; `C-M-f1'
3242   (define-key map [(control meta return)]    'icicle-help-on-candidate) ; `C-M-RET'
3243   (define-key map [(meta return)]            'icicle-candidate-read-fn-invoke) ;`M-RET' as `M-return'
3244   (define-key map "\C-\M-m"                  'icicle-candidate-read-fn-invoke) ;`M-RET' as `ESC RET'
3245   (define-key map [(control shift return)]   'icicle-candidate-alt-action) ; `C-S-RET'
3246   (define-key map [delete]                   'icicle-remove-candidate) ; `delete'
3247   (define-key map [(shift delete)]           'icicle-delete-candidate-object) ; `S-delete'
3248   (define-key map [(control ?w)]             'icicle-kill-region) ; `C-w'
3249   (define-key map [(control return)]         'icicle-candidate-action) ; `C-RET'
3250   (define-key map [(control ?!)]             'icicle-all-candidates-action) ; `C-!'
3251   (define-key map [(control ?|)]             'icicle-all-candidates-alt-action) ; `C-|'
3252   (define-key map [(meta ?!)]                'icicle-all-candidates-list-action) ; `M-!'
3253   (define-key map [(meta ?|)]                'icicle-all-candidates-list-alt-action) ; `M-|'
3254   (define-key map [(control meta ?/)]        'icicle-prefix-complete) ; `C-M-/', for `dabbrev.el'.
3255   (define-key map [(meta ?h)]                'icicle-history) ; `M-h'
3256   (define-key map [(meta pause)]             'icicle-keep-only-past-inputs) ; `M-pause'
3257   (define-key map [(control pause)]     'icicle-toggle-highlight-historical-candidates) ; `C-pause'
3258   (define-key map [(shift pause)]            'icicle-toggle-highlight-saved-candidates) ; `S-pause'
3259   (define-key map [(control meta pause)]     'icicle-other-history) ; `C-M-pause'
3260   (define-key map [(control insert)]         'icicle-switch-to-Completions-buf) ; `C-insert'
3261   (define-key map [insert]                   'icicle-save/unsave-candidate) ; `insert'
3262
3263   ;; In Emacs 22+, local is parent of local-completion
3264   (unless (eq minibuffer-local-map (keymap-parent minibuffer-local-completion-map))
3265     ;; Note: `setup-keys.el' binds `C-o' to `1on1-fit-minibuffer-frame' if defined.
3266     (define-key map [(control ?a)]           'icicle-beginning-of-line+) ; `C-a'
3267     (define-key map [(control ?e)]           'icicle-end-of-line+) ; `C-e'
3268     (define-key map [(control meta ?v)]      'icicle-scroll-forward) ; `C-M-v'
3269     (define-key map [(control meta shift ?v)] 'icicle-scroll-backward) ; `C-M-S-v' (aka `C-M-V')
3270     (define-key map [(control ?=)]           'icicle-insert-string-from-variable) ; `C-='
3271     ;; Replaces `tab-to-tab-stop':
3272     (define-key map [(meta ?i)]              'icicle-clear-current-history) ; `M-i'
3273     ;; Replaces `kill-sentence':
3274     (define-key map [(meta ?k)]              'icicle-erase-minibuffer-or-history-element) ; `M-k'
3275     (define-key map [(meta ?o)]              'icicle-insert-history-element) ; `M-o'
3276     (define-key map [(meta ?.)]              'icicle-insert-string-at-point) ; `M-.'
3277     (define-key map "\C-x\C-f"               'icicle-resolve-file-name) ; `C-x C-f'
3278     (define-key map [(meta ?:)]              'icicle-pp-eval-expression-in-minibuffer) ; `M-:'
3279     (when (fboundp 'yank-secondary)     ; In `second-sel.el'.
3280       (define-key map "\C-\M-y"              'icicle-yank-secondary)) ; `C-M-y'
3281     (define-key map [M-S-backspace]          'icicle-erase-minibuffer) ; `M-S-backspace'
3282     (define-key map [M-S-delete]             'icicle-erase-minibuffer) ; `M-S-delete'
3283     (dolist (key  icicle-completing-read+insert-keys)
3284       (define-key map key 'icicle-completing-read+insert)) ; `C-M-S-c'
3285     (dolist (key  icicle-read+insert-file-name-keys)
3286       (define-key map key 'icicle-read+insert-file-name)) ; `C-M-S-f'
3287     )
3288
3289   ;; Need `C-g', even if `minibuffer-local-completion-map' inherits from `minibuffer-local-map'.
3290   (define-key map [(control ?g)]             'icicle-abort-recursive-edit) ; `C-g'
3291   (define-key map [(meta ?q)]                'icicle-dispatch-M-q) ; `M-q'
3292   (define-key map [(control ?l)]             'icicle-retrieve-previous-input) ; `C-l'
3293   (define-key map [(control shift ?l)]       'icicle-retrieve-next-input) ; `C-L' (`C-S-l')
3294   (define-key map [(meta ?$)]                'icicle-candidate-set-truncate) ; `M-$'
3295   (define-key map [(control ?~)]             'icicle-candidate-set-complement) ; `C-~'
3296   (define-key map [(control ?-)]             'icicle-candidate-set-difference) ; `C--'
3297   (define-key map [(control ?+)]             'icicle-candidate-set-union) ; `C-+'
3298   (define-key map [(control ?*)]             'icicle-candidate-set-intersection) ; `C-*'
3299   (define-key map [(control ?>)]             'icicle-candidate-set-save-more) ; `C->'
3300   (define-key map [(control meta ?>)]        'icicle-candidate-set-save) ; `C-M->'
3301   (define-key map [(control ?\()]            'icicle-next-TAB-completion-method) ; `C-('
3302   (define-key map [(meta ?\()]               'icicle-next-S-TAB-completion-method) ; `M-('
3303   (define-key map [(control ?\))]            'icicle-candidate-set-save-more-selected) ; `C-)'
3304   (define-key map [(control meta ?\))]       'icicle-candidate-set-save-selected) ; `C-M-)'
3305   (define-key map [(control meta ?<)]        'icicle-candidate-set-retrieve) ; `C-M-<'
3306   (define-key map [(control meta ?})]        'icicle-candidate-set-save-to-variable) ; `C-M-}'
3307   (define-key map [(control meta ?{)]        'icicle-candidate-set-retrieve-from-variable) ; `C-M-{'
3308   (define-key map [(control ?})]             'icicle-candidate-set-save-persistently) ; `C-}'
3309   (define-key map [(control ?{)]             'icicle-candidate-set-retrieve-persistent) ; `C-{'
3310   (define-key map [(control ?%)]             'icicle-candidate-set-swap) ; `C-%'
3311   (define-key map [(meta ?%)]                'icicle-regexp-quote-input) ; `M-%'
3312   (define-key map [(control ?:)]             'icicle-candidate-set-define) ; `C-:'
3313   (define-key map [(control meta ?j)]        'icicle-insert-list-join-string) ; `C-M-j'
3314   (define-key map [(control ?,)]             'icicle-change-sort-order) ; `C-,'
3315   (define-key map [(control meta ?\;)]       'icicle-toggle-ignoring-comments) ; `C-M-;'
3316   (define-key map [(control ?`)]             'icicle-toggle-regexp-quote) ; `C-`'
3317   (define-key map [(control meta ?\.)]       'icicle-toggle-dot) ; `C-M-.'
3318   (define-key map [(control meta ?`)]        'icicle-toggle-literal-replacement) ; `C-M-`'
3319   (define-key map [(control ?<)]             'icicle-candidate-set-retrieve-more) ; `C-<'
3320   (define-key map [(control meta ?_)]        'icicle-toggle-proxy-candidates) ; `C-M-_'
3321   (define-key map [(control ?$)]             'icicle-toggle-transforming) ; `C-$'
3322   ;; In Emacs 22+, local is parent of local-completion
3323   (unless (eq minibuffer-local-map (keymap-parent minibuffer-local-completion-map))
3324     (define-key map [(control ??)]           'icicle-minibuffer-help)) ; `C-?'
3325   (define-key map [(control ?.)]             'icicle-dispatch-C-.) ; `C-.'
3326   (define-key map [(control ?#)]             'icicle-toggle-incremental-completion) ; `C-#'
3327   (define-key map [(control ?\;)]            'icicle-toggle-expand-to-common-match) ; `C-;'
3328   (define-key map [(meta ?\;)]               'icicle-toggle-search-replace-common-match) ; `M-;'
3329   (define-key map [(control ?^)]             'icicle-dispatch-C-^) ; `C-^'
3330   (define-key map [(control shift ?a)]       'icicle-toggle-case-sensitivity) ; `C-S-a' (`C-A')
3331   (define-key map [(meta ?~)]                'icicle-toggle-~-for-home-dir) ; `M-~'
3332   (define-key map [(control meta ?~)]        'icicle-toggle-search-complementing-domain) ; `C-M-~'
3333   (define-key map [(meta ?g)]                'icicle-toggle-C-for-actions) ; `M-g'
3334   (define-key map [(meta ?,)]                'icicle-dispatch-M-comma) ; `M-,'
3335   (define-key map [(control meta ?,)]        'icicle-toggle-alternative-sorting) ; `C-M-,'
3336   (define-key map [(control meta ?+)]        'icicle-plus-saved-sort) ; `C-M-+'
3337   (define-key map [(meta ?+)]                'icicle-widen-candidates) ; `M-+'
3338   (define-key map [(meta ?*)]                'icicle-narrow-candidates) ; `M-*'
3339   (define-key map [(meta ?&)]                'icicle-narrow-candidates-with-predicate) ; `M-&'
3340   (define-key map [(meta ?_)]                'icicle-dispatch-M-_) ; `M-_'
3341   (define-key map [(control meta ?&)]        'icicle-save-predicate-to-variable) ; `C-M-&'
3342   (define-key map [(shift ?\ )]              'icicle-apropos-complete-and-narrow) ; `S-SPC'
3343   (define-key map [(shift backspace)]        'icicle-apropos-complete-and-widen) ; `S-DEL'
3344   (define-key map "\C-v"                     'icicle-scroll-Completions-forward) ; `C-v'
3345   (define-key map "\M-v"                     'icicle-scroll-Completions-backward) ; `M-v'
3346   (define-key map "."                        'icicle-insert-dot-command) ; `.'
3347   (define-key map "\M-m"                     'icicle-toggle-show-multi-completion) ; `M-m'
3348   (define-key map "\C-x."                    'icicle-dispatch-C-x.) ; `C-x .'
3349   (when (fboundp 'icicle-cycle-image-file-thumbnail) ; Emacs 23+
3350     (define-key map "\C-xt"                  'icicle-cycle-image-file-thumbnail)) ; `C-x t'
3351   (when (fboundp 'doremi)
3352     (define-key map "\C-xw"                  'icicle-doremi-candidate-width-factor+) ; `C-x w'
3353     (define-key map "\C-x|"                  'icicle-doremi-inter-candidates-min-spaces+) ; `C-x |'
3354     (define-key map "\C-x#"                  'icicle-doremi-increment-max-candidates+) ; `C-x #'
3355     (when (fboundp 'text-scale-increase) ; Emacs 23+.
3356       (define-key map "\C-x-"                'icicle-doremi-zoom-Completions+)) ; `C-x -'
3357     (when (eq (icicle-current-TAB-method) 'swank)
3358       (define-key map "\C-x1"                'icicle-doremi-increment-swank-timeout+)
3359       (define-key map "\C-x2"                'icicle-doremi-increment-swank-prefix-length+)))
3360   ;; `minibuffer-completion-help' got wiped out by remap for self-insert.
3361   (define-key map "?"                        'icicle-self-insert) ; `?'
3362   (define-key map " "                        'icicle-self-insert) ; " "
3363   ;; In Emacs 22+, local is parent of local-completion
3364   (unless (eq minibuffer-local-map (keymap-parent minibuffer-local-completion-map))
3365     (define-key map "\n"                     'icicle-insert-newline-in-minibuffer))) ; `C-j'
3366
3367 (defun icicle-restore-completion-keys (map)
3368   "Restore standard keys for minibuffer completion map MAP.
3369 MAP is `minibuffer-local-completion-map',
3370 `minibuffer-local-filename-completion-map', or
3371 `minibuffer-local-must-match-map'."
3372
3373   ;; Menu-bar `Minibuf' menu.
3374   ;; In Emacs 22+, local is parent of local-completion
3375   (unless (eq minibuffer-local-map (keymap-parent minibuffer-local-completion-map))
3376     (define-key map [menu-bar minibuf quit]
3377       '(menu-item "Quit" keyboard-escape-quit :help "Abort input and exit minibuffer"))
3378     (define-key map [menu-bar minibuf return]
3379       '(menu-item "Enter" exit-minibuffer
3380         :help "Terminate input and exit minibuffer" :keys "RET"))
3381     (define-key map [menu-bar minibuf separator-help]                            nil)
3382     (define-key map [menu-bar minibuf completion-help]                           nil)
3383     (define-key map [menu-bar minibuf separator-last]                            nil)
3384     (define-key map [menu-bar minibuf icicle-clear-current-history]              nil)
3385     (define-key map [menu-bar minibuf icicle-toggle-search-complementing-domain] nil)
3386     (define-key map [menu-bar minibuf icicle-toggle-highlight-all-current]       nil)
3387     (define-key map [menu-bar minibuf icicle-regexp-quote-input]                 nil)
3388     (define-key map [menu-bar minibuf separator-set2]                            nil)
3389     (define-key map [menu-bar minibuf icicle-clear-current-history]              nil)
3390     (define-key map [menu-bar minibuf icicle-erase-minibuffer]                   nil)
3391     (define-key map [menu-bar minibuf icicle-delete-history-element]             nil)
3392     (define-key map [menu-bar minibuf icicle-insert-list-join-string]            nil)
3393     (define-key map [menu-bar minibuf icicle-insert-key-description]             nil)
3394     (define-key map [menu-bar minibuf icicle-insert-history-element]             nil)
3395     (define-key map [menu-bar minibuf icicle-insert-string-from-a-var]           nil)
3396     (define-key map [menu-bar minibuf icicle-insert-string-from-std-var]         nil)
3397     (define-key map [menu-bar minibuf icicle-insert-string-at-point]             nil)
3398     (define-key map [menu-bar minibuf icicle-completing-read+insert]             nil)
3399     (define-key map [menu-bar minibuf icicle-read+insert-file-name]              nil)
3400     )
3401   (define-key map [menu-bar minibuf icicle-goto/kill-failed-input]           nil)
3402   (define-key map [menu-bar minibuf icicle-retrieve-next-input]              nil)
3403   (define-key map [menu-bar minibuf icicle-retrieve-previous-input]          nil)
3404   (define-key map [menu-bar minibuf separator-C-l]                           nil)
3405   (define-key map [menu-bar minibuf alt-action-list-all]                     nil)
3406   (define-key map [menu-bar minibuf alt-action-all]                          nil)
3407   (define-key map [menu-bar minibuf action-list-all]                         nil)
3408   (define-key map [menu-bar minibuf action-all]                              nil)
3409   (define-key map [menu-bar minibuf separator-actions]                       nil)
3410   (define-key map [menu-bar minibuf set-define]                              nil)
3411   (define-key map [menu-bar minibuf icicle-keep-only-past-inputs]            nil)
3412   (define-key map [menu-bar minibuf set-union]                               nil)
3413   (define-key map [menu-bar minibuf set-difference]                          nil)
3414   (define-key map [menu-bar minibuf set-intersection]                        nil)
3415   (define-key map [menu-bar minibuf icicle-save-predicate-to-variable]       nil)
3416   (define-key map [menu-bar minibuf icicle-narrow-candidates-with-predicate] nil)
3417   (define-key map [menu-bar minibuf icicle-narrow-candidates]                nil)
3418   (define-key map [menu-bar minibuf icicle-widen-candidates]                 nil)
3419   (define-key map [menu-bar minibuf set-complement]                          nil)
3420   (define-key map [menu-bar minibuf separator-set1]                          nil)
3421   (define-key map [menu-bar minibuf set-swap]                                nil)
3422   (define-key map [menu-bar minibuf icicle-candidate-set-save-more-selected] nil)
3423   (define-key map [menu-bar minibuf icicle-candidate-set-save-selected]      nil)
3424   (define-key map [menu-bar minibuf icicle-candidate-set-save-more]          nil)
3425   (define-key map [menu-bar minibuf set-retrieve-from-cache-file]            nil)
3426   (define-key map [menu-bar minibuf set-retrieve-from-variable]              nil)
3427   (define-key map [menu-bar minibuf set-retrieve]                            nil)
3428   (define-key map [menu-bar minibuf set-save-to-cache-file]                  nil)
3429   (define-key map [menu-bar minibuf set-save-to-variable]                    nil)
3430   (define-key map [menu-bar minibuf set-save]                                nil)
3431   (define-key map [menu-bar minibuf separator-set2]                          nil)
3432   (define-key map [menu-bar minibuf word-complete]                           nil)
3433   (define-key map [menu-bar minibuf prefix-complete]                         nil)
3434   (define-key map [menu-bar minibuf apropos-complete]                        nil)
3435   (define-key map [menu-bar minibuf ?\?]
3436     '(menu-item "List Completions" minibuffer-completion-help
3437       :help "Display all possible completions"))
3438   (define-key map [menu-bar minibuf space]
3439     '(menu-item "Complete Word" minibuffer-complete-word :help "Complete at most one word"))
3440   (define-key map [menu-bar minibuf tab]
3441     '(menu-item "Complete" minibuffer-complete :help "Complete as far as possible"))
3442
3443   ;; Unmap commands that were bound for completion.
3444   (icicle-unmap 'self-insert-command           map 'icicle-self-insert)
3445   (icicle-unmap 'universal-argument            map 'icicle-universal-argument)
3446   (icicle-unmap 'negative-argument             map 'icicle-negative-argument)
3447   (icicle-unmap 'digit-argument                map 'icicle-digit-argument)
3448   (icicle-unmap 'backward-delete-char-untabify map 'icicle-backward-delete-char-untabify)
3449   (icicle-unmap 'delete-backward-char          map 'icicle-delete-backward-char)
3450   (icicle-unmap 'delete-char                   map 'icicle-delete-char)
3451   (icicle-unmap 'backward-kill-word            map 'icicle-backward-kill-word)
3452   (icicle-unmap 'kill-word                     map 'icicle-kill-word)
3453   (icicle-unmap 'backward-kill-sexp            map 'icicle-backward-kill-sexp)
3454   (icicle-unmap 'kill-sexp                     map 'icicle-kill-sexp)
3455   (icicle-unmap 'backward-kill-sentence        map 'icicle-backward-kill-sentence)
3456   (icicle-unmap 'backward-kill-paragraph       map 'icicle-backward-kill-paragraph)
3457   (icicle-unmap 'kill-paragraph                map 'icicle-kill-paragraph)
3458   (icicle-unmap 'kill-line                     map 'icicle-kill-line)
3459   (icicle-unmap 'reposition-window             map 'icicle-goto/kill-failed-input)
3460   (icicle-unmap 'transpose-chars               map 'icicle-transpose-chars)
3461   (icicle-unmap 'transpose-words               map 'icicle-transpose-words)
3462   (icicle-unmap 'transpose-sexps               map 'icicle-transpose-sexps)
3463   (icicle-unmap 'yank-pop                      map 'icicle-yank-pop)
3464   (icicle-unmap 'mouse-yank-secondary          map 'icicle-mouse-yank-secondary)
3465
3466   ;; Restore additional bindings.
3467   ;; Do the option keys first, so they can be rebound as needed.
3468   (dolist (key icicle-word-completion-keys)                   (define-key map key nil))
3469   (dolist (key icicle-apropos-complete-keys)                  (define-key map key nil))
3470   (dolist (key icicle-prefix-complete-keys)                   (define-key map key nil))
3471   (dolist (key icicle-apropos-complete-no-display-keys)       (define-key map key nil))
3472   (dolist (key icicle-prefix-complete-no-display-keys)        (define-key map key nil))
3473
3474   (dolist (key icicle-prefix-cycle-previous-keys)             (define-key map key nil))
3475   (dolist (key icicle-prefix-cycle-next-keys)                 (define-key map key nil))
3476   (dolist (key icicle-apropos-cycle-previous-keys)            (define-key map key nil))
3477   (dolist (key icicle-apropos-cycle-next-keys)                (define-key map key nil))
3478   (dolist (key icicle-prefix-cycle-previous-action-keys)      (define-key map key nil))
3479   (dolist (key icicle-prefix-cycle-previous-alt-action-keys)  (define-key map key nil))
3480   (dolist (key icicle-prefix-cycle-next-action-keys)          (define-key map key nil))
3481   (dolist (key icicle-prefix-cycle-next-alt-action-keys)      (define-key map key nil))
3482   (dolist (key icicle-apropos-cycle-previous-action-keys)     (define-key map key nil))
3483   (dolist (key icicle-apropos-cycle-previous-alt-action-keys) (define-key map key nil))
3484   (dolist (key icicle-apropos-cycle-next-action-keys)         (define-key map key nil))
3485   (dolist (key icicle-apropos-cycle-next-alt-action-keys)     (define-key map key nil))
3486   (dolist (key icicle-modal-cycle-up-keys)                    (define-key map key nil))
3487   (dolist (key icicle-modal-cycle-down-keys)                  (define-key map key nil))
3488   (dolist (key icicle-modal-cycle-up-action-keys)             (define-key map key nil))
3489   (dolist (key icicle-modal-cycle-up-alt-action-keys)         (define-key map key nil))
3490   (dolist (key icicle-modal-cycle-down-action-keys)           (define-key map key nil))
3491   (dolist (key icicle-modal-cycle-down-alt-action-keys)       (define-key map key nil))
3492   (dolist (key icicle-modal-cycle-up-help-keys)               (define-key map key nil))
3493   (dolist (key icicle-modal-cycle-down-help-keys)             (define-key map key nil))
3494   (dolist (key icicle-prefix-cycle-previous-help-keys)        (define-key map key nil))
3495   (dolist (key icicle-prefix-cycle-next-help-keys)            (define-key map key nil))
3496   (dolist (key icicle-apropos-cycle-previous-help-keys)       (define-key map key nil))
3497   (dolist (key icicle-apropos-cycle-next-help-keys)           (define-key map key nil))
3498
3499   (define-key map [(control help)]           nil)
3500   (define-key map [(control meta help)]      nil)
3501   (define-key map [(control f1)]             nil)
3502   (define-key map [(control meta f1)]        nil)
3503   (define-key map [(control meta return)]    nil)
3504   (define-key map [(meta return)]            nil)
3505   (define-key map "\C-\M-m"                  nil)
3506   (define-key map [(control shift return)]   nil)
3507   (define-key map [delete]                   nil)
3508   (define-key map [(shift delete)]           nil)
3509   (define-key map [(control ?w)]             nil)
3510   (define-key map [(control return)]         nil)
3511   (define-key map [(control ?!)]             nil)
3512   (define-key map [(control ?!)]             nil)
3513   (define-key map [(control ?|)]             nil)
3514   (define-key map [(meta ?!)]                nil)
3515   (define-key map [(meta ?|)]                nil)
3516   (define-key map [(control meta ?/)]        nil)
3517   (define-key map [(meta ?h)]                nil)
3518   (define-key map [(meta pause)]             nil)
3519   (define-key map [(control pause)]          nil)
3520   (define-key map [(shift pause)]            nil)
3521   (define-key map [(control meta pause)]     nil)
3522   (define-key map [(control insert)]         nil)
3523   (define-key map [insert]                   nil)
3524
3525   ;; In Emacs 22+, local is parent of local-completion
3526   (unless (eq minibuffer-local-map (keymap-parent minibuffer-local-completion-map))
3527     (define-key map [(control ?a)]           nil)
3528     (define-key map [(control ?e)]           nil)
3529     (define-key map [(control ?=)]           nil)
3530     (define-key map [(meta ?i)]              nil)
3531     (define-key map [(meta ?k)]              nil)
3532     (define-key map [(meta ?o)]              nil)
3533     (define-key map [(meta ?.)]              nil)
3534     (define-key map "\C-x\C-f"               nil)
3535     (define-key map [(meta ?:)]              nil)
3536     (define-key map "\C-\M-y"                nil)
3537     (define-key map [M-S-backspace]          nil)
3538     (define-key map [M-S-delete]             nil)
3539     (dolist (key  icicle-completing-read+insert-keys)
3540       (define-key minibuffer-local-must-match-map key nil))
3541     (dolist (key  icicle-read+insert-file-name-keys)
3542       (define-key minibuffer-local-must-match-map key nil))
3543     )
3544
3545   (define-key map [(meta ?q)]                nil)
3546   (define-key map [(control ?l)]             nil)
3547   (define-key map [(control shift ?l)]       nil)
3548   (define-key map [(meta ?$)]                nil)
3549   (define-key map [(control ?~)]             nil)
3550   (define-key map [(control ?-)]             nil)
3551   (define-key map [(control ?+)]             nil)
3552   (define-key map [(control ?*)]             nil)
3553   (define-key map [(control ?>)]             nil)
3554   (define-key map [(control meta ?>)]        nil)
3555   (define-key map [(control ?\()]            nil)
3556   (define-key map [(meta ?\()]               nil)
3557   (define-key map [(control ?\))]            nil)
3558   (define-key map [(control meta ?\))]       nil)
3559   (define-key map [(control meta ?<)]        nil)
3560   (define-key map [(control meta ?})]        nil)
3561   (define-key map [(control meta ?{)]        nil)
3562   (define-key map [(control ?})]             nil)
3563   (define-key map [(control ?{)]             nil)
3564   (define-key map [(control ?%)]             nil)
3565   (define-key map [(meta ?%)]                nil)
3566   (define-key map [(control ?:)]             nil)
3567   (define-key map [(control meta ?j)]        nil)
3568   (define-key map [(control ?,)]             nil)
3569   (define-key map [(control ? )]             nil)
3570   (define-key map [(control meta ?\;)]       nil)
3571   (define-key map [(control ?`)]             nil)
3572   (define-key map [(control meta ?`)]        nil)
3573   (define-key map [(control ?<)]             nil)
3574   (define-key map [(control meta ?_)]        nil)
3575   (define-key map [(control ?$)]             nil)
3576   ;; In Emacs 22+, local is parent of local-completion
3577   (unless (eq minibuffer-local-map (keymap-parent minibuffer-local-completion-map))
3578     (define-key map [(control ??)]           nil))
3579   (define-key map [(control ?.)]             nil)
3580   (define-key map [(control ?#)]             nil)
3581   (define-key map [(control ?\;)]            nil)
3582   (define-key map [(control meta ?\.)]       nil)
3583   (define-key map [(meta ?\;)]               nil)
3584   (define-key map [(control ?^)]             nil)
3585   (define-key map [(control shift ?a)]       nil)
3586   (define-key map [(meta ?~)]                nil)
3587   (define-key map [(control meta ?~)]        nil)
3588   (define-key map [(meta ?g)]                nil)
3589   (define-key map [(meta ?,)]                nil)
3590   (define-key map [(control meta ?,)]        nil)
3591   (define-key map [(control meta ?+)]        nil)
3592   (define-key map [(meta ?+)]                nil)
3593   (define-key map [(meta ?*)]                nil)
3594   (define-key map [(meta ?&)]                nil)
3595   (define-key map [(meta ?_)]                nil)
3596   (define-key map [(control meta ?&)]        nil)
3597   (define-key map [(shift ?\ )]              nil)
3598   (define-key map [(shift backspace)]        nil)
3599   (define-key map "\C-v"                     nil)
3600   (define-key map "\M-v"                     nil)
3601   (define-key map "."                        nil)
3602   (define-key map "\M-m"                     nil)
3603   (define-key map "\C-x."                    nil)
3604   (when (fboundp 'icicle-cycle-image-file-thumbnail) ; Emacs 23+
3605     (define-key map "\C-xt"                  nil))
3606   (when (fboundp 'doremi)
3607     (define-key map "\C-xw"                  nil)
3608     (define-key map "\C-x|"                  nil)
3609     (define-key map "\C-x#"                  nil)
3610     (when (fboundp 'text-scale-increase)
3611       (define-key map "\C-x-"                nil))
3612     (define-key map "\C-x1"                  nil)
3613     (define-key map "\C-x2"                  nil))
3614   ;; Do these last. -----------------
3615   (define-key map [(control ?i)]             'minibuffer-complete)
3616   (define-key map [tab]                      'minibuffer-complete)
3617   (define-key map "?"                        'minibuffer-completion-help)
3618   (define-key map " "                        'minibuffer-complete-word)
3619   (define-key map [(control ?g)]             (if (and (fboundp 'minibuffer-keyboard-quit)
3620                                                       delete-selection-mode)
3621                                                  'minibuffer-keyboard-quit
3622                                                'abort-recursive-edit))
3623   ;; In Emacs 22+, local is parent of local-completion
3624   (unless (eq minibuffer-local-map (keymap-parent minibuffer-local-completion-map))
3625     (define-key map "\n"                     'exit-minibuffer))
3626   (define-key map [(meta ?p)]                'previous-history-element)
3627   (define-key map [(meta ?n)]                'next-history-element)
3628   (define-key map [up]                       'previous-history-element)
3629   (define-key map [down]                     'next-history-element)
3630   (define-key map [(meta ?v)]                'switch-to-completions)
3631   (define-key map [prior]                    'switch-to-completions)
3632   (define-key map [next]                     'next-history-element))
3633
3634 (defun icicle-minibuffer-setup ()
3635   "Run in minibuffer on activation, to enable completion cycling.
3636 Usually run by inclusion in `minibuffer-setup-hook'."
3637   (when (and icicle-mode (window-minibuffer-p (selected-window)) (not executing-kbd-macro))
3638     ;; The pre- and post-command hooks are local to the
3639     ;; minibuffer, so they are added here, not in `icicle-mode'.
3640     ;; They are removed in `icicle-mode' when mode is exited.
3641     (unless (fboundp 'define-minor-mode) (make-local-hook 'pre-command-hook))
3642     (add-hook 'pre-command-hook  'icicle-top-level-prep) ; This must not be LOCAL (nil LOCAL arg).
3643     (add-hook 'pre-command-hook  'icicle-run-icicle-pre-command-hook nil t)
3644     (unless (fboundp 'define-minor-mode) (make-local-hook 'post-command-hook))
3645     (add-hook 'post-command-hook 'icicle-run-icicle-post-command-hook nil t)
3646     ;; Change the region background here dynamically.  It would be better to
3647     ;; just use a buffer-local face, but those don't yet exist.
3648     (when (= 1 (recursion-depth))
3649       (setq icicle-saved-region-background  (face-background 'region))
3650       (when icicle-change-region-background-flag
3651         (set-face-background 'region icicle-region-background)))
3652     ;; Reset prompt, because some commands (e.g. `find-file') don't use `read-file-name'
3653     ;; or `completing-read'.  Reset other stuff too.
3654     (setq icicle-candidate-nb                    nil
3655           icicle-completion-candidates           nil
3656           ;; This is so that cycling works right initially, without first hitting `TAB' or `S-TAB'.
3657           icicle-current-completion-mode         (and (< (minibuffer-depth) 2)
3658                                                       (case icicle-default-cycling-mode
3659                                                         ((nil)      nil)
3660                                                         (apropos    'apropos)
3661                                                         (prefix     'prefix)
3662                                                         (otherwise  nil)))
3663           icicle-next-apropos-complete-cycles-p  nil
3664           icicle-next-prefix-complete-cycles-p   nil
3665           icicle-default-directory               default-directory
3666           icicle-incremental-completion-p        icicle-incremental-completion-flag
3667           icicle-initial-value                   nil
3668           icicle-cmd-reading-input               this-command
3669           icicle-last-completion-command         nil
3670           icicle-last-completion-candidate       nil
3671           icicle-last-input                      nil
3672           icicle-input-fail-pos                  nil
3673           icicle-saved-proxy-candidates          nil
3674           ;; `other-buffer' doesn't work, because it looks for a buffer only from the same frame.
3675           icicle-pre-minibuffer-buffer           (cadr (buffer-list)) ; $$$$$$ (other-buffer nil t)
3676           )
3677     (when (and (icicle-completing-p) (> emacs-major-version 20))
3678       (let ((prompt-prefix   (if icicle-candidate-action-fn "+ " ". ")))
3679         (put-text-property 0 1 'face
3680                            (cond ((and icicle-candidate-action-fn (icicle-require-match-p))
3681                                   '(icicle-multi-command-completion icicle-mustmatch-completion))
3682                                  (icicle-candidate-action-fn 'icicle-multi-command-completion)
3683                                  ((icicle-require-match-p)
3684                                   '(icicle-completion icicle-mustmatch-completion))
3685                                  (t 'icicle-completion))
3686                            prompt-prefix)
3687         (if (overlayp icicle-completion-prompt-overlay)
3688             (move-overlay icicle-completion-prompt-overlay (point-min) (point-min))
3689           (setq icicle-completion-prompt-overlay  (make-overlay (point-min) (point-min))))
3690         (overlay-put icicle-completion-prompt-overlay 'before-string prompt-prefix)))
3691     (unless icicle-add-proxy-candidates-flag
3692       (setq icicle-saved-proxy-candidates  (prog1 icicle-proxy-candidates
3693                                              (setq icicle-proxy-candidates
3694                                                    icicle-saved-proxy-candidates))))
3695     (while icicle-saved-candidate-overlays
3696       (delete-overlay (car icicle-saved-candidate-overlays))
3697       (setq icicle-saved-candidate-overlays  (cdr icicle-saved-candidate-overlays)))
3698     (icicle-update-ignored-extensions-regexp)
3699     (when (memq icicle-default-value '(preselect-start preselect-end))
3700       (icicle-select-minibuffer-contents))
3701     (when (and icicle-show-Completions-initially-flag
3702                (not icicle-progressive-completing-p) ; If narrowed, then we have already completed.
3703                (icicle-completing-p)    ; Function initializes variable `icicle-completing-p'.
3704                (sit-for icicle-incremental-completion-delay)) ; Let user interrupt.
3705       (case icicle-default-cycling-mode
3706         (apropos    (icicle-apropos-complete))
3707         (otherwise  (icicle-prefix-complete)))) ; Prefix completion, by default.
3708     (run-hooks 'icicle-minibuffer-setup-hook)))
3709
3710 (defun icicle-define-cycling-keys (map)
3711   "Define keys for cycling candidates.
3712 The modal keys are defined first, then the non-modal keys.
3713 That means that in case of conflict mode-specific cyling wins.
3714 For example, if you define both `icicle-modal-cycle-up-keys' and
3715 `icicle-prefix-cycle-previous-keys' as ([up]), the latter gets the
3716 binding."
3717   (cond (icicle-use-C-for-actions-flag  ; Use `C-' for actions, no `C-' for plain cycling.
3718          ;; Modal cycling keys.
3719          (dolist (key icicle-modal-cycle-up-keys)
3720            (define-key map key 'icicle-previous-candidate-per-mode)) ; `up'
3721          (dolist (key icicle-modal-cycle-down-keys)
3722            (define-key map key 'icicle-next-candidate-per-mode)) ; `down'
3723          (dolist (key icicle-modal-cycle-up-action-keys)
3724            (define-key map key 'icicle-previous-candidate-per-mode-action)) ; `C-up'
3725          (dolist (key icicle-modal-cycle-down-action-keys)
3726            (define-key map key 'icicle-next-candidate-per-mode-action)) ; `C-down'
3727          ;; Non-modal cycling keys.  In case of conflict, these will prevail over modal keys.
3728          (dolist (key icicle-prefix-cycle-previous-keys)
3729            (define-key map key 'icicle-previous-prefix-candidate)) ; `home'
3730          (dolist (key icicle-prefix-cycle-next-keys)
3731            (define-key map key 'icicle-next-prefix-candidate)) ; `end'
3732          (dolist (key icicle-apropos-cycle-previous-keys)
3733            (define-key map key 'icicle-previous-apropos-candidate)) ; `prior'
3734          (dolist (key icicle-apropos-cycle-next-keys)
3735            (define-key map key 'icicle-next-apropos-candidate)) ; `next'
3736          (dolist (key icicle-prefix-cycle-previous-action-keys)
3737            (define-key map key 'icicle-previous-prefix-candidate-action)) ; `C-home'
3738          (dolist (key icicle-prefix-cycle-next-action-keys)
3739            (define-key map key 'icicle-next-prefix-candidate-action)) ; `C-end'
3740          (dolist (key icicle-apropos-cycle-previous-action-keys)
3741            (define-key map key 'icicle-previous-apropos-candidate-action)) ; `C-prior'
3742          (dolist (key icicle-apropos-cycle-next-action-keys)
3743            (define-key map key 'icicle-next-apropos-candidate-action))) ; `C-next'
3744
3745         (t                              ; Use `C-' for plain cycling, NO `C-' for action.
3746          ;; Modal cycling keys.  At least some of these will overwrite non-modal keys.
3747          (dolist (key icicle-modal-cycle-up-keys)
3748            (define-key map key 'icicle-previous-candidate-per-mode-action)) ; `up'
3749          (dolist (key icicle-modal-cycle-down-keys)
3750            (define-key map key 'icicle-next-candidate-per-mode-action)) ; `down'
3751          (dolist (key icicle-modal-cycle-up-action-keys)
3752            (define-key map key 'icicle-previous-candidate-per-mode)) ; `C-up'
3753          (dolist (key icicle-modal-cycle-down-action-keys)
3754            (define-key map key 'icicle-next-candidate-per-mode)) ; `C-down'
3755          ;; Non-modal cycling keys.  In case of conflict, these will prevail over modal keys.
3756          (dolist (key icicle-prefix-cycle-previous-keys)
3757            (define-key map key 'icicle-previous-prefix-candidate-action)) ; `home'
3758          (dolist (key icicle-prefix-cycle-next-keys)
3759            (define-key map key 'icicle-next-prefix-candidate-action)) ; `end'
3760          (dolist (key icicle-apropos-cycle-previous-keys)
3761            (define-key map key 'icicle-previous-apropos-candidate-action)) ; `prior'
3762          (dolist (key icicle-apropos-cycle-next-keys)
3763            (define-key map key 'icicle-next-apropos-candidate-action)) ; `next'
3764          (dolist (key icicle-prefix-cycle-previous-action-keys)
3765            (define-key map key 'icicle-previous-prefix-candidate)) ; `C-home'
3766          (dolist (key icicle-prefix-cycle-next-action-keys)
3767            (define-key map key 'icicle-next-prefix-candidate)) ; `C-end'
3768          (dolist (key icicle-apropos-cycle-previous-action-keys)
3769            (define-key map key 'icicle-previous-apropos-candidate)) ; `C-prior'
3770          (dolist (key icicle-apropos-cycle-next-action-keys)
3771            (define-key map key 'icicle-next-apropos-candidate))))
3772
3773   ;; Help and alternative-action keys are NOT controlled by `icicle-use-C-for-actions-flag'.
3774   ;;
3775   ;; Define modal cycling help and alternative action keys.
3776   (dolist (key icicle-modal-cycle-up-help-keys)
3777     (define-key map key 'icicle-previous-candidate-per-mode-help)) ; `C-M-up'
3778   (dolist (key icicle-modal-cycle-down-help-keys)
3779     (define-key map key 'icicle-next-candidate-per-mode-help)) ; `C-M-down'
3780   (dolist (key icicle-modal-cycle-up-alt-action-keys)
3781     (define-key map key 'icicle-previous-candidate-per-mode-alt-action)) ; `C-S-up'
3782   (dolist (key icicle-modal-cycle-down-alt-action-keys)
3783     (define-key map key 'icicle-next-candidate-per-mode-alt-action)) ; `C-S-down'
3784   ;; Define non-modal cycling help and alternative action keys.
3785   (dolist (key icicle-prefix-cycle-previous-help-keys)
3786     (define-key map key 'icicle-help-on-previous-prefix-candidate)) ; `C-M-home'
3787   (dolist (key icicle-prefix-cycle-next-help-keys)
3788     (define-key map key 'icicle-help-on-next-prefix-candidate)) ; `C-M-end'
3789   (dolist (key icicle-apropos-cycle-previous-help-keys)
3790     (define-key map key 'icicle-help-on-previous-apropos-candidate)) ; `C-M-prior'
3791   (dolist (key icicle-apropos-cycle-next-help-keys)
3792     (define-key map key 'icicle-help-on-next-apropos-candidate)) ; `C-M-next'
3793   (dolist (key icicle-prefix-cycle-previous-alt-action-keys)
3794     (define-key map key 'icicle-previous-prefix-candidate-alt-action)) ; `C-S-home'
3795   (dolist (key icicle-prefix-cycle-next-alt-action-keys)
3796     (define-key map key 'icicle-next-prefix-candidate-alt-action)) ; `C-S-end'
3797   (dolist (key icicle-apropos-cycle-previous-alt-action-keys)
3798     (define-key map key 'icicle-previous-apropos-candidate-alt-action)) ; `C-S-prior'
3799   (dolist (key icicle-apropos-cycle-next-alt-action-keys)
3800     (define-key map key 'icicle-next-apropos-candidate-alt-action))) ; `C-S-next'
3801
3802 (defun icicle-select-minibuffer-contents ()
3803   "Select minibuffer contents and leave point at its beginning."
3804   (let ((min  (icicle-minibuffer-prompt-end)))
3805     (set-mark (if (eq 'preselect-start icicle-default-value) (point-max) min))
3806     (goto-char (if (eq 'preselect-start icicle-default-value) min (point-max)))))
3807
3808 ;; $$$ (defadvice next-history-element (after icicle-select-minibuffer-contents activate)
3809 ;;   "Select minibuffer contents and leave point at its beginning."
3810 ;;   (when (and icicle-mode (memq icicle-default-value '(preselect-start preselect-end)))
3811 ;;     (icicle-select-minibuffer-contents)
3812 ;;     (setq deactivate-mark  nil)))
3813
3814 (defun icicle-cancel-Help-redirection ()
3815   "Cancel redirection of focus from *Help* buffer to minibuffer.
3816 Focus was redirected during `icicle-help-on-candidate'."
3817   (let* ((help-window  (get-buffer-window "*Help*" 0))
3818          (help-frame   (and help-window (window-frame help-window))))
3819     (when help-frame (redirect-frame-focus help-frame))))
3820
3821 (defun icicle-run-icicle-pre-command-hook ()
3822   "Run `icicle-pre-command-hook' functions.
3823 Used in `pre-command-hook'."
3824   (run-hooks 'icicle-pre-command-hook))
3825
3826 (defun icicle-run-icicle-post-command-hook ()
3827   "Run `icicle-post-command-hook' functions.
3828 Used in `post-command-hook'."
3829   (run-hooks 'icicle-post-command-hook))
3830
3831 (defun icicle-set-calling-cmd ()
3832   "Remember last command that called for completion.
3833 Used in `completion-setup-hook'."
3834   (setq icicle-cmd-calling-for-completion  this-command))
3835
3836 (defun icicle-update-ignored-extensions-regexp ()
3837   "Update ignored extensions if `completion-ignored-extensions' changed."
3838   (when (and (icicle-file-name-input-p) ; In `icicles-fn.el'.
3839              (not (equal icicle-ignored-extensions completion-ignored-extensions)))
3840     (setq icicle-ignored-extensions-regexp ; Make regexp for ignored file extensions.
3841           (concat "\\(" (mapconcat #'regexp-quote completion-ignored-extensions "\\|") "\\)\\'")
3842
3843           ;; Flag to prevent updating `icicle-ignored-extensions-regexp' unless
3844           ;; `completion-ignored-extensions' changes.
3845           icicle-ignored-extensions  completion-ignored-extensions)))
3846
3847 ;; We change the region background here dynamically.
3848 ;; It would be better to just use a buffer-local face, but those don't yet exist.
3849 (defun icicle-restore-region-face ()
3850   "Restore region face.  It was changed during minibuffer activity
3851 if `icicle-change-region-background-flag' is non-nil."
3852   (when (and icicle-change-region-background-flag (= 1 (recursion-depth)))
3853     (set-face-background 'region icicle-saved-region-background)))
3854
3855 (defun icicle-activate-mark ()
3856   "Prevent region from being deactivated.  Use in `icicle-post-command-hook'."
3857   (when (and (window-minibuffer-p (selected-window))
3858              icicle-completing-p
3859              (not executing-kbd-macro))
3860     (setq deactivate-mark  nil)))
3861
3862 (defun icicle-redefine-standard-functions ()
3863   "Alias the functions in `icicle-functions-to-redefine' to Icicles versions."
3864   (when (fboundp 'icicle-completing-read)
3865     (dolist (fn  icicle-functions-to-redefine)
3866       (when (fboundp (intern (concat "old-" (symbol-name fn))))
3867         (defalias fn (intern (concat "icicle-" (symbol-name fn))))))))
3868
3869 (defun icicle-restore-standard-functions ()
3870   "Restore original versions of functions in `icicle-functions-to-redefine'."
3871   (when (fboundp 'old-completing-read)
3872     (let (old-fn)
3873       (dolist (fn  icicle-functions-to-redefine)
3874         (when (fboundp (setq old-fn  (intern (concat "old-" (symbol-name fn)))))
3875           (defalias fn old-fn))))))
3876
3877 ;;; In Emacs versions before 22:
3878 ;;; Save original `read-file-name'.  We redefine it as `icicle-read-file-name' (which calls it).
3879 ;;; Then we restore it when you quit Icicle mode.  (In Emacs 22+, no redefinition is needed.)
3880 (unless (or (boundp 'read-file-name-function) (fboundp 'orig-read-file-name))
3881   (defalias 'orig-read-file-name (symbol-function 'read-file-name)))
3882
3883 (defun icicle-redefine-std-completion-fns ()
3884   "Replace some standard functions with versions for Icicle mode."
3885   (when (fboundp 'icicle-completing-read)
3886     (defalias 'choose-completion            'icicle-choose-completion)
3887     (defalias 'choose-completion-string     'icicle-choose-completion-string)
3888     (defalias 'completing-read              'icicle-completing-read)
3889     (defalias 'completion-setup-function    'icicle-completion-setup-function)
3890     (unless (> emacs-major-version 22)
3891       (defalias 'dired-smart-shell-command  'icicle-dired-smart-shell-command))
3892     (defalias 'display-completion-list      'icicle-display-completion-list)
3893     (defalias 'exit-minibuffer              'icicle-exit-minibuffer)
3894     (when (fboundp 'face-valid-attribute-values)
3895       (defalias 'face-valid-attribute-values 'icicle-face-valid-attribute-values))
3896     (defalias 'minibuffer-complete-and-exit 'icicle-minibuffer-complete-and-exit)
3897     (defalias 'mouse-choose-completion      'icicle-mouse-choose-completion)
3898     (defalias 'next-history-element         'icicle-next-history-element)
3899     (defalias 'read-face-name               'icicle-read-face-name)
3900     (if (boundp 'read-file-name-function) ; Emacs 22+
3901         (setq icicle-old-read-file-name-fn  (prog1 (and (not (eq read-file-name-function
3902                                                                  'icicle-read-file-name))
3903                                                         read-file-name-function)
3904                                               (setq read-file-name-function
3905                                                     'icicle-read-file-name)))
3906       (defalias 'read-file-name             'icicle-read-file-name)) ; Emacs 20, 21
3907     (when (fboundp 'icicle-read-number)
3908       (defalias 'read-number                'icicle-read-number))
3909     (unless (> emacs-major-version 22)
3910       (defalias 'shell-command              'icicle-shell-command))
3911     (unless (> emacs-major-version 22)
3912       (defalias 'shell-command-on-region    'icicle-shell-command-on-region))
3913     (defalias 'switch-to-completions        'icicle-switch-to-completions)
3914     (when (fboundp 'icicle-completing-read-multiple)
3915       (defalias 'completing-read-multiple   'icicle-completing-read-multiple)
3916       (setq crm-local-completion-map  icicle-crm-local-completion-map
3917             crm-local-must-match-map  icicle-crm-local-must-match-map))
3918     (when (> emacs-major-version 22)
3919       (defalias 'sit-for                    'icicle-sit-for))
3920     ))
3921
3922 (defun icicle-restore-std-completion-fns ()
3923   "Restore some standard functions that were replaced in Icicle mode."
3924   (when (fboundp 'old-completing-read)
3925     (defalias 'choose-completion            'old-choose-completion)
3926     (defalias 'choose-completion-string     'old-choose-completion-string)
3927     (defalias 'completing-read              'old-completing-read)
3928     (defalias 'completion-setup-function    'old-completion-setup-function)
3929     (when (fboundp 'old-dired-smart-shell-command) ; Emacs 23
3930       (defalias 'dired-smart-shell-command  'old-dired-smart-shell-command))
3931     (defalias 'display-completion-list      'old-display-completion-list)
3932     (defalias 'exit-minibuffer              'old-exit-minibuffer)
3933     (when (fboundp 'old-face-valid-attribute-values)
3934       (defalias 'face-valid-attribute-values 'old-face-valid-attribute-values))
3935     (defalias 'minibuffer-complete-and-exit 'old-minibuffer-complete-and-exit)
3936     (defalias 'mouse-choose-completion      'old-mouse-choose-completion)
3937     (defalias 'next-history-element         'old-next-history-element)
3938     (defalias 'read-face-name               'old-read-face-name)
3939     (if (boundp 'read-file-name-function) ; Emacs 22+
3940         (setq read-file-name-function  (and (not (eq icicle-old-read-file-name-fn
3941                                                      'icicle-read-file-name))
3942                                             icicle-old-read-file-name-fn))
3943       (defalias 'read-file-name             'orig-read-file-name)) ; Emacs 20, 21
3944     (when (fboundp 'old-read-number)
3945       (defalias 'read-number                'old-read-number))
3946     (when (fboundp 'old-shell-command) ; Emacs 23
3947       (defalias 'shell-command              'old-shell-command))
3948     (when (fboundp 'old-shell-command-on-region) ; Emacs 23
3949       (defalias 'shell-command-on-region    'old-shell-command-on-region))
3950     (defalias 'switch-to-completions        'old-switch-to-completions)
3951     (when (fboundp 'old-completing-read-multiple)
3952       (defalias 'completing-read-multiple   'old-completing-read-multiple)
3953       (setq crm-local-completion-map  old-crm-local-completion-map
3954             crm-local-must-match-map  old-crm-local-must-match-map))
3955     (when (> emacs-major-version 22)
3956       (defalias 'sit-for                    'old-sit-for))
3957     ))
3958
3959 ;; Free vars here: `icicle-saved-kmacro-ring-max' is bound in `icicles-var.el'.
3960 (defun icicle-redefine-standard-options ()
3961   "Replace certain standard Emacs options with Icicles versions."
3962   (when (boundp 'icicle-search-ring-max)
3963     (setq icicle-saved-search-ring-max         search-ring-max ; Save it.
3964           search-ring-max                      icicle-search-ring-max
3965           icicle-saved-regexp-search-ring-max  regexp-search-ring-max ; Save it.
3966           regexp-search-ring-max               icicle-regexp-search-ring-max))
3967   (when (boundp 'icicle-kmacro-ring-max)
3968     (setq icicle-saved-kmacro-ring-max  kmacro-ring-max ; Save it.
3969           kmacro-ring-max               icicle-kmacro-ring-max)))
3970
3971 (defun icicle-restore-standard-options ()
3972   "Restore standard Emacs options replaced in Icicle mode."
3973   (when (boundp 'icicle-saved-search-ring-max)
3974     (setq search-ring-max         icicle-saved-search-ring-max
3975           regexp-search-ring-max  icicle-saved-regexp-search-ring-max)))
3976
3977 ;; This is used only in Emacs 22+, but we define it always anyway.
3978 (defun icicle-undo-std-completion-faces ()
3979   "Get rid of standard completion-root highlighting in `*Completions*'."
3980   ;; Do this because the standard Emacs 22 highlighting can interfere with
3981   ;; apropos-completion highlighting.
3982   (when (fboundp 'face-spec-reset-face)
3983     (when (facep 'completions-common-part)
3984       (face-spec-reset-face 'completions-common-part)
3985       (set-face-attribute 'completions-common-part nil :inherit nil))
3986     (when (facep 'completions-first-difference)
3987       (face-spec-reset-face 'completions-first-difference)
3988       (set-face-attribute 'completions-first-difference nil :inherit nil))))
3989
3990
3991 ;;; Save original functions, so they can be restored when leave Icicle mode.
3992 ;;; Toggle Icicle mode after loading the library (and `icicles-mode.el'),
3993 ;;; to pick up the original definition.
3994 ;;;
3995 ;;; Note: The `boundp' test for `icicle-mode' is just in case the form gets evaluated while
3996 ;;; loading `icicles-mode.el' (e.g. the library gets loaded while loading `icicles-mode.el').
3997
3998 ;;; `comint.el' - `comint-dynamic-complete', `comint-replace-by-expanded-filename'.
3999 (let ((form  '(let ((icyp  (and (boundp 'icicle-mode) icicle-mode)))
4000                (when icyp (icicle-mode -1))
4001                (when (and (fboundp 'comint-dynamic-complete)
4002                           (not (fboundp 'old-comint-dynamic-complete)))
4003                  (defalias 'old-comint-dynamic-complete (symbol-function 'comint-dynamic-complete)))
4004                (when (and (fboundp 'comint-dynamic-complete-filename)
4005                           (not (fboundp 'old-comint-dynamic-complete-filename)))
4006                  (defalias 'old-comint-dynamic-complete-filename
4007                      (symbol-function 'comint-dynamic-complete-filename)))
4008                (when (and (fboundp 'comint-replace-by-expanded-filename)
4009                           (not (fboundp 'old-comint-replace-by-expanded-filename)))
4010                  (defalias 'old-comint-replace-by-expanded-filename
4011                      (symbol-function 'comint-replace-by-expanded-filename)))
4012                (when icyp (icicle-mode 1)))))
4013   (if (featurep 'comint) (eval-after-load "icicles-mode" form) (eval-after-load "comint" form)))
4014
4015 ;;; `ess-site.el' - `ess-complete-object-name'.
4016 (let ((form  '(let ((icyp  (and (boundp 'icicle-mode) icicle-mode)))
4017                (when icyp (icicle-mode -1))
4018                (when (and (fboundp 'ess-complete-object-name)
4019                           (not (fboundp 'old-ess-complete-object-name)))
4020                  (defalias 'old-ess-complete-object-name (symbol-function
4021                                                           'ess-complete-object-name)))
4022                (when icyp (icicle-mode 1)))))
4023   (if (featurep 'ess-site) (eval-after-load "icicles-mode" form) (eval-after-load "ess-site" form)))
4024
4025 ;;; `gud.el' - `gud-gdb-complete-command'.
4026 (let ((form  '(let ((icyp  (and (boundp 'icicle-mode) icicle-mode)))
4027                (when icyp (icicle-mode -1))
4028                (when (and (fboundp 'gud-gdb-complete-command)
4029                           (not (fboundp 'old-gud-gdb-complete-command)))
4030                  (defalias 'old-gud-gdb-complete-command (symbol-function
4031                                                           'gud-gdb-complete-command)))
4032                (when icyp (icicle-mode 1)))))
4033   (if (featurep 'gud) (eval-after-load "icicles-mode" form) (eval-after-load "gud" form)))
4034
4035 ;;; `info.el' - `Info-goto-node', `Info-index', `Info-menu'.
4036 (let ((form  '(let ((icyp  (and (boundp 'icicle-mode) icicle-mode)))
4037                (when icyp (icicle-mode -1))
4038                (when (and (featurep 'info) (not (fboundp 'old-Info-goto-node)))
4039                  (defalias 'old-Info-goto-node (symbol-function 'Info-goto-node))
4040                  (defalias 'old-Info-index     (symbol-function 'Info-index))
4041                  (defalias 'old-Info-menu      (symbol-function 'Info-menu)))
4042                (when icyp (icicle-mode 1)))))
4043   (if (featurep 'info) (eval-after-load "icicles-mode" form) (eval-after-load "info" form)))
4044
4045 ;;; `bbdb-com.el' -  `bbdb-complete-name'.
4046 (let ((form  '(let ((icyp  (and (boundp 'icicle-mode) icicle-mode)))
4047                (when icyp (icicle-mode -1))
4048                (when (and (fboundp 'bbdb-complete-name) (not (fboundp 'old-bbdb-complete-name)))
4049                  (defalias 'old-bbdb-complete-name (symbol-function 'bbdb-complete-name)))
4050                (when icyp (icicle-mode 1)))))
4051   (if (featurep 'bbdb-com) (eval-after-load "icicles-mode" form) (eval-after-load "bbdb-com" form)))
4052
4053 ;;; `dired-aux.el' - `dired-read-shell-command'.
4054 (let ((form  '(let ((icyp  (and (boundp 'icicle-mode) icicle-mode)))
4055                (when icyp (icicle-mode -1))
4056                (when (and (fboundp 'dired-read-shell-command)
4057                           (not (fboundp 'old-dired-read-shell-command)))
4058                  (defalias 'old-dired-read-shell-command (symbol-function
4059                                                           'dired-read-shell-command)))
4060                (when icyp (icicle-mode 1)))))
4061   (if (featurep 'dired-aux)
4062       (eval-after-load "icicles-mode" form)
4063     (eval-after-load "dired-aux" form)))
4064
4065 ;;; `dired-x.el' - `dired-read-shell-command', `dired-smart-shell-command'.
4066 (let ((form  '(let ((icyp  (and (boundp 'icicle-mode) icicle-mode)))
4067                (when icyp (icicle-mode -1))
4068                (when (and (fboundp 'dired-read-shell-command)
4069                           (not (fboundp 'old-dired-read-shell-command)))
4070                  (defalias 'old-dired-read-shell-command (symbol-function
4071                                                           'dired-read-shell-command)))
4072                (unless (fboundp 'read-shell-command) ; `dired-smart-shell-command' in Emacs < 23.
4073                  (when (and (fboundp 'dired-smart-shell-command)
4074                             (not (fboundp 'old-dired-smart-shell-command)))
4075                    (defalias 'old-dired-smart-shell-command (symbol-function
4076                                                              'dired-smart-shell-command))))
4077                (when icyp (icicle-mode 1)))))
4078   (if (featurep 'dired-x) (eval-after-load "icicles-mode" form) (eval-after-load "dired-x" form)))
4079
4080 ;;; `simple.el' - `read-shell-command' - Emacs 23+.
4081 (when (> emacs-major-version 22)
4082   ;; `simple.el' is preloaded for Emacs 23+, so just do it now.
4083   (let ((icyp  (and (boundp 'icicle-mode) icicle-mode)))
4084     (when icyp (icicle-mode -1))
4085     (when (and (fboundp 'read-shell-command) (not (fboundp 'old-read-shell-command)))
4086       (defalias 'old-read-shell-command (symbol-function 'read-shell-command)))
4087     (when icyp (icicle-mode 1))))
4088
4089 ;;; `recentf.el' - `recentf-make-menu-items'.
4090 (let ((form  '(let ((icyp  (and (boundp 'icicle-mode) icicle-mode)))
4091                (when icyp (icicle-mode -1))
4092                (when (and (fboundp 'recentf-make-menu-items)
4093                           (not (fboundp 'old-recentf-make-menu-items)))
4094                  (defalias 'old-recentf-make-menu-items (symbol-function 'recentf-make-menu-items)))
4095                (when icyp (icicle-mode 1)))))
4096   (if (featurep 'recentf) (eval-after-load "icicles-mode" form) (eval-after-load "recentf" form)))
4097
4098       
4099 ;; Do this last.
4100 ;;
4101 ;; When these libraries are first loaded, toggle Icicle mode to pick up the definitions
4102 (dolist (library '("bookmark+" "buff-menu" "comint" "dired" "ess-site" "gud" "ibuffer"
4103                    "idlw-shell"         ; (untested - I don't have an `idl' program)
4104                    "ielm" "info" "net-utils" "rlogin" "shell" "sh-script" "tcl"))
4105   (unless (if (fboundp 'load-history-regexp) ; Emacs 22+
4106               (load-history-filename-element (load-history-regexp library))
4107             (assoc library load-history))
4108     (eval-after-load library '(icicle-toggle-icicle-mode-twice))))
4109
4110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4111
4112 (provide 'icicles-mode)
4113
4114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4115 ;;; icicles-mode.el ends here