Closed moll closed 8 years ago
Hmm I guess hypothetically it can be done if you set a predefined fn_indent
level in your .vimrc
and then we check for that to determine how much we should indent (default to current indentation)
It seems like the current way is the "general" convention on how people usually style their code. Let me know if you can think of a better way to enforce code style without having to edit a bunch of vars in a vimrc file.
Umm, I don't think there is another way to express options without mind-reading besides writing them down (in Vim's case as variables), so I guess your proposal of using a variable fn_indent
would do the trick. :) You did suggest a variable, right, or is that some secret Vim builtin?
Though I'd follow suite with other filetype plugin configuration variables which usually are prepended with the language name.
I'd like this too, manually having to backspace out sucks. I'm happy to hack it into my fork, but my vim script isn't good enough to see where.
As for "usual", I don't know about that, it plays really horribly with node conventions on long function names, and 80 char limits to line length. If I wrap function args, its because I'm hitting the line length limit, so to then steal half the line for whitespace is annoying:
this.someFunnytThing = that.someOtherThing.methodName(999, ___"long string arg......."
Wrapping got me nowhere. Also, it means the argument indent has to change when the function name changes, which creates non-relevant whitespace changes in history, and its asymetrical with function definition, which gets indented as:
function something( arg, other
I'm not trying to convince anyone to change how they like to code, but I would really appreciate this being either customisable, or a pointer to what to hack up in a fork.
I believe this issue has been fixed. Please comment if it isn't and I'll re-open it.
@amadeus, thanks, but was there supposed to be a config setting for this or what branch am I to use or where do I find this? :) The master branch does not seem to fix this.
Yeah this is still an issue
This is definitely still an issue. I think we should use g:javascript_indent_style
, as it isn't just with functions.
I created a pull request that I believe fixes this. I created the pull request before I saw this issue and called the variable g:javascript_indent_to_parens, but maybe there is a better name?
PR is here: https://github.com/pangloss/vim-javascript/pull/156
Didn't get very far with the PR in the end which I've now closed, as it was being caught out with lots of edge cases and I didn't know enough about the indenter's internals.
If anyone is looking for the simpler indent functionality, I've found using vim-javascript's syntax highlighting with simple-javascript-indenter handling indentation does the job very nicely. If you use vundle, just put jiangmiao/simple-javascript-indenter higher up in your list of bundles than vim-javascript.
Wish this was configurable :(
Am I missing something, or is the following patch all it takes?
diff --git a/indent/javascript.vim b/indent/javascript.vim
index 0f526db..a935a87 100644
--- a/indent/javascript.vim
+++ b/indent/javascript.vim
@@ -426,14 +426,8 @@ function GetJavascriptIndent()
" add indent depending on the bracket type.
if line =~ '[[({]'
let counts = s:LineHasOpeningBrackets(lnum)
- if counts[0] == '1' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
- if col('.') + 1 == col('$')
+ if counts[0] == '1' || counts[1] == '1' || counts[2] == '1'
return ind + &sw
- else
- return virtcol('.')
- endif
- elseif counts[1] == '1' || counts[2] == '1'
- return ind + &sw
else
call cursor(v:lnum, vcol)
end
Admittedly, I don't understand what the whole searchpair
business is supposed to do, but I'm pretty sure I don't want it. Doesn't that patch :arrow_up: just essentially mean "when there's an opening paren/bracket/brace, add one shiftwidth
," which is exactly what we want?
Of course, we'd probably want to add it as a flag, but that's not difficult; #159 shows the way to do that.
If we all agree on removing the special parentheses indent, i can get this into develop
hey,on develop this was finally changed in a fairly large commit, which means certain things could have issues. testers are welcome
Thanks a lot, @bounceme. This will be a welcomed change.
The only problem I've had with the develop
branch is that it becomes:
function(1,
2)
Instead of
function(1,
2)
Still better than the previous behavior though.
my other branch,bounceme-patch-1, fixes that. i'll try and finish up my new pr soon
Yay. Has this been merged in already? If not, I'd suggest keeping this issue open until it's resolved in the stable release. Things tend to slip through otherwise. ;)
Is there a way to replace the default parenthesis-aligned line continuation indenting with a regular 1-indent per continuation?
While the parenthesis-alignment may look nice occasionally, it makes the code very irregular, sharp, wastes a lot of space with longer function names, doesn't work with tabs and kills bunnies.
That is, instead of:
get