|
1 | 1 | ;;; php.el --- PHP support for friends -*- lexical-binding: t; -*-
|
2 | 2 |
|
3 | 3 | ;; Copyright (C) 2022 Friends of Emacs-PHP development
|
| 4 | +;; Copyright (C) 1985, 1987, 1992-2022 Free Software Foundation, Inc. |
4 | 5 |
|
5 | 6 | ;; Author: USAMI Kenta <[email protected]>
|
6 | 7 | ;; Created: 5 Dec 2018
|
|
26 | 27 |
|
27 | 28 | ;; This file provides common variable and functions for PHP packages.
|
28 | 29 |
|
| 30 | +;; These functions are copied function from GNU Emacs. |
| 31 | +;; |
| 32 | +;; - c-end-of-token (cc-engine.el) |
| 33 | +;; |
| 34 | + |
29 | 35 | ;;; Code:
|
30 | 36 | (eval-when-compile
|
| 37 | + (require 'cc-mode) |
31 | 38 | (require 'cl-lib))
|
| 39 | +(require 'cc-engine) |
32 | 40 | (require 'flymake)
|
33 | 41 | (require 'php-project)
|
34 | 42 | (require 'rx)
|
@@ -431,6 +439,36 @@ can be used to match against definitions for that classlike."
|
431 | 439 | (when (re-search-backward re-pattern nil t)
|
432 | 440 | (match-string-no-properties 1)))))
|
433 | 441 |
|
| 442 | +(eval-and-compile |
| 443 | + (if (eval-when-compile (fboundp 'c-end-of-token)) |
| 444 | + (defalias 'php--c-end-of-token #'c-end-of-token) |
| 445 | + ;; Copyright (C) 1985, 1987, 1992-2022 Free Software Foundation, Inc. |
| 446 | + ;; Follows function is copied from Emacs 27's cc-engine.el. |
| 447 | + ;; https://emba.gnu.org/emacs/emacs/-/commit/95fb826dc58965eac287c0826831352edf2e56f7 |
| 448 | + (defun php--c-end-of-token (&optional back-limit) |
| 449 | + ;; Move to the end of the token we're just before or in the middle of. |
| 450 | + ;; BACK-LIMIT may be used to bound the backward search; if given it's |
| 451 | + ;; assumed to be at the boundary between two tokens. Return non-nil if the |
| 452 | + ;; point is moved, nil otherwise. |
| 453 | + ;; |
| 454 | + ;; This function might do hidden buffer changes. |
| 455 | + (let ((start (point))) |
| 456 | + (cond ;; ((< (skip-syntax-backward "w_" (1- start)) 0) |
| 457 | + ;; (skip-syntax-forward "w_")) |
| 458 | + ((> (skip-syntax-forward "w_") 0)) |
| 459 | + ((< (skip-syntax-backward ".()" back-limit) 0) |
| 460 | + (while (< (point) start) |
| 461 | + (if (looking-at c-nonsymbol-token-regexp) |
| 462 | + (goto-char (match-end 0)) |
| 463 | + ;; `c-nonsymbol-token-regexp' should always match since |
| 464 | + ;; we've skipped backward over punctuation or paren |
| 465 | + ;; syntax, but move forward in case it doesn't so that |
| 466 | + ;; we don't leave point earlier than we started with. |
| 467 | + (forward-char)))) |
| 468 | + (t (if (looking-at c-nonsymbol-token-regexp) |
| 469 | + (goto-char (match-end 0))))) |
| 470 | + (> (point) start))))) |
| 471 | + |
434 | 472 | (defun php-get-pattern ()
|
435 | 473 | "Find the pattern we want to complete.
|
436 | 474 | `find-tag-default' from GNU Emacs etags.el"
|
|
0 commit comments