summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2017-09-27 20:14:30 +0200
committerAdam Stankiewicz <sheerun@sher.pl>2017-09-27 20:14:30 +0200
commit7e10428cd6b53bf5e0ead79b2733be4286b16378 (patch)
tree205c5dedb051f901011f10065b876d6fd1cc220d
parent6a4fe34e61e8655a4b94c16bc70e124694df99fc (diff)
downloadvim-polyglot-7e10428cd6b53bf5e0ead79b2733be4286b16378.tar.gz
vim-polyglot-7e10428cd6b53bf5e0ead79b2733be4286b16378.zip
Add autohotkey syntax, closes #220
Diffstat (limited to '')
-rw-r--r--README.md1
-rwxr-xr-xbuild1
-rw-r--r--ftdetect/polyglot.vim4
-rw-r--r--indent/autohotkey.vim223
4 files changed, 229 insertions, 0 deletions
diff --git a/README.md b/README.md
index c3bf8af2..52bdd43d 100644
--- a/README.md
+++ b/README.md
@@ -41,6 +41,7 @@ If you need full functionality of any plugin, please use it directly with your p
- [applescript](https://github.com/vim-scripts/applescript.vim) (syntax)
- [arduino](https://github.com/sudar/vim-arduino-syntax) (syntax, indent)
- [asciidoc](https://github.com/asciidoc/vim-asciidoc) (syntax)
+- [autohotkey](https://github.com/hnamikaw/vim-autohotkey) (indent)
- [blade](https://github.com/jwalton512/vim-blade) (syntax, indent, ftplugin)
- [c++11](https://github.com/octol/vim-cpp-enhanced-highlight) (syntax)
- [c/c++](https://github.com/vim-jp/vim-cpp) (syntax)
diff --git a/build b/build
index 51251340..5edb3a77 100755
--- a/build
+++ b/build
@@ -113,6 +113,7 @@ PACKS="
yaml:stephpy/vim-yaml
ansible:pearofducks/ansible-vim
arduino:sudar/vim-arduino-syntax
+ autohotkey:hnamikaw/vim-autohotkey
blade:jwalton512/vim-blade
c++11:octol/vim-cpp-enhanced-highlight
c/c++:vim-jp/vim-cpp
diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim
index 018830d3..784fac46 100644
--- a/ftdetect/polyglot.vim
+++ b/ftdetect/polyglot.vim
@@ -57,6 +57,10 @@ au BufRead,BufNewFile *.ino,*.pde set filetype=arduino
augroup END
augroup filetypedetect
+" autohotkey:hnamikaw/vim-autohotkey
+augroup END
+
+augroup filetypedetect
" blade:jwalton512/vim-blade
autocmd BufNewFile,BufRead *.blade.php set filetype=blade
augroup END
diff --git a/indent/autohotkey.vim b/indent/autohotkey.vim
new file mode 100644
index 00000000..2a9e7a2d
--- /dev/null
+++ b/indent/autohotkey.vim
@@ -0,0 +1,223 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'autohotkey') == -1
+
+" Vim indent file
+" Language: AutoHotkey
+" Maintainer: Hirotoshi Namikawa <hnamikaw1@gmail.com>
+" URL: http://github.com/hnamikaw/vim-autohotkey
+" License: Same as Vim.
+
+if exists('b:did_indent')
+ finish
+endif
+
+setlocal autoindent
+setlocal indentexpr=GetAutoHotkeyIndent()
+setlocal indentkeys=!^F,o,O,0{,0},=if,=else,=return
+setlocal expandtab
+
+let b:undo_indent = 'setlocal '.join([
+ \ 'autoindent<',
+ \ 'indentexpr<',
+ \ 'indentkeys<',
+ \ 'expandtab<',
+ \ ])
+
+let s:TRUE = !0
+let s:FALSE = 0
+
+" Check BEGIN BLOCK
+" TRUE:
+" {
+" { ; with comment
+" if {
+" if { ; with comment
+"
+" FALSE:
+" ; if { comment
+" sleep 1000 ; {
+function! IsBeginBlockByStr(str)
+ return a:str =~? '^[^;]*{\s*\(;.*\)\?$' ? s:TRUE : s:FALSE
+endfunction
+
+" Check END BLOCK
+" TRUE:
+" }
+" } ; with comment
+" } else {
+" } else { ; with comment
+"
+" FALSE:
+" ; } else {
+function! IsEndBlockByStr(str)
+ return a:str =~? '^\s*}.*\(;.*\)\?$' ? s:TRUE : s:FALSE
+endfunction
+
+" Check DOUBLE CORON
+" TRUE:
+" LAlt up::
+" LAlt up:: ; with comment
+"
+" FALSE:
+" ; LAlt up::
+" sleep 1000 ; ::
+function! IsDoubleCoronByStr(str)
+ return a:str =~? '^[^;]*::\s*\(;.*\)\?$' ? s:TRUE : s:FALSE
+endfunction
+
+" Check RETURN
+" TRUE:
+" return
+" return 1
+" return ; with comment
+"
+" FALSE:
+" ; return
+function! IsReturnByStr(str)
+ return a:str =~? '^\s*return.*\(;.*\)\?$' ? s:TRUE : s:FALSE
+endfunction
+
+" Check IF STATEMENT(without BLOCK)
+" TRUE:
+" if
+" if ; with comment
+" else
+" else ; with comment
+"
+" FALSE:
+" if {
+" else {
+function! IsIfStatementByStr(str)
+ return a:str =~? '^\s*\(if\|else\)[^{]*\(;.*\)\?$' ? s:TRUE : s:FALSE
+endfunction
+
+" Check inside of BLOCK.
+" TRUE:
+" if {
+" hogehoge
+" fugafuga <--- line_num
+" }
+"
+" FALSE:
+" foobar <--- line_num
+function! IsInsideOfBlockByNum(line_num)
+ let block_indent_level = 0
+
+ for scan_line_num in range(1, a:line_num)
+ if IsBeginBlockByStr(getline(scan_line_num)) == s:TRUE
+ let block_indent_level += 1
+ endif
+
+ if IsEndBlockByStr(getline(scan_line_num)) == s:TRUE
+ let block_indent_level -= 1
+ endif
+ endfor
+
+ return block_indent_level >= 1 ? s:TRUE : s:FALSE
+endfunction
+
+function! AddIndentByInd(indent)
+ return a:indent + &l:shiftwidth
+endfunction
+
+function! UnIndentByInd(indent)
+ return a:indent - &l:shiftwidth
+endfunction
+
+function! GetAutoHotkeyIndent()
+ let l0_num = v:lnum
+ let l1_num = v:lnum - 1
+ let pl1_num = prevnonblank(l1_num)
+ let pl2_num = prevnonblank(pl1_num - 1)
+
+ let l0_str = getline(l0_num)
+ let pl1_str = getline(pl1_num)
+ let pl2_str = getline(pl2_num)
+ let pl1_ind = indent(pl1_num)
+ let pl2_ind = indent(pl2_num)
+
+ " Case: Next line of IF STATEMENT(without BLOCK)
+ " if bar = 1
+ " callFunc1() <--- AddIndent
+ "
+ " if bar = 1
+ " { <--- No! AddIndent
+ if IsIfStatementByStr(pl1_str) == s:TRUE && IsBeginBlockByStr(l0_str) == s:FALSE
+ return AddIndentByInd(pl1_ind)
+ endif
+
+ " Case: End of IF STATEMENT(without BLOCK)
+ " if bar = 1
+ " callFunc1()
+ " if bar = 2 <--- UnIndent
+ "
+ " Case: End of IF STATEMENT(without BLOCK) and END BLOCK(of outer block)
+ " if foo
+ " {
+ " if bar = 3
+ " callFunc3()
+ " } <--- UnIndent (2level)
+ if IsIfStatementByStr(pl2_str) == s:TRUE && IsBeginBlockByStr(pl1_str) == s:FALSE
+ if IsEndBlockByStr(l0_str) == s:FALSE
+ return UnIndentByInd(pl1_ind)
+ else
+ return UnIndentByInd(pl2_ind)
+ endif
+ endif
+
+ " Case: Next line of BEGIN BLOCK
+ " Swap(ByRef Left, ByRef Right)
+ " {
+ " temp := Left <--- AddIndent
+ " Left := Right
+ " Right := temp
+ " }
+ if IsBeginBlockByStr(pl1_str) == s:TRUE
+ return AddIndentByInd(pl1_ind)
+ endif
+
+ " Case: END BLOCK
+ " Swap(ByRef Left, ByRef Right)
+ " {
+ " temp := Left
+ " Left := Right
+ " Right := temp
+ " } <--- UnIndent
+ if IsEndBlockByStr(l0_str) == s:TRUE
+ return UnIndentByInd(pl1_ind)
+ endif
+
+ " Case: Next line of DOUBLE CORON
+ " #n::
+ " Run Notepad <--- AddIndent
+ " return
+ if IsDoubleCoronByStr(pl1_str) == s:TRUE
+ return AddIndentByInd(pl1_ind)
+ endif
+
+ " Case: RETURN
+ " Note: It is not nothing if in the BLOCK.
+ " #n::
+ " Run Notepad
+ " return <--- UnIndent
+ " ~~~
+ " if foo
+ " {
+ " callFunc1()
+ " return <--- No! UnIndent
+ " }
+ if IsReturnByStr(l0_str) == s:TRUE && IsInsideOfBlockByNum(l0_num) == s:FALSE
+ return UnIndentByInd(pl1_ind)
+ endif
+
+ " Case: Top line.
+ if pl1_num == 0
+ return 0
+ endif
+
+ " Case: It does not match anything.
+ return pl1_ind
+endfunction
+
+let b:did_indent = 1
+
+endif