* search-forward-regexp for median character sequence
@ 2022-08-17 20:47 uzibalqa
0 siblings, 0 replies; only message in thread
From: uzibalqa @ 2022-08-17 20:47 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
The following function shortens words. It takes care of replacing matches
for prefixes (e.g. replace starting `coun' with `k') and suffixes (e.g. replace
ending `ily' with letter `l').
I want to handle the case where the character sequence `ple' occurs medially
within a word (i.e. the word contains at least one character to either side
of the search pattern `ple').
I want to be able to use `search-forward-regexp' to do this, as is common
for prefixes and suffixes.
(defun shorten-word ()
"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'.
((search-forward-regexp
(concat "\\<"
(regexp-opt '("cog" "col" "com" "con" "cor" "cum" "coun")))
(cdr bounds)
t)
(replace-match "k"))
;;-----------------------------------------------
;; Insert `l' for words with final
;; `ley', `ily', and `ly'.
((search-forward-regexp
(concat (regexp-opt '("ley" "ily" "ly")) "\\>")
(cdr bounds)
t)
(replace-match "l"))
;;-----------------------------------------------
;; Insert letter `p, for median `ple'
;;-----------------------------------------------
(t nil))
(goto-char p))
(set-marker e nil)
(set-marker p nil)))
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-08-17 20:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-17 20:47 search-forward-regexp for median character sequence uzibalqa
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.