emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/nix-mode 63fbbf27bf 326/500: Improve indentation of closin


From: ELPA Syncer
Subject: [nongnu] elpa/nix-mode 63fbbf27bf 326/500: Improve indentation of closing parentheses.
Date: Sat, 29 Jan 2022 08:27:18 -0500 (EST)

branch: elpa/nix-mode
commit 63fbbf27bf2cecc6739a6503484871079b989a37
Author: Jakub Piecuch <j.piecuch96@gmail.com>
Commit: Jakub Piecuch <j.piecuch96@gmail.com>

    Improve indentation of closing parentheses.
---
 nix-mode.el | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/nix-mode.el b/nix-mode.el
index ba858594a0..792501ae95 100644
--- a/nix-mode.el
+++ b/nix-mode.el
@@ -574,6 +574,14 @@ STRING-TYPE type of string based off of Emacs syntax table 
types"
             (smie-backward-sexp)))
    '("{" ",")))
 
+(defun nix-smie--eol-p ()
+  "Whether there are no tokens after point on the current line."
+  (let ((eol (line-end-position)))
+    (save-excursion
+      (forward-comment (point-max))
+      (or (eobp)
+          (< eol (point))))))
+
 (defun nix-smie--indent-close ()
   "Align close paren with opening paren."
   (save-excursion
@@ -582,9 +590,13 @@ STRING-TYPE type of string based off of Emacs syntax table 
types"
       (condition-case nil
           (progn
             (backward-sexp 1)
-            ;; Align to the first token on the line containing
-            ;; the opening paren.
-            (current-indentation))
+            ;; If the opening paren is not the last token on its line,
+            ;; and it's either '[' or '{', align to the opening paren's
+            ;; position. Otherwise, align its line's anchor.
+            (if (and (memq (char-after) '(?\[ ?{))
+                     (not (save-excursion (forward-char) (nix-smie--eol-p))))
+                (current-column)
+             (nix-smie--anchor)))
         (scan-error nil)))))
 
 (defun nix-smie--indent-exps ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]