Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with aggressive-indent-mode #150

Open
Pitometsu opened this issue May 30, 2018 · 12 comments
Open

Incompatible with aggressive-indent-mode #150

Pitometsu opened this issue May 30, 2018 · 12 comments

Comments

@Pitometsu
Copy link

Malabarba/aggressive-indent-mode#116

scala-mode eat space symbols at the end of current line on imput when aggressive-indent-mode is enabled.
I suppose cause in scala-indent:indent-line.

@hvesalai
Copy link
Owner

If you have an idea about the exact location of the problem, would it be possible for you to make a PR that fixes it for your use case, but doesn't break it for others?

@Pitometsu
Copy link
Author

Well, maybe it's because of scala-indent:fixup-whitespace calling. I'm not sure. You right here: it should be customizable option.

@Pitometsu
Copy link
Author

Oh, I see, (scala-lib:delete-trailing-whitespace) in scala-indent:indent-code-line.

@Pitometsu
Copy link
Author

Pitometsu commented May 30, 2018

@hvesalai here's the simple fix:

1 file changed, 9 insertions(+), 2 deletions(-)
scala-mode-indent.el | 11 +++++++++--

modified   scala-mode-indent.el
@@ -125,6 +125,12 @@ when it is added to an empty line."
   :safe #'booleanp
   :group 'scala)
 
+(defcustom scala-indent:delete-trailing-whitespace t
+  "When non-nil, trailing whitespaces will be removed on indentation."
+  :type 'boolean
+  :safe #'booleanp
+  :group 'scala)
+
 (defcustom scala-indent:use-javadoc-style nil
   "When non-nil, multi-line comments are indented according to Javadoc
 style (i.e. indented to the first asterisk). This overrides the
@@ -799,9 +805,10 @@ strings"
     (if (eq last-command this-command)
         (scala-indent:toggle-effective-run-on-strategy)
       (scala-indent:reset-effective-run-on-strategy)))
 ;  (message "run-on-strategy is %s" (scala-indent:run-on-strategy))
   (scala-indent:indent-line-to (scala-indent:calculate-indent-for-line))
-  (scala-lib:delete-trailing-whitespace)
+  (when scala-indent:delete-trailing-whitespace
+    (scala-lib:delete-trailing-whitespace))
   (setq scala-indent:previous-indent-pos
         (save-excursion
           (beginning-of-line)

plz, add.

@Pitometsu
Copy link
Author

It's a dumb fix: it may have more complex behavior like keep deleting trailing whitespaces on all but current line.

@Pitometsu
Copy link
Author

Pitometsu commented May 31, 2018

@hvesalai more intelligent I'm sure should be more like this (not checked!):

1 file changed, 33 insertions(+), 5 deletions(-)
scala-mode-indent.el | 38 +++++++++++++++++++++++++++++++++-----

modified   scala-mode-indent.el
@@ -87,11 +87,11 @@ val x = if (foo)
   :group 'scala)
 
 (defconst scala-indent:eager-strategy 0
-  "See 'scala-indent:run-on-strategy'")
+  "See `scala-indent:run-on-strategy'")
 (defconst scala-indent:operator-strategy 1
-  "See 'scala-indent:run-on-strategy'")
+  "See `scala-indent:run-on-strategy'")
 (defconst scala-indent:reluctant-strategy 2
-  "See 'scala-indent:run-on-strategy'")
+  "See `scala-indent:run-on-strategy'")
 (defconst scala-indent:keywords-only-strategy 3
   "A strategy used internally by indent engine")
 
@@ -125,6 +125,28 @@ when it is added to an empty line."
   :safe #'booleanp
   :group 'scala)
 
+(defconst scala-indent:delete-trailing-whitespace-yes 1
+  "See `scala-indent:delete-trailing-whitespace'.")
+(defconst scala-indent:delete-trailing-whitespace-no 0
+  "See `scala-indent:delete-trailing-whitespace'.")
+(defconst scala-indent:delete-trailing-whitespace-smart -1
+  "See `scala-indent:delete-trailing-whitespace'.")
+
+(defcustom scala-indent:delete-trailing-whitespace scala-indent:delete-trailing-whitespace-yes
+  "Whether indentation keep trailing whitespaces.
+
+Possible values are:
+
+    Yes -- trailing whitespaces will be removed on indentation.
+    No -- all trailing whitespaces will be kept.
+    Smart -- trailing whitespaces will be removed on indentation for all lines except the current one."
+  :type `(choice (const :tag "Yes" ,scala-indent:delete-trailing-whitespace-yes)
+                 (const :tag "No" ,scala-indent:delete-trailing-whitespace-no)
+                 (const :tag "Smart" ,scala-indent:delete-trailing-whitespace-smart))
+  :group 'scala)
+
 (defcustom scala-indent:use-javadoc-style nil
   "When non-nil, multi-line comments are indented according to Javadoc
 style (i.e. indented to the first asterisk). This overrides the
@@ -799,9 +821,15 @@ strings"
     (if (eq last-command this-command)
         (scala-indent:toggle-effective-run-on-strategy)
       (scala-indent:reset-effective-run-on-strategy)))
-;  (message "run-on-strategy is %s" (scala-indent:run-on-strategy))
+  ;;  (message "run-on-strategy is %s" (scala-indent:run-on-strategy))
   (scala-indent:indent-line-to (scala-indent:calculate-indent-for-line))
-  (scala-lib:delete-trailing-whitespace)
+  (pcase scala-indent:delete-trailing-whitespace
+    (scala-indent:delete-trailing-whitespace-yes
+     (scala-lib:delete-trailing-whitespace))
+    (scala-indent:delete-trailing-whitespace-no t)
+    (scala-indent:delete-trailing-whitespace-smart
+     (when not-current-line
+       (scala-lib:delete-trailing-whitespace))))
   (setq scala-indent:previous-indent-pos
         (save-excursion
           (beginning-of-line)

@Pitometsu
Copy link
Author

But I have no clue, how to implement the not-current-line here..

@Pitometsu
Copy link
Author

Maybe we need custom indent-region-function for it.

@Pitometsu
Copy link
Author

Pitometsu commented May 31, 2018

And even in that case indent-region call 'indent-line-function or even 'indent-region-function inside save-excursion. Don't know how to get the original point from there without dirty hacks like advices on indent-region and line-number-at-pos saving in global scope...

@Pitometsu
Copy link
Author

@hvesalai ping. Would u merge it?

@Pitometsu
Copy link
Author

@hvesalai anybody here? :-)

NeQuissimus added a commit to NeQuissimus/emacs-scala-mode that referenced this issue Jun 7, 2019
@Antisune
Copy link

👍
This is a bug I encountered and was inconvenienced by too. Having a fix pulled in would be nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants