-
-
Save twlz0ne/0b66fefd460236b7d51567e99028afff to your computer and use it in GitHub Desktop.
Add string support for thing-at-point #Emacs #emacs-lisp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; string-at-point.el --- Add string support for ‘thing-at-point’ -*- lexical-binding: t; -*- | |
;; Copyright (C) 2020 Gong Qijian <gongqijian@gmail.com> | |
;; SPDX-License-Identifier: GPL-3.0-or-later | |
;;; Commentary: | |
;;; Code: | |
(require 'pcase) | |
(put 'string 'bounds-of-thing-at-point 'string-at-point-bounds-of-string-at-point) | |
(defun string-at-point-bounds-of-string-at-point () | |
"Return the bounds of the string at point." | |
(or (pcase (syntax-ppss) | |
(`(,_ ,_ ,_ ,at-string-p ,_ ,_ ,_ ,_ ,string-start . ,_) | |
(when (and at-string-p string-start) | |
(cons string-start | |
(save-excursion | |
(goto-char string-start) | |
(forward-sexp) | |
(point)))))) | |
;; Point at the beginning of string. | |
(if (eq (char-after (point)) ?\") | |
(cons (point) | |
(save-excursion | |
(forward-sexp 1) | |
(point)))))) | |
(defun string-at-point () | |
"Return the string at point, or nil if none is found." | |
(form-at-point 'string)) | |
(provide 'string-at-point) | |
;;; string-at-point.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment