emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-25 72c7438 2/2: Indent methods with keyword names co


From: Dmitry Gutov
Subject: [Emacs-diffs] emacs-25 72c7438 2/2: Indent methods with keyword names correctly
Date: Thu, 10 Mar 2016 12:36:59 +0000

branch: emacs-25
commit 72c7438c4c6ee0d24405636cde4b18c32034a634
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Indent methods with keyword names correctly
    
    * 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 |   14 +++++++++-----
 test/indent/ruby.rb         |    3 +++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 94fd277..be8f96d 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -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
diff --git a/test/indent/ruby.rb b/test/indent/ruby.rb
index 522c3bd..585263d 100644
--- a/test/indent/ruby.rb
+++ b/test/indent/ruby.rb
@@ -203,6 +203,9 @@ class C
     self.end
     D.new.class
   end
+
+  def begin
+  end
 end
 
 a = foo(j, k) -



reply via email to

[Prev in Thread] Current Thread [Next in Thread]