From 2578d9a6c360b5cb31a22703412e0d25e14f9d17 Mon Sep 17 00:00:00 2001 From: Tobias Zawada Date: Sat, 29 Jul 2023 07:30:08 +0200 Subject: [PATCH] Addresses #33. Re-structure also `adoc-kw-replacement`. Also add ert test for keyword-replacement --- adoc-mode.el | 21 ++++++++------------- test/adoc-mode-test.el | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/adoc-mode.el b/adoc-mode.el index d2a5d96..aba1a8d 100644 --- a/adoc-mode.el +++ b/adoc-mode.el @@ -1901,18 +1901,13 @@ meta characters." `(list ;; matcher function (lambda (end) - (let ((found t) (prevented t) saved-point) - (while (and found prevented) - (setq saved-point (point)) - (setq found - (adoc-kwf-search ,regexp end t)) - (setq prevented ; prevented is only meaningful wenn found is non-nil - (or - (not found) ; the following is only needed when found - (text-property-not-all (match-beginning 1) (match-end 1) 'adoc-reserved nil))) - (when (and found prevented) - (goto-char (+ saved-point 1)))) - (when (and found (not prevented) adoc-insert-replacement ,replacement) + (let (found) + (while (and (setq found + (adoc-kwf-search ,regexp end t)) + (text-property-not-all (match-beginning 1) (match-end 1) 'adoc-reserved nil)) + (setq found nil) + (goto-char (+ (match-beginning 0) 1))) + (when (and found adoc-insert-replacement ,replacement) (let* ((s (cond ((stringp ,replacement) ,replacement) @@ -1924,7 +1919,7 @@ meta characters." (setq adoc-replacement-failed (not o)) (unless adoc-replacement-failed (overlay-put o 'after-string s)))) - (and found (not prevented)))) + found)) ;; highlighers ;; TODO: replacement instead warining face if resolver is not given diff --git a/test/adoc-mode-test.el b/test/adoc-mode-test.el index c6b1d3e..d20ced6 100644 --- a/test/adoc-mode-test.el +++ b/test/adoc-mode-test.el @@ -1026,6 +1026,23 @@ Don't use it for anything real.") (cons "sub chapter 2.1" 262))))) (kill-buffer "adoc-test"))) +(ert-deftest adoctest-adoc-kw-replacement () + (unwind-protect + (progn + (set-buffer (get-buffer-create "adoc-test")) + (erase-buffer) + (adoc-mode) + (let ((adoc-insert-replacement t)) + (adoc-calc) + (insert "(C)") + (font-lock-flush) + (font-lock-ensure) + (should (string-equal (overlay-get (car (overlays-in (point) (point-max))) 'after-string) "©")) + ) + ) + (adoc-calc) + (kill-buffer "adoc-test"))) + ;; purpose ;; - ensure that the latest version, i.e. the one currently in buffer(s), of ;; adoc-mode and adoc-mode-test is used for the test