Subject: bug#5093 closed by Glenn Morris <[email-masked]> (Re: bug#5093: 23.1.50; including diary entries from narrowed buffers)

From: [email-masked] (Emacs bug Tracking System)
Date: Wed, 02 Dec 2009 03:15:21 +0000

This is an automatic notification regarding your bug report
which was filed against the emacs package:

#5093: 23.1.50; including diary entries from narrowed buffers

It has been closed by Glenn Morris <[email-masked]>.

Their explanation is attached below along with your original report.
If this explanation is unsatisfactory and you have not received a
better one in a separate message then please contact Glenn Morris <[email-masked]> by
replying to this email.

-- 
5093: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=5093
Emacs Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#5093: 23.1.50; including diary entries from narrowed buffers
From: Glenn Morris <[email-masked]>
To: [email-masked]
Date: Tue, 01 Dec 2009 22:05:46 -0500

I installed a similar fix.

Subject: 23.1.50; including diary entries from narrowed buffers
From: Stephen Berman <[email-masked]>
To: [email-masked]
Date: Tue, 01 Dec 2009 17:40:53 +0100

1. Save a ~/.todo-do file with entries in two categories, e.g. (this
file can be created from emacs -Q, e.g. by calling todo-show):
==cut==
-*- mode: todo; todo-categories: ("test" "Todo"); -*-
*/* --- test
*/* 2009-11-30 00:47 steve: another item
--- End
*/* ---------------------------------------------------------------------------
*/* --- Todo
*/* 2009-11-29 21:48 steve: todo item
--- End
*/* ---------------------------------------------------------------------------
==cut==

2. Save ~/diary with a line to include the todo file:
==cut==
#include "~/.todo-do"
==cut==

3. Save ~/.emacs with the following content (or start from emacs -Q and
either use the Custom interface for diary-list-entries-hook or eval
(add-hook 'diary-list-entries-hook 'diary-include-other-diary-files)):
==cut==
(custom-set-variables
 '(diary-list-entries-hook (quote (diary-include-other-diary-files))))
==cut==

4. Restart Emacs, type `M-x diary', answer y to the question about
applying the local variables list for todo-categories.
=> A buffer pops up with the following fancy diary display:

Tuesday, December 1, 2009
=========================
--- test
2009-11-30 00:47 steve: another item
---------------------------------------------------------------------------
--- Todo
2009-11-29 21:48 steve: todo item
---------------------------------------------------------------------------

5. Type `M-x todo-show' to visit the todo file in Todo mode (category
"test"), then type type `M-x diary' again.
=> Now fancy diary display looks like this:

Tuesday, December 1, 2009
=========================
2009-11-29 00:47 steve: another item

The output after step 5 is incomplete, in contrast to the output after
step 4.  (The latter is the intended output, as seen by the lines in
~/.todo-do with the prefix '*/*', which are added to each day's diary
entries.)  This is because diary-list-entries-2 in diary-lib.el, which
contains the search routine for new diary entries, does not take
possible narrowing into account, and that is in effect in Todo mode.
The patch below fixes this.  It assumes that narrowing should always be
suspended when searching for new diary entries, which seems reasonable
(the alternative would, AFAICT, require checking individual major
modes).  The problem also exists in Emacs 22, but that needs a separate
patch to list-diary-entries, due to this function being split up in
Emacs 23.  I don't have the Emacs 22 CVS branch at hand, so I can't
include the needed patch.

Steve Berman

2009-12-01  Stephen Berman  <[email-masked]>

	* calendar/diary-lib.el (diary-list-entries-2): Use
	save-restriction and widen in order to include all entries from
	files being visited with narrowing, as in Todo mode (bug#5XXX).

*** emacs/lisp/calendar/diary-lib.el.~1.195.~	2009-11-12 22:21:21.000000000 +0100
--- emacs/lisp/calendar/diary-lib.el	2009-12-01 17:07:35.000000000 +0100
***************
*** 648,682 ****
                              (if symbol (regexp-quote symbol) "")
                              (mapconcat 'eval date-form "\\)\\(?:")))
              entry-start date-start temp)
!         (goto-char (point-min))
!         (while (re-search-forward regexp nil t)
!           (if backup (re-search-backward "\\<" nil t))
!           ;; regexp moves us past the end of date, onto the next line.
!           ;; Trailing whitespace after date not allowed (see diary-file).
!           (if (and (bolp) (not (looking-at "[ \t]")))
!               ;; Diary entry that consists only of date.
!               (backward-char 1)
!             ;; Found a nonempty diary entry--make it
!             ;; visible and add it to the list.
!             (setq date-start (line-end-position 0))
!             ;; Actual entry starts on the next-line?
!             (if (looking-at "[ \t]*\n[ \t]") (forward-line 1))
!             (setq entry-found t
!                   entry-start (point))
!             (forward-line 1)
!             (while (looking-at "[ \t]") ; continued entry
!               (forward-line 1))
!             (unless (and (eobp) (not (bolp)))
!               (backward-char 1))
!             (unless list-only
!               (remove-overlays date-start (point) 'invisible 'diary))
!             (setq temp (diary-pull-attrs
!                         (buffer-substring-no-properties
!                          entry-start (point)) globattr))
!             (diary-add-to-list
!              (or gdate date) (car temp)
!              (buffer-substring-no-properties (1+ date-start) (1- entry-start))
!              (copy-marker entry-start) (cadr temp))))))
      entry-found))
  
  (defvar original-date)                  ; from diary-list-entries
--- 648,684 ----
                              (if symbol (regexp-quote symbol) "")
                              (mapconcat 'eval date-form "\\)\\(?:")))
              entry-start date-start temp)
! 	(save-restriction
! 	  (widen)
! 	  (goto-char (point-min))
! 	  (while (re-search-forward regexp nil t)
! 	    (if backup (re-search-backward "\\<" nil t))
! 	    ;; regexp moves us past the end of date, onto the next line.
! 	    ;; Trailing whitespace after date not allowed (see diary-file).
! 	    (if (and (bolp) (not (looking-at "[ \t]")))
! 		;; Diary entry that consists only of date.
! 		(backward-char 1)
! 	      ;; Found a nonempty diary entry--make it
! 	      ;; visible and add it to the list.
! 	      (setq date-start (line-end-position 0))
! 	      ;; Actual entry starts on the next-line?
! 	      (if (looking-at "[ \t]*\n[ \t]") (forward-line 1))
! 	      (setq entry-found t
! 		    entry-start (point))
! 	      (forward-line 1)
! 	      (while (looking-at "[ \t]") ; continued entry
! 		(forward-line 1))
! 	      (unless (and (eobp) (not (bolp)))
! 		(backward-char 1))
! 	      (unless list-only
! 		(remove-overlays date-start (point) 'invisible 'diary))
! 	      (setq temp (diary-pull-attrs
! 			  (buffer-substring-no-properties
! 			   entry-start (point)) globattr))
! 	      (diary-add-to-list
! 	       (or gdate date) (car temp)
! 	       (buffer-substring-no-properties (1+ date-start) (1- entry-start))
! 	       (copy-marker entry-start) (cadr temp)))))))
      entry-found))
  
  (defvar original-date)                  ; from diary-list-entries