mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2025-12-31 22:04:24 -05:00
implement #30 set filetype=telekasten
This commit is contained in:
77
ftplugin/telekasten.vim
Normal file
77
ftplugin/telekasten.vim
Normal file
@@ -0,0 +1,77 @@
|
||||
" Vim filetype plugin
|
||||
" Language: Markdown
|
||||
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
|
||||
" Last Change: 2019 Dec 05
|
||||
|
||||
" telekasten.nvim essentially deals with markdown, so we have to offer the
|
||||
" same
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
finish
|
||||
endif
|
||||
|
||||
runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
|
||||
|
||||
setlocal comments=fb:*,fb:-,fb:+,n:> commentstring=<!--%s-->
|
||||
setlocal formatoptions+=tcqln formatoptions-=r formatoptions-=o
|
||||
setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^[-*+]\\s\\+\\\|^\\[^\\ze[^\\]]\\+\\]:
|
||||
|
||||
if exists('b:undo_ftplugin')
|
||||
let b:undo_ftplugin .= "|setl cms< com< fo< flp<"
|
||||
else
|
||||
let b:undo_ftplugin = "setl cms< com< fo< flp<"
|
||||
endif
|
||||
|
||||
function! s:NotCodeBlock(lnum) abort
|
||||
return synIDattr(synID(v:lnum, 1, 1), 'name') !=# 'markdownCode'
|
||||
endfunction
|
||||
|
||||
function! MarkdownFold() abort
|
||||
let line = getline(v:lnum)
|
||||
|
||||
if line =~# '^#\+ ' && s:NotCodeBlock(v:lnum)
|
||||
return ">" . match(line, ' ')
|
||||
endif
|
||||
|
||||
let nextline = getline(v:lnum + 1)
|
||||
if (line =~ '^.\+$') && (nextline =~ '^=\+$') && s:NotCodeBlock(v:lnum + 1)
|
||||
return ">1"
|
||||
endif
|
||||
|
||||
if (line =~ '^.\+$') && (nextline =~ '^-\+$') && s:NotCodeBlock(v:lnum + 1)
|
||||
return ">2"
|
||||
endif
|
||||
|
||||
return "="
|
||||
endfunction
|
||||
|
||||
function! s:HashIndent(lnum) abort
|
||||
let hash_header = matchstr(getline(a:lnum), '^#\{1,6}')
|
||||
if len(hash_header)
|
||||
return hash_header
|
||||
else
|
||||
let nextline = getline(a:lnum + 1)
|
||||
if nextline =~# '^=\+\s*$'
|
||||
return '#'
|
||||
elseif nextline =~# '^-\+\s*$'
|
||||
return '##'
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! MarkdownFoldText() abort
|
||||
let hash_indent = s:HashIndent(v:foldstart)
|
||||
let title = substitute(getline(v:foldstart), '^#\+\s*', '', '')
|
||||
let foldsize = (v:foldend - v:foldstart + 1)
|
||||
let linecount = '['.foldsize.' lines]'
|
||||
return hash_indent.' '.title.' '.linecount
|
||||
endfunction
|
||||
|
||||
if has("folding") && exists("g:markdown_folding")
|
||||
setlocal foldexpr=MarkdownFold()
|
||||
setlocal foldmethod=expr
|
||||
setlocal foldtext=MarkdownFoldText()
|
||||
let b:undo_ftplugin .= " foldexpr< foldmethod< foldtext<"
|
||||
endif
|
||||
|
||||
" vim:set sw=2:
|
||||
@@ -1,6 +1,7 @@
|
||||
local builtin = require("telescope.builtin")
|
||||
local actions = require("telescope.actions")
|
||||
local action_state = require("telescope.actions.state")
|
||||
local action_set = require("telescope.actions.set")
|
||||
local pickers = require("telescope.pickers")
|
||||
local finders = require("telescope.finders")
|
||||
local conf = require("telescope.config").values
|
||||
@@ -64,9 +65,6 @@ M.Cfg = {
|
||||
close_after_yanking = false,
|
||||
insert_after_inserting = true,
|
||||
|
||||
-- make syntax available to markdown buffers and telescope previewers
|
||||
install_syntax = true,
|
||||
|
||||
-- tag notation: '#tag', ':tag:', 'yaml-bare'
|
||||
tag_notation = "#tag",
|
||||
|
||||
@@ -342,6 +340,9 @@ local media_preview = defaulter(function(opts)
|
||||
})
|
||||
end, {})
|
||||
|
||||
-- note picker actions
|
||||
local picker_actions = {}
|
||||
|
||||
-- find_files_sorted(opts)
|
||||
-- like builtin.find_files, but:
|
||||
-- - uses plenary.scan_dir synchronously instead of external jobs
|
||||
@@ -404,6 +405,11 @@ local function find_files_sorted(opts)
|
||||
previewer = media_preview.new(opts)
|
||||
end
|
||||
|
||||
opts.attach_mappings = opts.attach_mappings
|
||||
or function(prompt_bufnr, _)
|
||||
actions.select_default:replace(picker_actions.select_default)
|
||||
end
|
||||
|
||||
local picker = pickers.new(opts, {
|
||||
finder = finders.new_table({
|
||||
results = file_list,
|
||||
@@ -436,8 +442,15 @@ local function find_files_sorted(opts)
|
||||
picker:find()
|
||||
end
|
||||
|
||||
-- note picker actions
|
||||
local picker_actions = {}
|
||||
picker_actions.post_open = function()
|
||||
vim.cmd("set ft=telekasten")
|
||||
end
|
||||
|
||||
picker_actions.select_default = function(prompt_bufnr)
|
||||
local ret = action_set.select(prompt_bufnr, "default")
|
||||
picker_actions.post_open()
|
||||
return ret
|
||||
end
|
||||
|
||||
function picker_actions.close(opts)
|
||||
opts = opts or {}
|
||||
@@ -540,6 +553,7 @@ local function FindDailyNotes(opts)
|
||||
cwd = M.Cfg.dailies,
|
||||
find_command = M.Cfg.find_command,
|
||||
attach_mappings = function(_, map)
|
||||
actions.select_default:replace(picker_actions.select_default)
|
||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||
@@ -584,6 +598,7 @@ local function FindWeeklyNotes(opts)
|
||||
cwd = M.Cfg.weeklies,
|
||||
find_command = M.Cfg.find_command,
|
||||
attach_mappings = function(_, map)
|
||||
actions.select_default:replace(picker_actions.select_default)
|
||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||
@@ -762,6 +777,7 @@ local function FollowLink(opts)
|
||||
default_text = title,
|
||||
find_command = M.Cfg.find_command,
|
||||
attach_mappings = function(_, map)
|
||||
actions.select_default:replace(picker_actions.select_default)
|
||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||
@@ -1035,6 +1051,7 @@ local function GotoToday(opts)
|
||||
vim.cmd("wincmd w")
|
||||
end
|
||||
vim.cmd("e " .. fname)
|
||||
picker_actions.post_open()
|
||||
end)
|
||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||
@@ -1065,6 +1082,7 @@ local function FindNotes(opts)
|
||||
cwd = M.Cfg.home,
|
||||
find_command = M.Cfg.find_command,
|
||||
attach_mappings = function(_, map)
|
||||
actions.select_default:replace(picker_actions.select_default)
|
||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||
@@ -1141,6 +1159,7 @@ local function SearchNotes(opts)
|
||||
default_text = vim.fn.expand("<cword>"),
|
||||
find_command = M.Cfg.find_command,
|
||||
attach_mappings = function(_, map)
|
||||
actions.select_default:replace(picker_actions.select_default)
|
||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||
@@ -1175,6 +1194,7 @@ local function ShowBacklinks(opts)
|
||||
default_text = "\\[\\[" .. title .. "\\]\\]",
|
||||
find_command = M.Cfg.find_command,
|
||||
attach_mappings = function(_, map)
|
||||
actions.select_default:replace(picker_actions.select_default)
|
||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||
@@ -1217,6 +1237,7 @@ local function on_create(opts, title)
|
||||
default_text = title,
|
||||
find_command = M.Cfg.find_command,
|
||||
attach_mappings = function(_, map)
|
||||
actions.select_default:replace(picker_actions.select_default)
|
||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||
@@ -1262,6 +1283,7 @@ local function on_create_with_template(opts, title)
|
||||
if fexists == true then
|
||||
-- open the new note
|
||||
vim.cmd("e " .. fname)
|
||||
picker_actions.post_open()
|
||||
return
|
||||
end
|
||||
|
||||
@@ -1277,6 +1299,7 @@ local function on_create_with_template(opts, title)
|
||||
create_note_from_template(title, fname, template)
|
||||
-- open the new note
|
||||
vim.cmd("e " .. fname)
|
||||
picker_actions.post_open()
|
||||
end)
|
||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||
@@ -1332,6 +1355,7 @@ local function GotoThisWeek(opts)
|
||||
default_text = title,
|
||||
find_command = M.Cfg.find_command,
|
||||
attach_mappings = function(_, map)
|
||||
actions.select_default:replace(picker_actions.select_default)
|
||||
map("i", "<c-y>", picker_actions.yank_link(opts))
|
||||
map("i", "<c-i>", picker_actions.paste_link(opts))
|
||||
map("n", "<c-y>", picker_actions.yank_link(opts))
|
||||
@@ -1528,13 +1552,10 @@ local function Setup(cfg)
|
||||
weekly = M.Cfg.template_new_weekly,
|
||||
}
|
||||
|
||||
if M.Cfg.install_syntax then
|
||||
-- for previewers to pick up our syntax, we need to tell plenary to override `.md` with our syntax
|
||||
filetype.add_file("telekasten")
|
||||
|
||||
-- now activate our syntax also for all markdown files
|
||||
vim.cmd("autocmd filetype markdown set syntax=telekasten")
|
||||
end
|
||||
-- setting the syntax moved into plugin/telekasten.vim
|
||||
-- and does not work
|
||||
|
||||
if debug then
|
||||
print("Resulting config:")
|
||||
|
||||
@@ -9,3 +9,7 @@ function! s:telekasten_complete(arg,line,pos)
|
||||
endfunction
|
||||
|
||||
command! -nargs=? -complete=custom,s:telekasten_complete Telekasten lua require('telekasten').panel(<f-args>)
|
||||
|
||||
" overriding does not work -- so this is done by the plugin now in post_open()
|
||||
" au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mkdn,*.mdwn,*.md setf telekasten
|
||||
" autocmd filetype markdown set syntax=telekasten
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
"syn region Comment matchgroup=mkdDelimiter start="\%^---$" end="^\(---\|\.\.\.\)$" contains=tkTag keepend
|
||||
|
||||
syntax region tkLink matchgroup=tkBrackets start=/\[\[/ end=/\]\]/ display oneline
|
||||
syntax region tkHighlight matchgroup=tkBrackets start=/==/ end=/==/ display oneline
|
||||
|
||||
syntax match tkTag "\v#[a-zA-Z]+[a-zA-Z0-9/\-_]*"
|
||||
syntax match tkTag "\v:[a-zA-Z]+[a-zA-Z0-9/\-_]*:"
|
||||
|
||||
syntax match tkTagSep "\v\s*,\s*" contained
|
||||
syntax region tkTag matchgroup=tkBrackets start=/^tags\s*:\s*\[\s*/ end=/\s*\]\s*$/ contains=tkTagSep display oneline
|
||||
|
||||
" " just blue
|
||||
" hi tklink ctermfg=Blue cterm=bold,underline
|
||||
" hi tkBrackets ctermfg=gray
|
||||
|
||||
" " for gruvbox
|
||||
" hi tklink ctermfg=72 cterm=bold,underline
|
||||
" hi tkBrackets ctermfg=gray
|
||||
|
||||
" " Highlight ==highlighted== text
|
||||
" hi tkHighlight ctermbg=yellow ctermfg=darkred cterm=bold
|
||||
"
|
||||
" " Tags
|
||||
" hi tkTagSep ctermfg=gray
|
||||
" hi tkTag ctermfg=magenta
|
||||
Reference in New Issue
Block a user