Translate 4 line sublime package please


“you just need to send a POST request to the Meteor server containing the code and file path of the file you’d like to reload”

import sublime
import sublime_plugin
import urllib.request

class QualiaRevalCommand(sublime_plugin.TextCommand):
  def run(self, edit):
    url = 'http://localhost:3000/reval/reload?filePath=' + self.view.file_name()
    data = self.view.substr(sublime.Region(0, self.view.size()))
    request = urllib.request.Request(url, data=str.encode(data), headers={'Content-type': 'text/plain'})


As suggested by @leedohm in Slack, you should investigate the Package: Word Count section of the Flight Manual, specifically the part related to registering a command since it looks like this code registers a command that can be triggered by the user.


It does, the thinking goes that you then just go bind command to some key as user.


This will get you started. I don’t think it does everything the sublime one does, but it’s close.

http = require('http')

atom.commands.add 'atom-text-editor',
  'editor:qualia-reval': () ->
    var req = http.request({
      host: 'localhost',
      port: 3000,
      path: '/reval/reload?filePath=' + atom.workspace.getActiveTextEditor().getTitle(),
      method: 'POST'

This would go in your init script, or you can follow the flight manual to make it into a full on package.

Just a note: I’m not writing this because I want to encourage laziness. Quite the opposite. I want to show how easy it is to write small scripts like these, and I know the first one is the hardest.


I don’t know http since I use meteor/websockets. It says unmatched OUTDENT. Remove the var.