changeset 96159:cb4a9a7913cd

(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.
author Glenn Morris <rgm@gnu.org>
date Sat, 21 Jun 2008 19:28:42 +0000
parents 44b22c5bd2a9
children 6c5630f01152
files lisp/calendar/cal-move.el
diffstat 1 files changed, 30 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/calendar/cal-move.el	Sat Jun 21 19:28:09 2008 +0000
+++ b/lisp/calendar/cal-move.el	Sat Jun 21 19:28:42 2008 +0000
@@ -29,6 +29,7 @@
 
 ;;; Code:
 
+;; FIXME should calendar just require this?
 (require 'calendar)
 
 ;;;###cal-autoload
@@ -38,20 +39,21 @@
 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 @@
   (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 @@
            (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