aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/ruby-mode.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/ruby-mode.el')
-rw-r--r--lisp/progmodes/ruby-mode.el57
1 files changed, 23 insertions, 34 deletions
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 84cf7308d75..7c72b73a879 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -898,17 +898,7 @@ or blocks containing the current block."
898 (back-to-indentation) 898 (back-to-indentation)
899 (if (looking-at (concat "\\<\\(" ruby-block-mid-re "\\)\\>")) 899 (if (looking-at (concat "\\<\\(" ruby-block-mid-re "\\)\\>"))
900 (setq done nil))))) 900 (setq done nil)))))
901 (back-to-indentation) 901 (back-to-indentation)))
902 (when (< n 0)
903 (let ((eol (point-at-eol)) state next)
904 (if (< orig eol) (setq eol orig))
905 (setq orig (point))
906 (while (and (setq next (apply 'ruby-parse-partial eol state))
907 (< (point) eol))
908 (setq state next))
909 (when (cdaadr state)
910 (goto-char (cdaadr state)))
911 (backward-word)))))
912 902
913(defun ruby-beginning-of-block (&optional arg) 903(defun ruby-beginning-of-block (&optional arg)
914 "Move backward to the beginning of the current block. 904 "Move backward to the beginning of the current block.
@@ -1043,21 +1033,19 @@ For example:
1043 #exit 1033 #exit
1044 String#gsub 1034 String#gsub
1045 Net::HTTP#active? 1035 Net::HTTP#active?
1046 File::open. 1036 File.open
1047 1037
1048See `add-log-current-defun-function'." 1038See `add-log-current-defun-function'."
1049 ;; TODO: Document body
1050 ;; Why does this append a period to class methods?
1051 (condition-case nil 1039 (condition-case nil
1052 (save-excursion 1040 (save-excursion
1053 (let (mname mlist (indent 0)) 1041 (let (mname mlist (indent 0))
1054 ;; get current method (or class/module) 1042 ;; Get the current method definition (or class/module).
1055 (if (re-search-backward 1043 (if (re-search-backward
1056 (concat "^[ \t]*" ruby-defun-beg-re "[ \t]+" 1044 (concat "^[ \t]*" ruby-defun-beg-re "[ \t]+"
1057 "\\(" 1045 "\\("
1058 ;; \\. and :: for class method 1046 ;; \\. and :: for class methods
1059 "\\([A-Za-z_]" ruby-symbol-re "*\\|\\.\\|::" "\\)" 1047 "\\([A-Za-z_]" ruby-symbol-re "*\\|\\.\\|::" "\\)"
1060 "+\\)") 1048 "+\\)")
1061 nil t) 1049 nil t)
1062 (progn 1050 (progn
1063 (setq mname (match-string 2)) 1051 (setq mname (match-string 2))
@@ -1066,7 +1054,7 @@ See `add-log-current-defun-function'."
1066 (goto-char (match-beginning 1)) 1054 (goto-char (match-beginning 1))
1067 (setq indent (current-column)) 1055 (setq indent (current-column))
1068 (beginning-of-line))) 1056 (beginning-of-line)))
1069 ;; nest class/module 1057 ;; Walk up the class/module nesting.
1070 (while (and (> indent 0) 1058 (while (and (> indent 0)
1071 (re-search-backward 1059 (re-search-backward
1072 (concat 1060 (concat
@@ -1079,28 +1067,26 @@ See `add-log-current-defun-function'."
1079 (setq mlist (cons (match-string 2) mlist)) 1067 (setq mlist (cons (match-string 2) mlist))
1080 (setq indent (current-column)) 1068 (setq indent (current-column))
1081 (beginning-of-line)))) 1069 (beginning-of-line))))
1070 ;; Process the method name.
1082 (when mname 1071 (when mname
1083 (let ((mn (split-string mname "\\.\\|::"))) 1072 (let ((mn (split-string mname "\\.\\|::")))
1084 (if (cdr mn) 1073 (if (cdr mn)
1085 (progn 1074 (progn
1086 (cond 1075 (unless (string-equal "self" (car mn)) ; def self.foo
1087 ((string-equal "" (car mn)) 1076 ;; def C.foo
1088 (setq mn (cdr mn) mlist nil)) 1077 (let ((ml (nreverse mlist)))
1089 ((string-equal "self" (car mn)) 1078 ;; If the method name references one of the
1090 (setq mn (cdr mn))) 1079 ;; containing modules, drop the more nested ones.
1091 ((let ((ml (nreverse mlist)))
1092 (while ml 1080 (while ml
1093 (if (string-equal (car ml) (car mn)) 1081 (if (string-equal (car ml) (car mn))
1094 (setq mlist (nreverse (cdr ml)) ml nil)) 1082 (setq mlist (nreverse (cdr ml)) ml nil))
1095 (or (setq ml (cdr ml)) (nreverse mlist)))))) 1083 (or (setq ml (cdr ml)) (nreverse mlist))))
1096 (if mlist 1084 (if mlist
1097 (setcdr (last mlist) mn) 1085 (setcdr (last mlist) (butlast mn))
1098 (setq mlist mn)) 1086 (setq mlist (butlast mn))))
1099 (setq mn (last mn 2)) 1087 (setq mname (concat "." (car (last mn)))))
1100 (setq mname (concat "." (cadr mn)))
1101 (setcdr mn nil))
1102 (setq mname (concat "#" mname))))) 1088 (setq mname (concat "#" mname)))))
1103 ;; generate string 1089 ;; Generate the string.
1104 (if (consp mlist) 1090 (if (consp mlist)
1105 (setq mlist (mapconcat (function identity) mlist "::"))) 1091 (setq mlist (mapconcat (function identity) mlist "::")))
1106 (if mname 1092 (if mname
@@ -1561,7 +1547,8 @@ See `font-lock-syntax-table'.")
1561 ruby-keyword-end-re) 1547 ruby-keyword-end-re)
1562 2) 1548 2)
1563 ;; here-doc beginnings 1549 ;; here-doc beginnings
1564 (list ruby-here-doc-beg-re 0 'font-lock-string-face) 1550 `(,ruby-here-doc-beg-re 0 (unless (ruby-singleton-class-p (match-beginning 0))
1551 'font-lock-string-face))
1565 ;; variables 1552 ;; variables
1566 '("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(nil\\|self\\|true\\|false\\)\\>" 1553 '("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(nil\\|self\\|true\\|false\\)\\>"
1567 2 font-lock-variable-name-face) 1554 2 font-lock-variable-name-face)
@@ -1638,6 +1625,8 @@ The variable `ruby-indent-level' controls the amount of indentation.
1638 1625
1639;;;###autoload 1626;;;###autoload
1640(add-to-list 'auto-mode-alist (cons (purecopy "\\.rb\\'") 'ruby-mode)) 1627(add-to-list 'auto-mode-alist (cons (purecopy "\\.rb\\'") 'ruby-mode))
1628;;;###autoload
1629(add-to-list 'auto-mode-alist '("Rakefile\\'" . ruby-mode))
1641 1630
1642;;;###autoload 1631;;;###autoload
1643(dolist (name (list "ruby" "rbx" "jruby" "ruby1.9" "ruby1.8")) 1632(dolist (name (list "ruby" "rbx" "jruby" "ruby1.9" "ruby1.8"))