[Top][All Lists]

[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: Tue, 16 Aug 2022 10:55:10 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50

uzibalqa via Users list for the GNU Emacs text editor <> 

> 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.

Does this template help?

(defun shorten-word ()
  "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)
      (cond ((looking-at (regexp-opt '("cog" "col" "com" "con"
                                       "cor" "cum" "coun")
             (replace-match "k"))
            ;; Other rules
            (t nil))
      (goto-char p))
    (set-marker p nil)))

Best, Arash

reply via email to

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