unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Shortening words with multiple rules
@ 2022-08-16  0:49 uzibalqa via Users list for the GNU Emacs text editor
  2022-08-16  8:55 ` Arash Esbati
  0 siblings, 1 reply; 13+ messages in thread
From: uzibalqa via Users list for the GNU Emacs text editor @ 2022-08-16  0:49 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

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."

(interactive)

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

(cond

(equal translate-regexps "[RX]")
(insert (replace-regexp-in-string
(rx (seq word-start
(or (seq "co" (any "glmnr")) "coun" "cum")))
"k" word))
(t

(insert (replace-regexp-in-string "\\<\\(co[glmnr]\\|coun\\|cum\\)" "k" word))))

(goto-char point)))

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-08-17 21:29 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-16  0:49 Shortening words with multiple rules uzibalqa via Users list for the GNU Emacs text editor
2022-08-16  8:55 ` Arash Esbati
2022-08-16 10:08   ` uzibalqa
2022-08-16 10:45     ` Arash Esbati
2022-08-16 19:06       ` uzibalqa
2022-08-17  0:09         ` uzibalqa
2022-08-17  4:18           ` uzibalqa
2022-08-17  6:16             ` Arash Esbati
2022-08-17  9:16               ` uzibalqa
2022-08-17 10:07                 ` Arash Esbati
2022-08-17 11:00                   ` uzibalqa
2022-08-17 12:15                     ` Arash Esbati
2022-08-17 21:29                       ` uzibalqa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).