help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [External] : Re: Making a regex string that matches (


From: Drew Adams
Subject: RE: [External] : Re: Making a regex string that matches (
Date: Thu, 10 Mar 2022 17:57:12 +0000

> Have come up with the following function.  Would this be enough to
> count the number oy opening parantheses in a region ?
> 
> (defun bracketing-count (region-start region-end)
>   "Counts opening and closing bracketing marks.
> 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)
>                       (search-forward "\(" region-end t))
>         (setq count (1+ count))) ))))

1. You can just use function `count-matches', with "("
   as the regexp.

https://emacs.stackexchange.com/q/70870/105

2. (let (count) (setq count 0)...)
->
   (let ((count  0)...)

3. (search-forward "(" ...)  ; You don't need "\(".

4. If your user uses your command, s?he sees only the
   message "Counting bracketing marks...".  She likely
   would like to see the count at the end, no?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]