如何设置 org-mode 快速键序列

how to setup org-mode speed key sequence

我经常使用 org-mode 的快速键,我希望将按键序列作为快速键以便于记忆。在这种情况下,我想让 "i n" 插入一个副标题,"i t" 插入一个 todo 副标题。

我知道我可以使用这样的前缀键盘映射来设置序列:

(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)

所以按"C-c i n""C-c i t"调用相应的功能。很好

现在,当我将 "my-org-speed-command-insert-subheading-map" 作为 org speed 命令调用的函数时

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

它没有按预期工作。我做错了什么?

我知道我不能像实际命令那样调用前缀映射,因此在绑定 global-set-key 时没有引用它,所以我怀疑问题与此有关。但是我怎么称呼它呢?或者有没有更简单的方法来实现我根本没有看到的目标?

编辑: 我找到了一种解决问题的方法,方法是让 "i" 速度键调用此函数:

(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")))
    ))

但这是一个相当丑陋的解决方案,因为我必须为每个第一个字母调用不同的函数,而第二个和第三个字母则隐藏在函数定义中。因此,广泛使用这种方法势必会在更长的时间里带来很多混乱 运行.

我很确定您只能使用单个字母来表示速度命令。例如。 org-speed-command-activate 的文档字符串说:

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

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

GNU Emacs 次要模式,为 org-mode 提供类似 vi 的绑定

看一看,或者可能来自同一作者的"hydra"包。