Skip to content

Commit

Permalink
Use lexical-binding in all the cal-*.el files
Browse files Browse the repository at this point in the history
* lisp/calendar/cal-bahai.el: Use lexical-binding.
(calendar-bahai-date-string): Use `calendar-dlet*`.

* lisp/calendar/cal-china.el: Use lexical-binding.
(calendar-chinese-zodiac-sign-on-or-after)
(calendar-chinese-new-moon-on-or-after): Declare `year`.
(calendar-chinese-from-absolute-for-diary)
(calendar-chinese-to-absolute-for-diary)
(calendar-chinese-mark-date-pattern): Avoid dynbound var `date` as
function argument.

* lisp/calendar/cal-coptic.el: Use lexical-binding.
(calendar-coptic-date-string): Use `calendar-dlet*`.
(calendar-ethiopic-to-absolute, calendar-ethiopic-from-absolute)
(calendar-ethiopic-date-string, calendar-ethiopic-goto-date):
Avoid dynbound var `date` as function argument.

* lisp/calendar/cal-french.el: Use lexical-binding.

* lisp/calendar/cal-hebrew.el: Use lexical-binding.
(holiday-hebrew-hanukkah): Don't use the third form in `dotimes`.

* lisp/calendar/cal-islam.el: Use lexical-binding.
(calendar-islamic-to-absolute): Comment out unused vars `month` and `day`.

* lisp/calendar/cal-move.el:
* lisp/calendar/cal-mayan.el:
* lisp/calendar/cal-iso.el: Use lexical-binding.

* lisp/calendar/cal-persia.el: Use lexical-binding.
(calendar-persian-date-string): Use `calendar-dlet*`.

* lisp/calendar/cal-html.el: Use lexical-binding.
(cal-html-insert-minical): Comment out unused var `date`.
(cal-html-cursor-month, cal-html-cursor-year): Mark `event` arg as unused.

* lisp/calendar/cal-menu.el: Use lexical-binding.
(diary-list-include-blanks): Declare var.

* lisp/calendar/cal-x.el: Use lexical-binding.

* lisp/calendar/cal-tex.el: Use lexical-binding.
(diary-list-include-blanks): Declare var.
(cal-tex-insert-days, cal-tex-cursor-week-iso, cal-tex-week-hours)
(cal-tex-weekly-common, cal-tex-cursor-filofax-2week)
(cal-tex-cursor-filofax-daily, cal-tex-daily-page): Declare `date`
as dynbound for the benefit of `cal-tex-daily-string`.
  • Loading branch information
monnier committed Jan 21, 2021
1 parent 0c93d0d commit bacc24b
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 96 deletions.
13 changes: 7 additions & 6 deletions lisp/calendar/cal-bahai.el
@@ -1,4 +1,4 @@
;;; cal-bahai.el --- calendar functions for the Bahá’í calendar.
;;; cal-bahai.el --- calendar functions for the Bahá’í calendar. -*- lexical-binding: t; -*-

;; Copyright (C) 2001-2021 Free Software Foundation, Inc.

Expand Down Expand Up @@ -124,9 +124,10 @@ Defaults to today's date if DATE is not given."
(y (calendar-extract-year bahai-date)))
(if (< y 1)
"" ; pre-Bahai
(let* ((m (calendar-extract-month bahai-date))
(d (calendar-extract-day bahai-date))
(monthname (if (and (= m 19)
(let ((m (calendar-extract-month bahai-date))
(d (calendar-extract-day bahai-date)))
(calendar-dlet*
((monthname (if (and (= m 19)
(<= d 0))
"Ayyám-i-Há"
(aref calendar-bahai-month-name-array (1- m))))
Expand All @@ -137,8 +138,8 @@ Defaults to today's date if DATE is not given."
(year (number-to-string y))
(month (number-to-string m))
dayname)
;; Can't call calendar-date-string because of monthname oddity.
(mapconcat 'eval calendar-date-display-form "")))))
;; Can't call calendar-date-string because of monthname oddity.
(mapconcat #'eval calendar-date-display-form ""))))))

;;;###cal-autoload
(defun calendar-bahai-print-date ()
Expand Down
25 changes: 15 additions & 10 deletions lisp/calendar/cal-china.el
@@ -1,4 +1,4 @@
;;; cal-china.el --- calendar functions for the Chinese calendar
;;; cal-china.el --- calendar functions for the Chinese calendar -*- lexical-binding: t; -*-

;; Copyright (C) 1995, 1997, 2001-2021 Free Software Foundation, Inc.

Expand Down Expand Up @@ -185,7 +185,9 @@ N congruent to 1 gives the first name, N congruent to 2 gives the second name,
(defun calendar-chinese-zodiac-sign-on-or-after (d)
"Absolute date of first new Zodiac sign on or after absolute date D.
The Zodiac signs begin when the sun's longitude is a multiple of 30 degrees."
(let* ((year (calendar-extract-year (calendar-gregorian-from-absolute d)))
(with-suppressed-warnings ((lexical year))
(defvar year))
(let* ((year (calendar-extract-year (calendar-gregorian-from-absolute d)))
(calendar-time-zone (eval calendar-chinese-time-zone)) ; uses year
(calendar-daylight-time-offset
calendar-chinese-daylight-time-offset)
Expand All @@ -207,6 +209,8 @@ The Zodiac signs begin when the sun's longitude is a multiple of 30 degrees."

(defun calendar-chinese-new-moon-on-or-after (d)
"Absolute date of first new moon on or after absolute date D."
(with-suppressed-warnings ((lexical year))
(defvar year))
(let* ((year (calendar-extract-year (calendar-gregorian-from-absolute d)))
(calendar-time-zone (eval calendar-chinese-time-zone))
(calendar-daylight-time-offset
Expand Down Expand Up @@ -665,17 +669,17 @@ Echo Chinese date unless NOECHO is non-nil."
["正月" "二月" "三月" "四月" "五月" "六月"
"七月" "八月" "九月" "十月" "冬月" "臘月"])

;;; NOTE: In the diary the cycle and year of a Chinese date is
;;; combined using this formula: (+ (* cycle 100) year).
;; NOTE: In the diary the cycle and year of a Chinese date is
;; combined using this formula: (+ (* cycle 100) year).
;;;
;;; These two functions convert to and back from this representation.
(defun calendar-chinese-from-absolute-for-diary (date)
(pcase-let ((`(,c ,y ,m ,d) (calendar-chinese-from-absolute date)))
;; These two functions convert to and back from this representation.
(defun calendar-chinese-from-absolute-for-diary (thedate)
(pcase-let ((`(,c ,y ,m ,d) (calendar-chinese-from-absolute thedate)))
;; Note: For leap months M is a float.
(list (floor m) d (+ (* c 100) y))))

(defun calendar-chinese-to-absolute-for-diary (date &optional prefer-leap)
(pcase-let* ((`(,m ,d ,y) date)
(defun calendar-chinese-to-absolute-for-diary (thedate &optional prefer-leap)
(pcase-let* ((`(,m ,d ,y) thedate)
(cycle (floor y 100))
(year (mod y 100))
(months (calendar-chinese-months cycle year))
Expand All @@ -693,7 +697,8 @@ Echo Chinese date unless NOECHO is non-nil."
(unless (zerop month)
(calendar-mark-1 month day year
#'calendar-chinese-from-absolute-for-diary
(lambda (date) (calendar-chinese-to-absolute-for-diary date t))
(lambda (thedate)
(calendar-chinese-to-absolute-for-diary thedate t))
color)))

;;;###cal-autoload
Expand Down
33 changes: 17 additions & 16 deletions lisp/calendar/cal-coptic.el
@@ -1,4 +1,4 @@
;;; cal-coptic.el --- calendar functions for the Coptic/Ethiopic calendars
;;; cal-coptic.el --- calendar functions for the Coptic/Ethiopic calendars -*- lexical-binding: t; -*-

;; Copyright (C) 1995, 1997, 2001-2021 Free Software Foundation, Inc.

Expand Down Expand Up @@ -116,12 +116,13 @@ Defaults to today's date if DATE is not given."
(m (calendar-extract-month coptic-date)))
(if (< y 1)
""
(let ((monthname (aref calendar-coptic-month-name-array (1- m)))
(day (number-to-string (calendar-extract-day coptic-date)))
(dayname nil)
(month (number-to-string m))
(year (number-to-string y)))
(mapconcat 'eval calendar-date-display-form "")))))
(calendar-dlet*
((monthname (aref calendar-coptic-month-name-array (1- m)))
(day (number-to-string (calendar-extract-day coptic-date)))
(dayname nil)
(month (number-to-string m))
(year (number-to-string y)))
(mapconcat #'eval calendar-date-display-form "")))))

;;;###cal-autoload
(defun calendar-coptic-print-date ()
Expand Down Expand Up @@ -197,30 +198,30 @@ Echo Coptic date unless NOECHO is t."
(defconst calendar-ethiopic-name "Ethiopic"
"Used in some message strings.")

(defun calendar-ethiopic-to-absolute (date)
(defun calendar-ethiopic-to-absolute (thedate)
"Compute absolute date from Ethiopic date DATE.
The absolute date is the number of days elapsed since the (imaginary)
Gregorian date Sunday, December 31, 1 BC."
(let ((calendar-coptic-epoch calendar-ethiopic-epoch))
(calendar-coptic-to-absolute date)))
(calendar-coptic-to-absolute thedate)))

(defun calendar-ethiopic-from-absolute (date)
(defun calendar-ethiopic-from-absolute (thedate)
"Compute the Ethiopic equivalent for absolute date DATE.
The result is a list of the form (MONTH DAY YEAR).
The absolute date is the number of days elapsed since the imaginary
Gregorian date Sunday, December 31, 1 BC."
(let ((calendar-coptic-epoch calendar-ethiopic-epoch))
(calendar-coptic-from-absolute date)))
(calendar-coptic-from-absolute thedate)))

;;;###cal-autoload
(defun calendar-ethiopic-date-string (&optional date)
(defun calendar-ethiopic-date-string (&optional thedate)
"String of Ethiopic date of Gregorian DATE.
Returns the empty string if DATE is pre-Ethiopic calendar.
Defaults to today's date if DATE is not given."
(let ((calendar-coptic-epoch calendar-ethiopic-epoch)
(calendar-coptic-name calendar-ethiopic-name)
(calendar-coptic-month-name-array calendar-ethiopic-month-name-array))
(calendar-coptic-date-string date)))
(calendar-coptic-date-string thedate)))

;;;###cal-autoload
(defun calendar-ethiopic-print-date ()
Expand All @@ -232,16 +233,16 @@ Defaults to today's date if DATE is not given."
(call-interactively 'calendar-coptic-print-date)))

;;;###cal-autoload
(defun calendar-ethiopic-goto-date (date &optional noecho)
"Move cursor to Ethiopic date DATE.
(defun calendar-ethiopic-goto-date (thedate &optional noecho)
"Move cursor to Ethiopic date THEDATE.
Echo Ethiopic date unless NOECHO is t."
(interactive
(let ((calendar-coptic-epoch calendar-ethiopic-epoch)
(calendar-coptic-name calendar-ethiopic-name)
(calendar-coptic-month-name-array calendar-ethiopic-month-name-array))
(calendar-coptic-read-date)))
(calendar-goto-date (calendar-gregorian-from-absolute
(calendar-ethiopic-to-absolute date)))
(calendar-ethiopic-to-absolute thedate)))
(or noecho (calendar-ethiopic-print-date)))

;; To be called from diary-list-sexp-entries, where DATE is bound.
Expand Down
2 changes: 1 addition & 1 deletion lisp/calendar/cal-french.el
@@ -1,4 +1,4 @@
;;; cal-french.el --- calendar functions for the French Revolutionary calendar
;;; cal-french.el --- calendar functions for the French Revolutionary calendar -*- lexical-binding: t; -*-

;; Copyright (C) 1988-1989, 1992, 1994-1995, 1997, 2001-2021 Free
;; Software Foundation, Inc.
Expand Down
17 changes: 9 additions & 8 deletions lisp/calendar/cal-hebrew.el
@@ -1,4 +1,4 @@
;;; cal-hebrew.el --- calendar functions for the Hebrew calendar
;;; cal-hebrew.el --- calendar functions for the Hebrew calendar -*- lexical-binding: t; -*-

;; Copyright (C) 1995, 1997, 2001-2021 Free Software Foundation, Inc.

Expand Down Expand Up @@ -399,19 +399,20 @@ is non-nil."
(list m (calendar-last-day-of-month m y) y))))))
(abs-h (calendar-hebrew-to-absolute (list 9 25 h-y)))
(ord ["first" "second" "third" "fourth" "fifth" "sixth"
"seventh" "eighth"])
han)
"seventh" "eighth"]))
(holiday-filter-visible-calendar
(if (or all calendar-hebrew-all-holidays-flag)
(append
(list
(list (calendar-gregorian-from-absolute (1- abs-h))
"Erev Hanukkah"))
(dotimes (i 8 (nreverse han))
(push (list
(calendar-gregorian-from-absolute (+ abs-h i))
(format "Hanukkah (%s day)" (aref ord i)))
han)))
(let (han)
(dotimes (i 8)
(push (list
(calendar-gregorian-from-absolute (+ abs-h i))
(format "Hanukkah (%s day)" (aref ord i)))
han))
(nreverse han)))
(list (list (calendar-gregorian-from-absolute abs-h) "Hanukkah")))))))

;;;###holiday-autoload
Expand Down
19 changes: 9 additions & 10 deletions lisp/calendar/cal-html.el
@@ -1,4 +1,4 @@
;;; cal-html.el --- functions for printing HTML calendars
;;; cal-html.el --- functions for printing HTML calendars -*- lexical-binding: t; -*-

;; Copyright (C) 2002-2021 Free Software Foundation, Inc.

Expand Down Expand Up @@ -250,7 +250,7 @@ Contains links to previous and next month and year, and current minical."
calendar-week-start-day))
7))
(monthpage-name (cal-html-monthpage-name month year))
date)
) ;; date
;; Start writing table.
(insert (cal-html-comment "MINICAL")
(cal-html-b-table "class=minical border=1 align=center"))
Expand All @@ -276,7 +276,7 @@ Contains links to previous and next month and year, and current minical."
(insert cal-html-e-tablerow-string
cal-html-b-tablerow-string)))
;; End empty slots (for some browsers like konqueror).
(dotimes (i end-blank-days)
(dotimes (_ end-blank-days)
(insert
cal-html-b-tabledata-string
cal-html-e-tabledata-string)))
Expand Down Expand Up @@ -431,12 +431,11 @@ holidays in HOLIDAY-LIST."
;;; User commands.

;;;###cal-autoload
(defun cal-html-cursor-month (month year dir &optional event)
(defun cal-html-cursor-month (month year dir &optional _event)
"Write an HTML calendar file for numeric MONTH of four-digit YEAR.
The output directory DIR is created if necessary. Interactively,
MONTH and YEAR are taken from the calendar cursor position, or from
the position specified by EVENT. Note that any existing output files
are overwritten."
MONTH and YEAR are taken from the calendar cursor position.
Note that any existing output files are overwritten."
(interactive (let* ((event last-nonmenu-event)
(date (calendar-cursor-to-date t event))
(month (calendar-extract-month date))
Expand All @@ -446,11 +445,11 @@ are overwritten."
(cal-html-one-month month year dir))

;;;###cal-autoload
(defun cal-html-cursor-year (year dir &optional event)
(defun cal-html-cursor-year (year dir &optional _event)
"Write HTML calendar files (index and monthly pages) for four-digit YEAR.
The output directory DIR is created if necessary. Interactively,
YEAR is taken from the calendar cursor position, or from the position
specified by EVENT. Note that any existing output files are overwritten."
YEAR is taken from the calendar cursor position.
Note that any existing output files are overwritten."
(interactive (let* ((event last-nonmenu-event)
(year (calendar-extract-year
(calendar-cursor-to-date t event))))
Expand Down
6 changes: 3 additions & 3 deletions lisp/calendar/cal-islam.el
@@ -1,4 +1,4 @@
;;; cal-islam.el --- calendar functions for the Islamic calendar
;;; cal-islam.el --- calendar functions for the Islamic calendar -*- lexical-binding: t; -*-

;; Copyright (C) 1995, 1997, 2001-2021 Free Software Foundation, Inc.

Expand Down Expand Up @@ -67,8 +67,8 @@
"Absolute date of Islamic DATE.
The absolute date is the number of days elapsed since the (imaginary)
Gregorian date Sunday, December 31, 1 BC."
(let* ((month (calendar-extract-month date))
(day (calendar-extract-day date))
(let* (;;(month (calendar-extract-month date))
;;(day (calendar-extract-day date))
(year (calendar-extract-year date))
(y (% year 30))
(leap-years-in-cycle (cond ((< y 3) 0)
Expand Down
2 changes: 1 addition & 1 deletion lisp/calendar/cal-iso.el
@@ -1,4 +1,4 @@
;;; cal-iso.el --- calendar functions for the ISO calendar
;;; cal-iso.el --- calendar functions for the ISO calendar -*- lexical-binding: t; -*-

;; Copyright (C) 1995, 1997, 2001-2021 Free Software Foundation, Inc.

Expand Down
2 changes: 1 addition & 1 deletion lisp/calendar/cal-mayan.el
@@ -1,4 +1,4 @@
;;; cal-mayan.el --- calendar functions for the Mayan calendars
;;; cal-mayan.el --- calendar functions for the Mayan calendars -*- lexical-binding: t; -*-

;; Copyright (C) 1992-1993, 1995, 1997, 2001-2021 Free Software
;; Foundation, Inc.
Expand Down
4 changes: 3 additions & 1 deletion lisp/calendar/cal-menu.el
@@ -1,4 +1,4 @@
;;; cal-menu.el --- calendar functions for menu bar and popup menu support
;;; cal-menu.el --- calendar functions for menu bar and popup menu support -*- lexical-binding: t; -*-

;; Copyright (C) 1994-1995, 2001-2021 Free Software Foundation, Inc.

Expand Down Expand Up @@ -183,6 +183,8 @@ Signals an error if popups are unavailable."
;; Autoloaded in diary-lib.
(declare-function calendar-check-holidays "holidays" (date))

(defvar diary-list-include-blanks)

(defun calendar-mouse-view-diary-entries (&optional date diary event)
"Pop up menu of diary entries for mouse-selected date.
Use optional DATE and alternative file DIARY. EVENT is the event
Expand Down
2 changes: 1 addition & 1 deletion lisp/calendar/cal-move.el
@@ -1,4 +1,4 @@
;;; cal-move.el --- calendar functions for movement in the calendar
;;; cal-move.el --- calendar functions for movement in the calendar -*- lexical-binding: t; -*-

;; Copyright (C) 1995, 2001-2021 Free Software Foundation, Inc.

Expand Down
9 changes: 5 additions & 4 deletions lisp/calendar/cal-persia.el
@@ -1,4 +1,4 @@
;;; cal-persia.el --- calendar functions for the Persian calendar
;;; cal-persia.el --- calendar functions for the Persian calendar -*- lexical-binding: t; -*-

;; Copyright (C) 1996-1997, 2001-2021 Free Software Foundation, Inc.

Expand Down Expand Up @@ -139,13 +139,14 @@ Gregorian date Sunday, December 31, 1 BC."
(calendar-absolute-from-gregorian
(or date (calendar-current-date)))))
(y (calendar-extract-year persian-date))
(m (calendar-extract-month persian-date))
(monthname (aref calendar-persian-month-name-array (1- m)))
(m (calendar-extract-month persian-date)))
(calendar-dlet*
((monthname (aref calendar-persian-month-name-array (1- m)))
(day (number-to-string (calendar-extract-day persian-date)))
(year (number-to-string y))
(month (number-to-string m))
dayname)
(mapconcat 'eval calendar-date-display-form "")))
(mapconcat #'eval calendar-date-display-form ""))))

;;;###cal-autoload
(defun calendar-persian-print-date ()
Expand Down

0 comments on commit bacc24b

Please sign in to comment.