[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/raku-mode 0c480bb357 238/253: Hanging assignment support
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/raku-mode 0c480bb357 238/253: Hanging assignment support |
Date: |
Sat, 29 Jan 2022 08:29:02 -0500 (EST) |
branch: elpa/raku-mode
commit 0c480bb3570bf68f9a845c45f184da738d432c3f
Author: Roman Hargrave <roman@hargrave.info>
Commit: Roman Hargrave <roman@hargrave.info>
Hanging assignment support
---
raku-indent.el | 118 +++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 85 insertions(+), 33 deletions(-)
diff --git a/raku-indent.el b/raku-indent.el
index 517fceaa38..fa600f7426 100644
--- a/raku-indent.el
+++ b/raku-indent.el
@@ -11,7 +11,8 @@
(defconst raku-smie-grammar
(smie-prec2->grammar
- (smie-precs->prec2 '((assoc ";") (assoc ",") (left ":")))))
+ (smie-precs->prec2
+ '((assoc ";") (assoc "=") (assoc ",") (left ":")))))
(defcustom raku-indent-offset 4
"Basic size of one indentation step."
@@ -19,48 +20,99 @@
:group 'raku)
(defun raku-smie--not-interpolation-p ()
- (save-excursion
- (forward-char -1)
- (or (zerop (skip-chars-backward "-[:alnum:]"))
- (not (looking-back "#{\\$" (- (point) 3))))))
+ (save-excursion ;; Prepare for excursion
+ (forward-char -1) ;; Retreat one char
+
+ (or
+ ;; Backtrack til we hit something that _isn't_ alnum
+ ;; If we did not backtrack, we're not in interpolation
+ (zerop (skip-chars-backward "-[:alnum:]"))
+
+ ;; If we did backtrack, see if #{\$ (EOL) occurs three
+ ;; or more characters prior to point (??????????)
+ ;; if this does NOT match, we are not in an interpolation
+ (not (looking-back "#{\\$" (- (point) 3))))))
(defun raku-smie--forward-token ()
(cond
- ((and (eq (char-before) ?\})
- (raku-smie--not-interpolation-p)
- ;; FIXME: If the next char is not whitespace, what should we do?
- (or (memq (char-after) '(?\s ?\t ?\n))
- (looking-at comment-start-skip)))
- (if (memq (char-after) '(?\s ?\t ?\n))
- (forward-char 1) (forward-comment 1))
- ";")
- ((progn (forward-comment (point-max))
- (looking-at "[;,:]"))
- (forward-char 1) (match-string 0))
- (t (smie-default-forward-token))))
+ ((progn
+ ;; (message "frwd char-before=`%c` char-after=`%c` point=%s"
(char-before) (char-after) (point))
+ nil) nil)
+
+ ;; Return `;` to fudge end-of-block indentation (I think), as ; is optional
after a block
+ ((and (eq (char-before) ?\}) ;; Character immediately prior
to point is `}`
+ (raku-smie--not-interpolation-p) ;; And, not in an interpolation
+ ;; FIXME: If the next char is not whitespace, what should we do?
+ (or (memq (char-after) '(?\s ?\t ?\n)) ;; And, point is followed by
\s, \t, or \n
+ (looking-at comment-start-skip))) ;; or point is looking-at
/#+ */
+
+ (if (memq (char-after) '(?\s ?\t ?\n)) ;; If the above is true, and
point is followed by /[\s\t\n]/
+ (forward-char 1) (forward-comment 1)) ;; Then, advance by one
character, and one whole comment
+
+ (message "forward cond#1")
+ ";")
+
+ ((eq (char-after) ?\=) ;; Spit out '=' to kick off
proper indentation for hanging assignment
+ (forward-char 1)
+ "=")
+
+ ((progn (forward-comment (point-max)) ;; Read past ALL comments
+ (looking-at "[;,:]")) ;; Are we looking at ; , or :
+
+ (forward-char 1) ;; If so, advance one character
+ (match-string 0)) ;; And then return whatever
looking-at found (?)
+
+ (t (smie-default-forward-token)))) ;; If none of the above
matched, defer to SMIE default search
(defun raku-smie--backward-token ()
(let ((pos (point)))
- (forward-comment (- (point)))
+ (forward-comment (- (point))) ;; Retreate past ALL comments
up to point
+ ;; (message "back char-before=`%c` char-after=`%c` point=%s" (char-before)
(char-after) (point))
(cond
;; FIXME: If the next char is not whitespace, what should we do?
- ((and (eq (char-before) ?\}) (raku-smie--not-interpolation-p)
- (> pos (point))) ";")
- ((memq (char-before) '(?\; ?\, ?\:))
- (forward-char -1) (string (char-after)))
- (t (smie-default-backward-token)))))
+ ;; Cond #1 - Same end-of-block hack, I think
+ ((and (eq (char-before) ?\}) ;; Point is preceded
immediately by `}`
+ (raku-smie--not-interpolation-p) ;; And, not in an interpolation
+ (> pos (point))) ;; And, point has moved
backward
+
+ ";") ;; If so, yield ';'
+
+ ((eq (char-before) ?\=)
+ (forward-char -1)
+ "=")
+
+ ;; Cond #2 - Get whatever precedes [,:;]
+ ((memq (char-before) '(?\; ?\, ?\:)) ;; Point is preceded
immediately by `;`, `,`, or `:`
+ (forward-char -1) ;; Retreat one char
+ (string (char-after))) ;; Return char after point
(the char we just retreated past)
+
+ (t (smie-default-backward-token))))) ;; If none of the above
matched, defer to SMIE default search
(defun raku-smie-rules (kind token)
- (pcase (cons kind token)
- (`(:elem . basic) raku-indent-offset)
- (`(:elem . arg) 0)
- (`(:list-intro . ,(or `";" `"")) t) ;"" stands for BOB (bug#15467).
- (`(:before . "{")
- (when (smie-rule-hanging-p)
- (smie-backward-sexp ";")
- (smie-indent-virtual)))
- (`(:before . ,(or "{" "("))
- (if (smie-rule-hanging-p) (smie-rule-parent 0)))))
+ (progn
+ ;; (message "%S (point: %s)" (cons kind token) (point))
+ (pcase (cons kind token)
+ ;; Basic indent offset
+ (`(:elem . basic) raku-indent-offset)
+
+ ;; Indent offset for function args
+ (`(:elem . arg) 0)
+
+ (`(:list-intro . ,(or `";" `"")) t) ;"" stands for BOB (bug#15467).
+
+ ;; Make sure that hanging assignment gets indented
+ (`(:before . "=")
+ (if (smie-rule-hanging-p)
+ (smie-rule-parent raku-indent-offset)))
+
+ (`(:before . "{")
+ (when (smie-rule-hanging-p) ; is `{` the last thing on this line?
+ (smie-backward-sexp ";") ; y tho
+ (smie-indent-virtual)))
+
+ (`(:before . ,(or "{" "("))
+ (if (smie-rule-hanging-p)
+ (smie-rule-parent 0))))))
(provide 'raku-indent)
- [nongnu] elpa/raku-mode 20610a83b5 247/253: Merge pull request #53 from phikal/master, (continued)
- [nongnu] elpa/raku-mode 20610a83b5 247/253: Merge pull request #53 from phikal/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode fd286b2d1a 246/253: Remove pkg-info dependency, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode a316c3f195 240/253: Remove leftover debugging garbage, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 7dfe01182d 080/253: Highlight reduce operators, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 57a25ccadd 142/253: Remove commented code I accidentally left in, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 7322d74a5d 169/253: Changing to my copy of cask, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode b6cca3307b 203/253: Merge pull request #25 from matiaslina/repl, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode d474216840 223/253: Merge pull request #34 from hlissner/fix-autoloads, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode e4d8b0230a 218/253: Merge pull request #31 from tmtvl/add-raku-to-languages-customization-group, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 77afbe21fe 232/253: Merge pull request #40 from Lenin1917/path-1, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 0c480bb357 238/253: Hanging assignment support,
ELPA Syncer <=
- [nongnu] elpa/raku-mode 4ee9045eeb 252/253: Bump version to have an update without pkg-info, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode d8811251af 244/253: Update changelog for v0.2.0, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 5b47a0b1a2 066/253: Deal with [-'] preceded by a non-ASII identifier character, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode bf7900b286 137/253: Merge pull request #4 from Altai-man/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 07b596cab6 151/253: one more tweak to catch all forms of subs, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode fe2d579dfb 132/253: Indentation fix, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode c353cb2b74 208/253: Add perl6 defalias, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 0aae9be202 213/253: Update the default path for the shebang line per @Altai-man's suggestion., ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode 460b477ba2 237/253: format README for keybindings, ELPA Syncer, 2022/01/29
- [nongnu] elpa/raku-mode fff97f7fb0 226/253: Raku variable names have precedence over operators, ELPA Syncer, 2022/01/29