help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Shortening words with multiple rules


From: uzibalqa
Subject: Re: Shortening words with multiple rules
Date: Wed, 17 Aug 2022 09:16:59 +0000





Sent with Proton Mail secure email.

------- Original Message -------
On Wednesday, August 17th, 2022 at 6:16 AM, Arash Esbati <arash@gnu.org> wrote:


> uzibalqa uzibalqa@proton.me writes:
>
> > What is left is to do is the ability to insert the letter `p' for medial` 
> > ple' in a word.
>
>
> Maybe something like this:
>
> (defun shorten-word-b ()
> "Shortens a word according to specific rules."
> (interactive)
> (let* ((bounds (bounds-of-thing-at-point 'word))
> (s (car bounds))
> (case-fold-search nil)
> (e (make-marker))
> (p (point-marker)))
> (when s
> (set-marker e (cdr bounds))
> (goto-char s)
> (cond
> ;;-----------------------------------------------
> ;; Insert `k' for words with initial ;;` cog', `col',` com', `con',` cor', 
> `coun',` cum'.
> ((looking-at (concat "\\<"
> (regexp-opt '("cog" "col" "com" "con" "cor" "cum" "coun"))))
>
> (replace-match "k"))
>
> ;;-----------------------------------------------
> ;; Insert `l' for words with final ;;` ley', `ily', and` ly'.
> ((save-excursion
> (re-search-forward (concat
> (regexp-opt '("ley" "ily" "ly")) "\\>")
>
> e t))
> (replace-match "l"))
>
> ((save-excursion
> (re-search-forward "ple" e t))
> (replace-match "l"))
>
> (t nil))
> (goto-char p))
> (set-marker e nil)
> (set-marker p nil)))
>
> Best, Arash

Trying the code upon the word "please" results in "pase" because you have
not checked for mid-word in the final search.




reply via email to

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