;; This 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 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 GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
(defconst querer-version "0.1.4")
;;; New since 0.0:
;; Name change to querer.el (there's already a query.el)
;; Provide a recursive edit feature.
;; querer is a small utility to query the user for options and select
;; one of the options. So, meant for elisp authors.
;; Main function is: querer.
;; Tested with emacs >= 21.2, breaks on 20.7.
;; This example says it all:
(defun querer-example ()
"s: Type this to save some buffers,
S: Type this to save this buffer,
q: to quit
e: recursive edit."
;; Roman Belenov
;; Currently known user(s) of querer.el: ges.el
(defgroup querer nil
"The group querer"
(defcustom querer-after-load-hooks nil
"Hooks to run after loading querer."
;(defvar querer-window-original nil)
;(defvar querer-window-configuration nil
(defun querer-message-display (mesg)
;; this one not needed, but trying... so that menu may show up at
;; bottom, hopefully..
(car (last (window-list))))
(defun querer-message-undisplay ()
;; bury rather than kill.. the user might need it..
(defun querer (bindings &optional message prompt)
"Query for a key, accept one of the choices.
PROMPT gets displayed in the minibuffer.
MESSAGE is the long passage displayed in the dialog box.
q quits--don't forget to mention that in your message.
MESSAGE can also be nil or 'auto
Each of BINDINGS is of the form:
(key function &rest arguments)
(querer-args-internal (list bindings message prompt))
(unless prompt (setq prompt querer-prompt))
(defun* querer-auto-eval (expressions &optional (message 'auto) prompt
"This function auto-generates any needed bindings.
Moreover, the input is not functions, rather it is bindings.
Those bindings result in evalling of the expressions.
Upto 62 choices are supported.
When nicks are provided and message is 'auto, we generate the message
((c1 (loop for i from ?0 to ?9 collect i))
(c2 (loop for i from ?a to ?z collect i))
(c3 (loop for i from ?A to ?Z collect i))
(choices (append c1 c2 c3))
(setq e (car pointer) pointer (cdr pointer))
(while (member* (car choices)
(setq choices (cdr choices)))
(setq c (car choices) choices (cdr choices))
,(copy-tree (car remaining)))))
(setq remaining (cdr remaining))
(setq bindings (reverse rbindings))
(if (and nicks (eql message 'auto))
#'(lambda (binding nick)
(format "%c: %s" (car binding) nick))