unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Ryo Furue <ryofurue@gmail.com>
Cc: 24181@debbugs.gnu.org
Subject: bug#24181: 25.1.50; ruby mode: wrong auto indent after "?" string literal
Date: Sat, 2 Jan 2021 05:06:48 +0200	[thread overview]
Message-ID: <c720bba5-78c7-16f9-51f7-7d3e8ecc8dff@yandex.ru> (raw)
In-Reply-To: <CAGKoo-xzECsVgZtj1-2oT40vWLo192Hi8MhY9xLef33_t_zA7w@mail.gmail.com>

Sorry for digging this up, just looking through old issues.

On 11.08.2016 09:41, Ryo Furue wrote:

>>> ?a is a valid Ruby syntax for string literal.  After writing this, I
>>> learned
>>> that "a".ord is equivalent (I think)
>>
>> Yes, in Ruby 1.9 and newer, it's a full equivalent.
> 
> After my last message, I learned that Ruby has abandoned the idea of
> "character type" and instead of elevating ?a to a proper character
> literal, it has made it equivalent to a single-character string "a".
> So, a String is no longer a sequence of individual characters (because
> "character" has no representation in the language).  "a".ord returns
> the character code of this single-character string but "abc".ord
> ignores the "bc" part.  I don't think that's a clean design, but
> perhaps it's the simplest, practical one, in the face of various
> character encodings. . . .

This syntax there is purely for compatibility, I believe.

>  That makes me wonder how Haskell handles
> unicode.  In that language, "String" is an alias for "[Char]"  (list
> of Char's). . . . I digressed.

Types in a statically typed language are a bit of a different beast. 
E.g., you can eliminate a lot of associated overhead during compilation. 
Not so with a dynamically typed langues.

For posterity, a fix for the reported problem should look like the patch 
at the end of this message. I'm not going to commit it, though (or, at 
least, not in its current form) because Ruby makes it non-trivial to 
distinguish between these literals and the ternary operator:

 > abc ?( 1+ 2) : 4
=> 3

 > def dee(arg);
 > dee ?( 1+ 2) : 4
SyntaxError ((irb):27: syntax error, unexpected tINTEGER, expecting end)
dee ?( 1+ 2) : 4

Hopefully, the syntax will just be removed in some near future version 
of Ruby and save us the trouble. But here's the patch. To go in, it 
would have to be accompanied by some extra code looking around to 
determine the context.

diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 3effb6ed66..bd74e71f6a 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -1854,9 +1854,9 @@ ruby-syntax-propertize
       (syntax-propertize-rules
        ;; $' $" $` .... are variables.
        ;; ?' ?" ?` are character literals (one-char strings in 1.9+).
-      ("\\([?$]\\)[#\"'`:?]"
+      ("\\([?$]\\)[#\"'`:?[:alnum:]]"
         (1 (if (save-excursion
-                (nth 3 (syntax-ppss (match-beginning 0))))
+                (nth 8 (syntax-ppss (match-beginning 0))))
                ;; Within a string, skip.
                (ignore
                 (goto-char (match-end 1)))





  reply	other threads:[~2021-01-02  3:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-08  3:50 bug#24181: 25.1.50; ruby mode: wrong auto indent after "?" string literal Ryo Furue
2016-08-11  3:10 ` Dmitry Gutov
2016-08-11  6:41   ` Ryo Furue
2021-01-02  3:06     ` Dmitry Gutov [this message]
2021-08-15 12:26       ` Lars Ingebrigtsen
2021-08-15 22:21         ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c720bba5-78c7-16f9-51f7-7d3e8ecc8dff@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=24181@debbugs.gnu.org \
    --cc=ryofurue@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).