Skip to content

Commit 4202947

Browse files
committed
Copy thing-at-point-bounds-of-string-at-point function from thingatpt.el
1 parent ba65213 commit 4202947

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lisp/php.el

+22
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,28 @@ can be used to match against definitions for that classlike."
461461
(match-string-no-properties 1)))))
462462

463463
(eval-and-compile
464+
(if (eval-when-compile (fboundp 'thing-at-point-bounds-of-string-at-point))
465+
(defalias 'php--thing-at-point-bounds-of-string-at-point #'thing-at-point-bounds-of-string-at-point)
466+
;; Copyright (C) 1991-1998, 2000-2022 Free Software Foundation, Inc.
467+
;; Follows function is copied from Emacs 28's thingatpt.el.
468+
;; https://github.com/emacs-mirror/emacs/commit/2abf143f8185fced544c4f8d144ea710142d7a59
469+
(defun php--thing-at-point-bounds-of-string-at-point ()
470+
"Return the bounds of the string at point.
471+
Prefer the enclosing string with fallback on sexp at point.
472+
\[Internal function used by `bounds-of-thing-at-point'.]"
473+
(save-excursion
474+
(let ((ppss (syntax-ppss)))
475+
(if (nth 3 ppss)
476+
;; Inside the string
477+
(ignore-errors
478+
(goto-char (nth 8 ppss))
479+
(cons (point) (progn (forward-sexp) (point))))
480+
;; At the beginning of the string
481+
(if (eq (char-syntax (char-after)) ?\")
482+
(let ((bound (bounds-of-thing-at-point 'sexp)))
483+
(and bound
484+
(<= (car bound) (point)) (< (point) (cdr bound))
485+
bound))))))))
464486
(if (eval-when-compile (fboundp 'c-end-of-token))
465487
(defalias 'php--c-end-of-token #'c-end-of-token)
466488
;; Copyright (C) 1985, 1987, 1992-2022 Free Software Foundation, Inc.

0 commit comments

Comments
 (0)