comparison lisp/calendar/calendar.el @ 82118:baffe86b0c44

(calendar-mode-map): Move initialization into declaration. Add menu bindings (used to be done in cal-menu). (calendar-mode): Don't add an activate-menubar-hook.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 25 Jul 2007 21:59:26 +0000
parents 1ee19eca3bfc
children b98604865ea0
comparison
equal deleted inserted replaced
82117:8410b0ff0e7a 82118:baffe86b0c44
1675 (month (extract-calendar-month date)) 1675 (month (extract-calendar-month date))
1676 (year (extract-calendar-year date))) 1676 (year (extract-calendar-year date)))
1677 ;; (calendar-read-date t) returns a date with day = nil, which is 1677 ;; (calendar-read-date t) returns a date with day = nil, which is
1678 ;; not a legal date for the visible test in the diary section. 1678 ;; not a legal date for the visible test in the diary section.
1679 (if arg (setcar (cdr date) 1)) 1679 (if arg (setcar (cdr date) 1))
1680 (pop-to-buffer calendar-buffer)
1681 (increment-calendar-month month year (- calendar-offset)) 1680 (increment-calendar-month month year (- calendar-offset))
1682 (generate-calendar-window month year) 1681 (generate-calendar-window month year)
1682 ;; Display the buffer *after* generating it, so that menu entries that
1683 ;; use display-month do not fail when creating the new frame.
1684 (pop-to-buffer calendar-buffer)
1683 (if (and view-diary-entries-initially (calendar-date-is-visible-p date)) 1685 (if (and view-diary-entries-initially (calendar-date-is-visible-p date))
1684 (diary-view-entries))) 1686 (diary-view-entries)))
1685 (let* ((diary-buffer (get-file-buffer diary-file)) 1687 (let* ((diary-buffer (get-file-buffer diary-file))
1686 (diary-window (if diary-buffer (get-buffer-window diary-buffer))) 1688 (diary-window (if diary-buffer (get-buffer-window diary-buffer)))
1687 (split-height-threshold (if diary-window 2 1000))) 1689 (split-height-threshold (if diary-window 2 1000)))
2100 (run-hooks 'today-visible-calendar-hook) 2102 (run-hooks 'today-visible-calendar-hook)
2101 (run-hooks 'today-invisible-calendar-hook))))) 2103 (run-hooks 'today-invisible-calendar-hook)))))
2102 2104
2103 (defun generate-calendar (month year) 2105 (defun generate-calendar (month year)
2104 "Generate a three-month Gregorian calendar centered around MONTH, YEAR." 2106 "Generate a three-month Gregorian calendar centered around MONTH, YEAR."
2105 ;;; A negative YEAR is interpreted as BC; -1 being 1 BC, and so on. 2107 ;; A negative YEAR is interpreted as BC; -1 being 1 BC, and so on.
2106 ;;; Note that while calendars for years BC could be displayed as it 2108 ;; Note that while calendars for years BC could be displayed as it
2107 ;;; stands, almost all other calendar functions (eg holidays) would 2109 ;; stands, almost all other calendar functions (eg holidays) would
2108 ;;; at best have unpredictable results for such dates. 2110 ;; at best have unpredictable results for such dates.
2109 (if (< (+ month (* 12 (1- year))) 2) 2111 (if (< (+ month (* 12 (1- year))) 2)
2110 (error "Months before January, 1 AD cannot be displayed")) 2112 (error "Months before January, 1 AD cannot be displayed"))
2111 (setq displayed-month month 2113 (setq displayed-month month
2112 displayed-year year) 2114 displayed-year year)
2113 (erase-buffer) 2115 (erase-buffer)
2210 (defcustom calendar-debug-sexp nil 2212 (defcustom calendar-debug-sexp nil
2211 "Turn debugging on when evaluating a sexp in the diary or holiday list." 2213 "Turn debugging on when evaluating a sexp in the diary or holiday list."
2212 :type 'boolean 2214 :type 'boolean
2213 :group 'calendar) 2215 :group 'calendar)
2214 2216
2215 (defvar calendar-mode-map nil) 2217 (require 'cal-menu)
2216 (if calendar-mode-map 2218
2217 nil 2219 (defvar calendar-mode-map
2218 (let ((map (make-keymap))) 2220 (let ((map (make-keymap)))
2219 (suppress-keymap map) 2221 (suppress-keymap map)
2220 (dolist (c '(narrow-to-region mark-word mark-sexp mark-paragraph 2222 (dolist (c '(narrow-to-region mark-word mark-sexp mark-paragraph
2221 mark-defun mark-whole-buffer mark-page 2223 mark-defun mark-whole-buffer mark-page
2222 downcase-region upcase-region kill-region 2224 downcase-region upcase-region kill-region
2248 (define-key map "\ee" 'calendar-end-of-month) 2250 (define-key map "\ee" 'calendar-end-of-month)
2249 (define-key map "\e<" 'calendar-beginning-of-year) 2251 (define-key map "\e<" 'calendar-beginning-of-year)
2250 (define-key map "\e>" 'calendar-end-of-year) 2252 (define-key map "\e>" 'calendar-end-of-year)
2251 (define-key map "\C-@" 'calendar-set-mark) 2253 (define-key map "\C-@" 'calendar-set-mark)
2252 ;; Many people are used to typing C-SPC and getting C-@. 2254 ;; Many people are used to typing C-SPC and getting C-@.
2253 (define-key map [?\C- ] 'calendar-set-mark) 2255 (define-key map [?\C-\s] 'calendar-set-mark)
2254 (define-key map "\C-x\C-x" 'calendar-exchange-point-and-mark) 2256 (define-key map "\C-x\C-x" 'calendar-exchange-point-and-mark)
2255 (define-key map "\e=" 'calendar-count-days-region) 2257 (define-key map "\e=" 'calendar-count-days-region)
2256 (define-key map "gd" 'calendar-goto-date) 2258 (define-key map "gd" 'calendar-goto-date)
2257 (define-key map "gD" 'calendar-goto-day-of-year) 2259 (define-key map "gD" 'calendar-goto-day-of-year)
2258 (define-key map "gj" 'calendar-goto-julian-date) 2260 (define-key map "gj" 'calendar-goto-julian-date)
2336 (define-key map "tfw" 'cal-tex-cursor-filofax-2week) 2338 (define-key map "tfw" 'cal-tex-cursor-filofax-2week)
2337 (define-key map "tfW" 'cal-tex-cursor-filofax-week) 2339 (define-key map "tfW" 'cal-tex-cursor-filofax-week)
2338 (define-key map "tfy" 'cal-tex-cursor-filofax-year) 2340 (define-key map "tfy" 'cal-tex-cursor-filofax-year)
2339 (define-key map "ty" 'cal-tex-cursor-year) 2341 (define-key map "ty" 'cal-tex-cursor-year)
2340 (define-key map "tY" 'cal-tex-cursor-year-landscape) 2342 (define-key map "tY" 'cal-tex-cursor-year-landscape)
2341 (setq calendar-mode-map map) 2343
2342 ;; Require cal-menu after initializing calendar-mode-map because it uses it. 2344 (define-key map [menu-bar edit] 'undefined)
2343 (require 'cal-menu))) 2345 (define-key map [menu-bar search] 'undefined)
2346 ;; This ignores the mouse-up event after the mouse-down that pops up the
2347 ;; context menu. It should not be necessary because the mouse-up event
2348 ;; should be eaten up by the menu-handling toolkit.
2349 ;; (define-key map [mouse-2] 'ignore)
2350
2351 (easy-menu-define nil map nil cal-menu-moon-menu)
2352 (easy-menu-define nil map nil cal-menu-diary-menu)
2353 (easy-menu-define nil map nil cal-menu-holidays-menu)
2354 (easy-menu-define nil map nil cal-menu-goto-menu)
2355 (easy-menu-define nil map nil cal-menu-scroll-menu)
2356
2357 (define-key map [down-mouse-3]
2358 (easy-menu-binding cal-menu-context-mouse-menu))
2359 (define-key map [down-mouse-2]
2360 (easy-menu-binding cal-menu-global-mouse-menu))
2361
2362 map))
2344 2363
2345 (defun describe-calendar-mode () 2364 (defun describe-calendar-mode ()
2346 "Create a help buffer with a brief description of the `calendar-mode'." 2365 "Create a help buffer with a brief description of the `calendar-mode'."
2347 (interactive) 2366 (interactive)
2348 (help-setup-xref (list #'describe-calendar-mode) (interactive-p)) 2367 (help-setup-xref (list #'describe-calendar-mode) (interactive-p))
2399 This must be a list of items that evaluate to strings--those strings are 2418 This must be a list of items that evaluate to strings--those strings are
2400 evaluated and concatenated together, evenly separated by blanks. The variable 2419 evaluated and concatenated together, evenly separated by blanks. The variable
2401 `date' is available for use as the date under (or near) the cursor; `date' 2420 `date' is available for use as the date under (or near) the cursor; `date'
2402 defaults to the current date if it is otherwise undefined. Here is an example 2421 defaults to the current date if it is otherwise undefined. Here is an example
2403 value that has the Hebrew date, the day number/days remaining in the year, 2422 value that has the Hebrew date, the day number/days remaining in the year,
2404 and the ISO week/year numbers in the mode. When calendar-move-hook is set to 2423 and the ISO week/year numbers in the mode. When `calendar-move-hook' is set
2405 'update-calendar-mode-line, these mode line shows these values for the date 2424 to `update-calendar-mode-line', these mode line shows these values for the date
2406 under the cursor: 2425 under the cursor:
2407 2426
2408 (list 2427 (list
2409 \"\" 2428 \"\"
2410 '(calendar-hebrew-date-string date) 2429 '(calendar-hebrew-date-string date)
2416 '(let* ((d (calendar-absolute-from-gregorian date)) 2435 '(let* ((d (calendar-absolute-from-gregorian date))
2417 (iso-date (calendar-iso-from-absolute d))) 2436 (iso-date (calendar-iso-from-absolute d)))
2418 (format \"ISO week %d of %d\" 2437 (format \"ISO week %d of %d\"
2419 (extract-calendar-month iso-date) 2438 (extract-calendar-month iso-date)
2420 (extract-calendar-year iso-date))) 2439 (extract-calendar-year iso-date)))
2421 \"\")) 2440 \"\"))")
2422 ")
2423 2441
2424 (defun mouse-scroll-calendar-left (event) 2442 (defun mouse-scroll-calendar-left (event)
2425 "Scroll the displayed calendar left by one month. 2443 "Scroll the displayed calendar left by one month.
2426 Maintains the relative position of the cursor 2444 Maintains the relative position of the cursor
2427 with respect to the calendar as well as possible." 2445 with respect to the calendar as well as possible."
2472 (setq mode-name "Calendar") 2490 (setq mode-name "Calendar")
2473 (use-local-map calendar-mode-map) 2491 (use-local-map calendar-mode-map)
2474 (setq buffer-read-only t) 2492 (setq buffer-read-only t)
2475 (setq indent-tabs-mode nil) 2493 (setq indent-tabs-mode nil)
2476 (update-calendar-mode-line) 2494 (update-calendar-mode-line)
2477 (add-hook 'activate-menubar-hook 'cal-menu-update nil t)
2478 (make-local-variable 'calendar-mark-ring) 2495 (make-local-variable 'calendar-mark-ring)
2479 (make-local-variable 'displayed-month);; Month in middle of window. 2496 (make-local-variable 'displayed-month);; Month in middle of window.
2480 (make-local-variable 'displayed-year) ;; Year in middle of window. 2497 (make-local-variable 'displayed-year) ;; Year in middle of window.
2481 (set (make-local-variable 'font-lock-defaults) 2498 (set (make-local-variable 'font-lock-defaults)
2482 '(calendar-font-lock-keywords t)) 2499 '(calendar-font-lock-keywords t))
2596 (t displayed-year)))) 2613 (t displayed-year))))
2597 (if (and (looking-at "[ 0-9]?[0-9][^0-9]") 2614 (if (and (looking-at "[ 0-9]?[0-9][^0-9]")
2598 (< 2 (count-lines (point-min) (point)))) 2615 (< 2 (count-lines (point-min) (point))))
2599 (save-excursion 2616 (save-excursion
2600 (if (not (looking-at " ")) 2617 (if (not (looking-at " "))
2601 (re-search-backward "[^0-9]")) 2618 (re-search-backward "[^0-9]"))
2602 (list month 2619 (list month
2603 (string-to-number (buffer-substring (1+ (point)) (+ 4 (point)))) 2620 (string-to-number (buffer-substring (1+ (point)) (+ 4 (point))))
2604 year)) 2621 year))
2605 (if (and (looking-at "\\*") 2622 (if (and (looking-at "\\*")
2606 (save-excursion 2623 (save-excursion