Ticket #16 (closed defect: fixed)

Opened 4 months ago

Last modified 4 months ago

Vim indent : little problem

Reported by: victor Owned by: pmoura
Priority: minor Milestone: Logtalk distribution
Component: text editor support Version: 2.31.6
Keywords: Cc:

Description

Hello,

I found a bug in the indent plugin for vim :

There is a little example :

:- object(test).
  test :- 
    (a).
  test2.
:- end_object.

If you use the auto-indent of vim (select all the text and type "=") it will indent it like that :

:- object(test).
  test :- 
    (a).
    test2.
:- end_object.

If you remove the "(" ")" around a, it works as expected.

Attachments

Change History

  Changed 4 months ago by pmoura

  • status changed from new to assigned
  • owner set to pmoura

  Changed 4 months ago by pmoura

  • status changed from assigned to closed
  • resolution set to fixed

Could you please check that r4301 fixes the problem? Thanks.

  Changed 4 months ago by victor

  • status changed from closed to reopened
  • resolution deleted

Yes,

It do fix it, but I have another one for you :

  test :-
    (a),
    b.
}}

gives me :
{{{
  test :-
    (a),
      b.
}}
}}}

  Changed 4 months ago by victor

I meant :

  test :-
    (a),
    b.

gives me :

  test :-
    (a),
      b.

  Changed 4 months ago by anonymous

For some reason, I'm unable to test my changes to wenv/vim/indent/logtalk.vim. Could you try changing line 53 to:

if pline =~ '^\s*\([(;]\|->\)' && pline !~ '\.\s*\(%.*\)\?$' && pline !~ '^\s*\([);]\|->\)'

and report back?

  Changed 4 months ago by victor

Sorry,

It doesn't seem to work.

  Changed 4 months ago by pmoura

I cannot get auto-indentation working in any of my Vim installations (I've both GUI and no-GUI versions). I wrote the indent support long ago. I thought that copying the Logtalk indent file to indent folder was enough and that auto-indentation is on by default. Turning auto-indentation explicitly on does not get it working. Am I missing something obvious?

  Changed 4 months ago by anonymous

Maybe, this is what I have in my .vimrc :

syn on
filetype indent on

And you need of course to bind .lgt files to logtalk.vim (like noted in NOTES.txt)

What can be good for your vim plugin would be to have a file logtalk.vim containing :

au BufNewFile,BufRead *.lgt                     setf logtalk

And that should be put in ~/.vim/ftdetect/

Like that vim will load it every time :)

  Changed 4 months ago by pmoura

Thanks for the tips. Auto-indentation is now working and I've corrected the problem you pointed above in r4302. Not sure, however, the changes don't have some bad side effects. Please report back and close the ticket if everything works correctly.

  Changed 4 months ago by victor

  • status changed from reopened to closed
  • resolution set to fixed

Ok,

It looks like it works well :)

I tried auto-identing a big file and all seems ok :)

The only thing that could be better (but I think it will be hard to do it and it is not a real problem) would be to have a good indenting for things like :

test :-
  (a ->
    b
  ; c
  ).

The thing is that c is not aligned with b sometimes ... I am not even sure it is a good way to write if-then-else :)

  Changed 4 months ago by victor

  • status changed from closed to reopened
  • resolution deleted

Hello,

I found 2 bugs, I think they were introduced by the last patch.

1) When I open a new object with :

:- object(test).

And I type enter just after the end of the line, it doesn't indent of one indentation.

2) Maybe it is the same as 1), if I write :

  test.
  test2.

And auto-indent, I get :

  test.
test2.

It looks like there is something strange with one line definitions.

Thanks :)

  Changed 4 months ago by pmoura

Some Logtalk users adopted the style in the example source ode by indenting entity contents one tab stop. Other users, however, prefer to start all entity directives and predicate clauses at the first column (e.g. for making searching with regular expressions simpler). The current version of the Vim indent plug-in is targeting the second group of users. Not sure this can be customized in same easy way for the user to adopt the plug-in behavior to its personal preferences. Suggestions?

  Changed 4 months ago by victor

Maybe by using a variable that hold this information, and that is used by the plugin.

I think that vimrc is run before plugins, so if you put something like :

let lgtindententity = 1

in it, you can check for this value in the indent file ... But I am not sure how it works.

  Changed 4 months ago by victor

And, while we are talking about vim, I don't think you should specify configuration variable like :

setlocal ts=4
setlocal sw=4
setlocal fdm=syntax
setlocal fdc=2
setlocal autoindent

Is is more a user setting in my opinion. I tried to look at other syntax file I have and I did not see any setting of variables in it.

  Changed 4 months ago by pmoura

The standard solution is to define a filetype plugin, as Bram suggested the first time I send him the Logtalk Vim support files. I just never got around to do it. Maybe this is something that you're able to contribute?

follow-up: ↓ 17   Changed 4 months ago by victor

Hello,

In fact there is 4 file that can be created : ~/.vim/ftdetect/logtalk.vim :

au BufNewFile,BufRead *.lgt   setf logtalk

It contain the code for binding *.lgt file (and .config if you want) to the logtalk filtype. In fact this code is already available in vim distribution, so I don't think it is really needed to create this file, you can add it in NOTES.txt for information.

~/.vim/ftplugin/logtalk.vim : it contains initialization of variables and thing like that (for example omnifunc, ...), but I don't think you should put things like sw, ts, fdm, fdc and ai, they are user settings.

For example, the prolog one contains :

if exists("b:did_ftplugin")
  finish
endif
let b:did_ftplugin = 1

let b:undo_ftplugin = "setl com< cms< fo<"

setlocal comments=s1:/*,mb:*,ex:*/,:% commentstring=%\ %s
setlocal formatoptions-=t formatoptions+=croql

~/.vim/syntax/logtalk.vim : it contains only things for syntax highlighting. (current is good minus the setlocal) ~/.vim/indent/logtalk.vim : for indenting (current is good)

About a contribution, why not, but I think that from what I said, there is already enough info to make one from it :)

in reply to: ↑ 16   Changed 4 months ago by pmoura

  • status changed from reopened to closed
  • resolution set to fixed

I've already created a Logtalk file type plugin and updated the installation instructions for the Vim text editor. Check r4316. Hopefully, everything is now more compliant with the Vim standard practices.

Add/Change #16 (Vim indent : little problem)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.