ahk-mode icon indicating copy to clipboard operation
ahk-mode copied to clipboard

Indentation needs fixing

Open punassuming opened this issue 9 years ago • 8 comments

Fix indentation algorithm

punassuming avatar Mar 15 '15 18:03 punassuming

It is currently working, but not containing all items needed. Will likely rewrite the entire indentation heuristic.

;; Block types that can affect indentation
;; comments - ; AAA
;; - previous block beginning brace = +0
;; - indentation level is skipped when determining position for current line
;; function - AAA(.*) { .\n. } = +1
;; function - AAA(.*) { } = +0
;; label - AAA: = 0
;; Keybindings (next line) AAA:: = +1
;; Keybindings (current line) AAA:: =+0
;; Open block - {( +1 on next
;; Close block - {( -1 on current
;; Class AAA.* { ... } = +1
;; #if block open - #[iI]f[^ \n]* (.*) = +1
;; #if block close - #[iI]f[^ \n]*$ = -1
;; return block - [Rr]eturn = -1
;; for .*\n { .. } = +1
;; loop .*\n { .. } = +1
;; open assignment - .*operator-regexp$ = +1

punassuming avatar Apr 09 '15 05:04 punassuming

You should check modern modes like https://github.com/chrisbarrett/swift-mode and https://github.com/elixir-lang/emacs-elixir for ideas how to improve indentation overall. It's generally a good idea to leverage smie these days - https://www.gnu.org/software/emacs/manual/html_node/elisp/SMIE.html

bbatsov avatar Feb 15 '16 05:02 bbatsov

Indentation doesn't seem to be working at all on my setup (emacs x64 25.1.90.2 on Microsoft Windows). I get error ahk-indent-line: Symbol’s function definition is void: current-line.

Similarly, when installing via melpa, I get this warning: Warning (bytecomp): the function ‘current-line’ is not known to be defined.

p3r7 avatar Mar 04 '16 11:03 p3r7

Yeah, there's no current-line function. I was wondering about this myself.

bbatsov avatar Mar 20 '16 06:03 bbatsov

@p3r7 I've just pushed a fix for this.

bbatsov avatar Mar 20 '16 06:03 bbatsov

I have just created pull request #30 with a few fixes to the indentation code. It now works correctly for a 1800 line AHK script, for me and fixes some blatant misbehaviours.

ekr1 avatar Apr 12 '20 16:04 ekr1

Just came here to say thanks.

It works great!

p3r7 avatar Apr 13 '20 10:04 p3r7

In the Switch-Case statement the Default keyword sticks to the beginning of the line.

LewWadoo avatar Jun 02 '22 07:06 LewWadoo