Skip to content

Introduce scala-indent:defition-parameter-scaling-factor v2 #195

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,26 @@ val xs = for (i <- 1 to 10)
yield i
```

### Extra indentation for method or class declarations

Provided by `scala-indent:scala-indent:defition-parameter-scaling-factor`

When this variable is set to `2` (or any integer, default: 1) indention for method and class
decloration `scala-indent:step` multiply by `2` as:

```scala
case class Foo(
x: String,
y: Int
)

def foo(
x: String,
y: Int
): Unit
```


## Prettify-Symbols

Scala-mode has a preconfigured list of prettify-symbols rules. The
Expand Down
11 changes: 11 additions & 0 deletions scala-mode-indent.el
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ indentation will be one or two steps depending on context."
:safe #'integerp
:group 'scala)

(defcustom scala-indent:defition-parameter-scaling-factor 1
"Scale the number of spaces used to indent the parameter list
of class/function definitions. See also
https://github.com/hvesalai/emacs-scala-mode/issues/172"
:type 'integer
:safe #'integerp
:group 'scala)

(defcustom scala-indent:indent-value-expression nil
"Whether or not to indent multi-line value expressions, with
one extra step. When true, indenting will be
Expand Down Expand Up @@ -629,6 +637,9 @@ anchor for calculating block indent for current point (or point
(> (line-number-at-pos) (line-number-at-pos anchor))
(> start (match-beginning 0))))
(+ (* 2 scala-indent:step) lead))
;; optionally multiplies the step for parameter list
((scala-syntax:in-definition-parameter-list-p anchor start)
(+ (* scala-indent:defition-parameter-scaling-factor scala-indent:step) lead))
;; normal block line
(t (+ scala-indent:step lead)))))

Expand Down
11 changes: 11 additions & 0 deletions scala-mode-syntax.el
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,17 @@ stableId"
(forward-line -1)
(looking-at-p scala-syntax:empty-line-re))))

(defun scala-syntax:in-definition-parameter-list-p (anchor start)
"Return t if the (anchor, start) region is the parameter list
of a definition(class or def)"
(save-excursion
(goto-char (or (nth 1 (syntax-ppss start)) 0))
(while (or (looking-at-p "\(")
(looking-at-p "\\["))
(backward-sexp))
(backward-sexp)
(looking-at-p "class\\|def")))

(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."
Expand Down