aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2013-02-14 09:45:33 +0400
committerDmitry Gutov2013-02-14 09:45:33 +0400
commit71a048c16b1a3c8708c161b38e52155b77d0ea60 (patch)
tree84895b1fc0a34f1b914a08fd04c9fd2398f8fcf1
parent53ca88c478b773f2b56084442c8d17e83577f52c (diff)
downloademacs-71a048c16b1a3c8708c161b38e52155b77d0ea60.tar.gz
emacs-71a048c16b1a3c8708c161b38e52155b77d0ea60.zip
(ruby-add-log-current-method): Improve performance at the expense
of accuracy. `ruby-block-contains-point' is relatively slow, so only use it for method and singleton class blocks. * test/automated/ruby-mode-tests.el (ruby-add-log-current-method-after-inner-class): Lower expectations: move point inside a method, initially.
-rw-r--r--lisp/ChangeLog3
-rw-r--r--lisp/progmodes/ruby-mode.el41
-rw-r--r--test/ChangeLog2
-rw-r--r--test/automated/ruby-mode-tests.el6
4 files changed, 35 insertions, 17 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index fd520361889..6daf062814e 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -4,6 +4,9 @@
4 depth for unfinished percent literal. Not using it in the caller. 4 depth for unfinished percent literal. Not using it in the caller.
5 (ruby-move-to-block): Jump over multiline literals of all types, 5 (ruby-move-to-block): Jump over multiline literals of all types,
6 ignoring code-looking contents inside them. 6 ignoring code-looking contents inside them.
7 (ruby-add-log-current-method): Improve performance at the expense
8 of accuracy. `ruby-block-contains-point' is relatively slow, so
9 only use it for method and singleton class blocks.
7 10
82013-02-13 Michael Albinus <michael.albinus@gmx.de> 112013-02-13 Michael Albinus <michael.albinus@gmx.de>
9 12
diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index 453d08fc47b..9b007c0063a 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -1073,29 +1073,33 @@ For example:
1073See `add-log-current-defun-function'." 1073See `add-log-current-defun-function'."
1074 (condition-case nil 1074 (condition-case nil
1075 (save-excursion 1075 (save-excursion
1076 (let ((indent 0) mname mlist 1076 (let* ((indent 0) mname mlist
1077 (start (point)) 1077 (start (point))
1078 (definition-re 1078 (make-definition-re
1079 (concat "^[ \t]*" ruby-defun-beg-re "[ \t]+" 1079 (lambda (re)
1080 "\\(" 1080 (concat "^[ \t]*" re "[ \t]+"
1081 ;; \\. and :: for class methods 1081 "\\("
1082 "\\([A-Za-z_]" ruby-symbol-re "*\\|\\.\\|::" "\\)" 1082 ;; \\. and :: for class methods
1083 "+\\)"))) 1083 "\\([A-Za-z_]" ruby-symbol-re "*\\|\\.\\|::" "\\)"
1084 "+\\)")))
1085 (definition-re (funcall make-definition-re ruby-defun-beg-re))
1086 (module-re (funcall make-definition-re "\\(class\\|module\\)")))
1084 ;; Get the current method definition (or class/module). 1087 ;; Get the current method definition (or class/module).
1085 (when (re-search-backward definition-re nil t) 1088 (when (re-search-backward definition-re nil t)
1086 (goto-char (match-beginning 1)) 1089 (goto-char (match-beginning 1))
1087 (when (ruby-block-contains-point start) 1090 (if (not (string-equal "def" (match-string 1)))
1088 ;; We're inside the method, class or module. 1091 (setq mlist (list (match-string 2)))
1089 (setq mname (match-string 2)) 1092 ;; We're inside the method. For classes and modules,
1090 (unless (string-equal "def" (match-string 1)) 1093 ;; this check is skipped for performance.
1091 (setq mlist (list mname) mname nil))) 1094 (when (ruby-block-contains-point start)
1095 (setq mname (match-string 2))))
1092 (setq indent (current-column)) 1096 (setq indent (current-column))
1093 (beginning-of-line)) 1097 (beginning-of-line))
1094 ;; Walk up the class/module nesting. 1098 ;; Walk up the class/module nesting.
1095 (while (and (> indent 0) 1099 (while (and (> indent 0)
1096 (re-search-backward definition-re nil t)) 1100 (re-search-backward module-re nil t))
1097 (goto-char (match-beginning 1)) 1101 (goto-char (match-beginning 1))
1098 (when (ruby-block-contains-point start) 1102 (when (< (current-column) indent)
1099 (setq mlist (cons (match-string 2) mlist)) 1103 (setq mlist (cons (match-string 2) mlist))
1100 (setq indent (current-column)) 1104 (setq indent (current-column))
1101 (beginning-of-line))) 1105 (beginning-of-line)))
@@ -1121,6 +1125,13 @@ See `add-log-current-defun-function'."
1121 (let ((in-singleton-class 1125 (let ((in-singleton-class
1122 (when (re-search-forward ruby-singleton-class-re start t) 1126 (when (re-search-forward ruby-singleton-class-re start t)
1123 (goto-char (match-beginning 0)) 1127 (goto-char (match-beginning 0))
1128 ;; FIXME: Optimize it out, too?
1129 ;; This can be slow in a large file, but
1130 ;; unlike class/module declaration
1131 ;; indentations, method definitions can be
1132 ;; intermixed with these, and may or may not
1133 ;; be additionally indented after visibility
1134 ;; keywords.
1124 (ruby-block-contains-point start)))) 1135 (ruby-block-contains-point start))))
1125 (setq mname (concat 1136 (setq mname (concat
1126 (if in-singleton-class "." "#") 1137 (if in-singleton-class "." "#")
diff --git a/test/ChangeLog b/test/ChangeLog
index 7e08eccc2e3..7fed4f29408 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -4,6 +4,8 @@
4 (ruby-move-to-block-skips-percent-literal): Add depth-affecting 4 (ruby-move-to-block-skips-percent-literal): Add depth-affecting
5 bits inside the examples. 5 bits inside the examples.
6 (ruby-move-to-block-skips-heredoc): New test. 6 (ruby-move-to-block-skips-heredoc): New test.
7 (ruby-add-log-current-method-after-inner-class): Lower
8 expectations: move point inside a method, initially.
7 9
82013-02-13 Dmitry Gutov <dgutov@yandex.ru> 102013-02-13 Dmitry Gutov <dgutov@yandex.ru>
9 11
diff --git a/test/automated/ruby-mode-tests.el b/test/automated/ruby-mode-tests.el
index 9ee6462f6ad..c67f92e6ed9 100644
--- a/test/automated/ruby-mode-tests.el
+++ b/test/automated/ruby-mode-tests.el
@@ -390,11 +390,13 @@ VALUES-PLIST is a list with alternating index and value elements."
390 | class C 390 | class C
391 | class D 391 | class D
392 | end 392 | end
393 | _ 393 | def foo
394 | _
395 | end
394 | end 396 | end
395 |end") 397 |end")
396 (search-backward "_") 398 (search-backward "_")
397 (should (string= (ruby-add-log-current-method) "M::C")))) 399 (should (string= (ruby-add-log-current-method) "M::C#foo"))))
398 400
399(defvar ruby-block-test-example 401(defvar ruby-block-test-example
400 (ruby-test-string 402 (ruby-test-string