From bebba6be3da6544ec5d8051d74a976dcd52314ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= Date: Fri, 29 Aug 2025 10:55:21 +0200 Subject: [PATCH] Fix org-habit bug related to string mutation * lisp/org/org-habit.el (org-habit-build-graph): Rewrite without using string mutation (using vectors instead), fixing a bug where org-habit-completed-glyph and org-habit-today-glyph wouldn't display properly if in the U+0080..00FF range, discovered by the more restricted string mutation. Reported by Daniel Mendler in https://lists.gnu.org/archive/html/emacs-orgmode/2025-08/msg00224.html --- lisp/org/org-habit.el | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lisp/org/org-habit.el b/lisp/org/org-habit.el index 38975682152..010c9daa00e 100644 --- a/lisp/org/org-habit.el +++ b/lisp/org/org-habit.el @@ -333,7 +333,8 @@ current time." (start (time-to-days starting)) (now (time-to-days current)) (end (time-to-days ending)) - (graph (make-string (1+ (- end start)) ?\s)) + (graph (make-vector (1+ (- end start)) ?\s)) + (props nil) (index 0) last-done-date) (while (and done-dates (< (car done-dates) start)) @@ -411,17 +412,20 @@ current time." (not (eq face 'org-habit-overdue-face)) (not markedp)) (setq face (cdr faces))) - (put-text-property index (1+ index) 'face face graph) - (put-text-property index (1+ index) - 'help-echo - (concat (format-time-string - (org-time-stamp-format) - (time-add starting (days-to-time (- start (time-to-days starting))))) - (if donep " DONE" "")) - graph)) + (push (list index (1+ index) 'face face) props) + (push (list index (1+ index) + 'help-echo + (concat (format-time-string + (org-time-stamp-format) + (time-add starting (days-to-time (- start (time-to-days starting))))) + (if donep " DONE" ""))) + props)) (setq start (1+ start) index (1+ index))) - graph)) + (let ((graph-str (concat graph))) + (dolist (p props) + (put-text-property (nth 0 p) (nth 1 p) (nth 2 p) (nth 3 p) graph-str)) + graph-str))) (defun org-habit-insert-consistency-graphs (&optional line) "Insert consistency graph for any habitual tasks."