Commit 17a46341 authored by Glenn Morris's avatar Glenn Morris
Browse files

Use temp-buffers when not displaying the diary.

* lisp/calendar/diary-lib.el (diary-list-entries): Use temp buffers when
not displaying the diary.
(diary-add-to-list): If no buffer-file-name, fall back to diary-file.
* lisp/calendar/appt.el (appt-check): No longer need to kill diary.
parent 7161e329
2010-09-29 Glenn Morris <rgm@gnu.org> 2010-09-29 Glenn Morris <rgm@gnu.org>
   
* calendar/diary-lib.el (diary-list-entries): Use temp buffers when
not displaying the diary.
(diary-add-to-list): If no buffer-file-name, fall back to diary-file.
* calendar/appt.el (appt-check): No longer need to kill diary.
* calendar/diary-lib.el (diary-list-entries): Move the * calendar/diary-lib.el (diary-list-entries): Move the
"Preparing..." message entirely here. "Preparing..." message entirely here.
(diary-simple-display, diary-fancy-display): Move "Preparing..." (diary-simple-display, diary-fancy-display): Move "Preparing..."
......
...@@ -257,8 +257,6 @@ The variable `appt-audible' controls the audible reminder." ...@@ -257,8 +257,6 @@ The variable `appt-audible' controls the audible reminder."
(message "%s" string))))) (message "%s" string)))))
(defvar diary-selective-display)
(defun appt-check (&optional force) (defun appt-check (&optional force)
"Check for an appointment and update any reminder display. "Check for an appointment and update any reminder display.
If optional argument FORCE is non-nil, reparse the diary file for If optional argument FORCE is non-nil, reparse the diary file for
...@@ -326,7 +324,7 @@ displayed in a window: ...@@ -326,7 +324,7 @@ displayed in a window:
(mode-line-only (unless full-check appt-now-displayed)) (mode-line-only (unless full-check appt-now-displayed))
now cur-comp-time appt-comp-time appt-warn-time) now cur-comp-time appt-comp-time appt-warn-time)
(when (or full-check mode-line-only) (when (or full-check mode-line-only)
(save-excursion (save-excursion ; FIXME ?
;; Convert current time to minutes after midnight (12.01am = 1). ;; Convert current time to minutes after midnight (12.01am = 1).
(setq now (decode-time) (setq now (decode-time)
cur-comp-time (+ (* 60 (nth 2 now)) (nth 1 now))) cur-comp-time (+ (* 60 (nth 2 now)) (nth 1 now)))
...@@ -337,23 +335,13 @@ displayed in a window: ...@@ -337,23 +335,13 @@ displayed in a window:
(ignore-errors (ignore-errors
(let ((diary-hook (if (assoc 'appt-make-list diary-hook) (let ((diary-hook (if (assoc 'appt-make-list diary-hook)
diary-hook diary-hook
(cons 'appt-make-list diary-hook))) (cons 'appt-make-list diary-hook))))
d-buff d-buff2)
(if appt-display-diary (if appt-display-diary
(diary) (diary)
(setq d-buff (find-buffer-visiting diary-file))
;; Not displaying the diary, so we can ignore ;; Not displaying the diary, so we can ignore
;; diary-number-of-entries. Since appt.el only ;; diary-number-of-entries. Since appt.el only
;; works on a daily basis, no need for more entries. ;; works on a daily basis, no need for more entries.
(diary-list-entries (calendar-current-date) 1 t) (diary-list-entries (calendar-current-date) 1 t)))))
;; If diary buffer did not exist before this command, kill it.
;; FIXME does not kill any included diary files.
;; The real issue is that (diary) should not have
;; the side effect of visiting all the diary files.
;; It is not really appt.el's job to clean up this mess...
(and (not d-buff)
(setq d-buff2 (find-buffer-visiting diary-file))
(kill-buffer d-buff2))))))
(setq appt-prev-comp-time cur-comp-time (setq appt-prev-comp-time cur-comp-time
appt-mode-string nil appt-mode-string nil
appt-display-count nil) appt-display-count nil)
......
...@@ -594,19 +594,20 @@ The entry is added to the list as (DATE STRING SPECIFIER LOCATOR ...@@ -594,19 +594,20 @@ The entry is added to the list as (DATE STRING SPECIFIER LOCATOR
GLOBCOLOR), where LOCATOR has the form (MARKER FILENAME LITERAL), GLOBCOLOR), where LOCATOR has the form (MARKER FILENAME LITERAL),
FILENAME being the file containing the diary entry." FILENAME being the file containing the diary entry."
(when (and date string) (when (and date string)
(if diary-file-name-prefix ;; b-f-n is nil if we are visiting an include file in a temp-buffer.
(let ((prefix (funcall diary-file-name-prefix-function (let ((dfile (or (buffer-file-name) diary-file)))
(buffer-file-name)))) (if diary-file-name-prefix
(or (string-equal prefix "") (let ((prefix (funcall diary-file-name-prefix-function dfile)))
(setq string (format "[%s] %s" prefix string))))) (or (string-equal prefix "")
(and diary-modify-entry-list-string-function (setq string (format "[%s] %s" prefix string)))))
(setq string (funcall diary-modify-entry-list-string-function (and diary-modify-entry-list-string-function
string))) (setq string (funcall diary-modify-entry-list-string-function
(setq diary-entries-list string)))
(append diary-entries-list (setq diary-entries-list
(list (list date string specifier (append diary-entries-list
(list marker (buffer-file-name) literal) (list (list date string specifier
globcolor)))))) (list marker dfile literal)
globcolor)))))))
(define-obsolete-function-alias 'add-to-diary-list 'diary-add-to-list "23.1") (define-obsolete-function-alias 'add-to-diary-list 'diary-add-to-list "23.1")
...@@ -760,65 +761,72 @@ LIST-ONLY is non-nil, in which case it just returns the list." ...@@ -760,65 +761,72 @@ LIST-ONLY is non-nil, in which case it just returns the list."
(diary-buffer (find-buffer-visiting diary-file)) (diary-buffer (find-buffer-visiting diary-file))
;; Dynamically bound in diary-include-other-diary-files. ;; Dynamically bound in diary-include-other-diary-files.
(d-incp (and (boundp 'diary-including) diary-including)) (d-incp (and (boundp 'diary-including) diary-including))
diary-entries-list file-glob-attrs) diary-entries-list file-glob-attrs temp-buff)
(unless d-incp (unless d-incp
(setq diary-included-files nil) (setq diary-included-files nil)
(message "Preparing diary...")) (message "Preparing diary..."))
(save-current-buffer (unwind-protect
(if (not diary-buffer) (with-current-buffer (or diary-buffer
(set-buffer (find-file-noselect diary-file t)) (if list-only
(set-buffer diary-buffer) (setq temp-buff (generate-new-buffer
(or (verify-visited-file-modtime diary-buffer) " *diary-temp*"))
(revert-buffer t t))) (find-file-noselect diary-file t)))
;; Setup things like the header-line-format and invisibility-spec. (if diary-buffer
(if (eq major-mode (default-value 'major-mode)) (or (verify-visited-file-modtime diary-buffer)
(diary-mode) (revert-buffer t t)))
;; This kludge is to make customizations to (if temp-buff
;; diary-header-line-flag after diary has been displayed ;; If including, caller has already verified it is readable.
;; take effect. Unconditionally calling (diary-mode) (insert-file-contents diary-file)
;; clobbers file local variables. ;; Setup things like the header-line-format and invisibility-spec.
;; http://lists.gnu.org/archive/html/emacs-pretest-bug/2007-03/msg00363.html (if (eq major-mode (default-value 'major-mode))
;; http://lists.gnu.org/archive/html/emacs-pretest-bug/2007-04/msg00404.html (diary-mode)
(if (eq major-mode 'diary-mode) ;; This kludge is to make customizations to
(setq header-line-format (and diary-header-line-flag ;; diary-header-line-flag after diary has been displayed
diary-header-line-format)))) ;; take effect. Unconditionally calling (diary-mode)
;; d-s-p is passed to the diary display function. ;; clobbers file local variables.
(let ((diary-saved-point (point))) ;; http://lists.gnu.org/archive/html/emacs-pretest-bug/2007-03/msg00363.html
(save-excursion ;; http://lists.gnu.org/archive/html/emacs-pretest-bug/2007-04/msg00404.html
(save-restriction (if (eq major-mode 'diary-mode)
(widen) ; bug#5093 (setq header-line-format (and diary-header-line-flag
(setq file-glob-attrs (cadr (diary-pull-attrs nil ""))) diary-header-line-format)))))
(with-syntax-table diary-syntax-table ;; d-s-p is passed to the diary display function.
(goto-char (point-min)) (let ((diary-saved-point (point)))
(unless list-only (save-excursion
(let ((ol (make-overlay (point-min) (point-max) nil t nil))) (save-restriction
(set (make-local-variable 'diary-selective-display) t) (widen) ; bug#5093
(overlay-put ol 'invisible 'diary) (setq file-glob-attrs (cadr (diary-pull-attrs nil "")))
(overlay-put ol 'evaporate t))) (with-syntax-table diary-syntax-table
(dotimes (idummy number) (goto-char (point-min))
(let ((sexp-found (diary-list-sexp-entries date)) (unless list-only
(entry-found (diary-list-entries-2 (let ((ol (make-overlay (point-min) (point-max) nil t nil)))
date diary-nonmarking-symbol (set (make-local-variable 'diary-selective-display) t)
file-glob-attrs list-only))) (overlay-put ol 'invisible 'diary)
(if diary-list-include-blanks (overlay-put ol 'evaporate t)))
(or sexp-found entry-found (dotimes (idummy number)
(diary-add-to-list date "" "" "" ""))) (let ((sexp-found (diary-list-sexp-entries date))
(setq date (entry-found (diary-list-entries-2
(calendar-gregorian-from-absolute date diary-nonmarking-symbol
(1+ (calendar-absolute-from-gregorian date))))))) file-glob-attrs list-only)))
(goto-char (point-min)) (if diary-list-include-blanks
(run-hooks 'diary-nongregorian-listing-hook (or sexp-found entry-found
'diary-list-entries-hook) (diary-add-to-list date "" "" "" "")))
(unless list-only (setq date
(if (and diary-display-function (calendar-gregorian-from-absolute
(listp diary-display-function)) (1+ (calendar-absolute-from-gregorian date)))))))
;; Backwards compatibility. (goto-char (point-min))
(run-hooks 'diary-display-function) (run-hooks 'diary-nongregorian-listing-hook
(funcall (or diary-display-function 'diary-list-entries-hook)
'diary-simple-display)))) (unless list-only
(run-hooks 'diary-hook) (if (and diary-display-function
(or d-incp (message "Preparing diary...done")) (listp diary-display-function))
diary-entries-list))))))) ;; Backwards compatibility.
(run-hooks 'diary-display-function)
(funcall (or diary-display-function
'diary-simple-display))))
(run-hooks 'diary-hook)))))
(and temp-buff (buffer-name temp-buff) (kill-buffer temp-buff)))
(or d-incp (message "Preparing diary...done"))
diary-entries-list)))
(define-obsolete-function-alias 'list-diary-entries 'diary-list-entries "22.1") (define-obsolete-function-alias 'list-diary-entries 'diary-list-entries "22.1")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment