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

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

[nongnu] elpa/scala-mode 763c93c 107/217: scala-indent:join-line


From: ELPA Syncer
Subject: [nongnu] elpa/scala-mode 763c93c 107/217: scala-indent:join-line
Date: Sun, 29 Aug 2021 11:30:53 -0400 (EDT)

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

    scala-indent:join-line
---
 README.md             | 13 ++++++++++---
 scala-mode2-indent.el | 28 +++++++++++++++++++++++++---
 scala-mode2.el        |  4 +++-
 3 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/README.md b/README.md
index 4f02bc9..2189b32 100644
--- a/README.md
+++ b/README.md
@@ -274,6 +274,13 @@ To re-fill a paragraph, use the *fill-paragraph* command ( 
**M-q**
 command. To set the default, you use the *customize-variable* command
 or a mode-hook.
 
+## Joinin lines
+
+Scala-mode defines its own join-line function. Besides doing what the
+normal join-line function does, it also removes comment marks
+(asterisks and slashes) when comment lines are joined and space when
+code lines are joined and the uppper line ended with a dot.
+
 ## Motion
 
 Basic emacs motion will work as expected.
@@ -313,12 +320,12 @@ you may want to try. Just copy-paste it to your `.emacs` 
file.
   ;;   (newline-and-indent)
   ;;   (scala-indent:insert-asterisk-on-multiline-comment)))
 
-  ;; Bind the 'join-line' command to C-M-j. This command is normally
+  ;; Bind the 'join-line' command to M-RET. This command is normally
   ;; bound to M-^ which is hard to access, especially on some European
   ;; keyboards. The 'join-line' command has the effect or joining the
   ;; current line with the previous while fixing whitespace at the
-  ;; joint.
-  (local-set-key (kbd "C-M-j") 'join-line)
+  ;; joint. 
+  (local-set-key (kbd "M-RET") 'join-line)
 
   ;; Bind the backtab (shift tab) to
   ;; 'scala-indent:indent-with-reluctant-strategy command. This is usefull
diff --git a/scala-mode2-indent.el b/scala-mode2-indent.el
index cbaf176..af24925 100644
--- a/scala-mode2-indent.el
+++ b/scala-mode2-indent.el
@@ -642,7 +642,7 @@ with an opening parentheses, or nil if not."
 anchor for calculating opening parenthesis indent for the current
 point (or point 'point'). Returns point or nil, if line does not
 start with opening parenthesis."
-  ;; There are four cases we need to consider:
+  ;; There are five cases we need to consider:
   ;; 1. curry parentheses, i.e. 2..n parentheses groups.
   ;; 2. value body parentheses (follows '=').
   ;; 3. parameters, etc on separate line (who would be so mad?)
@@ -883,8 +883,8 @@ the line."
 (defun scala-indent:insert-asterisk-on-multiline-comment ()
   "Insert an asterisk at the end of the current line when at the beginning
 of a line inside a multi-line comment "
-  (let ((state (syntax-ppss))
-        (comment-start-pos (nth 8 (syntax-ppss))))
+  (let* ((state (syntax-ppss))
+         (comment-start-pos (nth 8 state)))
     (when (and (integerp (nth 4 state))
                ; Ensure that we're inside a scaladoc comment
                (string-match-p "^/\\*\\*[^\\*]"
@@ -905,4 +905,26 @@ of a line inside a multi-line comment "
 (defun scala-mode:indent-scaladoc-asterisk (&optional insert-space-p)
   (message "scala-mode:indent-scaladoc-asterisk has been deprecated"))
 
+(defun scala-indent:join-line ()
+  (interactive)
+  (join-line)
+  (let ((state (syntax-ppss)))
+    (cond 
+     ((and (integerp (nth 4 state)) ; nestable comment (i.e. with *)
+           (looking-at " \\*")
+           (save-excursion (goto-char (max (nth 8 state) 
(line-beginning-position)))
+                           (looking-at "\\s */?\\*")))
+      (delete-forward-char 2)
+      (delete-horizontal-space)
+      (insert " "))
+     ((and (nth 4 state) ; row comment (i.e. with //)
+           (looking-at " //"))
+      (delete-forward-char 3)
+      (delete-horizontal-space)
+      (insert " "))
+     ((and (not (nth 8 (syntax-ppss))) ; not in comment or string
+           (= (char-before) ?.))
+      (delete-horizontal-space)
+      ))))
+
 (provide 'scala-mode2-indent)
diff --git a/scala-mode2.el b/scala-mode2.el
index c53765f..42f3b40 100644
--- a/scala-mode2.el
+++ b/scala-mode2.el
@@ -62,7 +62,8 @@ When started, runs `scala-mode-hook'.
    'comment-multi-line
    'forward-sexp-function
    'indent-line-function
-   'indent-tabs-mode)
+   'indent-tabs-mode
+   'join-line)
 
   (add-hook 'syntax-propertize-extend-region-functions
             'scala-syntax:propertize-extend-region)
@@ -93,6 +94,7 @@ When started, runs `scala-mode-hook'.
         forward-sexp-function           'scala-mode:forward-sexp-function
         indent-line-function            'scala-indent:indent-line
         indent-tabs-mode                nil
+        join-line                       'scala-indent:join-line
         )
   (use-local-map scala-mode-map)
   ;; add indent functionality to some characters



reply via email to

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