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

feat: add line count to folded text overlay #129

Merged
merged 4 commits into from
Feb 12, 2025

Conversation

jhacksworth
Copy link
Contributor

@jhacksworth jhacksworth commented Feb 10, 2025

Description

Add a configurable line count to the folded text overlay.

Following are some screenshots of what it looks like.

Default setting

(defcustom ts-fold-linecount-replacement " ... %d ... "
  "Format string for displaying line count in folded text.
The %d will be replaced with the number of lines in the folded region."
  :type 'string
  :group 'ts-fold)
Screenshot - default

Using horizontal ellipsis unicode character

(setq ts-fold-linecount-replacement " … %d … ") 
Screenshot - horizontal ellipsis

With lines text and horizontal ellipsis unicode character

(setq ts-fold-linecount-replacement " … %d lines … ")
Screenshot - lines text

ts-fold.el Outdated
(line-count (and ts-fold-linecount-show (count-lines beg end))))
(cond
((and summary line-count)
(format "%s %s" summary (format ts-fold-linecount-replacement line-count)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable summary would truncate on its own, so I assumed this could be:

;; <S> This is the summary text... ... (2 lines) ...

and not

;; <S> This is the summary text... (2 lines) ...

I can see the same result from your screenshots. Is this intentional? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean here? The first example is what the behavior is--the summary truncates on its own and then the line count display is shown afterwards.

@jcs090218 jcs090218 added the enhancement New feature or request label Feb 10, 2025
- Use line-count instead of linecount
- Set `ts-fold-line-count-show` to `nil` by default
- Use `ts-fold--truncate-string-ellipsis` in
  `ts-fold-line-count-replacement` default value
- Remove extraneous code
@jhacksworth
Copy link
Contributor Author

Thanks for taking a look at this and providing feedback!

((and summary line-count)
(format "%s %s" summary (format ts-fold-line-count-format line-count)))
((and summary (not line-count))
(format "%s %s" summary (ts-fold--truncate-string-ellipsis)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the logic here since the summary handles truncation independently.

@jcs090218
Copy link
Member

I've changed the logic a little; can you see if it works? Thanks!

README.md Outdated
- `ts-fold-line-count-replacement`
- `ts-fold-line-count-format`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha! Funny thing is I had originally named this variable with the format ending but changed it to end with replacement after seeing the variable named ts-fold-replacement in this commit (where it was removed).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the "replacement" variable was intentionally used to replace the content (fold range). In this case, we want the "format". :)

Sorry for the confusion, and thanks for being aware of this! 🚀

@jhacksworth
Copy link
Contributor Author

It works great! Thank you for taking the time to deal with this PR.

@jcs090218 jcs090218 merged commit fb4544e into emacs-tree-sitter:master Feb 12, 2025
11 checks passed
@jcs090218
Copy link
Member

Thank you for your contribution! 🚀 🥳

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

Successfully merging this pull request may close these issues.

2 participants