Function: hypb:in-string-check
hypb:in-string-check is a byte-compiled function defined in hypb.el.
Signature
(hypb:in-string-check &optional RANGE-FLAG)
Documentation
Return non-nil iff point is within a string and not on the closing quote.
With optional RANGE-FLAG when there is a match, return list of (in-string-flag start-pos end-pos), where in-string-flag is t or nil and the positions exclude the delimiters.
To prevent searching back to the buffer start and producing slow performance, this limits its count of quotes found prior to point to the beginning of the first line prior to point that contains a non-backslashed quote mark and limits string length to a maximum of 9000 characters.
Quoting conventions recognized are:
double-quotes: "str";
Markdown triple backticks: ```str``;
Python single-quotes: \=str';
Python triple single-quotes: '''str''';
Python triple double-quotes: """str""";
Texinfo open and close quotes: `str'.
Source Code
;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hypb.el
(defun hypb:in-string-check (&optional range-flag)
"Return non-nil iff point is within a string and not on the closing quote.
With optional RANGE-FLAG when there is a match, return list of (in-string-flag
start-pos end-pos), where in-string-flag is t or nil and the positions exclude
the delimiters.
To prevent searching back to the buffer start and producing slow
performance, this limits its count of quotes found prior to point to the
beginning of the first line prior to point that contains a non-backslashed
quote mark and limits string length to a maximum of 9000 characters.
Quoting conventions recognized are:
double-quotes: \"str\";
Markdown triple backticks: ```str```;
Python single-quotes: \\='str\\=';
Python triple single-quotes: '''str''';
Python triple double-quotes: \"\"\"str\"\"\";
Texinfo open and close quotes: ``str''."
(let ((list-of-unformatted-open-close-regexps (eval hypb:in-string-mode-regexps))
;; search limit length
(limit 9000)
list-of-open-close-regexps)
(if (and list-of-unformatted-open-close-regexps
(listp list-of-unformatted-open-close-regexps)
(not (memq nil (mapcar #'listp list-of-unformatted-open-close-regexps))))
;; Modify open-close regexps to ignore backslash-quoted matches
(let* ((orig-format "\\(\\)\\(%s\\)")
(regexp-format "\\(^\\|[^\\]\\)\\(%s\\)"))
(setq list-of-open-close-regexps
(mapcar (lambda (open-close)
(list
(format orig-format (nth 0 open-close))
(format orig-format (nth 1 open-close))
(format regexp-format (nth 0 open-close))
(format regexp-format (nth 1 open-close))))
list-of-unformatted-open-close-regexps)))
(error "(hypb:in-string-p): `hypb:in-string-mode-regexps' must be a list of lists, not %S"
hypb:in-string-mode-regexps))
(cl-block :result
(let ((opoint (point))
(start (point-min)))
(dolist (open-close-regexps list-of-open-close-regexps)
(save-excursion
;; Don't use `syntax-ppss' here as it fails to ignore backquoted
;; double quote characters in strings and doesn't work in
;; `change-log-mode' due to its syntax-table.
(let ((open-match-string "")
possible-delim
in-str
str-start
str-end)
(cl-destructuring-bind (orig-open-regexp orig-close-regexp open-regexp _close-regexp)
open-close-regexps
(save-match-data
(if (and (setq possible-delim
(or (looking-at orig-open-regexp)
(looking-at orig-close-regexp)))
(/= (or (char-before) 0) ?\\)
(setq open-match-string (match-string 2)))
(while (and (setq possible-delim (search-backward open-match-string (max (point-min) (- (point) limit)) t))
(if (= (or (char-before) 0) ?\\)
(goto-char (1- (point)))
(progn (setq str-start (match-end 0))
nil))))
(when (setq possible-delim (re-search-backward open-regexp (max (point-min) (- (point) limit)) t))
(setq open-match-string (match-string 2))
(setq str-start (match-end 2))))
(when (and possible-delim
str-start
;; If this is the start of a string, it must be
;; at the start of line, preceded by whitespace
;; or preceded by another string end sequence.
;; (save-match-data
;; (or (string-empty-p (match-string 1))
;; (string-search (match-string 1) " \t\n\r\f")
;; (progn (goto-char (1+ (point)))
;; (looking-back close-regexp nil))))
)
(forward-line 0)
(setq start (point))
(goto-char opoint)
(if (and (derived-mode-p 'texinfo-mode)
(string-equal open-match-string texinfo-open-quote))
(and (cl-oddp (- (count-matches (regexp-quote open-match-string)
start (point))
;; Subtract any backslash quoted delimiters
(count-matches
(format "[\\]\\(%s\\)"
(regexp-quote open-match-string))
start (point))
(count-matches (regexp-quote texinfo-close-quote)
start (point))
;; Subtract any backslash quoted delimiters
(count-matches
(format "[\\]\\(%s\\)"
(regexp-quote texinfo-close-quote))
start (point))))
(progn (while (and (setq possible-delim (search-forward
texinfo-close-quote
(min (point-max) (+ (point) limit))
t))
(= (or (char-before (match-beginning 0)) 0) ?\\)))
possible-delim)
(setq str-end (match-beginning 0)
in-str t))
(and (cl-oddp (- (count-matches (regexp-quote open-match-string)
start (point))
;; Subtract any backslash quoted delimiters
(count-matches
(format "[\\]\\(%s\\)"
(regexp-quote open-match-string))
start (point))))
;; Move back one char in case point is on a
;; closing delimiter char to ensure it is not
;; backslash quoted and so the right delimiter is matched.
;; Find the matching closing delimiter
(progn (while (and (setq possible-delim
(search-forward open-match-string
(min (point-max) (+ (point) limit))
t))
(= (or (char-before (match-beginning 0)) 0) ?\\)))
possible-delim)
(setq str-end (match-beginning 0)
in-str t)))
(when (and in-str str-start str-end)
(cl-return-from :result
(if range-flag
(if (or (null str-start) (zerop str-start))
(list nil (point) (point))
(list in-str str-start str-end))
in-str)))))))))))))