unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
blob b65cef3690a03de1bbc0b65d661c292cf693d629 2232 bytes (raw)
name: emacs/selection-menu.el 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
 
;;; selection-menu.el --- "generic" menu to choose one string.
;;;
;;; Author: Tomi Ollila -- too ät iki piste fi

;;; License: GPLv2+

(defun selection-menu (ident items &optional unread)
  "Pops up a buffer listing lines given ITEMS one per line.
Use arrow keys (and C-p/C-n) to select and SPC/RET to select.
Return to parent buffer when any other key is pressed.
In this case if optional UNREAD is non-nil return the
read key back to input queue for parent to consume."
  (if (eq (length items) 0) nil
    (let ((helpmsg "Type ESC to abort, Space or Enter to select.")
	  (saved-point (point))
	  select buffer first last overlay pevent)
      (save-window-excursion
	(setq buffer (get-buffer-create " *Selection Menu*"))
	(set-buffer buffer)
	(setq buffer-read-only nil)
	(kill-all-local-variables)
	(erase-buffer)
	(dolist (item items) (insert " " item "\n"))
	(forward-line -1)
	(setq last (point))
	(goto-char (point-min))
	(setq first (1+ (point)))
	(pop-to-buffer buffer)
	(setq mode-name "Selection Menu"
	      mode-line-buffer-identification (concat "*" ident "*")
	      buffer-read-only t
	      overlay (make-overlay (point) (line-end-position)))
	(overlay-put overlay 'face 'highlight)
	(while
	    (let ((event (read-key helpmsg)))
	      (cond ((or (eq event 'up) (eq event 16))
		     (when (> (point) first)
		       (forward-line -1)
		       (move-overlay overlay (point) (line-end-position)))
		     t)
		    ((or (eq event 'down) (eq event 14))
		     (when (< (point) last)
		       (forward-line)
		       (move-overlay overlay (point) (line-end-position)))
		     t)
		    ((or (eq event 32) (eq event 13) (eq event 'return))
		     (setq select
			   (buffer-substring (1+ (point))
					     (line-end-position)))
		     nil)
		    ((eq event 'escape)
		     nil)
		    (t (setq pevent event)
		       nil)
		    ))))
      (goto-char saved-point)
      (kill-buffer buffer)
      (if (and unread pevent)
	  (push pevent unread-command-events))
      (message "")
      select)))

;;(selection-menu "foo" (list))
;;(selection-menu "foo" (list "a"))
;;(selection-menu "Send mail to:" (list "a" "b" "c" "d" "faaarao") t)
;; test by entering c-x c-e at the end of previous lines

(provide 'selection-menu)

debug log:

solving b65cef3 ...
found b65cef3 in https://yhetil.org/notmuch/1330009817-24148-1-git-send-email-tomi.ollila@iki.fi/

applying [1/1] https://yhetil.org/notmuch/1330009817-24148-1-git-send-email-tomi.ollila@iki.fi/
diff --git a/emacs/selection-menu.el b/emacs/selection-menu.el
new file mode 100644
index 0000000..b65cef3

Checking patch emacs/selection-menu.el...
Applied patch emacs/selection-menu.el cleanly.

index at:
100644 b65cef3690a03de1bbc0b65d661c292cf693d629	emacs/selection-menu.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).