From: uzibalqa via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Shortening words with multiple rules
Date: Tue, 16 Aug 2022 00:49:11 +0000 [thread overview]
Message-ID: <OODbwOYSsBa02Gk4_qB-4tfNSBEV6Z69MK3nvGw-11VlD6aVF66VVqZQnbAk5V9M_XcAAP4CqlTctEjF3T3kOw1BD6GdlMDI0ugK61IZLJ4=@proton.me> (raw)
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)))
next reply other threads:[~2022-08-16 0:49 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-16 0:49 uzibalqa via Users list for the GNU Emacs text editor [this message]
2022-08-16 8:55 ` Shortening words with multiple rules 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='OODbwOYSsBa02Gk4_qB-4tfNSBEV6Z69MK3nvGw-11VlD6aVF66VVqZQnbAk5V9M_XcAAP4CqlTctEjF3T3kOw1BD6GdlMDI0ugK61IZLJ4=@proton.me' \
--to=help-gnu-emacs@gnu.org \
--cc=uzibalqa@proton.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).