Skip to content

Commit 63f2e26

Browse files
committed
feat: support default text-scale
1 parent 4f84a70 commit 63f2e26

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

jcs-modeline.el

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
(:eval (jcs-modeline--render-read-only))
5454
(:eval (jcs-modeline--render-mode-line-process)))
5555
"List of item to render on the left."
56-
:type 'list
56+
:type '(list symbol)
5757
:group 'jcs-modeline)
5858

5959
(defcustom jcs-modeline-right
@@ -69,15 +69,15 @@
6969
(:eval (jcs-modeline--render-percent-position))
7070
(:eval (jcs-modeline--render-end-spaces)))
7171
"List of item to render on the right."
72-
:type 'list
72+
:type '(list symbol)
7373
:group 'jcs-modeline)
7474

7575
(defcustom jcs-modeline-checker-colors '((error . "#FB4933")
7676
(warning . "#FABD2F")
7777
(info . "#83A598")
7878
(note . "#83A598"))
7979
"Alist of colors for checkers."
80-
:type 'list
80+
:type '(list symbol)
8181
:group 'jcs-modeline)
8282

8383
;;
@@ -383,7 +383,7 @@ mouse-1: Toggle display of major mode name"
383383

384384
(defun jcs-modeline--project-root ()
385385
"Return project directory path."
386-
(when-let ((current (project-current))) (project-root current)))
386+
(when-let* ((current (project-current))) (project-root current)))
387387

388388
(defcustom jcs-modeline-show-project-name-virutal-buffer nil
389389
"If non-nil, display project's name in the virutal buffer."
@@ -444,7 +444,7 @@ mouse-1: Switch project"
444444
(nerd-icons-devicon "nf-dev-git_branch" :face 'jcs-modeline-vc-face)))
445445
(Hg . ,jcs-modeline-vc-unknown-icon))
446446
"Alist of vc backends to icon."
447-
:type 'list
447+
:type '(list symbol)
448448
:group 'jcs-modeline)
449449

450450
(declare-function vc-git--symbolic-ref "vc-git.el")
@@ -506,23 +506,37 @@ mouse-1: Switch project"
506506

507507
(defvar text-scale-mode-amount)
508508
(defvar text-scale-mode-lighter)
509+
(defvar default-text-scale--complement)
509510

510511
(defun jcs-modeline--render-text-scale ()
511512
"Render text-scale amount."
512-
(when (and (boundp 'text-scale-mode-lighter)
513-
(/= text-scale-mode-amount 0))
514-
(format "(%s) " (propertize text-scale-mode-lighter
515-
'mouse-face 'mode-line-highlight
516-
'help-echo (concat "Text scale " text-scale-mode-lighter)))))
513+
(let ((ts (and (boundp 'text-scale-mode-lighter)
514+
(/= text-scale-mode-amount 0)))
515+
(dts (and (boundp 'default-text-scale--complement)
516+
(/= default-text-scale--complement 0))))
517+
(when (or ts dts)
518+
(format "(%s:%s) "
519+
(if ts
520+
(propertize text-scale-mode-lighter
521+
'mouse-face 'mode-line-highlight
522+
'help-echo (concat "Text scale " text-scale-mode-lighter))
523+
"0")
524+
(if-let* ((dts)
525+
(delta (- 0 default-text-scale--complement))
526+
(delta (format (if (>= delta 0) "+%d" "%d") delta)))
527+
(propertize (jcs-modeline-2str delta)
528+
'mouse-face 'mode-line-highlight
529+
'help-echo (format "Default text scale %s" delta))
530+
"0")))))
517531

518532
;;
519533
;;; Undo
520534

521535
(defun jcs-modeline--render-undo-tree-buffer-name ()
522536
"Render text-scale amount."
523-
(when-let (((featurep 'undo-tree))
524-
((equal (buffer-name) undo-tree-visualizer-buffer-name))
525-
(ind (buffer-name undo-tree-visualizer-parent-buffer)))
537+
(when-let* (((featurep 'undo-tree))
538+
((equal (buffer-name) undo-tree-visualizer-buffer-name))
539+
(ind (buffer-name undo-tree-visualizer-parent-buffer)))
526540
(concat " "
527541
(propertize ind
528542
'mouse-face 'mode-line-highlight
@@ -614,9 +628,9 @@ If argument RUNNING is non-nil, we turn lighter into question mark."
614628
(last (car (last states)))
615629
result)
616630
(dolist (state states)
617-
(when-let ((lighter (jcs-modeline--flymake-lighter
618-
diags-by-type state
619-
(or some-waiting (null known) all-disabled))))
631+
(when-let* ((lighter (jcs-modeline--flymake-lighter
632+
diags-by-type state
633+
(or some-waiting (null known) all-disabled))))
620634
(setq result (concat result lighter
621635
(unless (equal state last) "/")))))
622636
(propertize result
@@ -646,7 +660,7 @@ If argument RUNNING is non-nil, we turn lighter into question mark."
646660
(running (eq 'running flycheck-last-status-change))
647661
result)
648662
(dolist (state states)
649-
(when-let ((lighter (jcs-modeline--flycheck-lighter state running)))
663+
(when-let* ((lighter (jcs-modeline--flycheck-lighter state running)))
650664
(setq result (concat result lighter
651665
(unless (equal state last) "/")))))
652666
(propertize result
@@ -661,8 +675,8 @@ If argument RUNNING is non-nil, we turn lighter into question mark."
661675

662676
(defun jcs-modeline--render-csv ()
663677
"Render for `csv-mode'."
664-
(when-let (((memq major-mode '(csv-mode tsv-mode)))
665-
(ind (format-mode-line csv-mode-line-format)))
678+
(when-let* (((memq major-mode '(csv-mode tsv-mode)))
679+
(ind (format-mode-line csv-mode-line-format)))
666680
(concat (propertize ind
667681
'mouse-face 'mode-line-highlight
668682
'help-echo "csv")
@@ -676,8 +690,8 @@ If argument RUNNING is non-nil, we turn lighter into question mark."
676690

677691
(defun jcs-modeline--render-nov ()
678692
"Render for nov."
679-
(when-let (((eq major-mode 'nov-mode))
680-
(ind (format "[%s/%s]" (1+ nov-documents-index) (length nov-documents))))
693+
(when-let* (((eq major-mode 'nov-mode))
694+
(ind (format "[%s/%s]" (1+ nov-documents-index) (length nov-documents))))
681695
(propertize ind
682696
'mouse-face 'mode-line-highlight
683697
'help-echo "[current page/totla page]")))

0 commit comments

Comments
 (0)