emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/adoc-mode 2322c32185 076/199: extracted make-two-line-titl


From: ELPA Syncer
Subject: [nongnu] elpa/adoc-mode 2322c32185 076/199: extracted make-two-line-title-underline from make-two-line-title
Date: Sun, 3 Sep 2023 06:59:35 -0400 (EDT)

branch: elpa/adoc-mode
commit 2322c321852aa1aba6d79206132a6bce1c829a3b
Author: Florian Kaufmann <sensorflo@gmail.com>
Commit: Florian Kaufmann <sensorflo@gmail.com>

    extracted make-two-line-title-underline from make-two-line-title
---
 adoc-mode-test.el |  6 ++++++
 adoc-mode.el      | 26 +++++++++++++++++---------
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/adoc-mode-test.el b/adoc-mode-test.el
index 7da1d10287..82ba796a2f 100644
--- a/adoc-mode-test.el
+++ b/adoc-mode-test.el
@@ -611,6 +611,12 @@ removed before TRANSFORM is evaluated.
        (should (equal (line-number-at-pos) 3)))
     (kill-buffer "adoc-test")))
 
+(ert-deftest adoctest-test-make-two-line-title-underline ()
+  (should (equal (adoc-make-two-line-title-underline 0 6)
+                "======"))
+  (should (equal (adoc-make-two-line-title-underline 2)
+                "~~~~")))
+    
 ;; 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
diff --git a/adoc-mode.el b/adoc-mode.el
index 7629b3fbd5..427a7e9884 100644
--- a/adoc-mode.el
+++ b/adoc-mode.el
@@ -503,19 +503,27 @@ match-data has his this sub groups:
    ;; 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."
-  (when (not (eq (length del) 2))
-    (error "two line title delimiters must be 2 chars long"))
-  (let ((repetition-cnt (if (>= (length text) 2) (/ (length text) 2) 1))
-        (result (concat text "\n")))
+(defun adoc-make-two-line-title (level text)
+  "Returns a two line title of given LEVEL containing given TEXT.
+LEVEL starts at 1."
+  (concat text "\n" (adoc-make-two-line-title-underline level (length text))))
+  
+(defun adoc-make-two-line-title-underline (level &optional length)
+  "Returns a two line title underline.
+LEVEL is the level of the title, starting at 1. LENGTH is the
+line of the title's text. When nil it defaults to 4."
+  (unless length
+    (setq length 4))
+  (let* ((repetition-cnt (if (>= length 2) (/ length 2) 1))
+        (del (nth level adoc-two-line-title-del))
+        (result ""))
     (while (> repetition-cnt 0)
       (setq result (concat result del))
       (setq repetition-cnt (- repetition-cnt 1)))
-    (when (eq (% (length text) 2) 1)
+    (when (eq (% length 2) 1)
       (setq result (concat result (substring del 0 1))))
     result))
-  
+
 (defun adoc-re-oulisti (type &optional level sub-type)
   "Returns a regexp matching an (un)ordered list item.
 
@@ -2009,7 +2017,7 @@ trailing delimiter ('== my title ==').
         (text (nth 3 descriptor)))
     (if (eq type 1)
         (adoc-make-one-line-title sub-type level text)
-      (adoc-make-two-line-title (nth level adoc-two-line-title-del) text))))
+      (adoc-make-two-line-title level text))))
 
 (defun adoc-modify-title (&optional new-level-rel new-level-abs new-type 
new-sub-type create)
   "Modify properties of title point is on.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]