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,174 +13,195 @@
(. 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.space {:provider " "})
(set mod.heirline.space {:provider " "}) (set mod.spacer {:provider " " :hl {:fg colors.bg :bg colors.bg}})
(set mod.heirline.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 :no :O-PENDING
:no :O-PENDING :nov :O-PENDING
:nov :O-PENDING :noV :O-PENDING
:noV :O-PENDING "no\022" :O-PENDING
"no\022" :O-PENDING :niI :NORMAL
:niI :NORMAL :niR :NORMAL
:niR :NORMAL :niV :NORMAL
:niV :NORMAL :nt :NORMAL
:nt :NORMAL :v :VISUAL
:v :VISUAL :vs :VISUAL
:vs :VISUAL :V :V-LINE
:V :V-LINE :Vs :V-LINE
:Vs :V-LINE "\022" :V-BLOCK
"\022" :V-BLOCK "\022s" :V-BLOCK
"\022s" :V-BLOCK :s :SELECT
:s :SELECT :S :S-LINE
:S :S-LINE "\019" :S-BLOCK
"\019" :S-BLOCK :i :INSERT
:i :INSERT :ic :INSERT
:ic :INSERT :ix :INSERT
:ix :INSERT :R :REPLACE
:R :REPLACE :Rc :REPLACE
:Rc :REPLACE :Rx :REPLACE
:Rx :REPLACE :Rv :V-REPLACE
:Rv :V-REPLACE :Rvc :V-REPLACE
:Rvc :V-REPLACE :Rvx :V-REPLACE
:Rvx :V-REPLACE :c :COMMAND
:c :COMMAND :cv :EX
:cv :EX :ce :EX
:ce :EX :r :REPLACE
:r :REPLACE :rm :MORE
:rm :MORE :r? :CONFIRM
:r? :CONFIRM :! :SHELL
:! :SHELL :t :TERMINAL}
:t :TERMINAL} :mode-hl {:n {:fg colors.black
:mode-hl {:n {:fg colors.black :bg colors.purple :bold true} :bg colors.purple
:i {:fg colors.black :bg colors.green :bold true} :bold true}
:v {:fg colors.black :bg colors.pink :bold true} :i {:fg colors.black
:V {:fg colors.black :bg colors.pink :bold true} :bg colors.green
"\022" {:fg colors.black :bg colors.pink :bold true} :bold true}
:c {:fg colors.black :bg colors.yellow :bold true} :v {:fg colors.black
:s {:fg colors.black :bg colors.orange :bold true} :bg colors.pink
:S {:fg colors.black :bg colors.orange :bold true} :bold true}
"\019" {:fg colors.black :V {:fg colors.black
:bg colors.orange :bg colors.pink
:bold true} :bold true}
:R {:fg colors.black :bg colors.yellow :bold true} "\022" {:fg colors.black
:r {:fg colors.black :bg colors.yellow :bold true} :bg colors.pink
:! {:fg colors.black :bg colors.purple :bold true} :bold true}
:t {:fg colors.black :bg colors.purple :bold true}}} :c {:fg colors.black
:provider (fn [self] :bg colors.yellow
(.. " " (. self :mode-names self.mode) " ")) :bold true}
:hl (fn [self] :s {:fg colors.black
(let [short-mode (self.mode:sub 1 1)] :bg colors.orange
(. self :mode-hl short-mode)))}) :bold true}
:S {:fg colors.black
:bg colors.orange
:bold true}
"\019" {:fg colors.black
:bg colors.orange
:bold true}
:R {:fg colors.black
:bg colors.yellow
: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]
(.. " " (. self :mode-names self.mode) " "))
:hl (fn [self]
(let [short-mode (self.mode:sub 1 1)]
(. 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
(icon color) (web-devicons.get_icon_color filename ext ext
{:default true})] {:default true})]
(set self.icon icon) (set self.icon icon)
(set self.icon-color color))) (set self.icon-color color)))
:provider (fn [self] :provider (fn [self]
(when self.icon (when self.icon
(.. 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.filetype-block
(set mod.heirline.filetype-block (heirline-utils.insert mod.filetype-block mod.file-icon mod.filetype))
(heirline-utils.insert mod.heirline.filetype-block
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 (set self.has-changes?
(or git-status.changed 0)) (or (> self.git-added 0) (> self.git-removed 0)
(set self.has-changes? (> self.git-changed 0)))))
(or (> self.git-added 0) 1 {:provider (fn [self]
(> self.git-removed 0) (.. "  " self.git-head " "))
(> self.git-changed 0))))) :hl {:fg colors.black :bg colors.orange :bold true}}
1 {:provider (fn [self] 2 {:condition (fn [self]
(.. "  " self.git-head " ")) self.has-changes?)
:hl {:fg colors.black :bg colors.orange :bold true}} :provider " "}
2 {:condition (fn [self] 3 {:provider (fn [self]
self.has-changes?) (let [spacer (if (or (> self.git-removed 0)
:provider " "} (> self.git-changed 0))
3 {:provider (fn [self] " " "")]
(let [spacer (if (or (> self.git-removed (when (> self.git-added 0)
0) (.. " " self.git-added spacer))))
(> self.git-changed :hl {:fg colors.bright_green}}
0)) 4 {:provider (fn [self]
" " "")] (let [spacer (if (> self.git-changed 0) " " "")]
(when (> self.git-added 0) (when (> self.git-removed 0)
(.. " " self.git-added spacer)))) (.. " " self.git-removed spacer))))
:hl {:fg colors.bright_green}} :hl {:fg colors.bright_red}}
4 {:provider (fn [self] 5 {:provider (fn [self]
(let [spacer (if (> self.git-changed 0) (when (> self.git-changed 0)
" " "")] (.. " " self.git-changed)))
(when (> self.git-removed 0) :hl {:fg colors.cyan}}})
(.. " " self.git-removed spacer))))
:hl {:fg colors.bright_red}}
5 {:provider (fn [self]
(when (> self.git-changed 0)
(.. " " self.git-changed)))
: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
(length (d.get 0 {:severity d.severity.ERROR}))) {: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.hints (set self.info
(length (d.get 0 {:severity d.severity.HINT}))))) (length (d.get 0
1 {:provider (fn [self] {:severity d.severity.INFO})))
(let [spacer (if (or (> self.warnings 0) (> self.info 0) (set self.hints
(> self.hints 0)) (length (d.get 0
" " "")] {:severity d.severity.HINT})))))
(when (> self.errors 0) 1 {:provider (fn [self]
(.. " " self.errors spacer)))) (let [spacer (if (or (> self.warnings 0)
:hl {:fg colors.red}} (> self.info 0)
2 {:provider (fn [self] (> self.hints 0))
(let [spacer (if (or (> self.info 0) (> self.hints 0)) " " "")]
" " "")] (when (> self.errors 0)
(when (> self.warnings 0) (.. " " self.errors spacer))))
(.. " " self.warnings spacer)))) :hl {:fg colors.red}}
:hl {:fg colors.yellow}} 2 {:provider (fn [self]
3 {:provider (fn [self] (let [spacer (if (or (> self.info 0)
(let [spacer (if (> self.hints 0) " " "")] (> self.hints 0))
(when (> self.info 0) " " "")]
(.. " " self.info spacer)))) (when (> self.warnings 0)
:hl {:fg colors.cyan}} (.. " " self.warnings spacer))))
4 {:provider (fn [self] :hl {:fg colors.yellow}}
(when (> self.hints 0) 3 {:provider (fn [self]
(.. " " self.hints))) (let [spacer (if (> self.hints 0) " " "")]
:hl {:fg colors.cyan}}}) (when (> self.info 0)
(.. " " self.info spacer))))
:hl {:fg colors.cyan}}
4 {:provider (fn [self]
(when (> self.hints 0)
(.. " " self.hints)))
: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,62 +209,69 @@
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) vim.wo.spell)))
vim.wo.spell))) :hl {:fg colors.black :bg colors.orange}
:hl {:fg colors.black :bg colors.orange} 1 {:condition (fn [self]
1 {:condition (fn [self] self.has-options?)
self.has-options?) :provider " "}
:provider " "} 2 {:provider (fn []
2 {:provider (fn [] (when (buffer-variable-exists? :nifoc_lsp_enabled)
(when (buffer-variable-exists? :nifoc_lsp_enabled) " "))}
" "))} 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]
(set self.current-line (get-current-line)) (let [pos (api.nvim_win_get_cursor 0)]
(set self.total-lines (get-total-lines))) (set self.position-line (tostring (. pos 1)))
:static {:scrollbar-icons ["🭶" "🭷" "🭸" "🭹" "🭺" "🭻"]} (set self.position-column (tostring (. pos 2)))))
:provider (fn [self] :provider (fn [self]
(let [i (+ (math.floor (* (/ (- self.current-line 1) (string.format " %3s:%-3s " self.position-line
self.total-lines) self.position-column))
(length self.scrollbar-icons))) :hl {:fg colors.black :bg colors.purple :bold true}})
1) ;; Scrollbar
new-scrollbar (. self :scrollbar-icons i)] (set mod.scrollbar {:init (fn [self]
(string.rep new-scrollbar 2))) (set self.current-line (get-current-line))
:hl {:fg colors.purple}}) (set self.total-lines (get-total-lines)))
:static {:scrollbar-icons ["🭶"
"🭷"
"🭸"
"🭹"
"🭺"
"🭻"]}
:provider (fn [self]
(let [i (+ (math.floor (* (/ (- self.current-line
1)
self.total-lines)
(length self.scrollbar-icons)))
1)
new-scrollbar (. self :scrollbar-icons
i)]
(string.rep new-scrollbar 2)))
: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;
}; };
}; };