[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/poke-mode e82e106625 1/3: Improve indentation of IF sta
From: |
ELPA Syncer |
Subject: |
[elpa] externals/poke-mode e82e106625 1/3: Improve indentation of IF statements |
Date: |
Sun, 10 Apr 2022 16:57:50 -0400 (EDT) |
branch: externals/poke-mode
commit e82e106625650452045eaaf4d815baf54391a952
Author: Jose E. Marchesi <jose.marchesi@oracle.com>
Commit: Jose E. Marchesi <jose.marchesi@oracle.com>
Improve indentation of IF statements
---
poke-mode.el | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 54 insertions(+), 2 deletions(-)
diff --git a/poke-mode.el b/poke-mode.el
index 411ce49ea3..413662a41a 100644
--- a/poke-mode.el
+++ b/poke-mode.el
@@ -283,13 +283,41 @@
(stmt (comp-stmt)
(id "=" exp)
("return" exp)
- ("if" stmt "else" stmt)
+ ("if" "if-(" exp "if-)" stmt "else" stmt)
(exp))
(stmts (stmts ";" stmts) (stmt)))
'((assoc ";") (assoc ",")
(assoc "+") (assoc "-")))))
+(defvar poke--smie-in-if-op nil)
+
(defun poke--smie-forward-token ()
+ (let ((case-fold-search nil)
+ (token (smie-default-forward-token)))
+ (cond
+ ;; Handle if-(
+ ((and (or (equal token "") (not token)) (looking-at "("))
+ (when (looking-back "if[ \t\n]*")
+ (forward-char 1)
+ "if-("))
+ ;; Handle if-)
+ ((and (or (equal token "") (not token))
+ (not poke--smie-in-if-op) (looking-at ")"))
+ (condition-case nil
+ (when (save-excursion
+ (forward-char 1)
+ (setq poke--smie-in-if-op t)
+ (backward-sexp)
+ (setq poke--smie-in-if-op nil)
+ (looking-back "if[ \t\n]*"))
+ (forward-char 1)
+ "if-)")
+ (scan-error
+ (setq poke--smie-in-if-op nil)
+ nil)))
+ (t
+ token))))
+
;; FIXME:
;; Don't merge ":" or ";" with some preceding punctuation such as ">".
(smie-default-forward-token))
@@ -301,7 +329,31 @@
((memq (char-before) '(?: ?\;))
(forward-char -1)
(string (char-after)))
- (t (smie-default-backward-token))))
+ (t
+ (let ((case-fold-search nil)
+ (token (smie-default-backward-token)))
+ (cond
+ ;; Handle if-(
+ ((and (or (equal token "") (not token)) (looking-back "if[ \t\n]*("))
+ (setq poke--smie-if-op (point))
+ (forward-char -1)
+ "if-(")
+ ;; Handle if-)
+ ((and (or (equal token "") (not token))
+ (not poke--smie-in-if-op) (looking-back ")"))
+ (condition-case nil
+ (when (save-excursion
+ (setq poke--smie-in-if-op t)
+ (backward-sexp)
+ (setq poke--smie-in-if-op nil)
+ (looking-back "if[ \t\n]*"))
+ (forward-char -1)
+ "if-)")
+ (scan-error
+ (setq poke--smie-in-if-op nil)
+ nil)))
+ (t
+ token))))))
(defun poke-smie-rules (token kind)
(pcase (cons token kind)