about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJake Coble2025-06-07 18:26:53 -0400
committerArun Isaac2025-06-08 03:07:47 +0100
commit5764b5f676b5873d5f36f218e744f446d0dcf7f9 (patch)
treebdb30a312b8551fe08aa947159652eecf099d71a
parent84798ff864c6975cfe3df8e28e10463823b1fc43 (diff)
downloadvaruga-5764b5f676b5873d5f36f218e744f446d0dcf7f9.tar.gz
varuga-5764b5f676b5873d5f36f218e744f446d0dcf7f9.tar.lz
varuga-5764b5f676b5873d5f36f218e744f446d0dcf7f9.zip
Don't swallow last character when splitting lines.
* varuga.el (varuga-insert-calendar-line): Don't swallow last
character when splitting lines.
* varuga-tests.el (line-limit-does-not-eat-characters): New test.

Signed-off-by: Arun Isaac <arunisaac@systemreboot.net>
-rw-r--r--varuga-tests.el7
-rw-r--r--varuga.el12
2 files changed, 13 insertions, 6 deletions
diff --git a/varuga-tests.el b/varuga-tests.el
index 97fb817..ca2d121 100644
--- a/varuga-tests.el
+++ b/varuga-tests.el
@@ -2,6 +2,7 @@
 
 ;; Send ical calendar invites by email
 ;; Copyright © 2024 by Arun I
+;; Copyright © 2025 Jake Coble <j@kecoble.com>
 ;;
 ;; Author: Arun Isaac <arunisaac@systemreboot.net>
 ;; Homepage: https://git.systemreboot.net/varuga
@@ -71,3 +72,9 @@
             (count-lines (point-min) (point-max)))
           2)))
 
+(ert-deftest line-limit-does-not-eat-characters ()
+  (should
+   (equal (with-temp-buffer
+            (varuga-insert-calendar-line 'foo (make-string 100 ?a))
+            (count-matches "a" (point-min) (point-max)))
+          100)))
diff --git a/varuga.el b/varuga.el
index 4010482..0c5070c 100644
--- a/varuga.el
+++ b/varuga.el
@@ -2,6 +2,7 @@
 
 ;; Send ical calendar invites by email
 ;; Copyright © 2024 Arun Isaac
+;; Copyright © 2025 Jake Coble <j@kecoble.com>
 ;;
 ;; Author: Arun Isaac <arunisaac@systemreboot.net>
 ;; Version: 0.1.0
@@ -88,13 +89,12 @@ KEY is the name of the ical property and VALUE is its value."
                      (next-octets (+ octets-so-far
                                      (string-bytes str))))
                 (if (< next-octets maximum-octets-per-line)
-                    (progn
-                      (insert str)
-                      (setq octets-so-far next-octets))
+                    (setq octets-so-far next-octets)
                   (insert "\n ")
-                  ;; Set octets so far to 1 to account for the
-                  ;; folding space.
-                  (setq octets-so-far 1))))
+                  ;; Add an extra 1 to octets so far to account for
+                  ;; the folding space.
+                  (setq octets-so-far (1+ (string-bytes str))))
+                (insert str)))
             (format "%s:%s"
                     (upcase (symbol-name key))
                     value)))