Composing Commands from Package (latextools)


#1

In an attempt to get atom well setup with Latex I am trying to compose two commands to one keybind. I’ve done a fair amount of research prior, and I’m grasping that I write a script in the init.coffee file and then call that in the keymap file. That being said, I am very inexperienced with Atom and am fairly lost after the following. The two commands I’m trying to combine are found in the latextools package, which are build & delete-temp-files. Assigning them to their own keymaps works perfectly, but I am lost trying to write a script to run both, one after the other. The commands are the following;

latextools:build
latextools:delete-temp-files

I would really appreciate if anyone would be able to assist me in getting a working script to assign to a keybind! Thanks in advance,

Jared.


#2

Just add this to your init.coffee.

atom.commands.add 'atom-text-editor', 'custom:latextools-build-del-temp', (event) ->
  atom.commands.dispatch event.target, 'latextools:build'
  atom.commands.dispatch event.target, 'latextools:delete-temp-files'

#3

That is wonderful, just what I was looking for. Thank you very much! That being said, this arises a new problem I’ve found. Despite those commands being in that order, the build event takes longer than the temp file delete, so despite running first it deletes the temp files before the build is even finished building, which means there are no temp files to delete yet. Is there a way to add a delay between the two, or only have the second run after the first is completed?

Thanks again!


#4

You can use setTimeout() to make the delay. atom.commands.dispatch() does not return a promise, so I don’t believe there’s a direct way to follow up on when it’s finished without modifying the latextools command to give yourself one.