diff options
| author | Dmitry Gutov | 2013-12-17 03:31:55 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2013-12-17 03:31:55 +0200 |
| commit | 5556c0cef106deb5a4614aabf96d223ada151f51 (patch) | |
| tree | 9fed64046ebb8d1a664b351c39dba9bdef59292c | |
| parent | 1c4b1e6107d17a184416b9bffd97222c06e5ff83 (diff) | |
| download | emacs-5556c0cef106deb5a4614aabf96d223ada151f51.tar.gz emacs-5556c0cef106deb5a4614aabf96d223ada151f51.zip | |
Fix bug#16116
* 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'.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/emacs-lisp/smie.el | 29 | ||||
| -rw-r--r-- | test/ChangeLog | 5 | ||||
| -rw-r--r-- | test/indent/ruby.rb | 9 |
4 files changed, 35 insertions, 15 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d267715bee3..4835311599e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2013-12-17 Dmitry Gutov <dgutov@yandex.ru> | ||
| 2 | |||
| 3 | * emacs-lisp/smie.el (smie-indent--rule): Extract `smie-indent--rule-1'. | ||
| 4 | (smie-indent-close): Call `smie-indent--rule-1' with METHOD | ||
| 5 | :close-all, to see which indentation method to use (Bug#16116). | ||
| 6 | (smie-rules-function): Document the method :close-all. | ||
| 7 | |||
| 1 | 2013-12-16 Lars Magne Ingebrigtsen <larsi@gnus.org> | 8 | 2013-12-16 Lars Magne Ingebrigtsen <larsi@gnus.org> |
| 2 | 9 | ||
| 3 | * net/shr.el (shr-tag-a): Support zero-length <a name="foo"> elements. | 10 | * net/shr.el (shr-tag-a): Support zero-length <a name="foo"> elements. |
diff --git a/lisp/emacs-lisp/smie.el b/lisp/emacs-lisp/smie.el index 1c468e013d6..08bf7348aa9 100644 --- a/lisp/emacs-lisp/smie.el +++ b/lisp/emacs-lisp/smie.el | |||
| @@ -1135,6 +1135,10 @@ METHOD can be: | |||
| 1135 | - :list-intro, in which case ARG is a token and the function should return | 1135 | - :list-intro, in which case ARG is a token and the function should return |
| 1136 | non-nil if TOKEN is followed by a list of expressions (not separated by any | 1136 | non-nil if TOKEN is followed by a list of expressions (not separated by any |
| 1137 | token) rather than an expression. | 1137 | token) rather than an expression. |
| 1138 | - :close-all, in which case ARG is a close-paren token at indentation and | ||
| 1139 | the function should return non-nil if it should be aligned with the opener | ||
| 1140 | of the last close-paren token on the same line, if there are multiple. | ||
| 1141 | Otherwise, it will be aligned with its own opener. | ||
| 1138 | 1142 | ||
| 1139 | When ARG is a token, the function is called with point just before that token. | 1143 | When ARG is a token, the function is called with point just before that token. |
| 1140 | A return value of nil always means to fallback on the default behavior, so the | 1144 | 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'." | |||
| 1316 | (defun smie-indent--rule (method token | 1320 | (defun smie-indent--rule (method token |
| 1317 | ;; FIXME: Too many parameters. | 1321 | ;; FIXME: Too many parameters. |
| 1318 | &optional after parent base-pos) | 1322 | &optional after parent base-pos) |
| 1319 | "Compute indentation column according to `indent-rule-functions'. | 1323 | "Compute indentation column according to `smie-rules-function'. |
| 1320 | METHOD and TOKEN are passed to `indent-rule-functions'. | 1324 | METHOD and TOKEN are passed to `smie-rules-function'. |
| 1321 | AFTER is the position after TOKEN, if known. | 1325 | AFTER is the position after TOKEN, if known. |
| 1322 | PARENT is the parent info returned by `smie-backward-sexp', if known. | 1326 | PARENT is the parent info returned by `smie-backward-sexp', if known. |
| 1323 | BASE-POS is the position relative to which offsets should be applied." | 1327 | 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." | |||
| 1330 | ;; - :after tok, where | 1334 | ;; - :after tok, where |
| 1331 | ;; ; after is set; parent=nil; base-pos=point; | 1335 | ;; ; after is set; parent=nil; base-pos=point; |
| 1332 | (save-excursion | 1336 | (save-excursion |
| 1333 | (let ((offset | 1337 | (let ((offset (smie-indent--rule-1 method token after parent))) |
| 1334 | (let ((smie--parent parent) | ||
| 1335 | (smie--token token) | ||
| 1336 | (smie--after after)) | ||
| 1337 | (funcall smie-rules-function method token)))) | ||
| 1338 | (cond | 1338 | (cond |
| 1339 | ((not offset) nil) | 1339 | ((not offset) nil) |
| 1340 | ((eq (car-safe offset) 'column) (cdr offset)) | 1340 | ((eq (car-safe offset) 'column) (cdr offset)) |
| @@ -1355,6 +1355,12 @@ BASE-POS is the position relative to which offsets should be applied." | |||
| 1355 | (smie-indent-virtual) (current-column))))) | 1355 | (smie-indent-virtual) (current-column))))) |
| 1356 | (t (error "Unknown indentation offset %s" offset)))))) | 1356 | (t (error "Unknown indentation offset %s" offset)))))) |
| 1357 | 1357 | ||
| 1358 | (defun smie-indent--rule-1 (method token &optional after parent) | ||
| 1359 | (let ((smie--parent parent) | ||
| 1360 | (smie--token token) | ||
| 1361 | (smie--after after)) | ||
| 1362 | (funcall smie-rules-function method token))) | ||
| 1363 | |||
| 1358 | (defun smie-indent-forward-token () | 1364 | (defun smie-indent-forward-token () |
| 1359 | "Skip token forward and return it, along with its levels." | 1365 | "Skip token forward and return it, along with its levels." |
| 1360 | (let ((tok (funcall smie-forward-token-function))) | 1366 | (let ((tok (funcall smie-forward-token-function))) |
| @@ -1423,8 +1429,13 @@ in order to figure out the indentation of some other (further down) point." | |||
| 1423 | (save-excursion | 1429 | (save-excursion |
| 1424 | ;; (forward-comment (point-max)) | 1430 | ;; (forward-comment (point-max)) |
| 1425 | (when (looking-at "\\s)") | 1431 | (when (looking-at "\\s)") |
| 1426 | (while (not (zerop (skip-syntax-forward ")"))) | 1432 | (if (smie-indent--rule-1 :close-all |
| 1427 | (skip-chars-forward " \t")) | 1433 | (buffer-substring-no-properties |
| 1434 | (point) (1+ (point))) | ||
| 1435 | (1+ (point))) | ||
| 1436 | (while (not (zerop (skip-syntax-forward ")"))) | ||
| 1437 | (skip-chars-forward " \t")) | ||
| 1438 | (forward-char 1)) | ||
| 1428 | (condition-case nil | 1439 | (condition-case nil |
| 1429 | (progn | 1440 | (progn |
| 1430 | (backward-sexp 1) | 1441 | (backward-sexp 1) |
diff --git a/test/ChangeLog b/test/ChangeLog index ffa12498de4..374cae5a295 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2013-12-17 Dmitry Gutov <dgutov@yandex.ru> | ||
| 2 | |||
| 3 | * indent/ruby.rb: Update examples according to the change | ||
| 4 | in `smie-indent-close'. | ||
| 5 | |||
| 1 | 2013-12-14 Dmitry Gutov <dgutov@yandex.ru> | 6 | 2013-12-14 Dmitry Gutov <dgutov@yandex.ru> |
| 2 | 7 | ||
| 3 | * indent/ruby.rb: New examples. | 8 | * indent/ruby.rb: New examples. |
diff --git a/test/indent/ruby.rb b/test/indent/ruby.rb index 7b85899577c..19bc0d03d47 100644 --- a/test/indent/ruby.rb +++ b/test/indent/ruby.rb | |||
| @@ -48,8 +48,7 @@ foo = { a: b, | |||
| 48 | foo({ # bug#16118 | 48 | foo({ # bug#16118 |
| 49 | a: b, | 49 | a: b, |
| 50 | c: d | 50 | c: d |
| 51 | } | 51 | }) |
| 52 | ) # bug#16116 | ||
| 53 | 52 | ||
| 54 | bar = foo( | 53 | bar = foo( |
| 55 | a, [ | 54 | a, [ |
| @@ -57,8 +56,7 @@ bar = foo( | |||
| 57 | ], | 56 | ], |
| 58 | :qux => [ | 57 | :qux => [ |
| 59 | 3 | 58 | 3 |
| 60 | ] | 59 | ]) |
| 61 | ) | ||
| 62 | 60 | ||
| 63 | foo( | 61 | foo( |
| 64 | [ | 62 | [ |
| @@ -78,8 +76,7 @@ foo([{ | |||
| 78 | b: 3 | 76 | b: 3 |
| 79 | }, | 77 | }, |
| 80 | 4 | 78 | 4 |
| 81 | ] | 79 | ]) |
| 82 | ) | ||
| 83 | 80 | ||
| 84 | foo = [ # ruby-deep-indent-disabled | 81 | foo = [ # ruby-deep-indent-disabled |
| 85 | 1 | 82 | 1 |