Skip to content

Commit

Permalink
Addresses #33. Re-structure also adoc-kw-replacement.
Browse files Browse the repository at this point in the history
Also add ert test for keyword-replacement
  • Loading branch information
Tobias Zawada authored and TobiasZawada committed Aug 3, 2023
1 parent d4abb0b commit 2578d9a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
21 changes: 8 additions & 13 deletions adoc-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions test/adoc-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2578d9a

Please sign in to comment.