Home / Modeline Parser
Name Modified Size InfoDownloads / Week
Parent folder
ModelineTopLevelSeparator.py 2013-01-23 2.5 kB
ModelineParser_readme.txt 2013-01-23 7.5 kB
ModelineLog.py 2012-10-21 613 Bytes
ModelineColormarker.py 2012-03-03 8.8 kB
ModelineParser_0.2.zip 2011-07-12 18.1 kB
ModelineParser_0.1.zip 2011-07-04 13.8 kB
Totals: 6 Items   51.3 kB 2
This Notepad++ plugin will read Vim modeline to have per file settings. It also supports shebang (#!) to select language.
Copyright 2011 Francois-R.Boyer@PolyMtl.ca
Distributed under GPL version 2.

It supports selecting language (including user defined languages), tabstop, wraping mode, text direction (note that Scintilla does not currently support bidi correctly), and more...  And is easily extensible to add language detection based on file content or filename/pathname.

Current addons to this plugin are:
- ModelineColormarker.py	Adds options to color parts of text and place markers automatically, for example on TODO comments.
- ModelineLog.py		Adds MS Notepad behaviour for files beginning with ".LOG", placing cursor at end of file with current date and time.
- ModelineTopLevelSeparator.py	Adds visual separators between top level folds (between functions, classes, ...).

This plugin is based on Python Plugin Square (https://sourceforge.net/projects/npppythonplugsq/), and requires Python Script plugin by davegb3 (https://sourceforge.net/projects/npppythonscript/).

-- Installing ----------
The .zip package should be decompressed under Notepad++ directory.
The .dll and .conf files should thus be in the "plugins\" directory, and the .py files (of main package and of any addon) should be in the "plugins\PythonScript\lib\" directory.

To start this plugin on Notepad++ startup, configure Python Script plugin to Initialisation:ATSTARTUP (in menu Plugins/Python Script/Configuration) and add the following lines to the end of the startup.py:
import ModelineParser_dll
import ModelineFoldmethod        # If you want to use the example option to fold based on indent
import ModelineLanguageDetectors # If you want to use the example language detectors
# import any other addons here...
ModelineParser_dll.modeline_start()

It can also be started/stoped from the Plugins/Modeline Parser menu.

-- History ----------
Version 0.2 (2011-07-12):
    New options: linebreak, breakindent, and breakindentshift (partly)
    Now supports registering of other options and language detectors, by outside code ("addons").  (Several parts have been modified/moved for this.)
    Now supports user-defined languages.
    Example language detectors: detect XML (based on content), makefile (based on filename) and used-defined language.
    Example option: 'foldmethod=indent:' to fold file based on indentation (useful for some "plain text" files, but note that this example is slow)
Version 0.1 (2011-07-04):
    Initial version supports shebang and modeline options filetype/syntax, tabstop, wrap, and rightleft.

-- Documentation ----------
Shebang "#!" must be the first characters of the file, then the name of the language interpreter.
For example a Perl file, with any file extension (including no extension), would be recognized if it starts with:
#!/usr/bin/env perl

Modeline must be in the first or last five lines of file, and can have anything before a " vi:" or " vim:" tag, thus any comment form is supported.  Note that the space before the "v" is important (and must not be a tab instead).
For example a PHP file could finish with:
<?php // vi: syntax=php : tabstop=4 : wrap : norightleft

(Note that "set" form Vim modelines are not supported, only the colon-separated form.)

The supported options are:

tabstop=, ts=				Sets the tab size.

wrap, nowrap				Sets wrap or not.

linebreak, lbr, nolinebreak, nolbr	Sets word wrap or character wrap mode (also default to 'fixed' in character wrap and 'same/ident' in word wrap mode).

breakindent, bri, nobreakindent, nobri	Sets wrap indent mode to 'same/indet' or fixed (see "Correctly indent wrapped lines" Vim patch http://groups.google.com/group/vim_dev/web/vim-patches).

breakindentshift=, brishift=		Sets wrap indent mode to 'shift' if >0 or 'same' if =0 (Scintilla does not currently support setting the indent).

rightleft, rl, norightleft, norl	Sets right-to-left or left-to-right writing direction (note that Scintilla does not currently support bidi correctly).

filetype=, ft=, syntax=, syn=		Sets the language.
	Language names are from LANGTYPE.names (in Python Script plugin): ada, asm, asp, au3, bash, batch, c, caml, cmake, cpp, cs, css, diff, flash, fortran, haskell, html, ini, inno, java, js, kix, lisp, lua, makefile, matlab, nfo, nsis, objc, pascal, perl, php, props, ps, python, rc, ruby, scheme, searchresult, smalltalk, sql, tcl, tex, txt, user, vb, verilog, vhdl, xml, yaml
	And the following names (which are in standard Vim configurations and are different than above): cobol, d, dosbatch, dosini, javascript, jsp, make, postscr, r, sh, st (for Smalltalk)
	Plus the following (not in standard Vim nor in LANGTYPE.names): gui4cli, powershell


It also permits to have "addons" for more options or language detection based on content or filename/pathname. Addons are Python files, importing ModelineParser_dll, and using the following functions to add required behaviour:

ModelineParser_dll.modeline_add_preparse(function)		The function will be called with 'settings' dict to be updated, file name, file path, and first line content.  The active buffer is the one which is being parsed, so global "editor" object can be used.

ModelineParser_dll.modeline_add_options(options_dict, function)	Adds new options (a dictionary of options) and a callback function, which is called on each buffer activation and buffer save.

ModelineParser_dll.modeline_add_languages(languages_dict)	Adds new language names (a dictionary of names), for user defined languages (maps to name in language menu), or to map other names to any available language (maps to a LANGTYPE).


Here is a simple language detector you can add to startup.py, to a script in the "Python Script" plugin menu, or in any other file you "import" in another script:

import ModelineParser_dll
# simple xml detector (content based)
ModelineParser_dll.modeline_add_preparse(lambda settings, name, path, text:
	text.startswith('<?xml') and settings.__setitem__('language','xml')
	)

See plugins\PythonScript\lib\ModelineLanguageDetectors.py for more language detector examples, or plugins\PythonScript\lib\ModelineFoldmethod.py for an example of adding options.


The modelines/shebang (and any other registered language detectors) are parsed only once per buffer, on buffer activation (not on file loading), and results are placed in an internal structure reread on each buffer activation.  This internal structure is updated for a single buffer when it is saved or when menu "Reparse modeline" is selected; the internal structure is completely reset when menu "Start modeline parsing" (which restarts the plugin) is selected.

-- Contents ----------
The package should include the following files, to be placed under Notepad++ folder:

plugins\ModelineParser.dll			The Python Plugin Square DLL (renamed to the plugin name; other files should have the same name as this file with the "." replaced by a "_", plus the correct extension).

plugins\ModelineParser_dll.conf			The configuration file for Python Plugin Square, specifies menu item names and Python functions to call.

plugins\PythonScript\lib\ModelineParser_dll.py	This plugin code, in Python.

plugins\PythonScript\lib\ModelineFoldmethod.py		Modeline options example, to fold based on indent.

plugins\PythonScript\lib\ModelineLanguageDetectors.py	Language detector examples.

# vi: syntax=txt : wrap : tabstop=8
Source: ModelineParser_readme.txt, updated 2013-01-23