(defun ruby-smie--redundant-do-p (&optional skip)
(save-excursion
- (if skip (backward-word-strictly 1))
+ (if skip (backward-word 1))
(member (nth 2 (smie-backward-sexp ";")) '("while" "until" "for"))))
(defun ruby-smie--opening-pipe-p ()
(memq (car (syntax-after pos)) '(7 15))
(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)))
- (eq (char-before) ?.)
- (not (eq (char-before (1- (point))) ?.))))
+ (or
+ (and
+ (eq (char-before) ?.)
+ (not (eq (char-before (1- (point))) ?.)))
+ (looking-back "^\\s *def\\s +\\=" (line-beginning-position)))))
(defun ruby-smie--forward-token ()
(let ((pos (point)))
" @ ")
((looking-at "\\s\"") "") ;A string.
(t
- (let ((dot (ruby-smie--at-dot-call))
+ (let ((dot (ruby-smie--before-method-name))
(tok (smie-default-forward-token)))
(when dot
(setq tok (concat "." tok)))
(cond
((member tok '("unless" "if" "while" "until"))
- (if (save-excursion (forward-word-strictly -1) (ruby-smie--bosp))
+ (if (save-excursion (forward-word -1) (ruby-smie--bosp))
tok "iuwu-mod"))
((string-match-p "\\`|[*&]?\\'" tok)
(forward-char (- 1 (length tok)))
" @ ")
(t
(let ((tok (smie-default-backward-token))
- (dot (ruby-smie--at-dot-call)))
+ (dot (ruby-smie--before-method-name)))
(when dot
(setq tok (concat "." tok)))
(cond
((equal tok "do")
(cond
((not (ruby-smie--redundant-do-p)) tok)
- ((> (save-excursion (forward-word-strictly 1)
+ ((> (save-excursion (forward-word 1)
(forward-comment (point-max)) (point))
(line-end-position))
(ruby-smie--backward-token)) ;Fully redundant.
;; us to do better.
(when (not (memq (car (syntax-after (1- (point)))) '(2 3 6 10)))
(or (not (memq (char-before) '(?\s ?\t)))
- (ignore (forward-word-strictly -1))
+ (ignore (forward-word -1))
(eq (char-before) ?_)
(not (looking-at ruby-singleton-class-re))))))
((let ((s (ruby-parse-region (point) ruby-indent-point)))
(and (nth 2 s) (> (nth 2 s) 0)
(or (goto-char (cdr (nth 1 s))) t)))
- (forward-word-strictly -1)
+ (forward-word -1)
(setq indent (ruby-indent-size (current-column)
(nth 2 state))))
(t
(if (null (cdr (nth 1 state)))
(error "Invalid nesting"))
(goto-char (cdr (nth 1 state)))
- (forward-word-strictly -1) ; skip back a keyword
+ (forward-word -1) ; skip back a keyword
(setq begin (point))
(cond
((looking-at "do\\>[^_]") ; iter block is a special case
(forward-char -1)
(not (looking-at "{")))
(progn
- (forward-word-strictly -1)
+ (forward-word -1)
(not (looking-at "do\\>[^_]")))))
(t t))))
(not (eq ?, c))
(not (eq (char-before (point)) ?.))
(not (eq (char-before (point)) ?:)))
(ruby-end-of-block)
- (forward-word-strictly 1))
+ (forward-word 1))
((looking-at "\\(\\$\\|@@?\\)?\\sw")
(while (progn
- (while (progn (forward-word-strictly 1)
- (looking-at "_")))
+ (while (progn (forward-word 1) (looking-at "_")))
(cond ((looking-at "::") (forward-char 2) t)
((> (skip-chars-forward ".") 0))
((looking-at "\\?\\|!\\(=[~=>]\\|[^~=]\\)")
(skip-chars-forward "<"))
(not expr))))
(setq i (1- i)))
- ((error) (forward-word-strictly 1)))
+ ((error) (forward-word 1)))
i))))
(defun ruby-backward-sexp (&optional arg)
((looking-at "\\s(") nil)
(t
(forward-char 1)
- (while (progn (forward-word-strictly -1)
+ (while (progn (forward-word -1)
(pcase (char-before)
(`?_ t)
(`?. (forward-char -1) t)
(syntax-propertize-rules
;; $' $" $` .... are variables.
;; ?' ?" ?` are character literals (one-char strings in 1.9+).
- ("\\([?$]\\)[#\"'`]"
+ ("\\([?$]\\)[#\"'`:?]"
(1 (if (save-excursion
(nth 3 (syntax-ppss (match-beginning 0))))
;; Within a string, skip.
(ignore
(goto-char (match-end 1)))
- (string-to-syntax "\\"))))
+ (put-text-property (match-end 1) (match-end 0)
+ 'syntax-table (string-to-syntax "_"))
+ (string-to-syntax "'"))))
;; Symbols with special characters.
("\\(^\\|[^:]\\)\\(:\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|![~=]?\\|\\[\\]=?\\)\\)"
(3 (string-to-syntax "_")))
1 font-lock-negation-char-face)
;; Character literals.
;; FIXME: Support longer escape sequences.
- ("\\_<\\?\\\\?\\S " 0 font-lock-string-face)
+ ("\\?\\\\?\\_<.\\_>" 0 font-lock-string-face)
;; Regexp options.
("\\(?:\\s|\\|/\\)\\([imxo]+\\)"
1 (when (save-excursion