Skip to content

Commit

Permalink
Version 1.0.10:
Browse files Browse the repository at this point in the history
Fixed - Codemarker is not accurate enough.
Added LanguageID detection for QuoteWithMarker.
  • Loading branch information
dennykorsukewitz committed Nov 8, 2023
1 parent ba6a5de commit 971ffda
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
include:
- project: $INCLUDE_PROJECT
file: '/templates/gitlab/Znuny-Sublime/default.yml'
File renamed without changes.
2 changes: 1 addition & 1 deletion Znuny.sublime-settings
Expand Up @@ -2,5 +2,5 @@
"znuny_workspaces": [ "/workspace/" ],
"znuny_github_username": "",
"znuny_github_token": "",
"znuny_code_marker": "Znuny",
"znuny_code_marker": "Znuny - ${year}.${month}.${day}",
}
96 changes: 56 additions & 40 deletions ZnunyQuoteWithMarker.py
@@ -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))
2 changes: 1 addition & 1 deletion messages.json
@@ -1,4 +1,4 @@
{
"install": "messages/install.txt",
"1.0.9": "messages/version.txt"
"1.0.10": "messages/version.txt"
}
4 changes: 4 additions & 0 deletions messages/changelog.txt
@@ -1,3 +1,7 @@
Version 1.0.10
✔ Fixed - Codemarker is not accurate enough.
✔ Added LanguageID detection for QuoteWithMarker.

Version 1.0.9
✔ Command Palette - Added Znuny Commands to Default.sublime-commands.

Expand Down
2 changes: 1 addition & 1 deletion messages/install.txt
Expand Up @@ -11,7 +11,7 @@ Your Znuny Team! 🚀

-------------------

🌟 Version 1.0.9 🌟 - Feature List
🌟 Version 1.0.10 🌟 - Feature List

✔ Add folder from workspace to project.
✔ Automatic fetching of framework files from github.
Expand Down
5 changes: 3 additions & 2 deletions messages/version.txt
@@ -1,6 +1,7 @@
🌟 Version 1.0.9 🌟
🌟 Version 1.0.10 🌟

✔ Command Palette - Added Znuny Commands to Default.sublime-commands.
✔ Fixed - Codemarker is not accurate enough.
✔ Added LanguageID detection for QuoteWithMarker.

GitHub link - https://github.com/znuny/Znuny-Sublime

Expand Down

0 comments on commit 971ffda

Please sign in to comment.