diff options
| author | Dmitry Gutov | 2012-11-13 13:30:16 +0400 |
|---|---|---|
| committer | Dmitry Gutov | 2012-11-13 13:30:16 +0400 |
| commit | 5745cae6984ed60299a89485aaea8f2f3fb67382 (patch) | |
| tree | d2566ee6ff5a0d45607b57f56a287374504ce2d9 /lisp | |
| parent | 2a14f83bbdb59565f3e4bffa8e583270e10cf92c (diff) | |
| download | emacs-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.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/progmodes/ruby-mode.el | 40 |
2 files changed, 24 insertions, 22 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index bab44db48a1..fc69b8643b6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2012-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 | |||
| 1 | 2012-11-13 Stefan Monnier <monnier@iro.umontreal.ca> | 7 | 2012-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 | ||
| 1038 | See `add-log-current-defun-function'." | 1038 | See `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 |