]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix bug#16116
authorDmitry Gutov <dgutov@yandex.ru>
Tue, 17 Dec 2013 01:31:55 +0000 (03:31 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Tue, 17 Dec 2013 01:31:55 +0000 (03:31 +0200)
* lisp/emacs-lisp/smie.el (smie-indent--rule): Extract `smie-indent--rule-1'.
(smie-indent-close): Call `smie-indent--rule-1' with METHOD
:close-all, to see which indentation method to use.
(smie-rules-function): Document the method :close-all.

* test/indent/ruby.rb: Update examples according to the change
in `smie-indent-close'.

lisp/ChangeLog
lisp/emacs-lisp/smie.el
test/ChangeLog
test/indent/ruby.rb

index d267715bee35202630e4e66237e7987dc82bccda..4835311599e7075afbd49b71a3150a2537dbc824 100644 (file)
@@ -1,3 +1,10 @@
+2013-12-17  Dmitry Gutov  <dgutov@yandex.ru>
+
+       * emacs-lisp/smie.el (smie-indent--rule): Extract `smie-indent--rule-1'.
+       (smie-indent-close): Call `smie-indent--rule-1' with METHOD
+       :close-all, to see which indentation method to use (Bug#16116).
+       (smie-rules-function): Document the method :close-all.
+
 2013-12-16  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
        * net/shr.el (shr-tag-a): Support zero-length <a name="foo"> elements.
index 1c468e013d64a99693ab10ce925ce37de216cf99..08bf7348aa91b0d4f2945892a3cbafb746739478 100644 (file)
@@ -1135,6 +1135,10 @@ METHOD can be:
 - :list-intro, in which case ARG is a token and the function should return
   non-nil if TOKEN is followed by a list of expressions (not separated by any
   token) rather than an expression.
+- :close-all, in which case ARG is a close-paren token at indentation and
+  the function should return non-nil if it should be aligned with the opener
+  of the last close-paren token on the same line, if there are multiple.
+  Otherwise, it will be aligned with its own opener.
 
 When ARG is a token, the function is called with point just before that token.
 A return value of nil always means to fallback on the default behavior, so the
@@ -1316,8 +1320,8 @@ Only meaningful when called from within `smie-rules-function'."
 (defun smie-indent--rule (method token
                           ;; FIXME: Too many parameters.
                           &optional after parent base-pos)
-  "Compute indentation column according to `indent-rule-functions'.
-METHOD and TOKEN are passed to `indent-rule-functions'.
+  "Compute indentation column according to `smie-rules-function'.
+METHOD and TOKEN are passed to `smie-rules-function'.
 AFTER is the position after TOKEN, if known.
 PARENT is the parent info returned by `smie-backward-sexp', if known.
 BASE-POS is the position relative to which offsets should be applied."
@@ -1330,11 +1334,7 @@ BASE-POS is the position relative to which offsets should be applied."
   ;; - :after tok, where
   ;;                  ; after is set; parent=nil; base-pos=point;
   (save-excursion
-    (let ((offset
-           (let ((smie--parent parent)
-                 (smie--token token)
-                 (smie--after after))
-             (funcall smie-rules-function method token))))
+    (let ((offset (smie-indent--rule-1 method token after parent)))
       (cond
        ((not offset) nil)
        ((eq (car-safe offset) 'column) (cdr offset))
@@ -1355,6 +1355,12 @@ BASE-POS is the position relative to which offsets should be applied."
                  (smie-indent-virtual) (current-column)))))
        (t (error "Unknown indentation offset %s" offset))))))
 
+(defun smie-indent--rule-1 (method token &optional after parent)
+  (let ((smie--parent parent)
+        (smie--token token)
+        (smie--after after))
+    (funcall smie-rules-function method token)))
+
 (defun smie-indent-forward-token ()
   "Skip token forward and return it, along with its levels."
   (let ((tok (funcall smie-forward-token-function)))
@@ -1423,8 +1429,13 @@ in order to figure out the indentation of some other (further down) point."
   (save-excursion
     ;; (forward-comment (point-max))
     (when (looking-at "\\s)")
-      (while (not (zerop (skip-syntax-forward ")")))
-        (skip-chars-forward " \t"))
+      (if (smie-indent--rule-1 :close-all
+                               (buffer-substring-no-properties
+                                (point) (1+ (point)))
+                               (1+ (point)))
+          (while (not (zerop (skip-syntax-forward ")")))
+            (skip-chars-forward " \t"))
+        (forward-char 1))
       (condition-case nil
           (progn
             (backward-sexp 1)
index ffa12498de41a00c5193aa71a39d1b5f579263e9..374cae5a295681110b1a44b484cdd30dd69055ff 100644 (file)
@@ -1,3 +1,8 @@
+2013-12-17  Dmitry Gutov  <dgutov@yandex.ru>
+
+       * indent/ruby.rb: Update examples according to the change
+       in `smie-indent-close'.
+
 2013-12-14  Dmitry Gutov  <dgutov@yandex.ru>
 
        * indent/ruby.rb: New examples.
index 7b85899577c2560c86b4d510fb48107705261d73..19bc0d03d47d21f30352168b400feb6905f22240 100644 (file)
@@ -48,8 +48,7 @@ foo = { a: b,
 foo({                           # bug#16118
       a: b,
       c: d
-    }
-   )                            # bug#16116
+    })
 
 bar = foo(
         a, [
@@ -57,8 +56,7 @@ bar = foo(
         ],
         :qux => [
           3
-        ]
-      )
+        ])
 
 foo(
   [
@@ -78,8 +76,7 @@ foo([{
        b: 3
      },
      4
-    ]
-   )
+    ])
 
 foo = [                         # ruby-deep-indent-disabled
   1