From 514c905eae8edef22ed7b92f981bdaeaf71b1ef8 Mon Sep 17 00:00:00 2001 From: Mike Vink Date: Mon, 8 Jan 2024 17:47:39 +0100 Subject: some new stuff --- mut/bin/window | 11 +++ mut/neovim/fnl/conf/events.fnl | 12 ++-- mut/neovim/fnl/conf/init.fnl | 126 ++++++++++++++++++--------------- mut/neovim/fnl/conf/pkgs.fnl | 1 + mut/neovim/fnl/conf/pkgs/lint.fnl | 6 ++ mut/neovim/fnl/conf/pkgs/lspconfig.fnl | 16 +---- 6 files changed, 93 insertions(+), 79 deletions(-) create mode 100755 mut/bin/window create mode 100644 mut/neovim/fnl/conf/pkgs/lint.fnl (limited to 'mut') diff --git a/mut/bin/window b/mut/bin/window new file mode 100755 index 0000000..bd40a4c --- /dev/null +++ b/mut/bin/window @@ -0,0 +1,11 @@ +#!/bin/sh +PIPE=/tmp/window-fifo +STDIN="$(cat -)" +rm $PIPE +mkfifo $PIPE +echo "$STDIN" | tee $PIPE >/dev/null & +if command -v st >/dev/null; then + st -e sh -c "<$PIPE ${*}" & +else + tmux splitw sh -c "<$PIPE ${*}" & +fi diff --git a/mut/neovim/fnl/conf/events.fnl b/mut/neovim/fnl/conf/events.fnl index f48f1b9..18d602e 100644 --- a/mut/neovim/fnl/conf/events.fnl +++ b/mut/neovim/fnl/conf/events.fnl @@ -19,12 +19,6 @@ :pattern ["ZoxideDirChanged"] :callback #(vim.schedule #(oil.open (vim.fn.getcwd)))}) -(event - :BufWritePost - {:group "conf#events" - :pattern ["*.rs"] - :callback #(vim.cmd (.. "Compile! rustfmt " (vim.fn.expand "%")))}) - (event :BufReadPost {:pattern ["*"] @@ -35,6 +29,12 @@ (vim.cmd "hi link TrailingWhitespace IncSearch")) :group "conf#events"}) +(event + :BufWritePost + {:group "conf#events" + :callback #(do (local lint (require :lint)) (lint.try_lint) (vim.diagnostic.setloclist))}) + + (local session-file (.. vim.env.HOME "/.vimsession.vim")) (event :VimLeave diff --git a/mut/neovim/fnl/conf/init.fnl b/mut/neovim/fnl/conf/init.fnl index 2c0adfb..55b24b5 100644 --- a/mut/neovim/fnl/conf/init.fnl +++ b/mut/neovim/fnl/conf/init.fnl @@ -30,12 +30,12 @@ (map :n :q ":cclose") (map :n :ll ":lopen") (map :n :l ":lclose") - (map :n : ":cprev") - (map :n : ":cprev") - (map :n : ":cnext") + (map :n "" cope) + (map :n "" ":cnext") + (map :n "" ":cprev") + (map :n : ":Recompile") (map :n : #(do - (vim.fn.setreg "/" "Compile") (vim.api.nvim_feedkeys (vim.api.nvim_replace_termcodes ":Compile" true false true) @@ -44,7 +44,6 @@ (vim.cmd "let v:searchforward = 0") (map :n :/ "/Compile.* " {:buffer true}) (map :n :? "?Compile.* " {:buffer true}))))) - (map :n : ":Recompile") (map :n "[q" ":cprevious") (map :n "]q" ":cnext") (map :n "[x" ":lprevious") @@ -52,6 +51,8 @@ (map :n : #(fzf.files)) (map :n :xp #(fzf.files)) (map :n ";" ":silent grep ") + (map :n "'" ":silent args `fd `") + (map :n :xa #(fzf.args)) (map :n :xb #(fzf.buffers {:keymap {:fzf {"ctrl-a" "select-all" "alt-a" "deselect-all"}} @@ -71,10 +72,6 @@ (local qf (fn [{: id : title}] (fn [lines] - (local fname (fn [e] - (if (not= 0 e.bufnr) - (vim.fn.bufname (. e :bufnr)) - ""))) (local s (fn [line pattern] (let [(result n) (line:gsub pattern "")] (match n @@ -82,63 +79,65 @@ _ result)))) (local prettify #(-> $1 (s "%c+%[[0-9:;<=>?]*[!\"#$%%&'()*+,-./]*[@A-Z%[%]^_`a-z{|}~]*;?[A-Z]?"))) - (local pos (fn [e] (if (not= 0 e.lnum) - (.. e.lnum " col " e.col) - ""))) - (local format (fn [e] (accumulate [l "" - _ word - (ipairs [(fname e) "|" (pos e) "| " e.text])] - (.. l word)))) - (local lines (icollect [_ l (ipairs lines)] - (if (not= l "") - (prettify l)))) - (local is-at-last-line (let [[n lnum & rest] (vim.fn.getcurpos) - last-line (vim.api.nvim_buf_line_count 0)] - (do - (= lnum last-line)))) - (local is-qf (= (vim.opt_local.buftype:get) "quickfix")) - (vim.fn.setqflist [] :a {: id : title : lines}) - (if (or - (not is-qf) - (and is-at-last-line is-qf)) - (vim.cmd ":cbottom"))))) + (vim.schedule + #(do + (vim.fn.setqflist + [] :a + {: id : title + :lines + (icollect [l lines] + (do + (if (not= l "") + (prettify l))))}) + (local is-qf (= (vim.opt_local.buftype:get) "quickfix")) + (local is-at-last-line (let [[row col] (vim.api.nvim_win_get_cursor 0) + last-line (vim.api.nvim_buf_line_count 0)] + (do + (= row last-line)))) + (if (or + (not is-qf) + (and is-at-last-line is-qf)) + (vim.cmd ":cbottom"))))))) (var last_job nil) -(local job +(local qfjob (fn [cmd] - (local title cmd) + (local title (table.concat cmd " ")) (vim.fn.setqflist [] " " {: title}) (local add2qf (qf (vim.fn.getqflist {:id 0 :title 1}))) - (local id - (vim.fn.jobstart - cmd - {:on_stdout (fn [id data] - (if data - (add2qf data))) - :on_stderr (fn [id data] - (if data - (add2qf data))) - :on_exit (fn [id rc] - (set last_job.finished true) - (set winnr (vim.fn.winnr)) - (if (not= rc 0) - (do - (cope) - (if (not= (vim.fn.winnr) winnr) - (do - (vim.notify "going back") - (vim.cmd "wincmd p | cbot")))) - (vim.notify (.. "\"" cmd "\" succeeded!"))))})) (set last_job - {: cmd - : id - :finished false}))) + (vim.system + cmd + {:stdout (fn [err data] + (if data + (add2qf (string.gmatch data "[^\n]+")))) + :stderr (fn [err data] + (if data + (add2qf (string.gmatch data "[^\n]+"))))} + (fn [obj] + (vim.schedule + #(do + (set winnr (vim.fn.winnr)) + (if (not= obj.code 0) + (do + (cope) + (if (not= (vim.fn.winnr) winnr) + (do + (vim.notify (.. title " failed, going back")) + (vim.cmd "wincmd p | cbot")) + (vim.notify (.. title "failed, going back")))) + (vim.notify (.. "\"" title "\" succeeded!")))))))))) (vim.api.nvim_create_user_command :Compile (fn [cmd] - (job cmd.args)) + (qfjob cmd.fargs)) + {:nargs :* :bang true :complete :shellcmd}) +(vim.api.nvim_create_user_command + :Sh + (fn [cmd] + (qfjob [:sh :-c cmd.args])) {:nargs :* :bang true :complete :shellcmd}) (vim.api.nvim_create_user_command :Recompile @@ -147,12 +146,21 @@ (vim.notify "nothing to recompile") (if (not last_job.finished) (vim.notify "Last job not finished") - (job last_job.cmd)))) + (qfjob last_job.cmd)))) {:bang true}) (vim.api.nvim_create_user_command - :Abort + :Stop (fn [] (if (not= nil last_job) - (vim.fn.jobstop last_job.id)) - (vim.notify "killed job")) + (last_job:kill)) + (vim.notify "stopped job")) {:bang true}) +(vim.api.nvim_create_user_command + :Args + (fn [obj] + (if (not= 0 (length obj.fargs)) + (vim.system + [:sh :-c obj.args] + {:stdin (vim.fn.argv)} + (fn [job] (vim.schedule #(if (not= job.code 0) (vim.notify (.. "Args " obj.args " failed")))))))) + {:nargs :* :bang true :complete :shellcmd}) diff --git a/mut/neovim/fnl/conf/pkgs.fnl b/mut/neovim/fnl/conf/pkgs.fnl index 37ebc52..c48b40d 100644 --- a/mut/neovim/fnl/conf/pkgs.fnl +++ b/mut/neovim/fnl/conf/pkgs.fnl @@ -5,5 +5,6 @@ (require :conf.pkgs.venn) (require :conf.pkgs.gitsigns) (require :conf.pkgs.oil) +(require :conf.pkgs.lint) ;; (require :conf.pkgs.lsp_lines) ;; (require :conf.pkgs.null-ls) diff --git a/mut/neovim/fnl/conf/pkgs/lint.fnl b/mut/neovim/fnl/conf/pkgs/lint.fnl new file mode 100644 index 0000000..3125103 --- /dev/null +++ b/mut/neovim/fnl/conf/pkgs/lint.fnl @@ -0,0 +1,6 @@ +(local lint (require :lint)) +(set + lint.linters_by_ft + {:markdown [:vale] + :sh [:shellcheck]}) + diff --git a/mut/neovim/fnl/conf/pkgs/lspconfig.fnl b/mut/neovim/fnl/conf/pkgs/lspconfig.fnl index 0a463ad..98dda2c 100644 --- a/mut/neovim/fnl/conf/pkgs/lspconfig.fnl +++ b/mut/neovim/fnl/conf/pkgs/lspconfig.fnl @@ -1,6 +1,8 @@ (local lspconfig (require :lspconfig)) (local configs (require :lspconfig.configs)) +(lspconfig.nil_ls.setup {}) + (lspconfig.rust_analyzer.setup {:autostart false :settings @@ -42,17 +44,3 @@ :lint {:enabled false :arguments " --profile=production --write=all " :path :ansible-lint}}}}) - -;; (tset configs :fennel_language_server -;; {:default_config {;; replace it with true path -;; :cmd [:fennel-language-server] -;; :filetypes [:fennel] -;; :single_file_support true -;; ;; source code resides in directory `fnl/` -;; :root_dir (lspconfig.util.root_pattern :fnl) -;; :settings {:fennel {:workspace {;; If you are using hotpot.nvim or aniseed, -;; ;; make the server aware of neovim runtime files. -;; :library (vim.api.nvim_list_runtime_paths)} -;; :diagnostics {:globals [:vim]}}}}}) -;; -;; (lspconfig.fennel_language_server.setup {:on_attach attach}) -- cgit v1.2.3