CVSROOT: /cvsroot/auctex Module name: auctex Changes by: Ralf Angeli <angeli> 09/03/29 19:56:22
Index: multi-prompt.el =================================================================== RCS file: /cvsroot/auctex/auctex/multi-prompt.el,v retrieving revision 5.9 retrieving revision 5.10 diff -u -b -r5.9 -r5.10 --- multi-prompt.el 3 Feb 2008 14:53:33 -0000 5.9 +++ multi-prompt.el 29 Mar 2009 19:56:22 -0000 5.10 @@ -1,17 +1,11 @@ -;;; multi-prompt.el --- completing read of multiple strings. +;;; multi-prompt.el --- Completing read of multiple strings -;; Copyright (C) 1996, 1997, 2000 Free Software Foundation +;; Copyright (C) 1996, 1997, 2000, 2009 Free Software Foundation ;; Author: Per Abrahamsen <[email protected]> +;; Maintainer: [email protected] +;; Created: 1996-08-31 ;; Keywords: extensions -;; Version: 0.4 -;; Bogus-Bureaucratic-Cruft: How 'bout ESR and the LCD people agreed -;; on a common format? - -;; LCD Archive Entry: -;; multi-prompt|Per Abrahamsen|[email protected]| -;; completing read of multiple strings| -;; 1996-08-31|0.1|~/functions/multi-prompt.el.Z| ;; 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 @@ -37,31 +31,15 @@ ;; where FOO, BAR, and BAZ are elements of some table. The function ;; `multi-prompt' is a replacement `completing-read' that will allow ;; the user to enter a string like the above, yet get completion on -;; both FOO, BAR, and BAZ. - -;;; Change Log: -;; -;; Wed Oct 3 14:48:11 EDT 2001 Peter S Galbraith <[email protected]> -;; * Version 0.4 released. -;; multi-prompt-next fixed for emacs-21. -;; Mon Jan 3 16:58:49 MET 2000 -;; * Version 0.2 released. -;; Don't allow partial completions when require-match is true. -;; Reported by 'anonymous'. -;; Sat Feb 15 17:58:31 MET 1997 -;; * Version 0.2 released. -;; Renamed predicate to `mp-predicate'. -;; Sat Aug 31 18:32:20 MET DST 1996 -;; * Version 0.1 released. -;; Fixed `predicate' bug. -;; Added provide. -;; Added `multi-prompt-found' variable. -;; Sat Aug 31 16:29:14 MET DST 1996 -;; * Created. +;; all FOO, BAR, and BAZ. ;;; Code: -(provide 'multi-prompt) +;; If `multi-prompt' (the function) is to be used as an alternative +;; for `completing-read-multiple' in Emacsen which do not provide the +;; latter, requiring crm.el will do no good, but we need it for +;; `multi-prompt-key-value'. +(require 'crm) (defvar multi-prompt-found nil "List of entries currently added during a `multi-prompt'.") @@ -151,4 +129,92 @@ (assoc content table)) (throw 'multi-prompt-next content))))) + +;;; Support for key=value completion + +;; The following code was ripped out of crm.el +;; (completing-read-multiple) and extended to support comma-separated +;; key=value lists. The code is separate from the code above. + +;; WARNING: This obviously relies on internals of crm.el and +;; minibuffer.el and will therefore have to be adapted if these +;; change. + +;; TODO: How to support stuff like "caption={[one]two}" or +;; "morekeywords={one,three,five}"? + +(defvar multi-prompt-separator "," + "Single-character string separating options in a key=value list.") +(defvar multi-prompt-key-value-sep "=" + "Single-character string separating key=value pairs.") +(defvar multi-prompt-completion-table nil + "Completion table used by `multi-prompt-key-value'.") + +(defun multi-prompt-key-value-collection-fn (string predicate flag) + "Function used by `multi-prompt-key-value' to compute completion values. +The value of STRING is the string to be completed. + +The value of PREDICATE is a function to filter possible matches, or +nil if none. + +The value of FLAG is used to specify the type of completion operation. +A value of nil specifies `try-completion'. A value of t specifies +`all-completions'. A value of lambda specifes a test for an exact match. + +For more information on STRING, PREDICATE, and FLAG, see the Elisp +Reference sections on 'Programmed Completion' and 'Basic Completion +Functions'." + (let ((beg 0) (last 0) matched) + ;; TODO: Will `string' ever contain a normal separator? + ;; `crm--select-current-element' probably already takes care that + ;; this does not happen. In that case it would also be senseless + ;; to have `multi-prompt-separator'. + (while (string-match (regexp-opt (list multi-prompt-separator + multi-prompt-key-value-sep)) + string beg) + (setq matched t + last beg + beg (match-end 0))) + (completion-table-with-context + (substring string 0 beg) + (if (or (not matched) + (string= (match-string 0 string) multi-prompt-separator)) + multi-prompt-completion-table + (cadr (assoc (substring string last (1- beg)) + multi-prompt-completion-table))) + (substring string beg) + predicate + flag))) + +;;;###autoload +(defun multi-prompt-key-value + (prompt table &optional predicate require-match initial-input + hist def inherit-input-method) + "Read multiple strings, with completion and key=value support. +PROMPT is a string to prompt with, usually ending with a colon +and a space. TABLE is an alist. The car of each element should +be a string representing a key and the optional cdr should be a +list with strings to be used as values for the key. + +See the documentation for `completing-read' for details on the +other arguments: PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HIST, +DEF, and INHERIT-INPUT-METHOD. + +The return value is the string as entered in the minibuffer." + (let* ((minibuffer-completion-table #'multi-prompt-key-value-collection-fn) + (minibuffer-completion-predicate predicate) + (minibuffer-completion-confirm + (unless (eq require-match t) require-match)) + (multi-prompt-completion-table table) + (map (if require-match + crm-local-must-match-map + crm-local-completion-map)) + (input (read-from-minibuffer + prompt initial-input map + nil hist def inherit-input-method))) + (and def (string-equal input "") (setq input def)) + input)) + +(provide 'multi-prompt) + ;;; multi-prompt.el ends here _______________________________________________ auctex-diffs mailing list [email protected] http://lists.gnu.org/mailman/listinfo/auctex-diffs
