diff runtime/indent/sh.vim @ 9407:619a98a67f67

commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 2 21:42:23 2016 +0200 Updated runtime files.
author Christian Brabandt <cb@256bit.org>
date Sat, 02 Jul 2016 21:45:06 +0200
parents f16bfe02cef1
children d183d629509e
line wrap: on
line diff
--- a/runtime/indent/sh.vim
+++ b/runtime/indent/sh.vim
@@ -3,9 +3,15 @@
 " Maintainer:          Christian Brabandt <cb@256bit.org>
 " Previous Maintainer: Peter Aronoff <telemachus@arpinum.org>
 " Original Author:     Nikolai Weibull <now@bitwi.se>
-" Latest Revision:     2016-02-15
+" Latest Revision:     2016-06-27
 " License:             Vim (see :h license)
 " Repository:          https://github.com/chrisbra/vim-sh-indent
+" Changelog:
+"          20160627: - detect heredocs correctly
+"          20160213: - detect function definition correctly
+"          20160202: - use shiftwidth() function
+"          20151215: - set b:undo_indent variable
+"          20150728: - add foreach detection for zsh
 
 if exists("b:did_indent")
   finish
@@ -102,6 +108,8 @@ function! GetShIndent()
     endif
   elseif s:is_case_break(line)
     let ind -= s:indent_value('case-breaks')
+  elseif s:is_here_doc(line)
+    let ind = 0
   endif
 
   return ind
@@ -160,6 +168,14 @@ function! s:is_case_break(line)
   return a:line =~ '^\s*;[;&]'
 endfunction
 
+function! s:is_here_doc(line)
+    if a:line =~ '^\w\+$'
+	let here_pat = '<<-\?'. s:escape(a:line). '\$'
+	return search(here_pat, 'bnW') > 0
+    endif
+    return 0
+endfunction
+
 function! s:is_case_ended(line)
   return s:is_case_break(a:line) || a:line =~ ';[;&]\s*\%(#.*\)\=$'
 endfunction
@@ -172,5 +188,9 @@ function! s:is_case_empty(line)
   endif
 endfunction
 
+function! s:escape(pattern)
+    return '\V'. escape(a:pattern, '\\')
+endfunction
+
 let &cpo = s:cpo_save
 unlet s:cpo_save