Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking duplicate letter #44

Open
Sasanidas opened this issue Dec 9, 2020 · 3 comments
Open

Checking duplicate letter #44

Sasanidas opened this issue Dec 9, 2020 · 3 comments

Comments

@Sasanidas
Copy link

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.

@jerrypnz
Copy link
Owner

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?

@Sasanidas
Copy link
Author

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

@jerrypnz
Copy link
Owner

jerrypnz commented Jan 2, 2021

Hi @Sasanidas,

Thanks for posting your code snippet. Yes I think it should work. I do have a couple of suggestions though:

  1. Perhaps you can implement this check in 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.
  2. Could you stick to -map and -filter functions provided by dash.el to keep it consistent? That's the library I use for sequence manipulation
  3. Would be awesome if the error message mentions the duplicate key(s)

If you're keen, feel free to submit a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants