13053
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
1 ;;; cal-move.el --- calendar functions for movement in the calendar
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
2
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
4
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
5 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
6 ;; Keywords: calendar
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
7 ;; Human-Keywords: calendar
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
8
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
9 ;; This file is part of GNU Emacs.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
10
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
14 ;; any later version.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
15
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful,
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
19 ;; GNU General Public License for more details.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
20
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
24
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
25 ;;; Commentary:
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
26
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
27 ;; This collection of functions implements movement in the calendar for
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
28 ;; calendar.el.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
29
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
30 ;; Comments, corrections, and improvements should be sent to
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
31 ;; Edward M. Reingold Department of Computer Science
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
32 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
33 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
34 ;; Urbana, Illinois 61801
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
35
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
36 ;;; Code:
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
37
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
38 (defun calendar-goto-today ()
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
39 "Reposition the calendar window so the current date is visible."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
40 (interactive)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
41 (let ((today (calendar-current-date)));; The date might have changed.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
42 (if (not (calendar-date-is-visible-p today))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
43 (generate-calendar-window)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
44 (update-calendar-mode-line)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
45 (calendar-cursor-to-visible-date today))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
46
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
47 (defun calendar-forward-month (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
48 "Move the cursor forward ARG months.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
49 Movement is backward if ARG is negative."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
50 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
51 (calendar-cursor-to-nearest-date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
52 (let* ((cursor-date (calendar-cursor-to-date t))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
53 (month (extract-calendar-month cursor-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
54 (day (extract-calendar-day cursor-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
55 (year (extract-calendar-year cursor-date)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
56 (increment-calendar-month month year arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
57 (let ((last (calendar-last-day-of-month month year)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
58 (if (< last day)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
59 (setq day last)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
60 ;; Put the new month on the screen, if needed, and go to the new date.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
61 (let ((new-cursor-date (list month day year)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
62 (if (not (calendar-date-is-visible-p new-cursor-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
63 (calendar-other-month month year))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
64 (calendar-cursor-to-visible-date new-cursor-date))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
65
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
66 (defun calendar-forward-year (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
67 "Move the cursor forward by ARG years.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
68 Movement is backward if ARG is negative."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
69 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
70 (calendar-forward-month (* 12 arg)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
71
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
72 (defun calendar-backward-month (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
73 "Move the cursor backward by ARG months.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
74 Movement is forward if ARG is negative."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
75 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
76 (calendar-forward-month (- arg)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
77
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
78 (defun calendar-backward-year (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
79 "Move the cursor backward ARG years.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
80 Movement is forward is ARG is negative."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
81 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
82 (calendar-forward-month (* -12 arg)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
83
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
84 (defun scroll-calendar-left (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
85 "Scroll the displayed calendar left by ARG months.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
86 If ARG is negative the calendar is scrolled right. Maintains the relative
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
87 position of the cursor with respect to the calendar as well as possible."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
88 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
89 (calendar-cursor-to-nearest-date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
90 (let ((old-date (calendar-cursor-to-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
91 (today (calendar-current-date)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
92 (if (/= arg 0)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
93 (progn
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
94 (increment-calendar-month displayed-month displayed-year arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
95 (generate-calendar-window displayed-month displayed-year)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
96 (calendar-cursor-to-visible-date
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
97 (cond
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
98 ((calendar-date-is-visible-p old-date) old-date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
99 ((calendar-date-is-visible-p today) today)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
100 (t (list displayed-month 1 displayed-year))))))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
101
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
102 (defun scroll-calendar-right (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
103 "Scroll the displayed calendar window right by ARG months.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
104 If ARG is negative the calendar is scrolled left. Maintains the relative
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
105 position of the cursor with respect to the calendar as well as possible."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
106 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
107 (scroll-calendar-left (- arg)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
108
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
109 (defun scroll-calendar-left-three-months (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
110 "Scroll the displayed calendar window left by 3*ARG months.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
111 If ARG is negative the calendar is scrolled right. Maintains the relative
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
112 position of the cursor with respect to the calendar as well as possible."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
113 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
114 (scroll-calendar-left (* 3 arg)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
115
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
116 (defun scroll-calendar-right-three-months (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
117 "Scroll the displayed calendar window right by 3*ARG months.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
118 If ARG is negative the calendar is scrolled left. Maintains the relative
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
119 position of the cursor with respect to the calendar as well as possible."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
120 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
121 (scroll-calendar-left (* -3 arg)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
122
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
123 (defun calendar-cursor-to-nearest-date ()
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
124 "Move the cursor to the closest date.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
125 The position of the cursor is unchanged if it is already on a date.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
126 Returns the list (month day year) giving the cursor position."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
127 (let ((date (calendar-cursor-to-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
128 (column (current-column)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
129 (if date
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
130 date
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
131 (if (> 3 (count-lines (point-min) (point)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
132 (progn
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
133 (goto-line 3)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
134 (move-to-column column)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
135 (if (not (looking-at "[0-9]"))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
136 (if (and (not (looking-at " *$"))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
137 (or (< column 25)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
138 (and (> column 27)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
139 (< column 50))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
140 (and (> column 52)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
141 (< column 75))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
142 (progn
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
143 (re-search-forward "[0-9]" nil t)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
144 (backward-char 1))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
145 (re-search-backward "[0-9]" nil t)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
146 (calendar-cursor-to-date))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
147
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
148 (defun calendar-forward-day (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
149 "Move the cursor forward ARG days.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
150 Moves backward if ARG is negative."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
151 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
152 (if (/= 0 arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
153 (let*
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
154 ((cursor-date (calendar-cursor-to-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
155 (cursor-date (if cursor-date
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
156 cursor-date
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
157 (if (> arg 0) (setq arg (1- arg)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
158 (calendar-cursor-to-nearest-date)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
159 (new-cursor-date
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
160 (calendar-gregorian-from-absolute
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
161 (+ (calendar-absolute-from-gregorian cursor-date) arg)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
162 (new-display-month (extract-calendar-month new-cursor-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
163 (new-display-year (extract-calendar-year new-cursor-date)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
164 ;; Put the new month on the screen, if needed, and go to the new date.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
165 (if (not (calendar-date-is-visible-p new-cursor-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
166 (calendar-other-month new-display-month new-display-year))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
167 (calendar-cursor-to-visible-date new-cursor-date))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
168
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
169 (defun calendar-backward-day (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
170 "Move the cursor back ARG days.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
171 Moves forward if ARG is negative."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
172 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
173 (calendar-forward-day (- arg)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
174
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
175 (defun calendar-forward-week (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
176 "Move the cursor forward ARG weeks.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
177 Moves backward if ARG is negative."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
178 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
179 (calendar-forward-day (* arg 7)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
180
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
181 (defun calendar-backward-week (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
182 "Move the cursor back ARG weeks.
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
183 Moves forward if ARG is negative."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
184 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
185 (calendar-forward-day (* arg -7)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
186
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
187 (defun calendar-beginning-of-week (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
188 "Move the cursor back ARG calendar-week-start-day's."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
189 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
190 (calendar-cursor-to-nearest-date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
191 (let ((day (calendar-day-of-week (calendar-cursor-to-date))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
192 (calendar-backward-day
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
193 (if (= day calendar-week-start-day)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
194 (* 7 arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
195 (+ (mod (- day calendar-week-start-day) 7)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
196 (* 7 (1- arg)))))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
197
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
198 (defun calendar-end-of-week (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
199 "Move the cursor forward ARG calendar-week-start-day+6's."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
200 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
201 (calendar-cursor-to-nearest-date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
202 (let ((day (calendar-day-of-week (calendar-cursor-to-date))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
203 (calendar-forward-day
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
204 (if (= day (mod (1- calendar-week-start-day) 7))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
205 (* 7 arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
206 (+ (- 6 (mod (- day calendar-week-start-day) 7))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
207 (* 7 (1- arg)))))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
208
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
209 (defun calendar-beginning-of-month (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
210 "Move the cursor backward ARG month beginnings."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
211 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
212 (calendar-cursor-to-nearest-date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
213 (let* ((date (calendar-cursor-to-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
214 (month (extract-calendar-month date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
215 (day (extract-calendar-day date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
216 (year (extract-calendar-year date)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
217 (if (= day 1)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
218 (calendar-backward-month arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
219 (calendar-cursor-to-visible-date (list month 1 year))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
220 (calendar-backward-month (1- arg)))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
221
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
222 (defun calendar-end-of-month (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
223 "Move the cursor forward ARG month ends."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
224 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
225 (calendar-cursor-to-nearest-date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
226 (let* ((date (calendar-cursor-to-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
227 (month (extract-calendar-month date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
228 (day (extract-calendar-day date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
229 (year (extract-calendar-year date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
230 (last-day (calendar-last-day-of-month month year)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
231 (if (/= day last-day)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
232 (progn
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
233 (calendar-cursor-to-visible-date (list month last-day year))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
234 (setq arg (1- arg))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
235 (increment-calendar-month month year arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
236 (let ((last-day (list
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
237 month
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
238 (calendar-last-day-of-month month year)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
239 year)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
240 (if (not (calendar-date-is-visible-p last-day))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
241 (calendar-other-month month year)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
242 (calendar-cursor-to-visible-date last-day)))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
243
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
244 (defun calendar-beginning-of-year (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
245 "Move the cursor backward ARG year beginnings."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
246 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
247 (calendar-cursor-to-nearest-date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
248 (let* ((date (calendar-cursor-to-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
249 (month (extract-calendar-month date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
250 (day (extract-calendar-day date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
251 (year (extract-calendar-year date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
252 (jan-first (list 1 1 year)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
253 (if (and (= day 1) (= 1 month))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
254 (calendar-backward-month (* 12 arg))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
255 (if (and (= arg 1)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
256 (calendar-date-is-visible-p jan-first))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
257 (calendar-cursor-to-visible-date jan-first)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
258 (calendar-other-month 1 (- year (1- arg)))))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
259
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
260 (defun calendar-end-of-year (arg)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
261 "Move the cursor forward ARG year beginnings."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
262 (interactive "p")
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
263 (calendar-cursor-to-nearest-date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
264 (let* ((date (calendar-cursor-to-date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
265 (month (extract-calendar-month date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
266 (day (extract-calendar-day date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
267 (year (extract-calendar-year date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
268 (dec-31 (list 12 31 year)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
269 (if (and (= day 31) (= 12 month))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
270 (calendar-forward-month (* 12 arg))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
271 (if (and (= arg 1)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
272 (calendar-date-is-visible-p dec-31))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
273 (calendar-cursor-to-visible-date dec-31)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
274 (calendar-other-month 12 (- year (1- arg)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
275 (calendar-cursor-to-visible-date (list 12 31 displayed-year))))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
276
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
277 (defun calendar-cursor-to-visible-date (date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
278 "Move the cursor to DATE that is on the screen."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
279 (let* ((month (extract-calendar-month date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
280 (day (extract-calendar-day date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
281 (year (extract-calendar-year date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
282 (first-of-month-weekday (calendar-day-of-week (list month 1 year))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
283 (goto-line (+ 3
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
284 (/ (+ day -1
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
285 (mod
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
286 (- (calendar-day-of-week (list month 1 year))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
287 calendar-week-start-day)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
288 7))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
289 7)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
290 (move-to-column (+ 6
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
291 (* 25
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
292 (1+ (calendar-interval
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
293 displayed-month displayed-year month year)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
294 (* 3 (mod
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
295 (- (calendar-day-of-week date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
296 calendar-week-start-day)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
297 7))))))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
298
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
299 (defun calendar-goto-date (date)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
300 "Move cursor to DATE."
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
301 (interactive (list (calendar-read-date)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
302 (let ((month (extract-calendar-month date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
303 (year (extract-calendar-year date)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
304 (if (not (calendar-date-is-visible-p date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
305 (calendar-other-month
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
306 (if (and (= month 1) (= year 1))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
307 2
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
308 month)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
309 year)))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
310 (calendar-cursor-to-visible-date date))
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
311
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
312 (provide 'cal-move)
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
313
|
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff
changeset
|
314 ;;; cal-move.el ends here
|