Skip to content

Commit

Permalink
Remove notes_fold_ignore_code option, always enabled now!
Browse files Browse the repository at this point in the history
I have over 800 notes and just tried the :RecentNotes command for the
first time in a while. It was really slow, took more than a minute..
I tried the :ShowTaggedNotes command, also very slow.

It turns out that the "improvement" to text folding which ignores # inside
code blocks was written in a very naive way, making it very slow on large
buffers (over 500 lines). I've now fixed this, making it fast enough on
large buffers to always enable the improvement and remove the option
altogether. I like it when I can remove options :-).
  • Loading branch information
xolox committed Nov 3, 2011
1 parent 8583afe commit 4a12f53
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
6 changes: 0 additions & 6 deletions README.md
Expand Up @@ -62,12 +62,6 @@ This option defines the pathname of the Python script that's used to perform acc

This option defines the pathname of the text file that stores the list of known tags used for tag name completion and the `:ShowTaggedNotes` command. The text file is created automatically when it's first needed, after that you can recreate it manually by executing `:IndexTaggedNotes` (see below).

### The `g:notes_fold_ignore_code` option

The notes syntax uses `#` to mark headings which define foldable sections of text. The notes syntax also supports embedding fragments of syntax highlighted text. Of course the plug-in should not fold lines starting with `#` inside a code block, because `#` is frequently used for single line comments! The fold function knows how to deal with this, however I suspect the current implementation to be very slow, so it's not enabled by default. If you set this variable to true the feature will be enabled:

:let g:notes_fold_ignore_code = 1

## Commands

To edit one of your existing notes you can use Vim commands such as [:edit] [edit], [:split] [split] and [:tabedit] [tabedit] with a filename that starts with *note:* followed by (part of) the title of one of your notes, e.g.:
Expand Down
35 changes: 20 additions & 15 deletions autoload/xolox/notes.vim
Expand Up @@ -6,7 +6,7 @@
" Note: This file is encoded in UTF-8 including a byte order mark so
" that Vim loads the script using the right encoding transparently.

let g:xolox#notes#version = '0.12.5'
let g:xolox#notes#version = '0.12.6'

function! xolox#notes#shortcut() " {{{1
" The "note:" pseudo protocol is just a shortcut for the :Note command.
Expand Down Expand Up @@ -510,7 +510,6 @@ function! s:internal_search(bang, pattern, keywords, phase2) " {{{2
endif
silent cwindow
if &buftype == 'quickfix'
setlocal ignorecase
execute 'match IncSearch' substitute(pattern, '^/', '/\\c', '')
endif
call xolox#misc#timer#stop('notes.vim %s: Searched notes in %s.', g:xolox#notes#version, starttime)
Expand Down Expand Up @@ -859,27 +858,33 @@ endfunction

function! xolox#notes#foldexpr() " {{{3
" Folding expression to fold atx style Markdown headings.
if xolox#misc#option#get('notes_fold_ignore_code', 0)
let pos_save = getpos('.')
call setpos('.', [0, v:lnum, 1, 0])
let in_code = (search('{{{\|\(}}}\)', 'bnpW') == 1)
call setpos('.', pos_save)
if in_code
return '='
endif
endif
let lastlevel = foldlevel(v:lnum - 1)
let nextlevel = match(getline(v:lnum), '^#\+\zs')
let retval = '='
if lastlevel <= 0 && nextlevel >= 1
return '>' . nextlevel
let retval = '>' . nextlevel
elseif nextlevel >= 1
if lastlevel > nextlevel
return '<' . nextlevel
let retval = '<' . nextlevel
else
return '>' . nextlevel
let retval = '>' . nextlevel
endif
endif
return '='
if retval != '='
" Check whether the change in folding introduced by 'rv'
" is invalidated because we're inside a code block.
let pos_save = getpos('.')
try
call setpos('.', [0, v:lnum, 1, 0])
if search('{{{\|\(}}}\)', 'bnpW') == 1
let retval = '='
endif
finally
" Always restore the cursor position!
call setpos('.', pos_save)
endtry
endif
return retval
endfunction

function! xolox#notes#foldtext() " {{{3
Expand Down
13 changes: 0 additions & 13 deletions doc/notes.txt
Expand Up @@ -135,19 +135,6 @@ known tags used for tag name completion and the |:ShowTaggedNotes| command.
The text file is created automatically when it's first needed, after that you
can recreate it manually by executing |:IndexTaggedNotes| (see below).

-------------------------------------------------------------------------------
The *g:notes_fold_ignore_code* option

The notes syntax uses '#' to mark headings which define foldable sections of
text. The notes syntax also supports embedding fragments of syntax highlighted
text. Of course the plug-in should not fold lines starting with '#' inside a
code block, because '#' is frequently used for single line comments! The fold
function knows how to deal with this, however I suspect the current
implementation to be very slow, so it's not enabled by default. If you set
this variable to true the feature will be enabled:
>
:let g:notes_fold_ignore_code = 1
===============================================================================
*notes-commands*
Commands ~
Expand Down

0 comments on commit 4a12f53

Please sign in to comment.