Function: hywiki-get-delimited-region

hywiki-get-delimited-region is a byte-compiled function defined in hywiki.el.

Signature

(hywiki-get-delimited-region)

Documentation

Immediately before or after a balanced delimiter, return the delimited range.

Include: (), {}, <>, [] and "" (double quotes). Exclude Org links and radio targets.

If no such range, return '(nil nil). This includes the delimiters: (), {}, <>, [] and "" (double quotes).

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260822.1645/hywiki.el
(defun hywiki-get-delimited-region ()
  "Immediately before or after a balanced delimiter, return the delimited range.
Include: (), {}, <>, [] and \"\" (double quotes).  Exclude Org links
and radio targets.

If no such range, return \\='(nil nil).
This includes the delimiters: (), {}, <>, [] and \"\" (double quotes)."
  (let* ((deleting-backward-flag
	  (and (symbolp this-command)
	       (string-match-p "backward" (symbol-name this-command))
	       (string-match-p "delete\\|kill" (symbol-name this-command))))
	 (result
	  (condition-case nil
              (with-syntax-table hbut:syntax-table
                (cond
                 (deleting-backward-flag
		  ;; Since are deleting backward, consider closing
		  ;; delims first
                  (hywiki--get-delimited-range-at-closing-delimiter))
                 ;; Handle opening delimiters
                 ((memq (char-before) '(?\[ ?\<))
		  (goto-char (1- (point)))
		  (hywiki--get-delimited-range-forward))
                 ((memq (char-after) '(?\[ ?\<))
		  (hywiki--get-delimited-range-forward))
                 ((memq (char-before) '(?\( ?\{))
		  (goto-char (1- (point)))
		  (list (point) (scan-sexps (point) 1)))
                 ((memq (char-after) '(?\( ?\{))
		  (list (point) (scan-sexps (point) 1)))
                 ((and (eq (char-before) ?\")
		       (hypb:in-string-p))
		  (goto-char (1- (point)))
		  (list (point) (scan-sexps (point) 1)))
                 ((and (eq (char-after) ?\")
		       (hypb:in-string-p))
		  (goto-char (1+ (point)))
		  (list (point) (scan-sexps (point) -1)))
                 ((not deleting-backward-flag)
                  (hywiki--get-delimited-range-at-closing-delimiter))))
	    (error nil))))
    (if (and (integerp (nth 0 result)) (integerp (nth 1 result)))
	(sort result #'<)
      '(nil nil))))