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

Add functions to increment/decrement context #161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ethan-coe-renner
Copy link

Thanks for this great package, I use it daily!

I wanted to be able to increase/decrease the before/after context via keybindings rather than clicking through the buttons in the header of a deadgrep buffer. I didn't see a way to do this with the functions deadgrep currently exposes, so I wrote my own. I figure others might find this useful, so this PR includes that code.

(Please let me know if I've missed something and this functionality already exists).

New Functions

deadgrep--update-context does most of the work. It takes a string (which-context, which can be either "before" or "after") and an integer (value). The function updates the context denoted by which-context by adding value to the appropriate field in deadgrep--context, after ensuring that doing so won't result in a negative value.

A family of interactive functions named deadgrep-<increment/decrement>-<before/after>-context are implemented to use deadgrep--update-context to increment/decrement the before/after context by 1 line. These are intended to be bound to keys.

Keybindings

I've not added any keybindings to the deadgrep-mode-map, but in my configuration I use the following hydra:

(defhydra deadgrep-context ()
                 "context"
                 ("B" deadgrep-increment-before-context "increment before context")
                 ("b" deadgrep-decrement-before-context "decrement before context")
                 ("A" deadgrep-increment-after-context "increment after context")
                 ("a" deadgrep-decrement-after-context "decrement after context"))

I'm happy to add default keybindings if that is desired and suggestions are welcome for such keybinds.

Note: This is my first non-trivial elisp contribution to an emacs package, so please let me know if there's anything here that needs to be changed, I'm happy to do it.

These functions can then be bound to keys to quickly increase and
decrease before/after context in the current search.
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

Successfully merging this pull request may close these issues.

1 participant