aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2012-11-13 13:30:16 +0400
committerDmitry Gutov2012-11-13 13:30:16 +0400
commit5745cae6984ed60299a89485aaea8f2f3fb67382 (patch)
treed2566ee6ff5a0d45607b57f56a287374504ce2d9
parent2a14f83bbdb59565f3e4bffa8e583270e10cf92c (diff)
downloademacs-5745cae6984ed60299a89485aaea8f2f3fb67382.tar.gz
emacs-5745cae6984ed60299a89485aaea8f2f3fb67382.zip
* lisp/progmodes/ruby-mode.el (ruby-add-log-current-method): Print the
period before class method names, not after. Remove handling of one impossible case. Add comments. * test/automated/ruby-mode-tests.el (ruby-add-log-current-method-examples): New test. (ruby-test-string): Extract from ruby-should-indent-buffer.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/progmodes/ruby-mode.el40
-rw-r--r--test/ChangeLog4
-rw-r--r--test/automated/ruby-mode-tests.el32
4 files changed, 54 insertions, 28 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index bab44db48a1..fc69b8643b6 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12012-11-13 Dmitry Gutov <dgutov@yandex.ru>
2
3 * progmodes/ruby-mode.el (ruby-add-log-current-method): Print the
4 period before class method names, not after. Remove handling of
5 one impossible case. Add comments.
6
12012-11-13 Stefan Monnier <monnier@iro.umontreal.ca> 72012-11-13 Stefan Monnier <monnier@iro.umontreal.ca>
2 8
3 * emacs-lisp/advice.el: Remove support for freezing. 9 * emacs-lisp/advice.el: Remove support for freezing.
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 9d2c6fa51f7..7c72b73a879 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -1033,21 +1033,19 @@ For example:
1033 #exit 1033 #exit
1034 String#gsub 1034 String#gsub
1035 Net::HTTP#active? 1035 Net::HTTP#active?
1036 File::open. 1036 File.open
1037 1037
1038See `add-log-current-defun-function'." 1038See `add-log-current-defun-function'."
1039 ;; TODO: Document body
1040 ;; Why does this append a period to class methods?
1041 (condition-case nil 1039 (condition-case nil
1042 (save-excursion 1040 (save-excursion
1043 (let (mname mlist (indent 0)) 1041 (let (mname mlist (indent 0))
1044 ;; get current method (or class/module) 1042 ;; Get the current method definition (or class/module).
1045 (if (re-search-backward 1043 (if (re-search-backward
1046 (concat "^[ \t]*" ruby-defun-beg-re "[ \t]+" 1044 (concat "^[ \t]*" ruby-defun-beg-re "[ \t]+"
1047 "\\(" 1045 "\\("
1048 ;; \\. and :: for class method 1046 ;; \\. and :: for class methods
1049 "\\([A-Za-z_]" ruby-symbol-re "*\\|\\.\\|::" "\\)" 1047 "\\([A-Za-z_]" ruby-symbol-re "*\\|\\.\\|::" "\\)"
1050 "+\\)") 1048 "+\\)")
1051 nil t) 1049 nil t)
1052 (progn 1050 (progn
1053 (setq mname (match-string 2)) 1051 (setq mname (match-string 2))
@@ -1056,7 +1054,7 @@ See `add-log-current-defun-function'."
1056 (goto-char (match-beginning 1)) 1054 (goto-char (match-beginning 1))
1057 (setq indent (current-column)) 1055 (setq indent (current-column))
1058 (beginning-of-line))) 1056 (beginning-of-line)))
1059 ;; nest class/module 1057 ;; Walk up the class/module nesting.
1060 (while (and (> indent 0) 1058 (while (and (> indent 0)
1061 (re-search-backward 1059 (re-search-backward
1062 (concat 1060 (concat
@@ -1069,28 +1067,26 @@ See `add-log-current-defun-function'."
1069 (setq mlist (cons (match-string 2) mlist)) 1067 (setq mlist (cons (match-string 2) mlist))
1070 (setq indent (current-column)) 1068 (setq indent (current-column))
1071 (beginning-of-line)))) 1069 (beginning-of-line))))
1070 ;; Process the method name.
1072 (when mname 1071 (when mname
1073 (let ((mn (split-string mname "\\.\\|::"))) 1072 (let ((mn (split-string mname "\\.\\|::")))
1074 (if (cdr mn) 1073 (if (cdr mn)
1075 (progn 1074 (progn
1076 (cond 1075 (unless (string-equal "self" (car mn)) ; def self.foo
1077 ((string-equal "" (car mn)) 1076 ;; def C.foo
1078 (setq mn (cdr mn) mlist nil)) 1077 (let ((ml (nreverse mlist)))
1079 ((string-equal "self" (car mn)) 1078 ;; If the method name references one of the
1080 (setq mn (cdr mn))) 1079 ;; containing modules, drop the more nested ones.
1081 ((let ((ml (nreverse mlist)))
1082 (while ml 1080 (while ml
1083 (if (string-equal (car ml) (car mn)) 1081 (if (string-equal (car ml) (car mn))
1084 (setq mlist (nreverse (cdr ml)) ml nil)) 1082 (setq mlist (nreverse (cdr ml)) ml nil))
1085 (or (setq ml (cdr ml)) (nreverse mlist)))))) 1083 (or (setq ml (cdr ml)) (nreverse mlist))))
1086 (if mlist 1084 (if mlist
1087 (setcdr (last mlist) mn) 1085 (setcdr (last mlist) (butlast mn))
1088 (setq mlist mn)) 1086 (setq mlist (butlast mn))))
1089 (setq mn (last mn 2)) 1087 (setq mname (concat "." (car (last mn)))))
1090 (setq mname (concat "." (cadr mn)))
1091 (setcdr mn nil))
1092 (setq mname (concat "#" mname))))) 1088 (setq mname (concat "#" mname)))))
1093 ;; generate string 1089 ;; Generate the string.
1094 (if (consp mlist) 1090 (if (consp mlist)
1095 (setq mlist (mapconcat (function identity) mlist "::"))) 1091 (setq mlist (mapconcat (function identity) mlist "::")))
1096 (if mname 1092 (if mname
diff --git a/test/ChangeLog b/test/ChangeLog
index ad136117c1d..44c013e9887 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,7 +1,9 @@
12012-11-13 Dmitry Gutov <dgutov@yandex.ru> 12012-11-13 Dmitry Gutov <dgutov@yandex.ru>
2 2
3 * automated/ruby-mode-tests.el (ruby-heredoc-font-lock) 3 * automated/ruby-mode-tests.el (ruby-heredoc-font-lock)
4 (ruby-singleton-class-no-heredoc-font-lock): New tests. 4 (ruby-singleton-class-no-heredoc-font-lock)
5 (ruby-add-log-current-method-examples): New tests.
6 (ruby-test-string): Extract from ruby-should-indent-buffer.
5 7
62012-11-12 Stefan Monnier <monnier@iro.umontreal.ca> 82012-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
7 9
diff --git a/test/automated/ruby-mode-tests.el b/test/automated/ruby-mode-tests.el
index 741692a07f7..0e41b2ba1e2 100644
--- a/test/automated/ruby-mode-tests.el
+++ b/test/automated/ruby-mode-tests.el
@@ -36,11 +36,13 @@
36 36
37The whitespace before and including \"|\" on each line is removed." 37The whitespace before and including \"|\" on each line is removed."
38 (with-temp-buffer 38 (with-temp-buffer
39 (cl-flet ((fix-indent (s) (replace-regexp-in-string "^[ \t]*|" "" s))) 39 (insert (ruby-test-string content))
40 (insert (fix-indent content)) 40 (ruby-mode)
41 (ruby-mode) 41 (indent-region (point-min) (point-max))
42 (indent-region (point-min) (point-max)) 42 (should (string= (ruby-test-string expected) (buffer-string)))))
43 (should (string= (fix-indent expected) (buffer-string)))))) 43
44(defun ruby-test-string (s &rest args)
45 (apply 'format (replace-regexp-in-string "^[ \t]*|" "" s) args))
44 46
45(defun ruby-assert-state (content &rest values-plist) 47(defun ruby-assert-state (content &rest values-plist)
46 "Assert syntax state values at the end of CONTENT. 48 "Assert syntax state values at the end of CONTENT.
@@ -261,6 +263,26 @@ VALUES-PLIST is a list with alternating index and value elements."
261 (ruby-assert-face "# #{comment}\n \"#{interpolation}\"" 16 263 (ruby-assert-face "# #{comment}\n \"#{interpolation}\"" 16
262 'font-lock-variable-name-face)) 264 'font-lock-variable-name-face))
263 265
266(ert-deftest ruby-add-log-current-method-examples ()
267 (let ((pairs '(("foo" . "#foo")
268 ("C.foo" . ".foo")
269 ("self.foo" . ".foo"))))
270 (loop for (name . value) in pairs
271 do (with-temp-buffer
272 (insert (ruby-test-string
273 "module M
274 | class C
275 | def %s
276 | end
277 | end
278 |end"
279 name))
280 (ruby-mode)
281 (search-backward "def")
282 (forward-line)
283 (should (string= (ruby-add-log-current-method)
284 (format "M::C%s" value)))))))
285
264(provide 'ruby-mode-tests) 286(provide 'ruby-mode-tests)
265 287
266;;; ruby-mode-tests.el ends here 288;;; ruby-mode-tests.el ends here