-
-
Notifications
You must be signed in to change notification settings - Fork 247
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
[Fix #445] def form with strings and docstrings #505
Conversation
This also closes #469 #405 abo-abo/lispy#301 |
Please add some unit tests and update the change log as well. (This suggestions applies to the other PRs you’ve opened as well) |
94f22b4
to
7174466
Compare
done for this one, the others will come soon |
(indent-according-to-mode) | ||
|
||
(should (equal expected-state (buffer-string))) | ||
(should (equal expected-state (buffer-substring-no-properties |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because clojure-in-docstring-p
checks for a font-lock-face, indent-according-to-mode
works differently (in this case) if font-lock-mode is off, so I wrote font-lock-ensure
since otherwise there is no font-lock information in the temp-buffer.
If this change wasn't there, this test:
clojure-mode/test/clojure-mode-indentation-test.el
Lines 123 to 125 in 43e3e65
(check-indentation no-indent-for-def-string | |
"(def foo \"hello|\")" | |
"(def foo \"hello|\")") |
would always pass, both in the current version and my version. To make it fail in the current version (which is expected and wanted), the change had to be made. I found no other way to mimic what is really happening.
And about the line you highlighted: you are right, I'll compare the strings without removing the properties, no reason to do that.
@@ -68,6 +68,7 @@ values of customisable variables." | |||
(search-forward "|") | |||
(delete-char -1) | |||
(clojure-mode) | |||
(font-lock-ensure) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can this affect an indentation test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is because the indentation command behaves differently depending on whether font lock mode is ON or OFF, in the case of docstrings.
This branch is master with the test added: https://github.com/carlosgeos/clojure-mode/tree/temp-branch. The tests are fine, but if (font-lock-ensure)
is added, the test with the docstring fails (like it should).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that’s odd. Turning on the mode should enable the font locking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually yes, but apparently not when using temp-buffer:
https://stackoverflow.com/a/23569337
https://emacs.stackexchange.com/a/44301
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again! The changes look great to me. Just one question: should we still font lock the below string as a docstring?
(def foo
"foo"
)
It seems sexp-at-point
removes that trailing whitespace, so we pass the wrong position to char-after
.
True, that example is incorrectly font locked. I'll make some modifications. |
The new solution handles whitespace and newlines better If everything is ok, I will squash |
;; In a def, at last position is not a docstring | ||
(not (and (string= "def" firstsym) | ||
(save-excursion | ||
(goto-char startpos) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary given the goto-char
below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first goto-char
looks redundant but I think it is not, because there is a (sexp-at-point)
below, and it needs the point at the correct position beforehand.
Also, the (sexp-at-point)
form does not take any arguments so I cannot pass startpos
to it.
Anyway, I tried without it and it didn't work. Happy to remove it if we find the way to make it work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, great point. I didn't think of that! Yeah, we definitely need it because of the (sexp-at-point)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go ahead and squash if you like. I will merge once I have the rights to do so.
Apart from that one final comment, everything looks great now. |
… forms - def forms can now have docstrings and strings properly font-locked - they will not be incorrectly indented added tests as well
[Fix clojure-emacs#445] def form with strings and docstrings
I took the proposed solution here: #445 (thanks @oskarkv) and scoped it to only the def form.
Basically:
how to use
andjust a string
are highlighted differently.And:
hello
is no longer highlighted as a docstringI did what was said in these comments: #445 (comment) and #445 (comment). Now it works for defs, defprotocol, ns (whatever the form)...
M-x checkdoc
and fixed any warnings in the code you've written.