Commit b7fa2691 authored by Glenn Morris's avatar Glenn Morris
Browse files

Remove yet more cal-tex code duplication

* lisp/calendar/cal-tex.el (cal-tex-weekly-common): New function.
(cal-tex-cursor-week-at-a-glance, cal-tex-cursor-filofax-week): Use it.
parent 52f56d5a
......@@ -9,6 +9,10 @@
 
2012-08-21 Glenn Morris <rgm@gnu.org>
 
* calendar/cal-tex.el (cal-tex-weekly-common): New function.
(cal-tex-cursor-week-at-a-glance, cal-tex-cursor-filofax-week):
Use it.
* calendar/cal-tex.el (cal-tex-rightday): Add optional funcname arg.
(cal-tex-shortday): New function.
(cal-tex-cursor-week-at-a-glance, cal-tex-cursor-filofax-week)
......
......@@ -1060,16 +1060,8 @@ shown are hard-coded to 8-12, 13-17."
(cal-tex-e-framebox)
(cal-tex-hspace "1cm")))
;;;###cal-autoload
(defun cal-tex-cursor-week-at-a-glance (&optional n event)
"One-week-at-a-glance full page calendar for week indicated by cursor.
Optional prefix argument N specifies number of weeks (default 1),
starting on Mondays. The calendar shows holiday and diary entries
if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
It does not show hours of the day. Optional EVENT indicates a buffer
position to use instead of point."
(interactive (list (prefix-numeric-value current-prefix-arg)
last-nonmenu-event))
(defun cal-tex-weekly-common (n event &optional filofax)
"Common code for weekly calendars."
(or n (setq n 1))
(let* ((date (calendar-gregorian-from-absolute
(calendar-dayname-on-or-before
......@@ -1085,6 +1077,15 @@ position to use instead of point."
(holiday-in-range d1 d2)))
(diary-list (if cal-tex-diary
(cal-tex-list-diary-entries d1 d2))))
(if filofax
(progn
(cal-tex-preamble "twoside")
(cal-tex-filofax-paper)
(insert cal-tex-righthead)
(cal-tex-rightday "1.85in")
(cal-tex-rightday "0.8in" "weekend")
(insert cal-tex-lefthead)
(cal-tex-leftday "1.85in"))
(cal-tex-preamble "twoside,12pt")
(insert "\\textwidth 7in
\\textheight 10.5in
......@@ -1099,7 +1100,7 @@ position to use instead of point."
(cal-tex-rightday "2.75in")
(cal-tex-rightday "1.8in" "weekend")
(insert cal-tex-lefthead)
(cal-tex-leftday "2.75in")
(cal-tex-leftday "2.75in"))
(cal-tex-b-document)
(cal-tex-cmd "\\pagestyle" "empty")
(dotimes (i n)
......@@ -1133,34 +1134,35 @@ position to use instead of point."
(insert "%\n")
(setq date (cal-tex-incr-date date)))
(insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
(cal-tex-nl)
(insert (cal-tex-mini-calendar
(calendar-extract-month (cal-tex-previous-month date))
(calendar-extract-year (cal-tex-previous-month date))
"lastmonth" "1.1in" "1in"))
(insert (cal-tex-mini-calendar
(calendar-extract-month date)
(calendar-extract-year date)
"thismonth" "1.1in" "1in"))
(insert (cal-tex-mini-calendar
(calendar-extract-month (cal-tex-next-month date))
(calendar-extract-year (cal-tex-next-month date))
"nextmonth" "1.1in" "1in"))
(insert "\\hbox to \\textwidth{")
(cal-tex-hfill)
(insert "\\lastmonth")
(cal-tex-hfill)
(insert "\\thismonth")
(cal-tex-hfill)
(insert "\\nextmonth")
(cal-tex-hfill)
(insert "}")
(unless filofax
(cal-tex-nl)
(insert (cal-tex-mini-calendar
(calendar-extract-month (cal-tex-previous-month date))
(calendar-extract-year (cal-tex-previous-month date))
"lastmonth" "1.1in" "1in"))
(insert (cal-tex-mini-calendar
(calendar-extract-month date)
(calendar-extract-year date)
"thismonth" "1.1in" "1in"))
(insert (cal-tex-mini-calendar
(calendar-extract-month (cal-tex-next-month date))
(calendar-extract-year (cal-tex-next-month date))
"nextmonth" "1.1in" "1in"))
(insert "\\hbox to \\textwidth{")
(cal-tex-hfill)
(insert "\\lastmonth")
(cal-tex-hfill)
(insert "\\thismonth")
(cal-tex-hfill)
(insert "\\nextmonth")
(cal-tex-hfill)
(insert "}"))
(cal-tex-newpage)
(insert "\\righthead")
(cal-tex-arg
(let ((d (cal-tex-incr-date date 3)))
(if (= (calendar-extract-month date)
(calendar-extract-month d))
(calendar-extract-month d))
(format "%s %s"
(cal-tex-month-name (calendar-extract-month date))
(calendar-extract-year date))
......@@ -1201,76 +1203,16 @@ position to use instead of point."
(run-hooks 'cal-tex-hook)))
;;;###cal-autoload
(defun cal-tex-cursor-filofax-2week (&optional n event)
"Two-weeks-at-a-glance Filofax style calendar for week cursor is in.
Optional prefix argument N specifies number of weeks (default 1).
The calendar shows holiday and diary entries if
`cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
Optional EVENT indicates a buffer position to use instead of point."
(defun cal-tex-cursor-week-at-a-glance (&optional n event)
"One-week-at-a-glance full page calendar for week indicated by cursor.
Optional prefix argument N specifies number of weeks (default 1),
starting on Mondays. The calendar shows holiday and diary entries
if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
It does not show hours of the day. Optional EVENT indicates a buffer
position to use instead of point."
(interactive (list (prefix-numeric-value current-prefix-arg)
last-nonmenu-event))
(or n (setq n 1))
(let* ((date (calendar-gregorian-from-absolute
(calendar-dayname-on-or-before
calendar-week-start-day
(calendar-absolute-from-gregorian
(calendar-cursor-to-date t event)))))
(month (calendar-extract-month date))
(year (calendar-extract-year date))
(day (calendar-extract-day date))
(d1 (calendar-absolute-from-gregorian date))
(d2 (+ (* 7 n) d1))
(holidays (if cal-tex-holidays
(holiday-in-range d1 d2)))
(diary-list (if cal-tex-diary
(cal-tex-list-diary-entries d1 d2))))
(cal-tex-preamble "twoside")
(cal-tex-filofax-paper)
(insert cal-tex-righthead)
(cal-tex-rightday "0.7in")
(insert cal-tex-lefthead)
(cal-tex-leftday "0.7in")
(cal-tex-b-document)
(cal-tex-cmd "\\pagestyle" "empty")
(dotimes (i n)
(if (zerop (mod i 2))
(insert "\\righthead")
(insert "\\lefthead"))
(cal-tex-arg
(let ((d (cal-tex-incr-date date 6)))
(if (= (calendar-extract-month date)
(calendar-extract-month d))
(format "%s %s"
(cal-tex-month-name (calendar-extract-month date))
(calendar-extract-year date))
(if (= (calendar-extract-year date)
(calendar-extract-year d))
(format "%s---%s %s"
(cal-tex-month-name (calendar-extract-month date))
(cal-tex-month-name (calendar-extract-month d))
(calendar-extract-year date))
(format "%s %s---%s %s"
(cal-tex-month-name (calendar-extract-month date))
(calendar-extract-year date)
(cal-tex-month-name (calendar-extract-month d))
(calendar-extract-year d))))))
(insert "%\n")
(dotimes (_jdummy 7)
(if (zerop (mod i 2))
(insert "\\rightday")
(insert "\\leftday"))
(cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
(cal-tex-arg (number-to-string (calendar-extract-day date)))
(cal-tex-arg (cal-tex-latexify-list diary-list date))
(cal-tex-arg (cal-tex-latexify-list holidays date))
(cal-tex-arg (eval cal-tex-daily-string))
(insert "%\n")
(setq date (cal-tex-incr-date date)))
(unless (= i (1- n))
(run-hooks 'cal-tex-week-hook)
(cal-tex-newpage)))
(cal-tex-end-document)
(run-hooks 'cal-tex-hook)))
(cal-tex-weekly-common n event))
;;;###cal-autoload
(defun cal-tex-cursor-filofax-week (&optional n event)
......@@ -1281,186 +1223,7 @@ if `cal-tex-holidays' and `cal-tex-diary', respectively, are non-nil.
Optional EVENT indicates a buffer position to use instead of point."
(interactive (list (prefix-numeric-value current-prefix-arg)
last-nonmenu-event))
(or n (setq n 1))
(let* ((date (calendar-gregorian-from-absolute
(calendar-dayname-on-or-before
1
(calendar-absolute-from-gregorian
(calendar-cursor-to-date t event)))))
(month (calendar-extract-month date))
(year (calendar-extract-year date))
(day (calendar-extract-day date))
(d1 (calendar-absolute-from-gregorian date))
(d2 (+ (* 7 n) d1))
(holidays (if cal-tex-holidays
(holiday-in-range d1 d2)))
(diary-list (if cal-tex-diary
(cal-tex-list-diary-entries d1 d2))))
(cal-tex-preamble "twoside")
(cal-tex-filofax-paper)
(insert cal-tex-righthead)
(cal-tex-rightday "1.85in")
(cal-tex-rightday "0.8in" "weekend")
(insert cal-tex-lefthead)
(cal-tex-leftday "1.85in")
(cal-tex-b-document)
(cal-tex-cmd "\\pagestyle" "empty")
(dotimes (i n)
(insert "\\lefthead")
(cal-tex-arg
(let ((d (cal-tex-incr-date date 2)))
(if (= (calendar-extract-month date)
(calendar-extract-month d))
(format "%s %s"
(cal-tex-month-name (calendar-extract-month date))
(calendar-extract-year date))
(if (= (calendar-extract-year date)
(calendar-extract-year d))
(format "%s---%s %s"
(cal-tex-month-name (calendar-extract-month date))
(cal-tex-month-name (calendar-extract-month d))
(calendar-extract-year date))
(format "%s %s---%s %s"
(cal-tex-month-name (calendar-extract-month date))
(calendar-extract-year date)
(cal-tex-month-name (calendar-extract-month d))
(calendar-extract-year d))))))
(insert "%\n")
(dotimes (_jdummy 3)
(insert "\\leftday")
(cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
(cal-tex-arg (number-to-string (calendar-extract-day date)))
(cal-tex-arg (cal-tex-latexify-list diary-list date))
(cal-tex-arg (cal-tex-latexify-list holidays date))
(cal-tex-arg (eval cal-tex-daily-string))
(insert "%\n")
(setq date (cal-tex-incr-date date)))
(insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n")
(cal-tex-newpage)
(insert "\\righthead")
(cal-tex-arg
(let ((d (cal-tex-incr-date date 3)))
(if (= (calendar-extract-month date)
(calendar-extract-month d))
(format "%s %s"
(cal-tex-month-name (calendar-extract-month date))
(calendar-extract-year date))
(if (= (calendar-extract-year date)
(calendar-extract-year d))
(format "%s---%s %s"
(cal-tex-month-name (calendar-extract-month date))
(cal-tex-month-name (calendar-extract-month d))
(calendar-extract-year date))
(format "%s %s---%s %s"
(cal-tex-month-name (calendar-extract-month date))
(calendar-extract-year date)
(cal-tex-month-name (calendar-extract-month d))
(calendar-extract-year d))))))
(insert "%\n")
(dotimes (_jdummy 2)
(insert "\\rightday")
(cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
(cal-tex-arg (number-to-string (calendar-extract-day date)))
(cal-tex-arg (cal-tex-latexify-list diary-list date))
(cal-tex-arg (cal-tex-latexify-list holidays date))
(cal-tex-arg (eval cal-tex-daily-string))
(insert "%\n")
(setq date (cal-tex-incr-date date)))
(dotimes (_jdummy 2)
(insert "\\weekend")
(cal-tex-arg (cal-tex-LaTeXify-string (calendar-day-name date)))
(cal-tex-arg (number-to-string (calendar-extract-day date)))
(cal-tex-arg (cal-tex-latexify-list diary-list date))
(cal-tex-arg (cal-tex-latexify-list holidays date))
(cal-tex-arg (eval cal-tex-daily-string))
(insert "%\n")
(setq date (cal-tex-incr-date date)))
(unless (= i (1- n))
(run-hooks 'cal-tex-week-hook)
(cal-tex-newpage)))
(cal-tex-end-document)
(run-hooks 'cal-tex-hook)))
;;;###cal-autoload
(defun cal-tex-cursor-filofax-daily (&optional n event)
"Day-per-page Filofax style calendar for week indicated by cursor.
Optional prefix argument N specifies number of weeks (default 1),
starting on Mondays. The calendar shows holiday and diary
entries if `cal-tex-holidays' and `cal-tex-diary', respectively,
are non-nil. Pages are ruled if `cal-tex-rules' is non-nil.
Optional EVENT indicates a buffer position to use instead of point."
(interactive (list (prefix-numeric-value current-prefix-arg)
last-nonmenu-event))
(or n (setq n 1))
(let* ((date (calendar-gregorian-from-absolute
(calendar-dayname-on-or-before
1
(calendar-absolute-from-gregorian
(calendar-cursor-to-date t event)))))
(month (calendar-extract-month date))
(year (calendar-extract-year date))
(day (calendar-extract-day date))
(d1 (calendar-absolute-from-gregorian date))
(d2 (+ (* 7 n) d1))
(holidays (if cal-tex-holidays
(holiday-in-range d1 d2)))
(diary-list (if cal-tex-diary
(cal-tex-list-diary-entries d1 d2))))
(cal-tex-preamble "twoside")
(cal-tex-filofax-paper)
(insert cal-tex-righthead)
(cal-tex-shortday "rightday")
(cal-tex-shortday "weekend")
(insert cal-tex-lefthead)
(cal-tex-shortday "leftday")
(insert "\\newbox\\LineBox
\\setbox\\LineBox=\\hbox to\\textwidth{%
\\vrule height.2in width0pt\\leaders\\hrule\\hfill}
\\def\\linesfill{\\par\\leaders\\copy\\LineBox\\vfill}
")
(cal-tex-b-document)
(cal-tex-cmd "\\pagestyle" "empty")
(dotimes (i n)
(dotimes (j 4)
(let ((even (zerop (% j 2))))
(insert (if even
"\\righthead"
"\\lefthead"))
(cal-tex-arg (calendar-date-string date))
(insert "%\n")
(insert (if even
"\\rightday"
"\\leftday")))
(cal-tex-arg (cal-tex-latexify-list diary-list date))
(cal-tex-arg (cal-tex-latexify-list holidays date "\\\\" t))
(cal-tex-arg (eval cal-tex-daily-string))
(insert "%\n")
(if cal-tex-rules
(insert "\\linesfill\n")
(insert "\\vfill\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
(cal-tex-newpage)
(setq date (cal-tex-incr-date date)))
(insert "%\n")
(dotimes (_jdummy 2)
(insert "\\lefthead")
(cal-tex-arg (calendar-date-string date))
(insert "\\weekend")
(cal-tex-arg (cal-tex-latexify-list diary-list date))
(cal-tex-arg (cal-tex-latexify-list holidays date "\\\\" t))
(cal-tex-arg (eval cal-tex-daily-string))
(insert "%\n")
(if cal-tex-rules
(insert "\\linesfill\n")
(insert "\\vfill"))
(setq date (cal-tex-incr-date date)))
(or cal-tex-rules
(insert "\\noindent\\rule{\\textwidth}{0.3pt}\\\\%\n"))
(unless (= i (1- n))
(run-hooks 'cal-tex-week-hook)
(cal-tex-newpage)))
(cal-tex-end-document)
(run-hooks 'cal-tex-hook)))
(cal-tex-weekly-common n event t))
;;;
;;; Daily calendars
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment