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

Fold the nearest node in the line #57

Open
isamert opened this issue May 1, 2023 · 5 comments
Open

Fold the nearest node in the line #57

isamert opened this issue May 1, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@isamert
Copy link

isamert commented May 1, 2023

Assume I have the following line and my cursor is at the beginning of the line.

image

Calling ts-fold-open does not open the fold, I have to move my cursor to the folding overlay to be able to open that. I am really accustomed to this flow from other folding modes, so it would be nice to have this kind of feature. I am currently using AndrewSwerlick's treesit.el fork1, let me know if this works on the original case but not in the fork. Currently I have no way of confirming this but assumed that the behavior is the same in upstream.

To fix this, I added the following function:

(defun ts-fold--first-foldable-node-at-line ()
  "Find the first foldable node in current line, after the current point."
  (catch 'return
    (dolist (pt (number-sequence (point) (cdr (bounds-of-thing-at-point 'line))))
      (when-let (fold (ts-fold--foldable-node-at-pos pt))
        (throw 'return fold)))))

and replaced all ts-fold--foldable-node-at-pos calls with this function. Probably a sub-optimal solution but it works for me.

@jcs090218
Copy link
Member

jcs090218 commented May 1, 2023

I'm using vs-edit-mode to deal with this issue, https://github.com/emacs-vs/vs-edit-mode/blob/7891dd1d39dea7c0059f158497930be1fc0da1c6/vs-edit-mode.el#L346-L376.

I don't have a strong opinion and don't know what provides the best UX. Therefore, I didn't choose to improve it until I knew what to do. 🤔

@isamert
Copy link
Author

isamert commented May 1, 2023

I see, I believe it makes more sense to have this behavior in ts-fold. I tried hs-minor-mode and origami-mode. They both work like I described above. Also outline-mode (and thus org-mode, markdown-mode) works in the same way. I think it is more natural, most of the time (maybe 95% of the time), one line will have only one fold and it does not make sense to force the user to be precise.

@mpereira
Copy link

Also coming from hs-minor-mode and origami-mode (and similar Vim plugins in the past) it makes sense (ergonomically) that folding operations happen at a fold in the same line as the cursor.

@jcs090218
Copy link
Member

Thanks for showing interest in this feature!

Please give the first post upvote 👍, so I know how many people are interested in this feature. 🤔

@jcs090218 jcs090218 added the enhancement New feature or request label May 18, 2023
@mpereira
Copy link

Upvoted. Thank you for your work on this package (and others) 🙂

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

No branches or pull requests

3 participants