GNU bug report logs - #48681
Patch: Make prettify-symbols-mode work with ruby-mode

Previous Next

Package: emacs;

Reported by: William Denton <wtd <at> pobox.com>

Date: Wed, 26 May 2021 18:25:01 UTC

Severity: normal

Tags: fixed, patch

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 48681 in the body.
You can then email your comments to 48681 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#48681; Package emacs. (Wed, 26 May 2021 18:25:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to William Denton <wtd <at> pobox.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 26 May 2021 18:25:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: William Denton <wtd <at> pobox.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Patch: Make prettify-symbols-mode work with ruby-mode
Date: Wed, 26 May 2021 13:26:03 -0400 (EDT)
[Message part 1 (text/plain, inline)]
Hello,

Attached is a small patch that will make prettify-symbols-mode work in 
ruby-mode.  It just adapts the code that's there for perl-mode, using some of 
the symbols from python-mode.

This is my first time submitting a patch, and I hope it and this commit message 
are close to what's needed:

# -----

Make prettify-symbols-mode work with ruby-mode

* lisp/progmodes/ruby.el
  (ruby--prettify-symbols-alist): New defvar with default symbols
  to prettify; prettify-symbols-alist is then set to this

# ------

My papers are signed and on file.

Thanks,

William Denton

--
William Denton
https://www.miskatonic.org/
Librarian, artist and licensed private investigator.
[prettify-ruby.patch (text/x-diff, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48681; Package emacs. (Wed, 26 May 2021 22:11:02 GMT) Full text and rfc822 format available.

Message #8 received at 48681 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: William Denton <wtd <at> pobox.com>
Cc: 48681 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode
Date: Thu, 27 May 2021 00:10:26 +0200
William Denton <wtd <at> pobox.com> writes:

> Hello,
>
> Attached is a small patch that will make prettify-symbols-mode work in
> ruby-mode.  It just adapts the code that's there for perl-mode, using
> some of the symbols from python-mode.
>
> This is my first time submitting a patch, and I hope it and this
> commit message are close to what's needed:

Thanks; the patch looks good to me.  I see that the equivalent thing in
Perl mode was added as:

+(defconst perl--prettify-symbols-alist
+  '(;;("andalso" . ?∧) ("orelse"  . ?∨) ("as" . ?≡)("not" . ?¬)
+    ;;("div" . ?÷) ("*"   . ?×) ("o"   . ?○)
+    ("->"  . ?→)
+    ("=>"  . ?⇒)
+    ;;("<-"  . ?←) ("<>"  . ?≠) (">="  . ?≥) ("<="  . ?≤) ("..." . ?⋯)
+    ("::" . ?∷)
+    ))

And then later the commented-out ?∧ (etc) stuff was removed, so I'm
wondering:

> +(defconst ruby--prettify-symbols-alist
> +  '(("and" . ?∧)
> +    ("or" . ?∨))
> +  "Value for `prettify-symbols-alist' in `ruby-mode'.")

Whether this is something that users of symbol prettification would
appreciate or not.  Since I use neither prettification or write Ruby, I
have no opinion here.  Perhaps Stefan has?  (Added to the CCs.)

(And why are these defconsts, anyway?)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) patch. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 26 May 2021 22:11:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48681; Package emacs. (Thu, 27 May 2021 01:56:01 GMT) Full text and rfc822 format available.

Message #13 received at 48681 <at> debbugs.gnu.org (full text, mbox):

From: William Denton <wtd <at> pobox.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 48681 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode
Date: Wed, 26 May 2021 21:54:55 -0400 (EDT)
[Message part 1 (text/plain, inline)]
On 27 May 2021, Lars Ingebrigtsen wrote:

> And then later the commented-out ?∧ (etc) stuff was removed, so I'm
> wondering:
>
>> +(defconst ruby--prettify-symbols-alist
>> +  '(("and" . ?∧)
>> +    ("or" . ?∨))
>> +  "Value for `prettify-symbols-alist' in `ruby-mode'.")
>
> Whether this is something that users of symbol prettification would
> appreciate or not.  Since I use neither prettification or write Ruby, I
> have no opinion here.  Perhaps Stefan has?  (Added to the CCs.)

This got me thinking, and I added four more prettifications (see attached patch) 
for &&, ||, <= and >=, which are all very basic.

I just hack on Ruby, but I use it a lot.  I think that anyone writing Ruby in 
Emacs who already has prettify-symbols-mode turned on (and is seeing it work 
with Python, R, Org, etc.) would, when they see this start working, say, "Hey, 
that's nice."

Thanks for looking at the patch.

Cheers,

Bill

--
William Denton
https://www.miskatonic.org/
Librarian, artist and licensed private investigator.
[prettify-ruby-2.patch (text/x-diff, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48681; Package emacs. (Thu, 27 May 2021 02:55:02 GMT) Full text and rfc822 format available.

Message #16 received at 48681 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: William Denton <wtd <at> pobox.com>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 48681 <at> debbugs.gnu.org
Subject: Re: bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode
Date: Wed, 26 May 2021 22:54:34 -0400
> +(defconst ruby--prettify-symbols-alist
> +  '(("and" . ?∧)
> +    ("&&" . ?∧)

Are `and` and `&&` absolutely 100% completely totally equivalent in Ruby?

> +    ("or" . ?∨)
> +    ("||" . ?∨)

Same question for `or` and `||`?


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48681; Package emacs. (Thu, 27 May 2021 03:53:02 GMT) Full text and rfc822 format available.

Message #19 received at 48681 <at> debbugs.gnu.org (full text, mbox):

From: William Denton <wtd <at> pobox.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 48681 <at> debbugs.gnu.org
Subject: Re: bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode
Date: Wed, 26 May 2021 23:52:32 -0400 (EDT)
[Message part 1 (text/plain, inline)]
On 26 May 2021, Stefan Monnier wrote:

>> +(defconst ruby--prettify-symbols-alist
>> +  '(("and" . ?∧)
>> +    ("&&" . ?∧)
>
> Are `and` and `&&` absolutely 100% completely totally equivalent in Ruby?
>
>> +    ("or" . ?∨)
>> +    ("||" . ?∨)
>
> Same question for `or` and `||`?

An excellent question, and I think I overstepped things.  The documentation¹ and 
answers on Stack Exchange² say "&&" and "||" are logical operators (so the 
logical symbols work) but "and" and "or" have lower precedence and are used 
differently.

It'd be best to just prettify "&&" and "||" with symbols, and anyone who wants 
"and" and "or" could add those by hand.  Shall I send a revised patch, or do you 
just want to delete those bits?

Thanks,

Bill

¹ https://ruby-doc.com/core/doc/syntax/precedence_rdoc.html
² E.g. https://stackoverflow.com/a/2083118/854346
--
William Denton
https://www.miskatonic.org/
Librarian, artist and licensed private investigator.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48681; Package emacs. (Thu, 27 May 2021 18:03:01 GMT) Full text and rfc822 format available.

Message #22 received at 48681 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: William Denton <wtd <at> pobox.com>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 48681 <at> debbugs.gnu.org
Subject: Re: bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode
Date: Thu, 27 May 2021 21:02:05 +0300
On 27.05.2021 06:52, William Denton wrote:
> An excellent question, and I think I overstepped things.  The 
> documentation¹ and answers on Stack Exchange² say "&&" and "||" are 
> logical operators (so the logical symbols work) but "and" and "or" have 
> lower precedence and are used differently.

Right. And apparently, it's exactly the same situation in Perl.

> It'd be best to just prettify "&&" and "||" with symbols, and anyone who 
> wants "and" and "or" could add those by hand.  Shall I send a revised 
> patch, or do you just want to delete those bits?

Looking at the various prettify-symbols definitions, there is no great 
consistency.

Even so, we can see that only python-mode uses the symbols ∧ and ∨.

As someone who graduated with an engineering degree a decade ago, the 
"intersection" and "union" symbols look unusual in a programming context 
to me. And a lot of software developers don't have a math background at all.

I'd recommend to just use the list from perl-mode:

  '(("->"  . ?→)
    ("=>"  . ?⇒)
    ("::" . ?∷))

and also add the ("lambda" . ?λ) mapping to it.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48681; Package emacs. (Sat, 29 May 2021 06:11:02 GMT) Full text and rfc822 format available.

Message #25 received at 48681 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: William Denton <wtd <at> pobox.com>, 48681 <at> debbugs.gnu.org,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode
Date: Sat, 29 May 2021 08:10:37 +0200
Dmitry Gutov <dgutov <at> yandex.ru> writes:

> I'd recommend to just use the list from perl-mode:
>
>   '(("->"  . ?→)
>     ("=>"  . ?⇒)
>     ("::" . ?∷))
>
> and also add the ("lambda" . ?λ) mapping to it.

I've now applied William's patch, tweaking for the comments from Stefan
and Dmitry, and ended up with:

(defconst ruby--prettify-symbols-alist
  '(("<=" . ?≤)
    (">=" . ?≥)
    ("->"  . ?→)
    ("=>"  . ?⇒)
    ("::" . ?∷)
    ("lambda" . ?λ))

Feel free to tweak further.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 29 May 2021 06:11:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 28.1, send any further explanations to 48681 <at> debbugs.gnu.org and William Denton <wtd <at> pobox.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 29 May 2021 06:11:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#48681; Package emacs. (Sat, 29 May 2021 11:08:01 GMT) Full text and rfc822 format available.

Message #32 received at 48681 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: William Denton <wtd <at> pobox.com>, 48681 <at> debbugs.gnu.org,
 Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode
Date: Sat, 29 May 2021 14:07:08 +0300
On 29.05.2021 09:10, Lars Ingebrigtsen wrote:
> I've now applied William's patch, tweaking for the comments from Stefan
> and Dmitry, and ended up with:
> 
> (defconst ruby--prettify-symbols-alist
>    '(("<=" . ?≤)
>      (">=" . ?≥)
>      ("->"  . ?→)
>      ("=>"  . ?⇒)
>      ("::" . ?∷)
>      ("lambda" . ?λ))
> 
> Feel free to tweak further.

Thanks!




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 26 Jun 2021 11:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 276 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.