(defconst ruby-symbol-re (concat "[" ruby-symbol-chars "]")
"Regexp to match symbols.")
+(defconst ruby-endless-method-head-re
+ (format " *\\(self\\.\\)?%s+[?!]? *\\(([^()]*)\\)? +=" ruby-symbol-re)
+ "Regexp to match the beginning of an endless method definition.
+
+It should match the part after \"def\" and until \"=\".")
+
(defvar ruby-use-smie t)
(make-obsolete-variable 'ruby-use-smie nil "28.1")
(exp (exp1) (exp "," exp) (exp "=" exp)
(id " @ " exp))
(exp1 (exp2) (exp2 "?" exp1 ":" exp1))
- (exp2 (exp3) (exp3 "." exp3))
+ (exp2 (exp3) (exp3 "." exp3)
+ (exp3 "def=" exp3))
(exp3 ("def" insts "end")
("begin" insts-rescue-insts "end")
("do" insts "end")
(ruby-smie--forward-token)) ;Fully redundant.
(t ";")))
((equal tok "&.") ".")
+ ((and (equal tok "def")
+ (looking-at ruby-endless-method-head-re))
+ "def=")
(t tok)))))))))
(defun ruby-smie--backward-token ()
(ruby-smie--backward-token)) ;Fully redundant.
(t ";")))
((equal tok "&.") ".")
+ ((and (equal tok "def")
+ (looking-at (concat "def" ruby-endless-method-head-re)))
+ "def=")
(t tok)))))))
(defun ruby-smie--indent-to-stmt ()
(not (ruby-smie--bosp)))
(forward-char -1))
(smie-indent-virtual))
+ ((save-excursion
+ (and (smie-rule-parent-p " @ ")
+ (goto-char (nth 1 (smie-indent--parent)))
+ (smie-rule-prev-p "def=")
+ (cons 'column (- (current-column) 3)))))
(t (smie-rule-parent))))))
(`(:after . ,(or "(" "[" "{"))
;; FIXME: Shouldn't this be the default behavior of
(and (smie-rule-parent-p ";" nil)
(smie-indent--hanging-p)
ruby-indent-level))
+ (`(:before . "=")
+ (save-excursion
+ (and (smie-rule-parent-p " @ ")
+ (goto-char (nth 1 (smie-indent--parent)))
+ (smie-rule-prev-p "def=")
+ (cons 'column (+ (current-column) ruby-indent-level -3)))))
(`(:after . ,(or "?" ":")) ruby-indent-level)
(`(:before . ,(guard (memq (intern-soft token) ruby-alignable-keywords)))
(when (not (ruby--at-indentation-p))
(while (and (re-search-backward definition-re nil t)
(if (if (string-equal "def" (match-string 1))
;; We're inside a method.
- (if (ruby-block-contains-point start)
+ (if (ruby-block-contains-point (1- start))
t
;; Try to match a method only once.
(setq definition-re module-re)