-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed - Codemarker is not accurate enough. Added LanguageID detection for QuoteWithMarker.
- Loading branch information
1 parent
ba6a5de
commit 971ffda
Showing
8 changed files
with
69 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include: | ||
- project: $INCLUDE_PROJECT | ||
file: '/templates/gitlab/Znuny-Sublime/default.yml' |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,90 @@ | ||
from datetime import date | ||
|
||
import sublime | ||
import sublime_plugin | ||
import re | ||
|
||
|
||
def plugin_loaded(): | ||
global settings | ||
settings = sublime.load_settings('Znuny.sublime-settings') | ||
settings = sublime.load_settings("Znuny.sublime-settings") | ||
|
||
|
||
class ZnunyQuoteWithMarkerCommand(sublime_plugin.TextCommand): | ||
def run(self, edit): | ||
|
||
# get quoting char | ||
quote_char = None | ||
syntax = self.view.settings().get('syntax') | ||
znuny_code_marker = settings.get('znuny_code_marker') or "Znuny" | ||
quote_char_start = "" | ||
quote_char_end = "" | ||
code_marker_replace = "" | ||
|
||
code_marker = settings.get("znuny_code_marker") or "Znuny" | ||
current_time = date.today() | ||
day = current_time.strftime("%d") | ||
month = current_time.strftime("%m") | ||
year = current_time.strftime("%Y") | ||
code_marker = code_marker.replace("${year}", year) | ||
code_marker = code_marker.replace("${month}", month) | ||
code_marker = code_marker.replace("${day}", day) | ||
|
||
if re.search("JavaScript", syntax): | ||
quote_char = '//' | ||
elif re.search("Perl", syntax): | ||
quote_char = '#' | ||
elif re.search("HTML", syntax): | ||
quote_char = '#' | ||
meta = self.view.meta_info("shellVariables", 0) | ||
for var in meta: | ||
if var["name"] == "TM_COMMENT_START": | ||
quote_char_start = var["value"] | ||
|
||
if not quote_char or not znuny_code_marker: | ||
return | ||
if var["name"] == "TM_COMMENT_END": | ||
quote_char_end = " " + var["value"] | ||
|
||
# loop over all selections | ||
# Loop over all selections. | ||
for region in self.view.sel(): | ||
|
||
# skip empty selections | ||
# Skip empty selections. | ||
if region.empty(): | ||
next | ||
|
||
# Get the selected text | ||
# Get the selected text. | ||
selection = self.view.substr(region) | ||
|
||
# start custom maker | ||
code_marker_replace = """{quote_char} --- | ||
{quote_char} {znuny_code_marker}- | ||
{quote_char} --- | ||
# Start custom maker. | ||
code_marker_replace = """{quote_char_start} ---{quote_char_end} | ||
{quote_char_start} {code_marker}{quote_char_end} | ||
{quote_char_start} ---{quote_char_end} | ||
""" | ||
# Add QuoteCharStart to every single line. | ||
for line in selection.split("\n"): | ||
|
||
# loop over each selected line | ||
for line in selection.split('\n'): | ||
if len(line) == 0: | ||
continue | ||
|
||
# add perl quote | ||
code_marker_replace += '{quote_char}' | ||
# Add quote. | ||
code_marker_replace += "{quote_char_start}" | ||
|
||
# insert leading space for non empty lines | ||
# Insert leading space for non empty lines. | ||
if len(line) >= 1: | ||
code_marker_replace += ' ' | ||
|
||
# add old line and an linebreak | ||
code_marker_replace += line + "\n" | ||
code_marker_replace += " " | ||
|
||
# add old selection and trailing code marker | ||
code_marker_replace += selection | ||
code_marker_replace += "\n\n{quote_char} ---" | ||
# Add old line and an linebreak. | ||
code_marker_replace += line + "{quote_char_end}\n" | ||
|
||
code_marker_replace = code_marker_replace.replace('{quote_char}', quote_char) | ||
code_marker_replace = code_marker_replace.replace('{znuny_code_marker}', znuny_code_marker) | ||
# code_marker_replace.format(**replace_dict) | ||
|
||
# replace the selection with transformed text | ||
# Add old selection and trailing code marker. | ||
code_marker_replace += selection | ||
code_marker_replace += "\n\n{quote_char_start} ---{quote_char_end}\n" | ||
|
||
code_marker_replace = code_marker_replace.replace( | ||
"{quote_char_start}", quote_char_start | ||
) | ||
code_marker_replace = code_marker_replace.replace( | ||
"{quote_char_end}", quote_char_end | ||
) | ||
code_marker_replace = code_marker_replace.replace( | ||
"{code_marker}", code_marker | ||
) | ||
|
||
# Replace the selection with transformed text | ||
self.view.replace(edit, region, code_marker_replace) | ||
|
||
# clear selection regions / cursor position | ||
# Clear selection regions / cursor position. | ||
self.view.sel().clear() | ||
|
||
# set new regions to inserted custom marker package name | ||
for begin in self.view.find_all("Znuny-\n"): | ||
# Set new regions to inserted custom marker package name. | ||
for begin in self.view.find_all(code_marker + "\n"): | ||
self.view.sel().add(sublime.Region(begin.a, begin.b - 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"install": "messages/install.txt", | ||
"1.0.9": "messages/version.txt" | ||
"1.0.10": "messages/version.txt" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters