2

I'm using vim 7.3 with slimv to edit *.lisp files.

Unfortunately, slimv pretty much ignores my vim indentation settings which causes a mess from time to time. I want to use tabs for indenting and have following lines in vimrc:

set tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab
let g:paredit_mode = 0

Slimv ignores those settings and insist on using spaces for indentation, 2 spaces per indent. I managed to fix "tab" behavior (so it no longer inserts 2 spaces instead of tab) by commenting out

setlocal expandtab

in Vim\vimfiles\indent\lisp.vim, however, I'm not quite sure how to fix autoindentation when I insert new line in the middle of lisp form. In this scenario slimv again ignores my settings and aligns new line using spaces instead of tabs, 2 spaces per indentation level.

As far as I can tell, indentation is handled in function! SlimvIndent( lnum ) which is located in `Vim/vimfiles/ftplugin/slimv.vim", but I'm not quite sure how to fix this function (and it doesn't seem to have any configurable settings anywhere).

How can I fix tab behavior in slimv? It has useful shortcuts (,e to evaluate form, etc), but the tab problem is quite annoying.

Ideas?

SigTerm
  • 26,089
  • 6
  • 66
  • 115
  • Do you have a (github) link to the plugin? – FDinoff Aug 19 '13 at 19:33
  • @FDinoff: I got it [**here**](http://www.vim.org/scripts/script.php?script_id=2531) It looks like it is hosted on bitbucket, most recent development version is [**here**](https://bitbucket.org/kovisoft/slimv). – SigTerm Aug 19 '13 at 19:39
  • I can not replicate the 2 spaces per indent. I do however see the plugin using a mix of tabs and spaces (when you press enter in the middle of an expression). But it uses as many tabs as it can and fills the rest with spaces to align the statement – FDinoff Aug 19 '13 at 19:46
  • Slimv author here. Tab expansion is done on purpose, using tabs is not supported by the plugin. The lisp indentation logic is quite different from many other languages, like C, Java, etc. It is not based on predefined tabstop columns. See [this](http://dept-info.labri.u-bordeaux.fr/~idurand/enseignement/PFS/Common/Strandh-Tutorial/indentation.html) or [this](http://www.emacswiki.org/emacs/TabsAreEvil) for example. – Tamas Kovacs Aug 19 '13 at 20:25
  • @FDinoff: Create *.lisp file, write `(defun test (a b) (+ a b))`, put cursor at the first(`(`) parenthesis of `(a b)`, insert newline. slimv will align `(a b) (+ a b))` using spaces. – SigTerm Aug 20 '13 at 04:31
  • @TamasKovacs: Well, while I understand that there are more or less accepted style of indentation, slimv behavior causes problem - with vim settings I posted, backspace will eat 4 spaces or a single tab, and pressing a tab will insert 4 spaces. Slimv, however, uses two spaces per level. Which means I won't be able to quickly realign lines with tab key. With current indentation style it would make much more sense to set tabstop, shiftwidth and softtabstop to 2 just for lisp files, instead of ignoring them. – SigTerm Aug 20 '13 at 04:38
  • @TamasKovacs: Since you're the author, perhaps you could tell me how could I change indentation style? In current version it is probably something like `indentLevel * 2 * ' '`. It should be possible to modify that. – SigTerm Aug 20 '13 at 04:40
  • I'm not quite sure I understand what you mean. This is also how vim's built in lisp indentation (function lispindent()) works. It pretty much ignores the tabstop settings. Just try to remove slimv and check it. It does not really make sense to set tabstop, shiftwidth and softtabstop to 2, because the indentation is not always done by 2 spaces. It highly depends on the structure of the current form. If you make some changes to the form then you can reindent it via the '=' operator. You shouldn't format the code, slimv should format it for you automatically. – Tamas Kovacs Aug 20 '13 at 06:39
  • @TamasKovacs: "I'm not quite sure I understand what you mean." When I edit *.cpp file, and write something like `int test(){int i = 0; i++; return i;}` and then start adding newlines, vim idents new lines using tabs or spaces, according to my settings. In other words, if I put cursor onto first letter of `int i` and insert new line, vim indents `int i;` using my vim settings. If noexpandtab is set, new line will be indented using tabs, if expandtab is set, new line will be indented using spaces. Which is what I want. slimv ignores those settings, and uses 2 spaces, even if shiftwidth is 4. – SigTerm Aug 20 '13 at 07:04
  • @TamasKovacs: Perhaps there's tutorial or a way to disable autoformatting? I do need help in status bur + autocompletion, but it looks like I often end up fighting slimv autoformatting, so perhaps I don't quite understand something? (I'm new to lisp, by the way). – SigTerm Aug 20 '13 at 07:05
  • If you `set noautoindent` then slimv does not try to do any indenting. In this case you need to do all indenting manually. But I don't advise to do that. Rather let slimv do all indenting for you. In case your editing invalidates the indentation, just use '=' to reindent. See chapter "Indentation" in |slimv-external| in the slimv doc. Just forget how Java, C, Python, etc do the indenting. Those languages have a tabstop based indentation, but lisp doesn't. – Tamas Kovacs Aug 20 '13 at 08:08

1 Answers1

2

I have fixed slimv so that it inserts tabs (plus spaces for the remaining columns) when indenting, if noexpandtab is set after the file is loaded. Slimv still defines expandtab by default, so it is not enough to just add :set noexpandtab to your .vimrc, but you can override this by a 'post' or 'after' command, for example:

au BufReadPost *.lisp set noexpandtab

Or just simply enter :set noexpandtab in the editor any time you wish.

Please fetch the most recent version from the Slimv repository. I still advise against using tabs in lisp source files, see my comments below the original post on why.

Tamas Kovacs
  • 1,495
  • 7
  • 9
  • Hello, I finally found time to do some lisp programming... your version honors shiftwidth and indention style used on previous line but it still tries to insert spaces at the beginning of line from time to time. For example, if I start writing top-level `defun` and insert a newline in the middle of the form, new line will be aligned by two spaces, although it should've inserted tab there. Anyway, thanks for the help. I'll mark your answer as accepted until I find some other way to fix that. – SigTerm Aug 28 '13 at 08:21
  • 1
    The slimv indentation is based on vim's built-in lispindent() function, which has a hardcoded indentation amount of two columns. Currently it is not possible to have another standard indentation amount (e.g. 4 columns) in slimv. All I did was add the possibility to have tab characters instead of spaces, but the standard indentation amount of two columns did not change. I'm planning to rewrite the indentation code in slimv so that it wouldn't use lispindent(). If it's ready then it will be possible to customize the indentation syle. – Tamas Kovacs Sep 01 '13 at 10:39
  • Okay, thanks for the info. Also thanks for fixing slimv - frankly, I did not expect that extension author himself would answer. – SigTerm Sep 01 '13 at 12:30