[Top][All Lists]

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

Shortening words with multiple rules

From: uzibalqa
Subject: Shortening words with multiple rules
Date: Tue, 16 Aug 2022 00:49:11 +0000

The following function shortens words according to specific rules. The specific
rule for the function is to replace a word beginning with the character sequence
`cog', `col', `com', `con', `cor', `coun', or `cum', and replacing the match by
the letter `k'‚Äč.

How can I have a function that is able to perform a number of rules rather than
just a single one.

(defun shorten-word ()
"Shortens a word according to specific rules."


(let* ( (bounds (bounds-of-thing-at-point 'word))
(word (buffer-substring (car bounds) (cdr bounds)))
(point (point))
(impl "[RX]") )

(goto-char (car bounds)) (delete-char (length word))


(equal translate-regexps "[RX]")
(insert (replace-regexp-in-string
(rx (seq word-start
(or (seq "co" (any "glmnr")) "coun" "cum")))
"k" 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]