+2013-11-08 Dmitry Gutov <dgutov@yandex.ru>
+
+ * progmodes/ruby-mode.el (ruby-smie-grammar): Improve precedences
+ of "and", "or", "&&" and "||".
+ (ruby-smie--args-separator-p): Prohibit keyword "do" as the first
+ argument. Prohibit opening curly brace because it could only be a
+ block opener in that position.
+ (ruby-smie--forward-token, ruby-smie--backward-token): Separate
+ "|" from "&" or "*" going after it. That can happen in block
+ arguments.
+ (ruby-smie--indent-to-stmt): New function, seeks the end of
+ previous statement or beginning of buffer.
+ (ruby-smie-rules): Use it.
+ (ruby-smie-rules): Check if there's a ":" before a curly block
+ opener candidate; if there is, it's a hash.
+
2013-11-07 Stefan Monnier <monnier@iro.umontreal.ca>
* emacs-lisp/cl-macs.el (cl-symbol-macrolet): Use macroexp-progn.
(smie-bnf->prec2
'((id)
(insts (inst) (insts ";" insts))
- (inst (exp) (inst "iuwu-mod" exp))
+ (inst (exp) (inst "iuwu-mod" exp)
+ ;; Somewhat incorrect (both can be used multiple times),
+ ;; but avoids lots of conflicts:
+ (exp "and" exp) (exp "or" exp))
(exp (exp1) (exp "," exp) (exp "=" exp)
(id " @ " exp)
(exp "." id))
(left "+" "-")
(left "*" "/" "%" "**")
;; (left "|") ; FIXME: Conflicts with | after block parameters.
+ (left "&&" "||")
(left "^" "&")
(nonassoc "<=>")
(nonassoc ">" ">=" "<" "<=")
(nonassoc "==" "===" "!=")
(nonassoc "=~" "!~")
- (left "<<" ">>")
- (left "&&" "||")
- (left "and" "or"))))))
+ (left "<<" ">>"))))))
(defun ruby-smie--bosp ()
(save-excursion (skip-chars-backward " \t")
(save-excursion
(goto-char pos)
(or (and (eq (char-syntax (char-after)) ?w)
- ;; FIXME: Also "do". But alas, that breaks some
- ;; indentation cases.
(not (looking-at (regexp-opt '("unless" "if" "while" "until"
- "else" "elsif" "end" "and" "or")
+ "else" "elsif" "do" "end" "and" "or")
'symbols))))
(memq (syntax-after pos) '(7 15))
- (looking-at "\\s(\\|[-+!~:]\\sw")))))
+ (looking-at "[([]\\|[-+!~:]\\sw")))))
(defun ruby-smie--at-dot-call ()
(and (eq ?w (char-syntax (following-char)))
((member tok '("unless" "if" "while" "until"))
(if (save-excursion (forward-word -1) (ruby-smie--bosp))
tok "iuwu-mod"))
- ((equal tok "|")
+ ((string-match "|[*&]?" tok)
+ (forward-char (- 1 (length tok)))
+ (setq tok "|")
(if (ruby-smie--opening-pipe-p) "opening-|" tok))
((and (equal tok "") (looking-at "\\\\\n"))
(goto-char (match-end 0)) (ruby-smie--forward-token))
tok "iuwu-mod"))
((equal tok "|")
(if (ruby-smie--opening-pipe-p) "opening-|" tok))
+ ((string-match-p "|[*&]" tok)
+ (forward-char 1)
+ (substring tok 1))
((and (equal tok "") (eq ?\\ (char-before)) (looking-at "\n"))
(forward-char -1) (ruby-smie--backward-token))
((equal tok "do")
(t ";")))
(t tok)))))))
+(defun ruby-smie--indent-to-stmt ()
+ (save-excursion
+ (let (parent)
+ (while (not (or (eq (car parent) t)
+ (equal (nth 2 parent) ";")))
+ (setq parent (let (smie--parent) (smie-indent--parent)))
+ (when (numberp (nth 1 parent))
+ (goto-char (nth 1 parent))))
+ (cons 'column (smie-indent-virtual)))))
+
(defun ruby-smie-rules (kind token)
(pcase (cons kind token)
(`(:elem . basic) ruby-indent-level)
(`(:before . ,(or `"(" `"[" `"{"))
(cond
((and (equal token "{")
- (not (smie-rule-prev-p "(" "{" "[" "," "=>" "=" "return" ";")))
+ (not (smie-rule-prev-p "(" "{" "[" "," "=>" "=" "return" ";"))
+ (save-excursion
+ (forward-comment -1)
+ (not (eq (preceding-char) ?:))))
;; Curly block opener.
- (smie-rule-parent))
+ (ruby-smie--indent-to-stmt))
((smie-rule-hanging-p)
;; Treat purely syntactic block-constructs as being part of their parent,
;; when the opening statement is hanging.
(when (eq t (car state)) (goto-char (cadr state))))
(cons 'column (smie-indent-virtual)))))
(`(:after . " @ ") (smie-rule-parent))
- (`(:before . "do") (smie-rule-parent))
+ (`(:before . "do") (ruby-smie--indent-to-stmt))
(`(,(or :before :after) . ".")
(unless (smie-rule-parent-p ".")
(smie-rule-parent ruby-indent-level)))