Mercurial > emacs
comparison lisp/calendar/calendar.el @ 82086:1ee19eca3bfc
(generate-calendar, (generate-calendar-month): Use dotimes rather than
calendar-for-loop.
(calendar-for-loop): Doc fix.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Tue, 24 Jul 2007 06:12:15 +0000 |
parents | cdd1d135369b |
children | baffe86b0c44 |
comparison
equal
deleted
inserted
replaced
82085:85f6cb7c9558 | 82086:1ee19eca3bfc |
---|---|
1341 (unless yr (setq yr displayed-year)) | 1341 (unless yr (setq yr displayed-year)) |
1342 (increment-calendar-month mon yr n) | 1342 (increment-calendar-month mon yr n) |
1343 (cons mon yr)) | 1343 (cons mon yr)) |
1344 | 1344 |
1345 (defmacro calendar-for-loop (var from init to final do &rest body) | 1345 (defmacro calendar-for-loop (var from init to final do &rest body) |
1346 "Execute a for loop." | 1346 "Execute a for loop. |
1347 Evaluate BODY with VAR bound to successive integers from INIT to FINAL, | |
1348 inclusive." | |
1347 (declare (debug (symbolp "from" form "to" form "do" body))) | 1349 (declare (debug (symbolp "from" form "to" form "do" body))) |
1348 `(let ((,var (1- ,init))) | 1350 `(let ((,var (1- ,init))) |
1349 (while (>= ,final (setq ,var (1+ ,var))) | 1351 (while (>= ,final (setq ,var (1+ ,var))) |
1350 ,@body))) | 1352 ,@body))) |
1351 | 1353 |
2108 (error "Months before January, 1 AD cannot be displayed")) | 2110 (error "Months before January, 1 AD cannot be displayed")) |
2109 (setq displayed-month month | 2111 (setq displayed-month month |
2110 displayed-year year) | 2112 displayed-year year) |
2111 (erase-buffer) | 2113 (erase-buffer) |
2112 (increment-calendar-month month year -1) | 2114 (increment-calendar-month month year -1) |
2113 (calendar-for-loop i from 0 to 2 do | 2115 (dotimes (i 3) |
2114 (generate-calendar-month month year (+ 5 (* 25 i))) | 2116 (generate-calendar-month month year (+ 5 (* 25 i))) |
2115 (increment-calendar-month month year 1))) | 2117 (increment-calendar-month month year 1))) |
2116 | 2118 |
2117 (defun generate-calendar-month (month year indent) | 2119 (defun generate-calendar-month (month year indent) |
2118 "Produce a calendar for MONTH, YEAR on the Gregorian calendar. | 2120 "Produce a calendar for MONTH, YEAR on the Gregorian calendar. |
2119 The calendar is inserted at the top of the buffer in which point is currently | 2121 The calendar is inserted at the top of the buffer in which point is currently |
2120 located, but indented INDENT spaces. The indentation is done from the first | 2122 located, but indented INDENT spaces. The indentation is done from the first |
2131 (calendar-string-spread | 2133 (calendar-string-spread |
2132 (list (format "%s %d" (calendar-month-name month) year)) ? 20) | 2134 (list (format "%s %d" (calendar-month-name month) year)) ? 20) |
2133 indent t) | 2135 indent t) |
2134 (calendar-insert-indented "" indent);; Go to proper spot | 2136 (calendar-insert-indented "" indent);; Go to proper spot |
2135 ;; Use the first two characters of each day to head the columns. | 2137 ;; Use the first two characters of each day to head the columns. |
2136 (calendar-for-loop i from 0 to 6 do | 2138 (dotimes (i 7) |
2137 (insert | 2139 (insert |
2138 (let ((string | 2140 (let ((string |
2139 (calendar-day-name (mod (+ calendar-week-start-day i) 7) nil t))) | 2141 (calendar-day-name (mod (+ calendar-week-start-day i) 7) nil t))) |
2140 (if enable-multibyte-characters | 2142 (if enable-multibyte-characters |
2141 (truncate-string-to-width string 2) | 2143 (truncate-string-to-width string 2) |
2142 (substring string 0 2))) | 2144 (substring string 0 2))) |
2143 " ")) | 2145 " ")) |
2144 (calendar-insert-indented "" 0 t);; Force onto following line | 2146 (calendar-insert-indented "" 0 t);; Force onto following line |
2145 (calendar-insert-indented "" indent);; Go to proper spot | 2147 (calendar-insert-indented "" indent);; Go to proper spot |
2146 ;; Add blank days before the first of the month | 2148 ;; Add blank days before the first of the month |
2147 (calendar-for-loop i from 1 to blank-days do (insert " ")) | 2149 (dotimes (idummy blank-days) (insert " ")) |
2148 ;; Put in the days of the month | 2150 ;; Put in the days of the month |
2149 (calendar-for-loop i from 1 to last do | 2151 (calendar-for-loop i from 1 to last do |
2150 (insert (format "%2d " i)) | 2152 (insert (format "%2d " i)) |
2151 (add-text-properties | 2153 (add-text-properties |
2152 (- (point) 3) (1- (point)) | 2154 (- (point) 3) (1- (point)) |