Open Sasanidas opened 3 years ago
Sorry for the late response. This would be a really useful feature and a PR is more than welcome! Have you thought about how it's gonna work? It simply fails when there are duplicate heads?
Sorry for the late response. This would be a really useful feature and a PR is more than welcome! Have you thought about how it's gonna work? It simply fails when there are duplicate heads?
Yes, I implement a simple example in the function major-mode-hydra-generate
(defun major-mode-hydra--generate (mode body heads-plist &optional overwrite-p) "Generate a major mode hydra for given MODE with given BODY and HEADS-PLIST. Overwrite existing hydra if OVERWRITE-P is t, otherwise add new heads to it." (let* ((hydra-name (major-mode-hydra--name-for mode)) (title (when (functionp major-mode-hydra-title-generator) (funcall major-mode-hydra-title-generator mode))) (letter-sequence (seq-mapcat (lambda (x) (seq-map #'car x)) (seq-filter #'listp heads-plist))) (body (-> body (lax-plist-put :hint nil) (major-mode-hydra--put-if-absent :color 'teal) (major-mode-hydra--put-if-absent :title title) (major-mode-hydra--put-if-absent :separator major-mode-hydra-separator) (major-mode-hydra--put-if-absent :quit-key major-mode-hydra-invisible-quit-key))) (df (if overwrite-p 'pretty-hydra-define 'pretty-hydra-define+))) (if (equal (-distinct letter-sequence) letter-sequence) `(,df ,hydra-name ,body ,heads-plist) (error "There are letters duplicated in the hydra"))))
It extracts the letters from the heads-plist
variable and check if they are duplicates.
This seems to work, but there is probably a faster way to get the letters.
What do you think?
Regards
Hi @Sasanidas,
Thanks for posting your code snippet. Yes I think it should work. I do have a couple of suggestions though:
pretty-hydra-generate
so that it's more generic. You'll find that it's also easier to get all the keys as there is a heads
binding which you can extract keys from.-map
and -filter
functions provided by dash.el
to keep it consistent? That's the library I use for sequence manipulationIf you're keen, feel free to submit a PR!
Sometimes when I have like a big hydra, I mess up the configuration and duplicate some symbols.
This can be easily solve with a simple check of the major-mode/MODE/heads, but I think it may be interesting to implement it into the macro major-mode-hydra-define (or somewhere else), I can develop that feature if you think is useful for the package.
Thank you.