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

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

[nongnu] elpa/sweeprolog 10516034be 061/166: ADDED: sweep-indent-line, a


From: ELPA Syncer
Subject: [nongnu] elpa/sweeprolog 10516034be 061/166: ADDED: sweep-indent-line, an indent-line-function for sweep-mode
Date: Fri, 30 Sep 2022 04:59:26 -0400 (EDT)

branch: elpa/sweeprolog
commit 10516034be4c2db4a03754aa9de8a1c0f61808ec
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>

    ADDED: sweep-indent-line, an indent-line-function for sweep-mode
---
 sweep.el | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 sweep.pl |  3 ++-
 2 files changed, 96 insertions(+), 1 deletion(-)

diff --git a/sweep.el b/sweep.el
index 48309a2434..46ea566ba4 100644
--- a/sweep.el
+++ b/sweep.el
@@ -820,6 +820,99 @@ Interactively, a prefix arg means to prompt for BUFFER."
   :doc "Keymap for `sweep-mode'."
   "C-c C-c" #'sweep-colourise-buffer)
 
+(defun sweep-indent-line ()
+  (interactive)
+  (when-let ((ppss (syntax-ppss))
+             (pos (- (point-max) (point)))
+             (indent (sweep-indent-line-indentation ppss)))
+    (back-to-indentation)
+    (if (= indent (current-column))
+        'noindent
+      (beginning-of-line)
+      (combine-after-change-calls
+        (delete-horizontal-space)
+        (insert (make-string indent ? )))
+      (if (> (- (point-max) pos) (point))
+          (goto-char (- (point-max) pos))))))
+
+(defun sweep-indent-line-indentation (ppss)
+  (save-match-data
+    (save-excursion
+      (beginning-of-line)
+      (re-search-backward (rx bol (zero-or-more (not "\n")) graph 
(zero-or-more (not "\n"))) nil t)
+      (cond
+       ((sweep-indent-line-ends-with-comment-or-string-p) 0)
+       ((sweep-indent-line-ends-with-fullstop-p)          0)
+       ((sweep-indent-line-ends-with-if))
+       ((sweep-indent-line-ends-with-then ppss))
+       ((sweep-indent-line-ends-with-else ppss))
+       ((sweep-indent-line-ends-with-arg ppss))
+       ((sweep-indent-line-ends-with-neck-p)              4)
+       (t (sweep-indent-line-fallback))))))
+
+(defun sweep-indent-line-fallback ()
+  (save-excursion
+    (back-to-indentation)
+    (current-column)))
+
+(defun sweep-indent-line-ends-with-if ()
+  (save-excursion
+    (end-of-line)
+    (when-let ((start-of-ite (nth 1 (syntax-ppss))))
+      (when (<= (pos-bol) start-of-ite)
+        (goto-char start-of-ite)
+        (let ((col (current-column)))
+          (when (looking-at-p (rx "(   "))
+            col))))))
+
+(defun sweep-indent-line-ends-with-then (ppss)
+  (save-excursion
+    (when-let ((orig (nth 1 ppss))
+               (start-of-ite (nth 1 (syntax-ppss))))
+      (when (= start-of-ite orig)
+        (back-to-indentation)
+        (let ((col (current-column)))
+          (when (looking-at-p (rx "->  "))
+            col))))))
+
+(defun sweep-indent-line-ends-with-else (ppss)
+  (save-excursion
+    (when-let ((orig (nth 1 ppss))
+               (start-of-ite (nth 1 (syntax-ppss))))
+      (when (= start-of-ite orig)
+        (back-to-indentation)
+        (let ((col (current-column)))
+          (when (looking-at-p (rx ";   "))
+            col))))))
+
+(defun sweep-indent-line-ends-with-arg (ppss)
+  (save-excursion
+    (end-of-line)
+    (when-let ((orig (nth 1 ppss))
+               (start-of-ite (nth 1 (syntax-ppss))))
+      (when (= start-of-ite orig)
+        (goto-char start-of-ite)
+        (forward-char 1)
+        (skip-syntax-forward " ")
+        (current-column)))))
+
+(defun sweep-indent-line-ends-with-neck-p ()
+  (save-excursion
+    (looking-at-p (rx (zero-or-more (not "\n"))
+                      (or ":-" "=>" "-->")
+                      (zero-or-more blank)
+                      eol))))
+
+(defun sweep-indent-line-ends-with-comment-or-string-p ()
+  (save-excursion
+    (end-of-line)
+    (nth 8 (syntax-ppss))))
+
+(defun sweep-indent-line-ends-with-fullstop-p ()
+  (save-excursion
+    (end-of-line)
+    (= ?. (preceding-char))))
+
 (defun sweep-syntax-propertize (start end)
   (goto-char start)
   (let ((case-fold-search nil))
@@ -840,6 +933,7 @@ Interactively, a prefix arg means to prompt for BUFFER."
   (setq-local beginning-of-defun-function #'sweep-beginning-of-top-term)
   (setq-local end-of-defun-function #'sweep-end-of-top-term)
   (setq-local syntax-propertize-function #'sweep-syntax-propertize)
+  (setq-local indent-line-function #'sweep-indent-line)
   (setq-local font-lock-defaults
               '(nil
                 nil
diff --git a/sweep.pl b/sweep.pl
index 6901b5998b..0a475effb9 100644
--- a/sweep.pl
+++ b/sweep.pl
@@ -159,6 +159,7 @@ sweep_module_path(ModuleName, Path) :-
     sweep_module_path_(Module, Path0),
     atom_string(Path0, Path).
 
+
 sweep_module_path_(Module, Path) :-
     module_property(Module, file(Path)), !.
 sweep_module_path_(Module, Path) :-
@@ -289,7 +290,7 @@ sweep_color_normalized(Offset, Col, Nom) :-
     Col =.. [Nom0|Rest],
     sweep_color_normalized_(Offset, Nom0, Rest, Nom).
 
-sweep_color_normalized_(Offset, Goal0, [Kind0,Head|_], [Goal,Kind,F,N]) :-
+sweep_color_normalized_(_, Goal0, [Kind0,Head|_], [Goal,Kind,F,N]) :-
     sweep_color_goal(Goal0),
     !,
     atom_string(Goal0, Goal),



reply via email to

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