1
0
Fork 0

nvim: heirline improvements

This commit is contained in:
Daniel Kempkens 2022-05-25 22:34:02 +02:00
parent e23936b1dc
commit f99d9a48e5
5 changed files with 283 additions and 230 deletions

View file

@ -1,13 +1,32 @@
(let [mod {} (let [mod {}
terminal-class (require :toggleterm.terminal) terminal-class (require :toggleterm.terminal)
terminal terminal-class.Terminal] terminal terminal-class.Terminal]
(local elixir (terminal:new {:cmd :iex :close_on_exit true})) (fn repl-setup []
(local erlang (terminal:new {:cmd :erl :close_on_exit true})) (set vim.b.nifoc_shell_mode :REPL))
(local fennel (terminal:new {:cmd "fennel --repl" :close_on_exit true}))
(local fish (terminal:new {:cmd :fish :close_on_exit true})) (fn shell-setup []
(local javascript (terminal:new {:cmd :node :close_on_exit true})) (set vim.b.nifoc_shell_mode :SHELL))
(local nix (terminal:new {:cmd "nix repl" :close_on_exit true}))
(local ruby (terminal:new {:cmd :irb :close_on_exit true})) (local elixir (terminal:new {:cmd :iex
:on_open repl-setup
:close_on_exit true}))
(local erlang (terminal:new {:cmd :erl
:on_open repl-setup
:close_on_exit true}))
(local fennel (terminal:new {:cmd "fennel --repl"
:on_open repl-setup
:close_on_exit true}))
(local fish (terminal:new {:cmd :fish
:on_open shell-setup
:close_on_exit true}))
(local javascript (terminal:new {:cmd :node
:on_open repl-setup
:close_on_exit true}))
(local nix (terminal:new {:cmd "nix repl"
:on_open repl-setup
:close_on_exit true}))
(local ruby
(terminal:new {:cmd :irb :on_open repl-setup :close_on_exit true}))
;; Map filetype to REPL ;; Map filetype to REPL
(local repl-map {: elixir : erlang : fennel : fish : javascript : nix : ruby}) (local repl-map {: elixir : erlang : fennel : fish : javascript : nix : ruby})

View file

@ -1,4 +1,4 @@
(let [mod {:heirline {}} (let [mod {}
api vim.api api vim.api
heirline-utils (require :heirline.utils) heirline-utils (require :heirline.utils)
heirline-conditions (require :heirline.conditions) heirline-conditions (require :heirline.conditions)
@ -13,17 +13,16 @@
(. cl 1))) (. cl 1)))
(fn get-total-lines [] (fn get-total-lines []
(vim.api.nvim_buf_line_count 0)) (api.nvim_buf_line_count 0))
;; Utils ;; Utils
(set mod.heirline.default-hl (set mod.default-hl (fn []
(fn []
{:bg colors.black})) {:bg colors.black}))
(set mod.heirline.space {:provider " "}) (set mod.space {:provider " "})
(set mod.heirline.spacer {:provider " " :hl {:fg colors.bg :bg colors.bg}}) (set mod.spacer {:provider " " :hl {:fg colors.bg :bg colors.bg}})
(set mod.push-right {:provider "%="})
;; Mode ;; Mode
(set mod.heirline.vi-mode (set mod.vi-mode {:init (fn [self]
{:init (fn [self]
(let [mode (. (api.nvim_get_mode) :mode)] (let [mode (. (api.nvim_get_mode) :mode)]
(set self.mode mode))) (set self.mode mode)))
:static {:mode-names {:n :NORMAL :static {:mode-names {:n :NORMAL
@ -61,35 +60,59 @@
:r? :CONFIRM :r? :CONFIRM
:! :SHELL :! :SHELL
:t :TERMINAL} :t :TERMINAL}
:mode-hl {:n {:fg colors.black :bg colors.purple :bold true} :mode-hl {:n {:fg colors.black
:i {:fg colors.black :bg colors.green :bold true} :bg colors.purple
:v {:fg colors.black :bg colors.pink :bold true} :bold true}
:V {:fg colors.black :bg colors.pink :bold true} :i {:fg colors.black
"\022" {:fg colors.black :bg colors.pink :bold true} :bg colors.green
:c {:fg colors.black :bg colors.yellow :bold true} :bold true}
:s {:fg colors.black :bg colors.orange :bold true} :v {:fg colors.black
:S {:fg colors.black :bg colors.orange :bold true} :bg colors.pink
:bold true}
:V {:fg colors.black
:bg colors.pink
:bold true}
"\022" {:fg colors.black
:bg colors.pink
:bold true}
:c {:fg colors.black
:bg colors.yellow
:bold true}
:s {:fg colors.black
:bg colors.orange
:bold true}
:S {:fg colors.black
:bg colors.orange
:bold true}
"\019" {:fg colors.black "\019" {:fg colors.black
:bg colors.orange :bg colors.orange
:bold true} :bold true}
:R {:fg colors.black :bg colors.yellow :bold true} :R {:fg colors.black
:r {:fg colors.black :bg colors.yellow :bold true} :bg colors.yellow
:! {:fg colors.black :bg colors.purple :bold true} :bold true}
:t {:fg colors.black :bg colors.purple :bold true}}} :r {:fg colors.black
:bg colors.yellow
:bold true}
:! {:fg colors.black
:bg colors.purple
:bold true}
:t {:fg colors.black
:bg colors.purple
:bold true}}}
:provider (fn [self] :provider (fn [self]
(.. " " (. self :mode-names self.mode) " ")) (.. " " (. self :mode-names self.mode) " "))
:hl (fn [self] :hl (fn [self]
(let [short-mode (self.mode:sub 1 1)] (let [short-mode (self.mode:sub 1 1)]
(. self :mode-hl short-mode)))}) (. self :mode-hl short-mode)))})
;; Filetype ;; Filetype
(set mod.heirline.filetype-block (set mod.filetype-block
{:init (fn [self] {:init (fn [self]
(set self.filename (api.nvim_buf_get_name 0)))}) (set self.filename (api.nvim_buf_get_name 0)))})
(set mod.heirline.file-icon (set mod.file-icon {:init (fn [self]
{:init (fn [self]
(let [filename self.filename (let [filename self.filename
ext (vim.fn.fnamemodify filename ":e") ext (vim.fn.fnamemodify filename ":e")
(icon color) (web-devicons.get_icon_color filename ext (icon color) (web-devicons.get_icon_color filename
ext
{:default true})] {:default true})]
(set self.icon icon) (set self.icon icon)
(set self.icon-color color))) (set self.icon-color color)))
@ -98,27 +121,22 @@
(.. self.icon " "))) (.. self.icon " ")))
:hl (fn [self] :hl (fn [self]
{:fg self.icon-color})}) {:fg self.icon-color})})
(set mod.heirline.filetype (set mod.filetype {:provider (fn []
{:provider (fn []
(let [ft vim.bo.filetype] (let [ft vim.bo.filetype]
(if (> (ft:len) 0) ft "no ft"))) (if (> (ft:len) 0) ft "no ft")))
:hl {:fg colors.white}}) :hl {:fg colors.white}})
(set mod.heirline.filetype-block (set mod.filetype-block
(heirline-utils.insert mod.heirline.filetype-block (heirline-utils.insert mod.filetype-block mod.file-icon mod.filetype))
mod.heirline.file-icon mod.heirline.filetype))
;; git ;; git
(set mod.heirline.git {:condition heirline-conditions.is_git_repo (set mod.git {:condition heirline-conditions.is_git_repo
:init (fn [self] :init (fn [self]
(let [git-status vim.b.gitsigns_status_dict] (let [git-status vim.b.gitsigns_status_dict]
(set self.git-head git-status.head) (set self.git-head git-status.head)
(set self.git-added (or git-status.added 0)) (set self.git-added (or git-status.added 0))
(set self.git-removed (set self.git-removed (or git-status.removed 0))
(or git-status.removed 0)) (set self.git-changed (or git-status.changed 0))
(set self.git-changed
(or git-status.changed 0))
(set self.has-changes? (set self.has-changes?
(or (> self.git-added 0) (or (> self.git-added 0) (> self.git-removed 0)
(> self.git-removed 0)
(> self.git-changed 0))))) (> self.git-changed 0)))))
1 {:provider (fn [self] 1 {:provider (fn [self]
(.. "  " self.git-head " ")) (.. "  " self.git-head " "))
@ -127,17 +145,14 @@
self.has-changes?) self.has-changes?)
:provider " "} :provider " "}
3 {:provider (fn [self] 3 {:provider (fn [self]
(let [spacer (if (or (> self.git-removed (let [spacer (if (or (> self.git-removed 0)
0) (> self.git-changed 0))
(> self.git-changed
0))
" " "")] " " "")]
(when (> self.git-added 0) (when (> self.git-added 0)
(.. " " self.git-added spacer)))) (.. " " self.git-added spacer))))
:hl {:fg colors.bright_green}} :hl {:fg colors.bright_green}}
4 {:provider (fn [self] 4 {:provider (fn [self]
(let [spacer (if (> self.git-changed 0) (let [spacer (if (> self.git-changed 0) " " "")]
" " "")]
(when (> self.git-removed 0) (when (> self.git-removed 0)
(.. " " self.git-removed spacer)))) (.. " " self.git-removed spacer))))
:hl {:fg colors.bright_red}} :hl {:fg colors.bright_red}}
@ -146,26 +161,32 @@
(.. " " self.git-changed))) (.. " " self.git-changed)))
:hl {:fg colors.cyan}}}) :hl {:fg colors.cyan}}})
;; Diagnostics ;; Diagnostics
(set mod.heirline.diagnostics (set mod.diagnostics {:condition heirline-conditions.has_diagnostics
{:condition heirline-conditions.has_diagnostics
:init (fn [self] :init (fn [self]
(let [d vim.diagnostic] (let [d vim.diagnostic]
(set self.errors (set self.errors
(length (d.get 0 {:severity d.severity.ERROR}))) (length (d.get 0
{:severity d.severity.ERROR})))
(set self.warnings (set self.warnings
(length (d.get 0 {:severity d.severity.WARN}))) (length (d.get 0
(set self.info (length (d.get 0 {:severity d.severity.INFO}))) {:severity d.severity.WARN})))
(set self.info
(length (d.get 0
{:severity d.severity.INFO})))
(set self.hints (set self.hints
(length (d.get 0 {:severity d.severity.HINT}))))) (length (d.get 0
{:severity d.severity.HINT})))))
1 {:provider (fn [self] 1 {:provider (fn [self]
(let [spacer (if (or (> self.warnings 0) (> self.info 0) (let [spacer (if (or (> self.warnings 0)
(> self.info 0)
(> self.hints 0)) (> self.hints 0))
" " "")] " " "")]
(when (> self.errors 0) (when (> self.errors 0)
(.. " " self.errors spacer)))) (.. " " self.errors spacer))))
:hl {:fg colors.red}} :hl {:fg colors.red}}
2 {:provider (fn [self] 2 {:provider (fn [self]
(let [spacer (if (or (> self.info 0) (> self.hints 0)) (let [spacer (if (or (> self.info 0)
(> self.hints 0))
" " "")] " " "")]
(when (> self.warnings 0) (when (> self.warnings 0)
(.. " " self.warnings spacer)))) (.. " " self.warnings spacer))))
@ -180,7 +201,7 @@
(.. " " self.hints))) (.. " " self.hints)))
:hl {:fg colors.cyan}}}) :hl {:fg colors.cyan}}})
;; Current Function ;; Current Function
(set mod.heirline.current-function (set mod.current-function
{:condition heirline-conditions.lsp_attached {:condition heirline-conditions.lsp_attached
:provider (fn [] :provider (fn []
(let [ctx vim.b.nifoc_lsp_current_context] (let [ctx vim.b.nifoc_lsp_current_context]
@ -188,8 +209,7 @@
ctx))) ctx)))
:hl {:fg colors.white}}) :hl {:fg colors.white}})
;; Buffer Options ;; Buffer Options
(set mod.heirline.buffer-options (set mod.buffer-options {:init (fn [self]
{:init (fn [self]
(set self.has-options? (set self.has-options?
(or (buffer-variable-exists? :nifoc_lsp_enabled) (or (buffer-variable-exists? :nifoc_lsp_enabled)
(buffer-variable-exists? :nifoc_treesitter_enabled) (buffer-variable-exists? :nifoc_treesitter_enabled)
@ -203,47 +223,55 @@
" "))} " "))}
3 {:provider (fn [] 3 {:provider (fn []
(when (or (buffer-variable-exists? :nifoc_lsp_formatter_enabled) (when (or (buffer-variable-exists? :nifoc_lsp_formatter_enabled)
(not= (vim.opt_local.formatprg:get) "")) (not= (vim.opt_local.formatprg:get)
""))
" "))} " "))}
4 {:provider (fn [] 4 {:provider (fn []
(when (buffer-variable-exists? :nifoc_treesitter_enabled) (when (buffer-variable-exists? :nifoc_treesitter_enabled)
" "))} " "))}
5 {:provider (fn [] 5 {:provider (fn []
(when vim.wo.spell (when vim.wo.spell
"暈 "))}}) "暈"))}})
;; Position ;; Position
(set mod.heirline.position {:init (fn [self] (set mod.position
(let [pos (api.nvim_win_get_cursor 0)]
(set self.position-line
(tostring (. pos 1)))
(set self.position-column
(tostring (. pos 2)))))
:provider (fn [self]
(string.format " %3s:%-3s "
self.position-line
self.position-column))
:hl {:fg colors.black
:bg colors.purple
:bold true}})
;; Scrollbar
(set mod.heirline.scrollbar
{:init (fn [self] {:init (fn [self]
(let [pos (api.nvim_win_get_cursor 0)]
(set self.position-line (tostring (. pos 1)))
(set self.position-column (tostring (. pos 2)))))
:provider (fn [self]
(string.format " %3s:%-3s " self.position-line
self.position-column))
:hl {:fg colors.black :bg colors.purple :bold true}})
;; Scrollbar
(set mod.scrollbar {:init (fn [self]
(set self.current-line (get-current-line)) (set self.current-line (get-current-line))
(set self.total-lines (get-total-lines))) (set self.total-lines (get-total-lines)))
:static {:scrollbar-icons ["🭶" "🭷" "🭸" "🭹" "🭺" "🭻"]} :static {:scrollbar-icons ["🭶"
"🭷"
"🭸"
"🭹"
"🭺"
"🭻"]}
:provider (fn [self] :provider (fn [self]
(let [i (+ (math.floor (* (/ (- self.current-line 1) (let [i (+ (math.floor (* (/ (- self.current-line
1)
self.total-lines) self.total-lines)
(length self.scrollbar-icons))) (length self.scrollbar-icons)))
1) 1)
new-scrollbar (. self :scrollbar-icons i)] new-scrollbar (. self :scrollbar-icons
i)]
(string.rep new-scrollbar 2))) (string.rep new-scrollbar 2)))
:hl {:fg colors.purple}}) :hl {:fg colors.purple}})
;; Custom Mode ;; Custom Mode
(fn mod.heirline.custom-mode [str] (fn mod.custom-mode [str fg bg]
{:provider (.. " " str " ") {:provider (.. " " str " ")
:hl {:fg colors.black :bg colors.green :bold true}}) :hl {:fg (. colors fg) :bg (. colors bg) :bold true}})
(fn mod.shell-mode [fg bg]
{:provider (fn []
(.. " " vim.b.nifoc_shell_mode " "))
:hl {:fg (. colors fg) :bg (. colors bg) :bold true}})
mod) mod)

View file

@ -1,32 +1,38 @@
(let [heirline (require :heirline) (let [heirline (require :heirline)
utils (require :heirline.utils) utils (require :heirline.utils)
conditions (require :heirline.conditions) conditions (require :heirline.conditions)
ns (. (require :nifoc.statusline) :heirline)] ns (require :nifoc.statusline)]
(local default-statusline [;; Left (local default-statusline [;; Left
ns.spacer
ns.vi-mode ns.vi-mode
(utils.surround [" " ""] nil ns.git) (utils.surround [" " ""] nil ns.git)
(utils.surround [" " ""] nil ns.diagnostics) (utils.surround [" " ""] nil ns.diagnostics)
(utils.surround [" " ""] nil ns.current-function) (utils.surround [" " ""] nil ns.current-function)
;; Right ;; Right
{:provider "%="} ns.push-right
ns.filetype-block ns.filetype-block
ns.space ns.space
ns.buffer-options ns.buffer-options
ns.space ns.space
ns.scrollbar ns.scrollbar
ns.space ns.space
ns.position ns.position])
ns.spacer])
(local telescope-statusline (local telescope-statusline
{:condition (fn [] {:condition (fn []
(conditions.buffer_matches {:filetype [:TelescopePrompt]})) (conditions.buffer_matches {:filetype [:TelescopePrompt]}))
1 ns.spacer 1 (ns.custom-mode :Telescope :black :green)})
2 (ns.custom-mode :Telescope)}) (local shell-statusline
{:condition (fn []
(not= vim.b.nifoc_shell_mode nil))
1 ns.vi-mode
2 ns.push-right
3 ns.scrollbar
4 ns.space
5 (ns.shell-mode :black :purple)})
(local statuslines {:hl ns.default-hl (local statuslines {:hl ns.default-hl
:init utils.pick_child_on_condition :init utils.pick_child_on_condition
1 telescope-statusline 1 telescope-statusline
2 default-statusline}) 2 shell-statusline
3 default-statusline})
;; Load Statusline ;; Load Statusline
(set vim.opt.laststatus 3) (set vim.opt.laststatus 3)
(heirline.setup statuslines)) (heirline.setup statuslines))

View file

@ -73,11 +73,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1653340164, "lastModified": 1653497002,
"narHash": "sha256-t6BPApyasx6FOv2cEVyFBXvkEDrknyUe7bngMbNSBkA=", "narHash": "sha256-L2kb16MAU59LIEWq7ODNsz5AHw5B5Dn9DNaKJF8pG/M=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "e66f0ff69a6c0698b35034b842c4b68814440778", "rev": "2c8489e57a04c913ba9e029cc2849a4bbac9673b",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -128,8 +128,8 @@
src = pkgs.fetchFromGitHub { src = pkgs.fetchFromGitHub {
owner = "nvim-telescope"; owner = "nvim-telescope";
repo = "telescope.nvim"; repo = "telescope.nvim";
rev = "328232e090004274f2c830fdaad9a2bda8ba2e60"; rev = "cd9e6aaee01624c1a5423a783e7fd5bc8fc955c5";
sha256 = "1lnl87b3bp31340ilp12dwr4gimxj8vajjf6nhqabd0w54r7g243"; sha256 = "1qvf0z2q0dz0nbvicz1vhd3684vx7nandxnz7246wncm2l5k26xr";
fetchSubmodules = false; fetchSubmodules = false;
}; };
}; };