aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/ruby-mode.el
diff options
context:
space:
mode:
authorDmitry Gutov2013-11-07 05:02:01 +0200
committerDmitry Gutov2013-11-07 05:02:01 +0200
commit1d1c86daf7d8999a1e82e3bbcf0ca5717286a217 (patch)
tree234da1b47bf099ca595b501f8f87530c76ee0370 /lisp/progmodes/ruby-mode.el
parentb420ccfc4cbe081b53881a7c9f0dd6b778b99b99 (diff)
downloademacs-1d1c86daf7d8999a1e82e3bbcf0ca5717286a217.tar.gz
emacs-1d1c86daf7d8999a1e82e3bbcf0ca5717286a217.zip
* lisp/progmodes/ruby-mode.el (ruby-smie--implicit-semi-p):
No implicit semi after "^", "and" or "or". (ruby-smie-grammar): New tokens: "and" and "or". (ruby-smie--args-separator-p): Fix the check for tokens at POS. Exclude "and" and "or". Remove "do" in order to work around token priorities. (ruby-smie-rules): Add all infix tokens. Handle the case of beginning-of-buffer.
Diffstat (limited to 'lisp/progmodes/ruby-mode.el')
-rw-r--r--lisp/progmodes/ruby-mode.el33
1 files changed, 19 insertions, 14 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index b5020344872..05fac2b42f2 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -329,7 +329,8 @@ explicitly declared in magic comment."
329 (nonassoc "==" "===" "!=") 329 (nonassoc "==" "===" "!=")
330 (nonassoc "=~" "!~") 330 (nonassoc "=~" "!~")
331 (left "<<" ">>") 331 (left "<<" ">>")
332 (left "&&" "||")))))) 332 (left "&&" "||")
333 (left "and" "or"))))))
333 334
334(defun ruby-smie--bosp () 335(defun ruby-smie--bosp ()
335 (save-excursion (skip-chars-backward " \t") 336 (save-excursion (skip-chars-backward " \t")
@@ -340,7 +341,7 @@ explicitly declared in magic comment."
340 (skip-chars-backward " \t") 341 (skip-chars-backward " \t")
341 (not (or (bolp) 342 (not (or (bolp)
342 (and (memq (char-before) 343 (and (memq (char-before)
343 '(?\; ?- ?+ ?* ?/ ?: ?. ?, ?\[ ?\( ?\{ ?\\ ?& ?> ?< ?% ?~)) 344 '(?\; ?- ?+ ?* ?/ ?: ?. ?, ?\[ ?\( ?\{ ?\\ ?& ?> ?< ?% ?~ ?^))
344 ;; Make sure it's not the end of a regexp. 345 ;; Make sure it's not the end of a regexp.
345 (not (eq (car (syntax-after (1- (point)))) 7))) 346 (not (eq (car (syntax-after (1- (point)))) 7)))
346 (and (eq (char-before) ?\?) 347 (and (eq (char-before) ?\?)
@@ -349,8 +350,8 @@ explicitly declared in magic comment."
349 (string-match "\\`\\s." (save-excursion 350 (string-match "\\`\\s." (save-excursion
350 (ruby-smie--backward-token)))) 351 (ruby-smie--backward-token))))
351 (and (eq (car (syntax-after (1- (point)))) 2) 352 (and (eq (car (syntax-after (1- (point)))) 2)
352 (equal (save-excursion (ruby-smie--backward-token)) 353 (member (save-excursion (ruby-smie--backward-token))
353 "iuwu-mod")) 354 '("iuwu-mod" "and" "or")))
354 (save-excursion 355 (save-excursion
355 (forward-comment 1) 356 (forward-comment 1)
356 (eq (char-after) ?.)))))) 357 (eq (char-after) ?.))))))
@@ -375,13 +376,15 @@ explicitly declared in magic comment."
375 ;; This isn't very important most of the time, though. 376 ;; This isn't very important most of the time, though.
376 (and (memq (preceding-char) '(?! ??)) 377 (and (memq (preceding-char) '(?! ??))
377 (eq (char-syntax (char-before (1- (point)))) '?w))) 378 (eq (char-syntax (char-before (1- (point)))) '?w)))
378 (or (and (eq (char-syntax (char-after pos)) ?w) 379 (save-excursion
379 (not (looking-at (regexp-opt '("unless" "if" "while" "until" 380 (goto-char pos)
380 "else" "elsif" "do" "end") 381 (or (and (eq (char-syntax (char-after)) ?w)
381 'symbols)))) 382 ;; FIXME: Also "do". But alas, that breaks some
382 (memq (syntax-after pos) '(7 15)) 383 ;; indentation cases.
383 (save-excursion 384 (not (looking-at (regexp-opt '("unless" "if" "while" "until"
384 (goto-char pos) 385 "else" "elsif" "end" "and" "or")
386 'symbols))))
387 (memq (syntax-after pos) '(7 15))
385 (looking-at "\\s(\\|[-+!~:]\\sw"))))) 388 (looking-at "\\s(\\|[-+!~:]\\sw")))))
386 389
387(defun ruby-smie--at-dot-call () 390(defun ruby-smie--at-dot-call ()
@@ -504,7 +507,6 @@ explicitly declared in magic comment."
504 (let ((state (smie-backward-sexp 'halfsexp))) 507 (let ((state (smie-backward-sexp 'halfsexp)))
505 (when (eq t (car state)) (goto-char (cadr state)))) 508 (when (eq t (car state)) (goto-char (cadr state))))
506 (cons 'column (smie-indent-virtual))))) 509 (cons 'column (smie-indent-virtual)))))
507 (`(:after . ,(or "=" "iuwu-mod")) 2)
508 (`(:after . " @ ") (smie-rule-parent)) 510 (`(:after . " @ ") (smie-rule-parent))
509 (`(:before . "do") (smie-rule-parent)) 511 (`(:before . "do") (smie-rule-parent))
510 (`(,(or :before :after) . ".") 512 (`(,(or :before :after) . ".")
@@ -513,8 +515,11 @@ explicitly declared in magic comment."
513 (`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure")) 0) 515 (`(:before . ,(or `"else" `"then" `"elsif" `"rescue" `"ensure")) 0)
514 (`(:before . ,(or `"when")) 516 (`(:before . ,(or `"when"))
515 (if (not (smie-rule-sibling-p)) 0)) ;; ruby-indent-level 517 (if (not (smie-rule-sibling-p)) 0)) ;; ruby-indent-level
516 (`(:after . "+") ;FIXME: Probably applicable to most infix operators. 518 (`(:after . ,(or "=" "iuwu-mod" "+" "-" "*" "/" "&&" "||" "%" "**" "^" "&"
517 (if (smie-rule-parent-p ";") ruby-indent-level)) 519 "<=>" ">" "<" ">=" "<=" "==" "===" "!=" "<<" ">>"
520 "+=" "-=" "*=" "/=" "%=" "**=" "&=" "|=" "^="
521 "<<=" ">>=" "&&=" "||=" "and" "or"))
522 (if (smie-rule-parent-p ";" nil) ruby-indent-level))
518 )) 523 ))
519 524
520(defun ruby-imenu-create-index-in-block (prefix beg end) 525(defun ruby-imenu-create-index-in-block (prefix beg end)