From debbugs-submit-bounces@debbugs.gnu.org Mon Sep 15 18:25:52 2025 Received: (at submit) by debbugs.gnu.org; 15 Sep 2025 22:25:52 +0000 Received: from localhost ([127.0.0.1]:44570 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uyHdt-0003MY-0j for submit@debbugs.gnu.org; Mon, 15 Sep 2025 18:25:52 -0400 Received: from lists.gnu.org ([2001:470:142::17]:56154) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uyFBe-0006mm-7d for submit@debbugs.gnu.org; Mon, 15 Sep 2025 15:48:34 -0400 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 1uyFBP-00063s-6E for bug-gnu-emacs@gnu.org; Mon, 15 Sep 2025 15:48:16 -0400 Received: from gw2.cammew.com ([64.182.209.149]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uyFB7-0004Bu-8j for bug-gnu-emacs@gnu.org; Mon, 15 Sep 2025 15:48:12 -0400 Received: from mail.hintonclan.org (unknown [66.182.66.34]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA512) (No client certificate requested) by gw2.cammew.com (Postfix) with ESMTPSA id 2BA7BEDCC4 for ; Mon, 15 Sep 2025 15:47:44 -0400 (EDT) Received: from secure.hintonclan.org (localhost.hintonclan.org [127.0.0.1]) by mail.hintonclan.org (OpenSMTPD) with ESMTPSA id faa6a759 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Mon, 15 Sep 2025 13:47:42 -0600 (MDT) MIME-Version: 1.0 Date: Mon, 15 Sep 2025 13:47:42 -0600 From: nathan To: bug-gnu-emacs@gnu.org Subject: ruby-mode regex syntax highlighting incorrect Message-ID: <51a38e01dd10d650372cd4ad56c52d23@hintonclan.org> X-Sender: nathan@hintonclan.org Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=64.182.209.149; envelope-from=nathan@hintonclan.org; helo=gw2.cammew.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Mon, 15 Sep 2025 18:25:47 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) When editing a ruby file I did an assignment like this: ```ruby some_var = 10 some_var /= 2 # some_var is now equal to 5 ``` This is a valid operator however the highlighting showed this as being part of a regex string which can be formed like this: ```ruby test_str = 'this is a test string' test_str.match? /test/ # Returns true ``` Here are the cases that I tested. The first col is what I did, the second is what I expected and the third is how it was highlighted: expression # expectation # reality 12/3 # division # division 12 /3 # division # regex 12/ 3 # division # division 12 / 3 # division # division I am not an expert in Ruby syntax but I would imagine that the change would be something like: require two slashes on the same line to highlight it as a regex expression In GNU Emacs 30.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.49, cairo version 1.18.4) of 2025-07-18, modified by Debian built on sbuild Windowing system distributor 'The X.Org Foundation', version 11.0.12401006 System Description: Debian GNU/Linux 13 (trixie) Configured using: 'configure --build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib --libexecdir=/usr/libexec --localstatedir=/var/lib --infodir=/usr/share/info --mandir=/usr/share/man --with-libsystemd --with-pop=yes --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/30.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/30.1/site-lisp:/usr/share/emacs/site-lisp --with-sound=alsa --without-gconf --with-mailutils --build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib --libexecdir=/usr/libexec --localstatedir=/var/lib --infodir=/usr/share/info --mandir=/usr/share/man --with-libsystemd --with-pop=yes --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/30.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/30.1/site-lisp:/usr/share/emacs/site-lisp --with-sound=alsa --without-gconf --with-mailutils --with-cairo --with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars 'CFLAGS=-g -O2 -Werror=implicit-function-declaration -ffile-prefix-map=/build/reproducible-path/emacs-30.1+1=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -Wall' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' LDFLAGS=-Wl,-z,relro' Configured features: ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB Important settings: value of $LANG: en_US.UTF-8 value of $XMODIFIERS: @im=ibus locale-coding-system: utf-8-unix Major mode: Ruby Minor modes in effect: inf-ruby-minor-mode: t global-auto-revert-mode: t display-time-mode: t vhdl-electric-mode: t tooltip-mode: t global-eldoc-mode: t show-paren-mode: t electric-indent-mode: t mouse-wheel-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t minibuffer-regexp-mode: t column-number-mode: t line-number-mode: t transient-mark-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message yank-media puny rfc822 mml mml-sec epa derived epg rfc6068 epg-config gnus-util mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils noutline outline jka-compr lisp-mnt finder-inf etags fileloop generator xref project dabbrev comp comp-cstr cl-extra help-mode warnings comp-run comp-common misearch multi-isearch inf-ruby thingatpt ruby-mode kmacro rect time-date vc-git diff-mode track-changes easy-mmode vc-dispatcher yaml-mode pcmpl-unix sh-script rx smie treesit executable files-x shell pcomplete cus-start autorevert filenotify time man dired dired-loaddefs vhdl-mode hippie-exp compile text-property-search comint ansi-osc ansi-color ring cus-edit pp cus-load wid-edit dockerfile-mode-autoloads inf-ruby-autoloads yaml-mode-autoloads package browse-url url url-proxy url-privacy url-expand url-methods url-history url-cookie generate-lisp-file url-domsuf url-util mailcap url-handlers url-parse auth-source cl-seq eieio eieio-core cl-macs icons password-cache json subr-x map byte-opt gv bytecomp byte-compile url-vars cl-loaddefs cl-lib rmc iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-dnd touch-screen tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic indonesian philippine cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese composite emoji-zwj charscript charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp files window text-properties overlay sha1 md5 base64 format env code-pages mule custom widget keymap hashtable-print-readable backquote threads dbusbind inotify lcms2 dynamic-setting system-font-setting font-render-setting cairo gtk x-toolkit xinput2 x multi-tty move-toolbar make-network-process native-compile emacs) Memory information: ((conses 16 284136 22299) (symbols 48 17187 0) (strings 32 60481 3751) (string-bytes 1 1717419) (vectors 16 28207) (vector-slots 8 360360 16523) (floats 8 89 968) (intervals 56 10023 0) (buffers 992 25)) From debbugs-submit-bounces@debbugs.gnu.org Mon Sep 15 19:21:38 2025 Received: (at 79454) by debbugs.gnu.org; 15 Sep 2025 23:21:38 +0000 Received: from localhost ([127.0.0.1]:44845 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uyIVu-0007RH-8E for submit@debbugs.gnu.org; Mon, 15 Sep 2025 19:21:38 -0400 Received: from fhigh-b6-smtp.messagingengine.com ([202.12.124.157]:59371) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uyIVk-0007Qp-6O for 79454@debbugs.gnu.org; Mon, 15 Sep 2025 19:21:35 -0400 Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id 2A10B7A0142; Mon, 15 Sep 2025 19:21:22 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Mon, 15 Sep 2025 19:21:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1757978482; x=1758064882; bh=t5UrIwrWqv0T82r9tCt0fzi8BPn0x3tVgjqOuJvV0Ps=; b= FiTxWy+TPwlG0tUwXPWSstUmZxMOieGLBeB95UDOquatzO2VMzeYqVxpQC9pOyWN NqGhGctLUl7CIBnHZTxsNvegLalpgHK2tqedP0oiZQbFIIHKAzjXM9oargPQA7x/ Z9RohjU7ESdw5yc4Je9e/YtJ2Y8KYxRecYm5T1k0c/XLG8upAESv+xRizR1NJsXO ZetcjOMq6eBV4Gdo3ffnoega+fPouDqm6kCjyCRVSoYtfSQUQre0kqBUz5UGyOxC PcCL7hUNtAvQEh1BOhvjIrtj/8SFcCGZi1GOm/OiisZB3GcsmG7YUDrPU78zjVSn /Y4XFdrAMG5ZSLosbVOhvg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1757978482; x=1758064882; bh=t 5UrIwrWqv0T82r9tCt0fzi8BPn0x3tVgjqOuJvV0Ps=; b=h/m4AKMBeCxWnNw55 Qe/ARz8akPX7A1tudU+PIaMm7v9i85wn27NeM4VorzPKWrOJOdXNpMRLwjrl42AA QYQG/Z81B4sevczOD6nsy0NmAAdXNhFLkWaXEWovC3xmxl9dxKsSILZqZ2u2UItN 9f7iCAHpUSH9NYLX7nkJ+CDDDA1oZt0Iha1obCv9FBMwcN4vf7P/hqvVviMrG+b9 H8Xn+JLHtkoaTFHsL4qAEdakKbzsxaCMxmM8spcS0wVKtU0hWfrTgh0S30zmTVUp K5+gRvyw6GJ8CM1qHFqpJ/Vu5thQ9VvR0ROk0cdGXNGpH9T1es+xziN/arV5re7k sNAxg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdefledttdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttd dvjeenucfhrhhomhepffhmihhtrhihucfiuhhtohhvuceoughmihhtrhihsehguhhtohhv rdguvghvqeenucggtffrrghtthgvrhhnpeegueegteffuddvjeevvdelleeitdeftdduhf effeffjedukeevjedvfeffgfevgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpegumhhithhrhiesghhuthhovhdruggvvhdpnhgspghrtghpth htohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepnhgrthhhrghnsehhihhn thhonhgtlhgrnhdrohhrghdprhgtphhtthhopeejleegheegseguvggssghughhsrdhgnh hurdhorhhg X-ME-Proxy: Feedback-ID: i07de48aa:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 15 Sep 2025 19:21:20 -0400 (EDT) Message-ID: Date: Tue, 16 Sep 2025 02:21:17 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug#79454: ruby-mode regex syntax highlighting incorrect To: nathan , 79454@debbugs.gnu.org References: <51a38e01dd10d650372cd4ad56c52d23@hintonclan.org> Content-Language: en-US From: Dmitry Gutov In-Reply-To: <51a38e01dd10d650372cd4ad56c52d23@hintonclan.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 79454 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) Hi! On 15/09/2025 22:47, nathan wrote: > > When editing a ruby file I did an assignment like this: > ```ruby > some_var = 10 > some_var /= 2 # some_var is now equal to 5 > ``` Thanks for the report. Somehow, this didn't come up yet. > This is a valid operator however the highlighting showed this as being > part of a regex string which can be formed like this: > ```ruby > test_str = 'this is a test string' > test_str.match? /test/ # Returns true > ``` > > Here are the cases that I tested. The first col is what I did, the > second is what I expected and the third is how it was highlighted: > > expression # expectation # reality > 12/3       # division    # division > 12 /3      # division    # regex > 12/ 3      # division    # division > 12 / 3     # division    # division Ruby is a little weird. For instance, your second example 12 /3 is parsed as expected, but a /3 will be parsed like /3 is the beginning of a regexp, apparently because 'a' could be a method that accepts a regexp. And the operator /= is an exception. We can make an effort to parse numbers literals followed by division specially as well, but TBF that comes up quite rarely in real-life code. > I am not an expert in Ruby syntax but I would imagine that the change > would be something like: require two slashes on the same line to > highlight it as a regex expression Ruby supports regexp spanning multiple lines, so that's not exactly an option. I've pushed a tweak that creates an exception for '/=', hope it resolves the important part of the issue (commit 76f50fa55ce19eb4): diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el index 459f8f338f7..b1104bf88a0 100644 --- a/lisp/progmodes/ruby-mode.el +++ b/lisp/progmodes/ruby-mode.el @@ -2204,6 +2204,7 @@ ruby-syntax-propertize (or (not ;; Looks like division. (or (eql (char-after) ?\s) + (eql (char-after) ?=) (not (eql (char-before (1- (point))) ?\s)))) (save-excursion (forward-char -1)