From d9be0d35088afba9e6000d8ca1ed861d12e2ecac Mon Sep 17 00:00:00 2001 From: Stephen Berman Date: Fri, 15 Jun 2012 00:32:09 +0100 Subject: [PATCH] * calendar/todos.el (todos-reset-done-separator) (todos-reset-and-enable-done-separator): New functions. (todos-reset-done-separator-string): Rewrite using todos-reset-done-separator for string longer than 1 character. (todos-mode): Add todos-reset-and-enable-done-separator to window-configuration-change-hook, replacing previous anonymous function. (todos-unload-hook): And remove it. --- lisp/ChangeLog | 11 ++++++ lisp/calendar/todos.el | 87 ++++++++++++++++++++---------------------- 2 files changed, 52 insertions(+), 46 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e7c9d8cb6ff..893ad521175 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,14 @@ +2012-09-23 Stephen Berman + + * calendar/todos.el (todos-reset-done-separator) + (todos-reset-and-enable-done-separator): New functions. + (todos-reset-done-separator-string): Rewrite using + todos-reset-done-separator for string longer than 1 character. + (todos-mode): Add todos-reset-and-enable-done-separator to + window-configuration-change-hook, replacing previous anonymous + function. + (todos-unload-hook): And remove it. + 2012-09-23 Stephen Berman * calendar/todos.el (todos-done-separator-string): New defcustom. diff --git a/lisp/calendar/todos.el b/lisp/calendar/todos.el index b1bf68fe4e1..97a433c6ead 100644 --- a/lisp/calendar/todos.el +++ b/lisp/calendar/todos.el @@ -182,28 +182,8 @@ the value of `todos-done-separator'." (sep todos-done-separator)) (custom-set-default symbol value) (setq todos-done-separator (todos-done-separator)) - ;; Replace any existing separator string overlays. - (when (not (equal value oldvalue)) - (dolist (f files) - (with-current-buffer (find-buffer-visiting f) - (save-excursion - (save-restriction - (widen) - (goto-char (point-min)) - (while (re-search-forward (concat "\n\\(" - (regexp-quote todos-category-done) - "\\)") nil t) - (setq beg (match-beginning 1)) - (setq end (match-end 0)) - (let* ((ovs (overlays-at beg)) - old-sep new-sep) - (and ovs - (setq old-sep (overlay-get (car ovs) 'display)) - (string= old-sep sep) - (delete-overlay (car ovs)) - (setq new-sep (make-overlay beg end)) - (overlay-put new-sep 'display - todos-done-separator))))))))))) + (when (= 1 (length value)) + (todos-reset-done-separator sep)))) (defcustom todos-done-string "DONE " "Identifying string appended to the front of done todos items." @@ -1053,6 +1033,43 @@ Displayed as an overlay instead of `todos-category-done' when done items are shown. Its value is determined by user option `todos-done-separator-string'.") +(defun todos-reset-done-separator (sep) + "Replace any existing overlays of separator string SEP." + (save-excursion + (save-restriction + (widen) + (goto-char (point-min)) + (while (re-search-forward + (concat "\n\\(" (regexp-quote todos-category-done) "\\)") nil t) + (setq beg (match-beginning 1)) + (setq end (match-end 0)) + (let* ((ovs (overlays-at beg)) + old-sep new-sep) + (and ovs + (setq old-sep (overlay-get (car ovs) 'display)) + (string= old-sep sep) + (delete-overlay (car ovs)) + (setq new-sep (make-overlay beg end)) + (overlay-put new-sep 'display + todos-done-separator))))))) + +(defun todos-reset-and-enable-done-separator () + "Hook function for activating new separator overlay. +Added to `window-configuration-change-hook' in `todos-mode'." + (when (= 1 (length todos-done-separator-string)) + (let ((sep todos-done-separator)) + (setq todos-done-separator (todos-done-separator)) + (todos-reset-done-separator sep)) + ;; If the separator overlay is now shown, we have to hide and then show it + ;; again in order to let the change in length take effect. + (save-excursion + (goto-char (point-min)) + (when (re-search-forward todos-done-string-start nil t) + (let ((todos-show-with-done nil)) + (todos-category-select)) + (let ((todos-show-with-done t)) + (todos-category-select)))))) + (defun todos-category-select () "Display the current category correctly." (let ((name (todos-current-category)) @@ -2560,28 +2577,7 @@ which is the value of the user option (when todos-show-current-file (add-hook 'pre-command-hook 'todos-show-current-file nil t)) (add-hook 'window-configuration-change-hook - ;; FIXME - (lambda () - (let ((sep todos-done-separator)) - (setq todos-done-separator (todos-done-separator)) - (save-excursion - (save-restriction - (widen) - (goto-char (point-min)) - (while (re-search-forward - (concat "\n\\(" (regexp-quote todos-category-done) - "\\)") nil t) - (setq beg (match-beginning 1)) - (setq end (match-end 0)) - (let* ((ovs (overlays-at beg)) - old-sep new-sep) - (and ovs - (setq old-sep (overlay-get (car ovs) 'display)) - (string= old-sep sep) - (delete-overlay (car ovs)) - (setq new-sep (make-overlay beg end)) - (overlay-put new-sep 'display - todos-done-separator)))))))) nil t) + 'todos-reset-and-enable-done-separator nil t) (add-hook 'kill-buffer-hook 'todos-reset-global-current-todos-file nil t)) ;; FIXME: need this? @@ -2592,8 +2588,7 @@ which is the value of the user option (remove-hook 'find-file-hook 'todos-display-as-todos-file t) (remove-hook 'find-file-hook 'todos-add-to-buffer-list t) (remove-hook 'window-configuration-change-hook - ;; FIXME - (lambda () (setq todos-done-separator (todos-done-separator))) t) + 'todos-reset-and-enable-done-separator t) (remove-hook 'kill-buffer-hook 'todos-reset-global-current-todos-file t)) (put 'todos-archive-mode 'mode-class 'special) -- 2.39.5