>From fb6fa889ec026f2b5d265a043ae5c7e0813aa7c5 Mon Sep 17 00:00:00 2001 From: Marcin Borkowski Date: Tue, 6 Mar 2018 06:46:10 +0100 Subject: [PATCH 1/2] Add a more general "tests-with-temp-buffer" macro --- test/lisp/emacs-lisp/lisp-tests.el | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/lisp/emacs-lisp/lisp-tests.el b/test/lisp/emacs-lisp/lisp-tests.el index 07eddb74d5..ec197602b6 100644 --- a/test/lisp/emacs-lisp/lisp-tests.el +++ b/test/lisp/emacs-lisp/lisp-tests.el @@ -307,12 +307,12 @@ backward-up-list-basic ;;; Helpers (eval-and-compile - (defvar elisp-test-point-position-regex "=!\\([a-zA-Z0-9-]+\\)=" + (defvar test-point-position-regex "=!\\([a-zA-Z0-9-]+\\)=" "A regexp matching placeholders for point position for `elisp-tests-with-temp-buffer'.")) ;; Copied and heavily modified from `python-tests-with-temp-buffer' -(defmacro elisp-tests-with-temp-buffer (contents &rest body) +(defmacro tests-with-temp-buffer (mode contents &rest body) "Create an `emacs-lisp-mode' enabled temp buffer with CONTENTS. BODY is the code to be executed within the temp buffer. Point is always located at the beginning of buffer. CONTENTS is an @@ -320,12 +320,12 @@ elisp-tests-with-temp-buffer of the form =!NAME= in CONTENTS are removed, and a for each one a variable called NAME is bound to the position of the word's start." - (declare (indent 1) (debug (def-form body))) + (declare (indent 2) (debug (def-form body))) (let* ((var-pos nil) (text (with-temp-buffer (insert (eval contents)) (goto-char (point-min)) - (while (re-search-forward elisp-test-point-position-regex nil t) + (while (re-search-forward test-point-position-regex nil t) (push (list (intern (match-string-no-properties 1)) (match-beginning 0)) var-pos) @@ -333,7 +333,7 @@ elisp-tests-with-temp-buffer (match-end 0))) (buffer-string)))) `(with-temp-buffer - (emacs-lisp-mode) + (,mode) (insert ,text) (goto-char (point-min)) (let ,var-pos @@ -341,6 +341,11 @@ elisp-tests-with-temp-buffer ,@(mapcar (lambda (v-p) `(ignore ,(car v-p))) var-pos) ,@body)))) +(defmacro elisp-tests-with-temp-buffer (contents &rest body) + "Use TESTS-WITH-TEMP-BUFFER with Emacs Lisp mode." + (declare (indent 1) (debug (def-form body))) + `(tests-with-temp-buffer emacs-lisp-mode ,contents ,@body)) + ;;; mark-defun (eval-and-compile -- 2.16.2