From 3eee90de6e9157dae8053f40006b6264ce5040cf Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Sat, 21 Jun 2008 19:28:58 +0000 Subject: [PATCH] (calendar-forward-day): Scroll in one month increments. (calendar-cursor-to-nearest-date): Use layout variables. Use calendar-column-to-month. (calendar-cursor-to-visible-date): Use layout variables. --- lisp/ChangeLog | 29 +++++++++++++++++++++ lisp/calendar/cal-move.el | 53 ++++++++++++++++++++++----------------- 2 files changed, 59 insertions(+), 23 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a293eab8dad..165e4edbbe6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,32 @@ +2008-06-21 Glenn Morris + + * calendar/cal-move.el (calendar-forward-day): Scroll in one month + increments. + + * calendar/calendar.el: Factor out the magic numbers controlling the + calendar layout. + (calendar-month-digit-width, calendar-month-width) + (calendar-right-margin): New variables. + (calendar-recompute-layout-variables, calendar-set-layout-variable): + New functions. + (calendar-left-margin, calendar-intermonth-spacing) + (calendar-column-width, calendar-day-header-width) + (calendar-day-digit-width): New options. + (calendar-first-date-row): New constant. + (calendar-move-to-column, calendar-ensure-newline): New functions, + replacing calendar-insert-indented. + (calendar-insert-indented): Remove function. + (calendar-generate-month): Use calendar-move-to-column and + calendar-ensure-newline. Use layout variables. + (calendar-generate, calendar-update-mode-line) + (calendar-font-lock-keywords): Use layout variables. + (calendar-column-to-month): New function. + (calendar-cursor-to-date): Use calendar-column-to-month. + Use layout variables. + * calendar/cal-move.el (calendar-cursor-to-nearest-date): + Use layout variables. Use calendar-column-to-month. + (calendar-cursor-to-visible-date): Use layout variables. + 2008-06-21 Stefan Monnier * Makefile.in (update-elclist): Don't exclude COMPILE_FIRST. diff --git a/lisp/calendar/cal-move.el b/lisp/calendar/cal-move.el index ec902c1da47..1a489d4577f 100644 --- a/lisp/calendar/cal-move.el +++ b/lisp/calendar/cal-move.el @@ -29,6 +29,7 @@ ;;; Code: +;; FIXME should calendar just require this? (require 'calendar) ;;;###cal-autoload @@ -38,20 +39,21 @@ The position of the cursor is unchanged if it is already on a date. Returns the list (month day year) giving the cursor position." (or (calendar-cursor-to-date) (let ((column (current-column))) - (when (> 3 (count-lines (point-min) (point))) - (goto-line 3) + (when (> calendar-first-date-row (count-lines (point-min) (point))) + (goto-line calendar-first-date-row) (move-to-column column)) - (if (not (looking-at "[0-9]")) - (if (and (not (looking-at " *$")) - (or (< column 25) - (and (> column 27) - (< column 50)) - (and (> column 52) - (< column 75)))) - (progn - (re-search-forward "[0-9]" nil t) - (backward-char 1)) - (re-search-backward "[0-9]" nil t))) + ;; FIXME the date positions are fixed and computable, + ;; but searching is probably more flexible. + ;; Note also that this may not be the "nearest" date. + ;; Eg with cursor just after end of month, can skip to next month. + (or (looking-at "[0-9]") + ;; We search forwards for a number, except close to the RH + ;; margin of a month, where we search backwards. + (if (or (looking-at " *$") + (< (calendar-column-to-month) 0)) + (re-search-backward "[0-9]" nil t) + (re-search-forward "[0-9]" nil t) + (backward-char 1))) (calendar-cursor-to-date)))) (defvar displayed-month) ; from calendar-generate @@ -63,21 +65,22 @@ Returns the list (month day year) giving the cursor position." (let ((month (calendar-extract-month date)) (day (calendar-extract-day date)) (year (calendar-extract-year date))) - (goto-line (+ 3 + (goto-line (+ calendar-first-date-row (/ (+ day -1 (mod (- (calendar-day-of-week (list month 1 year)) calendar-week-start-day) 7)) 7))) - (move-to-column (+ 6 - (* 25 + (move-to-column (+ calendar-left-margin (1- calendar-day-digit-width) + (* calendar-month-width (1+ (calendar-interval displayed-month displayed-year month year))) - (* 3 (mod - (- (calendar-day-of-week date) - calendar-week-start-day) - 7)))))) + (* calendar-column-width + (mod + (- (calendar-day-of-week date) + calendar-week-start-day) + 7)))))) ;;;###cal-autoload (defun calendar-goto-today () @@ -213,9 +216,13 @@ Moves backward if ARG is negative." (new-display-month (calendar-extract-month new-cursor-date)) (new-display-year (calendar-extract-year new-cursor-date))) ;; Put the new month on the screen, if needed, and go to the new date. - (if (not (calendar-date-is-visible-p new-cursor-date)) - (calendar-other-month new-display-month new-display-year)) - (calendar-cursor-to-visible-date new-cursor-date))) + (if (calendar-date-is-visible-p new-cursor-date) + (calendar-cursor-to-visible-date new-cursor-date) + ;; 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)) + (calendar-other-month new-display-month new-display-year)))) (run-hooks 'calendar-move-hook)) ;;;###cal-autoload -- 2.39.2