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-regionjs-indent-linejs-indent-two-linesfor indent current and previous linesjs-indent-linestake starting line's number, and ending line's number, indent region beetwen its
Some hooks:
js-each-line-before-indentjs-each-line-after-indentjs-before-indent-line-hookrun beforejs-indent-linejs-after-indent-line-hookrun afterjs-indent-linejs-before-indent-lines-hookrun beforejs-indent-linesjs-after-indent-lines-hookrun afterjs-indent-linesjs-before-indent-region-hookrun beforejs-indent-regionjs-after-indent-region-hookrun afterjs-indent-regionjs-before-indent-some-lines-hookrun beforejs-indent-regionandjs-indent-linesjs-after-indent-some-lines-hookrun afterjs-indent-regionandjs-indent-linesjs-before-run-indent-func-hookrun afterjs-indent-region,js-indent-linesandjs-indent-linejs-after-run-indent-func-hookrun afterjs-indent-region,js-indent-linesandjs-indent-line
And some variables:
js-indention-ruleslist ofsimple-indentation-rulesjs-one-indentin 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.