diff options
| author | Glenn Morris | 2009-08-22 19:45:30 +0000 |
|---|---|---|
| committer | Glenn Morris | 2009-08-22 19:45:30 +0000 |
| commit | b4deec2e852119c77df0803bb08f00f5d1637c28 (patch) | |
| tree | 09c88f79ef1823381c59d8bfbe3a33d61c66eb2b | |
| parent | 880be50e880dec91b92ca86f25461ca77291c979 (diff) | |
| download | emacs-b4deec2e852119c77df0803bb08f00f5d1637c28.tar.gz emacs-b4deec2e852119c77df0803bb08f00f5d1637c28.zip | |
(lunar-phase-names): New option.
(lunar-phase): Doc fix.
(lunar-cycles-per-year): New constant.
(lunar-index): New function.
(lunar-phase-list, diary-lunar-phases): Use lunar-index.
(lunar-phase-name): Use lunar-phase-names.
(calendar-lunar-phases): Use format.
(lunar-new-moon-on-or-after): Use lunar-cycles-per-year.
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/calendar/lunar.el | 84 |
2 files changed, 54 insertions, 39 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 22ec1f69ff3..ce2c1463b29 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,14 @@ | |||
| 1 | 2009-08-22 Glenn Morris <rgm@gnu.org> | 1 | 2009-08-22 Glenn Morris <rgm@gnu.org> |
| 2 | 2 | ||
| 3 | * calendar/lunar.el (lunar-phase-names): New option. | ||
| 4 | (lunar-phase): Doc fix. | ||
| 5 | (lunar-cycles-per-year): New constant. | ||
| 6 | (lunar-index): New function. | ||
| 7 | (lunar-phase-list, diary-lunar-phases): Use lunar-index. | ||
| 8 | (lunar-phase-name): Use lunar-phase-names. | ||
| 9 | (calendar-lunar-phases): Use format. | ||
| 10 | (lunar-new-moon-on-or-after): Use lunar-cycles-per-year. | ||
| 11 | |||
| 3 | * progmodes/cperl-mode.el (cperl-imenu-name-and-position): | 12 | * progmodes/cperl-mode.el (cperl-imenu-name-and-position): |
| 4 | Copy imenu-example--name-and-position function here for own use. | 13 | Copy imenu-example--name-and-position function here for own use. |
| 5 | (cperl-xsub-scan): Use cperl-imenu-name-and-position. | 14 | (cperl-xsub-scan): Use cperl-imenu-name-and-position. |
diff --git a/lisp/calendar/lunar.el b/lisp/calendar/lunar.el index 1e779452886..1b5cd36b23c 100644 --- a/lisp/calendar/lunar.el +++ b/lisp/calendar/lunar.el | |||
| @@ -44,17 +44,28 @@ | |||
| 44 | ;; calendar-astro-to-absolute and v versa are cal-autoloads. | 44 | ;; calendar-astro-to-absolute and v versa are cal-autoloads. |
| 45 | ;;;(require 'cal-julian) | 45 | ;;;(require 'cal-julian) |
| 46 | 46 | ||
| 47 | (defcustom lunar-phase-names | ||
| 48 | '("New Moon" "First Quarter Moon" "Full Moon" "Last Quarter Moon") | ||
| 49 | "List of names for the lunar phases." | ||
| 50 | :type '(list | ||
| 51 | (string :tag "New Moon") | ||
| 52 | (string :tag "First Quarter Moon") | ||
| 53 | (string :tag "Full Moon") | ||
| 54 | (string :tag "Last Quarter Moon")) | ||
| 55 | :group 'calendar | ||
| 56 | :version "23.2") | ||
| 57 | |||
| 47 | (defun lunar-phase (index) | 58 | (defun lunar-phase (index) |
| 48 | "Local date and time of lunar phase INDEX. | 59 | "Local date and time of lunar phase INDEX. |
| 49 | Integer below INDEX/4 gives the lunation number, counting from Jan 1, 1900; | 60 | Integer below INDEX/4 gives the lunation number, counting from Jan 1, 1900; |
| 50 | remainder mod 4 gives the phase: 0 new moon, 1 first quarter, 2 full moon, | 61 | remainder mod 4 gives the phase: 0 new moon, 1 first quarter, 2 full moon, |
| 51 | 3 last quarter." | 62 | 3 last quarter. Returns a list (DATE TIME PHASE)." |
| 52 | (let* ((phase (mod index 4)) | 63 | (let* ((phase (mod index 4)) |
| 53 | (index (/ index 4.0)) | 64 | (index (/ index 4.0)) |
| 54 | (time (/ index 1236.85)) | 65 | (time (/ index 1236.85)) |
| 55 | (date (+ (calendar-absolute-from-gregorian '(1 0.5 1900)) | 66 | (date (+ (calendar-absolute-from-gregorian '(1 0.5 1900)) |
| 56 | 0.75933 | 67 | 0.75933 |
| 57 | (* 29.53058868 index) | 68 | (* 29.53058868 index) ; FIXME 29.530588853? |
| 58 | (* 0.0001178 time time) | 69 | (* 0.0001178 time time) |
| 59 | (* -0.000000155 time time time) | 70 | (* -0.000000155 time time time) |
| 60 | (* 0.00033 | 71 | (* 0.00033 |
| @@ -136,28 +147,37 @@ remainder mod 4 gives the phase: 0 new moon, 1 first quarter, 2 full moon, | |||
| 136 | (adj (dst-adjust-time date time))) | 147 | (adj (dst-adjust-time date time))) |
| 137 | (list (car adj) (apply 'solar-time-string (cdr adj)) phase))) | 148 | (list (car adj) (apply 'solar-time-string (cdr adj)) phase))) |
| 138 | 149 | ||
| 150 | (defconst lunar-cycles-per-year 12.3685 ; 365.25/29.530588853 | ||
| 151 | "Mean number of lunar cycles per 365.25 day year.") | ||
| 152 | |||
| 153 | ;; FIXME new-moon index; use in lunar-phase-list implies always below. | ||
| 154 | (defun lunar-index (date) | ||
| 155 | "Return the lunar index for Gregorian date DATE. | ||
| 156 | This is 4 times the approximate number of new moons since 1 Jan 1900. | ||
| 157 | The factor of 4 allows (mod INDEX 4) to represent the four quarters." | ||
| 158 | (* 4 (truncate | ||
| 159 | (* lunar-cycles-per-year | ||
| 160 | ;; Years since 1900, as a real. | ||
| 161 | (+ (calendar-extract-year date) | ||
| 162 | (/ (calendar-day-number date) 366.0) | ||
| 163 | -1900))))) | ||
| 164 | |||
| 139 | (defun lunar-phase-list (month year) | 165 | (defun lunar-phase-list (month year) |
| 140 | "List of lunar phases for three months starting with Gregorian MONTH, YEAR." | 166 | "List of lunar phases for three months starting with Gregorian MONTH, YEAR." |
| 141 | (let* ((end-month month) | 167 | (let* ((index (lunar-index (list month 1 year))) |
| 142 | (end-year year) | 168 | (new-moon (lunar-phase index)) |
| 143 | (start-month month) | 169 | (end-date (let ((end-month month) |
| 144 | (start-year year) | 170 | (end-year year)) |
| 145 | (end-date (progn | ||
| 146 | (calendar-increment-month end-month end-year 3) | 171 | (calendar-increment-month end-month end-year 3) |
| 147 | (list (list end-month 1 end-year)))) | 172 | (list (list end-month 1 end-year)))) |
| 173 | ;; Alternative for start-date: | ||
| 174 | ;;; (calendar-gregorian-from-absolute | ||
| 175 | ;;; (1- (calendar-absolute-from-gregorian (list month 1 year)))) | ||
| 148 | (start-date (progn | 176 | (start-date (progn |
| 149 | (calendar-increment-month start-month start-year -1) | 177 | (calendar-increment-month month year -1) |
| 150 | (list (list start-month | 178 | (list (list month |
| 151 | (calendar-last-day-of-month | 179 | (calendar-last-day-of-month month year) |
| 152 | start-month start-year) | 180 | year)))) |
| 153 | start-year)))) | ||
| 154 | (index (* 4 (truncate | ||
| 155 | (* 12.3685 | ||
| 156 | (+ year | ||
| 157 | ( / (calendar-day-number (list month 1 year)) | ||
| 158 | 366.0) | ||
| 159 | -1900))))) | ||
| 160 | (new-moon (lunar-phase index)) | ||
| 161 | list) | 181 | list) |
| 162 | (while (calendar-date-compare new-moon end-date) | 182 | (while (calendar-date-compare new-moon end-date) |
| 163 | (if (calendar-date-compare start-date new-moon) | 183 | (if (calendar-date-compare start-date new-moon) |
| @@ -169,10 +189,7 @@ remainder mod 4 gives the phase: 0 new moon, 1 first quarter, 2 full moon, | |||
| 169 | (defun lunar-phase-name (phase) | 189 | (defun lunar-phase-name (phase) |
| 170 | "Name of lunar PHASE. | 190 | "Name of lunar PHASE. |
| 171 | 0 = new moon, 1 = first quarter, 2 = full moon, 3 = last quarter." | 191 | 0 = new moon, 1 = first quarter, 2 = full moon, 3 = last quarter." |
| 172 | (cond ((= 0 phase) "New Moon") | 192 | (nth phase lunar-phase-names)) |
| 173 | ((= 1 phase) "First Quarter Moon") | ||
| 174 | ((= 2 phase) "Full Moon") | ||
| 175 | ((= 3 phase) "Last Quarter Moon"))) | ||
| 176 | 193 | ||
| 177 | (defvar displayed-month) ; from calendar-generate | 194 | (defvar displayed-month) ; from calendar-generate |
| 178 | (defvar displayed-year) | 195 | (defvar displayed-year) |
| @@ -204,14 +221,9 @@ use instead of point." | |||
| 204 | (insert | 221 | (insert |
| 205 | (mapconcat | 222 | (mapconcat |
| 206 | (lambda (x) | 223 | (lambda (x) |
| 207 | (let ((date (car x)) | 224 | (format "%s: %s %s" (calendar-date-string (car x)) |
| 208 | (time (cadr x)) | 225 | (lunar-phase-name (nth 2 x)) |
| 209 | (phase (nth 2 x))) | 226 | (cadr x))) |
| 210 | (concat (calendar-date-string date) | ||
| 211 | ": " | ||
| 212 | (lunar-phase-name phase) | ||
| 213 | " " | ||
| 214 | time))) | ||
| 215 | (lunar-phase-list m1 y1) "\n"))) | 227 | (lunar-phase-list m1 y1) "\n"))) |
| 216 | (message "Computing phases of the moon...done")))) | 228 | (message "Computing phases of the moon...done")))) |
| 217 | 229 | ||
| @@ -244,13 +256,7 @@ This function is suitable for execution in a .emacs file." | |||
| 244 | "Moon phases diary entry. | 256 | "Moon phases diary entry. |
| 245 | An optional parameter MARK specifies a face or single-character string to | 257 | An optional parameter MARK specifies a face or single-character string to |
| 246 | use when highlighting the day in the calendar." | 258 | use when highlighting the day in the calendar." |
| 247 | (let* ((index (* 4 | 259 | (let* ((index (lunar-index date)) |
| 248 | (truncate | ||
| 249 | (* 12.3685 | ||
| 250 | (+ (calendar-extract-year date) | ||
| 251 | ( / (calendar-day-number date) | ||
| 252 | 366.0) | ||
| 253 | -1900))))) | ||
| 254 | (phase (lunar-phase index))) | 260 | (phase (lunar-phase index))) |
| 255 | (while (calendar-date-compare phase (list date)) | 261 | (while (calendar-date-compare phase (list date)) |
| 256 | (setq index (1+ index) | 262 | (setq index (1+ index) |
| @@ -385,7 +391,7 @@ as governed by the values of `calendar-daylight-savings-starts', | |||
| 385 | (floor (calendar-astro-to-absolute d)))) | 391 | (floor (calendar-astro-to-absolute d)))) |
| 386 | (year (+ (calendar-extract-year date) | 392 | (year (+ (calendar-extract-year date) |
| 387 | (/ (calendar-day-number date) 365.25))) | 393 | (/ (calendar-day-number date) 365.25))) |
| 388 | (k (floor (* (- year 2000.0) 12.3685))) | 394 | (k (floor (* (- year 2000.0) lunar-cycles-per-year))) |
| 389 | (date (lunar-new-moon-time k)) | 395 | (date (lunar-new-moon-time k)) |
| 390 | (a-date (progn | 396 | (a-date (progn |
| 391 | (while (< date d) | 397 | (while (< date d) |