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