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: Wed, 17 Aug 2022 11:00:50 +0000 Message-ID: References: <86tu6c4lg1.fsf@gnu.org> <86zgg4mpqf.fsf@gnu.org> <0ted8gWpziSeCqNIXIk-7J8IFrB2n29gZ5zJoBSzzCaLgig-oKvge9-s7T5Ss8Gbv2BxzrcSZjAUQg4pMD9HlPna-ETm22UNu6PVqZYLa18=@proton.me> <86wnb7xuln.fsf@gnu.org> <86wnb75gjl.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="12255"; 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 Wed Aug 17 13:06:36 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 1oOGse-0002z0-GY for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 17 Aug 2022 13:06:36 +0200 Original-Received: from localhost ([::1]:42584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oOGsb-0004pc-V8 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 17 Aug 2022 07:06:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57008) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOGnV-00031m-DB for help-gnu-emacs@gnu.org; Wed, 17 Aug 2022 07:01:24 -0400 Original-Received: from mail-4324.protonmail.ch ([185.70.43.24]:52659) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOGnS-0005BG-JI for help-gnu-emacs@gnu.org; Wed, 17 Aug 2022 07:01:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1660734064; x=1660993264; bh=jX4gNTIMD+PvV58z/Tm4Ibuo69KkF6gYn+3Fth2jbUE=; 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=idfQlm9YJKoJMF4TynzWJicMIBaOHijXJFbtOzSDs5vdky7QoSgJK8s8vnpHgZRaD cf4hzQ+FoLJOF/A3t8QM+B1QAP9jF6JSRg7jcI76+Py7w22rhjk5pxP6Av0aEp0moZ lwzugikzxfaRyK052Y6A9HviZiOzUSXYE9MZ88CpHBg1NntxBn1ZD/Grxpe69B1yHm qV/wKdWUCg7ohKY6FIlNtpsHCMX2/1G7SVlKJwBZQXKp8zPp1IkGvdbG+aAqrCFe6T cAGTXKKFzoYtDczES+dN76yKYbG3DevmYxtnpKYGifoyFyKZPMqbIBplCfUJuX2he1 hX+xVmJo5G//w== In-Reply-To: <86wnb75gjl.fsf@gnu.org> Feedback-ID: 52887082:user:proton Received-SPF: pass client-ip=185.70.43.24; envelope-from=uzibalqa@proton.me; helo=mail-4324.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=unavailable 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:138901 Archived-At: ------- Original Message ------- On Wednesday, August 17th, 2022 at 10:07 AM, Arash Esbati w= rote: > 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 Works by going one char forward. Would you have a solution that uses `sear= ch-forward-regexp' ? I think one can have all three possibilities function with `search-forward-= regexp'.