From b768f80498f9e9174eb6fa3e3aae5f45c5b21318 Mon Sep 17 00:00:00 2001 From: Josef Vlach Date: Sun, 31 May 2020 14:34:28 +0100 Subject: [PATCH] Fix the match block indentation so indent of elif, else still works --- gdscript-indent-and-nav.el | 21 +++++++++++++++------ gdscript-rx.el | 7 ++++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/gdscript-indent-and-nav.el b/gdscript-indent-and-nav.el index 5f39513..6803a4f 100644 --- a/gdscript-indent-and-nav.el +++ b/gdscript-indent-and-nav.el @@ -708,9 +708,7 @@ likely an invalid gdscript file." (goto-char dedenter-pos) (let* ((cur-line (line-beginning-position)) (pairs '(("elif" "elif" "if") - ("else" "if" "elif" "except" "for" "while") - ("except" "except" "try") - ("finally" "else" "except" "try"))) + ("else" "if" "elif"))) (dedenter (match-string-no-properties 0)) (possible-opening-blocks (cdr (assoc-string dedenter pairs))) (collected-indentations) @@ -718,7 +716,16 @@ likely an invalid gdscript file." (catch 'exit (while (gdscript-nav--syntactically (lambda () - (re-search-backward (gdscript-rx block-start) nil t)) + (re-search-backward (gdscript-rx block-start) nil t) + ;; At this point `(match-string-no-properties 0)' doesn't match whole gdscript's block expression, + ;; due to how `re-search-backward' works. + ;; To make `(match-string-no-properties 0)' match whole gdscript's block expression + ;; let's use `re-search-forward' from beginning of a line. + (beginning-of-line) + (re-search-forward (gdscript-rx block-start) nil t) + ;; And let's put point at the beginning of the match. + (beginning-of-line) + t) #'<) (let ((indentation (current-indentation))) (when (and (not (memq indentation collected-indentations)) @@ -741,8 +748,10 @@ likely an invalid gdscript file." no-back-indent))) (setq collected-indentations (cons indentation collected-indentations)) - (when (member (match-string-no-properties 0) - possible-opening-blocks) + (when + (seq-contains possible-opening-blocks + (string-trim (match-string-no-properties 0)) + (lambda (elt e) (string-prefix-p e elt))) (setq opening-blocks (cons (point) opening-blocks)))) (when (zerop indentation) (throw 'exit nil))))) diff --git a/gdscript-rx.el b/gdscript-rx.el index c3942b2..4193b06 100644 --- a/gdscript-rx.el +++ b/gdscript-rx.el @@ -1445,9 +1445,10 @@ following constructs: (defmacro gdscript-rx (&rest regexps) "Gdscript mode specialized rx macro. This variant of `rx' supports common Gdscript named REGEXPS." - `(gdscript-rx-let ((block-start (seq symbol-start - (or "func" "class" "if" "elif" "else" "for" "while" "match") - symbol-end)) + `(gdscript-rx-let ((block-start (seq (zero-or-more nonl) + ":" + (or (seq (zero-or-more " ") eol) + (seq (zero-or-more " ") "#" (zero-or-more nonl) eol)))) (dedenter (seq symbol-start (or "elif" "else") symbol-end))