summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--ftdetect/polyglot.vim20
-rw-r--r--indent/applescript.vim81
3 files changed, 102 insertions, 1 deletions
diff --git a/README.md b/README.md
index 5db51dea..586c7d34 100644
--- a/README.md
+++ b/README.md
@@ -44,7 +44,7 @@ If you need full functionality of any plugin, please use it directly with your p
- [ansible](https://github.com/pearofducks/ansible-vim) (syntax, indent, ftplugin)
- [apiblueprint](https://github.com/sheerun/apiblueprint.vim) (syntax)
-- [applescript](https://github.com/vim-scripts/applescript.vim) (syntax)
+- [applescript](https://github.com/mityu/vim-applescript) (syntax, indent)
- [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)
diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim
index 8ca8c576..0619d65f 100644
--- a/ftdetect/polyglot.vim
+++ b/ftdetect/polyglot.vim
@@ -78,6 +78,26 @@ autocmd FileType apiblueprint set makeprg=drafter\ -l\ %
augroup end
endif
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'applescript') == -1
+ augroup filetypedetect
+ " applescript, from applescript.vim in mityu/vim-applescript:_SYNTAX
+"Plugin Name: AppleScript
+"Author: mityu
+"Last Change: 04-Mar-2017.
+
+let s:cpo_save=&cpo
+set cpo&vim
+
+au BufNewFile,BufRead *.scpt setf applescript
+au BufNewFile,BufRead *.applescript setf applescript
+
+let &cpo=s:cpo_save
+unlet s:cpo_save
+
+" vim: foldmethod=marker
+ augroup end
+endif
+
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'asciidoc') == -1
augroup filetypedetect
" asciidoc, from asciidoc.vim in asciidoc/vim-asciidoc
diff --git a/indent/applescript.vim b/indent/applescript.vim
new file mode 100644
index 00000000..67c51b35
--- /dev/null
+++ b/indent/applescript.vim
@@ -0,0 +1,81 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'applescript') == -1
+
+"Plugin Name: applescript indent file.
+"Author: mityu
+"Last Change: 02-May-2017.
+
+let s:cpo_save=&cpo
+set cpo&vim
+
+setlocal indentexpr=GetAppleScriptIndent()
+setlocal indentkeys+=0=end,0=else,=error
+
+func! GetAppleScriptIndent()
+ let l:ignorecase_save=&ignorecase
+ try
+ let &ignorecase=0
+ return s:returnAppleScriptIndent()
+ finally
+ let &ignorecase=l:ignorecase_save
+ endtry
+endfunc
+
+func! s:returnAppleScriptIndent()
+ let l:current_text=getline(v:lnum)
+
+ let l:prev_line=prevnonblank(v:lnum-1)
+
+ "At the start of the file, use 0 indent.
+ if l:prev_line==0
+ return 0
+ endif
+
+ let l:prev_line_save=l:prev_line
+ let l:prev_line=s:prev_non_connected_line(l:prev_line)
+
+ let l:indent=indent(l:prev_line)
+
+ if l:prev_line_save-l:prev_line==1
+ "連結開始
+ let l:indent+=shiftwidth()*2
+ elseif l:prev_line_save-l:prev_line>=2
+ "絶賛連結中
+ "その時は前の行のインデントをそのまま流用する
+ return indent(l:prev_line_save)
+ elseif l:prev_line_save==l:prev_line && s:doesOrderConnect(getline(l:prev_line-1))
+ "前の行が連結される行の最終行の場合
+ let l:prev_line=s:prev_non_connected_line(l:prev_line-1)
+ if l:prev_line==0 | let l:prev_line=1 | endif
+ let l:indent=indent(l:prev_line)
+ endif
+
+ let l:prev_text=getline(l:prev_line)
+ if l:prev_text=~'^\s*\(on\|\(tell\(.*\<to\>\)\@!\)\|repeat\|try\|if\|else\)'
+ let l:indent+=shiftwidth()
+ endif
+
+ if l:current_text=~'^\s*\(end\|else\|on\serror\)'
+ let l:indent-=shiftwidth()
+ endif
+
+ return l:indent
+endfunc
+
+func! s:prev_non_connected_line(line)
+ let l:prev_line=prevnonblank(a:line)
+ while l:prev_line>0 && s:doesOrderConnect(getline(l:prev_line))
+ let l:prev_line-=1
+ endwhile
+ return l:prev_line
+endfunc
+
+func! s:doesOrderConnect(text)
+ return a:text=~'¬$'
+endfunc
+
+let &cpo=s:cpo_save
+unlet s:cpo_save
+
+" vim: foldmethod=marker
+
+endif