[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] /srv/bzr/emacs/trunk r111777: (ruby-add-log-current-method
From: |
Dmitry Gutov |
Subject: |
[Emacs-diffs] /srv/bzr/emacs/trunk r111777: (ruby-add-log-current-method): Improve performance at the expense |
Date: |
Thu, 14 Feb 2013 09:45:33 +0400 |
User-agent: |
Bazaar (2.5.0) |
------------------------------------------------------------
revno: 111777
committer: Dmitry Gutov <address@hidden>
branch nick: trunk
timestamp: Thu 2013-02-14 09:45:33 +0400
message:
(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.
modified:
lisp/ChangeLog
lisp/progmodes/ruby-mode.el
test/ChangeLog
test/automated/ruby-mode-tests.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog 2013-02-14 03:33:55 +0000
+++ b/lisp/ChangeLog 2013-02-14 05:45:33 +0000
@@ -4,6 +4,9 @@
depth for unfinished percent literal. Not using it in the caller.
(ruby-move-to-block): Jump over multiline literals of all types,
ignoring code-looking contents inside them.
+ (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.
2013-02-13 Michael Albinus <address@hidden>
=== modified file 'lisp/progmodes/ruby-mode.el'
--- a/lisp/progmodes/ruby-mode.el 2013-02-14 03:33:55 +0000
+++ b/lisp/progmodes/ruby-mode.el 2013-02-14 05:45:33 +0000
@@ -1073,29 +1073,33 @@
See `add-log-current-defun-function'."
(condition-case nil
(save-excursion
- (let ((indent 0) mname mlist
- (start (point))
- (definition-re
- (concat "^[ \t]*" ruby-defun-beg-re "[ \t]+"
- "\\("
- ;; \\. and :: for class methods
- "\\([A-Za-z_]" ruby-symbol-re "*\\|\\.\\|::" "\\)"
- "+\\)")))
+ (let* ((indent 0) mname mlist
+ (start (point))
+ (make-definition-re
+ (lambda (re)
+ (concat "^[ \t]*" re "[ \t]+"
+ "\\("
+ ;; \\. and :: for class methods
+ "\\([A-Za-z_]" ruby-symbol-re "*\\|\\.\\|::" "\\)"
+ "+\\)")))
+ (definition-re (funcall make-definition-re ruby-defun-beg-re))
+ (module-re (funcall make-definition-re "\\(class\\|module\\)")))
;; Get the current method definition (or class/module).
(when (re-search-backward definition-re nil t)
(goto-char (match-beginning 1))
- (when (ruby-block-contains-point start)
- ;; We're inside the method, class or module.
- (setq mname (match-string 2))
- (unless (string-equal "def" (match-string 1))
- (setq mlist (list mname) mname nil)))
+ (if (not (string-equal "def" (match-string 1)))
+ (setq mlist (list (match-string 2)))
+ ;; We're inside the method. For classes and modules,
+ ;; this check is skipped for performance.
+ (when (ruby-block-contains-point start)
+ (setq mname (match-string 2))))
(setq indent (current-column))
(beginning-of-line))
;; Walk up the class/module nesting.
(while (and (> indent 0)
- (re-search-backward definition-re nil t))
+ (re-search-backward module-re nil t))
(goto-char (match-beginning 1))
- (when (ruby-block-contains-point start)
+ (when (< (current-column) indent)
(setq mlist (cons (match-string 2) mlist))
(setq indent (current-column))
(beginning-of-line)))
@@ -1121,6 +1125,13 @@
(let ((in-singleton-class
(when (re-search-forward ruby-singleton-class-re start
t)
(goto-char (match-beginning 0))
+ ;; FIXME: Optimize it out, too?
+ ;; This can be slow in a large file, but
+ ;; unlike class/module declaration
+ ;; indentations, method definitions can be
+ ;; intermixed with these, and may or may not
+ ;; be additionally indented after visibility
+ ;; keywords.
(ruby-block-contains-point start))))
(setq mname (concat
(if in-singleton-class "." "#")
=== modified file 'test/ChangeLog'
--- a/test/ChangeLog 2013-02-14 03:33:55 +0000
+++ b/test/ChangeLog 2013-02-14 05:45:33 +0000
@@ -4,6 +4,8 @@
(ruby-move-to-block-skips-percent-literal): Add depth-affecting
bits inside the examples.
(ruby-move-to-block-skips-heredoc): New test.
+ (ruby-add-log-current-method-after-inner-class): Lower
+ expectations: move point inside a method, initially.
2013-02-13 Dmitry Gutov <address@hidden>
=== modified file 'test/automated/ruby-mode-tests.el'
--- a/test/automated/ruby-mode-tests.el 2013-02-14 03:33:55 +0000
+++ b/test/automated/ruby-mode-tests.el 2013-02-14 05:45:33 +0000
@@ -390,11 +390,13 @@
| class C
| class D
| end
- | _
+ | def foo
+ | _
+ | end
| end
|end")
(search-backward "_")
- (should (string= (ruby-add-log-current-method) "M::C"))))
+ (should (string= (ruby-add-log-current-method) "M::C#foo"))))
(defvar ruby-block-test-example
(ruby-test-string
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] /srv/bzr/emacs/trunk r111777: (ruby-add-log-current-method): Improve performance at the expense,
Dmitry Gutov <=