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

Replace (length with (string-width #74

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

Conversation

TomoeMami
Copy link

Improve multibyte characters align.

Ref: #72

Improve multibyte characters align
@rougier
Copy link
Owner

rougier commented Feb 19, 2024

I think string-pixel-width might be more accurate

@aaronjensen
Copy link
Contributor

It might, but I believe that is incredibly slow if I’m not mistaken. That would be a non-starter for a modeline.

@aaronjensen
Copy link
Contributor

Also, I think it’s fair to say that using a monospace font for any of these things is a requirement. We shouldn’t expect pixel perfect alignment of variable width fonts in Emacs yet.

@TomoeMami
Copy link
Author

It might, but I believe that is incredibly slow if I’m not mistaken. That would be a non-starter for a modeline.

And string-pixel-width will be changed when users specified their own font size.

#72 (comment)

@rougier
Copy link
Owner

rougier commented Feb 19, 2024

Is is really that slow ?

@aaronjensen
Copy link
Contributor

~16x slower on my machine, but still relatively fast (it takes a bit over 100 of them to get to 1ms). If there is only a few done it may not matter. I still try to avoid anything that is remotely slow in modelines because it affects typing and scrolling latency, and bad modelines have actually had material impact on my experience in Emacs. Modelines are rendered a lot, so for anything that accesses the file system, they benefit from memoization, etc.

string-pixel-width actually creates a buffer, puts the string in it, then measures it using buffer-text-pixel-size which actually renders the text in a temporary window. I'd personally avoid it in things like modelines, or make it optional so someone who needed it could opt in (which adds complexity)

@rougier
Copy link
Owner

rougier commented Feb 19, 2024

16x is huge slowdown. I guess we can wait for emacs 30.0 and the mode-line-format-right-align.

@aaronjensen
Copy link
Contributor

To be clear I was just benchmarking the function in isolation, not the entire modeline.

@aaronjensen
Copy link
Contributor

I vaguely remember that the right align thing doesn’t take variable fonts into account but I would have to test it.

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.

3 participants