参考 simple-modeline 和 doom-modeline 写了一个简化版的 modeline 自用。但是在分左右区域时,右侧区域却始终没能靠右对齐。请大家帮忙看看应该如何修改,实现红圈内的部分靠右边对齐。
;;;
;;; ========== pre-dec
;;;
;;; ~ evil-state ~
;;;
(defun blove-mode-line-evil-state ()
"The current evil state.
Requires `evil-mode' to be enabled."
(when (bound-and-true-p evil-local-mode)
(cond
((evil-normal-state-p) (format "%s" evil-normal-state-tag))
((evil-emacs-state-p) (format "%s" evil-emacs-state-tag))
((evil-insert-state-p) (format "%s" evil-insert-state-tag))
((evil-motion-state-p) (format "%s" evil-motion-state-tag))
((evil-visual-state-p) (format "%s" evil-visual-state-tag))
((evil-operator-state-p) (format "%s" evil-operator-state-tag))
((evil-replace-state-p) (format "%s" evil-replace-state-tag))
)
)
)
;;;
;;; ~ mode-line-modified ~
;;;
(defun blove-mode-line-modified ()
"Displays a color-coded buffer modification/read-only indicator in the mode-line."
(if (not (string-match-p "\\*.*\\*" (buffer-name)))
(let* ((read-only (and buffer-read-only (buffer-file-name)))
(modified (buffer-modified-p)))
(propertize
(if read-only " " (if modified " " " "))
'face `(t
,(if modified '(:background "red" :foreground "black")
(if read-only 'error
'shadow)))
)
)))
;;;
;;; ~ mode-line-buffer-name ~
;;;
(defun blove-mode-line-buffer-name ()
"Displays the name of the current buffer in the mode-line."
(propertize " %b" 'face 'blove-mode-line-buffer-name-face))
;;;
;;; ~ mode-line-current-position ~
;;;
(defun blove-mode-line-current-pos ()
"show blove mode line current line:pos:all-lines"
(format "%s" (concat " " (propertize " " 'face 'blove-mode-line-current-pos-title-face) " "
(propertize (number-to-string (line-number-at-pos (point))) 'face 'blove-mode-line-current-pos-lpa-face) ":"
(propertize (number-to-string (current-column)) 'face 'blove-mode-line-current-pos-lpa-face) ":"
(propertize (number-to-string (car (buffer-line-statistics))) 'face 'blove-mode-line-current-pos-lpa-face)
)
)
)
;;;
;;; ~ mode-line-system-memq ~
;;;
(defun blove-mode-line-system ()
(let (
(sys-plant (if (memq window-system '(w32 pgtk)) " " " "))
)
(propertize
(format "%s" sys-plant) 'face 'blove-mode-line-system-face)
)
)
;;;
;;; ~ mode-line-coding-show ~
;;;
(defun blove-mode-line-coding ()
(propertize
(concat " ["
(if (equal (symbol-name buffer-file-coding-system) "utf-8-dos")
"UTF-8"
(symbol-name buffer-file-coding-system)
)
"] ")
'face 'blove-mode-line-coding-face)
)
;;;
;;; ~ mode-line-remap-major-mode-name ~
;;;
(defun blove-re-major-mode-name ()
"Return simplifyed major mode name (symbol-name major-mode)"
(let* ((major-name (symbol-name major-mode))
(replace-table '(
python-mode " "
python-ts-mode " "
c++-mode " "
c++-ts-mode " "
c-mode " "
c-ts-mode " "
org-mode " "
fundamental-mode " "
messages-mode " "
debugger-mode " "
eshell-mode " "
emacs-lisp-mode " չ-Lisp "
lisp-interaction-mode " "
text-mode " "
dired-mode " "
help-mode " "
color-rg-mode " "
blove-rg-mode " "
))
(replace-name (plist-get replace-table (intern major-name))))
(if replace-name
replace-name
(capitalize major-name)))
)
(defun blove-mode-line-major-mode ()
"Displays the current major mode in the mode-line."
(propertize
(concat " ["
(or (and (boundp 'delighted-modes)
(cadr (assq major-mode delighted-modes)))
(blove-re-major-mode-name)
(format-mode-line mode-name)
)
"] ")
'face 'blove-mode-line-major-name-face)
)
;;;
;;; ~ mode-line-vc ~
;;;
(defun blove-mode-line-vc ()
"Displays color-coded version control information in the mode-line."
;; '(vc-mode vc-mode)
(if (equal (symbol-name (vc-backend buffer-file-name)) "Git")
(propertize " :master " 'face 'blove-mode-line-vc-face)
;; " "
)
)
;;;
;;; ========== main
;;;
;;; ~ gen-mode-line-segments ~
;;;
(defvar blove-mode-line-segments
'(
(blove-mode-line-evil-state
blove-mode-line-modified
blove-mode-line-buffer-name
blove-mode-line-current-pos)
(
blove-mode-line-system
blove-mode-line-coding
blove-mode-line-major-mode
blove-mode-line-vc ;; git
)
)
"modeline segments."
)
;;;
;;; ~ format-mode-line-segments ~
;;;
(defun blove-mode-line-format-segments (segments)
"Return a string from a list of SEGMENTS."
(format-mode-line (mapcar
(lambda (segment)
`(:eval (,segment)))
segments)))
(defun blove-mode-line-format (left-segments right-segments)
"Return a string of `window-width' length containing LEFT-SEGMENTS and RIGHT-SEGMENTS, aligned respectively."
(let* ((left (blove-mode-line-format-segments left-segments))
(right (blove-mode-line-format-segments right-segments))
(reserve (length right)))
(concat
left
(propertize " "
'display `((space :align-to (- (+ right right-fringe right-margin) ,reserve)
;; (- (+ right right-fringe right-margin 2.3) ,reserve)
;; (+ (- (+ right right-fringe right-margin) ,reserve) 11)
))
'face '(:inherit blove-mode-line-space))
right)))
(defvar blove-mode-line-mode-line
'((:eval
(blove-mode-line-format
(car blove-mode-line-segments)
(cadr blove-mode-line-segments)))))
;;;
;;; ~ show-mode-line ~
;;;
(setq-default mode-line-format '(:eval blove-mode-line-mode-line))
;;;
;;; ========== At The Bottom
;;;
(provide 'blove-mode-line)