help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Shortening words in a selected region


From: uzibalqa
Subject: Shortening words in a selected region
Date: Sat, 13 Aug 2022 15:12:25 +0000

Have the following function to shorten specific words, inserting `k' for words 
with initial `cog', `col', `com', `con',

`cor', `coun', `cum'. The word "corrupt" then becomes "krupt". One simply puts 
the cursor point on a word and
execute the function using "M-x shorten-word".

I would like to have an equivalent function that works on words in a selected 
region this time round.

(defun shorten-word ()
"Shortens certain words by introducing the letter 'k'."

(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)))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]