From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs Subject: bug#67390: 28; shorthands-font-lock-shorthands assumes shorthand uses same separator Date: Wed, 29 Nov 2023 13:56:28 +0000 Message-ID: References: <87a5r5ph3p.fsf@bernoul.li> <87msv2vmzf.fsf@bernoul.li> <878r6mzezo.fsf@ushin.org> <87sf4tg6ts.fsf@bernoul.li> <875y1po3nk.fsf@ushin.org> <871qccqmgi.fsf@ushin.org> <83bkbf9z1u.fsf@gnu.org> <87jzq0gb5x.fsf@ushin.org> 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="34463"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 67390@debbugs.gnu.org, Adam Porter , Eli Zaretskii , Jonas Bernoulli To: Joseph Turner Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 29 14:57:12 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 1r8L3w-0008jK-9W for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 29 Nov 2023 14:57:12 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r8L3g-0007jb-Jx; Wed, 29 Nov 2023 08:56:56 -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 1r8L3f-0007jJ-Hw for bug-gnu-emacs@gnu.org; Wed, 29 Nov 2023 08:56:55 -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 1r8L3f-0003EK-5V for bug-gnu-emacs@gnu.org; Wed, 29 Nov 2023 08:56:55 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r8L3m-0001hu-FA for bug-gnu-emacs@gnu.org; Wed, 29 Nov 2023 08:57:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 29 Nov 2023 13:57:02 +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.17012662176551 (code B ref 67390); Wed, 29 Nov 2023 13:57:02 +0000 Original-Received: (at 67390) by debbugs.gnu.org; 29 Nov 2023 13:56:57 +0000 Original-Received: from localhost ([127.0.0.1]:49160 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r8L3g-0001hZ-ME for submit@debbugs.gnu.org; Wed, 29 Nov 2023 08:56:57 -0500 Original-Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]:48577) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r8L3e-0001hJ-8E for 67390@debbugs.gnu.org; Wed, 29 Nov 2023 08:56:55 -0500 Original-Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-50bbef0e5d5so2300278e87.1 for <67390@debbugs.gnu.org>; Wed, 29 Nov 2023 05:56:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701266201; x=1701871001; darn=debbugs.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=LDaKNzgnx79HYT/ba6Jv/zFJ2VDZguVQV4914W8w0Yc=; b=Uwi0XifDbZkDyXaADsWtKsrGyriQkIfnvuS+tH2bOvdbonBQWQU2NEg+HkuHBp8SZQ 6OV/TAoi4C8uXBSe/XAv6UX54tXSZFKCEtU/bn3R2A2wYXgVEZV+zjcUyJH2AebbrVzb T9Wx8kx2nSrujYUldGEodk3QYu7maJukrjjqMZElzVHOmnmnGYoTQHaw7fiAWc4/QXCi KQJ4G64G/Iqcr31lVNmZaRbx9YyYGH+AbpDAG7lxnoC2o4XI4z4wupdzo7Ftuq0UxGbc FQ2XN+j6Q5ZI4BSBIvG4v0FD4MQG0dW3opavJqb5vPAArqW3toSxFS7tJ4lecAXJYfXm /u6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701266201; x=1701871001; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LDaKNzgnx79HYT/ba6Jv/zFJ2VDZguVQV4914W8w0Yc=; b=FElebSV8uDH3BCcz1XIHeBSTnlb0GMmz61VRQ1XbrHuDZEMJIxCsYoWjEi57sUouxC gNn2niZTf4R8K3pOWZ8aPS6dGCQwx2nvB6EZx2vuk/6xWivxInNmqTF7adZLvIVr60KT FCuxS4d+PGTOBcqqAu4QQ3NJbnK/haLjcTt1f92pshdV20K5A7GY5iFxTRvcTSJl82R2 1+CY3A0GWHUUfrSLbUQpkj5v0USKg+1NZvvP/D1pJAudIP9eqLhsWi7SG0SaooKFndrT NxnJXp10yy449usU4UszeqGy9mxCw2qqv/XN74j8D290tmkLjuKFOmof4ezoFvFVdft6 Ha/A== X-Gm-Message-State: AOJu0Yz/tf3vIG84yG/X1YNBPR6FH7904u8HrME1p79rZJlwEnXAl1/H UC26CJG6zEUSIU3YoH2mLhu2UnpkxUEEe09Y1kg= X-Google-Smtp-Source: AGHT+IFDvaZrYViYFceY8uFKd76zjhXYSgftJYaRoubUeoku7TOmez2HC/HopqIUU3bxJlJgOgOhi2lND1H4NehUv9A= X-Received: by 2002:a05:6512:e84:b0:50b:c975:8b30 with SMTP id bi4-20020a0565120e8400b0050bc9758b30mr182715lfb.66.1701266200452; Wed, 29 Nov 2023 05:56:40 -0800 (PST) In-Reply-To: <87jzq0gb5x.fsf@ushin.org> 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:275228 Archived-At: On Wed, Nov 29, 2023 at 9:29=E2=80=AFAM Joseph Turner wr= ote: > > Joseph can you try these variations? They're slightly more exact. Also = show at least one of the large lisp files or tell me how to generate > > one. If you still don't find any significant slowdown, I think we can m= erge your patch. > > I'm happy to try Eli's variation if you don't beat me to it ;) Great. No I don't think I will beat you to it :-), you have the machinery setup already. > However, if we rearrange the values like: > > ;; read-symbol-shorthands: ( > ;; ("he/" . "hyperdrive-entry-") > ;; ("he//" . "hyperdrive-entry--") > ;; ("h/" . "hyperdrive-") > ;; ("h//" . "hyperdrive--")) > > then shorthands doesn't add fontification for either "h//" or "he//". > (This surprised me - I was expecting to see just the "h/" and "he/" > highlit) > > However, I'm starting to wonder whether this is a case of user error. > Should we avoid overlapping shorthand prefixes? No, but you should make sure the longer prefixes appear before. It's not only a font-locking issue, if the shorter shorthand appears before it could read to an unintended symbol. If shorthands are (("h/" . "hello-") ("h//" . "hyperdrive--")) and you type "h//warp" , I'm fairly sure this will be read to "hello-/warp" , which is probably not what you intended The documentation doesn't mention this, but it should, so patches welcome for that. In theory, lread.c could do this sorting for you. I don't think this would affect performance, so patches welcome for that, too. Anyway, here's another patch that more or less bridges our two patches and seems to do the right thing every time, even making you aware of that ordering pitfall. It could be more performant (or less, or about the same), so if you can, please include it in your benchmarks. It does less work when presented with a "/"-ending shorthand for a "-"-separated symbol, so I'm starting to think that this "/" idea is a good convention for shorthands (useful for distinguishing them in github code, for example). I've tested it briefly with those 'he/', 'he//', etc cases. diff --git a/lisp/emacs-lisp/shorthands.el b/lisp/emacs-lisp/shorthands.el index b0665a55695..69e9e252aee 100644 --- a/lisp/emacs-lisp/shorthands.el +++ b/lisp/emacs-lisp/shorthands.el @@ -76,14 +76,19 @@ shorthands-font-lock-shorthands (sname (and probe (symbol-name probe))) (mismatch (and sname (shorthands--mismatch-from-end (match-string 1) sname))) - (guess (and mismatch (1+ mismatch)))) - (when guess - (when (and (< guess (1- (length (match-string 1)))) - ;; In bug#67390 we allow other separators - (eq (char-syntax (aref (match-string 1) guess)) ?_)) - (setq guess (1+ guess))) + probe2) + (when mismatch + (unless (eq (char-syntax (aref (match-string 1) mismatch)) ?_) + (or probe2 + (setq probe2 + (buffer-substring (match-beginning 1) + (+ (match-beginning 1) mismatch)))= ) + (setq mismatch (1- (length + (car (assoc probe2 + read-symbol-shorthands + (lambda (a b) (string-prefix-p b a)))))))) (add-face-text-property (match-beginning 1) - (+ (match-beginning 1) guess) + (+ (match-beginning 1) (1+ mismatch)) 'elisp-shorthand-font-lock-face)))))) (font-lock-add-keywords 'emacs-lisp-mode '((shorthands-font-lock-shorthands)) t)