[RFC PATCH 1/3] emacs: selection-menu.el
authorTomi Ollila <tomi.ollila@iki.fi>
Thu, 23 Feb 2012 15:10:15 +0000 (17:10 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:44:51 +0000 (09:44 -0800)
7d/d24305484a76c65b2ce01f1db77f5cc44ff85c [new file with mode: 0644]

diff --git a/7d/d24305484a76c65b2ce01f1db77f5cc44ff85c b/7d/d24305484a76c65b2ce01f1db77f5cc44ff85c
new file mode 100644 (file)
index 0000000..face731
--- /dev/null
@@ -0,0 +1,151 @@
+Return-Path: <too@guru.guru-group.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 89107431FAE\r
+       for <notmuch@notmuchmail.org>; Thu, 23 Feb 2012 07:10:21 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id rSHYPpDCd0F3 for <notmuch@notmuchmail.org>;\r
+       Thu, 23 Feb 2012 07:10:19 -0800 (PST)\r
+Received: from guru.guru-group.fi (guru-group.fi [87.108.86.66])\r
+       by olra.theworths.org (Postfix) with ESMTP id 824E7431FB6\r
+       for <notmuch@notmuchmail.org>; Thu, 23 Feb 2012 07:10:19 -0800 (PST)\r
+Received: by guru.guru-group.fi (Postfix, from userid 501)\r
+       id 71E9168055; Thu, 23 Feb 2012 17:10:19 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: notmuch@notmuchmail.org\r
+Subject: =?UTF-8?q?=5BRFC=20PATCH=201/3=5D=20emacs=3A=20selection-menu=2Eel?=\r
+Date: Thu, 23 Feb 2012 17:10:15 +0200\r
+Message-Id: <1330009817-24148-1-git-send-email-tomi.ollila@iki.fi>\r
+X-Mailer: git-send-email 1.7.6.1\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\r
+Cc: Tomi Ollila <tomi.ollila@iki.fi>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 23 Feb 2012 15:10:21 -0000\r
+\r
+RFC/Idea for "improving" some selections made (in notmuch or elsewhere)\r
+In the hope that this will be useful, and to get some improvement advice.\r
+\r
+I've found it somewhat difficult to use completing-read (i also tried ido-)\r
+to complete email addresses for mail recipients (not only due to the\r
+large selection of choises provided by nottoomuch-addresses.sh ;)\r
+and have tried to find alternatives.\r
+\r
+The buffer selection systems (electric-buffer-list, bs-show, etc) have been\r
+pretty useful but I haven't found anything general.\r
+\r
+After some 3 iterations I've come up with something like those but for\r
+arbitraty strings and so-far named that tool 'selection-menu'\r
+\r
+This works by popping up buffer with all the choices shown in separate\r
+lines. arrow keys (and c-p/c-n) can be used to choose string and\r
+RET/SPC to select that. Any other key will abort the selection (ESC\r
+mentioned spesifically as it never "unreads" any events).\r
+\r
+If requested user not choosing anything but pressing some key that\r
+key is "unread" so that the parent buffer will get it. I did that\r
+as in first tests I wanted to continue writing If I did not choose\r
+anything... More tests will show If really didn't want to loose that\r
+event).\r
+---\r
+ emacs/selection-menu.el |   68 +++++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 files changed, 68 insertions(+), 0 deletions(-)\r
+ create mode 100644 emacs/selection-menu.el\r
+\r
+diff --git a/emacs/selection-menu.el b/emacs/selection-menu.el\r
+new file mode 100644\r
+index 0000000..b65cef3\r
+--- /dev/null\r
++++ b/emacs/selection-menu.el\r
+@@ -0,0 +1,68 @@\r
++;;; selection-menu.el --- "generic" menu to choose one string.\r
++;;;\r
++;;; Author: Tomi Ollila -- too ät iki piste fi\r
++\r
++;;; License: GPLv2+\r
++\r
++(defun selection-menu (ident items &optional unread)\r
++  "Pops up a buffer listing lines given ITEMS one per line.\r
++Use arrow keys (and C-p/C-n) to select and SPC/RET to select.\r
++Return to parent buffer when any other key is pressed.\r
++In this case if optional UNREAD is non-nil return the\r
++read key back to input queue for parent to consume."\r
++  (if (eq (length items) 0) nil\r
++    (let ((helpmsg "Type ESC to abort, Space or Enter to select.")\r
++        (saved-point (point))\r
++        select buffer first last overlay pevent)\r
++      (save-window-excursion\r
++      (setq buffer (get-buffer-create " *Selection Menu*"))\r
++      (set-buffer buffer)\r
++      (setq buffer-read-only nil)\r
++      (kill-all-local-variables)\r
++      (erase-buffer)\r
++      (dolist (item items) (insert " " item "\n"))\r
++      (forward-line -1)\r
++      (setq last (point))\r
++      (goto-char (point-min))\r
++      (setq first (1+ (point)))\r
++      (pop-to-buffer buffer)\r
++      (setq mode-name "Selection Menu"\r
++            mode-line-buffer-identification (concat "*" ident "*")\r
++            buffer-read-only t\r
++            overlay (make-overlay (point) (line-end-position)))\r
++      (overlay-put overlay 'face 'highlight)\r
++      (while\r
++          (let ((event (read-key helpmsg)))\r
++            (cond ((or (eq event 'up) (eq event 16))\r
++                   (when (> (point) first)\r
++                     (forward-line -1)\r
++                     (move-overlay overlay (point) (line-end-position)))\r
++                   t)\r
++                  ((or (eq event 'down) (eq event 14))\r
++                   (when (< (point) last)\r
++                     (forward-line)\r
++                     (move-overlay overlay (point) (line-end-position)))\r
++                   t)\r
++                  ((or (eq event 32) (eq event 13) (eq event 'return))\r
++                   (setq select\r
++                         (buffer-substring (1+ (point))\r
++                                           (line-end-position)))\r
++                   nil)\r
++                  ((eq event 'escape)\r
++                   nil)\r
++                  (t (setq pevent event)\r
++                     nil)\r
++                  ))))\r
++      (goto-char saved-point)\r
++      (kill-buffer buffer)\r
++      (if (and unread pevent)\r
++        (push pevent unread-command-events))\r
++      (message "")\r
++      select)))\r
++\r
++;;(selection-menu "foo" (list))\r
++;;(selection-menu "foo" (list "a"))\r
++;;(selection-menu "Send mail to:" (list "a" "b" "c" "d" "faaarao") t)\r
++;; test by entering c-x c-e at the end of previous lines\r
++\r
++(provide 'selection-menu)\r
+-- \r
+1.7.8.2\r
+\r