Navigation Menu

Skip to content

Commit

Permalink
Fold function finally knows to ignore embedded code (thanks to Bart K…
Browse files Browse the repository at this point in the history
…roon

for the motivation to finally fix this bloody annoying misfeature ;-))
  • Loading branch information
xolox committed Oct 23, 2011
1 parent 2349000 commit 9985806
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -62,6 +62,12 @@ 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
13 changes: 11 additions & 2 deletions autoload/xolox/notes.vim
@@ -1,12 +1,12 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
" Last Change: October 18, 2011
" Last Change: October 23, 2011
" URL: http://peterodding.com/code/vim/notes/

" 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'
let g:xolox#notes#version = '0.12.1'

function! xolox#notes#shortcut() " {{{1
" The "note:" pseudo protocol is just a shortcut for the :Note command.
Expand Down Expand Up @@ -852,6 +852,15 @@ 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')
if lastlevel <= 0 && nextlevel >= 1
Expand Down
13 changes: 13 additions & 0 deletions doc/notes.txt
Expand Up @@ -135,6 +135,19 @@ 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 9985806

Please sign in to comment.