summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoam Postavsky <npostavs@gmail.com>2020-08-11 16:02:11 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2020-08-11 16:02:11 +0200
commit9b9473ad755da13cb74bf33c99c081f39eec6e08 (patch)
treec5fdbd7d857c6fc78e98c9b9559697262a68ed5d
parent2a47ef86e95fad1dcc14a02e7471ba5d9cad4b9b (diff)
downloademacs-9b9473ad755da13cb74bf33c99c081f39eec6e08.tar.gz
Fix (end-of-defun N) for N >= 2
* lisp/emacs-lisp/lisp.el (end-of-defun): Only skip to next line when after end of defun when ARG is 1 or less. * test/lisp/emacs-lisp/lisp-tests.el (end-of-defun-twice): New test (bug#24427).
-rw-r--r--lisp/emacs-lisp/lisp.el3
-rw-r--r--test/lisp/emacs-lisp/lisp-tests.el55
2 files changed, 57 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index 043cf01d2e9..8c18557c79a 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -482,7 +482,8 @@ is called as a function to find the defun's end."
(if (looking-at "\\s<\\|\n")
(forward-line 1))))))
(funcall end-of-defun-function)
- (funcall skip)
+ (when (<= arg 1)
+ (funcall skip))
(cond
((> arg 0)
;; Moving forward.
diff --git a/test/lisp/emacs-lisp/lisp-tests.el b/test/lisp/emacs-lisp/lisp-tests.el
index 8736ac70201..a2b8304c96a 100644
--- a/test/lisp/emacs-lisp/lisp-tests.el
+++ b/test/lisp/emacs-lisp/lisp-tests.el
@@ -367,6 +367,61 @@ start."
"
"Test buffer for `mark-defun'."))
+;;; end-of-defun
+
+(ert-deftest end-of-defun-twice ()
+ "Test behavior of prefix arg for `end-of-defun' (Bug#24427).
+Calling `end-of-defun' twice should be the same as a prefix arg
+of two."
+ (setq last-command nil)
+ (cl-flet ((eod2 (lambda ()
+ (goto-char (point-min))
+ (end-of-defun)
+ (end-of-defun)
+ (let ((pt-eod2 (point)))
+ (goto-char (point-min))
+ (end-of-defun 2)
+ (should (= (point) pt-eod2))))))
+ (with-temp-buffer
+ (insert "\
+\(defun a ())
+
+\(defun b ())
+
+\(defun c ())")
+ (eod2))
+ (with-temp-buffer
+ (insert "\
+\(defun a ())
+\(defun b ())
+\(defun c ())")
+ (eod2)))
+ (elisp-tests-with-temp-buffer ";; Comment header
+
+\(defun func-1 (arg)
+ \"docstring\"
+ body)
+=!p1=
+;; Comment before a defun
+\(defun func-2 (arg)
+ \"docstring\"
+ body)
+
+\(defun func-3 (arg)
+ \"docstring\"
+ body)
+=!p2=(defun func-4 (arg)
+ \"docstring\"
+ body)
+
+;; end
+"
+ (goto-char p1)
+ (end-of-defun 2)
+ (should (= (point) p2))))
+
+;;; mark-defun
+
(ert-deftest mark-defun-no-arg-region-inactive ()
"Test `mark-defun' with no prefix argument and inactive
region."