emacs-sideline / sideline

Show information on the side
GNU General Public License v3.0
118 stars 14 forks source link

Right-aligning via sideline--align: remove 'subtract 1' call to avoid bleeding 1 character into the next line #18

Closed DivineDominion closed 5 months ago

DivineDominion commented 7 months ago

I found that I needed to remove the (1- ...) when right-aligning the sideline overlay.

The code is this: https://github.com/emacs-sideline/sideline/blob/20e04fa2fd4dcc0cba47d0336aab37f3f42909d3/sideline.el#L438

The "fix" would be:

           (propertize " " 'display `((space :align-to (- right ,(sideline--align len-title offset)))

I don't quite understand why that's the case, though.

(Am using GUI Emacs for macOS)

I'm not good at debugging Elisp -- I can fiddle with stuff, run it again, and see if it helps, like I did here, but I'm not sure how to figure out the actual culprit. Hints welcome!

Observations

With (1- ...) but without truncating lines (my default)

2024-01-06 10-42-04 Emacs - Logger php

With (1- ...) and truncating lines

2024-01-06 10-41-20 Emacs - Logger php

That's bearable, but I found that replacing (1- len-title) with just len-title fixes things:

Without (1- ...)

2024-01-06 10-41-05 Emacs - Logger php

DivineDominion commented 7 months ago

Ah, since sideline--align is a function, it'd be possible to tweak the offset there, too, and use a length offset of 2 instead of 1:

(defun sideline--align (&rest lengths)
  "Align sideline string by LENGTHS from the right of the window."
  (list (* (window-font-width)
           (+ (apply #'+ lengths) (if (display-graphic-p) 2 3)))))

That's easier to override in my config. Ideas how to figure out the root problem still welcome, though :)

jcs090218 commented 7 months ago

Can you try with emacs -q? Generally, sideline can be miscalculated depending on the packages you use. Can you try turning some minor modes on/off? Let me know if you find anything. I would like to include a fix in this package. :)

antoineB commented 5 months ago

I have the same problem.

  1. Don't occur if run with -nw.
  2. If I have fringe activated (setq overflow-newline-into-fringe t) resolve the problem.
  3. Changing the size (lower or higher) seems also to solve the problem.
jcs090218 commented 5 months ago

Would this be a macOS-specific problem? 🤔 Sorry, I'm still a bit confuse.

antoineB commented 5 months ago

I am running pgtk emacs on linux and I use Source Code Pro font. If I use another font (DejaVu Sans for instance) the problem disappear.

jcs090218 commented 5 months ago

I think the issue is due to the font calculation? 🤔

https://github.com/emacs-sideline/sideline/blob/3bd6315e8c3437b262d6f9975f37d94ac84d0720/sideline.el#L235-L240

I would need sometime to investigate it.

jcs090218 commented 5 months ago

I've tried use the Source Code Pro on Windows, but it seems to work. 😕

antoineB commented 5 months ago

Here is how it looks:

Screenshot from 2024-02-28 22-28-57

I don't think the problem comes from sideline--str-len, here is what I get:

(length "antoineB, oct. 28 2023 15:49:54 â—‰ Add sql-ts-mode.el file to base the mode on another") ;; 85
(sideline--str-len "antoineB, oct. 28 2023 15:49:54 â—‰ Add sql-ts-mode.el file to base the mode on another") ;; 85
antoineB commented 5 months ago

Here is without the fringes.

Screenshot from 2024-02-28 22-40-44

I have resized to different size but it doesn't change the problem.

And I forgot to mention I have the same problem with awesome-tray package.

jcs090218 commented 5 months ago

Can you try the latest on the master branch? I've done a couple of improvements.

  1. Remove text properties in pixel calculation (some properties will affect the length) https://github.com/emacs-sideline/sideline/blob/1dc13272b6b1ba6fc0c246f4cd150752ae6a5f1d/sideline.el#L236
  2. Use the string's pixel size directly https://github.com/emacs-sideline/sideline/blob/1dc13272b6b1ba6fc0c246f4cd150752ae6a5f1d/sideline.el#L283-L288

I hope these changes solve this issue since I don't know what is causing this bug. 🤔

antoineB commented 5 months ago

Screenshot from 2024-02-29 12-11-09 In this picture we can see that the cursor at the end of the line is halfed, (- (window-width) (window-max-chars-per-line)) gives 1.

Therefor the sideline-blame shown above is offseted by 1 in sideline--align.

Another thing I don't understand the sideline-blame message is not characters aligned with the line below even the 2 lines use the same face.

After resizing the window I can align the characters, the sideline-blame text is displayed next to the right border, but the window-width and window-max-chars-per-line values still off by 1 char.

jcs090218 commented 5 months ago

Another thing I don't understand the sideline-blame message is not characters aligned with the line below even the 2 lines use the same face.

My guess is because it's displays from the right? 🤔

After resizing the window I can align the characters, the sideline-blame text is displayed next to the right border, but the window-width and window-max-chars-per-line values still off by 1 char.

Hmmm... I guess there are some miscalculations in the window width.

antoineB commented 5 months ago
(defun sideline--align (str offset)
  "Align sideline STR from the right of the window.

Argument OFFSET is additional calculation from the left/right alignment."
  (list (+
         ;; If the sideline text is displayed without at least 1 pixel gap from the right fringe and
         ;; overflow-newline-into-fringe is not true, emacs will line wrap it.
         (if (and (display-graphic-p)
                  (> (nth 1 (window-fringes)) 0)
                  (not overflow-newline-into-fringe))
             1
           0)
         (* (window-font-width)
            (+ offset (if (display-graphic-p)
                          ;; If right fringe is deactivated add 1 offset for line wrap char.
                          (if (= 0 (nth 1 (window-fringes))) 1 0)
                        1)))
           (sideline--string-pixel-width str))))

The problem was is a char is close with 0 pixel gap to the right fringe and overflow-newline-into-fringe set to nil then emacs line wrap. For @DivineDominion I see you have no right fringe, if you use emacs in a terminal did you try use sideline.el from master ? If you use gui emacs without a fringe you try my function.

jcs090218 commented 5 months ago

Okay, I can finally reproduce this issue with (setq overflow-newline-into-fringe nil). 😅

I've tested it, and your solution seems to solve this issue. Can you open a PR for this?

DivineDominion commented 5 months ago

Nice work :)