This is a major-mode for editing .cls files in ObjectScript using treesitter.
-
Emacs Version: You will need Emacs version 29.1 or greater. This version should ship with tree-sitter, but you will need to install it if it is missing.
-
Get objectscript-major-mode. You'll need to download our major mode for emacs here: https://github.com/intersystems/emacs-objectscript-ts-mode.git
-
Tree-sitter Library Files: You need the library files generated by
tree-sitter-objectscript
. You can configure Emacs to fetch these automatically from the repository.-
Add the ObjectScript languages to
treesit-language-source-alist
. This tells tree-sitter where to find the parser source files. Run the following Elisp for each required language (udl
,core
, andexpr
).For
udl
:(add-to-list 'treesit-language-source-alist '(objectscript_udl . "(https://github.com/intersystems/tree-sitter-objectscript.git)" "main" "udl/src")))
-
You can also add the languages to the alist directly in your configuration file. This should compile the language into an el.gz file which EMACS uses for its progmodes.
-
Additional Grammars: If you plan to write embedded Python, Java, or JavaScript within
.cls
files and want syntax highlighting, you will also need their respective tree-sitter grammars. You can install these using thetreesit-install-language-grammar
command, as they are officially supported. -
Install Grammars: After configuring the sources, run the command
M-x treesit-install-language-grammar
for each of the following grammars:objectscript_udl
objectscript_core
objectscript_expr
This will compile and install the grammars, making them available to the tree-sitter parser.
Once the preliminary steps are complete, installing the major-mode file is straightforward.
-
Place the
objectscript_udl-ts-mode.el
file in your Emacslisp/progmodes/
directory and append.gz
to the end so EMACS can read it properly. (Note: MELPA support coming soon so this step will be unnecessary). The location of this directory can vary based on your setup:- macOS:
/Applications/Emacs.app/Contents/Resources/lisp/progmodes/
- Windows/Linux: The path may differ.
- macOS:
-
With the file in place, you can now open a relevant file and enable the major-mode by running
M-x objectscript_udl-ts-mode
.
To make this major-mode the default for all .cls
files, add the following two lines to your init.el
file:
(autoload 'objectscript_udl-ts-mode "/Applications/Emacs.app/Contents/Resources/lisp/progmodes/objectscript_udl-ts-mode.el.gz" "A major mode for objectscript." t)
(add-to-list 'auto-mode-alist '("\\.cls\\'" . objectscript_udl-ts-mode))
This configuration will ensure that objectscript_udl-ts-mode is automatically activated when you open a .cls file, overriding the default mode for LaTeX files which can also use the .cls extension.
This project provided as-is and is licensed under the MIT License.