Anonymous avatar Anonymous committed 8846141

Added command 'hg_annotate_current_line' printing annotation of current line into status bar and the python console which is toggled by Ctrl+`

Comments (0)

Files changed (1)

 
 import os
 # import sys
-# import sublime
+import sublime
 import sublime_plugin
 import subprocess
 
 
 __all__ = [
     "__version__", "HgtkAnnotateCommand", "HgtkLogCommand", "HgMeldCommand",
-    "HgMeldViewCommand",
+    "HgMeldViewCommand", "HgAnnotateCurrentLineCommand",
 ]
 
 class BaseCommandMixin(object):
         self.do_tortoise_command_on_view("thg annotate")
 
 
+class HgAnnotateCurrentLineCommand(sublime_plugin.TextCommand, BaseCommandMixin):
+    """hg_annotate_current_line command class."""
+
+    def run(self, edit):
+        """Run the command by Sublime editor."""
+        #self.view.insert(edit, 0, sublime.__file__)
+
+        view = self.view
+        selection = view.sel()[0]
+        # line_text = view.substr(selection)
+        line_number, column = view.rowcol(selection.begin())
+
+        file_path_name = os.path.join(
+            self.get_view_root_folder(),
+            self.get_view_relative_file_name(),
+        )
+        cmd_str = (
+            "hg annotate -y -u -d -n -c '%(file_path_name)s' "
+            "| cat -n "
+            "| grep -E '^[[:space:]]+%(line_number)s[[:space:]]+'"
+        ) % dict(
+            file_path_name=file_path_name,
+            line_number=line_number + 1,
+        )
+        annotated_lines = (
+            subprocess.Popen(
+                cmd_str, shell=True, stdout=subprocess.PIPE
+            )
+            .stdout
+            .readlines()
+        )
+        status_message = u"".join(annotated_lines)
+        print status_message
+        sublime.status_message(status_message)
+
+
 class ThgLogCommand(sublime_plugin.TextCommand, BaseCommandMixin):
     """thg_log command class."""
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.