[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/adoc-mode a08c7f26cc 053/199: bugfixes for promote / denot
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/adoc-mode a08c7f26cc 053/199: bugfixes for promote / denote title |
Date: |
Sun, 3 Sep 2023 06:59:33 -0400 (EDT) |
branch: elpa/adoc-mode
commit a08c7f26cc8094a940a790b7c3def2274b2f0415
Author: Florian Kaufmann <sensorflo@gmail.com>
Commit: Florian Kaufmann <sensorflo@gmail.com>
bugfixes for promote / denote title
---
adoc-mode-test.el | 47 +++++++++++++++++++++++++++++++++++++++++++++++
adoc-mode.el | 53 ++++++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 89 insertions(+), 11 deletions(-)
diff --git a/adoc-mode-test.el b/adoc-mode-test.el
index 17aa293fd8..d72a663edf 100644
--- a/adoc-mode-test.el
+++ b/adoc-mode-test.el
@@ -57,6 +57,33 @@
;; tear-down
(kill-buffer buf-name)))
+(defun adoctest-trans (original-text expected-text transform-fn &optional args)
+ (let ((pos 0)
+ (line 0))
+ (while (and (< pos (length original-text))
+ (setq pos (string-match "\n\\|\\'" original-text pos)))
+ (adoctest-trans-inner original-text expected-text transform-fn args line)
+ (setq line (1+ line))
+ (setq pos (1+ pos)))))
+
+(defun adoctest-trans-inner (original-text expected-text transform-fn args
line)
+ (let ((not-done t)
+ (font-lock-support-mode))
+ (unwind-protect
+ (progn
+ ;; setup
+ (set-buffer (get-buffer-create "adoctest-trans"))
+ (delete-region (point-min) (point-max))
+ (adoc-mode)
+ (insert original-text)
+ (goto-line line)
+ ;; exercise
+ (funcall transform-fn args)
+ ;; verify
+ (should (string-equal (buffer-substring (point-min) (point-max))
expected-text))))
+ ;; tear-down
+ (kill-buffer "adoctest-trans")))
+
(ert-deftest adoctest-test-titles-simple-one-line-before ()
(adoctest-faces "titles-simple-one-line-before"
"= " markup-meta-hide-face "document title" markup-title-0-face "\n" nil
@@ -461,6 +488,26 @@
"lorem ** ipsum " markup-gen-face "::" markup-list-face " " nil "sit **
dolor\n" 'no-face
"lorem ** ipsum " markup-gen-face "::" markup-list-face " " nil "sit **
dolor" 'no-face))
+(ert-deftest adoctest-test-promote-title ()
+ (adoctest-trans "= foo" "== foo" 'adoc-promote-title 1)
+ (adoctest-trans "===== foo" "= foo" 'adoc-promote-title 1)
+ (adoctest-trans "== foo" "==== foo" 'adoc-promote-title 2)
+
+ (adoctest-trans "= foo =" "== foo ==" 'adoc-promote-title 1)
+ (adoctest-trans "===== foo =====" "= foo =" 'adoc-promote-title 1)
+ (adoctest-trans "== foo ==" "==== foo ====" 'adoc-promote-title 2)
+
+ (adoctest-trans "foo\n===" "foo\n---" 'adoc-promote-title 1)
+ (adoctest-trans "foo\n+++" "foo\n===" 'adoc-promote-title 1)
+ (adoctest-trans "foo\n---" "foo\n^^^" 'adoc-promote-title 2))
+
+;; since it's a whitebox test we know denote and promote only differ by inverse
+;; arg. So denote doesn't need to be throuhly tested again
+(ert-deftest adoctest-test-denote-title ()
+ (adoctest-trans "= foo" "===== foo" 'adoc-denote-title 1)
+ (adoctest-trans "= foo =" "===== foo =====" 'adoc-denote-title 1)
+ (adoctest-trans "foo\n===" "foo\n+++" 'adoc-denote-title 1))
+
(ert-deftest adoctest-pre-test-byte-compile ()
;; todo: also test for warnings
(should (byte-compile-file (locate-library "adoc-mode.el" t)))
diff --git a/adoc-mode.el b/adoc-mode.el
index 51240ab2be..d9c6d3648b 100644
--- a/adoc-mode.el
+++ b/adoc-mode.el
@@ -422,11 +422,37 @@ match-data has this sub groups:
(let ((del (make-string (+ level 1) ?=)))
(concat del " " text (when (eq sub-type 2) (concat " " del)))))
-;; for first line, 2nd line is not a regex but python code
+;; AsciiDoc handles that by source code, there is no regexp in AsciiDoc
+(defun adoc-re-two-line-title-undlerline (&optional del)
+ "Returns a regexp matching the underline of a two line title.
+
+DEL is an element of `adoc-two-line-title-del' or nil. If nil,
+any del is matched.
+
+Note that even if this regexp matches it still doesn't mean it is
+a two line title underline, see also `adoc-re-two-line-title'."
+ (concat
+ "\\("
+ (mapconcat
+ (lambda(x)
+ (concat
+ "\\(?:"
+ "\\(?:" (regexp-quote x) "\\)+"
+ (regexp-quote (substring x 0 1)) "?"
+ "\\)"))
+ (if del (list del) adoc-two-line-title-del) "\\|")
+ "\\)[ \t]*$"))
+
+;; asciidoc.conf regexps for _first_ line
;; ^(?P<title>.*?)$
(defun adoc-re-two-line-title (del)
- "Note that even if this regexp matches it still doesn't mean it is a two
line title.
-You additionaly have to test if the underline has the correct length.
+ "Returns a regexps that matches a two line title.
+
+Note that even if this regexp matches it still doesn't mean it is
+a two line title. You additionaly have to test if the underline
+has the correct length.
+
+DEL is described in `adoc-re-two-line-title-undlerline'.
match-data has his this sub groups:
1 title's text
@@ -435,13 +461,11 @@ match-data has his this sub groups:
(when (not (eq (length del) 2))
(error "two line title delimiters must be 2 chars long"))
(concat
- ;; title text (the first line) must contain at least one \w character. You
- ;; don't see that in asciidoc.conf, only in asciidoc source code.
+ ;; 1st line: title text must contain at least one \w character. You don't
see
+ ;; that in asciidoc.conf, only in asciidoc source code.
"\\(^.*?[a-zA-Z0-9_].*?\\)[ \t]*\n"
- "\\("
- "\\(?:" (regexp-quote del) "\\)+"
- (regexp-quote (substring del 0 1)) "?"
- "\\)[ \t]*$" ))
+ ;; 2nd line: underline
+ (adoc-re-two-line-title-undlerline del)))
(defun adoc-make-two-line-title (del text)
"Returns a two line title using given DEL containing given TEXT."
@@ -1664,7 +1688,7 @@ anchors in the [[id]] style."
(re-search-forward (concat "^\\[\\[" (match-string 1) "\\]\\]")))
(defun adoc-promote-title (&optional arg)
- "Promotes the title point is on ARG levels.
+ "Promotes the title at point ARG levels.
When ARG is nil (i.e. when no prefix arg is given), it defaults
to 1. When ARG is negative, level is denoted that many levels. If
@@ -1756,7 +1780,11 @@ trailing delimiter ('== my title ==').
;; method ensuring the correct length of the underline, be aware that
;; due to adoc-adjust-title-del we sometimes want to find a title
which has
;; the wrong underline length.
- ((looking-at (adoc-re-two-line-title (nth level
adoc-two-line-title-del)))
+ ((or (looking-at (adoc-re-two-line-title (nth level
adoc-two-line-title-del)))
+ (save-excursion
+ (forward-line -1)
+ (beginning-of-line)
+ (looking-at (adoc-re-two-line-title (nth level
adoc-two-line-title-del)))))
(setq type 2)
(setq text (match-string 1))
(setq found t))
@@ -1846,6 +1874,9 @@ and title's text are not preserved, afterwards its always
one space."
(setcar (nthcdr 1 descriptor) new-sub-type-val)
(setcar (nthcdr 2 descriptor) new-level)
(beginning-of-line)
+ (when (and (eq type 2) (looking-at (adoc-re-two-line-title-undlerline)))
+ (forward-line -1)
+ (beginning-of-line))
(delete-region start end)
(insert (adoc-make-title descriptor))
(when (eq new-type-val 2)
- [nongnu] elpa/adoc-mode e03d63e0b3 039/199: extened anchors unittest and fixed revealed bug, (continued)
- [nongnu] elpa/adoc-mode e03d63e0b3 039/199: extened anchors unittest and fixed revealed bug, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 6ccb9d6de5 009/199: intermediate checkin - to be removed, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode ce247928ec 021/199: added test for byte-compile-file without errors, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 105519ce37 033/199: changed image fontification without tests, added tests for attribute lists, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 3d2ab81750 041/199: new style font lock for xref inline macro, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 9c404a4e2d 042/199: test2, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 2756c62d86 043/199: revert test2, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode d4a57c5c03 045/199: cleaned up file comments a bit, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 97602c1577 046/199: fixed important typo, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 7b0009904e 047/199: updated URL and copyright date, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode a08c7f26cc 053/199: bugfixes for promote / denote title,
ELPA Syncer <=
- [nongnu] elpa/adoc-mode 504d490785 055/199: test: running the test is now more smoothly, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode fb170735f8 056/199: bugfixes and new tests for promote/denote/toggle title, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 4e13247892 058/199: test: added test for adjust-title-del, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 73b790fcf2 064/199: Merge branch 'develop', ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode fb4e940e0d 066/199: edited adoc-version's doc string, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode a805bd9787 071/199: bump version to 0.5.1, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 4b6054b5c8 079/199: added adoc-insert-indented, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode f779544180 084/199: bumped version to 0.6.1, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 27bf57f6fd 095/199: in commentary section, fixed wrong recipe how to use autoload, ELPA Syncer, 2023/09/03
- [nongnu] elpa/adoc-mode 1b3a175861 100/199: renamings and improved comments in field of macros, ELPA Syncer, 2023/09/03