]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge pull request #235 from jirislaby/patch-1
authorHiroshi Shirosaki <h.shirosaki@gmail.com>
Wed, 9 Dec 2015 06:47:02 +0000 (15:47 +0900)
committerHiroshi Shirosaki <h.shirosaki@gmail.com>
Wed, 9 Dec 2015 06:47:02 +0000 (15:47 +0900)
Makefile: support DESTDIR

.gitignore [new file with mode: 0644]
.travis.yml
Makefile
after/ftplugin/markdown.vim
test/README.md
test/folding.vader [new file with mode: 0644]
test/run-tests.sh
test/vimrc

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..378eac2
--- /dev/null
@@ -0,0 +1 @@
+build
index 130c2afb2e015b4c594562dbc6be856551bccc14..4a78b6f43db6385ddba5c884fd231642f98527ba 100644 (file)
@@ -4,22 +4,19 @@ env:
   - TEST=latest
 
 before_script: |
-  cd ..
   if [ "$TEST" = "package" ]; then
     sudo apt-get -y update
     sudo apt-get -y install vim
   else
+    cd ..
     git clone --depth 1 https://github.com/vim/vim
     cd vim
     ./configure --with-features=huge
     make
     sudo make install
     export PATH="/usr/local/bin:$PATH"
-    cd -
+    cd "$TRAVIS_BUILD_DIR"
   fi
-  git clone https://github.com/godlygeek/tabular
-  git clone https://github.com/junegunn/vader.vim
 
 script: |
-  cd "$TRAVIS_BUILD_DIR"
-  ./test/run-tests.sh
+  make test
index 4b2ed8d66950c173ddeb1e44880716b5712b71b8..9260a5281f14a940f3faaf31b9a61add8bf03aaa 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -15,3 +15,21 @@ install:
        cp -v after/ftplugin/markdown.vim ${ADDONS}/after/ftplugin/markdown.vim
        mkdir -pv ${REGISTRY}
        cp -v registry/markdown.yaml ${REGISTRY}/markdown.yaml
+
+test: build/tabular build/vader.vim
+       test/run-tests.sh
+.PHONY: test
+
+update: build/tabular build/vader.vim
+       cd build/tabular && git pull
+       cd build/vader.vim && git pull
+.PHONY: update
+
+build/tabular: | build
+       git clone https://github.com/godlygeek/tabular build/tabular
+
+build/vader.vim: | build
+       git clone https://github.com/junegunn/vader.vim build/vader.vim
+
+build:
+       mkdir build
index adac473a0568016191757fd08c98bc254ba75133..a140c25a2c2ae9ac128506085a149641d6f0d187 100644 (file)
@@ -6,27 +6,37 @@
 "
 " original version from Steve Losh's gist: https://gist.github.com/1038710
 
-func! Foldexpr_markdown(lnum)
-    if (a:lnum == 1)
-        let l0 = ''
-    else
-        let l0 = getline(a:lnum-1)
-    endif
-
-    let l1 = getline(a:lnum)
+func! s:is_mkdCode(lnum)
+    return synIDattr(synID(a:lnum, 1, 0), 'name') == 'mkdCode'
+endfunc
 
-    let l2 = getline(a:lnum+1)
+func! s:effective_line(lnum)
+    let line = getline(a:lnum)
+    return (line !~ '^[=-#]' || s:is_mkdCode(a:lnum)) ? '' : line
+endfunc
 
+func! Foldexpr_markdown(lnum)
+    let l2 = s:effective_line(a:lnum+1)
     if  l2 =~ '^==\+\s*'
         " next line is underlined (level 1)
         return '>1'
     elseif l2 =~ '^--\+\s*'
         " next line is underlined (level 2)
         return '>2'
-    elseif l1 =~ '^#'
+    endif
+
+    let l1 = s:effective_line(a:lnum)
+    if l1 =~ '^#'
         " don't include the section title in the fold
         return '-1'
-    elseif l0 =~ '^#'
+    endif
+
+    if (a:lnum == 1)
+        let l0 = ''
+    else
+        let l0 = s:effective_line(a:lnum-1)
+    endif
+    if l0 =~ '^#'
         " current line starts with hashes
         return '>'.matchend(l0, '^#\+')
     else
index 1817e55768c01525424bc488084d495051f419ec..a13d6d20ae11273f9bf7fc579ffed8363df57fde 100644 (file)
@@ -1,7 +1,5 @@
-To run the tests, you must install [Vader](https://github.com/junegunn/vader.vim).
+You can run the tests using the Makefile from the top directory:
 
-Vader and other plugins must be installed in the same directory as this repository.
+    make test
 
-Run the tests with:
-
-    ./run-tests.sh
+To run them manually please refer to the instructions/commands in the Makefile.
diff --git a/test/folding.vader b/test/folding.vader
new file mode 100644 (file)
index 0000000..ee20975
--- /dev/null
@@ -0,0 +1,38 @@
+Before:
+  source ../after/ftplugin/markdown.vim
+
+After:
+  setlocal foldexpr=0
+  setlocal foldmethod=manual
+
+Given markdown;
+# Title
+
+## Chapter 1
+
+```
+This is code block
+# This is just a comment
+```
+
+## Capter 2
+
+foobar
+
+Execute (fold level # in code block):
+  AssertEqual foldlevel(1), 0, '# Title'
+  AssertEqual foldlevel(3), 1, '## Chapter 1'
+  AssertEqual foldlevel(7), 2, '# This is just a comment'
+  AssertEqual foldlevel(8), 2, '```'
+  AssertEqual foldlevel(10), 1, '## Chapter 2'
+  AssertEqual foldlevel(12), 2, 'foobar'
+
+Given markdown;
+
+==+ Fold Level 1
+
+--+ Fold Level 2
+
+Execute (fold level ==+, --+):
+  AssertEqual foldlevel(2), 1, '==+'
+  AssertEqual foldlevel(4), 2, '--+'
index c8c62137ae96816135cab228aa17b66fe22e7ff4..731b3ced111f6331df20ecf9c09b32775078f168 100755 (executable)
@@ -1,3 +1,16 @@
 #!/usr/bin/env bash
 
-cd "$( dirname "${BASH_SOURCE[0]}" )" && vim -Nu vimrc -c 'Vader! *' > /dev/null
+# Exit on error.
+set -e
+
+cd "$( dirname "${BASH_SOURCE[0]}" )"
+
+for dep in ../build/tabular ../build/vader.vim; do
+  if [[ ! -d $dep ]]; then
+    echo "Missing dependency: $dep"
+    echo "You may just want to use 'make test'."
+    exit 1
+  fi
+done
+
+vim -Nu vimrc -c 'Vader! *' > /dev/null
index 44df1b6140b309adbe1c80ce40a0ac9e9714a428..59c61630f84e09bd346c93d4215a8101c52121fb 100644 (file)
@@ -1,7 +1,7 @@
 set nocompatible
 set rtp+=../
-set rtp+=../../tabular/
-set rtp+=../../vader.vim/
+set rtp+=../build/tabular/
+set rtp+=../build/vader.vim/
 filetype on
 filetype plugin on
 filetype indent on