From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: uzibalqa Newsgroups: gmane.emacs.help Subject: Re: Shortening words with multiple rules Date: Tue, 16 Aug 2022 19:06:12 +0000 Message-ID: References: <86tu6c4lg1.fsf@gnu.org> <86zgg4mpqf.fsf@gnu.org> Reply-To: uzibalqa Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8978"; mail-complaints-to="usenet@ciao.gmane.io" Cc: uzibalqa via Users list for the GNU Emacs text editor To: Arash Esbati Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 16 21:07:19 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oO1uH-00024D-Jb for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 16 Aug 2022 21:07:17 +0200 Original-Received: from localhost ([::1]:41382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oO1uG-0008HI-40 for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 16 Aug 2022 15:07:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oO1tc-0008Gv-1c for help-gnu-emacs@gnu.org; Tue, 16 Aug 2022 15:06:36 -0400 Original-Received: from mail-40141.protonmail.ch ([185.70.40.141]:14103) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oO1tW-000864-Fk; Tue, 16 Aug 2022 15:06:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1660676776; x=1660935976; bh=6fI6M4/wQgWI2bDfU+2J0iz2TD2HftMxycqONaf3tEc=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:Feedback-ID:From:To:Cc:Date:Subject:Reply-To: Feedback-ID:Message-ID; b=AqtWBpe+ghOIJ96el23o/hogHkisx3Idkn8Z1llLcsJcdQlputoMG5g0o3a3Wn/Bs VwMR0pLaKDLOUel0DOckRLra6CRXrqbh9b+D/ZblFT9iYHL6+wJlqdlFZ0K0Yqg0L1 /8A6HMoIgJBsRKt1VQxjtEr7eUpHD6xQEl/xM6hoQYmxASpSsEDoH1Vy8rhqhadsrF MaNHhR3gHGuyqxIa/y2xPiUU/cEqNC33FzTzPRg0zVXpIzpvlB7mf3nHy1vYLou7J0 6Fctb1EAaO5oYnG21ebYnfUk0s4heTP90b5La7MD9WON8VLt2zUEfRbzEoGmGn0nxe MFklZz/Dqh9rg== In-Reply-To: <86zgg4mpqf.fsf@gnu.org> Feedback-ID: 52887082:user:proton Received-SPF: pass client-ip=185.70.40.141; envelope-from=uzibalqa@proton.me; helo=mail-40141.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:138893 Archived-At: ------- Original Message ------- On Tuesday, August 16th, 2022 at 10:45 AM, Arash Esbati wro= te: > uzibalqa uzibalqa@proton.me writes: > > > It does help a lot. How would a match at the end of word (matching > > "ley" "ily" "ly") look like, with your scheme? > > > Maybe something like this: > > (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) > (p (point-marker))) > (when s > (goto-char s) > (cond ((looking-at (regexp-opt '("cog" "col" "com" "con" > "cor" "cum" "coun") > "\\<\\(")) > (replace-match "k")) > ((looking-at (concat "[[:alpha:]]*?" > "\\(" > (regexp-opt '("ley" "ily" "ly")) > "\\)\\>")) > > (replace-match "X" nil nil nil 1)) > (t nil)) > (goto-char p)) > (set-marker p nil))) > > Best, Arash Works very well Arash. Another task would be to match character sequences in the middle of a word. I have been using the following regex to match "ple" inside a word and repl= acing it with the letter "p", allowing punctuation. (replace-regexp-in-string "\[[:alpha:]]+[-]?\\)ple\\([[[:alpha:]]+[[:punct:]]?\\)" "\\1p\\2" word) How would this translate to your function?