robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f111b954a2
master
1" Vim indent file 2" Language: Handlebars 3" Maintainer: Devin Weaver 4" Last Change: 2026 Feb 20 5" Origin: https://github.com/joukevandermaas/vim-ember-hbs 6" Credits: Jouke van der Maas 7" Acknowledgement: Based on eruby.vim indentation by TPope 8" License: MIT 9" The MIT License (MIT) 10" 11" Copyright (c) 2026 Devin Weaver 12" Copyright (c) 2015 Jouke van der Maas 13" 14" Permission is hereby granted, free of charge, to any person obtaining a copy 15" of this software and associated documentation files (the "Software"), to deal 16" in the Software without restriction, including without limitation the rights 17" to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18" copies of the Software, and to permit persons to whom the Software is 19" furnished to do so, subject to the following conditions: 20" 21" The above copyright notice and this permission notice shall be included in all 22" copies or substantial portions of the Software. 23" 24" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29" OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30" SOFTWARE. 31 32if exists ( "b:did_indent" ) 33finish 34endif 35 36runtime ! indent/html.vim 37unlet ! b: did_indent 38 39" Force HTML indent to not keep state. 40let b: html_indent_usestate = 0 41let b: handlebars_current_indent = 0 42 43if & l: indentexpr == '' 44if & l: cindent 45let & l: indentexpr = 'cindent(v:lnum)' 46else 47let & l: indentexpr = 'indent(prevnonblank(v:lnum-1))' 48endif 49endif 50let b: handlebars_subtype_indentexpr = & l: indentexpr 51 52let b: did_indent = 1 53 54setlocal indentexpr = GetHandlebarsIndent () 55setlocal indentkeys = o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=else,={{#,={{/ 56 57" Only define the function once. 58if exists ( "*GetHandlebarsIndent" ) 59finish 60endif 61 62function ! GetHandlebarsIndent (...) 63" The value of a single shift-width 64let sw = shiftwidth () 65 66if a: 0 && a: 1 == '.' 67let v: lnum = line ( '.' ) 68elseif a: 0 && a: 1 =~ '^\d' 69let v: lnum = a: 1 70endif 71let vcol = col ( '.' ) 72call cursor ( v: lnum , 1 ) 73call cursor ( v: lnum , vcol ) 74exe "let ind = " . b: handlebars_subtype_indentexpr 75 76" Workaround for Andy Wokula's HTML indent. This should be removed after 77" some time, since the newest version is fixed in a different way. Credit 78" to eruby.vim indent by tpope 79if b: handlebars_subtype_indentexpr =~# '^HtmlIndent(' 80 \&& exists ( 'b:indent' ) 81 \&& type ( b: indent ) == type ({}) 82 \&& has_key ( b: indent , 'lnum' ) 83" Force HTML indent to not keep state 84let b: indent . lnum = -1 85endif 86 87let lnum = prevnonblank ( v: lnum - 1 ) 88let prevLine = getline ( lnum ) 89let currentLine = getline ( v: lnum ) 90 91" all indent rules only apply if the block opening/closing 92" tag is on a separate line 93 94" indent after block {{#block 95if prevLine =~# '\v\s*\{\{\#' 96let ind = ind + sw 97endif 98" but not if the block ends on the same line 99if prevLine =~# '\v\s*\{\{\#(.+)(\s+|\}\}).+\{\{\/\1' 100let ind = ind - sw 101endif 102" unindent after block close {{/block}} 103if currentLine =~# '\v^\s*\{\{\/' 104let ind = ind - sw 105endif 106" indent after component block {{a-component 107if prevLine =~# '\v\s*\{\{\w' 108let ind = ind + sw 109endif 110" but not if the component block ends on the same line 111if prevLine =~# '\v\s*\{\{\w(.+)\}\}' 112let ind = ind - sw 113endif 114" unindent }} lines 115if currentLine =~# '\v^\s*\}\}\s*$' || ( currentLine !~# '\v^\s*\{\{\/' && prevLine =~# '\v^\s*[^\{\}]+\}\}\s*$' ) 116let ind = ind - sw 117endif 118" unindent {{else}} 119if currentLine =~# '\v^\s*\{\{else' 120let ind = ind - sw 121endif 122" indent again after {{else}} 123if prevLine =~# '\v^\s*\{\{else' 124let ind = ind + sw 125endif 126 127return ind 128endfunction