Skip to content

Commit

Permalink
Fix string contents indentation (issue #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
immerrr committed Sep 18, 2011
1 parent e470943 commit bb9330f
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions lua-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -450,19 +450,16 @@ Return the amount the indentation changed by."
;; save point as a distance to eob - it's invariant w.r.t indentation
(pos (- (point-max) (point))))
(back-to-indentation)
(if (and (not lua-indent-string-contents) (lua-string-p))
(goto-char (- (point-max) pos)) ;; just restore point position

(setq indent (max 0 (- (lua-calculate-indentation nil)
(lua-calculate-unindentation))))
(when (not (equal indent (current-column)))
(delete-region (line-beginning-position) (point))
(indent-to indent))
;; If initial point was within line's indentation,
;; position after the indentation. Else stay at same point in text.
(if (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos)))
indent)))
(setq indent (max 0 (- (lua-calculate-indentation nil)
(lua-calculate-unindentation))))
(when (not (equal indent (current-column)))
(delete-region (line-beginning-position) (point))
(indent-to indent))
;; If initial point was within line's indentation,
;; position after the indentation. Else stay at same point in text.
(if (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos)))
indent))

(defun lua-find-regexp (direction regexp &optional limit ignore-p)
"Searches for a regular expression in the direction specified.
Expand Down Expand Up @@ -666,7 +663,10 @@ previous one even though it looked like an end-of-statement."
(let ((line-end (line-end-position)))
(save-excursion
(beginning-of-line)
(re-search-forward lua-cont-bol-regexp line-end t))))
;; if first character of the line is inside string, it's a continuation
;; if strings aren't supposed to be indented, `lua-calculate-indentation' won't even let
;; the control inside this function
(or (lua-comment-or-string-p) (re-search-forward lua-cont-bol-regexp line-end t)))))

(defun lua-is-continuing-statement-p (&optional parse-start)
"Return non-nil if the line continues a statement.
Expand Down Expand Up @@ -860,8 +860,8 @@ In usual case returns an integer: the column to indent to."

;; if bol is inside a string, suppress any indentation
;; or all of the whitespace will go into the literal
(when (lua-string-p)
(throw 'indent 0))
(when (and (lua-string-p) (not lua-indent-string-contents)
(throw 'indent 0)))

(setq shift-amt (if (lua-is-continuing-statement-p) lua-indent-level 0))
(if (bobp) ; If we're at the beginning of the buffer, no change.
Expand Down

0 comments on commit bb9330f

Please sign in to comment.