Skip to content

Commit

Permalink
Add support for display icons in check-simple-format (#706)
Browse files Browse the repository at this point in the history
This add an optional feature to include icons to check-simple-format, it makes doom-modeline fancy and easier to distinguish error types (related to: #639), this implementation no needs to force users add-advices or make a custom (and more complex) segment to modeline.
  • Loading branch information
DevelopmentCool2449 authored Mar 22, 2024
1 parent e09b8e9 commit 798d8b9
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 34 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,15 @@ Run `M-x customize-group RET doom-modeline RET` or set the variables.
(setq doom-modeline-total-line-number nil)
;; If non-nil, only display one number for check information if applicable.
;; If set to icons, display check information with icons.
(setq doom-modeline-check-simple-format t)
;; Change error icons.
;; Only if doom-modeline-check-simple-format is set to icons
(setq doom-modeline-check-error-icon "⛔")
(setq doom-modeline-check-warning-icon "❌")
(setq doom-modeline-check-note-icon "❎")
;; The maximum number displayed for notifications.
(setq doom-modeline-number-limit 99)
Expand Down
6 changes: 4 additions & 2 deletions doom-modeline-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,10 @@ in the given order."
"4.2.0")

(defcustom doom-modeline-check-simple-format t
"If non-nil, only display one number for check information if applicable."
:type 'boolean
"If non-nil, only display one number for check information if applicable.
If set to icons, display check information with icons."
:type '(choice boolean
(const :tag "simple icons" icons))
:group 'doom-modeline)

(defcustom doom-modeline-number-limit 99
Expand Down
110 changes: 78 additions & 32 deletions doom-modeline-segments.el
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@
(defvar winum-auto-setup-mode-line)
(defvar xah-fly-insert-state-p)

(defcustom doom-modeline-check-error-icon
(doom-modeline-check-icon
"nf-md-alert_circle_outline" "" "!" 'doom-modeline-urgent)
"Icon to be using in check segment.
Only works if `doom-modeline-check-simple-format' is set to icons."
:type '(string)
:group 'doom-modeline)

(defcustom doom-modeline-check-warning-icon
(doom-modeline-check-icon
"nf-md-alert_outline" "" "!" 'doom-modeline-warning)
"Icon to be using in check segment.
Only works if `doom-modeline-check-simple-format' is set to icons."
:type '(string)
:group 'doom-modeline)

(defcustom doom-modeline-check-note-icon
(doom-modeline-check-icon
"nf-md-information_outline" "" "i" 'doom-modeline-info)
"Icon to be using in check segment.
Only works if `doom-modeline-check-simple-format' is set to icons."
:type '(string)
:group 'doom-modeline)

(declare-function anzu--reset-status "ext:anzu")
(declare-function anzu--where-is-here "ext:anzu")
(declare-function async-inject-variables "ext:async")
Expand Down Expand Up @@ -783,11 +807,13 @@ level."
(pcase status
('finished (if flycheck-current-errors
(let-alist (doom-modeline--flycheck-count-errors)
(doom-modeline-check-icon
"nf-md-alert_circle_outline" "" "!"
(cond ((> .error 0) 'doom-modeline-urgent)
((> .warning 0) 'doom-modeline-warning)
(t 'doom-modeline-info))))
(if (not (eq doom-modeline-check-simple-format 'icons))
(doom-modeline-check-icon
"nf-md-alert_circle_outline" "" "!"
(cond ((> .error 0) 'doom-modeline-urgent)
((> .warning 0) 'doom-modeline-warning)
(t 'doom-modeline-info)))
doom-modeline-check-error-icon))
(doom-modeline-check-icon "nf-md-check_circle_outline" "" "" 'doom-modeline-info)))
('running (doom-modeline-check-icon "nf-md-timer_sand" "" "*" 'doom-modeline-debug))
('no-checker (doom-modeline-check-icon "nf-md-alert_box_outline" "" "-" 'doom-modeline-debug))
Expand Down Expand Up @@ -846,19 +872,28 @@ mouse-2: Show help for minor mode")
(pcase status
('finished (when flycheck-current-errors
(let-alist (doom-modeline--flycheck-count-errors)
(if doom-modeline-check-simple-format
(doom-modeline-check-text
(number-to-string (+ .error .warning .info))
(cond ((> .error 0) 'doom-modeline-urgent)
((> .warning 0) 'doom-modeline-warning)
(t 'doom-modeline-info)))
(format "%s/%s/%s"
(doom-modeline-check-text (number-to-string .error)
'doom-modeline-urgent)
(doom-modeline-check-text (number-to-string .warning)
'doom-modeline-warning)
(doom-modeline-check-text (number-to-string .info)
'doom-modeline-info))))))
(pcase doom-modeline-check-simple-format
('t (doom-modeline-check-text
(number-to-string (+ .error .warning .info))
(cond ((> .error 0) 'doom-modeline-urgent)
((> .warning 0) 'doom-modeline-warning)
(t 'doom-modeline-info))))
('nil (format "%s/%s/%s"
(doom-modeline-check-text (number-to-string .error)
'doom-modeline-urgent)
(doom-modeline-check-text (number-to-string .warning)
'doom-modeline-warning)
(doom-modeline-check-text (number-to-string .info)
'doom-modeline-info)))
('icons (format "%s %s %s %s %s"
(doom-modeline-check-text (number-to-string .error)
'doom-modeline-urgent)
doom-modeline-check-warning-icon
(doom-modeline-check-text (number-to-string .warning)
'doom-modeline-warning)
doom-modeline-check-note-icon
(doom-modeline-check-text (number-to-string .info)
'doom-modeline-info)))))))
('running (and doom-modeline--flycheck-text
(propertize doom-modeline--flycheck-text 'face 'doom-modeline-debug)))
;; ('no-checker nil)
Expand Down Expand Up @@ -958,10 +993,12 @@ mouse-3: Next error"
((> severity note-level) (cl-incf .warning))
(t (cl-incf .note))))))
(if (> (+ .error .warning .note) 0)
(doom-modeline-check-icon "nf-md-alert_circle_outline" "" "!"
(cond ((> .error 0) 'doom-modeline-urgent)
((> .warning 0) 'doom-modeline-warning)
(t 'doom-modeline-info)))
(if (not (eq doom-modeline-check-simple-format 'icons))
(doom-modeline-check-icon "nf-md-alert_circle_outline" "" "!"
(cond ((> .error 0) 'doom-modeline-urgent)
((> .warning 0) 'doom-modeline-warning)
(t 'doom-modeline-info)))
(doom-modeline-check-icon "nf-md-alert_circle_outline" "" "!" 'doom-modeline-urgent))
(doom-modeline-check-icon "nf-md-check_circle_outline" "" "-" 'doom-modeline-info))))))))
(propertize
icon
Expand Down Expand Up @@ -1039,18 +1076,27 @@ mouse-2: Show help for minor mode"
(all-disabled nil)
(t (let ((num (+ .error .warning .note)))
(when (> num 0)
(if doom-modeline-check-simple-format
(doom-modeline-check-text (number-to-string num)
(pcase doom-modeline-check-simple-format
('t (doom-modeline-check-text (number-to-string num)
(cond ((> .error 0) 'doom-modeline-urgent)
((> .warning 0) 'doom-modeline-warning)
(t 'doom-modeline-info)))
(format "%s/%s/%s"
(doom-modeline-check-text (number-to-string .error)
'doom-modeline-urgent)
(doom-modeline-check-text (number-to-string .warning)
'doom-modeline-warning)
(doom-modeline-check-text (number-to-string .note)
'doom-modeline-info)))))))))
(t 'doom-modeline-info))))
('nil (format "%s/%s/%s"
(doom-modeline-check-text (number-to-string .error)
'doom-modeline-urgent)
(doom-modeline-check-text (number-to-string .warning)
'doom-modeline-warning)
(doom-modeline-check-text (number-to-string .note)
'doom-modeline-info)))
('icons (format "%s %s %s %s %s"
(doom-modeline-check-text (number-to-string .error)
'doom-modeline-urgent)
doom-modeline-check-warning-icon
(doom-modeline-check-text (number-to-string .warning)
'doom-modeline-warning)
doom-modeline-check-note-icon
(doom-modeline-check-text (number-to-string .note)
'doom-modeline-info))))))))))
(propertize
text
'help-echo (cond
Expand Down

0 comments on commit 798d8b9

Please sign in to comment.