Although this ahk-mode.el file is quite old, 2016, it appears to be the latest version in melpa.
This version of ahk-mode.el has significant problems, especially with the OTB (One True Brace) style.
short example just for if statement here, more examples for other sorts of statements below the TL;DR line
Code: Select all
if (x < y) {
... <-- first-line of if branch is indented correctly
... <--- subsequent lines are not indented correctly
} else {
...
...
}
I wonder if anybody has already fixed this, and is willing to share?
or if anyone can point me to better a better emacs indentation mode for AutoHotKey?
(C-mode actually does pretty well, since AHK with lots of braces can be written to be very C light. But inevitably it will get confused by some AutoHotKey syntax and then break if you run indent-buffer. it's a pain to have to remember the places where you're not allowed to run indent-buffer.)
(one of my New Year's resolutions - for the past many years - has been to ask first rather than going in trying to write it myself)
TL;DR
Version of ahk-mode.el that I'm using --essentially what appears to be latest stable version in melpa, the emacs package repository.
And more examples of the indentation it produces.
Code: Select all
;;; ahk-mode.el --- Major mode for editing AHK (AutoHotkey and AutoHotkey_L) -*- lexical-binding: t -*-
...
;; Copyright (C) 2015-2016 by Rich Alesi
...
;; URL: https://github.com/ralesi/ahk-mode
;; Version: 1.5.6
...
;; Based on work from
;; xahk-mode - Author: Xah Lee ( http://xahlee.org/ ) - 2012
;; ahk-mode - Author: Robert Widhopf-Fenk
Code: Select all
{
;; BAD: basically ahk-mode.el is very inconsistent and
;; frequently broken with the OTB style, with { on same line
;; as if/function, etc
;; applying ahk-mode.el to the One True Brace (OTB) [K&R?] style
;; example on https://www.autohotkey.com/docs/commands/Block.htm
MyFunction(x, y) {
...
}
if (x < y) {
...
...
} else {
...
...
}
Loop %RepeatCount% {
...
...
}
While x < y {
...
...
}
For k, v in obj {
...
...
}
Try {
...
..
} Catch e {
...
...
} Finally {
....
...
}
}
{
;; GOOD - it handles naked {} blocks.
if(0)
lineTrue()
;; And recognizes the next line is not part of the if then clause
}
{
;; this is surprising
if(0)
lineTrue()
else
lineFalse()
;; but it might be considered a feature, giving a
;; strong hint that AutoHotKey does not really
;; understand traditional if withouut {braces} with
;; an else clause
}
{
;; GOOD - curly {braces} on line by themselves work
if(0)
{
...
}
if(0)
{
...
}
else if(0)
{
...
}
else
{
...
}
}
{
;; GOOD - {on same line
if(0) {
... 1st line
}
...
if(0){
... line #1
... line #2 <---- is not indented as you might like
}
if(0) {
...
}
else if(0) {
...
}
else {
...
}
if(0) {
...
} else if(0) {
...
} else {
...
}
}
;; well, at least class definitions get indented properly
foo()
{
...
...
}
foo() {
...
...
}
class ClassName
{
...
...
}
class ClassName {
...
... ;
}
{
;; applying ahk-mode.el to the One True Brace (OTB) [K&R?] style
;; example on https://www.autohotkey.com/docs/commands/Block.htm
MyFunction(x, y) {
...
}
if (x < y) {
...
...
} else {
...
...
}
Loop %RepeatCount% {
...
...
}
While x < y {
...
...
}
For k, v in obj {
...
...
}
Try {
...
..
} Catch e {
...
...
} Finally {
....
...
}
}