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-20260414.325/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))))
	 (closing-delims
	  '(cond
	    ;; Handle closing delimiters
	    ((memq (char-before) '(?\] ?\>))
	     (hywiki--get-delimited-range-backward))
	    ((memq (char-after) '(?\] ?\>))
	     (goto-char (1+ (point)))
	     (hywiki--get-delimited-range-backward))
	    ((memq (char-before) '(?\) ?\}))
	     (list (point) (scan-sexps (point) -1)))
	    ((memq (char-after) '(?\) ?\}))
	     (goto-char (1+ (point)))
	     (list (point) (scan-sexps (point) -1)))
	    ((and (eq (char-before) ?\")
		  (not (hypb:in-string-p)))
	     (list (point) (scan-sexps (point) -1)))
	    ((and (eq (char-after) ?\")
		  (not (hypb:in-string-p)))
	     (list (point) (scan-sexps (point) 1)))))
	 (result
	  (condition-case nil
	      (cond
	       (deleting-backward-flag
		;; Since are deleting backward, consider closing
		;; delims first
		(eval closing-delims))
	       ;; 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)
		(eval closing-delims)))
	    (error nil))))
    (if (and (integerp (nth 0 result)) (integerp (nth 1 result)))
	(sort result #'<)
      '(nil nil))))