comparison lisp/calendar/calendar.el @ 65620:eae4a82ba77a

(mark-visible-calendar-date): Save excursion. Re-indent within 80 columns. Use inhibit-read-only.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 19 Sep 2005 17:41:22 +0000
parents a08c0922f1c4
children 5c09efcfc1d9 ee12d75eb214
comparison
equal deleted inserted replaced
65619:e09cff91900a 65620:eae4a82ba77a
2898 (defun mark-visible-calendar-date (date &optional mark) 2898 (defun mark-visible-calendar-date (date &optional mark)
2899 "Mark DATE in the calendar window with MARK. 2899 "Mark DATE in the calendar window with MARK.
2900 MARK is a single-character string, a list of face attributes/values, or a face. 2900 MARK is a single-character string, a list of face attributes/values, or a face.
2901 MARK defaults to `diary-entry-marker'." 2901 MARK defaults to `diary-entry-marker'."
2902 (if (calendar-date-is-legal-p date) 2902 (if (calendar-date-is-legal-p date)
2903 (save-excursion 2903 (with-current-buffer calendar-buffer
2904 (set-buffer calendar-buffer) 2904 (save-excursion
2905 (calendar-cursor-to-visible-date date) 2905 (calendar-cursor-to-visible-date date)
2906 (let ((mark (or (and (stringp mark) (= (length mark) 1) mark) ; single-char 2906 (setq mark
2907 (and (listp mark) (> (length mark) 0) mark) ; attr list 2907 (or (and (stringp mark) (= (length mark) 1) mark) ; single-char
2908 (and (facep mark) mark) ; face-name 2908 (and (listp mark) (> (length mark) 0) mark) ; attr list
2909 diary-entry-marker))) 2909 (and (facep mark) mark) ; face-name
2910 (if (facep mark) 2910 diary-entry-marker))
2911 (progn ; face or an attr-list that contained a face 2911 (cond
2912 (overlay-put 2912 ;; face or an attr-list that contained a face
2913 (make-overlay (1- (point)) (1+ (point))) 'face mark)) 2913 ((facep mark)
2914 (if (and (stringp mark) 2914 (overlay-put
2915 (= (length mark) 1)) ; single-char 2915 (make-overlay (1- (point)) (1+ (point))) 'face mark))
2916 (let ((buffer-read-only nil)) 2916 ;; single-char
2917 (forward-char 1) 2917 ((and (stringp mark) (= (length mark) 1))
2918 (delete-char 1) 2918 (let ((inhibit-read-only t))
2919 (insert mark) 2919 (forward-char 1)
2920 (forward-char -2)) 2920 ;; Insert before delete so as to better preserve markers.
2921 (let ; attr list 2921 (insert mark)
2922 ((temp-face 2922 (delete-char 1)
2923 (make-symbol (apply 'concat "temp-" 2923 (forward-char -2)))
2924 (mapcar '(lambda (sym) 2924 (t ;; attr list
2925 (cond ((symbolp sym) (symbol-name sym)) 2925 (let ((temp-face
2926 ((numberp sym) (int-to-string sym)) 2926 (make-symbol
2927 (t sym))) mark)))) 2927 (apply 'concat "temp-"
2928 (faceinfo mark)) 2928 (mapcar (lambda (sym)
2929 (make-face temp-face) 2929 (cond
2930 ;; Remove :face info from the mark, copy the face info into temp-face 2930 ((symbolp sym) (symbol-name sym))
2931 (while (setq faceinfo (memq :face faceinfo)) 2931 ((numberp sym) (number-to-string sym))
2932 (copy-face (read (nth 1 faceinfo)) temp-face) 2932 (t sym)))
2933 (setcar faceinfo nil) 2933 mark))))
2934 (setcar (cdr faceinfo) nil)) 2934 (faceinfo mark))
2935 (setq mark (delq nil mark)) 2935 (make-face temp-face)
2936 ;; Apply the font aspects 2936 ;; Remove :face info from the mark, copy the face info into
2937 (apply 'set-face-attribute temp-face nil mark) 2937 ;; temp-face
2938 (overlay-put 2938 (while (setq faceinfo (memq :face faceinfo))
2939 (make-overlay (1- (point)) (1+ (point))) 'face temp-face)))))))) 2939 (copy-face (read (nth 1 faceinfo)) temp-face)
2940 (setcar faceinfo nil)
2941 (setcar (cdr faceinfo) nil))
2942 (setq mark (delq nil mark))
2943 ;; Apply the font aspects
2944 (apply 'set-face-attribute temp-face nil mark)
2945 (overlay-put
2946 (make-overlay (1- (point)) (1+ (point))) 'face temp-face))))))))
2940 2947
2941 (defun calendar-star-date () 2948 (defun calendar-star-date ()
2942 "Replace the date under the cursor in the calendar window with asterisks. 2949 "Replace the date under the cursor in the calendar window with asterisks.
2943 This function can be used with the `today-visible-calendar-hook' run after the 2950 This function can be used with the `today-visible-calendar-hook' run after the
2944 calendar window has been prepared." 2951 calendar window has been prepared."