I have the following code that counts the number of opening and closing braces, but getting the error
and: Wrong type argument: stringp, 40
Here is the code:
(defcustom rk-bracemk '("()" "[]" "{}" "<>")
"Two-character strings of open and close delimiters."
:type '(repeat string)
:group 'convenience)
(defun rk-bracemk-count (brcmarks reg-beg reg-end)
"Count brace marks within a region.
BRCMARKS String defining opening and closing brace marks.
REG-BEG Marker defining start of region.
REG-END Marker defining end of region.
Usage
M-x rk-bracemk-count"
(interactive
(list
(completing-read "Bracemarks: " rk-bracemk nil t)
(region-beginning)
(region-end)))
(save-excursion
(let* ( (begmk (aref brcmarks 0))
(endmk (aref brcmarks 1))
(a 0) (b 0) )
(goto-char reg-beg)
(while (and (< (point) reg-end)
(search-forward begmk reg-end t))
(cl-incf a))
(goto-char reg-beg)
(while (and (< (point) reg-end)
(search-forward endmk reg-end t))
(cl-incf b))
(message "Markers: %c %c" begmk endmk)
(message "Counts %d %d" a b)
(goto-char reg-beg)) ))
?\(
(40) as the first arg tosearch-forward
, and that arg needs to be a string. – Drew Mar 20 '22 at 05:24(p (aref brcmarks 0)) (q (aref brcmarks 1)) (begmk (char-to-string p)) (endmk (char-to-string q))
– Dilna Mar 20 '22 at 11:30