Skip to content

Commit 9896ccc

Browse files
authored
Merge pull request #740 from emacs-php/apply-monnier-patch
Apply Stefan Monnier's patch (3)
2 parents e515cc9 + 4b03e9b commit 9896ccc

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

Diff for: lisp/php-mode.el

+34-34
Original file line numberDiff line numberDiff line change
@@ -660,13 +660,14 @@ but only if the setting is enabled."
660660
'+)
661661
(t nil)))))))
662662

663-
(defun php-c-looking-at-or-maybe-in-bracelist (&optional _containing-sexp lim)
663+
(defun php-c-looking-at-or-maybe-in-bracelist (orig-fun &optional containing-sexp lim)
664664
"Replace `c-looking-at-or-maybe-in-bracelist'.
665665
666666
CONTAINING-SEXP is the position of the brace/paren/bracket enclosing
667667
POINT, or nil if there is no such position, or we do not know it. LIM is
668668
a backward search limit."
669669
(cond
670+
((not (derived-mode-p 'php-mode)) (apply orig-fun containing-sexp lim args))
670671
((looking-at-p "{")
671672
(save-excursion
672673
(c-backward-token-2 2 t lim)
@@ -994,20 +995,19 @@ HEREDOC-START."
994995

995996
(eval-and-compile
996997
(defconst php-syntax-propertize-rules
997-
`((php-heredoc-start-re
998-
(0 (ignore (php--syntax-propertize-heredoc
999-
(match-beginning 0)
1000-
(or (match-string 1) (match-string 2) (match-string 3))
1001-
(null (match-string 3))))))
1002-
(,(rx "#[")
1003-
(0 (ignore (php--syntax-propertize-attributes (match-beginning 0)))))
1004-
(,(rx (or "'" "\"" ))
1005-
(0 (ignore (php--syntax-propertize-quotes-in-comment (match-beginning 0)))))))
1006-
1007-
(defmacro php-build-propertize-function ()
1008-
`(byte-compile (syntax-propertize-rules ,@php-syntax-propertize-rules)))
1009-
1010-
(defalias 'php-syntax-propertize-function (php-build-propertize-function)))
998+
(syntax-propertize-precompile-rules
999+
(php-heredoc-start-re
1000+
(0 (ignore (php--syntax-propertize-heredoc
1001+
(match-beginning 0)
1002+
(or (match-string 1) (match-string 2) (match-string 3))
1003+
(null (match-string 3))))))
1004+
((rx "#[")
1005+
(0 (ignore (php--syntax-propertize-attributes (match-beginning 0)))))
1006+
((rx (or "'" "\""))
1007+
(0 (ignore (php--syntax-propertize-quotes-in-comment (match-beginning 0))))))))
1008+
1009+
(defalias 'php-syntax-propertize-function
1010+
(syntax-propertize-rules php-syntax-propertize-rules))
10111011

10121012
(defun php--syntax-propertize-heredoc (start id _is-heredoc)
10131013
"Apply propertize Heredoc and Nowdoc from START, with ID and IS-HEREDOC."
@@ -1208,7 +1208,7 @@ After setting the stylevars run hook `php-mode-STYLENAME-hook'."
12081208
(progn
12091209
(add-hook 'hack-local-variables-hook #'php-mode-set-style-delay t t)
12101210
(setq php-mode--delayed-set-style t)
1211-
(advice-add #'c-set-style :after #'php-mode--disable-delay-set-style '(local)))
1211+
(advice-add 'c-set-style :after #'php-mode--disable-delay-set-style))
12121212
(let ((php-mode-enable-backup-style-variables nil))
12131213
(php-set-style (symbol-name php-mode-coding-style))))
12141214

@@ -1242,15 +1242,12 @@ After setting the stylevars run hook `php-mode-STYLENAME-hook'."
12421242
php-mode-replace-flymake-diag-function)
12431243
(add-hook 'flymake-diagnostic-functions php-mode-replace-flymake-diag-function nil t))
12441244

1245-
(when (fboundp 'c-looking-at-or-maybe-in-bracelist)
1246-
(advice-add #'c-looking-at-or-maybe-in-bracelist
1247-
:override 'php-c-looking-at-or-maybe-in-bracelist '(local)))
1248-
(advice-add #'fixup-whitespace :after #'php-mode--fixup-whitespace-after '(local))
1245+
(advice-add 'c-looking-at-or-maybe-in-bracelist
1246+
:around 'php-c-looking-at-or-maybe-in-bracelist)
1247+
(advice-add 'fixup-whitespace :after #'php-mode--fixup-whitespace-after)
12491248

1250-
(when (fboundp #'acm-backend-tabnine-candidate-expand)
1251-
(advice-add #'acm-backend-tabnine-candidate-expand
1252-
:filter-args #'php-acm-backend-tabnine-candidate-expand-filter-args
1253-
'(local)))
1249+
(advice-add 'acm-backend-tabnine-candidate-expand
1250+
:filter-args #'php-acm-backend-tabnine-candidate-expand-filter-args)
12541251

12551252
(when (>= emacs-major-version 25)
12561253
(with-silent-modifications
@@ -1558,22 +1555,25 @@ The output will appear in the buffer *PHP*."
15581555
;;; logic of `fixup-whitespace'.
15591556
(defun php-mode--fixup-whitespace-after ()
15601557
"Remove whitespace before certain characters in PHP Mode."
1561-
(when (or (looking-at-p " \\(?:;\\|,\\|->\\|::\\)")
1562-
(save-excursion
1563-
(forward-char -2)
1564-
(looking-at-p "->\\|::")))
1558+
(when (and (derived-mode-p 'php-mode)
1559+
(or (looking-at-p " \\(?:;\\|,\\|->\\|::\\)")
1560+
(save-excursion
1561+
(forward-char -2)
1562+
(looking-at-p "->\\|::"))))
15651563
(delete-char 1)))
15661564

15671565
;; Advice for lsp-bridge' acm-backend-tabnine
15681566
;; see https://github.com/manateelazycat/lsp-bridge/issues/402#issuecomment-1305653058
15691567
(defun php-acm-backend-tabnine-candidate-expand-filter-args (args)
15701568
"Adjust to replace bound-start ARGS for Tabnine in PHP."
1571-
(cl-multiple-value-bind (candidate-info bound-start) args
1572-
(save-excursion
1573-
(goto-char bound-start)
1574-
(when (looking-at-p (eval-when-compile (regexp-quote "$")))
1575-
(setq bound-start (1+ bound-start))))
1576-
(list candidate-info bound-start)))
1569+
(if (not (derived-mode-p 'php-mode))
1570+
args
1571+
(cl-multiple-value-bind (candidate-info bound-start) args
1572+
(save-excursion
1573+
(goto-char bound-start)
1574+
(when (looking-at-p (eval-when-compile (regexp-quote "$")))
1575+
(setq bound-start (1+ bound-start))))
1576+
(list candidate-info bound-start))))
15771577

15781578
;;;###autoload
15791579
(progn

0 commit comments

Comments
 (0)