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

mode-line truncated in tty on window-split #397

Closed
mohkale opened this issue Dec 26, 2020 · 4 comments
Closed

mode-line truncated in tty on window-split #397

mohkale opened this issue Dec 26, 2020 · 4 comments

Comments

@mohkale
Copy link

mohkale commented Dec 26, 2020

Describe
There seems to be this weird issue where whenever you split a window vertically the modeline for the one on the eft is one-character shorter than the one on the right. That is to say the left modeline is truncated and the right isn't.

Resizing the window or any other affects doesn't seem to change this. I think it might be related to the fact that when you split a window the left one always has an odd width, whereas the right can have an odd or even width.

Steps and Expected

  1. emacs -nw -q - start emacs
  2. C-x b RET - goto scratch buffer
  3. C-S-v - paste this in from your clipboard
(progn
  (setq package-archives '(("melpa" . "https://melpa.org/packages/")
                           ("gnu" . "http://elpa.gnu.org/packages/")))
  (package-initialize)
  (package-refresh-contents)
  (package-install 'doom-modeline)
  (require 'doom-modeline)
  (doom-modeline-mode +1))
  1. Run M-x split-window-right
  2. Notice that the left mode-line has one space at the end and the right mode-line has two.

Environment:

  • OS and version: Linux mk-desktop 5.9.14-arch1-1 Modeline only appears in non-file buffers #1 SMP PREEMPT Sat, 12 Dec 2020 14:37:12 +0000 x86_64 GNU/Linux
  • Emacs Version: [e.g. 27.1]
  • Configuration: mohkale (NOTE: I haven't added my doom-modeline config yet, seeing as I can reproduce without it I hope that's OK)
  • Package version: 20201212.1823

Additional context
You can see the affect here.

@mohkale
Copy link
Author

mohkale commented Dec 27, 2020

Okay I tried switching away from doom-modeline into my own mode-line and I think I've figured out why this is happening. I'm quite sure there's a bug in emacs (at least on the tty). Which we notice here:

(list lhs-forms
(propertize
" "
'face (if (doom-modeline--active) 'mode-line 'mode-line-inactive)
'display `((space
:align-to
(- (+ right right-fringe right-margin)
,(* (let ((width (doom-modeline--font-width)))
(or (and (= width 1) 1)
(/ width (frame-char-width) 1.0)))
(string-width
(format-mode-line (cons "" rhs-forms))))))))
rhs-forms))

On the tty each window has an extra column which is taken up by the window seperator.

Screenshot_20201227_033248

Every window except the right most window. I believe the calculation for right in the :align-to properties above is assuming every window has that seperator to the right even when it doesn't in the case of a single window or a right-most window. That's making emacs believe the mode-line is one-character wider than it actually is causing it to be truncated. Someone should open an issue on the upstream emacs repo but seeing as I'm not using the latest emacs version I'll leave that for someone else to reproduce and submit.

Anyways we can get around the issue by keeping track of whether the current window is right-most or not and updating the offset accordingly. I tried doing so in the mode-line evaluation directly but noticed significant performance drops. For the mean-time I'm instead saving this value in a window-parameter and updating it in a hook.

Here's a patch which works for me, honestly it's kind of an ugly fix IMO and it's worth considering whether this is only a terminal issue or a tty issue (if it's the latter the condition below should be ANDed with (display-graphics-p)), but otherwise it's working.

@@ -926,6 +926,13 @@
 (add-hook 'after-setting-font-hook #'doom-modeline-refresh-font-width-cache)
 (add-hook 'server-after-make-frame-hook #'doom-modeline-refresh-font-width-cache)
 
+(add-hook 'window-configuration-change-hook
+          (defun doom-modeline-update-window-is-right-most ()
+            (dolist (window (window-list))
+              (set-window-parameter
+               window 'right-most
+               (not (window-in-direction 'right window))))))
+
 (defun doom-modeline-def-modeline (name lhs &optional rhs)
   "Defines a modeline format and byte-compiles it.
 NAME is a symbol to identify it (used by `doom-modeline' for retrieval).
@@ -949,6 +956,7 @@
                'display `((space
                            :align-to
                            (- (+ right right-fringe right-margin)
+                              ,(if (window-parameter (selected-window) 'right-most) 0 1)
                               ,(* (let ((width (doom-modeline--font-width)))
                                     (or (and (= width 1) 1)
                                         (/ width (frame-char-width) 1.0)))

@seagle0128
Copy link
Owner

The PRs are always welcome!

@mohkale
Copy link
Author

mohkale commented Dec 27, 2020

Just tried switching to a GUI for a second, this is definitely a TTY only issue. I'll patch out the fix in GUI frames and send over a PR.

@seagle0128
Copy link
Owner

Closed by 1d400aa.

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 a pull request may close this issue.

2 participants