From a25e46f1eb4577ef381deb25d6d1a61c2f7e3110 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 24 Feb 2016 22:26:54 +0000 Subject: [PATCH] Add autoindentation in makefile.kak, based on PR #582 by lenormf Closes #582 --- rc/base/makefile.kak | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/rc/base/makefile.kak b/rc/base/makefile.kak index ca042c5e..f641aa58 100644 --- a/rc/base/makefile.kak +++ b/rc/base/makefile.kak @@ -5,7 +5,7 @@ hook global BufSetOption mimetype=text/x-makefile %{ set buffer filetype makefile } -hook global BufCreate [mM]akefile %{ +hook global BufCreate .*/?[mM]akefile %{ set buffer filetype makefile } @@ -23,13 +23,35 @@ addhl -group /makefile/content regex ^[\w.%]+\h*:\s 0:identifier addhl -group /makefile/content regex \b(ifeq|ifneq|else|endif)\b 0:keyword addhl -group /makefile/content regex [+?:]= 0:operator +# Commands +# ‾‾‾‾‾‾‾‾ + +def -hidden _makefile-indent-on-new-line %{ + eval -draft -itersel %{ + # preserve previous line indent + try %{ exec -draft \;K } + ## If the line above is a target indent with a tab + try %{ exec -draft Z k ^[^:]+:\s z i } + # cleanup trailing white space son previous line + try %{ exec -draft k s \h+$ d } + # indent after ifeq, ifneq, else + try %{ exec -draft Z k ^\h*(ifeq|ifneq|else)\b z } + } +} + # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook global WinSetOption filetype=makefile %{ addhl ref makefile + hook window InsertChar \n -group makefile-indent _makefile-indent-on-new-line + set window comment_selection_chars "" set window comment_line_chars "#" } -hook global WinSetOption filetype=(?!makefile).* %{ rmhl makefile } + +hook global WinSetOption filetype=(?!makefile).* %{ + rmhl makefile + rmhooks window makefile-indent +}