Simple Define Indent's Funcs for Your Cool Major Modes in Emacs
Here I am implement indention functions for js
:
(require 'simple-indentation)
(simple-indentation-define-for-major-mode
js js
:one-indent " " ; By default 4 spaces
:rules
(list
(simple-indentation-rules-make
;; This rule ignore other rules
;; on situations:
;; if {log()}
;; |
;;
;; OR
;;
;; if {log()}|
;;
:begin
:on-chars-in-code "}"
:and
:on-chars-in-code "{"
:end
:on-current-or-previous-code-line)
(simple-indentation-rules-make
;; Indent when previous line has "{"
;; Example:
;;
;; if (ready) {
;; |
;;
:add-indent
:on-chars-in-code "{"
:check-on-prev-code-line)
(simple-indentation-rules-make
;; Deindent when line has "}"
;; Example:
;;
;; hack
;; }|
;;
:deindent
:on-chars-in-code "}")))
This create some functions:
js-indent-region
js-indent-line
js-indent-two-lines
for indent current and previous linesjs-indent-lines
take starting line's number, and ending line's number, indent region beetwen its
Some hooks:
js-each-line-before-indent
js-each-line-after-indent
js-before-indent-line-hook
run beforejs-indent-line
js-after-indent-line-hook
run afterjs-indent-line
js-before-indent-lines-hook
run beforejs-indent-lines
js-after-indent-lines-hook
run afterjs-indent-lines
js-before-indent-region-hook
run beforejs-indent-region
js-after-indent-region-hook
run afterjs-indent-region
js-before-indent-some-lines-hook
run beforejs-indent-region
andjs-indent-lines
js-after-indent-some-lines-hook
run afterjs-indent-region
andjs-indent-lines
js-before-run-indent-func-hook
run afterjs-indent-region
,js-indent-lines
andjs-indent-line
js-after-run-indent-func-hook
run afterjs-indent-region
,js-indent-lines
andjs-indent-line
And some variables:
js-indention-rules
list ofsimple-indentation-rules
js-one-indent
in this example 2 spaces
Two main function of simple-indentation
is:
simple-indentation-rules-make
(link to full doc)simple-indentation-define-for-major-mode
. (link to full doc)
First is very big for function for create indention rules, this is main conception of simple-indentation
(rules -> indent function)
Second is just easy wrapper on simple-indentation-rules-make
, which create some useful indent functions and a lot of hooks and cople of variables (see [Small Example][Small Example])
Yes, please do! See [CONTRIBUTING][CONTRIBUTING.md] for guidelines.
Copyright (c) 2022 Semen Khramtsov.