GNU bug report logs - #24181
25.1.50; ruby mode: wrong auto indent after "?" string literal

Previous Next

Package: emacs;

Reported by: Ryo Furue <ryofurue <at> gmail.com>

Date: Mon, 8 Aug 2016 03:52:02 UTC

Severity: normal

Tags: wontfix

Found in version 25.1.50

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 24181 in the body.
You can then email your comments to 24181 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#24181; Package emacs. (Mon, 08 Aug 2016 03:52:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ryo Furue <ryofurue <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 08 Aug 2016 03:52:02 GMT) Full text and rfc822 format available.

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

From: Ryo Furue <ryofurue <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.1.50; ruby mode: wrong auto indent after "?" string literal
Date: Mon, 8 Aug 2016 12:50:30 +0900
Hi emacs maintainers,

1. Open an empty Ruby source code, say "tmp.rb".
2. Type the following:

#!/usr/bin/ruby
base = ?a.ord - 1

On hitting the return key at the end of the second line, the cursor
moves below "a", not to the top of the third line. The indentation
state seems to be confused.  I did this test with "emacs -q" .

?a is a valid Ruby syntax for string literal.  After writing this, I learned
that "a".ord is equivalent (I think), so I already have a workaround.

Hope this helps,

Ryo



In GNU Emacs 25.1.50.1 (x86_64-apple-darwin15.6.0, NS appkit-1404.47
Version 10.11.6 (Build 15G31))
 of 2016-07-27 built on furufuru-mac.yes.jamstec.go.jp
Repository revision: 682fdae7efe5a36636539b953a657445f2f3382b
Windowing system distributor 'Apple', version 10.3.1404
Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
(New file)
C-h C-g is undefined
Making completion list... [2 times]

Configured using:
 'configure --disable-dependency-tracking --disable-silent-rules
 --enable-locallisppath=/usr/local/share/emacs/site-lisp
 --infodir=/usr/local/Cellar/emacs/HEAD-682fdae/share/info/emacs
 --prefix=/usr/local/Cellar/emacs/HEAD-682fdae --with-xml2
 --without-dbus --with-gnutls --with-rsvg --with-imagemagick --with-ns
 --disable-ns-self-contained'

Configured features:
JPEG RSVG IMAGEMAGICK NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS
NS

Important settings:
  value of $LC_COLLATE: C
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Ruby

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message subr-x puny seq byte-opt gv
bytecomp byte-compile cl-extra help-mode cconv cl-loaddefs pcase cl-lib
dired dired-loaddefs format-spec rfc822 mml mml-sec password-cache epa
derived epg epg-config gnus-util rmail rmail-loaddefs mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
ruby-mode smie easymenu time-date mule-util tooltip eldoc electric
uniquify ediff-hook vc-hooks lisp-float-type mwheel term/ns-win ns-win
ucs-normalize term/common-win tool-bar dnd fontset image regexp-opt
fringe tabulated-list newcomment elisp-mode lisp-mode prog-mode register
page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock
font-lock syntax facemenu font-core term/tty-colors frame cl-generic
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 charscript case-table epa-hook
jka-cmpr-hook help simple abbrev obarray minibuffer cl-preloaded nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote kqueue cocoa ns multi-tty
make-network-process emacs)

Memory information:
((conses 16 208190 9578)
 (symbols 48 20842 0)
 (miscs 40 74 216)
 (strings 32 19355 5290)
 (string-bytes 1 615360)
 (vectors 16 34870)
 (vector-slots 8 670676 5823)
 (floats 8 177 312)
 (intervals 56 241 2)
 (buffers 976 14))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24181; Package emacs. (Thu, 11 Aug 2016 03:11:01 GMT) Full text and rfc822 format available.

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

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Ryo Furue <ryofurue <at> gmail.com>, 24181 <at> debbugs.gnu.org
Subject: Re: bug#24181: 25.1.50; ruby mode: wrong auto indent after "?" string
 literal
Date: Thu, 11 Aug 2016 06:10:22 +0300
Hi!

On 08/08/2016 06:50 AM, Ryo Furue wrote:

> 1. Open an empty Ruby source code, say "tmp.rb".
> 2. Type the following:
>
> #!/usr/bin/ruby
> base = ?a.ord - 1
>
> On hitting the return key at the end of the second line, the cursor
> moves below "a", not to the top of the third line. The indentation
> state seems to be confused.  I did this test with "emacs -q" .

Thanks for the report. I'd like to fix it sometime, but it's not a big 
priority, considering this syntax is usually discouraged:

https://github.com/bbatsov/ruby-style-guide#no-character-literals

> ?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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24181; Package emacs. (Thu, 11 Aug 2016 06:43:02 GMT) Full text and rfc822 format available.

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

From: Ryo Furue <ryofurue <at> gmail.com>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: 24181 <at> debbugs.gnu.org
Subject: Re: bug#24181: 25.1.50;
 ruby mode: wrong auto indent after "?" string literal
Date: Thu, 11 Aug 2016 15:41:35 +0900
Hi,

> Thanks for the report. I'd like to fix it sometime, but it's not a big
> priority, considering this syntax is usually discouraged:
>
> https://github.com/bbatsov/ruby-style-guide#no-character-literals

Thank you for the link! It seems very comprehensive and must be useful
for many other issues, too.

I agree the bug I reported isn't a big issue.

>> ?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. . . .  That makes me wonder how Haskell handles
unicode.  In that language, "String" is an alias for "[Char]"  (list
of Char's). . . . I digressed.

Cheers,

Ryo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24181; Package emacs. (Sat, 02 Jan 2021 03:07:01 GMT) Full text and rfc822 format available.

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

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Ryo Furue <ryofurue <at> gmail.com>
Cc: 24181 <at> debbugs.gnu.org
Subject: Re: bug#24181: 25.1.50; ruby mode: wrong auto indent after "?" string
 literal
Date: Sat, 2 Jan 2021 05:06:48 +0200
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)))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24181; Package emacs. (Sun, 15 Aug 2021 12:28:01 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: 24181 <at> debbugs.gnu.org, Ryo Furue <ryofurue <at> gmail.com>
Subject: Re: bug#24181: 25.1.50; ruby mode: wrong auto indent after "?"
 string literal
Date: Sun, 15 Aug 2021 14:26:42 +0200
Dmitry Gutov <dgutov <at> yandex.ru> writes:

> 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.

So it sounds like the conclusion here is that we're not going to change
the behaviour here, and I'm closing this bug.

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




Added tag(s) wontfix. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sun, 15 Aug 2021 12:28:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 24181 <at> debbugs.gnu.org and Ryo Furue <ryofurue <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sun, 15 Aug 2021 12:28:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24181; Package emacs. (Sun, 15 Aug 2021 22:22:01 GMT) Full text and rfc822 format available.

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

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 24181 <at> debbugs.gnu.org, Ryo Furue <ryofurue <at> gmail.com>
Subject: Re: bug#24181: 25.1.50; ruby mode: wrong auto indent after "?" string
 literal
Date: Mon, 16 Aug 2021 01:21:07 +0300
On 15.08.2021 15:26, Lars Ingebrigtsen wrote:
> Dmitry Gutov<dgutov <at> yandex.ru>  writes:
> 
>> 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.
> So it sounds like the conclusion here is that we're not going to change
> the behaviour here, and I'm closing this bug.

For now, at least. Since there's not much apparent user demand for it.

Whether that's just because there are not too many Emacs users doing 
Ruby these days, or because the syntax really fell out of favor, I don't 
know.

Hope it's the latter.




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

This bug report was last modified 3 years and 280 days ago.

Previous Next


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