all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / 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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.