Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sequences of commands #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ aliasCommand 'package-control:install',
aliasCommand 'grammar-selector:set-syntax',
orig: 'grammar-selector:show'
scope: 'atom-editor'

# Composed commands
# You can pass it an array of commands
aliasCommand 'wq',
orig: ['core:save', 'core:close']
```

## Running Tests
Expand Down
7 changes: 6 additions & 1 deletion lib/atom-alias-command.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{CompositeDisposable} = require 'atom'

typeIsArray = Array.isArray || ( value ) -> return {}.toString.call( value ) is '[object Array]'

module.exports = aliasCommand = (as, {orig, scope}) ->
scope ?= 'atom-workspace'
aliasCommand.subscriptions.add(
atom.commands.add scope, as, (event) ->
atom.commands.dispatch event.target, orig
if typeIsArray orig
atom.commands.dispatch event.target, o for o in orig
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find great info in the Atom docs about the queuing behavior of commands. For example if I orig: dispatch('core:save') then dispatch('core:close'), does Atom guarantee that save will complete before we close the file? Perhaps the two commands can be executed in any order.

We don't need to answer this now if it's working for you. Just something to keep in mind if you notice any flakiness saving.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found these related discussions:
atom/atom#2670 (comment)
atom/atom@9aee7d4

Sounds like Atom core's stance is that composing commands at the dispatch level is ambiguous (series or parallel? what if one fails?), and that the ambiguity should be resolved by defining a new command that does the desired composition at the JS API level.

Seems to me like a reasonable stance to support with this plugin. Principled objection?

else
atom.commands.dispatch event.target, orig
)

aliasCommand.activate = ->
Expand Down