branch: elpa/nix-mode
commit 1a1ce340af420233e28b1fb0cf3b5fc6431c4108
Author: Matthew Bauer <[email protected]>
Commit: Matthew Bauer <[email protected]>

    Fix indentation case when '{' at beginning.
    
    When '{' started the buffer, it was not being picked up as a
    parenthesis. The while loop gets ugly when doing this but I've added a
    check for that specific case.
    
    Fixes #5
---
 nix-mode.el | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/nix-mode.el b/nix-mode.el
index 53b00b5630..207329f35e 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -165,18 +165,23 @@ If a close brace `}' ends an antiquote, the next 
character begins a string."
          (p2 (nth 1 (syntax-ppss)))
          (n 0))
 
+      ;; prevent moving beyond buffer
       (if (eq p2 1)
          (setq n (1+ n)))
 
-      (while (and p2 (not (eq p2 1)))
+      (while (and p2 (not (eq p2 1))) ;; make sure p2 > 1
        (goto-char p2)
        (backward-char)
        (let ((l1 (line-number-at-pos p1))
              (l2 (line-number-at-pos p2)))
          (if (not (eq l1 l2))
-             (setq n (+ n 1))))
+             (setq n (1+ n))))
        (setq p1 p2)
-       (setq p2 (nth 1 (syntax-ppss))))
+       (setq p2 (nth 1 (syntax-ppss)))
+
+       ;; make sure we don't go beyond buffer
+       (if (eq p2 1)
+           (setq n (1+ n))))
 
       n)))
 

Reply via email to