Skip to content

Commit 2db7b2b

Browse files
committed
Merge pull request #154 from elixir-lang/fix-first-indentation-after-defmodule
Correct behavior of indentation before end-of-buffer
2 parents 4a6d256 + 5bbaf01 commit 2db7b2b

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## v2.2.0-dev (unreleased)
44

5+
### Enhancements
6+
7+
* [Indentation] Correct behavior after last line in buffer. (#145)
8+
59
## v2.1.1 - 2014/12/24
610

711
### Enhancements

elixir-smie.el

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -169,33 +169,34 @@
169169

170170
(defun elixir-smie--semi-ends-match ()
171171
"Return non-nil if the current line concludes a match block."
172-
(save-excursion
173-
;; Warning: Recursion.
174-
;; This is easy though.
175-
176-
;; 1. If we're at a blank line, move forward a character. This takes us to
177-
;; the next line.
178-
;; 2. If we're not at the end of the buffer, call this function again.
179-
;; (Otherwise, return nil.)
180-
181-
;; The point here is that we want to treat blank lines as a single semi-
182-
;; colon when it comes to detecting the end of match statements. This could
183-
;; also be handled by a `while' expression or some other looping mechanism.
184-
(cl-flet ((self-call ()
185-
(if (< (point) (point-max))
186-
(elixir-smie--semi-ends-match)
187-
nil)))
188-
(cond
189-
((and (eolp) (bolp))
190-
(forward-char)
191-
(self-call))
192-
((looking-at elixir-smie--spaces-til-eol-regexp)
193-
(move-beginning-of-line 2)
194-
(self-call))
195-
;; And if we're NOT on a blank line, move to the end of the line, and see
196-
;; if we're looking back at a block operator.
197-
(t (move-end-of-line 1)
198-
(looking-back elixir-smie--block-operator-regexp))))))
172+
(when (not (eobp))
173+
(save-excursion
174+
;; Warning: Recursion.
175+
;; This is easy though.
176+
177+
;; 1. If we're at a blank line, move forward a character. This takes us to
178+
;; the next line.
179+
;; 2. If we're not at the end of the buffer, call this function again.
180+
;; (Otherwise, return nil.)
181+
182+
;; The point here is that we want to treat blank lines as a single semi-
183+
;; colon when it comes to detecting the end of match statements. This could
184+
;; also be handled by a `while' expression or some other looping mechanism.
185+
(cl-flet ((self-call ()
186+
(if (< (point) (point-max))
187+
(elixir-smie--semi-ends-match)
188+
nil)))
189+
(cond
190+
((and (eolp) (bolp))
191+
(forward-char)
192+
(self-call))
193+
((looking-at elixir-smie--spaces-til-eol-regexp)
194+
(move-beginning-of-line 2)
195+
(self-call))
196+
;; And if we're NOT on a blank line, move to the end of the line, and see
197+
;; if we're looking back at a block operator.
198+
(t (move-end-of-line 1)
199+
(looking-back elixir-smie--block-operator-regexp)))))))
199200

200201
(defun elixir-smie--same-line-as-parent (parent-pos child-pos)
201202
"Return non-nil if `child-pos' is on same line as `parent-pos'."
@@ -211,7 +212,10 @@
211212
((and (or (looking-at elixir-smie--comment-regexp)
212213
(looking-at "[\n#]"))
213214
(elixir-smie--implicit-semi-p))
214-
(if (eolp) (forward-char 1) (forward-comment 1))
215+
(when (not (save-excursion
216+
(forward-comment 1)
217+
(eobp)))
218+
(if (eolp) (forward-char 1) (forward-comment 1)))
215219
;; Note: `elixir-smie--semi-ends-match' will be called when the point is at
216220
;; the beginning of a new line. Keep that in mind.
217221
(if (elixir-smie--semi-ends-match)
@@ -313,7 +317,6 @@
313317
(cond
314318
((smie-rule-parent-p "if")
315319
(smie-rule-parent))
316-
317320
((and (smie-rule-parent-p "(")
318321
(save-excursion
319322
(goto-char (cadr smie--parent))

0 commit comments

Comments
 (0)