punassuming / ahk-mode

AutotHotkey major mode for emacs
38 stars 15 forks source link

Indentation needs fixing #1

Open punassuming opened 9 years ago

punassuming commented 9 years ago

Fix indentation algorithm

punassuming commented 9 years ago

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
bbatsov commented 8 years ago

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

p3r7 commented 8 years ago

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.

bbatsov commented 8 years ago

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

bbatsov commented 8 years ago

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

ekr1 commented 4 years ago

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.

p3r7 commented 4 years ago

Just came here to say thanks.

It works great!

LewWadoo commented 2 years ago

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