1995-09-21 03:11:06 +00:00
|
|
|
;;; cal-move.el --- calendar functions for movement in the calendar
|
|
|
|
|
2012-01-05 09:46:05 +00:00
|
|
|
;; Copyright (C) 1995, 2001-2012 Free Software Foundation, Inc.
|
1995-09-21 03:11:06 +00:00
|
|
|
|
|
|
|
;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
|
2005-10-08 04:49:48 +00:00
|
|
|
;; Maintainer: Glenn Morris <rgm@gnu.org>
|
1995-09-21 03:11:06 +00:00
|
|
|
;; Keywords: calendar
|
|
|
|
;; Human-Keywords: calendar
|
2010-08-29 16:17:13 +00:00
|
|
|
;; Package: calendar
|
1995-09-21 03:11:06 +00:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 03:07:58 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1995-09-21 03:11:06 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 03:07:58 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
1995-09-21 03:11:06 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 03:07:58 +00:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
1995-09-21 03:11:06 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
2008-04-01 02:43:05 +00:00
|
|
|
;; See calendar.el.
|
1995-09-21 03:11:06 +00:00
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2008-06-21 19:28:58 +00:00
|
|
|
;; FIXME should calendar just require this?
|
2008-03-14 06:45:16 +00:00
|
|
|
(require 'calendar)
|
|
|
|
|
2008-06-26 03:41:38 +00:00
|
|
|
|
|
|
|
;; Note that this is not really the "closest" date.
|
|
|
|
;; In most cases, it just searches forwards for the next day.
|
2008-03-14 06:45:16 +00:00
|
|
|
;;;###cal-autoload
|
|
|
|
(defun calendar-cursor-to-nearest-date ()
|
|
|
|
"Move the cursor to the closest date.
|
|
|
|
The position of the cursor is unchanged if it is already on a date.
|
|
|
|
Returns the list (month day year) giving the cursor position."
|
2008-03-28 02:45:58 +00:00
|
|
|
(or (calendar-cursor-to-date)
|
2008-06-26 03:41:38 +00:00
|
|
|
(let* ((col (current-column))
|
|
|
|
(edges (cdr (assoc (calendar-column-to-segment)
|
|
|
|
calendar-month-edges)))
|
|
|
|
(last (nth 2 edges))
|
|
|
|
(right (nth 3 edges)))
|
|
|
|
(when (< (count-lines (point-min) (point)) calendar-first-date-row)
|
2009-08-21 07:11:24 +00:00
|
|
|
(goto-char (point-min))
|
|
|
|
(forward-line (1- calendar-first-date-row))
|
2008-06-26 03:41:38 +00:00
|
|
|
(move-to-column col))
|
|
|
|
;; The date positions are fixed and computable, but searching
|
|
|
|
;; is probably more flexible. Need to consider blank days at
|
|
|
|
;; start and end of month if computing positions.
|
|
|
|
;; 'date text-property is used to exclude intermonth text.
|
|
|
|
(unless (and (looking-at "[0-9]")
|
|
|
|
(get-text-property (point) 'date))
|
|
|
|
;; We search forwards for a number, except close to the RH
|
|
|
|
;; margin of a month, where we search backwards.
|
|
|
|
;; Note that the searches can go to other lines.
|
|
|
|
(if (or (looking-at " *$")
|
|
|
|
(and (> col last) (< col right)))
|
|
|
|
(while (and (re-search-backward "[0-9]" nil t)
|
|
|
|
(not (get-text-property (point) 'date))))
|
|
|
|
(while (and (re-search-forward "[0-9]" nil t)
|
|
|
|
(not (get-text-property (1- (point)) 'date))))
|
|
|
|
(backward-char 1)))
|
2008-03-14 06:45:16 +00:00
|
|
|
(calendar-cursor-to-date))))
|
|
|
|
|
2008-04-07 01:59:37 +00:00
|
|
|
(defvar displayed-month) ; from calendar-generate
|
2003-08-03 13:56:21 +00:00
|
|
|
(defvar displayed-year)
|
|
|
|
|
2008-03-14 06:45:16 +00:00
|
|
|
;;;###cal-autoload
|
|
|
|
(defun calendar-cursor-to-visible-date (date)
|
|
|
|
"Move the cursor to DATE that is on the screen."
|
2008-04-07 01:59:37 +00:00
|
|
|
(let ((month (calendar-extract-month date))
|
|
|
|
(day (calendar-extract-day date))
|
|
|
|
(year (calendar-extract-year date)))
|
2009-08-21 07:11:24 +00:00
|
|
|
(goto-char (point-min))
|
|
|
|
(forward-line (+ calendar-first-date-row -1
|
|
|
|
(/ (+ day -1
|
|
|
|
(mod
|
|
|
|
(- (calendar-day-of-week (list month 1 year))
|
|
|
|
calendar-week-start-day)
|
|
|
|
7))
|
|
|
|
7)))
|
2008-06-21 19:28:58 +00:00
|
|
|
(move-to-column (+ calendar-left-margin (1- calendar-day-digit-width)
|
|
|
|
(* calendar-month-width
|
2008-03-14 06:45:16 +00:00
|
|
|
(1+ (calendar-interval
|
|
|
|
displayed-month displayed-year month year)))
|
2008-06-21 19:28:58 +00:00
|
|
|
(* calendar-column-width
|
|
|
|
(mod
|
|
|
|
(- (calendar-day-of-week date)
|
|
|
|
calendar-week-start-day)
|
|
|
|
7))))))
|
1997-09-12 22:08:16 +00:00
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-goto-today ()
|
|
|
|
"Reposition the calendar window so the current date is visible."
|
|
|
|
(interactive)
|
2008-03-14 06:45:16 +00:00
|
|
|
(let ((today (calendar-current-date))) ; the date might have changed
|
1995-09-21 03:11:06 +00:00
|
|
|
(if (not (calendar-date-is-visible-p today))
|
2008-04-07 01:59:37 +00:00
|
|
|
(calendar-generate-window)
|
|
|
|
(calendar-update-mode-line)
|
1999-08-28 15:20:18 +00:00
|
|
|
(calendar-cursor-to-visible-date today)))
|
|
|
|
(run-hooks 'calendar-move-hook))
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-forward-month (arg)
|
|
|
|
"Move the cursor forward ARG months.
|
|
|
|
Movement is backward if ARG is negative."
|
|
|
|
(interactive "p")
|
|
|
|
(calendar-cursor-to-nearest-date)
|
|
|
|
(let* ((cursor-date (calendar-cursor-to-date t))
|
2008-04-07 01:59:37 +00:00
|
|
|
(month (calendar-extract-month cursor-date))
|
|
|
|
(day (calendar-extract-day cursor-date))
|
|
|
|
(year (calendar-extract-year cursor-date))
|
2008-04-01 02:43:05 +00:00
|
|
|
(last (progn
|
2008-04-07 01:59:37 +00:00
|
|
|
(calendar-increment-month month year arg)
|
2008-04-01 02:43:05 +00:00
|
|
|
(calendar-last-day-of-month month year)))
|
|
|
|
(day (min last day))
|
|
|
|
;; Put the new month on the screen, if needed, and go to the new date.
|
|
|
|
(new-cursor-date (list month day year)))
|
|
|
|
(if (not (calendar-date-is-visible-p new-cursor-date))
|
|
|
|
(calendar-other-month month year))
|
|
|
|
(calendar-cursor-to-visible-date new-cursor-date))
|
1999-08-28 15:20:18 +00:00
|
|
|
(run-hooks 'calendar-move-hook))
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-forward-year (arg)
|
|
|
|
"Move the cursor forward by ARG years.
|
|
|
|
Movement is backward if ARG is negative."
|
|
|
|
(interactive "p")
|
|
|
|
(calendar-forward-month (* 12 arg)))
|
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-backward-month (arg)
|
|
|
|
"Move the cursor backward by ARG months.
|
|
|
|
Movement is forward if ARG is negative."
|
|
|
|
(interactive "p")
|
|
|
|
(calendar-forward-month (- arg)))
|
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-backward-year (arg)
|
|
|
|
"Move the cursor backward ARG years.
|
|
|
|
Movement is forward is ARG is negative."
|
|
|
|
(interactive "p")
|
|
|
|
(calendar-forward-month (* -12 arg)))
|
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
2007-07-27 06:23:45 +00:00
|
|
|
(defun calendar-scroll-left (&optional arg event)
|
1995-09-21 03:11:06 +00:00
|
|
|
"Scroll the displayed calendar left by ARG months.
|
|
|
|
If ARG is negative the calendar is scrolled right. Maintains the relative
|
2008-03-08 20:26:18 +00:00
|
|
|
position of the cursor with respect to the calendar as well as possible.
|
|
|
|
EVENT is an event like `last-nonmenu-event'."
|
2007-07-27 06:23:45 +00:00
|
|
|
(interactive (list (prefix-numeric-value current-prefix-arg)
|
|
|
|
last-nonmenu-event))
|
2000-09-17 17:08:04 +00:00
|
|
|
(unless arg (setq arg 1))
|
2007-07-27 06:23:45 +00:00
|
|
|
(save-selected-window
|
2008-04-24 05:43:27 +00:00
|
|
|
;; Nil if called from menu-bar.
|
|
|
|
(if (setq event (event-start event)) (select-window (posn-window event)))
|
2007-07-27 06:23:45 +00:00
|
|
|
(calendar-cursor-to-nearest-date)
|
2008-03-14 06:45:16 +00:00
|
|
|
(unless (zerop arg)
|
|
|
|
(let ((old-date (calendar-cursor-to-date))
|
|
|
|
(today (calendar-current-date))
|
|
|
|
(month displayed-month)
|
|
|
|
(year displayed-year))
|
2008-04-07 01:59:37 +00:00
|
|
|
(calendar-increment-month month year arg)
|
|
|
|
(calendar-generate-window month year)
|
2008-03-14 06:45:16 +00:00
|
|
|
(calendar-cursor-to-visible-date
|
|
|
|
(cond
|
|
|
|
((calendar-date-is-visible-p old-date) old-date)
|
|
|
|
((calendar-date-is-visible-p today) today)
|
|
|
|
(t (list month 1 year))))))
|
2007-07-27 06:23:45 +00:00
|
|
|
(run-hooks 'calendar-move-hook)))
|
|
|
|
|
2008-03-14 06:45:16 +00:00
|
|
|
(define-obsolete-function-alias
|
|
|
|
'scroll-calendar-left 'calendar-scroll-left "23.1")
|
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
2007-07-27 06:23:45 +00:00
|
|
|
(defun calendar-scroll-right (&optional arg event)
|
1995-09-21 03:11:06 +00:00
|
|
|
"Scroll the displayed calendar window right by ARG months.
|
|
|
|
If ARG is negative the calendar is scrolled left. Maintains the relative
|
2008-03-08 20:26:18 +00:00
|
|
|
position of the cursor with respect to the calendar as well as possible.
|
|
|
|
EVENT is an event like `last-nonmenu-event'."
|
2007-07-27 06:23:45 +00:00
|
|
|
(interactive (list (prefix-numeric-value current-prefix-arg)
|
|
|
|
last-nonmenu-event))
|
|
|
|
(calendar-scroll-left (- (or arg 1)) event))
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-03-14 06:45:16 +00:00
|
|
|
(define-obsolete-function-alias
|
|
|
|
'scroll-calendar-right 'calendar-scroll-right "23.1")
|
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
2009-01-10 22:01:32 +00:00
|
|
|
(defun calendar-scroll-left-three-months (arg &optional event)
|
1995-09-21 03:11:06 +00:00
|
|
|
"Scroll the displayed calendar window left by 3*ARG months.
|
|
|
|
If ARG is negative the calendar is scrolled right. Maintains the relative
|
2009-01-10 22:01:32 +00:00
|
|
|
position of the cursor with respect to the calendar as well as possible.
|
|
|
|
EVENT is an event like `last-nonmenu-event'."
|
|
|
|
(interactive (list (prefix-numeric-value current-prefix-arg)
|
|
|
|
last-nonmenu-event))
|
|
|
|
(calendar-scroll-left (* 3 arg) event))
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-03-14 06:45:16 +00:00
|
|
|
(define-obsolete-function-alias 'scroll-calendar-left-three-months
|
|
|
|
'calendar-scroll-left-three-months "23.1")
|
|
|
|
|
2011-04-06 02:05:45 +00:00
|
|
|
;; cf scroll-bar-toolkit-scroll
|
|
|
|
;;;###cal-autoload
|
|
|
|
(defun calendar-scroll-toolkit-scroll (event)
|
|
|
|
"Function to scroll the calendar after a toolkit scroll-bar click."
|
|
|
|
(interactive "e")
|
|
|
|
(let ((part (nth 4 (event-end event))))
|
|
|
|
;; Not bothering with drag events (handle, end-scroll).
|
|
|
|
(cond ((memq part '(above-handle up top))
|
|
|
|
(calendar-scroll-right nil event))
|
|
|
|
((memq part '(below-handle down bottom))
|
|
|
|
(calendar-scroll-left nil event)))))
|
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
2009-01-10 22:01:32 +00:00
|
|
|
(defun calendar-scroll-right-three-months (arg &optional event)
|
1995-09-21 03:11:06 +00:00
|
|
|
"Scroll the displayed calendar window right by 3*ARG months.
|
|
|
|
If ARG is negative the calendar is scrolled left. Maintains the relative
|
2009-01-10 22:01:32 +00:00
|
|
|
position of the cursor with respect to the calendar as well as possible.
|
|
|
|
EVENT is an event like `last-nonmenu-event'."
|
|
|
|
(interactive (list (prefix-numeric-value current-prefix-arg)
|
|
|
|
last-nonmenu-event))
|
|
|
|
(calendar-scroll-left (* -3 arg) event))
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-03-14 06:45:16 +00:00
|
|
|
(define-obsolete-function-alias 'scroll-calendar-right-three-months
|
|
|
|
'calendar-scroll-right-three-months "23.1")
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-forward-day (arg)
|
|
|
|
"Move the cursor forward ARG days.
|
|
|
|
Moves backward if ARG is negative."
|
|
|
|
(interactive "p")
|
2008-03-14 06:45:16 +00:00
|
|
|
(unless (zerop arg)
|
|
|
|
(let* ((cursor-date (or (calendar-cursor-to-date)
|
|
|
|
(progn
|
|
|
|
(if (> arg 0) (setq arg (1- arg)))
|
|
|
|
(calendar-cursor-to-nearest-date))))
|
1995-09-21 03:11:06 +00:00
|
|
|
(new-cursor-date
|
|
|
|
(calendar-gregorian-from-absolute
|
|
|
|
(+ (calendar-absolute-from-gregorian cursor-date) arg)))
|
2008-04-07 01:59:37 +00:00
|
|
|
(new-display-month (calendar-extract-month new-cursor-date))
|
|
|
|
(new-display-year (calendar-extract-year new-cursor-date)))
|
2009-05-21 04:40:08 +00:00
|
|
|
;; Put the new month on the screen, if needed.
|
|
|
|
(unless (calendar-date-is-visible-p new-cursor-date)
|
2008-06-21 19:28:58 +00:00
|
|
|
;; The next line gives smoother scrolling IMO (one month at a
|
|
|
|
;; time rather than two).
|
|
|
|
(calendar-increment-month new-display-month new-display-year
|
|
|
|
(if (< arg 0) 1 -1))
|
2009-05-21 04:40:08 +00:00
|
|
|
(calendar-other-month new-display-month new-display-year))
|
|
|
|
;; Go to the new date.
|
|
|
|
(calendar-cursor-to-visible-date new-cursor-date)))
|
1999-08-28 15:20:18 +00:00
|
|
|
(run-hooks 'calendar-move-hook))
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-backward-day (arg)
|
|
|
|
"Move the cursor back ARG days.
|
|
|
|
Moves forward if ARG is negative."
|
|
|
|
(interactive "p")
|
|
|
|
(calendar-forward-day (- arg)))
|
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-forward-week (arg)
|
|
|
|
"Move the cursor forward ARG weeks.
|
|
|
|
Moves backward if ARG is negative."
|
|
|
|
(interactive "p")
|
|
|
|
(calendar-forward-day (* arg 7)))
|
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-backward-week (arg)
|
|
|
|
"Move the cursor back ARG weeks.
|
|
|
|
Moves forward if ARG is negative."
|
|
|
|
(interactive "p")
|
|
|
|
(calendar-forward-day (* arg -7)))
|
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-beginning-of-week (arg)
|
|
|
|
"Move the cursor back ARG calendar-week-start-day's."
|
|
|
|
(interactive "p")
|
|
|
|
(calendar-cursor-to-nearest-date)
|
|
|
|
(let ((day (calendar-day-of-week (calendar-cursor-to-date))))
|
|
|
|
(calendar-backward-day
|
|
|
|
(if (= day calendar-week-start-day)
|
|
|
|
(* 7 arg)
|
|
|
|
(+ (mod (- day calendar-week-start-day) 7)
|
|
|
|
(* 7 (1- arg)))))))
|
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-end-of-week (arg)
|
|
|
|
"Move the cursor forward ARG calendar-week-start-day+6's."
|
|
|
|
(interactive "p")
|
|
|
|
(calendar-cursor-to-nearest-date)
|
|
|
|
(let ((day (calendar-day-of-week (calendar-cursor-to-date))))
|
|
|
|
(calendar-forward-day
|
|
|
|
(if (= day (mod (1- calendar-week-start-day) 7))
|
|
|
|
(* 7 arg)
|
|
|
|
(+ (- 6 (mod (- day calendar-week-start-day) 7))
|
|
|
|
(* 7 (1- arg)))))))
|
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-beginning-of-month (arg)
|
|
|
|
"Move the cursor backward ARG month beginnings."
|
|
|
|
(interactive "p")
|
|
|
|
(calendar-cursor-to-nearest-date)
|
|
|
|
(let* ((date (calendar-cursor-to-date))
|
2008-04-07 01:59:37 +00:00
|
|
|
(month (calendar-extract-month date))
|
|
|
|
(day (calendar-extract-day date))
|
|
|
|
(year (calendar-extract-year date)))
|
1995-09-21 03:11:06 +00:00
|
|
|
(if (= day 1)
|
|
|
|
(calendar-backward-month arg)
|
|
|
|
(calendar-cursor-to-visible-date (list month 1 year))
|
|
|
|
(calendar-backward-month (1- arg)))))
|
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-end-of-month (arg)
|
|
|
|
"Move the cursor forward ARG month ends."
|
|
|
|
(interactive "p")
|
|
|
|
(calendar-cursor-to-nearest-date)
|
|
|
|
(let* ((date (calendar-cursor-to-date))
|
2008-04-07 01:59:37 +00:00
|
|
|
(month (calendar-extract-month date))
|
|
|
|
(day (calendar-extract-day date))
|
|
|
|
(year (calendar-extract-year date))
|
2008-04-01 02:43:05 +00:00
|
|
|
(last-day (calendar-last-day-of-month month year))
|
|
|
|
(last-day (progn
|
|
|
|
(unless (= day last-day)
|
|
|
|
(calendar-cursor-to-visible-date
|
|
|
|
(list month last-day year))
|
|
|
|
(setq arg (1- arg)))
|
2008-04-07 01:59:37 +00:00
|
|
|
(calendar-increment-month month year arg)
|
2008-04-01 02:43:05 +00:00
|
|
|
(list month
|
|
|
|
(calendar-last-day-of-month month year)
|
|
|
|
year))))
|
|
|
|
(if (not (calendar-date-is-visible-p last-day))
|
|
|
|
(calendar-other-month month year)
|
|
|
|
(calendar-cursor-to-visible-date last-day)))
|
1999-08-28 15:20:18 +00:00
|
|
|
(run-hooks 'calendar-move-hook))
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-beginning-of-year (arg)
|
|
|
|
"Move the cursor backward ARG year beginnings."
|
|
|
|
(interactive "p")
|
|
|
|
(calendar-cursor-to-nearest-date)
|
|
|
|
(let* ((date (calendar-cursor-to-date))
|
2008-04-07 01:59:37 +00:00
|
|
|
(month (calendar-extract-month date))
|
|
|
|
(day (calendar-extract-day date))
|
|
|
|
(year (calendar-extract-year date))
|
1999-08-28 15:20:18 +00:00
|
|
|
(jan-first (list 1 1 year))
|
|
|
|
(calendar-move-hook nil))
|
1995-09-21 03:11:06 +00:00
|
|
|
(if (and (= day 1) (= 1 month))
|
|
|
|
(calendar-backward-month (* 12 arg))
|
|
|
|
(if (and (= arg 1)
|
|
|
|
(calendar-date-is-visible-p jan-first))
|
|
|
|
(calendar-cursor-to-visible-date jan-first)
|
2005-03-26 15:55:15 +00:00
|
|
|
(calendar-other-month 1 (- year (1- arg)))
|
|
|
|
(calendar-cursor-to-visible-date (list 1 1 displayed-year)))))
|
1999-08-28 15:20:18 +00:00
|
|
|
(run-hooks 'calendar-move-hook))
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-end-of-year (arg)
|
|
|
|
"Move the cursor forward ARG year beginnings."
|
|
|
|
(interactive "p")
|
|
|
|
(calendar-cursor-to-nearest-date)
|
|
|
|
(let* ((date (calendar-cursor-to-date))
|
2008-04-07 01:59:37 +00:00
|
|
|
(month (calendar-extract-month date))
|
|
|
|
(day (calendar-extract-day date))
|
|
|
|
(year (calendar-extract-year date))
|
1999-08-28 15:20:18 +00:00
|
|
|
(dec-31 (list 12 31 year))
|
|
|
|
(calendar-move-hook nil))
|
1995-09-21 03:11:06 +00:00
|
|
|
(if (and (= day 31) (= 12 month))
|
|
|
|
(calendar-forward-month (* 12 arg))
|
|
|
|
(if (and (= arg 1)
|
|
|
|
(calendar-date-is-visible-p dec-31))
|
|
|
|
(calendar-cursor-to-visible-date dec-31)
|
2005-03-26 15:55:15 +00:00
|
|
|
(calendar-other-month 12 (+ year (1- arg)))
|
1999-08-28 15:20:18 +00:00
|
|
|
(calendar-cursor-to-visible-date (list 12 31 displayed-year)))))
|
|
|
|
(run-hooks 'calendar-move-hook))
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
1995-09-21 03:11:06 +00:00
|
|
|
(defun calendar-goto-date (date)
|
|
|
|
"Move cursor to DATE."
|
|
|
|
(interactive (list (calendar-read-date)))
|
2008-04-07 01:59:37 +00:00
|
|
|
(let ((month (calendar-extract-month date))
|
|
|
|
(year (calendar-extract-year date)))
|
1995-09-21 03:11:06 +00:00
|
|
|
(if (not (calendar-date-is-visible-p date))
|
|
|
|
(calendar-other-month
|
|
|
|
(if (and (= month 1) (= year 1))
|
|
|
|
2
|
|
|
|
month)
|
|
|
|
year)))
|
1999-08-28 15:20:18 +00:00
|
|
|
(calendar-cursor-to-visible-date date)
|
|
|
|
(run-hooks 'calendar-move-hook))
|
1995-09-21 03:11:06 +00:00
|
|
|
|
2008-03-13 05:46:32 +00:00
|
|
|
;;;###cal-autoload
|
2003-08-17 22:49:46 +00:00
|
|
|
(defun calendar-goto-day-of-year (year day &optional noecho)
|
2008-03-14 06:45:16 +00:00
|
|
|
"Move cursor to YEAR, DAY number; echo DAY/YEAR unless NOECHO is non-nil.
|
2003-08-17 22:49:46 +00:00
|
|
|
Negative DAY counts backward from end of year."
|
|
|
|
(interactive
|
|
|
|
(let* ((year (calendar-read
|
|
|
|
"Year (>0): "
|
|
|
|
(lambda (x) (> x 0))
|
2008-04-08 07:08:24 +00:00
|
|
|
(number-to-string (calendar-extract-year
|
2003-08-17 22:49:46 +00:00
|
|
|
(calendar-current-date)))))
|
|
|
|
(last (if (calendar-leap-year-p year) 366 365))
|
|
|
|
(day (calendar-read
|
|
|
|
(format "Day number (+/- 1-%d): " last)
|
2008-03-08 03:45:43 +00:00
|
|
|
(lambda (x) (and (<= 1 (abs x)) (<= (abs x) last))))))
|
2003-08-17 22:49:46 +00:00
|
|
|
(list year day)))
|
|
|
|
(calendar-goto-date
|
|
|
|
(calendar-gregorian-from-absolute
|
|
|
|
(if (< 0 day)
|
|
|
|
(+ -1 day (calendar-absolute-from-gregorian (list 1 1 year)))
|
|
|
|
(+ 1 day (calendar-absolute-from-gregorian (list 12 31 year))))))
|
|
|
|
(or noecho (calendar-print-day-of-year)))
|
|
|
|
|
1995-09-21 03:11:06 +00:00
|
|
|
(provide 'cal-move)
|
|
|
|
|
|
|
|
;;; cal-move.el ends here
|