schmuu
schmuu

Reputation: 110

how to setup org-mode speed key sequence

I'm using org-mode's speed keys alot and I would like to have key sequences as speed keys for ease of remembering. In this case, I want to have "i n" insert a subheading, and "i t" insert a todo subheading.

I know I can setup a sequence by using a prefix keymap like this:

(progn
 (define-prefix-command 'my-org-speed-command-insert-subheading-map)

 (define-key my-org-speed-command-insert-subheading-map (kbd "n") 'jan/org-insert-subheading)
 (define-key my-org-speed-command-insert-subheading-map (kbd "t") 'jan/org-insert-todo-subheading)
)

(global-set-key (kbd "C-c i") my-org-speed-command-insert-subheading-map)

so pressing "C-c i n" and "C-c i t" call the corresponding functions. Fine.

Now, when I give "my-org-speed-command-insert-subheading-map" as the function to be called by org speed commands

(setq org-speed-commands-user (quote ((":" . helm-M-x)
                                      ("a" . org-toggle-archive-tag)
                                      ("i" . my-org-speed-command-insert-subheading-map)
                                      … … … 
                                      )))

it doesn't work as expected. What am I doing wrong?

I understand I can't call the prefix map like actual commands, and hence it isn't quoted when bound with global-set-key, so I suspect that the problem is related to this. But then how do I call it? Or is there a much simpler way for achieving my goal that I simply didn't see?

EDIT: I found a way to work around the issue for now by having the "i" speed key call this function:

(defun my-org-i-map-function ()
  (let (key1)
    (setq key1 (read-key-sequence "press \"i\" for a simple subheading, \"t\" for a TODO-subheading"))
    (cond
     ((equal key1 "i")(jan/org-insert-subheading nil))
     ((equal key1 "t")(jan/org-insert-todo-subheading nil))
     (t (message "you didn't set a function for this key sequence")))
    ))

but this is a rather ugly solution as I'd have to call different functions for every first letter, and the second and third letter are buried in the function definitions. So using this approach extensively is bound to bring about lots of confusion in the longer run.

Upvotes: 1

Views: 704

Answers (2)

dunkaroo
dunkaroo

Reputation: 136

https://github.com/abo-abo/worf

GNU Emacs minor mode that provides vi-like bindings for org-mode

Take a look or maybe "hydra" package from the same author.

Upvotes: 2

NickD
NickD

Reputation: 6412

I'm pretty sure you are limited to single letters for speed commands. E.g. the docstring for org-speed-command-activate says:

"Hook for activating single-letter speed commands. org-speed-commands-default specifies a minimal command set. Use org-speed-commands-user for further customization."

Upvotes: 0

Related Questions