From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bozhidar Batsov Newsgroups: gmane.emacs.devel Subject: Re: Small improvements to ruby-mode Date: Sat, 13 Jul 2013 13:24:34 +0300 Message-ID: References: <2A6700DEDCA640EF92B326002717596D@gmail.com> <51D31E12.7060002@yandex.ru> <51D4476A.40107@yandex.ru> <51D6A02C.2020207@yandex.ru> <51D6D500.7080306@yandex.ru> <51DB6516.1090708@yandex.ru> <51DC43CE.3090206@yandex.ru> <51DDA366.9020700@yandex.ru> <51E06787.8020401@yandex.ru> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c2480a9f8d4204e16208f2 X-Trace: ger.gmane.org 1373711088 22533 80.91.229.3 (13 Jul 2013 10:24:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 13 Jul 2013 10:24:48 +0000 (UTC) To: Dmitry Gutov , emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jul 13 12:24:50 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Uxx0R-00063i-Ni for ged-emacs-devel@m.gmane.org; Sat, 13 Jul 2013 12:24:47 +0200 Original-Received: from localhost ([::1]:36985 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uxx0R-0006B8-8B for ged-emacs-devel@m.gmane.org; Sat, 13 Jul 2013 06:24:47 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57776) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uxx0K-0006As-Er for emacs-devel@gnu.org; Sat, 13 Jul 2013 06:24:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uxx0F-0005tI-Cu for emacs-devel@gnu.org; Sat, 13 Jul 2013 06:24:40 -0400 Original-Received: from mail-qa0-x232.google.com ([2607:f8b0:400d:c00::232]:58295) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uxx0F-0005t7-8g for emacs-devel@gnu.org; Sat, 13 Jul 2013 06:24:35 -0400 Original-Received: by mail-qa0-f50.google.com with SMTP id l18so784236qak.2 for ; Sat, 13 Jul 2013 03:24:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=xxRquMxOuP5DA4OjFHIMrI+jRwx2+veimsy+XYrPBms=; b=FtfuOPasHy5TTaekrM2qzIH5ap1cA23vQGlzNh7hvS29cDVr8Yd/vyZddSAB2NcAZC P5aKsJer8p7SG7ONbH8nvML8qH8hstPJm4wwr4U/Otwfi988YrWenFtdROBiKR0qASOG 6uDF/nL3hCuCP8XRRHmiI5xJMh7DAU40+JhlIIIzqGzfjjMViaZ+DlLkPuk7uFe4bdqR 3vpXDUUBziNpSG0boM410wc/isx1JlTUKX3jYxnd18qGWQpSBPACX0hZWxhsBfV41LLq 7E+KW2KSs6uDyaKkE3jAvg6xX1AVdA+ZQgz9aROjg5OUYSUccP4pwnmA/zLDDn4vdLlc IEkg== X-Received: by 10.224.3.137 with SMTP id 9mr35219499qan.77.1373711074560; Sat, 13 Jul 2013 03:24:34 -0700 (PDT) Original-Received: by 10.49.59.13 with HTTP; Sat, 13 Jul 2013 03:24:34 -0700 (PDT) In-Reply-To: X-Google-Sender-Auth: 2lGN7bhow4ezBULWH5kNeFy5OQ0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c00::232 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:161853 Archived-At: --001a11c2480a9f8d4204e16208f2 Content-Type: text/plain; charset=UTF-8 Accidentally sent my last reply only to Dmitry instead of the emacs-devel. Sorry about that. On 13 July 2013 13:23, Bozhidar Batsov wrote: > On 12 July 2013 23:31, Dmitry Gutov wrote: > >> On 11.07.2013 15:23, Bozhidar Batsov wrote: >> >>> Still, we should consider functions with names like Float. Currently >>> they are not highlighted correctly - Something(test) is highlighted as a >>> constant, when obviously it's not. >>> >> >> Fixed, among other things, see the patch at the bottom. We don't >> highlight method calls, so I just disabled highlighting in this case. > > > Great! Btw, shouldn't we highlight the conversion methods from Kernel > (Float, Integer, etc) as built-ins? > > >> >> >> > I guess classes, constants and >> >>> functions like this could be font-locked after the first character >>> that's not part of the identifier name appears, to avoid the changing of >>> the face after the initial character. >>> >> >> Function calls can be identified by having a paren after the name (no >> luck with parenless calls). >> >> But there's really nothing that would distinguish a Math::E reference >> from Foo::C. Or from GC, IO, DL, IRB, URI, XML, HTML, etc. >> > > Yep, I'm aware we can't distinguish all cases without the use of a proper > parser, but I guess we should handle accordingly at least the scenarios > which are deterministic. > > >> >> === modified file 'lisp/progmodes/ruby-mode.el' >> --- lisp/progmodes/ruby-mode.el 2013-07-09 01:17:48 +0000 >> +++ lisp/progmodes/ruby-mode.el 2013-07-12 20:07:57 +0000 >> @@ -1351,7 +1351,7 @@ >> (progn >> (eval-and-compile >> (defconst ruby-percent-literal-beg-re >> - "\\(%\\)[qQrswWx]?\\([[:punct:**]]\\)" >> + "\\(%\\)[qQrswWxIi]?\\([[:**punct:]]\\)" >> "Regexp to match the beginning of percent literal.") >> >> (defconst ruby-syntax-methods-before-**regexp >> @@ -1387,7 +1387,7 @@ >> (funcall >> (syntax-propertize-rules >> ;; $' $" $` .... are variables. >> - ;; ?' ?" ?` are ascii codes. >> + ;; ?' ?" ?` are character literals (one-char strings in >> 1.9+). >> ("\\([?$]\\)[#\"'`]" >> (1 (unless (save-excursion >> ;; Not within a string. >> @@ -1518,7 +1518,7 @@ >> (save-match-data >> (save-excursion >> (goto-char (nth 8 parse-state)) >> - (looking-at "%\\(?:[QWrx]\\|\\W\\)"))))))) >> + (looking-at "%\\(?:[QWrxI]\\|\\W\\)"))))))**) >> >> (defun ruby-syntax-propertize-**expansions (start end) >> (save-excursion >> @@ -1848,8 +1848,11 @@ >> '("\\(\\$\\|@\\|@@\\)\\(\\w\\|**_\\)+" >> 0 font-lock-variable-name-face) >> ;; constants >> - '("\\(?:\\_<\\|::\\)\\([A-Z]+\**\(\\w\\|_\\)*\\)" >> - 1 font-lock-type-face) >> + '("\\(?:\\_<\\|::\\)\\([A-Z]+\**\(\\w\\|_\\)*\\)\\(?:\\_>[^\(]** >> \\|::\\|\\'\\)" >> + 1 (progn >> + (when (eq ?: (char-before)) >> + (forward-char -2)) >> + font-lock-type-face)) >> '("\\(^\\s *\\|[\[\{\(,]\\s *\\|\\sw\\s +\\)\\(\\(\\sw\\|_\\)+\\):[^:] >> **" 2 font-lock-constant-face) >> ;; expression expansion >> '(ruby-match-expression-**expansion >> @@ -1857,6 +1860,9 @@ >> ;; negation char >> '("[^[:alnum:]_]\\(!\\)[^=]" >> 1 font-lock-negation-char-face) >> + ;; character literals >> + ;; FIXME: Support longer escape sequences. >> + '("\\?\\\\?\\S " 0 font-lock-string-face) >> ) >> "Additional expressions to highlight in Ruby mode.") >> >> > --001a11c2480a9f8d4204e16208f2 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Accidentally sent my last reply only to Dmitry instead of = the emacs-devel. Sorry about that.


=
On 13 July 2013 13:23, Bozhidar Batsov <bozhi= dar@batsov.com> wrote:
On 12 Jul= y 2013 23:31, Dmitry Gutov <dgutov@yandex.ru> wrote:
On 11.07.2013 15:23, Bozhidar Batsov wrote:
Still, we should consider functions with names like Float. Currently
they are not highlighted correctly - Something(test) is highlighted as a constant, when obviously it's not.

Fixed, among other things, see the patch at the bottom. We don't highli= ght method calls, so I just disabled highlighting in this case.

Great! Btw, shouldn't we highlight the conve= rsion methods from Kernel (Float, Integer, etc) as built-ins?
=C2=A0


> I guess classes, constants and
functions like this could be font-locked after the first character
that's not part of the identifier name appears, to avoid the changing o= f
the face after the initial character.

Function calls can be identified by having a paren after the name (no luck = with parenless calls).

But there's really nothing that would distinguish a Math::E reference f= rom Foo::C. Or from GC, IO, DL, IRB, URI, XML, HTML, etc.
<= div>
Yep, I'm aware we can't distinguish all ca= ses without the use of a proper parser, but I guess we should handle accord= ingly at least the scenarios which are deterministic.
=C2=A0

=3D=3D=3D modified file 'lisp/progmodes/ruby-mode.el'
--- lisp/progmodes/ruby-mode.el 2013-07-09 01:17:48 +0000
+++ lisp/progmodes/ruby-mode.el 2013-07-12 20:07:57 +0000
@@ -1351,7 +1351,7 @@
=C2=A0 =C2=A0 =C2=A0(progn
=C2=A0 =C2=A0 =C2=A0 =C2=A0(eval-and-compile
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(defconst ruby-percent-literal-beg-re
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"\\(%\\)[qQrswWx]?\\([[:punct:<= /u>]]\\)"
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"\\(%\\)[qQrswWxIi]?\\([[:p= unct:]]\\)"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"Regexp to match the beginnin= g of percent literal.")

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(defconst ruby-syntax-methods-before-<= /u>regexp
@@ -1387,7 +1387,7 @@
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(funcall
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (syntax-propertize-rules
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; $' $" $` .... a= re variables.
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; ?' ?" ?` are ascii c= odes.
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; ?' ?" ?` are charact= er literals (one-char strings in 1.9+).
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0("\\([?$]\\)[#\"&= #39;`]"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (1 (unless (save-excursion=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0;; Not within a string.
@@ -1518,7 +1518,7 @@
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(save-match-data
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(save-excursion
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(goto-char (n= th 8 parse-state))
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(looking-at "= %\\(?:[QWrx]\\|\\W\\)")))))))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(looking-at "= %\\(?:[QWrxI]\\|\\W\\)")))))))

=C2=A0 =C2=A0 =C2=A0 =C2=A0(defun ruby-syntax-propertize-expansions = (start end)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(save-excursion
@@ -1848,8 +1848,11 @@
=C2=A0 =C2=A0 '("\\(\\$\\|@\\|@@\\)\\(\\w\\|_\\)+"
=C2=A0 =C2=A0 =C2=A0 0 font-lock-variable-name-face)
=C2=A0 =C2=A0 ;; constants
- =C2=A0 '("\\(?:\\_<\\|::\\)\\([A-Z]+\\(\\w\\|_\\)*\\)&= quot;
- =C2=A0 =C2=A0 1 font-lock-type-face)
+ '("\\(?:\\_<\\|::\\)\\([A-Z]+\\(\\w\\|_\\)*\\)\\(?:\\_= >[^\(]\\|::\\|\\'\\)"
+ =C2=A0 =C2=A0 1 (progn
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 (when (eq ?: (char-before))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (forward-char -2))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 font-lock-type-face))
=C2=A0 =C2=A0 '("\\(^\\s *\\|[\[\{\(,]\\s *\\|\\sw\\s +\\)\\(\\(\\= sw\\|_\\)+\\):[^:]" 2 font-lock-constant-face)
=C2=A0 =C2=A0 ;; expression expansion
=C2=A0 =C2=A0 '(ruby-match-expression-expansion
@@ -1857,6 +1860,9 @@
=C2=A0 =C2=A0 ;; negation char
=C2=A0 =C2=A0 '("[^[:alnum:]_]\\(!\\)[^=3D]"
=C2=A0 =C2=A0 =C2=A0 1 font-lock-negation-char-face)
+ =C2=A0 ;; character literals
+ =C2=A0 ;; FIXME: Support longer escape sequences.
+ =C2=A0 '("\\?\\\\?\\S " 0 font-lock-string-face)
=C2=A0 =C2=A0 )
=C2=A0 =C2=A0"Additional expressions to highlight in Ruby mode.")=



--001a11c2480a9f8d4204e16208f2--