Ticket #3068 (new enhancement)

Opened 6 years ago

Last modified 6 years ago

Vim's modeline support / tabulation settings per-file

Reported by: twasilczyk Owned by:
Priority: major Milestone: Future Releases
Component: mcedit Version: master
Keywords: tabstop softtabstop expandtab Cc:
Blocked By: Blocking:
Branch state: no branch Votes for changeset:

Description

Vim have useful feature, to set indentation related configuration per-file. It's done by adding a comment to the source file (usually at the end), for example:

/* vim: set tabstop=8 softtabstop=4 shiftwidth=4 noexpandtab: */

The above config means in mc:

  • Fake half tabs enabled
  • Fill tabs with spaces disabled
  • Tab spacing 8

I think having such feature in mc would be a nice step forward. I also think it should use the same namespace as vim, despite being totally distinct project.

Attachments

mcedit-vim-modeline-1.patch (9.8 KB) - added by twasilczyk 6 years ago.
Added vim's modeline support - initial implementation
mcedit-vim-modeline-2.patch (18.8 KB) - added by twasilczyk 6 years ago.
Added vim's modeline support - with "tabstop" mapped to tab spacing
mcedit-vim-modeline-3.patch (18.8 KB) - added by twasilczyk 6 years ago.
Small bugfix (backspace at line beginning created spaces)
mcedit-vim-modeline-4.patch (19.4 KB) - added by twasilczyk 6 years ago.
Various comment types supported

Change History

Changed 6 years ago by twasilczyk

Added vim's modeline support - initial implementation

comment:1 follow-up: ↓ 2 Changed 6 years ago by twasilczyk

I did initial implementation for this, however, it needs some work:

  • mc_findinfile should be placed somewhere else (maybe vfs.h?) and maybe named somehow better
  • vim's tabstop parameter isn't mapped to mc's tab spacing (it's easy to implement, I'll do it later)
  • currently, only C comments are supported; we should discuss other comment types that should be supported (C++ //, Python's #, others?)
  • I guess there should be some max size limit, to not look for config in 1MB+ files
  • mc depends on glib (which version?) so the scan could take advantage of it (regexp?)
  • there should be a warning in config file, if the global settings are overriden by local ones
  • if using fake half tabs with no tab-to-space filling, there is a possibility to create "bad" indentations (<tab><4xspace><tab><tab><4xspace>) - they should be converted (when editing a specific indentation) to standard ones (<tab><tab><tab><4xspace>)

[edit]

  • scanning modeline in editor buffer during file load
Last edited 6 years ago by twasilczyk (previous) (diff)

comment:2 in reply to: ↑ 1 ; follow-up: ↓ 3 Changed 6 years ago by andrew_b

Replying to twasilczyk:

I did initial implementation for this, however, it needs some work:

Thanks!

Some remarks:

  • this option should be optional
  • I guess there should be some max size limit, to not look for config in 1MB+ files
  • scanning modeline in editor buffer after (or even during) file load is better than scanning directly in file because we scan file only once. mcedit supports file of any size.
  • mc depends on glib (which version?) so the scan could take advantage of it (regexp?)
  • glib >= 2.12 is required, but mc already has own regexp-based search engine (see lib/search, lib/search.h)

comment:3 in reply to: ↑ 2 Changed 6 years ago by twasilczyk

Replying to andrew_b:
If we scan for modeline during file load, there will be no necessity to omit 1MB+ files, as it won't affect performance.

Changed 6 years ago by twasilczyk

Added vim's modeline support - with "tabstop" mapped to tab spacing

Changed 6 years ago by twasilczyk

Small bugfix (backspace at line beginning created spaces)

Changed 6 years ago by twasilczyk

Various comment types supported

comment:4 Changed 6 years ago by angel_il

so... scan_modeline try scan all file, potentially this could take a long time...
for example file size is 4gb, without '\n'

comment:5 Changed 6 years ago by twasilczyk

As far, as I understand, file is scanned anyway (for example, to find out the number of lines). Thus, adding another check into that loop won't affect performance that much.

Am I right?

comment:6 Changed 6 years ago by angel_il

i think, need scan first ~2000b

Last edited 6 years ago by angel_il (previous) (diff)

comment:7 Changed 6 years ago by ossi

maybe also the last - some files have the modeline at the bottom.

there is also an entirely different approach to the matter: http://kate-editor.org/2006/02/09/kateconfig-files/

Note: See TracTickets for help on using tickets.