[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/scala-mode c154f16 139/217: better join-line and fixup-whi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/scala-mode c154f16 139/217: better join-line and fixup-whitespace |
Date: |
Sun, 29 Aug 2021 11:31:00 -0400 (EDT) |
branch: elpa/scala-mode
commit c154f1623f4696d26e1c88d19170e67bf6825837
Author: Heikki Vesalainen <heikkivesalainen@yahoo.com>
Commit: Heikki Vesalainen <heikkivesalainen@yahoo.com>
better join-line and fixup-whitespace
---
README.md | 20 +++++++++--------
scala-mode2-indent.el | 61 ++++++++++++++++++++++++++++++---------------------
scala-mode2-map.el | 2 +-
scala-mode2.el | 4 ++++
4 files changed, 52 insertions(+), 35 deletions(-)
diff --git a/README.md b/README.md
index 1482bbd..9bd3b29 100644
--- a/README.md
+++ b/README.md
@@ -299,17 +299,19 @@ 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 (delete indentation)
+## Joinin lines (delete indentation) and removing horizontal whitespace
-Scala-mode defines its own *scala-indent:join-line' function. Besides
-doing what the normal *join-line* (aka *delete-indentation*) 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.
+Scala-mode defines its own *scala-indent:join-line* and
+*scala-indent:fixup-whitespace* functions.
-In scala-mode2 buffers *scala-indent:join-line* replaces
-*delete-indentation* in your key bindings. The default binding is
-**M-^**.
+Unlike the normal *join-line* (aka *delete-indentation*),
+*scala-indent:join-line* detects the comment fill-prefix and removes
+it.
+
+The *scala-indent:fixup-whitespace* first removes all horizontal
+whitespace, then adds one space the context requires none to be
+present (before semicolon, around dot, after '(' or '[', before ')' or
+']', etc).
## Motion
diff --git a/scala-mode2-indent.el b/scala-mode2-indent.el
index 3475f51..bb059f7 100644
--- a/scala-mode2-indent.el
+++ b/scala-mode2-indent.el
@@ -801,7 +801,7 @@ strings"
(defun scala-indent:indent-line (&optional strategy)
"Indents the current line."
- (interactive)
+ (interactive "*")
(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)
@@ -820,7 +820,7 @@ strings"
(t (current-indentation)))))))
(defun scala-indent:indent-with-reluctant-strategy ()
- (interactive)
+ (interactive "*")
(scala-indent:indent-line scala-indent:reluctant-strategy))
(defun scala-indent:scaladoc-indent (comment-start-pos)
@@ -917,28 +917,39 @@ 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
- (or (= (char-before) ?.)
- (= (char-after (1+ (point))) ?.)
- (= (char-after (1+ (point))) ?:)))
- (delete-horizontal-space)
- ))))
+
+(defun scala-indent:fixup-whitespace ()
+ "scala-mode2 version of `fixup-whitespace'"
+ (interactive "*")
+ (save-excursion
+ (delete-horizontal-space)
+ (if (or (looking-at "^\\|[]):.]")
+ (save-excursion (forward-char -1)
+ (if (nth 4 (syntax-ppss))
+ (looking-at "$\\|\\s(")
+ (looking-at "$\\|[[(.]")))
+ (and (= (char-before) ?{) (= (char-after) ?})))
+ nil
+ (insert ?\s))))
+
+(defun scala-indent:join-line (&optional arg)
+ "scala-mode2 version of `join-line', i.e. `delete-indentation'"
+ (interactive "*P")
+ (beginning-of-line)
+ (if arg (forward-line 1))
+ (when (= (preceding-char) ?\n)
+ (delete-region (point) (1- (point)))
+ (delete-horizontal-space)
+ (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))
+ ((and (nth 4 state) ; row comment (i.e. with //)
+ (looking-at " //"))
+ (delete-forward-char 3))))
+ (scala-indent:fixup-whitespace)))
(provide 'scala-mode2-indent)
diff --git a/scala-mode2-map.el b/scala-mode2-map.el
index 78a847b..70e3ae4 100644
--- a/scala-mode2-map.el
+++ b/scala-mode2-map.el
@@ -7,7 +7,7 @@
(defvar scala-mode-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map prog-mode-map)
- (substitute-key-definition 'delete-indentation 'scala-indent:join-line map
global-map)
+ ;(substitute-key-definition 'delete-indentation 'scala-indent:join-line
map global-map)
map)
"Local key map used for scala mode")
diff --git a/scala-mode2.el b/scala-mode2.el
index ff25e5e..efe2a68 100644
--- a/scala-mode2.el
+++ b/scala-mode2.el
@@ -106,6 +106,8 @@ When started, runs `scala-mode-hook'.
'forward-sexp-function
'find-tag-default-function
'indent-line-function
+ 'fixup-whitespace
+ 'delete-indentation
'indent-tabs-mode)
(add-hook 'syntax-propertize-extend-region-functions
@@ -137,6 +139,8 @@ When started, runs `scala-mode-hook'.
forward-sexp-function 'scala-mode:forward-sexp-function
find-tag-default-function 'scala-mode:find-tag
indent-line-function 'scala-indent:indent-line
+ fixup-whitespace 'scala-indent:fixup-whitespace
+ delete-indentation 'scala-indent:join-line
indent-tabs-mode nil
)
(use-local-map scala-mode-map)
- [nongnu] elpa/scala-mode 2201b1c 092/217: Interact nicely with global-font-lock-mode., (continued)
- [nongnu] elpa/scala-mode 2201b1c 092/217: Interact nicely with global-font-lock-mode., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 98d22a5 099/217: Added programming languages to README.md code, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 453c012 106/217: fixed bug in string escapes marking, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 6116127 042/217: Updated README.md, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 11a710d 044/217: Correct annotation highlighting., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 49bd528 045/217: working on README, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode d357a77 038/217: New 'scala-indent:align-parameters' customization variable, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode af0e387 053/217: Fixes #18: highlight escapes in strings after chars, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode bc446e7 120/217: sbt support is now in sbt-mode, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 597d421 145/217: Seems the imenu var needs to be set in a very local way., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode c154f16 139/217: better join-line and fixup-whitespace,
ELPA Syncer <=
- [nongnu] elpa/scala-mode e277378 143/217: WIP on end-of-defun and beggining of defun which should make writing imenu functionality much easier., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 811494f 155/217: Support nesting of classes in imenu index creation function., ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode d4885ac 159/217: Use [[:space:]] instead of literal space in syntax end/beggining of, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode c5ab657 160/217: Merge pull request #82 from IvanMalison/support_imenu, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode b8e835f 161/217: scala-mode:goto-start-of-code close #90, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode e8c8a51 169/217: Couple imenu-related issues (#95), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 3989897 174/217: bump version (#111), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 360b5ba 162/217: Merge pull request #92 from fommil/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode 387e93c 178/217: revert 618f0fbef4d3d94156f834a66e36c79f07a54e02, fixes #118 (#119), ELPA Syncer, 2021/08/29
- [nongnu] elpa/scala-mode c71efcc 188/217: quoteids are now propertized as symbols (#137), ELPA Syncer, 2021/08/29