Merge branch 'dev'

This commit is contained in:
Michael F. Schönitzer 2020-05-26 23:37:46 +02:00
commit 96b139253d
61 changed files with 18474 additions and 2176 deletions

2
.gitignore vendored
View File

@ -2,6 +2,7 @@
# This section is devoted to this project
##############################
doc/tags
.tags
# Vim stuff
##############################
@ -20,3 +21,4 @@ Session.vim
.Trashes
ehthumbs.db
Thumbs.db
vimtest

27
.travis.yml Normal file
View File

@ -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

View File

@ -1,3 +1,5 @@
# Contributing to Vimwiki
# Filing a bug
Before filing a bug or starting to write a patch, check the latest development version from
@ -15,7 +17,14 @@ Make sure to update `doc/vimwiki.txt` with the following information:
1. Update the changelog to include information on the new feature the PR introduces or the bug it
is fixing.
2. Add a help section to describe any new features or options.
2. If you are a first time contributor add your name to the list of contributors.
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
@ -30,17 +39,17 @@ Make sure to update `doc/vimwiki.txt` with the following information:
## Git branching model
- there are two branches with eternal lifetime:
- `dev`: This is where the main development happens. Tasks which are done in one or only a few
commits go here directly. Always try to keep this branch in a working state, that is, if the
task you work on requires multiple commits, make sure intermediate commits don't make Vimwiki
unusable (or at least push these commits at one go).
- `master`: This branch is for released states only. Whenever a reasonable set of changes has
piled up in the `dev` branch, a [release is done](#Preparing a release). After a release,
`dev` has been merged into `master` and `master` got exactly one additional commit in which
the version number in `plugin/vimwiki.vim` is updated. Apart from these commits and the merge
commit from `dev`, nothing happens on `master`. Never should `master` merge into `dev`. When
the users ask, we should recommend this branch for them to use.
- 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.
@ -55,9 +64,9 @@ Make sure to update `doc/vimwiki.txt` with the following information:
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.
10. In GitHub, go to _Releases_ -> _Draft a new release_ -> choose the tag, convert the changelog
from the doc to markdown and post it there. Make plans to build an automatic converter and
immediately forget this plan.
11. Tell the world.
%% vim:tw=99
<!-- vim:tw=99 -->

186
DesignNotes.md Normal file
View File

@ -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 = "\<ESC>o".s:create_empty_row(a:cols)
let cmd .= "\<ESC>:call vimwiki#tbl#format(line('.'))\<CR>"
let cmd .= "\<ESC>0"
if a:goto_first
let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'c', line('.'))\<CR>"
else
let cmd .= (col('.')-1)."l"
let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\<CR>"
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 `\<ESC>`, `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.

23
Dockerfile Normal file
View File

@ -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 \

139
README.md
View File

@ -1,8 +1,9 @@
# VimWiki: A Personal Wiki For Vim
![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)
@ -19,31 +20,36 @@
- [Wiki](https://github.com/vimwiki/vimwiki/wiki)
- [License](#license)
## Intro
----
## Introduction
VimWiki is a personal wiki for Vim -- a number of linked text files that have
their own syntax highlighting.
their own syntax highlighting. See the [VimWiki Wiki](https://vimwiki.github.io/vimwikiwiki/)
for an example website built with VimWiki!
With VimWiki you can:
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).
* Organize notes and ideas
* Manage to-do lists
* Write documentation
* Maintain a diary
* Export everything to HTML
With VimWiki, you can:
To do a quick start press `<Leader>ww` (this is usually `\ww`) to go to your
index wiki file. By default it is located in `~/vimwiki/index.wiki`.
- Organize notes and ideas
- Manage to-do lists
- Write documentation
- Maintain a diary
- Export everything to HTML
To do a quick start, press `<Leader>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,
@ -52,16 +58,14 @@ 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`.
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
@ -73,20 +77,20 @@ The result should look something like:
## 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.
Without them, VimWiki will not work properly.
#### Installation using [Vim packages](http://vimhelp.appspot.com/repeat.txt.html#packages) (since Vim 7.4.1528)
@ -94,9 +98,17 @@ Without them VimWiki will not work properly.
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
```
#### Installation using [Pathogen](http://www.vim.org/scripts/script.php?script_id=2332)
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
@ -121,7 +133,7 @@ Then run `:PlugInstall`.
#### Installation using [Vundle](https://github.com/VundleVim/Vundle.vim)
Add `Plugin 'vimwiki/vimwiki'` to your vimrc file and run
Add `Plugin 'vimwiki/vimwiki'` to your vimrc file and run:
```sh
@ -129,16 +141,17 @@ vim +PluginInstall +qall
```
Or download the [zip
archive](https://github.com/vimwiki/vimwiki/archive/master.zip) and extract it
in `~/.vim/bundle/`
#### 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 ===
@ -151,9 +164,9 @@ _italic_ -- italic text
[[wiki link|description]] -- wiki link with description
```
### Lists:
### Lists
```
```text
* bullet list item 1
- bullet list item 2
- bullet list item 3
@ -174,36 +187,49 @@ For other syntax elements, see `:h vimwiki-syntax`
## Key bindings
Normal mode:
### Normal mode
* `<Leader>ww` -- Open default wiki index file.
* `<Leader>wt` -- Open default wiki index file in a new tab.
* `<Leader>ws` -- Select and open wiki index file.
* `<Leader>wd` -- Delete wiki file you are in.
* `<Leader>wr` -- Rename wiki file you are in.
* `<Enter>` -- Follow/Create wiki link
* `<Shift-Enter>` -- Split and follow/create wiki link
* `<Ctrl-Enter>` -- Vertical split and follow/create wiki link
* `<Backspace>` -- Go back to parent(previous) wiki link
* `<Tab>` -- Find next wiki link
* `<Shift-Tab>` -- Find previous wiki link
**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.
For more keys, see `:h vimwiki-mappings`
#### Basic key bindings
- `<Leader>ww` -- Open default wiki index file.
- `<Leader>wt` -- Open default wiki index file in a new tab.
- `<Leader>ws` -- Select and open wiki index file.
- `<Leader>wd` -- Delete wiki file you are in.
- `<Leader>wr` -- Rename wiki file you are in.
- `<Enter>` -- Follow/Create wiki link.
- `<Shift-Enter>` -- Split and follow/create wiki link.
- `<Ctrl-Enter>` -- Vertical split and follow/create wiki link.
- `<Backspace>` -- Go back to parent(previous) wiki link.
- `<Tab>` -- Find next wiki link.
- `<Shift-Tab>` -- 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
- `: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)
(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:
following option in your `.vimrc`:
```vim
@ -214,15 +240,22 @@ let g:vimwiki_list = [{'path': '~/vimwiki/',
## Getting help
**Have a question?**
Visit the IRC channel [`#vimwiki`](https://webchat.freenode.net/?channels=#vimwiki) on Freenode ([webchat](https://webchat.freenode.net/?channels=#vimwiki), also synced to Matrix/Riot: `#vimwiki:matrix.org`) or post to the [mailing list](https://groups.google.com/forum/#!forum/vimwiki).
[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.
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

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
#
# This script converts markdown into html, to be used with vimwiki's
# "customwiki2html" option. Experiment with the two proposed methods by
# "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
@ -46,7 +46,7 @@ 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

View File

@ -4,6 +4,7 @@
<link rel="Stylesheet" type="text/css" href="%root_path%%css%">
<title>%title%</title>
<meta http-equiv="Content-Type" content="text/html; charset=%encoding%">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
%content%

View File

@ -4,16 +4,13 @@
" Home: https://github.com/vimwiki/vimwiki/
if exists("g:loaded_vimwiki_diary_auto") || &cp
if exists('g:loaded_vimwiki_diary_auto') || &compatible
finish
endif
let g:loaded_vimwiki_diary_auto = 1
let s:vimwiki_max_scan_for_caption = 5
function! s:prefix_zero(num)
function! s:prefix_zero(num) abort
if a:num < 10
return '0'.a:num
endif
@ -21,20 +18,20 @@ function! s:prefix_zero(num)
endfunction
function! s:diary_path(...)
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(...)
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(...)
function! vimwiki#diary#diary_date_link(...) abort
if a:0
return strftime('%Y-%m-%d', a:1)
else
@ -43,11 +40,11 @@ function! vimwiki#diary#diary_date_link(...)
endfunction
function! s:get_position_links(link)
function! s:get_position_links(link) abort
let idx = -1
let links = []
if a:link =~# '^\d\{4}-\d\d-\d\d'
let links = map(s:get_diary_files(), 'fnamemodify(v:val, ":t:r")')
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())
@ -59,36 +56,108 @@ function! s:get_position_links(link)
endfunction
function! s:get_month_name(month)
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')
function! s:read_captions(files)
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 rx_header = vimwiki#vars#get_syntaxlocal('rxHeader')
let caption_level = vimwiki#vars#get_wikilocal('diary_caption_level')
for fl in a:files
" remove paths and extensions
let fl_key = substitute(fnamemodify(fl, ':t'), vimwiki#vars#get_wikilocal('ext').'$', '', '')
let fl_captions = {}
if filereadable(fl)
for line in readfile(fl, '', s:vimwiki_max_scan_for_caption)
if line =~# rx_header && !has_key(result, fl_key)
let result[fl_key] = vimwiki#u#trim(matchstr(line, rx_header))
" 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
endfor
endif
if !has_key(result, fl_key)
let result[fl_key] = ''
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! s:get_diary_files()
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'))
@ -102,7 +171,7 @@ function! s:get_diary_files()
endfunction
function! s:group_links(links)
function! s:group_links(links) abort
let result = {}
let p_year = 0
let p_month = 0
@ -124,7 +193,7 @@ function! s:group_links(links)
endfunction
function! s:sort(lst)
function! s:sort(lst) abort
if vimwiki#vars#get_wikilocal('diary_sort') ==? 'desc'
return reverse(sort(a:lst))
else
@ -132,52 +201,10 @@ function! s:sort(lst)
endif
endfunction
function! s:format_diary()
let result = []
let links_with_captions = s:read_captions(s:get_diary_files())
let g_files = s:group_links(links_with_captions)
for year in s:sort(keys(g_files))
call add(result, '')
call add(result,
\ substitute(vimwiki#vars#get_syntaxlocal('rxH2_Template'), '__Header__', year , ''))
for month in s:sort(keys(g_files[year]))
call add(result, '')
call add(result, substitute(vimwiki#vars#get_syntaxlocal('rxH3_Template'),
\ '__Header__', s:get_month_name(month), ''))
for [fl, cap] in s:sort(items(g_files[year][month]))
let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate2')
if vimwiki#vars#get_wikilocal('syntax') == 'markdown'
let link_tpl = vimwiki#vars#get_syntaxlocal('Weblink1Template')
if empty(cap) " When using markdown syntax, we should ensure we always have a link description.
let cap = fl
endif
elseif empty(cap)
let link_tpl = vimwiki#vars#get_global('WikiLinkTemplate1')
endif
let entry = substitute(link_tpl, '__LinkUrl__', fl, '')
let entry = substitute(entry, '__LinkDescription__', cap, '')
call add(result, repeat(' ', vimwiki#lst#get_list_margin()).'* '.entry)
endfor
endfor
endfor
return result
endfunction
" The given wiki number a:wnum is 1 for the first wiki, 2 for the second and so on. This is in
" contrast to most other places, where counting starts with 0. When a:wnum is 0, the current wiki
" is used.
function! vimwiki#diary#make_note(wnum, ...)
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
@ -192,8 +219,6 @@ function! vimwiki#diary#make_note(wnum, ...)
return
endif
" TODO: refactor it. base#goto_index uses the same
call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('path', wiki_nr).
\ vimwiki#vars#get_wikilocal('diary_rel_path', wiki_nr))
@ -216,20 +241,23 @@ function! vimwiki#diary#make_note(wnum, ...)
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
function! vimwiki#diary#goto_diary_index(wnum)
if a:wnum > vimwiki#vars#number_of_wikis()
echomsg 'Vimwiki Error: Wiki '.a:wnum.' is not registered in g:vimwiki_list!'
return
endif
" TODO: refactor it. base#goto_index uses the same
if a:wnum > 0
let idx = a:wnum - 1
else
let idx = 0
endif
call vimwiki#base#edit_file('e', s:diary_index(idx), '')
if vimwiki#vars#get_wikilocal('auto_diary_index')
@ -239,7 +267,7 @@ function! vimwiki#diary#goto_diary_index(wnum)
endfunction
function! vimwiki#diary#goto_next_day()
function! vimwiki#diary#goto_next_day() abort
let link = ''
let [idx, links] = s:get_position_links(expand('%:t:r'))
@ -260,7 +288,7 @@ function! vimwiki#diary#goto_next_day()
endfunction
function! vimwiki#diary#goto_prev_day()
function! vimwiki#diary#goto_prev_day() abort
let link = ''
let [idx, links] = s:get_position_links(expand('%:t:r'))
@ -281,13 +309,95 @@ function! vimwiki#diary#goto_prev_day()
endfunction
function! vimwiki#diary#generate_diary_section()
let current_file = vimwiki#path#path_norm(expand("%:p"))
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 = '^\%(\s*\* \)\|\%(^\s*$\)\|\%('.vimwiki#vars#get_syntaxlocal('rxHeader').'\)'
call vimwiki#base#update_listing_in_buffer(s:format_diary(),
\ vimwiki#vars#get_wikilocal('diary_header'), content_rx, line('$')+1, 1)
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
@ -295,7 +405,7 @@ endfunction
" Callback function for Calendar.vim
function! vimwiki#diary#calendar_action(day, month, year, week, dir)
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)
@ -317,11 +427,10 @@ function! vimwiki#diary#calendar_action(day, month, year, week, dir)
endfunction
function vimwiki#diary#calendar_sign(day, month, year)
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

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
" Home: https://github.com/vimwiki/vimwiki/
if exists("g:loaded_vimwiki_list_auto") || &cp
if exists('g:loaded_vimwiki_list_auto') || &compatible
finish
endif
let g:loaded_vimwiki_list_auto = 1
@ -14,12 +14,12 @@ let g:loaded_vimwiki_list_auto = 1
" incrementation functions for the various kinds of numbers
" ---------------------------------------------------------
function! s:increment_1(value)
function! s:increment_1(value) abort
return eval(a:value) + 1
endfunction
function! s:increment_A(value)
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)))
@ -39,7 +39,7 @@ function! s:increment_A(value)
endfunction
function! s:increment_a(value)
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)))
@ -59,7 +59,7 @@ function! s:increment_a(value)
endfunction
function! s:increment_I(value)
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'],
@ -74,7 +74,7 @@ function! s:increment_I(value)
endfunction
function! s:increment_i(value)
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'],
@ -93,41 +93,41 @@ endfunction
" utility functions
" ---------------------------------------------------------
function! s:substitute_rx_in_line(lnum, pattern, new_string)
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)
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)
function! s:first_char(string) abort
return matchstr(a:string, '^.')
endfunction
if exists("*strdisplaywidth")
function! s:string_length(str)
if exists('*strdisplaywidth')
function! s:string_length(str) abort
return strdisplaywidth(a:str)
endfunction
else
function! s:string_length(str)
function! s:string_length(str) abort
return strlen(substitute(a:str, '.', 'x', 'g'))
endfunction
endif
function! vimwiki#lst#default_symbol()
function! vimwiki#lst#default_symbol() abort
return vimwiki#vars#get_syntaxlocal('list_markers')[0]
endfunction
function! vimwiki#lst#get_list_margin()
function! vimwiki#lst#get_list_margin() abort
let list_margin = vimwiki#vars#get_wikilocal('list_margin')
if list_margin < 0
return &sw
return &shiftwidth
else
return list_margin
endif
@ -136,7 +136,7 @@ endfunction
"Returns: the column where the text of a line starts (possible list item
"markers and checkboxes are skipped)
function! s:text_begin(lnum)
function! s:text_begin(lnum) abort
return s:string_length(matchstr(getline(a:lnum), vimwiki#vars#get_syntaxlocal('rxListItem')))
endfunction
@ -144,7 +144,7 @@ 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)
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'
@ -165,7 +165,7 @@ endfunction
"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)
function! s:get_item(lnum) abort
let item = {'lnum': a:lnum}
if a:lnum == 0 || a:lnum > line('$')
let item.type = 0
@ -174,15 +174,15 @@ function! s:get_item(lnum)
let matches = matchlist(getline(a:lnum), vimwiki#vars#get_syntaxlocal('rxListItem'))
if matches == [] ||
\ (matches[1] == '' && matches[2] == '') ||
\ (matches[1] != '' && matches[2] != '')
\ (matches[1] ==? '' && matches[2] ==? '') ||
\ (matches[1] !=? '' && matches[2] !=? '')
let item.type = 0
return item
endif
let item.cb = matches[3]
if matches[1] != ''
if matches[1] !=? ''
let item.type = 1
let item.mrkr = matches[1]
else
@ -194,14 +194,14 @@ function! s:get_item(lnum)
endfunction
function! s:empty_item()
function! s:empty_item() abort
return {'type': 0}
endfunction
"Returns: level of the line
"0 is the 'highest' level
function! s:get_level(lnum)
function! s:get_level(lnum) abort
if getline(a:lnum) =~# '^\s*$'
return 0
endif
@ -209,7 +209,7 @@ function! s:get_level(lnum)
let level = indent(a:lnum)
else
let level = s:string_length(matchstr(getline(a:lnum),
\ vimwiki#vars#get_syntaxlocal(rx_bullet_chars)))-1
\ vimwiki#vars#get_syntaxlocal('rx_bullet_chars')))-1
if level < 0
let level = (indent(a:lnum) == 0) ? 0 : 9999
endif
@ -221,7 +221,7 @@ 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)
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:]
@ -282,14 +282,14 @@ function! s:guess_kind_of_numbered_item(item)
endfunction
function! s:regexp_of_marker(item)
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 != ''
if match !=? ''
return '\'.ki.'\+'.vimwiki#u#escape(match[-1:])
endif
endfor
@ -300,7 +300,7 @@ endfunction
" Returns: Whether or not the checkbox of a list item is [X] or [-]
function! s:is_closed(item)
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')
@ -312,7 +312,7 @@ endfunction
"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)
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)
@ -336,7 +336,7 @@ 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)
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)
@ -358,7 +358,7 @@ function! s:get_prev_list_item(item, ignore_kind)
endfunction
function! s:get_item_of_level(cur_ln, cur_lvl, org_lvl, org_regex)
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'
@ -372,7 +372,7 @@ function! s:get_item_of_level(cur_ln, cur_lvl, org_lvl, org_regex)
endfunction
function! s:get_any_item_of_level(cur_ln, cur_lvl, org_lvl)
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
@ -381,7 +381,7 @@ function! s:get_any_item_of_level(cur_ln, cur_lvl, org_lvl)
endfunction
function! s:get_first_item_in_list(item, ignore_kind)
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)
@ -395,7 +395,7 @@ function! s:get_first_item_in_list(item, ignore_kind)
endfunction
function! s:get_last_item_in_list(item, ignore_kind)
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)
@ -413,17 +413,19 @@ endfunction
"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, ...)
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
let next_line = cur_ln + 1
else
let next_line = nextnonblank(a:lnum+1)
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
@ -439,20 +441,20 @@ 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)
let prev_line = prevnonblank(a:lnum-1)
function! s:get_prev_line(lnum) abort
let cur_ln = a:lnum - 1
if getline(prev_line) =~# vimwiki#vars#get_syntaxlocal('rxPreEnd')
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
let prev_line = cur_ln
endif
let prev_line = prevnonblank(cur_ln)
if prev_line < 0 || prev_line > line('$') ||
\ getline(prev_line) =~# vimwiki#vars#get_syntaxlocal('rxHeader')
return 0
@ -462,7 +464,7 @@ function! s:get_prev_line(lnum)
endfunction
function! s:get_first_child(item)
function! s:get_first_child(item) abort
if a:item.lnum >= line('$')
return s:empty_item()
endif
@ -483,7 +485,7 @@ 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)
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)
@ -502,7 +504,7 @@ function! s:get_next_child_item(parent, child)
endfunction
function! s:get_parent(item)
function! s:get_parent(item) abort
let parent_line = 0
let cur_ln = prevnonblank(a:item.lnum)
@ -530,7 +532,7 @@ endfunction
"Returns: the item above or the item below or an empty item
function! s:get_a_neighbor_item(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
@ -544,7 +546,7 @@ function! s:get_a_neighbor_item(item)
endfunction
function! s:get_a_neighbor_item_in_column(lnum, column)
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
@ -558,7 +560,7 @@ 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)
function! s:get_corresponding_item(lnum) abort
let item = s:get_item(a:lnum)
if item.type != 0
return item
@ -581,7 +583,7 @@ endfunction
"Returns: the last line of a (possibly multiline) item, including all children
function! s:get_last_line_of_item_incl_children(item)
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
@ -596,7 +598,7 @@ 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)
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