hvesalai / emacs-scala-mode

The definitive scala-mode for emacs
http://ensime.org
GNU General Public License v3.0
362 stars 68 forks source link

Multi-line Comments not considered as Blocks #156

Open benkio opened 4 years ago

benkio commented 4 years ago

Hi there, While using scala-mode + hs-minor-mode in order to hide code blocks I noticed that the hiding doesn't work for multi-line comments. Reading the hs-minor-mode manual in here: https://www.gnu.org/software/emacs/manual/html_node/emacs/Hideshow.html

Seems that, the definition of what is a block, is responsibility of the major mode. I attach also a short video showing the issue scalaModeHSMinMode

If you think this shouldn't go into the scala-mode repo, could you suggest me a way to configure the comments to be a block? Thank you so much

hvesalai commented 4 years ago

Since hs-minor-mode is part of emacs proper, you can add support for it in emacs-scala-mode.

Just do a PR that adds the needed configuration.

As I understand it, the only thing you need to do is to add the required regular expressions for comment start and end to the hs-special-modes-alist list (https://www.emacswiki.org/emacs/HideShow).

benkio commented 4 years ago

Cool, I didn't spot it, I'll do the PR then. It seems doable even for a elisp newbie like me :D (especially because those multiline comments are like the java's one)

benkio commented 4 years ago

I tried with this code

(push (purecopy '(scala-mode "{" "}" "/[*/]" nil nil)) (cdr (last hs-special-modes-alist)))

as for c-mode and java-mode and if you place the cursor on a multi-line comment executing hs-hide-block it works, hiding the comment properly

BUT 😄 if you put the cursor at the beginning of a class and execute the hs-hide-level the comments are not hid as for the content of defs. Someone has any idea why this is happening? I attach a gif so you can see by yourself hideBlockNotLevel

hvesalai commented 4 years ago

And you are sure that is not what is supposed to happen?

benkio commented 4 years ago

Personally I expected to see that collapsed as a normal block, but I don't know how HideShow works internally.

hvesalai commented 4 years ago

Can you open some Java code and see what happens.

benkio commented 4 years ago

I checked copying a java file from a random github java repo. Seems It behaves the same way. Then, I suppose it's right.

I'll rise a PR if you can suggest me where to put the extra line. As I said I'm a noob of elisp and modes :D

And maybe I'll just create a custom elisp function for collapsing all comments into the current block into my config ;)