1

For my current works style guide I need to indent two units (tabs in their case) for a line continuation. the default in emacs lua mode appears to be one.

e.g. (assuming two spaces are a tab or an indentation width)

correct example:

function doStuff(foo)
  local foo = otherFunc(
      someArgs,
      someMoreArgsToIllustrateIndentation)
  return foo
end

incorrect (default behaviour):

function doStuff(foo)
  local foo = otherFunc(
    someArgs,
    someMoreArgsToIllustrateIndentation)
  return foo
end

Now it seems like I need to modify lua-calculate-indentation in lua-mode.el but I can't seem to grok how it's working:

(defun lua-calculate-indentation (&optional parse-start)
  "Return appropriate indentation for current line as Lua code."
  (save-excursion
    (let ((continuing-p (lua-is-continuing-statement-p))
          (cur-line-begin-pos (line-beginning-position)))
      (or
       ;; when calculating indentation, do the following:
       ;; 1. check, if the line starts with indentation-modifier (open/close brace)
       ;;    and if it should be indented/unindented in special way
       (lua-calculate-indentation-override)

       (when (lua-forward-line-skip-blanks 'back)
         ;; the order of function calls here is important. block modifier
         ;; call may change the point to another line
         (let* ((modifier
                 (lua-calculate-indentation-block-modifier cur-line-begin-pos)))
           (+ (current-indentation) modifier)))

       ;; 4. if there's no previous line, indentation is 0
       0))))

Is this the right function to modify, and if so how do I do it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.