aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/NEWS2
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/progmodes/ruby-mode.el35
3 files changed, 43 insertions, 3 deletions
diff --git a/etc/NEWS b/etc/NEWS
index f681068c1d9..42a81429778 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -599,6 +599,8 @@ rather than mboxo. Customize `unrmail-mbox-format' to change this.
599 599
600*** New option `ruby-align-to-stmt-keywords'. 600*** New option `ruby-align-to-stmt-keywords'.
601 601
602*** New `electric-indent-mode' integration.
603
602** Search and Replace 604** Search and Replace
603 605
604*** New global command `M-s .' (`isearch-forward-symbol-at-point') 606*** New global command `M-s .' (`isearch-forward-symbol-at-point')
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 36877e3dbbe..f6b51d21a30 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,14 @@
12013-12-22 Dmitry Gutov <dgutov@yandex.ru> 12013-12-22 Dmitry Gutov <dgutov@yandex.ru>
2 2
3 * progmodes/ruby-mode.el (ruby--at-indentation-p): New function,
4 extracted from `ruby-smie-rules'.
5 (ruby--electric-indent-chars): New variable.
6 (ruby--electric-indent-p): New function.
7 (ruby-mode): Use `electric-indent-functions' instead of
8 `electric-indent-chars'.
9
102013-12-22 Dmitry Gutov <dgutov@yandex.ru>
11
3 * progmodes/ruby-mode.el (ruby-align-to-stmt-keywords): Tweak the 12 * progmodes/ruby-mode.el (ruby-align-to-stmt-keywords): Tweak the
4 docstring. 13 docstring.
5 (ruby-smie-rules): Indent plus one level after `=>'. 14 (ruby-smie-rules): Indent plus one level after `=>'.
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index fae7ce1f8e6..89c0cfad913 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -631,12 +631,19 @@ It is used when `ruby-encoding-magic-comment-style' is set to `custom'."
631 ruby-indent-level)) 631 ruby-indent-level))
632 (`(:after . ,(or "?" ":")) ruby-indent-level) 632 (`(:after . ,(or "?" ":")) ruby-indent-level)
633 (`(:before . ,(or "if" "while" "unless" "until" "begin" "case" "for")) 633 (`(:before . ,(or "if" "while" "unless" "until" "begin" "case" "for"))
634 (when (not (save-excursion (skip-chars-backward " \t") (bolp))) 634 (when (not (ruby--at-indentation-p))
635 (if (ruby-smie--indent-to-stmt-p token) 635 (if (ruby-smie--indent-to-stmt-p token)
636 (ruby-smie--indent-to-stmt) 636 (ruby-smie--indent-to-stmt)
637 (cons 'column (current-column))))) 637 (cons 'column (current-column)))))
638 )) 638 ))
639 639
640(defun ruby--at-indentation-p (&optional point)
641 (save-excursion
642 (unless point (setq point (point)))
643 (forward-line 0)
644 (skip-chars-forward " \t")
645 (eq (point) point)))
646
640(defun ruby-imenu-create-index-in-block (prefix beg end) 647(defun ruby-imenu-create-index-in-block (prefix beg end)
641 "Create an imenu index of methods inside a block." 648 "Create an imenu index of methods inside a block."
642 (let ((index-alist '()) (case-fold-search nil) 649 (let ((index-alist '()) (case-fold-search nil)
@@ -767,6 +774,29 @@ The style of the comment is controlled by `ruby-encoding-magic-comment-style'."
767 (when (buffer-modified-p) 774 (when (buffer-modified-p)
768 (basic-save-buffer-1))))))) 775 (basic-save-buffer-1)))))))
769 776
777(defvar ruby--electric-indent-chars '(?. ?\) ?} ?\]))
778
779(defun ruby--electric-indent-p (char)
780 (cond
781 ((memq char ruby--electric-indent-chars)
782 ;; Outdent after typing a closing paren.
783 (ruby--at-indentation-p (1- (point))))
784 ((memq (char-after) ruby--electric-indent-chars)
785 ;; Reindent after inserting something before a closing paren.
786 (ruby--at-indentation-p (1- (point))))
787 ((or (memq (char-syntax char) '(?w ?_)))
788 (let ((pt (point)))
789 (save-excursion
790 (skip-syntax-backward "w_")
791 (and (ruby--at-indentation-p)
792 (looking-at (regexp-opt (cons "end" ruby-block-mid-keywords)))
793 ;; Outdent after typing a keyword.
794 (or (eq (match-end 0) pt)
795 ;; Reindent if it wasn't a keyword after all.
796 (eq (match-end 0) (1- pt)))))))))
797
798;; FIXME: Remove this? It's unused here, but some redefinitions of
799;; `ruby-calculate-indent' in user init files still call it.
770(defun ruby-current-indentation () 800(defun ruby-current-indentation ()
771 "Return the indentation level of current line." 801 "Return the indentation level of current line."
772 (save-excursion 802 (save-excursion
@@ -2081,8 +2111,7 @@ See `font-lock-syntax-table'.")
2081 (setq-local end-of-defun-function 'ruby-end-of-defun) 2111 (setq-local end-of-defun-function 'ruby-end-of-defun)
2082 2112
2083 (add-hook 'after-save-hook 'ruby-mode-set-encoding nil 'local) 2113 (add-hook 'after-save-hook 'ruby-mode-set-encoding nil 'local)
2084 2114 (add-hook 'electric-indent-functions 'ruby--electric-indent-p nil 'local)
2085 (setq-local electric-indent-chars (append '(?\{ ?\}) electric-indent-chars))
2086 2115
2087 (setq-local font-lock-defaults '((ruby-font-lock-keywords) nil nil)) 2116 (setq-local font-lock-defaults '((ruby-font-lock-keywords) nil nil))
2088 (setq-local font-lock-keywords ruby-font-lock-keywords) 2117 (setq-local font-lock-keywords ruby-font-lock-keywords)