From 825c2bed71e7db737de55ff105a3ff4da1cee751 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 21 May 2019 14:32:50 +0800 Subject: [PATCH] Calculate the actual char height of the mode-line. doom-modeline-height is the minimal height of mode-line. It respects the actual char height. --- README.md | 5 +++-- doom-modeline-core.el | 18 ++++++++++++------ doom-modeline-segments.el | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index bb7f0d9..7fcd137 100644 --- a/README.md +++ b/README.md @@ -134,10 +134,11 @@ Strongly recommend to use ## Customize ``` emacs-lisp -;; How tall the mode-line should be (only respected in GUI Emacs). +;; How tall the mode-line should be. It's only respected in GUI. +;; If the actual char height is larger, it respects the actual height. (setq doom-modeline-height 25) -;; How wide the mode-line bar should be (only respected in GUI Emacs). +;; How wide the mode-line bar should be. It's only respected in GUI. (setq doom-modeline-bar-width 3) ;; Determines the style used by `doom-modeline-buffer-file-name'. diff --git a/doom-modeline-core.el b/doom-modeline-core.el index 7acc8a1..7e0ed3e 100644 --- a/doom-modeline-core.el +++ b/doom-modeline-core.el @@ -131,14 +131,12 @@ It returns a file name which can be used directly as argument of ;; Variables ;; -(defvar doom-modeline-height (let ((font (face-font 'mode-line))) - (if (and font (fboundp 'font-info)) - (* 2 (aref (font-info font) 2)) - 25)) - "How tall the mode-line should be (only respected in GUI Emacs).") +(defvar doom-modeline-height 25 + "How tall the mode-line should be. It's only respected in GUI. +If the actual char height is larger, it respects the actual char height.") (defvar doom-modeline-bar-width (if (eq system-type 'darwin) 3 6) - "How wide the mode-line bar should be (only respected in GUI Emacs).") + "How wide the mode-line bar should be. It's only respected in GUI.") (defvar doom-modeline-buffer-file-name-style 'truncate-upto-project "Determines the style used by `doom-modeline-buffer-file-name'. @@ -488,6 +486,14 @@ It returns a file name which can be used directly as argument of "Whether is an active window." (eq (selected-window) doom-modeline-current-window)) +(defun doom-modeline--char-height () + "Calculate the actual char height of the mode-line." + (or + (let ((font (face-font 'mode-line))) + (when (and font (fboundp 'font-info)) + (* 2 (aref (font-info font) 2)))) + (round (* 1.3 (frame-char-height))))) + (defsubst doom-modeline-vspc () "Text style with icons in mode-line." (propertize " " 'face (if (doom-modeline--active) diff --git a/doom-modeline-segments.el b/doom-modeline-segments.el index 2abba64..bfb2496 100644 --- a/doom-modeline-segments.el +++ b/doom-modeline-segments.el @@ -1226,12 +1226,12 @@ Returns \"\" to not break --no-window-system." (doom-modeline--make-xpm 'doom-modeline-bar (or width doom-modeline-bar-width) (max (or height doom-modeline-height) - (ceiling (* 1.3 (frame-char-height))))) + (doom-modeline--char-height))) doom-modeline--bar-inactive (doom-modeline--make-xpm 'doom-modeline-inactive-bar (or width doom-modeline-bar-width) (max (or height doom-modeline-height) - (ceiling (* 1.3 (frame-char-height))))))) + (doom-modeline--char-height))))) (when (>= emacs-major-version 26) (add-variable-watcher