Atom Editor Extension Guide: Create and publish your own syntax highlighter package
Atom editor is powerful, but sometimes you may need some features that are not provided by default, such as syntax highlighting for a specific language. At this time, it is particularly important to create custom packages. This article will guide you to create a syntax highlighting package and publish it to the Atom community.
Core points:
- Extend the functionality of the Atom editor by creating custom packages, especially for features that are missing by default.
- Create a folder in the
.atom/packages
directory and add a validpackage.json
file to initialize the new package. - For syntax highlighting, create a
grammars
subfolder, define language rules in a CSON file, and specify how Atom recognizes and highlights the language syntax. - Test your package in Atom using the
View/Reload
function to view changes immediately and make sure that the functionality is working. - Set up a public repository on GitHub and use the
apm publish
command to publish your package to the Atom community to benefit other developers.
What will we build?
This article will guide you to create a syntax highlighter similar to language-scilab
that you can apply to any language you need. We will learn how to initialize a new package, write syntax highlighting rules, and how to publish your package to the Atom community.
Initialize the new Atom package
Atom uses a configuration file folder called .atom
to store personal options and installed packages. Packages are located in the packages
subfolder of this folder, and each package has its own folder.
The first step is to create your package folder, such as language-mylanguage
(this is a naming convention to add language support). Then, create the package.json
file in that folder, and Atom can recognize and load it.
The following is an example of the language-mylanguage
file of a package.json
package:
{ "name": "language-mylanguage", "version": "0.0.0", "description": "Mylanguage language support in Atom", "engines": { "atom": "*" }, "dependencies": {}, "repository": { "type": "git", "url": "https://github.com/JeremyHeleine/language-mylanguage.git" }, "bugs": { "url": "https://github.com/JeremyHeleine/language-mylanguage/issues" }, "license": "MIT" }
Keyfield explanation:
-
"name"
: Package name. -
"version"
: Version number, following the convention for major, minor, and revised versions. It is recommended to use0.0.0
in the initial version. -
"description"
: Package description. -
"engines"
: Atom minimum version requirements. -
"dependencies"
: Package dependencies. -
"repository"
: The GitHub repository address of the package (can be empty before release). -
"bugs"
: Address to report the problem. -
"license"
: License.
After creating the package.json
file, Atom can recognize your package. You can use the View/Reload
command to force Atom to reload the package so that changes are immediately visible.
Create a syntax highlighter package
Create a grammars
subfolder in the package folder and create a CSON file named after the language name (for example mylanguage.cson
). This file contains syntax highlighting rules.
Basic Information
Before defining grammar rules, you need to tell Atom how to recognize your language:
{ "name": "language-mylanguage", "version": "0.0.0", "description": "Mylanguage language support in Atom", "engines": { "atom": "*" }, "dependencies": {}, "repository": { "type": "git", "url": "https://github.com/JeremyHeleine/language-mylanguage.git" }, "bugs": { "url": "https://github.com/JeremyHeleine/language-mylanguage/issues" }, "license": "MIT" }
-
scopeName
: Language identifier, used for topics, other packages, or configuration files. -
name
: The language name displayed at the bottom of the Atom editor. -
fileTypes
: The file extension array used by the language.
Grammar Rules
All rules must be declared in the patterns
array, each rule is enclosed in {}
:
'scopeName': 'source.mylanguage' 'name': 'Mylanguage' 'fileTypes': ['ext1', 'ext2']
Match syntax elements
Match syntax elements using the match
attribute, such as matching numbers:
'scopeName': 'source.mylanguage' 'name': 'Mylanguage' 'fileTypes': ['ext1', 'ext2'] 'patterns': [ { # 规则1 }, { # 规则2 } ]
match
Use regular expressions, name
Specify the style class name, and follow certain naming conventions so that the theme can apply the style correctly.
Match multiple elements
Match multiple elements using the captures
attribute, such as matching function declaration:
{ 'match': '\b(([0-9]+\.?[0-9]*)|(\.[0-9]+))\b' 'name': 'constant.numeric.mylanguage' }
Match begin
with end
and
begin
Match the start and end tags using the end
and
{ 'match': '\b(function)\s+(\w+)\s*\(.*\)' 'captures': { '1': { 'name': 'keyword.control.mylanguage' }, '2': { 'name': 'entity.name.function.mylanguage' } }, 'name': 'meta.function.mylanguage' }
beginCaptures
You can also use endCaptures
and patterns
to capture the start and end tags, and the
Release Atom package
package.json
Please check if the package with the same name already exists before publishing it. You need a public GitHub repository. Update the repository address in the
apm publish minor
Use the minor
command to publish the package (major
, patch
, and
Use the apm unpublish name-of-the-package
command to cancel the release package.
Conclusion
This article describes how to create and publish Atom syntax highlighting packages. Atom's flexibility allows the creation of various types of packages, but this article is limited to the creation of syntax highlighted packages. Hope this article helps you expand the functionality of the Atom Editor and share your results with the community.
FAQs (FAQs)
(The FAQs part in the original text is omitted here, because the content of this part is highly repetitive from the above, which is a summary and explanation of the above content. In order to avoid redundancy, repeated output is not performed here.)
The above is the detailed content of How To Develop a Package for GitHub's Atom Code Editor. For more information, please follow other related articles on the PHP Chinese website!

Customized telecom software development is undoubtedly a considerable investment. However, in the long run, you may realize that such a project may be more cost-effective because it can increase your productivity like any ready-made solution on the market. Understand the most important advantages of building a customized telecommunications system. Get the exact features you need There are two potential problems with the off-the-shelf telecom software you can buy. Some lack useful features that can significantly improve your productivity. Sometimes you can enhance them with some external integration, but that isn't always enough to make them great. Other software has too many functions and is too complicated to use. You probably won't use some of these (never!). A large number of features usually adds to the price. Based on your needs

CI/CD puzzles and solutions for open source software in Arm64 architecture Deploying open source software on Arm64 architecture requires a powerful CI/CD environment. However, there is a difference between the support levels of Arm64 and traditional x86 processor architectures, which are often at a disadvantage. Infrastructure components developers for multiple architectures have certain expectations for their work environment: Consistency: The tools and methods used across platforms are consistent, avoiding the need to change the development process due to the adoption of less popular platforms. Performance: The platform and support mechanism have good performance to ensure that deployment scenarios are not affected by insufficient speed when supporting multiple platforms. Test coverage: Efficiency, compliance and

Stay informed about the latest tech trends with these top developer newsletters! This curated list offers something for everyone, from AI enthusiasts to seasoned backend and frontend developers. Choose your favorites and save time searching for rel

This tutorial guides you through building a serverless image processing pipeline using AWS services. We'll create a Next.js frontend deployed on an ECS Fargate cluster, interacting with an API Gateway, Lambda functions, S3 buckets, and DynamoDB. Th

This pilot program, a collaboration between the CNCF (Cloud Native Computing Foundation), Ampere Computing, Equinix Metal, and Actuated, streamlines arm64 CI/CD for CNCF GitHub projects. The initiative addresses security concerns and performance lim


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Zend Studio 13.0.1
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
