diff options
| -rw-r--r-- | lisp/ChangeLog | 17 | ||||
| -rw-r--r-- | lisp/calendar/calendar.el | 230 |
2 files changed, 129 insertions, 118 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d8f54c5979a..09dddf4591e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,20 @@ | |||
| 1 | 2008-06-17 Glenn Morris <rgm@gnu.org> | ||
| 2 | |||
| 3 | * calendar/calendar.el (calendar-move-hook): | ||
| 4 | Add calendar-update-mode-line as an option. | ||
| 5 | (calendar-date-echo-text): New user option. | ||
| 6 | (calendar-generate-month): Set `day'. Use calendar-date-echo-text. | ||
| 7 | (calendar-insert-indented): Simplify newline insertion. | ||
| 8 | (calendar-describe-mode): Remove unused function. | ||
| 9 | (calendar-mode-line-entry): New function. | ||
| 10 | (calendar-mode-line-format): Doc fix. Use calendar-mode-line-entry. | ||
| 11 | Mark as risky. | ||
| 12 | (calendar-mouse-other-month): Remove function. | ||
| 13 | (calendar-other-month): Handle mouse events. | ||
| 14 | (calendar-goto-info-node): Call fit-window-to-buffer. | ||
| 15 | (calendar-mode): Use define-derived-mode. Doc fix. | ||
| 16 | (calendar-update-mode-line): Tweak whitespace. | ||
| 17 | |||
| 1 | 2008-06-16 Stefan Monnier <monnier@iro.umontreal.ca> | 18 | 2008-06-16 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 19 | ||
| 3 | * vc-dispatcher.el (vc-dir-child-files): Use vc-string-prefix-p. | 20 | * vc-dispatcher.el (vc-dir-child-files): Use vc-string-prefix-p. |
diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el index 0f8a468a3e4..4336dc117f5 100644 --- a/lisp/calendar/calendar.el +++ b/lisp/calendar/calendar.el | |||
| @@ -347,8 +347,34 @@ For example, | |||
| 347 | 347 | ||
| 348 | redisplays the diary for whatever date the cursor is moved to." | 348 | redisplays the diary for whatever date the cursor is moved to." |
| 349 | :type 'hook | 349 | :type 'hook |
| 350 | :options '(calendar-update-mode-line) | ||
| 350 | :group 'calendar-hooks) | 351 | :group 'calendar-hooks) |
| 351 | 352 | ||
| 353 | (defcustom calendar-date-echo-text | ||
| 354 | "mouse-2: general menu\nmouse-3: menu for this date" | ||
| 355 | "String displayed when the cursor is over a date in the calendar. | ||
| 356 | When this variable is evaluated, DAY, MONTH, and YEAR are | ||
| 357 | integers appropriate to the relevant date. For example, to | ||
| 358 | display the ISO week: | ||
| 359 | |||
| 360 | (require 'cal-iso) | ||
| 361 | (setq calendar-date-echo-text '(format \"ISO week: %2d \" | ||
| 362 | (car | ||
| 363 | (calendar-iso-from-absolute | ||
| 364 | (calendar-absolute-from-gregorian | ||
| 365 | (list month day year)))))) | ||
| 366 | Changing this variable without using customize has no effect on | ||
| 367 | pre-existing calendar windows." | ||
| 368 | :group 'calendar | ||
| 369 | :initialize 'custom-initialize-default | ||
| 370 | :risky t | ||
| 371 | :set (lambda (sym val) | ||
| 372 | (set sym val) | ||
| 373 | (calendar-redraw)) | ||
| 374 | :type '(choice (string :tag "Literal string") | ||
| 375 | (sexp :tag "Lisp expression")) | ||
| 376 | :version "23.1") | ||
| 377 | |||
| 352 | (defcustom diary-file "~/diary" | 378 | (defcustom diary-file "~/diary" |
| 353 | "Name of the file in which one's personal diary of dates is kept. | 379 | "Name of the file in which one's personal diary of dates is kept. |
| 354 | 380 | ||
| @@ -1152,7 +1178,7 @@ line." | |||
| 1152 | calendar-week-start-day) | 1178 | calendar-week-start-day) |
| 1153 | 7)) | 1179 | 7)) |
| 1154 | (last (calendar-last-day-of-month month year)) | 1180 | (last (calendar-last-day-of-month month year)) |
| 1155 | string) | 1181 | string day) |
| 1156 | (goto-char (point-min)) | 1182 | (goto-char (point-min)) |
| 1157 | (calendar-insert-indented | 1183 | (calendar-insert-indented |
| 1158 | (calendar-string-spread | 1184 | (calendar-string-spread |
| @@ -1175,13 +1201,14 @@ line." | |||
| 1175 | (dotimes (idummy blank-days) (insert " ")) | 1201 | (dotimes (idummy blank-days) (insert " ")) |
| 1176 | ;; Put in the days of the month. | 1202 | ;; Put in the days of the month. |
| 1177 | (dotimes (i last) | 1203 | (dotimes (i last) |
| 1178 | (insert (format "%2d " (1+ i))) | 1204 | (setq day (1+ i)) |
| 1205 | (insert (format "%2d " day)) | ||
| 1206 | ;; FIXME set-text-properties? | ||
| 1179 | (add-text-properties | 1207 | (add-text-properties |
| 1180 | (- (point) 3) (1- (point)) | 1208 | (- (point) 3) (1- (point)) |
| 1181 | '(mouse-face highlight | 1209 | `(mouse-face highlight help-echo ,(eval calendar-date-echo-text))) |
| 1182 | help-echo "mouse-2: menu of operations for this date")) | 1210 | (and (zerop (mod (+ day blank-days) 7)) |
| 1183 | (and (zerop (mod (+ i 1 blank-days) 7)) | 1211 | (/= day last) |
| 1184 | (/= i (1- last)) | ||
| 1185 | (calendar-insert-indented "" 0 t) ; force onto following line | 1212 | (calendar-insert-indented "" 0 t) ; force onto following line |
| 1186 | (calendar-insert-indented "" indent))))) ; go to proper spot | 1213 | (calendar-insert-indented "" indent))))) ; go to proper spot |
| 1187 | 1214 | ||
| @@ -1199,9 +1226,8 @@ after the inserted text. Returns t." | |||
| 1199 | ;; Advance to next line, if requested. | 1226 | ;; Advance to next line, if requested. |
| 1200 | (when newline | 1227 | (when newline |
| 1201 | (end-of-line) | 1228 | (end-of-line) |
| 1202 | (if (eobp) | 1229 | (or (zerop (forward-line 1)) |
| 1203 | (newline) | 1230 | (insert "\n"))) |
| 1204 | (forward-line 1))) | ||
| 1205 | t) | 1231 | t) |
| 1206 | 1232 | ||
| 1207 | (defun calendar-redraw () | 1233 | (defun calendar-redraw () |
| @@ -1340,10 +1366,6 @@ after the inserted text. Returns t." | |||
| 1340 | 1366 | ||
| 1341 | (define-key map [menu-bar edit] 'undefined) | 1367 | (define-key map [menu-bar edit] 'undefined) |
| 1342 | (define-key map [menu-bar search] 'undefined) | 1368 | (define-key map [menu-bar search] 'undefined) |
| 1343 | ;; This ignores the mouse-up event after the mouse-down that pops up the | ||
| 1344 | ;; context menu. It should not be necessary because the mouse-up event | ||
| 1345 | ;; should be eaten up by the menu-handling toolkit. | ||
| 1346 | ;; (define-key map [mouse-2] 'ignore) | ||
| 1347 | 1369 | ||
| 1348 | (easy-menu-define nil map nil cal-menu-moon-menu) | 1370 | (easy-menu-define nil map nil cal-menu-moon-menu) |
| 1349 | (easy-menu-define nil map nil cal-menu-diary-menu) | 1371 | (easy-menu-define nil map nil cal-menu-diary-menu) |
| @@ -1351,6 +1373,7 @@ after the inserted text. Returns t." | |||
| 1351 | (easy-menu-define nil map nil cal-menu-goto-menu) | 1373 | (easy-menu-define nil map nil cal-menu-goto-menu) |
| 1352 | (easy-menu-define nil map nil cal-menu-scroll-menu) | 1374 | (easy-menu-define nil map nil cal-menu-scroll-menu) |
| 1353 | 1375 | ||
| 1376 | ;; These are referenced in the default calendar-date-echo-text. | ||
| 1354 | (define-key map [down-mouse-3] | 1377 | (define-key map [down-mouse-3] |
| 1355 | (easy-menu-binding cal-menu-context-mouse-menu)) | 1378 | (easy-menu-binding cal-menu-context-mouse-menu)) |
| 1356 | (define-key map [down-mouse-2] | 1379 | (define-key map [down-mouse-2] |
| @@ -1359,118 +1382,80 @@ after the inserted text. Returns t." | |||
| 1359 | map) | 1382 | map) |
| 1360 | "Keymap for `calendar-mode'.") | 1383 | "Keymap for `calendar-mode'.") |
| 1361 | 1384 | ||
| 1362 | ;; FIXME unused? | ||
| 1363 | (defun calendar-describe-mode () | ||
| 1364 | "Create a help buffer with a brief description of the `calendar-mode'." | ||
| 1365 | (interactive) | ||
| 1366 | (help-setup-xref (list #'calendar-describe-mode) (interactive-p)) | ||
| 1367 | (with-output-to-temp-buffer (help-buffer) | ||
| 1368 | (princ | ||
| 1369 | (format | ||
| 1370 | "Calendar Mode:\nFor a complete description, type %s\n%s\n" | ||
| 1371 | (substitute-command-keys | ||
| 1372 | "\\<calendar-mode-map>\\[describe-mode] from within the calendar") | ||
| 1373 | (substitute-command-keys "\\{calendar-mode-map}"))) | ||
| 1374 | (print-help-return-message))) | ||
| 1375 | |||
| 1376 | ;; Calendar mode is suitable only for specially formatted data. | 1385 | ;; Calendar mode is suitable only for specially formatted data. |
| 1377 | (put 'calendar-mode 'mode-class 'special) | 1386 | (put 'calendar-mode 'mode-class 'special) |
| 1378 | 1387 | ||
| 1388 | (defun calendar-mode-line-entry (command echo &optional key string) | ||
| 1389 | "Return a propertized string for `calendar-mode-line-format'. | ||
| 1390 | COMMAND is a command to run, ECHO is the help-echo text, KEY | ||
| 1391 | is COMMAND's keybinding, STRING describes the binding." | ||
| 1392 | (propertize (or key | ||
| 1393 | (substitute-command-keys | ||
| 1394 | (format "\\<calendar-mode-map>\\[%s] %s" command string))) | ||
| 1395 | 'help-echo (format "mouse-1: %s" echo) | ||
| 1396 | 'mouse-face 'mode-line-highlight | ||
| 1397 | 'keymap (make-mode-line-mouse-map 'mouse-1 command))) | ||
| 1398 | |||
| 1379 | ;; After calendar-mode-map. | 1399 | ;; After calendar-mode-map. |
| 1380 | (defcustom calendar-mode-line-format | 1400 | (defcustom calendar-mode-line-format |
| 1381 | (list | 1401 | (list |
| 1382 | (propertize "<" | 1402 | (calendar-mode-line-entry 'calendar-scroll-right "previous month" "<") |
| 1383 | 'help-echo "mouse-1: previous month" | ||
| 1384 | 'mouse-face 'mode-line-highlight | ||
| 1385 | 'keymap (make-mode-line-mouse-map 'mouse-1 | ||
| 1386 | 'calendar-scroll-right)) | ||
| 1387 | "Calendar" | 1403 | "Calendar" |
| 1388 | (concat | 1404 | (concat |
| 1389 | (propertize | 1405 | (calendar-mode-line-entry 'calendar-goto-info-node "read Info on Calendar" |
| 1390 | (substitute-command-keys | 1406 | nil "info") |
| 1391 | "\\<calendar-mode-map>\\[calendar-goto-info-node] info") | ||
| 1392 | 'help-echo "mouse-1: read Info on Calendar" | ||
| 1393 | 'mouse-face 'mode-line-highlight | ||
| 1394 | 'keymap (make-mode-line-mouse-map 'mouse-1 'calendar-goto-info-node)) | ||
| 1395 | " / " | 1407 | " / " |
| 1396 | (propertize | 1408 | (calendar-mode-line-entry 'calendar-other-month "choose another month" |
| 1397 | (substitute-command-keys | 1409 | nil "other") |
| 1398 | " \\<calendar-mode-map>\\[calendar-other-month] other") | ||
| 1399 | 'help-echo "mouse-1: choose another month" | ||
| 1400 | 'mouse-face 'mode-line-highlight | ||
| 1401 | 'keymap (make-mode-line-mouse-map | ||
| 1402 | 'mouse-1 'calendar-mouse-other-month)) | ||
| 1403 | " / " | 1410 | " / " |
| 1404 | (propertize | 1411 | (calendar-mode-line-entry 'calendar-goto-today "go to today's date" |
| 1405 | (substitute-command-keys | 1412 | nil "today")) |
| 1406 | "\\<calendar-mode-map>\\[calendar-goto-today] today") | ||
| 1407 | 'help-echo "mouse-1: go to today's date" | ||
| 1408 | 'mouse-face 'mode-line-highlight | ||
| 1409 | 'keymap (make-mode-line-mouse-map 'mouse-1 #'calendar-goto-today))) | ||
| 1410 | '(calendar-date-string (calendar-current-date) t) | 1413 | '(calendar-date-string (calendar-current-date) t) |
| 1411 | (propertize ">" | 1414 | (calendar-mode-line-entry 'calendar-scroll-left "next month" ">")) |
| 1412 | 'help-echo "mouse-1: next month" | ||
| 1413 | 'mouse-face 'mode-line-highlight | ||
| 1414 | 'keymap (make-mode-line-mouse-map | ||
| 1415 | 'mouse-1 'calendar-scroll-left))) | ||
| 1416 | "The mode line of the calendar buffer. | 1415 | "The mode line of the calendar buffer. |
| 1416 | This is a list of items that evaluate to strings. The elements | ||
| 1417 | are evaluated and concatenated, evenly separated by blanks. | ||
| 1418 | During evaluation, the variable `date' is available as the date | ||
| 1419 | nearest the cursor (or today's date if that fails). To update | ||
| 1420 | the mode-line as the cursor moves, add `calendar-update-mode-line' | ||
| 1421 | to `calendar-move-hook'. Here is an example that has the Hebrew date, | ||
| 1422 | the day number/days remaining in the year, and the ISO week/year numbers: | ||
| 1417 | 1423 | ||
| 1418 | This must be a list of items that evaluate to strings--those strings are | 1424 | (list |
| 1419 | evaluated and concatenated together, evenly separated by blanks. The variable | 1425 | \"\" |
| 1420 | `date' is available for use as the date under (or near) the cursor; `date' | 1426 | '(calendar-hebrew-date-string date) |
| 1421 | defaults to the current date if it is otherwise undefined. Here is an example | 1427 | '(let* ((year (calendar-extract-year date)) |
| 1422 | value that has the Hebrew date, the day number/days remaining in the year, | 1428 | (d (calendar-day-number date)) |
| 1423 | and the ISO week/year numbers in the mode. When `calendar-move-hook' is set | 1429 | (days-remaining |
| 1424 | to `calendar-update-mode-line', the mode line shows these values for the date | 1430 | (- (calendar-day-number (list 12 31 year)) d))) |
| 1425 | under the cursor: | 1431 | (format \"%d/%d\" d days-remaining)) |
| 1426 | 1432 | '(let* ((d (calendar-absolute-from-gregorian date)) | |
| 1427 | (list | 1433 | (iso-date (calendar-iso-from-absolute d))) |
| 1428 | \"\" | 1434 | (format \"ISO week %d of %d\" |
| 1429 | '(calendar-hebrew-date-string date) | 1435 | (calendar-extract-month iso-date) |
| 1430 | '(let* ((year (calendar-extract-year date)) | 1436 | (calendar-extract-year iso-date))) |
| 1431 | (d (calendar-day-number date)) | 1437 | \"\"))" |
| 1432 | (days-remaining | 1438 | :risky t |
| 1433 | (- (calendar-day-number (list 12 31 year)) d))) | ||
| 1434 | (format \"%d/%d\" d days-remaining)) | ||
| 1435 | '(let* ((d (calendar-absolute-from-gregorian date)) | ||
| 1436 | (iso-date (calendar-iso-from-absolute d))) | ||
| 1437 | (format \"ISO week %d of %d\" | ||
| 1438 | (calendar-extract-month iso-date) | ||
| 1439 | (calendar-extract-year iso-date))) | ||
| 1440 | \"\"))" | ||
| 1441 | :type 'sexp | 1439 | :type 'sexp |
| 1442 | :group 'calendar) | 1440 | :group 'calendar) |
| 1443 | 1441 | ||
| 1444 | (defun calendar-mouse-other-month (event) | ||
| 1445 | "Display a three-month calendar centered around a specified month and year. | ||
| 1446 | EVENT is the last mouse event." | ||
| 1447 | (interactive "e") | ||
| 1448 | (save-selected-window | ||
| 1449 | (select-window (posn-window (event-start event))) | ||
| 1450 | (call-interactively 'calendar-other-month))) | ||
| 1451 | |||
| 1452 | (defun calendar-goto-info-node () | 1442 | (defun calendar-goto-info-node () |
| 1453 | "Go to the info node for the calendar." | 1443 | "Go to the info node for the calendar." |
| 1454 | (interactive) | 1444 | (interactive) |
| 1455 | (info "(emacs)Calendar/Diary")) | 1445 | (info "(emacs)Calendar/Diary") |
| 1446 | (fit-window-to-buffer)) | ||
| 1456 | 1447 | ||
| 1457 | (defvar calendar-mark-ring nil | 1448 | (defvar calendar-mark-ring nil |
| 1458 | "Used by `calendar-set-mark'.") | 1449 | "Used by `calendar-set-mark'.") |
| 1459 | 1450 | ||
| 1460 | (defun calendar-mode () | 1451 | (define-derived-mode calendar-mode nil "Calendar" |
| 1461 | "A major mode for the calendar window. | 1452 | "A major mode for the calendar window. |
| 1462 | 1453 | For a complete description, see the info node `Calendar/Diary'. | |
| 1463 | For a complete description, type \ | ||
| 1464 | \\<calendar-mode-map>\\[calendar-goto-info-node] from within the calendar. | ||
| 1465 | 1454 | ||
| 1466 | \\<calendar-mode-map>\\{calendar-mode-map}" | 1455 | \\<calendar-mode-map>\\{calendar-mode-map}" |
| 1467 | (kill-all-local-variables) | 1456 | (setq buffer-read-only t |
| 1468 | (setq major-mode 'calendar-mode | ||
| 1469 | mode-name "Calendar" | ||
| 1470 | buffer-read-only t | ||
| 1471 | buffer-undo-list t | 1457 | buffer-undo-list t |
| 1472 | indent-tabs-mode nil) | 1458 | indent-tabs-mode nil) |
| 1473 | (use-local-map calendar-mode-map) | ||
| 1474 | (calendar-update-mode-line) | 1459 | (calendar-update-mode-line) |
| 1475 | (make-local-variable 'calendar-mark-ring) | 1460 | (make-local-variable 'calendar-mark-ring) |
| 1476 | (make-local-variable 'displayed-month) ; month in middle of window | 1461 | (make-local-variable 'displayed-month) ; month in middle of window |
| @@ -1481,8 +1466,7 @@ For a complete description, type \ | |||
| 1481 | (unless (boundp 'displayed-month) (setq displayed-month 1)) | 1466 | (unless (boundp 'displayed-month) (setq displayed-month 1)) |
| 1482 | (unless (boundp 'displayed-year) (setq displayed-year 2001)) | 1467 | (unless (boundp 'displayed-year) (setq displayed-year 2001)) |
| 1483 | (set (make-local-variable 'font-lock-defaults) | 1468 | (set (make-local-variable 'font-lock-defaults) |
| 1484 | '(calendar-font-lock-keywords t)) | 1469 | '(calendar-font-lock-keywords t))) |
| 1485 | (run-mode-hooks 'calendar-mode-hook)) | ||
| 1486 | 1470 | ||
| 1487 | (defun calendar-string-spread (strings char length) | 1471 | (defun calendar-string-spread (strings char length) |
| 1488 | "Concatenate list of STRINGS separated with copies of CHAR to fill LENGTH. | 1472 | "Concatenate list of STRINGS separated with copies of CHAR to fill LENGTH. |
| @@ -1514,12 +1498,16 @@ the STRINGS are just concatenated and the result truncated." | |||
| 1514 | (if (bufferp (get-buffer calendar-buffer)) | 1498 | (if (bufferp (get-buffer calendar-buffer)) |
| 1515 | (with-current-buffer calendar-buffer | 1499 | (with-current-buffer calendar-buffer |
| 1516 | (setq mode-line-format | 1500 | (setq mode-line-format |
| 1517 | (calendar-string-spread | 1501 | ;; The magic numbers are based on the fixed calendar layout. |
| 1518 | (let ((date (condition-case nil | 1502 | (concat (make-string (+ 3 |
| 1519 | (calendar-cursor-to-nearest-date) | 1503 | (- (car (window-inside-edges)) |
| 1520 | (error (calendar-current-date))))) | 1504 | (car (window-edges)))) ?\s) |
| 1521 | (mapcar 'eval calendar-mode-line-format)) | 1505 | (calendar-string-spread |
| 1522 | ?\s (frame-width))) | 1506 | (let ((date (condition-case nil |
| 1507 | (calendar-cursor-to-nearest-date) | ||
| 1508 | (error (calendar-current-date))))) | ||
| 1509 | (mapcar 'eval calendar-mode-line-format)) | ||
| 1510 | ?\s 74))) | ||
| 1523 | (force-mode-line-update)))) | 1511 | (force-mode-line-update)))) |
| 1524 | 1512 | ||
| 1525 | (defun calendar-window-list () | 1513 | (defun calendar-window-list () |
| @@ -1660,19 +1648,25 @@ handle dates in years BC." | |||
| 1660 | month (1+ month))) | 1648 | month (1+ month))) |
| 1661 | (list month day year)))) | 1649 | (list month day year)))) |
| 1662 | 1650 | ||
| 1663 | (defun calendar-other-month (month year) | 1651 | (defun calendar-other-month (month year &optional event) |
| 1664 | "Display a three-month calendar centered around MONTH and YEAR." | 1652 | "Display a three-month calendar centered around MONTH and YEAR. |
| 1665 | (interactive (calendar-read-date 'noday)) | 1653 | EVENT is an event like `last-nonmenu-event'." |
| 1666 | (unless (and (= month displayed-month) | 1654 | (interactive (let ((event (list last-nonmenu-event))) |
| 1667 | (= year displayed-year)) | 1655 | (append (calendar-read-date 'noday) event))) |
| 1668 | (let ((old-date (calendar-cursor-to-date)) | 1656 | (save-selected-window |
| 1669 | (today (calendar-current-date))) | 1657 | (and event |
| 1670 | (calendar-generate-window month year) | 1658 | (setq event (event-start event)) |
| 1671 | (calendar-cursor-to-visible-date | 1659 | (select-window (posn-window event))) |
| 1672 | (cond | 1660 | (unless (and (= month displayed-month) |
| 1673 | ((calendar-date-is-visible-p old-date) old-date) | 1661 | (= year displayed-year)) |
| 1674 | ((calendar-date-is-visible-p today) today) | 1662 | (let ((old-date (calendar-cursor-to-date)) |
| 1675 | (t (list month 1 year))))))) | 1663 | (today (calendar-current-date))) |
| 1664 | (calendar-generate-window month year) | ||
| 1665 | (calendar-cursor-to-visible-date | ||
| 1666 | (cond | ||
| 1667 | ((calendar-date-is-visible-p old-date) old-date) | ||
| 1668 | ((calendar-date-is-visible-p today) today) | ||
| 1669 | (t (list month 1 year)))))))) | ||
| 1676 | 1670 | ||
| 1677 | (defun calendar-set-mark (arg) | 1671 | (defun calendar-set-mark (arg) |
| 1678 | "Mark the date under the cursor, or jump to marked date. | 1672 | "Mark the date under the cursor, or jump to marked date. |