Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One approach would be to, in your build system, first kill the running node process &amp; if that's not successful pass the current file to node. So your node.sublime-build might look like this:</p> <pre><code>{ "cmd": [ "killall node || node \"$file\"" ], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.js", "shell": true } </code></pre> <p>Sublime only allows one command which is passed multiple arguments, so something like <code>"cmd": [ "killall node ||", "node", "$file"]</code> wasn't working, though I think it worked previously in Sublime 2. Thus the need to wrap <code>$file</code> in escaped quotes, because otherwise the command will fail if the path to <code>$file</code> has a space in it. Also, <code>||</code> is pivotal here, because <code>killall</code> exits with a status of 1 (error) if there were no processes to kill, so the first time it will run node but the second time it won't.</p> <p>Note that, since we're working in the shell here, this is platform-specific. I don't know how to do the equivalent of <code>||</code> on Windows, but you'd just need something like this:</p> <pre><code>{ "cmd": [ "killall node || node \"$file\"" ], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.js", "shell": true "windows": { "cmd": [ "insert whatever works here..." ] } } </code></pre> <p>One big limitation is that this kills all running node processes; that'd be annoying if you want to keep something running in the background. If someone knows how to target a specific node process in a single command, please add to my answer.</p> <p>Secondly, you could wrap the cmd in a bash script, which would make it easier to do multiple things like kill a particular process. Then the cmd array would be <code>[ "bash", "name-of-script.sh" ]</code>. Using <code>lsof</code> it would be rather easy to get the particular node process that's running your current file. You could also use <code>bash -c</code> as the command and then paste a whole script into the second element of the cmd array.</p> <p>Hope that helps. I'm missing one piece of your requirement: <code>ESC</code> will still be needed to close the build window. Not sure what else can be done there without writing a Sublime plug-in.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload