[Top][All Lists]

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

Simplifying function that shortens words

From: uzibalqa
Subject: Simplifying function that shortens words
Date: Mon, 15 Aug 2022 17:04:48 +0000

With the following function that shortens a word containing the character 
sequence "ple" medially, I would like
to inquire on ways I can simplify the conditional part between ;;--------

Basically I have three options, 1) using rx ; 2) using a character class ; 3) 
using a regular regex.

(defun shorten-word ()
"Shortens a word, replacing ple occurring medially within a word with the 
letter p."

(let* ( (bounds (bounds-of-thing-at-point 'word))
(word (buffer-substring (car bounds) (cdr bounds)))
(point (point))
(translate-regexps "rx")
(char-class t) )

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

(if (equal translate-regexps "rx")
(insert (replace-regexp-in-string (rx (seq (group (one-or-more alpha))"ple" 
(group (one-or-more alpha))))
(rx (seq (backref 1) "p" (backref 2))) word))

(if char-class
(insert (replace-regexp-in-string "\\([[:alpha:]]+\\)ple\\([[:alpha:]]+\\)" 
"\\1p\\2" word))
(insert (replace-regexp-in-string "\\([A-Za-z]+\\)ple\\([A-Za-z]+\\)" "\\1p\\2" 
word)) ))

(goto-char point)))

reply via email to

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