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

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

[elpa] externals/phps-mode c890607: Added support for indentation for in


From: Christian Johansson
Subject: [elpa] externals/phps-mode c890607: Added support for indentation for inline HTML areas
Date: Mon, 26 Aug 2019 11:29:46 -0400 (EDT)

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

    Added support for indentation for inline HTML areas
---
 README.md                                          |   1 +
 docs/heuristics.md                                 |  17 ++-
 docs/todo.md                                       |   1 -
 phps-mode-functions.el                             | 155 ++++++++++++++++++---
 phps-mode-test-functions.el                        |  47 ++++++-
 phps-mode-test-integration.el                      |  18 +--
 phps-mode.el                                       |  65 +++++----
 sample-php-files/alternative-control-structure.php |  12 ++
 sample-php-files/class.php                         |   8 +-
 9 files changed, 251 insertions(+), 73 deletions(-)

diff --git a/README.md b/README.md
index b8dda02..9a9bd7a 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,7 @@ This mode does not require PHP installed on your computer 
because it has a built
 * Incremental lexer and syntax coloring after buffer changes
 * Incremental indentation and imenu generation after buffer changes
 * Supports `(comment-region)` and `(uncomment-region)`
+* Support indentation for inline-html areas
 * Imenu support
 * Minimal mode map
 * Tested using unit tests and integration tests
diff --git a/docs/heuristics.md b/docs/heuristics.md
index 3958a31..bbfab08 100644
--- a/docs/heuristics.md
+++ b/docs/heuristics.md
@@ -1,10 +1,19 @@
 ## Heuristics
 
-These should solve the problem of freezing editor when making white-space 
changes to code. Otherwise a full incremental re-parse would be triggered more 
often than necessary.
+These should solve the problem of freezing editor for too long when making 
white-space changes to code in large files. Otherwise a full incremental 
re-parse would be triggered more often than necessary.
 
-* When pressing return when the rest of the current line after cursor is only 
white-space
-* When pressing backspace when the rest of the current line before cursor is 
only white-space
+### Return
+When pressing return when the rest of the current line after cursor is only 
white-space, move indexes of tokens, lexer states, indentation and imenu 
forward one point
+
+
+### Backspace
+When pressing backspace when the rest of the current line before cursor is 
only white-space, move indexes of tokens, lexer states, indentation and imenu 
backward one pint
+
+### Indenting
+When indenting a line, calculate difference in white-space and change indexes 
of buffer after point correspondingly
+
+### Other changes
+When user has done none-whitespace changes, determine unchanged previous 
position R, determine changed maximum position X, determine new buffer length 
L. Do incremental lex from R to X, if new states at X equals old states at X 
just move indexes with delta X, otherwise do incremental lex of rest of buffer.
 
-In both of these cases, move indexes of tokens, states, indentations and imenu
 
 [Back to start](../../../)
diff --git a/docs/todo.md b/docs/todo.md
index 4c07a64..81e042a 100644
--- a/docs/todo.md
+++ b/docs/todo.md
@@ -7,7 +7,6 @@
 * Wisent LALR parser based on official PHP yacc parser automatically converted 
grammar (50%)
 * mmm-mode support (50%)
 * Full integration with Emacs Semantic subsystem (30%)
-* Support indentation for HTML/XML, Javascript and CSS content inside 
inline_html content (0%)
 * Eldoc support (0%)
 * Flymake support (0%)
 * PSR-2 auto-formatting tool based on lexer tokens (0%)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 7260d2f..9a3c83d 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -23,6 +23,7 @@
 
 ;;; Code:
 
+(require 'subr-x)
 (require 'phps-mode-lexer)
 
 (defvar phps-mode-functions-allow-after-change t
@@ -147,8 +148,97 @@
       (setq lines-in-string (1+ lines-in-string)))
     lines-in-string))
 
+(defun phps-mode-functions--get-inline-html-indentation (inline-html indent 
tag-level curly-bracket-level square-bracket-level round-bracket-level)
+  "Generate a list of indentation for each line in INLINE-HTML, working 
incrementally on INDENT, TAG-LEVEL, CURLY-BRACKET-LEVEL, SQUARE-BRACKET-LEVEL 
and ROUND-BRACKET-LEVEL."
+
+
+  (when phps-mode-functions-verbose
+    (message "Calculating HTML indent for: '%s'" inline-html))
+
+  ;; Add trailing newline if missing
+  (unless (string-match "\n$" inline-html)
+    (setq inline-html (concat inline-html "\n")))
+
+  (let ((start 0)
+        (indent-start indent)
+        (indent-end indent)
+        (line-indents nil)
+        (first-object-on-line t)
+        (first-object-is-nesting-decrease nil))
+    (while (string-match 
"\\([\n\C-m]\\)\\|\\(<[a-zA-Z]+\\)\\|\\(</[a-zA-Z]+\\)\\|\\(/>\\)\\|\\(\\[\\)\\|\\()\\)\\|\\((\\)"
 inline-html start)
+      (let* ((end (match-end 0))
+             (string (substring inline-html (match-beginning 0) end)))
+
+        (cond
+
+         ((string= string "\n")
+
+          (let ((temp-indent indent))
+            (when first-object-is-nesting-decrease
+              (when phps-mode-functions-verbose
+                (message "Decreasing indent with one since first object was a 
nesting decrease"))
+              (setq temp-indent (1- indent))
+              (when (< temp-indent 0)
+                (setq temp-indent 0)))
+            (push temp-indent line-indents))
+
+          (setq indent-end (+ tag-level curly-bracket-level 
square-bracket-level round-bracket-level))
+          (when phps-mode-functions-verbose
+            (message "Encountered a new-line"))
+          (if (> indent-end indent-start)
+              (progn
+                (when phps-mode-functions-verbose
+                  (message "Increasing indent since %s is above %s" indent-end 
indent-start))
+                (setq indent (1+ indent)))
+            (when (< indent-end indent-start)
+              (when phps-mode-functions-verbose
+                (message "Decreasing indent since %s is below %s" indent-end 
indent-start))
+              (setq indent (1- indent))
+              (when (< indent 0)
+                (setq indent 0))))
+
+          (setq indent-start indent-end)
+          (setq first-object-on-line t)
+          (setq first-object-is-nesting-decrease nil))
+
+         ((string= string "(")
+          (setq round-bracket-level (1+ round-bracket-level)))
+         ((string= string ")")
+          (setq round-bracket-level (1- round-bracket-level)))
+
+         ((string= string "[")
+          (setq square-bracket-level (1+ square-bracket-level)))
+         ((string= string "]")
+          (setq square-bracket-level (1- square-bracket-level)))
+
+         ((string= string "{")
+          (setq curly-bracket-level (1+ curly-bracket-level)))
+         ((string= string "}")
+          (setq curly-bracket-level (1- curly-bracket-level)))
+
+         ((string-match "<[a-zA-Z]+" string)
+          (setq tag-level (1+ tag-level)))
+
+         ((string-match "\\(</[a-zA-Z]+\\)\\|\\(/>\\)" string)
+          (setq tag-level (1- tag-level)))
+
+         )
+
+        (when first-object-on-line
+          (unless (string= string "\n")
+            (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)
+              (when phps-mode-functions-verbose
+                (message "First object was nesting decrease"))
+              (setq first-object-is-nesting-decrease t))))
+
+        (setq start end)))
+    (list (nreverse line-indents) indent tag-level curly-bracket-level 
square-bracket-level round-bracket-level)))
+
+;; TODO Make this function support incremental process
 (defun phps-mode-functions--process-current-buffer ()
-  "Process current buffer and generation indentation and Imenu in one 
iteration.  Complexity: O(n)."
+  "Generate indexes for indentation and imenu for current buffer in one pass.  
Complexity: O(n)."
   (if (boundp 'phps-mode-lexer-tokens)
       (save-excursion
         ;; (message "Processing current buffer")
@@ -159,6 +249,11 @@
               (in-heredoc-started-this-line nil)
               (in-heredoc-ended-this-line nil)
               (in-inline-control-structure nil)
+              (inline-html-indent 0)
+              (inline-html-tag-level 0)
+              (inline-html-curly-bracket-level 0)
+              (inline-html-square-bracket-level 0)
+              (inline-html-round-bracket-level 0)
               (first-token-is-inline-html nil)
               (after-special-control-structure nil)
               (after-special-control-structure-token nil)
@@ -383,10 +478,37 @@
                   (when first-token-on-line
                     (setq first-token-is-nesting-decrease t)))
 
-                ;; Detect in inline-html
-                (when (and (equal token 'T_INLINE_HTML)
-                           first-token-on-line)
-                  (setq first-token-is-inline-html t))
+                ;; Handle INLINE_HTML blocks
+                (when (equal token 'T_INLINE_HTML)
+
+                  (when first-token-on-line
+                    (setq first-token-is-inline-html t))
+
+                  (let ((inline-html-indents 
(phps-mode-functions--get-inline-html-indentation 
(buffer-substring-no-properties token-start token-end) inline-html-indent 
inline-html-tag-level inline-html-curly-bracket-level 
inline-html-square-bracket-level inline-html-round-bracket-level)))
+
+                    (when phps-mode-functions-verbose
+                      (message "Received inline html indent: %s from inline 
HTML: '%s'" inline-html-indents (buffer-substring-no-properties token-start 
token-end)))
+
+                    ;; Update indexes
+                    (setq inline-html-indent (nth 1 inline-html-indents))
+                    (setq inline-html-tag-level (nth 2 inline-html-indents))
+                    (setq inline-html-curly-bracket-level (nth 3 
inline-html-indents))
+                    (setq inline-html-square-bracket-level (nth 4 
inline-html-indents))
+                    (setq inline-html-round-bracket-level (nth 5 
inline-html-indents))
+
+                    ;; Does token span several lines and is it not only 
white-space?
+                    (when (> token-end-line-number token-start-line-number)
+                      (unless (string= (string-trim 
(buffer-substring-no-properties token-start token-end)) "")
+                        (let ((token-line-number-diff token-start-line-number))
+                          ;; Iterate lines here and add indents
+                          (dolist (item (nth 0 inline-html-indents))
+                            ;; Skip first line unless first token on line was 
inline-html
+                            (when (or (not (= token-line-number-diff 
token-start-line-number))
+                                      first-token-is-inline-html)
+                              (puthash token-line-number-diff (list item 0) 
line-indents)
+                              (when phps-mode-functions-verbose
+                                (message "Putting indent at line %s to %s from 
inline HTML" token-line-number-diff item)))
+                            (setq token-line-number-diff (1+ 
token-line-number-diff))))))))
 
                 ;; Keep track of when we are inside a class definition
                 (if in-class-declaration
@@ -830,8 +952,7 @@
 
                       ;; Inline HTML should have zero indent
                       (when first-token-is-inline-html
-                        (setq column-level-start 0))
-
+                        (setq column-level-start inline-html-indent))
 
                       ;; Save line indent
                       (when phps-mode-functions-verbose
@@ -840,7 +961,6 @@
                       (when (> token-start-line-number 0)
                         (puthash token-start-line-number `(,column-level-start 
,tuning-level) line-indents))
 
-
                       ;; Support trailing indent decrements
                       (when temp-post-indent
                         (setq column-level temp-post-indent)
@@ -870,8 +990,9 @@
                             )))
 
 
-                      ;; Does token span over several lines?
-                      (when (> token-end-line-number token-start-line-number)
+                      ;; Does token span over several lines and is it not a 
INLINE_HTML token?
+                      (when (and (> token-end-line-number 
token-start-line-number)
+                                 (not (equal token 'T_INLINE_HTML)))
                         (let ((column-level-end column-level))
 
                           ;; HEREDOC lines should have zero indent
@@ -880,10 +1001,6 @@
                                     in-heredoc-ended-this-line)
                             (setq column-level-end 0))
 
-                          ;; Inline HTML should have no indent
-                          (when (equal token 'T_INLINE_HTML)
-                            (setq column-level-end 0))
-
                           ;; (message "Token %s starts at %s and ends at %s 
indent %s %s" next-token token-start-line-number token-end-line-number 
column-level-end tuning-level)
 
                           ;; Indent doc-comment lines with 1 tuning
@@ -899,7 +1016,6 @@
                           ;; Rest tuning-level used for comments
                           (setq tuning-level 0)))
 
-
                       ;; Indent token-less lines here in between last tokens 
if distance is more than 1 line
                       (when (and (> next-token-start-line-number (1+ 
token-end-line-number))
                                  (not (equal token 'T_CLOSE_TAG)))
@@ -1024,11 +1140,10 @@
 
               )))))))
 
-;; TODO Consider how imenu-index should be affected by this
+;; TODO Consider how indentation and imenu-index should be affected by this
 (defun phps-mode-functions-after-change (start _stop _length)
   "Track buffer change from START to STOP with length LENGTH."
-  (when (and (string= major-mode "phps-mode")
-             phps-mode-functions-allow-after-change)
+  (when phps-mode-functions-allow-after-change
 
     ;; If we haven't scheduled incremental lexer before - do it
     (when (and (not phps-mode-functions-buffer-changes-start)
@@ -1043,8 +1158,8 @@
       (setq phps-mode-functions-buffer-changes-start start)
       ;; (message "Setting start of changes to: %s-%s" 
phps-mode-functions-buffer-changes-start stop))
 
-    ;; (message "phps-mode-functions-after-change %s %s %s" start stop length)
-    )))
+      ;; (message "phps-mode-functions-after-change %s %s %s" start stop 
length)
+      )))
 
 (defun phps-mode-functions-imenu-create-index ()
   "Get Imenu for current buffer."
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index 95db78f..d0f8161 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -268,6 +268,12 @@
    "Indent multi-dimensional arrays without trailing commas"
    ;; (message "Tokens: %s" (phps-mode-lexer-get-tokens))
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (0 
0)) (7 (0 0)) (8 (0 0)) (9 (1 0)) (10 (2 0)) (11 (1 0)) (12 (0 0))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent))))
+
+   (phps-mode-test-with-buffer
+    "<html>\n    <head>\n        <?php echo $title; ?>\n    </head>\n    
<body>\n    <?php\n\n    if ($myTest) {\n        doSomething();\n    }\n\n    
?>\n    </body>\n</html>"
+    "A mixed HTML and PHP file."
+    ;; (message "Indent: %s" (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))
+    (should (equal '((1 (0 0)) (2 (1 0)) (3 (0 0)) (4 (1 0)) (5 (1 0)) (6 (0 
0)) (7 (0 0)) (8 (0 0)) (9 (1 0)) (10 (0 0)) (11 (0 0)) (12 (0 0)) (13 (1 0)) 
(14 (0 0))) (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))))
    )
 
   )
@@ -637,7 +643,7 @@
    (goto-char 110)
    (phps-mode-functions-indent-line)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
-     (should (equal buffer-contents "<html><head><title><?php if 
($myCondition) {\nif ($mySeconCondition) {\necho 
$title3;\n\n}\n?>\n</title><body>Bla bla</body></html>"))))
+     (should (equal buffer-contents "<html><head><title><?php if 
($myCondition) {\nif ($mySeconCondition) {\necho $title3;\n\n}\n?>\n    
</title><body>Bla bla</body></html>"))))
 
   (phps-mode-test-with-buffer
    "<?php\n$variable = array(\n'random3'\n);\n$variable = true;\n"
@@ -1037,10 +1043,49 @@
 
   )
 
+(defun phps-mode-test-functions-get-inline-html-indentation ()
+  "Test function."
+
+  (should (equal
+           '(0 1 2 1 1 2 1 0)
+           (nth 0 (phps-mode-functions--get-inline-html-indentation
+                   
"<html>\n<head>\n<title>MyTitle</title>\n</head>\n<body>\n<p>My 
paragraph</p>\n</body>\n</html>"
+                   0
+                   0
+                   0
+                   0
+                   0
+                   ))))
+
+  (should (equal
+           '(2 2 1 0)
+           (nth 0 (phps-mode-functions--get-inline-html-indentation
+                   "\n<p>My paragraph</p>\n</body>\n</html>"
+                   2
+                   2
+                   0
+                   0
+                   0
+                   ))))
+
+  (should (equal
+           '(0)
+           (nth 0 (phps-mode-functions--get-inline-html-indentation
+                   "<html>"
+                   0
+                   0
+                   0
+                   0
+                   0
+                   ))))
+  
+  )
+
 (defun phps-mode-test-functions ()
   "Run test for functions."
   ;; (setq debug-on-error t)
   ;; (setq phps-mode-functions-verbose t)
+  (phps-mode-test-functions-get-inline-html-indentation)
   (phps-mode-test-functions-get-lines-indent-if)
   (phps-mode-test-functions-get-lines-indent-classes)
   (phps-mode-test-functions-get-lines-indent-inline-if)
diff --git a/phps-mode-test-integration.el b/phps-mode-test-integration.el
index 93754a6..91a1c31 100644
--- a/phps-mode-test-integration.el
+++ b/phps-mode-test-integration.el
@@ -37,7 +37,7 @@
    "<?php\nnamespace myNamespace\n{\n    class myClass\n    {\n        public 
function myFunction()\n        {\n            echo 'my statement';\n        }\n 
   }\n}\n"
    "Integration-test 1 for regular PHP with namespaces, classes and functions"
 
-   ;; Make changes
+   ;; Make changes - insert a new function
    (goto-char 144)
    (insert "\n\n        public function myFunctionB()\n        {\n            
echo 'my second statement';\n        }\n")
    (should (equal (phps-mode-functions-get-buffer-changes-start) 144)))
@@ -46,17 +46,21 @@
    "<?php\nnamespace myNamespace\n{\n    class myClass\n    {\n        public 
function myFunction()\n        {\n            echo 'my statement';\n        }\n 
   }\n}\n"
    "Integration-test 2 for regular PHP with namespaces, classes and functions"
 
-   ;; Make changes
+   ;; Make changes - insert a new function
    (goto-char 144)
    (insert "\n\n        public function myFunctionB()\n        {\n            
echo 'my second statement';\n        }\n")
    (should (equal (phps-mode-functions-get-buffer-changes-start) 144))
+
+   ;; Run incremental lexer
    (phps-mode-lexer-run-incremental)
 
-   ;; Remove first function
+   ;; Make changes - remove first function
    (goto-char 55)
    (push-mark nil t t)
    (goto-char 145)
    (execute-kbd-macro (kbd "<backspace>"))
+
+   ;; Test
    (should (equal (phps-mode-functions-get-buffer-changes-start) 55)))
 
   (phps-mode-test-incremental-vs-intial-buffer
@@ -66,22 +70,18 @@
    ;; Make changes
    (goto-char 1)
    (insert "<?php\nfunction myFunctionA()\n{\n    echo 'my second 
statement';\n}\n")
+
+   ;; Test
    (should (equal (phps-mode-functions-get-buffer-changes-start) 1)))
 
   (phps-mode-test-incremental-vs-intial-buffer
    "<?php\n/**\n *\n */\nnamespace myNamespace\n{\n    class myClass\n    {\n  
      public function myFunction()\n        {\n            echo 'my 
statement';\n        }\n    }\n}\n"
    "Integration-test 4 for regular PHP with namespaces, classes and functions, 
white-space change inside token"
 
-   ;; (message "Before tokens: %s" (phps-mode-lexer-get-tokens))
-   ;; (message "Before indent: %s" (phps-mode-test-hash-to-list 
phps-mode-functions-lines-indent))
-
    ;; Make changes
    (goto-char 13)
    (newline-and-indent)
 
-   ;; (message "After tokens: %s" (phps-mode-lexer-get-tokens))
-   ;; (message "After indent: %s" (phps-mode-test-hash-to-list 
phps-mode-functions-lines-indent))
-   
    (should (equal (phps-mode-functions-get-buffer-changes-start) nil)))
 
   )
diff --git a/phps-mode.el b/phps-mode.el
index 607ac2a..d035a18 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: 21 Aug 2019
-;; Version: 0.2.6
+;; Modified: 26 Aug 2019
+;; Version: 0.2.8
 ;; Keywords: tools, convenience
 ;; URL: https://github.com/cjohansson/emacs-phps-mode
 
@@ -48,6 +48,12 @@
 (require 'phps-mode-tags)
 (require 'semantic)
 
+(defvar phps-mode-use-electric-pair-mode t
+  "Whether or not we want to use electric pair mode.")
+
+(defvar phps-mode-use-transient-mark-mode t
+  "Whether or not we want to use transient mark mode.")
+
 (defvar phps-mode-use-psr-2 t
   "Whether to use PSR-2 guidelines for white-space or not.")
 
@@ -56,37 +62,34 @@
 
 (defvar phps-mode-flycheck-applied nil "Boolean flag whether flycheck 
configuration has been applied or not.")
 
-(defvar phps-mode-map-applied nil "Boolean flag whether mode-map has been 
initialized or not.")
-
 (defvar phps-mode-inline-mmm-submode nil "Symbol declaring what mmm-mode to 
use as submode in inline areas.")
 
+(defvar phps-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map (kbd "C-c /") #'comment-region)
+    (define-key map (kbd "C-c DEL") #'uncomment-region)
+    map)
+  "Keymap for `phps-mode'.")
+
 (define-derived-mode phps-mode prog-mode "PHPs"
   "Major mode for PHP with Semantic integration."
 
-  ;; TODO Check whether PSR-2 requires final newlines or not
-  (setq-local require-final-newline t)
-
   ;; Skip comments when navigating via syntax-table
   (setq-local parse-sexp-ignore-comments t)
 
   ;; Key-map
-  ;; prog-mode will create the key-map and we just modify it here.
-  ;; should break this out to stand-alone variable
-  (when (and phps-mode-map
-             (not phps-mode-map-applied))
-    (define-key phps-mode-map (kbd "C-c /") #'comment-region)
-    (define-key phps-mode-map (kbd "C-c DEL") #'uncomment-region)
-    (setq phps-mode-map-applied t))
   (use-local-map phps-mode-map)
 
   ;; Syntax table
   (set-syntax-table phps-mode-syntax-table)
 
-  ;; NOTE: These are required for wrapping region functionality
-  (transient-mark-mode)
+  (when phps-mode-use-transient-mark-mode
+    ;; NOTE: These are required for wrapping region functionality
+    (transient-mark-mode))
 
-  ;; TODO Add this as a setting similar to php-mode
-  (electric-pair-local-mode)
+  ;; TODO Add this as a menu setting similar to php-mode
+  (when phps-mode-use-electric-pair-mode
+    (electric-pair-local-mode))
 
   ;; Font lock
   ;; This makes it possible to have full control over syntax coloring from the 
lexer
@@ -114,8 +117,7 @@
   (setq-local imenu-create-index-function 
#'phps-mode-functions-imenu-create-index)
 
   ;; Should we follow PSR-2?
-  (when (and (boundp 'phps-mode-use-psr-2)
-             phps-mode-use-psr-2)
+  (when phps-mode-use-psr-2
 
     ;; Code MUST use an indent of 4 spaces
     (setq-local tab-width 4)
@@ -127,11 +129,11 @@
   (advice-add #'newline :around #'phps-mode-functions-around-newline)
 
   ;; Reset flags
-  (set (make-local-variable 'phps-mode-functions-allow-after-change) t)
-  (set (make-local-variable 'phps-mode-functions-buffer-changes-start) nil)
-  (set (make-local-variable 'phps-mode-functions-lines-indent) nil)
-  (set (make-local-variable 'phps-mode-functions-imenu) nil)
-  (set (make-local-variable 'phps-mode-functions-processed-buffer) nil)
+  (setq-local phps-mode-functions-allow-after-change t)
+  (setq-local phps-mode-functions-buffer-changes-start nil)
+  (setq-local phps-mode-functions-lines-indent nil)
+  (setq-local phps-mode-functions-imenu nil)
+  (setq-local phps-mode-functions-processed-buffer nil)
 
   ;; Make (comment-region) and (uncomment-region) work
   (setq-local comment-region-function #'phps-mode-functions-comment-region)
@@ -140,21 +142,16 @@
   (setq-local comment-end "")
 
   ;; Support for change detection
-  (add-hook 'after-change-functions #'phps-mode-functions-after-change)
+  (add-hook 'after-change-functions #'phps-mode-functions-after-change 0 t)
 
   ;; Lexer
-  (if (and (boundp 'semantic-lex-syntax-table)
-           (boundp 'phps-mode-syntax-table))
-      (setq-local semantic-lex-syntax-table phps-mode-syntax-table)
-    (signal 'error "Semantic or regular syntax-table for PHPs-mode missing!"))
+  (setq-local semantic-lex-syntax-table phps-mode-syntax-table)
 
   ;; Semantic
-  (if (boundp 'semantic-lex-analyzer)
-      (setq-local semantic-lex-analyzer #'phps-mode-lexer-lex)
-    (signal 'error "Semantic semantic-lex-analyzer missing!"))
+  (setq-local semantic-lex-analyzer #'phps-mode-lexer-lex)
 
   ;; Set semantic-lex initializer function
-  (add-hook 'semantic-lex-reset-functions #'phps-mode-lexer-setup)
+  (add-hook 'semantic-lex-reset-functions #'phps-mode-lexer-setup 0 t)
 
   ;; Reset tokens
   (setq-local phps-mode-lexer-tokens nil)
diff --git a/sample-php-files/alternative-control-structure.php 
b/sample-php-files/alternative-control-structure.php
index cd9a48a..260d90d 100644
--- a/sample-php-files/alternative-control-structure.php
+++ b/sample-php-files/alternative-control-structure.php
@@ -11,6 +11,15 @@ else:
     echo 'was false 2';
 endif;
 
+function myFunction() {
+    echo 'was here';
+    ?>
+<html><body>
+    <div>My random stuff</div>
+</body></html>
+    <?php
+}
+
 
 switch (true):
     case true:
@@ -24,5 +33,8 @@ endswitch;
 ?>
 <html>
     <body>
+        <p>
+<?php echo $my; ?>
+        </p>
     </body>
 </html>
diff --git a/sample-php-files/class.php b/sample-php-files/class.php
index d555b4b..2225452 100644
--- a/sample-php-files/class.php
+++ b/sample-php-files/class.php
@@ -26,14 +26,14 @@ class MyClass
             $this->var = '';
         }
         if (empty(
-                $this->var
+            $this->var
         )) {
             $this->var = 'abc';
         }
         if (empty(
-                $this->var
-                ) && !empty($this->var)
-            ) {
+            $this->var
+            ) && !empty($this->var)
+        ) {
             $this->var = 'abc123';
         }
 



reply via email to

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