unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode
@ 2021-05-26 17:26 William Denton
  2021-05-26 22:10 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: William Denton @ 2021-05-26 17:26 UTC (permalink / raw)
  To: 48681

[-- Attachment #1: Type: text/plain, Size: 677 bytes --]

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.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-diff; name=prettify-ruby.patch, Size: 806 bytes --]

diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 0c54a1d27a..f6bb9c43db 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -2421,6 +2421,11 @@ ruby-flymake-auto
    report-fn
    args))
 
+(defconst ruby--prettify-symbols-alist
+  '(("and" . ?∧)
+    ("or" . ?∨))
+  "Value for `prettify-symbols-alist' in `ruby-mode'.")
+
 ;;;###autoload
 (define-derived-mode ruby-mode prog-mode "Ruby"
   "Major mode for editing Ruby code."
@@ -2437,6 +2442,7 @@ ruby-mode
 
   (setq-local font-lock-defaults '((ruby-font-lock-keywords) nil nil
                                    ((?_ . "w"))))
+  (setq-local prettify-symbols-alist ruby--prettify-symbols-alist)
 
   (setq-local syntax-propertize-function #'ruby-syntax-propertize))
 

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode
  2021-05-26 17:26 bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode William Denton
@ 2021-05-26 22:10 ` Lars Ingebrigtsen
  2021-05-27  1:54   ` William Denton
  0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-05-26 22:10 UTC (permalink / raw)
  To: William Denton; +Cc: 48681, Stefan Monnier

William Denton <wtd@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





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode
  2021-05-26 22:10 ` Lars Ingebrigtsen
@ 2021-05-27  1:54   ` William Denton
  2021-05-27  2:54     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 8+ messages in thread
From: William Denton @ 2021-05-27  1:54 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 48681, Stefan Monnier

[-- Attachment #1: Type: text/plain, Size: 1053 bytes --]

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.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-diff; name=prettify-ruby-2.patch, Size: 886 bytes --]

diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 0c54a1d27a..a48879bfe6 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -2421,6 +2421,15 @@ ruby-flymake-auto
    report-fn
    args))
 
+(defconst ruby--prettify-symbols-alist
+  '(("and" . ?∧)
+    ("&&" . ?∧)
+    ("or" . ?∨)
+    ("||" . ?∨)
+    ("<=" . ?≤)
+    (">=" . ?≥))
+  "Value for `prettify-symbols-alist' in `ruby-mode'.")
+
 ;;;###autoload
 (define-derived-mode ruby-mode prog-mode "Ruby"
   "Major mode for editing Ruby code."
@@ -2437,6 +2446,7 @@ ruby-mode
 
   (setq-local font-lock-defaults '((ruby-font-lock-keywords) nil nil
                                    ((?_ . "w"))))
+  (setq-local prettify-symbols-alist ruby--prettify-symbols-alist)
 
   (setq-local syntax-propertize-function #'ruby-syntax-propertize))
 

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode
  2021-05-27  1:54   ` William Denton
@ 2021-05-27  2:54     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-05-27  3:52       ` William Denton
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-05-27  2:54 UTC (permalink / raw)
  To: William Denton; +Cc: Lars Ingebrigtsen, 48681

> +(defconst ruby--prettify-symbols-alist
> +  '(("and" . ?∧)
> +    ("&&" . ?∧)

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

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

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


        Stefan






^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode
  2021-05-27  2:54     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2021-05-27  3:52       ` William Denton
  2021-05-27 18:02         ` Dmitry Gutov
  0 siblings, 1 reply; 8+ messages in thread
From: William Denton @ 2021-05-27  3:52 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Lars Ingebrigtsen, 48681

[-- Attachment #1: Type: text/plain, Size: 991 bytes --]

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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode
  2021-05-27  3:52       ` William Denton
@ 2021-05-27 18:02         ` Dmitry Gutov
  2021-05-29  6:10           ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Dmitry Gutov @ 2021-05-27 18:02 UTC (permalink / raw)
  To: William Denton, Stefan Monnier; +Cc: Lars Ingebrigtsen, 48681

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.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode
  2021-05-27 18:02         ` Dmitry Gutov
@ 2021-05-29  6:10           ` Lars Ingebrigtsen
  2021-05-29 11:07             ` Dmitry Gutov
  0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2021-05-29  6:10 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: William Denton, 48681, Stefan Monnier

Dmitry Gutov <dgutov@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





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode
  2021-05-29  6:10           ` Lars Ingebrigtsen
@ 2021-05-29 11:07             ` Dmitry Gutov
  0 siblings, 0 replies; 8+ messages in thread
From: Dmitry Gutov @ 2021-05-29 11:07 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: William Denton, 48681, Stefan Monnier

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!





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-05-29 11:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-26 17:26 bug#48681: Patch: Make prettify-symbols-mode work with ruby-mode William Denton
2021-05-26 22:10 ` Lars Ingebrigtsen
2021-05-27  1:54   ` William Denton
2021-05-27  2:54     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-05-27  3:52       ` William Denton
2021-05-27 18:02         ` Dmitry Gutov
2021-05-29  6:10           ` Lars Ingebrigtsen
2021-05-29 11:07             ` Dmitry Gutov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).