diff --git a/Default (Linux).sublime-keymap b/Default (Linux).sublime-keymap index 476b2b5..0f25b49 100644 --- a/Default (Linux).sublime-keymap +++ b/Default (Linux).sublime-keymap @@ -1,5 +1,5 @@ [ { "keys": ["ctrl+alt+f"], "command": "smart_comments_file"}, - { "keys": ["ctrl+alt+o"], "command": "smart_comments_folder"}, - { "keys": ["ctrl+alt+t"], "command": "smart_comments_text"} + { "keys": ["ctrl+alt+d"], "command": "smart_comments_folder"}, + { "keys": ["ctrl+alt+s"], "command": "smart_comments_text"} ] diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap new file mode 100644 index 0000000..0f25b49 --- /dev/null +++ b/Default (OSX).sublime-keymap @@ -0,0 +1,5 @@ +[ + { "keys": ["ctrl+alt+f"], "command": "smart_comments_file"}, + { "keys": ["ctrl+alt+d"], "command": "smart_comments_folder"}, + { "keys": ["ctrl+alt+s"], "command": "smart_comments_text"} +] diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap new file mode 100644 index 0000000..437273d --- /dev/null +++ b/Default (Windows).sublime-keymap @@ -0,0 +1,5 @@ +[ + { "keys": ["ctrl+alt+f"], "command": "smart_comments_file"}, + { "keys": ["ctrl+alt+o"], "command": "smart_comments_folder"}, + { "keys": ["ctrl+alt+s"], "command": "smart_comments_text"} +] diff --git a/Default.sublime-commands b/Default.sublime-commands index 2326ff7..7578cb0 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -1,4 +1,5 @@ [ { "caption": "SmartComments: Comments for Current File ", "command": "smart_comments_file" }, - { "caption": "SmartComments: Comments for File Folder ", "command": "smart_comments_folder" } + { "caption": "SmartComments: Comments for File Folder ", "command": "smart_comments_folder" }, + { "caption": "SmartComments: Comments for Selected Code", "command": "smart_comments_text" } ] diff --git a/README.md b/README.md index ef6a13b..7e5f27a 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,12 @@ Try SmartComments online [here](http://smartcomments.github.io). usage ===== +**New** +In any JS source file, press Ctrl+Alt+S (Linux & Windows) to generate comments from **current selection**. In any JS source file, press Ctrl+Alt+F (Linux & Windows) to generate comments from **current file**. -In any JS source file, press Ctrl+Alt+O (Linux & Windows) to generate comments from **current directory**. +In any JS source file, press Ctrl+Alt+D (Linux & Windows) to generate comments from **current directory**. install ======= diff --git a/packages.json b/packages.json index 4cab8f4..25e0aa5 100644 --- a/packages.json +++ b/packages.json @@ -1,16 +1,16 @@ { - "schema_version": "0.1", + "schema_version": "0.2", "packages": [ { "name": "Sublime SmartComments", "description": "SmartComments", "author": "smartcomments", "homepage": "https://github.com/smartcomments/sublime-smartcomments", - "last_modified": "28/09/2013", + "last_modified": "26/11/2013", "platforms": { "*": [ { - "version": "0.1", + "version": "0.2", "url": "https://github.com/smartcomments/sublime-smartcomments" } ] diff --git a/smartcomments.py b/smartcomments.py index 7a49f86..c0c2e2f 100644 --- a/smartcomments.py +++ b/smartcomments.py @@ -1,7 +1,16 @@ import sublime, sublime_plugin from subprocess import PIPE, Popen +from io import open as io_open +from os import remove from os.path import dirname as path_dirname +from tempfile import mkstemp +import platform +def get_command(): + command = "smartcomments" + if platform.system() == "Windows": + command = "smartcomments.cmd" + return command def fn_execute(cmd_args=[], cmd=None): """ @@ -9,13 +18,16 @@ def fn_execute(cmd_args=[], cmd=None): result = None try: if cmd: - result = Popen(cmd_args, executable=cmd, stdout=PIPE, stderr=PIPE).communicate() + result = Popen(cmd_args, executable=cmd, + stdout=PIPE, stderr=PIPE).communicate() else: result = Popen(cmd_args, stdout=PIPE, stderr=PIPE).communicate() - except (TypeError, err): - print ("Error %1 ocurrido al ejecutar el comando %2 ".args(err, cmd )) - except (FileNotFoundError, err): - print ("Error %1 ocurrido al ejecutar el comando %2 ".args(err, cmd )) + except TypeError as err: + print("Error {0} ocurrido al ejecutar el comando {1} \ + ".format(err, cmd)) + except FileNotFoundError as err: + print("Error {0} ocurrido al ejecutar el comando {1} \ + ".format(err, cmd)) return result @@ -28,7 +40,8 @@ def run(self, edit): return file_dir = path_dirname(file_name) - result = fn_execute(["smartcomments","-g", "-t", file_dir]) + result = fn_execute([get_command(), "-g","-t", file_dir]) + print(result) class SmartCommentsFileCommand(sublime_plugin.TextCommand): @@ -39,7 +52,8 @@ def run(self, edit): if not file_name or not str(file_name).endswith("js"): return - result = fn_execute(["smartcomments","-g", "-t", file_name]) + result = fn_execute([get_command(), "-g", "-t", file_name]) + print(result) class SmartCommentsTextCommand(sublime_plugin.TextCommand): @@ -50,3 +64,21 @@ def run(self, edit): if not file_name or not str(file_name).endswith("js"): return + selection = self.view.sel() + for region in selection: + if not region.empty(): + s = self.view.substr(region) + js_tmpfile = mkstemp(suffix='.js', text=True) + with io_open(js_tmpfile[1], 'w+') as tmpf: + tmpf.write(s) + try: + fn_execute([get_command(), "-g", "-t", js_tmpfile[1]]) + except: + remove(js_tmpfile[1]) + with io_open(js_tmpfile[1], 'r') as tmpf: + file_size = tmpf.seek(0, 2) + tmpf.seek(0, 0) + data = tmpf.read(file_size) + if data != '': + self.view.replace(edit, region, data) + remove(js_tmpfile[1])