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: Arash Esbati
Subject: Re: Shortening words with multiple rules
Date: Wed, 17 Aug 2022 08:16:52 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50

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



reply via email to

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