commit 7af1016b383b6bf14a87feab59b99fcb9de889dd
parent ac44011388b1119d0ca575b84b259c7028adb8d3
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Tue, 8 Jan 2019 15:20:12 +0100
Tagbar vimwiki integration
Former-commit-id: 6de474fec8ebf30424fcb30731997ef9e0f1e471
Diffstat:
3 files changed, 121 insertions(+), 0 deletions(-)
diff --git a/other-scripts/vwtags.py b/other-scripts/vwtags.py
@@ -0,0 +1,82 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from __future__ import print_function
+
+help_text = """
+Extracts tags from Vimwiki files. Useful for the Tagbar plugin.
+
+Usage:
+Install Tagbar (http://majutsushi.github.io/tagbar/). Then, put this file
+anywhere and add the following to your .vimrc:
+
+let g:tagbar_type_vimwiki = {
+ \ 'ctagstype':'vimwiki'
+ \ , 'kinds':['h:header']
+ \ , 'sro':'&&&'
+ \ , 'kind2scope':{'h':'header'}
+ \ , 'sort':0
+ \ , 'ctagsbin':'/path/to/vwtags.py'
+ \ , 'ctagsargs': 'default'
+ \ }
+
+The value of ctagsargs must be one of 'default', 'markdown' or 'media',
+whatever syntax you use. However, if you use multiple wikis with different
+syntaxes, you can, as a workaround, use the value 'all' instead. Then, Tagbar
+will show markdown style headers as well as default/mediawiki style headers,
+but there might be erroneously shown headers.
+"""
+
+import sys
+import re
+
+if len(sys.argv) < 3:
+ print(help_text)
+ exit()
+
+syntax = sys.argv[1]
+filename = sys.argv[2]
+rx_default_media = r"^\s*(={1,6})([^=].*[^=])\1\s*$"
+rx_markdown = r"^\s*(#{1,6})([^#].*)$"
+
+if syntax in ("default", "media"):
+ rx_header = re.compile(rx_default_media)
+elif syntax == "markdown":
+ rx_header = re.compile(rx_markdown)
+else:
+ rx_header = re.compile(rx_default_media + "|" + rx_markdown)
+
+file_content = []
+try:
+ with open(filename, "r") as vim_buffer:
+ file_content = vim_buffer.readlines()
+except:
+ exit()
+
+state = [""]*6
+for lnum, line in enumerate(file_content):
+
+ match_header = rx_header.match(line)
+
+ if not match_header:
+ continue
+
+ match_lvl = match_header.group(1) or match_header.group(3)
+ match_tag = match_header.group(2) or match_header.group(4)
+
+ cur_lvl = len(match_lvl)
+ cur_tag = match_tag.strip()
+ cur_searchterm = "^" + match_header.group(0).rstrip("\r\n") + "$"
+ cur_kind = "h"
+
+ state[cur_lvl-1] = cur_tag
+ for i in range(cur_lvl, 6):
+ state[i] = ""
+
+ scope = "&&&".join(
+ [state[i] for i in range(0, cur_lvl-1) if state[i] != ""])
+ if scope:
+ scope = "\theader:" + scope
+
+ print('{0}\t{1}\t/{2}/;"\t{3}\tline:{4}{5}'.format(
+ cur_tag, filename, cur_searchterm, cur_kind, str(lnum+1), scope))
diff --git a/vim/general.vimrc b/vim/general.vimrc
@@ -91,3 +91,5 @@ set modelines=5 "within the first/last 5 lines
" Allow italics
set t_ZH=[3m
set t_ZR=[23m
+
+let tlist_vimwiki_settings = 'wiki;h:Headers'
diff --git a/vim/pluginconf.vimrc b/vim/pluginconf.vimrc
@@ -1,2 +1,39 @@
let g:NERDSpaceDelims = 1
let g:vimwiki_list = [{'path': '~/Dropbox/vimwiki'}]
+let g:tagbar_type_vimwiki = {
+ \ 'ctagstype':'vimwiki'
+ \ , 'kinds':['h:header']
+ \ , 'sro':'&&&'
+ \ , 'kind2scope':{'h':'header'}
+ \ , 'sort':0
+ \ , 'ctagsbin':'$CONF_DIR/other-scripts/vwtags.py'
+ \ , 'ctagsargs': 'default'
+ \ }
+
+let g:tagbar_type_go = {
+ \ 'ctagstype' : 'go',
+ \ 'kinds' : [
+ \ 'p:package',
+ \ 'i:imports:1',
+ \ 'c:constants',
+ \ 'v:variables',
+ \ 't:types',
+ \ 'n:interfaces',
+ \ 'w:fields',
+ \ 'e:embedded',
+ \ 'm:methods',
+ \ 'r:constructor',
+ \ 'f:functions'
+ \ ],
+ \ 'sro' : '.',
+ \ 'kind2scope' : {
+ \ 't' : 'ctype',
+ \ 'n' : 'ntype'
+ \ },
+ \ 'scope2kind' : {
+ \ 'ctype' : 't',
+ \ 'ntype' : 'n'
+ \ },
+ \ 'ctagsbin' : 'gotags',
+ \ 'ctagsargs' : '-sort -silent'
+\ }