-
-
Notifications
You must be signed in to change notification settings - Fork 247
Identation issues in docstrings #241
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
Comments
@bzg is working on this particular feature. |
Thanks for the heads up. I'll have a look but can't do it before next week. |
@bzg No worries. Now that we have some unit tests you might add a few for the docstring filling logic as well. |
I also think it would be better if the first char on the second line was aligned with the first char on the first line and not with the (defn foo []
"Alignment
like this")
(defn bar []
"Instead
of this") This would make it consistent with how the content of a (let [foo (bar)
baz (atom nil)]
...) and not this, where baz is aligned with (let [foo (bar)
baz (atom nil)]
...) Thoughts? |
@expez The newline/(auto)indentation is tricky in Emacs. I push a PR (#243) so that TAB does the right thing in docstring, but there is no auto-indentation yet. Will have a closer look. As for whether this should be "a docstring... or "a docstring I don't know. Aesthetically and for consistency with the rest of Clojure indentation I agree, but all the functions in Clojure source code use the "wrong" indentation. The question should be raised on the Clojure mailing list so that everyone can agree on the same convention, don't you think so? |
Every function looks like that in the Clojure source because that's what happens when you hit That might be an argument in and of itself, though, that this is what you get in emacs lisp or common lisp mode, in emacs, when you hit The clojure plugin for vim already has a setting, which is off by default, called |
@expez the problem with this example you present... (defn foo []
"Alignment
like this")
(defn bar []
"Instead
of this") is that (defn f
"(λ x) → ⊤
(λ x → y) → ⊤"
([x])
([x y])) which exhibits exactly this mis-alignment behavior. user> (defn f
"(λ x) → ⊤
(λ x → y) → ⊤"
([x])
([x y]))
#'user/f
user> (use 'clojure.repl)
nil
user> (doc f)
-------------------------
user/f
([x] [x y])
(λ x) → ⊤
(λ x → y) → ⊤
nil So no, I don't think that the 75% market share of emacs and vim together justifies this formatting breaking change. Otherwise 👍 on this, the first line failure to indent really gets on my nerves. |
I created this PR (#244) which adds an option for this. |
Thanks for pointing that out, @arrdem! If this doesn't lead to actual breakage in the tools, just moving the alignment problem from the source to the output of the tools, then I'll start using the new default @bzg created--at least for my personal use--and hope it catches on. That way, in a few years, all tools might possibly take this into account and we can be free of this problem. I don't want to wait until the next lisp to fix this :) |
@arrdem I guess we should simply patch |
@bbatsov is your issue with the implicit two spaces, or that it should be an implicit three spaces or what? The standing behavior seems pretty reasonable to me. I certainly don't want Clojure to try and package a "real" typesetting engine for docstrings 👅 |
I am having a persistent but somewhat different problem with docstring indentation.
|
Hi Christopher, Christopher Genovese [email protected] writes:
Sorry, I won't have time to check this particular issue before long, I hope someone else will. |
Thanks, Bastien. As an update, I have a simpler explanation for what is happening. Whenever the first line This explains all the examples I showed because in In |
Christopher Genovese [email protected] writes:
Thanks in advance for that. Please don't hesitate to provide |
Got busy at work; sorry for the delay. I've attached (and included below) a small patch (based on the current I believe the problem lies in the setting of I made three changes: 1. I eliminated the setting of I've generated a number of ad hoc test cases and grabbed a variety of code So do take a look if you get a chance, and let me know if you want more (or Thanks and regards, Chris *** clojure-mode.el Tue Dec 16 20:55:18 2014 On Sat, Dec 6, 2014 at 10:25 AM, Bastien [email protected] wrote:
|
The patch didn't come through here well, so here is a gist with the patch. I've also included it more cleanly below.
|
Thanks Christopher, I'll have a look when I have a moment, don't hold your breath though. |
Bastien, If I had a choice, then, given your timing, I would suggest making the It's up to you, of course. If there's something more you'd like me to do, Thanks, Chris On Wed, Dec 17, 2014 at 10:12 AM, Bastien [email protected] wrote:
|
@bzg The problem I have with the current (defn foo
"foo should be called like
(with-bar something
(foo x))
where something is something."
[x]
(do-stuff-with m)) and after indentation I end up with (defn foo
"foo should be called like
(with-bar something
(foo x))
where something is something."
[x]
(do-stuff-with m)) Of course, now you'll say "then don't hit TAB in docstrings" but I use aggressive-indent-mode which re-indents while typing. Right now, I simply |
Hi Tassilo, I don't have enough time at hand right now -- if you can come up with a patch for this, I'll gladly accept it! Thanks in advance. |
I'm having indentation issues on things like this: https://github.com/Datomic/day-of-datomic/blob/master/src/datomic/samples/schema.clj#L50 (Just to add another datapoint.) |
Fix doctring indentation issue in #241
The #289 PR that got merged this weekend should address this issue. |
Great, thanks! |
Hurrah! |
If the docstring body aligns with the first character instead of the starting double quote, then the docstring gets displayed strangely by `clojure.repl/doc`: ```clojure (defn foo "I don't do a whole lot. But at least I'm properly indented, right?" [x] (println x "Hello, world!")) ;= #'user/foo (doc foo) ; ------------------------- ; user/foo ; ([x]) ; I don't do a whole lot. ; But at least I'm properly indented, ; right? ;= nil (defn bar "I don't do a whole lot. But at least I'm *actually* properly indented, right?" [x] (println x "Hello, world!")) ;= #'user/bar (doc bar) ; ------------------------- ; user/bar ; ([x]) ; I don't do a whole lot. ; But at least I'm *actually* properly indented, ; right? ;= nil ``` For more information, see: - <bbatsov/clojure-style-guide#43 (comment)> (the above code example was actually adapted from this comment) - <clojure-emacs/clojure-mode#241 (comment)>
But it still looks like |
The behavior I see in a docstring with
The docstring of
So I'm inclined to think Also beware that
|
But the docstring for command
So your first bullet point sounds like wrong behavior of |
The text was updated successfully, but these errors were encountered: