annotate lisp/calendar/cal-move.el @ 93258:16142d1d9f33

(redisplay_internal): Reset selected_frame earlier.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 26 Mar 2008 18:11:47 +0000
parents f296fd96bd7c
children 6139daabcf5f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
1 ;;; cal-move.el --- calendar functions for movement in the calendar
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
2
79703
974a828870fe Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 78216
diff changeset
3 ;; Copyright (C) 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
67465
a55ee709ec8d Update copyright pending Emacs 22.
Glenn Morris <rgm@gnu.org>
parents: 65919
diff changeset
4 ;; Free Software Foundation, Inc.
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
5
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
65919
5c09efcfc1d9 Update maintainer email address.
Glenn Morris <rgm@gnu.org>
parents: 64085
diff changeset
7 ;; Maintainer: Glenn Morris <rgm@gnu.org>
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
8 ;; Keywords: calendar
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
9 ;; Human-Keywords: calendar
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
10
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
12
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
78216
93e11478c954 Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 77279
diff changeset
15 ;; the Free Software Foundation; either version 3, or (at your option)
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
16 ;; any later version.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
17
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
21 ;; GNU General Public License for more details.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
22
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13053
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 60981
diff changeset
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 60981
diff changeset
26 ;; Boston, MA 02110-1301, USA.
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
27
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
28 ;;; Commentary:
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
29
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
30 ;; This collection of functions implements movement in the calendar for
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
31 ;; calendar.el.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
32
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
33 ;;; Code:
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
34
92916
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
35 (require 'calendar)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
36
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
37 ;;;###cal-autoload
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
38 (defun calendar-cursor-to-nearest-date ()
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
39 "Move the cursor to the closest date.
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
40 The position of the cursor is unchanged if it is already on a date.
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
41 Returns the list (month day year) giving the cursor position."
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
42 (let ((date (calendar-cursor-to-date))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
43 (column (current-column)))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
44 (or date
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
45 (when (> 3 (count-lines (point-min) (point)))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
46 (goto-line 3)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
47 (move-to-column column))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
48 (if (not (looking-at "[0-9]"))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
49 (if (and (not (looking-at " *$"))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
50 (or (< column 25)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
51 (and (> column 27)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
52 (< column 50))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
53 (and (> column 52)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
54 (< column 75))))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
55 (progn
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
56 (re-search-forward "[0-9]" nil t)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
57 (backward-char 1))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
58 (re-search-backward "[0-9]" nil t)))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
59 (calendar-cursor-to-date))))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
60
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
61 (defvar displayed-month) ; from generate-calendar
52112
e7d0572ccca5 (displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 31670
diff changeset
62 (defvar displayed-year)
e7d0572ccca5 (displayed-month, displayed-year): Define for compiler.
Glenn Morris <rgm@gnu.org>
parents: 31670
diff changeset
63
92916
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
64 ;;;###cal-autoload
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
65 (defun calendar-cursor-to-visible-date (date)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
66 "Move the cursor to DATE that is on the screen."
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
67 (let* ((month (extract-calendar-month date))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
68 (day (extract-calendar-day date))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
69 (year (extract-calendar-year date))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
70 (first-of-month-weekday (calendar-day-of-week (list month 1 year))))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
71 (goto-line (+ 3
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
72 (/ (+ day -1
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
73 (mod
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
74 (- (calendar-day-of-week (list month 1 year))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
75 calendar-week-start-day)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
76 7))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
77 7)))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
78 (move-to-column (+ 6
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
79 (* 25
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
80 (1+ (calendar-interval
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
81 displayed-month displayed-year month year)))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
82 (* 3 (mod
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
83 (- (calendar-day-of-week date)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
84 calendar-week-start-day)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
85 7))))))
19892
b3d4cde6e4c3 Require calendar.el.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
86
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
87 ;;;###cal-autoload
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
88 (defun calendar-goto-today ()
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
89 "Reposition the calendar window so the current date is visible."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
90 (interactive)
92916
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
91 (let ((today (calendar-current-date))) ; the date might have changed
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
92 (if (not (calendar-date-is-visible-p today))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
93 (generate-calendar-window)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
94 (update-calendar-mode-line)
25411
0d68ae69cd8c Call the new hook in every movement function.
Richard M. Stallman <rms@gnu.org>
parents: 24337
diff changeset
95 (calendar-cursor-to-visible-date today)))
0d68ae69cd8c Call the new hook in every movement function.
Richard M. Stallman <rms@gnu.org>
parents: 24337
diff changeset
96 (run-hooks 'calendar-move-hook))
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
97
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
98 ;;;###cal-autoload
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
99 (defun calendar-forward-month (arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
100 "Move the cursor forward ARG months.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
101 Movement is backward if ARG is negative."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
102 (interactive "p")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
103 (calendar-cursor-to-nearest-date)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
104 (let* ((cursor-date (calendar-cursor-to-date t))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
105 (month (extract-calendar-month cursor-date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
106 (day (extract-calendar-day cursor-date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
107 (year (extract-calendar-year cursor-date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
108 (increment-calendar-month month year arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
109 (let ((last (calendar-last-day-of-month month year)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
110 (if (< last day)
92916
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
111 (setq day last)))
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
112 ;; Put the new month on the screen, if needed, and go to the new date.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
113 (let ((new-cursor-date (list month day year)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
114 (if (not (calendar-date-is-visible-p new-cursor-date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
115 (calendar-other-month month year))
25411
0d68ae69cd8c Call the new hook in every movement function.
Richard M. Stallman <rms@gnu.org>
parents: 24337
diff changeset
116 (calendar-cursor-to-visible-date new-cursor-date)))
0d68ae69cd8c Call the new hook in every movement function.
Richard M. Stallman <rms@gnu.org>
parents: 24337
diff changeset
117 (run-hooks 'calendar-move-hook))
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
118
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
119 ;;;###cal-autoload
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
120 (defun calendar-forward-year (arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
121 "Move the cursor forward by ARG years.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
122 Movement is backward if ARG is negative."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
123 (interactive "p")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
124 (calendar-forward-month (* 12 arg)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
125
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
126 ;;;###cal-autoload
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
127 (defun calendar-backward-month (arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
128 "Move the cursor backward by ARG months.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
129 Movement is forward if ARG is negative."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
130 (interactive "p")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
131 (calendar-forward-month (- arg)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
132
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
133 ;;;###cal-autoload
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
134 (defun calendar-backward-year (arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
135 "Move the cursor backward ARG years.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
136 Movement is forward is ARG is negative."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
137 (interactive "p")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
138 (calendar-forward-month (* -12 arg)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
139
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
140 ;;;###cal-autoload
82150
0d322d300115 (calendar-scroll-left, calendar-scroll-right):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82148
diff changeset
141 (defun calendar-scroll-left (&optional arg event)
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
142 "Scroll the displayed calendar left by ARG months.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
143 If ARG is negative the calendar is scrolled right. Maintains the relative
92634
decf6dfe9876 (calendar-scroll-left, calendar-scroll-right): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 92590
diff changeset
144 position of the cursor with respect to the calendar as well as possible.
decf6dfe9876 (calendar-scroll-left, calendar-scroll-right): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 92590
diff changeset
145 EVENT is an event like `last-nonmenu-event'."
82150
0d322d300115 (calendar-scroll-left, calendar-scroll-right):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82148
diff changeset
146 (interactive (list (prefix-numeric-value current-prefix-arg)
0d322d300115 (calendar-scroll-left, calendar-scroll-right):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82148
diff changeset
147 last-nonmenu-event))
31670
4560c1d5e629 (scroll-calendar-left)
Dave Love <fx@gnu.org>
parents: 25411
diff changeset
148 (unless arg (setq arg 1))
82150
0d322d300115 (calendar-scroll-left, calendar-scroll-right):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82148
diff changeset
149 (save-selected-window
0d322d300115 (calendar-scroll-left, calendar-scroll-right):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82148
diff changeset
150 (select-window (posn-window (event-start event)))
0d322d300115 (calendar-scroll-left, calendar-scroll-right):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82148
diff changeset
151 (calendar-cursor-to-nearest-date)
92916
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
152 (unless (zerop arg)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
153 (let ((old-date (calendar-cursor-to-date))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
154 (today (calendar-current-date))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
155 (month displayed-month)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
156 (year displayed-year))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
157 (increment-calendar-month month year arg)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
158 (generate-calendar-window month year)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
159 (calendar-cursor-to-visible-date
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
160 (cond
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
161 ((calendar-date-is-visible-p old-date) old-date)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
162 ((calendar-date-is-visible-p today) today)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
163 (t (list month 1 year))))))
82150
0d322d300115 (calendar-scroll-left, calendar-scroll-right):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82148
diff changeset
164 (run-hooks 'calendar-move-hook)))
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
165
92916
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
166 (define-obsolete-function-alias
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
167 'scroll-calendar-left 'calendar-scroll-left "23.1")
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
168
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
169 ;;;###cal-autoload
82150
0d322d300115 (calendar-scroll-left, calendar-scroll-right):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82148
diff changeset
170 (defun calendar-scroll-right (&optional arg event)
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
171 "Scroll the displayed calendar window right by ARG months.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
172 If ARG is negative the calendar is scrolled left. Maintains the relative
92634
decf6dfe9876 (calendar-scroll-left, calendar-scroll-right): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 92590
diff changeset
173 position of the cursor with respect to the calendar as well as possible.
decf6dfe9876 (calendar-scroll-left, calendar-scroll-right): Doc fix.
Glenn Morris <rgm@gnu.org>
parents: 92590
diff changeset
174 EVENT is an event like `last-nonmenu-event'."
82150
0d322d300115 (calendar-scroll-left, calendar-scroll-right):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82148
diff changeset
175 (interactive (list (prefix-numeric-value current-prefix-arg)
0d322d300115 (calendar-scroll-left, calendar-scroll-right):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82148
diff changeset
176 last-nonmenu-event))
0d322d300115 (calendar-scroll-left, calendar-scroll-right):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82148
diff changeset
177 (calendar-scroll-left (- (or arg 1)) event))
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
178
92916
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
179 (define-obsolete-function-alias
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
180 'scroll-calendar-right 'calendar-scroll-right "23.1")
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
181
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
182 ;;;###cal-autoload
82148
d979cb10446a (calendar-scroll-left, calendar-scroll-right, calendar-scroll-left-three-months)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78216
diff changeset
183 (defun calendar-scroll-left-three-months (arg)
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
184 "Scroll the displayed calendar window left by 3*ARG months.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
185 If ARG is negative the calendar is scrolled right. Maintains the relative
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
186 position of the cursor with respect to the calendar as well as possible."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
187 (interactive "p")
82148
d979cb10446a (calendar-scroll-left, calendar-scroll-right, calendar-scroll-left-three-months)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78216
diff changeset
188 (calendar-scroll-left (* 3 arg)))
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
189
92916
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
190 (define-obsolete-function-alias 'scroll-calendar-left-three-months
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
191 'calendar-scroll-left-three-months "23.1")
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
192
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
193 ;;;###cal-autoload
82148
d979cb10446a (calendar-scroll-left, calendar-scroll-right, calendar-scroll-left-three-months)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78216
diff changeset
194 (defun calendar-scroll-right-three-months (arg)
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
195 "Scroll the displayed calendar window right by 3*ARG months.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
196 If ARG is negative the calendar is scrolled left. Maintains the relative
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
197 position of the cursor with respect to the calendar as well as possible."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
198 (interactive "p")
82148
d979cb10446a (calendar-scroll-left, calendar-scroll-right, calendar-scroll-left-three-months)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78216
diff changeset
199 (calendar-scroll-left (* -3 arg)))
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
200
92916
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
201 (define-obsolete-function-alias 'scroll-calendar-right-three-months
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
202 'calendar-scroll-right-three-months "23.1")
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
203
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
204 ;;;###cal-autoload
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
205 (defun calendar-forward-day (arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
206 "Move the cursor forward ARG days.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
207 Moves backward if ARG is negative."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
208 (interactive "p")
92916
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
209 (unless (zerop arg)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
210 (let* ((cursor-date (or (calendar-cursor-to-date)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
211 (progn
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
212 (if (> arg 0) (setq arg (1- arg)))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
213 (calendar-cursor-to-nearest-date))))
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
214 (new-cursor-date
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
215 (calendar-gregorian-from-absolute
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
216 (+ (calendar-absolute-from-gregorian cursor-date) arg)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
217 (new-display-month (extract-calendar-month new-cursor-date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
218 (new-display-year (extract-calendar-year new-cursor-date)))
92916
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
219 ;; Put the new month on the screen, if needed, and go to the new date.
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
220 (if (not (calendar-date-is-visible-p new-cursor-date))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
221 (calendar-other-month new-display-month new-display-year))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
222 (calendar-cursor-to-visible-date new-cursor-date)))
25411
0d68ae69cd8c Call the new hook in every movement function.
Richard M. Stallman <rms@gnu.org>
parents: 24337
diff changeset
223 (run-hooks 'calendar-move-hook))
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
224
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
225 ;;;###cal-autoload
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
226 (defun calendar-backward-day (arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
227 "Move the cursor back ARG days.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
228 Moves forward if ARG is negative."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
229 (interactive "p")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
230 (calendar-forward-day (- arg)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
231
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
232 ;;;###cal-autoload
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
233 (defun calendar-forward-week (arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
234 "Move the cursor forward ARG weeks.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
235 Moves backward if ARG is negative."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
236 (interactive "p")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
237 (calendar-forward-day (* arg 7)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
238
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
239 ;;;###cal-autoload
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
240 (defun calendar-backward-week (arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
241 "Move the cursor back ARG weeks.
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
242 Moves forward if ARG is negative."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
243 (interactive "p")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
244 (calendar-forward-day (* arg -7)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
245
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
246 ;;;###cal-autoload
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
247 (defun calendar-beginning-of-week (arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
248 "Move the cursor back ARG calendar-week-start-day's."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
249 (interactive "p")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
250 (calendar-cursor-to-nearest-date)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
251 (let ((day (calendar-day-of-week (calendar-cursor-to-date))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
252 (calendar-backward-day
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
253 (if (= day calendar-week-start-day)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
254 (* 7 arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
255 (+ (mod (- day calendar-week-start-day) 7)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
256 (* 7 (1- arg)))))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
257
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
258 ;;;###cal-autoload
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
259 (defun calendar-end-of-week (arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
260 "Move the cursor forward ARG calendar-week-start-day+6's."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
261 (interactive "p")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
262 (calendar-cursor-to-nearest-date)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
263 (let ((day (calendar-day-of-week (calendar-cursor-to-date))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
264 (calendar-forward-day
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
265 (if (= day (mod (1- calendar-week-start-day) 7))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
266 (* 7 arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
267 (+ (- 6 (mod (- day calendar-week-start-day) 7))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
268 (* 7 (1- arg)))))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
269
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
270 ;;;###cal-autoload
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
271 (defun calendar-beginning-of-month (arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
272 "Move the cursor backward ARG month beginnings."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
273 (interactive "p")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
274 (calendar-cursor-to-nearest-date)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
275 (let* ((date (calendar-cursor-to-date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
276 (month (extract-calendar-month date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
277 (day (extract-calendar-day date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
278 (year (extract-calendar-year date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
279 (if (= day 1)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
280 (calendar-backward-month arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
281 (calendar-cursor-to-visible-date (list month 1 year))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
282 (calendar-backward-month (1- arg)))))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
283
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
284 ;;;###cal-autoload
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
285 (defun calendar-end-of-month (arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
286 "Move the cursor forward ARG month ends."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
287 (interactive "p")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
288 (calendar-cursor-to-nearest-date)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
289 (let* ((date (calendar-cursor-to-date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
290 (month (extract-calendar-month date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
291 (day (extract-calendar-day date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
292 (year (extract-calendar-year date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
293 (last-day (calendar-last-day-of-month month year)))
92916
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
294 (unless (= day last-day)
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
295 (calendar-cursor-to-visible-date (list month last-day year))
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
296 (setq arg (1- arg)))
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
297 (increment-calendar-month month year arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
298 (let ((last-day (list
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
299 month
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
300 (calendar-last-day-of-month month year)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
301 year)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
302 (if (not (calendar-date-is-visible-p last-day))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
303 (calendar-other-month month year)
92916
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
304 (calendar-cursor-to-visible-date last-day))))
25411
0d68ae69cd8c Call the new hook in every movement function.
Richard M. Stallman <rms@gnu.org>
parents: 24337
diff changeset
305 (run-hooks 'calendar-move-hook))
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
306
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
307 ;;;###cal-autoload
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
308 (defun calendar-beginning-of-year (arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
309 "Move the cursor backward ARG year beginnings."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
310 (interactive "p")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
311 (calendar-cursor-to-nearest-date)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
312 (let* ((date (calendar-cursor-to-date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
313 (month (extract-calendar-month date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
314 (day (extract-calendar-day date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
315 (year (extract-calendar-year date))
25411
0d68ae69cd8c Call the new hook in every movement function.
Richard M. Stallman <rms@gnu.org>
parents: 24337
diff changeset
316 (jan-first (list 1 1 year))
0d68ae69cd8c Call the new hook in every movement function.
Richard M. Stallman <rms@gnu.org>
parents: 24337
diff changeset
317 (calendar-move-hook nil))
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
318 (if (and (= day 1) (= 1 month))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
319 (calendar-backward-month (* 12 arg))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
320 (if (and (= arg 1)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
321 (calendar-date-is-visible-p jan-first))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
322 (calendar-cursor-to-visible-date jan-first)
60981
669da3d2cff9 Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents: 52401
diff changeset
323 (calendar-other-month 1 (- year (1- arg)))
669da3d2cff9 Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents: 52401
diff changeset
324 (calendar-cursor-to-visible-date (list 1 1 displayed-year)))))
25411
0d68ae69cd8c Call the new hook in every movement function.
Richard M. Stallman <rms@gnu.org>
parents: 24337
diff changeset
325 (run-hooks 'calendar-move-hook))
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
326
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
327 ;;;###cal-autoload
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
328 (defun calendar-end-of-year (arg)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
329 "Move the cursor forward ARG year beginnings."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
330 (interactive "p")
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
331 (calendar-cursor-to-nearest-date)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
332 (let* ((date (calendar-cursor-to-date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
333 (month (extract-calendar-month date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
334 (day (extract-calendar-day date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
335 (year (extract-calendar-year date))
25411
0d68ae69cd8c Call the new hook in every movement function.
Richard M. Stallman <rms@gnu.org>
parents: 24337
diff changeset
336 (dec-31 (list 12 31 year))
0d68ae69cd8c Call the new hook in every movement function.
Richard M. Stallman <rms@gnu.org>
parents: 24337
diff changeset
337 (calendar-move-hook nil))
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
338 (if (and (= day 31) (= 12 month))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
339 (calendar-forward-month (* 12 arg))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
340 (if (and (= arg 1)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
341 (calendar-date-is-visible-p dec-31))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
342 (calendar-cursor-to-visible-date dec-31)
60981
669da3d2cff9 Update copyright and maintainer.
Glenn Morris <rgm@gnu.org>
parents: 52401
diff changeset
343 (calendar-other-month 12 (+ year (1- arg)))
25411
0d68ae69cd8c Call the new hook in every movement function.
Richard M. Stallman <rms@gnu.org>
parents: 24337
diff changeset
344 (calendar-cursor-to-visible-date (list 12 31 displayed-year)))))
0d68ae69cd8c Call the new hook in every movement function.
Richard M. Stallman <rms@gnu.org>
parents: 24337
diff changeset
345 (run-hooks 'calendar-move-hook))
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
346
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
347 ;;;###cal-autoload
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
348 (defun calendar-goto-date (date)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
349 "Move cursor to DATE."
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
350 (interactive (list (calendar-read-date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
351 (let ((month (extract-calendar-month date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
352 (year (extract-calendar-year date)))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
353 (if (not (calendar-date-is-visible-p date))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
354 (calendar-other-month
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
355 (if (and (= month 1) (= year 1))
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
356 2
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
357 month)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
358 year)))
25411
0d68ae69cd8c Call the new hook in every movement function.
Richard M. Stallman <rms@gnu.org>
parents: 24337
diff changeset
359 (calendar-cursor-to-visible-date date)
0d68ae69cd8c Call the new hook in every movement function.
Richard M. Stallman <rms@gnu.org>
parents: 24337
diff changeset
360 (run-hooks 'calendar-move-hook))
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
361
92836
e4347538b00b (generated-autoload-file): Don't set, instead use different values of
Glenn Morris <rgm@gnu.org>
parents: 92634
diff changeset
362 ;;;###cal-autoload
52231
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
363 (defun calendar-goto-day-of-year (year day &optional noecho)
92916
f296fd96bd7c (calendar-cursor-to-nearest-date): Use or, when. Move definition before use.
Glenn Morris <rgm@gnu.org>
parents: 92855
diff changeset
364 "Move cursor to YEAR, DAY number; echo DAY/YEAR unless NOECHO is non-nil.
52231
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
365 Negative DAY counts backward from end of year."
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
366 (interactive
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
367 (let* ((year (calendar-read
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
368 "Year (>0): "
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
369 (lambda (x) (> x 0))
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
370 (int-to-string (extract-calendar-year
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
371 (calendar-current-date)))))
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
372 (last (if (calendar-leap-year-p year) 366 365))
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
373 (day (calendar-read
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
374 (format "Day number (+/- 1-%d): " last)
92590
8ef3d5355402 Unquote lambda functions. Add autoload cookies to functions formerly
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
375 (lambda (x) (and (<= 1 (abs x)) (<= (abs x) last))))))
52231
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
376 (list year day)))
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
377 (calendar-goto-date
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
378 (calendar-gregorian-from-absolute
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
379 (if (< 0 day)
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
380 (+ -1 day (calendar-absolute-from-gregorian (list 1 1 year)))
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
381 (+ 1 day (calendar-absolute-from-gregorian (list 12 31 year))))))
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
382 (or noecho (calendar-print-day-of-year)))
9529ff0804c2 Edward M. Reingold <reingold@emr.cs.iit.edu>
Glenn Morris <rgm@gnu.org>
parents: 52112
diff changeset
383
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
384 (provide 'cal-move)
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
385
82148
d979cb10446a (calendar-scroll-left, calendar-scroll-right, calendar-scroll-left-three-months)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78216
diff changeset
386 ;; arch-tag: d0883c46-7e16-4914-8ff8-8f67e699b781
13053
621d48117fde Initial revision
Edward M. Reingold <reingold@emr.cs.iit.edu>
parents:
diff changeset
387 ;;; cal-move.el ends here