emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phps-mode 18deb2f: Fixed issue with mixed newline glyph


From: Christian Johansson
Subject: [elpa] externals/phps-mode 18deb2f: Fixed issue with mixed newline glyphs and indentation
Date: Tue, 12 Nov 2019 10:48:37 -0500 (EST)

branch: externals/phps-mode
commit 18deb2f5bde374569bbc0eb13852407a3d114a95
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>

    Fixed issue with mixed newline glyphs and indentation
---
 phps-mode-analyzer.el            | 39 ++++++++++++++++++++-------------------
 phps-mode.el                     |  4 ++--
 test/phps-mode-test-functions.el |  7 +++++++
 3 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/phps-mode-analyzer.el b/phps-mode-analyzer.el
index 7a9de58..f9d7d36 100644
--- a/phps-mode-analyzer.el
+++ b/phps-mode-analyzer.el
@@ -145,7 +145,7 @@
 ;; NOTE original is [a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*
 ;; NOTE Rebuilt for comparability with emacs-lisp
 
-(defvar phps-mode-lexer-WHITESPACE "[ \n\r\t\C-m]+"
+(defvar phps-mode-lexer-WHITESPACE "[ \n\r\t]+"
   "White-space.")
 
 (defvar phps-mode-lexer-TABS_AND_SPACES "[ \t]*"
@@ -156,11 +156,11 @@
 ;; NOTE Original is [;:,.\[\]()|^&+-/*=%!~$<>?@]
 ;; NOTE The hyphen moved last since it has special meaning and to avoid it 
being interpreted as a range.
 
-(defvar phps-mode-lexer-ANY_CHAR ".\\|\n\\|\C-m"
+(defvar phps-mode-lexer-ANY_CHAR ".\\|\n"
   "Any character.  The Zend equivalent is [^] but is not possible in Emacs 
Lisp.")
 
-(defvar phps-mode-lexer-NEWLINE "\\(\r\\|\n\\|\C-m\\|\r\n\\)"
-  "Newline characters.")
+(defvar phps-mode-lexer-NEWLINE "\\(\r\n\\|\r\\|\n\\)"
+  "Newline characters.  The Zend equivalent is (\"\r\"|\"\n\"|\"\r\n\").")
 
 
 ;; FUNCTIONS
@@ -1306,7 +1306,7 @@
              (phps-mode-lexer-RETURN_TOKEN 'T_OPEN_TAG_WITH_ECHO start end))))
 
         (phps-mode-lexer-re2c-rule
-         (and ST_INITIAL (looking-at "<\\?php\\([ \t]\\|\n\\|\C-m\\)"))
+         (and ST_INITIAL (looking-at (concat "<\\?php\\([ \t]\\|" 
phps-mode-lexer-NEWLINE "\\)")))
          (lambda()
            (let ((start (match-beginning 0))
                  (end (match-end 0)))
@@ -1410,7 +1410,7 @@
              (phps-mode-lexer-RETURN_TOKEN data start end))))
 
         (phps-mode-lexer-re2c-rule
-         (and ST_VAR_OFFSET (looking-at (concat "[ \n\C-m\r\t'#]")))
+         (and ST_VAR_OFFSET (looking-at (concat "[ \n\r\t'#]")))
          (lambda()
            (let* ((start (match-beginning 0))
                   (end (- (match-end 0) 1)))
@@ -1463,7 +1463,7 @@
                    (phps-mode-lexer-MOVE_FORWARD (point-max))))))))
 
         (phps-mode-lexer-re2c-rule
-         (and ST_IN_SCRIPTING (looking-at "\\?>\n?\C-m?"))
+         (and ST_IN_SCRIPTING (looking-at (concat "\\?>" 
phps-mode-lexer-NEWLINE "?")))
          (lambda()
            (let ((start (match-beginning 0))
                  (end (match-end 0)))
@@ -1665,15 +1665,16 @@
            (let ((string-start
                   (search-forward-regexp
                    (concat
-                    "\\(\\(\n\\|\C-m\\)"
+                    "\\(\n"
                     heredoc_label
-                    ";?\\(\n\\|\C-m\\)\\|\\$"
+                    ";?\n\\|\\$"
                     phps-mode-lexer-LABEL
                     "\\|{\\$"
                     phps-mode-lexer-LABEL
                     "\\|\\${"
                     phps-mode-lexer-LABEL
-                    "\\)") nil t)))
+                    "\\)"
+                    ) nil t)))
              (if string-start
                  (let* ((start (match-beginning 0))
                         (end (match-end 0))
@@ -1682,7 +1683,7 @@
 
                    (cond
 
-                    ((string-match (concat "\\(\n\\|\C-m\\)" heredoc_label 
";?\\(\n\\|\C-m\\)") data)
+                    ((string-match (concat "\n" heredoc_label ";?\n") data)
                                         ;, (message "Found heredoc end at 
%s-%s" start end)
                      (phps-mode-lexer-BEGIN 'ST_END_HEREDOC)
                      (phps-mode-lexer-RETURN_TOKEN 'T_ENCAPSED_AND_WHITESPACE 
old-start start))
@@ -1700,7 +1701,7 @@
         (phps-mode-lexer-re2c-rule
          (and ST_NOWDOC (looking-at phps-mode-lexer-ANY_CHAR))
          (lambda()
-           (let ((string-start (search-forward-regexp (concat 
"\\(\n\\|\C-m\\)" heredoc_label ";?\\(\n\\|\C-m\\)") nil t)))
+           (let ((string-start (search-forward-regexp (concat "\n" 
heredoc_label ";?\\\n") nil t)))
              (if string-start
                  (let* ((start (match-beginning 0))
                         (end (match-end 0))
@@ -2070,7 +2071,7 @@
   "Return the number of lines in STRING."
   (let ((lines-in-string 0)
         (start 0))
-    (while (string-match "[\n\C-m]" string start)
+    (while (string-match "[\n]" string start)
       (setq start (match-end 0))
       (setq lines-in-string (1+ lines-in-string)))
     lines-in-string))
@@ -2090,7 +2091,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
    (message "Calculating HTML indent for: '%s'" inline-html))
 
   ;; Add trailing newline if missing
-  (unless (string-match-p "\\(\n\\|\C-m\\)$" inline-html)
+  (unless (string-match-p "\n$" inline-html)
     (setq inline-html (concat inline-html "\n")))
 
   (let ((start 0)
@@ -2101,7 +2102,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
         (first-object-is-nesting-decrease nil))
     (while
         (string-match
-         
"\\([\n\C-m]\\)\\|\\(<[a-zA-Z]+\\)\\|\\(</[a-zA-Z]+\\)\\|\\(/>\\)\\|\\(\\[\\)\\|\\()\\)\\|\\((\\)\\|\\({\\|}\\)"
+         
"\\([\n]\\)\\|\\(<[a-zA-Z]+\\)\\|\\(</[a-zA-Z]+\\)\\|\\(/>\\)\\|\\(\\[\\)\\|\\()\\)\\|\\((\\)\\|\\({\\|}\\)"
          inline-html
          start)
       (let* ((end (match-end 0))
@@ -2109,7 +2110,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
 
         (cond
 
-         ((string-match-p "\\(\n\\|\C-m\\)" string)
+         ((string-match-p "\n" string)
 
           (let ((temp-indent indent))
             (when first-object-is-nesting-decrease
@@ -2162,7 +2163,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
          )
 
         (when first-object-on-line
-          (unless (string-match-p "\\(\n\\|\C-m\\)" string)
+          (unless (string-match-p "\n" string)
             (setq first-object-on-line nil)
             (setq indent-end (+ tag-level curly-bracket-level 
square-bracket-level round-bracket-level))
             (when (< indent-end indent-start)
@@ -2468,7 +2469,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
                   (setq
                    inline-html-rest-is-whitespace
                    (string-match
-                    "^[\ \t]\\(\n\\|\C-m\\)"
+                    "^[\ \t\r\f]+\n"
                     (substring
                      string
                      (1- token-start)
@@ -3157,7 +3158,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
 
                           (setq inline-html-is-whitespace
                                 (not (null
-                                      (string-match "[\n\C-m][ \t]+$" 
(substring string (1- token-start) (1- token-end))))))
+                                      (string-match "[\r\n][ \f\t]+$" 
(substring string (1- token-start) (1- token-end))))))
                           (phps-mode-debug-message
                            (message "Trailing inline html line is whitespace: 
%s" inline-html-is-whitespace))
                           (phps-mode-debug-message
diff --git a/phps-mode.el b/phps-mode.el
index 08ac499..65b5fec 100644
--- a/phps-mode.el
+++ b/phps-mode.el
@@ -5,8 +5,8 @@
 ;; Author: Christian Johansson <address@hidden>
 ;; Maintainer: Christian Johansson <address@hidden>
 ;; Created: 3 Mar 2018
-;; Modified: 11 Nov 2019
-;; Version: 0.3.12
+;; Modified: 12 Nov 2019
+;; Version: 0.3.13
 ;; Keywords: tools, convenience
 ;; URL: https://github.com/cjohansson/emacs-phps-mode
 
diff --git a/test/phps-mode-test-functions.el b/test/phps-mode-test-functions.el
index a82909f..31ae263 100644
--- a/test/phps-mode-test-functions.el
+++ b/test/phps-mode-test-functions.el
@@ -280,6 +280,11 @@
    "Indentation for single-line inline control structures."
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))
 
+  (phps-mode-test-with-buffer
+   "<?php
\n\nif (true) {\n    // Was here\n}"
+   "If condition after a mixed newline encoded file"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (0 0))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))
+
   )
 
 (defun phps-mode-test-functions-get-lines-indent-psr-2 ()
@@ -1087,6 +1092,8 @@
 
   )
 
+
+
 (defun phps-mode-test-functions ()
   "Run test for functions."
   ;; (setq debug-on-error t)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]