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

lv-message not appearing in the centre #394

Open
bestlem opened this issue Dec 26, 2020 · 1 comment
Open

lv-message not appearing in the centre #394

bestlem opened this issue Dec 26, 2020 · 1 comment

Comments

@bestlem
Copy link

bestlem commented Dec 26, 2020

When lv-use-padding is set the hydra is meant to be centred in the free space.

This is not happening as the padding is worked out fropm the first line only - which tends to be a title and so shorter than other lines

I have altered the code to look at all the lines and calculate the padding from the longest line

 (defun lv--pad-to-center (str width)
      "Pad STR with spaces on the left to be centered to WIDTH."
      (let* ((strs (split-string str "\n"))
             (padding (make-string
                       (/ (- width (apply 'max (mapcar 'length strs))) 2)
                       ?\ )))
        (mapconcat (lambda (s) (concat padding s)) strs "\n")))
@bestlem
Copy link
Author

bestlem commented Jan 16, 2021

And it needs a bit of error checking - if the frame is too small that it tries to pad -1
So better

(defun lv--pad-to-center (str width)
      "Pad STR with spaces on the left to be centered to WIDTH."
      (let* ((strs (split-string str "\n"))
             (padding-length (/ (- width (apply 'max (mapcar 'length strs))) 2)))
        (if (> padding-length  0)
            (mapconcat (lambda (s)
                         (concat (make-string padding-length ?\ ) s)) strs "\n")
          str)))

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

No branches or pull requests

1 participant