From e808d2d49b36a72eae5393fd2ca956025a1b2717 Mon Sep 17 00:00:00 2001
From: Maxim Likhachev
Date: Wed, 5 Feb 2020 13:43:00 +0300
Subject: [PATCH] =?UTF-8?q?vim:=20vimwiki:=20=D0=BE=D0=B1=D0=BD=D0=BE?=
=?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B0=20=D0=BF?=
=?UTF-8?q?=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD=D1=8E=D1=8E=20=D0=B2=D0=B5?=
=?UTF-8?q?=D1=80=D1=81=D0=B8=D1=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
etc/soft/nvim/+plugins/vimwiki/CONTRIBUTING.md | 63 +
etc/soft/nvim/+plugins/vimwiki/LICENSE.md | 22 +
etc/soft/nvim/+plugins/vimwiki/README-cn.md | 161 ++
etc/soft/nvim/+plugins/vimwiki/README.md | 250 ++
.../+plugins/vimwiki/autoload/vimwiki/base.vim | 2060 +++++++++----
.../vimwiki/autoload/vimwiki/customwiki2html.sh | 62 +
.../+plugins/vimwiki/autoload/vimwiki/default.tpl | 2 +-
.../+plugins/vimwiki/autoload/vimwiki/diary.vim | 445 +--
.../+plugins/vimwiki/autoload/vimwiki/html.vim | 1505 +++++-----
.../nvim/+plugins/vimwiki/autoload/vimwiki/lst.vim | 1888 ++++++++++--
.../vimwiki/autoload/vimwiki/markdown_base.vim | 150 +
.../+plugins/vimwiki/autoload/vimwiki/path.vim | 183 ++
.../+plugins/vimwiki/autoload/vimwiki/style.css | 68 +-
.../+plugins/vimwiki/autoload/vimwiki/tags.vim | 342 +++
.../nvim/+plugins/vimwiki/autoload/vimwiki/tbl.vim | 547 ++--
.../nvim/+plugins/vimwiki/autoload/vimwiki/u.vim | 72 +
.../+plugins/vimwiki/autoload/vimwiki/vars.vim | 850 ++++++
etc/soft/nvim/+plugins/vimwiki/doc/entries.png | Bin 0 -> 181181 bytes
etc/soft/nvim/+plugins/vimwiki/doc/lists.png | Bin 0 -> 282418 bytes
.../nvim/+plugins/vimwiki/doc/screenshot_1.png | Bin 0 -> 29362 bytes
.../nvim/+plugins/vimwiki/doc/screenshot_2.png | Bin 0 -> 49959 bytes
etc/soft/nvim/+plugins/vimwiki/doc/todos.png | Bin 0 -> 255099 bytes
etc/soft/nvim/+plugins/vimwiki/doc/vimwiki.txt | 3043 +++++++++++++-------
etc/soft/nvim/+plugins/vimwiki/doc/wiki.png | Bin 0 -> 312706 bytes
.../nvim/+plugins/vimwiki/ftplugin/vimwiki.vim | 773 +++--
etc/soft/nvim/+plugins/vimwiki/plugin/vimwiki.vim | 631 ++--
etc/soft/nvim/+plugins/vimwiki/syntax/vimwiki.vim | 658 +++--
.../+plugins/vimwiki/syntax/vimwiki_default.vim | 117 +-
.../+plugins/vimwiki/syntax/vimwiki_markdown.vim | 104 +
.../vimwiki/syntax/vimwiki_markdown_custom.vim | 194 ++
.../nvim/+plugins/vimwiki/syntax/vimwiki_media.vim | 110 +-
.../vimwiki.v1/autoload/vimwiki/base.vim | 1056 +++++++
.../vimwiki.v1/autoload/vimwiki/default.tpl | 11 +
.../vimwiki.v1/autoload/vimwiki/diary.vim | 286 ++
.../vimwiki.v1/autoload/vimwiki/html.vim | 1441 +++++++++
.../vimwiki.v1/autoload/vimwiki/lst.vim | 369 +++
.../vimwiki.v1/autoload/vimwiki/style.css | 39 +
.../vimwiki.v1/autoload/vimwiki/tbl.vim | 510 ++++
.../+plugins_disabled/vimwiki.v1/doc/vimwiki.txt | 2339 +++++++++++++++
.../vimwiki.v1/ftplugin/vimwiki.vim | 418 +++
.../vimwiki.v1/plugin/vimwiki.vim | 445 +++
.../vimwiki.v1/syntax/vimwiki.vim | 407 +++
.../vimwiki.v1/syntax/vimwiki_default.vim | 85 +
.../vimwiki.v1/syntax/vimwiki_media.vim | 69 +
etc/soft/nvim/vimrc | 4 +-
45 files changed, 17959 insertions(+), 3820 deletions(-)
create mode 100644 etc/soft/nvim/+plugins/vimwiki/CONTRIBUTING.md
create mode 100644 etc/soft/nvim/+plugins/vimwiki/LICENSE.md
create mode 100644 etc/soft/nvim/+plugins/vimwiki/README-cn.md
create mode 100644 etc/soft/nvim/+plugins/vimwiki/README.md
create mode 100755 etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/customwiki2html.sh
create mode 100644 etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/markdown_base.vim
create mode 100644 etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/path.vim
create mode 100644 etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/tags.vim
create mode 100644 etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/u.vim
create mode 100644 etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/vars.vim
create mode 100644 etc/soft/nvim/+plugins/vimwiki/doc/entries.png
create mode 100644 etc/soft/nvim/+plugins/vimwiki/doc/lists.png
create mode 100644 etc/soft/nvim/+plugins/vimwiki/doc/screenshot_1.png
create mode 100644 etc/soft/nvim/+plugins/vimwiki/doc/screenshot_2.png
create mode 100644 etc/soft/nvim/+plugins/vimwiki/doc/todos.png
create mode 100644 etc/soft/nvim/+plugins/vimwiki/doc/wiki.png
create mode 100644 etc/soft/nvim/+plugins/vimwiki/syntax/vimwiki_markdown.vim
create mode 100644 etc/soft/nvim/+plugins/vimwiki/syntax/vimwiki_markdown_custom.vim
create mode 100644 etc/soft/nvim/+plugins_disabled/vimwiki.v1/autoload/vimwiki/base.vim
create mode 100644 etc/soft/nvim/+plugins_disabled/vimwiki.v1/autoload/vimwiki/default.tpl
create mode 100644 etc/soft/nvim/+plugins_disabled/vimwiki.v1/autoload/vimwiki/diary.vim
create mode 100644 etc/soft/nvim/+plugins_disabled/vimwiki.v1/autoload/vimwiki/html.vim
create mode 100644 etc/soft/nvim/+plugins_disabled/vimwiki.v1/autoload/vimwiki/lst.vim
create mode 100644 etc/soft/nvim/+plugins_disabled/vimwiki.v1/autoload/vimwiki/style.css
create mode 100644 etc/soft/nvim/+plugins_disabled/vimwiki.v1/autoload/vimwiki/tbl.vim
create mode 100644 etc/soft/nvim/+plugins_disabled/vimwiki.v1/doc/vimwiki.txt
create mode 100644 etc/soft/nvim/+plugins_disabled/vimwiki.v1/ftplugin/vimwiki.vim
create mode 100644 etc/soft/nvim/+plugins_disabled/vimwiki.v1/plugin/vimwiki.vim
create mode 100644 etc/soft/nvim/+plugins_disabled/vimwiki.v1/syntax/vimwiki.vim
create mode 100644 etc/soft/nvim/+plugins_disabled/vimwiki.v1/syntax/vimwiki_default.vim
create mode 100644 etc/soft/nvim/+plugins_disabled/vimwiki.v1/syntax/vimwiki_media.vim
diff --git a/etc/soft/nvim/+plugins/vimwiki/CONTRIBUTING.md b/etc/soft/nvim/+plugins/vimwiki/CONTRIBUTING.md
new file mode 100644
index 0000000..1685084
--- /dev/null
+++ b/etc/soft/nvim/+plugins/vimwiki/CONTRIBUTING.md
@@ -0,0 +1,63 @@
+# Filing a bug
+
+Before filing a bug or starting to write a patch, check the latest development version from
+https://github.com/vimwiki/vimwiki/tree/dev to see if your problem is already fixed.
+
+Issues can be filed at https://github.com/vimwiki/vimwiki/issues/ .
+
+# Creating a pull request
+
+If you want to provide a pull request on GitHub, please start from the `dev` branch, not from the
+`master` branch. (Caution, GitHub shows `master` as the default branch from which to start a PR.)
+
+Make sure to update `doc/vimwiki.txt` with the following information:
+
+1. Update the changelog to include information on the new feature the PR introduces or the bug it
+ is fixing.
+2. Add a help section to describe any new features or options.
+2. If you are a first time contributor add your name to the list of contributors.
+
+# More info and advice for (aspiring) core developers
+
+- Before implementing a non-trivial feature, think twice what it means for the user. We should
+ always try to keep backward compatibility. If you are not sure, discuss it on GitHub.
+- Also, when thinking about adding a new feature, it should be something which fits into the
+ overall design of Vimwiki and which a significant portion of the users may like. Keep in mind
+ that everybody has their own way to use Vimwiki.
+- Keep the coding style consistent.
+- Test your changes. Keep in mind that Vim has a ton of options and the users tons of different
+ setups. Take a little time to think about under which circumstances your changes could break.
+
+## Git branching model
+
+- there are two branches with eternal lifetime:
+ - `dev`: This is where the main development happens. Tasks which are done in one or only a few
+ commits go here directly. Always try to keep this branch in a working state, that is, if the
+ task you work on requires multiple commits, make sure intermediate commits don't make Vimwiki
+ unusable (or at least push these commits at one go).
+ - `master`: This branch is for released states only. Whenever a reasonable set of changes has
+ piled up in the `dev` branch, a [release is done](#Preparing a release). After a release,
+ `dev` has been merged into `master` and `master` got exactly one additional commit in which
+ the version number in `plugin/vimwiki.vim` is updated. Apart from these commits and the merge
+ commit from `dev`, nothing happens on `master`. Never should `master` merge into `dev`. When
+ the users ask, we should recommend this branch for them to use.
+- Larger changes which require multiple commits are done in feature branches. They are based on
+ `dev` and merge into `dev` when the work is done.
+
+## Preparing a release
+
+1. `git checkout dev`
+2. Update the changelog in the doc, nicely grouped, with a new version number and release date.
+3. Update the list of contributors.
+4. Update the version number at the top of the doc file.
+5. If necessary, update the Readme and the home page.
+6. `git checkout master && git merge dev`
+7. Update the version number at the top of plugin/vimwiki.vim.
+8. Set a tag with the version number in Git: `git tag vX.Y`
+9. `git push --tags`
+10. In GitHub, go to _Releases_ -> _Draft a new release_ -> choose the tag, convert the changelog from the
+ doc to markdown and post it there. Make plans to build an automatic converter and immediately
+ forget this plan.
+11. Tell the world.
+
+%% vim:tw=99
diff --git a/etc/soft/nvim/+plugins/vimwiki/LICENSE.md b/etc/soft/nvim/+plugins/vimwiki/LICENSE.md
new file mode 100644
index 0000000..cdf8546
--- /dev/null
+++ b/etc/soft/nvim/+plugins/vimwiki/LICENSE.md
@@ -0,0 +1,22 @@
+MIT License
+
+Copyright (c) 2008-2010 Maxim Kim
+ 2013-2017 Daniel Schemala
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/etc/soft/nvim/+plugins/vimwiki/README-cn.md b/etc/soft/nvim/+plugins/vimwiki/README-cn.md
new file mode 100644
index 0000000..5d1a064
--- /dev/null
+++ b/etc/soft/nvim/+plugins/vimwiki/README-cn.md
@@ -0,0 +1,161 @@
+VimWiki —— Vim 个人 Wiki 插件
+==============================================================================
+
+[English](README.md)
+
+
+ *
+
+介绍
+------------------------------------------------------------------------------
+
+Vimwiki 是 Vim 中的个人 Wiki —— 一组链接起来的、有独特语法高亮的文本文件。
+
+通过 Vimwiki,你可以:
+
+ * 组织笔记和想法
+ * 管理待办事项
+ * 编写文档
+ * 坚持写日记
+ * 将这一切导出成 HTML 网页
+
+马上开始!按下 `ww`(通常是 `\ww`)进入作为目录页的 wiki 文件,这个文件默认存放在 `~/vimwiki/index.wiki`。
+
+在该文件中输入以下示例:
+
+ = 我的个人知识库 =
+ * 任务列表 -- _昨天_ 就该完成的事!!!
+ * Gutenberg 计划 -- 好书给我力量。
+ * 草稿 -- 临时记录一些东西。
+
+把光标移到 `任务` 二字上,按 Enter(回车)创建链接。按下后,`任务`二字会变成 `[[任务]]` —— 这是一个 Vimwiki 链接。再次按 Enter 即可进入这个链接(打开新的 wiki 文件)。编辑这个新文件,保存,然后按 Backspace(退格)就能回到目录页。
+
+如果 Vimwiki 链接长度不止一个单词(指的是英文单词),只需在 Visual 模式选择这段文本后按 Enter 即可。用上面的 `Gutenberg 计划` 试试吧。最终结果是这样:
+
+ = 我的个人知识库 =
+ * [[任务列表]] -- _昨天_ 就该完成的事!!!
+ * [[Gutenberg 计划]] -- 好书给我力量。
+ * 草稿 -- 临时记录一些东西。
+
+
+基本标记
+------------------------------------------------------------------------------
+
+ = 一级标题 =
+ == 二级标题 ==
+ === 三级标题 ===
+
+
+ *bold* -- 粗体文本
+ _italic_ -- 斜体文本
+ (应用于句中的汉字文本时,必须在标记前后加空格,例如:一段 *中文* 文本)
+
+ [[wiki link]] -- wiki 链接
+ [[wiki link|description]] -- 带有描述文本的 wiki 链接
+
+
+列表:
+
+ * bullet list item 1(无编号列表)
+ - bullet list item 2
+ - bullet list item 3
+ * bullet list item 4
+ * bullet list item 5
+ * bullet list item 6
+ * bullet list item 7
+ - bullet list item 8
+ - bullet list item 9
+
+ 1. numbered list item 1(有编号列表)
+ 2. numbered list item 2
+ a) numbered list item 3
+ b) numbered list item 4
+
+
+更多格式说明,请阅 `:h vimwiki-syntax`
+
+
+键位绑定
+------------------------------------------------------------------------------
+
+normal 模式:
+
+ * `ww` -- 打开默认的 wiki 目录文件
+ * `wt` -- 在新标签(Tab)中打开 wiki 目录文件
+ * `ws` -- 在多个 wiki 中选择并打开该 wiki 的目录文件
+ * `wd` -- 删除当前 wiki 文件
+ * `wr` -- 重命名当前 wiki 文件
+ * `` -- 创建或打开 wiki 链接
+ * `` -- 先上下分屏再打开 wiki 链接(若非链接则先创建)
+ * `` -- 先左右分屏再打开 wiki 链接(若非链接则先创建)
+ * `` -- 返回之前浏览的 wiki 文件
+ * `` -- 跳到本文件中下一个 wiki 链接
+ * `` -- 跳到本文件中上一个 wiki 链接
+
+更多快捷键说明,请阅 `:h vimwiki-mappings`
+
+
+命令
+------------------------------------------------------------------------------
+
+ * `:Vimwiki2HTML` -- 将当前 wiki 文件转换成 HTML 网页
+ * `:VimwikiAll2HTML` -- 把所有 wiki 文件转换成 HTML 网页
+ * `:help vimwiki-commands` -- 显示全部命令
+
+
+安装
+==============================================================================
+
+准备工作
+------------------------------------------------------------------------------
+
+确保在 `vimrc` 中加入了以下设置:
+
+ set nocompatible
+ filetype plugin on
+ syntax on
+
+没有这些设置,Vimwiki 将无法正常工作。
+
+通过 [Vim packages](http://vimhelp.appspot.com/repeat.txt.html#packages) 安装(Vim 7.4.1528 后)
+------------------------------------------------------------------------------
+
+ git clone https://github.com/vimwiki/vimwiki.git ~/.vim/pack/plugins/start/vimwiki
+
+通过 [Pathogen](http://www.vim.org/scripts/script.php?script_id=2332) 安装
+------------------------------------------------------------------------------
+
+ cd ~/.vim
+ mkdir bundle
+ cd bundle
+ git clone https://github.com/vimwiki/vimwiki.git
+
+通过 [Vim-Plug](https://github.com/junegunn/vim-plug) 安装
+------------------------------------------------------------------------------
+
+在 `vimrc` 中加入以下插件设置:
+
+ Plug 'vimwiki/vimwiki'
+
+然后运行 `:PlugInstall`。
+
+通过 [Vundle](https://github.com/VundleVim/Vundle.vim) 安装
+------------------------------------------------------------------------------
+
+在 `vimrc` 中加入 `Plugin 'vimwiki/vimwiki'`,然后执行:
+
+ vim +PluginInstall +qall
+
+或者下载 [zip 压缩包](https://github.com/vimwiki/vimwiki/archive/master.zip)然后解压到 `~/.vim/bundle/` 目录下。
+
+安装后,启动 Vim 并执行 `:Helptags` 以及 `:help vimwiki`,检查安装是否成功。
+
+
+获取帮助
+==============================================================================
+
+遇到问题?在 Freenode 的 IRC 频道 `#vimwiki`([网页聊天](https://webchat.freenode.net/?channels=#vimwiki))提问,或者发送问题到[邮件列表](https://groups.google.com/forum/#!forum/vimwiki)上吧。
+
+
+----
+\* 前面截图中用的是 [solarized 配色方案](https://github.com/altercation/vim-colors-solarized)以及 [lightline](https://github.com/itchyny/lightline.vim) 插件。
diff --git a/etc/soft/nvim/+plugins/vimwiki/README.md b/etc/soft/nvim/+plugins/vimwiki/README.md
new file mode 100644
index 0000000..6edd731
--- /dev/null
+++ b/etc/soft/nvim/+plugins/vimwiki/README.md
@@ -0,0 +1,250 @@
+# VimWiki: A Personal Wiki For Vim
+
+[中文](README-cn.md)
+
+- [Intro](#intro)
+- [Installation](#installation)
+ - [Prerequisites](#prerequisites)
+ - [VIM Packages](#installation-using-vim-packages-since-vim-741528)
+ - [Pathogen](#installation-using-pathogen)
+ - [Vim-Plug](#installation-using-vim-plug)
+ - [Vundle](#installation-using-vundle)
+- [Basic Markup](#basic-markup)
+ - [Lists](#lists)
+- [Key Bindings](#key-bindings)
+- [Commands](#commands)
+- [Changing Wiki Syntax](#changing-wiki-syntax)
+- [Getting Help](#getting-help)
+- [Helping VimWiki](#helping-vimwiki)
+- [Wiki](https://github.com/vimwiki/vimwiki/wiki)
+- [License](#license)
+
+## Intro
+
+VimWiki is a personal wiki for Vim -- a number of linked text files that have
+their own syntax highlighting.
+
+With VimWiki you can:
+
+ * Organize notes and ideas
+ * Manage to-do lists
+ * Write documentation
+ * Maintain a diary
+ * Export everything to HTML
+
+To do a quick start press `ww` (this is usually `\ww`) to go to your
+index wiki file. By default it is located in `~/vimwiki/index.wiki`.
+
+Feed it with the following example:
+
+```
+
+= My knowledge base =
+ * Tasks -- things to be done _yesterday_!!!
+ * Project Gutenberg -- good books are power.
+ * Scratchpad -- various temporary stuff.
+
+```
+
+Place your cursor on `Tasks` and press Enter to create a link. Once pressed,
+`Tasks` will become `[[Tasks]]` -- a VimWiki link. Press Enter again to
+open it. Edit the file, save it, and then press Backspace to jump back to your
+index.
+
+A VimWiki link can be constructed from more than one word. Just visually
+select the words to be linked and press Enter. Try it with `Project Gutenberg`.
+The result should look something like:
+
+```
+
+= My knowledge base =
+ * [[Tasks]] -- things to be done _yesterday_!!!
+ * [[Project Gutenberg]] -- good books are power.
+ * Scratchpad -- various temporary stuff.
+
+```
+
+## Screenshots
+
+
+
+
+
+
+## Installation
+
+### Prerequisites
+
+Make sure you have these settings in your vimrc file:
+
+```vim
+
+set nocompatible
+filetype plugin on
+syntax on
+
+```
+
+Without them VimWiki will not work properly.
+
+
+#### Installation using [Vim packages](http://vimhelp.appspot.com/repeat.txt.html#packages) (since Vim 7.4.1528)
+
+```sh
+
+git clone https://github.com/vimwiki/vimwiki.git ~/.vim/pack/plugins/start/vimwiki
+
+```
+
+#### Installation using [Pathogen](http://www.vim.org/scripts/script.php?script_id=2332)
+
+```sh
+
+cd ~/.vim
+mkdir bundle
+cd bundle
+git clone https://github.com/vimwiki/vimwiki.git
+
+```
+
+#### Installation using [Vim-Plug](https://github.com/junegunn/vim-plug)
+
+Add the following to the plugin-configuration in your vimrc:
+
+```vim
+
+Plug 'vimwiki/vimwiki'
+
+```
+
+Then run `:PlugInstall`.
+
+#### Installation using [Vundle](https://github.com/VundleVim/Vundle.vim)
+
+Add `Plugin 'vimwiki/vimwiki'` to your vimrc file and run
+
+```sh
+
+vim +PluginInstall +qall
+
+```
+
+Or download the [zip
+archive](https://github.com/vimwiki/vimwiki/archive/master.zip) and extract it
+in `~/.vim/bundle/`
+
+Then launch Vim, run `:Helptags` and then `:help vimwiki` to verify it was
+installed.
+
+## Basic Markup
+
+```
+= Header1 =
+== Header2 ==
+=== Header3 ===
+
+
+*bold* -- bold text
+_italic_ -- italic text
+
+[[wiki link]] -- wiki link
+[[wiki link|description]] -- wiki link with description
+```
+
+### Lists:
+
+```
+* bullet list item 1
+ - bullet list item 2
+ - bullet list item 3
+ * bullet list item 4
+ * bullet list item 5
+* bullet list item 6
+* bullet list item 7
+ - bullet list item 8
+ - bullet list item 9
+
+1. numbered list item 1
+2. numbered list item 2
+ a) numbered list item 3
+ b) numbered list item 4
+```
+
+For other syntax elements, see `:h vimwiki-syntax`
+
+## Key bindings
+
+Normal mode:
+
+ * `ww` -- Open default wiki index file.
+ * `wt` -- Open default wiki index file in a new tab.
+ * `ws` -- Select and open wiki index file.
+ * `wd` -- Delete wiki file you are in.
+ * `wr` -- Rename wiki file you are in.
+ * `` -- Follow/Create wiki link
+ * `` -- Split and follow/create wiki link
+ * `` -- Vertical split and follow/create wiki link
+ * `` -- Go back to parent(previous) wiki link
+ * `` -- Find next wiki link
+ * `` -- Find previous wiki link
+
+For more keys, see `:h vimwiki-mappings`
+
+## Commands
+
+ * `:Vimwiki2HTML` -- Convert current wiki link to HTML
+ * `:VimwikiAll2HTML` -- Convert all your wiki links to HTML
+ * `:help vimwiki-commands` -- list all commands
+ * `:help vimwiki` -- General vimwiki help docs
+
+## Changing Wiki Syntax
+
+VimWiki currently ships with 3 syntaxes: VimWiki (default), Markdown
+(markdown), and MediaWiki (media)
+
+If you would prefer to use either Markdown or MediaWiki syntaxes, set the
+following option in your .vimrc:
+
+```vim
+
+let g:vimwiki_list = [{'path': '~/vimwiki/',
+ \ 'syntax': 'markdown', 'ext': '.md'}]
+
+```
+
+## Getting help
+
+**Have a question?**
+Visit the IRC channel [`#vimwiki`](https://webchat.freenode.net/?channels=#vimwiki) on Freenode ([webchat](https://webchat.freenode.net/?channels=#vimwiki), also synced to Matrix/Riot: `#vimwiki:matrix.org`) or post to the [mailing list](https://groups.google.com/forum/#!forum/vimwiki).
+
+## Helping VimWiki
+
+VimWiki has a lot of users but only very few recurring developers or people
+helping the community. Your help is therefore appreciated. Everyone can help!
+See [#625](https://github.com/vimwiki/vimwiki/issues/625) for information on
+how you can help.
+
+## License
+
+MIT License
+
+Copyright (c) 2008-2010 Maxim Kim
+ 2013-2017 Daniel Schemala
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/base.vim b/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/base.vim
index fc6168f..7986609 100644
--- a/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/base.vim
+++ b/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/base.vim
@@ -1,242 +1,796 @@
-" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
+" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki autoload plugin file
-" Author: Maxim Kim
-" Home: http://code.google.com/p/vimwiki/
+" Desc: Basic functionality
+" Home: https://github.com/vimwiki/vimwiki/
if exists("g:loaded_vimwiki_auto") || &cp
finish
endif
let g:loaded_vimwiki_auto = 1
-if has("win32")
- let s:os_sep = '\'
-else
- let s:os_sep = '/'
-endif
-let s:badsymbols = '['.g:vimwiki_badsyms.g:vimwiki_stripsym.'<>|?*:"]'
+function! s:safesubstitute(text, search, replace, mode)
+ " Substitute regexp but do not interpret replace
+ let escaped = escape(a:replace, '\&')
+ return substitute(a:text, a:search, escaped, a:mode)
+endfunction
-" MISC helper functions {{{
-function! vimwiki#base#chomp_slash(str) "{{{
- return substitute(a:str, '[/\\]\+$', '', '')
-endfunction "}}}
+function! s:vimwiki_get_known_syntaxes()
+ " Getting all syntaxes that different wikis could have
+ let syntaxes = {}
+ let syntaxes['default'] = 1
+ for wiki_nr in range(vimwiki#vars#number_of_wikis())
+ let wiki_syntax = vimwiki#vars#get_wikilocal('syntax', wiki_nr)
+ let syntaxes[wiki_syntax] = 1
+ endfor
+ " also consider the syntaxes from g:vimwiki_ext2syntax
+ for syn in values(vimwiki#vars#get_global('ext2syntax'))
+ let syntaxes[syn] = 1
+ endfor
+ return keys(syntaxes)
+endfunction
-function! vimwiki#base#path_norm(path) "{{{
- return substitute(a:path, '\', '/', 'g')
-endfunction "}}}
-function! vimwiki#base#mkdir(path) "{{{
- let path = expand(a:path)
- if !isdirectory(path) && exists("*mkdir")
- let path = vimwiki#base#chomp_slash(path)
- if s:is_windows() && !empty(g:vimwiki_w32_dir_enc)
- let path = iconv(path, &enc, g:vimwiki_w32_dir_enc)
- endif
- call mkdir(path, "p")
- endif
+function! vimwiki#base#file_pattern(files)
+ " Get search regex from glob()
+ " string. Aim to support *all* special characters, forcing the user to choose
+ " names that are compatible with any external restrictions that they
+ " encounter (e.g. filesystem, wiki conventions, other syntaxes, ...).
+ " See: https://github.com/vimwiki-backup/vimwiki/issues/316
+ " Change / to [/\\] to allow "Windows paths"
+ return '\V\%('.join(a:files, '\|').'\)\m'
endfunction
-" }}}
-function! vimwiki#base#safe_link(link) "{{{
- " handling Windows absolute paths
- if a:link =~ '^[[:alpha:]]:[/\\].*'
- let link_start = a:link[0 : 2]
- let link = a:link[3 : ]
- else
- let link_start = ''
- let link = a:link
- endif
- let link = substitute(link, s:badsymbols, g:vimwiki_stripsym, 'g')
- return link_start.link
-endfunction
-"}}}
-function! vimwiki#base#unsafe_link(string) "{{{
- if len(g:vimwiki_stripsym) > 0
- return substitute(a:string, g:vimwiki_stripsym, s:badsymbols, 'g')
+"FIXME TODO slow and faulty
+function! vimwiki#base#subdir(path, filename)
+ let path = a:path
+ " ensure that we are not fooled by a symbolic link
+ "FIXME if we are not "fooled", we end up in a completely different wiki?
+ if a:filename !~# '^scp:'
+ let filename = resolve(a:filename)
else
- return a:string
+ let filename = a:filename
endif
-endfunction
-"}}}
-
-function! vimwiki#base#subdir(path, filename)"{{{
- let path = expand(a:path)
- let filename = expand(a:filename)
let idx = 0
+ "FIXME this can terminate in the middle of a path component!
while path[idx] ==? filename[idx]
let idx = idx + 1
endwhile
let p = split(strpart(filename, idx), '[/\\]')
- let res = join(p[:-2], s:os_sep)
+ let res = join(p[:-2], '/')
if len(res) > 0
- let res = res.s:os_sep
+ let res = res.'/'
endif
return res
-endfunction"}}}
+endfunction
-function! vimwiki#base#current_subdir()"{{{
- return vimwiki#base#subdir(VimwikiGet('path'), expand('%:p'))
-endfunction"}}}
-function! vimwiki#base#open_link(cmd, link, ...) "{{{
- if vimwiki#base#is_non_wiki_link(a:link)
- if s:is_path_absolute(a:link)
- call vimwiki#base#edit_file(a:cmd, a:link)
- else
- call vimwiki#base#edit_file(a:cmd, VimwikiGet('path').a:link)
+function! vimwiki#base#current_subdir()
+ return vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), expand('%:p'))
+endfunction
+
+
+function! vimwiki#base#invsubdir(subdir)
+ return substitute(a:subdir, '[^/\.]\+/', '../', 'g')
+endfunction
+
+
+" Returns: the number of the wiki a file belongs to or -1 if it doesn't belong
+" to any registered wiki.
+" The path can be the full path or just the directory of the file
+function! vimwiki#base#find_wiki(path)
+ let bestmatch = -1
+ let bestlen = 0
+ let path = vimwiki#path#path_norm(vimwiki#path#chomp_slash(a:path))
+ for idx in range(vimwiki#vars#number_of_wikis())
+ let idx_path = expand(vimwiki#vars#get_wikilocal('path', idx))
+ let idx_path = vimwiki#path#path_norm(vimwiki#path#chomp_slash(idx_path))
+ let common_pfx = vimwiki#path#path_common_pfx(idx_path, path)
+ if vimwiki#path#is_equal(common_pfx, idx_path)
+ if len(common_pfx) > bestlen
+ let bestlen = len(common_pfx)
+ let bestmatch = idx
+ endif
endif
+ endfor
+
+ return bestmatch
+endfunction
+
+
+" THE central function of Vimwiki. Extract infos about the target from a link.
+" If the second parameter is present, which should be an absolute file path, it
+" is assumed that the link appears in that file. Without it, the current file
+" is used.
+function! vimwiki#base#resolve_link(link_text, ...)
+ if a:0
+ let source_wiki = vimwiki#base#find_wiki(a:1)
+ let source_file = a:1
else
- if a:0
- let vimwiki_prev_link = [a:1, []]
- elseif &ft == 'vimwiki'
- let vimwiki_prev_link = [expand('%:p'), getpos('.')]
+ let source_wiki = vimwiki#vars#get_bufferlocal('wiki_nr')
+ let source_file = vimwiki#path#current_wiki_file()
+ endif
+
+ let link_text = a:link_text
+
+
+ let link_infos = {
+ \ 'index': -1,
+ \ 'scheme': '',
+ \ 'filename': '',
+ \ 'anchor': '',
+ \ }
+
+ if link_text == ''
+ return link_infos
+ endif
+
+ let scheme = matchstr(link_text, '^\zs'.vimwiki#vars#get_global('rxSchemes').'\ze:')
+ if scheme == ''
+ let link_infos.scheme = 'wiki'.source_wiki
+ else
+ let link_infos.scheme = scheme
+
+ if link_infos.scheme !~# '\mwiki\d\+\|diary\|local\|file'
+ let link_infos.filename = link_text " unknown scheme, may be a weblink
+ return link_infos
endif
- if vimwiki#base#is_link_to_dir(a:link)
- if g:vimwiki_dir_link == ''
- call vimwiki#base#edit_file(a:cmd, VimwikiGet('path').a:link)
+ let link_text = matchstr(link_text, '^'.vimwiki#vars#get_global('rxSchemes').':\zs.*\ze')
+ endif
+
+ let is_wiki_link = link_infos.scheme =~# '\mwiki\d\+' || link_infos.scheme ==# 'diary'
+
+ " extract anchor
+ if is_wiki_link
+ let split_lnk = split(link_text, '#', 1)
+ let link_text = split_lnk[0]
+ if len(split_lnk) > 1 && split_lnk[-1] != ''
+ let link_infos.anchor = join(split_lnk[1:], '#')
+ endif
+ if link_text == '' " because the link was of the form '#anchor'
+ let expected_ext = vimwiki#u#escape(vimwiki#vars#get_wikilocal('ext')).'$'
+ if source_file =~# expected_ext
+ " Source file has expected extension. Remove it, it will be added later on
+ let ext_len = strlen(vimwiki#vars#get_wikilocal('ext'))
+ let link_text = fnamemodify(source_file, ':p:t')[:-ext_len-1]
+ endif
+
+ endif
+ endif
+
+ " check if absolute or relative path
+ if is_wiki_link && link_text[0] == '/'
+ if link_text != '/'
+ let link_text = link_text[1:]
+ endif
+ let is_relative = 0
+ elseif !is_wiki_link && vimwiki#path#is_absolute(link_text)
+ let is_relative = 0
+ else
+ let is_relative = 1
+ let root_dir = fnamemodify(source_file, ':p:h') . '/'
+ endif
+
+
+ " extract the other items depending on the scheme
+ if link_infos.scheme =~# '\mwiki\d\+'
+ let link_infos.index = eval(matchstr(link_infos.scheme, '\D\+\zs\d\+\ze'))
+ if link_infos.index < 0 || link_infos.index >= vimwiki#vars#number_of_wikis()
+ let link_infos.index = -1
+ let link_infos.filename = ''
+ return link_infos
+ endif
+
+ if !is_relative || link_infos.index != source_wiki
+ let root_dir = vimwiki#vars#get_wikilocal('path', link_infos.index)
+ endif
+
+ let link_infos.filename = root_dir . link_text
+
+ if vimwiki#path#is_link_to_dir(link_text)
+ if vimwiki#vars#get_global('dir_link') != ''
+ let link_infos.filename .= vimwiki#vars#get_global('dir_link') .
+ \ vimwiki#vars#get_wikilocal('ext', link_infos.index)
+ endif
+ else
+ let link_infos.filename .= vimwiki#vars#get_wikilocal('ext', link_infos.index)
+ endif
+
+ elseif link_infos.scheme ==# 'diary'
+ let link_infos.index = source_wiki
+
+ let link_infos.filename =
+ \ vimwiki#vars#get_wikilocal('path', link_infos.index) .
+ \ vimwiki#vars#get_wikilocal('diary_rel_path', link_infos.index) .
+ \ link_text .
+ \ vimwiki#vars#get_wikilocal('ext', link_infos.index)
+ elseif (link_infos.scheme ==# 'file' || link_infos.scheme ==# 'local') && is_relative
+ let link_infos.filename = simplify(root_dir . link_text)
+ else " absolute file link
+ " collapse repeated leading "/"'s within a link
+ let link_text = substitute(link_text, '\m^/\+', '/', '')
+ " expand ~/
+ let link_text = fnamemodify(link_text, ':p')
+ let link_infos.filename = simplify(link_text)
+ endif
+
+ let link_infos.filename = vimwiki#path#normalize(link_infos.filename)
+ return link_infos
+endfunction
+
+
+function! vimwiki#base#system_open_link(url)
+ " handlers
+ function! s:win32_handler(url)
+ "Disable shellslash for cmd and command.com, but enable for all other shells
+ "See Issue #560
+ if (&shell =~? "cmd") || (&shell =~? "command.com")
+
+ if exists('+shellslash')
+ let old_ssl = &shellslash
+ set noshellslash
+ let url = shellescape(a:url, 1)
+ let &shellslash = old_ssl
else
- call vimwiki#base#edit_file(a:cmd,
- \ VimwikiGet('path').a:link.
- \ g:vimwiki_dir_link.
- \ VimwikiGet('ext'))
+ let url = shellescape(a:url, 1)
endif
+ execute 'silent ! start "Title" /B ' . url
+
else
- call vimwiki#base#edit_file(a:cmd, VimwikiGet('path').a:link.VimwikiGet('ext'))
+
+ if exists('+shellslash')
+ let old_ssl = &shellslash
+ set shellslash
+ let url = shellescape(a:url, 1)
+ let &shellslash = old_ssl
+ else
+ let url = shellescape(a:url, 1)
+ endif
+ execute 'silent ! start ' . url
+
endif
-
- if exists('vimwiki_prev_link')
- let b:vimwiki_prev_link = vimwiki_prev_link
+ endfunction
+ function! s:macunix_handler(url)
+ call system('open ' . shellescape(a:url).' &')
+ endfunction
+ function! s:linux_handler(url)
+ call system('xdg-open ' . shellescape(a:url).' &')
+ endfunction
+ try
+ if vimwiki#u#is_windows()
+ call s:win32_handler(a:url)
+ return
+ elseif vimwiki#u#is_macos()
+ call s:macunix_handler(a:url)
+ return
+ else
+ call s:linux_handler(a:url)
+ return
endif
- endif
+ endtry
+ echomsg 'Vimwiki Error: Default Vimwiki link handler was unable to open the HTML file!'
endfunction
-" }}}
-function! vimwiki#base#select(wnum)"{{{
- if a:wnum < 1 || a:wnum > len(g:vimwiki_list)
+
+function! vimwiki#base#open_link(cmd, link, ...)
+ let link_infos = {}
+ if a:0
+ let link_infos = vimwiki#base#resolve_link(a:link, a:1)
+ else
+ let link_infos = vimwiki#base#resolve_link(a:link)
+ endif
+
+ if link_infos.filename == ''
+ if link_infos.index == -1
+ echomsg 'Vimwiki Error: No registered wiki ''' . link_infos.scheme . '''.'
+ else
+ echomsg 'Vimwiki Error: Unable to resolve link!'
+ endif
return
endif
- if &ft == 'vimwiki'
- let b:vimwiki_idx = g:vimwiki_current_idx
+
+ let is_wiki_link = link_infos.scheme =~# '\mwiki\d\+' || link_infos.scheme =~# 'diary'
+
+ let update_prev_link = is_wiki_link &&
+ \ !vimwiki#path#is_equal(link_infos.filename, vimwiki#path#current_wiki_file())
+
+ let vimwiki_prev_link = []
+ " update previous link for wiki pages
+ if update_prev_link
+ if a:0
+ let vimwiki_prev_link = [a:1, []]
+ elseif &ft ==# 'vimwiki'
+ let vimwiki_prev_link = [vimwiki#path#current_wiki_file(), getpos('.')]
+ endif
+ endif
+
+ " open/edit
+ if is_wiki_link
+ call vimwiki#base#edit_file(a:cmd, link_infos.filename, link_infos.anchor,
+ \ vimwiki_prev_link, update_prev_link)
+ else
+ call vimwiki#base#system_open_link(link_infos.filename)
endif
- let g:vimwiki_current_idx = a:wnum - 1
endfunction
-" }}}
-function! vimwiki#base#generate_links()"{{{
- let links = s:get_links('*'.VimwikiGet('ext'))
- " We don't want link to itself.
- let cur_link = expand('%:t:r')
- call filter(links, 'v:val != cur_link')
+function! vimwiki#base#get_globlinks_escaped() abort
+ " only get links from the current dir
+ " change to the directory of the current file
+ let orig_pwd = getcwd()
+ lcd! %:h
+ " all path are relative to the current file's location
+ let globlinks = glob('*'.vimwiki#vars#get_wikilocal('ext'), 1)."\n"
+ " remove extensions
+ let globlinks = substitute(globlinks, '\'.vimwiki#vars#get_wikilocal('ext').'\ze\n', '', 'g')
+ " restore the original working directory
+ exe 'lcd! '.orig_pwd
+ " convert to a List
+ let lst = split(globlinks, '\n')
+ " Apply fnameescape() to each item
+ call map(lst, 'fnameescape(v:val)')
+ " Convert back to newline-separated list
+ let globlinks = join(lst, "\n")
+ " return all escaped links as a single newline-separated string
+ return globlinks
+endfunction
- if len(links)
- call append(line('$'), '= Generated Links =')
- endif
+function! vimwiki#base#generate_links()
+ let lines = []
+
+ let links = vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 0)
call sort(links)
+ let bullet = repeat(' ', vimwiki#lst#get_list_margin()) . vimwiki#lst#default_symbol().' '
for link in links
- if s:is_wiki_word(link)
- call append(line('$'), '- '.link)
- else
- call append(line('$'), '- [['.link.']]')
+ let abs_filepath = vimwiki#path#abs_path_of_link(link)
+ if !s:is_diary_file(abs_filepath)
+ call add(lines, bullet.
+ \ s:safesubstitute(vimwiki#vars#get_global('WikiLinkTemplate1'),
+ \ '__LinkUrl__', link, ''))
endif
endfor
-endfunction " }}}
-function! vimwiki#base#goto(key) "{{{
- call vimwiki#base#edit_file(':e',
- \ VimwikiGet('path').
- \ a:key.
- \ VimwikiGet('ext'))
-endfunction "}}}
+ let links_rx = '\m^\s*'.vimwiki#u#escape(vimwiki#lst#default_symbol()).' '
+
+ call vimwiki#base#update_listing_in_buffer(lines, 'Generated Links', links_rx, line('$')+1, 1)
+endfunction
-function! s:is_windows() "{{{
- return has("win32") || has("win64") || has("win95") || has("win16")
-endfunction "}}}
-function! s:is_path_absolute(path) "{{{
- return a:path =~ '^/.*' || a:path =~ '^[[:alpha:]]:[/\\].*'
-endfunction "}}}
+function! vimwiki#base#goto(...)
+ let key = a:1
+ let anchor = a:0 > 1 ? a:2 : ''
+
+ call vimwiki#base#edit_file(':e',
+ \ vimwiki#vars#get_wikilocal('path') . key . vimwiki#vars#get_wikilocal('ext'),
+ \ anchor)
+endfunction
-function! s:get_links(pat) "{{{
- " search all wiki files in 'path' and its subdirs.
- let subdir = vimwiki#base#current_subdir()
+function! vimwiki#base#backlinks()
+ let current_filename = expand("%:p")
+ let locations = []
+ for idx in range(vimwiki#vars#number_of_wikis())
+ let syntax = vimwiki#vars#get_wikilocal('syntax', idx)
+ let wikifiles = vimwiki#base#find_files(idx, 0)
+ for source_file in wikifiles
+ let links = s:get_links(source_file, idx)
+ for [target_file, _, lnum, col] in links
+ " don't include links from the current file to itself
+ if vimwiki#path#is_equal(target_file, current_filename) &&
+ \ !vimwiki#path#is_equal(target_file, source_file)
+ call add(locations, {'filename':source_file, 'lnum':lnum, 'col':col})
+ endif
+ endfor
+ endfor
+ endfor
+
+ if empty(locations)
+ echomsg 'Vimwiki: No other file links to this file'
+ else
+ call setloclist(0, locations, 'r')
+ lopen
+ endif
+endfunction
+
+
+" Returns: a list containing all files of the given wiki as absolute file path.
+" If the given wiki number is negative, the diary of the current wiki is used
+" If the second argument is not zero, only directories are found
+function! vimwiki#base#find_files(wiki_nr, directories_only)
+ let wiki_nr = a:wiki_nr
+ if wiki_nr >= 0
+ let root_directory = vimwiki#vars#get_wikilocal('path', wiki_nr)
+ else
+ let root_directory = vimwiki#vars#get_wikilocal('path') .
+ \ vimwiki#vars#get_wikilocal('diary_rel_path')
+ let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
+ endif
+ if a:directories_only
+ let ext = '/'
+ else
+ let ext = vimwiki#vars#get_wikilocal('ext', wiki_nr)
+ endif
" if current wiki is temporary -- was added by an arbitrary wiki file then do
" not search wiki files in subdirectories. Or it would hang the system if
" wiki file was created in $HOME or C:/ dirs.
- if VimwikiGet('temp')
- let search_dirs = ''
+ if vimwiki#vars#get_wikilocal('is_temporary_wiki', wiki_nr)
+ let pattern = '*'.ext
else
- let search_dirs = '**/'
+ let pattern = '**/*'.ext
endif
- let globlinks = glob(VimwikiGet('path').subdir.search_dirs.a:pat)
+ return split(globpath(root_directory, pattern), '\n')
+endfunction
- " remove extensions (and backup extensions too: .wiki~)
- let globlinks = substitute(globlinks, '\'.VimwikiGet('ext').'\~\?', "", "g")
- let links = split(globlinks, '\n')
- " remove paths
- let rem_path = escape(expand(VimwikiGet('path')).subdir, '\')
- call map(links, 'substitute(v:val, rem_path, "", "g")')
+" Returns: a list containing the links to get from the current file to all wiki
+" files in the given wiki.
+" If the given wiki number is negative, the diary of the current wiki is used.
+" If also_absolute_links is nonzero, also return links of the form /file
+function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links)
+ let files = vimwiki#base#find_files(a:wiki_nr, 0)
+ if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr')
+ let cwd = vimwiki#path#wikify_path(expand('%:p:h'))
+ elseif a:wiki_nr < 0
+ let cwd = vimwiki#vars#get_wikilocal('path') . vimwiki#vars#get_wikilocal('diary_rel_path')
+ else
+ let cwd = vimwiki#vars#get_wikilocal('path', a:wiki_nr)
+ endif
+ let result = []
+ for wikifile in files
+ let wikifile = fnamemodify(wikifile, ':r') " strip extension
+ let wikifile = vimwiki#path#relpath(cwd, wikifile)
+ call add(result, wikifile)
+ endfor
+ if a:also_absolute_links
+ for wikifile in files
+ if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr')
+ let cwd = vimwiki#vars#get_wikilocal('path')
+ elseif a:wiki_nr < 0
+ let cwd = vimwiki#vars#get_wikilocal('path') . vimwiki#vars#get_wikilocal('diary_rel_path')
+ endif
+ let wikifile = fnamemodify(wikifile, ':r') " strip extension
+ let wikifile = '/'.vimwiki#path#relpath(cwd, wikifile)
+ call add(result, wikifile)
+ endfor
+ endif
+ return result
+endfunction
- " Remove trailing slashes.
- call map(links, 'substitute(v:val, "[/\\\\]*$", "", "g")')
- return links
-endfunction "}}}
+" Returns: a list containing the links to all directories from the current file
+function! vimwiki#base#get_wiki_directories(wiki_nr)
+ let dirs = vimwiki#base#find_files(a:wiki_nr, 1)
+ if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr')
+ let cwd = vimwiki#path#wikify_path(expand('%:p:h'))
+ let root_dir = vimwiki#vars#get_wikilocal('path')
+ else
+ let cwd = vimwiki#vars#get_wikilocal('path', a:wiki_nr)
+ endif
+ let result = ['./']
+ for wikidir in dirs
+ let wikidir_relative = vimwiki#path#relpath(cwd, wikidir)
+ call add(result, wikidir_relative)
+ if a:wiki_nr == vimwiki#vars#get_bufferlocal('wiki_nr')
+ let wikidir_absolute = '/'.vimwiki#path#relpath(root_dir, wikidir)
+ call add(result, wikidir_absolute)
+ endif
+ endfor
+ return result
+endfunction
-" Builtin cursor doesn't work right with unicode characters.
-function! s:cursor(lnum, cnum) "{{{
- exe a:lnum
- exe 'normal! 0'.a:cnum.'|'
-endfunction "}}}
-function! s:filename(link) "{{{
- let result = vimwiki#base#safe_link(a:link)
- if a:link =~ '|'
- let result = vimwiki#base#safe_link(split(a:link, '|')[0])
- elseif a:link =~ ']['
- let result = vimwiki#base#safe_link(split(a:link, '][')[0])
+function! vimwiki#base#get_anchors(filename, syntax)
+ if !filereadable(a:filename)
+ return []
endif
- return result
+
+ let rxheader = vimwiki#vars#get_syntaxlocal('header_search', a:syntax)
+ let rxbold = vimwiki#vars#get_syntaxlocal('bold_search', a:syntax)
+ let rxtag = vimwiki#vars#get_syntaxlocal('tag_search', a:syntax)
+
+ let anchor_level = ['', '', '', '', '', '', '']
+ let anchors = []
+ let current_complete_anchor = ''
+ for line in readfile(a:filename)
+
+ " collect headers
+ let h_match = matchlist(line, rxheader)
+ if !empty(h_match)
+ let header = vimwiki#u#trim(h_match[2])
+ let level = len(h_match[1])
+ call add(anchors, header)
+ let anchor_level[level-1] = header
+ for l in range(level, 6)
+ let anchor_level[l] = ''
+ endfor
+ if level == 1
+ let current_complete_anchor = header
+ else
+ let current_complete_anchor = ''
+ for l in range(level-1)
+ if anchor_level[l] != ''
+ let current_complete_anchor .= anchor_level[l].'#'
+ endif
+ endfor
+ let current_complete_anchor .= header
+ call add(anchors, current_complete_anchor)
+ endif
+ endif
+
+ " collect bold text (there can be several in one line)
+ let bold_count = 1
+ while 1
+ let bold_text = matchstr(line, rxbold, 0, bold_count)
+ if bold_text == ''
+ break
+ endif
+ call add(anchors, bold_text)
+ if current_complete_anchor != ''
+ call add(anchors, current_complete_anchor.'#'.bold_text)
+ endif
+ let bold_count += 1
+ endwhile
+
+ " collect tags text (there can be several in one line)
+ let tag_count = 1
+ while 1
+ let tag_group_text = matchstr(line, rxtag, 0, tag_count)
+ if tag_group_text == ''
+ break
+ endif
+ for tag_text in split(tag_group_text, ':')
+ call add(anchors, tag_text)
+ if current_complete_anchor != ''
+ call add(anchors, current_complete_anchor.'#'.tag_text)
+ endif
+ endfor
+ let tag_count += 1
+ endwhile
+
+ endfor
+
+ return anchors
+endfunction
+
+
+function! s:jump_to_anchor(anchor)
+ let oldpos = getpos('.')
+ call cursor(1, 1)
+
+ let anchor = vimwiki#u#escape(a:anchor)
+
+ let segments = split(anchor, '#', 0)
+
+ for segment in segments
+
+ let anchor_header = s:safesubstitute(
+ \ vimwiki#vars#get_syntaxlocal('header_match'),
+ \ '__Header__', segment, '')
+ let anchor_bold = s:safesubstitute(
+ \ vimwiki#vars#get_syntaxlocal('bold_match'),
+ \ '__Text__', segment, '')
+ let anchor_tag = s:safesubstitute(
+ \ vimwiki#vars#get_syntaxlocal('tag_match'),
+ \ '__Tag__', segment, '')
+
+ if !search(anchor_tag, 'Wc') && !search(anchor_header, 'Wc') && !search(anchor_bold, 'Wc')
+ call setpos('.', oldpos)
+ break
+ endif
+ let oldpos = getpos('.')
+ endfor
endfunction
-" }}}
-function! s:is_wiki_word(str) "{{{
- if a:str =~ g:vimwiki_rxWikiWord && a:str !~ '[[:space:]\\/]'
- return 1
+
+" Params: full path to a wiki file and its wiki number
+" Returns: a list of all links inside the wiki file
+" Every list item has the form
+" [target file, anchor, line number of the link in source file, column number]
+function! s:get_links(wikifile, idx)
+ if !filereadable(a:wikifile)
+ return []
endif
- return 0
+
+ let syntax = vimwiki#vars#get_wikilocal('syntax', a:idx)
+ let rx_link = vimwiki#vars#get_syntaxlocal('wikilink', syntax)
+ let links = []
+ let lnum = 0
+
+ for line in readfile(a:wikifile)
+ let lnum += 1
+
+ let link_count = 1
+ while 1
+ let col = match(line, rx_link, 0, link_count)+1
+ let link_text = matchstr(line, rx_link, 0, link_count)
+ if link_text == ''
+ break
+ endif
+ let link_count += 1
+ let target = vimwiki#base#resolve_link(link_text, a:wikifile)
+ if target.filename != '' && target.scheme =~# '\mwiki\d\+\|diary\|file\|local'
+ call add(links, [target.filename, target.anchor, lnum, col])
+ endif
+ endwhile
+ endfor
+
+ return links
endfunction
-" }}}
-function! vimwiki#base#edit_file(command, filename) "{{{
- let fname = escape(a:filename, '% ')
- call vimwiki#base#mkdir(fnamemodify(a:filename, ":p:h"))
- try
- execute a:command.' '.fname
- catch /E37/ " catch 'No write since last change' error
- execute ':split '.fname
- catch /E325/ " catch 'ATTENTION' error (:h E325)
- endtry
+
+function! vimwiki#base#check_links()
+ let anchors_of_files = {}
+ let links_of_files = {}
+ let errors = []
+ for idx in range(vimwiki#vars#number_of_wikis())
+ let syntax = vimwiki#vars#get_wikilocal('syntax', idx)
+ let wikifiles = vimwiki#base#find_files(idx, 0)
+ for wikifile in wikifiles
+ let links_of_files[wikifile] = s:get_links(wikifile, idx)
+ let anchors_of_files[wikifile] = vimwiki#base#get_anchors(wikifile, syntax)
+ endfor
+ endfor
+
+ for wikifile in keys(links_of_files)
+ for [target_file, target_anchor, lnum, col] in links_of_files[wikifile]
+ if target_file == '' && target_anchor == ''
+ call add(errors, {'filename':wikifile, 'lnum':lnum, 'col':col,
+ \ 'text': "numbered scheme refers to a non-existent wiki"})
+ elseif has_key(anchors_of_files, target_file)
+ if target_anchor != '' && index(anchors_of_files[target_file], target_anchor) < 0
+ call add(errors, {'filename':wikifile, 'lnum':lnum, 'col':col,
+ \'text': "there is no such anchor: ".target_anchor})
+ endif
+ else
+ if target_file =~ '\m/$' " maybe it's a link to a directory
+ if !isdirectory(target_file)
+ call add(errors, {'filename':wikifile, 'lnum':lnum, 'col':col,
+ \'text': "there is no such directory: ".target_file})
+ endif
+ else " maybe it's a non-wiki file
+ if filereadable(target_file)
+ let anchors_of_files[target_file] = []
+ else
+ call add(errors, {'filename':wikifile, 'lnum':lnum, 'col':col,
+ \'text': "there is no such file: ".target_file})
+ endif
+ endif
+ endif
+ endfor
+ endfor
+
+
+ " Check which wiki files are reachable from at least one of the index files.
+ " First, all index files are marked as reachable. Then, pick a reachable file
+ " and mark all files to which it links as reachable, too. Repeat until the
+ " links of all reachable files have been checked.
+
+ " Map every wiki file to a number. 0 means not reachable from any index file,
+ " 1 means reachable, but the outgoing links are not checked yet, 2 means
+ " reachable and done.
+ let reachable_wikifiles = {}
+
+ " first, all files are considered not reachable
+ for wikifile in keys(links_of_files)
+ let reachable_wikifiles[wikifile] = 0
+ endfor
+
+ " mark every index file as reachable
+ for idx in range(vimwiki#vars#number_of_wikis())
+ let index_file = vimwiki#vars#get_wikilocal('path', idx) .
+ \ vimwiki#vars#get_wikilocal('index', idx) . vimwiki#vars#get_wikilocal('ext', idx)
+ if filereadable(index_file)
+ let reachable_wikifiles[index_file] = 1
+ endif
+ endfor
+
+ while 1
+ let next_unvisited_wikifile = ''
+ for wf in keys(reachable_wikifiles)
+ if reachable_wikifiles[wf] == 1
+ let next_unvisited_wikifile = wf
+ let reachable_wikifiles[wf] = 2
+ break
+ endif
+ endfor
+ if next_unvisited_wikifile == ''
+ break
+ endif
+ for [target_file, target_anchor, lnum, col] in links_of_files[next_unvisited_wikifile]
+ if has_key(reachable_wikifiles, target_file) && reachable_wikifiles[target_file] == 0
+ let reachable_wikifiles[target_file] = 1
+ endif
+ endfor
+ endwhile
+
+ for wf in keys(reachable_wikifiles)
+ if reachable_wikifiles[wf] == 0
+ call add(errors, {'text':wf." is not reachable from the index file"})
+ endif
+ endfor
+
+ if empty(errors)
+ echomsg 'Vimwiki: All links are OK'
+ else
+ call setqflist(errors, 'r')
+ copen
+ endif
endfunction
-" }}}
-function! s:search_word(wikiRx, cmd) "{{{
+
+function! vimwiki#base#edit_file(command, filename, anchor, ...)
+ let fname = escape(a:filename, '% *|#`')
+ let dir = fnamemodify(a:filename, ":p:h")
+
+ let ok = vimwiki#path#mkdir(dir, 1)
+
+ if !ok
+ echomsg ' '
+ echomsg 'Vimwiki Error: Unable to edit file in non-existent directory: '.dir
+ return
+ endif
+
+ " Check if the file we want to open is already the current file
+ " which happens if we jump to an achor in the current file.
+ " This hack is necessary because apparently Vim messes up the result of
+ " getpos() directly after this command. Strange.
+ if !(a:command ==# ':e ' && vimwiki#path#is_equal(a:filename, expand('%:p')))
+ if &autowriteall && !&hidden " in this case, the file is saved before switching to the
+ " new buffer. This causes Vim to show two messages in the command line which triggers
+ " the annoying hit-enter prompt. Solution: show no messages at all.
+ silent execute a:command fname
+ else
+ try
+ execute a:command fname
+ catch /E37:/
+ echomsg 'Vimwiki: Can''t leave the current buffer, because it is modified. Hint: Take a look at'
+ \ ''':h g:vimwiki_autowriteall'' to see how to save automatically.'
+ return
+ catch /E325:/
+ echom 'Vimwiki: Vim couldn''t open the file, probably because a swapfile already exists. See :h E325.'
+ return
+ endtry
+ endif
+
+ " If the opened file was not already loaded by Vim, an autocommand is
+ " triggered at this point
+
+ " Make sure no other plugin takes ownership over the new file. Vimwiki
+ " rules them all! Well, except for directories, which may be opened with
+ " Netrw
+ if &filetype != 'vimwiki' && fname !~ '\m/$'
+ setfiletype vimwiki
+ endif
+ endif
+ if a:anchor != ''
+ call s:jump_to_anchor(a:anchor)
+ endif
+
+ " save previous link
+ " a:1 -- previous vimwiki link to save
+ " a:2 -- should we update previous link
+ if a:0 && a:2 && len(a:1) > 0
+ call vimwiki#vars#set_bufferlocal('prev_link', a:1)
+ endif
+endfunction
+
+
+function! vimwiki#base#search_word(wikiRx, cmd)
let match_line = search(a:wikiRx, 's'.a:cmd)
if match_line == 0
- echomsg "vimwiki: Wiki link not found."
+ echomsg 'Vimwiki: Wiki link not found'
endif
endfunction
-" }}}
-function! s:get_word_at_cursor(wikiRX) "{{{
+
+" Returns part of the line that matches wikiRX at cursor
+function! vimwiki#base#matchstr_at_cursor(wikiRX)
let col = col('.') - 1
let line = getline('.')
let ebeg = -1
@@ -256,65 +810,50 @@ function! s:get_word_at_cursor(wikiRX) "{{{
else
return ""
endif
-endf "}}}
+endfunction
-function! s:strip_word(word) "{{{
- let result = a:word
- if strpart(a:word, 0, 2) == "[["
- " get rid of [[ and ]]
- let w = strpart(a:word, 2, strlen(a:word)-4)
- if w =~ '|'
- " we want "link" from [[link|link desc]]
- let w = split(w, "|")[0]
- elseif w =~ ']['
- " we want "link" from [[link][link desc]]
- let w = split(w, "][")[0]
+function! vimwiki#base#replacestr_at_cursor(wikiRX, sub)
+ let col = col('.') - 1
+ let line = getline('.')
+ let ebeg = -1
+ let cont = match(line, a:wikiRX, 0)
+ while (ebeg >= 0 || (0 <= cont) && (cont <= col))
+ let contn = matchend(line, a:wikiRX, cont)
+ if (cont <= col) && (col < contn)
+ let ebeg = match(line, a:wikiRX, cont)
+ let elen = contn - ebeg
+ break
+ else
+ let cont = match(line, a:wikiRX, contn)
endif
-
- let result = vimwiki#base#safe_link(w)
+ endwh
+ if ebeg >= 0
+ " TODO: There might be problems with Unicode chars...
+ let newline = strpart(line, 0, ebeg).a:sub.strpart(line, ebeg+elen)
+ call setline(line('.'), newline)
endif
- return result
endfunction
-" }}}
-
-function! vimwiki#base#is_non_wiki_link(lnk) "{{{
- let exts = '.\+\.\%('.
- \ join(split(g:vimwiki_file_exts, '\s*,\s*'), '\|').
- \ '\)$'
- if a:lnk =~ exts
- return 1
- endif
- return 0
-endfunction "}}}
-function! vimwiki#base#is_link_to_dir(link) "{{{
- " Check if link is to a directory.
- " It should be ended with \ or /.
- if a:link =~ '.\+[/\\]$'
- return 1
- endif
- return 0
-endfunction " }}}
-function! s:print_wiki_list() "{{{
+function! s:print_wiki_list()
let idx = 0
- while idx < len(g:vimwiki_list)
- if idx == g:vimwiki_current_idx
+ while idx < vimwiki#vars#number_of_wikis()
+ if idx == vimwiki#vars#get_bufferlocal('wiki_nr')
let sep = ' * '
echohl PmenuSel
else
let sep = ' '
echohl None
endif
- echo (idx + 1).sep.VimwikiGet('path', idx)
+ echo (idx + 1) . sep . vimwiki#vars#get_wikilocal('path', idx)
let idx += 1
endwhile
echohl None
endfunction
-" }}}
-function! s:update_wiki_link(fname, old, new) " {{{
+
+function! s:update_wiki_link(fname, old, new)
echo "Updating links in ".a:fname
let has_updates = 0
let dest = []
@@ -322,6 +861,7 @@ function! s:update_wiki_link(fname, old, new) " {{{
if !has_updates && match(line, a:old) != -1
let has_updates = 1
endif
+ " XXX: any other characters to escape!?
call add(dest, substitute(line, a:old, escape(a:new, "&"), "g"))
endfor
" add exception handling...
@@ -331,44 +871,37 @@ function! s:update_wiki_link(fname, old, new) " {{{
call delete(a:fname.'#vimwiki_upd#')
endif
endfunction
-" }}}
-function! s:update_wiki_links_dir(dir, old_fname, new_fname) " {{{
+
+function! s:update_wiki_links_dir(wiki_nr, dir, old_fname, new_fname)
let old_fname = substitute(a:old_fname, '[/\\]', '[/\\\\]', 'g')
let new_fname = a:new_fname
- let old_fname_r = old_fname
- let new_fname_r = new_fname
- if !s:is_wiki_word(new_fname) && s:is_wiki_word(old_fname)
- let new_fname_r = '[['.new_fname.']]'
- endif
+ let old_fname_r = vimwiki#base#apply_template(
+ \ vimwiki#vars#get_syntaxlocal('WikiLinkMatchUrlTemplate',
+ \ vimwiki#vars#get_wikilocal('syntax', a:wiki_nr)), old_fname, '', '')
- if !s:is_wiki_word(old_fname)
- let old_fname_r = '\[\[\zs'.vimwiki#base#unsafe_link(old_fname).
- \ '\ze\%(|.*\)\?\%(\]\[.*\)\?\]\]'
- else
- let old_fname_r = '!\@'
- endif
-
- let files = split(glob(VimwikiGet('path').a:dir.'*'.VimwikiGet('ext')), '\n')
- for fname in files
- call s:update_wiki_link(fname, old_fname_r, new_fname_r)
+ let files = split(glob(vimwiki#vars#get_wikilocal('path', a:wiki_nr).a:dir.'*'.
+ \ vimwiki#vars#get_wikilocal('ext', a:wiki_nr)), '\n')
+ for fname in l:files
+ call s:update_wiki_link(fname, old_fname_r, new_fname)
endfor
endfunction
-" }}}
-function! s:tail_name(fname) "{{{
+
+function! s:tail_name(fname)
let result = substitute(a:fname, ":", "__colon__", "g")
let result = fnamemodify(result, ":t:r")
let result = substitute(result, "__colon__", ":", "g")
return result
-endfunction "}}}
+endfunction
+
-function! s:update_wiki_links(old_fname, new_fname) " {{{
- let old_fname = s:tail_name(a:old_fname)
- let new_fname = s:tail_name(a:new_fname)
+function! s:update_wiki_links(wiki_nr, old_fname, new_fname,old_fname_relpath)
+ let old_fname = a:old_fname
+ let new_fname = a:new_fname
- let subdirs = split(a:old_fname, '[/\\]')[: -2]
+ let subdirs = split(a:old_fname_relpath, '[/\\]')[: -2]
" TODO: Use Dictionary here...
let dirs_keys = ['']
@@ -390,158 +923,40 @@ function! s:update_wiki_links(old_fname, new_fname) " {{{
while idx < len(dirs_keys)
let dir = dirs_keys[idx]
let new_dir = dirs_vals[idx]
- call s:update_wiki_links_dir(dir,
- \ new_dir.old_fname, new_dir.new_fname)
+ call s:update_wiki_links_dir(a:wiki_nr, dir, new_dir.old_fname, new_dir.new_fname)
let idx = idx + 1
endwhile
-endfunction " }}}
+endfunction
-function! s:get_wiki_buffers() "{{{
+
+function! s:get_wiki_buffers()
let blist = []
let bcount = 1
while bcount<=bufnr("$")
if bufexists(bcount)
let bname = fnamemodify(bufname(bcount), ":p")
- if bname =~ VimwikiGet('ext')."$"
- let bitem = [bname, getbufvar(bname, "vimwiki_prev_link")]
+ " this may find buffers that are not part of the current wiki, but that
+ " doesn't hurt
+ if bname =~# vimwiki#vars#get_wikilocal('ext')."$"
+ let bitem = [bname, vimwiki#vars#get_bufferlocal('prev_link', bcount)]
call add(blist, bitem)
endif
endif
let bcount = bcount + 1
endwhile
return blist
-endfunction " }}}
-
-function! s:open_wiki_buffer(item) "{{{
- call vimwiki#base#edit_file(':e', a:item[0])
- if !empty(a:item[1])
- call setbufvar(a:item[0], "vimwiki_prev_link", a:item[1])
- endif
-endfunction " }}}
-
-" }}}
-
-" SYNTAX highlight {{{
-function! vimwiki#base#highlight_links() "{{{
- try
- syntax clear VimwikiNoExistsLink
- syntax clear VimwikiNoExistsLinkT
- syntax clear VimwikiLink
- syntax clear VimwikiLinkT
- catch
- endtry
-
- "" use max highlighting - could be quite slow if there are too many wikifiles
- if VimwikiGet('maxhi')
- " Every WikiWord is nonexistent
- if g:vimwiki_camel_case
- execute 'syntax match VimwikiNoExistsLink /'.g:vimwiki_rxWikiWord.'/ display'
- execute 'syntax match VimwikiNoExistsLinkT /'.g:vimwiki_rxWikiWord.'/ display contained'
- endif
- execute 'syntax match VimwikiNoExistsLink /'.g:vimwiki_rxWikiLink1.'/ display contains=VimwikiNoLinkChar'
- execute 'syntax match VimwikiNoExistsLink /'.g:vimwiki_rxWikiLink2.'/ display contains=VimwikiNoLinkChar'
-
- execute 'syntax match VimwikiNoExistsLinkT /'.g:vimwiki_rxWikiLink1.'/ display contained'
- execute 'syntax match VimwikiNoExistsLinkT /'.g:vimwiki_rxWikiLink2.'/ display contained'
-
- " till we find them in vimwiki's path
- call s:highlight_existed_links()
- else
- " A WikiWord (unqualifiedWikiName)
- execute 'syntax match VimwikiLink /\<'.g:vimwiki_rxWikiWord.'\>/'
- " A [[bracketed wiki word]]
- execute 'syntax match VimwikiLink /'.g:vimwiki_rxWikiLink1.'/ display contains=VimwikiLinkChar'
- execute 'syntax match VimwikiLink /'.g:vimwiki_rxWikiLink2.'/ display contains=VimwikiLinkChar'
-
- execute 'syntax match VimwikiLinkT /\<'.g:vimwiki_rxWikiWord.'\>/ display contained'
- execute 'syntax match VimwikiLinkT /'.g:vimwiki_rxWikiLink1.'/ display contained'
- execute 'syntax match VimwikiLinkT /'.g:vimwiki_rxWikiLink2.'/ display contained'
- endif
-
- execute 'syntax match VimwikiLink `'.g:vimwiki_rxWeblink.'` display contains=@NoSpell'
-endfunction "}}}
-
-function! s:highlight_existed_links() "{{{
- let links = s:get_links('*'.VimwikiGet('ext'))
-
- " Links with subdirs should be highlighted for linux and windows separators
- " Change \ or / to [/\\]
- let os_p = '[/\\]'
- let os_p2 = escape(os_p, '\')
- call map(links, 'substitute(v:val, os_p, os_p2, "g")')
-
- for link in links
- if g:vimwiki_camel_case &&
- \ link =~ g:vimwiki_rxWikiWord && !vimwiki#base#is_non_wiki_link(link)
- execute 'syntax match VimwikiLink /!\@/ display'
- endif
- execute 'syntax match VimwikiLink /\[\['.
- \ escape(vimwiki#base#unsafe_link(link), '~&$.*').
- \ '\%(|\+.\{-}\)\{-}\]\]/ display contains=VimwikiLinkChar'
- execute 'syntax match VimwikiLink /\[\['.
- \ escape(vimwiki#base#unsafe_link(link), '~&$.*').
- \ '\]\[.\{-1,}\]\]/ display contains=VimwikiLinkChar'
-
- execute 'syntax match VimwikiLinkT /\[\['.
- \ escape(vimwiki#base#unsafe_link(link), '~&$.*').
- \ '\%(|\+.\{-}\)\{-}\]\]/ display contained'
- execute 'syntax match VimwikiLinkT /\[\['.
- \ escape(vimwiki#base#unsafe_link(link), '~&$.*').
- \ '\]\[.\{-1,}\]\]/ display contained'
- endfor
- execute 'syntax match VimwikiLink /\[\[.\+\.\%(jpg\|png\|gif\)\%(|\+.*\)*\]\]/ display contains=VimwikiLinkChar'
- execute 'syntax match VimwikiLink /\[\[.\+\.\%(jpg\|png\|gif\)\]\[.\+\]\]/ display contains=VimwikiLinkChar'
-
- execute 'syntax match VimwikiLinkT /\[\[.\+\.\%(jpg\|png\|gif\)\%(|\+.*\)*\]\]/ display contained'
- execute 'syntax match VimwikiLinkT /\[\[.\+\.\%(jpg\|png\|gif\)\]\[.\+\]\]/ display contained'
-
- " Issue 103: Always highlight links to non-wiki files as existed.
- execute 'syntax match VimwikiLink /\[\[.\+\.\%('.
- \join(split(g:vimwiki_file_exts, '\s*,\s*'), '\|').
- \'\)\%(|\+.*\)*\]\]/ display contains=VimwikiLinkChar'
- execute 'syntax match VimwikiLink /\[\[.\+\.\%('.
- \join(split(g:vimwiki_file_exts, '\s*,\s*'), '\|').
- \'\)\]\[.\+\]\]/ display contains=VimwikiLinkChar'
-
- execute 'syntax match VimwikiLinkT /\[\[.\+\.\%('.
- \join(split(g:vimwiki_file_exts, '\s*,\s*'), '\|').
- \'\)\%(|\+.*\)*\]\]/ display contained'
- execute 'syntax match VimwikiLinkT /\[\[.\+\.\%('.
- \join(split(g:vimwiki_file_exts, '\s*,\s*'), '\|').
- \'\)\]\[.\+\]\]/ display contained'
-
- " highlight dirs
- let dirs = s:get_links('*/')
- call map(dirs, 'substitute(v:val, os_p, os_p2, "g")')
- for dir in dirs
- execute 'syntax match VimwikiLink /\[\['.
- \ escape(vimwiki#base#unsafe_link(dir), '~&$.*').
- \ '[/\\]*\%(|\+.*\)*\]\]/ display contains=VimwikiLinkChar'
- execute 'syntax match VimwikiLink /\[\['.
- \ escape(vimwiki#base#unsafe_link(dir), '~&$.*').
- \ '[/\\]*\%(\]\[\+.*\)*\]\]/ display contains=VimwikiLinkChar'
-
- execute 'syntax match VimwikiLinkT /\[\['.
- \ escape(vimwiki#base#unsafe_link(dir), '~&$.*').
- \ '[/\\]*\%(|\+.*\)*\]\]/ display contained'
- execute 'syntax match VimwikiLinkT /\[\['.
- \ escape(vimwiki#base#unsafe_link(dir), '~&$.*').
- \ '[/\\]*\%(\]\[\+.*\)*\]\]/ display contained'
- endfor
-endfunction "}}}
+endfunction
-function! vimwiki#base#hl_exists(hl) "{{{
- if !hlexists(a:hl)
- return 0
+
+function! s:open_wiki_buffer(item)
+ call vimwiki#base#edit_file(':e', a:item[0], '')
+ if !empty(a:item[1])
+ call vimwiki#vars#set_bufferlocal('prev_link', a:item[1], a:item[0])
endif
- redir => hlstatus
- exe "silent hi" a:hl
- redir END
- return (hlstatus !~ "cleared")
endfunction
-"}}}
-function! vimwiki#base#nested_syntax(filetype, start, end, textSnipHl) abort "{{{
+
+function! vimwiki#base#nested_syntax(filetype, start, end, textSnipHl) abort
" From http://vim.wikia.com/wiki/VimTip857
let ft=toupper(a:filetype)
let group='textGroup'.ft
@@ -557,8 +972,9 @@ function! vimwiki#base#nested_syntax(filetype, start, end, textSnipHl) abort "{{
" let b:skip_set_iskeyword = 1
let is_keyword = &iskeyword
- execute 'syntax include @'.group.' syntax/'.a:filetype.'.vim'
try
+ " keep going even if syntax file is not found
+ execute 'syntax include @'.group.' syntax/'.a:filetype.'.vim'
execute 'syntax include @'.group.' after/syntax/'.a:filetype.'.vim'
catch
endtry
@@ -570,6 +986,14 @@ function! vimwiki#base#nested_syntax(filetype, start, end, textSnipHl) abort "{{
else
unlet b:current_syntax
endif
+
+ " Fix issue #236: tell Vimwiki to think in maths when encountering maths
+ " blocks like {{$ }}$. Here, we don't want the tex highlight group, but the
+ " group for tex math.
+ if a:textSnipHl ==# 'VimwikiMath'
+ let group='texMathZoneGroup'
+ endif
+
execute 'syntax region textSnip'.ft.
\ ' matchgroup='.a:textSnipHl.
\ ' start="'.a:start.'" end="'.a:end.'"'.
@@ -579,154 +1003,340 @@ function! vimwiki#base#nested_syntax(filetype, start, end, textSnipHl) abort "{{
" regular one.
" Perl syntax file has perlFunctionName which is usually has no effect due to
" 'contained' flag. Now we have 'syntax include' that makes all the groups
- " included as 'contained' into specific group.
+ " included as 'contained' into specific group.
" Here perlFunctionName (with quite an angry regexp "\h\w*[^:]") clashes with
" the rest syntax rules as now it has effect being really 'contained'.
" Clear it!
- if ft =~ 'perl'
- syntax clear perlFunctionName
+ if ft =~? 'perl'
+ syntax clear perlFunctionName
+ endif
+endfunction
+
+
+" creates or updates auto-generated listings in a wiki file, like TOC, diary
+" links, tags list etc.
+" - the listing consists of a level 1 header and a list of strings as content
+" - a:content_regex is used to determine how long a potentially existing list is
+" - a:default_lnum is the line number where the new listing should be placed if
+" it's not already present
+" - if a:create is true, it will be created if it doesn't exist, otherwise it
+" will only be updated if it already exists
+function! vimwiki#base#update_listing_in_buffer(strings, start_header,
+ \ content_regex, default_lnum, create)
+ " Vim behaves strangely when files change while in diff mode
+ if &diff || &readonly
+ return
+ endif
+
+ " check if the listing is already there
+ let already_there = 0
+
+ let header_rx = '\m^\s*'.substitute(vimwiki#vars#get_syntaxlocal('rxH1_Template'),
+ \ '__Header__', a:start_header, '') .'\s*$'
+
+ let start_lnum = 1
+ while start_lnum <= line('$')
+ if getline(start_lnum) =~# header_rx
+ let already_there = 1
+ break
+ endif
+ let start_lnum += 1
+ endwhile
+
+ if !already_there && !a:create
+ return
+ endif
+
+ let winview_save = winsaveview()
+ let cursor_line = winview_save.lnum
+ let is_cursor_after_listing = 0
+
+ let is_fold_closed = 1
+
+ let lines_diff = 0
+
+ if already_there
+ let is_fold_closed = ( foldclosed(start_lnum) > -1 )
+ " delete the old listing
+ let whitespaces_in_first_line = matchstr(getline(start_lnum), '\m^\s*')
+ let end_lnum = start_lnum + 1
+ while end_lnum <= line('$') && getline(end_lnum) =~# a:content_regex
+ let end_lnum += 1
+ endwhile
+ let is_cursor_after_listing = ( cursor_line >= end_lnum )
+ " We'll be removing a range. But, apparently, if folds are enabled, Vim
+ " won't let you remove a range that overlaps with closed fold -- the entire
+ " fold gets deleted. So we temporarily disable folds, and then reenable
+ " them right back.
+ let foldenable_save = &l:foldenable
+ setlocal nofoldenable
+ silent exe 'keepjumps ' . start_lnum.','.string(end_lnum - 1).'delete _'
+ let &l:foldenable = foldenable_save
+ let lines_diff = 0 - (end_lnum - start_lnum)
+ else
+ let start_lnum = a:default_lnum
+ let is_cursor_after_listing = ( cursor_line > a:default_lnum )
+ let whitespaces_in_first_line = ''
+ endif
+
+ let start_of_listing = start_lnum
+
+ " write new listing
+ let new_header = whitespaces_in_first_line
+ \ . s:safesubstitute(vimwiki#vars#get_syntaxlocal('rxH1_Template'),
+ \ '__Header__', a:start_header, '')
+ keepjumps call append(start_lnum - 1, new_header)
+ let start_lnum += 1
+ let lines_diff += 1 + len(a:strings)
+ for string in a:strings
+ keepjumps call append(start_lnum - 1, string)
+ let start_lnum += 1
+ endfor
+ " append an empty line if there is not one
+ if start_lnum <= line('$') && getline(start_lnum) !~# '\m^\s*$'
+ keepjumps call append(start_lnum - 1, '')
+ let lines_diff += 1
+ endif
+
+ " Open fold, if needed
+ if !is_fold_closed && ( foldclosed(start_of_listing) > -1 )
+ exe start_of_listing
+ norm! zo
endif
-endfunction "}}}
-"}}}
+ if is_cursor_after_listing
+ let winview_save.lnum += lines_diff
+ endif
+ call winrestview(winview_save)
+endfunction
-" WIKI functions {{{
-function! vimwiki#base#find_next_link() "{{{
- call s:search_word(g:vimwiki_rxWikiLink.'\|'.g:vimwiki_rxWeblink, '')
+
+function! vimwiki#base#find_next_link()
+ call vimwiki#base#search_word(vimwiki#vars#get_syntaxlocal('rxAnyLink'), '')
endfunction
-" }}}
-function! vimwiki#base#find_prev_link() "{{{
- call s:search_word(g:vimwiki_rxWikiLink.'\|'.g:vimwiki_rxWeblink, 'b')
+
+function! vimwiki#base#find_prev_link()
+ "Jump 2 times if the cursor is in the middle of a link
+ if synIDattr(synID(line('.'), col('.'), 0), "name") =~# "VimwikiLink.*" &&
+ \ synIDattr(synID(line('.'), col('.')-1, 0), "name") =~# "VimwikiLink.*"
+ call vimwiki#base#search_word(vimwiki#vars#get_syntaxlocal('rxAnyLink'), 'b')
+ endif
+ call vimwiki#base#search_word(vimwiki#vars#get_syntaxlocal('rxAnyLink'), 'b')
endfunction
-" }}}
-function! vimwiki#base#follow_link(split) "{{{
- if a:split == "split"
- let cmd = ":split "
- elseif a:split == "vsplit"
- let cmd = ":vsplit "
- elseif a:split == "tabnew"
- let cmd = ":tabnew "
- else
- let cmd = ":e "
+
+function! vimwiki#base#follow_link(split, ...)
+ let reuse_other_split_window = a:0 >= 1 ? a:1 : 0
+ let move_cursor_to_new_window = a:0 >= 2 ? a:2 : 1
+
+ " Parse link at cursor and pass to VimwikiLinkHandler, or failing that, the
+ " default open_link handler
+
+ " try WikiLink
+ let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink')),
+ \ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'))
+ " try WikiIncl
+ if lnk == ""
+ let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWikiIncl')),
+ \ vimwiki#vars#get_global('rxWikiInclMatchUrl'))
+ endif
+ " try Weblink
+ if lnk == ""
+ let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink')),
+ \ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'))
endif
- let link = s:strip_word(s:get_word_at_cursor(g:vimwiki_rxWikiLink))
- if link == ""
- let weblink = s:strip_word(s:get_word_at_cursor(g:vimwiki_rxWeblink))
- if weblink != ""
- call VimwikiWeblinkHandler(escape(weblink, '#'))
+ if lnk != "" " cursor is indeed on a link
+ let processed_by_user_defined_handler = VimwikiLinkHandler(lnk)
+ if processed_by_user_defined_handler
+ return
+ endif
+
+ if a:split ==# "hsplit"
+ let cmd = ":split "
+ elseif a:split ==# "vsplit"
+ let cmd = ":vsplit "
+ elseif a:split ==# "tab"
+ let cmd = ":tabnew "
else
- execute "normal! \n"
+ let cmd = ":e "
+ endif
+
+ " if we want to and can reuse a split window, jump to that window and open
+ " the new file there
+ if (a:split ==# 'hsplit' || a:split ==# 'vsplit') && reuse_other_split_window
+ let previous_window_nr = winnr('#')
+ if previous_window_nr > 0 && previous_window_nr != winnr()
+ execute previous_window_nr . 'wincmd w'
+ let cmd = ':e'
+ endif
+ endif
+
+
+ if vimwiki#vars#get_wikilocal('syntax') == 'markdown'
+ let processed_by_markdown_reflink = vimwiki#markdown_base#open_reflink(lnk)
+ if processed_by_markdown_reflink
+ return
+ endif
+
+ " remove the extension from the filename if exists, because non-vimwiki
+ " markdown files usually include the extension in links
+ let lnk = substitute(lnk, '\'.vimwiki#vars#get_wikilocal('ext').'$', '', '')
+ endif
+
+ let current_tab_page = tabpagenr()
+
+ call vimwiki#base#open_link(cmd, lnk)
+
+ if !move_cursor_to_new_window
+ if (a:split ==# 'hsplit' || a:split ==# 'vsplit')
+ execute 'wincmd p'
+ elseif a:split ==# 'tab'
+ execute 'tabnext ' . current_tab_page
+ endif
+ endif
+
+ else
+ if a:0 >= 3
+ execute "normal! ".a:3
+ else
+ call vimwiki#base#normalize_link(0)
endif
- return
endif
+endfunction
+
+
+function! vimwiki#base#go_back_link()
+ let prev_link = vimwiki#vars#get_bufferlocal('prev_link')
+ if !empty(prev_link)
+ " go back to saved wiki link
+ call vimwiki#base#edit_file(':e ', prev_link[0], '')
+ call setpos('.', prev_link[1])
+ else
+ " maybe we came here by jumping to a tag -> pop from the tag stack
+ silent! pop!
+ endif
+endfunction
- let subdir = vimwiki#base#current_subdir()
- call vimwiki#base#open_link(cmd, subdir.link)
-endfunction " }}}
+function! vimwiki#base#goto_index(wnum, ...)
+ if a:wnum > vimwiki#vars#number_of_wikis()
+ echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in your Vimwiki settings!'
+ return
+ endif
+
+ " usually a:wnum is greater then 0 but with the following command it is == 0:
+ " vim -n -c ":VimwikiIndex"
+ if a:wnum > 0
+ let idx = a:wnum - 1
+ else
+ let idx = 0
+ endif
-function! vimwiki#base#go_back_link() "{{{
- if exists("b:vimwiki_prev_link")
- " go back to saved WikiWord
- let prev_word = b:vimwiki_prev_link
- execute ":e ".substitute(prev_word[0], '\s', '\\\0', 'g')
- call setpos('.', prev_word[1])
+ if a:0
+ if a:1 == 1
+ let cmd = 'tabedit'
+ elseif a:1 == 2
+ let cmd = 'split'
+ elseif a:1 == 3
+ let cmd = 'vsplit'
+ endif
+ else
+ let cmd = 'edit'
endif
-endfunction " }}}
-function! vimwiki#base#goto_index(index) "{{{
- call vimwiki#base#select(a:index)
- call vimwiki#base#edit_file('e',
- \ VimwikiGet('path').VimwikiGet('index').VimwikiGet('ext'))
-endfunction "}}}
+ let index_file = vimwiki#vars#get_wikilocal('path', idx).
+ \ vimwiki#vars#get_wikilocal('index', idx).
+ \ vimwiki#vars#get_wikilocal('ext', idx)
+
+ call vimwiki#base#edit_file(cmd, index_file, '')
+endfunction
+
-function! vimwiki#base#delete_link() "{{{
- "" file system funcs
- "" Delete WikiWord you are in from filesystem
- let val = input('Delete ['.expand('%').'] (y/n)? ', "")
- if val != 'y'
+function! vimwiki#base#delete_link()
+ " Delete wiki file you are in from filesystem
+ let val = input('Delete "'.expand('%').'" [y]es/[N]o? ')
+ if val !~? '^y'
return
endif
let fname = expand('%:p')
try
call delete(fname)
catch /.*/
- echomsg 'vimwiki: Cannot delete "'.expand('%:t:r').'"!'
+ echomsg 'Vimwiki Error: Cannot delete "'.expand('%:t:r').'"!'
return
endtry
+
+ call vimwiki#base#go_back_link()
execute "bdelete! ".escape(fname, " ")
- " reread buffer => deleted WikiWord should appear as non-existent
+ " reread buffer => deleted wiki link should appear as non-existent
if expand('%:p') != ""
execute "e"
endif
-endfunction "}}}
+endfunction
+
-function! vimwiki#base#rename_link() "{{{
- "" Rename WikiWord, update all links to renamed WikiWord
- let subdir = vimwiki#base#current_subdir()
+" Rename current file, update all links to it
+function! vimwiki#base#rename_link()
+ let subdir = vimwiki#vars#get_bufferlocal('subdir')
let old_fname = subdir.expand('%:t')
" there is no file (new one maybe)
if glob(expand('%:p')) == ''
- echomsg 'vimwiki: Cannot rename "'.expand('%:p').
+ echomsg 'Vimwiki Error: Cannot rename "'.expand('%:p').
\'". It does not exist! (New file? Save it before renaming.)'
return
endif
- let val = input('Rename "'.expand('%:t:r').'" (y/n)? ', "")
- if val!='y'
+ let val = input('Rename "'.expand('%:t:r').'" [y]es/[N]o? ')
+ if val !~? '^y'
return
endif
- let new_link = input('Enter new name: ', "")
+ let new_link = input('Enter new name: ')
- if new_link =~ '[/\\]'
- " It is actually doable but I do not have free time to do it.
- echomsg 'vimwiki: Cannot rename to a filename with path!'
+ if new_link =~# '[/\\]'
+ echomsg 'Vimwiki Error: Cannot rename to a filename with path!'
return
endif
- " check new_fname - it should be 'good', not empty
if substitute(new_link, '\s', '', 'g') == ''
- echomsg 'vimwiki: Cannot rename to an empty filename!'
+ echomsg 'Vimwiki Error: Cannot rename to an empty filename!'
return
endif
- if vimwiki#base#is_non_wiki_link(new_link)
- echomsg 'vimwiki: Cannot rename to a filename with extension (ie .txt .html)!'
- return
+
+ let url = matchstr(new_link, vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'))
+ if url != ''
+ let new_link = url
endif
let new_link = subdir.new_link
- let new_link = s:strip_word(new_link)
- let new_fname = VimwikiGet('path').s:filename(new_link).VimwikiGet('ext')
+ let wiki_nr = vimwiki#vars#get_bufferlocal("wiki_nr")
+ let new_fname = vimwiki#vars#get_wikilocal('path') . new_link . vimwiki#vars#get_wikilocal('ext')
- " do not rename if word with such name exists
+ " do not rename if file with such name exists
let fname = glob(new_fname)
if fname != ''
- echomsg 'vimwiki: Cannot rename to "'.new_fname.
- \ '". File with that name exist!'
+ echomsg 'Vimwiki Error: Cannot rename to "'.new_fname.'". File with that name exist!'
return
endif
- " rename WikiWord file
+ " rename wiki link file
try
- echomsg "Renaming ".VimwikiGet('path').old_fname." to ".new_fname
+ echomsg 'Vimwiki: Renaming '.vimwiki#vars#get_wikilocal('path').old_fname.' to '.new_fname
let res = rename(expand('%:p'), expand(new_fname))
if res != 0
throw "Cannot rename!"
end
catch /.*/
- echomsg 'vimwiki: Cannot rename "'.expand('%:t:r').'" to "'.new_fname.'"'
+ echomsg 'Vimwiki Error: Cannot rename "'.expand('%:t:r').'" to "'.new_fname.'"'
return
endtry
let &buftype="nofile"
- let cur_buffer = [expand('%:p'),
- \getbufvar(expand('%:p'), "vimwiki_prev_link")]
+ let cur_buffer = [expand('%:p'), vimwiki#vars#get_bufferlocal('prev_link')]
let blist = s:get_wiki_buffers()
@@ -747,25 +1357,25 @@ function! vimwiki#base#rename_link() "{{{
setlocal nomore
" update links
- call s:update_wiki_links(old_fname, new_link)
+ call s:update_wiki_links(wiki_nr, s:tail_name(old_fname), s:tail_name(new_link),old_fname)
" restore wiki buffers
for bitem in blist
- if bitem[0] != cur_buffer[0]
+ if !vimwiki#path#is_equal(bitem[0], cur_buffer[0])
call s:open_wiki_buffer(bitem)
endif
endfor
- call s:open_wiki_buffer([new_fname,
- \ cur_buffer[1]])
+ call s:open_wiki_buffer([new_fname, cur_buffer[1]])
" execute 'bwipeout '.escape(cur_buffer[0], ' ')
- echomsg old_fname." is renamed to ".new_fname
+ echomsg 'Vimwiki: '.old_fname.' is renamed to '.new_fname
let &more = setting_more
-endfunction " }}}
+endfunction
+
-function! vimwiki#base#ui_select()"{{{
+function! vimwiki#base#ui_select()
call s:print_wiki_list()
let idx = input("Select Wiki (specify number): ")
if idx == ""
@@ -773,56 +1383,62 @@ function! vimwiki#base#ui_select()"{{{
endif
call vimwiki#base#goto_index(idx)
endfunction
-"}}}
-" }}}
-" TEXT OBJECTS functions {{{
-
-function! vimwiki#base#TO_header(inner, visual) "{{{
- if !search('^\(=\+\).\+\1\s*$', 'bcW')
+function! vimwiki#base#TO_header(inner, including_subheaders, count)
+ let headers = s:collect_headers()
+ if empty(headers)
return
endif
-
- let sel_start = line("'<")
- let sel_end = line("'>")
- let block_start = line(".")
- let advance = 0
- let level = vimwiki#base#count_first_sym(getline('.'))
+ let current_line = line('.')
- let is_header_selected = sel_start == block_start
- \ && sel_start != sel_end
+ let current_header_index = s:current_header(headers, current_line)
- if a:visual && is_header_selected
- if level > 1
- let level -= 1
- call search('^\(=\{'.level.'\}\).\+\1\s*$', 'bcW')
- else
- let advance = 1
- endif
+ if current_header_index < 0
+ return
endif
- normal! V
+ " from which to which header
+ if !a:including_subheaders && a:count <= 1
+ let first_line = headers[current_header_index][0]
+ let last_line = current_header_index == len(headers)-1 ? line('$') :
+ \ headers[current_header_index + 1][0] - 1
+ else
+ let first_header_index = current_header_index
+ for _ in range(a:count - 1)
+ let parent = s:get_another_header(headers, first_header_index, -1, '<')
+ if parent < 0
+ break
+ else
+ let first_header_index = parent
+ endif
+ endfor
- if a:visual && is_header_selected
- call cursor(sel_end + advance, 0)
+ let next_sibling_or_higher = s:get_another_header(headers, first_header_index, +1, '<=')
+
+ let first_line = headers[first_header_index][0]
+ let last_line =
+ \ next_sibling_or_higher >= 0 ? headers[next_sibling_or_higher][0] - 1 : line('$')
endif
- if search('^\(=\{1,'.level.'}\).\+\1\s*$', 'W')
- call cursor(line('.') - 1, 0)
- else
- call cursor(line('$'), 0)
+ if a:inner
+ let first_line += 1
+ let last_line = prevnonblank(last_line)
endif
- if a:inner && getline(line('.')) =~ '^\s*$'
- let lnum = prevnonblank(line('.') - 1)
- call cursor(lnum, 0)
+ if first_line > last_line
+ " this can happen e.g. when doing vih on a header with another header in the very next line
+ return
endif
+
+ call cursor(first_line, 1)
+ normal! V
+ call cursor(last_line, 1)
endfunction
-"}}}
-function! vimwiki#base#TO_table_cell(inner, visual) "{{{
+
+function! vimwiki#base#TO_table_cell(inner, visual)
if col('.') == col('$')-1
return
endif
@@ -866,7 +1482,7 @@ function! vimwiki#base#TO_table_cell(inner, visual) "{{{
" XXX: WORKAROUND.
" if blockwise selection is ended at | character then pressing j to extend
- " selection furhter fails. But if we shake the cursor left and right then
+ " selection further fails. But if we shake the cursor left and right then
" it works.
normal! hl
else
@@ -884,10 +1500,11 @@ function! vimwiki#base#TO_table_cell(inner, visual) "{{{
normal! 2h
endif
endif
-endfunction "}}}
+endfunction
+
-function! vimwiki#base#TO_table_col(inner, visual) "{{{
- let t_rows = vimwiki_tbl#get_rows(line('.'))
+function! vimwiki#base#TO_table_col(inner, visual)
+ let t_rows = vimwiki#tbl#get_rows(line('.'))
if empty(t_rows)
return
endif
@@ -903,14 +1520,14 @@ function! vimwiki#base#TO_table_col(inner, visual) "{{{
if firsttime
" place cursor to the top row of the table
- call s:cursor(t_rows[0][0], virtcol('.'))
+ call vimwiki#u#cursor(t_rows[0][0], virtcol('.'))
" do not accept the match at cursor position if cursor is next to column
" separator of the table separator (^ is a cursor):
" |-----^-+-------|
" | bla | bla |
" |-------+-------|
" or it will select wrong column.
- if strpart(getline('.'), virtcol('.')-1) =~ '^-+'
+ if strpart(getline('.'), virtcol('.')-1) =~# '^-+'
let s_flag = 'b'
else
let s_flag = 'cb'
@@ -933,7 +1550,7 @@ function! vimwiki#base#TO_table_col(inner, visual) "{{{
normal! `>
if !firsttime && getline('.')[virtcol('.')] == '|'
normal! l
- elseif a:inner && getline('.')[virtcol('.')+1] =~ '[|+]'
+ elseif a:inner && getline('.')[virtcol('.')+1] =~# '[|+]'
normal! 2l
endif
" search for the next column separator
@@ -948,7 +1565,7 @@ function! vimwiki#base#TO_table_col(inner, visual) "{{{
normal! h
endif
" expand selection to the bottom line of the table
- call s:cursor(t_rows[-1][0], virtcol('.'))
+ call vimwiki#u#cursor(t_rows[-1][0], virtcol('.'))
let sel_end = getpos('.')
call setpos('.', sel_start)
@@ -957,14 +1574,14 @@ function! vimwiki#base#TO_table_col(inner, visual) "{{{
else
" place cursor to the top row of the table
- call s:cursor(t_rows[0][0], virtcol('.'))
+ call vimwiki#u#cursor(t_rows[0][0], virtcol('.'))
" do not accept the match at cursor position if cursor is next to column
" separator of the table separator (^ is a cursor):
" |-----^-+-------|
" | bla | bla |
" |-------+-------|
" or it will select wrong column.
- if strpart(getline('.'), virtcol('.')-1) =~ '^-+'
+ if strpart(getline('.'), virtcol('.')-1) =~# '^-+'
let s_flag = 'b'
else
let s_flag = 'cb'
@@ -996,61 +1613,484 @@ function! vimwiki#base#TO_table_col(inner, visual) "{{{
normal! h
endif
" expand selection to the bottom line of the table
- call s:cursor(t_rows[-1][0], virtcol('.'))
+ call vimwiki#u#cursor(t_rows[-1][0], virtcol('.'))
endif
-endfunction "}}}
+endfunction
-function! vimwiki#base#count_first_sym(line) "{{{
- let first_sym = matchstr(a:line, '\S')
- return len(matchstr(a:line, first_sym.'\+'))
-endfunction "}}}
-function! vimwiki#base#AddHeaderLevel() "{{{
+function! vimwiki#base#AddHeaderLevel()
let lnum = line('.')
let line = getline(lnum)
-
- if line =~ '^\s*$'
+ let rxHdr = vimwiki#vars#get_syntaxlocal('rxH')
+ if line =~# '^\s*$'
return
endif
- if line =~ '^\s*\(=\+\).\+\1\s*$'
- let level = vimwiki#base#count_first_sym(line)
+ if line =~# vimwiki#vars#get_syntaxlocal('rxHeader')
+ let level = vimwiki#u#count_first_sym(line)
if level < 6
- let line = substitute(line, '\(=\+\).\+\1', '=&=', '')
+ if vimwiki#vars#get_syntaxlocal('symH')
+ let line = substitute(line, '\('.rxHdr.'\+\).\+\1', rxHdr.'&'.rxHdr, '')
+ else
+ let line = substitute(line, '\('.rxHdr.'\+\).\+', rxHdr.'&', '')
+ endif
call setline(lnum, line)
endif
else
- let line = substitute(line, '^\s*', '&= ', '')
- let line = substitute(line, '\s*$', ' =&', '')
- call setline(lnum, line)
+ let line = substitute(line, '^\s*', '&'.rxHdr.' ', '')
+ if vimwiki#vars#get_syntaxlocal('symH')
+ let line = substitute(line, '\s*$', ' '.rxHdr.'&', '')
+ endif
+ call setline(lnum, line)
endif
endfunction
-"}}}
-function! vimwiki#base#RemoveHeaderLevel() "{{{
+
+function! vimwiki#base#RemoveHeaderLevel()
let lnum = line('.')
let line = getline(lnum)
-
- if line =~ '^\s*$'
+ let rxHdr = vimwiki#vars#get_syntaxlocal('rxH')
+ if line =~# '^\s*$'
return
endif
- if line =~ '^\s*\(=\+\).\+\1\s*$'
- let level = vimwiki#base#count_first_sym(line)
- let old = repeat('=', level)
- let new = repeat('=', level - 1)
+ if line =~# vimwiki#vars#get_syntaxlocal('rxHeader')
+ let level = vimwiki#u#count_first_sym(line)
+ let old = repeat(rxHdr, level)
+ let new = repeat(rxHdr, level - 1)
- let chomp = line =~ '=\s'
+ let chomp = line =~# rxHdr.'\s'
- let line = substitute(line, old, new, 'g')
+ if vimwiki#vars#get_syntaxlocal('symH')
+ let line = substitute(line, old, new, 'g')
+ else
+ let line = substitute(line, old, new, '')
+ endif
if level == 1 && chomp
let line = substitute(line, '^\s', '', 'g')
let line = substitute(line, '\s$', '', 'g')
endif
+
+ let line = substitute(line, '\s*$', '', '')
+
call setline(lnum, line)
endif
endfunction
-" }}}
-" }}}
+
+
+" Returns all the headers in the current buffer as a list of the form
+" [[line_number, header_level, header_text], [...], [...], ...]
+function! s:collect_headers()
+ let is_inside_pre_or_math = 0 " 1: inside pre, 2: inside math, 0: outside
+ let headers = []
+ for lnum in range(1, line('$'))
+ let line_content = getline(lnum)
+ if (is_inside_pre_or_math == 1 && line_content =~# vimwiki#vars#get_syntaxlocal('rxPreEnd')) ||
+ \ (is_inside_pre_or_math == 2 && line_content =~# vimwiki#vars#get_syntaxlocal('rxMathEnd'))
+ let is_inside_pre_or_math = 0
+ continue
+ endif
+ if is_inside_pre_or_math > 0
+ continue
+ endif
+ if line_content =~# vimwiki#vars#get_syntaxlocal('rxPreStart')
+ let is_inside_pre_or_math = 1
+ continue
+ endif
+ if line_content =~# vimwiki#vars#get_syntaxlocal('rxMathStart')
+ let is_inside_pre_or_math = 2
+ continue
+ endif
+ if line_content !~# vimwiki#vars#get_syntaxlocal('rxHeader')
+ continue
+ endif
+ let header_level = vimwiki#u#count_first_sym(line_content)
+ let header_text =
+ \ vimwiki#u#trim(matchstr(line_content, vimwiki#vars#get_syntaxlocal('rxHeader')))
+ call add(headers, [lnum, header_level, header_text])
+ endfor
+
+ return headers
+endfunction
+
+
+function! s:current_header(headers, line_number)
+ if empty(a:headers)
+ return -1
+ endif
+
+ if a:line_number >= a:headers[-1][0]
+ return len(a:headers) - 1
+ endif
+
+ let current_header_index = -1
+ while a:headers[current_header_index+1][0] <= a:line_number
+ let current_header_index += 1
+ endwhile
+ return current_header_index
+endfunction
+
+
+function! s:get_another_header(headers, current_index, direction, operation)
+ if empty(a:headers) || a:current_index < 0
+ return -1
+ endif
+ let current_level = a:headers[a:current_index][1]
+ let index = a:current_index + a:direction
+
+ while 1
+ if index < 0 || index >= len(a:headers)
+ return -1
+ endif
+ if eval('a:headers[index][1] ' . a:operation . ' current_level')
+ return index
+ endif
+ let index += a:direction
+ endwhile
+endfunction
+
+
+function! vimwiki#base#goto_parent_header()
+ let headers = s:collect_headers()
+ let current_header_index = s:current_header(headers, line('.'))
+ let parent_header = s:get_another_header(headers, current_header_index, -1, '<')
+ if parent_header >= 0
+ call cursor(headers[parent_header][0], 1)
+ else
+ echo 'Vimwiki: no parent header found'
+ endif
+endfunction
+
+
+function! vimwiki#base#goto_next_header()
+ let headers = s:collect_headers()
+ let current_header_index = s:current_header(headers, line('.'))
+ if current_header_index >= 0 && current_header_index < len(headers) - 1
+ call cursor(headers[current_header_index + 1][0], 1)
+ elseif current_header_index < 0 && !empty(headers) " we're above the first header
+ call cursor(headers[0][0], 1)
+ else
+ echo 'Vimwiki: no next header found'
+ endif
+endfunction
+
+
+function! vimwiki#base#goto_prev_header()
+ let headers = s:collect_headers()
+ let current_header_index = s:current_header(headers, line('.'))
+ " if the cursor already was on a header, jump to the previous one
+ if current_header_index >= 1 && headers[current_header_index][0] == line('.')
+ let current_header_index -= 1
+ endif
+ if current_header_index >= 0
+ call cursor(headers[current_header_index][0], 1)
+ else
+ echo 'Vimwiki: no previous header found'
+ endif
+endfunction
+
+
+function! vimwiki#base#goto_sibling(direction)
+ let headers = s:collect_headers()
+ let current_header_index = s:current_header(headers, line('.'))
+ let next_potential_sibling =
+ \ s:get_another_header(headers, current_header_index, a:direction, '<=')
+ if next_potential_sibling >= 0 && headers[next_potential_sibling][1] ==
+ \ headers[current_header_index][1]
+ call cursor(headers[next_potential_sibling][0], 1)
+ else
+ echo 'Vimwiki: no sibling header found'
+ endif
+endfunction
+
+
+" a:create == 1: creates or updates TOC in current file
+" a:create == 0: update if TOC exists
+function! vimwiki#base#table_of_contents(create)
+ let headers = s:collect_headers()
+ let toc_header_text = vimwiki#vars#get_global('toc_header')
+
+ if !a:create
+ " Do nothing if there is no TOC to update. (This is a small performance optimization -- if
+ " auto_toc == 1, but the current buffer has no TOC but is long, saving the buffer could
+ " otherwise take a few seconds for nothing.)
+ let toc_already_present = 0
+ for entry in headers
+ if entry[2] ==# toc_header_text
+ let toc_already_present = 1
+ break
+ endif
+ endfor
+ if !toc_already_present
+ return
+ endif
+ endif
+
+ let numbering = vimwiki#vars#get_global('html_header_numbering')
+ let headers_levels = [['', 0], ['', 0], ['', 0], ['', 0], ['', 0], ['', 0]]
+ let complete_header_infos = []
+ for header in headers
+ let h_text = header[2]
+ let h_level = header[1]
+ if h_text ==# toc_header_text " don't include the TOC's header itself
+ continue
+ endif
+ let headers_levels[h_level-1] = [h_text, headers_levels[h_level-1][1]+1]
+ for idx in range(h_level, 5) | let headers_levels[idx] = ['', 0] | endfor
+
+ let h_complete_id = ''
+ for l in range(h_level-1)
+ if headers_levels[l][0] != ''
+ let h_complete_id .= headers_levels[l][0].'#'
+ endif
+ endfor
+ let h_complete_id .= headers_levels[h_level-1][0]
+
+ if numbering > 0 && numbering <= h_level
+ let h_number = join(map(copy(headers_levels[numbering-1 : h_level-1]), 'v:val[1]'), '.')
+ let h_number .= vimwiki#vars#get_global('html_header_numbering_sym')
+ let h_text = h_number.' '.h_text
+ endif
+
+ call add(complete_header_infos, [h_level, h_complete_id, h_text])
+ endfor
+
+ let lines = []
+ let startindent = repeat(' ', vimwiki#lst#get_list_margin())
+ let indentstring = repeat(' ', vimwiki#u#sw())
+ let bullet = vimwiki#lst#default_symbol().' '
+ for [lvl, link, desc] in complete_header_infos
+ if vimwiki#vars#get_wikilocal('syntax') == 'markdown'
+ let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink1Template')
+ else
+ let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate2')
+ endif
+ let link = s:safesubstitute(link_tpl, '__LinkUrl__',
+ \ '#'.link, '')
+ let link = s:safesubstitute(link, '__LinkDescription__', desc, '')
+ call add(lines, startindent.repeat(indentstring, lvl-1).bullet.link)
+ endfor
+
+ let links_rx = '\m^\s*'.vimwiki#u#escape(vimwiki#lst#default_symbol()).' '
+
+ call vimwiki#base#update_listing_in_buffer(lines, toc_header_text, links_rx, 1, a:create)
+endfunction
+
+
+" Construct a regular expression matching from template (with special
+" characters properly escaped), by substituting rxUrl for __LinkUrl__, rxDesc
+" for __LinkDescription__, and rxStyle for __LinkStyle__. The three
+" arguments rxUrl, rxDesc, and rxStyle are copied verbatim, without any
+" special character escapes or substitutions.
+function! vimwiki#base#apply_template(template, rxUrl, rxDesc, rxStyle)
+ let lnk = a:template
+ if a:rxUrl != ""
+ let lnk = s:safesubstitute(lnk, '__LinkUrl__', a:rxUrl, 'g')
+ endif
+ if a:rxDesc != ""
+ let lnk = s:safesubstitute(lnk, '__LinkDescription__', a:rxDesc, 'g')
+ endif
+ if a:rxStyle != ""
+ let lnk = s:safesubstitute(lnk, '__LinkStyle__', a:rxStyle, 'g')
+ endif
+ return lnk
+endfunction
+
+
+function! s:clean_url(url)
+ " remove protocol and tld
+ let url = substitute(a:url, '^\a\+\d*:', '', '')
+ let url = substitute(url, '^//', '', '')
+ let url = substitute(url, '^\([^/]\+\)\.\a\{2,4}/', '\1/', '')
+ let url = split(url, '/\|=\|-\|&\|?\|\.')
+ let url = filter(url, 'v:val !=# ""')
+ if url[0] == "www"
+ let url = url[1:]
+ endif
+ if url[-1] =~ '^\(htm\|html\|php\)$'
+ let url = url[0:-2]
+ endif
+ " remove words consisting of only hexadecimal digits or non-word characters
+ let url = filter(url, 'v:val !~ "^\\A\\{4,}$"')
+ let url = filter(url, 'v:val !~ "^\\x\\{4,}$" || v:val !~ "\\d"')
+ return join(url, " ")
+endfunction
+
+
+function! s:is_diary_file(filename)
+ let file_path = vimwiki#path#path_norm(a:filename)
+ let rel_path = vimwiki#vars#get_wikilocal('diary_rel_path')
+ let diary_path = vimwiki#path#path_norm(vimwiki#vars#get_wikilocal('path') . rel_path)
+ return rel_path != '' && file_path =~# '^'.vimwiki#u#escape(diary_path)
+endfunction
+
+
+function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template)
+ let url = matchstr(a:str, a:rxUrl)
+ let descr = matchstr(a:str, a:rxDesc)
+ if descr == ""
+ let descr = s:clean_url(url)
+ endif
+ let lnk = s:safesubstitute(a:template, '__LinkDescription__', descr, '')
+ let lnk = s:safesubstitute(lnk, '__LinkUrl__', url, '')
+ return lnk
+endfunction
+
+
+function! vimwiki#base#normalize_imagelink_helper(str, rxUrl, rxDesc, rxStyle, template)
+ let lnk = vimwiki#base#normalize_link_helper(a:str, a:rxUrl, a:rxDesc, a:template)
+ let style = matchstr(a:str, a:rxStyle)
+ let lnk = s:safesubstitute(lnk, '__LinkStyle__', style, '')
+ return lnk
+endfunction
+
+
+function! s:normalize_link_in_diary(lnk)
+ let link = a:lnk . vimwiki#vars#get_wikilocal('ext')
+ let link_wiki = vimwiki#vars#get_wikilocal('path') . '/' . link
+ let link_diary = vimwiki#vars#get_wikilocal('path') . '/'
+ \ . vimwiki#vars#get_wikilocal('diary_rel_path') . '/' . link
+ let link_exists_in_diary = filereadable(link_diary)
+ let link_exists_in_wiki = filereadable(link_wiki)
+ let link_is_date = a:lnk =~# '\d\d\d\d-\d\d-\d\d'
+
+ if link_exists_in_diary || link_is_date
+ let str = a:lnk
+ let rxUrl = vimwiki#vars#get_global('rxWord')
+ let rxDesc = ''
+ let template = vimwiki#vars#get_global('WikiLinkTemplate1')
+ elseif link_exists_in_wiki
+ let depth = len(split(vimwiki#vars#get_wikilocal('diary_rel_path'), '/'))
+ let str = repeat('../', depth) . a:lnk . '|' . a:lnk
+ let rxUrl = '^.*\ze|'
+ let rxDesc = '|\zs.*$'
+ let template = vimwiki#vars#get_global('WikiLinkTemplate2')
+ else
+ let str = a:lnk
+ let rxUrl = '.*'
+ let rxDesc = ''
+ let template = vimwiki#vars#get_global('WikiLinkTemplate1')
+ endif
+
+ return vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template)
+endfunction
+
+
+function! s:normalize_link_syntax_n()
+
+ " try WikiLink
+ let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink'))
+ if !empty(lnk)
+ let sub = vimwiki#base#normalize_link_helper(lnk,
+ \ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'),
+ \ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr'),
+ \ vimwiki#vars#get_global('WikiLinkTemplate2'))
+ call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink'), sub)
+ return
+ endif
+
+ " try WikiIncl
+ let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWikiIncl'))
+ if !empty(lnk)
+ " NO-OP !!
+ return
+ endif
+
+ " try Weblink
+ let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink'))
+ if !empty(lnk)
+ let sub = vimwiki#base#normalize_link_helper(lnk,
+ \ lnk, '', vimwiki#vars#get_global('WikiLinkTemplate2'))
+ call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWeblink'), sub)
+ return
+ endif
+
+ " try Word (any characters except separators)
+ " rxWord is less permissive than rxWikiLinkUrl which is used in
+ " normalize_link_syntax_v
+ let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWord'))
+ if !empty(lnk)
+ if s:is_diary_file(expand("%:p"))
+ let sub = s:normalize_link_in_diary(lnk)
+ else
+ let sub = s:safesubstitute(
+ \ vimwiki#vars#get_global('WikiLinkTemplate1'), '__LinkUrl__', lnk, '')
+ endif
+ call vimwiki#base#replacestr_at_cursor('\V'.lnk, sub)
+ return
+ endif
+
+endfunction
+
+
+function! s:normalize_link_syntax_v()
+ let sel_save = &selection
+ let &selection = "old"
+ let default_register_save = @"
+ let registertype_save = getregtype('"')
+
+ try
+ " Save selected text to register "
+ normal! gv""y
+
+ " Set substitution
+ if s:is_diary_file(expand("%:p"))
+ let sub = s:normalize_link_in_diary(@")
+ else
+ let sub = s:safesubstitute(vimwiki#vars#get_global('WikiLinkTemplate1'),
+ \ '__LinkUrl__', @", '')
+ endif
+
+ " Put substitution in register " and change text
+ call setreg('"', substitute(sub, '\n', '', ''), visualmode())
+ normal! `>""pgvd
+ finally
+ call setreg('"', default_register_save, registertype_save)
+ let &selection = sel_save
+ endtry
+endfunction
+
+
+function! vimwiki#base#normalize_link(is_visual_mode)
+ if exists('*vimwiki#'.vimwiki#vars#get_wikilocal('syntax').'_base#normalize_link')
+ " Syntax-specific links
+ call vimwiki#{vimwiki#vars#get_wikilocal('syntax')}_base#normalize_link(a:is_visual_mode)
+ else
+ if !a:is_visual_mode
+ call s:normalize_link_syntax_n()
+ elseif line("'<") == line("'>")
+ " action undefined for multi-line visual mode selections
+ call s:normalize_link_syntax_v()
+ endif
+ endif
+endfunction
+
+
+function! vimwiki#base#detect_nested_syntax()
+ let last_word = '\v.*<(\w+)\s*$'
+ let lines = map(filter(getline(1, "$"), 'v:val =~ "\\%({{{\\|```\\)" && v:val =~ last_word'),
+ \ 'substitute(v:val, last_word, "\\=submatch(1)", "")')
+ let dict = {}
+ for elem in lines
+ let dict[elem] = elem
+ endfor
+ return dict
+endfunction
+
+
+function! vimwiki#base#complete_links_escaped(ArgLead, CmdLine, CursorPos) abort
+ " We can safely ignore args if we use -custom=complete option, Vim engine
+ " will do the job of filtering.
+ return vimwiki#base#get_globlinks_escaped()
+endfunction
+
+
+" -------------------------------------------------------------------------
+" Load syntax-specific Wiki functionality
+for s:syn in s:vimwiki_get_known_syntaxes()
+ execute 'runtime! autoload/vimwiki/'.s:syn.'_base.vim'
+endfor
+" -------------------------------------------------------------------------
+
diff --git a/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/customwiki2html.sh b/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/customwiki2html.sh
new file mode 100755
index 0000000..6b0c17a
--- /dev/null
+++ b/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/customwiki2html.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+#
+# This script converts markdown into html, to be used with vimwiki's
+# "customwiki2html" option. Experiment with the two proposed methods by
+# commenting / uncommenting the relevant lines below.
+#
+# NEW! An alternative converter was developed by Jason6Anderson, and can
+# be located at https://github.com/vimwiki-backup/vimwiki/issues/384
+#
+#
+# To use this script, you must have the Discount converter installed.
+#
+# http://www.pell.portland.or.us/~orc/Code/discount/
+#
+# To verify your installation, check that the commands markdown and mkd2text,
+# are on your path.
+#
+# Also verify that this file is executable.
+#
+# Then, in your .vimrc file, set:
+#
+# g:vimwiki_customwiki2html=$HOME.'/.vim/autoload/vimwiki/customwiki2html.sh'
+#
+# On your next restart, Vimwiki will run this script instead of using the
+# internal wiki2html converter.
+#
+
+MARKDOWN=markdown
+MKD2HTML=mkd2html
+
+
+FORCE="$1"
+SYNTAX="$2"
+EXTENSION="$3"
+OUTPUTDIR="$4"
+INPUT="$5"
+CSSFILE="$6"
+
+FORCEFLAG=
+
+[ $FORCE -eq 0 ] || { FORCEFLAG="-f"; };
+[ $SYNTAX = "markdown" ] || { echo "Error: Unsupported syntax"; exit -2; };
+
+OUTPUT="$OUTPUTDIR"/$(basename "$INPUT" .$EXTENSION).html
+
+# # Method 1:
+# # markdown [-d] [-T] [-V] [-b url-base] [-C prefix] [-F bitmap] [-f flags] [-o file] [-s text] [-t text] [textfile]
+#
+# URLBASE=http://example.com
+# $MARKDOWN -T -b $URLBASE -o $OUTPUT $INPUT
+
+
+# Method 2:
+# mkd2html [-css file] [-header string] [-footer string] [file]
+
+$MKD2HTML -css "$CSSFILE" "$INPUT"
+OUTPUTTMP=$(dirname "$INPUT")/$(basename "$INPUT" ."$EXTENSION").html
+mv -f "$OUTPUTTMP" "$OUTPUT"
+
+
+
diff --git a/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/default.tpl b/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/default.tpl
index 3e31d99..3a4045f 100644
--- a/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/default.tpl
+++ b/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/default.tpl
@@ -1,4 +1,4 @@
-
+
diff --git a/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/diary.vim b/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/diary.vim
index a38d547..37f6d5c 100644
--- a/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/diary.vim
+++ b/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/diary.vim
@@ -1,251 +1,245 @@
-" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
+" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki autoload plugin file
-" Desc: Handle diary notes
-" Author: Maxim Kim
-" Home: http://code.google.com/p/vimwiki/
+" Description: Handle diary notes
+" Home: https://github.com/vimwiki/vimwiki/
+
-" Load only once {{{
if exists("g:loaded_vimwiki_diary_auto") || &cp
finish
endif
let g:loaded_vimwiki_diary_auto = 1
-"}}}
-function! s:prefix_zero(num) "{{{
+
+let s:vimwiki_max_scan_for_caption = 5
+
+
+function! s:prefix_zero(num)
if a:num < 10
return '0'.a:num
endif
return a:num
-endfunction "}}}
-
-function! s:desc(d1, d2) "{{{
- return a:d1 == a:d2 ? 0 : a:d1 < a:d2 ? 1 : -1
-endfunction "}}}
-
-function! s:get_date_link(fmt) "{{{
- return strftime(a:fmt)
-endfunction "}}}
-
-function! s:link_exists(lines, link) "{{{
- let link_exists = 0
- for line in a:lines
- if line =~ escape(a:link, '[]\')
- let link_exists = 1
- break
- endif
- endfor
- return link_exists
-endfunction "}}}
-
-function! s:diary_path() "{{{
- return VimwikiGet('path').VimwikiGet('diary_rel_path')
-endfunction "}}}
-
-function! s:diary_index() "{{{
- return s:diary_path().VimwikiGet('diary_index').VimwikiGet('ext')
-endfunction "}}}
-
-function! s:get_diary_range(lines, header) "{{{
- let rx = '\[\[\d\{4}-\d\d-\d\d\]\]'
- let idx = 0
- let ln_start = -1
- let ln_end = -1
- for line in a:lines
- if ln_start != -1
- if line =~ '^\s*\(=\)\+.*\1\s*$' || (line !~ rx && line !~ '^\s*$')
- break
- endif
- endif
- if line =~ '^\s*\(=\)\+\s*'.a:header.'\s*\1\s*$'
- let ln_start = idx + 1
- endif
- let idx += 1
- endfor
+endfunction
- let ln_end = idx
- return [ln_start, ln_end]
-endfunction "}}}
-function! s:diary_date_link() "{{{
- return s:get_date_link(VimwikiGet('diary_link_fmt'))
-endfunction "}}}
+function! s:diary_path(...)
+ let idx = a:0 == 0 ? vimwiki#vars#get_bufferlocal('wiki_nr') : a:1
+ return vimwiki#vars#get_wikilocal('path', idx).vimwiki#vars#get_wikilocal('diary_rel_path', idx)
+endfunction
-function! s:get_file_contents(file_name) "{{{
- let lines = []
- let bufnr = bufnr(expand(a:file_name))
- if bufnr != -1
- let lines = getbufline(bufnr, 1, '$')
- else
- try
- let lines = readfile(expand(a:file_name))
- catch
- endtry
- endif
- return [lines, bufnr]
-endfunction "}}}
-function! s:get_links() "{{{
- let rx = '\d\{4}-\d\d-\d\d'
- let s_links = glob(VimwikiGet('path').VimwikiGet('diary_rel_path').
- \ '*'.VimwikiGet('ext'))
+function! s:diary_index(...)
+ let idx = a:0 == 0 ? vimwiki#vars#get_bufferlocal('wiki_nr') : a:1
+ return s:diary_path(idx).vimwiki#vars#get_wikilocal('diary_index', idx).
+ \ vimwiki#vars#get_wikilocal('ext', idx)
+endfunction
- let s_links = substitute(s_links, '\'.VimwikiGet('ext'), "", "g")
- let links = split(s_links, '\n')
- " remove backup files (.wiki~)
- call filter(links, 'v:val !~ ''.*\~$''')
-
- " remove paths
- call map(links, 'fnamemodify(v:val, ":t")')
+function! vimwiki#diary#diary_date_link(...)
+ if a:0
+ return strftime('%Y-%m-%d', a:1)
+ else
+ return strftime('%Y-%m-%d')
+ endif
+endfunction
- call filter(links, 'v:val =~ "'.escape(rx, '\').'"')
- return links
-endfunction "}}}
-function! s:get_position_links(link) "{{{
+function! s:get_position_links(link)
let idx = -1
let links = []
- if a:link =~ '\d\{4}-\d\d-\d\d'
- let links = s:get_links()
+ if a:link =~# '^\d\{4}-\d\d-\d\d'
+ let links = map(s:get_diary_files(), 'fnamemodify(v:val, ":t:r")')
" include 'today' into links
- if index(links, s:diary_date_link()) == -1
- call add(links, s:diary_date_link())
+ if index(links, vimwiki#diary#diary_date_link()) == -1
+ call add(links, vimwiki#diary#diary_date_link())
endif
call sort(links)
let idx = index(links, a:link)
endif
return [idx, links]
-endfunction "}}}
-
-function! s:format_links(links) "{{{
- let lines = []
- let line = '| '
- let idx = 0
- let trigger = 0
- while idx < len(a:links)
- if idx/VimwikiGet('diary_link_count') > trigger
- let trigger = idx/VimwikiGet('diary_link_count')
- call add(lines, substitute(line, '\s\+$', '', ''))
- let line = '| '
- endif
- let line .= a:links[idx].' | '
- let idx += 1
- endwhile
- call add(lines, substitute(line, '\s\+$', '', ''))
- call extend(lines, [''])
+endfunction
- return lines
-endfunction "}}}
-function! s:add_link(page, header, link) "{{{
- let [lines, bufnr] = s:get_file_contents(a:page)
+function! s:get_month_name(month)
+ return vimwiki#vars#get_global('diary_months')[str2nr(a:month)]
+endfunction
- let [ln_start, ln_end] = s:get_diary_range(lines, a:header)
- let link = '[['.a:link.']]'
+function! s:read_captions(files)
+ let result = {}
+ let rx_header = vimwiki#vars#get_syntaxlocal('rxHeader')
+ for fl in a:files
+ " remove paths and extensions
+ let fl_key = substitute(fnamemodify(fl, ':t'), vimwiki#vars#get_wikilocal('ext').'$', '', '')
- let link_exists = s:link_exists(lines[ln_start : ln_end], link)
-
- if !link_exists
-
- if ln_start == -1
- call insert(lines, '= '.a:header.' =')
- let ln_start = 1
- let ln_end = 1
+ if filereadable(fl)
+ for line in readfile(fl, '', s:vimwiki_max_scan_for_caption)
+ if line =~# rx_header && !has_key(result, fl_key)
+ let result[fl_key] = vimwiki#u#trim(matchstr(line, rx_header))
+ endif
+ endfor
endif
- " removing 'old' links
- let idx = ln_end - ln_start
- while idx > 0
- call remove(lines, ln_start)
- let idx -= 1
- endwhile
-
- " get all diary links from filesystem
- let links = s:get_links()
- call map(links, '"[[".v:val."]]"')
-
- " add current link
- if index(links, link) == -1
- call add(links, link)
+ if !has_key(result, fl_key)
+ let result[fl_key] = ''
endif
- let links = sort(links, 's:desc')
- call extend(lines, s:format_links(links), ln_start)
+ endfor
+ return result
+endfunction
+
- if bufnr != -1
- exe 'buffer '.bufnr
- if !&readonly
- 1,$delete _
- call append(1, lines)
- 1,1delete _
- endif
- else
- call writefile(lines, expand(a:page))
+function! s:get_diary_files()
+ let rx = '^\d\{4}-\d\d-\d\d'
+ let s_files = glob(vimwiki#vars#get_wikilocal('path').
+ \ vimwiki#vars#get_wikilocal('diary_rel_path').'*'.vimwiki#vars#get_wikilocal('ext'))
+ let files = split(s_files, '\n')
+ call filter(files, 'fnamemodify(v:val, ":t") =~# "'.escape(rx, '\').'"')
+
+ " remove backup files (.wiki~)
+ call filter(files, 'v:val !~# ''.*\~$''')
+
+ return files
+endfunction
+
+
+function! s:group_links(links)
+ let result = {}
+ let p_year = 0
+ let p_month = 0
+ for fl in sort(keys(a:links))
+ let year = strpart(fl, 0, 4)
+ let month = strpart(fl, 5, 2)
+ if p_year != year
+ let result[year] = {}
+ let p_month = 0
+ endif
+ if p_month != month
+ let result[year][month] = {}
endif
+ let result[year][month][fl] = a:links[fl]
+ let p_year = year
+ let p_month = month
+ endfor
+ return result
+endfunction
+
+
+function! s:sort(lst)
+ if vimwiki#vars#get_wikilocal('diary_sort') ==? 'desc'
+ return reverse(sort(a:lst))
+ else
+ return sort(a:lst)
endif
-endfunction "}}}
+endfunction
-function! s:make_date_link(...) "{{{
- if a:0
- let link = a:1
+
+function! s:format_diary()
+ let result = []
+
+ let links_with_captions = s:read_captions(s:get_diary_files())
+ let g_files = s:group_links(links_with_captions)
+
+ for year in s:sort(keys(g_files))
+ call add(result, '')
+ call add(result,
+ \ substitute(vimwiki#vars#get_syntaxlocal('rxH2_Template'), '__Header__', year , ''))
+
+ for month in s:sort(keys(g_files[year]))
+ call add(result, '')
+ call add(result, substitute(vimwiki#vars#get_syntaxlocal('rxH3_Template'),
+ \ '__Header__', s:get_month_name(month), ''))
+
+ for [fl, cap] in s:sort(items(g_files[year][month]))
+ let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate2')
+
+ if vimwiki#vars#get_wikilocal('syntax') == 'markdown'
+ let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink1Template')
+
+ if empty(cap) " When using markdown syntax, we should ensure we always have a link description.
+ let cap = fl
+ endif
+ elseif empty(cap)
+ let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate1')
+ endif
+
+ let entry = substitute(link_tpl, '__LinkUrl__', fl, '')
+ let entry = substitute(entry, '__LinkDescription__', cap, '')
+ call add(result, repeat(' ', vimwiki#lst#get_list_margin()).'* '.entry)
+ endfor
+
+ endfor
+ endfor
+
+ return result
+endfunction
+
+
+" The given wiki number a:wnum is 1 for the first wiki, 2 for the second and so on. This is in
+" contrast to most other places, where counting starts with 0. When a:wnum is 0, the current wiki
+" is used.
+function! vimwiki#diary#make_note(wnum, ...)
+ if a:wnum == 0
+ let wiki_nr = vimwiki#vars#get_bufferlocal('wiki_nr')
+ if wiki_nr < 0 " this happens when e.g. VimwikiMakeDiaryNote was called outside a wiki buffer
+ let wiki_nr = 0
+ endif
else
- let link = s:diary_date_link()
+ let wiki_nr = a:wnum - 1
+ endif
+
+ if wiki_nr >= vimwiki#vars#number_of_wikis()
+ echomsg 'Vimwiki Error: Wiki '.wiki_nr.' is not registered in g:vimwiki_list!'
+ return
endif
- let header = VimwikiGet('diary_header')
- call s:add_link(s:diary_index(), header, link)
- return VimwikiGet('diary_rel_path').link
-endfunction "}}}
-
-function! vimwiki#diary#make_note(index, ...) "{{{
- call vimwiki#base#select(a:index)
- call vimwiki#base#mkdir(VimwikiGet('path').VimwikiGet('diary_rel_path'))
+
+ " TODO: refactor it. base#goto_index uses the same
+
+ call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('path', wiki_nr).
+ \ vimwiki#vars#get_wikilocal('diary_rel_path', wiki_nr))
+
+ let cmd = 'edit'
if a:0
- let link = s:make_date_link(a:1)
+ if a:1 == 1
+ let cmd = 'tabedit'
+ elseif a:1 == 2
+ let cmd = 'split'
+ elseif a:1 == 3
+ let cmd = 'vsplit'
+ endif
+ endif
+ if a:0>1
+ let link = 'diary:'.a:2
else
- let link = s:make_date_link()
+ let link = 'diary:'.vimwiki#diary#diary_date_link()
endif
- call vimwiki#base#open_link(':e ', link, s:diary_index())
-endfunction "}}}
-function! vimwiki#diary#goto_index(index) "{{{
- call vimwiki#base#select(a:index)
- call vimwiki#base#edit_file(':e', s:diary_index())
-endfunction "}}}
+ call vimwiki#base#open_link(cmd, link, s:diary_index(wiki_nr))
+endfunction
-" Calendar.vim callback function.
-function! vimwiki#diary#calendar_action(day, month, year, week, dir) "{{{
- let day = s:prefix_zero(a:day)
- let month = s:prefix_zero(a:month)
- let link = a:year.'-'.month.'-'.day
- if winnr('#') == 0
- if a:dir == 'V'
- vsplit
- else
- split
- endif
+function! vimwiki#diary#goto_diary_index(wnum)
+ if a:wnum > vimwiki#vars#number_of_wikis()
+ echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in g:vimwiki_list!'
+ return
+ endif
+
+ " TODO: refactor it. base#goto_index uses the same
+ if a:wnum > 0
+ let idx = a:wnum - 1
else
- wincmd p
- if !&hidden && &modified
- new
- endif
+ let idx = 0
endif
- " Create diary note for a selected date in default wiki.
- call vimwiki#diary#make_note(1, link)
-endfunction "}}}
+ call vimwiki#base#edit_file('e', s:diary_index(idx), '')
+
+ if vimwiki#vars#get_wikilocal('auto_diary_index')
+ call vimwiki#diary#generate_diary_section()
+ write! " save changes
+ endif
+endfunction
-" Calendar.vim sign function.
-function vimwiki#diary#calendar_sign(day, month, year) "{{{
- let day = s:prefix_zero(a:day)
- let month = s:prefix_zero(a:month)
- let sfile = VimwikiGet('path').VimwikiGet('diary_rel_path').
- \ a:year.'-'.month.'-'.day.VimwikiGet('ext')
- return filereadable(expand(sfile))
-endfunction "}}}
-function! vimwiki#diary#goto_next_day() "{{{
+function! vimwiki#diary#goto_next_day()
let link = ''
let [idx, links] = s:get_position_links(expand('%:t:r'))
@@ -254,18 +248,19 @@ function! vimwiki#diary#goto_next_day() "{{{
endif
if idx != -1 && idx < len(links) - 1
- let link = VimwikiGet('diary_rel_path').links[idx+1]
+ let link = 'diary:'.links[idx+1]
else
" goto today
- let link = VimwikiGet('diary_rel_path').s:diary_date_link()
+ let link = 'diary:'.vimwiki#diary#diary_date_link()
endif
if len(link)
call vimwiki#base#open_link(':e ', link)
endif
-endfunction "}}}
+endfunction
+
-function! vimwiki#diary#goto_prev_day() "{{{
+function! vimwiki#diary#goto_prev_day()
let link = ''
let [idx, links] = s:get_position_links(expand('%:t:r'))
@@ -274,13 +269,59 @@ function! vimwiki#diary#goto_prev_day() "{{{
endif
if idx > 0
- let link = VimwikiGet('diary_rel_path').links[idx-1]
+ let link = 'diary:'.links[idx-1]
else
" goto today
- let link = VimwikiGet('diary_rel_path').s:diary_date_link()
+ let link = 'diary:'.vimwiki#diary#diary_date_link()
endif
if len(link)
call vimwiki#base#open_link(':e ', link)
endif
-endfunction "}}}
+endfunction
+
+
+function! vimwiki#diary#generate_diary_section()
+ let current_file = vimwiki#path#path_norm(expand("%:p"))
+ let diary_file = vimwiki#path#path_norm(s:diary_index())
+ if vimwiki#path#is_equal(current_file, diary_file)
+ let content_rx = '^\%(\s*\* \)\|\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxHeader').'\)'
+ call vimwiki#base#update_listing_in_buffer(s:format_diary(),
+ \ vimwiki#vars#get_wikilocal('diary_header'), content_rx, line('$')+1, 1)
+ else
+ echomsg 'Vimwiki Error: You can generate diary links only in a diary index page!'
+ endif
+endfunction
+
+
+" Callback function for Calendar.vim
+function! vimwiki#diary#calendar_action(day, month, year, week, dir)
+ let day = s:prefix_zero(a:day)
+ let month = s:prefix_zero(a:month)
+
+ let link = a:year.'-'.month.'-'.day
+ if winnr('#') == 0
+ if a:dir ==? 'V'
+ vsplit
+ else
+ split
+ endif
+ else
+ wincmd p
+ if !&hidden && &modified
+ new
+ endif
+ endif
+
+ call vimwiki#diary#make_note(0, 0, link)
+endfunction
+
+
+function vimwiki#diary#calendar_sign(day, month, year)
+ let day = s:prefix_zero(a:day)
+ let month = s:prefix_zero(a:month)
+ let sfile = vimwiki#vars#get_wikilocal('path').vimwiki#vars#get_wikilocal('diary_rel_path').
+ \ a:year.'-'.month.'-'.day.vimwiki#vars#get_wikilocal('ext')
+ return filereadable(expand(sfile))
+endfunction
+
diff --git a/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/html.vim b/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/html.vim
index 0dbe9d1..ba2cc4c 100644
--- a/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/html.vim
+++ b/etc/soft/nvim/+plugins/vimwiki/autoload/vimwiki/html.vim
@@ -1,55 +1,57 @@
-" vim:tabstop=2:shiftwidth=2:expandtab:foldmethod=marker:textwidth=79
+" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99
" Vimwiki autoload plugin file
-" Export to HTML
-" Author: Maxim Kim
-" Home: http://code.google.com/p/vimwiki/
+" Description: HTML export
+" Home: https://github.com/vimwiki/vimwiki/
-" XXX: This file should be refactored!
-" Load only once {{{
if exists("g:loaded_vimwiki_html_auto") || &cp
finish
endif
let g:loaded_vimwiki_html_auto = 1
-"}}}
-" UTILITY "{{{
-function! s:root_path(subdir) "{{{
+
+function! s:root_path(subdir)
return repeat('../', len(split(a:subdir, '[/\\]')))
-endfunction "}}}
+endfunction
+
+
+function! s:syntax_supported()
+ return vimwiki#vars#get_wikilocal('syntax') ==? "default"
+endfunction
-function! s:syntax_supported() " {{{
- return VimwikiGet('syntax') == "default"
-endfunction " }}}
-function! s:remove_blank_lines(lines) " {{{
- while !empty(a:lines) && a:lines[-1] =~ '^\s*$'
+function! s:remove_blank_lines(lines)
+ while !empty(a:lines) && a:lines[-1] =~# '^\s*$'
call remove(a:lines, -1)
endwhile
-endfunction "}}}
+endfunction
-function! s:is_web_link(lnk) "{{{
- if a:lnk =~ '^\%(https://\|http://\|www.\|ftp://\|file://\|mailto:\)'
+
+function! s:is_web_link(lnk)
+ if a:lnk =~# '^\%(https://\|http://\|www.\|ftp://\|file://\|mailto:\)'
return 1
endif
return 0
-endfunction "}}}
+endfunction
+
-function! s:is_img_link(lnk) "{{{
- if a:lnk =~ '\.\%(png\|jpg\|gif\|jpeg\)$'
+function! s:is_img_link(lnk)
+ if tolower(a:lnk) =~# '\.\%(png\|jpg\|gif\|jpeg\)$'
return 1
endif
return 0
-endfunction "}}}
+endfunction
-function! s:has_abs_path(fname) "{{{
- if a:fname =~ '\(^.:\)\|\(^/\)'
+
+function! s:has_abs_path(fname)
+ if a:fname =~# '\(^.:\)\|\(^/\)'
return 1
endif
return 0
-endfunction "}}}
+endfunction
+
-function! s:find_autoload_file(name) " {{{
+function! s:find_autoload_file(name)
for path in split(&runtimepath, ',')
let fname = path.'/autoload/vimwiki/'.a:name
if glob(fname) != ''
@@ -57,91 +59,110 @@ function! s:find_autoload_file(name) " {{{
endif
endfor
return ''
-endfunction " }}}
+endfunction
-function! s:create_default_CSS(path) " {{{
+
+function! s:default_CSS_full_name(path)
let path = expand(a:path)
- let css_full_name = path.VimwikiGet('css_name')
+ let css_full_name = path . vimwiki#vars#get_wikilocal('css_name')
+ return css_full_name
+endfunction
+
+
+function! s:create_default_CSS(path)
+ let css_full_name = s:default_CSS_full_name(a:path)
if glob(css_full_name) == ""
- call vimwiki#base#mkdir(fnamemodify(css_full_name, ':p:h'))
+ call vimwiki#path#mkdir(fnamemodify(css_full_name, ':p:h'))
let default_css = s:find_autoload_file('style.css')
if default_css != ''
let lines = readfile(default_css)
call writefile(lines, css_full_name)
- echomsg "Default style.css has been created."
+ return 1
endif
endif
-endfunction "}}}
+ return 0
+endfunction
-function! s:template_full_name(name) "{{{
+
+function! s:template_full_name(name)
if a:name == ''
- let name = VimwikiGet('template_default')
+ let name = vimwiki#vars#get_wikilocal('template_default')
else
let name = a:name
endif
- let fname = expand(VimwikiGet('template_path').
- \name.
- \VimwikiGet('template_ext'))
+ let fname = expand(vimwiki#vars#get_wikilocal('template_path').
+ \ name . vimwiki#vars#get_wikilocal('template_ext'))
if filereadable(fname)
return fname
else
return ''
endif
-endfunction "}}}
+endfunction
+
-function! s:get_html_template(wikifile, template) "{{{
+function! s:get_html_template(template)
" TODO: refactor it!!!
let lines=[]
- let template_name = s:template_full_name(a:template)
- if template_name != ''
+ if a:template != ''
+ let template_name = s:template_full_name(a:template)
try
let lines = readfile(template_name)
return lines
catch /E484/
- echomsg 'vimwiki: html template '.template_name.
- \ ' does not exist!'
+ echomsg 'Vimwiki: HTML template '.template_name. ' does not exist!'
endtry
endif
- " if no VimwikiGet('html_template') set up or error while reading template
- " file -- use default one.
- let default_tpl = s:find_autoload_file('default.tpl')
- if default_tpl != ''
- let lines = readfile(default_tpl)
+ let default_tpl = s:template_full_name('')
+
+ if default_tpl == ''
+ let default_tpl = s:find_autoload_file('default.tpl')
endif
+
+ let lines = readfile(default_tpl)
return lines
-endfunction "}}}
+endfunction
+
+
+function! s:safe_html_preformatted(line)
+ let line = substitute(a:line,'<','\<', 'g')
+ let line = substitute(line,'>','\>', 'g')
+ return line
+endfunction
+
+
+function! s:escape_html_attribute(string)
+ return substitute(a:string, '"', '\"', 'g')
+endfunction
-function! s:safe_html(line) "{{{
- "" htmlize symbols: < > &
+function! s:safe_html_line(line)
+ " escape & < > when producing HTML text
+ " s:lt_pattern, s:gt_pattern depend on g:vimwiki_valid_html_tags
+ " and are set in vimwiki#html#Wiki2HTML()
let line = substitute(a:line, '&', '\&', 'g')
+ let line = substitute(line,s:lt_pattern,'\<', 'g')
+ let line = substitute(line,s:gt_pattern,'\>', 'g')
- let tags = join(split(g:vimwiki_valid_html_tags, '\s*,\s*'), '\|')
- let line = substitute(line,'<\%(/\?\%('
- \.tags.'\)\%(\s\{-1}\S\{-}\)\{-}/\?>\)\@!',
- \'\<', 'g')
- let line = substitute(line,'\%(\?\%('
- \.tags.'\)\%(\s\{-1}\S\{-}\)\{-}/\?\)\@',
- \'\>', 'g')
return line
-endfunction "}}}
+endfunction
-function! s:delete_html_files(path) "{{{
+
+function! s:delete_html_files(path)
let htmlfiles = split(glob(a:path.'**/*.html'), '\n')
for fname in htmlfiles
" ignore user html files, e.g. search.html,404.html
- if stridx(g:vimwiki_user_htmls, fnamemodify(fname, ":t")) >= 0
+ if stridx(vimwiki#vars#get_global('user_htmls'), fnamemodify(fname, ":t")) >= 0
continue
endif
" delete if there is no corresponding wiki file
- let subdir = vimwiki#base#subdir(VimwikiGet('path_html'), fname)
- let wikifile = VimwikiGet("path").subdir.
- \fnamemodify(fname, ":t:r").VimwikiGet("ext")
+ let subdir = vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path_html'), fname)
+ let wikifile = vimwiki#vars#get_wikilocal('path').subdir.
+ \fnamemodify(fname, ":t:r").vimwiki#vars#get_wikilocal('ext')
if filereadable(wikifile)
continue
endif
@@ -149,16 +170,18 @@ function! s:delete_html_files(path) "{{{
try
call delete(fname)
catch
- echomsg 'vimwiki: Cannot delete '.fname
+ echomsg 'Vimwiki Error: Cannot delete '.fname
endtry
endfor
-endfunction "}}}
+endfunction
+
-function! s:mid(value, cnt) "{{{
+function! s:mid(value, cnt)
return strpart(a:value, a:cnt, len(a:value) - 2 * a:cnt)
-endfunction "}}}
+endfunction
-function! s:subst_func(line, regexp, func) " {{{
+
+function! s:subst_func(line, regexp, func, ...)
" Substitute text found by regexp with result of
" func(matched) function.
@@ -169,94 +192,45 @@ function! s:subst_func(line, regexp, func) " {{{
let res_line = res_line.line
let matched = matchstr(a:line, a:regexp, pos)
if matched != ""
- let res_line = res_line.{a:func}(matched)
+ if a:0
+ let res_line = res_line.{a:func}(matched, a:1)
+ else
+ let res_line = res_line.{a:func}(matched)
+ endif
endif
let pos = matchend(a:line, a:regexp, pos)
endfor
return res_line
-endfunction " }}}
+endfunction
-function! s:save_vimwiki_buffer() "{{{
- if &filetype == 'vimwiki'
- silent update
- endif
-endfunction "}}}
-
-function! s:trim(string) "{{{
- let res = substitute(a:string, '^\s\+', '', '')
- let res = substitute(res, '\s\+$', '', '')
- return res
-endfunction "}}}
-
-function! s:get_html_toc(toc_list) "{{{
- " toc_list is list of [level, header_text, header_id]
- " ex: [[1, "Header", "toc1"], [2, "Header2", "toc2"], ...]
- function! s:close_list(toc, plevel, level) "{{{
- let plevel = a:plevel
- while plevel > a:level
- call add(a:toc, '')
- let plevel -= 1
- endwhile
- return plevel
- endfunction "}}}
-
- if empty(a:toc_list)
- return []
- endif
-
- let toc = ['
']
- let level = 0
- let plevel = 0
- for [level, text, id] in a:toc_list
- if level > plevel
- call add(toc, '
')
- elseif level < plevel
- let plevel = s:close_list(toc, plevel, level)
- endif
- let toc_text = s:process_tags_remove_links(text)
- let toc_text = s:process_tags_typefaces(toc_text)
- call add(toc, '
")
return 0
endif
return a:para
-endfunction "}}}
+endfunction
+
-function! s:close_tag_table(table, ldest) "{{{
+function! s:close_tag_table(table, ldest, header_ids)
" The first element of table list is a string which tells us if table should be centered.
" The rest elements are rows which are lists of columns:
- " ['center',
+ " ['center',
" [ CELL1, CELL2, CELL3 ],
" [ CELL1, CELL2, CELL3 ],
" [ CELL1, CELL2, CELL3 ],
" ]
" And CELLx is: { 'body': 'col_x', 'rowspan': r, 'colspan': c }
- function! s:sum_rowspan(table) "{{{
+ function! s:sum_rowspan(table)
let table = a:table
" Get max cells
- let max_cells = 0
+ let max_cells = 0
for row in table[1:]
let n_cells = len(row)
if n_cells > max_cells
@@ -633,9 +678,9 @@ function! s:close_tag_table(table, ldest) "{{{
endif
endfor
endfor
- endfunction "}}}
+ endfunction
- function! s:sum_colspan(table) "{{{
+ function! s:sum_colspan(table)
for row in a:table[1:]
let cols = 1
@@ -648,19 +693,19 @@ function! s:close_tag_table(table, ldest) "{{{
endif
endfor
endfor
- endfunction "}}}
+ endfunction
- function! s:close_tag_row(row, header, ldest) "{{{
+ function! s:close_tag_row(row, header, ldest, header_ids)
call add(a:ldest, '
')
- " Set tag element of columns
+ " Set tag element of columns
if a:header
let tag_name = 'th'
else
let tag_name = 'td'
end
- " Close tag of columns
+ " Close tag of columns
for cell in a:row
if cell.rowspan == 0 || cell.colspan == 0
continue
@@ -678,12 +723,12 @@ function! s:close_tag_table(table, ldest) "{{{
endif
call add(a:ldest, '<' . tag_name . rowspan_attr . colspan_attr .'>')
- call add(a:ldest, s:process_inline_tags(cell.body))
+ call add(a:ldest, s:process_inline_tags(cell.body, a:header_ids))
call add(a:ldest, ''. tag_name . '>')
endfor
call add(a:ldest, '
')
- endfunction "}}}
+ endfunction
let table = a:table
let ldest = a:ldest
@@ -691,7 +736,7 @@ function! s:close_tag_table(table, ldest) "{{{
call s:sum_rowspan(table)
call s:sum_colspan(table)
- if table[0] == 'center'
+ if table[0] ==# 'center'
call add(ldest, "
")
else
call add(ldest, "
")
@@ -711,45 +756,52 @@ function! s:close_tag_table(table, ldest) "{{{
if head > 0
for row in table[1 : head-1]
if !empty(filter(row, '!empty(v:val)'))
- call s:close_tag_row(row, 1, ldest)
+ call s:close_tag_row(row, 1, ldest, a:header_ids)
endif
endfor
for row in table[head+1 :]
- call s:close_tag_row(row, 0, ldest)
+ call s:close_tag_row(row, 0, ldest, a:header_ids)
endfor
else
for row in table[1 :]
- call s:close_tag_row(row, 0, ldest)
+ call s:close_tag_row(row, 0, ldest, a:header_ids)
endfor
endif
call add(ldest, "
")
let table = []
endif
return table
-endfunction "}}}
+endfunction
-function! s:close_tag_list(lists, ldest) "{{{
+
+function! s:close_tag_list(lists, ldest)
while len(a:lists)
let item = remove(a:lists, 0)
call insert(a:ldest, item[0])
endwhile
-endfunction! "}}}
+endfunction
+
-function! s:close_tag_def_list(deflist, ldest) "{{{
+function! s:close_tag_def_list(deflist, ldest)
if a:deflist
call insert(a:ldest, "")
return 0
endif
return a:deflist
-endfunction! "}}}
+endfunction
+
-function! s:process_tag_pre(line, pre) "{{{
+function! s:process_tag_pre(line, pre)
" pre is the list of [is_in_pre, indent_of_pre]
+ "XXX always outputs a single line or empty list!
let lines = []
let pre = a:pre
let processed = 0
- if !pre[0] && a:line =~ '^\s*{{{[^\(}}}\)]*\s*$'
+ "XXX huh?
+ "if !pre[0] && a:line =~# '^\s*{{{[^\(}}}\)]*\s*$'
+ if !pre[0] && a:line =~# '^\s*{{{'
let class = matchstr(a:line, '{{{\zs.*$')
+ "FIXME class cannot contain arbitrary strings
let class = substitute(class, '\s\+$', '', 'g')
if class != ""
call add(lines, "
")
@@ -758,22 +810,62 @@ function! s:process_tag_pre(line, pre) "{{{
endif
let pre = [1, len(matchstr(a:line, '^\s*\ze{{{'))]
let processed = 1
- elseif pre[0] && a:line =~ '^\s*}}}\s*$'
+ elseif pre[0] && a:line =~# '^\s*}}}\s*$'
let pre = [0, 0]
call add(lines, "
")
let processed = 1
elseif pre[0]
let processed = 1
- call add(lines, substitute(a:line, '^\s\{'.pre[1].'}', '', ''))
+ "XXX destroys indent in general!
+ "call add(lines, substitute(a:line, '^\s\{'.pre[1].'}', '', ''))
+ call add(lines, s:safe_html_preformatted(a:line))
endif
return [processed, lines, pre]
-endfunction "}}}
+endfunction
+
+
+function! s:process_tag_math(line, math)
+ " math is the list of [is_in_math, indent_of_math]
+ let lines = []
+ let math = a:math
+ let processed = 0
+ if !math[0] && a:line =~# '^\s*{{\$[^\(}}$\)]*\s*$'
+ let class = matchstr(a:line, '{{$\zs.*$')
+ "FIXME class cannot be any string!
+ let class = substitute(class, '\s\+$', '', 'g')
+ " store the environment name in a global variable in order to close the
+ " environment properly
+ let s:current_math_env = matchstr(class, '^%\zs\S\+\ze%')
+ if s:current_math_env != ""
+ call add(lines, substitute(class, '^%\(\S\+\)%', '\\begin{\1}', ''))
+ elseif class != ""
+ call add(lines, "\\\[".class)
+ else
+ call add(lines, "\\\[")
+ endif
+ let math = [1, len(matchstr(a:line, '^\s*\ze{{\$'))]
+ let processed = 1
+ elseif math[0] && a:line =~# '^\s*}}\$\s*$'
+ let math = [0, 0]
+ if s:current_math_env != ""
+ call add(lines, "\\end{".s:current_math_env."}")
+ else
+ call add(lines, "\\\]")
+ endif
+ let processed = 1
+ elseif math[0]
+ let processed = 1
+ call add(lines, substitute(a:line, '^\s\{'.math[1].'}', '', ''))
+ endif
+ return [processed, lines, math]
+endfunction
+
-function! s:process_tag_quote(line, quote) "{{{
+function! s:process_tag_quote(line, quote)
let lines = []
let quote = a:quote
let processed = 0
- if a:line =~ '^\s\{4,}\S'
+ if a:line =~# '^\s\{4,}\S'
if !quote
call add(lines, "
'
let chk = matchlist(a:line, a:rx_list)
- if len(chk) > 0
- if len(chk[1])>0
- "wildcard characters are difficult to match correctly
- if chk[1] =~ '[.*\\^$~]'
- let chk[1] ='\'.chk[1]
- endif
- let completion = match(g:vimwiki_listsyms, '\C' . chk[1])
- if completion >= 0 && completion <=4
- let st_tag = '
'
- endif
+ if !empty(chk) && len(chk[1]) > 0
+ let completion = index(vimwiki#vars#get_syntaxlocal('listsyms_list'), chk[1])
+ let n = len(vimwiki#vars#get_syntaxlocal('listsyms_list'))
+ if completion == 0
+ let st_tag = '
'
+ elseif completion > 0 && completion < n
+ let completion = float2nr(round(completion / (n-1.0) * 3.0 + 0.5 ))
+ let st_tag = '
'
endif
endif
- return [st_tag, en_tag]
- endfunction "}}}
+ return [st_tag, '']
+ endfunction
+
let in_list = (len(a:lists) > 0)
" If it is not list yet then do not process line that starts from *bold*
" text.
+ " XXX necessary? in *bold* text, no space must follow the first *
if !in_list
- let pos = match(a:line, g:vimwiki_rxBold)
- if pos != -1 && strpart(a:line, 0, pos) =~ '^\s*$'
+ let pos = match(a:line, '^\s*'.vimwiki#vars#get_syntaxlocal('rxBold'))
+ if pos != -1
return [0, []]
endif
endif
@@ -823,16 +916,16 @@ function! s:process_tag_list(line, lists) "{{{
let lines = []
let processed = 0
- if a:line =~ g:vimwiki_rxListBullet
- let lstSym = matchstr(a:line, '[*-]')
+ if a:line =~# '^\s*'.s:bullets.'\s'
+ let lstSym = matchstr(a:line, s:bullets)
let lstTagOpen = '
'
let lstTagClose = '
'
- let lstRegExp = g:vimwiki_rxListBullet
- elseif a:line =~ g:vimwiki_rxListNumber
- let lstSym = '#'
+ let lstRegExp = '^\s*'.s:bullets.'\s'
+ elseif a:line =~# '^\s*'.s:numbers.'\s'
+ let lstSym = matchstr(a:line, s:numbers)
let lstTagOpen = ''
let lstTagClose = ''
- let lstRegExp = g:vimwiki_rxListNumber
+ let lstRegExp = '^\s*'.s:numbers.'\s'
else
let lstSym = ''
let lstTagOpen = ''
@@ -846,9 +939,8 @@ function! s:process_tag_list(line, lists) "{{{
let line = substitute(a:line, '\t', repeat(' ', &tabstop), 'g')
let indent = stridx(line, lstSym)
- let checkbox = '\s*\[\(.\?\)\]\s*'
- let [st_tag, en_tag] = s:add_checkbox(line,
- \ lstRegExp.checkbox, '