I want to write a function that uses a selected region and counts the number of left and right bracketing marks (whether ()
, {}
, []
, <>
).
I have started with this
(defun veak-count (region-start region-end)
"todo
Interactive functions enable them to be called using `M-x`"
(interactive "r") ; gets region start and end
(message "Counting bracketing marks ...")
(save-excursion
(let (count)
(setq count 0)
(goto-char region-start)
(while (and (< (point) region-end)
(re-search-forward "\(" region-end t))
(setq count (1+ count))) ))))
I then updated to use `count-matches`, but selecting the following line, gives 0 as count.
(global-set-key (kbd "[") 'skeleton-pair-insert-maybe)
--------
(defun veak-count (region-start region-end)
"Count the `{` characters in the region.
REGION-START and REGION-END are the region limits."
(interactive "r")
(save-excursion
(let ( (count (count-matches "\(" (point) region-end)) )
(message "%d" count) )))