Ticket #3068 (new enhancement)
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
Change History
Changed 11 years ago by twasilczyk
- Attachment mcedit-vim-modeline-1.patch added
comment:1 follow-up: ↓ 2 Changed 11 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>)
comment:2 in reply to: ↑ 1 ; follow-up: ↓ 3 Changed 11 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 11 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 11 years ago by twasilczyk
- Attachment mcedit-vim-modeline-2.patch added
Added vim's modeline support - with "tabstop" mapped to tab spacing
Changed 11 years ago by twasilczyk
- Attachment mcedit-vim-modeline-3.patch added
Small bugfix (backspace at line beginning created spaces)
Changed 11 years ago by twasilczyk
- Attachment mcedit-vim-modeline-4.patch added
Various comment types supported
comment:4 Changed 11 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 11 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:7 Changed 11 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/
Added vim's modeline support - initial implementation