From 3c635136a80e9a5c56e37176860bbb0c97637a93 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Sat, 7 Apr 2018 14:24:36 +0200 Subject: [PATCH 2/6] 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. --- lisp/org-macs.el | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lisp/org-macs.el b/lisp/org-macs.el index 007882b79..c1c57fd10 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -244,6 +244,20 @@ 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, space and RET are treated equivalently." + (let* ((char (read-char-exclusive prompt)) + (key (char-to-string + (cond ((memq char '(?\s ?\t ?\r)) ?\t) + (t 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 +294,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 +307,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 +330,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")) -- 2.17.0