summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/+modeline.el47
-rw-r--r--lisp/+tab-bar.el80
2 files changed, 105 insertions, 22 deletions
diff --git a/lisp/+modeline.el b/lisp/+modeline.el index a0195f1..3f25a40 100644 --- a/lisp/+modeline.el +++ b/lisp/+modeline.el
@@ -88,7 +88,7 @@ This function makes a lambda, so you can throw it straight into
88(defun +modeline-major-mode (&optional spacer) 88(defun +modeline-major-mode (&optional spacer)
89 "Display the current `major-mode'." 89 "Display the current `major-mode'."
90 (concat (or spacer +modeline-default-spacer) 90 (concat (or spacer +modeline-default-spacer)
91 (propertize (+string-truncate (format-mode-line mode-name) 12) 91 (propertize (+string-truncate (format-mode-line mode-name) 16)
92 'face 'bold 92 'face 'bold
93 'keymap mode-line-major-mode-keymap 93 'keymap mode-line-major-mode-keymap
94 'help-echo (concat (format-mode-line mode-name) 94 'help-echo (concat (format-mode-line mode-name)
@@ -185,27 +185,30 @@ The order of elements matters: whichever one matches first is applied."
185 185
186(defun +modeline-position (&optional _) ; adapted from `simple-modeline' 186(defun +modeline-position (&optional _) ; adapted from `simple-modeline'
187 "Display the current cursor position." 187 "Display the current cursor position."
188 (list '((line-number-mode 188 (let ((sep "|") (before " [") (after "]"))
189 ((column-number-mode 189 (list `(:propertize (line-number-mode
190 (column-number-indicator-zero-based 190 ((column-number-mode
191 (9 " %l:%c") 191 (column-number-indicator-zero-based
192 (9 " %l:%C")) 192 ,(concat before "%l" sep "%c" after)
193 (6 " %l:"))) 193 ,(concat before "%l" sep "%C" after))
194 ((column-number-mode 194 ,(concat before "%l" sep "" after)))
195 (column-number-indicator-zero-based 195 ((column-number-mode
196 (5 " :%c") 196 (column-number-indicator-zero-based
197 (5 " :%C")))))) 197 ,(concat before sep "%c" after)
198 '(file-percentage-mode 198 ,(concat before sep "%C" after)))))
199 ((-3 "%p") "%% ")) 199 font-lock-face font-lock-comment-face)
200 (if (region-active-p) 200 (if (region-active-p)
201 (propertize (format "%s%-5d" 201 (propertize (format "%s%-5d"
202 (if (and (mark) (< (point) (mark))) "-" "+") 202 (if (and (mark) (< (point) (mark))) "-" "+")
203 (apply '+ (mapcar 203 (apply '+ (mapcar
204 (lambda (pos) 204 (lambda (pos)
205 (- (cdr pos) 205 (- (cdr pos)
206 (car pos))) 206 (car pos)))
207 (region-bounds)))) 207 (region-bounds))))
208 'font-lock-face 'font-lock-variable-name-face)))) 208 'font-lock-face 'font-lock-variable-name-face))
209 '(:propertize (file-percentage-mode
210 (" " (-3 "%p") "%%"))
211 font-lock-face font-lock-comment-face))))
209 212
210(defun +modeline-vc (&optional spacer) 213(defun +modeline-vc (&optional spacer)
211 "Display the version control branch of the current buffer in the modeline." 214 "Display the version control branch of the current buffer in the modeline."
diff --git a/lisp/+tab-bar.el b/lisp/+tab-bar.el new file mode 100644 index 0000000..2a03121 --- /dev/null +++ b/lisp/+tab-bar.el
@@ -0,0 +1,80 @@
1;;; +tab-bar.el -*- lexical-binding: t; -*-
2
3;;; Commentary:
4
5;; Emacs 28 comes with an easy-to-use `tab-bar-format' option, but I still use
6;; Emacs 27 on my Windows machine. Thus, the code in this file.
7
8;;; Code:
9
10(require 'tab-bar)
11
12
13;; Common
14
15(defun +tab-bar-misc-info ()
16 "Display `mode-line-misc-info', formatted for the tab-bar."
17 `((global menu-item ,(string-trim-right
18 (format-mode-line mode-line-misc-info))
19 ignore)))
20
21(defvar +tab-bar-show-original nil
22 "Original value of `tab-bar-show'.")
23
24
25;; Emacs 27
26
27(defun +tab-bar-misc-info-27 (output &rest _)
28 "Display `mode-line-misc-info' in the `tab-bar' on Emacs 27.
29This is :filter-return advice for `tab-bar-make-keymap-1'."
30 (let* ((reserve (length (format-mode-line mode-line-misc-info)))
31 (str (propertize " "
32 'display `(space :align-to (- right (- 0 right-margin)
33 ,reserve)))))
34 (prog1 (append output
35 `((align-right menu-item ,str nil))
36 (+tab-bar-misc-info)))))
37
38
39;; Emacs 28
40
41(defvar +tab-bar-format-original nil
42 "Original value of `tab-bar-format'.")
43
44(defun +tab-bar-misc-info-28 ()
45 "Display `mode-line-misc-info', right-aligned, on Emacs 28."
46 (append (unless (memq 'tab-bar-format-align-right tab-bar-format)
47 '(tab-bar-format-align-right))
48 '(+tab-bar-misc-info)))
49
50
51
52(define-minor-mode +tab-bar-misc-info-mode
53 "Show the `mode-line-misc-info' in the `tab-bar'."
54 :lighter ""
55 :global t
56 (if +tab-bar-misc-info-mode
57 (progn ; Enable
58 (setq +tab-bar-show-original tab-bar-show)
59 (cond
60 ((boundp 'tab-bar-format) ; Emacs 28
61 (setq +tab-bar-format-original tab-bar-format)
62 (unless (memq '+tab-bar-misc-info tab-bar-format)
63 (setq tab-bar-format
64 (append tab-bar-format (+tab-bar-misc-info-28)))))
65 ((fboundp 'tab-bar-make-keymap-1) ; Emacs 27
66 (advice-add 'tab-bar-make-keymap-1 :filter-return
67 '+tab-bar-misc-info-27)))
68 (setq tab-bar-show t))
69 (progn ; Disable
70 (setq tab-bar-show +tab-bar-show-original)
71 (cond
72 ((boundp 'tab-bar-format) ; Emacs 28
73 (setq tab-bar-format +tab-bar-format-original))
74 ((fboundp 'tab-bar-make-keymap-1) ; Emacs 27
75 (advice-remove 'tab-bar-make-keymap-1 '+tab-bar-misc-info-27))))))
76
77
78
79(provide '+tab-bar)
80;;; +tab-bar.el ends here