Skip to content

cyruseuros/handle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 

Repository files navigation

./handle.jpg

A handle for major-mode generic functions.

Value Proposition

handle provides generic functions that specialize on major modes and intended purpose instead of arguments. Similar functionality is needed across programming languages such as:

  • evaluating expressions
  • starting repls
  • finding documentation
  • going to definition
  • formatting code
  • compiling code
  • listing errors

But this functionality is performed by different callables across major modes and often by multiple callables in the same one. handle groups them together so that they can be bound to a single global kbd, selected based on major mode, and run in sequence until one succeeds.

Usage

handle generates handle-* functions based on (user-specified) handle-keywords that can then be bound to a single global kbd and used in any major mode.

So by running this:

(handle '(python-mode inferior-python-mode)
          :repls #'run-python
          :formatters #'lsp-format-buffer
          :docs '(lsp-describe-thing-at-point
                  python-help-for-region-or-symbol
                  python-eldoc-for-region-or-symbol
                  python-shell-print-region-or-symbol))

And then calling handle-docs in python mode, handle will run each of the functions specified under :docs in order untill one succeeds. If a function errors out (or returns nil, see handle-nice-functions) it will calmly proceed to the next one. The same function will behave differently in other modes.

handle is also aware of the Emacs mode hierarchy. If it cannot handle the task you gave it in a specific mode, it will attempt to do so with the instructions you gave for the parent mode. This also means that you can set default/global handlers by targeting modes like prog-mode and text-mode.

Note

This package is designed to be as unopinionated as possible. I strongly recommend setting your own handle-keywords before loading the package. The appropriate handle-* functions will then be generated, and the handle function itself will be able to interpret all of them.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published