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

Special cases for add-space-for-scaladoc-asterisk #69

Closed
Toxaris opened this issue Apr 12, 2014 · 3 comments
Closed

Special cases for add-space-for-scaladoc-asterisk #69

Toxaris opened this issue Apr 12, 2014 · 3 comments

Comments

@Toxaris
Copy link
Contributor

Toxaris commented Apr 12, 2014

I use the default setting of scala-indent:add-space-for-scaladoc-asterisk to t, so when I press RET * in a ScalaDoc comment, a space is inserted automatically. This is great except for two situations:

  1. I press RET RET to add an empty line in a Scaladoc comment. In this case, I get something like " * \n" for the empty line, but I would prefer something like " *\n" without the trailing whitespace.
  2. I press RET * / RET to end the Scaladoc comment. In this case, I get something like " * /\n" for the intended last line of the comment, but I really need something like " */\n" to actually end the comment.
@hvesalai
Copy link
Owner

Hi,

For #1 you can use the newline-and-indent function, which removes any trailing whitespace from the line where you press RET (see README.md on how to do this)

If you insist on not using newline-and-indent, then you can have something like this:

(add-hook 'scala-mode-hook '(lambda ()
  (local-set-key (kbd "RET") '(lambda ()
                                (interactive)
                                (delete-horizontal-space t)
                                (newline) ;; or what ever you like)))

#2 is something that bothers me also. If you would like to make a pull request with a solution, I'd gladly review it.

You could start by looking how the scala-indent:indent-on-scaladoc-asterisk is registered in scala-mode2-map.el and how it is implemented in scala-mode2-indent.el. Then you can create a new function called scala-indent:fix-scaladoc-close that does something like the following:

  • check that you are inside a multiline comment (like the indent-on-scaladoc-asterisk does)
  • using looking-back check for the regexp "^\\s *\\*\\s /", ie. space, one asterisk, one space and /
  • if so, delete the space before the slash

@Toxaris
Copy link
Contributor Author

Toxaris commented Apr 12, 2014

Thanks for the hint for (1), I followed the readme and I'm happy about my more powerful RET so far.

I started to look into the implementation of (2), but I'm concerned about what happens if a line in a comment starts with /. For example:

 /** some text
   * {{{
   * // a comment in a code snippet in a comment in a code snippet in a comment on github :)
   * }}}
   */

In this case, we would not want to delete the space in the third line, but only in the fifth line.

Toxaris added a commit to Toxaris/scala-mode2 that referenced this issue Apr 12, 2014
This allows to type */ to end a multi-line comment even if automatic
insertion of spaces after * is turned on. See issue hvesalai#69.

Potential problem: What if the user actually wants to start a line
with / in a multi-line comment?
@hvesalai
Copy link
Owner

Thank you for the commit. I have merged it and included you in the list of commiters in README.md.

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

2 participants