From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: florian@fsavigny.de (Florian v. Savigny) Newsgroups: gmane.emacs.help Subject: Choosing interactively from a list Date: Sun, 07 Dec 2014 03:58:06 +0100 Message-ID: <87bnng2mkh.fsf@bertrandrussell.Speedport_W_723V_1_36_000> NNTP-Posting-Host: plane.gmane.org Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1417921126 23274 80.91.229.3 (7 Dec 2014 02:58:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 7 Dec 2014 02:58:46 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 07 03:58:39 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XxS3S-00053O-SY for geh-help-gnu-emacs@m.gmane.org; Sun, 07 Dec 2014 03:58:39 +0100 Original-Received: from localhost ([::1]:56252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XxS3S-000802-G5 for geh-help-gnu-emacs@m.gmane.org; Sat, 06 Dec 2014 21:58:38 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40631) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XxS38-0007zL-NP for help-gnu-emacs@gnu.org; Sat, 06 Dec 2014 21:58:26 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XxS31-0007EL-8I for help-gnu-emacs@gnu.org; Sat, 06 Dec 2014 21:58:18 -0500 Original-Received: from srv4.ns-domain-hosting.de ([178.63.89.203]:58152) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XxS30-0007CR-UW for help-gnu-emacs@gnu.org; Sat, 06 Dec 2014 21:58:11 -0500 X-No-Relay: not in my network Original-Received: from bertrandrussell.Speedport_W_723V_1_36_000 (p548BE8C7.dip0.t-ipconnect.de [84.139.232.199]) by srv4.ns-domain-hosting.de (Postfix) with ESMTPSA id 01F06186433 for ; Sun, 7 Dec 2014 03:58:07 +0100 (CET) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 178.63.89.203 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:101458 Archived-At: Hi there everybody, I would like to do something which seemed easy to me at first glance, but is now proving mysteriously difficult: I have a list, say ("A" "B" "C" "D" ... "Z" "a" "b" "c" "d" ... "z"). I also have an index, say 13. I would like to choose an item from this list in the minibuffer, and be able to go forward and backwards in this list, starting from the index, i.e. here, 13. In other words, if the list goes on alphabetically as hinted above, the element with the index 13 would be the string "N". I would like to have "N" as the initial input in the minibuffer, and I would like to go back (i.e. "M", "L", "K" - you name it) with some key and forth (i.e. "O", "P", "Q" and so on). I tried to do this with the usual minibuffer functions, and it almost works, but not completely as I would like it: (defun choose-from-list (list &optional index) "Choose an item from LIST in the minibuffer. Use a copy of LIST as history list, i.e. do not modify LIST. Optional arg INDEX means start in the list at index INDEX." (let ((reverse-list (reverse list)) (reverse-ind (- (length list) index)) (history-length t))=20 (read-from-minibuffer "Choose: " (nth index list) nil nil (cons 'reverse-list reverse-ind)))) (setq list (list "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "O" "P" "= Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "o" "p" "q" "r" = "s" "t" "u" "v" "w" "x" "y" "z")) (choose-from-list list 13) This does exactly what I want, i.e. hitting M-p gets me one item back in the list; M-n gets me one item forward. However, I would like to require that the user (me) cannot change the value from the list, only pick it. Thus, I have tried completing-read instead of read-from-minibuffer, because completing-read has REQUIRE-MATCH: (defun choose-from-list-cmplr (list &optional index) "Choose an item from LIST in the minibuffer. Use a copy of LIST as history list, i.e. do not modify LIST. Optional arg INDEX means start in the list at index INDEX." (let ((reverse-list (reverse list)) (reverse-ind (- (length list) index)) (history-length t))=20 (completing-read "Choose: " list nil t (nth index list) (cons 'reverse-list reverse-ind)))) I imagine this should be the same thing as regards the minibuffer history, but here, the history cycling is somehow different: Although I get the same list element as initial input, hitting M-n now gives me the item at the *beginning* of the list ("A"), M-p gives me the item at the *end*. Can somebody explain that to me? An important aspect might be that I am not really looking for completion, but rather rigid cycling through a fixed list. And the whole approach, i.e. using the history for something that is not really a history (and is not even supposed to be modified like a history variable is), reversing it etc, feels very roundabout and not as it should be. Many thanks in advance! Best regards, Florian --=20 Florian von Savigny Melanchthonstr. 41 33615 Bielefeld