Giter Site home page Giter Site logo

Comments (3)

jerrypnz avatar jerrypnz commented on September 24, 2024

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?

from major-mode-hydra.el.

Sasanidas avatar Sasanidas commented on September 24, 2024

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

from major-mode-hydra.el.

jerrypnz avatar jerrypnz commented on September 24, 2024

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!

from major-mode-hydra.el.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.