Select All Then Auto Indent


#1

So I want to make a keyboard shortcut to first select all the text and then auto indent it.

This is my code for the init.coffee
atom.commands.add ‘atom-text-editor’, ‘custom:auto-format’, ->
editor = atom.workspace.getActiveTextEditor()
core.selectAll();
editor.autoIndent()

And this is my code for the keymap.cson
’atom-text-editor’:
‘ctrl-shift-f’: ‘custom:auto-format’

Now when I try to use the shortcut, nothing happens. Can someone help please.

Thanks, Popolok


#2

For the changes to take effect, the software must be restarted.
Did you do this yet?

Ctrl+Shift+F5 is the “soft” restart.
Else the “hard” restart is to close Atom and re-open it.




See is the following code helps you:

atom.commands.add 'atom-text-editor', 'custom:auto-format', ->
	return false unless _editor = atom.workspace.getActiveTextEditor()
	_editor.selectAll()
	_editor.autoIndentSelectedRows()
	_editor.clearSelections()

Reference: https://atom.io/docs/api/v1.23.2/TextEditor


#3

So doing the soft reset gave me this error.
Uncaught ReferenceError: core is not defined

But the code fixed the problem

Thank you


#4

There’s no core variable. Any globals provided by Atom are under atom, such as atom.workspace and atom.commands.