From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#67390: 28; shorthands-font-lock-shorthands assumes shorthand uses same separator Date: Sat, 25 Nov 2023 14:42:48 -0800 Message-ID: <875y1po3nk.fsf@ushin.org> References: <87a5r5ph3p.fsf@bernoul.li> <87msv2vmzf.fsf@bernoul.li> <878r6mzezo.fsf@ushin.org> <87sf4tg6ts.fsf@bernoul.li> Reply-To: Joseph Turner Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25798"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 67390@debbugs.gnu.org, Adam Porter , =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= To: Jonas Bernoulli Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 25 23:44:18 2023 Return-path: Envelope-to: geb-bug-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 1r71Nn-0006Ut-UN for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 25 Nov 2023 23:44:16 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r71NX-000233-RL; Sat, 25 Nov 2023 17:43:59 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r71NV-00021a-8s for bug-gnu-emacs@gnu.org; Sat, 25 Nov 2023 17:43:57 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r71NV-0007fl-0U for bug-gnu-emacs@gnu.org; Sat, 25 Nov 2023 17:43:57 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r71Na-0000iP-0f for bug-gnu-emacs@gnu.org; Sat, 25 Nov 2023 17:44:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Joseph Turner Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 25 Nov 2023 22:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67390 X-GNU-PR-Package: emacs Original-Received: via spool by 67390-submit@debbugs.gnu.org id=B67390.17009522072698 (code B ref 67390); Sat, 25 Nov 2023 22:44:01 +0000 Original-Received: (at 67390) by debbugs.gnu.org; 25 Nov 2023 22:43:27 +0000 Original-Received: from localhost ([127.0.0.1]:40443 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r71N1-0000hS-8j for submit@debbugs.gnu.org; Sat, 25 Nov 2023 17:43:27 -0500 Original-Received: from out-179.mta0.migadu.com ([2001:41d0:1004:224b::b3]:37027) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r71My-0000hE-8H for 67390@debbugs.gnu.org; Sat, 25 Nov 2023 17:43:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ushin.org; s=key1; t=1700952195; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZVTUocfwnxBI2E4GenOqygA8Yl7Ms04uToyk/fkBujc=; b=RctsIcXhUrz+QzQSjb/3XTBo1nXNNtQRKACWPKkLyj/rf/tdq6xnFD55MlZb6lZ+jJGhjA y2/G9ku2mUG13r5EGjJuky8heq2ucQwS3nO8YSLInC7yeJL5ubiB0cESFXKhoPtnNKhZv9 EBnde/pHBr6zY/T9+oiKDW2yC/vEW2bTQDPJRTQDaois74yzozoXmwp132mSxSQbFkhQTm 9jiJ6CPFQ4E0nix5K7atEl2+VpcpbGxhn/zUhq/KZtBOByC0MJOkL/mqIZNstq7p3sunyh Pwu2UC6+Jdh5dQMn0aMWKHalxTLkzQ7Igen2E0OkreOwXYNC7Jc6G/SEMtU21A== X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: <87sf4tg6ts.fsf@bernoul.li> X-Migadu-Flow: FLOW_OUT X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:275024 Archived-At: --=-=-= Content-Type: text/plain Jonas Bernoulli writes: > Joseph Turner writes: > >> + (car (shorthands--find-if >> + (lambda (short) >> + (string-prefix-p short (match-string 1))) >> + read-symbol-shorthands #'car))))) > > Or simply: > (car (assoc (match-string 1) > read-symbol-shorthands > #'string-prefix-p)) Much nicer - see patch. Thanks, Jonas! --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Support-shorthand-prefixes-besides.patch >From 5033a0e14950ed1622db78df1828c40de4b5a23a Mon Sep 17 00:00:00 2001 From: Joseph Turner Date: Fri, 24 Nov 2023 19:17:13 -0800 Subject: [PATCH] Support shorthand prefixes besides "-" * lisp/emacs-lisp/shorthands.el (shorthands-font-lock-shorthands): Add font locking to the shorthand prefix by checking if any of the shorthand prefixes in read-symbol-shorthands are a prefix for the current symbol name (bug#67390). Co-authored-by: Jonas Bernoulli --- lisp/emacs-lisp/shorthands.el | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lisp/emacs-lisp/shorthands.el b/lisp/emacs-lisp/shorthands.el index 82200ab88e9..6ce9984a353 100644 --- a/lisp/emacs-lisp/shorthands.el +++ b/lisp/emacs-lisp/shorthands.el @@ -52,13 +52,6 @@ :version "28.1" :group 'font-lock-faces) -(defun shorthands--mismatch-from-end (str1 str2) - (cl-loop with l1 = (length str1) with l2 = (length str2) - for i from 1 - for i1 = (- l1 i) for i2 = (- l2 i) - while (and (>= i1 0) (>= i2 0) (eq (aref str1 i1) (aref str2 i2))) - finally (return (1- i)))) - (defun shorthands-font-lock-shorthands (limit) (when read-symbol-shorthands (while (re-search-forward @@ -69,10 +62,14 @@ font-lock-string-face))) (intern-soft (match-string 1)))) (sname (and probe (symbol-name probe))) - (mm (and sname (shorthands--mismatch-from-end - (match-string 1) sname)))) - (unless (or (null mm) (= mm (length sname))) - (add-face-text-property (match-beginning 1) (1+ (- (match-end 1) mm)) + (prefix (and sname + (not (string-equal (match-string 1) sname)) + (car (assoc (match-string 1) + read-symbol-shorthands + #'string-prefix-p))))) + (when prefix + (add-face-text-property (match-beginning 1) + (+ (match-beginning 1) (length prefix)) 'elisp-shorthand-font-lock-face)))))) (font-lock-add-keywords 'emacs-lisp-mode '((shorthands-font-lock-shorthands)) t) -- 2.41.0 --=-=-=--