[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: count matches in string, not region?
From: |
Emanuel Berg |
Subject: |
Re: count matches in string, not region? |
Date: |
Wed, 26 Feb 2020 07:24:14 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
> Anyway as you see the 4th line doesn't look
> good, instead of moving the point one would
> like to invoke the/a count function with the
> already-fetched isbn-as argument.
>
> So is there a count-matches-in-string or
> something to that extent anywhere, that you
> are aware of?
Problem solved with `replace-regexp-in-string'.
Can still be useful to count matches in
a string, I guess...
Yank it in a temporary buffer and then use
region there is perhaps a poor man's solution...
(defun check-isbn-at-point ()
"Compute and echo the check digit from the ISBN at point."
(interactive)
(let*((isbn-string (thing-at-point 'symbol t))
(digits-only (replace-regexp-in-string "[^0-9]" "" isbn-string))
(num-digits (length digits-only))
(check-digit (if (> num-digits 10)
(checksum-isbn-13 digits-only)
(checksum-isbn-10 digits-only) )))
(message "check digit: %s" check-digit)
))
(defalias 'ciap #'check-isbn-at-point)
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal