Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
@@ -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"}
]
5 changes: 5 additions & 0 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
@@ -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"}
]
5 changes: 5 additions & 0 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
@@ -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"}
]
3 changes: 2 additions & 1 deletion Default.sublime-commands
Original file line number Diff line number Diff line change
@@ -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" }
]
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======
Expand Down
6 changes: 3 additions & 3 deletions packages.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
Expand Down
46 changes: 39 additions & 7 deletions smartcomments.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
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):
"""
"""
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


Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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])