aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbard <[email protected]>2024-03-07 07:15:04 -0500
committerbard <[email protected]>2024-03-07 07:15:04 -0500
commit1edfe7eca24f830551ce5d68816669cbdc0ae2ba (patch)
tree5f6504b7be2b02634e6892beb754cda1e41d47ad
parent1faa5b382c6527b01543b3a7f3dd9c4df9017b2f (diff)
right align misc information
-rw-r--r--bard-elisp/bard-modeline.el80
-rw-r--r--bard-emacs-modules/bard-emacs-modeline.el44
2 files changed, 102 insertions, 22 deletions
diff --git a/bard-elisp/bard-modeline.el b/bard-elisp/bard-modeline.el
index 5e8d0a4..f5dcbb1 100644
--- a/bard-elisp/bard-modeline.el
+++ b/bard-elisp/bard-modeline.el
@@ -53,6 +53,84 @@ or not."
(with-selected-window (minibuffer-window)
(eq window (minibuffer-selected-window)))))))
+;;;; Right side alignment
+
+(defun prot-modeline--right-align-rest ()
+ "Return string if everything after `prot-modeline-align-right'."
+ (format-mode-line
+ `(""
+ ,@(cdr (memq 'prot-modeline-align-right mode-line-format)))))
+
+(defun prot-modeline--right-align-width ()
+ "Return pixel width of `prot-modeline--right-align-rest'."
+ (string-pixel-width (prot-modeline--right-align-rest)))
+
+(defun prot-modeline--box-p ()
+ "Return non-nil if the `mode-line' has a box attribute."
+ (when-let ((box (face-attribute 'mode-line :box))
+ ((null (eq (face-attribute 'mode-line :box) 'unspecified))))
+ (or (plist-get box :line-width)
+ t)))
+
+;; NOTE 2023-07-13: I could also do what I am doing in
+;; `fontaine--family-list-variable-pitch' and check if the family is a
+;; member of those, but I don't need that as I always inherit
+;; `variable-pitch' in my themes instead of hardcoding the family.
+(defun prot-modeline--variable-pitch-p ()
+ "Return non-nil if the `mode-line' inherits `variable-pitch'."
+ (when-let* ((mode-line-inherit (face-attribute 'mode-line :inherit))
+ ((string-match-p "variable-pitch" (symbol-name mode-line-inherit)))
+ (family-face (face-attribute mode-line-inherit :inherit))
+ (variable-pitch
+ (if (listp family-face)
+ (memq 'variable-pitch family-face)
+ (eq 'variable-pitch family-face))))
+ variable-pitch))
+
+;; I just came up with this experimentally, but I am not sure if it is
+;; the best approach.
+(defun prot-modeline--magic-number ()
+ "Return constant for use in `prot-modeline-align-right'."
+ (let ((height (face-attribute 'mode-line :height nil 'default))
+ (m-width (string-pixel-width (propertize "m" 'face 'mode-line))))
+ (round height (* m-width (* height m-width 0.001)))))
+
+(defvar-local prot-modeline-align-right
+ '(:eval
+ (propertize
+ " "
+ 'display
+ (let* ((box (prot-modeline--box-p))
+ (box-natnum-p (natnump box))
+ (variable-pitch-p (prot-modeline--variable-pitch-p))
+ (magic-number (prot-modeline--magic-number)))
+ `(space
+ :align-to
+ (- right
+ right-fringe
+ right-margin
+ ,(ceiling
+ (prot-modeline--right-align-width)
+ (string-pixel-width (propertize "m" 'face 'mode-line)))
+ ,(cond
+ ;; FIXME 2023-07-13: These hardcoded numbers are
+ ;; probably wrong in some case. I am still testing.
+ ((and box-natnum-p variable-pitch-p)
+ (+ (* box 2.375) magic-number))
+ (box-natnum-p
+ (* magic-number (* box 1.15)))
+ ((and variable-pitch-p box)
+ (* magic-number 0.5))
+ ((and (not variable-pitch-p) box)
+ (* magic-number 0.25))
+ ((and variable-pitch-p (not box))
+ 0)
+ ;; No box, no variable pitch, but I am keeping it as
+ ;; the fallback for the time being.
+ (t (* magic-number -0.1))))))))
+ "Mode line construct to align following elements to the right.
+Read Info node `(elisp) Pixel Specification'.")
+
;;;; Faces
(defface prot-modeline-indicator-button nil
@@ -537,7 +615,7 @@ Specific to the current window's mode line.")
prot-modeline-vc-branch
prot-modeline-flymake
prot-modeline-eglot
- ;; prot-modeline-align-right
+ prot-modeline-align-right
prot-modeline-notmuch-indicator
prot-modeline-misc-info))
(put construct 'risky-local-variable t))
diff --git a/bard-emacs-modules/bard-emacs-modeline.el b/bard-emacs-modules/bard-emacs-modeline.el
index acec052..9327d87 100644
--- a/bard-emacs-modules/bard-emacs-modeline.el
+++ b/bard-emacs-modules/bard-emacs-modeline.el
@@ -32,26 +32,26 @@
;; Face customization
-(defun bard/modus-light-faces ()
- (modus-themes-with-colors
- (custom-set-faces
- `(mode-line ((t :background ,bg-ochre :foreground ,fg-main :box (:line-width 6 :color ,bg-ochre :style nil)))))
- (custom-set-faces
- `(mode-line-inactive ((t :background ,bg-mode-line-inactive :foreground ,fg-dim :box (:line-width 6 :color ,bg-mode-line-inactive :style nil)))))))
-
-(defun bard/modus-dark-faces ()
- (modus-themes-with-colors
- (custom-set-faces
- `(mode-line ((t :background ,bg-magenta-subtle :foreground ,fg-main :box (:line-width 6 :color ,bg-magenta-subtle :style nil)))))
- (custom-set-faces
- `(mode-line-inactive ((t :background ,bg-mode-line-inactive :foreground ,fg-dim :box (:line-width 6 :color ,bg-mode-line-inactive :style nil)))))))
-
-(defun bard/modus-themes-faces ()
- (if (or (memq 'modus-operandi custom-enabled-themes)
- (memq 'modus-operandi-tinted custom-enabled-themes))
- (bard/modus-light-faces)
- (bard/modus-dark-faces)
- ))
+;; (defun bard/modus-light-faces ()
+;; (modus-themes-with-colors
+;; (custom-set-faces
+;; `(mode-line ((t :background ,bg-ochre :foreground ,fg-main :box (:line-width 6 :color ,bg-ochre :style nil)))))
+;; (custom-set-faces
+;; `(mode-line-inactive ((t :background ,bg-mode-line-inactive :foreground ,fg-dim :box (:line-width 6 :color ,bg-mode-line-inactive :style nil)))))))
+
+;; (defun bard/modus-dark-faces ()
+;; (modus-themes-with-colors
+;; (custom-set-faces
+;; `(mode-line ((t :background ,bg-magenta-subtle :foreground ,fg-main :box (:line-width 6 :color ,bg-magenta-subtle :style nil)))))
+;; (custom-set-faces
+;; `(mode-line-inactive ((t :background ,bg-mode-line-inactive :foreground ,fg-dim :box (:line-width 6 :color ,bg-mode-line-inactive :style nil)))))))
+
+;; (defun bard/modus-themes-faces ()
+;; (if (or (memq 'modus-operandi custom-enabled-themes)
+;; (memq 'modus-operandi-tinted custom-enabled-themes))
+;; (bard/modus-light-faces)
+;; (bard/modus-dark-faces)
+;; ))
;; (modus-themes-with-colors
;; (custom-set-faces
@@ -59,10 +59,11 @@
;; (custom-set-faces
;; `(mode-line-inactive ((t :background ,bg-purple-nuanced :foreground ,fg-dim :box (:line-width 3 :color ,purple-faint))))))
-(add-hook 'modus-themes-after-load-theme-hook #'bard/modus-themes-faces)
+;; (add-hook 'modus-themes-after-load-theme-hook #'bard/modus-themes-faces)
;;; Mode line
(setq mode-line-compact nil) ; Emacs 28
+(setq mode-line-right-align-edge 'right-margin)
(setq-default mode-line-format
'("%e"
prot-modeline-narrow
@@ -79,6 +80,7 @@
" "
prot-modeline-flymake
" "
+ prot-modeline-align-right
prot-modeline-misc-info))
(with-eval-after-load 'spacious-padding