Function: hui-select-string-p

hui-select-string-p is a byte-compiled function defined in hui-select.el.

Signature

(hui-select-string-p &optional START-DELIM END-DELIM)

Documentation

Return (start . end) positions of a string, including delimiters.

This works when point is immediately before the opening or closing delimiter or within the text of the string. The string is delimited by double quotes, unless optional START-DELIM and END-DELIM (strings) are given. Return nil if not at a string.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hui-select.el
(defun hui-select-string-p (&optional start-delim end-delim)
  "Return (start . end) positions of a string, including delimiters.
This works when point is immediately before the opening or closing
delimiter or within the text of the string.  The string is delimited
by double quotes, unless optional START-DELIM and END-DELIM (strings)
are given.  Return nil if not at a string."
  (unless start-delim (setq start-delim "\""))
  (unless end-delim (setq end-delim "\""))
  (let (string-start-end)
  (with-syntax-table hbut:syntax-table
    ;; On or before double quote delimiters
    (if (and (equal start-delim "\"") (equal end-delim "\""))
        (cond ((and (= (or (char-after) 0) ?\")
		    (/= (or (char-before) 0) ?\\))
	       (if (setq string-start-end (hypb:in-string-p nil t))
		   ;; Add double quote delimiters to the region returned
		   (hui-select-set-region (1- (nth 1 string-start-end))
					  (1+ (nth 2 string-start-end)))
		 ;; May be on the closing double quote of a string in
		 ;; which case this first scan-sexps will fail but
		 ;; the second will succeed.
		 (when (setq string-start-end
			     (or (ignore-errors (hui-select-set-region (point) (scan-sexps (point) 1)))
				 (ignore-errors (hui-select-set-region
						 (scan-sexps (1+ (point)) -1)
						 (1+ (point))))))
		   (hui-select-set-region
		    (min (car string-start-end) (cdr string-start-end))
		    (max (car string-start-end) (cdr string-start-end))))))
	      ((and (= (or (char-before) 0) ?\")
		    (/= (or (char-before (1- (point))) 0) ?\\))
	       (if (setq string-start-end (hypb:in-string-p nil t))
		   ;; Add double quote delimiters to the region returned
		   (hui-select-set-region (1- (nth 1 string-start-end))
					  (1+ (nth 2 string-start-end)))
		 ;; Either there are no matching string delimiters
		 ;; (only an open delimiter) or (point) is immediately
		 ;; after the end of the string in which case the
		 ;; following scan-sexps will succeed.
		 (when (setq string-start-end
			     (ignore-errors (hui-select-set-region (point) (scan-sexps (point) -1))))
		   (hui-select-set-region
		    (min (car string-start-end) (cdr string-start-end))
		    (max (car string-start-end) (cdr string-start-end)))))))

      ;; Non-double quote delimiters
      (save-excursion
        (when (looking-at (regexp-quote start-delim))
	  (goto-char (match-end 0)))
        (when (setq string-start-end
		    (hargs:delimited start-delim end-delim nil nil t))
	  ;; Include delimiters
	  (hui-select-set-region (- (nth 1 string-start-end)
				    (length start-delim))
				 (+ (nth 2 string-start-end)
				    (length end-delim)))))))))