Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

don't add $ inside comments #2

Merged
merged 4 commits into from

3 participants

@balaclark

Thanks for the useful plugin, I've made a small tweak to stop the $ being added inside of comments. This works for both single and multiple line comments.

@balaclark

I've also now stopped $ being added outside of the <? ?> context.

@sergeylunev

@graarh merge this PR please.

@graarh graarh merged commit 62f953e into graarh:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 4 deletions.
  1. +8 −3 AutoPHPDollar.py
  2. +0 −1  README.md
View
11 AutoPHPDollar.py
@@ -30,7 +30,6 @@
rules = settings.get("rules", [])
ignore_after = settings.get("ignore after", [])
-
def get_patterns(view):
return rules + [
#already known variables
@@ -101,7 +100,7 @@ def apply_patterns(text, patterns):
class CphpListener(sublime_plugin.EventListener):
def on_modified(self, view):
if syntax_name(view) == "PHP":
- #avoid heavy calculations for "hold delete/backspace and wait"
+ # avoid heavy calculations for "hold delete/backspace and wait"
action = view.command_history(0, True)[0]
if action == "left_delete" or action == "right_delete":
return
@@ -114,13 +113,19 @@ def on_modified(self, view):
patterns = get_patterns(view)
#get list of <? .. ?> segments
- php_regions = view.find_all(r"<\?.+?\?>")
+ php_regions = view.find_all(r"<\?[\w\W]+?(\?>|\z)")
+
+ #get list of commented regions
+ comments = view.find_all(r"(#|//).+|/\*[\w\W]+?\*/")
#strings should be modified in the reversed order
#to keep upper regions positions correct
edit = None
selection = view.sel()
for i in range(len(selection) - 1, -1, -1):
+ #do not make changes inside comments
+ if len(comments) and in_list(selection[i], comments):
+ continue
#do not make any changes outside <? ... ?> segments
if not in_list(selection[i], php_regions):
continue
View
1  README.md
@@ -67,5 +67,4 @@ You can not use constructions like function $myfuncname($args) in PHP, so you do
```
### Roadmap and TODO:
-- avoid of adding "$" inside comments and text blocks
- improve variables detection
Something went wrong with that request. Please try again.