Skip to content

Latest commit

 

History

History
172 lines (119 loc) · 4.82 KB

SNIPPETS.md

File metadata and controls

172 lines (119 loc) · 4.82 KB

Snippets for your macros.coffee

A toolbar button for the command palette

The code snippet for your macros.coffee:

@commandPalette = ->
  dispatchWorkspaceCommand 'command-palette:toggle'
@commandPalette.icon = 'three-bars'

@cpSeparator = "----------------"

Toolbar buttons for mocha testing

Requires the mocha-test-runner package.

The code snippet for your macros.coffee:

@runTest = ->
  dispatchWorkspaceCommand  'mocha-test-runner:run'
@runTest.icon = 'ion-checkmark'


@runLastTest  = ->
  dispatchWorkspaceCommand  'mocha-test-runner:run-previous'
@runLastTest.icon = 'ion-checkmark-circled'

@debugTest = ->
  dispatchWorkspaceCommand  'mocha-test-runner:debug'
@debugTest.icon = 'bug'

@debugLastTest = ->
  dispatchWorkspaceCommand  'mocha-test-runner:debug-previous'
@debugLastTest.icon = 'ion-bug'

@testSep = "----------------"

Open file from path on clipboard

Copy your filename (e.g. from your stacktrace) to the clipboard. Run this command:

openExtendedPath = (extendedPath) ->
  parts = /^([^:]+)(?::(\d+)(?::(\d+))?)?$/.exec(extendedPath)
  return unless parts?

  [filename,row,col] = parts.slice(1)
  return unless filename?

  fs = require 'fs'
  unless fs.existsSync(filename)
    alert "File not found: #{filename}"
    return

  atom.workspace.open(filename)
  .then ->

    return unless row?
    col ?= 0

    {Point} = require 'atom'
    position = new Point(--row, --col)
    getActiveTextEditor().scrollToBufferPosition(position, center:true)
    getActiveTextEditor().setCursorBufferPosition(position)

@openFileFromPathInClipboard = ->
  extendedPath = atom.clipboard.read()
  openExtendedPath(extendedPath)
@openFileFromPathInClipboard.icon = 'fa-file'

Main toolbar

Add Icons to the toolbar for the main Atom, commands, like toolbar-main does:

@tbMainSep0 = '-'

@newFile = -> dispatchWorkspaceCommand 'application:new-file'
@newFile.icon = 'ion-document'
@newFile.title = 'New File'

@openFile = -> dispatchWorkspaceCommand 'application:open-file'
@openFile.icon = 'ion-folder'
@openFile.title = 'Open...'

@saveFile = -> dispatchWorkspaceCommand 'core:save'
@saveFile.icon = 'ion-archive'
@saveFile.title = 'Save'

@tbMainSep1 = '-'

@findInBuffer = -> dispatchWorkspaceCommand 'find-and-replace:show'
@findInBuffer.icon = 'ion-search'
@findInBuffer.title = 'Find in Buffer'

@replaceInBuffer = -> dispatchWorkspaceCommand 'find-and-replace:show-replace'
@replaceInBuffer.icon = 'ion-shuffle'
@replaceInBuffer.title = 'Replace in Buffer'

@tbMainSep2 = '-'

@toggleCommandPalette = -> dispatchWorkspaceCommand 'command-palette:toggle'
@toggleCommandPalette.icon = 'ion-navicon-round'
@toggleCommandPalette.title = 'Toggle Command Palette'

@openSettings = -> dispatchWorkspaceCommand 'settings-view:open'
@openSettings.icon = 'ion-gear-a'
@openSettings.title = 'Open Settings View'

if atom.inDevMode()
  @tbMainSep3 = '-'

  @reloadWindow = -> dispatchWorkspaceCommand 'window:reload'
  @reloadWindow.icon = 'ion-refresh'
  @reloadWindow.title = 'Reload Window'

  @toggleDeveloperTools = -> require('remote').getCurrentWindow().toggleDevTools()
  @toggleDeveloperTools.icon = 'terminal'
  @toggleDeveloperTools.title = 'Toggle Developer Tools'

"Do not disturb!"

You might not want to be disturbed during work... So why not simply switch a red light on, when working (i.e. Atom is open), and switch it of when you stopped?

Ingredients (as running at my office):

  • A red light, e.g. this one, (hacked to run on wired power supply)
  • A radio controllable socket, e.g. these
  • A RF-Gateway, e.g. Brematic 433
  • A control-script, e.g. this one

The code snippet for your macros.coffee:

atom.redLightOn = false # remember state globally

# the control methods

switchRedLightOn = ->
  exec 'gtfsi04 101100111000 00010001'
  atom.redLightOn = true

switchRedLightOff = ->
  exec 'gtfsi04 101100111000 00000000'
  atom.redLightOn = false

# Button on the toolbar / command in the menu for manual triggering:

@toggleRedLight = ->
  if atom.redLightOn then switchRedLightOff() else switchRedLightOn()

@toggleRedLight.title =  ->
  if atom.redLightOn then 'Switch Red Light off' else 'Switch Red Light on'

@toggleRedLight.icon =  ->
  if atom.redLightOn then 'ion-ios7-lightbulb-outline' else 'ion-ios7-lightbulb'

# call on load/on unload:

@onLoad = =>
  switchRedLightOn()
  @toggleRedLight.updateButton()

@onUnload = ->
  switchRedLightOff()