Skip to content

Commit c9601d9

Browse files
author
fallchildren
committed
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)
1 parent c3f3ac1 commit c9601d9

File tree

2 files changed

+19
-36
lines changed

2 files changed

+19
-36
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ In chronological order:
389389
72. tangxifan
390390
73. [Serghei Iakovlev](https://github.com/sergeyklay)
391391
74. [Christian Albrecht](https://github.com/calbrecht)
392+
75. [Sebastian Fieber](https://github.com/fallchildren)
392393

393394

394395

php-mode.el

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
(defconst php-mode-version-number "1.18.4"
1616
"PHP Mode version number.")
1717

18-
(defconst php-mode-modified "2017-12-03"
18+
(defconst php-mode-modified "2018-01-23"
1919
"PHP Mode build date.")
2020

2121
;; This file is free software; you can redistribute it and/or
@@ -469,6 +469,9 @@ SYMBOL
469469
(c-lang-defconst c-vsemi-status-unknown-p-fn
470470
php 'php-c-vsemi-status-unknown-p)
471471

472+
(c-lang-defconst c-get-state-before-change-functions
473+
php nil)
474+
472475
;; Make php-mode recognize opening tags as preprocessor macro's.
473476
;;
474477
;; This is a workaround, the tags must be recognized as something
@@ -951,18 +954,12 @@ this ^ lineup"
951954

952955
(defun php-syntax-propertize-function (start end)
953956
"Apply propertize rules from START to END."
954-
;; (defconst php-syntax-propertize-function
955-
;; (syntax-propertize-rules
956-
;; (php-heredoc-start-re (0 (ignore (php-heredoc-syntax))))))
957-
(goto-char start)
958-
(while (and (< (point) end)
959-
(re-search-forward php-heredoc-start-re end t))
960-
(php-heredoc-syntax))
961-
(goto-char start)
962-
(while (re-search-forward "['\"]" end t)
963-
(when (php-in-comment-p)
964-
(c-put-char-property (match-beginning 0)
965-
'syntax-table (string-to-syntax "_")))))
957+
(funcall
958+
(syntax-propertize-rules
959+
(php-heredoc-start-re (0 (ignore (php-heredoc-syntax))))
960+
("\\(\"\\)\\(\\\\.\\|[^\"\n\\]\\)*\\(\"\\)" (1 "\"") (3 "\""))
961+
("\\(\'\\)\\(\\\\.\\|[^\'\n\\]\\)*\\(\'\\)" (1 "\"") (3 "\"")))
962+
start end))
966963

967964
(defun php-heredoc-syntax ()
968965
"Mark the boundaries of searched heredoc."
@@ -1146,18 +1143,13 @@ After setting the stylevars run hooks according to STYLENAME
11461143
(modify-syntax-entry ?_ "_" php-mode-syntax-table)
11471144
(modify-syntax-entry ?` "\"" php-mode-syntax-table)
11481145
(modify-syntax-entry ?\" "\"" php-mode-syntax-table)
1146+
(modify-syntax-entry ?' "\"" php-mode-syntax-table)
11491147
(modify-syntax-entry ?# "< b" php-mode-syntax-table)
11501148
(modify-syntax-entry ?\n "> b" php-mode-syntax-table)
1151-
(modify-syntax-entry ?$ "'" php-mode-syntax-table)
1152-
1153-
(set (make-local-variable 'syntax-propertize-via-font-lock)
1154-
'(("\\(\"\\)\\(\\\\.\\|[^\"\n\\]\\)*\\(\"\\)" (1 "\"") (3 "\""))
1155-
("\\(\'\\)\\(\\\\.\\|[^\'\n\\]\\)*\\(\'\\)" (1 "\"") (3 "\""))))
11561149

1150+
(setq-local syntax-propertize-function #'php-syntax-propertize-function)
11571151
(add-to-list (make-local-variable 'syntax-propertize-extend-region-functions)
11581152
#'php-syntax-propertize-extend-region)
1159-
(set (make-local-variable 'syntax-propertize-function)
1160-
#'php-syntax-propertize-function)
11611153

11621154
(setq imenu-generic-expression php-imenu-generic-expression)
11631155

@@ -1497,8 +1489,8 @@ a completion list."
14971489

14981490
(defvar php-phpdoc-font-lock-keywords
14991491
`((,(lambda (limit)
1500-
(c-font-lock-doc-comments "/\\*\\*" limit
1501-
php-phpdoc-font-lock-doc-comments)))))
1492+
(c-font-lock-doc-comments "/\\*\\*" limit
1493+
php-phpdoc-font-lock-doc-comments)))))
15021494

15031495
(defconst php-font-lock-keywords-1 (c-lang-const c-matchers-1 php)
15041496
"Basic highlighting for PHP Mode.")
@@ -1539,6 +1531,10 @@ a completion list."
15391531
("\\b\\(array\\)\\s-+\\$" 1 font-lock-type-face)
15401532
(")\\s-*:\\s-*\\??\\(array\\)\\b" 1 font-lock-type-face)
15411533

1534+
;; namespaces
1535+
("\\(\\([a-zA-Z0-9]+\\\\\\)+[a-zA-Z0-9]+\\|\\(\\\\[a-zA-Z0-9]+\\)+\\)[^:a-zA-Z0-9\\\\]" 1 'font-lock-type-face)
1536+
("\\(\\([a-zA-Z0-9]+\\\\\\)+[a-zA-Z0-9]+\\|\\(\\\\[a-zA-Z0-9]+\\)+\\)::" 1 'php-constant)
1537+
15421538
;; Support the ::class constant in PHP5.6
15431539
("\\sw+\\(::\\)\\(class\\)\\b" (1 'php-paamayim-nekudotayim) (2 'php-constant)))
15441540

@@ -1679,20 +1675,6 @@ The output will appear in the buffer *PHP*."
16791675
(delete-char 1))))
16801676

16811677
(ad-activate 'fixup-whitespace)
1682-
1683-
;; Advice `font-lock-fontify-keywords-region' to support namespace
1684-
;; separators in class names. Use word syntax for backslashes when
1685-
;; doing keyword fontification, but not when doing syntactic
1686-
;; fontification because that breaks \ as escape character in strings.
1687-
;;
1688-
;; Special care is taken to restore the original syntax, because we
1689-
;; want \ not to be word for functions like forward-word.
1690-
(defadvice font-lock-fontify-keywords-region (around backslash-as-word activate)
1691-
"Fontify keywords with backslash as word character."
1692-
(let ((old-syntax (string (char-syntax ?\\))))
1693-
(modify-syntax-entry ?\\ "w")
1694-
ad-do-it
1695-
(modify-syntax-entry ?\\ old-syntax)))
16961678

16971679

16981680
(defcustom php-class-suffix-when-insert "::"

0 commit comments

Comments
 (0)