From 8e56aa8706ea62a539f44d9d7862e447d8d5023b Mon Sep 17 00:00:00 2001 From: Eric Dallo Date: Fri, 5 Jun 2020 14:25:21 -0300 Subject: [PATCH 1/4] Add lsp modeline --- modules/ui/modeline/+light.el | 58 +++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/modules/ui/modeline/+light.el b/modules/ui/modeline/+light.el index 83d2ef6d6..f49ce1c74 100644 --- a/modules/ui/modeline/+light.el +++ b/modules/ui/modeline/+light.el @@ -109,14 +109,22 @@ side of the modeline, and whose CDR is the right-hand side.") (if (eq idx len) "\"};" "\",\n"))))) 'xpm t :ascent 'center))))) -(defun +modeline-format-icon (icon label &optional face help-echo voffset) - (propertize (concat (all-the-icons-material - icon - :face face - :height 1.1 - :v-adjust (or voffset -0.225)) - (propertize label 'face face)) - 'help-echo help-echo)) +(defun +modeline-format-icon (icon-set icon label &optional face help-echo voffset) + "Build from ICON-SET the ICON with LABEL. +Using optionals attributes FACE, HELP-ECHO and VOFFSET." + (let ((icon-set-fn (pcase icon-set + ('octicon #'all-the-icons-octicon) + ('faicon #'all-the-icons-faicon) + ('material #'all-the-icons-material) + ('alltheicon #'all-the-icons-alltheicon) + ('fileicon #'all-the-icons-fileicon)))) + (propertize (concat (funcall icon-set-fn + icon + :face face + :height 1.1 + :v-adjust (or voffset -0.225)) + (propertize label 'face face)) + 'help-echo help-echo))) (defun set-modeline! (name &optional default) "Set the modeline to NAME. @@ -410,7 +418,7 @@ Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with (let ((error (or .error 0)) (warning (or .warning 0)) (info (or .info 0))) - (+modeline-format-icon "do_not_disturb_alt" + (+modeline-format-icon 'material "do_not_disturb_alt" (number-to-string (+ error warning info)) (cond ((> error 0) 'error) ((> warning 0) 'warning) @@ -420,10 +428,11 @@ Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with warning info)))) (+modeline-format-icon "check" "" 'success))) - (`running (+modeline-format-icon "access_time" "*" 'mode-line-inactive "Running...")) - (`errored (+modeline-format-icon "sim_card_alert" "!" 'error "Errored!")) - (`interrupted (+modeline-format-icon "pause" "!" 'mode-line-inactive "Interrupted")) - (`suspicious (+modeline-format-icon "priority_high" "!" 'error "Suspicious")))))) + (`running (+modeline-format-icon'material "access_time" "*" 'mode-line-inactive "Running...")) + (`errored (+modeline-format-icon'material "sim_card_alert" "!" 'error "Errored!")) + (`interrupted (+modeline-format-icon'material "pause" "!" 'mode-line-inactive "Interrupted")) + (`suspicious (+modeline-format-icon'material "priority_high" "!" 'error "Suspicious")))))) + ;;; `+modeline-selection-info' @@ -476,6 +485,26 @@ lines are selected, or the NxM dimensions of a block selection.") (add-hook 'deactivate-mark-hook #'+modeline-remove-selection-segment-h)) +;;; `+modeline-lsp' +(progn + (def-modeline-var! +modeline-lsp nil + "Display LSP connection status icon for the current buffer." + :local t) + + (add-hook! '(lsp-before-initialize-hook + lsp-after-initialize-hook + lsp-after-uninitialized-functions + lsp-before-open-hook + lsp-after-open-hook) + (defun +modeline-lsp-update (&rest _) + "Update lsp state." + (let* ((workspaces (lsp-workspaces)) + (face (if workspaces 'success 'warning)) + (label (if workspaces "LSP Connected" "LSP Disconnected"))) + (setq +modeline-lsp + (+modeline-format-icon 'faicon "rocket" "" face label -0.0575)))))) + + ;;; `+modeline-encoding' (def-modeline-var! +modeline-encoding `(:eval @@ -508,6 +537,9 @@ lines are selected, or the NxM dimensions of a block selection.") +modeline-position) `("" mode-line-misc-info + " " + +modeline-lsp + " " +modeline-modes (vc-mode (" " ,(all-the-icons-octicon "git-branch" :v-adjust 0.0) From 7ddfb6271d2667b307868f05a35e8b3c3d1a6f25 Mon Sep 17 00:00:00 2001 From: Eric Dallo Date: Fri, 5 Jun 2020 17:47:16 -0300 Subject: [PATCH 2/4] Add repl modeline --- modules/ui/modeline/+light.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modules/ui/modeline/+light.el b/modules/ui/modeline/+light.el index f49ce1c74..951a26c48 100644 --- a/modules/ui/modeline/+light.el +++ b/modules/ui/modeline/+light.el @@ -485,6 +485,24 @@ lines are selected, or the NxM dimensions of a block selection.") (add-hook 'deactivate-mark-hook #'+modeline-remove-selection-segment-h)) +;;; `+modeline-repl' +(progn + (def-modeline-var! +modeline-repl nil + "Display REPL connection status icon." + :local t) + + (add-hook! '(cider-connected-hook + cider-disconnected-hook + cider-mode-hook) + (defun +modeline-repl-cider-update () + "Update repl connection to cider connection state." + (let* ((connected (cider-connected-p)) + (face (if connected 'success 'warning)) + (label (if connected "Cider connected" "Cider disconnected"))) + (setq +modeline-repl + (+modeline-format-icon 'faicon "terminal" "" face label -0.0575)))))) + + ;;; `+modeline-lsp' (progn (def-modeline-var! +modeline-lsp nil @@ -538,6 +556,8 @@ lines are selected, or the NxM dimensions of a block selection.") `("" mode-line-misc-info " " + +modeline-repl + " " +modeline-lsp " " +modeline-modes From c224e2e771e40ed44f118d0d23dc953f45a2ca9c Mon Sep 17 00:00:00 2001 From: Eric Dallo Date: Fri, 5 Jun 2020 21:42:36 -0300 Subject: [PATCH 3/4] Move to global-mode-string --- modules/lang/clojure/config.el | 19 +++++++++++++++ modules/tools/lsp/+lsp.el | 23 +++++++++++++++++- modules/ui/modeline/+light.el | 43 ---------------------------------- 3 files changed, 41 insertions(+), 44 deletions(-) diff --git a/modules/lang/clojure/config.el b/modules/lang/clojure/config.el index 4f7690eca..32f2b8991 100644 --- a/modules/lang/clojure/config.el +++ b/modules/lang/clojure/config.el @@ -94,6 +94,25 @@ (evil-make-overriding-map cider--debug-mode-map 'normal) (evil-normalize-keymaps)))) + (when (featurep! :ui modeline +light) + (defvar-local cider-modeline-icon nil) + + (add-hook! '(cider-connected-hook + cider-disconnected-hook + cider-mode-hook) + (defun +clojure--cider-update-modeline () + "Update modeline with cider connection state." + (let* ((connected (cider-connected-p)) + (face (if connected 'success 'warning)) + (label (if connected "Cider connected" "Cider disconnected"))) + (setq cider-modeline-icon (concat + " " + (+modeline-format-icon 'faicon "terminal" "" face label -0.0575) + " ")) + (add-to-list 'global-mode-string + 'cider-modeline-icon + 'append))))) + ;; The CIDER welcome message obscures error messages that the above code is ;; supposed to be make visible. (setq cider-repl-display-help-banner nil) diff --git a/modules/tools/lsp/+lsp.el b/modules/tools/lsp/+lsp.el index 8548243a7..efef270be 100644 --- a/modules/tools/lsp/+lsp.el +++ b/modules/tools/lsp/+lsp.el @@ -130,7 +130,28 @@ server getting expensively restarted when reverting buffers." (or doom-debug-p (not (eq +lsp-prompt-to-install-server 'quiet))))) (doom-shut-up-a #'lsp--info "No language server available for %S" - major-mode)))))) + major-mode))))) + + (when (featurep! :ui modeline +light) + (defvar-local lsp-modeline-icon nil) + + (add-hook! '(lsp-before-initialize-hook + lsp-after-initialize-hook + lsp-after-uninitialized-functions + lsp-before-open-hook + lsp-after-open-hook) + (defun +lsp-update-modeline (&rest _) + "Update modeline with lsp state." + (let* ((workspaces (lsp-workspaces)) + (face (if workspaces 'success 'warning)) + (label (if workspaces "LSP Connected" "LSP Disconnected"))) + (setq lsp-modeline-icon (concat + " " + (+modeline-format-icon 'faicon "rocket" "" face label -0.0575) + " ")) + (add-to-list 'global-mode-string + '(t (:eval lsp-modeline-icon)) + 'append)))))) (use-package! lsp-ui diff --git a/modules/ui/modeline/+light.el b/modules/ui/modeline/+light.el index 951a26c48..3b13583da 100644 --- a/modules/ui/modeline/+light.el +++ b/modules/ui/modeline/+light.el @@ -485,44 +485,6 @@ lines are selected, or the NxM dimensions of a block selection.") (add-hook 'deactivate-mark-hook #'+modeline-remove-selection-segment-h)) -;;; `+modeline-repl' -(progn - (def-modeline-var! +modeline-repl nil - "Display REPL connection status icon." - :local t) - - (add-hook! '(cider-connected-hook - cider-disconnected-hook - cider-mode-hook) - (defun +modeline-repl-cider-update () - "Update repl connection to cider connection state." - (let* ((connected (cider-connected-p)) - (face (if connected 'success 'warning)) - (label (if connected "Cider connected" "Cider disconnected"))) - (setq +modeline-repl - (+modeline-format-icon 'faicon "terminal" "" face label -0.0575)))))) - - -;;; `+modeline-lsp' -(progn - (def-modeline-var! +modeline-lsp nil - "Display LSP connection status icon for the current buffer." - :local t) - - (add-hook! '(lsp-before-initialize-hook - lsp-after-initialize-hook - lsp-after-uninitialized-functions - lsp-before-open-hook - lsp-after-open-hook) - (defun +modeline-lsp-update (&rest _) - "Update lsp state." - (let* ((workspaces (lsp-workspaces)) - (face (if workspaces 'success 'warning)) - (label (if workspaces "LSP Connected" "LSP Disconnected"))) - (setq +modeline-lsp - (+modeline-format-icon 'faicon "rocket" "" face label -0.0575)))))) - - ;;; `+modeline-encoding' (def-modeline-var! +modeline-encoding `(:eval @@ -555,11 +517,6 @@ lines are selected, or the NxM dimensions of a block selection.") +modeline-position) `("" mode-line-misc-info - " " - +modeline-repl - " " - +modeline-lsp - " " +modeline-modes (vc-mode (" " ,(all-the-icons-octicon "git-branch" :v-adjust 0.0) From f36874540643a8eaa86d08091750c124e6eafd7d Mon Sep 17 00:00:00 2001 From: Eric Dallo Date: Tue, 16 Jun 2020 18:13:48 -0300 Subject: [PATCH 4/4] Fix eval on modeline --- modules/lang/clojure/config.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/lang/clojure/config.el b/modules/lang/clojure/config.el index 32f2b8991..c5447f820 100644 --- a/modules/lang/clojure/config.el +++ b/modules/lang/clojure/config.el @@ -110,7 +110,7 @@ (+modeline-format-icon 'faicon "terminal" "" face label -0.0575) " ")) (add-to-list 'global-mode-string - 'cider-modeline-icon + '(t (:eval cider-modeline-icon)) 'append))))) ;; The CIDER welcome message obscures error messages that the above code is