Sublime Forum

Sublime 3: custom syntax

#1

Hi there,

I am currently evaluating sublime 3. It looks very interested, but, after about an hour of googling, I’ve still not found a clear answer to my problem.

I will use this editor also to edit some custom files. They are basically written in some almost unknown programming language. I do not need it to 100% recognize all the tokens: as a start, it would be enough to teach it to recognize comments and keywords.

What i would like to do is:

  1. Create a new syntax file
  2. Associate the extensions to it
  3. Include c-style comment recognition in the file
  4. Include the keywords in the file

Is there any step-by-step tutorial to do this?

Thank you

0 Likes

#2

Since you are evaluating, the newer .sublime-syntax format for defining syntaxes is not interesting for you because it’s only available on dev builds at the moment.

Either way, there isn’t a strict walk through for all you steps, but there is documentation available on each of the individual steps at the unofficial docs:

docs.sublimetext.info/en/latest/ … xdefs.html
docs.sublimetext.info/en/latest/ … ments.html
docs.sublimetext.info/en/latest/ … mbols.html

0 Likes

#3

Thank you for your answer!

I have tried to follow your links, but when I install the AAAPackageDev plugin, all menus are grayed out making it basically unusable.

I have been trying to track the issue and it seems related to this long thread github.com/SublimeText/AAAPackageDev/issues/19 that basically concludes that the plugin is still not ready for sublime3.

The newer .sublime-syntax format now definitely looks more appealing to me, since it doesn’t seem to require a plugin for editing… is there a planned release date for this function? :smiley:

0 Likes

#4

This can not be the issue since the pull request that added support for Sublime Text 3 has been merged long ago (by me).
Please post your entire console log with the package installed either here or in a new issue at the PackageDev repo.

[quote=“bodom”]
The newer .sublime-syntax format now definitely looks more appealing to me, since it doesn’t seem to require a plugin for editing… is there a planned release date for this function? :D[/quote]

No. It’s been first released around April earlier this year and besides updating a few bundled pakcages, there hasn’t been any communication from the devloper since.

0 Likes

#5

DPI scale: 0.999 startup, version: 3083 linux x64 channel: stable executable: /opt/sublime_text/sublime_text working dir: / packages path: ~/.config/sublime-text-3/Packages state path: ~/.config/sublime-text-3/Local zip path: /opt/sublime_text/Packages zip path: ~/.config/sublime-text-3/Installed Packages ignored_packages: "Vintage"] pre session restore time: 0.112212 loading dictionary Packages/Language - English/en_US.dic startup time: 0.366275 first paint time: 0.430517 reloading plugin Default.block reloading plugin Default.comment reloading plugin Default.copy_path reloading plugin Default.delete_word reloading plugin Default.detect_indentation reloading plugin Default.duplicate_line reloading plugin Default.echo reloading plugin Default.exec reloading plugin Default.fold reloading plugin Default.font reloading plugin Default.goto_line reloading plugin Default.history_list reloading plugin Default.indentation reloading plugin Default.kill_ring reloading plugin Default.mark reloading plugin Default.new_templates reloading plugin Default.open_context_url reloading plugin Default.open_file_settings reloading plugin Default.open_in_browser reloading plugin Default.pane reloading plugin Default.paragraph reloading plugin Default.paste_from_history reloading plugin Default.quick_panel reloading plugin Default.save_on_focus_lost reloading plugin Default.scroll reloading plugin Default.set_unsaved_view_name reloading plugin Default.side_bar reloading plugin Default.sort reloading plugin Default.swap_line reloading plugin Default.switch_file reloading plugin Default.symbol reloading plugin Default.transform reloading plugin Default.transpose reloading plugin Default.trim_trailing_white_space reloading plugin CSS.css_completions reloading plugin Diff.diff reloading plugin HTML.encode_html_entities reloading plugin HTML.html_completions reloading plugin AAAPackageDev.AAA Traceback (most recent call last): File "/opt/sublime_text/sublime_plugin.py", line 74, in reload_plugin m = importlib.import_module(modulename) File "./importlib/__init__.py", line 90, in import_module File "<frozen importlib._bootstrap>", line 1584, in _gcd_import File "<frozen importlib._bootstrap>", line 1565, in _find_and_load File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked File "/opt/sublime_text/sublime_plugin.py", line 678, in load_module exec(compile(source, source_path, 'exec'), mod.__dict__) File "AAA in ~/.config/sublime-text-3/Installed Packages/AAAPackageDev.sublime-package", line 9 print "[AAAPackageDev] Added sublime_lib to sys.path." ^ SyntaxError: invalid syntax reloading plugin AAAPackageDev.build_sys_dev Traceback (most recent call last): File "/opt/sublime_text/sublime_plugin.py", line 74, in reload_plugin m = importlib.import_module(modulename) File "./importlib/__init__.py", line 90, in import_module File "<frozen importlib._bootstrap>", line 1584, in _gcd_import File "<frozen importlib._bootstrap>", line 1565, in _find_and_load File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked File "/opt/sublime_text/sublime_plugin.py", line 678, in load_module exec(compile(source, source_path, 'exec'), mod.__dict__) File "build_sys_dev in ~/.config/sublime-text-3/Installed Packages/AAAPackageDev.sublime-package", line 3, in <module> ImportError: No module named 'sublime_lib' reloading plugin AAAPackageDev.commands_file_dev Traceback (most recent call last): File "/opt/sublime_text/sublime_plugin.py", line 74, in reload_plugin m = importlib.import_module(modulename) File "./importlib/__init__.py", line 90, in import_module File "<frozen importlib._bootstrap>", line 1584, in _gcd_import File "<frozen importlib._bootstrap>", line 1565, in _find_and_load File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked File "/opt/sublime_text/sublime_plugin.py", line 678, in load_module exec(compile(source, source_path, 'exec'), mod.__dict__) File "commands_file_dev in ~/.config/sublime-text-3/Installed Packages/AAAPackageDev.sublime-package", line 3, in <module> ImportError: No module named 'sublime_lib' reloading plugin AAAPackageDev.completions_dev Traceback (most recent call last): File "/opt/sublime_text/sublime_plugin.py", line 74, in reload_plugin m = importlib.import_module(modulename) File "./importlib/__init__.py", line 90, in import_module File "<frozen importlib._bootstrap>", line 1584, in _gcd_import File "<frozen importlib._bootstrap>", line 1565, in _find_and_load File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked File "/opt/sublime_text/sublime_plugin.py", line 678, in load_module exec(compile(source, source_path, 'exec'), mod.__dict__) File "completions_dev in ~/.config/sublime-text-3/Installed Packages/AAAPackageDev.sublime-package", line 3, in <module> ImportError: No module named 'sublime_lib' reloading plugin AAAPackageDev.package_dev Traceback (most recent call last): File "/opt/sublime_text/sublime_plugin.py", line 74, in reload_plugin m = importlib.import_module(modulename) File "./importlib/__init__.py", line 90, in import_module File "<frozen importlib._bootstrap>", line 1584, in _gcd_import File "<frozen importlib._bootstrap>", line 1565, in _find_and_load File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked File "/opt/sublime_text/sublime_plugin.py", line 678, in load_module exec(compile(source, source_path, 'exec'), mod.__dict__) File "package_dev in ~/.config/sublime-text-3/Installed Packages/AAAPackageDev.sublime-package", line 94 print "[NewPackage] Creating new package...", ^ SyntaxError: invalid syntax reloading plugin AAAPackageDev.settings_dev Traceback (most recent call last): File "/opt/sublime_text/sublime_plugin.py", line 74, in reload_plugin m = importlib.import_module(modulename) File "./importlib/__init__.py", line 90, in import_module File "<frozen importlib._bootstrap>", line 1584, in _gcd_import File "<frozen importlib._bootstrap>", line 1565, in _find_and_load File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked File "/opt/sublime_text/sublime_plugin.py", line 678, in load_module exec(compile(source, source_path, 'exec'), mod.__dict__) File "settings_dev in ~/.config/sublime-text-3/Installed Packages/AAAPackageDev.sublime-package", line 3, in <module> ImportError: No module named 'sublime_lib' reloading plugin AAAPackageDev.snippet_dev Traceback (most recent call last): File "/opt/sublime_text/sublime_plugin.py", line 74, in reload_plugin m = importlib.import_module(modulename) File "./importlib/__init__.py", line 90, in import_module File "<frozen importlib._bootstrap>", line 1584, in _gcd_import File "<frozen importlib._bootstrap>", line 1565, in _find_and_load File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked File "/opt/sublime_text/sublime_plugin.py", line 678, in load_module exec(compile(source, source_path, 'exec'), mod.__dict__) File "snippet_dev in ~/.config/sublime-text-3/Installed Packages/AAAPackageDev.sublime-package", line 3, in <module> ImportError: No module named 'sublime_lib' reloading plugin AAAPackageDev.syntax_def_dev Traceback (most recent call last): File "/opt/sublime_text/sublime_plugin.py", line 74, in reload_plugin m = importlib.import_module(modulename) File "./importlib/__init__.py", line 90, in import_module File "<frozen importlib._bootstrap>", line 1584, in _gcd_import File "<frozen importlib._bootstrap>", line 1565, in _find_and_load File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked File "/opt/sublime_text/sublime_plugin.py", line 678, in load_module exec(compile(source, source_path, 'exec'), mod.__dict__) File "syntax_def_dev in ~/.config/sublime-text-3/Installed Packages/AAAPackageDev.sublime-package", line 85 print "[AAAPackageDev] File does not exists. (%s)" % path ^ SyntaxError: invalid syntax plugins loaded

Mhhh… it looks like a syntax error… so weird: somebody should had noticed it before… missing parenthesis on print()?

Thank you

0 Likes

#6

How did you install the package? That version is ancient.

Please remove the package and install it using Package Control.

Edit: Did you perhaps follow the instructions for manual installation? I just noticed they still point to a version from 2012 (when ST3 didn’t even exist). Will have to remove that link since there is really no point in manual installation - and if you want to do it, you should know how beforehand.

0 Likes

#7

Yep, I’ve been following the manual install instructions.

I have now uninstalled it, installed the package manager and then finally installed again.

It now works. I’ve been following your links and managed to create a first syntax definitions file. After building into .tmLanguage, is seems to be ignored by the editor, even after restarting it i still can’t select my new language.

Anyway, starting to define a language from scratch seems to be a long and useless challenge to me: I would prefer to start from something else (eg. C++) and adapt it to my needs. Is it possible? I couldn’t find definition files for other languages.

0 Likes

#8

You can open resources in the shipped packages via PackageResourceViewer (package).

I do not know exactly what your syntax is like, but you could either copy relevant parts of existing definitions into yours, include the syntax definition of another language/file in yours (with include patterns) or, similarly to the latter, include specific parts of a syntax definition and inject custom patterns into it (requires .sublime-syntax).

0 Likes

#9

Thank you!

0 Likes