Table of Contents
Basic Information
Grammar Rules
Match syntax elements
Match multiple elements
Match begin with end and
Home Technology peripherals It Industry How To Develop a Package for GitHub's Atom Code Editor

How To Develop a Package for GitHub's Atom Code Editor

Feb 19, 2025 am 10:20 AM

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.

How To Develop a Package for GitHub's Atom Code Editor

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 valid package.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.

How To Develop a Package for GitHub's Atom Code Editor

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.

How To Develop a Package for GitHub's Atom Code Editor

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"
}
Copy after login
Copy after login

Keyfield explanation:

  • "name": Package name.
  • "version": Version number, following the convention for major, minor, and revised versions. It is recommended to use 0.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"
}
Copy after login
Copy after login
  • 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']
Copy after login

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
    }
]
Copy after login

matchUse regular expressions, nameSpecify 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'
}
Copy after login

Match begin with end and

beginMatch the start and end tags using the end and

properties, such as matching single quote strings:
{
    'match': '\b(function)\s+(\w+)\s*\(.*\)'
    'captures': {
        '1': { 'name': 'keyword.control.mylanguage' },
        '2': { 'name': 'entity.name.function.mylanguage' }
    },
    'name': 'meta.function.mylanguage'
}
Copy after login

beginCaptures You can also use endCaptures and patterns to capture the start and end tags, and the

attributes match sub-elements inside the matching element.

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

file.

apm publish minorUse the minor command to publish the package (major, patch, and

respectively update the minor version, major version and patch version respectively). This command will register your package name, add version number, create Git tags and push changes.

How To Develop a Package for GitHub's Atom Code Editor

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Building a Network Vulnerability Scanner with Go Building a Network Vulnerability Scanner with Go Apr 01, 2025 am 08:27 AM

This Go-based network vulnerability scanner efficiently identifies potential security weaknesses. It leverages Go's concurrency features for speed and includes service detection and vulnerability matching. Let's explore its capabilities and ethical

CNCF Arm64 Pilot: Impact and Insights CNCF Arm64 Pilot: Impact and Insights Apr 15, 2025 am 08:27 AM

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

Serverless Image Processing Pipeline with AWS ECS and Lambda Serverless Image Processing Pipeline with AWS ECS and Lambda Apr 18, 2025 am 08:28 AM

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

Top 21 Developer Newsletters to Subscribe To in 2025 Top 21 Developer Newsletters to Subscribe To in 2025 Apr 24, 2025 am 08:28 AM

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

See all articles