Commit cc16dac3 authored by Glenn Morris's avatar Glenn Morris

(diary-face-attrs): Fix type of `width'.

(list-diary-entries-hook, mark-diary-entries-hook)
(include-other-diary-files, mark-included-diary-files): Doc fixes.
(diary-set-header): New function.
(diary-header-line-flag, diary-header-line-format):
Use diary-set-header for custom :set function.
(diary-set-maybe-redraw): Use symbol-value rather than eval.
(diary-attrtype-convert): Use intern-soft rather than read.
(diary-display-no-entries): New function.
(simple-diary-display, fancy-diary-display): Use it.
(fancy-diary-display): Doc fix.  Remove unneeded local entry-list.
parent 872edde5
...@@ -84,7 +84,7 @@ are holidays." ...@@ -84,7 +84,7 @@ are holidays."
(defcustom diary-face-attrs (defcustom diary-face-attrs
'((" *\\[foreground:\\([-a-z]+\\)\\]$" 1 :foreground string) '((" *\\[foreground:\\([-a-z]+\\)\\]$" 1 :foreground string)
(" *\\[background:\\([-a-z]+\\)\\]$" 1 :background string) (" *\\[background:\\([-a-z]+\\)\\]$" 1 :background string)
(" *\\[width:\\([-a-z]+\\)\\]$" 1 :width symbol) (" *\\[width:\\([-a-z]+\\)\\]$" 1 :width int)
(" *\\[height:\\([-0-9a-z]+\\)\\]$" 1 :height int) (" *\\[height:\\([-0-9a-z]+\\)\\]$" 1 :height int)
(" *\\[weight:\\([-a-z]+\\)\\]$" 1 :weight symbol) (" *\\[weight:\\([-a-z]+\\)\\]$" 1 :weight symbol)
(" *\\[slant:\\([-a-z]+\\)\\]$" 1 :slant symbol) (" *\\[slant:\\([-a-z]+\\)\\]$" 1 :slant symbol)
...@@ -139,25 +139,11 @@ See the documentation for the function `list-sexp-diary-entries'." ...@@ -139,25 +139,11 @@ See the documentation for the function `list-sexp-diary-entries'."
:type 'string :type 'string
:group 'diary) :group 'diary)
;; FIXME
(defcustom list-diary-entries-hook nil (defcustom list-diary-entries-hook nil
"List of functions called after diary file is culled for relevant entries. "List of functions called after diary file is culled for relevant entries.
It is to be used for diary entries that are not found in the diary file. You might wish to add `include-other-diary-files', in which case
you will probably also want to add `mark-included-diary-files' to
A function `include-other-diary-files' is provided for use as the value of `mark-diary-entries-hook'. For example, you could use
this hook. This function enables you to use shared diary files together
with your own. The files included are specified in the diary file by lines
of the form
#include \"filename\"
This is recursive; that is, #include directives in files thus included are
obeyed. You can change the \"#include\" to some other string by changing
the variable `diary-include-string'. When you use `include-other-diary-files'
as part of the list-diary-entries-hook, you will probably also want to use the
function `mark-included-diary-files' as part of `mark-diary-entries-hook'.
For example, you could use
(add-hook 'list-diary-entries-hook 'include-other-diary-files) (add-hook 'list-diary-entries-hook 'include-other-diary-files)
(add-hook 'list-diary-entries-hook 'sort-diary-entries) (add-hook 'list-diary-entries-hook 'sort-diary-entries)
...@@ -170,20 +156,11 @@ lexicographic order." ...@@ -170,20 +156,11 @@ lexicographic order."
:options '(include-other-diary-files sort-diary-entries) :options '(include-other-diary-files sort-diary-entries)
:group 'diary) :group 'diary)
;; FIXME
(defcustom mark-diary-entries-hook nil (defcustom mark-diary-entries-hook nil
"List of functions called after marking diary entries in the calendar. "List of functions called after marking diary entries in the calendar.
You might wish to add `mark-included-diary-files', in which case
A function `mark-included-diary-files' is also provided for use as the you will probably also want to add `include-other-diary-files' to
`mark-diary-entries-hook'; it enables you to use shared diary files together `list-diary-entries-hook'."
with your own. The files included are specified in the diary file by lines
of the form
#include \"filename\"
This is recursive; that is, #include directives in files thus included are
obeyed. You can change the \"#include\" to some other string by changing the
variable `diary-include-string'. When you use `mark-included-diary-files' as
part of the mark-diary-entries-hook, you will probably also want to use the
function `include-other-diary-files' as part of `list-diary-entries-hook'."
:type 'hook :type 'hook
:options '(mark-included-diary-files) :options '(mark-included-diary-files)
:group 'diary) :group 'diary)
...@@ -306,6 +283,49 @@ template following the rules above." ...@@ -306,6 +283,49 @@ template following the rules above."
:group 'diary) :group 'diary)
(defun diary-set-header (symbol value)
"Set SYMBOL's value to VALUE, and redraw the diary header if necessary."
(let ((oldvalue (symbol-value symbol))
(dbuff (and diary-file
(find-buffer-visiting
(substitute-in-file-name diary-file)))))
(custom-set-default symbol value)
(and dbuff
(not (equal value oldvalue))
(with-current-buffer dbuff
(if (eq major-mode 'diary-mode)
(setq header-line-format (and diary-header-line-flag
diary-header-line-format)))))))
;; This can be removed once the kill/yank treatment of invisible text
;; (see etc/TODO) is fixed. -- gm
(defcustom diary-header-line-flag t
"Non-nil means `simple-diary-display' will show a header line.
The format of the header is specified by `diary-header-line-format'."
:group 'diary
:type 'boolean
:initialize 'custom-initialize-default
:set 'diary-set-header
:version "22.1")
(defvar diary-selective-display nil
"Internal diary variable; non-nil if some diary text is hidden.")
(defcustom diary-header-line-format
'(:eval (calendar-string-spread
(list (if diary-selective-display
"Some text is hidden - press \"s\" in calendar \
before edit/copy"
"Diary"))
?\s (frame-width)))
"Format of the header line displayed by `simple-diary-display'.
Only used if `diary-header-line-flag' is non-nil."
:group 'diary
:type 'sexp
:initialize 'custom-initialize-default
:set 'diary-set-header
:version "22.1")
;; The first version of this also checked for diary-selective-display ;; The first version of this also checked for diary-selective-display
;; in the non-fancy case. This was an attempt to distinguish between ;; in the non-fancy case. This was an attempt to distinguish between
;; displaying the diary and just visiting the diary file. However, ;; displaying the diary and just visiting the diary file. However,
...@@ -329,45 +349,13 @@ template following the rules above." ...@@ -329,45 +349,13 @@ template following the rules above."
"Set SYMBOL's value to VALUE, and redraw the diary if necessary. "Set SYMBOL's value to VALUE, and redraw the diary if necessary.
Redraws the diary if it is being displayed (note this is not the same as Redraws the diary if it is being displayed (note this is not the same as
just visiting the `diary-file'), and SYMBOL's value is to be changed." just visiting the `diary-file'), and SYMBOL's value is to be changed."
(let ((oldvalue (eval symbol))) ; FIXME symbol-value? (let ((oldvalue (symbol-value symbol)))
(custom-set-default symbol value) (custom-set-default symbol value)
(and (not (equal value oldvalue)) (and (not (equal value oldvalue))
(diary-live-p) (diary-live-p)
;; Note this assumes diary was called without prefix arg. ;; Note this assumes diary was called without prefix arg.
(diary)))) (diary))))
(defvar diary-selective-display nil
"Internal diary variable; non-nil if some diary text is hidden.")
;; This can be removed once the kill/yank treatment of invisible text
;; (see etc/TODO) is fixed. -- gm
(defcustom diary-header-line-flag t
"Non-nil means `simple-diary-display' will show a header line.
The format of the header is specified by `diary-header-line-format'."
:group 'diary
:type 'boolean
:initialize 'custom-initialize-default
;; FIXME overkill.
:set 'diary-set-maybe-redraw
:version "22.1")
(defcustom diary-header-line-format
'(:eval (calendar-string-spread
(list (if diary-selective-display
"Some text is hidden - press \"s\" in calendar \
before edit/copy"
"Diary"))
?\s (frame-width)))
"Format of the header line displayed by `simple-diary-display'.
Only used if `diary-header-line-flag' is non-nil."
:group 'diary
:type 'sexp
:initialize 'custom-initialize-default
;; FIXME overkill.
:set 'diary-set-maybe-redraw
:version "22.1")
(defcustom number-of-diary-entries 1 (defcustom number-of-diary-entries 1
"Specifies how many days of diary entries are to be displayed initially. "Specifies how many days of diary entries are to be displayed initially.
This variable affects the diary display when the command \\[diary] is used, This variable affects the diary display when the command \\[diary] is used,
...@@ -460,7 +448,7 @@ syntax of `*' and `:' changed to be word constituents.") ...@@ -460,7 +448,7 @@ syntax of `*' and `:' changed to be word constituents.")
"Convert string ATTRVALUE to TYPE appropriate for a face description. "Convert string ATTRVALUE to TYPE appropriate for a face description.
Valid TYPEs are: string, symbol, int, stringtnil, tnil." Valid TYPEs are: string, symbol, int, stringtnil, tnil."
(cond ((eq type 'string) attrvalue) (cond ((eq type 'string) attrvalue)
((eq type 'symbol) (read attrvalue)) ; FIXME intern-soft? ((eq type 'symbol) (intern-soft attrvalue))
((eq type 'int) (string-to-number attrvalue)) ((eq type 'int) (string-to-number attrvalue))
((eq type 'stringtnil) ((eq type 'stringtnil)
(cond ((string-equal "t" attrvalue) t) (cond ((string-equal "t" attrvalue) t)
...@@ -713,7 +701,7 @@ If LIST-ONLY is non-nil don't modify or display the buffer, only return a list." ...@@ -713,7 +701,7 @@ If LIST-ONLY is non-nil don't modify or display the buffer, only return a list."
;; d-s-p is passed to the diary display function. ;; d-s-p is passed to the diary display function.
(let ((diary-saved-point (point))) (let ((diary-saved-point (point)))
(save-excursion (save-excursion
;; FIXME move after goto? ;; FIXME move after goto? Syntax?
(setq file-glob-attrs (cadr (diary-pull-attrs nil ""))) (setq file-glob-attrs (cadr (diary-pull-attrs nil "")))
(with-syntax-table diary-syntax-table (with-syntax-table diary-syntax-table
(goto-char (point-min)) (goto-char (point-min))
...@@ -754,7 +742,7 @@ If LIST-ONLY is non-nil don't modify or display the buffer, only return a list." ...@@ -754,7 +742,7 @@ If LIST-ONLY is non-nil don't modify or display the buffer, only return a list."
(defun include-other-diary-files () (defun include-other-diary-files ()
"Include the diary entries from other diary files with those of `diary-file'. "Include the diary entries from other diary files with those of `diary-file'.
This function is suitable for use in `list-diary-entries-hook'; This function is suitable for use with `list-diary-entries-hook';
it enables you to use shared diary files together with your own. it enables you to use shared diary files together with your own.
The files included are specified in the `diary-file' by lines of this form: The files included are specified in the `diary-file' by lines of this form:
#include \"filename\" #include \"filename\"
...@@ -787,36 +775,58 @@ changing the variable `diary-include-string'." ...@@ -787,36 +775,58 @@ changing the variable `diary-include-string'."
(sleep-for 2)))) (sleep-for 2))))
(goto-char (point-min))) (goto-char (point-min)))
;; Bound in diary-list-entries. (defvar date-string) ; bound in diary-list-entries
(defvar date-string)
(defvar diary-saved-point) (defun diary-display-no-entries ()
"Common subroutine of `simple-diary-display' and `fancy-diary-display'.
;; FIXME common code with fancy-diary-display. Handles the case where there are no diary entries.
(defun simple-diary-display () Returns a cons (NOENTRIES . HOLIDAY-STRING)."
"Display the diary buffer if there are any relevant entries or holidays." (let* ((holiday-list (if holidays-in-diary-buffer
(let* ((holiday-list (if holidays-in-diary-buffer (calendar-check-holidays original-date)))
(calendar-check-holidays original-date))) (hol-string (format "%s%s%s"
(hol-string (format "%s%s%s" date-string
date-string (if holiday-list ": " "")
(if holiday-list ": " "") (mapconcat 'identity holiday-list "; ")))
(mapconcat 'identity holiday-list "; "))) (msg (format "No diary entries for %s" hol-string))
(msg (format "No diary entries for %s" hol-string)) ;; Empty list, or single item with no text.
;; If selected window is dedicated (to the calendar), ;; FIXME multiple items with no text?
;; need a new one to display the diary. (noentries (or (not diary-entries-list)
(pop-up-frames (or pop-up-frames (and (not (cdr diary-entries-list))
(window-dedicated-p (selected-window))))) (string-equal "" (cadr
(calendar-set-mode-line (format "Diary for %s" hol-string)) (car diary-entries-list)))))))
(if (or (not diary-entries-list) ;; Inconsistency: whether or not the holidays are displayed in a
(and (not (cdr diary-entries-list)) ;; separate buffer depends on if there are diary entries.
(string-equal (cadr (car diary-entries-list)) ""))) (when noentries
(if (< (length msg) (frame-width)) (if (or (< (length msg) (frame-width))
(not holiday-list))
(message "%s" msg) (message "%s" msg)
;; holiday-list which is too wide for a message gets a buffer.
(calendar-in-read-only-buffer holiday-buffer (calendar-in-read-only-buffer holiday-buffer
(calendar-set-mode-line date-string) (calendar-set-mode-line (format "Holidays for %s" date-string))
(insert (mapconcat 'identity holiday-list "\n"))) (insert (mapconcat 'identity holiday-list "\n")))
(message "No diary entries for %s" date-string)) (message "No diary entries for %s" date-string)))
(with-current-buffer (cons noentries hol-string)))
(find-buffer-visiting (substitute-in-file-name diary-file))
(defvar diary-saved-point) ; bound in diary-list-entries
(defun simple-diary-display ()
"Display the diary buffer if there are any relevant entries or holidays."
;; If selected window is dedicated (to the calendar), need a new one
;; to display the diary.
(let* ((pop-up-frames (or pop-up-frames
(window-dedicated-p (selected-window))))
(dbuff (find-buffer-visiting (substitute-in-file-name diary-file)))
(empty (diary-display-no-entries)))
;; This may be too wide, but when simple diary is used there is
;; nowhere else for the holidays to go. Also, it is documented in
;; holidays-in-diary-buffer that the holidays go in the mode-line.
;; FIXME however if there are no diary entries a separate buffer
;; is displayed - this is inconsistent.
(with-current-buffer dbuff
(calendar-set-mode-line (format "Diary for %s" (cdr empty))))
(unless (car empty) ; no entries
(with-current-buffer dbuff
(let ((window (display-buffer (current-buffer)))) (let ((window (display-buffer (current-buffer))))
;; d-s-p is passed from diary-list-entries. ;; d-s-p is passed from diary-list-entries.
(set-window-point window diary-saved-point) (set-window-point window diary-saved-point)
...@@ -853,33 +863,20 @@ changing the variable `diary-include-string'." ...@@ -853,33 +863,20 @@ changing the variable `diary-include-string'."
(defun fancy-diary-display () (defun fancy-diary-display ()
"Prepare a diary buffer with relevant entries in a fancy, noneditable form. "Prepare a diary buffer with relevant entries in a fancy, noneditable form.
This function is provided for optional use as the `diary-display-hook'." To use this function, add it to `diary-display-hook'."
;; Turn off selective-display in the diary file's buffer. ;; Turn off selective-display in the diary file's buffer.
(with-current-buffer (with-current-buffer
(find-buffer-visiting (substitute-in-file-name diary-file)) (find-buffer-visiting (substitute-in-file-name diary-file))
(diary-unhide-everything)) (diary-unhide-everything))
(if (or (not diary-entries-list) (unless (car (diary-display-no-entries)) ; no entries
(and (not (cdr diary-entries-list))
(string-equal (cadr (car diary-entries-list)) "")))
(let* ((holiday-list (if holidays-in-diary-buffer
(calendar-check-holidays original-date)))
(msg (format "No diary entries for %s %s"
(concat date-string (if holiday-list ":" ""))
(mapconcat 'identity holiday-list "; "))))
(if (<= (length msg) (frame-width))
(message "%s" msg)
(calendar-in-read-only-buffer holiday-buffer
(insert (mapconcat 'identity holiday-list "\n")))
(message "No diary entries for %s" date-string)))
;; Prepare the fancy diary buffer. ;; Prepare the fancy diary buffer.
(calendar-in-read-only-buffer fancy-diary-buffer (calendar-in-read-only-buffer fancy-diary-buffer
(calendar-set-mode-line "Diary Entries") (calendar-set-mode-line "Diary Entries")
(let ((entry-list diary-entries-list) (let ((holiday-list-last-month 1)
(holiday-list)
(holiday-list-last-month 1)
(holiday-list-last-year 1) (holiday-list-last-year 1)
(date (list 0 0 0))) (date (list 0 0 0))
(dolist (entry entry-list) holiday-list)
(dolist (entry diary-entries-list)
(unless (calendar-date-equal date (car entry)) (unless (calendar-date-equal date (car entry))
(setq date (car entry)) (setq date (car entry))
(and holidays-in-diary-buffer (and holidays-in-diary-buffer
...@@ -1305,7 +1302,7 @@ is marked. See the documentation for the function `list-sexp-diary-entries'." ...@@ -1305,7 +1302,7 @@ is marked. See the documentation for the function `list-sexp-diary-entries'."
(defun mark-included-diary-files () (defun mark-included-diary-files ()
"Mark the diary entries from other diary files with those of the diary file. "Mark the diary entries from other diary files with those of the diary file.
This function is suitable for use as the `mark-diary-entries-hook'; it enables This function is suitable for use with `mark-diary-entries-hook'; it enables
you to use shared diary files together with your own. The files included are you to use shared diary files together with your own. The files included are
specified in the `diary-file' by lines of this form: specified in the `diary-file' by lines of this form:
#include \"filename\" #include \"filename\"
......
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