diff --git a/nvim/.config/nvim/fnl/dotfiles/plugin/orgbullets.fnl b/nvim/.config/nvim/fnl/dotfiles/plugin/orgbullets.fnl index ab767ed..ff5e499 100644 --- a/nvim/.config/nvim/fnl/dotfiles/plugin/orgbullets.fnl +++ b/nvim/.config/nvim/fnl/dotfiles/plugin/orgbullets.fnl @@ -1,3 +1,47 @@ (module dotfiles.plugin.orgbullets - {autoload {org-bullets org-bullets}}) + {autoload {nvim aniseed.nvim a aniseed.core ts-utils dotfiles.ts-utils}}) +(def stars ["◉" "⦾" "○" "✸" "✿" "✶" "•" "‣"]) + +(def stars-query "(headline (stars) @stars)") + +(defn star-index [heading-level] + (let [star-count (a.count stars) + idx (math.fmod heading-level star-count)] + (if (< 0 idx) + idx + star-count))) + +(defonce extmark-namespace (vim.api.nvim_create_namespace :HeaderStars)) + +(def star-captures (ts-utils.make-query :org stars-query)) + +(defn gen-star-extmarks [] + (when (= :org vim.bo.filetype) + (let [bufnr (vim.api.nvim_get_current_buf) + star-count (a.count stars)] + (vim.api.nvim_buf_clear_namespace bufnr extmark-namespace 0 -1) + (each [id node metadata (star-captures bufnr)] + (let [[start-line start-col end-row end-col] [(node:range)] + heading-level (if (= start-line end-row) + (- end-col start-col)) + star (a.get stars (star-index heading-level)) + replacement (string.format (a.str "%" (+ 2 heading-level) :s) + star)] + (vim.api.nvim_buf_set_extmark bufnr extmark-namespace start-line + start-col + {:end_col end-col + :end_row end-row + :virt_text [[replacement []]] + :virt_text_pos :overlay + :hl_mode :combine})))))) + +(let [group (nvim.create_augroup :HeaderStars {:clear true})] + (nvim.create_autocmd [:FileChangedShellPost + :Syntax + :TextChanged + :InsertLeave + :WinScrolled] + {: group + ;; :pattern [:*.org] + :callback gen-star-extmarks})) diff --git a/nvim/.config/nvim/fnl/dotfiles/plugin/orgmode.fnl b/nvim/.config/nvim/fnl/dotfiles/plugin/orgmode.fnl index af4d803..64d0593 100644 --- a/nvim/.config/nvim/fnl/dotfiles/plugin/orgmode.fnl +++ b/nvim/.config/nvim/fnl/dotfiles/plugin/orgmode.fnl @@ -1,8 +1,8 @@ -(module dotfiles.plugin.orgmode - {autoload {orgmode orgmode}}) +(module dotfiles.plugin.orgmode {autoload {orgmode orgmode}}) (orgmode.setup_ts_grammar) -(orgmode.setup - {:org_agenda_files ["~/Dropbox/org/*" "~/my-orgs/**/*"] - :org_default_notes_file "~/Dropbox/org/refile.org" }) +(orgmode.setup {:org_agenda_files ["~/Dropbox/org/*" "~/my-orgs/**/*"] + :org_default_notes_file "~/Dropbox/org/refile.org"}) + +(require :dotfiles.plugin.orgbullets) diff --git a/nvim/.config/nvim/fnl/dotfiles/plugins.fnl b/nvim/.config/nvim/fnl/dotfiles/plugins.fnl index ddc1340..8f374b9 100644 --- a/nvim/.config/nvim/fnl/dotfiles/plugins.fnl +++ b/nvim/.config/nvim/fnl/dotfiles/plugins.fnl @@ -22,7 +22,6 @@ :Olical/conjure {:mod :conjure} :Olical/fennel.vim {} :airblade/vim-gitgutter {} - :akinsho/org-bullets.nvim {:mod :orgbullets} :clojure-vim/vim-jack-in {} :dhruvasagar/vim-table-mode {} :folke/lsp-colors.nvim {} diff --git a/nvim/.config/nvim/fnl/dotfiles/ts-utils.fnl b/nvim/.config/nvim/fnl/dotfiles/ts-utils.fnl new file mode 100644 index 0000000..66cd489 --- /dev/null +++ b/nvim/.config/nvim/fnl/dotfiles/ts-utils.fnl @@ -0,0 +1,12 @@ +(module dotfiles.ts-utils {autoload {nvim aniseed.nvim a aniseed.core}}) + +(defn root [bufnr lang] (let [parser (vim.treesitter.get_parser bufnr lang {}) + tree (a.first (: parser :parse))] + (: tree :root))) + +(defn make-query [lang query-string] + (let [query (vim.treesitter.parse_query lang "(headline (stars) @stars)")] + (fn [bufnr] + (let [root-node (root bufnr lang) + iter-captures (query.iter_captures query root-node bufnr 0 -1)] + iter-captures))))