derekwyatt / vim-scala

My work on integration of Scala into Vim - not a ton here, but useful for me.
http://derekwyatt.org
Apache License 2.0
1.09k stars 144 forks source link

Indentation problem for `}`? #29

Open pengyu opened 11 years ago

pengyu commented 11 years ago

The following is what is indented by vim-scala. The last } is indented one level. Shouldn't it be unindented?

object HelloWorld {
  def main(args: Array[String]) {
    println("Hello, world!")
  }
  }
derekwyatt commented 11 years ago

I can't reproduce that.

YannMoisan commented 10 years ago

I can reproduce : vim version 7.4.16, very annoying issue !

Here is another example def method() = { List().map { _ + 1 } }

mblund commented 10 years ago

I can reproduce this issue

package foo
import org.scalatest.FunSuite
class FooSuite extends FunSuite {
  test("foo") {
    println("foo")
  }
  }

I'm using vim on a centos 6.3 machine :version tells me

VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Apr  5 2012 10:17:30)
Inkluderade patchar: 1-411
Modifierad av <bugzilla@redhat.com>
Kompilerad av <bugzilla@redhat.com>
Enorm version utan GUI.  Funktioner inkluderade (+) eller inte (-):
+arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset +cindent -clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info
+comments +cryptv +cscope +cursorshape +dialog_con +diff +digraphs -dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path
+find_in_path +float +folding -footer +fork() +gettext -hangul_input +iconv +insert_expand +jumplist +keymap +langmap +libcall +linebreak +lispindent
+listcmds +localmap +menu +mksession +modify_fname +mouse -mouseshape +mouse_dec +mouse_gpm -mouse_jsbterm +mouse_netterm -mouse_sysmouse +mouse_xterm
+multi_byte +multi_lang -mzscheme -netbeans_intg -osfiletype +path_extra +perl +postscript +printer +profile +python +quickfix +reltime +rightleft -ruby
+scrollbind +signs +smartindent -sniff +startuptime +statusline -sun_workshop +syntax +tag_binary +tag_old_static -tag_any_white -tcl +terminfo
+termresponse +textobjects +title -toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo +vreplace +wildignore +wildmenu +windows
+writebackup -X11 -xfontset -xim -xsmp -xterm_clipboard -xterm_save
   system-vimrc-fil: "/etc/vimrc"
     användar-vimrc-fil: "$HOME/.vimrc"
      användar-exrc-fil: "$HOME/.exrc"
  reserv för $VIM: "/usr/share/vim"
Kompilering: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -O2 -g -pipe -Wall  -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GN
U_SOURCE -D_FILE_OFFSET_BITS=64  -D_FORTIFY_SOURCE=1    -D_REENTRANT -D_GNU_SOURCE  -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFF
SET_BITS=64  -I/usr/lib64/perl5/CORE  -I/usr/include/python2.6 -pthread
Länkning: gcc   -Wl,-E -Wl,-rpath,/usr/lib64/perl5/CORE   -L/usr/local/lib -o vim       -lselinux  -lncurses -lacl -lgpm   -Wl,-E -Wl,-rpath,/usr/lib64/pe
rl5/CORE  -fstack-protector  -L/usr/lib64/perl5/CORE -lperl -lresolv -lutil -lc -L/usr/lib64/python2.6/config -lpython2.6 -lutil -lm -Xlinker -export-dyna
mic

How can I help with more info about this issue?

derekwyatt commented 10 years ago

I'm on 7.3 with patches 1-429 and can't reproduce.

First, upgrade, then try and reproduce it. If you can, then we'll dig into it, otherwise we'll close this off.

mblund commented 10 years ago

sorry, I'm on centos 6.4 not 6.3, my mistake

cat /etc/*release*
CentOS release 6.4 (Final)

vim seems up to date with centos, but still on 7.2...

yum info vim-enhanced
Loaded plugins: fastestmirror, protectbase
Loading mirror speeds from cached hostfile
0 packages excluded due to repository protections
Installed Packages
Name        : vim-enhanced
Arch        : x86_64
Epoch       : 2
Version     : 7.2.411
Release     : 1.8.el6
Size        : 1.8 M
Repo        : installed
From repo   : base
derekwyatt commented 10 years ago

That doesn't really change anything :) The version of VIM is what's in question and yours is way out of date (hell, mine's pretty out of date too, but it works, and it's years ahead of the version you're using).

At this point, I'm inclined to close the ticket on the assumption that upgrading to a later version of VIM will solve the problem unless you can prove otherwise.

YannMoisan commented 10 years ago

As mentioned above, i can repoduce with Vim 7.4.16

derekwyatt commented 10 years ago

Ah, right... sorry, forgot about that. I'll try and update soon and see if I can reproduce it there.

mblund commented 10 years ago

yeah, I know it's old as hell but you know, those unused cpu:s on our server is to tempting to use when I'm a mba right now.

I saw that I swedish language setting so I tried to update them to en_US instead. Also checked charcet. Still no luck

export LANG=en_US.utf8
export LC_CTYPE=en_US.utf8
export LC_COLLATE=C
vim foo.scala 
file -bi foo.scala 
text/x-java; charset=utf-8

I should mention that I installed vim-scala with Vundle. Copied the sample .vimrc and added vim-scala

derekwyatt commented 10 years ago

OK, I've now tried this on my Mac (7.4a Beta) and a build that I just created from the VIM source.

Can't reproduce. I have no idea why you guys are seeing this. My version of vim-scala is the same as what's in this repository so there's nothing special about my system. there's something more interesting going on here.

Have a look through your settings that have to do with indenting (e.g. indentkeys, autoindent, filetype indent, etc..).

I have:

filetype indent on
set autoindent

And the indentkeys is what's in the plugin file. Is your autoindent not set?

mblund commented 10 years ago

I tried it on my mac now. I get the same error!

$ git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle

This is my .vimrc

set nocompatible              " be iMproved
filetype off                  " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'
Bundle 'derekwyatt/vim-scala'
filetype plugin indent on     " required!

and then

:Bundleinstall

inside of vim

I tried to indent the sampleFile.scala and doesn't come out right

derekwyatt commented 10 years ago

Try set autoindent

mblund commented 10 years ago

still no luck.

to indent i use

gg=G

or visual and then =

derekwyatt commented 10 years ago

Then I'm out of ideas. Every single VIM installation I use this on (and there are many) this all works just fine.

But, the beauty is that you've got the source and you're in a great position to figure it out. Since I can't see it, I can't figure it out... you're the man to do it.

mblund commented 10 years ago

I will try to have a look at it tomorrow and maybe get some help from my vim-support at work. Probably a case of pebkac . Thanks for today anyway.

mblund commented 10 years ago

I gave it a try but the indent/scala.vim file was over my head.

The indention problems only occurs for me when I run on the full file with gg=G or with visual. I works fine with single lines so I'm happy to get the correct indentions and syntax coloring when I write code. I maybe use a sbt plugin to format the hole file later on.

derekwyatt commented 10 years ago

K. I'm gonna close this one. I know it's a frustrating problem for people but unless I can see it, or unless someone else can see it and fix it (or at least tell me what's happening) there's jack-all that I can do about it.

I hope someone files a new bug later with more information.

jiripospisil commented 10 years ago

I think I figured it out. Not really sure how exactly it's related however when I set virtualedit to all (which is what @derekwyatt is using), the indentation seems to work fine. The default value is just an empty string so if you want to break it for the current session, type :set virtualedit=

jiripospisil commented 10 years ago

Hm, so changing the single virtualedit value fixes it for me, but doesn't for a friend of mine... Anyway, give it a shot.

derekwyatt commented 10 years ago

Reproduced! Thanks a lot!

Bekbolatov commented 10 years ago

I had the same problem and virtual edit worked, so I am putting this in indent/scala.vim as a workaround for now:

setlocal virtualedit=all
mblund commented 10 years ago

That worked it out for me. Thanks!