unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: ruby-mode broken with indentation?
       [not found] <8661sgt427.knu@iDaemons.org>
@ 2013-11-02  5:22 ` Dmitry Gutov
  2013-11-03 22:51   ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Gutov @ 2013-11-02  5:22 UTC (permalink / raw)
  To: Akinori MUSHA; +Cc: Stefan Monnier, emacs-devel

Hi Akinori,

On 29.10.2013 20:49, Akinori MUSHA wrote:
> I found ruby-mode indents an assignment + block construct incorrectly:
>
> What I expect is as follows:
>
> ```
> a = b {
>    c
> }
> aa = bb do
>    cc
> end
> ```
>
> But ruby-mode from Emacs trunk indents it as follows:
>
> ```
> a = b {
>      c
>    }
> aa = bb do
>       cc
>     end
> ```
>
> Does this reproduce for you?

It does. ruby-mode in Emacs trunk has switched to SMIE as its default 
indentation engine, and it still handles some cases badly. To use the 
old indentation engine, add (setq ruby-use-smie nil) to your config.

I've fixed the examples above in revision 114901, but I'm not sure if 
that was a good approach. Stefan, could you take a look?



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

* Re: ruby-mode broken with indentation?
  2013-11-02  5:22 ` ruby-mode broken with indentation? Dmitry Gutov
@ 2013-11-03 22:51   ` Stefan Monnier
  2013-11-05  1:12     ` Dmitry Gutov
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2013-11-03 22:51 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Akinori MUSHA, emacs-devel

> I've fixed the examples above in revision 114901, but I'm not sure if that
> was a good approach. Stefan, could you take a look?

I think this was actually a bug in smie.el.
The patch below seems to do the right thing.  Not sure how ti might
affect other major modes using SMIE, but at least my sml-mode test suite
seems unaffected.


        Stefan


=== modified file 'lisp/emacs-lisp/smie.el'
--- lisp/emacs-lisp/smie.el	2013-10-24 21:16:20 +0000
+++ lisp/emacs-lisp/smie.el	2013-11-03 22:46:30 +0000
@@ -1236,15 +1236,7 @@
     (goto-char (cadr (smie-indent--parent)))
     (cons 'column
           (+ (or offset 0)
-             ;; Use smie-indent-virtual when indenting relative to an opener:
-             ;; this will also by default use current-column unless
-             ;; that opener is hanging, but will additionally consult
-             ;; rules-function, so it gives it a chance to tweak
-             ;; indentation (e.g. by forcing indentation relative to
-             ;; its own parent, as in fn a => fn b => fn c =>).
-             (if (or (not (numberp (car smie--parent)))
-		     (smie-indent--hanging-p))
-                 (smie-indent-virtual) (current-column))))))
+             (smie-indent-virtual)))))
 
 (defvar smie-rule-separator-outdent 2)
 
@@ -1837,6 +1829,14 @@
       (edebug-instrument-function smie-rules-function)
     (error "Sorry, don't know how to instrument a lambda expression")))
 
+(defun smie--next-indent-change ()
+  (interactive)
+  (while
+      (let ((tick (buffer-modified-tick)))
+        (indent-according-to-mode)
+        (eq tick (buffer-modified-tick)))
+    (forward-line 1)))
+
 ;;; User configuration
 
 ;; This is designed to be a completely independent "module", so we can play

=== modified file 'lisp/progmodes/ruby-mode.el'
--- lisp/progmodes/ruby-mode.el	2013-11-02 05:18:11 +0000
+++ lisp/progmodes/ruby-mode.el	2013-11-03 22:48:27 +0000
@@ -467,16 +467,6 @@
            (t ";")))
          (t tok)))))))
 
-(defun ruby-smie--rule-parent-skip-assign ()
-  (let* ((parent (smie-indent--parent))
-         (tok (caddr parent)))
-    (if (and (stringp tok) (string-match-p "[+-*&|^]?=\\'" tok))
-        (progn
-          (goto-char (cadr parent))
-          (let (smie--parent)
-            (smie-rule-parent)))
-      (smie-rule-parent))))
-
 (defun ruby-smie-rules (kind token)
   (pcase (cons kind token)
     (`(:elem . basic) ruby-indent-level)
@@ -499,7 +489,7 @@
       ((and (equal token "{")
             (not (smie-rule-prev-p "(" "{" "[" "," "=>" "=" "return" ";")))
        ;; Curly block opener.
-       (ruby-smie--rule-parent-skip-assign))
+       (smie-rule-parent))
       ((smie-rule-hanging-p)
        ;; Treat purely syntactic block-constructs as being part of their parent,
        ;; when the opening statement is hanging.
@@ -508,7 +498,7 @@
        (cons 'column  (smie-indent-virtual)))))
     (`(:after . ,(or "=" "iuwu-mod")) 2)
     (`(:after . " @ ") (smie-rule-parent))
-    (`(:before . "do") (ruby-smie--rule-parent-skip-assign))
+    (`(:before . "do") (smie-rule-parent))
     (`(,(or :before :after) . ".")
      (unless (smie-rule-parent-p ".")
        (smie-rule-parent ruby-indent-level)))




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

* Re: ruby-mode broken with indentation?
  2013-11-03 22:51   ` Stefan Monnier
@ 2013-11-05  1:12     ` Dmitry Gutov
  0 siblings, 0 replies; 3+ messages in thread
From: Dmitry Gutov @ 2013-11-05  1:12 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Akinori MUSHA, emacs-devel

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

>> I've fixed the examples above in revision 114901, but I'm not sure if that
>> was a good approach. Stefan, could you take a look?
>
> I think this was actually a bug in smie.el.

I see, thanks for the fix.

> The patch below seems to do the right thing.  Not sure how ti might
> affect other major modes using SMIE, but at least my sml-mode test suite
> seems unaffected.

It also fixed one other example in ruby.rb, while keeping the already
working ones unaffected:

foo :bar do
  qux
end



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

end of thread, other threads:[~2013-11-05  1:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <8661sgt427.knu@iDaemons.org>
2013-11-02  5:22 ` ruby-mode broken with indentation? Dmitry Gutov
2013-11-03 22:51   ` Stefan Monnier
2013-11-05  1:12     ` 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).