Arash
Arash

Reputation: 568

Process text in emacs

I need to define a function that reads all the content of a specific document in Emacs and processes the text in it. For example, I'm reading an XML file and I want to search for specific attributes and count the number of occurrences. Can anyone help?

Upvotes: 1

Views: 182

Answers (1)

Daniel Leschkowski
Daniel Leschkowski

Reputation: 937

M-x count-matches RET

You may use regex to match your attribute

I added this small animation out of screenshots to show you an example of usage. If you need a more complex one, feel free to ask.

Small example of usage

If you want to solve this with Emacs-Lisp, check out -> [question]: https://stackoverflow.com/questions/41522/tips-for-learning-elisp/1313997#1313997 espacially the point count-string-matches, or do it like this:

(defun count-words ()
(interactive)
(let ((words (count-matches "[-A-Za-z0-9][-A-Za-z0-9.]*"
(point-min) (point-max))))
(message (format "%d matches" words))))

Upvotes: 5

Related Questions