[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
elect-mbuf.el - minibuffer completion and default input cycling
From: |
Drew Adams |
Subject: |
elect-mbuf.el - minibuffer completion and default input cycling |
Date: |
Wed, 17 Jan 2001 16:42:05 -0500 |
;;; elect-mbuf.el --- Minibuffer completion and default input cycling.
;;
;; Emacs Lisp Archive Entry
;; Filename: elect-mbuf.el
;; Description: Minibuffer completion and default input cycling.
;; Author: address@hidden
;; Drew Adams
;; Maintainer: Drew Adams
;; Copyright (C) 1996-2001, Drew Adams, all rights reserved.
;; Created: Tue Aug 1 14:21:16 1995
;; Version: $Id: elect-mbuf.el,v 1.8 2001/01/10 18:42:22 dadams Exp $
;; Last-Updated: Wed Jan 10 10:40:45 2001
;; By: dadams
;; Update #: 744
;; Keywords: internal, lisp, extensions, help, abbrev, faces, local
;; Compatibility: GNU Emacs 20.x
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; Extensions to the `completing-read' commands in the minibuffer.
;; Enables minibuffer cycling of default inputs via the arrow keys,
;; and more support for input completion.
;;
;; Main new functions here:
;;
;; `abort-minibuffer-input', `assoc-tail', `buffer-alist',
;; `minibuffer-completion-help+', `mod+', `next-default-input',
;; `previous-default-input', `rebind-minibuffer-completion-maps'.
;;
;; Main new user options (variables) defined here:
;;
;; `mbuf-completion-help-face', `mbuf-completion-help-title-face'.
;;
;; Other new variables defined here:
;; `command-calling-for-completion', `completing-read-prompt',
;; `completing-read-prompt-suffix',
;; `minibuffer-completion-help-string'.
;;
;;
;; ***** NOTE: These EMACS PRIMITIVES have been REDEFINED HERE:
;;
;; `completing-read' - (See below, and doc string.)
;; `exit-minibuffer' -
;; 1) Remove *Completion* window.
;; 2) Reset `minibuffer-completion-table' so no icompletion.
;;
;; Hitting `M-n' (`M-p') will yank the next (previous) default value
;; into the buffer, from the current list of completions. For
;; example, suppose you execute the `switch-to-buffer' command, but
;; the default "other buffer" is not the one you desire. Instead of
;; typing the desired buffer's name, just hit `M-n' until the desired
;; buffer's name appears in the minibuffer, and hit return. This also
;; works with any command which reads a function or variable name, or
;; a programmer specified completion list. It does not work, however,
;; with functions which read a file name.
;;
;; Key Bindings
;; ------------
;;
;; The following binding is made here for mode `completion-list-mode'.
;; Also, character self-insertion is now inhibited in that mode.
;;
;; `C-g' `abort-minibuffer-input'
;;
;; The following bindings are made here for the minibuffer during completion.
;;
;; `?' `minibuffer-completion-help+'
;; NEXT `next-default-input', where NEXT is any binding
;; for `next-line'
;; PREV `previous-default-input', where PREV is any binding
;; for `previous-line'
;;
;; Command`delete-lines' is bound here to [M-S-backspace] and [M-S-??]
;; in all minibuffer-local-* keymaps.
;;
;; The current buffer's binding for ESC TAB is now also used for the
;; minibuffer.
;;
;;
;; NOTE:
;; Load this file only after all other files are loaded that bind
;; keys, so that the top-level `rebind-minibuffer-completion-maps'
;; here will pick up all those previous definitions.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change log:
;;
;; RCS $Log: elect-mbuf.el,v $
;; RCS Revision 1.8 2001/01/10 18:42:22 dadams
;; RCS 1. Added soft require of frame-cmds.el.
;; RCS 2. Protected remove-windows-on via fboundp.
;; RCS
;; RCS Revision 1.7 2001/01/08 22:45:20 dadams
;; RCS Adapted file header for Emacs Lisp Archive.
;; RCS
;; RCS Revision 1.6 2001/01/03 17:34:29 dadams
;; RCS *** empty log message ***
;; RCS
;; RCS Revision 1.5 2001/01/03 00:36:42 dadams
;; RCS *** empty log message ***
;; RCS
;; RCS Revision 1.4 2001/01/03 00:10:46 dadams
;; RCS *** empty log message ***
;; RCS
;; RCS Revision 1.3 2000/11/28 19:31:41 dadams
;; RCS Optional require's via 3rd arg=t now.
;; RCS
;; RCS Revision 1.2 2000/09/27 21:56:10 dadams
;; RCS *** empty log message ***
;; RCS
;; RCS Revision 1.1 2000/09/14 15:39:00 dadams
;; RCS Initial revision
;; RCS
; Revision 1.6 1999/09/03 07:49:51 dadams
; 1. Require def-face-const.el when compile.
; 2. Added: mbuf-completion-help-face, mbuf-completion-help-title-face.
; 3. minibuffer-completion-help+: use mbuf-*-face's instead of hard-coding.
; 4. minibuffer-completion-help-string, completing-read-prompt-suffix:
; defconst -> defvar.
;
; Revision 1.5 1999/08/26 09:21:43 dadams
; 1. Protected faces via boundp.
; 2. *4 -> Dark* (e.g. Magenta4 -> DarkMagenta).
;
; Revision 1.4 1999/08/25 13:56:39 dadams
; *** empty log message ***
;
; Revision 1.3 1999/04/13 12:53:32 dadams
; Bound `delete-lines' to M-S-DEL and M-S-backspace.
;
; Revision 1.2 1999/03/17 13:23:41 dadams
; 1. Removed: frame-alist, read-frame, read-number, read-buffer,
; read-variable.
; 2. Removed require: std-faces, completion.
; 3. protect calls with test fboundp.
; 4. defvar -> defconst: completing-read-prompt-suffix.
;
; Revision 1.1 1997/03/20 08:05:16 dadams
; Initial revision
;
; Revision 1.39 1996/06/28 13:19:45 dadams
; Removed read-face-name to new file faces+.el.
;
; Revision 1.38 1996/06/28 12:58:47 dadams
; Removed mouse-choose-completion to new file `mouse+.el'.
;
; Revision 1.37 1996/06/11 08:53:54 dadams
; symbol-nearest-point no longer takes an arg.
;
; Revision 1.36 1996/06/06 13:34:27 dadams
; 1. Require std-faces.el.
; 2. ###autoload: command-calling-for-completion,
; completing-read-prompt-suffix.
; 3. Update of file dependency comments (e.g. "Autoloaded from...").
;
; Revision 1.35 1996/04/26 09:09:07 dadams
; Put escaped newlines on long-line strings.
;
; Revision 1.34 1996/04/16 09:03:05 dadams
; Added read-number.
;
; Revision 1.33 1996/04/12 11:23:33 dadams
; (trivial)
;
; Revision 1.32 1996/04/12 11:01:20 dadams
; choose-completion, choose-completion-string, completion-setup-function:
; Removed to new file simple+.el.
;
; Revision 1.31 1996/04/05 14:22:22 dadams
; 1. Improved Commentary: List redefinitions.
; 2. Require completion.el (to quiet byte compiler).
;
; Revision 1.30 1996/03/26 16:11:25 dadams
; 1. minibuffer-completion-help+: concat -> concat-w-faces (color).
; 2. Added redefinition of completion-setup-function (concat-w-faces).
;
; Revision 1.29 1996/03/20 07:22:12 dadams
; 1. Added defvar for completion-reference-buffer to quiet byte compiler.
; 2. read-variable: Use new symbol-nearest-point, with syntax table arg.
;
; Revision 1.28 1996/03/08 14:46:50 dadams
; 1. Doc strings cleaned up.
; 2. read-buffer: other-buffer-anywhere -> another-buffer.
;
; Revision 1.27 1996/03/07 17:05:49 dadams
; 1. Copyright.
; 2. drew-util-19.el -> misc-fns.el, drew-strings.el -> thingatpt+.el,
; drew-windows.el -> frame-fns.el.
;
; Revision 1.26 1996/02/27 10:24:34 dadams
; (trivial)
;
; Revision 1.25 1996/02/14 16:05:08 dadams
; symbol-named-at-point -> symbol-nearest-point
;
; Revision 1.24 1996/02/12 09:35:53 dadams
; Updated header keywords (for finder).
;
; Revision 1.23 1996/02/06 10:57:52 dadams
; (trivial) Cleanup (cl etc.).
;
; Revision 1.22 1996/02/01 09:42:46 dadams
; Added read-face-name.
;
; Revision 1.21 1996/01/15 08:07:36 dadams
; read-variable: local-syntax-table -> unwind-protect, set-syntax-table
;
; Revision 1.20 1995/12/28 15:28:09 dadams
; 1. Added ;;;###autoloads.
; 2. Removed requires for drew-util-19.el, drew-strings.el, drew-windows.el,
; since autoloaded.
;
; Revision 1.19 1995/12/20 07:16:16 dadams
; exit-minibuffer: Iconify *Completion* frame.
;
; Revision 1.18 1995/12/15 08:17:40 dadams
; 1. abort-minibuffer-input: Reset minibuffer-completion-table to avoid
; icompletion.
; 2. Defined replacement exit-minibuffer to do the same as #1.
;
; Revision 1.17 1995/12/05 12:59:05 dadams
; 1) (def-completion-wrapper abort-minibuffer-input...) for completion.el.
; 2) Cosmetics: when, unless, binary setq's only, etc.
;
; Revision 1.16 1995/12/01 14:12:51 dadams
; 1) abort-minibuffer-input: Incorporated delete-selection-mode code.
; 2) rebind-minibuffer-completion-maps: Added C-g bindings for
; minibuffer-local-map, minibuffer-local-ns-map,
; minibuffer-local-isearch-map.
;
; Revision 1.15 1995/11/30 16:50:43 dadams
; Moved fset's to col 1 so imenu picks them up (cosmetic).
;
; Revision 1.14 1995/11/28 12:37:49 dadams
; Put define-key's in first column, so imenu picks them up (cosmetic).
;
; Revision 1.13 1995/11/22 15:10:27 dadams
; Require drew-strings.el and drew-windows.el.
;
; Revision 1.12 1995/10/25 10:02:44 dadams
; Put defconst of minibuffer-completion-help-string after do
; rebind-minibuffer-completion-maps, so its doc string gives bindings.
;
; Revision 1.11 1995/10/24 07:52:02 dadams
; Mention ESC-TAB completion in completing-read.
;
; Revision 1.10 1995/10/17 15:19:10 dadams
; Let minibuffer use ESC-TAB for completion (of Lisp symbols etc.)
; 1) completing-read: Minibuffer adopts current buffer's ESC-TAB binding.
; 2) Added choose-completion-string from simple.el:
; Doesn't exit minibuffer if just lisp-complete-symbol completion.
; 3) Added command-calling-for-completion to memorize current command
; (done in completion-setup-hook).
;
; Revision 1.9 1995/09/12 13:22:42 dadams
; 1) Added abort-minibuffer-input.
; 2) Define C-g as abort-minibuffer-input in completion-list-mode-map
; and minibuffer-local-* maps.
; 3) No self-insertion for completion-list-mode-map.
;
; Revision 1.8 1995/09/04 14:13:24 dadams
; Changed header to GNU std.
;
; Revision 1.7 1995/08/24 13:17:31 dadams
; flash-ding -> flash-ding-minibuffer-frame
;
; Revision 1.6 1995/08/16 08:45:42 dadams
; 1) read-frame: Added optional `existing' arg.
; 2) next-default-input: Fixed bug - skip over repeated alist entries.
;
; Revision 1.5 1995/08/10 06:27:11 dadams
; 1) Rewrote minibuffer-completion-help+: Provide help even if no completions.
; 2) So, added minibuffer-completion-help-string.
; 3) Added choose-completion (from simple.el), mouse-choose-completion
; (from mouse.el): bury-buffer in orig. -> iconify-frame here.
; 4) Put back reminder in completing-read prompt.
; 5) `?' defined correctly for minibuffer-local-must-match-map.
;
; Revision 1.4 1995/08/08 12:58:56 dadams
; next-default-input: error msg: no hard coding of key seq.
;
; Revision 1.3 1995/08/04 15:11:19 dadams
; Removed no-completing-read-reminder.
;
; Revision 1.2 1995/08/02 15:01:06 dadams
; Major rewrite.
; 1) No reminders in prompts.
; 2) Added minibuffer-completion-help+ to provide help info for *Completions*.
; 3) minibuffer-yank-next(previous)-completion -> next(previous)-default-input
; 4) Removed mod+ to drew-util-19.el.
;
; Revision 1.1 1995/08/02 09:24:26 dadams
; Initial revision
;;
;; Original posting:
;; From address@hidden Mon Jun 19 19:27:58 1989
;; To: address@hidden
;; Cc: Hans <address@hidden>
;; Subject: elect-mbuf.el
;; Date: Tue, 13 Jun 89 15:17:07 -0400
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:
(require 'cl) ;; when, unless, caar, push, pop
;; Get macro `define-face-const' when this is compiled,
;; or run interpreted, but not when the compiled code is loaded.
(eval-when-compile (require 'def-face-const))
(require 'strings nil t) ;; (no error if not found): concat-w-faces
(require 'frame-cmds nil t) ;; (no error if not found): remove-windows-on
(provide 'elect-mbuf)
;;;;;;;;;;;;;
(defsubst mod+ (x y mod)
"Add X and Y and take MOD."
(setq x (+ y x))
(if (>= x mod) (setq x (- x mod)))
(if (< x 0) (setq x (+ x mod)))
x)
;;; User variables
;;;###autoload
(defvar mbuf-completion-help-face
(or (and (boundp 'darkmagenta-foreground-face)
darkmagenta-foreground-face)
(define-face-const "DarkMagenta" nil))
"*Face used to highlight minibuffer completion help.")
;;;###autoload
(defvar mbuf-completion-help-title-face
(or (and (boundp 'red-foreground-face)
red-foreground-face)
(define-face-const "Red" nil))
"*Face used for instructions introducing completion help.")
;;; Internal variables
(defvar minibuffer-last-default nil
"If `minibuffer-completion-table' is an obarray, then this is the
index in that array of the default value to be read. If it is an
association list (alist), then this is the default value as a string.
For optimal performance, any function which reads from the minibuffer
and accepts a default value should, before reading, put that value in
`minibuffer-last-default'. For example, `completing-read' does that.")
;;;###autoload
(defun buffer-alist ()
"Alist of (BUF-NAME . BUF) items, where BUF-NAME (a string) names BUF,
which is in (buffer-list), and BUF-NAME does not start with SPACE."
(let (bn-alist)
(mapcar (function (lambda (buf) (let ((bn (buffer-name buf)))
(unless (equal " " (substring bn 0 1))
(push (cons bn buf) bn-alist)))))
(buffer-list))
(reverse bn-alist)))
(defvar completing-read-prompt "")
(or (fboundp 'old-completing-read)
(fset 'old-completing-read (symbol-function 'completing-read)))
;; REPLACES ORIGINAL:
;; (See doc string here and Commentary at beginning of this file.)
;; COMPLETING-READ-PROMPT-SUFFIX is a free variable here.
;; It is defined at the end of this file, so that its doc string is up to date.
;;;###autoload
(defun completing-read
(prompt table &optional
predicate require-match initial-input hist def inherit-input-method)
"Read string in minibuffer, with completion and default input cycling.
Minibuffer completion help via \\<minibuffer-local-completion-map>\
\\[minibuffer-completion-help+]. Completion via \\[minibuffer-complete-word], \
\\[minibuffer-complete] and ESC-TAB.
Cycling of default inputs via \\[previous-default-input] and \
\\[next-default-input].
Cycling of past inputs via \\[previous-history-element] and \
\\[next-history-element].
Searching through input history via \\[previous-matching-history-element] \
and \\[next-matching-history-element].
Case is ignored if `completion-ignore-case' is non-nil.
Type \\[exit-minibuffer] to end your input.
Args: PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HIST:
PROMPT is a string to prompt with; normally ends in a colon and space.
TABLE is an alist whose elements' cars are strings, or an obarray.
PREDICATE limits completion to a subset of TABLE.
See `try-completion' and `all-completions' for more details on
completion, TABLE, PREDICATE.
If REQUIRE-MATCH is non-nil, you are not allowed to exit unless the
input is (or completes to) an element of TABLE or is null. If it is
also not `t', \\[exit-minibuffer] doesn't exit if it effects non-null
completion. If the input is null, `completing-read' returns an empty
string, regardless of the value of REQUIRE-MATCH.
If INITIAL-INPUT is non-nil, insert it in the minibuffer initially.
If it is (STRING . POSITION), the initial input is STRING, but point
is placed POSITION characters into the string.
HIST, if non-nil, specifies a history list, and optionally the initial
position in the list. It can be a symbol, which is the history list
variable to use, or it can be a cons cell (HISTVAR . HISTPOS). In
that case, HISTVAR is the history list variable to use, and HISTPOS is
the initial position (the position in the list which INITIAL-INPUT
corresponds to). Positions are counted starting from 1 at the
beginning of the list.
DEF, if non-nil, is the default value.
If INHERIT-INPUT-METHOD is non-nil, the minibuffer inherits the
current input method and the setting of `enable-multibyte-characters'.
Completion ignores case when`completion-ignore-case' is non-nil."
(setq minibuffer-completion-table table)
(unless initial-input (setq initial-input ""))
(setq initial-input (format "%s" initial-input)) ; Convert (symbol) to string
(setq minibuffer-last-default (if (arrayp table) 0 initial-input))
;; Let minibuffer use the current buffer's binding for ESC TAB.
(let* ((map (or (current-local-map) (current-global-map)))
(esc-tab-fn (lookup-key map "\M-\t")))
(define-key minibuffer-local-completion-map "\M-\t" esc-tab-fn)
(define-key minibuffer-local-must-match-map "\M-\t" esc-tab-fn))
;; Append suffix if prompt not too long.
(if (> (length initial-input)
(- (window-width (minibuffer-window)) (length prompt)))
(setq completing-read-prompt prompt) ; No suffix added.
(setq completing-read-prompt (concat prompt
completing-read-prompt-suffix)))
(old-completing-read completing-read-prompt table predicate require-match
initial-input hist def inherit-input-method))
(defun next-default-input (&optional incr)
"Replace input by next possible default input."
(interactive)
(setq incr (or incr 1))
(cond (;;vector keymap
(arrayp minibuffer-completion-table)
(erase-buffer)
(let ((len (length minibuffer-completion-table))
next
orig)
(cond ((not (and (numberp minibuffer-last-default)
(>= minibuffer-last-default 0)
(< minibuffer-last-default len)))
(setq next 0)
(setq orig (- len 1)))
(t
(setq orig minibuffer-last-default)
(setq next (mod+ orig incr len))))
(while
(and minibuffer-completion-predicate
(not (= next orig))
(not (condition-case err
(funcall minibuffer-completion-predicate
(aref minibuffer-completion-table next))
(error nil))))
(setq next (mod+ next incr len))) ; Cycle next one.
(while (and (not (= next orig)) ; Skip to non-empty keymap entry.
(eq 0 (aref minibuffer-completion-table next)))
(setq next (mod+ next incr len)))
(setq minibuffer-last-default next) ; Set new last default.
(insert-string
(prin1-to-string (aref minibuffer-completion-table next)))))
(;; alist keymap
(consp minibuffer-completion-table)
(erase-buffer)
(let ((table (if (< incr 0)
(reverse minibuffer-completion-table)
minibuffer-completion-table))
next orig remainder)
(setq orig (assoc-tail minibuffer-last-default table))
(setq next (cdr orig))
(while (or (null (car next)) ; Skip entries if null or the same.
(string= (caar orig) (caar next)))
(pop next)
(unless next (setq next table))) ; Back to table beginning.
(while (and minibuffer-completion-predicate
(not (eq next orig))
(not (condition-case err
(funcall minibuffer-completion-predicate
(car next))
(error nil))))
(pop next) ; Cycle next one.
(while (null (car next)) ; Skip null alist entries.
(pop next)
(unless next (setq next table)))) ; Back to table beginning
(setq minibuffer-last-default (caar next)) ; Reset last default
(insert-string minibuffer-last-default)
(when (> (length minibuffer-last-default)
(- (window-width (minibuffer-window))
(length completing-read-prompt)))
(beginning-of-line))))
(t
;; Function name as keymap: e.g. 'read-file-name-internal.
;; Cannot cycle.
(when (fboundp 'flash-ding-minibuffer-frame)
(flash-ding-minibuffer-frame))
(message
(substitute-command-keys
"Cannot cycle default inputs. Try \
\\<minibuffer-local-completion-map>\\[minibuffer-complete-word]/\
\\[minibuffer-complete]/\\[minibuffer-completion-help+] to complete.")))))
(defun previous-default-input ()
"Replace input by previous possible default input."
(interactive)
(next-default-input -1))
;;;###autoload
(defun assoc-tail (element list)
"Returns longest (i.e. first) tail of LIST whose caar matches ELEMENT.
Matching is done with function `equal'."
(let ((continue t))
(while continue
(if (or (null list) (equal element (caar list)))
(setq continue nil)
(pop list)))
list))
;;;###autoload
(defun abort-minibuffer-input ()
"Abort input, or, if in delete selection mode, deactivate the mark.
Iconify \"*Completions*\" frame, if any, before aborting minibuffer
input via `abort-recursive-edit'.
This can be used in delete selection mode to cancel a selection in
the minibuffer without aborting. (A second C-g will then abort.)
This feature won't work if using icomplete (`icomplete-inhibit' =
nil; see file `icomplete.el')."
(interactive)
(if (and (boundp 'delete-selection-mode) ; Defined in `delsel.el'.
delete-selection-mode
transient-mark-mode mark-active)
(setq deactivate-mark t)
(when (fboundp 'remove-windows-on) ; Defined in `frame-cmds.el'.
(remove-windows-on "*Completions*"))
(setq minibuffer-completion-table nil) ; To avoid icompletion by default.
(abort-recursive-edit)))
;; This is just the macro expansion of the following:
;; `(def-completion-wrapper abort-minibuffer-input :minibuffer-separator)'.
;; Taken from the definition of `def-completion-wrapper' in `completion.el'.
(put 'abort-minibuffer-input 'completion-function
'use-completion-minibuffer-separator)
;; `completion-list-mode-map' not to allow normal input, and to abort on `C-g'.
(define-key completion-list-mode-map "\C-g" 'abort-minibuffer-input)
(suppress-keymap completion-list-mode-map) ; Inhibit character self-insertion.
;;;###autoload
(defun rebind-minibuffer-completion-maps ()
"Rebind minibuffer completion maps to be able to cycle minibuffer
default inputs. This should be done after all keys have been bound,
because it redefines minibuffer keymaps."
;; Default minibuffer map.
(define-key minibuffer-local-map "\C-g" 'abort-minibuffer-input)
;; This key is normally bound globally to `clear-rectangle',
;; which has little use in the minibuffer.
(when (fboundp 'delete-lines) ; Defined in `misc-cmds.el'.
(define-key minibuffer-local-map [M-S-backspace] 'delete-lines)
(define-key minibuffer-local-map [M-S-??] 'delete-lines))
;; Default minibuffer map when spaces are not allowed.
(define-key minibuffer-local-ns-map "\C-g" 'abort-minibuffer-input)
;; This key is normally bound globally to `clear-rectangle',
;; which has little use in the minibuffer.
(when (fboundp 'delete-lines) ; Defined in `misc-cmds.el'.
(define-key minibuffer-local-ns-map [M-S-backspace] 'delete-lines)
(define-key minibuffer-local-ns-map [M-S-??] 'delete-lines))
;; Minibuffer map for editing isearch strings.
(define-key minibuffer-local-isearch-map "\C-g" 'abort-minibuffer-input)
(when (fboundp 'delete-lines) ; Defined in `misc-cmds.el'.
(define-key minibuffer-local-isearch-map [M-S-backspace] 'delete-lines)
(define-key minibuffer-local-isearch-map [M-S-??] 'delete-lines))
;; Completion map
(define-key minibuffer-local-completion-map "\C-g" 'abort-minibuffer-input)
;; This key is normally bound globally to `clear-rectangle',
;; which has little use in the minibuffer.
(when (fboundp 'delete-lines) ; Defined in `misc-cmds.el'.
(define-key minibuffer-local-completion-map [M-S-backspace] 'delete-lines)
(define-key minibuffer-local-completion-map [M-S-??] 'delete-lines))
(define-key minibuffer-local-completion-map "?"
'minibuffer-completion-help+)
(mapcar (function (lambda (keyseq)
(define-key minibuffer-local-completion-map keyseq
'previous-default-input)))
(where-is-internal 'previous-line nil nil))
(mapcar (function (lambda (keyseq)
(define-key minibuffer-local-completion-map keyseq
'next-default-input)))
(where-is-internal 'next-line nil nil))
;; Must-match map.
(define-key minibuffer-local-must-match-map "\C-g" 'abort-minibuffer-input)
;; This key is normally bound globally to `clear-rectangle',
;; which has little use in the minibuffer.
(when (fboundp 'delete-lines) ; Defined in `misc-cmds.el'.
(define-key minibuffer-local-must-match-map [M-S-backspace] 'delete-lines)
(define-key minibuffer-local-must-match-map [M-S-??] 'delete-lines))
(define-key minibuffer-local-must-match-map "?"
'minibuffer-completion-help+)
(mapcar (function (lambda (keyseq)
(define-key minibuffer-local-must-match-map keyseq
'previous-default-input)))
(where-is-internal 'previous-line nil nil))
(mapcar (function (lambda (keyseq)
(define-key minibuffer-local-must-match-map keyseq
'next-default-input)))
(where-is-internal 'next-line nil nil)))
;; `minibuffer-completion-help-string' is a free variable here.
;; It is defined at the end of this file, so that its doc string is up to date.
;;;###autoload
(defun minibuffer-completion-help+ ()
"Describe minibuffer bindings. Display list of possible completions
of current minibuffer contents."
(interactive)
(save-excursion
(set-buffer (get-buffer-create "*Completions*"))
(erase-buffer))
(minibuffer-completion-help)
(switch-to-buffer-other-window "*Completions*")
(beginning-of-buffer)
(cond ((eobp) ; No completions available.
(insert minibuffer-completion-help-string)
(beginning-of-buffer))
((fboundp 'concat-w-faces)
(insert (concat-w-faces
(list mbuf-completion-help-face
minibuffer-completion-help-string)
(list mbuf-completion-help-title-face
"For help on completion, see beginning of this buffer.
"))))
(t
(insert (concat minibuffer-completion-help-string
"For help on completion, see beginning of this buffer.
"))))
(let ((compl-win (get-buffer-window "*Completions*" 'visible)))
(when compl-win (set-window-point compl-win (point))))
(set-buffer-modified-p nil))
;;;###autoload
(defvar command-calling-for-completion nil
"Last command causing display of list of possible completions.")
;; Remember command that called for completion.
(add-hook 'completion-setup-hook
(function (lambda ()
(setq command-calling-for-completion this-command)))
'append)
(or (fboundp 'old-exit-minibuffer)
(fset 'old-exit-minibuffer (symbol-function 'exit-minibuffer)))
;; REPLACES ORIGINAL:
;; 1) Remove *Completion* window.
;; 2) Reset `minibuffer-completion-table' so no icompletion unless desired.
;;;###autoload
(defun exit-minibuffer ()
"Terminate this minibuffer argument."
(interactive)
(when (fboundp 'remove-windows-on) ; Defined in `frame-cmds.el'.
(remove-windows-on "*Completions*"))
;; Don't icomplete by default from now on.
(setq minibuffer-completion-table nil)
(old-exit-minibuffer))
;; Do the bindings here and now, for default bindings.
;; May need to be done again (e.g. at startup time) to pick up new bindings.
(rebind-minibuffer-completion-maps)
;;; `XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
;; Do this *after* calling `rebind-minibuffer-completion-maps'
;; so bindings are up-to-date.
(defvar minibuffer-completion-help-string
(substitute-command-keys
"\\<minibuffer-local-completion-map> \
Minibuffer Completion
---------------------
Your input in the minibuffer can be completed in several ways.
You can:
* Complete the current input in the minibuffer.
Complete a word at a time: \\[minibuffer-complete-word]
Complete as much as possible: \\[minibuffer-complete]
* Choose a default input value.
Cycle among candidate default values: \\[previous-default-input], \
\\[next-default-input]
* Choose a previous input from the minibuffer history.
Cycle among minibuffer history items: \\[previous-history-element], \
\\[next-history-element]
Search among minibuffer history items: \
\\[previous-matching-history-element], \\[next-matching-history-element]
* Choose from the possible completions for the current input.
Show the list, plus this explanation: \\[minibuffer-completion-help+]
Choose from the list: \\<completion-list-mode-map>\
\\[choose-completion], \\[mouse-choose-completion]
(in buffer *Completions*)
The list is also available when completion is ambiguous.
* Modify your input if you like, once chosen or completed.
Send your finished input to Emacs: \
\\<minibuffer-local-completion-map>\\[exit-minibuffer]
Abandon minibuffer input: \\[abort-recursive-edit]
Remember: You can always input any character that is bound to a
command (e.g. \\[minibuffer-complete-word], \
\\[minibuffer-complete], \\[minibuffer-completion-help+]) by preceding it \
with \\<global-map>\\[quoted-insert].
Here are the current bindings for the minibuffer:
\\{minibuffer-local-completion-map}---------------------------------------\
---------------------
")
"Description of minibuffer bindings.")
;; Do *after* calling `rebind-minibuffer-completion-maps' for default suffix.
(defvar completing-read-prompt-suffix
(substitute-command-keys
"(\\<minibuffer-local-completion-map>\\[minibuffer-completion-help+] for \
help) ")
"String to append to `completing-read's prompt, if there is room.
Intended to remind you how to obtain input completion help.
Set this to nil or to \"\" to append nothing.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; `elect-mbuf.el' ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- elect-mbuf.el - minibuffer completion and default input cycling,
Drew Adams <=