all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Arash Esbati <arash@gnu.org>
To: uzibalqa <uzibalqa@proton.me>
Cc: uzibalqa via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Re: Shortening words with multiple rules
Date: Wed, 17 Aug 2022 12:07:58 +0200	[thread overview]
Message-ID: <86wnb75gjl.fsf@gnu.org> (raw)
In-Reply-To: <KATn30BvzORW2K0VcapDxcXMS0C_LJr4Vn_ch1c1QdwxgQfIkc_elAZcrumu5ryaDJamcnuFAZQ_dkQiTfg35oIcKRrMFbMjVzS_5MZ92eg=@proton.me> (uzibalqa@proton.me's message of "Wed, 17 Aug 2022 09:16:59 +0000")

uzibalqa <uzibalqa@proton.me> writes:

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

For me, it turns "please" into "lase".  Maybe I didn't understand this
correctly, but do you want to apply all the rules to a word?  In that
case, you have adjust the code to do so 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)
      
      ;;-----------------------------------------------
      ;; Insert `k' for words with initial
      ;; `cog', `col', `com', `con', `cor', `coun', `cum'.
      (when (looking-at
             (concat  "\\<"
                      (regexp-opt '("cog" "col" "com" "con" "cor" "cum" 
                                    "coun"))))

        (replace-match "k")
        (goto-char s))
      

      ;;-----------------------------------------------
      ;; Insert `l' for words with final
      ;; `ley', `ily', and `ly'.
      (when (save-excursion
              (re-search-forward (concat
                                  (regexp-opt '("ley" "ily" "ly")) "\\>")
                                 e t))
        (replace-match "l")
        (goto-char s))

      ;; Make sure we don't match anything at the beginning of the
      ;; string by going one char forward:
      (when (save-excursion
              (forward-char)
              (re-search-forward "ple" e t))
        (replace-match "l")
        (goto-char s))
      
      (goto-char p))
    (set-marker e nil)
    (set-marker p nil)))

This turns "completely" to "kltel".  If you want only one rule to apply,
adjust the last version with `cond' to your needs.

Best, Arash



  reply	other threads:[~2022-08-17 10:07 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-16  0:49 Shortening words with multiple rules uzibalqa via Users list for the GNU Emacs text editor
2022-08-16  8:55 ` Arash Esbati
2022-08-16 10:08   ` uzibalqa
2022-08-16 10:45     ` Arash Esbati
2022-08-16 19:06       ` uzibalqa
2022-08-17  0:09         ` uzibalqa
2022-08-17  4:18           ` uzibalqa
2022-08-17  6:16             ` Arash Esbati
2022-08-17  9:16               ` uzibalqa
2022-08-17 10:07                 ` Arash Esbati [this message]
2022-08-17 11:00                   ` uzibalqa
2022-08-17 12:15                     ` Arash Esbati
2022-08-17 21:29                       ` uzibalqa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86wnb75gjl.fsf@gnu.org \
    --to=arash@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    --cc=uzibalqa@proton.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.