- (let ((column (current-column)))
- (when (> 3 (count-lines (point-min) (point)))
- (goto-line 3)
- (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)))
+ (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)
+ (goto-char (point-min))
+ (forward-line (1- calendar-first-date-row))
+ (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)))