• Packages
  • Themes
  • Documentation
  • Blog
  • Discussions

Chapter 1: Getting Started

  • Why Atom?
  • Installing Atom
  • Atom Basics
  • Summary

Chapter 2: Using Atom

  • Atom Packages
  • Moving in Atom
  • Atom Selections
  • Editing and Deleting Text
  • Find and Replace
  • Snippets
  • Autocomplete
  • Folding
  • Panes
  • Pending Pane Items
  • Grammar
  • Version Control in Atom
  • GitHub package
  • Writing in Atom
  • Basic Customization
  • Summary

Chapter 3: Hacking Atom

  • Tools of the Trade
  • The Init File
  • Package: Word Count
  • Package: Modifying Text
  • Package: Active Editor Info
  • Creating a Theme
  • Creating a Grammar
  • Creating a Legacy TextMate Grammar
  • Publishing
  • Iconography
  • Debugging
  • Writing specs
  • Handling URIs
  • Cross-Platform Compatibility
  • Converting from TextMate
  • Hacking on Atom Core
  • Contributing to Official Atom Packages
  • Creating a Fork of a Core Package in atom/atom
  • Maintaining a Fork of a Core Package in atom/atom
  • Summary

Chapter 4: Behind Atom

  • Configuration API
  • Keymaps In-Depth
  • Scoped Settings, Scopes and Scope Descriptors
  • Serialization in Atom
  • Developing Node Modules
  • Interacting With Other Packages Via Services
  • Maintaining Your Packages
  • How Atom Uses Chromium Snapshots
  • Summary

Reference: API

  • AtomEnvironment
  • BufferedNodeProcess
  • BufferedProcess
  • Clipboard
  • Color
  • CommandRegistry
  • CompositeDisposable
  • Config
  • ContextMenuManager
  • Cursor
  • Decoration
  • DeserializerManager
  • Directory
  • DisplayMarker
  • DisplayMarkerLayer
  • Disposable
  • Dock
  • Emitter
  • File
  • GitRepository
  • Grammar
  • GrammarRegistry
  • Gutter
  • HistoryManager
  • KeymapManager
  • LayerDecoration
  • MarkerLayer
  • MenuManager
  • Notification
  • NotificationManager
  • Package
  • PackageManager
  • Pane
  • Panel
  • PathWatcher
  • Point
  • Project
  • Range
  • ScopeDescriptor
  • Selection
  • StyleManager
  • Task
  • TextBuffer
  • TextEditor
  • ThemeManager
  • TooltipManager
  • ViewRegistry
  • Workspace
  • WorkspaceCenter

Appendix A: Resources

  • Glossary

Appendix B: FAQ

  • Is Atom open source?
  • What does Atom cost?
  • What platforms does Atom run on?
  • How can I contribute to Atom?
  • Why does Atom collect usage data?
  • Atom in the cloud?
  • What's the difference between an IDE and an editor?
  • How can I tell if subpixel antialiasing is working?
  • Why is Atom deleting trailing whitespace? Why is there a newline at the end of the file?
  • What does Safe Mode do?
  • I have a question about a specific Atom community package. Where is the best place to ask it?
  • I’m using an international keyboard and keys that use AltGr or Ctrl+Alt aren’t working
  • I’m having a problem with Julia! What do I do?
  • I’m getting an error about a “self-signed certificate”. What do I do?
  • I’m having a problem with PlatformIO! What do I do?
  • How do I make Atom recognize a file with extension X as language Y?
  • How do I make the Welcome screen stop showing up?
  • How do I preview web page changes automatically?
  • How do I accept input from my program or script when using the script package?
  • I am unable to update to the latest version of Atom on macOS. How do I fix this?
  • I’m trying to change my syntax colors from styles.less, but it isn’t working!
  • How do I build or execute code I've written in Atom?
  • How do I uninstall Atom on macOS?
  • macOS Mojave font rendering change
  • Why does macOS say that Atom wants to access my calendar, contacts, photos, etc.?
  • How do I turn on line wrap?
  • The menu bar disappeared, how do I get it back?
  • How do I use a newline in the result of find and replace?
  • What is this line on the right in the editor view?

Appendix C: Shadow DOM

  • Removing Shadow DOM styles

Appendix D: Upgrading to 1.0 APIs

  • Upgrading Your Package
  • Upgrading Your UI Theme Or Package Selectors
  • Upgrading Your Syntax Theme

Appendix E: Atom server-side APIs

  • Atom package server API
  • Atom update server API

  • mac
  • windows
  • linux

KeymapManager Extended

Allows commands to be associated with keystrokes in a context-sensitive way. In Atom, you can access a global instance of this object via atom.keymaps.

Key bindings are plain JavaScript objects containing CSS selectors as their top level keys, then keystroke patterns mapped to commands.

'.workspace':
  'ctrl-l': 'package:do-something'
  'ctrl-z': 'package:do-something-else'
'.mini.editor':
  'enter': 'core:confirm'

When a keystroke sequence matches a binding in a given context, a custom DOM event with a type based on the command is dispatched on the target of the keyboard event.

To match a keystroke sequence, the keymap starts at the target element for the keyboard event. It looks for key bindings associated with selectors that match the target element. If multiple match, the most specific is selected. If there is a tie in specificity, the most recently added binding wins. If no bindings are found for the events target, the search is repeated again for the target’s parent node and so on recursively until a binding is found or we traverse off the top of the document.

When a binding is found, its command event is always dispatched on the original target of the keyboard event, even if the matching element is higher up in the DOM. In addition, .preventDefault() is called on the keyboard event to prevent the browser from taking action. .preventDefault is only called if a matching binding is found.

Command event objects have a non-standard method called .abortKeyBinding(). If your command handler is invoked but you programmatically determine that no action can be taken and you want to allow other bindings to be matched, call .abortKeyBinding() on the event object. An example of where this is useful is binding snippet expansion to tab. If snippets:expand is invoked when the cursor does not follow a valid snippet prefix, we abort the binding and allow tab to be handled by the default handler, which inserts whitespace.

Multi-keystroke bindings are possible. If a sequence of one or more keystrokes partially matches a multi-keystroke binding, the keymap enters a pending state. The pending state is terminated on the next keystroke, or after ::getPartialMatchTimeout milliseconds has elapsed. When the pending state is terminated via a timeout or a keystroke that leads to no matches, the longest ambiguous bindings that caused the pending state are temporarily disabled and the previous keystrokes are replayed. If there is ambiguity again during the replay, the next longest bindings are disabled and the keystrokes are replayed again.

Class Methods

.buildKeydownEvent(key, options)

Create a keydown DOM event for testing purposes.

Argument Description

key

The key or keyIdentifier of the event. For example, 'a', '1', 'escape', 'backspace', etc.

options

optional

An Object containing any of the following:

ctrl

A Boolean indicating the ctrl modifier key

alt

A Boolean indicating the alt modifier key

shift

A Boolean indicating the shift modifier key

cmd

A Boolean indicating the cmd modifier key

which

A Number indicating which value of the event. See the docs for KeyboardEvent for more information.

target

The target element of the event.

Construction and Destruction

::constructor(options)

Create a new KeymapManager.

Argument Description

options

An Object containing properties to assign to the keymap. You can pass custom properties to be used by extension methods. The following properties are also supported:

defaultTarget

This will be used as the target of events whose target is document.body to allow for a catch-all element when nothing is focused.

::clear()

Clear all registered key bindings and enqueued keystrokes. For use in tests.

::destroy()

Unwatch all watched paths.

Event Subscription

::onDidMatchBinding(callback)

Invoke the given callback when one or more keystrokes completely match a key binding.

Argument Description

callback

Function to be called when keystrokes match a binding.

event

Object with the following keys:

keystrokes

String of keystrokes that matched the binding.

binding

KeyBinding that the keystrokes matched.

keyboardEventTarget

DOM element that was the target of the most recent keyboard event.

Return values

Returns a Disposable on which .dispose() can be called to unsubscribe.

::onDidPartiallyMatchBindings(callback)

Invoke the given callback when one or more keystrokes partially match a binding.

Argument Description

callback

Function to be called when keystrokes partially match a binding.

event

Object with the following keys:

keystrokes

String of keystrokes that matched the binding.

partiallyMatchedBindings

KeyBindings that the keystrokes partially matched.

keyboardEventTarget

DOM element that was the target of the most recent keyboard event.

Return values

Returns a Disposable on which .dispose() can be called to unsubscribe.

::onDidFailToMatchBinding(callback)

Invoke the given callback when one or more keystrokes fail to match any bindings.

Argument Description

callback

Function to be called when keystrokes fail to match any bindings.

event

Object with the following keys:

keystrokes

String of keystrokes that matched the binding.

keyboardEventTarget

DOM element that was the target of the most recent keyboard event.

Return values

Returns a Disposable on which .dispose() can be called to unsubscribe.

::onDidFailToReadFile(callback)

Invoke the given callback when a keymap file not able to be loaded.

Argument Description

callback

Function to be called when a keymap file is unloaded.

error

Object with the following keys:

message

String the error message.

stack

String the error stack trace.

Return values

Returns a Disposable on which .dispose() can be called to unsubscribe.

Adding and Removing Bindings

::add(source, bindings, priority)

Add sets of key bindings grouped by CSS selector.

Argument Description

source

A String (usually a path) uniquely identifying the given bindings so they can be removed later.

bindings

An Object whose top-level keys point at sub-objects mapping keystroke patterns to commands.

priority

A Number used to sort keybindings which have the same specificity. Defaults to 0.

Extended Methods

::build(source, bindings, priority)

Construct KeyBindings from an object grouping them by CSS selector.

Argument Description

source

A String (usually a path) uniquely identifying the given bindings so they can be removed later.

bindings

An Object whose top-level keys point at sub-objects mapping keystroke patterns to commands.

priority

A Number used to sort keybindings which have the same specificity. Defaults to 0.

Accessing Bindings

::getKeyBindings()

Get all current key bindings.

Return values

Returns an Array of KeyBindings.

::findKeyBindings(params)

Get the key bindings for a given command and optional target.

Argument Description

params

An Object whose keys constrain the binding search:

keystrokes

A String representing one or more keystrokes, such as ‘ctrl-x ctrl-s’

command

A String representing the name of a command, such as ‘editor:backspace’

target

An optional DOM element constraining the search. If this parameter is supplied, the call will only return bindings that can be invoked by a KeyboardEvent originating from the target element.

Return values

Returns an Array of key bindings.

Managing Keymap Files

::loadKeymap(path, options)

Load the key bindings from the given path.

Argument Description

path

A String containing a path to a file or a directory. If the path is a directory, all files inside it will be loaded.

options

An Object containing the following optional keys:

watch

If true, the keymap will also reload the file at the given path whenever it changes. This option cannot be used with directory paths.

priority

A Number used to sort keybindings which have the same specificity.

::watchKeymap(path, options)

Cause the keymap to reload the key bindings file at the given path whenever it changes.

This method doesn’t perform the initial load of the key bindings file. If that’s what you’re looking for, call ::loadKeymap with watch: true.

Argument Description

path

A String containing a path to a file or a directory. If the path is a directory, all files inside it will be loaded.

options

An Object containing the following optional keys:

priority

A Number used to sort keybindings which have the same specificity.

Managing Keyboard Events

::handleKeyboardEvent(event)

Dispatch a custom event associated with the matching key binding for the given KeyboardEvent if one can be found.

If a matching binding is found on the event’s target or one of its ancestors, .preventDefault() is called on the keyboard event and the binding’s command is emitted as a custom event on the matching element.

If the matching binding’s command is ‘native!’, the method will terminate without calling .preventDefault() on the keyboard event, allowing the browser to handle it as normal.

If the matching binding’s command is ‘unset!’, the search will continue from the current element’s parent.

If the matching binding’s command is ‘abort!’, the search will terminate without dispatching a command event.

If the event’s target is document.body, it will be treated as if its target is .defaultTarget if that property is assigned on the keymap.

Argument Description

event

A KeyboardEvent of type ‘keydown’

::keystrokeForKeyboardEvent(event)

Translate a keydown event to a keystroke string.

Argument Description

event

A KeyboardEvent of type ‘keydown’

Return values

Returns a String describing the keystroke.

::addKeystrokeResolver(resolver)

Customize translation of raw keyboard events to keystroke strings. This API is useful for working around Chrome bugs or changing how Atom resolves certain key combinations. If multiple resolvers are installed, the most recently-added resolver returning a string for a given keystroke takes precedence.

Argument Description

resolver

A Function that returns a keystroke String and is called with an object containing the following keys:

keystroke

The currently resolved keystroke string. If your function returns a falsy value, this is how Atom will resolve your keystroke.

event

The raw DOM 3 KeyboardEvent being resolved. See the DOM API documentation for more details.

layoutName

The OS-specific name of the current keyboard layout.

keymap

An object mapping DOM 3 KeyboardEvent.code values to objects with the typed character for that key in each modifier state, based on the current operating system layout.

Return values

Returns a Disposable that removes the added resolver.

::getPartialMatchTimeout()

Get the number of milliseconds allowed before pending states caused by partial matches of multi-keystroke bindings are terminated.

Return values

Returns a Number

  • Terms of Use
  • Privacy
  • Code of Conduct
  • Releases
  • FAQ
  • Contact
  • Contribute!
with by