Preselect last command in menus; reverse universal arg behavior

+ The universal argument tells a menu to use the last run command, if
  available.
+ If a last run command exists, preselect it in the menu.
This commit is contained in:
Henrik Lissner 2018-03-19 02:02:11 -04:00
parent 46dbf8f490
commit ab180cd51e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -12,12 +12,12 @@ PROMPT (a string) and COMMAND (a list of command plists; see `def-menu!').")
(defun doom-menu-read-default (prompt commands)
"Default method for displaying a completion-select prompt."
(completing-read prompt (mapcar #'car commands)))
(completing-read prompt (mapcar #'car commands) nil nil nil nil (car doom-menu-last-command)))
;;;###autoload
(defun doom--menu-read (prompt commands)
(if-let* ((choice (funcall doom-menu-display-fn prompt commands)))
(cdr (assoc choice commands))
(assoc choice commands)
(user-error "Aborted")))
;;;###autoload
@ -82,18 +82,18 @@ lisp form.
`(cl-sort ,commands #'string-lessp :key #'car)
commands)
,(format "Menu for %s" name))
(defun ,name (arg)
(defun ,name (arg command)
,(concat
(if (stringp desc) (concat desc "\n\n"))
"This is a command dispatcher. It will rerun the last command on\n"
"consecutive executions. If ARG (universal argument) is non-nil\n"
"then it always prompt you.")
(interactive "P")
(declare (interactive-only t))
(interactive
(list current-prefix-arg
(progn
(unless ,commands-var
(user-error "The '%s' menu is empty" ',name))
(doom--menu-exec
(or (unless arg doom-menu-last-command)
(setq doom-menu-last-command
(doom--menu-read
,prop-prompt
(or (cl-remove-if-not
@ -111,8 +111,12 @@ lisp form.
(or (or (not when) (eval when))
(or (not unless) (not (eval unless)))
(and (stringp project)
(file-in-directory-p buffer-file-name project-root))))))))
(file-in-directory-p (or buffer-file-name default-directory)
project-root))))))))
,commands-var)
(user-error "No commands available here"))))
(user-error "No command selected")))))))
(user-error "No commands available here"))))))
(doom--menu-exec
(cdr (or (when arg doom-menu-last-command)
(setq doom-menu-last-command command)
(user-error "No command selected"))))))))