summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus <rasmus@gmx.us>2018-04-07 14:24:36 +0200
committerRasmus <rasmus@gmx.us>2018-04-08 12:47:08 +0200
commitac4d5fe1b3c782011ef2a3d78cbd44b042da7c12 (patch)
treef34bd6f02c0e555341bbec44082852873b48dc4b
parent06ab656f4250ee7a765550f353743056aed31c8d (diff)
downloadorg-mode-ac4d5fe1b3c782011ef2a3d78cbd44b042da7c12.tar.gz
org-macs: Make tab, space and RET equivalent in org-mks
* lisp/org-macs.el (org--mks-read-key): New function. (org-mks): Use new function and make space, tab and RET equivalent.
-rw-r--r--lisp/org-macs.el26
1 files changed, 19 insertions, 7 deletions
diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 007882b..78c8414 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -244,6 +244,19 @@ error when the user input is empty."
'org-time-stamp-inactive)
(apply #'completing-read args)))
+(defun org--mks-read-key (allowed-keys prompt)
+ "Read a key and ensure it is a member of ALLOWED-KEYS.
+TAB, SPC and RET are treated equivalently."
+ (let* ((key (char-to-string
+ (pcase (read-char-exclusive prompt)
+ ((or ?\s ?\t ?\r) ?\t)
+ (char char)))))
+ (if (member key allowed-keys)
+ key
+ (message "Invalid key: `%s'" key)
+ (sit-for 1)
+ (org--mks-read-key allowed-keys prompt))))
+
(defun org-mks (table title &optional prompt specials)
"Select a member of an alist with multiple keys.
@@ -280,6 +293,7 @@ is selected, only the bare key is returned."
(insert title "\n\n")
(let ((des-keys nil)
(allowed-keys '("\C-g"))
+ (tab-alternatives '("\s" "\t" "\r"))
(cursor-type nil))
;; Populate allowed keys and descriptions keys
;; available with CURRENT selector.
@@ -292,7 +306,10 @@ is selected, only the bare key is returned."
(`(,(and key (pred (string-match re))) ,desc)
(let ((k (match-string 1 key)))
(push k des-keys)
- (push k allowed-keys)
+ ;; Keys ending in tab, space or RET are equivalent.
+ (if (member k tab-alternatives)
+ (push "\t" allowed-keys)
+ (push k allowed-keys))
(insert prefix "[" k "]" "..." " " desc "..." "\n")))
;; Usable entry.
(`(,(and key (pred (string-match re))) ,desc . ,_)
@@ -312,12 +329,7 @@ is selected, only the bare key is returned."
(goto-char (point-min))
(unless (pos-visible-in-window-p (point-max))
(org-fit-window-to-buffer))
- (message prompt)
- (let ((pressed (char-to-string (read-char-exclusive))))
- (while (not (member pressed allowed-keys))
- (message "Invalid key `%s'" pressed) (sit-for 1)
- (message prompt)
- (setq pressed (char-to-string (read-char-exclusive))))
+ (let ((pressed (org--mks-read-key allowed-keys prompt)))
(setq current (concat current pressed))
(cond
((equal pressed "\C-g") (user-error "Abort"))