From 3deb8b4b541940030011c5a5af1332d7830790a3 Mon Sep 17 00:00:00 2001 From: Anthony Perkins Date: Mon, 21 Mar 2022 13:10:23 +0000 Subject: [PATCH] Add vimwiki plugin --- .../start/vimwiki/.github/issue_template.md | 7 + .../vimwiki/.github/pull_request_template.md | 9 + pack/acp/start/vimwiki/.gitignore | 24 + pack/acp/start/vimwiki/.travis.yml | 27 + pack/acp/start/vimwiki/CONTRIBUTING.md | 72 + pack/acp/start/vimwiki/DesignNotes.md | 186 + pack/acp/start/vimwiki/Dockerfile | 23 + pack/acp/start/vimwiki/LICENSE.md | 22 + pack/acp/start/vimwiki/README-cn.md | 161 + pack/acp/start/vimwiki/README.md | 283 + .../start/vimwiki/autoload/vimwiki/base.vim | 2395 ++++ .../autoload/vimwiki/customwiki2html.sh | 62 + .../vimwiki/autoload/vimwiki/default.tpl | 12 + .../start/vimwiki/autoload/vimwiki/diary.vim | 436 + .../start/vimwiki/autoload/vimwiki/html.vim | 1744 +++ .../start/vimwiki/autoload/vimwiki/lst.vim | 1713 +++ .../autoload/vimwiki/markdown_base.vim | 162 + .../start/vimwiki/autoload/vimwiki/path.vim | 210 + .../start/vimwiki/autoload/vimwiki/style.css | 187 + .../start/vimwiki/autoload/vimwiki/tags.vim | 405 + .../start/vimwiki/autoload/vimwiki/tbl.vim | 861 ++ pack/acp/start/vimwiki/autoload/vimwiki/u.vim | 157 + .../start/vimwiki/autoload/vimwiki/vars.vim | 984 ++ pack/acp/start/vimwiki/doc/entries.png | Bin 0 -> 341380 bytes pack/acp/start/vimwiki/doc/lists.png | Bin 0 -> 430499 bytes pack/acp/start/vimwiki/doc/screenshot_1.png | Bin 0 -> 29362 bytes pack/acp/start/vimwiki/doc/screenshot_2.png | Bin 0 -> 49959 bytes pack/acp/start/vimwiki/doc/splash.png | Bin 0 -> 9699 bytes pack/acp/start/vimwiki/doc/todos.png | Bin 0 -> 369021 bytes pack/acp/start/vimwiki/doc/vimwiki.txt | 3988 ++++++ pack/acp/start/vimwiki/doc/wiki.png | Bin 0 -> 476675 bytes pack/acp/start/vimwiki/ftplugin/vimwiki.vim | 701 + pack/acp/start/vimwiki/plugin/vimwiki.vim | 469 + pack/acp/start/vimwiki/syntax/vimwiki.vim | 490 + .../start/vimwiki/syntax/vimwiki_default.vim | 110 + .../start/vimwiki/syntax/vimwiki_markdown.vim | 104 + .../syntax/vimwiki_markdown_custom.vim | 206 + .../start/vimwiki/syntax/vimwiki_media.vim | 85 + pack/acp/start/vimwiki/test/README.md | 75 + .../vimwiki/test/command_generate_links.vader | 103 + .../vimwiki/test/command_generate_tags.vader | 96 + .../acp/start/vimwiki/test/command_goto.vader | 64 + .../vimwiki/test/command_rename_link.vader | 189 + pack/acp/start/vimwiki/test/command_toc.vader | 149 + .../vimwiki/test/convert_default_html.vader | 59 + .../vimwiki/test/independent_runs/map.vader | 461 + .../test/independent_runs/search.vader | 66 + .../vimwiki/test/independent_runs/vader_setup | 1 + .../test/independent_runs/vader_teardown | 1 + .../start/vimwiki/test/link_creation.vader | 125 + .../link_markdown_multiple_per_file.vader | 225 + .../vimwiki/test/list_VimwikiReturn.vader | 282 + pack/acp/start/vimwiki/test/list_margin.vader | 108 + pack/acp/start/vimwiki/test/list_update.vader | 191 + .../start/vimwiki/test/resources/delay.wiki | 10923 ++++++++++++++++ .../test/resources/testmarkdown/buzz_bozz.md | 3 + .../test/resources/testmarkdown/index.md | 59 + .../resources/testwiki space/buzz bozz.wiki | 3 + .../test/resources/testwiki space/index.wiki | 30 + .../test/resources/testwiki/buzz_bozz.wiki | 3 + .../test/resources/testwiki/index.wiki | 35 + pack/acp/start/vimwiki/test/run_tests.sh | 248 + pack/acp/start/vimwiki/test/syntax.vader | 318 + .../start/vimwiki/test/table_autoformat.vader | 157 + .../start/vimwiki/test/tabnext_delay.vader | 32 + .../test/vader_includes/vader_setup.vader | 89 + .../test/vader_includes/vader_teardown.vader | 6 + pack/acp/start/vimwiki/test/vimrc | 67 + plugins.md | 1 + 69 files changed, 30464 insertions(+) create mode 100644 pack/acp/start/vimwiki/.github/issue_template.md create mode 100644 pack/acp/start/vimwiki/.github/pull_request_template.md create mode 100644 pack/acp/start/vimwiki/.gitignore create mode 100644 pack/acp/start/vimwiki/.travis.yml create mode 100644 pack/acp/start/vimwiki/CONTRIBUTING.md create mode 100644 pack/acp/start/vimwiki/DesignNotes.md create mode 100644 pack/acp/start/vimwiki/Dockerfile create mode 100644 pack/acp/start/vimwiki/LICENSE.md create mode 100644 pack/acp/start/vimwiki/README-cn.md create mode 100644 pack/acp/start/vimwiki/README.md create mode 100644 pack/acp/start/vimwiki/autoload/vimwiki/base.vim create mode 100755 pack/acp/start/vimwiki/autoload/vimwiki/customwiki2html.sh create mode 100644 pack/acp/start/vimwiki/autoload/vimwiki/default.tpl create mode 100644 pack/acp/start/vimwiki/autoload/vimwiki/diary.vim create mode 100644 pack/acp/start/vimwiki/autoload/vimwiki/html.vim create mode 100644 pack/acp/start/vimwiki/autoload/vimwiki/lst.vim create mode 100644 pack/acp/start/vimwiki/autoload/vimwiki/markdown_base.vim create mode 100644 pack/acp/start/vimwiki/autoload/vimwiki/path.vim create mode 100644 pack/acp/start/vimwiki/autoload/vimwiki/style.css create mode 100644 pack/acp/start/vimwiki/autoload/vimwiki/tags.vim create mode 100644 pack/acp/start/vimwiki/autoload/vimwiki/tbl.vim create mode 100644 pack/acp/start/vimwiki/autoload/vimwiki/u.vim create mode 100644 pack/acp/start/vimwiki/autoload/vimwiki/vars.vim create mode 100644 pack/acp/start/vimwiki/doc/entries.png create mode 100644 pack/acp/start/vimwiki/doc/lists.png create mode 100644 pack/acp/start/vimwiki/doc/screenshot_1.png create mode 100644 pack/acp/start/vimwiki/doc/screenshot_2.png create mode 100644 pack/acp/start/vimwiki/doc/splash.png create mode 100644 pack/acp/start/vimwiki/doc/todos.png create mode 100644 pack/acp/start/vimwiki/doc/vimwiki.txt create mode 100644 pack/acp/start/vimwiki/doc/wiki.png create mode 100644 pack/acp/start/vimwiki/ftplugin/vimwiki.vim create mode 100644 pack/acp/start/vimwiki/plugin/vimwiki.vim create mode 100644 pack/acp/start/vimwiki/syntax/vimwiki.vim create mode 100644 pack/acp/start/vimwiki/syntax/vimwiki_default.vim create mode 100644 pack/acp/start/vimwiki/syntax/vimwiki_markdown.vim create mode 100644 pack/acp/start/vimwiki/syntax/vimwiki_markdown_custom.vim create mode 100644 pack/acp/start/vimwiki/syntax/vimwiki_media.vim create mode 100644 pack/acp/start/vimwiki/test/README.md create mode 100644 pack/acp/start/vimwiki/test/command_generate_links.vader create mode 100644 pack/acp/start/vimwiki/test/command_generate_tags.vader create mode 100644 pack/acp/start/vimwiki/test/command_goto.vader create mode 100644 pack/acp/start/vimwiki/test/command_rename_link.vader create mode 100644 pack/acp/start/vimwiki/test/command_toc.vader create mode 100644 pack/acp/start/vimwiki/test/convert_default_html.vader create mode 100644 pack/acp/start/vimwiki/test/independent_runs/map.vader create mode 100644 pack/acp/start/vimwiki/test/independent_runs/search.vader create mode 120000 pack/acp/start/vimwiki/test/independent_runs/vader_setup create mode 120000 pack/acp/start/vimwiki/test/independent_runs/vader_teardown create mode 100644 pack/acp/start/vimwiki/test/link_creation.vader create mode 100644 pack/acp/start/vimwiki/test/link_markdown_multiple_per_file.vader create mode 100644 pack/acp/start/vimwiki/test/list_VimwikiReturn.vader create mode 100644 pack/acp/start/vimwiki/test/list_margin.vader create mode 100644 pack/acp/start/vimwiki/test/list_update.vader create mode 100755 pack/acp/start/vimwiki/test/resources/delay.wiki create mode 100644 pack/acp/start/vimwiki/test/resources/testmarkdown/buzz_bozz.md create mode 100644 pack/acp/start/vimwiki/test/resources/testmarkdown/index.md create mode 100644 pack/acp/start/vimwiki/test/resources/testwiki space/buzz bozz.wiki create mode 100644 pack/acp/start/vimwiki/test/resources/testwiki space/index.wiki create mode 100644 pack/acp/start/vimwiki/test/resources/testwiki/buzz_bozz.wiki create mode 100644 pack/acp/start/vimwiki/test/resources/testwiki/index.wiki create mode 100755 pack/acp/start/vimwiki/test/run_tests.sh create mode 100644 pack/acp/start/vimwiki/test/syntax.vader create mode 100644 pack/acp/start/vimwiki/test/table_autoformat.vader create mode 100644 pack/acp/start/vimwiki/test/tabnext_delay.vader create mode 100644 pack/acp/start/vimwiki/test/vader_includes/vader_setup.vader create mode 100644 pack/acp/start/vimwiki/test/vader_includes/vader_teardown.vader create mode 100644 pack/acp/start/vimwiki/test/vimrc diff --git a/pack/acp/start/vimwiki/.github/issue_template.md b/pack/acp/start/vimwiki/.github/issue_template.md new file mode 100644 index 0000000..d8cc987 --- /dev/null +++ b/pack/acp/start/vimwiki/.github/issue_template.md @@ -0,0 +1,7 @@ +Prior to submitting a new issue make sure to complete these steps: + +- [ ] Checkout the `dev` branch and confirm the issue is present there as well. + The `dev` branch contains fixes that may not have been merged to `master` yet. +- [ ] Post the syntax you are using (default/mediawiki/markdown) **and** your vimwiki settings from your `.vimrc` +- [ ] Provide a detailed description of the problem including **steps to reproduce the issue**. +- [ ] Include the output of `:VimwikiShowVersion`. diff --git a/pack/acp/start/vimwiki/.github/pull_request_template.md b/pack/acp/start/vimwiki/.github/pull_request_template.md new file mode 100644 index 0000000..9b797b8 --- /dev/null +++ b/pack/acp/start/vimwiki/.github/pull_request_template.md @@ -0,0 +1,9 @@ +Steps for submitting a pull request: + +- [ ] **ALL** pull requests should be made against the `dev` branch! +- [ ] Take a look at [CONTRIBUTING.MD](https://github.com/vimwiki/vimwiki/blob/dev/CONTRIBUTING.md) +- [ ] Reference any related issues. +- [ ] Provide a description of the proposed changes. +- [ ] PRs must pass Vint tests and add new Vader tests as applicable. +- [ ] Make sure to update the documentation in `doc/vimwiki.txt` if applicable, + including the Changelog and Contributors sections. diff --git a/pack/acp/start/vimwiki/.gitignore b/pack/acp/start/vimwiki/.gitignore new file mode 100644 index 0000000..3929660 --- /dev/null +++ b/pack/acp/start/vimwiki/.gitignore @@ -0,0 +1,24 @@ +# Local stuff +# This section is devoted to this project +############################## +doc/tags +.tags + +# Vim stuff +############################## +*.s[a-w][a-z] +*.un~ +Session.vim +.netrwhist +*~ + +# OS generated files +############################## +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db +vimtest diff --git a/pack/acp/start/vimwiki/.travis.yml b/pack/acp/start/vimwiki/.travis.yml new file mode 100644 index 0000000..cc519c7 --- /dev/null +++ b/pack/acp/start/vimwiki/.travis.yml @@ -0,0 +1,27 @@ +# No language: we download vim and compile it oursselves +language: generic + +cache: + # Enable cache folder + bundler: true + directories: + - $HOME/docker_images + +before_cache: + # Save tagged docker images. Info at https://github.com/travis-ci/travis-ci/issues/5358#issuecomment-248915326 + - > + mkdir -p $HOME/docker_images && docker images -a --filter='dangling=false' --format '{{.Repository}}:{{.Tag}} {{.ID}}' + | xargs -n 2 -t sh -c 'test -e $HOME/docker_images/$1.tar.gz || docker save $0 | gzip -2 > $HOME/docker_images/$1.tar.gz' + +before_install: + # Install docker + - n_image=$(ls -1 $HOME/docker_images/*.tar.gz | wc -l) + - if (( $n_image )); then ls $HOME/docker_images/*.tar.gz | xargs -I {file} sh -c "zcat {file} | docker load"; + else docker build --tag vimwiki .; + fi + +script: + # Run All tests + - pushd test + - bash run_tests.sh + - popd diff --git a/pack/acp/start/vimwiki/CONTRIBUTING.md b/pack/acp/start/vimwiki/CONTRIBUTING.md new file mode 100644 index 0000000..8d3e53b --- /dev/null +++ b/pack/acp/start/vimwiki/CONTRIBUTING.md @@ -0,0 +1,72 @@ +# Contributing to Vimwiki + +# 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. +3. If you are a first time contributor add your name to the list of contributors. + +**Testing:** Vimwiki uses [vader](https://github.com/junegunn/vader.vim) for unit tests and +[vint](https://github.com/Kuniwak/vint) for linting. Any new PRs must add new tests and pass all +linter checks. See the [test README](test/README.md) for more info. + +- In addition to the included tests, there are more example wikis that can be used for testing + [here](https://github.com/vimwiki/testwikis). + +# 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: + 1. `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). + 2. `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. + + diff --git a/pack/acp/start/vimwiki/DesignNotes.md b/pack/acp/start/vimwiki/DesignNotes.md new file mode 100644 index 0000000..5e7f957 --- /dev/null +++ b/pack/acp/start/vimwiki/DesignNotes.md @@ -0,0 +1,186 @@ +# Design Notes + +This file is meant to document design decisions and algorithms inside vimwiki +which are too large for code comments, and not necessarily interesting to +users. Please create a new section to document each behavior. + +## Formatting tables + +In vimwiki, formatting tables occurs dynamically, when navigating between cells +and adding new rows in a table in the Insert mode, or statically, when pressing +`gqq` or `gqw` (which are mappings for commands `VimwikiTableAlignQ` and +`VimwikiTableAlignW` respectively) in the Normal mode. It also triggers when +leaving Insert mode, provided variable `g:vimwiki_table_auto_fmt` is set. In +this section, the original and the newer optimized algorithms of table +formatting will be described and compared. + +### The older table formatting algorithm and why this is not optimal + +Let's consider a simple example. Open a new file, say _tmp.wiki_, and create a +new table with command `VimwikiTable`. This should create a blank table. + +``` +| | | | | | +|---|---|---|---|---| +| | | | | | +``` + +Let's put the cursor in the first header column of the table, enter the Insert +mode and type a name, say _Col1_. Then press _Tab_: the cursor will move to the +second column of the header and the table will get aligned (in the context of +the table formatting story, words _aligned_ and _formatted_ are considered as +synonyms). Now the table looks as in the following snippet. + +``` +| Col1 | | | | | +|------|---|---|---|---| +| | | | | | +``` + +Then, when moving cursor to the first data row (i.e. to the third line of the +table below the separator line) and typing anything here and there while +navigating using _Tab_ or _Enter_ (pressing this creates a new row below the +current row), the table shall keep formatting. Below is a result of such a +random edit. + +``` +| Col1 | | | | | +|------|-------|---|-------|----------| +| | Data1 | | Data2 | | +| | | | | New data | +``` + +The lowest row gets aligned when leaving the Insert mode. Let's copy _Data1_ +(using `viwy` or another keystroke) and paste it (using `p`) in the second data +row of the first column. Now the table looks mis-aligned (as we did not enter +the Insert mode). + +``` +| Col1 | | | | | +|------|-------|---|-------|----------| +| | Data1 | | Data2 | | +| Data1 | | | | New data | +``` + +This is not a big problem though, because we can put the cursor at _any_ place +in the table and press `gqq`: the table will get aligned. + +``` +| Col1 | | | | | +|-------|-------|---|-------|----------| +| | Data1 | | Data2 | | +| Data1 | | | | New data | +``` + +Now let's make real problems! Move the cursor to the lowest row and copy it +with `yy`. Then 500-fold paste it with `500p`. Now the table very long. Move +the cursor to the lowest row (by pressing `G`), enter the Insert mode, and try +a new random editing session by typing anything in cells with _Tab_ and _Enter_ +navigation interleaves. The editing got painfully slow, did not? + +The reason of the slowing down is the older table formatting algorithm. Every +time _Tab_ or _Enter_ get pressed down, all rows in the table get visited to +calculate a new alignment. Moreover, by design it may happen even more than +once per one press! + +```vim +function! s:kbd_create_new_row(cols, goto_first) + let cmd = "\o".s:create_empty_row(a:cols) + let cmd .= "\:call vimwiki#tbl#format(line('.'))\" + let cmd .= "\0" + if a:goto_first + let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'c', line('.'))\" + else + let cmd .= (col('.')-1)."l" + let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\" + endif + let cmd .= "a" + + return cmd +endfunction +``` + +Function `s:kbd_create_new_row()` is called when _Tab_ or _Enter_ get pressed. +Formatting of the whole table happens in function `vimwiki#tbl#format()`. But +remember that leaving the Insert mode triggers re-formatting of a table when +variable `g:vimwiki_table_auto_fmt` is set. This means that formatting of the +whole table is called on all those multiple interleaves between the Insert and +the Normal mode in `s:kbd_create_new_row` (notice `\`, `o`, etc.). + +### The newer table formating algorithm + +The newer algorithm was introduced to struggle against performance issues when +formatting large tables. + +Let's take the table from the previous example in an intermediate state. + +``` +| Col1 | | | | | +|------|-------|---|-------|----------| +| | Data1 | | Data2 | | +| Data1 | | | | New data | +``` + +Then move the cursor to the first data row, copy it with `yy`, go down to the +mis-aligned line, and press `5p`. Now we have a slightly bigger mis-aligned +table. + +``` +| Col1 | | | | | +|------|-------|---|-------|----------| +| | Data1 | | Data2 | | +| Data1 | | | | New data | +| | Data1 | | Data2 | | +| | Data1 | | Data2 | | +| | Data1 | | Data2 | | +| | Data1 | | Data2 | | +| | Data1 | | Data2 | | +``` + +Go down to the lowest, the 7th, data row and press `gq1`. Nothing happened. +Let's go to the second or the third data row and press `gq1` once again. Now +the table gets aligned. Let's undo formatting with `u`, go to the fourth row, +and press `gq1`. Now the table should look like in the following snippet. + +``` +| Col1 | | | | | +|------|-------|---|-------|----------| +| | Data1 | | Data2 | | +| Data1 | | | | New data | +| | Data1 | | Data2 | | +| | Data1 | | Data2 | | +| | Data1 | | Data2 | | +| | Data1 | | Data2 | | +| | Data1 | | Data2 | | +``` + +What a peculiar command! Does using it make any sense? Not much, honestly. +Except it shows how the newer optimized table formatting algorithm works in the +Insert mode. + +Indeed, the newer table formatting algorithm introduces a _viewport_ on a table. +Now, when pressing _Tab_ or _Enter_ in the Insert mode, only a small part of +rows are checked for possible formatting: two rows above the current line and +the current line itself (the latter gets preliminary shrunk with function +`s:fmt_row()`). If all three lines in the viewport are of the same length, then +nothing happens (case 1 in the example). If the second or the shrunk current +line is longer then the topmost line in the viewport, then the algorithm falls +back to the older formatting algorithm and the whole table gets aligned +(case 2). If the topmost line in the viewport is longer than the second +and the shrunk current line, then the two lowest lines get aligned according to +the topmost line (case 3). + +Performance of the newer formatting algorithm should not depend on the height +of the table. The newer algorithm should also be consistent with respect to +user editing experience. Indeed, as soon as a table should normally be edited +row by row from the top to the bottom, dynamic formatting should be both fast +(watching only three rows in a table, re-formatting only when the shrunk +current row gets longer than any of the two rows above) and eager (a table +should look formatted on every press on _Tab_ and _Enter_). However, the newer +algorithm differs from the older algorithm when starting editing a mis-aligned +table in an area where mis-aligned rows do not get into the viewport: in this +case the newer algorithm will format the table partly (in the rows of the +viewport) until one of the being edited cells grows in length to a value big +enough to trigger the older algorithm and the whole table gets aligned. When +partial formatting is not desirable, the whole table can be formatted by +pressing `gqq` in the Normal mode. diff --git a/pack/acp/start/vimwiki/Dockerfile b/pack/acp/start/vimwiki/Dockerfile new file mode 100644 index 0000000..b6ffdd0 --- /dev/null +++ b/pack/acp/start/vimwiki/Dockerfile @@ -0,0 +1,23 @@ +FROM testbed/vim:17 + +# add packages +RUN apk --no-cache add bash=~5.0 +RUN apk --no-cache add git=~2.22 +RUN apk --no-cache add python3=~3.7 + +# get vint for linting +RUN pip3 install vim-vint==0.3.21 + +# get vader for unit tests +RUN git clone -n https://github.com/junegunn/vader.vim /vader +WORKDIR /vader +RUN git checkout de8a976f1eae2c2b680604205c3e8b5c8882493c + +# build vim and neovim versions we want to test +# TODO uncomment nvim tag +WORKDIR / +RUN install_vim -tag v7.3.429 -name vim_7.3.429 -build \ + -tag v7.4.1099 -name vim_7.4.1099 -build \ + -tag v7.4.1546 -name vim_7.4.1546 -build \ + -tag v8.0.0027 -name vim_8.0.0027 -build \ + -tag v8.1.0519 -name vim_8.1.0519 -build \ diff --git a/pack/acp/start/vimwiki/LICENSE.md b/pack/acp/start/vimwiki/LICENSE.md new file mode 100644 index 0000000..cdf8546 --- /dev/null +++ b/pack/acp/start/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/pack/acp/start/vimwiki/README-cn.md b/pack/acp/start/vimwiki/README-cn.md new file mode 100644 index 0000000..5d1a064 --- /dev/null +++ b/pack/acp/start/vimwiki/README-cn.md @@ -0,0 +1,161 @@ +VimWiki —— Vim 个人 Wiki 插件 +============================================================================== + +[English](README.md) + +![screenshot1](doc/screenshot_1.png) +![screenshot2](doc/screenshot_2.png) * + +介绍 +------------------------------------------------------------------------------ + +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/pack/acp/start/vimwiki/README.md b/pack/acp/start/vimwiki/README.md new file mode 100644 index 0000000..d53526c --- /dev/null +++ b/pack/acp/start/vimwiki/README.md @@ -0,0 +1,283 @@ +![VimWiki: A Personal Wiki For Vim](doc/splash.png) + +[中文](README-cn.md) + +- [Intro](#intro) +- [Screenshots](#screenshots) +- [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) + +---- + +## Introduction + +VimWiki is a personal wiki for Vim -- a number of linked text files that have +their own syntax highlighting. See the [VimWiki Wiki](https://vimwiki.github.io/vimwikiwiki/) +for an example website built with VimWiki! + +For the latest features and fixes checkout the [dev branch](https://github.com/vimwiki/vimwiki/tree/dev). +If you are interested in contributing see [this section](#helping-vimwiki). + +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` (default is `\ww`) to go to your index +wiki file. By default, it is located in `~/vimwiki/index.wiki`. See `:h vimwiki_list` +for registering a different path/wiki. + +Feed it with the following example: + +```text += 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: + +```text += My knowledge base = + * [[Tasks]] -- things to be done _yesterday_!!! + * [[Project Gutenberg]] -- good books are power. + * Scratchpad -- various temporary stuff. +``` + +## Screenshots + +![Lists View](doc/lists.png) +![Entries View](doc/entries.png) +![Todos View](doc/todos.png) +![Wiki View](doc/wiki.png) + +## Installation + +VimWiki has been tested on **Vim >= 7.3**. It will likely work on older +versions but will not be officially supported. + +### 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 + +# to generate documentation i.e. ':h vimwiki' +vim -c 'helptags ~/.vim/pack/plugins/start/vimwiki/doc' -c quit + +``` + +Notes: + +- See `:h helptags` for issues with installing the documentation. +- For general information on vim packages see `:h packages`. + +#### Installation using [Pathogen](https://github.com/tpope/vim-pathogen) + +```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 + +``` + +#### Manual Install + +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 + +```text += Header1 = +== Header2 == +=== Header3 === + + +*bold* -- bold text +_italic_ -- italic text + +[[wiki link]] -- wiki link +[[wiki link|description]] -- wiki link with description +``` + +### Lists + +```text +* 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 + +**Note:** your terminal may prevent capturing some of the default bindings +listed below. See `:h vimwiki-local-mappings` for suggestions for alternative +bindings if you encounter a problem. + +#### Basic key bindings + +- `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. + +#### Advanced key bindings + +Refer to the complete documentation at `:h vimwiki-mappings` to see many +more bindings. + +## 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). + +**NOTE:** Only the default syntax ships with a built-in HTML converter. For +Markdown or MediaWiki see `:h vimwiki-option-custom_wiki2html`. Some examples +and 3rd party tools are available [here](https://vimwiki.github.io/vimwikiwiki/Related%20Tools.html#Related%20Tools-External%20Tools). + +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 + +[GitHub issues](https://github.com/vimwiki/vimwiki/issues) are the primary +method for raising bug reports or feature requests. + +Additional resources include the IRC channel [#vimwiki](https://webchat.freenode.net/?channels=#vimwiki) on Freenode +([webchat](https://webchat.freenode.net/?channels=#vimwiki), also synced to Matrix/Riot: `#freenode_#vimwiki:matrix.org` and [Telegram](https://t.me/joinchat/JqBaKBfWs04qNVrp5oWcMg)) +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. + +Also, take a look at [CONTRIBUTING.md](https://github.com/vimwiki/vimwiki/blob/master/CONTRIBUTING.md). + +---- + +## 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/pack/acp/start/vimwiki/autoload/vimwiki/base.vim b/pack/acp/start/vimwiki/autoload/vimwiki/base.vim new file mode 100644 index 0000000..4a13da8 --- /dev/null +++ b/pack/acp/start/vimwiki/autoload/vimwiki/base.vim @@ -0,0 +1,2395 @@ +" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99 +" Vimwiki autoload plugin file +" Desc: Basic functionality +" Home: https://github.com/vimwiki/vimwiki/ + +if exists('g:loaded_vimwiki_auto') || &compatible + finish +endif +let g:loaded_vimwiki_auto = 1 + + +let g:vimwiki_max_scan_for_caption = 5 + + +function! s:safesubstitute(text, search, replace, mode) abort + " Substitute regexp but do not interpret replace + let escaped = escape(a:replace, '\&') + return substitute(a:text, a:search, escaped, a:mode) +endfunction + + +function! s:vimwiki_get_known_syntaxes() abort + " 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#file_pattern(files) abort + " 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 + + +"FIXME TODO slow and faulty +function! vimwiki#base#subdir(path, filename) abort + 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 + let filename = a:filename + endif + 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], '/') + if len(res) > 0 + let res = res.'/' + endif + return res +endfunction + + +function! vimwiki#base#current_subdir() abort + return vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), expand('%:p')) +endfunction + + +function! vimwiki#base#invsubdir(subdir) abort + 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) abort + 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 + + +" helper: check if a link is a well formed wiki link +function! s:is_wiki_link(link_infos) abort + return a:link_infos.scheme =~# '\mwiki\d\+' || a:link_infos.scheme ==# 'diary' +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, ...) abort + if a:0 + let source_wiki = vimwiki#base#find_wiki(a:1) + let source_file = a:1 + else + let source_wiki = vimwiki#vars#get_bufferlocal('wiki_nr') + let source_file = vimwiki#path#current_wiki_file() + endif + + " get rid of '\' in escaped characters in []() style markdown links + " other style links don't allow '\' + let link_text = substitute(a:link_text, '\(\\\)\(\W\)\@=', '', 'g') + + 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 ==? '' + " interwiki link scheme is default + 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 + + let link_text = matchstr(link_text, '^'.vimwiki#vars#get_global('rxSchemes').':\zs.*\ze') + endif + + let is_wiki_link = s:is_wiki_link(link_infos) + + " 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\+' + + " interwiki link named wiki 'wn.name:link' format + let wnmatch = matchlist(link_text, '\m^wn\.\([a-zA-Z0-9\-_ ]\+\):\(.*\)') + if len(wnmatch) >= 2 && wnmatch[1] !=? '' && wnmatch[2] !=? '' + let wname = wnmatch[1] + for idx in range(vimwiki#vars#number_of_wikis()) + if vimwiki#vars#get_wikilocal('name', idx) ==# wname + " name matches! + let link_infos.index = idx + let link_text = wnmatch[2] + break + endif + endfor + if link_text !=# wnmatch[2] + " error: invalid wiki name + let link_infos.index = -2 + let link_infos.filename = '' + " use scheme field to return invalid wiki name + let link_infos.scheme = wname + return link_infos + endif + else + " interwiki link numbered wiki format + 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 + 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 ext = fnamemodify(link_text, ':e') + if ext ==? '' " append ext iff one not already present + let link_infos.filename .= vimwiki#vars#get_wikilocal('ext', link_infos.index) + endif + 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) abort + " handlers + function! s:win32_handler(url) abort + "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 + let url = shellescape(a:url, 1) + endif + execute 'silent ! start "Title" /B ' . url + + else + + 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 + endfunction + function! s:macunix_handler(url) abort + call system('open ' . shellescape(a:url).' &') + endfunction + function! s:linux_handler(url) abort + 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 + endtry + echomsg 'Vimwiki Error: Default Vimwiki link handler was unable to open the HTML file!' +endfunction + + +function! vimwiki#base#open_link(cmd, link, ...) abort + 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 . '''.' + elseif link_infos.index == -2 + " scheme field stores wiki name for this error case + echom 'Vimwiki Error: No wiki found with name "' . link_infos.scheme . '"' + else + echomsg 'Vimwiki Error: Unable to resolve link!' + endif + return + endif + + let is_wiki_link = s:is_wiki_link(link_infos) + + let vimwiki_prev_link = [] + " update previous link for wiki pages + if is_wiki_link + if a:0 + let vimwiki_prev_link = [a:1, []] + elseif vimwiki#u#ft_is_vw() + 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, is_wiki_link) + else + call vimwiki#base#system_open_link(link_infos.filename) + endif +endfunction + + +function! vimwiki#base#get_globlinks_escaped(...) abort + let s_arg_lead = a:0 > 0 ? a:1 : '' + " 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') + " Filter files whose path matches the user's argument leader + " " use smart case matching + let r_arg = substitute(s_arg_lead, '\u', '[\0\l\0]', 'g') + call filter(lst, '-1 != match(v:val, r_arg)') + " Apply fnameescape() to each item + call map(lst, 'fnameescape(v:val)') + " Return list (for customlist completion) + return lst +endfunction + + +" Optional pattern argument +function! vimwiki#base#generate_links(create, ...) abort + " Get pattern if present + " Globlal to script to be passed to closure + if a:0 + let s:pattern = a:1 + else + let s:pattern = '' + endif + + " Define link generator closure + let GeneratorLinks = copy(l:) + function! GeneratorLinks.f() abort + let lines = [] + + let links = vimwiki#base#get_wikilinks(vimwiki#vars#get_bufferlocal('wiki_nr'), 0, s:pattern) + call sort(links) + + let bullet = repeat(' ', vimwiki#lst#get_list_margin()) . vimwiki#lst#default_symbol().' ' + let l:diary_file_paths = vimwiki#diary#get_diary_files() + + for link in links + let link_infos = vimwiki#base#resolve_link(link) + if !vimwiki#base#is_diary_file(link_infos.filename, copy(l:diary_file_paths)) + if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown' + let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink1Template') + else + let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate1') + endif + + let link_caption = vimwiki#base#read_caption(link_infos.filename) + if link_caption ==? '' " default to link if caption not found + let link_caption = link + endif + + let entry = s:safesubstitute(link_tpl, '__LinkUrl__', link, '') + let entry = s:safesubstitute(entry, '__LinkDescription__', link_caption, '') + call add(lines, bullet. entry) + endif + endfor + + return lines + endfunction + + let links_rx = '\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxListBullet').'\)' + + call vimwiki#base#update_listing_in_buffer( + \ GeneratorLinks, + \ vimwiki#vars#get_global('links_header'), + \ links_rx, + \ line('$')+1, + \ vimwiki#vars#get_global('links_header_level'), + \ a:create) +endfunction + + +function! vimwiki#base#goto(...) abort + let key = a:0 > 0 ? a:1 : input('Enter name: ') + let anchor = a:0 > 1 ? a:2 : '' + + " Save current file pos + let vimwiki_prev_link = [vimwiki#path#current_wiki_file(), getpos('.')] + + call vimwiki#base#edit_file(':e', + \ vimwiki#vars#get_wikilocal('path') . key . vimwiki#vars#get_wikilocal('ext'), + \ anchor, + \ vimwiki_prev_link, + \ vimwiki#u#ft_is_vw()) +endfunction + + +function! vimwiki#base#backlinks() abort + 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 + if vimwiki#u#is_windows() + " TODO this is a temporary fix - see issue #478 + let target_file = substitute(target_file, '/', '\', 'g') + let current_filename = substitute(current_filename, '/', '\', 'g') + endif + " 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 +" If third argument: pattern to search for +function! vimwiki#base#find_files(wiki_nr, directories_only, ...) abort + 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 pattern is given, use it + " 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 a:0 && a:1 !=# '' + let pattern = a:1 + elseif vimwiki#vars#get_wikilocal('is_temporary_wiki', wiki_nr) + let pattern = '*'.ext + else + let pattern = '**/*'.ext + endif + let files = split(globpath(root_directory, pattern), '\n') + + " filter excluded files before returning + for pattern in vimwiki#vars#get_wikilocal('exclude_files') + let efiles = split(globpath(root_directory, pattern), '\n') + let files = filter(files, 'index(efiles, v:val) == -1') + endfor + + return files +endfunction + + +" 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 +" If pattern is not '', only filepaths matching pattern will be considered +function! vimwiki#base#get_wikilinks(wiki_nr, also_absolute_links, pattern) abort + let files = vimwiki#base#find_files(a:wiki_nr, 0, a:pattern) + 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 + if vimwiki#u#is_windows() + " TODO temporary fix see #478 + let wikifile = substitute(wikifile , '/', '\', 'g') + endif + 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 + if vimwiki#u#is_windows() + " TODO temporary fix see #478 + let wikifile = substitute(wikifile , '/', '\', 'g') + endif + let wikifile = '/'.vimwiki#path#relpath(cwd, wikifile) + call add(result, wikifile) + endfor + endif + return result +endfunction + + +" Returns: a list containing the links to all directories from the current file +function! vimwiki#base#get_wiki_directories(wiki_nr) abort + 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 + + +function! vimwiki#base#get_anchors(filename, syntax) abort + if !filereadable(a:filename) + return [] + endif + + 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) abort + 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 + + +" 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) abort + if !filereadable(a:wikifile) + return [] + endif + + let syntax = vimwiki#vars#get_wikilocal('syntax', a:idx) + if syntax ==# 'markdown' + let rx_link = vimwiki#vars#get_syntaxlocal('rxWeblink1MatchUrl', syntax) + else + let rx_link = vimwiki#vars#get_syntaxlocal('wikilink', syntax) + endif + + 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#check_links() abort + 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! vimwiki#base#edit_file(command, filename, anchor, ...) abort + 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'))) + 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 + + " 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 !vimwiki#u#ft_is_vw() && fname !~? '\m/$' + call vimwiki#u#ft_set() + 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 + let prev_links = vimwiki#vars#get_bufferlocal('prev_links') + call insert(prev_links, a:1) + call vimwiki#vars#set_bufferlocal('prev_links', prev_links) + endif +endfunction + + +function! vimwiki#base#search_word(wikiRx, cmd) abort + let match_line = search(a:wikiRx, 's'.a:cmd) + if match_line == 0 + echomsg 'Vimwiki: Wiki link not found' + endif +endfunction + + +" Returns part of the line that matches wikiRX at cursor +function! vimwiki#base#matchstr_at_cursor(wikiRX) abort + 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 + endwh + if ebeg >= 0 + return strpart(line, ebeg, elen) + else + return '' + endif +endfunction + + +function! vimwiki#base#replacestr_at_cursor(wikiRX, sub) abort + 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 + 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 +endfunction + + +function! s:print_wiki_list() abort + " find the max name length for prettier formatting + let max_len = 0 + for idx in range(vimwiki#vars#number_of_wikis()) + let wname = vimwiki#vars#get_wikilocal('name', idx) + if len(wname) > max_len + let max_len = len(wname) + endif + endfor + + " print each wiki, active wiki highlighted and marked with '*' + for idx in range(vimwiki#vars#number_of_wikis()) + if idx == vimwiki#vars#get_bufferlocal('wiki_nr') + let sep = '*' + echohl PmenuSel + else + let sep = ' ' + echohl None + endif + let wname = vimwiki#vars#get_wikilocal('name', idx) + let wpath = vimwiki#vars#get_wikilocal('path', idx) + if wname ==? '' + let wname = '----' + if max_len < 4 + let max_len = 4 + endif + endif + let wname = '"' . wname . '"' + echo printf('%2d %s %-*s %s', idx+1, sep, max_len+2, wname, wpath) + endfor + echohl None +endfunction + + +" Update link: in fname.ext +" Param: fname: the source file where to change links +" Param: old: url regex of old path relative to wiki root +" Param: new: url string of new path +function! s:update_wiki_link(fname, old, new) abort + echo 'Updating links in '.a:fname + let has_updates = 0 + let dest = [] + for line in readfile(a:fname) + 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... + if has_updates + call rename(a:fname, a:fname.'#vimwiki_upd#') + call writefile(dest, a:fname) + call delete(a:fname.'#vimwiki_upd#') + endif +endfunction + + +" Update link for all files in dir +" Param: old_url, new_url: path of the old, new url relative to ... +" Param: dir: directory of the files, relative to wiki_root +function! s:update_wiki_links(wiki_nr, dir, old_url, new_url) abort + " Get list of wiki files + let wiki_root = vimwiki#vars#get_wikilocal('path', a:wiki_nr) + let fsources = vimwiki#base#find_files(a:wiki_nr, 0) + + " Shorten dirname + let dir_rel_root = vimwiki#path#relpath(wiki_root, a:dir) + + " Cache relative url, because they are often the same, like `../dir1/vim-vimwiki.md` + let cache_dict = {} + + " Regex from path + function! s:compute_old_url_r(wiki_nr, dir_rel_fsource, old_url) abort + " Old url + let old_url_r = a:dir_rel_fsource . a:old_url + " Add potential ./ + let old_url_r = '\%(\.[/\\]\)\?' . old_url_r + " Compute old url regex with filename between \zs and \ze + let old_url_r = vimwiki#base#apply_template( + \ vimwiki#vars#get_syntaxlocal('WikiLinkMatchUrlTemplate', + \ vimwiki#vars#get_wikilocal('syntax', a:wiki_nr)), old_url_r, '', '') + + return old_url_r + endfunction + + " For each wikifile + for fsource in fsources + " Shorten fname directory + let fsource_rel_root = vimwiki#path#relpath(wiki_root, fsource) + let fsource_rel_root = fnamemodify(fsource_rel_root, ':h') + + " Compute old_url relative to fname + let dir_rel_fsource = vimwiki#path#relpath(fsource_rel_root, dir_rel_root) + " TODO get relpath coherent (and remove next 2 stuff) + " Remove the trailing ./ + if dir_rel_fsource =~# '.[/\\]$' + let dir_rel_fsource = dir_rel_fsource[:-3] + endif + " Append a / if needed + if !empty(dir_rel_fsource) && dir_rel_fsource !~# '[/\\]$' + let dir_rel_fsource .= '/' + endif + + " New url + let new_url = dir_rel_fsource . a:new_url + + " Old url + " Avoid E713 + let key = empty(dir_rel_fsource) ? 'NaF' : dir_rel_fsource + if index(keys(cache_dict), key) == -1 + let cache_dict[key] = s:compute_old_url_r( + \ a:wiki_nr, dir_rel_fsource, a:old_url) + endif + let old_url_r = cache_dict[key] + + " Update url in source file + call s:update_wiki_link(fsource, old_url_r, new_url) + endfor +endfunction + + +function! s:tail_name(fname) abort + let result = substitute(a:fname, ':', '__colon__', 'g') + let result = fnamemodify(result, ':t:r') + let result = substitute(result, '__colon__', ':', 'g') + return result +endfunction + + +function! s:get_wiki_buffers() abort + let blist = [] + let bcount = 1 + while bcount<=bufnr('$') + if bufexists(bcount) + let bname = fnamemodify(bufname(bcount), ':p') + " 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_links', bcount)] + call add(blist, bitem) + endif + endif + let bcount = bcount + 1 + endwhile + return blist +endfunction + + +function! s:open_wiki_buffer(item) abort + call vimwiki#base#edit_file(':e', a:item[0], '') + if !empty(a:item[1]) + call vimwiki#vars#set_bufferlocal('prev_links', a:item[1], a:item[0]) + endif +endfunction + + +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 + if exists('b:current_syntax') + let s:current_syntax=b:current_syntax + " Remove current syntax definition, as some syntax files (e.g. cpp.vim) + " do nothing if b:current_syntax is defined. + unlet b:current_syntax + endif + + " Some syntax files set up iskeyword which might scratch vimwiki a bit. + " Let us save and restore it later. + " let b:skip_set_iskeyword = 1 + let is_keyword = &iskeyword + + " Check for the existence of syntax files in the runtime path before + " attempting to include them. + " https://vi.stackexchange.com/a/10354 + " Previously, this used a try/catch block to intercept any errors thrown + " when attempting to include files. The error(s) interferred with running + " with Vader tests (specifically, testing VimwikiSearch). + if !empty(globpath(&runtimepath, 'syntax/'.a:filetype.'.vim')) + execute 'syntax include @'.group.' syntax/'.a:filetype.'.vim' + endif + if !empty(globpath(&runtimepath, 'after/syntax/'.a:filetype.'.vim')) + execute 'syntax include @'.group.' after/syntax/'.a:filetype.'.vim' + endif + + let &iskeyword = is_keyword + + if exists('s:current_syntax') + let b:current_syntax=s:current_syntax + 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 + + let concealpre = vimwiki#vars#get_global('conceal_pre') ? ' concealends' : '' + execute 'syntax region textSnip'.ft. + \ ' matchgroup='.a:textSnipHl. + \ ' start="'.a:start.'" end="'.a:end.'"'. + \ ' contains=@'.group.' keepend'.concealpre + + " A workaround to Issue 115: Nested Perl syntax highlighting differs from + " 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. + " 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 + endif +endfunction + + +" creates or updates auto-generated listings in a wiki file, like TOC, diary +" links, tags list etc. +" - the listing consists of a header and a list of strings provided by a funcref +" - 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(Generator, start_header, + \ content_regex, default_lnum, header_level, create) abort + " 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_level = 'rxH' . a:header_level . '_Template' + let header_rx = '\m^\s*'.substitute(vimwiki#vars#get_syntaxlocal(header_level), + \ '__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 = '' + " append newline if not replacing first line + if start_lnum > 1 + keepjumps call append(start_lnum -1, '') + let start_lnum += 1 + endif + endif + + let start_of_listing = start_lnum + + " write new listing + let new_header = whitespaces_in_first_line + \ . s:safesubstitute(vimwiki#vars#get_syntaxlocal(header_level), + \ '__Header__', a:start_header, '') + keepjumps call append(start_lnum - 1, new_header) + let start_lnum += 1 + let lines_diff += 1 + if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown' + for _ in range(vimwiki#vars#get_global('markdown_header_style')) + keepjumps call append(start_lnum - 1, '') + let start_lnum += 1 + let lines_diff += 1 + endfor + endif + for string in a:Generator.f() + keepjumps call append(start_lnum - 1, string) + let start_lnum += 1 + let lines_diff += 1 + endfor + + " remove empty line if end of file, otherwise append if needed + if start_lnum == line('$') + silent exe 'keepjumps ' . start_lnum.'delete _' + elseif 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 + + if is_cursor_after_listing + let winview_save.lnum += lines_diff + endif + call winrestview(winview_save) +endfunction + +function! vimwiki#base#find_next_task() abort + let taskRegex = vimwiki#vars#get_syntaxlocal('rxListItemWithoutCB') + \ . '\+\(\[ \]\s\+\)\zs' + call vimwiki#base#search_word(taskRegex, '') +endfunction + +function! vimwiki#base#find_next_link() abort + call vimwiki#base#search_word(vimwiki#vars#get_syntaxlocal('rxAnyLink'), '') +endfunction + + +function! vimwiki#base#find_prev_link() abort + "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, ...) abort + 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 + + if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown' + " markdown image ![]() + if lnk ==# '' + let lnk = matchstr(vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxImage')), + \ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl')) + if lnk !=# '' + if lnk !~# '\%(\%('.vimwiki#vars#get_global('web_schemes1').'\):\%(\/\/\)\?\)\S\{-1,}' + " prepend file: scheme so link is opened by sytem handler if it isn't a web url + let lnk = 'file:'.lnk + endif + endif + endif + endif + + 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 + 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 " cursor is not on a link + if a:0 >= 3 + execute 'normal! '.a:3 + elseif vimwiki#vars#get_global('create_link') + call vimwiki#base#normalize_link(0) + endif + endif +endfunction + + +function! vimwiki#base#go_back_link() abort + " try pop previous link from buffer list + let prev_links = vimwiki#vars#get_bufferlocal('prev_links') + if !empty(prev_links) + let prev_link = remove(prev_links, 0) + call vimwiki#vars#set_bufferlocal('prev_links', prev_links) + else + let prev_link = [] + endif + + 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 + + +function! vimwiki#base#goto_index(wnum, ...) abort + + " if wnum = 0 the current wiki is used + if a:wnum == 0 + let idx = vimwiki#vars#get_bufferlocal('wiki_nr') + if idx < 0 " not in a wiki + let idx = 0 + endif + else + let idx = a:wnum - 1 " convert to 0 based counting + endif + + if a:wnum > vimwiki#vars#number_of_wikis() + echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in your Vimwiki settings!' + return + endif + + 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 + + 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() abort + " 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 Error: Cannot delete "'.expand('%:t:r').'"!' + return + endtry + + call vimwiki#base#go_back_link() + execute 'bdelete! '.escape(fname, ' ') + + " reread buffer => deleted wiki link should appear as non-existent + if expand('%:p') !=? '' + execute 'e' + endif +endfunction + + +" Rename current file, update all links to it +function! vimwiki#base#rename_link() abort + " Get filename relative to wiki root + let subdir = vimwiki#vars#get_bufferlocal('subdir') + let old_fname = subdir.expand('%:t') + + " Get current path + let old_dir = expand('%:p:h') + + " there is no file (new one maybe) + if glob(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]es/[N]o? ') + if val !~? '^y' + return + endif + + let new_link = input('Enter new name: ') + + if new_link =~# '[/\\]' + echomsg 'Vimwiki Error: Cannot rename to a filename with path!' + return + endif + + if substitute(new_link, '\s', '', 'g') ==? '' + echomsg 'Vimwiki Error: Cannot rename to an empty filename!' + return + endif + + let url = matchstr(new_link, vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl')) + if url !=? '' + let new_link = url + endif + + let new_link = subdir.new_link + 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 file with such name exists + let fname = glob(new_fname) + if fname !=? '' + echomsg 'Vimwiki Error: Cannot rename to "'.new_fname.'". File with that name exist!' + return + endif + " rename wiki link file + try + 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 Error: Cannot rename "'.expand('%:t:r').'" to "'.new_fname.'"' + return + endtry + + let &buftype='nofile' + + let cur_buffer = [expand('%:p'), vimwiki#vars#get_bufferlocal('prev_links')] + + let blist = s:get_wiki_buffers() + + " save wiki buffers + for bitem in blist + execute ':b '.escape(bitem[0], ' ') + execute ':update' + endfor + + execute ':b '.escape(cur_buffer[0], ' ') + + " remove wiki buffers + for bitem in blist + execute 'bwipeout '.escape(bitem[0], ' ') + endfor + + let setting_more = &more + setlocal nomore + + " update links + call s:update_wiki_links(wiki_nr, old_dir, s:tail_name(old_fname), s:tail_name(new_fname)) + + " restore wiki buffers + for bitem in blist + 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]]) + " execute 'bwipeout '.escape(cur_buffer[0], ' ') + + echomsg 'Vimwiki: '.old_fname.' is renamed to '.new_fname + + let &more = setting_more +endfunction + + +function! vimwiki#base#ui_select() abort + call s:print_wiki_list() + let idx = input('Select Wiki by number and press (empty cancels): ') + if idx ==# '' + return + elseif idx !~# '\m[0-9]\+' + echo "\n" + echom 'Invalid wiki selection.' + return + endif + call vimwiki#base#goto_index(idx) +endfunction + + +function! vimwiki#base#TO_header(inner, including_subheaders, count) abort + let headers = s:collect_headers() + if empty(headers) + return + endif + + let current_line = line('.') + + let current_header_index = s:current_header(headers, current_line) + + if current_header_index < 0 + return + endif + + " 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 + + 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 a:inner + let first_line += 1 + let last_line = prevnonblank(last_line) + endif + + 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) abort + if col('.') == col('$')-1 + return + endif + + if a:visual + normal! `> + let sel_end = getpos('.') + normal! `< + let sel_start = getpos('.') + + let firsttime = sel_start == sel_end + + if firsttime + if !search('|\|\(-+-\)', 'cb', line('.')) + return + endif + if getline('.')[virtcol('.')] ==# '+' + normal! l + endif + if a:inner + normal! 2l + endif + let sel_start = getpos('.') + endif + + normal! `> + call search('|\|\(-+-\)', '', line('.')) + if getline('.')[virtcol('.')] ==# '+' + normal! l + endif + if a:inner + if firsttime || abs(sel_end[2] - getpos('.')[2]) != 2 + normal! 2h + endif + endif + let sel_end = getpos('.') + + call setpos('.', sel_start) + exe "normal! \" + call setpos('.', sel_end) + + " XXX: WORKAROUND. + " if blockwise selection is ended at | character then pressing j to extend + " selection further fails. But if we shake the cursor left and right then + " it works. + normal! hl + else + if !search('|\|\(-+-\)', 'cb', line('.')) + return + endif + if a:inner + normal! 2l + endif + normal! v + call search('|\|\(-+-\)', '', line('.')) + if !a:inner && getline('.')[virtcol('.')-1] ==# '|' + normal! h + elseif a:inner + normal! 2h + endif + endif +endfunction + + +function! vimwiki#base#TO_table_col(inner, visual) abort + let t_rows = vimwiki#tbl#get_rows(line('.')) + if empty(t_rows) + return + endif + + " TODO: refactor it! + if a:visual + normal! `> + let sel_end = getpos('.') + normal! `< + let sel_start = getpos('.') + + let firsttime = sel_start == sel_end + + if firsttime + " place cursor to the top row of the table + 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) =~# '^-+' + let s_flag = 'b' + else + let s_flag = 'cb' + endif + " search the column separator backwards + if !search('|\|\(-+-\)', s_flag, line('.')) + return + endif + " -+- column separator is matched --> move cursor to the + sign + if getline('.')[virtcol('.')] ==# '+' + normal! l + endif + " inner selection --> reduce selection + if a:inner + normal! 2l + endif + let sel_start = getpos('.') + endif + + normal! `> + if !firsttime && getline('.')[virtcol('.')] ==# '|' + normal! l + elseif a:inner && getline('.')[virtcol('.')+1] =~# '[|+]' + normal! 2l + endif + " search for the next column separator + call search('|\|\(-+-\)', '', line('.')) + " Outer selection selects a column without border on the right. So we move + " our cursor left if the previous search finds | border, not -+-. + if getline('.')[virtcol('.')] !=# '+' + normal! h + endif + if a:inner + " reduce selection a bit more if inner. + normal! h + endif + " expand selection to the bottom line of the table + call vimwiki#u#cursor(t_rows[-1][0], virtcol('.')) + let sel_end = getpos('.') + + call setpos('.', sel_start) + exe "normal! \" + call setpos('.', sel_end) + + else + " place cursor to the top row of the table + 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) =~# '^-+' + let s_flag = 'b' + else + let s_flag = 'cb' + endif + " search the column separator backwards + if !search('|\|\(-+-\)', s_flag, line('.')) + return + endif + " -+- column separator is matched --> move cursor to the + sign + if getline('.')[virtcol('.')] ==# '+' + normal! l + endif + " inner selection --> reduce selection + if a:inner + normal! 2l + endif + + exe "normal! \" + + " search for the next column separator + call search('|\|\(-+-\)', '', line('.')) + " Outer selection selects a column without border on the right. So we move + " our cursor left if the previous search finds | border, not -+-. + if getline('.')[virtcol('.')] !=# '+' + normal! h + endif + " reduce selection a bit more if inner. + if a:inner + normal! h + endif + " expand selection to the bottom line of the table + call vimwiki#u#cursor(t_rows[-1][0], virtcol('.')) + endif +endfunction + + +function! vimwiki#base#AddHeaderLevel(...) abort + if a:1 > 1 + call vimwiki#base#AddHeaderLevel(a:1 - 1) + endif + let lnum = line('.') + let line = getline(lnum) + let rxHdr = vimwiki#vars#get_syntaxlocal('rxH') + if line =~# '^\s*$' + return + endif + + if line =~# vimwiki#vars#get_syntaxlocal('rxHeader') + let level = vimwiki#u#count_first_sym(line) + if level < 6 + 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*', '&'.rxHdr.' ', '') + if vimwiki#vars#get_syntaxlocal('symH') + let line = substitute(line, '\s*$', ' '.rxHdr.'&', '') + endif + call setline(lnum, line) + endif +endfunction + + +function! vimwiki#base#RemoveHeaderLevel(...) abort + if a:1 > 1 + call vimwiki#base#RemoveHeaderLevel(a:1 - 1) + endif + let lnum = line('.') + let line = getline(lnum) + let rxHdr = vimwiki#vars#get_syntaxlocal('rxH') + if line =~# '^\s*$' + return + endif + + 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 =~# rxHdr.'\s' + + 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() abort + 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 + if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown' + if stridx(line_content, vimwiki#vars#get_syntaxlocal('rxH')) > 0 + continue " markdown headers must start in the first column + endif + 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) abort + 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) abort + 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() abort + 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() abort + 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() abort + 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) abort + 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) abort + 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 + + " use a dictionary function for closure like capability + " copy all local variables into dict (add a: if arguments are needed) + let GeneratorTOC = copy(l:) + function! GeneratorTOC.f() abort + 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 self.headers + let h_text = header[2] + let h_level = header[1] + " don't include the TOC's header itself + if h_text ==# self.toc_header_text + 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 = '' + if vimwiki#vars#get_global('toc_link_format') == 0 + for l in range(h_level-1) + if headers_levels[l][0] !=? '' + let h_complete_id .= headers_levels[l][0].'#' + endif + endfor + endif + let h_complete_id .= headers_levels[h_level-1][0] + + 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('Weblink2Template') + elseif vimwiki#vars#get_global('toc_link_format') == 0 + let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate2') + else + let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate1') + 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 + + return lines + endfunction + + let links_rx = '\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxListBullet').'\)' + + call vimwiki#base#update_listing_in_buffer( + \ GeneratorTOC, + \ toc_header_text, + \ links_rx, + \ 1, + \ vimwiki#vars#get_global('toc_header_level'), + \ 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) abort + 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) abort + " don't use an extension as part of the description + let url = substitute(a:url, '\'.vimwiki#vars#get_wikilocal('ext').'$', '', '') + " remove protocol and tld + let url = substitute(url, '^\a\+\d*:', '', '') + " remove absolute path prefix + let url = substitute(url, '^//', '', '') + let url = substitute(url, '^\([^/]\+\)\.\a\{2,4}/', '\1/', '') + let url_l = split(url, '/\|=\|-\|&\|?\|\.') + " case only a '-' + if url_l == [] + return '' + endif + let url_l = filter(url_l, 'v:val !=# ""') + if url_l[0] ==# 'www' + let url_l = url_l[1:] + endif + if url_l[-1] =~# '^\(htm\|html\|php\)$' + let url_l = url_l[0:-2] + endif + " remove words with black listed codepoints + " TODO mutualize blacklist in a variable + let url_l = filter(url_l, 'v:val !~? "[!\"$%&''()*+,:;<=>?\[\]\\^`{}]"') + " remove words consisting of only hexadecimal digits + let url_l = filter(url_l, 'v:val !~? "^\\x\\{4,}$" || v:val !~? "\\d"') + return join(url_l, ' ') +endfunction + +" An optional second argument allows you to pass in a list of diary files rather +" than generating a list on each call to the function. +function! vimwiki#base#is_diary_file(filename, ...) abort + let l:diary_file_paths = a:0 > 0 ? a:1 : vimwiki#diary#get_diary_files() + let l:normalised_file_paths = + \ map(l:diary_file_paths, 'vimwiki#path#normalize(v:val)') + let l:matching_files = + \ filter(l:normalised_file_paths, 'v:val =~# a:filename') + return len(l:matching_files) > 0 " filename is a diary file if match is found +endfunction + + +function! vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) abort + let url = matchstr(a:str, a:rxUrl) + if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown' && vimwiki#vars#get_global('markdown_link_ext') + " strip the extension if it exists so it doesn't get added multiple times + let url = substitute(url, '\'.vimwiki#vars#get_wikilocal('ext').'$', '', '') + endif + let descr = matchstr(a:str, a:rxDesc) + " Try to clean, do not work if bad link + if descr ==# '' + let descr = s:clean_url(url) + if descr ==# '' | return url | endif + 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) abort + 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! vimwiki#base#normalize_link_in_diary(lnk) abort + let sc = vimwiki#vars#get_wikilocal('links_space_char') + let link = a:lnk . vimwiki#vars#get_wikilocal('ext') + let link_wiki = substitute(vimwiki#vars#get_wikilocal('path') . '/' . link, '\s', sc, 'g') + let link_diary = substitute(vimwiki#vars#get_wikilocal('path') . '/' + \ . vimwiki#vars#get_wikilocal('diary_rel_path') . '/' . link, '\s', sc, 'g') + 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_is_date + let str = a:lnk + let rxUrl = vimwiki#vars#get_global('rxWord') + let rxDesc = '\d\d\d\d-\d\d-\d\d' + 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 + let rxUrl = '.*' + let rxDesc = '[^/]*$' + let template = vimwiki#vars#get_global('WikiLinkTemplate2') + else + let str = a:lnk + let rxUrl = '.*' + let rxDesc = '' + let template = vimwiki#vars#get_global('WikiLinkTemplate1') + endif + + if vimwiki#vars#get_wikilocal('syntax') ==? 'markdown' + let template = vimwiki#vars#get_syntaxlocal('Weblink1Template') + endif + + return vimwiki#base#normalize_link_helper(str, rxUrl, rxDesc, template) +endfunction + + +function! s:normalize_link_syntax_n() abort + + " 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 vimwiki#base#is_diary_file(expand('%:p')) + let sub = vimwiki#base#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() abort + 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 vimwiki#base#is_diary_file(expand('%:p')) + let sub = vimwiki#base#normalize_link_in_diary(@") + else + let sub = s:safesubstitute(vimwiki#vars#get_global('WikiLinkTemplate1'), + \ '__LinkUrl__', @", '') + endif + + " Put substitution in register " and change text + let sc = vimwiki#vars#get_wikilocal('links_space_char') + call setreg('"', substitute(substitute(sub, '\n', '', ''), '\s', sc, 'g'), 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) abort + 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() abort + let last_word = '\v.*<(\w+)\s*$' + let lines = map(filter(getline(1, '$'), 'v:val =~# "\\%({{{\\|`\\{3,\}\\|\\~\\{3,\}\\)" && 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 abort + return vimwiki#base#get_globlinks_escaped(a:ArgLead) +endfunction + + +function! vimwiki#base#read_caption(file) abort + let rx_header = vimwiki#vars#get_syntaxlocal('rxHeader') + + if filereadable(a:file) + for line in readfile(a:file, '', g:vimwiki_max_scan_for_caption) + if line =~# rx_header + return vimwiki#u#trim(matchstr(line, rx_header)) + endif + endfor + endif + + return '' +endfunction + + +" For commands VimwikiSearch and VWS +function! vimwiki#base#search(search_pattern) abort + if empty(a:search_pattern) + echomsg 'Vimwiki Error: No search pattern given.' + return + endif + + let pattern = a:search_pattern + + " If the pattern does not start with a '/', then we'll assume that a + " literal search is intended and enclose and escape it: + if match(pattern, '^/') == -1 + let pattern = '/'.escape(pattern, '\').'/' + endif + + let path = fnameescape(vimwiki#vars#get_wikilocal('path')) + let ext = vimwiki#vars#get_wikilocal('ext') + let cmd = 'lvimgrep '.pattern.' '.path.'**/*'.ext + + " Catch E480 error from lvimgrep if there's no match and present + " a friendlier error message. + try + execute cmd + catch + echomsg 'VimwikiSearch: No match found.' + endtry +endfunction + +function! vimwiki#base#deprecate(old, new) abort + echohl WarningMsg + echo a:old 'is deprecated and will be removed in future versions, use' a:new 'instead.' + echohl None +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/pack/acp/start/vimwiki/autoload/vimwiki/customwiki2html.sh b/pack/acp/start/vimwiki/autoload/vimwiki/customwiki2html.sh new file mode 100755 index 0000000..4818d02 --- /dev/null +++ b/pack/acp/start/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/pack/acp/start/vimwiki/autoload/vimwiki/default.tpl b/pack/acp/start/vimwiki/autoload/vimwiki/default.tpl new file mode 100644 index 0000000..35371d5 --- /dev/null +++ b/pack/acp/start/vimwiki/autoload/vimwiki/default.tpl @@ -0,0 +1,12 @@ + + + + +%title% + + + + +%content% + + diff --git a/pack/acp/start/vimwiki/autoload/vimwiki/diary.vim b/pack/acp/start/vimwiki/autoload/vimwiki/diary.vim new file mode 100644 index 0000000..46d14ce --- /dev/null +++ b/pack/acp/start/vimwiki/autoload/vimwiki/diary.vim @@ -0,0 +1,436 @@ +" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99 +" Vimwiki autoload plugin file +" Description: Handle diary notes +" Home: https://github.com/vimwiki/vimwiki/ + + +if exists('g:loaded_vimwiki_diary_auto') || &compatible + finish +endif +let g:loaded_vimwiki_diary_auto = 1 + + +function! s:prefix_zero(num) abort + if a:num < 10 + return '0'.a:num + endif + return a:num +endfunction + + +function! s:diary_path(...) abort + 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:diary_index(...) abort + 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 + + +function! vimwiki#diary#diary_date_link(...) abort + if a:0 + return strftime('%Y-%m-%d', a:1) + else + return strftime('%Y-%m-%d') + endif +endfunction + + +function! s:get_position_links(link) abort + let idx = -1 + let links = [] + if a:link =~# '^\d\{4}-\d\d-\d\d' + let links = map(vimwiki#diary#get_diary_files(), 'fnamemodify(v:val, ":t:r")') + " include 'today' into links + 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:get_month_name(month) abort + return vimwiki#vars#get_global('diary_months')[str2nr(a:month)] +endfunction + +function! s:get_first_header(fl) abort + " Get the first header in the file within the first s:vimwiki_max_scan_for_caption lines. + let header_rx = vimwiki#vars#get_syntaxlocal('rxHeader') + + for line in readfile(a:fl, '', g:vimwiki_max_scan_for_caption) + if line =~# header_rx + return vimwiki#u#trim(matchstr(line, header_rx)) + endif + endfor + return '' +endfunction + +function! s:get_all_headers(fl, maxlevel) abort + " Get a list of all headers in a file up to a given level. + " Returns a list whose elements are pairs [level, title] + let headers_rx = {} + for i in range(1, a:maxlevel) + let headers_rx[i] = vimwiki#vars#get_syntaxlocal('rxH'.i.'_Text') + endfor + + let headers = [] + for line in readfile(a:fl, '') + for [i, header_rx] in items(headers_rx) + if line =~# header_rx + call add(headers, [i, vimwiki#u#trim(matchstr(line, header_rx))]) + break + endif + endfor + endfor + return headers +endfunction + +function! s:count_headers_level_less_equal(headers, maxlevel) abort + " Count headers with level <= maxlevel in a list of [level, title] pairs. + let l:count = 0 + for [header_level, _] in a:headers + if header_level <= a:maxlevel + let l:count += 1 + endif + endfor + return l:count +endfunction + +function! s:get_min_header_level(headers) abort + " The minimum level of any header in a list of [level, title] pairs. + if len(a:headers) == 0 + return 0 + endif + let minlevel = a:headers[0][0] + for [level, _] in a:headers + let minlevel = min([minlevel, level]) + endfor + return minlevel +endfunction + + +function! s:read_captions(files) abort + let result = {} + let caption_level = vimwiki#vars#get_wikilocal('diary_caption_level') + + for fl in a:files + " remove paths and extensions + let fl_captions = {} + + " Default; no captions from the file. + let fl_captions['top'] = '' + let fl_captions['rest'] = [] + + if caption_level >= 0 && filereadable(fl) + if caption_level == 0 + " Take first header of any level as the top caption. + let fl_captions['top'] = s:get_first_header(fl) + else + let headers = s:get_all_headers(fl, caption_level) + if len(headers) > 0 + " If first header is the only one at its level or less, then make it the top caption. + let [first_level, first_header] = headers[0] + if s:count_headers_level_less_equal(headers, first_level) == 1 + let fl_captions['top'] = first_header + call remove(headers, 0) + endif + + let min_header_level = s:get_min_header_level(headers) + for [level, header] in headers + call add(fl_captions['rest'], [level - min_header_level, header]) + endfor + endif + endif + endif + + let fl_key = substitute(fnamemodify(fl, ':t'), vimwiki#vars#get_wikilocal('ext').'$', '', '') + let result[fl_key] = fl_captions + endfor + return result +endfunction + + +function! vimwiki#diary#get_diary_files() abort + 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) abort + 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) abort + if vimwiki#vars#get_wikilocal('diary_sort') ==? 'desc' + return reverse(sort(a:lst)) + else + return sort(a:lst) + endif +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, ...) abort + 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 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 + + 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 + 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 = 'diary:'.vimwiki#diary#diary_date_link() + endif + + call vimwiki#base#open_link(cmd, link, s:diary_index(wiki_nr)) +endfunction + +function! vimwiki#diary#goto_diary_index(wnum) abort + + " if wnum = 0 the current wiki is used + if a:wnum == 0 + let idx = vimwiki#vars#get_bufferlocal('wiki_nr') + if idx < 0 " not in a wiki + let idx = 0 + endif + else + let idx = a:wnum - 1 " convert to 0 based counting + endif + + if a:wnum > vimwiki#vars#number_of_wikis() + echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in g:vimwiki_list!' + return + endif + + 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 + + +function! vimwiki#diary#goto_next_day() abort + let link = '' + let [idx, links] = s:get_position_links(expand('%:t:r')) + + if idx == (len(links) - 1) + return + endif + + if idx != -1 && idx < len(links) - 1 + let link = 'diary:'.links[idx+1] + else + " goto today + let link = 'diary:'.vimwiki#diary#diary_date_link() + endif + + if len(link) + call vimwiki#base#open_link(':e ', link) + endif +endfunction + + +function! vimwiki#diary#goto_prev_day() abort + let link = '' + let [idx, links] = s:get_position_links(expand('%:t:r')) + + if idx == 0 + return + endif + + if idx > 0 + let link = 'diary:'.links[idx-1] + else + " goto today + let link = 'diary:'.vimwiki#diary#diary_date_link() + endif + + if len(link) + call vimwiki#base#open_link(':e ', link) + endif +endfunction + + +function! vimwiki#diary#generate_diary_section() abort + + let GeneratorDiary = copy(l:) + function! GeneratorDiary.f() abort + let lines = [] + + let links_with_captions = s:read_captions(vimwiki#diary#get_diary_files()) + let g_files = s:group_links(links_with_captions) + let g_keys = s:sort(keys(g_files)) + + for year in g_keys + if len(lines) > 0 + call add(lines, '') + endif + + call add(lines, substitute(vimwiki#vars#get_syntaxlocal('rxH2_Template'), '__Header__', year , '')) + + for month in s:sort(keys(g_files[year])) + call add(lines, '') + call add(lines, substitute(vimwiki#vars#get_syntaxlocal('rxH3_Template'), + \ '__Header__', s:get_month_name(month), '')) + + if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown' + for _ in range(vimwiki#vars#get_global('markdown_header_style')) + call add(lines, '') + endfor + endif + + for [fl, captions] in s:sort(items(g_files[year][month])) + let topcap = captions['top'] + 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(topcap) " When using markdown syntax, we should ensure we always have a link description. + let topcap = fl + endif + endif + + if empty(topcap) + let top_link_tpl = vimwiki#vars#get_global('WikiLinkTemplate1') + else + let top_link_tpl = link_tpl + endif + + let bullet = vimwiki#lst#default_symbol().' ' + let entry = substitute(top_link_tpl, '__LinkUrl__', fl, '') + let entry = substitute(entry, '__LinkDescription__', topcap, '') + " If single H1 then that will be used as the description for the link to the file + " if multple H1 then the filename will be used as the description for the link to the + " file and multiple H1 headers will be indented by shiftwidth + call add(lines, repeat(' ', vimwiki#lst#get_list_margin()).bullet.entry) + + let startindent = repeat(' ', vimwiki#lst#get_list_margin()) + let indentstring = repeat(' ', vimwiki#u#sw()) + + for [depth, subcap] in captions['rest'] + if empty(subcap) + continue + endif + let entry = substitute(link_tpl, '__LinkUrl__', fl.'#'.subcap, '') + let entry = substitute(entry, '__LinkDescription__', subcap, '') + " if single H1 then depth H2=0, H3=1, H4=2, H5=3, H6=4 + " if multiple H1 then depth H1= 0, H2=1, H3=2, H4=3, H5=4, H6=5 + " indent subsequent headers levels by shiftwidth + call add(lines, startindent.repeat(indentstring, depth+1).bullet.entry) + endfor + endfor + + endfor + endfor + + return lines + endfunction + + 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 = '^\%('.vimwiki#vars#get_syntaxlocal('rxHeader').'\)\|'. + \ '\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxListBullet').'\)' + + call vimwiki#base#update_listing_in_buffer( + \ GeneratorDiary, + \ vimwiki#vars#get_wikilocal('diary_header'), + \ content_rx, + \ 1, + \ 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) abort + 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) abort + 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/pack/acp/start/vimwiki/autoload/vimwiki/html.vim b/pack/acp/start/vimwiki/autoload/vimwiki/html.vim new file mode 100644 index 0000000..0da3d81 --- /dev/null +++ b/pack/acp/start/vimwiki/autoload/vimwiki/html.vim @@ -0,0 +1,1744 @@ +" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99 +" Vimwiki autoload plugin file +" Description: HTML export +" Home: https://github.com/vimwiki/vimwiki/ + + +if exists('g:loaded_vimwiki_html_auto') || &compatible + finish +endif +let g:loaded_vimwiki_html_auto = 1 + + +function! s:root_path(subdir) abort + return repeat('../', len(split(a:subdir, '[/\\]'))) +endfunction + + +function! s:syntax_supported() abort + return vimwiki#vars#get_wikilocal('syntax') ==? 'default' +endfunction + + +function! s:remove_blank_lines(lines) abort + while !empty(a:lines) && a:lines[-1] =~# '^\s*$' + call remove(a:lines, -1) + endwhile +endfunction + + +function! s:is_web_link(lnk) abort + if a:lnk =~# '^\%(https://\|http://\|www.\|ftp://\|file://\|mailto:\)' + return 1 + endif + return 0 +endfunction + + +function! s:is_img_link(lnk) abort + if tolower(a:lnk) =~# '\.\%(png\|jpg\|gif\|jpeg\)$' + return 1 + endif + return 0 +endfunction + + +function! s:has_abs_path(fname) abort + if a:fname =~# '\(^.:\)\|\(^/\)' + return 1 + endif + return 0 +endfunction + + +function! s:find_autoload_file(name) abort + for path in split(&runtimepath, ',') + let fname = path.'/autoload/vimwiki/'.a:name + if glob(fname) !=? '' + return fname + endif + endfor + return '' +endfunction + + +function! s:default_CSS_full_name(path) abort + let path = expand(a:path) + let css_full_name = path . vimwiki#vars#get_wikilocal('css_name') + return css_full_name +endfunction + + +function! s:create_default_CSS(path) abort + let css_full_name = s:default_CSS_full_name(a:path) + if glob(css_full_name) ==? '' + 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) + return 1 + endif + endif + return 0 +endfunction + + +function! s:template_full_name(name) abort + if a:name ==? '' + let name = vimwiki#vars#get_wikilocal('template_default') + else + let name = a:name + endif + + 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 + + +function! s:get_html_template(template) abort + " TODO: refactor it!!! + let lines=[] + + 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!' + endtry + endif + + 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 + + +function! s:safe_html_preformatted(line) abort + let line = substitute(a:line,'<','\<', 'g') + let line = substitute(line,'>','\>', 'g') + return line +endfunction + + +function! s:escape_html_attribute(string) abort + return substitute(a:string, '"', '\"', 'g') +endfunction + + +function! s:safe_html_line(line) abort + " 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') + + return line +endfunction + + +function! s:delete_html_files(path) abort + let htmlfiles = split(glob(a:path.'**/*.html'), '\n') + for fname in htmlfiles + " ignore user html files, e.g. search.html,404.html + 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(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 + + try + call delete(fname) + catch + echomsg 'Vimwiki Error: Cannot delete '.fname + endtry + endfor +endfunction + + +function! s:mid(value, cnt) abort + return strpart(a:value, a:cnt, len(a:value) - 2 * a:cnt) +endfunction + + +function! s:subst_func(line, regexp, func, ...) abort + " Substitute text found by regexp with result of + " func(matched) function. + + let pos = 0 + let lines = split(a:line, a:regexp, 1) + let res_line = '' + for line in lines + let res_line = res_line.line + let matched = matchstr(a:line, a:regexp, pos) + if 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 + + +function! s:process_date(placeholders, default_date) abort + if !empty(a:placeholders) + for [placeholder, row, idx] in a:placeholders + let [type, param] = placeholder + if type ==# 'date' && !empty(param) + return param + endif + endfor + endif + return a:default_date +endfunction + + +function! s:process_title(placeholders, default_title) abort + if !empty(a:placeholders) + for [placeholder, row, idx] in a:placeholders + let [type, param] = placeholder + if type ==# 'title' && !empty(param) + return param + endif + endfor + endif + return a:default_title +endfunction + + +function! s:is_html_uptodate(wikifile) abort + let tpl_time = -1 + + let tpl_file = s:template_full_name('') + if tpl_file !=? '' + let tpl_time = getftime(tpl_file) + endif + + let wikifile = fnamemodify(a:wikifile, ':p') + + if vimwiki#vars#get_wikilocal('html_filename_parameterization') + let parameterized_wikiname = s:parameterized_wikiname(wikifile) + let htmlfile = expand(vimwiki#vars#get_wikilocal('path_html') . + \ vimwiki#vars#get_bufferlocal('subdir') . parameterized_wikiname) + else + let htmlfile = expand(vimwiki#vars#get_wikilocal('path_html') . + \ vimwiki#vars#get_bufferlocal('subdir') . fnamemodify(wikifile, ':t:r').'.html') + endif + + if getftime(wikifile) <= getftime(htmlfile) && tpl_time <= getftime(htmlfile) + return 1 + endif + return 0 +endfunction + +function! s:parameterized_wikiname(wikifile) abort + let initial = fnamemodify(a:wikifile, ':t:r') + let lower_sanitized = tolower(initial) + let substituted = substitute(lower_sanitized, '[^a-z0-9_-]\+','-', 'g') + let substituted = substitute(substituted, '\-\+','-', 'g') + let substituted = substitute(substituted, '^-', '', 'g') + let substituted = substitute(substituted, '-$', '', 'g') + return substitute(substituted, '\-\+','-', 'g') . '.html' +endfunction + +function! s:html_insert_contents(html_lines, content) abort + let lines = [] + for line in a:html_lines + if line =~# '%content%' + let parts = split(line, '%content%', 1) + if empty(parts) + call extend(lines, a:content) + else + for idx in range(len(parts)) + call add(lines, parts[idx]) + if idx < len(parts) - 1 + call extend(lines, a:content) + endif + endfor + endif + else + call add(lines, line) + endif + endfor + return lines +endfunction + + +function! s:tag_eqin(value) abort + " mathJAX wants \( \) for inline maths + return '\('.s:mid(a:value, 1).'\)' +endfunction + + +function! s:tag_em(value) abort + return ''.s:mid(a:value, 1).'' +endfunction + + +function! s:tag_strong(value, header_ids) abort + let text = s:mid(a:value, 1) + let id = s:escape_html_attribute(text) + let complete_id = '' + for l in range(6) + if a:header_ids[l][0] !=? '' + let complete_id .= a:header_ids[l][0].'-' + endif + endfor + if a:header_ids[5][0] ==? '' + let complete_id = complete_id[:-2] + endif + let complete_id .= '-'.id + return ''.text.'' +endfunction + + +function! s:tag_tags(value, header_ids) abort + let complete_id = '' + for level in range(6) + if a:header_ids[level][0] !=? '' + let complete_id .= a:header_ids[level][0].'-' + endif + endfor + if a:header_ids[5][0] ==? '' + let complete_id = complete_id[:-2] + endif + let complete_id = s:escape_html_attribute(complete_id) + + let result = [] + for tag in split(a:value, ':') + let id = s:escape_html_attribute(tag) + call add(result, ''.tag.'') + endfor + return join(result) +endfunction + + +function! s:tag_todo(value) abort + return ''.a:value.'' +endfunction + + +function! s:tag_strike(value) abort + return ''.s:mid(a:value, 2).'' +endfunction + + +function! s:tag_super(value) abort + return ''.s:mid(a:value, 1).'' +endfunction + + +function! s:tag_sub(value) abort + return ''.s:mid(a:value, 2).'' +endfunction + + +function! s:tag_code(value) abort + let l:retstr = ' 0.5) + \ ? 'black' : 'white' + + let l:retstr .= + \ " style='background-color:" . l:str . + \ ';color:' . l:fg_color . ";'" + endif + + let l:retstr .= '>'.s:safe_html_preformatted(l:str).'' + return l:retstr +endfunction + + +" match n-th ARG within {{URL[|ARG1|ARG2|...]}} +" *c,d,e),... +function! s:incl_match_arg(nn_index) abort + let rx = vimwiki#vars#get_global('rxWikiInclPrefix'). vimwiki#vars#get_global('rxWikiInclUrl') + let rx = rx . repeat(vimwiki#vars#get_global('rxWikiInclSeparator') . + \ vimwiki#vars#get_global('rxWikiInclArg'), a:nn_index-1) + if a:nn_index > 0 + let rx = rx. vimwiki#vars#get_global('rxWikiInclSeparator'). '\zs' . + \ vimwiki#vars#get_global('rxWikiInclArg') . '\ze' + endif + let rx = rx . vimwiki#vars#get_global('rxWikiInclArgs') . + \ vimwiki#vars#get_global('rxWikiInclSuffix') + return rx +endfunction + + +function! s:linkify_link(src, descr) abort + let src_str = ' href="'.s:escape_html_attribute(a:src).'"' + let descr = vimwiki#u#trim(a:descr) + let descr = (descr ==? '' ? a:src : descr) + let descr_str = (descr =~# vimwiki#vars#get_global('rxWikiIncl') + \ ? s:tag_wikiincl(descr) + \ : descr) + return ''.descr_str.'' +endfunction + + +function! s:linkify_image(src, descr, verbatim_str) abort + let src_str = ' src="'.a:src.'"' + let descr_str = (a:descr !=? '' ? ' alt="'.a:descr.'"' : '') + let verbatim_str = (a:verbatim_str !=? '' ? ' '.a:verbatim_str : '') + return '' +endfunction + + +function! s:tag_weblink(value) abort + " Weblink Template -> descr + let str = a:value + let url = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl')) + let descr = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWeblinkMatchDescr')) + let line = s:linkify_link(url, descr) + return line +endfunction + + +function! s:tag_wikiincl(value) abort + " {{imgurl|arg1|arg2}} -> ??? + " {{imgurl}} -> + " {{imgurl|descr|style="A"}} -> descr + " {{imgurl|descr|class="B"}} -> descr + let str = a:value + " custom transclusions + let line = VimwikiWikiIncludeHandler(str) + " otherwise, assume image transclusion + if line ==? '' + let url_0 = matchstr(str, vimwiki#vars#get_global('rxWikiInclMatchUrl')) + let descr = matchstr(str, s:incl_match_arg(1)) + let verbatim_str = matchstr(str, s:incl_match_arg(2)) + + let link_infos = vimwiki#base#resolve_link(url_0) + + if link_infos.scheme =~# '\mlocal\|wiki\d\+\|diary' + let url = vimwiki#path#relpath(fnamemodify(s:current_html_file, ':h'), link_infos.filename) + " strip the .html extension when we have wiki links, so that the user can + " simply write {{image.png}} to include an image from the wiki directory + if link_infos.scheme =~# '\mwiki\d\+\|diary' + let url = fnamemodify(url, ':r') + endif + else + let url = link_infos.filename + endif + + let url = escape(url, '#') + let line = s:linkify_image(url, descr, verbatim_str) + endif + return line +endfunction + + +function! s:tag_wikilink(value) abort + " [[url]] -> url + " [[url|descr]] -> descr + " [[url|{{...}}]] -> ... + " [[fileurl.ext|descr]] -> descr + " [[dirurl/|descr]] -> descr + " [[url#a1#a2]] -> url#a1#a2 + " [[#a1#a2]] -> #a1#a2 + let str = a:value + let url = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl')) + let descr = matchstr(str, vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr')) + let descr = vimwiki#u#trim(descr) + let descr = (descr !=? '' ? descr : url) + + let line = VimwikiLinkConverter(url, s:current_wiki_file, s:current_html_file) + if line ==? '' + let link_infos = vimwiki#base#resolve_link(url, s:current_wiki_file) + + if link_infos.scheme ==# 'file' + " external file links are always absolute + let html_link = link_infos.filename + elseif link_infos.scheme ==# 'local' + let html_link = vimwiki#path#relpath(fnamemodify(s:current_html_file, ':h'), + \ link_infos.filename) + elseif link_infos.scheme =~# '\mwiki\d\+\|diary' + " wiki links are always relative to the current file + let html_link = vimwiki#path#relpath( + \ fnamemodify(s:current_wiki_file, ':h'), + \ fnamemodify(link_infos.filename, ':r')) + if html_link !~? '\m/$' + let html_link .= '.html' + endif + else " other schemes, like http, are left untouched + let html_link = link_infos.filename + endif + + if link_infos.anchor !=? '' + let anchor = substitute(link_infos.anchor, '#', '-', 'g') + let html_link .= '#'.anchor + endif + let line = html_link + endif + + let line = s:linkify_link(line, descr) + return line +endfunction + + +function! s:tag_remove_internal_link(value) abort + let value = s:mid(a:value, 2) + + let line = '' + if value =~# '|' + let link_parts = split(value, '|', 1) + else + let link_parts = split(value, '][', 1) + endif + + if len(link_parts) > 1 + if len(link_parts) < 3 + let style = '' + else + let style = link_parts[2] + endif + let line = link_parts[1] + else + let line = value + endif + return line +endfunction + + +function! s:tag_remove_external_link(value) abort + let value = s:mid(a:value, 1) + + let line = '' + if s:is_web_link(value) + let lnkElements = split(value) + let head = lnkElements[0] + let rest = join(lnkElements[1:]) + if rest ==? '' + let rest = head + endif + let line = rest + elseif s:is_img_link(value) + let line = '' + else + " [alskfj sfsf] shouldn't be a link. So return it as it was -- + " enclosed in [...] + let line = '['.value.']' + endif + return line +endfunction + + +function! s:make_tag(line, regexp, func, ...) abort + " Make tags for a given matched regexp. + " Exclude preformatted text and href links. + " FIXME + let patt_splitter = '\(`[^`]\+`\)\|'. + \ '\('.vimwiki#vars#get_syntaxlocal('rxPreStart').'.\+'. + \ vimwiki#vars#get_syntaxlocal('rxPreEnd').'\)\|'. + \ '\(\)\|'. + \ '\(\)\|'. + \ '\(\)\|'. + \ '\('.vimwiki#vars#get_syntaxlocal('rxEqIn').'\)' + + "FIXME FIXME !!! these can easily occur on the same line! + "XXX {{{ }}} ??? obsolete + if '`[^`]\+`' ==# a:regexp || '{{{.\+}}}' ==# a:regexp || + \ vimwiki#vars#get_syntaxlocal('rxEqIn') ==# a:regexp + let res_line = s:subst_func(a:line, a:regexp, a:func) + else + let pos = 0 + " split line with patt_splitter to have parts of line before and after + " href links, preformatted text + " ie: + " hello world `is just a` simple type of prg. + " result: + " ['hello world ', ' simple ', 'type of', ' prg'] + let lines = split(a:line, patt_splitter, 1) + let res_line = '' + for line in lines + if a:0 + let res_line = res_line.s:subst_func(line, a:regexp, a:func, a:1) + else + let res_line = res_line.s:subst_func(line, a:regexp, a:func) + endif + let res_line = res_line.matchstr(a:line, patt_splitter, pos) + let pos = matchend(a:line, patt_splitter, pos) + endfor + endif + return res_line +endfunction + + +function! s:process_tags_remove_links(line) abort + let line = a:line + let line = s:make_tag(line, '\[\[.\{-}\]\]', 's:tag_remove_internal_link') + let line = s:make_tag(line, '\[.\{-}\]', 's:tag_remove_external_link') + return line +endfunction + + +function! s:process_tags_typefaces(line, header_ids) abort + let line = a:line + let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxItalic'), 's:tag_em') + let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxBold'), 's:tag_strong', a:header_ids) + let line = s:make_tag(line, vimwiki#vars#get_global('rxTodo'), 's:tag_todo') + let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxDelText'), 's:tag_strike') + let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxSuperScript'), 's:tag_super') + let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxSubScript'), 's:tag_sub') + let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxCode'), 's:tag_code') + let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxEqIn'), 's:tag_eqin') + let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxTags'), 's:tag_tags', a:header_ids) + return line +endfunction + + +function! s:process_tags_links(line) abort + let line = a:line + let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxWikiLink'), 's:tag_wikilink') + let line = s:make_tag(line, vimwiki#vars#get_global('rxWikiIncl'), 's:tag_wikiincl') + let line = s:make_tag(line, vimwiki#vars#get_syntaxlocal('rxWeblink'), 's:tag_weblink') + return line +endfunction + + +function! s:process_inline_tags(line, header_ids) abort + let line = s:process_tags_links(a:line) + let line = s:process_tags_typefaces(line, a:header_ids) + return line +endfunction + + +function! s:close_tag_pre(pre, ldest) abort + if a:pre[0] + call insert(a:ldest, '') + return 0 + endif + return a:pre +endfunction + + +function! s:close_tag_math(math, ldest) abort + if a:math[0] + call insert(a:ldest, "\\\]") + return 0 + endif + return a:math +endfunction + + +function! s:close_tag_quote(quote, ldest) abort + if a:quote + call insert(a:ldest, '') + return 0 + endif + return a:quote +endfunction + + +function! s:close_tag_para(para, ldest) abort + if a:para + call insert(a:ldest, '

') + return 0 + endif + return a:para +endfunction + + +function! s:close_tag_table(table, ldest, header_ids) abort + " 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', + " [ CELL1, CELL2, CELL3 ], + " [ CELL1, CELL2, CELL3 ], + " [ CELL1, CELL2, CELL3 ], + " ] + " And CELLx is: { 'body': 'col_x', 'rowspan': r, 'colspan': c } + + function! s:sum_rowspan(table) abort + let table = a:table + + " Get max cells + let max_cells = 0 + for row in table[1:] + let n_cells = len(row) + if n_cells > max_cells + let max_cells = n_cells + end + endfor + + " Sum rowspan + for cell_idx in range(max_cells) + let rows = 1 + + for row_idx in range(len(table)-1, 1, -1) + if cell_idx >= len(table[row_idx]) + let rows = 1 + continue + endif + + if table[row_idx][cell_idx].rowspan == 0 + let rows += 1 + else " table[row_idx][cell_idx].rowspan == 1 + let table[row_idx][cell_idx].rowspan = rows + let rows = 1 + endif + endfor + endfor + endfunction + + function! s:sum_colspan(table) abort + for row in a:table[1:] + let cols = 1 + + for cell_idx in range(len(row)-1, 0, -1) + if row[cell_idx].colspan == 0 + let cols += 1 + else "row[cell_idx].colspan == 1 + let row[cell_idx].colspan = cols + let cols = 1 + endif + endfor + endfor + endfunction + + function! s:close_tag_row(row, header, ldest, header_ids) abort + call add(a:ldest, '') + + " Set tag element of columns + if a:header + let tag_name = 'th' + else + let tag_name = 'td' + end + + " Close tag of columns + for cell in a:row + if cell.rowspan == 0 || cell.colspan == 0 + continue + endif + + if cell.rowspan > 1 + let rowspan_attr = ' rowspan="' . cell.rowspan . '"' + else "cell.rowspan == 1 + let rowspan_attr = '' + endif + if cell.colspan > 1 + let colspan_attr = ' colspan="' . cell.colspan . '"' + else "cell.colspan == 1 + let colspan_attr = '' + endif + + call add(a:ldest, '<' . tag_name . rowspan_attr . colspan_attr .'>') + call add(a:ldest, s:process_inline_tags(cell.body, a:header_ids)) + call add(a:ldest, '') + endfor + + call add(a:ldest, '') + endfunction + + let table = a:table + let ldest = a:ldest + if len(table) + call s:sum_rowspan(table) + call s:sum_colspan(table) + + if table[0] ==# 'center' + call add(ldest, "") + else + call add(ldest, '
') + endif + + " Empty lists are table separators. + " Search for the last empty list. All the above rows would be a table header. + " We should exclude the first element of the table list as it is a text tag + " that shows if table should be centered or not. + let head = 0 + for idx in range(len(table)-1, 1, -1) + if empty(table[idx]) + let head = idx + break + endif + endfor + 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, a:header_ids) + endif + endfor + for row in table[head+1 :] + 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, a:header_ids) + endfor + endif + call add(ldest, '
') + let table = [] + endif + return table +endfunction + + +function! s:close_tag_list(lists, ldest) abort + while len(a:lists) + let item = remove(a:lists, 0) + call insert(a:ldest, item[0]) + endwhile +endfunction + + +function! s:close_tag_def_list(deflist, ldest) abort + if a:deflist + call insert(a:ldest, '') + return 0 + endif + return a:deflist +endfunction + + +function! s:process_tag_pre(line, pre) abort + " 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 + "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, '
')
+    else
+      call add(lines, '
')
+    endif
+    let pre = [1, len(matchstr(a:line, '^\s*\ze{{{'))]
+    let processed = 1
+  elseif pre[0] && a:line =~# '^\s*}}}\s*$'
+    let pre = [0, 0]
+    call add(lines, '
') + let processed = 1 + elseif pre[0] + let processed = 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 + + +function! s:process_tag_math(line, math) abort + " 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) abort + let lines = [] + let quote = a:quote + let processed = 0 + if a:line =~# '^\s\{4,}\S' + if !quote + call add(lines, '
') + let quote = 1 + endif + let processed = 1 + call add(lines, substitute(a:line, '^\s*', '', '')) + elseif quote + call add(lines, '
') + let quote = 0 + endif + return [processed, lines, quote] +endfunction + + +function! s:process_tag_list(line, lists) abort + + function! s:add_checkbox(line, rx_list) abort + let st_tag = '
  • ' + let chk = matchlist(a:line, a:rx_list) + 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 == -1 && chk[1] == vimwiki#vars#get_global('listsym_rejected') + 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, ''] + 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, '^\s*'.vimwiki#vars#get_syntaxlocal('rxBold')) + if pos != -1 + return [0, []] + endif + endif + + let lines = [] + let processed = 0 + + if a:line =~# '^\s*'.s:bullets.'\s' + let lstSym = matchstr(a:line, s:bullets) + let lstTagOpen = '
      ' + let lstTagClose = '
    ' + 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 = '^\s*'.s:numbers.'\s' + else + let lstSym = '' + let lstTagOpen = '' + let lstTagClose = '' + let lstRegExp = '' + endif + + if lstSym !=? '' + " To get proper indent level 'retab' the line -- change all tabs + " to spaces*tabstop + 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) + + if !in_list + call add(a:lists, [lstTagClose, indent]) + call add(lines, lstTagOpen) + elseif (in_list && indent > a:lists[-1][1]) + let item = remove(a:lists, -1) + call add(lines, item[0]) + + call add(a:lists, [lstTagClose, indent]) + call add(lines, lstTagOpen) + elseif (in_list && indent < a:lists[-1][1]) + while len(a:lists) && indent < a:lists[-1][1] + let item = remove(a:lists, -1) + call add(lines, item[0]) + endwhile + elseif in_list + let item = remove(a:lists, -1) + call add(lines, item[0]) + endif + + call add(a:lists, [en_tag, indent]) + call add(lines, st_tag) + call add(lines, substitute(a:line, lstRegExp.'\%('.checkbox.'\)\?', '', '')) + let processed = 1 + elseif in_list && a:line =~# '^\s\+\S\+' + if vimwiki#vars#get_global('list_ignore_newline') + call add(lines, a:line) + else + call add(lines, '
    '.a:line) + endif + let processed = 1 + else + call s:close_tag_list(a:lists, lines) + endif + return [processed, lines] +endfunction + + +function! s:process_tag_def_list(line, deflist) abort + let lines = [] + let deflist = a:deflist + let processed = 0 + let matches = matchlist(a:line, '\(^.*\)::\%(\s\|$\)\(.*\)') + if !deflist && len(matches) > 0 + call add(lines, '
    ') + let deflist = 1 + endif + if deflist && len(matches) > 0 + if matches[1] !=? '' + call add(lines, '
    '.matches[1].'
    ') + endif + if matches[2] !=? '' + call add(lines, '
    '.matches[2].'
    ') + endif + let processed = 1 + elseif deflist + let deflist = 0 + call add(lines, '
    ') + endif + return [processed, lines, deflist] +endfunction + + +function! s:process_tag_para(line, para) abort + let lines = [] + let para = a:para + let processed = 0 + if a:line =~# '^\s\{,3}\S' + if !para + call add(lines, '

    ') + let para = 1 + endif + let processed = 1 + if vimwiki#vars#get_global('text_ignore_newline') + call add(lines, a:line) + else + call add(lines, a:line.'
    ') + endif + elseif para && a:line =~# '^\s*$' + call add(lines, '

    ') + let para = 0 + endif + return [processed, lines, para] +endfunction + + +function! s:process_tag_h(line, id) abort + let line = a:line + let processed = 0 + let h_level = 0 + let h_text = '' + let h_id = '' + + if a:line =~# vimwiki#vars#get_syntaxlocal('rxHeader') + let h_level = vimwiki#u#count_first_sym(a:line) + endif + if h_level > 0 + + let h_text = vimwiki#u#trim(matchstr(line, vimwiki#vars#get_syntaxlocal('rxHeader'))) + let h_number = '' + let h_complete_id = '' + let h_id = s:escape_html_attribute(h_text) + let centered = (a:line =~# '^\s') + + if h_text !=# vimwiki#vars#get_global('toc_header') + + let a:id[h_level-1] = [h_text, a:id[h_level-1][1]+1] + + " reset higher level ids + for level in range(h_level, 5) + let a:id[level] = ['', 0] + endfor + + for l in range(h_level-1) + let h_number .= a:id[l][1].'.' + if a:id[l][0] !=? '' + let h_complete_id .= a:id[l][0].'-' + endif + endfor + let h_number .= a:id[h_level-1][1] + let h_complete_id .= a:id[h_level-1][0] + + if vimwiki#vars#get_global('html_header_numbering') + let num = matchstr(h_number, + \ '^\(\d.\)\{'.(vimwiki#vars#get_global('html_header_numbering')-1).'}\zs.*') + if !empty(num) + let num .= vimwiki#vars#get_global('html_header_numbering_sym') + endif + let h_text = num.' '.h_text + endif + let h_complete_id = s:escape_html_attribute(h_complete_id) + let h_part = '
    ' + let h_part .= '' + let h_part .= '
    ' + + let processed = 1 + endif + return [processed, line] +endfunction + + +function! s:process_tag_hr(line) abort + let line = a:line + let processed = 0 + if a:line =~# '^-----*$' + let line = '
    ' + let processed = 1 + endif + return [processed, line] +endfunction + + +function! s:process_tag_table(line, table, header_ids) abort + function! s:table_empty_cell(value) abort + let cell = {} + + if a:value =~# '^\s*\\/\s*$' + let cell.body = '' + let cell.rowspan = 0 + let cell.colspan = 1 + elseif a:value =~# '^\s*>\s*$' + let cell.body = '' + let cell.rowspan = 1 + let cell.colspan = 0 + elseif a:value =~# '^\s*$' + let cell.body = ' ' + let cell.rowspan = 1 + let cell.colspan = 1 + else + let cell.body = a:value + let cell.rowspan = 1 + let cell.colspan = 1 + endif + + return cell + endfunction + + function! s:table_add_row(table, line) abort + if empty(a:table) + if a:line =~# '^\s\+' + let row = ['center', []] + else + let row = ['normal', []] + endif + else + let row = [[]] + endif + return row + endfunction + + let table = a:table + let lines = [] + let processed = 0 + + if vimwiki#tbl#is_separator(a:line) + call extend(table, s:table_add_row(a:table, a:line)) + let processed = 1 + elseif vimwiki#tbl#is_table(a:line) + call extend(table, s:table_add_row(a:table, a:line)) + + let processed = 1 + " let cells = split(a:line, vimwiki#tbl#cell_splitter(), 1)[1: -2] + let cells = vimwiki#tbl#get_cells(a:line) + call map(cells, 's:table_empty_cell(v:val)') + call extend(table[-1], cells) + else + let table = s:close_tag_table(table, lines, a:header_ids) + endif + return [processed, lines, table] +endfunction + + +function! s:parse_line(line, state) abort + let state = {} + let state.para = a:state.para + let state.quote = a:state.quote + let state.pre = a:state.pre[:] + let state.math = a:state.math[:] + let state.table = a:state.table[:] + let state.lists = a:state.lists[:] + let state.deflist = a:state.deflist + let state.placeholder = a:state.placeholder + let state.header_ids = a:state.header_ids + + let res_lines = [] + let processed = 0 + let line = a:line + + if !processed + " allows insertion of plain text to the final html conversion + " for example: + " %plainhtml
    + " inserts the line above to the final html file (without %plainhtml prefix) + let trigger = '%plainhtml' + if line =~# '^\s*' . trigger + let lines = [] + let processed = 1 + + " if something precedes the plain text line, + " make sure everything gets closed properly + " before inserting plain text. this ensures that + " the plain text is not considered as + " part of the preceding structure + if processed && len(state.table) + let state.table = s:close_tag_table(state.table, lines, state.header_ids) + endif + if processed && state.deflist + let state.deflist = s:close_tag_def_list(state.deflist, lines) + endif + if processed && state.quote + let state.quote = s:close_tag_quote(state.quote, lines) + endif + if processed && state.para + let state.para = s:close_tag_para(state.para, lines) + endif + + " remove the trigger prefix + let pp = split(line, trigger)[0] + + call add(lines, pp) + call extend(res_lines, lines) + endif + endif + + let line = s:safe_html_line(a:line) + + " pres + if !processed + let [processed, lines, state.pre] = s:process_tag_pre(line, state.pre) + " pre is just fine to be in the list -- do not close list item here. + " if processed && len(state.lists) + " call s:close_tag_list(state.lists, lines) + " endif + if !processed + let [processed, lines, state.math] = s:process_tag_math(line, state.math) + endif + if processed && len(state.table) + let state.table = s:close_tag_table(state.table, lines, state.header_ids) + endif + if processed && state.deflist + let state.deflist = s:close_tag_def_list(state.deflist, lines) + endif + if processed && state.quote + let state.quote = s:close_tag_quote(state.quote, lines) + endif + if processed && state.para + let state.para = s:close_tag_para(state.para, lines) + endif + call extend(res_lines, lines) + endif + + + if !processed + if line =~# vimwiki#vars#get_syntaxlocal('rxComment') + let processed = 1 + endif + endif + + " nohtml -- placeholder + if !processed + if line =~# '\m^\s*%nohtml\s*$' + let processed = 1 + let state.placeholder = ['nohtml'] + endif + endif + + " title -- placeholder + if !processed + if line =~# '\m^\s*%title\%(\s.*\)\?$' + let processed = 1 + let param = matchstr(line, '\m^\s*%title\s\+\zs.*') + let state.placeholder = ['title', param] + endif + endif + + " date -- placeholder + if !processed + if line =~# '\m^\s*%date\%(\s.*\)\?$' + let processed = 1 + let param = matchstr(line, '\m^\s*%date\s\+\zs.*') + let state.placeholder = ['date', param] + endif + endif + + " html template -- placeholder + if !processed + if line =~# '\m^\s*%template\%(\s.*\)\?$' + let processed = 1 + let param = matchstr(line, '\m^\s*%template\s\+\zs.*') + let state.placeholder = ['template', param] + endif + endif + + + " tables + if !processed + let [processed, lines, state.table] = s:process_tag_table(line, state.table, state.header_ids) + call extend(res_lines, lines) + endif + + + " lists + if !processed + let [processed, lines] = s:process_tag_list(line, state.lists) + if processed && state.quote + let state.quote = s:close_tag_quote(state.quote, lines) + endif + if processed && state.pre[0] + let state.pre = s:close_tag_pre(state.pre, lines) + endif + if processed && state.math[0] + let state.math = s:close_tag_math(state.math, lines) + endif + if processed && len(state.table) + let state.table = s:close_tag_table(state.table, lines, state.header_ids) + endif + if processed && state.deflist + let state.deflist = s:close_tag_def_list(state.deflist, lines) + endif + if processed && state.para + let state.para = s:close_tag_para(state.para, lines) + endif + + call map(lines, 's:process_inline_tags(v:val, state.header_ids)') + + call extend(res_lines, lines) + endif + + + " headers + if !processed + let [processed, line] = s:process_tag_h(line, state.header_ids) + if processed + call s:close_tag_list(state.lists, res_lines) + let state.table = s:close_tag_table(state.table, res_lines, state.header_ids) + let state.pre = s:close_tag_pre(state.pre, res_lines) + let state.math = s:close_tag_math(state.math, res_lines) + let state.quote = s:close_tag_quote(state.quote, res_lines) + let state.para = s:close_tag_para(state.para, res_lines) + + call add(res_lines, line) + endif + endif + + + " quotes + if !processed + let [processed, lines, state.quote] = s:process_tag_quote(line, state.quote) + if processed && len(state.lists) + call s:close_tag_list(state.lists, lines) + endif + if processed && state.deflist + let state.deflist = s:close_tag_def_list(state.deflist, lines) + endif + if processed && len(state.table) + let state.table = s:close_tag_table(state.table, lines, state.header_ids) + endif + if processed && state.pre[0] + let state.pre = s:close_tag_pre(state.pre, lines) + endif + if processed && state.math[0] + let state.math = s:close_tag_math(state.math, lines) + endif + if processed && state.para + let state.para = s:close_tag_para(state.para, lines) + endif + + call map(lines, 's:process_inline_tags(v:val, state.header_ids)') + + call extend(res_lines, lines) + endif + + + " horizontal rules + if !processed + let [processed, line] = s:process_tag_hr(line) + if processed + call s:close_tag_list(state.lists, res_lines) + let state.table = s:close_tag_table(state.table, res_lines, state.header_ids) + let state.pre = s:close_tag_pre(state.pre, res_lines) + let state.math = s:close_tag_math(state.math, res_lines) + call add(res_lines, line) + endif + endif + + + " definition lists + if !processed + let [processed, lines, state.deflist] = s:process_tag_def_list(line, state.deflist) + + call map(lines, 's:process_inline_tags(v:val, state.header_ids)') + + call extend(res_lines, lines) + endif + + + "" P + if !processed + let [processed, lines, state.para] = s:process_tag_para(line, state.para) + if processed && len(state.lists) + call s:close_tag_list(state.lists, lines) + endif + if processed && state.quote + let state.quote = s:close_tag_quote(state.quote, res_lines) + endif + if processed && state.pre[0] + let state.pre = s:close_tag_pre(state.pre, res_lines) + endif + if processed && state.math[0] + let state.math = s:close_tag_math(state.math, res_lines) + endif + if processed && len(state.table) + let state.table = s:close_tag_table(state.table, res_lines, state.header_ids) + endif + + call map(lines, 's:process_inline_tags(v:val, state.header_ids)') + + call extend(res_lines, lines) + endif + + + "" add the rest + if !processed + call add(res_lines, line) + endif + + return [res_lines, state] + +endfunction + + +function! s:use_custom_wiki2html() abort + let custom_wiki2html = vimwiki#vars#get_wikilocal('custom_wiki2html') + return !empty(custom_wiki2html) && + \ (s:file_exists(custom_wiki2html) || s:binary_exists(custom_wiki2html)) +endfunction + + +function! vimwiki#html#CustomWiki2HTML(path, wikifile, force) abort + call vimwiki#path#mkdir(a:path) + let output = system(vimwiki#vars#get_wikilocal('custom_wiki2html'). ' '. + \ a:force. ' '. + \ vimwiki#vars#get_wikilocal('syntax'). ' '. + \ strpart(vimwiki#vars#get_wikilocal('ext'), 1). ' '. + \ shellescape(a:path). ' '. + \ shellescape(a:wikifile). ' '. + \ shellescape(s:default_CSS_full_name(a:path)). ' '. + \ (len(vimwiki#vars#get_wikilocal('template_path')) > 1 ? + \ shellescape(expand(vimwiki#vars#get_wikilocal('template_path'))) : '-'). ' '. + \ (len(vimwiki#vars#get_wikilocal('template_default')) > 0 ? + \ vimwiki#vars#get_wikilocal('template_default') : '-'). ' '. + \ (len(vimwiki#vars#get_wikilocal('template_ext')) > 0 ? + \ vimwiki#vars#get_wikilocal('template_ext') : '-'). ' '. + \ (len(vimwiki#vars#get_bufferlocal('subdir')) > 0 ? + \ shellescape(s:root_path(vimwiki#vars#get_bufferlocal('subdir'))) : '-'). ' '. + \ (len(vimwiki#vars#get_wikilocal('custom_wiki2html_args')) > 0 ? + \ vimwiki#vars#get_wikilocal('custom_wiki2html_args') : '-')) + " Echo if non void + if output !~? '^\s*$' + echomsg output + endif +endfunction + + +function! s:convert_file(path_html, wikifile) abort + let done = 0 + + let wikifile = fnamemodify(a:wikifile, ':p') + + let path_html = expand(a:path_html).vimwiki#vars#get_bufferlocal('subdir') + let htmlfile = fnamemodify(wikifile, ':t:r').'.html' + + " the currently processed file name is needed when processing links + " yeah yeah, shame on me for using (quasi-) global variables + let s:current_wiki_file = wikifile + let s:current_html_file = path_html . htmlfile + + if s:use_custom_wiki2html() + let force = 1 + call vimwiki#html#CustomWiki2HTML(path_html, wikifile, force) + let done = 1 + endif + + if s:syntax_supported() && done == 0 + let lsource = readfile(wikifile) + let ldest = [] + + call vimwiki#path#mkdir(path_html) + + " nohtml placeholder -- to skip html generation. + let nohtml = 0 + + " template placeholder + let template_name = '' + + " for table of contents placeholders. + let placeholders = [] + + " current state of converter + let state = {} + let state.para = 0 + let state.quote = 0 + let state.pre = [0, 0] " [in_pre, indent_pre] + let state.math = [0, 0] " [in_math, indent_math] + let state.table = [] + let state.deflist = 0 + let state.lists = [] + let state.placeholder = [] + let state.header_ids = [['', 0], ['', 0], ['', 0], ['', 0], ['', 0], ['', 0]] + " [last seen header text in this level, number] + + " prepare constants for s:safe_html_line() + let s:lt_pattern = '<' + let s:gt_pattern = '>' + if vimwiki#vars#get_global('valid_html_tags') !=? '' + let tags = join(split(vimwiki#vars#get_global('valid_html_tags'), '\s*,\s*'), '\|') + let s:lt_pattern = '\c<\%(/\?\%('.tags.'\)\%(\s\{-1}\S\{-}\)\{-}/\?>\)\@!' + let s:gt_pattern = '\c\%(' + endif + + " prepare regexps for lists + let s:bullets = '[*-]' + let s:numbers = '\C\%(#\|\d\+)\|\d\+\.\|[ivxlcdm]\+)\|[IVXLCDM]\+)\|\l\{1,2})\|\u\{1,2})\)' + + for line in lsource + let oldquote = state.quote + let [lines, state] = s:parse_line(line, state) + + " Hack: There could be a lot of empty strings before s:process_tag_quote + " find out `quote` is over. So we should delete them all. Think of the way + " to refactor it out. + if oldquote != state.quote + call s:remove_blank_lines(ldest) + endif + + if !empty(state.placeholder) + if state.placeholder[0] ==# 'nohtml' + let nohtml = 1 + break + elseif state.placeholder[0] ==# 'template' + let template_name = state.placeholder[1] + else + call add(placeholders, [state.placeholder, len(ldest), len(placeholders)]) + endif + let state.placeholder = [] + endif + + call extend(ldest, lines) + endfor + + + if nohtml + echon "\r".'%nohtml placeholder found' + return '' + endif + + call s:remove_blank_lines(ldest) + + " process end of file + " close opened tags if any + let lines = [] + call s:close_tag_quote(state.quote, lines) + call s:close_tag_para(state.para, lines) + call s:close_tag_pre(state.pre, lines) + call s:close_tag_math(state.math, lines) + call s:close_tag_list(state.lists, lines) + call s:close_tag_def_list(state.deflist, lines) + call s:close_tag_table(state.table, lines, state.header_ids) + call extend(ldest, lines) + + let title = s:process_title(placeholders, fnamemodify(a:wikifile, ':t:r')) + let date = s:process_date(placeholders, strftime('%Y-%m-%d')) + let wiki_path = strpart(s:current_wiki_file, strlen(vimwiki#vars#get_wikilocal('path'))) + + let html_lines = s:get_html_template(template_name) + + " processing template variables (refactor to a function) + call map(html_lines, 'substitute(v:val, "%title%", "'. title .'", "g")') + call map(html_lines, 'substitute(v:val, "%date%", "'. date .'", "g")') + call map(html_lines, 'substitute(v:val, "%root_path%", "'. + \ s:root_path(vimwiki#vars#get_bufferlocal('subdir')) .'", "g")') + call map(html_lines, 'substitute(v:val, "%wiki_path%", "'. wiki_path .'", "g")') + + let css_name = expand(vimwiki#vars#get_wikilocal('css_name')) + let css_name = substitute(css_name, '\', '/', 'g') + call map(html_lines, 'substitute(v:val, "%css%", "'. css_name .'", "g")') + + let enc = &fileencoding + if enc ==? '' + let enc = &encoding + endif + call map(html_lines, 'substitute(v:val, "%encoding%", "'. enc .'", "g")') + + let html_lines = s:html_insert_contents(html_lines, ldest) " %contents% + + call writefile(html_lines, path_html.htmlfile) + let done = 1 + + endif + + if done == 0 + echomsg 'Vimwiki Error: Conversion to HTML is not supported for this syntax' + return '' + endif + + return path_html.htmlfile +endfunction + + +function! vimwiki#html#Wiki2HTML(path_html, wikifile) abort + let result = s:convert_file(a:path_html, a:wikifile) + if result !=? '' + call s:create_default_CSS(a:path_html) + endif + return result +endfunction + + +function! vimwiki#html#WikiAll2HTML(path_html, force) abort + if !s:syntax_supported() && !s:use_custom_wiki2html() + echomsg 'Vimwiki Error: Conversion to HTML is not supported for this syntax' + return + endif + + echomsg 'Vimwiki: Saving Vimwiki files ...' + let save_eventignore = &eventignore + let &eventignore = 'all' + try + wall + catch + " just ignore errors + endtry + let &eventignore = save_eventignore + + let path_html = expand(a:path_html) + call vimwiki#path#mkdir(path_html) + + if !vimwiki#vars#get_wikilocal('html_filename_parameterization') + echomsg 'Vimwiki: Deleting non-wiki html files ...' + call s:delete_html_files(path_html) + endif + + echomsg 'Vimwiki: Converting wiki to html files ...' + let setting_more = &more + setlocal nomore + + " temporarily adjust current_subdir global state variable + let current_subdir = vimwiki#vars#get_bufferlocal('subdir') + let current_invsubdir = vimwiki#vars#get_bufferlocal('invsubdir') + + let wikifiles = split(glob(vimwiki#vars#get_wikilocal('path').'**/*'. + \ vimwiki#vars#get_wikilocal('ext')), '\n') + for wikifile in wikifiles + let wikifile = fnamemodify(wikifile, ':p') + + " temporarily adjust 'subdir' and 'invsubdir' state variables + let subdir = vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), wikifile) + call vimwiki#vars#set_bufferlocal('subdir', subdir) + call vimwiki#vars#set_bufferlocal('invsubdir', vimwiki#base#invsubdir(subdir)) + + if a:force || !s:is_html_uptodate(wikifile) + echomsg 'Vimwiki: Processing '.wikifile + + call s:convert_file(path_html, wikifile) + else + echomsg 'Vimwiki: Skipping '.wikifile + endif + endfor + " reset 'subdir' state variable + call vimwiki#vars#set_bufferlocal('subdir', current_subdir) + call vimwiki#vars#set_bufferlocal('invsubdir', current_invsubdir) + + let created = s:create_default_CSS(path_html) + if created + echomsg 'Vimwiki: Default style.css has been created' + endif + echomsg 'Vimwiki: HTML exported to '.path_html + echomsg 'Vimwiki: Done!' + + let &more = setting_more +endfunction + + +function! s:file_exists(fname) abort + return !empty(getftype(expand(a:fname))) +endfunction + + +function! s:binary_exists(fname) abort + return executable(expand(a:fname)) +endfunction + + +function! s:get_wikifile_url(wikifile) abort + return vimwiki#vars#get_wikilocal('path_html') . + \ vimwiki#base#subdir(vimwiki#vars#get_wikilocal('path'), a:wikifile). + \ fnamemodify(a:wikifile, ':t:r').'.html' +endfunction + + +function! vimwiki#html#PasteUrl(wikifile) abort + execute 'r !echo file://'.s:get_wikifile_url(a:wikifile) +endfunction + + +function! vimwiki#html#CatUrl(wikifile) abort + execute '!echo file://'.s:get_wikifile_url(a:wikifile) +endfunction + diff --git a/pack/acp/start/vimwiki/autoload/vimwiki/lst.vim b/pack/acp/start/vimwiki/autoload/vimwiki/lst.vim new file mode 100644 index 0000000..bebd89b --- /dev/null +++ b/pack/acp/start/vimwiki/autoload/vimwiki/lst.vim @@ -0,0 +1,1713 @@ +" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99 +" Vimwiki autoload plugin file +" Description: Everything concerning lists and checkboxes +" Home: https://github.com/vimwiki/vimwiki/ + + +if exists('g:loaded_vimwiki_list_auto') || &compatible + finish +endif +let g:loaded_vimwiki_list_auto = 1 + + +" --------------------------------------------------------- +" incrementation functions for the various kinds of numbers +" --------------------------------------------------------- + +function! s:increment_1(value) abort + return eval(a:value) + 1 +endfunction + + +function! s:increment_A(value) abort + let list_of_chars = split(a:value, '.\zs') + let done = 0 + for idx in reverse(range(len(list_of_chars))) + let cur_num = char2nr(list_of_chars[idx]) + if cur_num < 90 + let list_of_chars[idx] = nr2char(cur_num + 1) + let done = 1 + break + else + let list_of_chars[idx] = 'A' + endif + endfor + if !done + call insert(list_of_chars, 'A') + endif + return join(list_of_chars, '') +endfunction + + +function! s:increment_a(value) abort + let list_of_chars = split(a:value, '.\zs') + let done = 0 + for idx in reverse(range(len(list_of_chars))) + let cur_num = char2nr(list_of_chars[idx]) + if cur_num < 122 + let list_of_chars[idx] = nr2char(cur_num + 1) + let done = 1 + break + else + let list_of_chars[idx] = 'a' + endif + endfor + if !done + call insert(list_of_chars, 'a') + endif + return join(list_of_chars, '') +endfunction + + +function! s:increment_I(value) abort + let subst_list = [ ['XLVIII$', 'IL'], ['VIII$', 'IX'], ['III$', 'IV'], + \ ['DCCCXCIX$', 'CM'], ['CCCXCIX$', 'CD'], ['LXXXIX$', 'XC'], + \ ['XXXIX$', 'XL'], ['\(I\{1,2\}\)$', '\1I'], ['CDXCIX$', 'D'], + \ ['CMXCIX$', 'M'], ['XCIX$', 'C'], ['I\([VXLCDM]\)$', '\1'], + \ ['\([VXLCDM]\)$', '\1I'] ] + for [regex, subst] in subst_list + if a:value =~# regex + return substitute(a:value, regex, subst, '') + endif + endfor + return '' +endfunction + + +function! s:increment_i(value) abort + let subst_list = [ ['xlviii$', 'il'], ['viii$', 'ix'], ['iii$', 'iv'], + \ ['dcccxcix$', 'cm'], ['cccxcix$', 'cd'], ['lxxxix$', 'xc'], + \ ['xxxix$', 'xl'], ['\(i\{1,2\}\)$', '\1i'], ['cdxcix$', 'd'], + \ ['cmxcix$', 'm'], ['xcix$', 'c'], ['i\([vxlcdm]\)$', '\1'], + \ ['\([vxlcdm]\)$', '\1i'] ] + for [regex, subst] in subst_list + if a:value =~# regex + return substitute(a:value, regex, subst, '') + endif + endfor + return '' +endfunction + + +" --------------------------------------------------------- +" utility functions +" --------------------------------------------------------- + +function! s:substitute_rx_in_line(lnum, pattern, new_string) abort + call setline(a:lnum, substitute(getline(a:lnum), a:pattern, a:new_string, '')) +endfunction + + +function! s:substitute_string_in_line(lnum, old_string, new_string) abort + call s:substitute_rx_in_line(a:lnum, vimwiki#u#escape(a:old_string), a:new_string) +endfunction + + +function! s:first_char(string) abort + return matchstr(a:string, '^.') +endfunction + + +if exists('*strdisplaywidth') + function! s:string_length(str) abort + return strdisplaywidth(a:str) + endfunction +else + function! s:string_length(str) abort + return strlen(substitute(a:str, '.', 'x', 'g')) + endfunction +endif + + +function! vimwiki#lst#default_symbol() abort + return vimwiki#vars#get_syntaxlocal('list_markers')[0] +endfunction + + +function! vimwiki#lst#get_list_margin() abort + let list_margin = vimwiki#vars#get_wikilocal('list_margin') + if list_margin < 0 + return &shiftwidth + else + return list_margin + endif +endfunction + + +"Returns: the column where the text of a line starts (possible list item +"markers and checkboxes are skipped) +function! s:text_begin(lnum) abort + return s:string_length(matchstr(getline(a:lnum), vimwiki#vars#get_syntaxlocal('rxListItem'))) +endfunction + + +"Returns: 2 if there is a marker and text +" 1 for a marker and no text +" 0 for no marker at all (empty line or only text) +function! s:line_has_marker(lnum) abort + if getline(a:lnum) =~# vimwiki#vars#get_syntaxlocal('rxListItem').'\s*$' + return 1 + elseif getline(a:lnum) =~# vimwiki#vars#get_syntaxlocal('rxListItem').'\s*\S' + return 2 + else + return 0 + endif +endfunction + + +" --------------------------------------------------------- +" get properties of a list item +" --------------------------------------------------------- + +"Returns: the mainly used data structure in this file +"An item represents a single list item and is a dictionary with the keys +"lnum - the line number of the list item +"type - 1 for bulleted item, 2 for numbered item, 0 for a regular line +"mrkr - the concrete marker, e.g. '**' or 'b)' +"cb - the char in the checkbox or '' if there is no checkbox +function! s:get_item(lnum) abort + let item = {'lnum': a:lnum} + if a:lnum == 0 || a:lnum > line('$') + let item.type = 0 + return item + endif + + let matches = matchlist(getline(a:lnum), vimwiki#vars#get_syntaxlocal('rxListItem')) + if matches == [] || + \ (matches[1] ==? '' && matches[2] ==? '') || + \ (matches[1] !=? '' && matches[2] !=? '') + let item.type = 0 + return item + endif + + let item.cb = matches[3] + + if matches[1] !=? '' + let item.type = 1 + let item.mrkr = matches[1] + else + let item.type = 2 + let item.mrkr = matches[2] + endif + + return item +endfunction + + +function! s:empty_item() abort + return {'type': 0} +endfunction + + +"Returns: level of the line +"0 is the 'highest' level +function! s:get_level(lnum) abort + if getline(a:lnum) =~# '^\s*$' + return 0 + endif + if !vimwiki#vars#get_syntaxlocal('recurring_bullets') + let level = indent(a:lnum) + else + let level = s:string_length(matchstr(getline(a:lnum), + \ vimwiki#vars#get_syntaxlocal('rx_bullet_chars')))-1 + if level < 0 + let level = (indent(a:lnum) == 0) ? 0 : 9999 + endif + endif + return level +endfunction + + +"Returns: 1, a, i, A, I or '' +"If in doubt if alphanumeric character or romanian +"numeral, peek in the previous line +function! s:guess_kind_of_numbered_item(item) abort + if a:item.type != 2 | return '' | endif + let number_chars = a:item.mrkr[:-2] + let divisor = a:item.mrkr[-1:] + + let number_kinds = vimwiki#vars#get_syntaxlocal('number_kinds') + + if number_chars =~# '\d\+' + return '1' + endif + if number_chars =~# '\l\+' + if number_chars !~# '^[ivxlcdm]\+' || index(number_kinds, 'i') == -1 + return 'a' + else + + let item_above = s:get_prev_list_item(a:item, 0) + if item_above.type != 0 + if index(number_kinds, 'a') == -1 || + \ (item_above.mrkr[-1:] !=# divisor && number_chars =~# 'i\+') || + \ s:increment_i(item_above.mrkr[:-2]) ==# number_chars + return 'i' + else + return 'a' + endif + else + if number_chars =~# 'i\+' || index(number_kinds, 'a') == -1 + return 'i' + else + return 'a' + endif + endif + + endif + endif + if number_chars =~# '\u\+' + if number_chars !~# '^[IVXLCDM]\+' || index(number_kinds, 'I') == -1 + return 'A' + else + + let item_above = s:get_prev_list_item(a:item, 0) + if item_above.type != 0 + if index(number_kinds, 'A') == -1 || + \ (item_above.mrkr[-1:] !=# divisor && number_chars =~# 'I\+') || + \ s:increment_I(item_above.mrkr[:-2]) ==# number_chars + return 'I' + else + return 'A' + endif + else + if number_chars =~# 'I\+' || index(number_kinds, 'A') == -1 + return 'I' + else + return 'A' + endif + endif + + endif + endif +endfunction + + +function! s:regexp_of_marker(item) abort + if a:item.type == 1 + return vimwiki#u#escape(a:item.mrkr) + elseif a:item.type == 2 + let number_divisors = vimwiki#vars#get_syntaxlocal('number_divisors') + for ki in ['d', 'u', 'l'] + let match = matchstr(a:item.mrkr, '\'.ki.'\+['.number_divisors.']') + if match !=? '' + return '\'.ki.'\+'.vimwiki#u#escape(match[-1:]) + endif + endfor + else + return '' + endif +endfunction + + +" Returns: Whether or not the checkbox of a list item is [X] or [-] +function! s:is_closed(item) abort + let state = a:item.cb + return state ==# vimwiki#vars#get_syntaxlocal('listsyms_list')[-1] + \ || state ==# vimwiki#vars#get_global('listsym_rejected') +endfunction + +" --------------------------------------------------------- +" functions for navigating between items +" --------------------------------------------------------- + +"Returns: the list item after a:item or an empty item +"If a:ignore_kind is 1, the markers can differ +function! s:get_next_list_item(item, ignore_kind) abort + let org_lvl = s:get_level(a:item.lnum) + if !a:ignore_kind + let org_regex = s:regexp_of_marker(a:item) + endif + + let cur_ln = s:get_next_line(a:item.lnum) + while cur_ln <= line('$') + let cur_lvl = s:get_level(cur_ln) + if cur_lvl <= org_lvl + if a:ignore_kind + return s:get_any_item_of_level(cur_ln, cur_lvl, org_lvl) + else + return s:get_item_of_level(cur_ln, cur_lvl, org_lvl, org_regex) + endif + endif + let cur_ln = s:get_next_line(cur_ln) + endwhile + return s:empty_item() +endfunction + + +"Returns: the list item before a:item or an empty item +"If a:ignore_kind is 1, the markers can differ +function! s:get_prev_list_item(item, ignore_kind) abort + let org_lvl = s:get_level(a:item.lnum) + if !a:ignore_kind + let org_regex = s:regexp_of_marker(a:item) + endif + + let cur_ln = s:get_prev_line(a:item.lnum) + while cur_ln >= 1 + let cur_lvl = s:get_level(cur_ln) + if cur_lvl <= org_lvl + if a:ignore_kind + return s:get_any_item_of_level(cur_ln, cur_lvl, org_lvl) + else + return s:get_item_of_level(cur_ln, cur_lvl, org_lvl, org_regex) + endif + endif + let cur_ln = s:get_prev_line(cur_ln) + endwhile + return s:empty_item() +endfunction + + +function! s:get_item_of_level(cur_ln, cur_lvl, org_lvl, org_regex) abort + let cur_linecontent = getline(a:cur_ln) + if a:cur_lvl == a:org_lvl + if cur_linecontent =~# '^\s*'.a:org_regex.'\s' + return s:get_item(a:cur_ln) + else + return s:empty_item() + endif + elseif a:cur_lvl < a:org_lvl + return s:empty_item() + endif +endfunction + + +function! s:get_any_item_of_level(cur_ln, cur_lvl, org_lvl) abort + if a:cur_lvl == a:org_lvl + return s:get_item(a:cur_ln) + elseif a:cur_lvl < a:org_lvl + return s:empty_item() + endif +endfunction + + +function! s:get_first_item_in_list(item, ignore_kind) abort + let cur_item = a:item + while 1 + let prev_item = s:get_prev_list_item(cur_item, a:ignore_kind) + if prev_item.type == 0 + break + else + let cur_item = prev_item + endif + endwhile + return cur_item +endfunction + + +function! s:get_last_item_in_list(item, ignore_kind) abort + let cur_item = a:item + while 1 + let next_item = s:get_next_list_item(cur_item, a:ignore_kind) + if next_item.type == 0 + break + else + let cur_item = next_item + endif + endwhile + return cur_item +endfunction + + +"Returns: lnum+1 in most cases, but skips blank lines and preformatted text, +"0 in case of nonvalid line. +"If there is no second argument, 0 is returned at a header, otherwise the +"header is skipped +function! s:get_next_line(lnum, ...) abort + if getline(a:lnum) =~# vimwiki#vars#get_syntaxlocal('rxPreStart') + let cur_ln = a:lnum + 1 + while cur_ln <= line('$') && getline(cur_ln) !~# vimwiki#vars#get_syntaxlocal('rxPreEnd') + let cur_ln += 1 + endwhile + let next_line = cur_ln + 1 + else + let next_line = a:lnum + 1 + endif + + let next_line = nextnonblank(next_line) + + if a:0 > 0 && getline(next_line) =~# vimwiki#vars#get_syntaxlocal('rxHeader') + let next_line = s:get_next_line(next_line, 1) + endif + + if next_line < 0 || next_line > line('$') || + \ (getline(next_line) =~# vimwiki#vars#get_syntaxlocal('rxHeader') && a:0 == 0) + return 0 + endif + + return next_line +endfunction + + +"Returns: lnum-1 in most cases, but skips blank lines and preformatted text +"0 in case of nonvalid line and a header, because a header ends every list +function! s:get_prev_line(lnum) abort + let cur_ln = a:lnum - 1 + + if getline(cur_ln) =~# vimwiki#vars#get_syntaxlocal('rxPreEnd') + while 1 + if cur_ln == 0 || getline(cur_ln) =~# vimwiki#vars#get_syntaxlocal('rxPreStart') + break + endif + let cur_ln -= 1 + endwhile + endif + + let prev_line = prevnonblank(cur_ln) + + if prev_line < 0 || prev_line > line('$') || + \ getline(prev_line) =~# vimwiki#vars#get_syntaxlocal('rxHeader') + return 0 + endif + + return prev_line +endfunction + + +function! s:get_first_child(item) abort + if a:item.lnum >= line('$') + return s:empty_item() + endif + let org_lvl = s:get_level(a:item.lnum) + let cur_item = s:get_item(s:get_next_line(a:item.lnum)) + while 1 + if cur_item.type != 0 && s:get_level(cur_item.lnum) > org_lvl + return cur_item + endif + if cur_item.lnum > line('$') || cur_item.lnum <= 0 || s:get_level(cur_item.lnum) <= org_lvl + return s:empty_item() + endif + let cur_item = s:get_item(s:get_next_line(cur_item.lnum)) + endwhile +endfunction + + +"Returns: the next sibling of a:child, given the parent item +"Used for iterating over children +"Note: child items do not necessarily have the same indent, i.e. level +function! s:get_next_child_item(parent, child) abort + if a:parent.type == 0 | return s:empty_item() | endif + let parent_lvl = s:get_level(a:parent.lnum) + let cur_ln = s:get_last_line_of_item_incl_children(a:child) + while 1 + let next_line = s:get_next_line(cur_ln) + if next_line == 0 || s:get_level(next_line) <= parent_lvl + break + endif + let cur_ln = next_line + let cur_item = s:get_item(cur_ln) + if cur_item.type > 0 + return cur_item + endif + endwhile + return s:empty_item() +endfunction + + +function! s:get_parent(item) abort + let parent_line = 0 + + let cur_ln = prevnonblank(a:item.lnum) + let child_lvl = s:get_level(cur_ln) + if child_lvl == 0 + return s:empty_item() + endif + + while 1 + let cur_ln = s:get_prev_line(cur_ln) + if cur_ln == 0 | break | endif + let cur_lvl = s:get_level(cur_ln) + if cur_lvl < child_lvl + let cur_item = s:get_item(cur_ln) + if cur_item.type == 0 + let child_lvl = cur_lvl + continue + endif + let parent_line = cur_ln + break + endif + endwhile + return s:get_item(parent_line) +endfunction + + +"Returns: the item above or the item below or an empty item +function! s:get_a_neighbor_item(item) abort + let prev_item = s:get_prev_list_item(a:item, 1) + if prev_item.type != 0 + return prev_item + else + let next_item = s:get_next_list_item(a:item, 1) + if next_item.type != 0 + return next_item + endif + endif + return s:empty_item() +endfunction + + +function! s:get_a_neighbor_item_in_column(lnum, column) abort + let cur_ln = s:get_prev_line(a:lnum) + while cur_ln >= 1 + if s:get_level(cur_ln) <= a:column + return s:get_corresponding_item(cur_ln) + endif + let cur_ln = s:get_prev_line(cur_ln) + endwhile + return s:empty_item() +endfunction + + +"Returns: the item if there is one in a:lnum +"else the multiline item a:lnum belongs to +function! s:get_corresponding_item(lnum) abort + let item = s:get_item(a:lnum) + if item.type != 0 + return item + endif + let org_lvl = s:get_level(a:lnum) + let cur_ln = a:lnum + while cur_ln > 0 + let cur_lvl = s:get_level(cur_ln) + let cur_item = s:get_item(cur_ln) + if cur_lvl < org_lvl && cur_item.type != 0 + return cur_item + endif + if cur_lvl < org_lvl + let org_lvl = cur_lvl + endif + let cur_ln = s:get_prev_line(cur_ln) + endwhile + return s:empty_item() +endfunction + + +"Returns: the last line of a (possibly multiline) item, including all children +function! s:get_last_line_of_item_incl_children(item) abort + let cur_ln = a:item.lnum + let org_lvl = s:get_level(a:item.lnum) + while 1 + let next_line = s:get_next_line(cur_ln) + if next_line == 0 || s:get_level(next_line) <= org_lvl + return cur_ln + endif + let cur_ln = next_line + endwhile +endfunction + + +"Returns: the last line of a (possibly multiline) item +"Note: there can be other list items between the first and last line +function! s:get_last_line_of_item(item) abort + if a:item.type == 0 | return 0 | endif + let org_lvl = s:get_level(a:item.lnum) + let last_corresponding_line = a:item.lnum + + let cur_ln = s:get_next_line(a:item.lnum) + while 1 + if cur_ln == 0 || s:get_level(cur_ln) <= org_lvl + break + endif + let cur_item = s:get_item(cur_ln) + if cur_item.type == 0 + let last_corresponding_line = cur_ln + let cur_ln = s:get_next_line(cur_ln) + else + let cur_ln = s:get_next_line(s:get_last_line_of_item_incl_children(cur_item)) + endif + endwhile + + return last_corresponding_line +endfunction + + +" --------------------------------------------------------- +" renumber list items +" --------------------------------------------------------- + +"Renumbers the current list from a:item on downwards +"Returns: the last item that was adjusted +function! s:adjust_numbered_list_below(item, recursive) abort + if !(a:item.type == 2 || (a:item.type == 1 && a:recursive)) + return a:item + endif + + let kind = s:guess_kind_of_numbered_item(a:item) + + let cur_item = a:item + while 1 + if a:recursive + call s:adjust_items_recursively(cur_item) + endif + + let next_item = s:get_next_list_item(cur_item, 0) + if next_item.type == 0 + break + endif + + if cur_item.type == 2 + let new_val = s:increment_{kind}(cur_item.mrkr[:-2]) . cur_item.mrkr[-1:] + call s:substitute_string_in_line(next_item.lnum, next_item.mrkr, new_val) + let next_item.mrkr = new_val + endif + + let cur_item = next_item + endwhile + return cur_item +endfunction + + +function! s:adjust_items_recursively(parent) abort + if a:parent.type == 0 + return s:empty_item() + end + + let child_item = s:get_first_child(a:parent) + if child_item.type == 0 + return child_item + endif + while 1 + let last_item = s:adjust_numbered_list(child_item, 1, 1) + + let child_item = s:get_next_child_item(a:parent, last_item) + if child_item.type == 0 + return last_item + endif + endwhile +endfunction + + +"Renumbers the list a:item is in. +"If a:ignore_kind == 0, only the items which have the same kind of marker as +"a:item are considered, otherwise all items. +"Returns: the last item that was adjusted +function! s:adjust_numbered_list(item, ignore_kind, recursive) abort + if !(a:item.type == 2 || (a:item.type == 1 && (a:ignore_kind || a:recursive))) + return s:empty_item() + end + + let first_item = s:get_first_item_in_list(a:item, a:ignore_kind) + + while 1 + if first_item.type == 2 + let new_mrkr = s:guess_kind_of_numbered_item(first_item) . first_item.mrkr[-1:] + call s:substitute_string_in_line(first_item.lnum, first_item.mrkr, new_mrkr) + let first_item.mrkr = new_mrkr + endif + + let last_item = s:adjust_numbered_list_below(first_item, a:recursive) + + let next_first_item = s:get_next_list_item(last_item, 1) + if a:ignore_kind == 0 || next_first_item.type == 0 + return last_item + endif + let first_item = next_first_item + endwhile +endfunction + + +"Renumbers the list the cursor is in +"also update its parents checkbox state +function! vimwiki#lst#adjust_numbered_list() abort + let cur_item = s:get_corresponding_item(line('.')) + if cur_item.type == 0 | return | endif + call s:adjust_numbered_list(cur_item, 1, 0) + call s:update_state(s:get_parent(cur_item)) +endfunction + + +"Renumbers all lists of the buffer +"of course, this might take some seconds +function! vimwiki#lst#adjust_whole_buffer() abort + let cur_ln = 1 + while 1 + let cur_item = s:get_item(cur_ln) + if cur_item.type != 0 + let cur_item = s:adjust_numbered_list(cur_item, 0, 1) + endif + let cur_ln = s:get_next_line(cur_item.lnum, 1) + if cur_ln <= 0 || cur_ln > line('$') + return + endif + endwhile +endfunction + + +" --------------------------------------------------------- +" checkbox stuff +" --------------------------------------------------------- + +"Returns: the rate of checkboxed list item in percent +function! s:get_rate(item) abort + if a:item.type == 0 || a:item.cb ==? '' + return -1 + endif + let state = a:item.cb + if state == vimwiki#vars#get_global('listsym_rejected') + return -1 + endif + let n = len(vimwiki#vars#get_syntaxlocal('listsyms_list')) + return index(vimwiki#vars#get_syntaxlocal('listsyms_list'), state) * 100/(n-1) +endfunction + + +"Set state of the list item to [ ] or [o] or whatever +"Returns: 1 if the state changed, 0 otherwise +function! s:set_state(item, new_rate) abort + let new_state = s:rate_to_state(a:new_rate) + let old_state = s:rate_to_state(s:get_rate(a:item)) + if new_state !=# old_state + call s:substitute_rx_in_line(a:item.lnum, '\[.]', '['.new_state.']') + return 1 + else + return 0 + endif +endfunction + + +" Sets the state of the list item to [ ] or [o] or whatever. Updates the states of its child items. +" If the new state should be [X] or [-], the state of the current list item is changed to this +" state, but if a child item already has [X] or [-] it is left alone. +function! s:set_state_plus_children(item, new_rate, ...) abort + let retain_state_if_closed = a:0 > 0 && a:1 > 0 + + if !(retain_state_if_closed && (a:new_rate == 100 || a:new_rate == -1) && s:is_closed(a:item)) + call s:set_state(a:item, a:new_rate) + endif + + let all_children_are_done = 1 + let all_children_are_rejected = 1 + + let child_item = s:get_first_child(a:item) + while 1 + if child_item.type == 0 + break + endif + if child_item.cb != vimwiki#vars#get_global('listsym_rejected') + let all_children_are_rejected = 0 + endif + if child_item.cb != vimwiki#vars#get_syntaxlocal('listsyms_list')[-1] + let all_children_are_done = 0 + endif + if !all_children_are_done && !all_children_are_rejected + break + endif + let child_item = s:get_next_child_item(a:item, child_item) + endwhile + + if (a:new_rate == 100 && all_children_are_done) || + \ (a:new_rate == -1) && all_children_are_rejected + return + endif + + if (a:new_rate == -1 && all_children_are_done) || + \ (a:new_rate == 100 && all_children_are_rejected) + let retain_closed_children = 0 + else + let retain_closed_children = 1 + endif + + let child_item = s:get_first_child(a:item) + while 1 + if child_item.type == 0 + break + endif + if child_item.cb !=? '' + call s:set_state_plus_children(child_item, a:new_rate, retain_closed_children) + endif + let child_item = s:get_next_child_item(a:item, child_item) + endwhile +endfunction + + +"Returns: the appropriate symbol for a given percent rate +function! s:rate_to_state(rate) abort + let listsyms_list = vimwiki#vars#get_syntaxlocal('listsyms_list') + let state = '' + let n = len(listsyms_list) + if a:rate == 100 + let state = listsyms_list[n-1] + elseif a:rate == 0 + let state = listsyms_list[0] + elseif a:rate == -1 + let state = vimwiki#vars#get_global('listsym_rejected') + else + let index = float2nr(ceil(a:rate/100.0*(n-2))) + let state = listsyms_list[index] + endif + return state +endfunction + + +"updates the symbol of a checkboxed item according to the symbols of its +"children +function! s:update_state(item) abort + if a:item.type == 0 || a:item.cb ==? '' + return + endif + + let sum_children_rate = 0 + let count_children_with_cb = 0 + let count_rejected_children = 0 + + let child_item = s:get_first_child(a:item) + + while 1 + if child_item.type == 0 + break + endif + if child_item.cb !=? '' + let rate = s:get_rate(child_item) + if rate == -1 + " for calculating the parent rate, a [-] item counts as much as a [X] item ... + let rate = 100 + " ... with the exception that a parent with *only* [-] items will be [-] too + let count_rejected_children += 1 + endif + let count_children_with_cb += 1 + let sum_children_rate += rate + endif + let child_item = s:get_next_child_item(a:item, child_item) + endwhile + + if count_children_with_cb > 0 + if count_rejected_children == count_children_with_cb + let new_rate = -1 + else + let new_rate = sum_children_rate / count_children_with_cb + endif + call s:set_state_recursively(a:item, new_rate) + else + let rate = s:get_rate(a:item) + if rate > 0 && rate < 100 + call s:set_state_recursively(a:item, 0) + endif + endif +endfunction + + +function! s:set_state_recursively(item, new_rate) abort + let state_changed = s:set_state(a:item, a:new_rate) + if state_changed + call s:update_state(s:get_parent(a:item)) + endif +endfunction + + +"Creates checkbox in a list item. +"Returns: 1 if successful +function! s:create_cb(item, start_rate) abort + if a:item.type == 0 || a:item.cb !=? '' + return 0 + endif + + let new_item = a:item + let new_item.cb = s:rate_to_state(a:start_rate) + call s:substitute_rx_in_line(new_item.lnum, + \ vimwiki#u#escape(new_item.mrkr) . '\zs\ze', ' [' . new_item.cb . ']') + + call s:update_state(new_item) + return 1 +endfunction + + +function! s:remove_cb(item) abort + let item = a:item + if item.type != 0 && item.cb !=? '' + let item.cb = '' + call s:substitute_rx_in_line(item.lnum, '\s\+\[.\]', '') + endif + return item +endfunction + + +" Change state of the checkboxes in the lines of the given range +function! s:change_cb(from_line, to_line, new_rate) abort + let from_item = s:get_corresponding_item(a:from_line) + if from_item.type == 0 + return + endif + + let parent_items_of_lines = [] + + for cur_ln in range(from_item.lnum, a:to_line) + let cur_item = s:get_item(cur_ln) + if cur_item.type != 0 && cur_item.cb !=? '' + call s:set_state_plus_children(cur_item, a:new_rate) + let cur_parent_item = s:get_parent(cur_item) + if index(parent_items_of_lines, cur_parent_item) == -1 + call insert(parent_items_of_lines, cur_parent_item) + endif + endif + endfor + + for parent_item in parent_items_of_lines + call s:update_state(parent_item) + endfor + +endfunction + + +" Toggles checkbox between two states in the lines of the given range, creates checkboxes (with +" a:start_rate as state) if there aren't any. +function! s:toggle_create_cb(from_line, to_line, state1, state2, start_rate) abort + let from_item = s:get_corresponding_item(a:from_line) + if from_item.type == 0 + return + endif + + if from_item.cb ==? '' + + "if from_line has no CB, make a CB in every selected line + let parent_items_of_lines = [] + for cur_ln in range(from_item.lnum, a:to_line) + let cur_item = s:get_item(cur_ln) + let success = s:create_cb(cur_item, a:start_rate) + + if success + let cur_parent_item = s:get_parent(cur_item) + if index(parent_items_of_lines, cur_parent_item) == -1 + call insert(parent_items_of_lines, cur_parent_item) + endif + endif + endfor + + for parent_item in parent_items_of_lines + call s:update_state(parent_item) + endfor + + else + + "if from_line has CB, toggle it and set all siblings to the same new state + let rate_first_line = s:get_rate(from_item) + let new_rate = rate_first_line == a:state1 ? a:state2 : a:state1 + + call s:change_cb(a:from_line, a:to_line, new_rate) + + endif + +endfunction + + +"Decrement checkbox between [ ] and [X] +"in the lines of the given range +function! vimwiki#lst#decrement_cb(from_line, to_line) abort + let from_item = s:get_corresponding_item(a:from_line) + if from_item.type == 0 + return + endif + + "if from_line has CB, decrement it and set all siblings to the same new state + let rate_first_line = s:get_rate(from_item) + let n = len(vimwiki#vars#get_syntaxlocal('listsyms_list')) + let new_rate = max([rate_first_line - 100/(n-1)-1, 0]) + + call s:change_cb(a:from_line, a:to_line, new_rate) + +endfunction + + +"Increment checkbox between [ ] and [X] +"in the lines of the given range +function! vimwiki#lst#increment_cb(from_line, to_line) abort + let from_item = s:get_corresponding_item(a:from_line) + if from_item.type == 0 + return + endif + + "if from_line has CB, increment it and set all siblings to the same new state + let rate_first_line = s:get_rate(from_item) + let n = len(vimwiki#vars#get_syntaxlocal('listsyms_list')) + let new_rate = min([rate_first_line + 100/(n-1)+1, 100]) + + call s:change_cb(a:from_line, a:to_line, new_rate) + +endfunction + + +"Toggles checkbox between [ ] and [X] or creates one +"in the lines of the given range +function! vimwiki#lst#toggle_cb(from_line, to_line) abort + return s:toggle_create_cb(a:from_line, a:to_line, 100, 0, 0) +endfunction + + +"Toggles checkbox between [ ] and [-] or creates one +"in the lines of the given range +function! vimwiki#lst#toggle_rejected_cb(from_line, to_line) abort + return s:toggle_create_cb(a:from_line, a:to_line, -1, 0, -1) +endfunction + + +function! vimwiki#lst#remove_cb(first_line, last_line) abort + let first_item = s:get_corresponding_item(a:first_line) + let last_item = s:get_corresponding_item(a:last_line) + + if first_item.type == 0 || last_item.type == 0 + return + endif + + let parent_items_of_lines = [] + let cur_ln = first_item.lnum + while 1 + if cur_ln <= 0 || cur_ln > last_item.lnum | break | endif + let cur_item = s:get_item(cur_ln) + if cur_item.type != 0 + let cur_item = s:remove_cb(cur_item) + let cur_parent_item = s:get_parent(cur_item) + if index(parent_items_of_lines, cur_parent_item) == -1 + call insert(parent_items_of_lines, cur_parent_item) + endif + endif + let cur_ln = s:get_next_line(cur_ln) + endwhile + for parent_item in parent_items_of_lines + call s:update_state(parent_item) + endfor +endfunction + + +function! vimwiki#lst#remove_cb_in_list() abort + let first_item = s:get_first_item_in_list(s:get_corresponding_item(line('.')), 0) + + let cur_item = first_item + while 1 + let next_item = s:get_next_list_item(cur_item, 0) + let cur_item = s:remove_cb(cur_item) + if next_item.type == 0 + break + else + let cur_item = next_item + endif + endwhile + + call s:update_state(s:get_parent(first_item)) +endfunction + + + +" --------------------------------------------------------- +" change the level of list items +" --------------------------------------------------------- + +function! s:set_indent(lnum, new_indent) abort + if &expandtab + let indentstring = repeat(' ', a:new_indent) + else + let indentstring = repeat('\t', a:new_indent / &tabstop) . repeat(' ', a:new_indent % &tabstop) + endif + call s:substitute_rx_in_line(a:lnum, '^\s*', indentstring) +endfunction + + +function! s:decrease_level(item) abort + let removed_indent = 0 + if vimwiki#vars#get_syntaxlocal('recurring_bullets') && a:item.type == 1 && + \ index(vimwiki#vars#get_syntaxlocal('multiple_bullet_chars'), + \ s:first_char(a:item.mrkr)) > -1 + if s:string_length(a:item.mrkr) >= 2 + call s:substitute_string_in_line(a:item.lnum, s:first_char(a:item.mrkr), '') + let removed_indent = -1 + endif + else + let old_indent = indent(a:item.lnum) + if &shiftround + let new_indent = (old_indent - 1) / vimwiki#u#sw() * vimwiki#u#sw() + else + let new_indent = old_indent - vimwiki#u#sw() + endif + call s:set_indent(a:item.lnum, new_indent) + let removed_indent = new_indent - old_indent + endif + return removed_indent +endfunction + + +function! s:increase_level(item) abort + let additional_indent = 0 + if vimwiki#vars#get_syntaxlocal('recurring_bullets') && a:item.type == 1 && + \ index(vimwiki#vars#get_syntaxlocal('multiple_bullet_chars'), + \ s:first_char(a:item.mrkr)) > -1 + call s:substitute_string_in_line(a:item.lnum, a:item.mrkr, a:item.mrkr . + \ s:first_char(a:item.mrkr)) + let additional_indent = 1 + else + let old_indent = indent(a:item.lnum) + if &shiftround + let new_indent = (old_indent / vimwiki#u#sw() + 1) * vimwiki#u#sw() + else + let new_indent = old_indent + vimwiki#u#sw() + endif + call s:set_indent(a:item.lnum, new_indent) + let additional_indent = new_indent - old_indent + endif + return additional_indent +endfunction + + +"adds a:indent_by to the current indent +"a:indent_by can be negative +function! s:indent_line_by(lnum, indent_by) abort + let item = s:get_item(a:lnum) + if vimwiki#vars#get_syntaxlocal('recurring_bullets') && item.type == 1 && + \ index(vimwiki#vars#get_syntaxlocal('multiple_bullet_chars'), + \ s:first_char(item.mrkr)) > -1 + if a:indent_by > 0 + call s:substitute_string_in_line(a:lnum, item.mrkr, item.mrkr . s:first_char(item.mrkr)) + elseif a:indent_by < 0 + call s:substitute_string_in_line(a:lnum, s:first_char(item.mrkr), '') + endif + else + call s:set_indent(a:lnum, indent(a:lnum) + a:indent_by) + endif +endfunction + + +"changes lvl of lines in selection +function! s:change_level(from_line, to_line, direction, plus_children) abort + let from_item = s:get_corresponding_item(a:from_line) + if from_item.type == 0 + if a:direction ==# 'increase' && a:from_line == a:to_line && empty(getline(a:from_line)) + "that's because :> doesn't work on an empty line + exe 'normal!' "gi\" + else + execute a:from_line.','.a:to_line.(a:direction ==# 'increase' ? '>' : '<') + endif + return + endif + + if a:direction ==# 'decrease' && s:get_level(from_item.lnum) == 0 + return + endif + + if a:from_line == a:to_line + if a:plus_children + let to_line = s:get_last_line_of_item_incl_children(from_item) + else + let to_line = s:get_last_line_of_item(from_item) + endif + else + let to_item = s:get_corresponding_item(a:to_line) + if to_item.type == 0 + let to_line = a:to_line + else + if a:plus_children + let to_line = s:get_last_line_of_item_incl_children(to_item) + else + let to_line = s:get_last_line_of_item(to_item) + endif + endif + endif + + if to_line == 0 + return + endif + + let to_be_adjusted = s:get_a_neighbor_item(from_item) + let old_parent = s:get_parent(from_item) + let first_line_level = s:get_level(from_item.lnum) + let more_than_one_level_concerned = 0 + + let first_line_indented_by = (a:direction ==# 'increase') ? + \ s:increase_level(from_item) : s:decrease_level(from_item) + + let cur_ln = s:get_next_line(from_item.lnum) + while cur_ln > 0 && cur_ln <= to_line + if !more_than_one_level_concerned && + \ s:get_level(cur_ln) != first_line_level && + \ s:get_item(cur_ln).type != 0 + let more_than_one_level_concerned = 1 + endif + call s:indent_line_by(cur_ln, first_line_indented_by) + let cur_ln = s:get_next_line(cur_ln, 1) + endwhile + + if a:from_line == a:to_line + call s:adjust_mrkr(from_item) + endif + call s:update_state(old_parent) + let from_item = s:get_item(from_item.lnum) + if from_item.cb !=? '' + call s:update_state(from_item) + call s:update_state(s:get_parent(from_item)) + endif + + if more_than_one_level_concerned + call vimwiki#lst#adjust_whole_buffer() + else + call s:adjust_numbered_list(from_item, 0, 0) + call s:adjust_numbered_list(to_be_adjusted, 0, 0) + endif +endfunction + + +function! vimwiki#lst#change_level(from_line, to_line, direction, plus_children) abort + let cur_col = col('$') - col('.') + call s:change_level(a:from_line, a:to_line, a:direction, a:plus_children) + call cursor('.', col('$') - cur_col) +endfunction + + +"indent line a:lnum to be the continuation of a:prev_item +function! s:indent_multiline(prev_item, lnum) abort + if a:prev_item.type != 0 + call s:set_indent(a:lnum, s:text_begin(a:prev_item.lnum)) + endif +endfunction + + +" --------------------------------------------------------- +" change markers of list items +" --------------------------------------------------------- + +"Returns: the position of a marker in g:vimwiki_list_markers +function! s:get_idx_list_markers(item) abort + if a:item.type == 1 + let m = s:first_char(a:item.mrkr) + else + let m = s:guess_kind_of_numbered_item(a:item) . a:item.mrkr[-1:] + endif + return index(vimwiki#vars#get_syntaxlocal('list_markers'), m) +endfunction + + +"changes the marker of the given item to the next in g:vimwiki_list_markers +function! s:get_next_mrkr(item) abort + let markers = vimwiki#vars#get_syntaxlocal('list_markers') + if a:item.type == 0 + let new_mrkr = markers[0] + else + let idx = s:get_idx_list_markers(a:item) + let new_mrkr = markers[(idx+1) % len(markers)] + endif + return new_mrkr +endfunction + + +"changes the marker of the given item to the previous in g:vimwiki_list_markers +function! s:get_prev_mrkr(item) abort + let markers = vimwiki#vars#get_syntaxlocal('list_markers') + if a:item.type == 0 + return markers[-1] + endif + let idx = s:get_idx_list_markers(a:item) + if idx == -1 + return markers[-1] + else + return markers[(idx - 1 + len(markers)) % len(markers)] + endif +endfunction + + +function! s:set_new_mrkr(item, new_mrkr) abort + if a:item.type == 0 + call s:substitute_rx_in_line(a:item.lnum, '^\s*\zs\ze', a:new_mrkr.' ') + if indent(a:item.lnum) == 0 && !vimwiki#vars#get_syntaxlocal('recurring_bullets') + call s:set_indent(a:item.lnum, vimwiki#lst#get_list_margin()) + endif + else + call s:substitute_string_in_line(a:item.lnum, a:item.mrkr, a:new_mrkr) + endif +endfunction + + +function! vimwiki#lst#change_marker(from_line, to_line, new_mrkr, mode) abort + let cur_col_from_eol = col('$') - (a:mode ==# 'i' ? col("'^") : col('.')) + let new_mrkr = a:new_mrkr + let cur_ln = a:from_line + while 1 + let cur_item = s:get_item(cur_ln) + + if new_mrkr ==# 'next' + let new_mrkr = s:get_next_mrkr(cur_item) + elseif new_mrkr ==# 'prev' + let new_mrkr = s:get_prev_mrkr(cur_item) + endif + + "handle markers like *** + if index(vimwiki#vars#get_syntaxlocal('multiple_bullet_chars'), s:first_char(new_mrkr)) > -1 + "use *** if the item above has *** too + let item_above = s:get_prev_list_item(cur_item, 1) + if item_above.type == 1 && s:first_char(item_above.mrkr) ==# s:first_char(new_mrkr) + let new_mrkr = item_above.mrkr + else + "use *** if the item below has *** too + let item_below = s:get_next_list_item(cur_item, 1) + if item_below.type == 1 && s:first_char(item_below.mrkr) ==# s:first_char(new_mrkr) + let new_mrkr = item_below.mrkr + else + "if the old is ### and the new is * use *** + if cur_item.type == 1 && + \ index(vimwiki#vars#get_syntaxlocal('multiple_bullet_chars'), + \ s:first_char(cur_item.mrkr))>-1 + let new_mrkr = repeat(new_mrkr, s:string_length(cur_item.mrkr)) + else + "use *** if the parent item has ** + let parent_item = s:get_parent(cur_item) + if parent_item.type == 1 && s:first_char(parent_item.mrkr) ==# s:first_char(new_mrkr) + let new_mrkr = repeat(s:first_char(parent_item.mrkr), + \ s:string_length(parent_item.mrkr)+1) + endif + endif + endif + endif + + endif + + call s:set_new_mrkr(cur_item, new_mrkr) + call s:adjust_numbered_list(s:get_item(cur_ln), 1, 0) + + if cur_ln >= a:to_line | break | endif + let cur_ln = s:get_next_line(cur_ln, 1) + endwhile + + call cursor('.', col('$') - cur_col_from_eol) +endfunction + + +function! vimwiki#lst#change_marker_in_list(new_mrkr) abort + let cur_item = s:get_corresponding_item(line('.')) + let first_item = s:get_first_item_in_list(cur_item, 0) + let last_item = s:get_last_item_in_list(cur_item, 0) + if first_item.type == 0 || last_item.type == 0 | return | endif + let first_item_line = first_item.lnum + + let cur_item = first_item + while cur_item.type != 0 && cur_item.lnum <= last_item.lnum + call s:set_new_mrkr(cur_item, a:new_mrkr) + let cur_item = s:get_next_list_item(cur_item, 1) + endwhile + + call s:adjust_numbered_list(s:get_item(first_item_line), 0, 0) +endfunction + + +"sets kind of the item depending on neighbor items and the parent item +function! s:adjust_mrkr(item) abort + if a:item.type == 0 || vimwiki#vars#get_syntaxlocal('recurring_bullets') + return + endif + + let new_mrkr = a:item.mrkr + let neighbor_item = s:get_a_neighbor_item(a:item) + if neighbor_item.type != 0 + let new_mrkr = neighbor_item.mrkr + endif + + "if possible, set e.g. *** if parent has ** as marker + if neighbor_item.type == 0 && a:item.type == 1 && + \ index(vimwiki#vars#get_syntaxlocal('multiple_bullet_chars'), + \ s:first_char(a:item.mrkr)) > -1 + let parent_item = s:get_parent(a:item) + if parent_item.type == 1 && s:first_char(parent_item.mrkr) ==# s:first_char(a:item.mrkr) + let new_mrkr = repeat(s:first_char(parent_item.mrkr), s:string_length(parent_item.mrkr)+1) + endif + endif + + call s:substitute_string_in_line(a:item.lnum, a:item.mrkr, new_mrkr) + call s:adjust_numbered_list(a:item, 0, 1) +endfunction + + +function! s:clone_marker_from_to(from, to) abort + let item_from = s:get_item(a:from) + if item_from.type == 0 | return | endif + let new_mrkr = item_from.mrkr . ' ' + call s:substitute_rx_in_line(a:to, '^\s*', new_mrkr) + let new_indent = ( vimwiki#vars#get_syntaxlocal('recurring_bullets') ? 0 : indent(a:from) ) + call s:set_indent(a:to, new_indent) + if item_from.cb !=? '' + call s:create_cb(s:get_item(a:to), 0) + call s:update_state(s:get_parent(s:get_item(a:to))) + endif + if item_from.type == 2 + let adjust_from = ( a:from < a:to ? a:from : a:to ) + call s:adjust_numbered_list_below(s:get_item(adjust_from), 0) + endif +endfunction + + +function! s:remove_mrkr(item) abort + let item = a:item + if item.cb !=? '' + let item = s:remove_cb(item) + let parent_item = s:get_parent(item) + else + let parent_item = s:empty_item() + endif + call s:substitute_rx_in_line(item.lnum, vimwiki#u#escape(item.mrkr).'\s*', '') + call remove(item, 'mrkr') + call remove(item, 'cb') + let item.type = 0 + call s:update_state(parent_item) + return item +endfunction + + +function! s:create_marker(lnum) abort + let new_sibling = s:get_corresponding_item(a:lnum) + if new_sibling.type == 0 + let new_sibling = s:get_a_neighbor_item_in_column(a:lnum, virtcol('.')) + endif + if new_sibling.type != 0 + call s:clone_marker_from_to(new_sibling.lnum, a:lnum) + else + let cur_item = s:get_item(a:lnum) + call s:set_new_mrkr(cur_item, vimwiki#vars#get_syntaxlocal('list_markers')[0]) + call s:adjust_numbered_list(cur_item, 0, 0) + endif +endfunction + + +" --------------------------------------------------------- +" handle keys +" --------------------------------------------------------- + +function! vimwiki#lst#kbd_o() abort + let fold_end = foldclosedend('.') + let lnum = (fold_end == -1) ? line('.') : fold_end + let cur_item = s:get_item(lnum) + let parent = s:get_corresponding_item(lnum) + "inserting and deleting the x is necessary + "because otherwise the indent is lost + exe 'normal!' "ox\" + if !vimwiki#u#is_codeblock(lnum) + if parent.type != 0 + call s:clone_marker_from_to(parent.lnum, cur_item.lnum+1) + else + call s:indent_multiline(cur_item, cur_item.lnum+1) + endif + endif + startinsert! +endfunction + + +function! vimwiki#lst#kbd_O() abort + exe 'normal!' "Ox\" + let cur_ln = line('.') + if !vimwiki#u#is_codeblock(cur_ln) + if getline(cur_ln+1) !~# '^\s*$' + call s:clone_marker_from_to(cur_ln+1, cur_ln) + else + call s:clone_marker_from_to(cur_ln-1, cur_ln) + endif + endif + startinsert! +endfunction + + +function! s:cr_on_empty_list_item(lnum, behavior) abort + if a:behavior == 1 + "just make a new list item + exe 'normal!' "gi\\" + call s:clone_marker_from_to(a:lnum, a:lnum+1) + startinsert! + return + elseif a:behavior == 2 + "insert new marker but remove marker in old line + call append(a:lnum-1, '') + startinsert! + return + elseif a:behavior == 3 + "list is finished, but cursor stays in current line + let item = s:get_item(a:lnum) + let neighbor_item = s:get_a_neighbor_item(item) + let child_item = s:get_first_child(item) + let parent_item = (item.cb !=? '') ? s:get_parent(item) : s:empty_item() + normal! "_cc + call s:adjust_numbered_list(neighbor_item, 0, 0) + call s:adjust_numbered_list(child_item, 0, 0) + call s:update_state(parent_item) + startinsert + return + elseif a:behavior == 4 + "list is finished, but cursor goes to next line + let item = s:get_item(a:lnum) + let neighbor_item = s:get_a_neighbor_item(item) + let child_item = s:get_first_child(item) + let parent_item = (item.cb !=? '') ? s:get_parent(item) : s:empty_item() + exe 'normal!' "_cc\" + call s:adjust_numbered_list(neighbor_item, 0, 0) + call s:adjust_numbered_list(child_item, 0, 0) + call s:update_state(parent_item) + startinsert + return + elseif a:behavior == 5 + "successively decrease level + if s:get_level(a:lnum) > 0 + call s:change_level(a:lnum, a:lnum, 'decrease', 0) + startinsert! + else + let item = s:get_item(a:lnum) + let neighbor_item = s:get_a_neighbor_item(item) + let child_item = s:get_first_child(item) + let parent_item = (item.cb !=? '') ? s:get_parent(item) : s:empty_item() + normal! "_cc + call s:adjust_numbered_list(neighbor_item, 0, 0) + call s:adjust_numbered_list(child_item, 0, 0) + call s:update_state(parent_item) + startinsert + endif + return + endif +endfunction + +function! s:cr_on_empty_line(lnum, behavior) abort + let lst = s:get_corresponding_item(a:lnum) + + "inserting and deleting the x is necessary + "because otherwise the indent is lost + exe 'normal!' "gi\x\\" + + if a:behavior == 2 || a:behavior == 3 + if lst.type == 0 || vimwiki#u#is_codeblock(a:lnum) + " don't insert new bullet if not part of a list + return + else + call s:create_marker(a:lnum+1) + endif + endif +endfunction + + +function! s:cr_on_list_item(lnum, insert_new_marker, not_at_eol) abort + if a:insert_new_marker + "the ultimate feature of this script: make new marker on + exe 'normal!' "gi\\" + call s:clone_marker_from_to(a:lnum, a:lnum+1) + "tiny sweet extra feature: indent next line if current line ends with : + if !a:not_at_eol && getline(a:lnum) =~# ':$' + call s:change_level(a:lnum+1, a:lnum+1, 'increase', 0) + endif + else + " || (cur_item.lnum < s:get_last_line_of_item(cur_item)) + "indent this line so that it becomes the continuation of the line above + exe 'normal!' "gi\\" + let prev_line = s:get_corresponding_item(s:get_prev_line(a:lnum+1)) + call s:indent_multiline(prev_line, a:lnum+1) + endif +endfunction + + +function! vimwiki#lst#kbd_cr(normal, just_mrkr) abort + let lnum = line('.') + let has_bp = s:line_has_marker(lnum) + + if has_bp != 0 && virtcol('.') < s:text_begin(lnum) + call append(lnum-1, '') + startinsert! + return + endif + + if has_bp == 1 + call s:cr_on_empty_list_item(lnum, a:just_mrkr) + return + endif + + let insert_new_marker = (a:normal == 1 || a:normal == 3) + if getline('.')[col("'^")-1:] =~# '^\s\+$' + let cur_col = 0 + else + let cur_col = col('$') - col("'^") + if getline('.')[col("'^")-1] =~# '\s' && exists('*strdisplaywidth') + let ws_behind_cursor = + \ strdisplaywidth(matchstr(getline('.')[col("'^")-1:], '\s\+'), + \ virtcol("'^")-1) + let cur_col -= ws_behind_cursor + endif + if insert_new_marker && cur_col == 0 && getline(lnum) =~# '\s$' + let insert_new_marker = 0 + endif + endif + + if has_bp == 0 + call s:cr_on_empty_line(lnum, a:normal) + endif + + if has_bp == 2 + call s:cr_on_list_item(lnum, insert_new_marker, cur_col) + endif + + call cursor(lnum+1, col('$') - cur_col) + if cur_col == 0 + startinsert! + else + startinsert + endif + +endfunction + + +"creates a list item in the current line or removes it +function! vimwiki#lst#toggle_list_item() abort + let cur_col_from_eol = col('$') - col("'^") + let cur_item = s:get_item(line('.')) + + if cur_item.type == 0 + call s:create_marker(cur_item.lnum) + else + let prev_item = s:get_prev_list_item(cur_item, 1) + if prev_item.type == 0 + let prev_item = s:get_corresponding_item(s:get_prev_line(cur_item.lnum)) + endif + let cur_item = s:remove_mrkr(cur_item) + let adjust_prev_item = (prev_item.type == 2 && + \ s:get_level(cur_item.lnum) <= s:get_level(prev_item.lnum)) ? 1 : 0 + call s:indent_multiline(prev_item, cur_item.lnum) + if adjust_prev_item + call s:adjust_numbered_list_below(prev_item, 0) + endif + endif + + "set cursor position s.t. it's on the same char as before + let new_cur_col = col('$') - cur_col_from_eol + call cursor(cur_item.lnum, new_cur_col >= 1 ? new_cur_col : 1) + + if cur_col_from_eol == 0 || getline(cur_item.lnum) =~# '^\s*$' + startinsert! + else + startinsert + endif +endfunction + + +" --------------------------------------------------------- +" misc stuff +" --------------------------------------------------------- + +function! vimwiki#lst#TO_list_item(inner, visual) abort + let lnum = prevnonblank('.') + let item = s:get_corresponding_item(lnum) + if item.type == 0 + return + endif + let from_line = item.lnum + if a:inner + let to_line = s:get_last_line_of_item(item) + else + let to_line = s:get_last_line_of_item_incl_children(item) + endif + normal! V + call cursor(to_line, 0) + normal! o + call cursor(from_line, 0) +endfunction + + +function! vimwiki#lst#fold_level(lnum) abort + let cur_item = s:get_item(a:lnum) + if cur_item.type != 0 + let parent_item = s:get_parent(cur_item) + let child_item = s:get_first_child(cur_item) + let next_item = s:get_next_child_item(parent_item, cur_item) + if child_item.type != 0 + return 'a1' + elseif next_item.type == 0 + let c_indent = indent(a:lnum) / &shiftwidth + let n_indent = indent(a:lnum+1) / &shiftwidth + return 's' . (c_indent - n_indent) + endif + endif + return '=' +endfunction + diff --git a/pack/acp/start/vimwiki/autoload/vimwiki/markdown_base.vim b/pack/acp/start/vimwiki/autoload/vimwiki/markdown_base.vim new file mode 100644 index 0000000..bfbd140 --- /dev/null +++ b/pack/acp/start/vimwiki/autoload/vimwiki/markdown_base.vim @@ -0,0 +1,162 @@ +" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99 +" Vimwiki autoload plugin file +" Description: Link functions for markdown syntax +" Home: https://github.com/vimwiki/vimwiki/ + + +function! s:safesubstitute(text, search, replace, mode) abort + " Substitute regexp but do not interpret replace + let escaped = escape(a:replace, '\&') + return substitute(a:text, a:search, escaped, a:mode) +endfunction + + +function! vimwiki#markdown_base#scan_reflinks() abort + let mkd_refs = {} + " construct list of references using vimgrep + try + " Why noautocmd? Because https://github.com/vimwiki/vimwiki/issues/121 + noautocmd execute 'vimgrep #'.vimwiki#vars#get_syntaxlocal('rxMkdRef').'#j %' + catch /^Vim\%((\a\+)\)\=:E480/ " No Match + "Ignore it, and move on to the next file + endtry + + for d in getqflist() + let matchline = join(getline(d.lnum, min([d.lnum+1, line('$')])), ' ') + let descr = matchstr(matchline, vimwiki#vars#get_syntaxlocal('rxMkdRefMatchDescr')) + let url = matchstr(matchline, vimwiki#vars#get_syntaxlocal('rxMkdRefMatchUrl')) + if descr !=? '' && url !=? '' + let mkd_refs[descr] = url + endif + endfor + call vimwiki#vars#set_bufferlocal('markdown_refs', mkd_refs) + return mkd_refs +endfunction + + +" try markdown reference links +function! vimwiki#markdown_base#open_reflink(link) abort + " echom "vimwiki#markdown_base#open_reflink" + let link = a:link + let mkd_refs = vimwiki#vars#get_bufferlocal('markdown_refs') + if has_key(mkd_refs, link) + let url = mkd_refs[link] + call vimwiki#base#system_open_link(url) + return 1 + else + return 0 + endif +endfunction + + +function! s:normalize_link_syntax_n() abort + let lnum = line('.') + + " try WikiIncl + let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_global('rxWikiIncl')) + if !empty(lnk) + " NO-OP !! + return + endif + + " try WikiLink0: replace with WikiLink1 + let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink0')) + if !empty(lnk) + let sub = vimwiki#base#normalize_link_helper(lnk, + \ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchUrl'), + \ vimwiki#vars#get_syntaxlocal('rxWikiLinkMatchDescr'), + \ vimwiki#vars#get_syntaxlocal('WikiLink1Template2')) + call vimwiki#base#replacestr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink0'), sub) + return + endif + + " try WikiLink1: replace with WikiLink0 + let lnk = vimwiki#base#matchstr_at_cursor(vimwiki#vars#get_syntaxlocal('rxWikiLink1')) + 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('rxWikiLink1'), sub) + 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, + \ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchUrl'), + \ vimwiki#vars#get_syntaxlocal('rxWeblinkMatchDescr'), + \ vimwiki#vars#get_syntaxlocal('Weblink1Template')) + 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 vimwiki#base#is_diary_file(expand('%:p')) + let sub = vimwiki#base#normalize_link_in_diary(lnk) + else + let sub = vimwiki#base#normalize_link_helper(lnk, + \ vimwiki#vars#get_global('rxWord'), '', + \ vimwiki#vars#get_syntaxlocal('Weblink1Template')) + endif + call vimwiki#base#replacestr_at_cursor('\V'.lnk, sub) + return + endif + +endfunction + + +function! s:normalize_link_syntax_v() abort + let lnum = line('.') + let sel_save = &selection + let &selection = 'old' + let rv = @" + let rt = getregtype('"') + let done = 0 + + try + norm! gvy + let visual_selection = @" + + if vimwiki#base#is_diary_file(expand('%:p')) + let link = vimwiki#base#normalize_link_in_diary(visual_selection) + else + let link = s:safesubstitute(vimwiki#vars#get_syntaxlocal('Weblink1Template'), + \ '__LinkUrl__', visual_selection, '') + endif + + " replace spaces with new character if option is set + let link = substitute(link, '\s', vimwiki#vars#get_wikilocal('links_space_char'), 'g') + + let link = s:safesubstitute(link, '__LinkDescription__', visual_selection, '') + call setreg('"', substitute(link, '\n', '', ''), visualmode()) + + " paste result + norm! `>""pgvd + + finally + call setreg('"', rv, rt) + let &selection = sel_save + endtry + +endfunction + + +function! vimwiki#markdown_base#normalize_link(is_visual_mode) abort + if 0 + " Syntax-specific links + 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 + diff --git a/pack/acp/start/vimwiki/autoload/vimwiki/path.vim b/pack/acp/start/vimwiki/autoload/vimwiki/path.vim new file mode 100644 index 0000000..c0ce8eb --- /dev/null +++ b/pack/acp/start/vimwiki/autoload/vimwiki/path.vim @@ -0,0 +1,210 @@ +" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99 +" Vimwiki autoload plugin file +" Description: Path manipulation functions +" Home: https://github.com/vimwiki/vimwiki/ + + +function! vimwiki#path#chomp_slash(str) abort + return substitute(a:str, '[/\\]\+$', '', '') +endfunction + + +" Define path-compare function, either case-sensitive or not, depending on OS. +if vimwiki#u#is_windows() + function! vimwiki#path#is_equal(p1, p2) abort + return a:p1 ==? a:p2 + endfunction +else + function! vimwiki#path#is_equal(p1, p2) abort + return a:p1 ==# a:p2 + endfunction +endif + +" collapse sections like /a/b/../c to /a/c and /a/b/./c to /a/b/c +function! vimwiki#path#normalize(path) abort + let path = a:path + while 1 + let intermediateResult = substitute(path, '/[^/]\+/\.\.', '', '') + let result = substitute(intermediateResult, '/\./', '/', '') + if result ==# path + break + endif + let path = result + endwhile + return result +endfunction + + +function! vimwiki#path#path_norm(path) abort + " /-slashes + if a:path !~# '^scp:' + let path = substitute(a:path, '\', '/', 'g') + " treat multiple consecutive slashes as one path separator + let path = substitute(path, '/\+', '/', 'g') + " ensure that we are not fooled by a symbolic link + return resolve(path) + else + return a:path + endif +endfunction + + +function! vimwiki#path#is_link_to_dir(link) abort + " Check if link is to a directory. + " It should be ended with \ or /. + return a:link =~# '\m[/\\]$' +endfunction + + +function! vimwiki#path#abs_path_of_link(link) abort + return vimwiki#path#normalize(expand('%:p:h').'/'.a:link) +endfunction + + +" return longest common path prefix of 2 given paths. +" '~/home/usrname/wiki', '~/home/usrname/wiki/shmiki' => '~/home/usrname/wiki' +function! vimwiki#path#path_common_pfx(path1, path2) abort + let p1 = split(a:path1, '[/\\]', 1) + let p2 = split(a:path2, '[/\\]', 1) + + let idx = 0 + let minlen = min([len(p1), len(p2)]) + while (idx < minlen) && vimwiki#path#is_equal(p1[idx], p2[idx]) + let idx = idx + 1 + endwhile + if idx == 0 + return '' + else + return join(p1[: idx-1], '/') + endif +endfunction + + +function! vimwiki#path#wikify_path(path) abort + let result = resolve(fnamemodify(a:path, ':p')) + if vimwiki#u#is_windows() + let result = substitute(result, '\\', '/', 'g') + endif + let result = vimwiki#path#chomp_slash(result) + return result +endfunction + + +function! vimwiki#path#current_wiki_file() abort + return vimwiki#path#wikify_path(expand('%:p')) +endfunction + + +" Returns: the relative path from a:dir to a:file +function! vimwiki#path#relpath(dir, file) abort + " Check if dir here ('.') -> return file + if empty(a:dir) || a:dir =~# '^\.[/\\]\?$' + return a:file + endif + let result = [] + if vimwiki#u#is_windows() + " TODO temporary fix see #478 + " not sure why paths get converted back to using forward slash + " when passed to the function in the form C:\path\to\file + let dir = substitute(a:dir, '/', '\', 'g') + let file = substitute(a:file, '/', '\', 'g') + let dir = split(dir, '\') + let file = split(file, '\') + else + let dir = split(a:dir, '/') + let file = split(a:file, '/') + endif + while (len(dir) > 0 && len(file) > 0) && vimwiki#path#is_equal(dir[0], file[0]) + call remove(dir, 0) + call remove(file, 0) + endwhile + if empty(dir) && empty(file) + if vimwiki#u#is_windows() + " TODO temporary fix see #478 + return '.\' + else + return './' + endif + endif + for segment in dir + let result += ['..'] + endfor + for segment in file + let result += [segment] + endfor + if vimwiki#u#is_windows() + " TODO temporary fix see #478 + let result_path = join(result, '\') + if a:file =~? '\m\\$' + let result_path .= '\' + endif + else + let result_path = join(result, '/') + if a:file =~? '\m/$' + let result_path .= '/' + endif + endif + return result_path +endfunction + + +" If the optional argument provided and nonzero, +" it will ask before creating a directory +" Returns: 1 iff directory exists or successfully created +function! vimwiki#path#mkdir(path, ...) abort + let path = expand(a:path) + + if path =~# '^scp:' + " we can not do much, so let's pretend everything is ok + return 1 + endif + + if isdirectory(path) + return 1 + else + if !exists('*mkdir') + return 0 + endif + + let path = vimwiki#path#chomp_slash(path) + if vimwiki#u#is_windows() && !empty(vimwiki#vars#get_global('w32_dir_enc')) + let path = iconv(path, &encoding, vimwiki#vars#get_global('w32_dir_enc')) + endif + + if a:0 && a:1 && input('Vimwiki: Make new directory: '.path."\n [y]es/[N]o? ") !~? '^y' + return 0 + endif + + call mkdir(path, 'p') + return 1 + endif +endfunction + + +function! vimwiki#path#is_absolute(path) abort + if vimwiki#u#is_windows() + return a:path =~? '\m^\a:' + else + return a:path =~# '\m^/\|\~/' + endif +endfunction + + +" Combine a directory and a file into one path, doesn't generate duplicate +" path separator in case the directory is also having an ending / or \. This +" is because on windows ~\vimwiki//.tags is invalid but ~\vimwiki/.tags is a +" valid path. +if vimwiki#u#is_windows() + function! vimwiki#path#join_path(directory, file) abort + let directory = vimwiki#path#chomp_slash(a:directory) + let file = substitute(a:file, '\m^[\\/]\+', '', '') + return directory . '/' . file + endfunction +else + function! vimwiki#path#join_path(directory, file) abort + let directory = substitute(a:directory, '\m/\+$', '', '') + let file = substitute(a:file, '\m^/\+', '', '') + return directory . '/' . file + endfunction +endif + diff --git a/pack/acp/start/vimwiki/autoload/vimwiki/style.css b/pack/acp/start/vimwiki/autoload/vimwiki/style.css new file mode 100644 index 0000000..43d6b57 --- /dev/null +++ b/pack/acp/start/vimwiki/autoload/vimwiki/style.css @@ -0,0 +1,187 @@ +body { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;; + margin: 2em 4em 2em 4em; + font-size: 120%; + line-height: 130%; +} + +h1, h2, h3, h4, h5, h6 { + font-weight: bold; + line-height:100%; + margin-top: 1.5em; + margin-bottom: 0.5em; +} + +h1 {font-size: 2em; color: #000000;} +h2 {font-size: 1.8em; color: #404040;} +h3 {font-size: 1.6em; color: #707070;} +h4 {font-size: 1.4em; color: #909090;} +h5 {font-size: 1.2em; color: #989898;} +h6 {font-size: 1em; color: #9c9c9c;} + +p, pre, blockquote, table, ul, ol, dl { + margin-top: 1em; + margin-bottom: 1em; +} + +ul ul, ul ol, ol ol, ol ul { + margin-top: 0.5em; + margin-bottom: 0.5em; +} + +li { margin: 0.3em auto; } + +ul { + margin-left: 2em; + padding-left: 0; +} + +dt { font-weight: bold; } + +img { border: none; } + +pre { + border-left: 5px solid #dcdcdc; + background-color: #f5f5f5; + padding-left: 1em; + font-family: Monaco, "Courier New", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace; + font-size: 0.8em; + border-radius: 6px; +} + +p > a { + color: white; + text-decoration: none; + font-size: 0.7em; + padding: 3px 6px; + border-radius: 3px; + background-color: #1e90ff; + text-transform: uppercase; + font-weight: bold; +} + +p > a:hover { + color: #dcdcdc; + background-color: #484848; +} + +li > a { + color: #1e90ff; + font-weight: bold; + text-decoration: none; +} + +li > a:hover { color: #ff4500; } + +blockquote { + color: #686868; + font-size: 0.8em; + line-height: 120%; + padding: 0.8em; + border-left: 5px solid #dcdcdc; +} + +th, td { + border: 1px solid #ccc; + padding: 0.3em; +} + +th { background-color: #f0f0f0; } + +hr { + border: none; + border-top: 1px solid #ccc; + width: 100%; +} + +del { + text-decoration: line-through; + color: #777777; +} + +.toc li { list-style-type: none; } + +.todo { + font-weight: bold; + background-color: #ff4500 ; + color: white; + font-size: 0.8em; + padding: 3px 6px; + border-radius: 3px; +} + +.justleft { text-align: left; } +.justright { text-align: right; } +.justcenter { text-align: center; } + +.center { + margin-left: auto; + margin-right: auto; +} + +.tag { + background-color: #eeeeee; + font-family: monospace; + padding: 2px; +} + +.header a { + text-decoration: none; + color: inherit; +} + +/* classes for items of todo lists */ + +.rejected { + /* list-style: none; */ + background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAMAAAAMCGV4AAAACXBIWXMAAADFAAAAxQEdzbqoAAAAB3RJTUUH4QgEFhAtuWgv9wAAAPZQTFRFmpqam5iYnJaWnJeXnpSUn5OTopCQpoqKpouLp4iIqIiIrYCAt3V1vW1tv2xsmZmZmpeXnpKS/x4e/x8f/yAg/yIi/yQk/yUl/yYm/ygo/ykp/yws/zAw/zIy/zMz/zQ0/zU1/zY2/zw8/0BA/0ZG/0pK/1FR/1JS/1NT/1RU/1VV/1ZW/1dX/1pa/15e/19f/2Zm/2lp/21t/25u/3R0/3p6/4CA/4GB/4SE/4iI/46O/4+P/52d/6am/6ur/66u/7Oz/7S0/7e3/87O/9fX/9zc/93d/+Dg/+vr/+3t/+/v//Dw//Ly//X1//f3//n5//z8////gzaKowAAAA90Uk5T/Pz8/Pz8/Pz8/Pz8/f39ppQKWQAAAAFiS0dEEnu8bAAAAACuSURBVAhbPY9ZF4FQFEZPSKbIMmWep4gMGTKLkIv6/3/GPbfF97b3w17rA0kQOPgvAeHW6uJ6+5h7HqLdwowgOzejXRXBdx6UdSru216xuOMBHHNU0clTzeSUA6EhF8V8kqroluMiU6HKcuf4phGPr1o2q9kYZWwNq1qfRRmTaXpqsyjj17KkWCxKBUBgXWueHIyiAIg18gsse4KHkLF5IKIY10WQgv7fOy4ST34BRiopZ8WLNrgAAAAASUVORK5CYII=); + background-repeat: no-repeat; + background-position: 0 .2em; + padding-left: 1.5em; +} +.done0 { + /* list-style: none; */ + background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAxQAAAMUBHc26qAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAA7SURBVCiR7dMxEgAgCANBI3yVRzF5KxNbW6wsuH7LQ2YKQK1mkswBVERYF5Os3UV3gwd/jF2SkXy66gAZkxS6BniubAAAAABJRU5ErkJggg==); + background-repeat: no-repeat; + background-position: 0 .2em; + padding-left: 1.5em; +} +.done1 { + background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAxQAAAMUBHc26qAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAABtSURBVCiR1ZO7DYAwDER9BDmTeZQMFXmUbGYpOjrEryA0wOvO8itOslFrJYAug5BMM4BeSkmjsrv3aVTa8p48Xw1JSkSsWVUFwD05IqS1tmYzk5zzae9jnVVVzGyXb8sALjse+euRkEzu/uirFomVIdDGOLjuAAAAAElFTkSuQmCC); + background-repeat: no-repeat; + background-position: 0 .15em; + padding-left: 1.5em; +} +.done2 { + background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAxQAAAMUBHc26qAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAB1SURBVCiRzdO5DcAgDAVQGxjAYgTvxlDIu1FTIRYAp8qlFISkSH7l5kk+ZIwxKiI2mIyqWoeILYRgZ7GINDOLjnmF3VqklKCUMgTee2DmM661Qs55iI3Zm/1u5h9sm4ig9z4ERHTFzLyd4G4+nFlVrYg8+qoF/c0kdpeMsmcAAAAASUVORK5CYII=); + background-repeat: no-repeat; + background-position: 0 .15em; + padding-left: 1.5em; +} +.done3 { + background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAxQAAAMUBHc26qAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAABoSURBVCiR7dOxDcAgDATA/0DtUdiKoZC3YhLkHjkVKF3idJHiztKfvrHZWnOSE8Fx95RJzlprimJVnXktvXeY2S0SEZRSAAAbmxnGGKH2I5T+8VfxPhIReQSuuY3XyYWa3T2p6quvOgGrvSFGlewuUAAAAABJRU5ErkJggg==); + background-repeat: no-repeat; + background-position: 0 .15em; + padding-left: 1.5em; +} +.done4 { + background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAAQCAYAAAAbBi9cAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAzgAAAM4BlP6ToAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAIISURBVDiNnZQ9SFtRFMd/773kpTaGJoQk1im4VDpWQcTNODhkFBcVTCNCF0NWyeDiIIiCm82QoIMIUkHUxcFBg1SEQoZszSat6cdTn1qNue92CMbEr9Sey+XC/Z/zu+f8h6ukUil3sVg0+M+4cFxk42/jH2wAqqqKSCSiPQdwcHHAnDHH9s/tN1h8V28ETdP+eU8fT9Nt62ancYdIPvJNtsu87bmjrJlrTDVM4RROJs1JrHPrD4Bar7A6cpc54iKOaTdJXCUI2UMVrQZ0Js7YPN18ECKkYNQcJe/OE/4dZsw7VqNXQMvHy3QZXQypQ6ycrtwDjf8aJ+PNEDSCzLpn7+m2pD8ZKHlKarYhy6XjEoCYGcN95qansQeA3fNdki+SaJZGTMQIOoL3W/Z89rxv+tokubNajlvk/vm+LFpF2XnUKZHI0I+QrI7Dw0OZTqdzUkpsM7mZTyfy5OPGyw1tK7AFSvmB/Ks8w8YwbUYbe6/3QEKv0vugfxWPnMLJun+d/kI/WLdizpNjMbAIKrhMF4OuwadBALqqs+RfInwUvuNi+fBd+wjogfogAFVRmffO02q01mZZ0HHdgXIzdz0QQLPezIQygX6llxNKKgOFARYCC49CqhoHIUTlss/Vx2phlYwjw8j1CAlfAiwQiJpiy7o1VHnsG5FISkoJu7Q/2YmmaV+i0ei7v38L2CBguSi5AAAAAElFTkSuQmCC); + background-repeat: no-repeat; + background-position: 0 .15em; + padding-left: 1.5em; +} + +code { + font-family: Monaco, "Courier New", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace; + -webkit-border-radius: 1px; + -moz-border-radius: 1px; + border-radius: 1px; + -moz-background-clip: padding; + -webkit-background-clip: padding-box; + background-clip: padding-box; + padding: 0px 3px; + display: inline-block; + color: #52595d; + border: 1px solid #ccc; + background-color: #f9f9f9; +} diff --git a/pack/acp/start/vimwiki/autoload/vimwiki/tags.vim b/pack/acp/start/vimwiki/autoload/vimwiki/tags.vim new file mode 100644 index 0000000..b3ac93f --- /dev/null +++ b/pack/acp/start/vimwiki/autoload/vimwiki/tags.vim @@ -0,0 +1,405 @@ +" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99 +" Vimwiki autoload plugin file + + +let s:TAGS_METADATA_FILE_NAME = '.vimwiki_tags' + + + +" Tags metadata in-memory format: +" metadata := { 'pagename': [entries, ...] } +" entry := { 'tagname':..., 'lineno':..., 'link':... } + +" Tags metadata in-file format: +" +" Is based on CTags format (see |tags-file-format|). +" +" {tagaddress} is set to lineno. We'll let vim search by exact line number; we +" can afford that, we assume metadata file is always updated before use. +" +" Pagename and link are not saved in standard ctags fields, so we'll add +" an optional field, "vimwiki:". In this field, we encode tab-separated values +" of missing parameters -- "pagename" and "link". + + + +" Update tags metadata. +" a:full_rebuild == 1: re-scan entire wiki +" a:full_rebuild == 0: only re-scan current page +" a:all_files == '': only if the file is newer than .tags +function! vimwiki#tags#update_tags(full_rebuild, all_files) abort + let all_files = a:all_files !=? '' + if !a:full_rebuild + " Updating for one page (current) + let page_name = vimwiki#vars#get_bufferlocal('subdir') . expand('%:t:r') + " Collect tags in current file + let tags = s:scan_tags(getline(1, '$'), page_name) + " Load metadata file + let metadata = s:load_tags_metadata() + " Drop old tags + let metadata = s:remove_page_from_tags(metadata, page_name) + " Merge in the new ones + let metadata = s:merge_tags(metadata, page_name, tags) + " Save + call s:write_tags_metadata(metadata) + else " full rebuild + let files = vimwiki#base#find_files(vimwiki#vars#get_bufferlocal('wiki_nr'), 0) + let wiki_base_dir = vimwiki#vars#get_wikilocal('path') + let tags_file_last_modification = getftime(vimwiki#tags#metadata_file_path()) + let metadata = s:load_tags_metadata() + for file in files + if all_files || getftime(file) >= tags_file_last_modification + let subdir = vimwiki#base#subdir(wiki_base_dir, file) + let page_name = subdir . fnamemodify(file, ':t:r') + let tags = s:scan_tags(readfile(file), page_name) + let metadata = s:remove_page_from_tags(metadata, page_name) + let metadata = s:merge_tags(metadata, page_name, tags) + endif + endfor + call s:write_tags_metadata(metadata) + endif +endfunction + + +function! s:safesubstitute(text, search, replace, mode) abort + " Substitute regexp but do not interpret replace + let escaped = escape(a:replace, '\&') + return substitute(a:text, a:search, escaped, a:mode) +endfunction + + +" Scans the list of text lines (argument) and produces tags metadata as a list of tag entries. +function! s:scan_tags(lines, page_name) abort + + let entries = [] + + " Code wireframe to scan for headers -- borrowed from + " vimwiki#base#get_anchors(), with minor modifications. + + let rxheader = vimwiki#vars#get_syntaxlocal('header_search') + let rxtag = vimwiki#vars#get_syntaxlocal('tag_search') + + let anchor_level = ['', '', '', '', '', '', ''] + let current_complete_anchor = '' + + let PROXIMITY_LINES_NR = 2 + let header_line_nr = - (2 * PROXIMITY_LINES_NR) + + for line_nr in range(1, len(a:lines)) + let line = a:lines[line_nr - 1] + + " ignore verbatim blocks + if vimwiki#u#is_codeblock(line_nr) + continue + endif + + " process headers + let h_match = matchlist(line, rxheader) + if !empty(h_match) " got a header + let header_line_nr = line_nr + let header = vimwiki#u#trim(h_match[2]) + let level = len(h_match[1]) + 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 + endif + continue " tags are not allowed in headers + endif + + " Scan line for tags. There can be many of them. + let str = line + while 1 + let tag_group = matchstr(str, rxtag) + if tag_group ==? '' + break + endif + let tagend = matchend(str, rxtag) + let str = str[(tagend):] + for tag in split(tag_group, ':') + " Create metadata entry + let entry = {} + let entry.tagname = tag + let entry.lineno = line_nr + if line_nr <= PROXIMITY_LINES_NR && header_line_nr < 0 + " Tag appeared at the top of the file + let entry.link = a:page_name + elseif line_nr <= (header_line_nr + PROXIMITY_LINES_NR) + " Tag appeared right below a header + let entry.link = a:page_name . '#' . current_complete_anchor + else + " Tag stands on its own + let entry.link = a:page_name . '#' . tag + endif + call add(entries, entry) + endfor + endwhile + + endfor " loop over lines + return entries +endfunction + + +" Returns tags metadata file path +function! vimwiki#tags#metadata_file_path() abort + return fnamemodify(vimwiki#path#join_path(vimwiki#vars#get_wikilocal('path'), + \ s:TAGS_METADATA_FILE_NAME), ':p') +endfunction + + +" Loads tags metadata from file, returns a dictionary +function! s:load_tags_metadata() abort + let metadata_path = vimwiki#tags#metadata_file_path() + if !filereadable(metadata_path) + return {} + endif + let metadata = {} + for line in readfile(metadata_path) + if line =~# '^!_TAG_.*$' + continue + endif + let parts = matchlist(line, '^\(.\{-}\);"\(.*\)$') + if parts[0] ==? '' || parts[1] ==? '' || parts[2] ==? '' + throw 'VimwikiTags1: Metadata file corrupted' + endif + let std_fields = split(parts[1], '\t') + if len(std_fields) != 3 + throw 'VimwikiTags2: Metadata file corrupted' + endif + let vw_part = parts[2] + if vw_part[0] !=? "\t" + throw 'VimwikiTags3: Metadata file corrupted' + endif + let vw_fields = split(vw_part[1:], "\t") + if len(vw_fields) != 1 || vw_fields[0] !~# '^vimwiki:' + throw 'VimwikiTags4: Metadata file corrupted' + endif + let vw_data = substitute(vw_fields[0], '^vimwiki:', '', '') + let vw_data = substitute(vw_data, '\\n', "\n", 'g') + let vw_data = substitute(vw_data, '\\r', "\r", 'g') + let vw_data = substitute(vw_data, '\\t', "\t", 'g') + let vw_data = substitute(vw_data, '\\\\', "\\", 'g') + let vw_fields = split(vw_data, "\t") + if len(vw_fields) != 2 + throw 'VimwikiTags5: Metadata file corrupted' + endif + let pagename = vw_fields[0] + let entry = {} + let entry.tagname = std_fields[0] + let entry.lineno = std_fields[2] + let entry.link = vw_fields[1] + if has_key(metadata, pagename) + call add(metadata[pagename], entry) + else + let metadata[pagename] = [entry] + endif + endfor + return metadata +endfunction + + +" Removes all entries for given page from metadata in-place. Returns updated +" metadata (just in case). +function! s:remove_page_from_tags(metadata, page_name) abort + if has_key(a:metadata, a:page_name) + call remove(a:metadata, a:page_name) + return a:metadata + else + return a:metadata + endif +endfunction + + +" Merges metadata of one file into a:metadata +function! s:merge_tags(metadata, pagename, file_metadata) abort + let metadata = a:metadata + let metadata[a:pagename] = a:file_metadata + return metadata +endfunction + + +" Compares two actual lines from tags file. Return value is in strcmp style. +" See help on sort() -- that's what this function is going to be used for. +" See also s:write_tags_metadata below -- that's where we compose these tags +" file lines. +" +" This function is needed for tags sorting, since plain sort() compares line +" numbers as strings, not integers, and so, for example, tag at line 14 +" preceeds the same tag on the same page at line 9. (Because string "14" is +" alphabetically 'less than' string "9".) +function! s:tags_entry_cmp(i1, i2) abort + let items = [] + for orig_item in [a:i1, a:i2] + let fields = split(orig_item, "\t") + let item = {} + let item.text = fields[0]."\t".fields[1] + let item.lineno = 0 + matchstr(fields[2], '\m\d\+') + call add(items, item) + endfor + if items[0].text ># items[1].text + return 1 + elseif items[0].text <# items[1].text + return -1 + elseif items[0].lineno > items[1].lineno + return 1 + elseif items[0].lineno < items[1].lineno + return -1 + else + return 0 + endif +endfunction + + +" Saves metadata object into a file. Throws exceptions in case of problems. +function! s:write_tags_metadata(metadata) abort + let metadata_path = vimwiki#tags#metadata_file_path() + let tags = [] + for pagename in keys(a:metadata) + for entry in a:metadata[pagename] + let entry_data = pagename . "\t" . entry.link + let entry_data = substitute(entry_data, "\\", '\\\\', 'g') + let entry_data = substitute(entry_data, "\t", '\\t', 'g') + let entry_data = substitute(entry_data, "\r", '\\r', 'g') + let entry_data = substitute(entry_data, "\n", '\\n', 'g') + call add(tags, + \ entry.tagname . "\t" + \ . pagename . vimwiki#vars#get_wikilocal('ext') . "\t" + \ . entry.lineno + \ . ';"' + \ . "\t" . 'vimwiki:' . entry_data + \) + endfor + endfor + call sort(tags, 's:tags_entry_cmp') + let tag_comments = [ + \ "!_TAG_PROGRAM_VERSION\t2.5", + \ "!_TAG_PROGRAM_URL\thttps://github.com/vimwiki/vimwiki", + \ "!_TAG_PROGRAM_NAME\tVimwiki Tags", + \ "!_TAG_PROGRAM_AUTHOR\tVimwiki", + \ "!_TAG_OUTPUT_MODE\tvimwiki-tags", + \ "!_TAG_FILE_SORTED\t1", + \ "!_TAG_FILE_FORMAT\t2", + \ ] + for c in tag_comments + call insert(tags, c) + endfor + call writefile(tags, metadata_path) +endfunction + + +" Returns list of unique tags found in the .tags file +function! vimwiki#tags#get_tags() abort + let metadata = s:load_tags_metadata() + let tags = {} + for entries in values(metadata) + for entry in entries + let tags[entry.tagname] = 1 + endfor + endfor + return keys(tags) +endfunction + + +" Similar to vimwiki#base#generate_links. In the current buffer, appends +" tags and references to all their instances. If no arguments (tags) are +" specified, outputs all tags. +function! vimwiki#tags#generate_tags(create, ...) abort + let specific_tags = a:000 + let header_level = vimwiki#vars#get_global('tags_header_level') + + " use a dictionary function for closure like capability + " copy all local variables into dict (add a: if arguments are needed) + let GeneratorTags = copy(l:) + function! GeneratorTags.f() abort + let need_all_tags = empty(self.specific_tags) + let metadata = s:load_tags_metadata() + + " make a dictionary { tag_name: [tag_links, ...] } + let tags_entries = {} + for entries in values(metadata) + for entry in entries + if has_key(tags_entries, entry.tagname) + call add(tags_entries[entry.tagname], entry.link) + else + let tags_entries[entry.tagname] = [entry.link] + endif + endfor + unlet entry " needed for older vims with sticky type checking since name is reused + endfor + + let lines = [] + let bullet = repeat(' ', vimwiki#lst#get_list_margin()).vimwiki#lst#default_symbol().' ' + for tagname in sort(keys(tags_entries)) + if need_all_tags || index(self.specific_tags, tagname) != -1 + if len(lines) > 0 + call add(lines, '') + endif + + let tag_tpl = printf('rxH%d_Template', self.header_level + 1) + call add(lines, s:safesubstitute(vimwiki#vars#get_syntaxlocal(tag_tpl), '__Header__', tagname, '')) + + if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown' + for _ in range(vimwiki#vars#get_global('markdown_header_style')) + call add(lines, '') + endfor + endif + + for taglink in sort(tags_entries[tagname]) + if vimwiki#vars#get_wikilocal('syntax') ==# 'markdown' + let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink3Template') + let link_infos = vimwiki#base#resolve_link(taglink) + if empty(link_infos.anchor) + let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink1Template') + let entry = s:safesubstitute(link_tpl, '__LinkUrl__', taglink, '') + let entry = s:safesubstitute(entry, '__LinkDescription__', taglink, '') + else + let link_caption = split(link_infos.anchor, '#', 0)[-1] + let link_text = split(taglink, '#', 1)[0] + let entry = s:safesubstitute(link_tpl, '__LinkUrl__', link_text, '') + let entry = s:safesubstitute(entry, '__LinkAnchor__', link_infos.anchor, '') + let entry = s:safesubstitute(entry, '__LinkDescription__', link_caption, '') + endif + + call add(lines, bullet . entry) + else + let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate1') + call add(lines, bullet . substitute(link_tpl, '__LinkUrl__', taglink, '')) + endif + endfor + endif + endfor + + return lines + endfunction + + let tag_match = printf('rxH%d', header_level + 1) + let links_rx = '^\%('.vimwiki#vars#get_syntaxlocal(tag_match).'\)\|'. + \ '\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxListBullet').'\)' + + call vimwiki#base#update_listing_in_buffer( + \ GeneratorTags, + \ vimwiki#vars#get_global('tags_header'), + \ links_rx, + \ line('$')+1, + \ header_level, + \ a:create) +endfunction + + +function! vimwiki#tags#complete_tags(ArgLead, CmdLine, CursorPos) abort + " We can safely ignore args if we use -custom=complete option, Vim engine + " will do the job of filtering. + let taglist = vimwiki#tags#get_tags() + return join(taglist, "\n") +endfunction + diff --git a/pack/acp/start/vimwiki/autoload/vimwiki/tbl.vim b/pack/acp/start/vimwiki/autoload/vimwiki/tbl.vim new file mode 100644 index 0000000..b26a89d --- /dev/null +++ b/pack/acp/start/vimwiki/autoload/vimwiki/tbl.vim @@ -0,0 +1,861 @@ +" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99 +" Vimwiki autoload plugin file +" Description: Tables +" | Easily | manageable | text | tables | ! | +" |--------|------------|-------|--------|---------| +" | Have | fun! | Drink | tea | Period. | +" +" Home: https://github.com/vimwiki/vimwiki/ + + + +if exists('g:loaded_vimwiki_tbl_auto') || &compatible + finish +endif +let g:loaded_vimwiki_tbl_auto = 1 + + +let s:textwidth = &textwidth + + +function! s:rxSep() abort + return vimwiki#vars#get_syntaxlocal('rxTableSep') +endfunction + + +function! s:wide_len(str) abort + " vim73 has new function that gives correct string width. + if exists('*strdisplaywidth') + return strdisplaywidth(a:str) + endif + + " get str display width in vim ver < 7.2 + if !vimwiki#vars#get_global('CJK_length') + let ret = strlen(substitute(a:str, '.', 'x', 'g')) + else + let savemodified = &modified + let save_cursor = getpos('.') + exe "norm! o\" + call setline(line('.'), a:str) + let ret = virtcol('$') - 1 + d + call setpos('.', save_cursor) + let &modified = savemodified + endif + return ret +endfunction + + +function! s:cell_splitter() abort + return '\s*'.s:rxSep().'\s*' +endfunction + + +function! s:sep_splitter() abort + return '-'.s:rxSep().'-' +endfunction + + +function! s:is_table(line) abort + return s:is_separator(a:line) || + \ (a:line !~# s:rxSep().s:rxSep() && a:line =~# '^\s*'.s:rxSep().'.\+'.s:rxSep().'\s*$') +endfunction + + +function! s:is_separator(line) abort + return a:line =~# '^\s*'.s:rxSep().'\(:\=--\+:\='.s:rxSep().'\)\+\s*$' +endfunction + + +function! s:is_separator_tail(line) abort + return a:line =~# '^\{-1}\%(\s*\|-*\)\%('.s:rxSep().'-\+\)\+'.s:rxSep().'\s*$' +endfunction + + +function! s:is_last_column(lnum, cnum) abort + let line = strpart(getline(a:lnum), a:cnum - 1) + return line =~# s:rxSep().'\s*$' && line !~# s:rxSep().'.*'.s:rxSep().'\s*$' +endfunction + + +function! s:is_first_column(lnum, cnum) abort + let line = strpart(getline(a:lnum), 0, a:cnum - 1) + return line =~# '^\s*$' || + \ (line =~# '^\s*'.s:rxSep() && line !~# '^\s*'.s:rxSep().'.*'.s:rxSep()) +endfunction + + +function! s:count_separators_up(lnum) abort + let lnum = a:lnum - 1 + while lnum > 1 + if !s:is_separator(getline(lnum)) + break + endif + let lnum -= 1 + endwhile + + return (a:lnum-lnum) +endfunction + + +function! s:count_separators_down(lnum) abort + let lnum = a:lnum + 1 + while lnum < line('$') + if !s:is_separator(getline(lnum)) + break + endif + let lnum += 1 + endwhile + + return (lnum-a:lnum) +endfunction + + +function! s:create_empty_row(cols) abort + let row = s:rxSep() + let cell = ' '.s:rxSep() + + for c in range(a:cols) + let row .= cell + endfor + + return row +endfunction + + +function! s:create_row_sep(cols) abort + let row = s:rxSep() + let cell = '---'.s:rxSep() + + for c in range(a:cols) + let row .= cell + endfor + + return row +endfunction + + +function! vimwiki#tbl#get_cells(line, ...) abort + let result = [] + let state = 'NONE' + let cell_start = 0 + let quote_start = 0 + let len = strlen(a:line) - 1 + + " 'Simple' FSM + while state !=# 'CELL' + if quote_start != 0 && state !=# 'CELL' + let state = 'CELL' + endif + for idx in range(quote_start, len) + " The only way I know Vim can do Unicode... + let ch = a:line[idx] + if state ==# 'NONE' + if ch ==# '|' + let cell_start = idx + 1 + let state = 'CELL' + endif + elseif state ==# 'CELL' + if ch ==# '[' || ch ==# '{' + let state = 'BEFORE_QUOTE_START' + let quote_start = idx + elseif ch ==# '|' + let cell = strpart(a:line, cell_start, idx - cell_start) + if a:0 && a:1 + let cell = substitute(cell, '^ \(.*\) $', '\1', '') + else + let cell = vimwiki#u#trim(cell) + endif + call add(result, cell) + let cell_start = idx + 1 + endif + elseif state ==# 'BEFORE_QUOTE_START' + if ch ==# '[' || ch ==# '{' + let state = 'QUOTE' + let quote_start = idx + else + let state = 'CELL' + endif + elseif state ==# 'QUOTE' + if ch ==# ']' || ch ==# '}' + let state = 'BEFORE_QUOTE_END' + endif + elseif state ==# 'BEFORE_QUOTE_END' + if ch ==# ']' || ch ==# '}' + let state = 'CELL' + endif + endif + endfor + if state ==# 'NONE' + break + endif + endwhile + + return result +endfunction + + +function! s:col_count(lnum) abort + return len(vimwiki#tbl#get_cells(getline(a:lnum))) +endfunction + + +function! s:get_indent(lnum, depth) abort + if !s:is_table(getline(a:lnum)) + return + endif + + let indent = 0 + + let lnum = a:lnum - 1 + while lnum > 1 + let line = getline(lnum) + if !s:is_table(line) + let indent = indent(lnum+1) + break + endif + let lnum -= 1 + if a:depth > 0 && lnum < a:lnum - a:depth + break + endif + endwhile + + return indent +endfunction + + +function! s:get_rows(lnum, ...) abort + if !s:is_table(getline(a:lnum)) + return + endif + + let rows = [] + + let lnum = a:lnum - 1 + let depth = a:0 > 0 ? a:1 : 0 + let ldepth = 0 + while lnum >= 1 && (depth == 0 || ldepth < depth) + let line = getline(lnum) + if s:is_table(line) + call insert(rows, [lnum, line]) + else + break + endif + let lnum -= 1 + let ldepth += 1 + endwhile + + let lnum = a:lnum + while lnum <= line('$') + let line = getline(lnum) + if s:is_table(line) + call add(rows, [lnum, line]) + else + break + endif + if depth > 0 + break + endif + let lnum += 1 + endwhile + + return rows +endfunction + + +function! s:get_cell_aligns(lnum, ...) abort + let aligns = {} + let depth = a:0 > 0 ? a:1 : 0 + for [lnum, row] in s:get_rows(a:lnum, depth) + if s:is_separator(row) + let cells = vimwiki#tbl#get_cells(row) + for idx in range(len(cells)) + let cell = cells[idx] + if cell =~# '^--\+:' + let aligns[idx] = 'right' + elseif cell =~# '^:--\+:' + let aligns[idx] = 'center' + else + let aligns[idx] = 'left' + endif + endfor + else + let cells = vimwiki#tbl#get_cells(row) + for idx in range(len(cells)) + if !has_key(aligns, idx) + let aligns[idx] = 'left' + endif + endfor + endif + endfor + return aligns +endfunction + + +function! s:get_cell_aligns_fast(rows) abort + let aligns = {} + let clen = 0 + for [lnum, row] in a:rows + if s:is_separator(row) + return s:get_cell_aligns(lnum, 1) + endif + let cells = vimwiki#tbl#get_cells(row, 1) + let clen = len(cells) + for idx in range(clen) + let cell = cells[idx] + if !has_key(aligns, idx) + let cs = matchlist(cell, '^\(\s*\)[^[:space:]].\{-}\(\s*\)$') + if !empty(cs) + let lstart = len(cs[1]) + let lend = len(cs[2]) + if lstart > 0 && lend > 0 + let aligns[idx] = 'center' + elseif lend > 0 + let aligns[idx] = 'left' + elseif lstart > 0 + let aligns[idx] = 'right' + endif + endif + endif + endfor + endfor + for idx in range(clen) + if !has_key(aligns, idx) + return {} + endif + endfor + return aligns +endfunction + + +function! s:get_cell_max_lens(lnum, ...) abort + let max_lens = {} + let rows = a:0 > 2 ? a:3 : s:get_rows(a:lnum) + for [lnum, row] in rows + if s:is_separator(row) + continue + endif + let cells = a:0 > 1 ? a:1[lnum - a:2] : vimwiki#tbl#get_cells(row) + for idx in range(len(cells)) + let value = cells[idx] + if has_key(max_lens, idx) + let max_lens[idx] = max([s:wide_len(value), max_lens[idx]]) + else + let max_lens[idx] = s:wide_len(value) + endif + endfor + endfor + return max_lens +endfunction + + +function! s:get_aligned_rows(lnum, col1, col2, depth) abort + let rows = [] + let aligns = {} + let startlnum = 0 + let cells = [] + let max_lens = {} + let check_all = 1 + if a:depth > 0 + let rows = s:get_rows(a:lnum, a:depth) + let startlnum = rows[0][0] + let lrows = len(rows) + if lrows == a:depth + 1 + let line = rows[-1][1] + if !s:is_separator(line) + let lcells = vimwiki#tbl#get_cells(line) + let lclen = len(lcells) + let lmax_lens = repeat([0], lclen) + let laligns = repeat(['left'], lclen) + let rows[-1][1] = s:fmt_row(lcells, lmax_lens, laligns, 0, 0) + endif + let i = 1 + for [lnum, row] in rows + call add(cells, vimwiki#tbl#get_cells(row, i != lrows - 1)) + let i += 1 + endfor + let max_lens = s:get_cell_max_lens(a:lnum, cells, startlnum, rows) + " user option not to expand last call + if vimwiki#vars#get_global('table_reduce_last_col') + let last_index = keys(max_lens)[-1] + let max_lens[last_index] = 1 + endif + let fst_lens = s:get_cell_max_lens(a:lnum, cells, startlnum, rows[0:0]) + let check_all = max_lens != fst_lens + let aligns = s:get_cell_aligns_fast(rows[0:-2]) + let rows[-1][1] = line + endif + endif + if check_all + " all the table must be re-formatted + let rows = s:get_rows(a:lnum) + let startlnum = rows[0][0] + let cells = [] + for [lnum, row] in rows + call add(cells, vimwiki#tbl#get_cells(row)) + endfor + let max_lens = s:get_cell_max_lens(a:lnum, cells, startlnum, rows) + " user option not to expand last call + if vimwiki#vars#get_global('table_reduce_last_col') + let last_index = keys(max_lens)[-1] + let max_lens[last_index] = 1 + endif + endif + if empty(aligns) + let aligns = s:get_cell_aligns(a:lnum) + endif + let result = [] + for [lnum, row] in rows + if s:is_separator(row) + let new_row = s:fmt_sep(max_lens, aligns, a:col1, a:col2) + else + let new_row = s:fmt_row(cells[lnum - startlnum], max_lens, aligns, a:col1, a:col2) + endif + call add(result, [lnum, new_row]) + endfor + return result +endfunction + + +" Number of the current column. Starts from 0. +function! s:cur_column() abort + let line = getline('.') + if !s:is_table(line) + return -1 + endif + " TODO: do we need conditional: if s:is_separator(line) + + let curs_pos = col('.') + let mpos = match(line, s:rxSep(), 0) + let col = -1 + while mpos < curs_pos && mpos != -1 + let mpos = match(line, s:rxSep(), mpos+1) + if mpos != -1 + let col += 1 + endif + endwhile + return col +endfunction + + +function! s:fmt_cell(cell, max_len, align) abort + let cell = ' '.a:cell.' ' + + let diff = a:max_len - s:wide_len(a:cell) + if diff == 0 && empty(a:cell) + let diff = 1 + endif + if a:align ==# 'left' + let cell .= repeat(' ', diff) + elseif a:align ==# 'right' + let cell = repeat(' ',diff).cell + else + let cell = repeat(' ',diff/2).cell.repeat(' ',diff-diff/2) + endif + return cell +endfunction + + +function! s:fmt_row(cells, max_lens, aligns, col1, col2) abort + let new_line = s:rxSep() + for idx in range(len(a:cells)) + if idx == a:col1 + let idx = a:col2 + elseif idx == a:col2 + let idx = a:col1 + endif + let value = a:cells[idx] + let new_line .= s:fmt_cell(value, a:max_lens[idx], a:aligns[idx]).s:rxSep() + endfor + + let idx = len(a:cells) + while idx < len(a:max_lens) + let new_line .= s:fmt_cell('', a:max_lens[idx], a:aligns[idx]).s:rxSep() + let idx += 1 + endwhile + return new_line +endfunction + + +function! s:fmt_cell_sep(max_len, align) abort + let cell = '' + if a:max_len == 0 + let cell .= '-' + else + let cell .= repeat('-', a:max_len) + endif + if a:align ==# 'right' + return cell.'-:' + elseif a:align ==# 'left' + return cell.'--' + else + return ':'.cell.':' + endif +endfunction + + +function! s:fmt_sep(max_lens, aligns, col1, col2) abort + let new_line = s:rxSep() + for idx in range(len(a:max_lens)) + if idx == a:col1 + let idx = a:col2 + elseif idx == a:col2 + let idx = a:col1 + endif + let new_line .= s:fmt_cell_sep(a:max_lens[idx], a:aligns[idx]).s:rxSep() + endfor + return new_line +endfunction + + +function! s:kbd_create_new_row(cols, goto_first) abort + let cmd = "\o".s:create_empty_row(a:cols) + let cmd .= "\:call vimwiki#tbl#format(line('.'), 2)\" + let cmd .= "\0" + if a:goto_first + let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'c', line('.'))\" + else + let cmd .= (col('.')-1).'l' + let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\" + endif + let cmd .= 'a' + + return cmd +endfunction + + +function! s:kbd_goto_next_row() abort + let cmd = "\j" + let cmd .= ":call search('.\\(".s:rxSep()."\\)', 'c', line('.'))\" + let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\" + let cmd .= 'a' + return cmd +endfunction + + +function! s:kbd_goto_prev_row() abort + let cmd = "\k" + let cmd .= ":call search('.\\(".s:rxSep()."\\)', 'c', line('.'))\" + let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\" + let cmd .= 'a' + return cmd +endfunction + + +" Used in s:kbd_goto_next_col +function! vimwiki#tbl#goto_next_col() abort + let curcol = virtcol('.') + let lnum = line('.') + let depth = 2 + let newcol = s:get_indent(lnum, depth) + let rows = s:get_rows(lnum, depth) + let startlnum = rows[0][0] + let cells = [] + for [lnum, row] in rows + call add(cells, vimwiki#tbl#get_cells(row, 1)) + endfor + let max_lens = s:get_cell_max_lens(lnum, cells, startlnum, rows) + for cell_len in values(max_lens) + if newcol >= curcol-1 + break + endif + let newcol += cell_len + 3 " +3 == 2 spaces + 1 separator |... + endfor + let newcol += 2 " +2 == 1 separator + 1 space |... + if newcol + delta > curcol-1 + let newcol -= (prev_cell_len + 3) " +3 == 2 spaces + 1 separator |... + break + elseif newcol + delta == curcol-1 + break + endif + let prev_cell_len = cell_len + let newcol += delta + endfor + let newcol += 2 " +2 == 1 separator + 1 space |" + " let cmd .= "a" + "echomsg "DEBUG kbd_goto_prev_col> ".cmd + return cmd +endfunction + + +function! vimwiki#tbl#kbd_cr() abort + let lnum = line('.') + if !s:is_table(getline(lnum)) + return '' + endif + + if s:is_separator(getline(lnum+1)) || !s:is_table(getline(lnum+1)) + let cols = len(vimwiki#tbl#get_cells(getline(lnum))) + return s:kbd_create_new_row(cols, 0) + else + return s:kbd_goto_next_row() + endif +endfunction + + +function! vimwiki#tbl#kbd_tab() abort + let lnum = line('.') + if !s:is_table(getline(lnum)) + return "\" + endif + + let last = s:is_last_column(lnum, col('.')) + let is_sep = s:is_separator_tail(getline(lnum)) + "echomsg "DEBUG kbd_tab> last=".last.", is_sep=".is_sep + if (is_sep || last) && !s:is_table(getline(lnum+1)) + let cols = len(vimwiki#tbl#get_cells(getline(lnum))) + return s:kbd_create_new_row(cols, 1) + endif + return s:kbd_goto_next_col(is_sep || last) +endfunction + + +function! vimwiki#tbl#kbd_shift_tab() abort + let lnum = line('.') + if !s:is_table(getline(lnum)) + return "\" + endif + + let first = s:is_first_column(lnum, col('.')) + let is_sep = s:is_separator_tail(getline(lnum)) + "echomsg "DEBUG kbd_tab> ".first + if (is_sep || first) && !s:is_table(getline(lnum-1)) + return '' + endif + return s:kbd_goto_prev_col(is_sep || first) +endfunction + + +function! vimwiki#tbl#format(lnum, ...) abort + if !vimwiki#u#ft_is_vw() + return + endif + let line = getline(a:lnum) + if !s:is_table(line) + return + endif + + let depth = a:0 == 1 ? a:1 : 0 + + if a:0 == 2 + let col1 = a:1 + let col2 = a:2 + else + let col1 = 0 + let col2 = 0 + endif + + let indent = s:get_indent(a:lnum, depth) + if &expandtab + let indentstring = repeat(' ', indent) + else + execute "let indentstring = repeat('\', indent / &tabstop) . repeat(' ', indent % &tabstop)" + endif + + " getting N = depth last rows is enough for having been formatted tables + for [lnum, row] in s:get_aligned_rows(a:lnum, col1, col2, depth) + let row = indentstring.row + if getline(lnum) != row + call setline(lnum, row) + endif + endfor + + let &textwidth = s:textwidth +endfunction + + +function! vimwiki#tbl#create(...) abort + if a:0 > 1 + let cols = a:1 + let rows = a:2 + elseif a:0 == 1 + let cols = a:1 + let rows = 2 + elseif a:0 == 0 + let cols = 5 + let rows = 2 + endif + + if cols < 1 + let cols = 5 + endif + + if rows < 1 + let rows = 2 + endif + + let lines = [] + let row = s:create_empty_row(cols) + + call add(lines, row) + if rows > 1 + call add(lines, s:create_row_sep(cols)) + endif + + for r in range(rows - 1) + call add(lines, row) + endfor + + call append(line('.'), lines) +endfunction + + +function! vimwiki#tbl#align_or_cmd(cmd, ...) abort + if s:is_table(getline('.')) + call call('vimwiki#tbl#format', [line('.')] + a:000) + else + exe 'normal! '.a:cmd + endif +endfunction + + +function! vimwiki#tbl#reset_tw(lnum) abort + if !vimwiki#u#ft_is_vw() + return + endif + let line = getline(a:lnum) + if !s:is_table(line) + return + endif + + let s:textwidth = &textwidth + let &textwidth = 0 +endfunction + + +" TODO: move_column_left and move_column_right are good candidates to be refactored. +function! vimwiki#tbl#move_column_left() abort + + "echomsg "DEBUG move_column_left: " + + let line = getline('.') + + if !s:is_table(line) + return + endif + + let cur_col = s:cur_column() + if cur_col == -1 + return + endif + + if cur_col > 0 + call vimwiki#tbl#format(line('.'), cur_col-1, cur_col) + call cursor(line('.'), 1) + + let sep = '\('.s:rxSep().'\).\zs' + let mpos = -1 + let col = -1 + while col < cur_col-1 + let mpos = match(line, sep, mpos+1) + if mpos != -1 + let col += 1 + else + break + endif + endwhile + + endif +endfunction + + +function! vimwiki#tbl#move_column_right() abort + + let line = getline('.') + + if !s:is_table(line) + return + endif + + let cur_col = s:cur_column() + if cur_col == -1 + return + endif + + if cur_col < s:col_count(line('.'))-1 + call vimwiki#tbl#format(line('.'), cur_col, cur_col+1) + call cursor(line('.'), 1) + + let sep = '\('.s:rxSep().'\).\zs' + let mpos = -1 + let col = -1 + while col < cur_col+1 + let mpos = match(line, sep, mpos+1) + if mpos != -1 + let col += 1 + else + break + endif + endwhile + endif +endfunction + + +function! vimwiki#tbl#get_rows(lnum) abort + return s:get_rows(a:lnum) +endfunction + + +function! vimwiki#tbl#is_table(line) abort + return s:is_table(a:line) +endfunction + + +function! vimwiki#tbl#is_separator(line) abort + return s:is_separator(a:line) +endfunction + + +function! vimwiki#tbl#cell_splitter() abort + return s:cell_splitter() +endfunction + + +function! vimwiki#tbl#sep_splitter() abort + return s:sep_splitter() +endfunction + diff --git a/pack/acp/start/vimwiki/autoload/vimwiki/u.vim b/pack/acp/start/vimwiki/autoload/vimwiki/u.vim new file mode 100644 index 0000000..08bc896 --- /dev/null +++ b/pack/acp/start/vimwiki/autoload/vimwiki/u.vim @@ -0,0 +1,157 @@ +" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99 +" Vimwiki autoload plugin file +" Description: Utility functions +" Home: https://github.com/vimwiki/vimwiki/ + + +" Execute: string v:count times +function! vimwiki#u#count_exe(cmd) abort + for i in range( max([1, v:count]) ) + exe a:cmd + endfor +endfunction + + +function! vimwiki#u#trim(string, ...) abort + let chars = '' + if a:0 > 0 + let chars = a:1 + endif + let res = substitute(a:string, '^[[:space:]'.chars.']\+', '', '') + let res = substitute(res, '[[:space:]'.chars.']\+$', '', '') + return res +endfunction + + +" Builtin cursor doesn't work right with unicode characters. +function! vimwiki#u#cursor(lnum, cnum) abort + exe a:lnum + exe 'normal! 0'.a:cnum.'|' +endfunction + + +" Returns: OS name, human readable +function! vimwiki#u#os_name() abort + if vimwiki#u#is_windows() + return 'Windows' + elseif vimwiki#u#is_macos() + return 'Mac' + else + return 'Linux' + endif +endfunction + + +function! vimwiki#u#is_windows() abort + return has('win32') || has('win64') || has('win95') || has('win16') +endfunction + + +function! vimwiki#u#is_macos() abort + if has('mac') || has('macunix') || has('gui_mac') + return 1 + endif + " that still doesn't mean we are not on Mac OS + let os = substitute(system('uname'), '\n', '', '') + return os ==? 'Darwin' || os ==? 'Mac' +endfunction + + +function! vimwiki#u#count_first_sym(line) abort + let first_sym = matchstr(a:line, '\S') + return len(matchstr(a:line, first_sym.'\+')) +endfunction + + +function! vimwiki#u#escape(string) abort + return escape(a:string, '~.*[]\^$') +endfunction + + +" Load concrete Wiki syntax: sets regexes and templates for headers and links +function! vimwiki#u#reload_regexes() abort + execute 'runtime! syntax/vimwiki_'.vimwiki#vars#get_wikilocal('syntax').'.vim' +endfunction + + +" Load syntax-specific functionality +function! vimwiki#u#reload_regexes_custom() abort + execute 'runtime! syntax/vimwiki_'.vimwiki#vars#get_wikilocal('syntax').'_custom.vim' +endfunction + + +" Backward compatible version of the built-in function shiftwidth() +if exists('*shiftwidth') + function! vimwiki#u#sw() abort + return shiftwidth() + endfunc +else + function! vimwiki#u#sw() abort + return &shiftwidth + endfunc +endif + +" a:mode single character indicating the mode as defined by :h maparg +" a:key the key sequence to map +" a:plug the plug command the key sequence should be mapped to +" a:1 optional argument with the following functionality: +" if a:1==1 then the hasmapto() check is skipped. +" this can be used to map different keys to the same definition +" if a:1==2 then the mapping is not specific i.e. it is global +function! vimwiki#u#map_key(mode, key, plug, ...) abort + if a:0 && a:1 == 2 + " global mappings + if !hasmapto(a:plug) && maparg(a:key, a:mode) ==# '' + exe a:mode . 'map ' . a:key . ' ' . a:plug + endif + elseif a:0 && a:1 == 1 + " vimwiki buffer mappings, repeat mapping to the same definition + exe a:mode . 'map ' . a:key . ' ' . a:plug + else + " vimwiki buffer mappings + if !hasmapto(a:plug) + exe a:mode . 'map ' . a:key . ' ' . a:plug + endif + endif +endfunction + + +" returns 1 if line is a code block or math block +" +" The last two conditions are needed for this to correctly +" detect nested syntaxes within code blocks +function! vimwiki#u#is_codeblock(lnum) abort + let syn_g = synIDattr(synID(a:lnum,1,1),'name') + if syn_g =~# 'Vimwiki\(Pre.*\|IndentedCodeBlock\|Math.*\)' + \ || (syn_g !~# 'Vimwiki.*' && syn_g !=? '') + return 1 + else + return 0 + endif +endfunction + +" Sets the filetype to vimwiki +" If g:vimwiki_filetypes variable is set +" the filetype will be vimwiki.. etc. +function! vimwiki#u#ft_set() abort + let ftypelist = vimwiki#vars#get_global('filetypes') + let ftype = 'vimwiki' + for ftypeadd in ftypelist + let ftype = ftype . '.' . ftypeadd + endfor + let &filetype = ftype +endfunction + +" Returns: 1 if filetype is vimwiki, 0 else +" If multiple fileytpes are in use 1 is returned only if the +" first ft is vimwiki which should always be the case unless +" the user manually changes it to something else +function! vimwiki#u#ft_is_vw() abort + " Clause: is filetype defined + if &filetype ==# '' | return 0 | endif + if split(&filetype, '\.')[0] ==? 'vimwiki' + return 1 + else + return 0 + endif +endfunction diff --git a/pack/acp/start/vimwiki/autoload/vimwiki/vars.vim b/pack/acp/start/vimwiki/autoload/vimwiki/vars.vim new file mode 100644 index 0000000..f98ddef --- /dev/null +++ b/pack/acp/start/vimwiki/autoload/vimwiki/vars.vim @@ -0,0 +1,984 @@ +" vim:tabstop=2:shiftwidth=2:expandtab:textwidth=99 +" Vimwiki autoload plugin file +" Home: https://github.com/vimwiki/vimwiki/ + + + +" ------------------------------------------------------------------------------------------------ +" This file provides functions to manage the various state variables which are needed during a +" Vimwiki session. +" They consist of: +" +" - global variables. These are stored in the dict g:vimwiki_global_vars. They consist mainly of +" global user variables and syntax stuff which is the same for every syntax. +" +" - wiki-local variables. They are stored in g:vimwiki_wikilocal_vars which is a list of +" dictionaries, one dict for every registered wiki. The last dictionary contains default values +" (used for temporary wikis). +" +" - syntax variables. Stored in the dict g:vimwiki_syntax_variables which holds all the regexes and +" other stuff which is needed for highlighting. +" +" - buffer-local variables. They are stored as buffer variables directly (b:foo) + +" As a developer, you should, if possible, only use the get_ and set_ functions for these types of +" variables, not the underlying dicts! +" ------------------------------------------------------------------------------------------------ + + +function! s:populate_global_variables() abort + + let g:vimwiki_global_vars = {} + + call s:read_global_settings_from_user() + call s:normalize_global_settings() + + " non-configurable global variables: + + " Scheme regexes must be defined even if syntax file is not loaded yet cause users should be + " able to ww without opening any vimwiki file first + let g:vimwiki_global_vars.schemes = join(['wiki\d\+', 'diary', 'local'], '\|') + let g:vimwiki_global_vars.web_schemes1 = join(['http', 'https', 'file', 'ftp', 'gopher', + \ 'telnet', 'nntp', 'ldap', 'rsync', 'imap', 'pop', 'irc', 'ircs', 'cvs', 'svn', 'svn+ssh', + \ 'git', 'ssh', 'fish', 'sftp'], '\|') + let web_schemes2 = + \ join(['mailto', 'news', 'xmpp', 'sip', 'sips', 'doi', 'urn', 'tel', 'data'], '\|') + + let g:vimwiki_global_vars.rxSchemes = '\%('. + \ g:vimwiki_global_vars.schemes . '\|'. + \ g:vimwiki_global_vars.web_schemes1 . '\|'. + \ web_schemes2 . + \ '\)' + + " match URL for common protocols; see http://en.wikipedia.org/wiki/URI_scheme + " http://tools.ietf.org/html/rfc3986 + let rxWebProtocols = + \ '\%('. + \ '\%('. + \ '\%('.g:vimwiki_global_vars.web_schemes1 . '\):'. + \ '\%(//\)'. + \ '\)'. + \ '\|'. + \ '\%('.web_schemes2.'\):'. + \ '\)' + + let g:vimwiki_global_vars.rxWeblinkUrl = rxWebProtocols . '\S\{-1,}'. '\%(([^ \t()]*)\)\=' + + let wikilink_prefix = '[[' + let wikilink_suffix = ']]' + let wikilink_separator = '|' + let g:vimwiki_global_vars.rx_wikilink_prefix = vimwiki#u#escape(wikilink_prefix) + let g:vimwiki_global_vars.rx_wikilink_suffix = vimwiki#u#escape(wikilink_suffix) + let g:vimwiki_global_vars.rx_wikilink_separator = vimwiki#u#escape(wikilink_separator) + + " templates for the creation of wiki links + " [[URL]] + let g:vimwiki_global_vars.WikiLinkTemplate1 = wikilink_prefix . '__LinkUrl__'. wikilink_suffix + " [[URL|DESCRIPTION]] + let g:vimwiki_global_vars.WikiLinkTemplate2 = wikilink_prefix . '__LinkUrl__'. wikilink_separator + \ . '__LinkDescription__' . wikilink_suffix + + let valid_chars = '[^\\\]]' + let g:vimwiki_global_vars.rxWikiLinkUrl = valid_chars.'\{-}' + let g:vimwiki_global_vars.rxWikiLinkDescr = valid_chars.'\{-}' + + " this regexp defines what can form a link when the user presses in the + " buffer (and not on a link) to create a link + " basically, it's Ascii alphanumeric characters plus #|./@-_~ plus all + " non-Ascii characters, except that . is not accepted as the last character + " TODO look behind for . reduces the second part of the regex that is the same with '.' added + let g:vimwiki_global_vars.rxWord = '[^[:blank:]!"$%&''()*+,:;<=>?\[\]\\^`{}]*[^[:blank:]!"$%&''()*+.,:;<=>?\[\]\\^`{}]' + + let g:vimwiki_global_vars.rx_wikilink_prefix1 = g:vimwiki_global_vars.rx_wikilink_prefix . + \ g:vimwiki_global_vars.rxWikiLinkUrl . g:vimwiki_global_vars.rx_wikilink_separator + let g:vimwiki_global_vars.rx_wikilink_suffix1 = g:vimwiki_global_vars.rx_wikilink_suffix + + let g:vimwiki_global_vars.rxWikiInclPrefix = '{{' + let g:vimwiki_global_vars.rxWikiInclSuffix = '}}' + let g:vimwiki_global_vars.rxWikiInclSeparator = '|' + " '{{__LinkUrl__}}' + let g:vimwiki_global_vars.WikiInclTemplate1 = g:vimwiki_global_vars.rxWikiInclPrefix + \ .'__LinkUrl__'. g:vimwiki_global_vars.rxWikiInclSuffix + " '{{__LinkUrl____LinkDescription__}}' + let g:vimwiki_global_vars.WikiInclTemplate2 = g:vimwiki_global_vars.rxWikiInclPrefix + \ . '__LinkUrl__' . g:vimwiki_global_vars.rxWikiInclSeparator . '__LinkDescription__' + \ . g:vimwiki_global_vars.rxWikiInclSuffix + + let valid_chars = '[^\\\}]' + let g:vimwiki_global_vars.rxWikiInclUrl = valid_chars.'\{-}' + let g:vimwiki_global_vars.rxWikiInclArg = valid_chars.'\{-}' + let g:vimwiki_global_vars.rxWikiInclArgs = '\%('. g:vimwiki_global_vars.rxWikiInclSeparator. + \ g:vimwiki_global_vars.rxWikiInclArg. '\)'.'\{-}' + + " *. {{URL}[{...}]} - i.e. {{URL}}, {{URL|ARG1}}, {{URL|ARG1|ARG2}}, etc. + " *a) match {{URL}[{...}]} + let g:vimwiki_global_vars.rxWikiIncl = g:vimwiki_global_vars.rxWikiInclPrefix. + \ g:vimwiki_global_vars.rxWikiInclUrl. + \ g:vimwiki_global_vars.rxWikiInclArgs. g:vimwiki_global_vars.rxWikiInclSuffix + " *b) match URL within {{URL}[{...}]} + let g:vimwiki_global_vars.rxWikiInclMatchUrl = g:vimwiki_global_vars.rxWikiInclPrefix. + \ '\zs'. g:vimwiki_global_vars.rxWikiInclUrl . '\ze'. + \ g:vimwiki_global_vars.rxWikiInclArgs . g:vimwiki_global_vars.rxWikiInclSuffix + + let g:vimwiki_global_vars.rxWikiInclPrefix1 = g:vimwiki_global_vars.rxWikiInclPrefix. + \ g:vimwiki_global_vars.rxWikiInclUrl . g:vimwiki_global_vars.rxWikiInclSeparator + let g:vimwiki_global_vars.rxWikiInclSuffix1 = g:vimwiki_global_vars.rxWikiInclArgs. + \ g:vimwiki_global_vars.rxWikiInclSuffix + + let g:vimwiki_global_vars.rxTodo = '\C\<\%(TODO\|DONE\|STARTED\|FIXME\|FIXED\|XXX\)\>' + + " default colors when headers of different levels are highlighted differently + " not making it yet another option; needed by ColorScheme autocommand + let g:vimwiki_global_vars.hcolor_guifg_light = ['#aa5858', '#507030', '#1030a0', '#103040' + \ , '#505050', '#636363'] + let g:vimwiki_global_vars.hcolor_ctermfg_light = ['DarkRed', 'DarkGreen', 'DarkBlue', 'Black' + \ , 'Black', 'Black'] + let g:vimwiki_global_vars.hcolor_guifg_dark = ['#e08090', '#80e090', '#6090e0', '#c0c0f0' + \ , '#e0e0f0', '#f0f0f0'] + let g:vimwiki_global_vars.hcolor_ctermfg_dark = ['Red', 'Green', 'Blue', 'White', 'White' + \ , 'White'] +endfunction + + +function! s:read_global_settings_from_user() abort + let global_settings = { + \ 'CJK_length': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, + \ 'auto_chdir': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, + \ 'auto_header': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, + \ 'autowriteall': {'type': type(0), 'default': 1, 'min': 0, 'max': 1}, + \ 'conceallevel': {'type': type(0), 'default': 2, 'min': 0, 'max': 3}, + \ 'conceal_onechar_markers': {'type': type(0), 'default': 1, 'min': 0, 'max': 1}, + \ 'conceal_pre': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, + \ 'create_link': {'type': type(0), 'default': 1, 'min':0, 'max': 1}, + \ 'diary_months': {'type': type({}), 'default': + \ { + \ 1: 'January', 2: 'February', 3: 'March', + \ 4: 'April', 5: 'May', 6: 'June', + \ 7: 'July', 8: 'August', 9: 'September', + \ 10: 'October', 11: 'November', 12: 'December' + \ }}, + \ 'dir_link': {'type': type(''), 'default': ''}, + \ 'ext2syntax': {'type': type({}), 'default': {'.md': 'markdown', '.mkdn': 'markdown', + \ '.mdwn': 'markdown', '.mdown': 'markdown', '.markdown': 'markdown', '.mw': 'media'}}, + \ 'folding': {'type': type(''), 'default': '', 'possible_values': ['', 'expr', 'syntax', + \ 'list', 'custom', ':quick', 'expr:quick', 'syntax:quick', 'list:quick', + \ 'custom:quick']}, + \ 'filetypes': {'type': type([]), 'default': []}, + \ 'global_ext': {'type': type(0), 'default': 1, 'min': 0, 'max': 1}, + \ 'hl_cb_checked': {'type': type(0), 'default': 0, 'min': 0, 'max': 2}, + \ 'hl_headers': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, + \ 'html_header_numbering': {'type': type(0), 'default': 0, 'min': 0, 'max': 6}, + \ 'html_header_numbering_sym': {'type': type(''), 'default': ''}, + \ 'key_mappings': {'type': type({}), 'default': + \ { + \ 'all_maps': 1, 'global': 1, 'headers': 1, 'text_objs': 1, + \ 'table_format': 1, 'table_mappings': 1, 'lists': 1, 'links': 1, + \ 'html': 1, 'mouse': 0, + \ }}, + \ 'list_ignore_newline': {'type': type(0), 'default': 1, 'min': 0, 'max': 1}, + \ 'text_ignore_newline': {'type': type(0), 'default': 1, 'min': 0, 'max': 1}, + \ 'links_header': {'type': type(''), 'default': 'Generated Links', 'min_length': 1}, + \ 'links_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 6}, + \ 'listsyms': {'type': type(''), 'default': ' .oOX', 'min_length': 2}, + \ 'listsym_rejected': {'type': type(''), 'default': '-', 'length': 1}, + \ 'map_prefix': {'type': type(''), 'default': 'w'}, + \ 'markdown_header_style': {'type': type(0), 'default': 1, 'min':0, 'max': 2}, + \ 'markdown_link_ext': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, + \ 'menu': {'type': type(''), 'default': 'Vimwiki'}, + \ 'table_auto_fmt': {'type': type(0), 'default': 1, 'min': 0, 'max': 1}, + \ 'table_reduce_last_col': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, + \ 'table_mappings': {'type': type(0), 'default': 1, 'min': 0, 'max': 1}, + \ 'tags_header': {'type': type(''), 'default': 'Generated Tags', 'min_length': 1}, + \ 'tags_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 5}, + \ 'toc_header': {'type': type(''), 'default': 'Contents', 'min_length': 1}, + \ 'toc_header_level': {'type': type(0), 'default': 1, 'min': 1, 'max': 6}, + \ 'toc_link_format': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, + \ 'url_maxsave': {'type': type(0), 'default': 15, 'min': 0}, + \ 'use_calendar': {'type': type(0), 'default': 1, 'min': 0, 'max': 1}, + \ 'use_mouse': {'type': type(0), 'default': 0, 'min': 0, 'max': 1}, + \ 'user_htmls': {'type': type(''), 'default': ''}, + \ 'valid_html_tags': {'type': type(''), 'default': + \ 'b,i,s,u,sub,sup,kbd,br,hr,div,center,strong,em'}, + \ 'w32_dir_enc': {'type': type(''), 'default': ''}, + \ } + + " copy the user's settings from variables of the form g:vimwiki_

    G+tFX=&@_QIc`*Z}`f$czCLCr=V#w zhT`scRFNTzGLa47jh^$j8`9|=Dr@76B)Xa5VVL&c%R1Me zbBr)%vm9g%0WqZuO5Vm%5kJp(zJc*ASk`eo$Dt-Q>JZAE2&WlsddkM3m{qoSA2ZEi z2k&app~yNP2knP_eM&x%%b(!V=CPSohw+>f%J-pM^xW;($|y|{UCYb6MeWL?LF2%A zWM`zpr)08h0o6}c^C%&ozO1UrbF=PgV|Cp6G4T_H)M{0O8>`k@a2tLBph9!I=C?|k zj3cTkHSv~T0PHFtO84v4pzy*q9Wfmp%;5)@+T{H^%_CQfZ`2X1xEfDZtMQId5eI zwtT_-coOgAQZhVO`E;!ZMWH~o-DeMuMjcoFzJ%>Hj_vGE-1{_j$JtOOxNflt*UV0C zp`pDp1Fv|71Xk%}I|tOkR6OS7gp5!)9K7ewyj<&3VGqhL{6@WZtC+SdX&tieb-Ai? zJ01~6d===9sOJ^Y=gZ_6Vb$K2b2+FHQEESw-Y zWfL%6=n@d9@-}0#jw=vYXnS0&pV`q)cKa$ir zuChd}-?0~O+JHXk&osG(?N|2_>pkm2bbKA|R|K-&BQ@@KzrinJl?Y~G#`#$@5<|J> zMaEEjyH{KMA_2UGTbzkwUl_CMHwz1Vqr%RZwo;gF8CQDVxhag|S888E9sX9cGVdtT zlnT|4s4P>TQIB8mh3xt`eKhF|{=fZ_wp0QslHZeoG9ITmx$*_fZD90Fx| zj_;ZuL^y$k=HAi7JmY0xn`3^^cEuVj5rpF!7K1c1!wIdsZ-BK1R+;o-cttN zQfn=9#u5kYBwtO*o$k+DPN^^Y zUtas?uASTh6Ss8P%86V+mO!G|<_vK%?kRMQSY^&LIbYV3^>^#(Tsln54p4J!N9kuxvJ1W0u|)^ z>DR3Fm;fYvCbJD{&{_!d_)sB7H^!Ng5%K!!;_4TyI8W;=Ll95}1oX+a`qUPUDME$v zU7FZdvRI=uN3+}@zT-Ah2p(152JK(8Wnl!=C^-cFU0n-5loot+NhGS&>1FHj$z*Q5 z>y@5uW~%pOMP+Ud?*p_PGDGgCpEpi5*0oBc&3I0gSUvHrvC5WPt{u<z#@MoZj6u99!kHaQVOe-`$n9rSp?yP&&zrvuPt?>g z!{?&&#Ew0EAAGetz}=aD`zZ?Nlc1sFZ8b}7Y?EJ7rS-Ie_FXTLOmMRikxUYk#N+(- ztmGa7B>&Y7<hq;%{mt8|sjXX0$qj;JQIAkVAQN+su(#@MIS*CXs4%42kUh zq6PZHA={Te7=TV%(Ok3cj`0f9*f=QhA!~ud$^tj>Pe)2C5_u%5dG=3#uxi9hsye%U z?45P1aIQ^Q2FzoA#zb3se4bo(CHF}TT_aB#DB`(VC$LF|Eh^rGQ{NRfPN{(n8W_th3o|X0xLnGe@Ok=Aw6C8*453?Lvn=pirQyMz&hn zH9jC~VZ`%I+(((hu1eS*+rD|rvZa1!3ZNn?B&WXsz1g6f#>w}#A77RFCf!G5Ntb$F zoYcr|l?mBJ({gi|fa#5H7Hc5<>-}gi7sk-$>9s_140m}Oii3==LDh6*5Ye|TyV{Mx zLDQJ~S;od3HWl%7K~}GKn%`)bblz3kC%oIthQ@@2fX@x(l*&Qpd%N2^Xg*2%y`pU2 zY`I;czB#U{+-C^o{%riVw-SW63f(S9P?YK>nl~aZSM8DonhM@*rdF0#N$GEK%B_yHW3<W6C|@>zOPGtgl}k(POCn$atM{)O+7QTZ!C)b|ea5 zy|~~T)gR0dGA!5a4aBPd;dR`qsZ+1e)-zLXXwS28LpscAT|INjZSJV;`aNirorb2v z8onAtNg7sy%*~9;)w7GGa|ICNc{UvaVh=b`fKFb-moq@C^~d4kYJu!R0cqXbpG)Ga2??N21&bV6`HnqVa-V z&OBCUpI_ynW*1AHC{m`(C)vLnQ6b@@ zhxsw0zX}wxTEhO|B6aAdcBiQc%8{aSWn8?+|G@T@&pP++Mq$E2(sK@l@V>RhDYt|l z_|iN#Cx&lN2Vz%k(L?m?Aw$sw<#^;$IarrQo@q_l_2FU>SO2nbPCwwnVB=A=8&Ur$i(Cqhl1vnwVF-45BBD1$3@Jwy0MDN z=F^aUv!T=_#(sS)s`TdXZUlW~F*Eb1j!Qq%7}QbRmvN^EnF)*q5~b*ZQMT_IeiUUy zGrvxbjb=W!i84Xwx$`$Rmao=UqJ%E2j~;zH>kO9oRMT@+fd!y8k>l}No+r;^6`|hi z+F*s>K!vpH+l55j;+p6-=hGuxT#uk8+77sx0QMVx@uFf%m8p2pOYQewT1zqswr}l% zhxdwi9<7mb5fyRG2$&`$rWhp99@|pQym^_DHM|e9i*md_l2$${TM;B|dE8Q1H&NED z8`+1^D)c&niHR;|@lXlLqyg=dp`EKRVO8qkrknm!r_cYNP#RPaz`1NdPV(| zgwh9MKo-T3vc>F8iusmPLEa_Il@+Vj!_K~e_pHZJh-A3%|?NVdJgK zPLwK{8<`LEB08Q$H*faxa>j7r7<8YWwO9+tGhrvjdWB6X_!4)rv1dxtkY%aa&5h{` z(Oz&9xN`^dlb9ylzU?NjM0?$v{H<%00@)Kl9)Yy|(yP{f$Fl?l*rodSQh_hG|I{u_jfn0LLH_##=a$g8WyYLk$BmbjE+q* z(u6p-qmM)<1`UZXxC@?IRs%I);X!XTqTw@dQxgPg{VR@6F__J_nmW^qa=aRakcA(4 z>SuGF9SJ-xJ-t_rKD(D>!Idx$EC!6uuNrUWU{VP|y;8h6otuM5hr5;cRxt65c4<&c z$Oqh>C7?~QaJ*gEha5zk1^Z}cOn7o z8GP^#j4?T>h$Cp2A+>KA@B7OGCP2+cckLw5ZZKl~ab4q0O1o>`vI` zlGMLLGU}-`A4w7haL0^gOJS8f$7?YD!8eg1UAlA7fm$1@ft2YX_Sxhn07sC03lMn5 zHNtQDIP%$=1KQ{Lc~`@+EQ!Z&)n@}9nxt5{rUz*7Z`wj!gFC-GK2N59I$bMmrB|pz z$5>)GJO2RmuHj3x|wyT}8fF$D9uS_zk$*Fb+g0?A)Z)lT#mLqqip& zk2#4mb9@c$o{ZC=lYM6}tMI)0(V^*J&toSI5VHwlkC2~C=DyD*UDMZ246I>Sf=SqM zRt61eHICwdWLkF4kIgtbewsmt!<0*yr@s^cAE%{T zn{8|DXX2lPPkhe|4$Rpry3F;cT|?%G5Lml#_M2>f z05Y^`IGBUn==iFsUMx@5Rki0nDzoVHH7H-pd(f7gI}0v#mDrugP5$OLR8phgEx>l) zph0AJb+G(lT7HC14@QK&Yj*O9Ogn$I+PplE&6Sw;Sed&^vd=CU$G1riUi+2M*Q>5} zl4<)+Z(@1GssHKz^C*yAYW{!xM~q}stSSvkWPl6_+cy$i41_%V0W7dkjkA<4=1l_4_B-m`E#xVs0&=h(G z?7S5&+<5g+i0uWAbcVLCCN!l6vOUX1E=cS3;Mys#eIeJW@1xZGEYRj3nfbmfV_R>0 zctL;*qfTKMM?u492ktF4Ry=wYKFCT-76;qC3??b)B<|5($h0RtP2EBZ&`s%&1 z-UE6yX%Ii~&RxuOtw|`m?$GXQwZ%}3q7dwrx)^obMHIDISX~OY{hKN)=mcIFl9}{l zEG#ZP3a`sOx=~GY$&Es#@1j+Pb{1hjIi&qis=@#$3D6|&v%$_XLdGwrvS0qgN}A_U z94O;V*Uq*X9My7QgV0^#rOk`LRV--WJ%xO+3;nmY0|julk^OUFWL|$^>G#X8LNU+Z z7mb+YV#&x5((EMcJ4vegQ!KgZ4ELmCVT$A4>*q0krPg|>^g<2Q%M!KB7xz%VDtGWv zNS_n_^Qhr})HtQcM$|YJWZIs&l@53(ksF;i6Ie{~*<}B!r$|?So}w}v{MiLpKyy^B zd#G5So-ib6pvR}ON==oJQh@v!B;U{2QY4^1`3-FOW1M-{aS9_`_Q8Ev1Gd-&gl(Bo zlxe?4T+-*u1Sdn?5IKrbs#>FyIc*C4qe`QnC|u<=AwP^-P&HePFmt%SV54fQM9)9n zGUQplzP>g}wus2ULiOW?KRE~d{hr*vZq%i+#QXUO$!M6SC!6}uHHSY7QCJQNcJrU7LdV?zsU9PGXB?dCnh9J zfb(9`repN~6!z~P*m#fp1hBO;F%aY`#pr)DUqK5pkiNLfBVPZTvDMS zhCFDg;uL==VLpql1b83tL;WvI{>3SN_90-P&oZI+*E-qHqsS2PO*X<8ne=xr|95$) zG!db!nf{UD)vuu}jE#ssKeF9336LUr`NsmtGpRv5{sA`Ndi=y&>mCBqpE zK=mU*iC>EOEqaBC@X+5O8Kv`kdyy%u`&a)2m>H2EbK|}HKJZQeG{Vd47_Vl zO==E*_?R?D27vyZI^b_)_)RJ&8U$pmX>W4;23Z>x$Rf0W!4&RtwNf2*CiNn-M);g! z7znvtm>h7vIba!%h9-;&IGk+!51ZZo&*)L#(3Jp*--hWU|B^Ko|0D{~s(G(msNY=o zfcwrU^<0BvcKg?nu&^h9`82d$xF!B}%1`TBLK>uAudS# z-@HT^`FT_^hFK$ElnfSz56~#lQnsEfFn*L46-9+uM&8vWZm+s3_!qVR#SlNQ5ah4& zqtO1+>MNi)r2%k{d~N4zqAM!cA9Ur(r@=-)QhgBf1BtC1;7hY0Qbs zUylJ$qE;9qE+s{_oqFWkcr(6T`S&%&{uSuLM+gT!db`bU@~cq(sq$2s7yvO*(MJ%_ z=%~_qiQQs@^7t)f6Ys6l>ez3A`hNufq-wgBSG8#OL)$u3zy*oGzwKD ziZn{CQ){lT-L)%>{GZd)Tiky88>sn}ImD$ex)NXqhi>{`J9B{DI%zc~6IQ$>Ji}3G?97lxDD`Ye0Kgs?1W^_*EMo9qrwh#}1W(Q7erb(SI z_N(Lko00x`9>s`of+vH|KL7F#X+IRsaN#msz?UyyNRND}si_}oHQk%fUv~S$N0zny z_LWm%UZj~?0Yp|ZRPLD#wGA~&AvTN(p|YWb=t?geo?v!|)-=Rs`RZXZsyst}uI1-| zhkisPcmeM7E)CH7KB%N7 zE{yWa(e5X#i4NFK_p;;OFRAv_bH8ssZo6IN278B zgoRObs7H@c{k|#i73x|fnJ@YwJ>ZX2&X#O+T<@vvknH_`K^sIvg=7TkSD=&powgo` z7%=?yxW#TXQ$(;>==Oli?H&dhxXr+9`>%>XaIA?R1*l-I*8fU`gopcY$4)N_v=-n{ z)kp6v%hu|$_D2<6$8r$dQ)pO$PX2cmeo^BeTHPav0#pc+9pe2PQN#=U+oUsRQ2m6U zW0CkcK30AY(6C*=x66<_ix!A{B0IHDFqsgrh3xIe50Qr-p7OaAq?pHR-wAr$4~XZ4 z(@-J*_d{P?7`dIb{{x-+uPkLUqhB-u9Ioap-JAzGr0izPTd$JI1Uy|L&lxhjosMB_ z=;#?hs1>A#%>IH$f$XpH{C+1>7hM`K%fegg67s9NxnTJl5CgDDIJ<^;w^JKE&a>w!%1EXzLaqv3 zVdk{|t{B9xqYEg{0SAZAMlU6Pcl>xi6u&xt!sP$uFMjB1h)3gwNG0Tcu3 zPW&eA`TwvH4HdFaq#uf(58KES(_fqp7YXk@!hn)4HHyDe|6TvWC{R2k48X0j1ry`% zqMxuJVF1)0{q--u-^r9k7?F;o)a-X7K1RX-G}9NyDgDmizX!=5{%prUg=AEp0LV4` zm3$@$FA7ir+AJ8S{oe|4ML-f-*qhK_eJNO&l8y?=h;oQWLibndzZvk4%X!4J&0Q`n zzgtl)#Sg`AYM8QH;eQhuM3)A<|DuBQ^>Uc7=3kVh zfPkBCHLfgw(c^D0frPgsfs7BhqVd+(`IWdZ$~!75BqIzZ!kpjb{40v8Mf;)nsSgr% z%luB{j35fYF7!5y@qZh~Cj{ZGOwCWUf9LxBJ7MJZykHmMdixjNA?!%girf6EJrq#}%X2i}y=J7J|-(2? zX9H|*+o{e9XS&QZN)pIv1(fP?^=tnM`B7eE&t(TVEp;oKOWEM=JD*U$<@{R>AY zm{^h(Ms7bE^2*iw)gGC?2*)5kbItln@5D92?>wLh&$z##MBs6ax3{n0$+pmaBVwJL z;+pe_!1l)_SIzSc_<^O6a}XuaUA_Ub=&TrN`xj4cyw`5FGmalVCY>BtznZsU z6RLIN;hD5W@v|vwv{=Y$zS+(Ir+J_C3G$$L*_5}|EqH9FE%EJ_5U@tucpOyrHZ9nL z1ZEmxr#V@d*+QJk$>N#ixJs~64F$rXNCo~#%}}k8*&Uzn3-*?a zY6z|KA3npgva1=BG(f-jNgLU~T-MOBIwwnyY>vOfe3>ox(4!OHD+FH!-mO#CyFe-L zucaVe1d7jlA0kna0U^!cMomMX*K;%d{no{$TUT?Il)mrZ&wK>?xYbYV*wi|CE}2FM z!QI{VOY5hXz_xEgrX%gvb1y=K8jRejz6^U_!?ioA;z zjFEjI?(l&u)o+bY$aCut9rM_^=XRt_-X4Pto#hPg@D$NLOZ7hHUaTlJb9o1t)yQ$F zK!1v-1pA4D&z9yMF;vw@pHgDsxl#i-nYSsIzoPU$`EdllJs!c#J9;A?kYd+V2#z#L zwCb-118h7y=JDd!MB_n_W<;M~f=Ihdo_8}A=xl(r(nX+n0EA9t@bL>9yQg_wuLdn~gT2>% zH8&0G(M4aaXvN{@yQ@X}?Md-Aj>`cWw$r_uUQcUv8s6ol*f}wzyPN3ZiM--5`-$s2 zoN<3=>2^NE&CL(eoxlBp>vZr^N61M}B|q5j4^zKJwt6Brb{7R0eL?%=*KyJX4H5>x z3$Klp<@eB}!`*R3T3K`+In0OA*&;x4MCiT+0iHf8B&keHfV)0L;F?9chXv)brlHR! zh4+aFWX>|<2CNQE(8T@Z=TurdeJ0~^Ii9(tWXYZ##KGA3bMYaxTyMeeq!TpdoS{UG9-qF^Jq ztqWhaA;}_{QRbMryk*UU0s<+LsX@|e4qR(^|~!w=L|OI_KP5IoDL zO4y768=Z+9rY*Q}XUiD06a#Fa7SN*aLvKv^4f4>61al9}kjO%_Z-Sz?;5 zM||Pctg8L%n9L@nxx=@@auJQmJ!EP9c_DhfSxbx z5`p7u0i?W6ISV%Bt=69;a2wi@v94`3^&A7=Zl^lOz+!dhla77wZ-EQPzV}|-o)xxnPQm`!$7R<6C|*Ls36Q({i7L;0CDVm{ z4hf;{@x-e3eH|;C#J&`tPYdl655wSr&~8}O0n}!QZKyg89Lm<#kd5=Wc{5(uJLBnP z*qkb&KIna$WX7Wr;(?ddVIV`qD7p=Fb<})(HKIFIrdb2*y0ICf&95Tgt1Ul0I+T)ub(VSuO~@s=4r(>^zw2^gzc$igVnA~hnJh|;ZOLO^ePV4TJo zrl^L2hq+rj654eR`-@i}X4$2*T=>oBdMSMm;AaUS9=-!UW6Lzxcw($tFP3q96yDRu zU8G*v)xt=cQ$OQZcNW2T*Kx0L8HPr$qeg~S<{O^{+j_cvZRSTz_h$*9!FhEzvVbRO z6z-Y2)`huy6k-kc*S$iExd{gIN+_z_es4a0sOqD)Yd)+yw;WAsJ|BKNlR9MNh}*yH zI-`G7kR9>vimM{b;mLP`I>@qDGed?q=iCV9?viPwz~VdR(%5I3&h7O=Ps0!&3Lsb2 zvn1&d>QWcF{(*CM6hz_qf^k8+mw<9sUI=ypy45aa7TX?aV&HxevuFQ?9+@ z?P7jedY-*7PR6sPzXwc8&^z=np8^-=CHD(ap7Cpq;Ql!M{$M1?+kH%?x(IZ7?gMR$ zRZ#S%G@+!l%>lcWoM(q^JFeNqfyh2oh(ucIcl5&H5RljR2ghiua}Zz19oTod)Ezr~ z2$=7zw? z{1eo@C_AbRbP|Y*p?Kp~muEcoSayO@i1T^#R9 zFvHvNP_#tJFT{M~DHM+$Z);&|;nJu1b_U^;pSnCPi>npabJ;7*w>acns5|MvY9>(N z`4JR^YkycfqaYsisE%e4^J?CvywSF9j{fd~;%b;@{n0(y*jm$mnJ%q^DDKCLF)3~q zH)`RBdZ%hh=FP`#UTddcM7%z0UA8==Iif2u3MRs1yZVPixp&=8l>?{nby`rKxr~ai zkS`PlBx3;b(>~6V9>048^gioj5cJ%2l58~dJt_M$S=D&kMK=-bc-Y5R1$yhBM)J_;*EMr$rnLaR^ ze&u1KD3FjN$a}T!+55~{Zp$2xfs@d3ehsPD9qbD~r_5M}fPKMU4{~Uo_6qYAu#J`0 z8rCCZfxXP$W2sl|9ANMBM%((OY0Bv`G+~rPITF$^7k2X<#86Kle8u*|dN{X2%d0h( zN0DN&6IEe_+<2s%PyIOL2|CEa3Jur1+e1mnBSip&T$Xz#U3`_NQ#@(CKN34q&Vt<7 z_DDskx=bHDd~^~t`Zdgr^mCF`_VU_y&ZnvsOWx;0tCmCfIMH1M0pun>sQQa|D>{Ur zqA;q64Ka4D^I9Pabv*l^Cj1$0evY;1N~UQ!fHeQ9C+>K~f?cymWX*^C!>)7V54Q)^ zkr`KswvG%w#cRDShd$5Hid_ewvZ*E_&q0i|73NKb55Fc(2Vapys{bf!IeT}^%Xx<_ zyAKspR2;~W#tHh(QI7kGQNy^XulVi*E}3I*0Y$mZl)if#8=c`%~NGHLU;DS7nh_UQNiYOUP5};!>OYRQAIW->eZhALM$iiW79s*Eqo^LE@w?6UF*R>uYuD6XR3ge>Jh_d5Fbuy?V*rt}kgL`Kx->mSe}*57|saT1-r0WxAq=UfO$s zUoP_BmhQ7HH-6GWiau_;J=*Wia$Lmar@DCDORXmLMBZ!pXUH^8N165QvvJ!r%BA?_ z_R1X<$Uqi~SGr*heB2<4ZB^`{xSqS!dS~S9R-!5Py+77+IET2tyT##W;(vjjiDU`! z5YGPgY1KJmSYC$rvfa;;^z0=+PIak1^I6;IfzAdVMYmWIBB8Rho1b9-sbLZ-k5f)B zJ+?PLtA61-y<4gq^~i0bl+w|Inos=zT=C)faWsR7b^`G})cB?iHz9%ZD1ivk9L9{H zYMLNXQTlSiUiuhbq!~C5y_PW~gvdgj3qo6Z9fdFIIC&8*o zH#W-f;A}Y*QbbA?kNohjZK71BAtnINQBDYUA>b5HXun$!A`sw!yH*lJ;aQ+5;pc%$ zy^CG4U)DT~rxD*R%Eos!t!4W7IE`_CwyI7Whv&^ZHiNuR#6oe8j4N#ta)7UX;SXDxvA_>H^s5w`?Ar>`JAjeL^>4zwTiH(yrg zPV!Rh&h}TqDzYqb?%E=g30H|7jxID{ht9`#SzqbT@?R&H5&tktlq5VhMi1C=iC`I~ ztm~ziTU&?Ddrs}48D<*#!Y*ad?vpIjwYl_N2DxFmzWm{K-g@>W^)vwS3hC5JEVh?fPXexv7kq{ud*TjZDxs^*2JHXO>CJlI9~$ zhRaaA1md-c0-xPd_~U`Atlo29T&5`e0OUdek8<*@AbCpnUsNubkl?4=-^LJ5Ba+D zKbojC$G{MCc;vZe%%U}2S*f*OTEBd@OirS9w69SM6?seIl_Cms ziG8-^z*D(^)kZJKl3Tf#h#;SlACLD*C)L#uH&_pHt#JH47v3`hF-Ip2*^<%$XkGl_ zGB}y*bcp(uY^j$L%fx&7-c^0{=akNmZ>IO@5Q93;En!Zhsy{&s;i*@SQSc535{(3heTOI~E;y zvYG$KP(KDLq)g0DzfV_Oupz?~06hN>V{aYR51I#mv+Gk-(QQMvb1{LQN9p{@)MOc!IXuc(S@*WnL~@WDoD;Hi1Q0-*Z3c-yNo8x@&eyJ zl{OaHPdZVm!x#d0dPRt>*Oypv4@Bb2s@ITR%vbo0+9_;SSL4szWfgL~WZLiSb)n`$!1;bHAbE zwwh0q$_}1a-tf+(VZ;;sYuDiEQDzHXF=J3=Gn1#imx&t8yZr0Uk0Bi44nbM&^GtLX zGaYKm9EtH$BQlf>8ozpXh+i~$%0cT`u;Hz}pb1NS=fZd7FXl>}~tmq`hT!zWUG=&3u%(7C}MNqqB zb>R@515~ijwy}2NAP9c(H8GBX-$HqLAxuuZIgv07;L3;B*+Az@{yxnmXQDLF*#kmE zwoqY8A&?9Cou=Q3+jog9tA6CI5gb+%K(ny-y)~&QI%=IZh1pd~>5STC`uEoE{>6P_ zG|v^w`&PI2tm#ip8Rc7u2U7`7h;>u5y^$+qd^j8HbJFJwo;|)`kjO6&45dRxi()yk zu1SZ^r48M&xK)ToarJ6WY=EAFMJ$;Xr7n$np)71N-7dv+y09Q?J-2<&Une)!E(nht z(N**xcy3XUew_`(TK8jy`n}MIDB@@?N_he%^_)Qi$$BH!q2SQC1U^`yM~&cdPU-P) z{}QO%DDn9Xqs)Qz9pdBG1wF*^Yje*o_U3vf=^v2YFR!C@x9RV2D{mopgR1Kh;a7Sx zx@3R#I7mXty8F-T3}uZvD)vqqSgmMn_Nf(SxfCNjOZ(5-y-05k({;FMxYa>}2G$+I z&izRFc5pmBxEr!yn|bn}wTP5L41!)$c|`WEYZvw%&&BjEkw#EctduK>2{|d!!_kEqsSsKWBD;h`AQzdUDW%t~B|G&vV)el%! zRVo4%-D1(kQd?PUx_(|R_!dBm^7#p=uQ2W00 z!I4Mu!fDU>zQT;q~+O6`7kD{N9pqvv<3K7@vo71)b* zsg`4U=4S=-ExN?41l503|9D1std2pP25(8158>=K&|)+do2^&Hg88S57~~^iA5#6P z#fRs%1M}1Ep8_Cd_HasN_g=k|;^GVS>EOeeRE!HL5J2ljvRJma=Q^4T)YiW^mo+aJ z+{k=VRCu!2_0!=Pl23zyEyUy37?t)OfCF|^S_nNP)G2X`v5hCPu0?UPzC-C`y93^6 zmv2fq*&QJ6wZWuq%}5GNH2iYTnEpp&eBXUFf3Ilw?aZ)f`uEra(* zn^)6C|FGI#bOJV}kwwurW%HG&;S7y;`>u`9+OI{)g0W+>CLqqb-u+VU$tMSXY9L2T z#KKA-Mz6if#3+E8iRUdW*G?ttZBHU^wvS_F$v;c)aBp)anqK0|dT{7UlI&Oc4i!JP zGHKiHdX`iy&N=TYETdZ!N~G(2Qu}QqlG5X=q(v&A3(5QroJo)Z@lOzK?dTE5Dji zaRX+4RfgJet3bQjeZ`;U>H?LmT;c|Own?54l1+uEsB*sk_d^lQ)1BHweP-cLWBVNM zccptSz3z-JY?>;`?(MxGrh(Pce4%t>-=5%-$*aVgTJe5rI3x7krtl0Ho6}p9>qulU zsPw`aWu-H}l%|OvTDJ0=@qsrNBgXdS;4Lc`9OJK#c|gh@o1P#$NiCuvaYe)enRk}f zfXeBKc#^Ao6%5)sb$y_AE_iPtQNe?*idqLIW=zah$=J_mm}XPhJ6!?ROjlsGHq1ICc!`3@=%9|J0Mj52`NxpRx=! zGX3}zVPX_iQ}Ta^U4SGGDdu-uR3~^%4Z<~#Br5H0mnh7=Zom?QZ zR&c~I?~fWoYl2Lj69xAr-}<%YSiwxE5>-gB9&hLbz_im(YOL z(mI{>nD=Dl`;um`C3RU$D{a)g-qbuWYgYSDVmc9fbtq!VvPWmcRtv$czZP?(UvnH< z&p6=QwjCYiFj_PLUQD!+$t+-jgFzs45a~?h>?qoc{8&?@Y zgL>KZb9Y+hVnilpoNJ@X2c9?bZPl;tLmf+Ox!xgKwcXydn$$h-JZYQH3HVZF1m#xV zdMQ9CsR;|br>n5#Dawptdh=Ylp@DZ-#^W-zI3 zEu&KAe?`grp9jB6#`qIV?Nf^jRC8pW4kIBjeN$8Wh|~_ zyN`MMwC_r<-6VHX4UdP8z$>#}MeDY6H9B{>@;mKfq;I>JM*1ltYpwNEh}BcJiAt4> zva^vOW*c>vrk|Cufh7D2G2ds*v>@um*)ljxUVAD(!)={e*+vK7Fc-;X9}sPOQ5M;A z##saOxx%vm*hHI3AYB#Wo-!v@_f{jel=(3lT~F`Hnp5&3GKJ#GT5Hj0;&b6QpMhkL zVH3IwpNrtQWEW9;-Ib=0#b~~l%2qY-+eiJi4jn|#Gcrp0q|^rq9T6X218FkDAA4{Q6}!uDr-x+qpGE8b^_qXyhhRq3|`dpVF4jTz&bMDNNLENy^xM>dw>t z>*Mvk!Wmz*UKV!s=8C`c`|0|USk1k7Ur@|Ur3j;J4nV1O`rmt-%BHqb{Tu8ujjKte zhRcJHfO7WoNFxzDZRJD<&^ z<=|OVv~ioakFgh?x$lTgjG4R7bTnE189-~jgcfF#ZT@eYOztF zvA=R1yWYJ0fzp_kL*uqi`Zg4(~`HF`>XFrfWDmd zgra*zvVXeO&qWH!WANipMDVF%vwL>%0gm@;1>4q^-?XRJ(<~oixf@e)hnONFHU%YQ zo0EKWA)$Ybl(71s#FrKjE(+x)>-?`2A+(f#aEmg;yH(27oRg+Qk;Z@w=*q9B|H3!{ z&Ch*>wLCaMi#K?YCt&rxj*WKzb1Ie9BtQz}tfs~s(Zl+)o6FtXA=AgGl2^ZXB^!}- zl3-k{SUz8lHtEUWB5$yU1s$WIqhXwKSRLi&U!D{=_`Q zc3K{25?HIMKcd$5j6MWQs)HOYRf+*nRaDGwxl98eiuUz!LO1i8hRip-*S4HI#ylpGxf&Et~M3JfJXi`#Di@eJY(ituQ1^`o%L7 zaTxjIK`|K10_TC;&NP)UT<>z}+tGAH5x`|$WtF7yvEDH=Y^N$8% zDHEwBhPBLqem78BIP8&A6^}<=$5A+&?)G?G+4YU;kug}Wb|CwLNq%joqS@rImCi&W zUrd5)e!7Nr&%@d_(Q(-6=SEHW?x)X>B6U&LPFrD84F{9X&S^jTT^B#UoJ)HAJdL{S zTH6A@;ztK}BrdY73AU&cYk4!@kc_Wq9%sM(qpeuj7h6)NkT2e6iwmJy;q~lfVVrwp zSbT4vLb$qv!wU9Z{mTVF~=dWp%)<6B3DZrSM1fY3wC?qjBHBN6_c@sm-4gc-trS)-M^4m+J_ z<-f$f6`XPq;gDtxN&GQ)*nEhg%eZHrqK^PljmnweOHRX`yE1BbN}o6HkC`)q1KZ44 zKu=v>o|MCRM3htTbX=X@?;$6PA}V)ba}2C=aF<-I#8O;6=ay}A++jp@lzx_Zz1|HO z#8MYO^lp%oLld$2Azz)!zrujx*3Eky1kXazRW+IYLML+(;&h*1E%Y3Zga0inL zQq!9G;6o}*q}`Usu8A#D>g8HBhZSrtKefZ)A%wwZj5fN8#fcjIL}bA?b>ZvHmA8!s z!BHObc7~K8orQ77v3#!~&(B=(Jnm4i3$OjLoZ-%x@kTQC8xwh10MMwISWnrD^GlsL;dSgld^3uSYM99vaD)s&Y^Kod_r)~MEj}jWppS3Pt;tH;oZQM;D=Vh&NM(zqse02Ded$gOLEj}_$RoQ8Z z+Zz+p+Hk8Y<;8jV8UksF;F~U|*b=w%$WTRXT4I(%d@A){QaptpB&3|O-_fX4&IsPF z>zl3YgGP&>iw>i@JVyf@0FD2JuZ=PPi?M{zc*g+ZyeRq$uXKVlM23(b1%9Aq@;h^E zrIoIq?-77ld%Oruf{aAlTb7Nw>fDb^%QsXHiJ(?R_I!|Fq+`-Hcdaozez7Q*c^8&p zJ^5YJMpz`N{u#AsJ`EsRYX+SwLsX1ru*w`{-N6(@*m!a-DrTDNh-n5~VD8es=c0qh zmm!Fsx~D9WsG)!q4@qSna8xupjpw>0)$@VoLk#vzx@~vdb3L)(%v*1qOB;mK;c1ny z0j0xl7ILJRtRr00OX=u1W1e*`3Pw&J`ZCDkW%4WGhBju(Eeb8WUlqB|r2owDUruk< zswfYI02HSe?U&EgI})5(KY+u;c9jge=vyKu%?9LquMih_3L?t0G!q-X{E(CUpTmjyJ(${%CQ@A4U>HN}NG(adXZ zqs$+qq@MZonLo;{Pu53V0arJC!&k#1YRRksW0ksl-2VLAI(X-tVNI}b!mmOo_Z2IE zoe4sTx0ehxoZnA%V927V=Z$bk@VJj`BCe>M;s&_0gLdvtOjmsHA!>Xp$Cfq)Y{4J{ z-8Y_m6ZIQ2b-0-l^rc3#_DX7G8&;U0CA(PZ&@ln=lby>*K{k*GRh z8E+ZpJ?}LdfTt7!iDy@o{;doDN05;zG>9c{)fGx1vrzb>y_IuBY)(4tmW=5Zo9c_t zAR%ptjKJr|MPEseb#BH_u&aN>FK4(PS06JFS9vMY^Il)cyeqgb&Kb66^R6Ycv96Vz z4u&(Lp?-Ox{XL|1;!!M~@u!C*#WKwHQ>9@A{6!DU`*9!m_R}P%{Dw`}+#u;Qi-Ygg zgSph+GQVe4x$RKdP1*MmWx=9{iU#%a=2Q20fnA#;Our=-)ehJ#Y1Mrg&v~27qIm)D z?2i%`>|c|L9fK^W`x>^FT+$cfKbVD1P zXRbK>2I_3QaiSmm0dDfT@CoUlizJ0b>cf-({Go8+_;kP%kRni5}h|@T0jX|F9ANzkwtyWnVq?ARy;2J@~(>Em`t)CRz3GW#q3w z^K)D+%xIo+Z0 z=E~cVY#IA6X&2o?Ho|jl|Kbzg)zK#Tqke8wuO0srmw&$SrToTg-&3g)Aw*`4=)3>n zw|k;W`Ia)|Dy0A)`KZ8lRW|VpH~eT$Nx-L_R;1qCt>Ht@f$t5Az>ONWm@E0)1s1{k zqnmppdhRRU++u(IKr;V>Wn!hw^M|*8>l@FqJwTY)gcD^zv><|A?N$BXuFO(Ll?T)$ zznkpM@=<_{l0j#e&?}NHk0i|%Zat%u^vKnWzj|rr=5kuceP#Tj^4oDJVy2m}*%Z<7 z5cKyw=c4RGLJu?pyzl>ZT6#+JQKk4&X|U2mS`Zd zprZGf4cd)A{iN!B?#y4`^-+jy1}v5?5tHmNTYuZRCIQi&dA)b} z?;rU+zC&pCECGMi4AS7s@1zi4YzSqD>BH*(A1=*fe!xR#lYjN@Z-3AduxgZkgI)0FI*ksmYrEdvpJd?0?@s0$hbxseZc%fk71T-KZUd z!ryJA|F6&f^*Xc>a8ku;D*opJ^#JTv&pt!oKic-+e~*uR1F)?I+bgL5{rCP}nIav) z;j^OKR?omG)p}p1S7F5`R}rJ=*KRQ{`=D}5zWc*P zJI2ir{kXqxmnC^)cAa+d0SxzPNq-qk3qt38D*t^6-|Ygq1hSi8;Tgto!z06`@_B~u zq|?mjmx43fa~(6(yg`F6ov{Lc{(<1skWJoTxvgXMFNUOJb;*O7YadU(FV3`vQv6bM zQ)EclJPX`zqjn|VTzUWTWPg|5Xy=$a^sY$eH;IZ)R%J^dc$-d11a9qgnrKx&wm~A& zgcJ*vhHqp^{GXn}Y>Nu@fBj)MPyg|UH5rI`$1q)x>4a_)4`=-rdJ?z3eemICS!JXA z$ouVeKqU1*Diq#;+2olj>A-rDxvq{=7I~kpj=xK;*C7wCIk|sr=r+9d6kCS+s*`%- zfB|^V@a5)Q6z?Ydpeh^x5l1%s3&0{DlZB)VNcUWVA39_QFLx(!n{N%mo0<)lwgP7f zSs8(w4czEceD+0CC^Vy2|(Bv8Da3R6JOL`?C>u5LRw2~DV;1YY7T0`2+KAmRZy77hjblPj6!P0N0rda!m1X13wFV#Ws)_0{~ueTLD zu#%0~%z_^~)t!N)DPmOAIht& z<@m`?lS*BkAoTJhRrV7)4Z2mt{5fMcggeT)A);%aPGpw)c`AJZy-=()%Tsl(i~r&q9LY*P7v>