如何模块化管理Hydra快捷键命令

例如,现有这样的hydra定义:

(pretty-hydra-define hydra-org
  (:color red
          :title hydra-org--title
          :hint nil)
  (
   "Navigation"
   (
    ("n" org-next-visible-heading "next")
    ("p" org-previous-visible-heading "previous")
    ("f" org-forward-heading-same-level "forward same")
    ("b" org-backward-heading-same-level "backward same")
    ("u" outline-up-heading "parent")
    ("F" org-next-block "next-block")
    ("B" org-previous-block "previous-block")
    ("g" org-clock-goto "goto clcok entry")
    )
   "Clock"
   (
    ("I" org-clock-in "in")
    ("O" org-clock-out "out")
    ("c c" org-clock-in-last "continue")
    ("c d" org-clock-display "display")
    ("c r" org-clock-report "report")
    ("c q" org-clock-cancel "quit")
    )
   ))

有没有办法把"Navigation"和"Clock"抽出来作为模块,可以被其他的hydra定义调用?

尝试过:

(defvar hydra-clock-block
  '(
    ("I" org-clock-in "in")
    ("O" org-clock-out "out")
    ("c c" org-clock-in-last "continue")
    ("c d" org-clock-display "display")
    ("c r" org-clock-report "report")
    ("c q" org-clock-cancel "quit")
    )
  "block hydra clock")

(pretty-hydra-define hydra-org
  (:color red
          :title hydra-org--title
          :hint nil)
  (
   "Navigation"
   (
    ("n" org-next-visible-heading "next")
    ("p" org-previous-visible-heading "previous")
    ("f" org-forward-heading-same-level "forward same")
    ("b" org-backward-heading-same-level "backward same")
    ("u" outline-up-heading "parent")
    ("F" org-next-block "next-block")
    ("B" org-previous-block "previous-block")
    ("g" org-clock-goto "goto clcok entry")
    )
   "Clock"
   ,hydra-clock-block
   ))

会报错:

pretty-hydra--normalize-heads-plist!: Wrong type argument: listp, \,

这个需要一种叫macro的东西 我也不会

这个怕是要给pretty-hydra作者提需求了

pretty-hydra 是支持类似功能的(原版hydra也是支持的),可以用 pretty-hydra-define+ 反向解决。

比如我是这么玩的 (我稍微魔改了一点 pretty-hydra 的API,但意思是一样的):

我在 load lsp-mode 的时候给多个major mode(如 rustic-mode)定义了 default hydra,然后在 load rustic-mode 的时候覆盖(或增加)major mode specific hydra

最简单的方式是用eval

(defvar hydra-clock-block
  '(
    ("I"  "in")
    ("I" org-clock-in "in")
    ("O" org-clock-out "out")
    ("c c" org-clock-in-last "continue")
    ("c d" org-clock-display "display")
    ("c r" org-clock-report "report")
    ("c q" org-clock-cancel "quit"))
  "block hydra clock")

(eval `(pretty-hydra-define hydra-org
         (:color red :title "ssss" :hint nil)
         ("Navigation"
          (("n" org-next-visible-heading "next")
           ("p" org-previous-visible-heading "previous")
           ("f" org-forward-heading-same-level "forward same")
           ("b" org-backward-heading-same-level "backward same")
           ("u" outline-up-heading "parent")
           ("F" org-next-block "next-block")
           ("B" org-previous-block "previous-block")
           ("g" org-clock-goto "goto clcok entry"))
          "Clock" ,hydra-clock-block)))

2赞

感谢大家的帮助! @xiyang 的方案在目前看来最简单,也很易读!