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

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

[nongnu] elpa/scala-mode 7113976 059/217: Indenting for multi-line strin


From: ELPA Syncer
Subject: [nongnu] elpa/scala-mode 7113976 059/217: Indenting for multi-line strings with margin, fixed row comment indent
Date: Sun, 29 Aug 2021 11:30:43 -0400 (EDT)

branch: elpa/scala-mode
commit 7113976a0e3c0d7961439359663339aa01f79561
Author: Heikki Vesalainen <heikkivesalainen@yahoo.com>
Commit: Heikki Vesalainen <heikkivesalainen@yahoo.com>

    Indenting for multi-line strings with margin, fixed row comment indent
---
 README.md            |  1 -
 scala-mode-indent.el | 36 ++++++++++++++++++++++++++----------
 scala-mode-syntax.el |  1 +
 3 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/README.md b/README.md
index 6593f82..080456f 100644
--- a/README.md
+++ b/README.md
@@ -325,7 +325,6 @@ customization variable *frame-background-mode* to *dark* 
(use **M-x**
   multiple lines
 - beginning-of-defun, end-of-defun
 - indent case, etc after they are typed (use first space as self-insert-hook)
-- indent multi-line strings with margin correctly
 - movement commands to move to previous or next definition (val,
   var, def, class, trait, object)
 - highlight headings and annotations inside scaladoc specially (use
diff --git a/scala-mode-indent.el b/scala-mode-indent.el
index 47772d7..1e656e1 100644
--- a/scala-mode-indent.el
+++ b/scala-mode-indent.el
@@ -662,20 +662,25 @@ anchored at 'anchor'."
            (goto-char anchor)
            ;; find =
            (scala-syntax:has-char-before ?= start))
-         (message "=")
+;         (message "=")
          scala-indent:step)
         (t
 ;         (message "normal at %d" (current-column))
          0)))
 
-(defun scala-indent:goto-line-comment-anchor (&optional pos)
+(defun scala-indent:goto-line-comment-anchor (&optional point)
   "Goto and return the position relative to which a line comment
 will be indented. This will be the start of the line-comment on
 previous line, if any."
-  (if (and (looking-at "\\s *//")
-           (forward-comment -1))
-      (point)))
-      
+  (let ((pos (point)))
+    (when (save-excursion
+            (when point (goto-char point))
+            (when (and (looking-at "\\s *//")
+                       (not (scala-syntax:looking-back-empty-line-p))
+                       (forward-comment -1))
+              (setq pos (point))))
+      (goto-char pos))))
+    
 ;;;
 ;;; Indentation engine
 ;;;
@@ -686,6 +691,7 @@ the sum of the value and the respective indent step, or nil 
if
 nothing was applied."
   (when rule-indents
     (save-excursion
+      (when point (goto-char point))
       (let* ((pos (scala-syntax:beginning-of-code-line))
              (rule-indent (car rule-indents))
              (rule-statement (car rule-indent))
@@ -694,7 +700,7 @@ nothing was applied."
         (if anchor
             (progn 
               (if scala-mode:debug-messages
-                  (message "indenting acording to %s at %d" rule-statement 
anchor))
+                  (message "indenting acording to %s at %d for pos %d for 
point %s" rule-statement anchor pos point))
               (when (/= anchor (point))
                 (error (format "Assertion error: anchor=%d, point=%d" anchor 
(point))))
               (+ (current-column)
@@ -748,9 +754,19 @@ strings"
   (let ((state (save-excursion (syntax-ppss (line-beginning-position)))))
     (if (not (nth 8 state)) ;; 8 = start pos of comment or string, nil if none
         (scala-indent:indent-code-line strategy)
-      (if (integerp (nth 4 state)) ;; 4 = nesting level of comment for scaladoc
-          (scala-indent:indent-line-to (scala-indent:scaladoc-indent (nth 8 
state)))
-        (scala-indent:indent-line-to (current-indentation))))))
+      (scala-indent:indent-line-to 
+       (cond ((integerp (nth 4 state))    ;; 4 = nesting level of multi-line 
comment
+              (scala-indent:scaladoc-indent (nth 8 state)))
+             ((eq t (nth 3 state))   ;; 3 = t for multi-line string
+              (or (save-excursion
+                    (beginning-of-line)
+                    (when (and (looking-at "\\s *|")
+                               (progn (goto-char (nth 8 state))
+                                      (looking-at "\\(\"\"\"\\)|")))
+                      (goto-char (match-end 1))
+                      (current-column)))
+                  (current-indentation)))
+             (t (current-indentation)))))))
 
 (defun scala-indent:indent-with-reluctant-strategy ()
   (interactive)
diff --git a/scala-mode-syntax.el b/scala-mode-syntax.el
index 6ef3099..27b5f30 100644
--- a/scala-mode-syntax.el
+++ b/scala-mode-syntax.el
@@ -613,6 +613,7 @@ stableId"
 (defun scala-syntax:skip-forward-ignorable ()
   "Moves forward over ignorable whitespace and comments. A 
 completely empty line is not ignorable and will not be mobed over."
+  (interactive)
   (save-match-data
     (while (and (not (scala-syntax:looking-at-empty-line-p))
                 (forward-comment 1)))



reply via email to

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