comparison lisp/calendar/cal-move.el @ 93809:3ff2b47de8f2

Update for calendar.el name changes.
author Glenn Morris <rgm@gnu.org>
date Mon, 07 Apr 2008 01:59:37 +0000
parents b9615f927009
children bf9ef749c23e
comparison
equal deleted inserted replaced
93808:2c72483f42c9 93809:3ff2b47de8f2
54 (re-search-forward "[0-9]" nil t) 54 (re-search-forward "[0-9]" nil t)
55 (backward-char 1)) 55 (backward-char 1))
56 (re-search-backward "[0-9]" nil t))) 56 (re-search-backward "[0-9]" nil t)))
57 (calendar-cursor-to-date)))) 57 (calendar-cursor-to-date))))
58 58
59 (defvar displayed-month) ; from generate-calendar 59 (defvar displayed-month) ; from calendar-generate
60 (defvar displayed-year) 60 (defvar displayed-year)
61 61
62 ;;;###cal-autoload 62 ;;;###cal-autoload
63 (defun calendar-cursor-to-visible-date (date) 63 (defun calendar-cursor-to-visible-date (date)
64 "Move the cursor to DATE that is on the screen." 64 "Move the cursor to DATE that is on the screen."
65 (let ((month (extract-calendar-month date)) 65 (let ((month (calendar-extract-month date))
66 (day (extract-calendar-day date)) 66 (day (calendar-extract-day date))
67 (year (extract-calendar-year date))) 67 (year (calendar-extract-year date)))
68 (goto-line (+ 3 68 (goto-line (+ 3
69 (/ (+ day -1 69 (/ (+ day -1
70 (mod 70 (mod
71 (- (calendar-day-of-week (list month 1 year)) 71 (- (calendar-day-of-week (list month 1 year))
72 calendar-week-start-day) 72 calendar-week-start-day)
85 (defun calendar-goto-today () 85 (defun calendar-goto-today ()
86 "Reposition the calendar window so the current date is visible." 86 "Reposition the calendar window so the current date is visible."
87 (interactive) 87 (interactive)
88 (let ((today (calendar-current-date))) ; the date might have changed 88 (let ((today (calendar-current-date))) ; the date might have changed
89 (if (not (calendar-date-is-visible-p today)) 89 (if (not (calendar-date-is-visible-p today))
90 (generate-calendar-window) 90 (calendar-generate-window)
91 (update-calendar-mode-line) 91 (calendar-update-mode-line)
92 (calendar-cursor-to-visible-date today))) 92 (calendar-cursor-to-visible-date today)))
93 (run-hooks 'calendar-move-hook)) 93 (run-hooks 'calendar-move-hook))
94 94
95 ;;;###cal-autoload 95 ;;;###cal-autoload
96 (defun calendar-forward-month (arg) 96 (defun calendar-forward-month (arg)
97 "Move the cursor forward ARG months. 97 "Move the cursor forward ARG months.
98 Movement is backward if ARG is negative." 98 Movement is backward if ARG is negative."
99 (interactive "p") 99 (interactive "p")
100 (calendar-cursor-to-nearest-date) 100 (calendar-cursor-to-nearest-date)
101 (let* ((cursor-date (calendar-cursor-to-date t)) 101 (let* ((cursor-date (calendar-cursor-to-date t))
102 (month (extract-calendar-month cursor-date)) 102 (month (calendar-extract-month cursor-date))
103 (day (extract-calendar-day cursor-date)) 103 (day (calendar-extract-day cursor-date))
104 (year (extract-calendar-year cursor-date)) 104 (year (calendar-extract-year cursor-date))
105 (last (progn 105 (last (progn
106 (increment-calendar-month month year arg) 106 (calendar-increment-month month year arg)
107 (calendar-last-day-of-month month year))) 107 (calendar-last-day-of-month month year)))
108 (day (min last day)) 108 (day (min last day))
109 ;; Put the new month on the screen, if needed, and go to the new date. 109 ;; Put the new month on the screen, if needed, and go to the new date.
110 (new-cursor-date (list month day year))) 110 (new-cursor-date (list month day year)))
111 (if (not (calendar-date-is-visible-p new-cursor-date)) 111 (if (not (calendar-date-is-visible-p new-cursor-date))
149 (unless (zerop arg) 149 (unless (zerop arg)
150 (let ((old-date (calendar-cursor-to-date)) 150 (let ((old-date (calendar-cursor-to-date))
151 (today (calendar-current-date)) 151 (today (calendar-current-date))
152 (month displayed-month) 152 (month displayed-month)
153 (year displayed-year)) 153 (year displayed-year))
154 (increment-calendar-month month year arg) 154 (calendar-increment-month month year arg)
155 (generate-calendar-window month year) 155 (calendar-generate-window month year)
156 (calendar-cursor-to-visible-date 156 (calendar-cursor-to-visible-date
157 (cond 157 (cond
158 ((calendar-date-is-visible-p old-date) old-date) 158 ((calendar-date-is-visible-p old-date) old-date)
159 ((calendar-date-is-visible-p today) today) 159 ((calendar-date-is-visible-p today) today)
160 (t (list month 1 year)))))) 160 (t (list month 1 year))))))
209 (if (> arg 0) (setq arg (1- arg))) 209 (if (> arg 0) (setq arg (1- arg)))
210 (calendar-cursor-to-nearest-date)))) 210 (calendar-cursor-to-nearest-date))))
211 (new-cursor-date 211 (new-cursor-date
212 (calendar-gregorian-from-absolute 212 (calendar-gregorian-from-absolute
213 (+ (calendar-absolute-from-gregorian cursor-date) arg))) 213 (+ (calendar-absolute-from-gregorian cursor-date) arg)))
214 (new-display-month (extract-calendar-month new-cursor-date)) 214 (new-display-month (calendar-extract-month new-cursor-date))
215 (new-display-year (extract-calendar-year new-cursor-date))) 215 (new-display-year (calendar-extract-year new-cursor-date)))
216 ;; Put the new month on the screen, if needed, and go to the new date. 216 ;; Put the new month on the screen, if needed, and go to the new date.
217 (if (not (calendar-date-is-visible-p new-cursor-date)) 217 (if (not (calendar-date-is-visible-p new-cursor-date))
218 (calendar-other-month new-display-month new-display-year)) 218 (calendar-other-month new-display-month new-display-year))
219 (calendar-cursor-to-visible-date new-cursor-date))) 219 (calendar-cursor-to-visible-date new-cursor-date)))
220 (run-hooks 'calendar-move-hook)) 220 (run-hooks 'calendar-move-hook))
268 (defun calendar-beginning-of-month (arg) 268 (defun calendar-beginning-of-month (arg)
269 "Move the cursor backward ARG month beginnings." 269 "Move the cursor backward ARG month beginnings."
270 (interactive "p") 270 (interactive "p")
271 (calendar-cursor-to-nearest-date) 271 (calendar-cursor-to-nearest-date)
272 (let* ((date (calendar-cursor-to-date)) 272 (let* ((date (calendar-cursor-to-date))
273 (month (extract-calendar-month date)) 273 (month (calendar-extract-month date))
274 (day (extract-calendar-day date)) 274 (day (calendar-extract-day date))
275 (year (extract-calendar-year date))) 275 (year (calendar-extract-year date)))
276 (if (= day 1) 276 (if (= day 1)
277 (calendar-backward-month arg) 277 (calendar-backward-month arg)
278 (calendar-cursor-to-visible-date (list month 1 year)) 278 (calendar-cursor-to-visible-date (list month 1 year))
279 (calendar-backward-month (1- arg))))) 279 (calendar-backward-month (1- arg)))))
280 280
282 (defun calendar-end-of-month (arg) 282 (defun calendar-end-of-month (arg)
283 "Move the cursor forward ARG month ends." 283 "Move the cursor forward ARG month ends."
284 (interactive "p") 284 (interactive "p")
285 (calendar-cursor-to-nearest-date) 285 (calendar-cursor-to-nearest-date)
286 (let* ((date (calendar-cursor-to-date)) 286 (let* ((date (calendar-cursor-to-date))
287 (month (extract-calendar-month date)) 287 (month (calendar-extract-month date))
288 (day (extract-calendar-day date)) 288 (day (calendar-extract-day date))
289 (year (extract-calendar-year date)) 289 (year (calendar-extract-year date))
290 (last-day (calendar-last-day-of-month month year)) 290 (last-day (calendar-last-day-of-month month year))
291 (last-day (progn 291 (last-day (progn
292 (unless (= day last-day) 292 (unless (= day last-day)
293 (calendar-cursor-to-visible-date 293 (calendar-cursor-to-visible-date
294 (list month last-day year)) 294 (list month last-day year))
295 (setq arg (1- arg))) 295 (setq arg (1- arg)))
296 (increment-calendar-month month year arg) 296 (calendar-increment-month month year arg)
297 (list month 297 (list month
298 (calendar-last-day-of-month month year) 298 (calendar-last-day-of-month month year)
299 year)))) 299 year))))
300 (if (not (calendar-date-is-visible-p last-day)) 300 (if (not (calendar-date-is-visible-p last-day))
301 (calendar-other-month month year) 301 (calendar-other-month month year)
306 (defun calendar-beginning-of-year (arg) 306 (defun calendar-beginning-of-year (arg)
307 "Move the cursor backward ARG year beginnings." 307 "Move the cursor backward ARG year beginnings."
308 (interactive "p") 308 (interactive "p")
309 (calendar-cursor-to-nearest-date) 309 (calendar-cursor-to-nearest-date)
310 (let* ((date (calendar-cursor-to-date)) 310 (let* ((date (calendar-cursor-to-date))
311 (month (extract-calendar-month date)) 311 (month (calendar-extract-month date))
312 (day (extract-calendar-day date)) 312 (day (calendar-extract-day date))
313 (year (extract-calendar-year date)) 313 (year (calendar-extract-year date))
314 (jan-first (list 1 1 year)) 314 (jan-first (list 1 1 year))
315 (calendar-move-hook nil)) 315 (calendar-move-hook nil))
316 (if (and (= day 1) (= 1 month)) 316 (if (and (= day 1) (= 1 month))
317 (calendar-backward-month (* 12 arg)) 317 (calendar-backward-month (* 12 arg))
318 (if (and (= arg 1) 318 (if (and (= arg 1)
326 (defun calendar-end-of-year (arg) 326 (defun calendar-end-of-year (arg)
327 "Move the cursor forward ARG year beginnings." 327 "Move the cursor forward ARG year beginnings."
328 (interactive "p") 328 (interactive "p")
329 (calendar-cursor-to-nearest-date) 329 (calendar-cursor-to-nearest-date)
330 (let* ((date (calendar-cursor-to-date)) 330 (let* ((date (calendar-cursor-to-date))
331 (month (extract-calendar-month date)) 331 (month (calendar-extract-month date))
332 (day (extract-calendar-day date)) 332 (day (calendar-extract-day date))
333 (year (extract-calendar-year date)) 333 (year (calendar-extract-year date))
334 (dec-31 (list 12 31 year)) 334 (dec-31 (list 12 31 year))
335 (calendar-move-hook nil)) 335 (calendar-move-hook nil))
336 (if (and (= day 31) (= 12 month)) 336 (if (and (= day 31) (= 12 month))
337 (calendar-forward-month (* 12 arg)) 337 (calendar-forward-month (* 12 arg))
338 (if (and (= arg 1) 338 (if (and (= arg 1)
344 344
345 ;;;###cal-autoload 345 ;;;###cal-autoload
346 (defun calendar-goto-date (date) 346 (defun calendar-goto-date (date)
347 "Move cursor to DATE." 347 "Move cursor to DATE."
348 (interactive (list (calendar-read-date))) 348 (interactive (list (calendar-read-date)))
349 (let ((month (extract-calendar-month date)) 349 (let ((month (calendar-extract-month date))
350 (year (extract-calendar-year date))) 350 (year (calendar-extract-year date)))
351 (if (not (calendar-date-is-visible-p date)) 351 (if (not (calendar-date-is-visible-p date))
352 (calendar-other-month 352 (calendar-other-month
353 (if (and (= month 1) (= year 1)) 353 (if (and (= month 1) (= year 1))
354 2 354 2
355 month) 355 month)
363 Negative DAY counts backward from end of year." 363 Negative DAY counts backward from end of year."
364 (interactive 364 (interactive
365 (let* ((year (calendar-read 365 (let* ((year (calendar-read
366 "Year (>0): " 366 "Year (>0): "
367 (lambda (x) (> x 0)) 367 (lambda (x) (> x 0))
368 (int-to-string (extract-calendar-year 368 (int-to-string (calendar-extract-year
369 (calendar-current-date))))) 369 (calendar-current-date)))))
370 (last (if (calendar-leap-year-p year) 366 365)) 370 (last (if (calendar-leap-year-p year) 366 365))
371 (day (calendar-read 371 (day (calendar-read
372 (format "Day number (+/- 1-%d): " last) 372 (format "Day number (+/- 1-%d): " last)
373 (lambda (x) (and (<= 1 (abs x)) (<= (abs x) last)))))) 373 (lambda (x) (and (<= 1 (abs x)) (<= (abs x) last))))))