From 6184e74ca8256d322276b50b0a4ea2ab072bb83a Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Thu, 25 Jun 2020 15:06:51 +0100 Subject: Use lexical-binding and byte-compile tests * Makefile (test, clean): Byte-compile test suite to catch more errors. * bog-tests.el: Use lexical-binding. Remove the need for cl-lib by replacing single cl-gensym with make-symbol. Declare 'citekey' as a special variable. Add footer line. (bog-tests-with-temp-dir): Replace cl-gensym with make-symbol. (bog-tests-with-temp-text): Allow instrumenting for debugging. Evaluate arguments only once. Don't assume 'citekey' is bound. Pass non-nil FIXEDCASE and LITERAL arguments to replace-match. Simplify with buffer rather than string manipulation. (bog-file-citekeys/multiple-variants): Fix typo caught by byte-compilation. * bog.el: Use lexical-binding. Quote function symbols as such. (bog--with-citekey-cache): Allow instrumenting for debugging. Replace cl-gensym with make-symbol. (bog-selection-method): Simplify and reindent. (bog--agenda-map): New keymap. (bog--with-search-lprops): Use it instead of generating it on the fly. Allow instrumenting for debugging. Don't use org-let which calls eval without lexical-binding. Bind uninterned symbol around body. Use unwind-protect to ensure org-lprops are restored. (bog-search-notes, bog-agenda-redo): Unquote body passed to bog--with-search-lprops now that it no longer uses org-let. (bog-command-map): Make docstring consistent with that of other keymaps. --- bog-tests.el | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'bog-tests.el') diff --git a/bog-tests.el b/bog-tests.el index b1b2ea1..3a1539c 100644 --- a/bog-tests.el +++ b/bog-tests.el @@ -1,4 +1,4 @@ -;;; bog-tests.el --- Tests for Bog +;;; bog-tests.el --- Tests for Bog -*- lexical-binding: t -*- ;; Copyright (C) 2013-2016 Kyle Meyer @@ -19,15 +19,17 @@ ;;; Code: +(require 'bog) (require 'ert) (require 'org) -(require 'cl-lib) -(require 'bog) + +(with-no-warnings ;; Silence "lacks a prefix" warning. + (defvar citekey)) ;; Modified from magit-tests.el. (defmacro bog-tests-with-temp-dir (&rest body) (declare (indent 0) (debug t)) - (let ((dir (cl-gensym))) + (let ((dir (make-symbol "dir"))) `(let ((,dir (file-name-as-directory (make-temp-file "dir" t)))) (unwind-protect (let ((default-directory ,dir)) ,@body) @@ -44,21 +46,18 @@ value of the variable `citekey'. If the string \"\" appears in TEXT then remove it and place the point there before running BODY, otherwise place the point at the beginning of the inserted text." - (declare (indent 1)) - `(let* ((inside-text (if (stringp ,text) ,text (eval ,text))) - (is-citekey (string-match "" inside-text))) - (when (and is-citekey citekey) - (setq inside-text (replace-match citekey nil nil inside-text))) - (with-temp-buffer - (org-mode) - (let ((point (string-match "" inside-text))) - (if point - (progn - (insert (replace-match "" nil nil inside-text)) - (goto-char (1+ (match-beginning 0)))) - (insert inside-text) - (goto-char (point-min)))) - ,@body))) + (declare (indent 1) (debug t)) + `(with-temp-buffer + (org-mode) + (insert ,text) + (goto-char (point-min)) + (when (and (bound-and-true-p citekey) + (search-forward "" nil t)) + (replace-match citekey t t)) + (goto-char (point-min)) + (when (search-forward "" nil t) + (replace-match "" t t)) + ,@body)) ;;; Citekey functions @@ -410,7 +409,7 @@ some text" (concat citekey ".txt") (concat citekey "_0.pdf") (concat citekey "-supplement.pdf"))) - found-files) + files-found) (make-directory bog-file-directory) (dolist (var variants) (write-region "" nil (expand-file-name var bog-file-directory))) @@ -582,3 +581,5 @@ some text" (sort (bog--find-duplicates (list "a" "b" "c" "b" "a")) #'string-lessp)))) + +;;; bog-tests.el ends here -- cgit v1.2.3