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.
This commit is contained in:
parent
28532a91a9
commit
72c7438c4c
2 changed files with 12 additions and 5 deletions
|
@ -481,10 +481,14 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
|
||||||
(memq (car (syntax-after pos)) '(7 15))
|
(memq (car (syntax-after pos)) '(7 15))
|
||||||
(looking-at "[([]\\|[-+!~:]\\(?:\\sw\\|\\s_\\)")))))
|
(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)))
|
(and (eq ?w (char-syntax (following-char)))
|
||||||
(eq (char-before) ?.)
|
(or
|
||||||
(not (eq (char-before (1- (point))) ?.))))
|
(and
|
||||||
|
(eq (char-before) ?.)
|
||||||
|
(not (eq (char-before (1- (point))) ?.)))
|
||||||
|
(looking-back "^\\s *def\\s +\\=" (line-beginning-position)))))
|
||||||
|
|
||||||
(defun ruby-smie--forward-token ()
|
(defun ruby-smie--forward-token ()
|
||||||
(let ((pos (point)))
|
(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.
|
((looking-at "\\s\"") "") ;A string.
|
||||||
(t
|
(t
|
||||||
(let ((dot (ruby-smie--at-dot-call))
|
(let ((dot (ruby-smie--before-method-name))
|
||||||
(tok (smie-default-forward-token)))
|
(tok (smie-default-forward-token)))
|
||||||
(when dot
|
(when dot
|
||||||
(setq tok (concat "." tok)))
|
(setq tok (concat "." tok)))
|
||||||
|
@ -551,7 +555,7 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
|
||||||
" @ ")
|
" @ ")
|
||||||
(t
|
(t
|
||||||
(let ((tok (smie-default-backward-token))
|
(let ((tok (smie-default-backward-token))
|
||||||
(dot (ruby-smie--at-dot-call)))
|
(dot (ruby-smie--before-method-name)))
|
||||||
(when dot
|
(when dot
|
||||||
(setq tok (concat "." tok)))
|
(setq tok (concat "." tok)))
|
||||||
(cond
|
(cond
|
||||||
|
|
|
@ -203,6 +203,9 @@ def foo
|
||||||
self.end
|
self.end
|
||||||
D.new.class
|
D.new.class
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def begin
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
a = foo(j, k) -
|
a = foo(j, k) -
|
||||||
|
|
Loading…
Add table
Reference in a new issue