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

M-j to continue a comment on the next lines indents the next line #981

Closed
emmanueltouzery opened this issue Nov 7, 2015 · 9 comments
Closed

Comments

@emmanueltouzery
Copy link
Contributor

in emacs while in the middle of a comment, it's possible to ask to insert a carriage return and continue the comment on the next line.

eg, if "|" is the cursor position:

-- my comment|

you press M-j and you should get:

-- my comment
-- |

but I get:

-- my comment
    -- |

the comment continuation on the second line should not be indented.

@gracjan
Copy link
Contributor

gracjan commented Nov 20, 2015

Are you able to add a test case to tests/haskell-indentation-mode-tests.el?

@emmanueltouzery
Copy link
Contributor Author

I can try. I opened the file and it looks straightforward to add new tests, however I didn't manage to run the existing tests. I also didn't find guidance about that in the contribution guide or readme? Before I can modify tests I must be able to run the existing ones. I guess it's basic knowledge for authors of emacs-lisp packages, but it's knowledge I just don't have currently...

@gracjan
Copy link
Contributor

gracjan commented Dec 1, 2015 via email

@emmanueltouzery
Copy link
Contributor Author

ok this test accurately reproduces the problem:

(ert-deftest haskell-indentation-altj-comment ()
  (switch-to-buffer (get-buffer-create "another.hs"))
  (haskell-mode)
  ;; (insert "-- comment") ;; <-- with this insert, it passes
  (insert "main = do\n    return ()\n\n-- comment")
  (execute-kbd-macro (kbd "M-j"))
  (should (equal 2 (count-lines (point-min) (point))))
  (should (equal 3 (- (point) (line-beginning-position)))))

i guess fixing the problem itself would be considerably more involved..?

@gracjan
Copy link
Contributor

gracjan commented Dec 1, 2015

Add:

:expected-result :failed

and then this test case qualified for a pull request.

As about fixing it really: indentation mode currently ignores comments (treats them as whitespace), so it aligns your second comment to the tokens that were even before the first comment. Comments should be represented as a new token type. This requires some thought, but you may give it a try.

emmanueltouzery added a commit to emmanueltouzery/haskell-mode that referenced this issue Dec 1, 2015
gracjan added a commit that referenced this issue Dec 1, 2015
Failing testcase for bug #981: M-j to continue a comment on the next lines indents the next line
@gracjan
Copy link
Contributor

gracjan commented Dec 26, 2015

Interestingly the test that we have for this work on Emacs 25.

@fice-t
Copy link
Contributor

fice-t commented Feb 22, 2016

@gracjan That's because they changed the function in the core. There's this included part:

(comment-indent-function
 ;; If the previous comment is on its own line, then
 ;; reuse its indentation unconditionally.
 ;; Important for modes like Python/Haskell where
 ;; auto-indentation is unreliable.
 (if (save-excursion (goto-char compos)
                     (skip-chars-backward " \t")
                     (bolp))
     (lambda () comment-column) comment-indent-function))

@gracjan
Copy link
Contributor

gracjan commented Feb 22, 2016

Oh, sneaky!

@gracjan
Copy link
Contributor

gracjan commented Aug 5, 2016

Same as #225.

@gracjan gracjan closed this as completed Aug 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants