[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),
- [nongnu] elpa/sweeprolog c8192b8c31 145/166: DOC: document imenu support in sweep-mode buffers, (continued)
- [nongnu] elpa/sweeprolog c8192b8c31 145/166: DOC: document imenu support in sweep-mode buffers, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 6b9e2a7833 139/166: Tweak README to prevent a hosting platform from failing to render it, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 79bf5b78b8 042/166: Run `make check` with libswipl preloaded, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 97440dda21 043/166: DOC: update the manual to reflect the latest GMP deconflication, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 9466ce0d59 046/166: ADDED: completion-at-point function in sweep-top-level-mode, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 6e9ac379e6 047/166: DOC: Expand top-level documentation section, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 4ecc8ec55f 050/166: Add BSD license, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog a26ca14c81 053/166: ENHANCED: show more relevant candidates in top-level completion, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 7fa11fdcdd 055/166: FIXED: hide predicates starting with '$' in sweep-find-predicate, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog e70b4aef2f 057/166: ADDED: sweep-file-name-handler, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 10516034be 061/166: ADDED: sweep-indent-line, an indent-line-function for sweep-mode,
ELPA Syncer <=
- [nongnu] elpa/sweeprolog face064afa 062/166: ADDED: custom font-lock-fontify-region-function for sweep-mode, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 6363ddef3a 073/166: ADDED: implemented all xref backend callback functions, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 8dc9359dca 082/166: ADDED: sweep-set-prolog-flag for setting Prolog flags, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 0f86b23be9 080/166: ENHANCED: emit Prolog messages with color coding, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 1f4b1a6dcc 079/166: MODIFIED: use executable-find to locate the swipl executable..., ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog f772a136e4 081/166: DOC: fix typos, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 75ec7290be 096/166: ADDED: sweep-load-buffer, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 3717572348 091/166: FIXED: handle more missing color terms, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 1744b29cc2 092/166: FIXED: off by one in sweep-colourise-some-terms, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 16d1a380ab 122/166: FIXED: (sweep-beginning-of-top-term): possible infinite loop, ELPA Syncer, 2022/09/30