Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fixate value on the right side of the modeline?

Tags:

emacs

modeline

Is there a way to position a value on the the right end of the modeline?

From my understanding currently the modeline "pushes" its values farther right if the values increase in size. I would prefer it if some values would start on the right side and expand into the middle.

I have tried solutions like powerline, but they seem rather distracting and more complicated in setup to display the same amount of informatioon as the standard modeline.

like image 748
edt_devel Avatar asked May 27 '13 15:05

edt_devel


1 Answers

Here is one way to do it. The trick is to add spaces until the end of the line minus the place needed to display your text (extracted from powerline code on the emacs wiki):

(defun mode-line-fill (face reserve)
  "Return empty space using FACE and leaving RESERVE space on the right."
  (unless reserve
    (setq reserve 20))
  (when (and window-system (eq 'right (get-scroll-bar-mode)))
    (setq reserve (- reserve 3)))
  (propertize " "
              'display `((space :align-to (- (+ right right-fringe right-margin) ,reserve)))
              'face face))


;; Set the modeline to tell me the filename, hostname, etc..
(setq-default mode-line-format (list
   " "
   mode-line-mule-info
   'mode-line-modified
   "-  "
   'mode-line-buffer-identification
   "  (%l, %c)  "
   'mode-line-modes
   " -- "
   `(vc-mode vc-mode)

   ;; Fill until the end of line but 10 characters
   (mode-line-fill 'mode-line 10)
   "Some text"
   )
)
like image 158
Nicolas Rougier Avatar answered Nov 15 '22 06:11

Nicolas Rougier