Skip to content

Apply Stefan Monnier's patch (3) #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions lisp/php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -660,13 +660,14 @@ but only if the setting is enabled."
'+)
(t nil)))))))

(defun php-c-looking-at-or-maybe-in-bracelist (&optional _containing-sexp lim)
(defun php-c-looking-at-or-maybe-in-bracelist (orig-fun &optional containing-sexp lim)
"Replace `c-looking-at-or-maybe-in-bracelist'.

CONTAINING-SEXP is the position of the brace/paren/bracket enclosing
POINT, or nil if there is no such position, or we do not know it. LIM is
a backward search limit."
(cond
((not (derived-mode-p 'php-mode)) (apply orig-fun containing-sexp lim args))
((looking-at-p "{")
(save-excursion
(c-backward-token-2 2 t lim)
Expand Down Expand Up @@ -994,20 +995,19 @@ HEREDOC-START."

(eval-and-compile
(defconst php-syntax-propertize-rules
`((php-heredoc-start-re
(0 (ignore (php--syntax-propertize-heredoc
(match-beginning 0)
(or (match-string 1) (match-string 2) (match-string 3))
(null (match-string 3))))))
(,(rx "#[")
(0 (ignore (php--syntax-propertize-attributes (match-beginning 0)))))
(,(rx (or "'" "\"" ))
(0 (ignore (php--syntax-propertize-quotes-in-comment (match-beginning 0)))))))

(defmacro php-build-propertize-function ()
`(byte-compile (syntax-propertize-rules ,@php-syntax-propertize-rules)))

(defalias 'php-syntax-propertize-function (php-build-propertize-function)))
(syntax-propertize-precompile-rules
(php-heredoc-start-re
(0 (ignore (php--syntax-propertize-heredoc
(match-beginning 0)
(or (match-string 1) (match-string 2) (match-string 3))
(null (match-string 3))))))
((rx "#[")
(0 (ignore (php--syntax-propertize-attributes (match-beginning 0)))))
((rx (or "'" "\""))
(0 (ignore (php--syntax-propertize-quotes-in-comment (match-beginning 0))))))))

(defalias 'php-syntax-propertize-function
(syntax-propertize-rules php-syntax-propertize-rules))

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

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

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

(when (fboundp #'acm-backend-tabnine-candidate-expand)
(advice-add #'acm-backend-tabnine-candidate-expand
:filter-args #'php-acm-backend-tabnine-candidate-expand-filter-args
'(local)))
(advice-add 'acm-backend-tabnine-candidate-expand
:filter-args #'php-acm-backend-tabnine-candidate-expand-filter-args)

(when (>= emacs-major-version 25)
(with-silent-modifications
Expand Down Expand Up @@ -1558,22 +1555,25 @@ The output will appear in the buffer *PHP*."
;;; logic of `fixup-whitespace'.
(defun php-mode--fixup-whitespace-after ()
"Remove whitespace before certain characters in PHP Mode."
(when (or (looking-at-p " \\(?:;\\|,\\|->\\|::\\)")
(save-excursion
(forward-char -2)
(looking-at-p "->\\|::")))
(when (and (derived-mode-p 'php-mode)
(or (looking-at-p " \\(?:;\\|,\\|->\\|::\\)")
(save-excursion
(forward-char -2)
(looking-at-p "->\\|::"))))
(delete-char 1)))

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

;;;###autoload
(progn
Expand Down