php-mode icon indicating copy to clipboard operation
php-mode copied to clipboard

single quote in shell style comments breaks indenting

Open calguy1000 opened this issue 12 years ago • 4 comments

<?php
# This project's homepage is  http://www.website.com
$a = 1;
if( $a == 1 ) {
$a = $a + 1;
}
?>

Attempting to indent line 5 with tab will not work.... adding spaces and pressing tab to re-indent the line sets the indenting at 0

Change to // comments or /* comments */ works fine. Removing the single quote in line 2 also works fine.

Unfortunately I have thousands of files with these styles of comments in them.

calguy1000 avatar Mar 16 '14 16:03 calguy1000

So THAT'S why my indentation always fails. I couldn't pin it down before. I never would have suspected comments.

Perhaps because the four supported styles all have something along the lines of Use of Perl/shell style comments (#) is discouraged ???

However, I wouldn't expect that failure-to-indent is not the proper form of discouragement.

MichaelPaulukonis avatar Mar 19 '14 19:03 MichaelPaulukonis

Thank you @calguy1000 for the bug report, and my apologies about the slow response. That bug is... odd. I can duplicate the problem on my end, at least, but at a glance I am not sure what causes it. Changing the style of the comment interestingly (and cofusingly) changes the semantics that CC Mode assigns to live five, and that, in my opinion, is ultimately the cause of the bug. But I see no obvious way to connect the dots.

I will try to figure out what I can, but this one is a head-scratcher, so I apologize in advanced if this bug takes a while to fix. Honestly, I hope someone sees an obvious solution that I am simply missing.

ejmr avatar Mar 19 '14 20:03 ejmr

How about following patch ?

diff --git a/php-mode.el b/php-mode.el
index 8e20d5a..155289f 100644
--- a/php-mode.el
+++ b/php-mode.el
@@ -727,6 +727,9 @@ the string HEREDOC-START."
   (string-match "\\w+" heredoc-start)
   (concat "^\\(" (match-string 0 heredoc-start) "\\)\\W"))

+(defsubst php-in-comment-p ()
+  (nth 4 (syntax-ppss)))
+
 (defun php-syntax-propertize-function (start end)
   "Apply propertize rules from START to END."
   ;; (defconst php-syntax-propertize-function
@@ -735,7 +738,12 @@ the string HEREDOC-START."
   (goto-char start)
   (while (and (< (point) end)
               (re-search-forward php-heredoc-start-re end t))
-    (php-heredoc-syntax)))
+    (php-heredoc-syntax))
+  (goto-char start)
+  (while (re-search-forward "['\"]" end t)
+    (when (php-in-comment-p)
+      (c-put-char-property (match-beginning 0)
+                           'syntax-table (string-to-syntax "_")))))

 (defun php-heredoc-syntax ()
   "Mark the boundaries of searched heredoc."

syohex avatar Aug 25 '14 09:08 syohex

ありがとうございます吉田さん。受け取って合いました。^^

ejmr avatar Aug 25 '14 10:08 ejmr