From a9aeb16b917547dff0b2edaa27be25223cb8437a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Sun, 14 Jan 2024 12:15:39 -0800 Subject: emacs: eglot modeline --- .emacs.d/rul-lisp/packages/rul-modeline.el | 76 +++++------------------------- 1 file changed, 12 insertions(+), 64 deletions(-) (limited to '.emacs.d/rul-lisp') diff --git a/.emacs.d/rul-lisp/packages/rul-modeline.el b/.emacs.d/rul-lisp/packages/rul-modeline.el index a05eeb9..ae250c4 100644 --- a/.emacs.d/rul-lisp/packages/rul-modeline.el +++ b/.emacs.d/rul-lisp/packages/rul-modeline.el @@ -66,68 +66,16 @@ Truncation is done up to `rul-modeline-string-truncate-length'." (propertize "%]" 'face 'rul-modeline-indicator-red)) "Mode line construct for displaying major modes.") -;(makunbound 'rul-modeline-major-mode) - -;;;; Align right -(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." - (and (face-attribute 'mode-line :box) - (null (eq (face-attribute 'mode-line :box) 'unspecified)))) - -(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)) - -(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-p (prot-modeline--box-p)) - (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 - ((and variable-pitch-p box-p) - (* magic-number 0.5)) - ((and (not variable-pitch-p) box-p) - (* magic-number 0.25)) - ((and variable-pitch-p (not box-p)) - (* magic-number -0.05)) - (t (* magic-number -0.1)))))))) - "Mode line construct to align following elements to the right. -Read Info node `(elisp) Pixel Specification'.") - +(with-eval-after-load 'eglot + (setq mode-line-misc-info + (delete '(eglot--managed-mode (" [" eglot--mode-line-format "] ")) mode-line-misc-info))) + +(defvar-local prot-modeline-eglot + `(:eval + (when (and (featurep 'eglot) (mode-line-window-selected-p)) + '(eglot--managed-mode eglot--mode-line-format))) + "Mode line construct displaying Eglot information. +Specific to the current window's mode line.") ;;;; Miscellaneous (defvar-local rul-modeline-misc-info @@ -146,7 +94,6 @@ Specific to the current window's mode line.") (dolist (construct '( rul-modeline-major-mode rul-modeline-misc-info - prot-modeline-align-right )) (put construct 'risky-local-variable t)) @@ -157,7 +104,8 @@ Specific to the current window's mode line.") mode-line-buffer-identification mode-line-front-space rul-modeline-major-mode - prot-modeline-align-right + prot-modeline-eglot + mode-line-format-right-align rul-modeline-misc-info )) -- cgit v1.2.3