Skip to content

Commit 5179a1c

Browse files
committed
Copy c-end-of-token function from cc-engine.el
This function is committed in https://emba.gnu.org/emacs/emacs/-/commit/95fb826dc58965eac287c0826831352edf2e56f7
1 parent 6531053 commit 5179a1c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

lisp/php.el

+38
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
;;; php.el --- PHP support for friends -*- lexical-binding: t; -*-
22

33
;; Copyright (C) 2022 Friends of Emacs-PHP development
4+
;; Copyright (C) 1985, 1987, 1992-2022 Free Software Foundation, Inc.
45

56
;; Author: USAMI Kenta <[email protected]>
67
;; Created: 5 Dec 2018
@@ -26,9 +27,16 @@
2627

2728
;; This file provides common variable and functions for PHP packages.
2829

30+
;; These functions are copied function from GNU Emacs.
31+
;;
32+
;; - c-end-of-token (cc-engine.el)
33+
;;
34+
2935
;;; Code:
3036
(eval-when-compile
37+
(require 'cc-mode)
3138
(require 'cl-lib))
39+
(require 'cc-engine)
3240
(require 'flymake)
3341
(require 'php-project)
3442
(require 'rx)
@@ -431,6 +439,36 @@ can be used to match against definitions for that classlike."
431439
(when (re-search-backward re-pattern nil t)
432440
(match-string-no-properties 1)))))
433441

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+
434472
(defun php-get-pattern ()
435473
"Find the pattern we want to complete.
436474
`find-tag-default' from GNU Emacs etags.el"

0 commit comments

Comments
 (0)