emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 a22eb9ae0f9: ruby-add-log-current-method: Reduce the use of 'nr


From: Dmitry Gutov
Subject: emacs-29 a22eb9ae0f9: ruby-add-log-current-method: Reduce the use of 'nreverse'
Date: Wed, 12 Apr 2023 18:11:10 -0400 (EDT)

branch: emacs-29
commit a22eb9ae0f9bfb745d05ea5b069b59592f19f1eb
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>

    ruby-add-log-current-method: Reduce the use of 'nreverse'
    
    * lisp/progmodes/ruby-mode.el (ruby-add-log-current-method):
    Reduce the use of 'nreverse' (bug#62761).
    
    * test/lisp/progmodes/ruby-mode-tests.el
    (ruby-add-log-current-method-singleton-referencing-outer):
    New test.
---
 lisp/progmodes/ruby-mode.el            |  4 ++--
 test/lisp/progmodes/ruby-mode-tests.el | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el
index beccb8182a7..b252826680c 100644
--- a/lisp/progmodes/ruby-mode.el
+++ b/lisp/progmodes/ruby-mode.el
@@ -1905,13 +1905,13 @@ See `add-log-current-defun-function'."
                   (progn
                     (unless (string-equal "self" (car mn)) ; def self.foo
                       ;; def C.foo
-                      (let ((ml (nreverse mlist)))
+                      (let ((ml (reverse mlist)))
                         ;; If the method name references one of the
                         ;; containing modules, drop the more nested ones.
                         (while ml
                           (if (string-equal (car ml) (car mn))
                               (setq mlist (nreverse (cdr ml)) ml nil))
-                          (or (setq ml (cdr ml)) (nreverse mlist))))
+                          (setq ml (cdr ml))))
                       (if mlist
                           (setcdr (last mlist) (butlast mn))
                         (setq mlist (butlast mn))))
diff --git a/test/lisp/progmodes/ruby-mode-tests.el 
b/test/lisp/progmodes/ruby-mode-tests.el
index 8a75c83d2c3..117385ea3e8 100644
--- a/test/lisp/progmodes/ruby-mode-tests.el
+++ b/test/lisp/progmodes/ruby-mode-tests.el
@@ -567,6 +567,22 @@ VALUES-PLIST is a list with alternating index and value 
elements."
     (search-backward "_")
     (should (string= (ruby-add-log-current-method) "C::D#foo"))))
 
+(ert-deftest ruby-add-log-current-method-singleton-referencing-outer ()
+  (ruby-with-temp-buffer (ruby-test-string
+                          "module M
+                          |  module N
+                          |    module C
+                          |      class D
+                          |        def C.foo
+                          |          _
+                          |        end
+                          |      end
+                          |    end
+                          |  end
+                          |end")
+    (search-backward "_")
+    (should (string= (ruby-add-log-current-method) "M::N::C.foo"))))
+
 (ert-deftest ruby-add-log-current-method-after-inner-class ()
   (ruby-with-temp-buffer (ruby-test-string
                           "module M



reply via email to

[Prev in Thread] Current Thread [Next in Thread]