Arthur Miller <arthur.mil...@live.com> writes: > Anyway, I have been playing and testing a bit, and didn't want to prolong > discussion untill I have something to show. So here is a small prototype. It > is > just a rough sketch of the idea.
Thanks! I will not comment on Elisp part just yet. Let's first settle down the design. > this example the mode map approach seems slightly more convenient. I don't > know, > in org-agenda-test, I haven't implemented all of org-agenda, restrictions, > prefixes and some other stuff, mostly because I don't really understand the > implementation. In the nutshell, agenda restrictions will execute some elisp that sets certain global variables affecting other agenda commands. selecting the restriction should not leave the agenda menu. Also, unlike other selections being echoed literally upon selection, restriction echo must depend on the global state. If you press "<" in the menu, the menu prompt should change between "Press key for agenda command (unrestricted):", Press key for agenda command (restricted to buffer):, ... etc Note that there is not much point echoing the selection. Tim, do I understand correctly that changed minibuffer prompt will be also spoken out by emacspeak? > About the name: org-select; i really have no idea what to call it, so better > name would be nice. Sorry for the bugs, I am aware of many, but it still > displays the idea I think. It does not matter at this point. We can discuss it at the very end. It is not like M-x replace-regexp is difficult to run later. > (defun osl--make-mode-map () > (let ((map (make-sparse-keymap))) > (define-key map [?q] #'org-select-quit) > (define-key map [?\C-g] #'org-select-abort) > (define-key map [left] #'osl--back) > (define-key map [?\C-p] #'osl--back) binding left and C-p is unexpected. C-n and C-p are usually dedicated to moving around. A very conservative alternative could be creating a new buffer for sub-menus and letting the user use the usual previous-buffer command. > ;;; API > > (defun org-select (tables &rest args) > "Select a member of an alist with multiple keys. > > TABLE is an alist which should contain entries where the car is a string. > There should be two types of entries. This is confusing because there is no TABLE argument in the command. I it not immediately clear that you can use multiple tables to build a single menu. > ARGS is a property list containing following members: Does it apply to individual menu entries? I am a bit confused here. > :text a string placed over the selection in the buffer. > :label a string used for the selections buffer name. :label name is confusing. Why not directly :buffer-name? > :always when `t', this menu is shown; even descended into submenus > :transient when `t', the menu is dissmised after user perform an > action Does it apply to the whole table? Individual entries? > TABLES are additional menus in the same format as TABLE. If there are more > than one menus, they will be separated by a separator line rendered with > character as specified in `org-select-horizontal-separator'" > (defun org-capture-test (&optional goto keys) > (defun org-capture--handle (entry) > (org-select-quit "") > (cond > ((or (equal "C" (car entry)) (equal "q" (car entry))) > (eval (nth 2 entry))) > (t > (let* ((orig-buf (current-buffer)) This looks fragile. It is hard to know what is the value of (current-buffer) after exiting the manu. It is not guaranteed to be the buffer where the menu was called initially. A more proper alternative could be allowing the menu to setup some variables _before_ running the menu. For example, org-select can store some setting as buffer-local variables in the menu buffer. This way, the caller can fill some initial settings at the calling time. The settings will then be available at the time user actually select the menu option. > (defvar org-agenda--menu > '((("a" "Agenda for current week or day" (org-agenda--exec > 'org-agenda-list)) It's nice that I can instead do `((("a" ,(propertize "Agenda for current week or day" 'face 'highlight) (org-agenda--exec 'org-agenda-list)) and the face is actually preserved (: Best, Ihor