codekingpro/portable-devtools
114k
1" Vim indent file2" Language: Handlebars3" Maintainer: Devin Weaver4" Last Change: 2026 Feb 205" Origin: https://github.com/joukevandermaas/vim-ember-hbs6" Credits: Jouke van der Maas7" Acknowledgement: Based on eruby.vim indentation by TPope8" License: MIT9" The MIT License (MIT)10"11" Copyright (c) 2026 Devin Weaver12" Copyright (c) 2015 Jouke van der Maas13"14" Permission is hereby granted, free of charge, to any person obtaining a copy15" of this software and associated documentation files (the "Software"), to deal16" in the Software without restriction, including without limitation the rights17" to use, copy, modify, merge, publish, distribute, sublicense, and/or sell18" copies of the Software, and to permit persons to whom the Software is19" furnished to do so, subject to the following conditions:20"21" The above copyright notice and this permission notice shall be included in all22" copies or substantial portions of the Software.23"24" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR25" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,26" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE27" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER28" 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 THE30" SOFTWARE.31 32if exists("b:did_indent")33 finish34endif35 36runtime! indent/html.vim37unlet! b:did_indent38 39" Force HTML indent to not keep state.40let b:html_indent_usestate = 041let b:handlebars_current_indent = 042 43if &l:indentexpr == ''44 if &l:cindent45 let &l:indentexpr = 'cindent(v:lnum)'46 else47 let &l:indentexpr = 'indent(prevnonblank(v:lnum-1))'48 endif49endif50let b:handlebars_subtype_indentexpr = &l:indentexpr51 52let b:did_indent = 153 54setlocal indentexpr=GetHandlebarsIndent()55setlocal indentkeys=o,O,*<Return>,<>>,{,},0),0],o,O,!^F,=else,={{#,={{/56 57" Only define the function once.58if exists("*GetHandlebarsIndent")59 finish60endif61 62function! GetHandlebarsIndent(...)63 " The value of a single shift-width64 let sw = shiftwidth()65 66 if a:0 && a:1 == '.'67 let v:lnum = line('.')68 elseif a:0 && a:1 =~ '^\d'69 let v:lnum = a:170 endif71 let vcol = col('.')72 call cursor(v:lnum,1)73 call cursor(v:lnum,vcol)74 exe "let ind = ".b:handlebars_subtype_indentexpr75 76 " Workaround for Andy Wokula's HTML indent. This should be removed after77 " some time, since the newest version is fixed in a different way. Credit78 " to eruby.vim indent by tpope79 if 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 state84 let b:indent.lnum = -185 endif86 87 let lnum = prevnonblank(v:lnum-1)88 let prevLine = getline(lnum)89 let currentLine = getline(v:lnum)90 91 " all indent rules only apply if the block opening/closing92 " tag is on a separate line93 94 " indent after block {{#block95 if prevLine =~# '\v\s*\{\{\#'96 let ind = ind + sw97 endif98 " but not if the block ends on the same line99 if prevLine =~# '\v\s*\{\{\#(.+)(\s+|\}\}).+\{\{\/\1'100 let ind = ind - sw101 endif102 " unindent after block close {{/block}}103 if currentLine =~# '\v^\s*\{\{\/'104 let ind = ind - sw105 endif106 " indent after component block {{a-component107 if prevLine =~# '\v\s*\{\{\w'108 let ind = ind + sw109 endif110 " but not if the component block ends on the same line111 if prevLine =~# '\v\s*\{\{\w(.+)\}\}'112 let ind = ind - sw113 endif114 " unindent }} lines115 if currentLine =~# '\v^\s*\}\}\s*$' || (currentLine !~# '\v^\s*\{\{\/' && prevLine =~# '\v^\s*[^\{\}]+\}\}\s*$')116 let ind = ind - sw117 endif118 " unindent {{else}}119 if currentLine =~# '\v^\s*\{\{else'120 let ind = ind - sw121 endif122 " indent again after {{else}}123 if prevLine =~# '\v^\s*\{\{else'124 let ind = ind + sw125 endif126 127 return ind128endfunction129 