]> code.delx.au - gnu-emacs/commitdiff
Indent methods with keyword names correctly
authorDmitry Gutov <dgutov@yandex.ru>
Thu, 10 Mar 2016 12:35:45 +0000 (14:35 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Thu, 10 Mar 2016 12:36:08 +0000 (14:36 +0200)
* lisp/progmodes/ruby-mode.el (ruby-smie--at-dot-call):
Rename to ruby-smie--before-method-name.  Now also check if we're
after a 'def' keyword.  Update both callers.

lisp/progmodes/ruby-mode.el
test/indent/ruby.rb

index 94fd2771ab708367721eb0a2992659203ea6e4ae..be8f96dcfd9d271948a48634a5c9b63c3f2bbc56 100644 (file)
@@ -481,10 +481,14 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
          (memq (car (syntax-after pos)) '(7 15))
          (looking-at "[([]\\|[-+!~:]\\(?:\\sw\\|\\s_\\)")))))
 
-(defun ruby-smie--at-dot-call ()
+(defun ruby-smie--before-method-name ()
+  ;; Only need to be accurate when method has keyword name.
   (and (eq ?w (char-syntax (following-char)))
-       (eq (char-before) ?.)
-       (not (eq (char-before (1- (point))) ?.))))
+       (or
+        (and
+         (eq (char-before) ?.)
+         (not (eq (char-before (1- (point))) ?.)))
+        (looking-back "^\\s *def\\s +\\=" (line-beginning-position)))))
 
 (defun ruby-smie--forward-token ()
   (let ((pos (point)))
@@ -507,7 +511,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
         " @ ")
        ((looking-at "\\s\"") "")                    ;A string.
        (t
-        (let ((dot (ruby-smie--at-dot-call))
+        (let ((dot (ruby-smie--before-method-name))
               (tok (smie-default-forward-token)))
           (when dot
             (setq tok (concat "." tok)))
@@ -551,7 +555,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
       " @ ")
      (t
       (let ((tok (smie-default-backward-token))
-            (dot (ruby-smie--at-dot-call)))
+            (dot (ruby-smie--before-method-name)))
         (when dot
           (setq tok (concat "." tok)))
         (cond
index 522c3bd5465c81ae9463a9dea6d84f8ded9e8041..585263d02a6c713ff076079947d21b3f20ae43b4 100644 (file)
@@ -203,6 +203,9 @@ class C
     self.end
     D.new.class
   end
+
+  def begin
+  end
 end
 
 a = foo(j, k) -