* [ruby-mode] dot-alignment support for multi-line method chaining @ 2014-01-21 12:25 Bozhidar Batsov 2014-01-22 13:41 ` Dmitry Gutov 0 siblings, 1 reply; 6+ messages in thread From: Bozhidar Batsov @ 2014-01-21 12:25 UTC (permalink / raw) To: emacs-devel [-- Attachment #1: Type: text/plain, Size: 553 bytes --] Currently when doing method chaining on multiple lines we get the following indentation: something.ala .one .two .three An alternative style that seems to be popular is: something.ala .one .two .three Here are some references (not just for Ruby): * http://en.wikipedia.org/wiki/Fluent_interface * https://github.com/bbatsov/ruby-style-guide/pull/176#issuecomment-18664622 I guess it will be good if ruby-mode supported the alternative style via some customisable option. -- Cheers, Bozhidar [-- Attachment #2: Type: text/html, Size: 1833 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [ruby-mode] dot-alignment support for multi-line method chaining 2014-01-21 12:25 [ruby-mode] dot-alignment support for multi-line method chaining Bozhidar Batsov @ 2014-01-22 13:41 ` Dmitry Gutov 2014-01-22 17:28 ` Bozhidar Batsov 0 siblings, 1 reply; 6+ messages in thread From: Dmitry Gutov @ 2014-01-22 13:41 UTC (permalink / raw) To: Bozhidar Batsov; +Cc: emacs-devel Hi! Bozhidar Batsov <bozhidar@batsov.com> writes: > Currently when doing method chaining on multiple lines we get the > following indentation: > > something.ala > .one > .two > .three > > An alternative style that seems to be popular is: > > something.ala > .one > .two > .three Good suggestion, but it looks harder than the previous ones, and it'll require modifying (or maybe "fixing") the SMIE grammar. At the moment, the parent of a "." token is never the previous ".". I have an experimental patch, included at the end, but it throws up some grammar priority warnings, and it changes the indentation in the following example: zoo.keep.bar!( {x: y, z: t}) If I modify the code a little, the indentation here will be like this: zoo.keep.bar!( {x: y, z: t}) which corresponds to zoo.keep.bar!( {x: y, z: t} ) which, in turn, is a small modification of zoo.keep .bar!( {x: y, z: t} ) Would you consider this appropriate, for the "fluent interface" indentation? Or how would you indent it instead? By the way, do you think it'd be good if the same variable toggled between foo = foobar .baz and foo = foobar .baz ? Or would that be a different variable? P.S. Could you use the bug tracker for feature requests next time? Bugs are easier to keep track of and to get back to later. === modified file 'lisp/progmodes/ruby-mode.el' --- lisp/progmodes/ruby-mode.el 2014-01-17 03:15:02 +0000 +++ lisp/progmodes/ruby-mode.el 2014-01-22 13:25:38 +0000 @@ -351,7 +351,7 @@ (exp "and" exp) (exp "or" exp)) (exp (exp1) (exp "," exp) (exp "=" exp) (id " @ " exp) - (exp "." id)) + (id "." exp)) (exp1 (exp2) (exp2 "?" exp1 ":" exp1)) (exp2 ("def" insts "end") ("begin" insts-rescue-insts "end") @@ -380,7 +380,7 @@ (ielsei (itheni) (itheni "else" insts)) (if-body (ielsei) (if-body "elsif" if-body))) '((nonassoc "in") (assoc ";") (right " @ ") - (assoc ",") (right "=") (assoc ".")) + (assoc ",") (right "=")) '((assoc "when")) '((assoc "elsif")) '((assoc "rescue" "ensure")) @@ -399,7 +399,8 @@ (nonassoc ">" ">=" "<" "<=") (nonassoc "==" "===" "!=") (nonassoc "=~" "!~") - (left "<<" ">>")))))) + (left "<<" ">>") + (assoc ".")))))) (defun ruby-smie--bosp () (save-excursion (skip-chars-backward " \t") @@ -622,7 +623,10 @@ (unless (or (eolp) (forward-comment 1)) (cons 'column (current-column))))) (`(:before . "do") (ruby-smie--indent-to-stmt)) - (`(:before . ".") ruby-indent-level) + (`(:before . ".") + (if (smie-rule-sibling-p) + 0 + ruby-indent-level)) (`(:after . "=>") ruby-indent-level) (`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure")) (smie-rule-parent)) ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [ruby-mode] dot-alignment support for multi-line method chaining 2014-01-22 13:41 ` Dmitry Gutov @ 2014-01-22 17:28 ` Bozhidar Batsov 2014-01-30 4:31 ` Dmitry Gutov 0 siblings, 1 reply; 6+ messages in thread From: Bozhidar Batsov @ 2014-01-22 17:28 UTC (permalink / raw) To: Dmitry Gutov; +Cc: emacs-devel [-- Attachment #1: Type: text/plain, Size: 3661 bytes --] On 22 January 2014 15:41, Dmitry Gutov <dgutov@yandex.ru> wrote: > Hi! > > Bozhidar Batsov <bozhidar@batsov.com> writes: > > > Currently when doing method chaining on multiple lines we get the > > following indentation: > > > > something.ala > > .one > > .two > > .three > > > > An alternative style that seems to be popular is: > > > > something.ala > > .one > > .two > > .three > > Good suggestion, but it looks harder than the previous ones, and it'll > require modifying (or maybe "fixing") the SMIE grammar. At the moment, > the parent of a "." token is never the previous ".". > > I have an experimental patch, included at the end, but it throws up some > grammar priority warnings, and it changes the indentation in the > following example: > > zoo.keep.bar!( > {x: y, > z: t}) > > If I modify the code a little, the indentation here will be like this: > > zoo.keep.bar!( > {x: y, > z: t}) > > which corresponds to > > zoo.keep.bar!( > {x: y, > z: t} > ) > > which, in turn, is a small modification of > > zoo.keep > .bar!( > {x: y, > z: t} > ) > > Would you consider this appropriate, for the "fluent interface" > indentation? Or how would you indent it instead? > Hard to read indentation examples in an email, but it seems to me that: zoo.keep.bar!( {x: y, z: t} ) is the only sensible indentation for the third example and the forth should be: zoo.keep .bar!( {x: y, z: t} ) when using the fluent-api-style indentation. > > By the way, do you think it'd be good if the same variable toggled between > > foo = foobar > .baz > > and > > foo = foobar > .baz > > ? Or would that be a different variable? > Didn't notice this until now. Seems to me the default indent should be relative to the `=` (similar to what we do for ops like +, -, etc): foo = foobar .baz > > P.S. Could you use the bug tracker for feature requests next time? Bugs > are easier to keep track of and to get back to later. > Sure. > > > === modified file 'lisp/progmodes/ruby-mode.el' > --- lisp/progmodes/ruby-mode.el 2014-01-17 03:15:02 +0000 > +++ lisp/progmodes/ruby-mode.el 2014-01-22 13:25:38 +0000 > @@ -351,7 +351,7 @@ > (exp "and" exp) (exp "or" exp)) > (exp (exp1) (exp "," exp) (exp "=" exp) > (id " @ " exp) > - (exp "." id)) > + (id "." exp)) > (exp1 (exp2) (exp2 "?" exp1 ":" exp1)) > (exp2 ("def" insts "end") > ("begin" insts-rescue-insts "end") > @@ -380,7 +380,7 @@ > (ielsei (itheni) (itheni "else" insts)) > (if-body (ielsei) (if-body "elsif" if-body))) > '((nonassoc "in") (assoc ";") (right " @ ") > - (assoc ",") (right "=") (assoc ".")) > + (assoc ",") (right "=")) > '((assoc "when")) > '((assoc "elsif")) > '((assoc "rescue" "ensure")) > @@ -399,7 +399,8 @@ > (nonassoc ">" ">=" "<" "<=") > (nonassoc "==" "===" "!=") > (nonassoc "=~" "!~") > - (left "<<" ">>")))))) > + (left "<<" ">>") > + (assoc ".")))))) > > (defun ruby-smie--bosp () > (save-excursion (skip-chars-backward " \t") > @@ -622,7 +623,10 @@ > (unless (or (eolp) (forward-comment 1)) > (cons 'column (current-column))))) > (`(:before . "do") (ruby-smie--indent-to-stmt)) > - (`(:before . ".") ruby-indent-level) > + (`(:before . ".") > + (if (smie-rule-sibling-p) > + 0 > + ruby-indent-level)) > (`(:after . "=>") ruby-indent-level) > (`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure")) > (smie-rule-parent)) > > [-- Attachment #2: Type: text/html, Size: 6095 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [ruby-mode] dot-alignment support for multi-line method chaining 2014-01-22 17:28 ` Bozhidar Batsov @ 2014-01-30 4:31 ` Dmitry Gutov 2014-01-30 8:51 ` Andreas Schwab 0 siblings, 1 reply; 6+ messages in thread From: Dmitry Gutov @ 2014-01-30 4:31 UTC (permalink / raw) To: Bozhidar Batsov; +Cc: emacs-devel See http://debbugs.gnu.org/16593 On 22.01.2014 19:28, Bozhidar Batsov wrote: > Hard to read indentation examples in an email, but it seems to me that: Yeah, both Gnus and Thunderbird mangle indentation quite a bit for me. lists.gnu.org displays it right, though. > zoo.keep.bar!( > {x: y, > z: t} > ) > > is the only sensible indentation for the third example It doesn't seem to correspond to the AST, but sure, this looks nicer. > By the way, do you think it'd be good if the same variable toggled > between > > foo = foobar > .baz > > and > > foo = foobar > .baz > > ? Or would that be a different variable? > > > Didn't notice this until now. Seems to me the default indent should be > relative to the `=` (similar to what we do for ops like +, -, etc): Okay, won't touch this for now, then, ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [ruby-mode] dot-alignment support for multi-line method chaining 2014-01-30 4:31 ` Dmitry Gutov @ 2014-01-30 8:51 ` Andreas Schwab 2014-01-30 14:45 ` Dmitry Gutov 0 siblings, 1 reply; 6+ messages in thread From: Andreas Schwab @ 2014-01-30 8:51 UTC (permalink / raw) To: Dmitry Gutov; +Cc: Bozhidar Batsov, emacs-devel Dmitry Gutov <dgutov@yandex.ru> writes: > On 22.01.2014 19:28, Bozhidar Batsov wrote: >> Hard to read indentation examples in an email, but it seems to me that: > > Yeah, both Gnus and Thunderbird mangle indentation quite a bit for > me. You should ignore the totally stupid html part (adding "text/html" to mm-discouraged-alternatives will save your life). Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [ruby-mode] dot-alignment support for multi-line method chaining 2014-01-30 8:51 ` Andreas Schwab @ 2014-01-30 14:45 ` Dmitry Gutov 0 siblings, 0 replies; 6+ messages in thread From: Dmitry Gutov @ 2014-01-30 14:45 UTC (permalink / raw) To: Andreas Schwab; +Cc: Bozhidar Batsov, emacs-devel Andreas Schwab <schwab@linux-m68k.org> writes: > You should ignore the totally stupid html part (adding "text/html" to > mm-discouraged-alternatives will save your life). Thanks, this make things better in Gnus, but also makes it apparent that Bozhidar's messages are written using proportional font, so the examples still don't line up in a monospace reader. Thunderbird actually renders the html very similarly to lists.gnu.org, so both look better. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-01-30 14:45 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-01-21 12:25 [ruby-mode] dot-alignment support for multi-line method chaining Bozhidar Batsov 2014-01-22 13:41 ` Dmitry Gutov 2014-01-22 17:28 ` Bozhidar Batsov 2014-01-30 4:31 ` Dmitry Gutov 2014-01-30 8:51 ` Andreas Schwab 2014-01-30 14:45 ` 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).