I want to modify words according no certain rules.
Here is a small example with three rules
a) Insert k
for words with initial cog
, col
, com
, con
, cor
, coun
, cum
.
(insert (replace-regexp-in-string "\\<\\(co[glmnr]\\|coun\\|cum\\)" "k" word))
b) Insert l
for words with final ly
, ily
, and ley
.
(insert (replace-regexp-in-string "\\(ly\\|ily\\|ley\\)\\>" "l" word))
c) Omit some
for words starting with some
.
(insert (replace-regexp-in-string "\\<some" "" word))
The problem is how to scan the word, doing the necessary replacements on the original word. What would be a good scheme to use?
Currently I have the following function to enforce a single rule
(defun shorten-word ()
"Insert shortened words."
(interactive)
(let* ((bounds (bounds-of-thing-at-point 'word))
(word (buffer-substring (car bounds) (cdr bounds)))
(point (point)))
(goto-char (car bounds))
(delete-char (length word))
(insert (replace-regexp-in-string "\\<\\(co[glmnr]\\|coun\\|cum\\)" "k" word))
(goto-char point)))