After far too many years of counting the number of characters in the region by doing M-: (- (point) (mark))
, I just discovered M-= (count-words-region
). Much better! But now I'm looking for a way to obtain the number of bytes that the characters in the region occupy in the buffer's coding system--typically, or always really, UTF-8. Is there an easy way to do this?
For context, I've been doing some code golfing on codegolf.stackexchange.com in a language that supports various Unicode operators, and I need to know how many bytes my submission occupies. So far I've been saving the region to a file, doing ls -l
on it, then deleting it. I could easily whip up a function to do this automatically, but it seems rather inelegant.
hexl
mode, you could then use the regular Emacs commands to count bytes.