[Top][All Lists]

[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 04:18:09 +0000

Arash, I have come up with a variation of what you wrote

(defun shorten-word-b ()
  "Shortens a word according to specific rules."


  (let* ((bounds (bounds-of-thing-at-point 'word))
         (s (car bounds))
         (case-fold-search nil)
         (p (point-marker)))

    (when s
      (goto-char s)

       ;; 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'.
       ((search-forward-regexp (concat
           (regexp-opt '("ley" "ily" "ly")) "\\>"))

        (replace-match "l"))

       (t nil))
      (goto-char p))
    (set-marker p nil)))

What is left is to do is the ability to insert the letter `p' for medial `ple' 
in a word.
Medially means that the character sequence appears inside the word with at 
least one character
on each side op the character sequence `ple`.  An example would be the word 
complementary, where
"ple" occurs from character 4 to character 7.

reply via email to

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