From 27f87c9855b54ce6b99bea20128eab70cffd672c Mon Sep 17 00:00:00 2001 From: Bala Clark Date: Mon, 20 Aug 2012 11:49:17 +0200 Subject: [PATCH 1/4] do not add dollar inside comments --- AutoPHPDollar.py | 8 +++++++- README.md | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/AutoPHPDollar.py b/AutoPHPDollar.py index b6ee86c..fd82ced 100644 --- a/AutoPHPDollar.py +++ b/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,6 +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" action = view.command_history(0, True)[0] if action == "left_delete" or action == "right_delete": @@ -116,11 +116,17 @@ def on_modified(self, view): #get list of segments php_regions = view.find_all(r"<\?.+?\?>") + #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 in_list(selection[i], comments): + continue #do not make any changes outside segments if not in_list(selection[i], php_regions): continue diff --git a/README.md b/README.md index b710416..65ea53f 100644 --- a/README.md +++ b/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 From 9b90aac80d884a8bbc153ff6950197862c5a0675 Mon Sep 17 00:00:00 2001 From: Bala Clark Date: Mon, 20 Aug 2012 12:12:51 +0200 Subject: [PATCH 2/4] fixed bug in comment checking caused by in_list() returning True if the list is empty --- AutoPHPDollar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AutoPHPDollar.py b/AutoPHPDollar.py index fd82ced..8aa11e0 100644 --- a/AutoPHPDollar.py +++ b/AutoPHPDollar.py @@ -125,7 +125,7 @@ def on_modified(self, view): selection = view.sel() for i in range(len(selection) - 1, -1, -1): #do not make changes inside comments - if in_list(selection[i], 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): From 880516927071abf8394cee8b69b125b317eeef66 Mon Sep 17 00:00:00 2001 From: Bala Clark Date: Mon, 20 Aug 2012 12:14:43 +0200 Subject: [PATCH 3/4] simplified comment regexp --- AutoPHPDollar.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/AutoPHPDollar.py b/AutoPHPDollar.py index 8aa11e0..884263f 100644 --- a/AutoPHPDollar.py +++ b/AutoPHPDollar.py @@ -100,8 +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 @@ -117,7 +116,7 @@ def on_modified(self, view): php_regions = view.find_all(r"<\?.+?\?>") #get list of commented regions - comments = view.find_all(r"#.+|//.+|/\*[\w\W]+?\*/") + comments = view.find_all(r"(#|//).+|/\*[\w\W]+?\*/") #strings should be modified in the reversed order #to keep upper regions positions correct From 62f953e5a47f257ea2ebfcab07bbe63474db7647 Mon Sep 17 00:00:00 2001 From: Bala Clark Date: Mon, 20 Aug 2012 16:10:33 +0200 Subject: [PATCH 4/4] don't add dollar outside of php segments --- AutoPHPDollar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AutoPHPDollar.py b/AutoPHPDollar.py index 884263f..b04ae31 100644 --- a/AutoPHPDollar.py +++ b/AutoPHPDollar.py @@ -113,7 +113,7 @@ 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]+?\*/")