diff options
| author | Dmitry Gutov | 2023-04-13 00:45:54 +0300 |
|---|---|---|
| committer | Dmitry Gutov | 2023-04-13 00:46:11 +0300 |
| commit | a22eb9ae0f9bfb745d05ea5b069b59592f19f1eb (patch) | |
| tree | fadadc41f3ce775f5d957eab59038ad2684cd5c2 | |
| parent | 17d803d0a7545db360c917e576aa77cea10a9b29 (diff) | |
| download | emacs-a22eb9ae0f9bfb745d05ea5b069b59592f19f1eb.tar.gz emacs-a22eb9ae0f9bfb745d05ea5b069b59592f19f1eb.zip | |
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.
| -rw-r--r-- | lisp/progmodes/ruby-mode.el | 4 | ||||
| -rw-r--r-- | 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'." | |||
| 1905 | (progn | 1905 | (progn |
| 1906 | (unless (string-equal "self" (car mn)) ; def self.foo | 1906 | (unless (string-equal "self" (car mn)) ; def self.foo |
| 1907 | ;; def C.foo | 1907 | ;; def C.foo |
| 1908 | (let ((ml (nreverse mlist))) | 1908 | (let ((ml (reverse mlist))) |
| 1909 | ;; If the method name references one of the | 1909 | ;; If the method name references one of the |
| 1910 | ;; containing modules, drop the more nested ones. | 1910 | ;; containing modules, drop the more nested ones. |
| 1911 | (while ml | 1911 | (while ml |
| 1912 | (if (string-equal (car ml) (car mn)) | 1912 | (if (string-equal (car ml) (car mn)) |
| 1913 | (setq mlist (nreverse (cdr ml)) ml nil)) | 1913 | (setq mlist (nreverse (cdr ml)) ml nil)) |
| 1914 | (or (setq ml (cdr ml)) (nreverse mlist)))) | 1914 | (setq ml (cdr ml)))) |
| 1915 | (if mlist | 1915 | (if mlist |
| 1916 | (setcdr (last mlist) (butlast mn)) | 1916 | (setcdr (last mlist) (butlast mn)) |
| 1917 | (setq mlist (butlast mn)))) | 1917 | (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." | |||
| 567 | (search-backward "_") | 567 | (search-backward "_") |
| 568 | (should (string= (ruby-add-log-current-method) "C::D#foo")))) | 568 | (should (string= (ruby-add-log-current-method) "C::D#foo")))) |
| 569 | 569 | ||
| 570 | (ert-deftest ruby-add-log-current-method-singleton-referencing-outer () | ||
| 571 | (ruby-with-temp-buffer (ruby-test-string | ||
| 572 | "module M | ||
| 573 | | module N | ||
| 574 | | module C | ||
| 575 | | class D | ||
| 576 | | def C.foo | ||
| 577 | | _ | ||
| 578 | | end | ||
| 579 | | end | ||
| 580 | | end | ||
| 581 | | end | ||
| 582 | |end") | ||
| 583 | (search-backward "_") | ||
| 584 | (should (string= (ruby-add-log-current-method) "M::N::C.foo")))) | ||
| 585 | |||
| 570 | (ert-deftest ruby-add-log-current-method-after-inner-class () | 586 | (ert-deftest ruby-add-log-current-method-after-inner-class () |
| 571 | (ruby-with-temp-buffer (ruby-test-string | 587 | (ruby-with-temp-buffer (ruby-test-string |
| 572 | "module M | 588 | "module M |