Skip to content

Commit

Permalink
lua-calculate-indentation-override: make unindent offset customizable
Browse files Browse the repository at this point in the history
- add lua-indentation-offset-alist to specify separate offsets for each
  token type;
- add (lua-get-offset TOKEN-TYPE) function to retrieve alist values
  • Loading branch information
immerrr committed Mar 16, 2013
1 parent c24f16e commit 60b44d5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lua-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,18 @@ This function replaces previous prefix-key binding with a new one."
If point is not inside string or comment, return nil."
(save-excursion (elt (syntax-ppss pos) 8)))

(defvar lua-indentation-offset-alist '((block-open . 3)
(block-close . -3))
"Alist of amounts by which Lua tokens are indented.")

(defun lua-get-offset (token-type)
"Return indentation offset for specified token type.
Indentation offsets are taken from `lua-indentation-offset-alist'."
(let ((tok-offset-cons (assoc token-type lua-indentation-offset-alist)))
(when tok-offset-cons
(cdr tok-offset-cons))))

(defun lua-indent-line ()
"Indent current line for Lua mode.
Return the amount the indentation changed by."
Expand Down Expand Up @@ -1237,7 +1249,9 @@ to the left by the amount specified in lua-indent-level."
(let ((block-start-column (current-column))
(block-start-point (point)))
(if (lua-point-is-after-left-shifter-p)
(current-indentation)
(+ (current-indentation)
(lua-get-offset 'block-open)
(lua-get-offset 'block-close))
block-start-column)))))))

(defun lua-calculate-indentation (&optional parse-start)
Expand Down

0 comments on commit 60b44d5

Please sign in to comment.