Mercurial > emacs
comparison lisp/calendar/calendar.el @ 18940:953dfe84b101
(calendar-day-name): New optional args WIDTH, ABSOLUTE.
(calendar-month-name): New optional arg WIDTH.
(generate-calendar-month, calendar-date-string): Pass new args
instead of using substring here.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 24 Jul 1997 07:42:23 +0000 |
parents | 321afd5b0bc5 |
children | 06cb7a02a079 |
comparison
equal
deleted
inserted
replaced
18939:7415a69ea66e | 18940:953dfe84b101 |
---|---|
1781 (calendar-string-spread | 1781 (calendar-string-spread |
1782 (list (format "%s %d" (calendar-month-name month) year)) ? 20) | 1782 (list (format "%s %d" (calendar-month-name month) year)) ? 20) |
1783 indent t) | 1783 indent t) |
1784 (calendar-insert-indented "" indent);; Go to proper spot | 1784 (calendar-insert-indented "" indent);; Go to proper spot |
1785 (calendar-for-loop i from 0 to 6 do | 1785 (calendar-for-loop i from 0 to 6 do |
1786 (insert (substring (aref calendar-day-name-array | 1786 (insert (calendar-day-name (mod (+ calendar-week-start-day i) 7) |
1787 (mod (+ calendar-week-start-day i) 7)) | 1787 2 t)) |
1788 0 2)) | |
1789 (insert " ")) | 1788 (insert " ")) |
1790 (calendar-insert-indented "" 0 t);; Force onto following line | 1789 (calendar-insert-indented "" 0 t);; Force onto following line |
1791 (calendar-insert-indented "" indent);; Go to proper spot | 1790 (calendar-insert-indented "" indent);; Go to proper spot |
1792 ;; Add blank days before the first of the month | 1791 ;; Add blank days before the first of the month |
1793 (calendar-for-loop i from 1 to blank-days do (insert " ")) | 1792 (calendar-for-loop i from 1 to blank-days do (insert " ")) |
2261 value)) | 2260 value)) |
2262 | 2261 |
2263 (defun calendar-read-date (&optional noday) | 2262 (defun calendar-read-date (&optional noday) |
2264 "Prompt for Gregorian date. Returns a list (month day year). | 2263 "Prompt for Gregorian date. Returns a list (month day year). |
2265 If optional NODAY is t, does not ask for day, but just returns | 2264 If optional NODAY is t, does not ask for day, but just returns |
2266 (month nil year); if NODAY is any other non-nil value the value returned is | 2265 \(month nil year); if NODAY is any other non-nil value the value returned is |
2267 (month year) " | 2266 \(month year) " |
2268 (let* ((year (calendar-read | 2267 (let* ((year (calendar-read |
2269 "Year (>0): " | 2268 "Year (>0): " |
2270 '(lambda (x) (> x 0)) | 2269 '(lambda (x) (> x 0)) |
2271 (int-to-string (extract-calendar-year | 2270 (int-to-string (extract-calendar-year |
2272 (calendar-current-date))))) | 2271 (calendar-current-date))))) |
2292 (defun calendar-interval (mon1 yr1 mon2 yr2) | 2291 (defun calendar-interval (mon1 yr1 mon2 yr2) |
2293 "The number of months difference between MON1, YR1 and MON2, YR2." | 2292 "The number of months difference between MON1, YR1 and MON2, YR2." |
2294 (+ (* 12 (- yr2 yr1)) | 2293 (+ (* 12 (- yr2 yr1)) |
2295 (- mon2 mon1))) | 2294 (- mon2 mon1))) |
2296 | 2295 |
2297 (defun calendar-day-name (date) | 2296 (defun calendar-day-name (date &optional width absolute) |
2298 "Returns a string with the name of the day of the week of DATE." | 2297 "Returns a string with the name of the day of the week of DATE. |
2299 (aref calendar-day-name-array (calendar-day-of-week date))) | 2298 If WIDTH is non-nil, return just the first WIDTH characters of the name. |
2299 If ABSOLUTE is non-nil, then DATE is actual the day-of-the-week | |
2300 rather than a date." | |
2301 (let ((string (aref calendar-day-name-array | |
2302 (if absolute date (calendar-day-of-week date))))) | |
2303 (if width | |
2304 (let ((i 0) (result "") (pos 0)) | |
2305 (while (< i width) | |
2306 (let ((chartext (char-to-string (sref string pos)))) | |
2307 (setq pos (+ pos (length chartext))) | |
2308 (setq result (concat result chartext))) | |
2309 (setq i (1+ i))) | |
2310 result) | |
2311 string))) | |
2300 | 2312 |
2301 (defvar calendar-day-name-array | 2313 (defvar calendar-day-name-array |
2302 ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"]) | 2314 ["Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"]) |
2303 | 2315 |
2304 (defvar calendar-month-name-array | 2316 (defvar calendar-month-name-array |
2315 (setq index (1+ index)) | 2327 (setq index (1+ index)) |
2316 (cons (if filter (funcall filter x) x) | 2328 (cons (if filter (funcall filter x) x) |
2317 index)) | 2329 index)) |
2318 (append sequence nil)))) | 2330 (append sequence nil)))) |
2319 | 2331 |
2320 (defun calendar-month-name (month) | 2332 (defun calendar-month-name (month &optional width) |
2321 "The name of MONTH." | 2333 "The name of MONTH. |
2322 (aref calendar-month-name-array (1- month))) | 2334 If WIDTH is non-nil, return just the first WIDTH characters of the name." |
2335 (let ((string (aref calendar-month-name-array (1- month)))) | |
2336 (if width | |
2337 (let ((i 0) (result "") (pos 0)) | |
2338 (while (< i width) | |
2339 (let ((chartext (char-to-string (sref string pos)))) | |
2340 (setq pos (+ pos (length chartext))) | |
2341 (setq result (concat result chartext))) | |
2342 (setq i (1+ i))) | |
2343 result) | |
2344 string))) | |
2323 | 2345 |
2324 (defun calendar-day-of-week (date) | 2346 (defun calendar-day-of-week (date) |
2325 "Returns the day-of-the-week index of DATE, 0 for Sunday, 1 for Monday, etc." | 2347 "Returns the day-of-the-week index of DATE, 0 for Sunday, 1 for Monday, etc." |
2326 (% (calendar-absolute-from-gregorian date) 7)) | 2348 (% (calendar-absolute-from-gregorian date) 7)) |
2327 | 2349 |
2410 omits the name of the day of the week." | 2432 omits the name of the day of the week." |
2411 (let* ((dayname | 2433 (let* ((dayname |
2412 (if nodayname | 2434 (if nodayname |
2413 nil | 2435 nil |
2414 (if abbreviate | 2436 (if abbreviate |
2415 (substring (calendar-day-name date) 0 3) | 2437 (calendar-day-name date 3) |
2416 (calendar-day-name date)))) | 2438 (calendar-day-name date)))) |
2417 (month (extract-calendar-month date)) | 2439 (month (extract-calendar-month date)) |
2418 (monthname | 2440 (monthname |
2419 (if abbreviate | 2441 (if abbreviate |
2420 (substring | 2442 (calendar-month-name month 3) |
2421 (calendar-month-name month) 0 3) | |
2422 (calendar-month-name month))) | 2443 (calendar-month-name month))) |
2423 (day (int-to-string (extract-calendar-day date))) | 2444 (day (int-to-string (extract-calendar-day date))) |
2424 (month (int-to-string month)) | 2445 (month (int-to-string month)) |
2425 (year (int-to-string (extract-calendar-year date)))) | 2446 (year (int-to-string (extract-calendar-year date)))) |
2426 (mapconcat 'eval calendar-date-display-form ""))) | 2447 (mapconcat 'eval calendar-date-display-form ""))) |