Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
369f0a1
ST3 compatibility, VIM compatibility
klorenz Jan 28, 2014
82618b3
removed logging
klorenz Jan 28, 2014
b858efa
remove typo
MerlinDMC Oct 7, 2014
d100a14
PY3: make python3 happy
MerlinDMC Oct 7, 2014
fbac0c3
fix typo
MerlinDMC Oct 7, 2014
ed26369
Migrate cleanup script to bash
Frizlab Jan 22, 2026
a2fba70
Fix cd in cleanup
Frizlab Jan 22, 2026
738e833
Add __pycache__ in the cleanup files in cleanup script
Frizlab Jan 22, 2026
438e47e
Convert .gitignore to unix EoL
Frizlab Jan 22, 2026
368fd09
Remove obsolete hg files
Frizlab Jan 22, 2026
ffd3be0
Remove obsolete “make release” script
Frizlab Jan 22, 2026
9116291
Dummy code formatting change
Frizlab Jan 22, 2026
1ee1ba9
Remove RunTests script
Frizlab Jan 22, 2026
b0785da
Dummy code-style fix
Frizlab Jan 22, 2026
62516f9
Convert and update the Readme
Frizlab Jan 22, 2026
431a272
Update and rename the license file
Frizlab Jan 22, 2026
767ae64
Convert EoL to unix everywhere
Frizlab Jan 22, 2026
540276e
Dummy comments formatting fixes
Frizlab Jan 23, 2026
58c110e
Update manifest file
Frizlab Jan 23, 2026
dd26106
Remove modeline from script
Frizlab Jan 23, 2026
396c317
Remove unused files
Frizlab Jan 23, 2026
4d8e7ac
Use double-quotes instead of simple-quotes
Frizlab Jan 23, 2026
13cfdf9
Ident empty lines
Frizlab Jan 23, 2026
195d48a
Dummy syntax changes
Frizlab Jan 23, 2026
3c60255
Fix and make less flexible syntax setting
Frizlab Jan 23, 2026
5ee3bfe
Dummy code formatting change
Frizlab Jan 23, 2026
3cb77eb
Remove some dead code
Frizlab Jan 23, 2026
d331972
Remove vim support
Frizlab Jan 23, 2026
a888337
Add info about setting language name for x_syntax in Readme
Frizlab Jan 23, 2026
0dea4ee
Fix some rst to md conversion failures
Frizlab Jan 23, 2026
337c2fa
Remove some dead code
Frizlab Jan 23, 2026
c4f6e22
Disable debug logging
Frizlab Jan 23, 2026
241186f
Import importlib instead of imp
Frizlab Jan 23, 2026
7c3b0c1
Differentiate logging to log and to tmp
Frizlab Jan 23, 2026
bee07e6
Add some missing trailing newlines
Frizlab Jan 23, 2026
dfb5bba
Remove init from tests
Frizlab Jan 23, 2026
89aa5b0
Remove useless command
Frizlab Jan 23, 2026
f595ee1
Fix running the tests
Frizlab Jan 23, 2026
4f7359c
Continue test fixes
Frizlab Jan 23, 2026
79c0ede
Remove type hints in tests as they are not supported by UnitTesting
Frizlab Jan 23, 2026
6bad26b
Fix test compilation
Frizlab Jan 23, 2026
b001b0f
Change a test to make sure we do not call meta_info anymore
Frizlab Jan 23, 2026
fb9ff7f
Fix test_get_line_comment_char_does_not_call_meta_info
Frizlab Jan 23, 2026
40e1935
Fix test_to_json_type
Frizlab Jan 23, 2026
5680c0c
Enable a new test, remove dead code
Frizlab Jan 24, 2026
42823fd
Finish migrating old original tests
Frizlab Jan 24, 2026
6120e85
Reformat newer test file and remove duplicated test
Frizlab Jan 24, 2026
9499d28
Typo fix
Frizlab Jan 24, 2026
28b5af6
Add Guillermo López-Anglada contribution in Readme
Frizlab Jan 24, 2026
46380fb
Add Guillermo López-Anglada Copyright back in the License file
Frizlab Jan 24, 2026
ceb7d47
Update URL for Sublime package installation documentation
Frizlab Jan 24, 2026
6c71f4c
Add a GitHub workflow to test the package on the CI
Frizlab Jan 24, 2026
8aa5377
Start splitting source code in multiple files
Frizlab Jan 25, 2026
b56d6de
Add settings
Frizlab Jan 26, 2026
d35f3ae
Remove the delimited mode from default formats
Frizlab Jan 26, 2026
44f875a
Remove a stray log
Frizlab Jan 26, 2026
99e6ab3
Remove a useless import
Frizlab Jan 26, 2026
285b2a6
Add new setting to set the number of lines to scan to find the modelines
Frizlab Jan 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: tests

on: [push, pull_request]

jobs:
run-tests:
strategy:
fail-fast: false
matrix:
st-version: [3, 4]
os: ["ubuntu-latest", "macOS-latest", "windows-latest"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: SublimeText/UnitTesting/actions/setup@v1
with:
sublime-text-version: ${{ matrix.st-version }}
- uses: SublimeText/UnitTesting/actions/run-tests@v1
with:
coverage: true
- uses: codecov/codecov-action@v4
24 changes: 11 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
*.hgignore
*.hgtags
*.pyc
*.cache
*.sublime-project

_*.txt
sample-grammar.js
Manifest
MANIFEST

dist/
build/
*.pyc
*.cache
*.sublime-project

_*.txt
sample-grammar.js
Manifest
MANIFEST

dist/
build/
9 changes: 0 additions & 9 deletions .hgignore

This file was deleted.

2 changes: 0 additions & 2 deletions .hgtags

This file was deleted.

1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.8
10 changes: 10 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"caption": "Preferences: Sublime Modelines Settings",
"command": "edit_settings",
"args": {
"base_file": "${packages}/Modelines/Sublime Modelines.sublime-settings",
"default": "/* See the left pane for the list of settings and valid values. */\n{\n\t$0\n}\n",
}
}
]
39 changes: 20 additions & 19 deletions LICENSE.TXT → License.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
Copyright (c) 2010 Guillermo López-Anglada

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Copyright (c) 2010 Guillermo López-Anglada
(c) 2026 Frizlab

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
4 changes: 0 additions & 4 deletions MANIFEST.in

This file was deleted.

22 changes: 22 additions & 0 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[{
"id": "preferences",
"children": [
{
"caption": "Package Settings",
"mnemonic": "P",
"id": "package-settings",
"children": [
{
"caption": "Sublime Modelines",
"id": "sublime-modelines-settings",
"command": "edit_settings",
"args": {
"base_file": "${packages}/Modelines/Sublime Modelines.sublime-settings",
"default": "/* See the left pane for the list of settings and valid values. */\n{\n\t$0\n}\n",
}
}
]
}
]
}
]
72 changes: 0 additions & 72 deletions README.rst

This file was deleted.

90 changes: 90 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Sublime Modelines

Set settings local to a single buffer.
A more granular approach to settings than the per file type `.sublime-settings` files.

Inspired by Vim’s modelines feature.


## Getting Started

### Recommended Installation

Use Package Control and install `SublimeModelines`.

### Manual Installation

Download and install [SublimeModelines](<https://github.com/SublimeText/Modelines>).

See the [installation instructions](<https://docs.sublimetext.io/guide/extensibility/packages.html#installing-packages>) for `.sublime-package`s.


## Side Effects

Buffers will be scanned `.on_load()` for modelines and settings will be set accordingly.
Settings will apply **only** to the buffer declaring them.

**Note**: Application- and window-level options declared in modelines are obviously global.


## Usage

### How to Declare Modelines

Modelines must be declared at the top or the bottom of source code files with one of the following syntaxes:

```text
# sublime: option_name value
# sublime: option_name value; another_option value; third_option value
```

**Note**:
`#` is the default comment character.
Use the corresponding single-line comment character for your language.
When there isn't a concept of comment, the default comment character must be used.

### How to Define Comment Characters in Sublime Text

SublimeModelines finds the appropriate single-line comment character by inspecting the `shellVariables` preference,
which must be defined in a `.tmPreferences` file.
To see an example of how this is done, open `Packages/Python/Miscellaneous.tmPreferences`.

Many packages giving support for programming languages already include this,
but you might need to create a `.tmPreferences` file for the language you're working with
if you want SublimeModelines to be available.


## Caveats

If the option’s value contains a semicolon (`;`), make sure it isn't followed by a blank space.
Otherwise it will be interpreted as a multi-option separator.


## Non-Standard Options

For some common cases, no directly settable option exists (for example, a setting to specify a syntax).
For such cases, Sublime Modelines provides non-standard accessors as a stop-gap solution.

```text
# sublime: x_syntax Foo
or
# sublime: x_syntax Packages/Foo/Foo.tmLanguage
```

Sets the syntax to the specified `.tmLanguage` file.


# Contributors

[Guillermo López-Anglada](<https://github.com/guillermooo>):
- Implemented the first version of this package (for Sublime Text 2).

Kay-Uwe (Kiwi) Lorenz <kiwi@franka.dyndns.org> (<http://quelltexter.org>):
- Added VIM compatibility;
- Smart syntax matching;
- Modelines also parsed on save;
- Settings are erased from view, if removed from modeline.

[Frizlab](<https://github.com/Frizlab>):
- Removed VIM compatibility (use `VimModelines` if you need that);
- Modernize/clean the project, and make sure it works with SublimeText 4.
17 changes: 17 additions & 0 deletions Sublime Modelines.sublime-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
/* Which types of modelines format are allowed. */
"formats": [
/* `# sublime: key val(; key2 val2)*`
* Usually works well unless putting the modeline in a `/*`-style comment.
* Can also not work when the syntax of the file is not known, because we check the line to begin with the comment char before parsing it. */
"classic",
/* `#~~ sublime: key val(; key2 val2)* ~~`
* For this format the comment char does not matter.
* All that matter is there is a `~~` token before the 9th char of the line (and another one anywhere in the line). */
//"delimited",
],

/* These two settings determine how far the search for a modeline should be done. */
"number_of_lines_to_check_from_beginning": 5,
"number_of_lines_to_check_from_end": 5,
}
9 changes: 9 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from . import logger
from . import settings
from . import sublime_modelines

__all__ = [
"logger",
"settings",
"sublime_modelines",
]
38 changes: 38 additions & 0 deletions app/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sys



class Logger:
"""A simple logger."""

# Default config for the logger.
log_to_tmp = False
enable_debug_log = False

def __new__(cls, *args, **kwargs):
raise RuntimeError("Logger is static and thus cannot be instantiated.")

@staticmethod
def debug(s, *args):
if not Logger.enable_debug_log:
return
Logger._log(Logger._format("", s, *args))

@staticmethod
def info(s, *args):
Logger._log(Logger._format("", s, *args))

@staticmethod
def warning(s, *args):
Logger._log(Logger._format("*** ", s, *args))

@staticmethod
def _format(prefix, s, *args):
return "[Sublime Modelines] " + prefix + (s % args) + "\n"

@staticmethod
def _log(str):
if Logger.log_to_tmp:
with open("/tmp/sublime_modelines_debug.log", "a") as myfile:
myfile.write(str)
sys.stderr.write(str)
Loading