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 {}
terminal-class (require :toggleterm.terminal)
terminal terminal-class.Terminal]
(local elixir (terminal:new {:cmd :iex :close_on_exit true}))
(local erlang (terminal:new {:cmd :erl :close_on_exit true}))
(local fennel (terminal:new {:cmd "fennel --repl" :close_on_exit true}))
(local fish (terminal:new {:cmd :fish :close_on_exit true}))
(local javascript (terminal:new {:cmd :node :close_on_exit true}))
(local nix (terminal:new {:cmd "nix repl" :close_on_exit true}))
(local ruby (terminal:new {:cmd :irb :close_on_exit true}))
(fn repl-setup []
(set vim.b.nifoc_shell_mode :REPL))
(fn shell-setup []
(set vim.b.nifoc_shell_mode :SHELL))
(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
(local repl-map {: elixir : erlang : fennel : fish : javascript : nix : ruby})

View file

@ -1,4 +1,4 @@
(let [mod {:heirline {}}
(let [mod {}
api vim.api
heirline-utils (require :heirline.utils)
heirline-conditions (require :heirline.conditions)
@ -13,174 +13,195 @@
(. cl 1)))
(fn get-total-lines []
(vim.api.nvim_buf_line_count 0))
(api.nvim_buf_line_count 0))
;; Utils
(set mod.heirline.default-hl
(fn []
{:bg colors.black}))
(set mod.heirline.space {:provider " "})
(set mod.heirline.spacer {:provider " " :hl {:fg colors.bg :bg colors.bg}})
(set mod.default-hl (fn []
{:bg colors.black}))
(set mod.space {:provider " "})
(set mod.spacer {:provider " " :hl {:fg colors.bg :bg colors.bg}})
(set mod.push-right {:provider "%="})
;; Mode
(set mod.heirline.vi-mode
{:init (fn [self]
(let [mode (. (api.nvim_get_mode) :mode)]
(set self.mode mode)))
:static {:mode-names {:n :NORMAL
:no :O-PENDING
:nov :O-PENDING
:noV :O-PENDING
"no\022" :O-PENDING
:niI :NORMAL
:niR :NORMAL
:niV :NORMAL
:nt :NORMAL
:v :VISUAL
:vs :VISUAL
:V :V-LINE
:Vs :V-LINE
"\022" :V-BLOCK
"\022s" :V-BLOCK
:s :SELECT
:S :S-LINE
"\019" :S-BLOCK
:i :INSERT
:ic :INSERT
:ix :INSERT
:R :REPLACE
:Rc :REPLACE
:Rx :REPLACE
:Rv :V-REPLACE
:Rvc :V-REPLACE
:Rvx :V-REPLACE
:c :COMMAND
:cv :EX
:ce :EX
:r :REPLACE
:rm :MORE
:r? :CONFIRM
:! :SHELL
:t :TERMINAL}
:mode-hl {:n {:fg colors.black :bg colors.purple :bold true}
:i {:fg colors.black :bg colors.green :bold true}
:v {:fg colors.black :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
: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)))})
(set mod.vi-mode {:init (fn [self]
(let [mode (. (api.nvim_get_mode) :mode)]
(set self.mode mode)))
:static {:mode-names {:n :NORMAL
:no :O-PENDING
:nov :O-PENDING
:noV :O-PENDING
"no\022" :O-PENDING
:niI :NORMAL
:niR :NORMAL
:niV :NORMAL
:nt :NORMAL
:v :VISUAL
:vs :VISUAL
:V :V-LINE
:Vs :V-LINE
"\022" :V-BLOCK
"\022s" :V-BLOCK
:s :SELECT
:S :S-LINE
"\019" :S-BLOCK
:i :INSERT
:ic :INSERT
:ix :INSERT
:R :REPLACE
:Rc :REPLACE
:Rx :REPLACE
:Rv :V-REPLACE
:Rvc :V-REPLACE
:Rvx :V-REPLACE
:c :COMMAND
:cv :EX
:ce :EX
:r :REPLACE
:rm :MORE
:r? :CONFIRM
:! :SHELL
:t :TERMINAL}
:mode-hl {:n {:fg colors.black
:bg colors.purple
:bold true}
:i {:fg colors.black
:bg colors.green
:bold true}
:v {:fg colors.black
: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
: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
(set mod.heirline.filetype-block
(set mod.filetype-block
{:init (fn [self]
(set self.filename (api.nvim_buf_get_name 0)))})
(set mod.heirline.file-icon
{:init (fn [self]
(let [filename self.filename
ext (vim.fn.fnamemodify filename ":e")
(icon color) (web-devicons.get_icon_color filename ext
{:default true})]
(set self.icon icon)
(set self.icon-color color)))
:provider (fn [self]
(when self.icon
(.. self.icon " ")))
:hl (fn [self]
{:fg self.icon-color})})
(set mod.heirline.filetype
{:provider (fn []
(let [ft vim.bo.filetype]
(if (> (ft:len) 0) ft "no ft")))
:hl {:fg colors.white}})
(set mod.heirline.filetype-block
(heirline-utils.insert mod.heirline.filetype-block
mod.heirline.file-icon mod.heirline.filetype))
(set mod.file-icon {:init (fn [self]
(let [filename self.filename
ext (vim.fn.fnamemodify filename ":e")
(icon color) (web-devicons.get_icon_color filename
ext
{:default true})]
(set self.icon icon)
(set self.icon-color color)))
:provider (fn [self]
(when self.icon
(.. self.icon " ")))
:hl (fn [self]
{:fg self.icon-color})})
(set mod.filetype {:provider (fn []
(let [ft vim.bo.filetype]
(if (> (ft:len) 0) ft "no ft")))
:hl {:fg colors.white}})
(set mod.filetype-block
(heirline-utils.insert mod.filetype-block mod.file-icon mod.filetype))
;; git
(set mod.heirline.git {:condition heirline-conditions.is_git_repo
:init (fn [self]
(let [git-status vim.b.gitsigns_status_dict]
(set self.git-head git-status.head)
(set self.git-added (or git-status.added 0))
(set self.git-removed
(or git-status.removed 0))
(set self.git-changed
(or git-status.changed 0))
(set self.has-changes?
(or (> self.git-added 0)
(> self.git-removed 0)
(> self.git-changed 0)))))
1 {:provider (fn [self]
(.. "  " self.git-head " "))
:hl {:fg colors.black :bg colors.orange :bold true}}
2 {:condition (fn [self]
self.has-changes?)
:provider " "}
3 {:provider (fn [self]
(let [spacer (if (or (> self.git-removed
0)
(> self.git-changed
0))
" " "")]
(when (> self.git-added 0)
(.. " " self.git-added spacer))))
:hl {:fg colors.bright_green}}
4 {:provider (fn [self]
(let [spacer (if (> self.git-changed 0)
" " "")]
(when (> self.git-removed 0)
(.. " " 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}}})
(set mod.git {:condition heirline-conditions.is_git_repo
:init (fn [self]
(let [git-status vim.b.gitsigns_status_dict]
(set self.git-head git-status.head)
(set self.git-added (or git-status.added 0))
(set self.git-removed (or git-status.removed 0))
(set self.git-changed (or git-status.changed 0))
(set self.has-changes?
(or (> self.git-added 0) (> self.git-removed 0)
(> self.git-changed 0)))))
1 {:provider (fn [self]
(.. "  " self.git-head " "))
:hl {:fg colors.black :bg colors.orange :bold true}}
2 {:condition (fn [self]
self.has-changes?)
:provider " "}
3 {:provider (fn [self]
(let [spacer (if (or (> self.git-removed 0)
(> self.git-changed 0))
" " "")]
(when (> self.git-added 0)
(.. " " self.git-added spacer))))
:hl {:fg colors.bright_green}}
4 {:provider (fn [self]
(let [spacer (if (> self.git-changed 0) " " "")]
(when (> self.git-removed 0)
(.. " " 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
(set mod.heirline.diagnostics
{:condition heirline-conditions.has_diagnostics
:init (fn [self]
(let [d vim.diagnostic]
(set self.errors
(length (d.get 0 {:severity d.severity.ERROR})))
(set self.warnings
(length (d.get 0 {:severity d.severity.WARN})))
(set self.info (length (d.get 0 {:severity d.severity.INFO})))
(set self.hints
(length (d.get 0 {:severity d.severity.HINT})))))
1 {:provider (fn [self]
(let [spacer (if (or (> self.warnings 0) (> self.info 0)
(> self.hints 0))
" " "")]
(when (> self.errors 0)
(.. " " self.errors spacer))))
:hl {:fg colors.red}}
2 {:provider (fn [self]
(let [spacer (if (or (> self.info 0) (> self.hints 0))
" " "")]
(when (> self.warnings 0)
(.. " " self.warnings spacer))))
:hl {:fg colors.yellow}}
3 {:provider (fn [self]
(let [spacer (if (> self.hints 0) " " "")]
(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}}})
(set mod.diagnostics {:condition heirline-conditions.has_diagnostics
:init (fn [self]
(let [d vim.diagnostic]
(set self.errors
(length (d.get 0
{:severity d.severity.ERROR})))
(set self.warnings
(length (d.get 0
{:severity d.severity.WARN})))
(set self.info
(length (d.get 0
{:severity d.severity.INFO})))
(set self.hints
(length (d.get 0
{:severity d.severity.HINT})))))
1 {:provider (fn [self]
(let [spacer (if (or (> self.warnings 0)
(> self.info 0)
(> self.hints 0))
" " "")]
(when (> self.errors 0)
(.. " " self.errors spacer))))
:hl {:fg colors.red}}
2 {:provider (fn [self]
(let [spacer (if (or (> self.info 0)
(> self.hints 0))
" " "")]
(when (> self.warnings 0)
(.. " " self.warnings spacer))))
:hl {:fg colors.yellow}}
3 {:provider (fn [self]
(let [spacer (if (> self.hints 0) " " "")]
(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
(set mod.heirline.current-function
(set mod.current-function
{:condition heirline-conditions.lsp_attached
:provider (fn []
(let [ctx vim.b.nifoc_lsp_current_context]
@ -188,62 +209,69 @@
ctx)))
:hl {:fg colors.white}})
;; Buffer Options
(set mod.heirline.buffer-options
{:init (fn [self]
(set self.has-options?
(or (buffer-variable-exists? :nifoc_lsp_enabled)
(buffer-variable-exists? :nifoc_treesitter_enabled)
vim.wo.spell)))
:hl {:fg colors.black :bg colors.orange}
1 {:condition (fn [self]
self.has-options?)
:provider " "}
2 {:provider (fn []
(when (buffer-variable-exists? :nifoc_lsp_enabled)
" "))}
3 {:provider (fn []
(when (or (buffer-variable-exists? :nifoc_lsp_formatter_enabled)
(not= (vim.opt_local.formatprg:get) ""))
" "))}
4 {:provider (fn []
(when (buffer-variable-exists? :nifoc_treesitter_enabled)
" "))}
5 {:provider (fn []
(when vim.wo.spell
"暈 "))}})
(set mod.buffer-options {:init (fn [self]
(set self.has-options?
(or (buffer-variable-exists? :nifoc_lsp_enabled)
(buffer-variable-exists? :nifoc_treesitter_enabled)
vim.wo.spell)))
:hl {:fg colors.black :bg colors.orange}
1 {:condition (fn [self]
self.has-options?)
:provider " "}
2 {:provider (fn []
(when (buffer-variable-exists? :nifoc_lsp_enabled)
" "))}
3 {:provider (fn []
(when (or (buffer-variable-exists? :nifoc_lsp_formatter_enabled)
(not= (vim.opt_local.formatprg:get)
""))
" "))}
4 {:provider (fn []
(when (buffer-variable-exists? :nifoc_treesitter_enabled)
" "))}
5 {:provider (fn []
(when vim.wo.spell
"暈"))}})
;; Position
(set mod.heirline.position {: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.heirline.scrollbar
(set mod.position
{:init (fn [self]
(set self.current-line (get-current-line))
(set self.total-lines (get-total-lines)))
:static {:scrollbar-icons ["🭶" "🭷" "🭸" "🭹" "🭺" "🭻"]}
(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]
(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}})
(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.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
(fn mod.heirline.custom-mode [str]
(fn mod.custom-mode [str fg bg]
{: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)

View file

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

View file

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

View file

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