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