Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't add $ inside comments #2

Merged
merged 4 commits into from Mar 7, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions AutoPHPDollar.py
Expand Up @@ -30,7 +30,6 @@
rules = settings.get("rules", [])
ignore_after = settings.get("ignore after", [])


def get_patterns(view):
return rules + [
#already known variables
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -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