From c9601d9130977f69392cc29869e4cbe5cefc8f89 Mon Sep 17 00:00:00 2001 From: fallchildren Date: Tue, 23 Jan 2018 00:27:57 +0100 Subject: [PATCH 1/4] fix some font-lock and indentation issues in emacs 25 - Removed advice "font-lock-fontify-keywords-region" (fixes GitHub Issue: #280) - Changed syntax-propertize code to work with emacs 25 (fixes GitHub Issue: #371) - Necessary code changes to replace the advice (font-locking for namespaces) --- README.md | 1 + php-mode.el | 54 ++++++++++++++++++----------------------------------- 2 files changed, 19 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 0e201d4c..db9e407b 100644 --- a/README.md +++ b/README.md @@ -389,6 +389,7 @@ In chronological order: 72. tangxifan 73. [Serghei Iakovlev](https://github.com/sergeyklay) 74. [Christian Albrecht](https://github.com/calbrecht) +75. [Sebastian Fieber](https://github.com/fallchildren) diff --git a/php-mode.el b/php-mode.el index e0673eb8..6b3f56e7 100644 --- a/php-mode.el +++ b/php-mode.el @@ -15,7 +15,7 @@ (defconst php-mode-version-number "1.18.4" "PHP Mode version number.") -(defconst php-mode-modified "2017-12-03" +(defconst php-mode-modified "2018-01-23" "PHP Mode build date.") ;; This file is free software; you can redistribute it and/or @@ -469,6 +469,9 @@ SYMBOL (c-lang-defconst c-vsemi-status-unknown-p-fn php 'php-c-vsemi-status-unknown-p) +(c-lang-defconst c-get-state-before-change-functions + php nil) + ;; Make php-mode recognize opening tags as preprocessor macro's. ;; ;; This is a workaround, the tags must be recognized as something @@ -951,18 +954,12 @@ this ^ lineup" (defun php-syntax-propertize-function (start end) "Apply propertize rules from START to END." - ;; (defconst php-syntax-propertize-function - ;; (syntax-propertize-rules - ;; (php-heredoc-start-re (0 (ignore (php-heredoc-syntax)))))) - (goto-char start) - (while (and (< (point) end) - (re-search-forward php-heredoc-start-re end t)) - (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 "_"))))) + (funcall + (syntax-propertize-rules + (php-heredoc-start-re (0 (ignore (php-heredoc-syntax)))) + ("\\(\"\\)\\(\\\\.\\|[^\"\n\\]\\)*\\(\"\\)" (1 "\"") (3 "\"")) + ("\\(\'\\)\\(\\\\.\\|[^\'\n\\]\\)*\\(\'\\)" (1 "\"") (3 "\""))) + start end)) (defun php-heredoc-syntax () "Mark the boundaries of searched heredoc." @@ -1146,18 +1143,13 @@ After setting the stylevars run hooks according to STYLENAME (modify-syntax-entry ?_ "_" php-mode-syntax-table) (modify-syntax-entry ?` "\"" php-mode-syntax-table) (modify-syntax-entry ?\" "\"" php-mode-syntax-table) + (modify-syntax-entry ?' "\"" php-mode-syntax-table) (modify-syntax-entry ?# "< b" php-mode-syntax-table) (modify-syntax-entry ?\n "> b" php-mode-syntax-table) - (modify-syntax-entry ?$ "'" php-mode-syntax-table) - - (set (make-local-variable 'syntax-propertize-via-font-lock) - '(("\\(\"\\)\\(\\\\.\\|[^\"\n\\]\\)*\\(\"\\)" (1 "\"") (3 "\"")) - ("\\(\'\\)\\(\\\\.\\|[^\'\n\\]\\)*\\(\'\\)" (1 "\"") (3 "\"")))) + (setq-local syntax-propertize-function #'php-syntax-propertize-function) (add-to-list (make-local-variable 'syntax-propertize-extend-region-functions) #'php-syntax-propertize-extend-region) - (set (make-local-variable 'syntax-propertize-function) - #'php-syntax-propertize-function) (setq imenu-generic-expression php-imenu-generic-expression) @@ -1497,8 +1489,8 @@ a completion list." (defvar php-phpdoc-font-lock-keywords `((,(lambda (limit) - (c-font-lock-doc-comments "/\\*\\*" limit - php-phpdoc-font-lock-doc-comments))))) + (c-font-lock-doc-comments "/\\*\\*" limit + php-phpdoc-font-lock-doc-comments))))) (defconst php-font-lock-keywords-1 (c-lang-const c-matchers-1 php) "Basic highlighting for PHP Mode.") @@ -1539,6 +1531,10 @@ a completion list." ("\\b\\(array\\)\\s-+\\$" 1 font-lock-type-face) (")\\s-*:\\s-*\\??\\(array\\)\\b" 1 font-lock-type-face) + ;; namespaces + ("\\(\\([a-zA-Z0-9]+\\\\\\)+[a-zA-Z0-9]+\\|\\(\\\\[a-zA-Z0-9]+\\)+\\)[^:a-zA-Z0-9\\\\]" 1 'font-lock-type-face) + ("\\(\\([a-zA-Z0-9]+\\\\\\)+[a-zA-Z0-9]+\\|\\(\\\\[a-zA-Z0-9]+\\)+\\)::" 1 'php-constant) + ;; Support the ::class constant in PHP5.6 ("\\sw+\\(::\\)\\(class\\)\\b" (1 'php-paamayim-nekudotayim) (2 'php-constant))) @@ -1679,20 +1675,6 @@ The output will appear in the buffer *PHP*." (delete-char 1)))) (ad-activate 'fixup-whitespace) - -;; Advice `font-lock-fontify-keywords-region' to support namespace -;; separators in class names. Use word syntax for backslashes when -;; doing keyword fontification, but not when doing syntactic -;; fontification because that breaks \ as escape character in strings. -;; -;; Special care is taken to restore the original syntax, because we -;; want \ not to be word for functions like forward-word. -(defadvice font-lock-fontify-keywords-region (around backslash-as-word activate) - "Fontify keywords with backslash as word character." - (let ((old-syntax (string (char-syntax ?\\)))) - (modify-syntax-entry ?\\ "w") - ad-do-it - (modify-syntax-entry ?\\ old-syntax))) (defcustom php-class-suffix-when-insert "::" From 96bf2b02336224282e2d81261446a470a6eeadca Mon Sep 17 00:00:00 2001 From: fallchildren Date: Tue, 23 Jan 2018 09:54:17 +0100 Subject: [PATCH 2/4] fix compilation error "php-heredoc-start-re" must be defined when compiled and run, else macroexpansion fails at compile time. --- php-mode.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/php-mode.el b/php-mode.el index 6b3f56e7..3eeb0e6a 100644 --- a/php-mode.el +++ b/php-mode.el @@ -942,9 +942,10 @@ this ^ lineup" (beginning-of-line) (if (looking-at-p "\\s-*;\\s-*$") 0 '+))) -(defconst php-heredoc-start-re - "<<<\\(?:\\w+\\|'\\w+'\\)$" - "Regular expression for the start of a PHP heredoc.") +(eval-and-compile + (defconst php-heredoc-start-re + "<<<\\(?:\\w+\\|'\\w+'\\)$" + "Regular expression for the start of a PHP heredoc.")) (defun php-heredoc-end-re (heredoc-start) "Build a regular expression for the end of a heredoc started by the string HEREDOC-START." From 2b8b0ea1b2e38e97eceb0132c224c24ba03eafa4 Mon Sep 17 00:00:00 2001 From: fallchildren Date: Tue, 23 Jan 2018 13:08:39 +0100 Subject: [PATCH 3/4] fix tests --- php-mode.el | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/php-mode.el b/php-mode.el index 3eeb0e6a..f84bbca7 100644 --- a/php-mode.el +++ b/php-mode.el @@ -955,9 +955,17 @@ this ^ lineup" (defun php-syntax-propertize-function (start end) "Apply propertize rules from START to END." + (goto-char start) + (while (and (< (point) end) + (re-search-forward php-heredoc-start-re end t)) + (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 "_")))) (funcall (syntax-propertize-rules - (php-heredoc-start-re (0 (ignore (php-heredoc-syntax)))) ("\\(\"\\)\\(\\\\.\\|[^\"\n\\]\\)*\\(\"\\)" (1 "\"") (3 "\"")) ("\\(\'\\)\\(\\\\.\\|[^\'\n\\]\\)*\\(\'\\)" (1 "\"") (3 "\""))) start end)) @@ -1144,9 +1152,9 @@ After setting the stylevars run hooks according to STYLENAME (modify-syntax-entry ?_ "_" php-mode-syntax-table) (modify-syntax-entry ?` "\"" php-mode-syntax-table) (modify-syntax-entry ?\" "\"" php-mode-syntax-table) - (modify-syntax-entry ?' "\"" php-mode-syntax-table) (modify-syntax-entry ?# "< b" php-mode-syntax-table) (modify-syntax-entry ?\n "> b" php-mode-syntax-table) + (modify-syntax-entry ?$ "'" php-mode-syntax-table) (setq-local syntax-propertize-function #'php-syntax-propertize-function) (add-to-list (make-local-variable 'syntax-propertize-extend-region-functions) From 7e4ba4ec53730172ae003bf6026cc42593b3fdfc Mon Sep 17 00:00:00 2001 From: fallchildren Date: Tue, 23 Jan 2018 17:28:13 +0100 Subject: [PATCH 4/4] fix for test "issue-9" in current emacs master this seems also to make font-locking a bit more stable in current emacs master. --- php-mode.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/php-mode.el b/php-mode.el index f84bbca7..cdb1b617 100644 --- a/php-mode.el +++ b/php-mode.el @@ -472,6 +472,11 @@ SYMBOL (c-lang-defconst c-get-state-before-change-functions php nil) +(c-lang-defconst c-before-font-lock-functions + php (if (fboundp #'c-depropertize-new-text) + '(c-depropertize-new-text) + nil)) + ;; Make php-mode recognize opening tags as preprocessor macro's. ;; ;; This is a workaround, the tags must be recognized as something @@ -967,7 +972,7 @@ this ^ lineup" (funcall (syntax-propertize-rules ("\\(\"\\)\\(\\\\.\\|[^\"\n\\]\\)*\\(\"\\)" (1 "\"") (3 "\"")) - ("\\(\'\\)\\(\\\\.\\|[^\'\n\\]\\)*\\(\'\\)" (1 "\"") (3 "\""))) + ("\\('\\)\\(\\\\.\\|[^'\n\\]\\)*\\('\\)" (1 "\"") (3 "\""))) start end)) (defun php-heredoc-syntax ()