Share your init.coffee


#1

Hi guys and Marry Christmas :),

I am curios about some useful scripts in init.coffee, would you like to share yours ?:slight_smile:


Share your stylesheet!
Key Bind Regex Find and Replace
How can we help you write packages?
#2

My Atom environment is always available at https://github.com/lee-dohm/dotfiles/tree/master/atom

But in the interest of posterity, here is what is currently in my init.coffee:

path = require 'path'

oldWindowDimensions = {}

atom.commands.add 'atom-workspace',
  'custom:open-todo-list': ->
    todoList = path.join(process.env.HOME, 'Dropbox/todo/todo.txt')
    atom.workspace.open(todoList)

  'custom:screenshot-prep': ->
    oldWindowDimensions = atom.getWindowDimensions()
    atom.setWindowDimensions('width': 1366, 'height': 768)

  'custom:screenshot-restore': ->
    atom.setWindowDimensions(oldWindowDimensions)

#3

thank you @leedohm anybody else ? :slight_smile: @mark_hahn ? @abe?


#4

I don’t have anything in my init.coffee. I find it easiest to just create packages for anything I need.


#5

I do tend to go through and audit both my init.coffee and styles.less occasionally to convert appropriate portions to packages.


#6

Same here :smile:

Crap to reach the 20 chars limit


#7

Actually, I’m probably going to create a todo.txt package soon, so a third of my init.coffee will go away then. I just have to get the first version of Endokken wrapped up.


#8

Somewhere I read that Atom has a different cursor blink period than the rest of OSX. So:

atom.workspaceView.eachEditorView (editorView) ->
    editorView.component.props.cursorBlinkPeriod = 1000

I have no idea whether it’s still needed…


#9

This is as always a work in progress

path = require 'path'

# ----------------------------------------------------------------------------
# Commands
# ----------------------------------------------------------------------------
atom.commands.add 'atom-workspace',
'custom:open-todo-list': ->
    todoList = path.join(process.env.HOME, 'Dropbox/Bucket/Todo.taskpaper')
    atom.workspace.open(todoList)

# ----------------------------------------------------------------------------
# Behaviors
# ----------------------------------------------------------------------------
getActiveTextEditor = () ->
    atom.workspace.getActiveTextEditor()

onActiveTextEditor = () ->
    extension = path.extname(getActiveTextEditor()?.getPath())
    if extension is '.md' or extension is '.markdown'
        atom.workspaceView.addClass 'markdown-user-custom'

        # Soft Wrap
        if not getActiveTextEditor()?.isSoftWrapped()
            getActiveTextEditor()?.setSoftWrapped true
    else
        atom.workspaceView.removeClass 'markdown-user-custom'

    if extension is '.taskpaper'
        atom.workspaceView.addClass 'todo-user-custom'

        # Soft Wrap
        if not getActiveTextEditor()?.isSoftWrapped()
            getActiveTextEditor()?.setSoftWrapped true
    else
        atom.workspaceView.removeClass 'todo-user-custom'

atom.workspace.onDidChangeActivePaneItem =>
    onActiveTextEditor()

onActiveTextEditor()

    #     # Hide TreeView if this is the only tab visible
    #     tabs = workspace.find('.tab-bar')
    #     if (tabs.find('li').length) == 1 and workspace.find('.tree-view').length
    #         workspace.trigger 'tree-view:toggle'
    #
# ----------------------------------------------------------------------------
# Hide tabs if there is only one tab open in the pane
# ----------------------------------------------------------------------------
onPaneEvent = (paneView) ->
    tabs = paneView.find('.tab-bar')
    if paneView.model.getItems().length == 1
        tabs.hide(150)
    else
        tabs.show(150)

atom.workspace.onDidAddPaneItem =>
    paneView = atom.workspaceView.getActivePaneView()
    onPaneEvent(paneView)

atom.workspace.onDidDestroyPaneItem =>
    paneView = atom.workspaceView.getActivePaneView()
    onPaneEvent(paneView)

atom.workspaceView.eachPaneView (paneView) =>
    onPaneEvent(paneView)

And my styles.less to go with it

@import "packages/file-icons/features/force-show-icons";

atom-text-editor {
    -webkit-font-smoothing: antialiased;
}

atom-text-editor::shadow .git-commit.line-too-long.deprecated {
    color: orange;
    text-decoration: none;
}

atom-text-editor::shadow .git-commit.line-too-long.illegal {
    color: #fff;
    background: #DA2C43;
    opacity: 0.9;
}

// ----------------------------------------------------------------------------
// .taskpaper
// ----------------------------------------------------------------------------
.todo-user-custom {
    atom-text-editor {
        margin-top:  20px;
        margin-left: auto;
        margin-right: auto;
        width: 70%;
        opacity: 0.7;
    }

    atom-text-editor::shadow .gutter {
        display: none;
    }
}


// ----------------------------------------------------------------------------
// markdown
// ----------------------------------------------------------------------------
.markdown-user-custom {
    atom-text-editor {
        margin-top:  20px;
        margin-left: auto;
        margin-right: auto;
        width: 70%;
        opacity: 0.7;
    }

    atom-text-editor::shadow .gutter {
        display: none;
    }
}

#10

I know this is an old thread; but I would have loved to find this piece of init.coffee when I was looking for a solution to build a single file:


MakePandocFile = (extention, args) ->
  [pandoc_args,cwd] =  MakePandocArgs(extention,args)
  spawnchild('pandoc',pandoc_args,cwd)

MakePandocArgs = (extention, args) ->
  editor = atom.workspace.getActiveTextEditor()
  from_path = editor.getPath()
  to_path = from_path.substr(0, from_path.lastIndexOf('.') + 1) + extention;
  cwd = from_path.substr(0, from_path.lastIndexOf('\\') + 1);
  fpath = [from_path]
  pandoc_args = fpath.concat(args, ["-o"],[to_path])
  [pandoc_args, cwd]

spawnchild = (cmd,args,cwd) ->
  childProcess = require 'child_process'
  pandoc = childProcess.spawn cmd,args, {cwd}
  pandoc.stdout.on 'data', (d) -> console.log('stdout: ' + d);
  pandoc.stderr.on 'data', (d) -> console.log('stderr: ' + d);
  pandoc.on 'close', (c) -> console.log('child process exited with code ' + c);

atom.commands.add 'atom-text-editor', 'Pandoc:pandoc2Word': ->
  args = ['-s']
  MakePandocFile('docx',args)

atom.commands.add 'atom-text-editor', 'Pandoc:pandoc2Tex': ->
  args = ['--latex-engine=xelatex', '-s']
  MakePandocFile('tex',args)

atom.commands.add 'atom-text-editor', 'Pandoc:pandoc2HTML': ->
  args = ['--webtex','-s']
  MakePandocFile('html',args)

atom.commands.add 'atom-text-editor', 'Pandoc:pandoc2RevealJS': ->
  args = ['-t', 'revealjs','-V','theme=solarized','transistion=fade','-s']
  MakePandocFile('html',args)

I’m writing in markdown, and whenever someon wants to have a Word version of my memos I just Ctrl-Shift-PPandoc2Word and there’s a beautiful Word File! But with the same ease of use I’ll make it HTML or Tex or … whatever!


#11

Nice! Would be great if you could turn that into a package. Have you seen Using Atom for academic writing? :smile:


#13

I’ve seen that, I actually was looking there to find what I built myself :slight_smile:
If I find some time I’ll turn it into a package.


#14

Here is my init script

Probably the most useful thing is the toggle folding function I added. I have it bound to shift-f in normal mode (reverse find character isn’t that useful).


#15


#16

Hey, my personal project allows you to share not only your init scripts, but also your settings in general. Feel free to check it out and let me know if you have any honest feedback :slight_smile: AtomSettings.com


#17

It’s still a WIP, alpha-ish version :stuck_out_tongue: