rougier / elegant-emacs

A very minimal but elegant emacs (I think)
GNU General Public License v3.0
1.37k stars 78 forks source link

Use space :align-to instead of manual computations #30

Closed DivineDominion closed 2 years ago

DivineDominion commented 2 years ago

Fixes #29


Looking at marginalia.el issues, code, and the README I found out about alignment propertization, and that fixes the problem of chopped-off characters for me:

(defun mode-line-render (left right)
  "Function to render the modeline LEFT to RIGHT."
  (concat left
          (propertize " "
                      'display `(space :align-to (- right ,(length right))))
          right))

You can also easily add a middle column later if you want:

(defun mode-line-render (left center right)
  "Function to render the modeline LEFT, CENTER, and RIGHT."
  (concat left
          (propertize " "
                      'display `(space :align-to (- center ,(length center))))
          center
          (propertize " "
                      'display `(space :align-to (- right ,(length right))))
          right))

With the space alignment stuff here, this even works on a per-pixel offset basis -- I can freely resize the window and the line and column indicators stick to the window edges.

Compare with

(setq frame-resize-pixelwise t)

... and you'll see that the current approach moves in units of 1 character, while this PR will move per pixel.

DivineDominion commented 2 years ago

Relevant docs: https://www.gnu.org/software/emacs/manual/html_node/elisp/Display-Property.html https://www.gnu.org/software/emacs/manual/html_node/elisp/Specified-Space.html

rougier commented 2 years ago

I remember having tried that but I got problem with the face using for alignment. For example, if you want to have a continuous underline, it was not working.

DivineDominion commented 2 years ago

@rougier Do you remember the particular setup? When I save my replacement for mode-line-render in elegant.el and launch emacs -q -l sanity.el -l elegance.el Splash.org & it looks fine.

rougier commented 2 years ago

Thanks. I need I'll merge. In the meantime, I'll try to adapt your code to nano-modeline