-
Notifications
You must be signed in to change notification settings - Fork 44
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
Enable leap to work as a telescope item selector that triggers a pick #218
Conversation
73e53a0
to
120be07
Compare
fnl/leap/highlight.fnl
Outdated
@@ -21,14 +21,17 @@ | |||
(fn M.cleanup [self affected-windows] | |||
; Clear beacons & cursor. | |||
(each [_ [bufnr id] (ipairs self.extmarks)] | |||
(api.nvim_buf_del_extmark bufnr self.ns id)) | |||
(let [is-valid-buf (api.nvim_buf_is_valid bufnr)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: use when
if there is no else-branch; no need for extracting the result
(when (api.nvim_buf_is_valid bufnr)
(api.nvim_buf_del_extmark bufnr self.ns id)))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this was the first time I used fennel, so I assumed there were some style mistakes! Working on these changes now
fnl/leap/highlight.fnl
Outdated
(set self.extmarks []) | ||
; Clear backdrop. | ||
(when (pcall api.nvim_get_hl_by_name self.group.backdrop false) ; group exists? | ||
(each [_ winid (ipairs affected-windows)] | ||
(local wininfo (. (vim.fn.getwininfo winid) 1)) | ||
(api.nvim_buf_clear_namespace | ||
wininfo.bufnr self.ns (dec wininfo.topline) wininfo.botline)) | ||
(if (> (length wininfo) 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not simply:
(each [_ winid (ipairs affected-windows)]
(when (api.nvim_win_is_valid winid)
...)
Note: It just occurred to me that there is a potential problem with the backdrop cleanup. What if the window has become invalid, but the buffer is still there? We do not remove the backdrop then.
Anyway, this can be fixed in a followup commit, should be thought through.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, made the changes. That's a great point, perhaps there would be affected-bufs
too.
[:w win name] (if (api.nvim_win_is_valid win) | ||
(api.nvim_win_set_option win name val)) | ||
[:b buf name] (if (api.nvim_buf_is_valid buf) | ||
(api.nvim_buf_set_option buf name val)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
-> when
; indentation
@aaronlifton :) |
… formatting issue
Problem: The target window/buffer might be automatically closed right after selecting the target (use case: e.g., results of a fuzzy finder), and Leap trying to do cleanup there results in error. Solution: Check if the window/buffer is still valid before cleanup. Closes #218. Co-authored-by: Aaron Lifton <aaronlifton@gmail.com>
Sorry for the delay, just did some tweaks & added you as co-author, to speed things up. Thanks very much for the contribution! The snippet above works fine, but there is a stack overflow error if triggering it before entering any input. Do you happen to have an idea how that could be fixed? (It might worth adding it to the "Extending Leap" section, but this edge case is a bit annoying.) |
I have the following telescope mapping, which enables me to pick a single row from a Telescope list via leap (
s
). Because the mapping picks a row in telescope, it triggers the closing of the telescope window which causes leap to not be able to find the win/buf. The error can be reproduced as follows, given the following mapping:So in a telescope window, entering normal mode and pressing
s
will turn the list of telescope items into leap targets, and selecting one will pick that item.However, since this closes the telescope window, there are 2 undefined win/buf errors inside of leap, since leap seems to not expect a leap target like a telescope item. So, I protected these statements with guard clauses, and now I'm able to leap to a telescope target without error. I felt this was appropriate because it enables further usages of leap.
Here is a video of this customization in my branch working without error:
leap.recording.mp4