mirror of
https://github.com/stevenproctor/dotfiles.git
synced 2026-01-28 15:59:56 -06:00
Fancy Header stars in org files
This commit is contained in:
@@ -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}))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
12
nvim/.config/nvim/fnl/dotfiles/ts-utils.fnl
Normal file
12
nvim/.config/nvim/fnl/dotfiles/ts-utils.fnl
Normal file
@@ -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))))
|
||||
Reference in New Issue
Block a user