diff --git a/autoload/vimwiki/base.vim b/autoload/vimwiki/base.vim index ad99ba8..c081b96 100644 --- a/autoload/vimwiki/base.vim +++ b/autoload/vimwiki/base.vim @@ -441,7 +441,7 @@ function! vimwiki#base#system_open_link(url) "{{{ execute '!open ' . shellescape(a:url, 1) endfunction function! s:linux_handler(url) - execute 'silent !xdg-open ' . shellescape(a:url, 1) + call system('xdg-open ' . shellescape(a:url, 1).' &') endfunction let success = 0 try @@ -549,7 +549,7 @@ endfunction "}}} function! vimwiki#base#backlinks() "{{{ execute 'lvimgrep "\%(^\|[[:blank:][:punct:]]\)'. \ expand("%:t:r"). - \ '\([[:blank:][:punct:]]\|$\)" '. + \ '\([[:blank:][:punct:]]\|$\)\C" '. \ escape(VimwikiGet('path').'**/*'.VimwikiGet('ext'), ' ') endfunction "}}} @@ -639,7 +639,7 @@ function! vimwiki#base#edit_file(command, filename, ...) "{{{ " then " [[test*file]]... " you'll have E77: Too many file names - let fname = escape(a:filename, '% *|') + let fname = escape(a:filename, '% *|#') let dir = fnamemodify(a:filename, ":p:h") if vimwiki#base#mkdir(dir, 1) execute a:command.' '.fname diff --git a/autoload/vimwiki/html.vim b/autoload/vimwiki/html.vim index 4b5aac7..b4a2d36 100644 --- a/autoload/vimwiki/html.vim +++ b/autoload/vimwiki/html.vim @@ -4,7 +4,15 @@ " Author: Maxim Kim " Home: http://code.google.com/p/vimwiki/ -" XXX: This file should be refactored! +" TODO: We need vimwiki abstract syntax tree. If properly designed it wourld +" greatly symplify different syntax to HTML generation. +" +" vimwiki -- --> PDF +" \ / +" markdown -----> AST -----> HTML +" / \ +" mediawiki -- --> Latex +" " Load only once {{{ if exists("g:loaded_vimwiki_html_auto") || &cp @@ -137,22 +145,12 @@ endfunction "}}} function! s:safe_html(line) "{{{ " escape & < > when producing HTML text - " uses variables s:lt_pattern, s:gt_pattern that are - " set in vimwiki#html#Wiki2HTML() according to g:vimwiki_valid_html_tags - "" htmlize symbols: < > & - + " 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') - " the following depends on g:vimwiki_valid_html_tags let line = substitute(line,s:lt_pattern,'\<', 'g') let line = substitute(line,s:gt_pattern,'\>', 'g') - "let tags = join(split(g:vimwiki_valid_html_tags, '\s*,\s*'), '\|') - "let line = substitute(line,'<\%(/\?\%(' - " \.tags.'\)\%(\s\{-1}\S\{-}\)\{-}/\?>\)\@!', - " \'\<', 'g') - "let line = substitute(line,'\%(', - " \'\>', 'g') return line endfunction "}}} @@ -456,11 +454,10 @@ function! s:tag_wikilink(value) "{{{ if g:vimwiki_debug > 1 echom '[[idx='.idx.', scheme='.scheme.', path='.path.', subdir='.subdir.', lnk='.lnk.', ext='.ext.']]' endif - let url = escape(url, '#') let line = vimwiki#html#linkify_link(url, descr) return line endfunction "}}} -"}}} v1.3 links +"}}} function! s:tag_remove_internal_link(value) "{{{ @@ -1352,13 +1349,17 @@ endfunction " }}} function! vimwiki#html#CustomWiki2HTML(path, wikifile, force) "{{{ call vimwiki#base#mkdir(a:path) - execute '!'.VimwikiGet('custom_wiki2html'). ' ' + echomsg system(VimwikiGet('custom_wiki2html'). ' '. \ a:force. ' '. \ VimwikiGet('syntax'). ' '. \ strpart(VimwikiGet('ext'), 1). ' '. - \ a:path. ' '. - \ a:wikifile. ' '. - \ s:default_CSS_full_name(a:path) + \ shellescape(a:path, 1). ' '. + \ shellescape(a:wikifile, 1). ' '. + \ shellescape(s:default_CSS_full_name(a:path), 1). ' '. + \ (len(VimwikiGet('template_path')) > 1 ? shellescape(expand(VimwikiGet('template_path')), 1) : '-'). ' '. + \ (len(VimwikiGet('template_default')) > 0 ? VimwikiGet('template_default') : '-'). ' '. + \ (len(VimwikiGet('template_ext')) > 0 ? VimwikiGet('template_ext') : '-'). ' '. + \ (len(VimwikiGet('subdir')) > 0 ? shellescape(s:root_path(VimwikiGet('subdir')), 1) : '-')) endfunction " }}} function! vimwiki#html#Wiki2HTML(path_html, wikifile) "{{{ @@ -1415,8 +1416,8 @@ function! vimwiki#html#Wiki2HTML(path_html, wikifile) "{{{ let s:gt_pattern = '>' if g:vimwiki_valid_html_tags != '' let tags = join(split(g:vimwiki_valid_html_tags, '\s*,\s*'), '\|') - let s:lt_pattern = '<\%(/\?\%('.tags.'\)\%(\s\{-1}\S\{-}\)\{-}/\?>\)\@!' - let s:gt_pattern = '\%(' + let s:lt_pattern = '\c<\%(/\?\%('.tags.'\)\%(\s\{-1}\S\{-}\)\{-}/\?>\)\@!' + let s:gt_pattern = '\c\%(' endif for line in lsource @@ -1566,7 +1567,7 @@ function! vimwiki#html#WikiAll2HTML(path_html) "{{{ endfunction "}}} function! s:file_exists(fname) "{{{ - return !empty(getftype(a:fname)) + return !empty(getftype(expand(a:fname))) endfunction "}}} " uses VimwikiGet('path') diff --git a/autoload/vimwiki/tbl.vim b/autoload/vimwiki/tbl.vim index 67a0f8f..3a8991d 100644 --- a/autoload/vimwiki/tbl.vim +++ b/autoload/vimwiki/tbl.vim @@ -16,10 +16,13 @@ let g:loaded_vimwiki_tbl_auto = 1 "}}} let s:textwidth = &tw -let s:rxSep = g:vimwiki_rxTableSep " Misc functions {{{ +function! s:rxSep() "{{{ + return g:vimwiki_rxTableSep +endfunction "}}} + function! s:wide_len(str) "{{{ " vim73 has new function that gives correct string width. if exists("*strdisplaywidth") @@ -43,36 +46,36 @@ function! s:wide_len(str) "{{{ endfunction "}}} function! s:cell_splitter() "{{{ - return '\s*'.s:rxSep.'\s*' + return '\s*'.s:rxSep().'\s*' endfunction "}}} function! s:sep_splitter() "{{{ - return '-'.s:rxSep.'-' + return '-'.s:rxSep().'-' endfunction "}}} function! s:is_table(line) "{{{ - return s:is_separator(a:line) || (a:line !~ s:rxSep.s:rxSep && a:line =~ '^\s*'.s:rxSep.'.\+'.s:rxSep.'\s*$') + 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) "{{{ - return a:line =~ '^\s*'.s:rxSep.'\(--\+'.s:rxSep.'\)\+\s*$' + return a:line =~ '^\s*'.s:rxSep().'\(--\+'.s:rxSep().'\)\+\s*$' endfunction "}}} function! s:is_separator_tail(line) "{{{ - return a:line =~ '^\{-1}\%(\s*\|-*\)\%('.s:rxSep.'-\+\)\+'.s:rxSep.'\s*$' + return a:line =~ '^\{-1}\%(\s*\|-*\)\%('.s:rxSep().'-\+\)\+'.s:rxSep().'\s*$' endfunction "}}} function! s:is_last_column(lnum, cnum) "{{{ let line = strpart(getline(a:lnum), a:cnum - 1) - "echomsg "DEBUG is_last_column> ".(line =~ s:rxSep.'\s*$' && line !~ s:rxSep.'.*'.s:rxSep.'\s*$') - return line =~ s:rxSep.'\s*$' && line !~ s:rxSep.'.*'.s:rxSep.'\s*$' + "echomsg "DEBUG is_last_column> ".(line =~ s:rxSep().'\s*$' && line !~ s:rxSep().'.*'.s:rxSep().'\s*$') + return line =~ s:rxSep().'\s*$' && line !~ s:rxSep().'.*'.s:rxSep().'\s*$' endfunction "}}} function! s:is_first_column(lnum, cnum) "{{{ let line = strpart(getline(a:lnum), 0, a:cnum - 1) - "echomsg "DEBUG is_first_column> ".(line =~ '^\s*'.s:rxSep && line !~ '^\s*'.s:rxSep.'.*'.s:rxSep) - return line =~ '^\s*$' || (line =~ '^\s*'.s:rxSep && line !~ '^\s*'.s:rxSep.'.*'.s:rxSep) + "echomsg "DEBUG is_first_column> ".(line =~ '^\s*'.s:rxSep() && line !~ '^\s*'.s:rxSep().'.*'.s:rxSep()) + return line =~ '^\s*$' || (line =~ '^\s*'.s:rxSep() && line !~ '^\s*'.s:rxSep().'.*'.s:rxSep()) endfunction "}}} function! s:count_separators_up(lnum) "{{{ @@ -100,8 +103,8 @@ function! s:count_separators_down(lnum) "{{{ endfunction "}}} function! s:create_empty_row(cols) "{{{ - let row = s:rxSep - let cell = " ".s:rxSep + let row = s:rxSep() + let cell = " ".s:rxSep() for c in range(a:cols) let row .= cell @@ -111,8 +114,8 @@ function! s:create_empty_row(cols) "{{{ endfunction "}}} function! s:create_row_sep(cols) "{{{ - let row = s:rxSep - let cell = "---".s:rxSep + let row = s:rxSep() + let cell = "---".s:rxSep() for c in range(a:cols) let row .= cell @@ -274,10 +277,10 @@ function! s:cur_column() "{{{ " TODO: do we need conditional: if s:is_separator(line) let curs_pos = col('.') - let mpos = match(line, s:rxSep, 0) + let mpos = match(line, s:rxSep(), 0) let col = -1 while mpos < curs_pos && mpos != -1 - let mpos = match(line, s:rxSep, mpos+1) + let mpos = match(line, s:rxSep(), mpos+1) if mpos != -1 let col += 1 endif @@ -301,7 +304,7 @@ function! s:fmt_cell(cell, max_len) "{{{ endfunction "}}} function! s:fmt_row(line, max_lens, col1, col2) "{{{ - let new_line = s:rxSep + let new_line = s:rxSep() let cells = vimwiki#tbl#get_cells(a:line) for idx in range(len(cells)) if idx == a:col1 @@ -310,12 +313,12 @@ function! s:fmt_row(line, max_lens, col1, col2) "{{{ let idx = a:col1 endif let value = cells[idx] - let new_line .= s:fmt_cell(value, a:max_lens[idx]).s:rxSep + let new_line .= s:fmt_cell(value, a:max_lens[idx]).s:rxSep() endfor let idx = len(cells) while idx < len(a:max_lens) - let new_line .= s:fmt_cell('', a:max_lens[idx]).s:rxSep + let new_line .= s:fmt_cell('', a:max_lens[idx]).s:rxSep() let idx += 1 endwhile return new_line @@ -330,14 +333,14 @@ function! s:fmt_cell_sep(max_len) "{{{ endfunction "}}} function! s:fmt_sep(max_lens, col1, col2) "{{{ - let new_line = s:rxSep + 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]).s:rxSep + let new_line .= s:fmt_cell_sep(a:max_lens[idx]).s:rxSep() endfor return new_line endfunction "}}} @@ -349,10 +352,10 @@ function! s:kbd_create_new_row(cols, goto_first) "{{{ let cmd .= "\:call vimwiki#tbl#format(line('.'))\" let cmd .= "\0" if a:goto_first - let cmd .= ":call search('\\(".s:rxSep."\\)\\zs', 'c', line('.'))\" + let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'c', line('.'))\" else let cmd .= (col('.')-1)."l" - let cmd .= ":call search('\\(".s:rxSep."\\)\\zs', 'bc', line('.'))\" + let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\" endif let cmd .= "a" @@ -361,16 +364,16 @@ endfunction "}}} function! s:kbd_goto_next_row() "{{{ let cmd = "\j" - let cmd .= ":call search('.\\(".s:rxSep."\\)', 'c', line('.'))\" - let cmd .= ":call search('\\(".s:rxSep."\\)\\zs', 'bc', line('.'))\" + 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() "{{{ let cmd = "\k" - let cmd .= ":call search('.\\(".s:rxSep."\\)', 'c', line('.'))\" - let cmd .= ":call search('\\(".s:rxSep."\\)\\zs', 'bc', line('.'))\" + let cmd .= ":call search('.\\(".s:rxSep()."\\)', 'c', line('.'))\" + let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'bc', line('.'))\" let cmd .= "a" return cmd endfunction "}}} @@ -432,7 +435,7 @@ function! s:kbd_goto_prev_col(jumpup) "{{{ let cmd .= "$" endif let cmd .= ":call vimwiki#tbl#goto_prev_col()\a" - " let cmd .= ":call search('\\(".s:rxSep."\\)\\zs', 'b', line('.'))\" + " let cmd .= ":call search('\\(".s:rxSep()."\\)\\zs', 'b', line('.'))\" " let cmd .= "a" "echomsg "DEBUG kbd_goto_prev_col> ".cmd return cmd @@ -487,6 +490,9 @@ function! vimwiki#tbl#kbd_shift_tab() "{{{ endfunction "}}} function! vimwiki#tbl#format(lnum, ...) "{{{ + if !(&filetype == 'vimwiki') + return + endif let line = getline(a:lnum) if !s:is_table(line) return @@ -554,6 +560,9 @@ function! vimwiki#tbl#align_or_cmd(cmd) "{{{ endfunction "}}} function! vimwiki#tbl#reset_tw(lnum) "{{{ + if !(&filetype == 'vimwiki') + return + endif let line = getline(a:lnum) if !s:is_table(line) return @@ -584,7 +593,7 @@ function! vimwiki#tbl#move_column_left() "{{{ call vimwiki#tbl#format(line('.'), cur_col-1, cur_col) call cursor(line('.'), 1) - let sep = '\('.s:rxSep.'\).\zs' + let sep = '\('.s:rxSep().'\).\zs' let mpos = -1 let col = -1 while col < cur_col-1 @@ -617,7 +626,7 @@ function! vimwiki#tbl#move_column_right() "{{{ call vimwiki#tbl#format(line('.'), cur_col, cur_col+1) call cursor(line('.'), 1) - let sep = '\('.s:rxSep.'\).\zs' + let sep = '\('.s:rxSep().'\).\zs' let mpos = -1 let col = -1 while col < cur_col+1 diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index 849b6be..4ae55d9 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -9,7 +9,7 @@ |___| |___| |_| |_||__| |__||___| |___| |_||___| ~ - Version: 2.0.1 'stu' + Version: 2.1 ============================================================================== CONTENTS *vimwiki-contents* @@ -634,7 +634,7 @@ If the Id is defined elsewhere in the source, as per the Markdown standard: > [Id]: URL then the URL is opened with the system default handler. Otherwise, Vimwiki -treats the reference-sytle link as a Wikilink, interpreting the Id field as a +treats the reference-style link as a Wikilink, interpreting the Id field as a wiki page name. Highlighting of existing links when |vimwiki-option-maxhi| is activated @@ -1042,9 +1042,10 @@ in HTML: > ============================================================================== 6. Folding/Outline *vimwiki-folding* -Vimwiki can fold or outline headers and list items. +Vimwiki can fold or outline sections using headers and preformatted blocks. +Alternatively, one can fold list subitems instead. -Example: +Example for list folding: = My current task = * [ ] Do stuff 1 * [ ] Do substuff 1.1 @@ -1641,13 +1642,24 @@ The following arguments, in this order, are passed to the 4. output_dir : the full path of the output directory, i.e. 'path_html' 5. input_file : the full path of the wiki page 6. css_file : the full path of the css file for this wiki +7. template_path : the full path to the wiki's templates +8. template_default : the default template name +9. template_ext : the extension of template files +10. root_path : a count of ../ for pages buried in subdirs + if you have wikilink [[dir1/dir2/dir3/my page in a subdir]] then + %root_path% is replaced by '../../../'. + +Options 7-10 are experimental and may change in the future. If any of these +parameters is empty, then a hyphen "-" is passed to the script in its place. For an example and further instructions, refer to the following script: $VIMHOME/autoload/vimwiki/customwiki2html.sh -To use the internal wiki2html converter, use an empty string (the default). +An alternative converter was developed by Jason6Anderson, and can +be located at http://code.google.com/p/vimwiki/issues/detail?id=384 +To use the internal wiki2html converter, use an empty string (the default). *vimwiki-option-list_margin* ------------------------------------------------------------------------------ @@ -1736,7 +1748,7 @@ An extension that is registered with vimwiki can trigger creation of a |g:vimwiki_list| are automatically registered with vimwiki using the default syntax. -Default: {'.md': 'markdown'} +Default: {} ------------------------------------------------------------------------------ *g:vimwiki_auto_checkbox* @@ -1796,26 +1808,22 @@ Default: 0 ------------------------------------------------------------------------------ *g:vimwiki_folding* -Enable/disable vimwiki's folding/outline functionality. Folding in vimwiki -uses the 'expr' foldmethod which is very flexible but really slow. +Enable/disable vimwiki's folding (outline) functionality. Folding in vimwiki +can uses either the 'expr' or the 'syntax' |foldmethod| of Vim. Value Description~ -0 Disable folding. -1 Enable folding. +'' Disable folding. +'expr' Folding based on expression (folds sections and code blocks). +'syntax' Folding based on syntax (folds sections; slower than 'expr'). +'list' Folding based on expression (folds list subitems; much slower). -Default: 0 - - ------------------------------------------------------------------------------- -*g:vimwiki_fold_lists* - -Enable/disable folding of list subitems. - -Value Description~ -0 Disable list subitem's folding. -1 Enable list subitem's folding. +Default: '' -Default: 0 +Limitations: + - Opening very large files may be slow when folding is enabled. + - 'list' folding is particularly slow with larger files. + - 'list' is intended to work with lists nicely indented with 'shiftwidth'. + - 'syntax' is only available for the default syntax so far. ------------------------------------------------------------------------------ @@ -2068,7 +2076,7 @@ Default: '' (empty) ------------------------------------------------------------------------------ *g:vimwiki_valid_html_tags* -Comma-separated list of HTML tags that can be used in vimwiki. +Case-insensitive comma separated list of HTML tags that can be used in vimwiki. Default: 'b,i,s,u,sub,sup,kbd,br,hr' @@ -2097,30 +2105,46 @@ a new tab or window, it would be set to default value. Vimwiki sets |conceallevel| to g:vimwiki_conceallevel everytime vimwiki buffer is entered. +With default settings, Vimwiki conceals one-character markers, shortens long +URLs and hides markers and URL for links that have a description. + Default: 2 ------------------------------------------------------------------------------ -*g:vimwiki_url_mingain* +*g:vimwiki_autowriteall* -The minimum number of characters that should be gained by concealing URLs. If -the length of the concealed part of the URL would be less than -|g:vimwiki_url_mingain|, the URL is not concealed at all. -The conceal feature works only with vim >= 7.3. +In vim |autowriteall| is a global setting. With g:vimwiki_autowriteall vimwiki +makes it local to its buffers. -Default: 12 +Value Description~ +0 autowriteall is off +1 autowriteall is on + +Default: 1 ------------------------------------------------------------------------------ *g:vimwiki_url_maxsave* -The maximum number of characters that is retained at the end after concealing -URLs. At most there will be |g:vimwiki_url_maxsave| characters left at the end of the URL. -However, it could be less when one of /,#,? can be found at the end. -In that case the URL will be concealed right before the last occurrence of one -of these characters. -The conceal feature works only with vim >= 7.3. Beware: when using the default -'wrap' option, the effect is not always pleasing. +Setting the value of |g:vimwiki_url_maxsave| to 0 will prevent any link +shortening: you will see the full URL in all types of links, with no parts +being concealed. Concealing of one-character markers is not affected. + +When positive, the value determines the maximum number of characters that +are retained at the end after concealing the middle part of a long URL. +It could be less: in case one of the characters /,#,? is found near the end, +the URL will be concealed up to the last occurrence of that character. + +Note: + * The conceal feature works only with Vim >= 7.3. + * When using the default |wrap| option of Vim, the effect of concealed links + is not always pleasing, because the visible text on longer lines with + a lot of concealed parts may appear to be strangely broken across several + lines. This is a limitation of Vim's |conceal| feature. + * Many color schemes do not define an unobtrusive color for the Conceal + highlight group - this might be quite noticeable on shortened URLs. + Default: 15 @@ -2137,6 +2161,7 @@ Value Description~ Default: 0 + ------------------------------------------------------------------------------ *g:vimwiki_diary_months* @@ -2186,6 +2211,22 @@ Vim plugins: http://www.vim.org/scripts/script.php?script_id=2226 ============================================================================== 14. Changelog *vimwiki-changelog* +2.1~ + + * Concealing of links can be turned off - set |g:vimwiki_url_maxsave| to 0. + The option g:vimwiki_url_mingain was removed + * |g:vimwiki_folding| also accepts value 'list'; with 'expr' both sections + and code blocks folded, g:vimwiki_fold_lists option was removed + * Issue 261: Syntax folding is back. |g:vimwiki_folding| values are + changed to '', 'expr', 'syntax'. + * Issue 372: Ignore case in g:vimwiki_valid_html_tags + * Issue 374: Make autowriteall local to vimwiki. It is not 100% local + though. + * Issue 384: Custom_wiki2html script now receives templating arguments + * Issue 393: Custom_wiki2html script path can contain tilde character + * Issue 392: Custom_wiki2html arguments are quoted, e.g names with spaces + * Various small bug fixes. + 2.0.1 'stu'~ * Follow (i.e. open target of) markdown reference-style links. @@ -2195,7 +2236,7 @@ Vim plugins: http://www.vim.org/scripts/script.php?script_id=2226 2.0 'stu'~ This release is partly incompatible with previous. - * + Summary ~ * Quick page-link creation. @@ -2221,7 +2262,7 @@ Summary ~ * Table syntax change. Row separator uses | instead of +. * Fold multilined list items. * Custom wiki to HTML converters. See |vimwiki-option-custom_wiki2html|. - * Conceal long weblinks. See |g:vimwiki_url_mingain|. + * Conceal long weblinks. See g:vimwiki_url_mingain. * Option to disable table mappings. See |g:vimwiki_table_mappings|. For detailed information see issues list on diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index bf6e7b5..6b03bd1 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -12,18 +12,16 @@ let b:did_ftplugin = 1 " Don't load another plugin for this buffer " Reset the following options to undo this plugin. let b:undo_ftplugin = "setlocal ". \ "suffixesadd< isfname< comments< ". - \ "autowriteall< ". \ "formatoptions< foldtext< ". \ "foldmethod< foldexpr< commentstring< " " UNDO }}} " MISC STUFF {{{ -setlocal autowriteall setlocal commentstring=%%%s if g:vimwiki_conceallevel && exists("+conceallevel") - let &conceallevel = g:vimwiki_conceallevel + let &l:conceallevel = g:vimwiki_conceallevel endif " MISC }}} @@ -63,56 +61,8 @@ endif " COMMENTS }}} " FOLDING for headers and list items using expr fold method. {{{ -function! VimwikiFoldLevel(lnum) "{{{ - let line = getline(a:lnum) - - " Header folding... - if line =~ g:vimwiki_rxHeader - let n = vimwiki#u#count_first_sym(line) - return '>'.n - endif - - let base_level = s:get_base_level(a:lnum) - - " List item folding... - if g:vimwiki_fold_lists - let nnline = getline(a:lnum + 1) - let rx_list_item = '\('. - \ g:vimwiki_rxListBullet.'\|'.g:vimwiki_rxListNumber. - \ '\)' - - - if line =~ rx_list_item - let [nnum, nline] = s:find_forward(rx_list_item, a:lnum) - let level = s:get_li_level(a:lnum) - let leveln = s:get_li_level(nnum) - let adj = s:get_li_level(s:get_start_list(rx_list_item, a:lnum)) - - if leveln > level - return ">".(base_level+leveln-adj) - " check if multilined list item - elseif (nnum-a:lnum) > 1 - \ && nline =~ rx_list_item && nnline !~ '^\s*$' - return ">".(base_level+level+1-adj) - else - return (base_level+level-adj) - endif - else - " process multilined list items - let [pnum, pline] = s:find_backward(rx_list_item, a:lnum) - if pline =~ rx_list_item - if indent(a:lnum) >= indent(pnum) && line !~ '^\s*$' - let level = s:get_li_level(pnum) - let adj = s:get_li_level(s:get_start_list(rx_list_item, pnum)) - return (base_level+level+1-adj) - endif - endif - endif - endif - - return base_level -endfunction "}}} +" Folding list items using expr fold method. {{{ function! s:get_base_level(lnum) "{{{ let lnum = a:lnum - 1 @@ -177,12 +127,126 @@ function! s:get_start_list(rx_item, lnum) "{{{ return 0 endfunction "}}} +function! VimwikiFoldListLevel(lnum) "{{{ + let line = getline(a:lnum) + + "" XXX Disabled: Header/section folding... + "if line =~ g:vimwiki_rxHeader + " return '>'.vimwiki#u#count_first_sym(line) + "endif + + "let nnline = getline(a:lnum+1) + + "" Unnecessary? + "if nnline =~ g:vimwiki_rxHeader + " return '<'.vimwiki#u#count_first_sym(nnline) + "endif + "" Very slow when called on every single line! + "let base_level = s:get_base_level(a:lnum) + + "FIXME does not work correctly + let base_level = 0 + + if line =~ g:vimwiki_rxListItem + let [nnum, nline] = s:find_forward(g:vimwiki_rxListItem, a:lnum) + let level = s:get_li_level(a:lnum) + let leveln = s:get_li_level(nnum) + let adj = s:get_li_level(s:get_start_list(g:vimwiki_rxListItem, a:lnum)) + + if leveln > level + return ">".(base_level+leveln-adj) + " check if multilined list item + elseif (nnum-a:lnum) > 1 + \ && (nline =~ g:vimwiki_rxListItem || nnline !~ '^\s*$') + return ">".(base_level+level+1-adj) + else + return (base_level+level-adj) + endif + else + " process multilined list items + let [pnum, pline] = s:find_backward(g:vimwiki_rxListItem, a:lnum) + if pline =~ g:vimwiki_rxListItem + if indent(a:lnum) >= indent(pnum) && line !~ '^\s*$' + let level = s:get_li_level(pnum) + let adj = s:get_li_level(s:get_start_list(g:vimwiki_rxListItem, pnum)) + return (base_level+level+1-adj) + endif + endif + endif + + return base_level +endfunction "}}} +" Folding list items }}} + +" Folding sections and code blocks using expr fold method. {{{ +function! VimwikiFoldLevel(lnum) "{{{ + let line = getline(a:lnum) + + " Header/section folding... + if line =~ g:vimwiki_rxHeader + return '>'.vimwiki#u#count_first_sym(line) + " Code block folding... + elseif line =~ '^\s*'.g:vimwiki_rxPreStart + return 'a1' + elseif line =~ '^\s*'.g:vimwiki_rxPreEnd.'\s*$' + return 's1' + else + return "=" + endif + +endfunction "}}} + +" Constants used by VimwikiFoldText {{{ +" use \u2026 and \u21b2 (or \u2424) if enc=utf-8 to save screen space +let s:ellipsis = (&enc ==? 'utf-8') ? "\u2026" : "..." +let s:ell_len = strlen(s:ellipsis) +let s:newline = (&enc ==? 'utf-8') ? "\u21b2 " : " " +let s:tolerance = 5 +" }}} + +function! s:shorten_text_simple(text, len) "{{{ unused + let spare_len = a:len - len(a:text) + return (spare_len>=0) ? [a:text,spare_len] : [a:text[0:a:len].s:ellipsis, -1] +endfunction "}}} + +" s:shorten_text(text, len) = [string, spare] with "spare" = len-strlen(string) +" for long enough "text", the string's length is within s:tolerance of "len" +" (so that -s:tolerance <= spare <= s:tolerance, "string" ends with s:ellipsis) +function! s:shorten_text(text, len) "{{{ returns [string, spare] + let spare_len = a:len - strlen(a:text) + if (spare_len + s:tolerance >= 0) + return [a:text, spare_len] + endif + " try to break on a space; assumes a:len-s:ell_len >= s:tolerance + let newlen = a:len - s:ell_len + let idx = strridx(a:text, ' ', newlen + s:tolerance) + let break_idx = (idx + s:tolerance >= newlen) ? idx : newlen + return [a:text[0:break_idx].s:ellipsis, newlen - break_idx] +endfunction "}}} + function! VimwikiFoldText() "{{{ - let line = substitute(getline(v:foldstart), '\t', - \ repeat(' ', &tabstop), 'g') - return line.' ['.(v:foldend - v:foldstart).']' + let line = getline(v:foldstart) + let main_text = substitute(line, '^\s*', repeat(' ',indent(v:foldstart)), '') + let fold_len = v:foldend - v:foldstart + 1 + let len_text = ' ['.fold_len.'] ' + if line !~ '^\s*'.g:vimwiki_rxPreStart + let [main_text, spare_len] = s:shorten_text(main_text, 50) + return main_text.len_text + else + " fold-text for code blocks: use one or two of the starting lines + let [main_text, spare_len] = s:shorten_text(main_text, 24) + let line1 = substitute(getline(v:foldstart+1), '^\s*', ' ', '') + let [content_text, spare_len] = s:shorten_text(line1, spare_len+20) + if spare_len > s:tolerance && fold_len > 3 + let line2 = substitute(getline(v:foldstart+2), '^\s*', s:newline, '') + let [more_text, spare_len] = s:shorten_text(line2, spare_len+12) + let content_text .= more_text + endif + return main_text.len_text.content_text + endif endfunction "}}} +" Folding sections and code blocks }}} " FOLDING }}} " COMMANDS {{{ diff --git a/plugin/vimwiki.vim b/plugin/vimwiki.vim index 95d85d5..aec7f5a 100644 --- a/plugin/vimwiki.vim +++ b/plugin/vimwiki.vim @@ -69,6 +69,8 @@ function! s:setup_buffer_leave() "{{{ echom " Setup_buffer_leave g:curr_idx=".g:vimwiki_current_idx." b:curr_idx=".s:vimwiki_idx()."" endif + let &autowriteall = s:vimwiki_autowriteall + " Set up menu if g:vimwiki_menu != "" exe 'nmenu disable '.g:vimwiki_menu.'.Table' @@ -195,13 +197,17 @@ function! s:setup_buffer_enter() "{{{ " Settings foldmethod, foldexpr and foldtext are local to window. Thus in a " new tab with the same buffer folding is reset to vim defaults. So we " insist vimwiki folding here. - if g:vimwiki_folding == 2 && &fdm != 'expr' - " User-defined fold-expression, and fold-text - endif - if g:vimwiki_folding == 1 + if g:vimwiki_folding == 'expr' setlocal fdm=expr setlocal foldexpr=VimwikiFoldLevel(v:lnum) setlocal foldtext=VimwikiFoldText() + elseif g:vimwiki_folding == 'list' || g:vimwiki_folding == 'lists' + setlocal fdm=expr + setlocal foldexpr=VimwikiFoldListLevel(v:lnum) + setlocal foldtext=VimwikiFoldText() + elseif g:vimwiki_folding == 'syntax' + setlocal fdm=syntax + setlocal foldtext=VimwikiFoldText() endif " And conceal level too. @@ -228,6 +234,10 @@ function! s:setup_buffer_reenter() "{{{ if g:vimwiki_debug ==3 echom " Setup_buffer_reenter g:curr_idx=".g:vimwiki_current_idx." b:curr_idx=".s:vimwiki_idx()."" endif + if !exists("s:vimwiki_autowriteall") + let s:vimwiki_autowriteall = &autowriteall + endif + let &autowriteall = g:vimwiki_autowriteall endfunction "}}} function! s:setup_cleared_syntax() "{{{ highlight groups that get cleared @@ -372,12 +382,10 @@ let s:vimwiki_defaults.list_margin = -1 call s:default('list', [s:vimwiki_defaults]) call s:default('auto_checkbox', 1) call s:default('use_mouse', 0) -call s:default('folding', 0) -call s:default('fold_trailing_empty_lines', 0) -call s:default('fold_lists', 0) +call s:default('folding', '') call s:default('menu', 'Vimwiki') call s:default('global_ext', 1) -call s:default('ext2syntax', {'.md': 'markdown'}) " syntax map keyed on extension +call s:default('ext2syntax', {}) " syntax map keyed on extension call s:default('hl_headers', 0) call s:default('hl_cb_checked', 0) call s:default('list_ignore_newline', 1) @@ -390,11 +398,11 @@ call s:default('CJK_length', 0) call s:default('dir_link', '') call s:default('valid_html_tags', 'b,i,s,u,sub,sup,kbd,br,hr,div,center,strong,em') call s:default('user_htmls', '') +call s:default('autowriteall', 1) call s:default('html_header_numbering', 0) call s:default('html_header_numbering_sym', '') call s:default('conceallevel', 2) -call s:default('url_mingain', 12) call s:default('url_maxsave', 15) call s:default('debug', 0) diff --git a/syntax/vimwiki.vim b/syntax/vimwiki.vim index c100da6..693c7f4 100644 --- a/syntax/vimwiki.vim +++ b/syntax/vimwiki.vim @@ -49,6 +49,9 @@ execute 'runtime! syntax/vimwiki_'.VimwikiGet('syntax').'.vim' " ------------------------------------------------------------------------- let time0 = vimwiki#u#time(starttime) "XXX +let g:vimwiki_rxListItem = '\('. + \ g:vimwiki_rxListBullet.'\|'.g:vimwiki_rxListNumber. + \ '\)' " LINKS: setup of larger regexes {{{ @@ -65,7 +68,7 @@ let g:vimwiki_WikiLinkTemplate2 = g:vimwiki_rxWikiLinkPrefix . '__LinkUrl__'. \ g:vimwiki_rxWikiLinkSuffix " let magic_chars = '.*[]\^$' -let valid_chars = '[^\\]' +let valid_chars = '[^\\\]]' let g:vimwiki_rxWikiLinkPrefix = escape(g:vimwiki_rxWikiLinkPrefix, magic_chars) let g:vimwiki_rxWikiLinkSuffix = escape(g:vimwiki_rxWikiLinkSuffix, magic_chars) @@ -111,6 +114,8 @@ let g:vimwiki_WikiInclTemplate2 = g:vimwiki_rxWikiInclPrefix . '__LinkUrl__'. \ '__LinkDescription__'. \ g:vimwiki_rxWikiInclSuffix +let valid_chars = '[^\\\}]' + let g:vimwiki_rxWikiInclPrefix = escape(g:vimwiki_rxWikiInclPrefix, magic_chars) let g:vimwiki_rxWikiInclSuffix = escape(g:vimwiki_rxWikiInclSuffix, magic_chars) let g:vimwiki_rxWikiInclSeparator = escape(g:vimwiki_rxWikiInclSeparator, magic_chars) @@ -281,6 +286,8 @@ if g:vimwiki_symH for i in range(1,6) let g:vimwiki_rxH{i}_Template = repeat(g:vimwiki_rxH, i).' __Header__ '.repeat(g:vimwiki_rxH, i) let g:vimwiki_rxH{i} = '^\s*'.g:vimwiki_rxH.'\{'.i.'}[^'.g:vimwiki_rxH.'].*[^'.g:vimwiki_rxH.']'.g:vimwiki_rxH.'\{'.i.'}\s*$' + let g:vimwiki_rxH{i}_Start = '^\s*'.g:vimwiki_rxH.'\{'.i.'}[^'.g:vimwiki_rxH.'].*[^'.g:vimwiki_rxH.']'.g:vimwiki_rxH.'\{'.i.'}\s*$' + let g:vimwiki_rxH{i}_End = '^\s*'.g:vimwiki_rxH.'\{1,'.i.'}[^'.g:vimwiki_rxH.'].*[^'.g:vimwiki_rxH.']'.g:vimwiki_rxH.'\{1,'.i.'}\s*$' endfor let g:vimwiki_rxHeader = '^\s*\('.g:vimwiki_rxH.'\{1,6}\)\zs[^'.g:vimwiki_rxH.'].*[^'.g:vimwiki_rxH.']\ze\1\s*$' else @@ -288,6 +295,8 @@ else for i in range(1,6) let g:vimwiki_rxH{i}_Template = repeat(g:vimwiki_rxH, i).' __Header__' let g:vimwiki_rxH{i} = '^\s*'.g:vimwiki_rxH.'\{'.i.'}[^'.g:vimwiki_rxH.'].*$' + let g:vimwiki_rxH{i}_Start = '^\s*'.g:vimwiki_rxH.'\{'.i.'}[^'.g:vimwiki_rxH.'].*$' + let g:vimwiki_rxH{i}_End = '^\s*'.g:vimwiki_rxH.'\{1,'.i.'}[^'.g:vimwiki_rxH.'].*$' endfor let g:vimwiki_rxHeader = '^\s*\('.g:vimwiki_rxH.'\{1,6}\)\zs[^'.g:vimwiki_rxH.'].*\ze$' endif @@ -295,29 +304,53 @@ endif " Header levels, 1-6 for i in range(1,6) execute 'syntax match VimwikiHeader'.i.' /'.g:vimwiki_rxH{i}.'/ contains=VimwikiTodo,VimwikiHeaderChar,VimwikiNoExistsLink,VimwikiCode,VimwikiLink,@Spell' + execute 'syntax region VimwikiH'.i.'Folding start=/'.g:vimwiki_rxH{i}_Start. + \ '/ end=/'.g:vimwiki_rxH{i}_End.'/me=s-1 transparent fold' endfor -" }}} -" concealed chars " {{{ -let cchar = '' -if exists("+conceallevel") - syntax conceal on - let cchar = ' cchar=~ ' -endif +" }}} -syntax spell toplevel +" possibly concealed chars " {{{ +let conceal = exists("+conceallevel") ? ' conceal' : '' + +execute 'syn match VimwikiEqInChar contained /'.g:vimwiki_char_eqin.'/'.conceal +execute 'syn match VimwikiBoldChar contained /'.g:vimwiki_char_bold.'/'.conceal +execute 'syn match VimwikiItalicChar contained /'.g:vimwiki_char_italic.'/'.conceal +execute 'syn match VimwikiBoldItalicChar contained /'.g:vimwiki_char_bolditalic.'/'.conceal +execute 'syn match VimwikiItalicBoldChar contained /'.g:vimwiki_char_italicbold.'/'.conceal +execute 'syn match VimwikiCodeChar contained /'.g:vimwiki_char_code.'/'.conceal +execute 'syn match VimwikiDelTextChar contained /'.g:vimwiki_char_deltext.'/'.conceal +execute 'syn match VimwikiSuperScript contained /'.g:vimwiki_char_superscript.'/'.conceal +execute 'syn match VimwikiSubScript contained /'.g:vimwiki_char_subscript.'/'.conceal +" }}} +" concealed link parts " {{{ if g:vimwiki_debug > 1 - echom 'WikiLink Prefix: '.g:vimwiki_rxWikiLinkPrefix1 - echom 'WikiLink Suffix: '.g:vimwiki_rxWikiLinkSuffix1 + echom 'WikiLink Prefix: '.g:vimwiki_rxWikiLinkPrefix + echom 'WikiLink Suffix: '.g:vimwiki_rxWikiLinkSuffix + echom 'WikiLink Prefix1: '.g:vimwiki_rxWikiLinkPrefix1 + echom 'WikiLink Suffix1: '.g:vimwiki_rxWikiLinkSuffix1 echom 'WikiIncl Prefix: '.g:vimwiki_rxWikiInclPrefix1 echom 'WikiIncl Suffix: '.g:vimwiki_rxWikiInclSuffix1 endif +" define the conceal attribute for links only if Vim is new enough to handle it +" and the user has g:vimwiki_url_maxsave > 0 + +let options = ' contained transparent contains=NONE' +" +" A shortener for long URLs: LinkRest (a middle part of the URL) is concealed +" VimwikiLinkRest group is left undefined if link shortening is not desired +if exists("+conceallevel") && g:vimwiki_url_maxsave > 0 + let options .= conceal + execute 'syn match VimwikiLinkRest `\%(///\=[^/ \t]\+/\)\zs\S\+\ze' + \.'\%([/#?]\w\|\S\{'.g:vimwiki_url_maxsave.'}\)`'.' cchar=~'.options +endif + " VimwikiLinkChar is for syntax markers (and also URL when a description " is present) and may be concealed -let options = ' contained transparent contains=NONE' + " conceal wikilinks execute 'syn match VimwikiLinkChar /'.g:vimwiki_rxWikiLinkPrefix.'/'.options execute 'syn match VimwikiLinkChar /'.g:vimwiki_rxWikiLinkSuffix.'/'.options @@ -329,24 +362,6 @@ execute 'syn match VimwikiLinkChar /'.g:vimwiki_rxWikiInclPrefix.'/'.options execute 'syn match VimwikiLinkChar /'.g:vimwiki_rxWikiInclSuffix.'/'.options execute 'syn match VimwikiLinkChar /'.g:vimwiki_rxWikiInclPrefix1.'/'.options execute 'syn match VimwikiLinkChar /'.g:vimwiki_rxWikiInclSuffix1.'/'.options - -" A shortener for long URLs: LinkRest (a middle part of the URL) is concealed -execute 'syn match VimwikiLinkRest `\%(///\=[^/ \t]\+/\)\zs\S\{' - \.g:vimwiki_url_mingain.',}\ze\%([/#?]\w\|\S\{' - \.g:vimwiki_url_maxsave.'}\)`'.cchar.options - -execute 'syn match VimwikiEqInChar contained /'.g:vimwiki_char_eqin.'/' -execute 'syn match VimwikiBoldChar contained /'.g:vimwiki_char_bold.'/' -execute 'syn match VimwikiItalicChar contained /'.g:vimwiki_char_italic.'/' -execute 'syn match VimwikiBoldItalicChar contained /'.g:vimwiki_char_bolditalic.'/' -execute 'syn match VimwikiItalicBoldChar contained /'.g:vimwiki_char_italicbold.'/' -execute 'syn match VimwikiCodeChar contained /'.g:vimwiki_char_code.'/' -execute 'syn match VimwikiDelTextChar contained /'.g:vimwiki_char_deltext.'/' -execute 'syn match VimwikiSuperScript contained /'.g:vimwiki_char_superscript.'/' -execute 'syn match VimwikiSubScript contained /'.g:vimwiki_char_subscript.'/' -if exists("+conceallevel") - syntax conceal off -endif " }}} " non concealed chars " {{{ @@ -489,6 +504,7 @@ endif "}}} + " syntax group highlighting "{{{ hi def link VimwikiMarkers Normal @@ -578,6 +594,7 @@ hi def link VimwikiNoExistsLinkCharT VimwikiNoExistsLinkT execute 'runtime! syntax/vimwiki_'.VimwikiGet('syntax').'_custom.vim' " ------------------------------------------------------------------------- +" FIXME it now does not make sense to pretend there is a single syntax "vimwiki" let b:current_syntax="vimwiki" " EMBEDDED syntax setup "{{{ @@ -597,5 +614,8 @@ call vimwiki#base#nested_syntax('tex', \ '^\s*'.g:vimwiki_rxMathEnd, 'VimwikiMath') "}}} + +syntax spell toplevel + let timeend = vimwiki#u#time(starttime) "XXX call VimwikiLog_extend('timing',['syntax:scans',timescans],['syntax:regexloaded',time0],['syntax:beforeHLexisting',time01],['syntax:afterHLexisting',time02],['syntax:end',timeend])