unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: uzibalqa via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Shortening words in a selected region
Date: Sat, 13 Aug 2022 15:12:25 +0000	[thread overview]
Message-ID: <6ImZMUatP1-0QW1fUx1-6E_18djoPm36v2Hrs8a-WvxFnPdfKOGmXREgPm7ToVIGazDTJGJGoh2u4lc6g5aumI6uEXy0A39GQI0VvYax1JQ=@proton.me> (raw)

Have the following function to shorten specific words, inserting `k' for words with initial `cog', `col', `com', `con',

`cor', `coun', `cum'. The word "corrupt" then becomes "krupt". One simply puts the cursor point on a word and
execute the function using "M-x shorten-word".

I would like to have an equivalent function that works on words in a selected region this time round.

(defun shorten-word ()
"Shortens certain words by introducing the letter 'k'."

(interactive)
(let* ( (bounds (bounds-of-thing-at-point 'word))
(word (buffer-substring (car bounds) (cdr bounds)))
(point (point)) )

(goto-char (car bounds))
(delete-char (length word)) (insert (replace-regexp-in-string "\\<\\(co[glmnr]\\|coun\\|cum\\)" "k" word))

(goto-char point)))

                 reply	other threads:[~2022-08-13 15:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to='6ImZMUatP1-0QW1fUx1-6E_18djoPm36v2Hrs8a-WvxFnPdfKOGmXREgPm7ToVIGazDTJGJGoh2u4lc6g5aumI6uEXy0A39GQI0VvYax1JQ=@proton.me' \
    --to=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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).