Skip to content

Commit

Permalink
update: markdown.vim, hi.fnl, match.fnl, nmap.fnl, cmd.fnl, g.fnl, in…
Browse files Browse the repository at this point in the history
…it.fnl, init.fnl, plugs.fnl, hi.fnl, macros.fnl, init.lua, ime.lua, util.lua, map.lua, user.lua,
  • Loading branch information
Cassin01 committed Apr 7, 2024
1 parent 0b33399 commit 2cbb696
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 56 deletions.
3 changes: 3 additions & 0 deletions after/ftplugin/markdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ function! s:markdown_checkbox(from, to) abort
if lnum == curpos[1]
let curpos[2] += 6
endif
if expand('%f') ==# 'todo.md'
call append(line('.'), ' - CREATED: ' .. strftime('%Y-%m-%d'))
endif
elseif line =~ list_pattern .. '\[ \]\s+'
" blank box -> check
let line = substitute(line, '\[ \]', '[x]', '')
Expand Down
33 changes: 22 additions & 11 deletions fnl/core/au/hi.fnl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(import-macros {: def : when-let} :util.macros)
(local {: get-hl} (require :kaza.hi))
(local va vim.api)
(local vf vim.fn)

Expand All @@ -11,16 +12,16 @@
(def gen-hl [name tbl] [:string :table :table]
[name (link name tbl)])

(def get-hl [name part] [:string :string :?string]
"name: hlname
part: bg or fg"
(let [target (va.nvim_get_hl_by_name name 0)]
(if
(= part :fg)
(.. :# (vf.printf :%0x (. target :foreground)))
(= part :bg)
(.. :# (vf.printf :%0x (. target :background)))
nil)))
; (def get-hl [name part] [:string :string :?string]
; "name: hlname
; part: bg or fg"
; (let [target (va.nvim_get_hl_by_name name 0)]
; (if
; (= part :fg)
; (.. :# (vf.printf :%0x (. target :foreground)))
; (= part :bg)
; (.. :# (vf.printf :%0x (. target :background)))
; nil)))

(macro add-hl [name tbl]
`(table.insert hl-info (gen-hl ,name ,tbl)))
Expand All @@ -31,7 +32,17 @@
(add-hl :SpecialKey {:bg nil :italic true})
(when-let bg (get-hl :Normal :bg)
(add-hl :StatusLine {:fg bg})
(add-hl :StatusLineNC {:fg bg}))
(add-hl :StatusLineNC {:fg bg})
(add-hl :WinBar {:bg bg})
(add-hl :WinBarNC {:bg bg}))
; (when-let fg (get-hl :Comment :fg)
; ; For plugin: bufferline
; (local cs (vim.api.nvim_get_hl 0 {}))
; (print (vim.inspect cs))
; (each [hi-name _ (pairs cs)]
; (when (not= (hi-name:match "^BufferLineDevIcon.*Inactive$") nil)
; (add-hl hi-name {:fg fg})))
; )
hl-info)

;;; INFO
Expand Down
4 changes: 3 additions & 1 deletion fnl/core/au/match.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
(each [ft matches (pairs fts)]
(when (= ft vim.bo.filetype)
(each [_ m (ipairs matches)]
(vf.matchadd (unpack m))))))))
(vf.matchadd (unpack m)))))
(when (= (vim.fn.expand :%f) "todo.md")
(vf.matchadd :Comment "CREATED: \\d\\d\\d\\d-\\d\\d-\\d\\d")))))

{: add-matches}
3 changes: 3 additions & 0 deletions fnl/core/map/nmap.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"replace `.` and `,`"]
[:a ":vim TODO ~/org/*.org<cr>" "agenda"]
[:ts ":%s/\t/ /g<cr>" "replace tab with space"]
[:t2s ":%s/\t/ /g<cr>" "replace tab with 2 spaces"]
[:tm (la
(local a (require :async))
(local co coroutine)
Expand Down Expand Up @@ -135,6 +136,8 @@
(bufferline))) :clear-bufferlne]
[:fn (la (print (vim.fn.expand :%:t))) "show file name"]
[:fp (la (print (vim.fn.expand :%:p))) "show file path"]
[:fft (la (vim.cmd "echo &filetype")) "show file type"]
[:fr ":<c-u>e %<cr>" "reload the file"]
[:ft (la (if (= vim.o.foldmethod :indent)
(tset vim.o :foldmethod :marker)
(tset vim.o :foldmethod :indent))
Expand Down
2 changes: 1 addition & 1 deletion fnl/core/opt/cmd.fnl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[
"lang en_US.UTf-8"
;"lang en_US.UTf-8"
"filetype plugin indent on"
"syntax on"
"set clipboard+=unnamed"
Expand Down
3 changes: 2 additions & 1 deletion fnl/core/opt/g.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
; :colors_name :kanagawa
; :colors_name :habamax
; :colors_name :tokyonight-night
:colors_name :catppuccin-mocha
; :colors_name :catppuccin-mocha
:colors_name :fluoromachine
:markdown_fenced_languages [:python :ruby :javascript :js=javascript
:json=javascript :vim :css :ocaml
:rust
Expand Down
2 changes: 1 addition & 1 deletion fnl/core/opt/init.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
:vertleft " "
:vertright " "
:verthoriz " "
:horiz " "
;:horiz " "
:horizup " "
:horizdown " "
:eob " "})
Expand Down
4 changes: 2 additions & 2 deletions fnl/core/pack/init.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
(timeout 200
(lambda []
(vim.cmd "doautocmd User plug-lazy-load")
; (require :user)
;(require :user)
(require :ime)
(require :map)
; (lplug :bracket.vim)
(lplug :command.vim)
(lplug :hyper_witch.vim)
; (lplug :hyper_witch.vim)
(lplug :terminal.vim)))

57 changes: 39 additions & 18 deletions fnl/core/pack/plugs.fnl
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
(import-macros {: req-f : ref-f : epi : ep : when-let} :util.macros)
(import-macros {: nmaps : map : cmd : plug : space : ui-ignore-filetype : la : br : let-g : au!} :kaza.macros)
; (import-macros {: nmaps : map : cmd : plug : space : ui-ignore-filetype : la : br : let-g : au!} :kaza.macros)
(import-macros { : map : cmd : plug : space : ui-ignore-filetype : la : br : let-g : au!} :kaza.macros)

(macro lcnf [file_name]
`(vim.cmd (table.concat ["source ~/.config/nvim/after_opt/" ,file_name ] "")))

(local myutil (require :lua.util))
(local nmaps myutil.nmaps)


[
;;; snippet

Expand Down Expand Up @@ -46,17 +51,17 @@
:opt true
:event ["User plug-lazy-load"]
:requires [:lambdalisue/fern-git-status.vim
{1 :lambdalisue/fern-renderer-devicons.vim
:requires [:ryanoasis/vim-devicons]}
{1 :lambdalisue/fern-renderer-nerdfont.vim
:dependencies [:lambdalisue/nerdfont.vim]}
:yuki-yano/fern-preview.vim]
:config (λ []
(tset vim.g :fern#renderer :devicons)
(tset vim.g :fern_renderer_devicons_disable_warning true)
(tset vim.g :fern#renderer :nerdfont)
; (tset vim.g :fern_renderer_devicons_disable_warning true)
(lcnf "fern.vim")
(nmaps
:<Space>n
:fern
[[:p (cmd "Fern . -drawer -toggle") "open fern on a current working drectory"]
[[:p (cmd "Fern . -drawer -toggle") "open fern on a current working directory"]
[:d (cmd "Fern %:h -drawer -toggle") "open fern on a parent directory of a current buffer"]])
)}

Expand Down Expand Up @@ -211,7 +216,8 @@

{1 :Cassin01/wf.nvim
:event ["User plug-lazy-load"]
:branch :update
:branch :develop
; :branch :new_feat
; :tag :update
:config (la (ref-f :setup :wf {:theme :chad})
(require :user))}
Expand Down Expand Up @@ -456,7 +462,7 @@
{1 :hrsh7th/cmp-cmdline :after :nvim-cmp}
{1 :hrsh7th/cmp-calc :after :nvim-cmp}
{1 :hrsh7th/cmp-nvim-lsp-document-symbol :after :nvim-cmp}
{1 :kdheepak/cmp-latex-symbols}
; {1 :kdheepak/cmp-latex-symbols}
{1 :saadparwaiz1/cmp_luasnip :after [:nvim-cmp :LuaSnip]}
; :nvim-orgmode/orgmode
{1 :uga-rosa/cmp-dictionary
Expand Down Expand Up @@ -540,8 +546,8 @@
{:name :ultisnips :group_index 2}
; {:name :orgmode}
{:name :lsp_document_symbol}
{:name :latex_symbols
:option {:strategy 0}}
; {:name :latex_symbols
; :option {:strategy 0}}
; {:name :skkeleton :group_index 5}
{:name :buffer
:option {:get_bufnrs (λ []
Expand Down Expand Up @@ -605,7 +611,7 @@
:<c-e> (cmp.mapping.abort)
:<c-p> (cmp.mapping.select_prev_item)
:<c-n> (cmp.mapping.select_next_item)
:<cr> (cmp.mapping.confirm {:select true}) }) })
:<cr> (cmp.mapping.confirm {:select false}) }) })
(vim.api.nvim_set_hl 0 :CmpItemKindCopilot {:fg :#6CC644})
(cmp.setup.cmdline :/ {:mapping (cmp.mapping.preset.cmdline)
:sources [{:name :buffer}]})
Expand Down Expand Up @@ -743,13 +749,13 @@
))}
{1 :tpope/vim-rhubarb :event ["User plug-lazy-load"]} ; enable :Gbrowse
{1 :tpope/vim-commentary :event ["User plug-lazy-load"]}
{1 :LudoPinelli/comment-box.nvim
:config (lambda []
(local cb (require :comment-box))
(nmaps :<Space>o :comment-box
[[:c cb.accbox "accbox"]
[:b cb.lbox "lbox"]
[:l cb.cline "cline"] ])) }
; {1 :LudoPinelli/comment-box.nvim
; :config (lambda []
; (local cb (require :comment-box))
; (nmaps :<Space>o :comment-box
; [[:c cb.accbox "accbox"]
; [:b cb.lbox "lbox"]
; [:l cb.cline "cline"] ])) }
{1 :tpope/vim-unimpaired :event ["User plug-lazy-load"]}
{1 :tpope/vim-surround :event ["User plug-lazy-load"]}
{1 :tpope/vim-abolish :event ["User plug-lazy-load"]}
Expand Down Expand Up @@ -911,6 +917,16 @@
(tset vim.g :translate_target :ja)
(tset vim.g :translate_popup_window false)
(tset vim.g :translate_winsize 10)
(vim.keymap.set :n :<space>kj
(lambda []
(tset vim.g :translate_source :en)
(tset vim.g :translate_target :ja))
{:desc "[translate] en2jp"})
(vim.keymap.set :n :<space>ke
(lambda []
(tset vim.g :translate_source :ja)
(tset vim.g :translate_target :en))
{:desc "[translate] jp2en"})
(vim.cmd "nnoremap gr <Plug>(Translate)")
(vim.cmd "vnoremap <c-t> :Translate<cr>"))}

Expand All @@ -934,6 +950,8 @@
{1 :ThePrimeagen/vim-apm
:event ["User plug-lazy-load"]}

:echasnovski/mini.nvim

;;; language

;; sche
Expand Down Expand Up @@ -1011,6 +1029,9 @@
(let [prefix ((. (require :kaza.map) :prefix-o) :n :<Space>a :auto-collect)]
(prefix.map "e" "<cmd>EnableAutocorrect<cr>" "enable auto correct")))}

;; html
:mattn/emmet-vim

; ;; tailwind
; {1 :mrshmllow/document-color.nvim
; :config (λ []
Expand Down
14 changes: 13 additions & 1 deletion fnl/kaza/hi.fnl
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
(import-macros {: def} :util.macros)
(local {: concat-with} (require :util.string))

(def get-hl [name part] [:string :string :?string]
"name: hlname
part: bg or fg"
(let [target (vim.api.nvim_get_hl_by_name name 0)]
(if
(= part :fg)
(.. :# (vim.fn.printf :%0x (. target :foreground)))
(= part :bg)
(.. :# (vim.fn.printf :%0x (. target :background)))
nil)))

(fn hi-clear [group-name]
"clear highlight"
(assert (-> (type group-name) (= :string)))
(let [cmd (concat-with " " :hi :clear group-name)]
(vim.cmd cmd)))

{: hi-clear}
{: hi-clear : get-hl}
2 changes: 1 addition & 1 deletion fnl/kaza/macros.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

;;; autocmd
(fn _group_handler [group]
`(if
`(if
(= (type ,group) :string)
(vim.api.nvim_create_augroup ,group {:clear true})
(= (type ,group) :number)
Expand Down
3 changes: 2 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ require("setup")
-- vim.cmd([[colorscheme tokyonight]])
-- vim.cmd([[colorscheme lunaperche]])
-- vim.cmd([[colorscheme nord]])
vim.cmd([[colorscheme nova]])
-- vim.cmd([[colorscheme nova]])
vim.cmd([[colorscheme fluoromachine]])

-- vim.cmd([[set background=light]])
-- vim.cmd([[colorscheme morning]])
2 changes: 1 addition & 1 deletion lua/ime.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local toggle = false
local toggle = true
local external_ime_control = true

if vim.fn.has("mac") == 0 then
Expand Down
16 changes: 16 additions & 0 deletions lua/lua/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,20 @@ function M.findc(str, c)
end
end

function M.nmaps(prefix, group, tbl)
local sign = "[" .. group .. "]"
-- table.insert(_G.__key_prefixes["n"], prefix, sign)
-- table.insert(_G["__kaza"]["prefix"], prefix, sign)
_G["__kaza"]["prefix"][prefix] = sign
local set = function(key, cmd, desc, opt)
local _opt = opt or {}
_opt["desc"] = sign .. " " .. desc
_opt["noremap"] = true
vim.keymap.set("n", prefix .. key, cmd, _opt)
end
for _, v in ipairs(tbl) do
set(unpack(v))
end
end

return M
31 changes: 27 additions & 4 deletions lua/map.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ table.insert(
return "{}<Left><CR><ESC>O" .. string.rep("<Space>", vim.bo.shiftwidth)
end,
},
{
prefix = "c;",
ret = function()
local header = string.format(vim.opt_local.commentstring["_value"], " {{{ ")
local footer = string.format(vim.opt_local.commentstring["_value"], " }}} ")
return header .. footer .. string.rep("<Left>", string.len(footer)) .. "<CR><ESC>O" .. string.rep("<Space>", vim.bo.shiftwidth)
end
},
})
)
table.insert(
Expand Down Expand Up @@ -246,8 +254,8 @@ local function match_back(str, patt)
return string.sub(str, string.len(patt) * -1, -1) == patt
end

for _, m in ipairs(maps) do
vim.keymap.set("i", m.striker, function()
local core = function(m)
return function()
local prefix = vim.fn.getline("."):sub(1, vim.fn.col(".") - 1)
local max_len = -1
local cont
Expand All @@ -256,7 +264,7 @@ for _, m in ipairs(maps) do
if string.len(a.prefix) > max_len then
cont = function()
return string.rep("<BS>", string.len(a.prefix))
.. (type(a.ret) == "function" and a.ret() or a.ret)
.. (type(a.ret) == "function" and a.ret() or a.ret)
end
max_len = string.len(a.prefix)
end
Expand All @@ -266,5 +274,20 @@ for _, m in ipairs(maps) do
return cont()
end
return m.striker
end, { noremap = true, silent = true, expr = true })
end
end

for _, m in ipairs(maps) do
vim.keymap.set("i", m.striker, core(m), { noremap = true, silent = true, expr = true })
end

-- vim.api.nvim_create_autocmd(
-- {"BufRead", "BufNewFile"},
-- {
-- callback = function ()
-- vim.key
-- end,
-- pattern = {".html"},
-- group = create_augroup("specific_stiker", {clear = true})
-- }
-- )
Loading

0 comments on commit 2cbb696

Please sign in to comment.