GNU bug report logs - #16996
24.3.50; [ruby-mode] Incorrect indentation for implicit hash arguments

Previous Next

Package: emacs;

Reported by: Bozhidar Batsov <bozhidar <at> batsov.com>

Date: Wed, 12 Mar 2014 10:55:02 UTC

Severity: minor

Found in version 24.3.50

To reply to this bug, email your comments to 16996 AT debbugs.gnu.org.

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#16996; Package emacs. (Wed, 12 Mar 2014 10:55:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Bozhidar Batsov <bozhidar <at> batsov.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 12 Mar 2014 10:55:02 GMT) Full text and rfc822 format available.

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

From: Bozhidar Batsov <bozhidar <at> batsov.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3.50; [ruby-mode] Incorrect indentation for implicit hash arguments
Date: Wed, 12 Mar 2014 12:53:57 +0200
[Message part 1 (text/plain, inline)]
The following code is indented properly:

top(x, { a: 1,
         b: 2 })

Removing the hash literal curly braces, however, breaks the indentation:

top(1, a: 1,
    b: 2)

Ideally the code would be indented like this for consistency's sake:

top(1, a: 1,
       b: 2)

I'm not sure, however, that we can do this for the Ruby 1.9 syntax,
because a and b might very well be keyword args. On the other hand
there's no ambiguity when using =>:

top(1, :a => 1,
    :b => 2)

top(1, :a => 1,
       :b => 2)



In GNU Emacs 24.3.50.1 (x86_64-apple-darwin13.0.0, NS apple-appkit-1265.00)
 of 2014-03-04 on bozhidar-home.local
Windowing system distributor `Apple', version 10.3.1265
Configured using:
 `configure --prefix=/usr/local/Cellar/emacs/HEAD --without-dbus
 --enable-locallisppath=/usr/local/share/emacs/site-lisp
 --infodir=/usr/local/Cellar/emacs/HEAD/share/info/emacs
 --without-gnutls --with-ns --disable-ns-self-contained'

Important settings:
  locale-coding-system: utf-8-unix

Major mode: Ruby

Minor modes in effect:
  subword-mode: t
  ruby-tools-mode: t
  inf-ruby-minor-mode: t
  diff-auto-refine-mode: t
  guru-mode: t
  erc-truncate-mode: t
  erc-spelling-mode: t
  erc-list-mode: t
  erc-menu-mode: t
  erc-autojoin-mode: t
  erc-ring-mode: t
  erc-networks-mode: t
  erc-pcomplete-mode: t
  erc-track-mode: t
  erc-match-mode: t
  erc-button-mode: t
  erc-fill-mode: t
  erc-stamp-mode: t
  erc-netsplit-mode: t
  erc-irccontrols-mode: t
  erc-noncommands-mode: t
  erc-move-to-prompt-mode: t
  erc-readonly-mode: t
  global-flycheck-mode: t
  flycheck-mode: t
  which-function-mode: t
  flx-ido-mode: t
  ido-ubiquitous-mode: t
  winner-mode: t
  global-undo-tree-mode: t
  undo-tree-mode: t
  whitespace-mode: t
  global-anzu-mode: t
  anzu-mode: t
  projectile-global-mode: t
  projectile-mode: t
  flyspell-mode: t
  shell-dirtrack-mode: t
  volatile-highlights-mode: t
  global-hl-line-mode: t
  recentf-mode: t
  savehist-mode: t
  show-smartparens-global-mode: t
  show-smartparens-mode: t
  smartparens-mode: t
  global-auto-revert-mode: t
  delete-selection-mode: t
  prelude-global-mode: t
  prelude-mode: t
  tooltip-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  size-indication-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
C-f C-f C-f C-f C-f C-f C-f C-k S t r i n g s-/ s-/
s-/ <backspace> C s-/ <return> <return> t o s <backspace>
_ s SPC w i t h SPC a r g u m e n t s SPC s h o u l
d SPC n o t SPC t r i g g e r SPC a n SPC o f e n <backspace>
<backspace> f e n s e . SPC <backspace> C-a C-f C-f
C-f C-f C-f C-e C-c C-c P P l l q <help-echo> <help-echo>
<help-echo> <help-echo> <down-mouse-1> <mouse-1> C-h
C-a q s-r t e s t <return> C-n C-n C-n C-n C-a C-k
C-k C-k C-k C-k C-k C-k <return> <return> t o p ( ,
<backspace> 1 , SPC 2 , SPC 3 , SPC : <backspace> :
a <backspace> <backspace> b <backspace> : <backspace>
a : SPC 1 , C-j <tab> : <backspace> b : SPC 2 <tab>
C-e C-p C-p C-n C-e C-b C-b C-b C-b C-d SPC = > C-n
C-b C-b C-b <backspace> SPC = > C-a <tab> C-p C-p C-n
C-n <tab> C-p C-p C-n C-e C-b C-b C-b C-b C-b C-b C-b
C-b C-f { C-d C-SPC SPC SPC C-n <tab> C-b SPC } <tab>
C-p C-p C-n C-a C-f C-f C-f C-f C-f C-f C-f C-d C-d
C-d C-d C-d C-d C-n <tab> <help-echo> <help-echo> <help-echo>
<help-echo> <help-echo> <down-mouse-1> <mouse-1> <return>
C-y C-a C-SPC C-e M-w C-p C-p C-p C-b C-b C-b <backspace>
<backspace> <backspace> <backspace> a <backspace> a
: N <backspace> C-n C-f C-f C-f C-f <backspace> <backspace>
<backspace> <backspace> <backspace> <backspace> <backspace>
b : SPC 2 <tab> C-e C-e <help-echo> <help-echo> <down-mouse-1>
<drag-mouse-1> <down-mouse-1> <mouse-1> M-x r e p o
r t e m a c s <return>

Recent messages:
Reverting buffer `cider/README.md'. [3 times]
Saving file /Users/bozhidar/projects/test.rb...
Wrote /Users/bozhidar/projects/test.rb
Mark set
Indenting region...done
Mark activated
Source files should end with a newline (\n).
Auto-saving...done
Saving file /Users/bozhidar/projects/test.rb...
Wrote /Users/bozhidar/projects/test.rb

Load-path shadows:
/Users/bozhidar/.emacs.d/elpa/flycheck-20140107.305/.dir-locals hides /usr/local/Cellar/emacs/HEAD/share/emacs/24.3.50/lisp/gnus/.dir-locals
/Users/bozhidar/.emacs.d/elpa/tabulated-list-20120406.2251/tabulated-list hides /usr/local/Cellar/emacs/HEAD/share/emacs/24.3.50/lisp/emacs-lisp/tabulated-list

Features:
(shadow sort mail-extr emacsbug sendmail hippie-exp superword subword
ruby-tools inf-ruby ruby-mode-expansions smartparens-ruby ruby-mode smie
jka-compr rst eieio-opt speedbar sb-image ezimage dframe yaml-mode ffap
url-parse url-vars executable misearch multi-isearch mule-util
magit-key-mode magit view epa derived epg epg-config diff-mode
git-rebase-mode git-commit-mode server log-edit message rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045
ietf-drums mailabbrev mail-utils gmm-utils mailheader pcvs-util add-log
vc-git markdown-mode noutline outline rainbow-mode color
rainbow-delimiters elisp-slime-nav guru-mode prelude-key-chord key-chord
prelude-xml nxml-mode-expansions html-mode-expansions smartparens-html
rng-nxml rng-valid rng-loc rng-uri rng-parse nxml-parse rng-match rng-dt
rng-util rng-pttrn nxml-ns nxml-mode nxml-outln nxml-rap nxml-util
nxml-glyph nxml-enc xmltok prelude-scheme prelude-ruby prelude-perl
prelude-org prelude-js prelude-erc erc-truncate erc-autoaway
erc-spelling erc-notify erc-log erc-list erc-menu erc-join erc-ring
erc-networks erc-pcomplete erc-track erc-match erc-button erc-fill
erc-stamp erc-netsplit erc-goodies erc erc-backend erc-compat
prelude-emacs-lisp prelude-css prelude-common-lisp slime-autoloads
prelude-clojure prelude-lisp prelude-c prelude-programming flycheck
help-mode rx f which-func imenu prelude-ido smex flx-ido flx
ido-ubiquitous warnings ido prelude-osx exec-path-from-shell
prelude-global-keybindings prelude-editor winner undo-tree diff esh-var
esh-io esh-cmd esh-opt esh-ext esh-proc esh-arg eldoc esh-groups eshell
esh-module esh-mode esh-util re-builder whitespace browse-kill-ring
midnight ediff-merg ediff-wind ediff-diff ediff-mult ediff-help
ediff-init ediff-util ediff dired-x dired anzu projectile pkg-info
find-func grep compile s bookmark pp expand-region text-mode-expansions
er-basic-expansions expand-region-custom expand-region-core flyspell
ispell tramp tramp-compat auth-source gnus-util mm-util mail-prsvr
password-cache tramp-loaddefs trampver shell pcomplete comint ansi-color
format-spec etags ring volatile-highlights hl-line windmove recentf
tree-widget wid-edit savehist saveplace diminish smartparens-config
smartparens autorevert filenotify delsel prelude-mode easy-mmode edmacro
kmacro prelude-core epl advice help-fns dash thingatpt prelude-ui
zenburn-theme prelude-packages finder-inf ace-jump-mode-autoloads
ack-and-a-half-autoloads diminish-autoloads elisp-slime-nav-autoloads
flx-autoloads eieio byte-opt bytecomp byte-compile cconv eieio-core
grizzl-autoloads ido-ubiquitous-autoloads key-chord-autoloads
logito-autoloads info easymenu move-text-autoloads
rainbow-delimiters-autoloads rainbow-mode-autoloads request-autoloads
cl-macs gv caml-autoloads volatile-highlights-autoloads
yaml-mode-autoloads package cl cl-loaddefs cl-lib time-date tooltip
electric uniquify ediff-hook vc-hooks lisp-float-type mwheel ns-win
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
lisp-mode prog-mode register page menu-bar rfn-eshadow timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese hebrew greek romanian slovak czech european ethiopic
indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple
abbrev minibuffer 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 make-network-process
cocoa ns multi-tty emacs)

[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16996; Package emacs. (Wed, 12 Mar 2014 15:19:02 GMT) Full text and rfc822 format available.

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

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Bozhidar Batsov <bozhidar <at> batsov.com>
Cc: 16996 <at> debbugs.gnu.org
Subject: Re: bug#16996: 24.3.50;
 [ruby-mode] Incorrect indentation for implicit hash arguments
Date: Wed, 12 Mar 2014 17:18:01 +0200
Bozhidar Batsov <bozhidar <at> batsov.com> writes:

> top(1, :a => 1,
>     :b => 2)
>
> top(1, :a => 1,
>        :b => 2)

This looks like something that would be pretty gnarly to implement. I'm
not sure if we want to. Here's another example:

top(1, {
      :a => 1,
      :b => 2
    })

If we remove the braces, would you still indent :a and :b like if the
braces were present?




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

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: 16996 <at> debbugs.gnu.org, Bozhidar Batsov <bozhidar <at> batsov.com>
Subject: Re: bug#16996: 24.3.50; [ruby-mode] Incorrect indentation for
 implicit hash arguments
Date: Sat, 29 May 2021 10:55:02 +0200
Dmitry Gutov <dgutov <at> yandex.ru> writes:

> Bozhidar Batsov <bozhidar <at> batsov.com> writes:
>
>> top(1, :a => 1,
>>     :b => 2)
>>
>> top(1, :a => 1,
>>        :b => 2)
>
> This looks like something that would be pretty gnarly to implement. I'm
> not sure if we want to. Here's another example:
>
> top(1, {
>       :a => 1,
>       :b => 2
>     })
>
> If we remove the braces, would you still indent :a and :b like if the
> braces were present?

The current indentation in Ruby here seems pretty natural to me, so I'm
closing this bug report.

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




bug closed, send any further explanations to 16996 <at> debbugs.gnu.org and Bozhidar Batsov <bozhidar <at> batsov.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sat, 29 May 2021 08:56:02 GMT) Full text and rfc822 format available.

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

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

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 16996 <at> debbugs.gnu.org, Bozhidar Batsov <bozhidar <at> batsov.com>
Subject: Re: bug#16996: 24.3.50; [ruby-mode] Incorrect indentation for
 implicit hash arguments
Date: Sat, 29 May 2021 21:25:22 +0300
On 29.05.2021 11:55, Lars Ingebrigtsen wrote:
> The current indentation in Ruby here seems pretty natural to me, so I'm
> closing this bug report.

We should probably reopen it. It's not very urgent (as the bug creation 
date will confirm), but I wanted to get around to this someday.

Bozhidar, could you confirm it's still needed (or good to have)?

I wanted to find some style guide or other solid description of this 
style, but haven't managed to.

Ruby Style Guide strategically avoids this example, and 
https://www.rubydoc.info/gems/rubocop/0.83.0/RuboCop/Cop/Layout/HashAlignment 
and 
https://www.rubydoc.info/gems/rubocop/0.83.0/RuboCop/Cop/Layout/ArgumentAlignment 
do that too.

Despite that, I actually have to deal with this implicit recommendation 
on a regular basis at work, because when both cops are enabled, Rubocop 
will frown on

  top(1, :a => 1,
    :b => 2

and

  top 1, a: 1,
      b: 2

I do remember style like

  top(1, :a => 1,
         :b => 2)

being popular back in the day, but AFAICT a lot of editors now (like 
Atom and VS Code) don't support it either.




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

bug unarchived. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 30 Jun 2021 12:17:02 GMT) Full text and rfc822 format available.

Did not alter fixed versions and reopened. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 30 Jun 2021 12:17:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16996; Package emacs. (Sun, 18 Jul 2021 01:06:02 GMT) Full text and rfc822 format available.

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

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Bozhidar Batsov <bozhidar <at> batsov.com>
Cc: 16996 <at> debbugs.gnu.org, Lars Ingebrigtsen <larsi <at> gnus.org>
Subject: Re: bug#16996: 24.3.50; [ruby-mode] Incorrect indentation for
 implicit hash arguments
Date: Sun, 18 Jul 2021 04:05:25 +0300
On 30.06.2021 11:25, Bozhidar Batsov wrote:
> Sorry for the slow responses.

Same. :-(

> On Sat, 29 May 2021 at 21:25, Dmitry Gutov <dgutov <at> yandex.ru 
> <mailto:dgutov <at> yandex.ru>> wrote:
> 
>     On 29.05.2021 11:55, Lars Ingebrigtsen wrote:
>      > The current indentation in Ruby here seems pretty natural to me,
>     so I'm
>      > closing this bug report.
> 
>     We should probably reopen it. It's not very urgent (as the bug creation
>     date will confirm), but I wanted to get around to this someday.
> 
>     Bozhidar, could you confirm it's still needed (or good to have)?
> 
>     I wanted to find some style guide or other solid description of this
>     style, but haven't managed to.
> 
> 
> Perhaps we should first discuss our options there and adjust ruby-mode 
> afterwards? It's always a bit painful to discuss indentation issues over 
> email. :D

I'm happy to do that anywhere. You can ping me on Discord too.

>     Ruby Style Guide strategically avoids this example, and
>     https://www.rubydoc.info/gems/rubocop/0.83.0/RuboCop/Cop/Layout/HashAlignment
>     <https://www.rubydoc.info/gems/rubocop/0.83.0/RuboCop/Cop/Layout/HashAlignment>
> 
>     and
>     https://www.rubydoc.info/gems/rubocop/0.83.0/RuboCop/Cop/Layout/ArgumentAlignment
>     <https://www.rubydoc.info/gems/rubocop/0.83.0/RuboCop/Cop/Layout/ArgumentAlignment>
> 
>     do that too.
> 
> 
> Most likely that's just an oversight. People tend to focus on the most 
> common scenarios.

I was also thinking that perhaps you had been unfortunately biased 
toward not explicitly recommending a style which ruby-mode cannot 
support. :(

>     Despite that, I actually have to deal with this implicit recommendation
>     on a regular basis at work, because when both cops are enabled, Rubocop
>     will frown on
> 
>         top(1, :a => 1,
>           :b => 2
> 
>     and
> 
>         top 1, a: 1,
>             b: 2
> 
> 
> You get those offenses for fixed indentation? For align that seems like 
> an offense indeed, but for fixed it seems quite natural.

What's a "fixed indentation"? In both of the above cases I get 
complaints from the Layout/HashAlignment cop. I think we're using its 
default config.

>     I do remember style like
> 
>         top(1, :a => 1,
>                :b => 2)
> 
>     being popular back in the day, but AFAICT a lot of editors now (like
>     Atom and VS Code) don't support it either.
> 
> 
> I have to admit that I always stick to:
> 
>   top(1,
>         :a => 1,
>         :b => 2)

Likewise, if only out of necessity.

> Still, the second option seems somewhat reasonable if you're into mixing 
> argument types on the same line, although probably aligning on the hash 
> keys would be better for the readability of the code. Probably 
> your example makes even more sense for keyword arguments.

Sure. Depending on the code, or particular invocation, I could see 
either style being more reasonable than the other.




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

Previous Next


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