Function: hui-select-brace-def-or-declaration
hui-select-brace-def-or-declaration is an interactive and
byte-compiled function defined in hui-select.el.
Signature
(hui-select-brace-def-or-declaration POS)
Documentation
Return (start . end) region of a brace delimited language definition at POS.
If POS is at the first character, opening brace or closing brace of a brace delimited language definition, return (start . end) region, else nil. The major mode for each supported brace language must be included in the list, hui-select-brace-modes.
Key Bindings
Source Code
;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hui-select.el
;;;
;;; Code selections
;;;
(defun hui-select-brace-def-or-declaration (pos)
"Return (start . end) region of a brace delimited language definition at POS.
If POS is at the first character, opening brace or closing brace
of a brace delimited language definition, return (start . end)
region, else nil. The major mode for each supported brace
language must be included in the list, hui-select-brace-modes."
(interactive)
(when (and (featurep 'cc-mode) (memq major-mode hui-select-brace-modes))
(save-excursion
(goto-char pos)
(let ((at-def-brace
(or (looking-at "^\{") (looking-at "^\}")
;; Handle stupid old C-style and new Java
;; style of putting braces at the end of
;; lines.
(and (= (following-char) ?\{)
(stringp defun-prompt-regexp)
(save-excursion
(beginning-of-line)
(looking-at defun-prompt-regexp)))
(and (= (following-char) ?\})
(stringp defun-prompt-regexp)
(ignore-errors
;; Leave point at opening brace.
(goto-char
(hui-select-scan-sexps (1+ (point)) -1))
;; Test if these are defun braces.
(save-excursion
(beginning-of-line)
(looking-at defun-prompt-regexp))))))
eod)
(when (or at-def-brace
;; At the start of a definition:
;; Must be at the first non-whitespace character in the line.
(and (= (point) (save-excursion (hui-select-back-to-indentation)))
;; Must be on an alpha or symbol-constituent character.
;; Also allow ~ for C++ destructors.
(looking-at "[a-zA-z~]\\|\\s_")
;; Previous line, if any, must be blank or a comment
;; start or end or we must be looking at
;; `defun-prompt-regexp' when at the beginning of the line.
(or (and (stringp defun-prompt-regexp)
(save-excursion
(beginning-of-line)
(looking-at defun-prompt-regexp)))
(save-excursion
(if (/= (forward-line -1) 0)
t
(hui-select-at-blank-line-or-comment))))))
(setq hui-select-previous 'brace-def-or-declaration)
;; Handle declarations and definitions embedded within classes.
(if (and (eq (following-char) ?\{)
(/= (point) (save-excursion
(hui-select-back-to-indentation))))
(setq at-def-brace nil))
;;
(unless at-def-brace
(beginning-of-line))
(if (and (not at-def-brace)
(stringp defun-prompt-regexp)
(or (looking-at defun-prompt-regexp)
;; For Java classes mainly
(looking-at "[a-zA-Z_$. \t]+\\s-*\{")))
;; Mark the declaration or definition
(hui-select-set-region
(point)
(progn (goto-char (match-end 0))
(when (eq (preceding-char) ?\{)
(backward-char 1))
(if (eq (following-char) ?\{)
(forward-list 1)
(search-forward ";" nil t))
(skip-chars-forward " \t")
(skip-chars-forward "\n")
(when (looking-at "^\\s-*$")
(forward-line 1))
(point)))
;; Mark function definitions only
(setq eod (save-excursion
(condition-case ()
(progn
(if (and (memq major-mode '(java-mode java-ts-mode))
(fboundp 'id-java-end-of-defun))
(id-java-end-of-defun)
(end-of-defun))
(if (looking-at "^\\s-*$")
(forward-line 1))
(point))
(error (point-max)))))
(when (= (following-char) ?\})
;; Leave point at opening brace.
(goto-char (hui-select-scan-sexps (1+ (point)) -1)))
(when (= (following-char) ?\{)
(while (and (zerop (forward-line -1))
(not (hui-select-at-blank-line-or-comment))))
(when (hui-select-at-blank-line-or-comment)
(forward-line 1)))
;; Mark the whole definition
(setq hui-select-previous 'brace-def-or-declaration)
(hui-select-set-region (point) eod)))))))