将光标移动到Emacs中12个月轮换日历的日期的算法 [英] Algorithms for moving the cursor to a date on a 12 month rotating calendar in Emacs

查看:109
本文介绍了将光标移动到Emacs中12个月轮换日历的日期的算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:此线程的目标是创建两(2)个数学公式,以在函数 lawlist-calendar-cursor中的@lawlist替换长方法-to-visible-date (下)。



故障问题



现在,Emacs中存在一个12个月的日历,一个月内(或更多)向前和向后滚动。功能 lawlist-calendar-cursor-to-visible-date 用于标记指定事件(例如生日,假期,约会等)的覆盖的日期;或者,将光标简单地移动到特定的日期。 @lawlist已经设计了一个长期的解决方案,它并不完全使用数学方程来计算显示的每一天365天的光标位置。可能需要创建两个简洁的算法来代替长期解决方案。



12个月滚动日历的工作草案( 可以在这里找到:



https://stackoverflow.com/a/21409154/2112489



LEGEND



显示月份(数字1到12)是出现在缓冲区左上角的月份,它会随着12每月日历向前或向后滚动。



目标月份(数字1到12)是月份我们需要在两个数学公式的帮助下找到,它的位置取决于标记的日期(例如,生日,假期,约会),并且取决于显示月份在缓冲区的左上角。目标可以是12个可能的位置中的任何一个。轴坐标(即 6 31 56 < /强>)。有四(4)个可能的 y 轴坐标(即 0 9 18 27 )。 [引用x / y坐标: http://www.mathsisfun.com/data/ cartesian-coordinates.html ]



的水平定义为3个月。 >

一个被定义为垂直的4个月。



第一个论坛必须等于 0 9 18 27 ,具体取决于该点是否在 1,2,3或4 - 即从上到下。



第二个论坛必须等于 6 31 56 ,具体取决于该点在 1,2或3 - - 即从左到右。



示例




  • 如果显示月份是1月(即1),目标月份是8月(即8),则等于 18 等于 31


  • 显示月份是二月(即2),目标是八月(即8) code>行等于 18 等于 6 。 >


  • 如果显示月份是3月(即3),目标 / code>是八月(即8),然后等于 9 等于 56


  • 如果显示月份是四月(即4)和目标是八月(即8),然后等于 9 等于 31


  • 如果显示月份是May(即5),目标 month 是八月(即8),然后等于 9 等于 6

    li>


12个月的日历如下所示:布局一次滚动一个月:

  ;; 1 2 3 
;; 4 5 6
;; 7 8 9
;; 10 11 12

;; 2 3 4
;; 5 6 7
;; 8 9 10
;; 11 12 1

;; 3 4 5
;; 6 7 8
;; 9 10 11
;; 12 1 2

;; 4 5 6
;; 7 8 9
;; 10 11 12
;; 1 2 3

;; 5 6 7
;; 8 9 10
;; 11 12 1
;; 2 3 4

;; 6 7 8
;; 9 10 11
;; 12 1 2
;; 3 4 5

;; 7 8 9
;; 10 11 12
;; 1 2 3
;; 4 5 6

;; 8 9 10
;; 11 12 1
;; 2 3 4
;; 5 6 7

;; 9 10 11
;; 12 1 2
;; 3 4 5
;; 6 7 8

;; 10 11 12
;; 1 2 3
;; 4 5 6
;; 7 8 9

;; 11 12 1
;; 2 3 4
;; 5 6 7
;; 8 9 10

;; 12 1 2
;; 3 4 5
;; 6 7 8
;; 9 10 11

@lawlist的长手解决方案如下:

 (defun lawlist-calendar-cursor-to-visible-date(date)
将光标移动到屏幕上的DATE。
(let(
(month(calendar-extract-month date))
(day(日历提取日期))
(year(calendar-extract-年份日))
(月初 - 周日(日历 - 周日(列表1年))))
(goto-line
(+ 3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(cond
;; 1 2 3
;; 4 5 6
;; 7 8 9
;; 10 11 12
((和
(eq显示月份1)
(memq月`(1 2 3)))
0)
((和
(eq显示月1)
(memq月`(4 5 6)))
9)
(和
(eq显示月份1)
(memq month`(7 8 9)))
18)
((和
(eq显示月份1)
(memq month`(10 11 12)))
27)
;; 2 3 4
;; 5 6 7
;; 8 9 10
;; 11 12 1
((和
(eq显示月份2)
(memq月`(2 3 4)))
0)
((和
(eq显示月份2)
(memq月`(5 6 7)))
9)
((和
(eq显示月份2)
(memq month`(8 9 10)))
18)
((和
(eq显示月份2)
(memq month`(11 12 1 )))
27)
;; 3 4 5
;; 6 7 8
;; 9 10 11
;; 12 1 2
((和
(eq显示月份3)
(memq月`(3 4 5)))
0)
((和
(eq显示月份3)
(memq month`(6 7 8)))
9)
((和
(eq显示月份3)
(memq month`(9 10 11)))
18)
((和
(eq显示月份3)
(memq month`(12 1 2 )))
27)
;; 4 5 6
;; 7 8 9
;; 10 11 12
;; 1 2 3
((和
(eq显示月份4)
(memq月`(4 5 6)))
0)
((和
(eq显示月份4)
(memq month`(7 8 9)))
9)
((和
(eq显示月份4)
(memq month`(10 11 12)))
18)
((和
(eq显示月份4)
(memq month`(1 2 3 )))
27)
;; 5 6 7
;; 8 9 10
;; 11 12 1
;; 2 3 4
((和
(eq显示月份5)
(memq月`(5 6 7)))
0)
((和
(eq显示月份5)
(memq month`(8 9 10)))
9)
((和
(eq显示月份5)
(memq month`(11 12 1)))
18)
((和
(eq显示月份5)
(memq month`(2 3 4 )))
27)
;; 6 7 8
;; 9 10 11
;; 12 1 2
;; 3 4 5
((和
(eq显示月份6)
(memq月`(6 7 8)))
0)
((和
(eq显示月份6)
(memq month`(9 10 11)))
9)
((和
(eq显示月份6)
(memq month`(12 1 2)))
18)
((和
(eq显示月份6)
(memq月`(3 4 5 )))
27)
;; 7 8 9
;; 10 11 12
;; 1 2 3
;; 4 5 6
((和
(eq显示月份7)
(memq月`(7 8 9)))
0)
((和
(eq显示月份7)
(memq month`(10 11 12)))
9)
((和
(eq显示月份7)
(memq month`(1 2 3)))
18)
((和
(eq显示月份7)
(memq月`(4 5 6 )))
27)
;; 8 9 10
;; 11 12 1
;; 2 3 4
;; 5 6 7
((和
(eq显示月份8)
(memq月`(8 9 10)))
0)
((和
(eq显示月份8)
(memq月`(11 12 1)))
9)
((和
(eq显示月份8)
(memq month`(2 3 4)))
18)
((和
(eq显示月份8)
(memq month`(5 6 7 )))
27)
;; 9 10 11
;; 12 1 2
;; 3 4 5
;; 6 7 8
((和
(eq显示月9)
(memq月`(9 10 11)))
0)
((和
(eq显示月份9)
(memq month`(12 1 2)))
9)
((和
(eq显示月份9)
(memq month`(3 4 5)))
18)
((和
(eq显示月份9)
(memq月`(6 7 8 )))
27)
;; 10 11 12
;; 1 2 3
;; 4 5 6
;; 7 8 9
((和
(eq显示月份10)
(memq月`(10 11 12)))
0)
((和
(eq显示月份10)
(memq month`(1 2 3)))
9)
((和
(eq显示月份10)
(memq month`(4 5 6)))
18)
((和
(eq显示月份10)
(memq month`(7 8 9 )))
27)
;; 11 12 1
;; 2 3 4
;; 5 6 7
;; 8 9 10
((和
(eq显示月份11)
(memq月`(11 12 1)))
0)
((和
(eq显示月份11)
(memq月`(2 3 4)))
9)
((和
(eq显示月份11)
(memq month`(5 6 7)))
18)
((和
(eq显示月份11)
(memq month`(8 9 10 )))
27)
;; 12 1 2
;; 3 4 5
;; 6 7 8
;; 9 10 11
((和
(eq显示月份12)
(memq月`(12 1 2)))
0)
((和
(eq显示月份12)
(memq月`(3 4 5)))
9)
((和
(eq显示月份12)
(memq month`(6 7 8)))
18)
((和
(eq显示月份12)
(memq month`(9 10 11 )))
27))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(/(+ day -1
(mod
( - (日历 - 周一(列表1年))日历 - 周 - 开始日)
7))
7)))
(move-to-column
(+
;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;
(cond
;; 1 2 3
;; 4 5 6
;; 7 8 9
;; 10 11 12
((和
(eq显示月份1)
(memq月`(1 4 7 10)))
6)
((和
-month 1)
(memq month`(2 5 8 11)))
31)
((和
(eq显示月份1)
(memq月(3 6 9 12)))
56)
;; 2 3 4
;; 5 6 7
;; 8 9 10
;; 11 12 1
((和
(eq显示月份2)
(memq month`(2 5 8 11)))
6)
((和
(eq显示月份2)
(memq月`(3 6 9 12) )
31)
((和
(eq显示月份2)
(memq月`(4 7 10 1)))
56)
;; 3 4 5
;; 6 7 8
;; 9 10 11
;; 12 1 2
((和
(eq显示月份3)
(memq月`(3 6 9 12)))
6)
((和
(eq显示月份3)
(memq month`(4 7 10 1)))
31)
((和
(eq显示月份3 )
(memq month`(5 8 11 2)))
56)
;; 4 5 6
;; 7 8 9
;; 10 11 12
;; 1 2 3
((和
(eq显示月份4)
(memq月`(4 7 10 1)))
6)
((和
(eq显示月份4)
(memq month`(5 8 11 2)))
31)
((和
(eq显示月份4 )
(memq month`(6 9 12 3)))
56)
;; 5 6 7
;; 8 9 10
;; 11 12 1
;; 2 3 4
((和
(eq显示月份5)
(memq月`(5 8 11 2)))
6)
((和
(eq显示月份5)
(memq month`(6 9 12 3)))
31)
((和
(eq显示月份5 )
(memq month`(7 10 1 4)))
56)
;; 6 7 8
;; 9 10 11
;; 12 1 2
;; 3 4 5
((和
(eq显示月份6)
(memq月`(6 9 12 3)))
6)
((和
(eq显示月份6)
(memq month`(7 10 1 4)))
31)
((和
(eq显示月份6 )
(memq month`(8 11 2 5)))
56)
;; 7 8 9
;; 10 11 12
;; 1 2 3
;; 4 5 6
((和
(eq显示月份7)
(memq月`(7 10 1 4)))
6)
((和
(eq显示月份7)
(memq month`(8 11 2 5)))
31)
((和
(eq显示月份7 )
(memq month`(9 12 3 6)))
56)
;; 8 9 10
;; 11 12 1
;; 2 3 4
;; 5 6 7
((和
(eq显示月份8)
(memq月`(8 11 2 5)))
6)
((和
(eq display-month 8)
(memq month`(9 12 3 6)))
31)
((和

(memq month`(10 1 4 7)))
56)
;; 9 10 11
;; 12 1 2
;; 3 4 5
;; 6 7 8
((和
(eq显示月份9)
(memq月`(9 12 3 6)))
6)
((和
(eq显示月份9)
(memq month`(10 1 4 7)))
31)
((和
(eq显示月份9 )
(memq month`(11 2 5 8)))
56)
;; 10 11 12
;; 1 2 3
;; 4 5 6
;; 7 8 9
((和
(eq显示月份10)
(memq月`(10 1 4 7)))
6)
((和
(eq显示月份10)
(memq月`(11 2 5 8)))
31)
((和
(eq显示月10 )
(memq month`(12 3 6 9)))
56)
;; 11 12 1
;; 2 3 4
;; 5 6 7
;; 8 9 10
((和
(eq显示月份11)
(memq月`(11 2 5 8)))
6)
((和
(eq显示月份11)
(memq month`(12 3 6 9)))
31)
((和
(eq显示月份11 )
(memq month`(1 4 7 10)))
56)
;; 12 1 2
;; 3 4 5
;; 6 7 8
;; 9 10 11
((和
(eq显示月份12)
(memq月`(12 3 6 9)))
6)
((和
(eq显示月份12)
(memq month`(1 4 7 10)))
31)
((和
(eq显示月份12 )
(memq month`(2 5 8 11)))
56))
;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;
(* 3(mod
( - (日历 - 星期几)日历 - 周 - 开始日)
7))))))


解决方案

我必须缺少一些东西,因为它的公式很简单(伪代码):

  first = 9 *(rows  -  1)
second = 6 + 25 *(cols - 1)

根据您的编辑,您可以计算行和列移动:

 如果target>显示
差异=目标 - 显示
其他
差异= 12 +目标 - 显示
行=差异/ 3
cols =差异%3
rowmove = 9 *行
colmove = 6 + 25 * cols

然后使用上面的公式。



我尝试elisp:

 (让差异(if > =目标月份显示月份)
( - 目标月份显示月份)
( - (+ target-month 12)显示月份)))
(let rows /差3))
(let cols(%difference 3))
(let rowmove(* 9 rows))
(let colmove(+ 6(* 25 cols)))


GOAL:  The goal of this thread is to create two (2) mathematical formulas to replace the long-hand solution by @lawlist in the function lawlist-calendar-cursor-to-visible-date (below).

                                                            STORY PROBLEM

There now exists a 12-month calendar in Emacs that scrolls forwards and backwards one month (or more) at a time. The function lawlist-calendar-cursor-to-visible-date is used to mark dates with overlays for designated events (e.g., birthdays, holidays, appointments, etc.); or, to simply move the cursor to a particular date. @lawlist has devised a solution by long-hand, which does not entirely use mathematical equations to calculate the cursor position for each of the 365 days that are displayed. It may be possible to create two (2) concise algorithms to replace the long-hand solution.

A working draft of the 12-month scrolling calendar (without the long-hand solution) may be found here:

     https://stackoverflow.com/a/21409154/2112489

LEGEND:

displayed-month (numbers 1 through 12) is the month that appears in the upper left-hand corner of the buffer, and this changes as the 12-month calendar is scrolled forwards or backwards.

The target month (numbers 1 through 12) is the month that we need to locate with assistance from the two mathematical formulas -- its location varies depending upon the date being marked (e.g., birthday, holiday, appointment), and depending upon the displayed-month in the upper left-hand corner of the buffer. The target month can be in any one of 12 possible positions. There are three (3) possible x axis coordinates (i.e., 6, 31, or 56). There are four (4) possible y axis coordinates (i.e., 0, 9, 18 or 27). [Citation to x / y coordinates: http://www.mathsisfun.com/data/cartesian-coordinates.html ]

A row is defined as 3 months horizontally.

A column is defined as 4 months vertically.

The first forumula must equal 0, 9, 18 or 27 depending upon whether the point is on row 1, 2, 3 or 4 -- i.e., from top to bottom.

The second forumula must equal 6, 31, or 56 depending upon whether the point is on column 1, 2 or 3 -- i.e., from left to right.

EXAMPLE:

  • If displayed-month is January (i.e., 1) and the target month is August (i.e., 8), then row equals 18 and column equals 31.

  • If displayed-month is February (i.e., 2) and the target month is August (i.e., 8), then row equals 18 and column equals 6.

  • If displayed-month is March (i.e., 3) and the target month is August (i.e., 8), then row equals 9 and column equals 56.

  • If displayed-month is April (i.e., 4) and target month is August (i.e., 8), then row equals 9 and column equals 31.

  • If displayed-month is May (i.e., 5) and the target month is August (i.e., 8), then row equals 9 and column equals 6.

The 12-month calendar looks like the following as the layout scrolls forward one month at a time:

;;  1 2 3
;;  4 5 6
;;  7 8 9
;;  10 11 12

;;  2 3 4
;;  5 6 7
;;  8 9 10
;;  11 12 1

;;  3 4 5
;;  6 7 8
;;  9 10 11
;;  12 1 2

;;  4 5 6
;;  7 8 9
;;  10 11 12
;;  1 2 3

;;  5 6 7
;;  8 9 10
;;  11 12 1
;;  2 3 4

;;  6 7 8
;;  9 10 11
;;  12 1 2
;;  3 4 5

;;  7 8 9
;;  10 11 12
;;  1 2 3
;;  4 5 6

;;  8 9 10
;;  11 12 1
;;  2 3 4
;;  5 6 7

;;  9 10 11
;;  12 1 2
;;  3 4 5
;;  6 7 8

;;  10 11 12
;;  1 2 3
;;  4 5 6
;;  7 8 9

;;  11 12 1
;;  2 3 4
;;  5 6 7
;;  8 9 10

;;  12 1 2
;;  3 4 5
;;  6 7 8
;;  9 10 11

The long-hand solution by @lawlist is as follows:

(defun lawlist-calendar-cursor-to-visible-date (date)
  "Move the cursor to DATE that is on the screen."
  (let* (
      (month (calendar-extract-month date))
      (day (calendar-extract-day date))
      (year (calendar-extract-year date))
      (first-of-month-weekday (calendar-day-of-week (list month 1 year))))
    (goto-line
      (+ 3
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        (cond
          ;;  1 2 3
          ;;  4 5 6
          ;;  7 8 9
          ;;  10 11 12
          ((and
              (eq displayed-month 1)
              (memq month `(1 2 3)))
            0)
          ((and
              (eq displayed-month 1)
              (memq month `(4 5 6)))
            9)
          ((and
              (eq displayed-month 1)
              (memq month `(7 8 9)))
            18)
          ((and
              (eq displayed-month 1)
              (memq month `(10 11 12)))
            27)
          ;;  2 3 4
          ;;  5 6 7
          ;;  8 9 10
          ;;  11 12 1
          ((and
              (eq displayed-month 2)
              (memq month `(2 3 4)))
            0)
          ((and
              (eq displayed-month 2)
              (memq month `(5 6 7)))
            9)
          ((and
              (eq displayed-month 2)
              (memq month `(8 9 10)))
            18)
          ((and
              (eq displayed-month 2)
              (memq month `(11 12 1)))
            27)
          ;;  3 4 5
          ;;  6 7 8
          ;;  9 10 11
          ;;  12 1 2
          ((and
              (eq displayed-month 3)
              (memq month `(3 4 5)))
            0)
          ((and
              (eq displayed-month 3)
              (memq month `(6 7 8)))
            9)
          ((and
              (eq displayed-month 3)
              (memq month `(9 10 11)))
            18)
          ((and
              (eq displayed-month 3)
              (memq month `(12 1 2)))
            27)
          ;;  4 5 6
          ;;  7 8 9
          ;;  10 11 12
          ;;  1 2 3
          ((and
              (eq displayed-month 4)
              (memq month `(4 5 6)))
            0)
          ((and
              (eq displayed-month 4)
              (memq month `(7 8 9)))
            9)
          ((and
              (eq displayed-month 4)
              (memq month `(10 11 12)))
            18)
          ((and
              (eq displayed-month 4)
              (memq month `(1 2 3)))
            27)
          ;;  5 6 7
          ;;  8 9 10
          ;;  11 12 1
          ;;  2 3 4
          ((and
              (eq displayed-month 5)
              (memq month `(5 6 7)))
            0)
          ((and
              (eq displayed-month 5)
              (memq month `(8 9 10)))
            9)
          ((and
              (eq displayed-month 5)
              (memq month `(11 12 1)))
            18)
          ((and
              (eq displayed-month 5)
              (memq month `(2 3 4)))
            27)
          ;;  6 7 8
          ;;  9 10 11
          ;;  12 1 2
          ;;  3 4 5
          ((and
              (eq displayed-month 6)
              (memq month `(6 7 8)))
            0)
          ((and
              (eq displayed-month 6)
              (memq month `(9 10 11)))
            9)
          ((and
              (eq displayed-month 6)
              (memq month `(12 1 2)))
            18)
          ((and
              (eq displayed-month 6)
              (memq month `(3 4 5)))
            27)
          ;;  7 8 9
          ;;  10 11 12
          ;;  1 2 3
          ;;  4 5 6
          ((and
              (eq displayed-month 7)
              (memq month `(7 8 9)))
            0)
          ((and
              (eq displayed-month 7)
              (memq month `(10 11 12)))
            9)
          ((and
              (eq displayed-month 7)
              (memq month `(1 2 3)))
            18)
          ((and
              (eq displayed-month 7)
              (memq month `(4 5 6)))
            27)
          ;;  8 9 10
          ;;  11 12 1
          ;;  2 3 4
          ;;  5 6 7
          ((and
              (eq displayed-month 8)
              (memq month `(8 9 10)))
            0)
          ((and
              (eq displayed-month 8)
              (memq month `(11 12 1)))
            9)
          ((and
              (eq displayed-month 8)
              (memq month `(2 3 4)))
            18)
          ((and
              (eq displayed-month 8)
              (memq month `(5 6 7)))
            27)
          ;;  9 10 11
          ;;  12 1 2
          ;;  3 4 5
          ;;  6 7 8
          ((and
              (eq displayed-month 9)
              (memq month `(9 10 11)))
            0)
          ((and
              (eq displayed-month 9)
              (memq month `(12 1 2)))
            9)
          ((and
              (eq displayed-month 9)
              (memq month `(3 4 5)))
            18)
          ((and
              (eq displayed-month 9)
              (memq month `(6 7 8)))
            27)
          ;;  10 11 12
          ;;  1 2 3
          ;;  4 5 6
          ;;  7 8 9
          ((and
              (eq displayed-month 10)
              (memq month `(10 11 12)))
            0)
          ((and
              (eq displayed-month 10)
              (memq month `(1 2 3)))
            9)
          ((and
              (eq displayed-month 10)
              (memq month `(4 5 6)))
            18)
          ((and
              (eq displayed-month 10)
              (memq month `(7 8 9)))
            27)
          ;;  11 12 1
          ;;  2 3 4
          ;;  5 6 7
          ;;  8 9 10
          ((and
              (eq displayed-month 11)
              (memq month `(11 12 1)))
            0)
          ((and
              (eq displayed-month 11)
              (memq month `(2 3 4)))
            9)
          ((and
              (eq displayed-month 11)
              (memq month `(5 6 7)))
            18)
          ((and
              (eq displayed-month 11)
              (memq month `(8 9 10)))
            27)
          ;;  12 1 2
          ;;  3 4 5
          ;;  6 7 8
          ;;  9 10 11
          ((and
              (eq displayed-month 12)
              (memq month `(12 1 2)))
            0)
          ((and
              (eq displayed-month 12)
              (memq month `(3 4 5)))
            9)
          ((and
              (eq displayed-month 12)
              (memq month `(6 7 8)))
            18)
          ((and
              (eq displayed-month 12)
              (memq month `(9 10 11)))
            27) )
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
          (/ (+ day  -1
            (mod
              (- (calendar-day-of-week (list month 1 year)) calendar-week-start-day)
                7))
                  7)))
    (move-to-column
      (+ 
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        (cond
          ;;  1 2 3
          ;;  4 5 6
          ;;  7 8 9
          ;;  10 11 12
          ((and
              (eq displayed-month 1)
              (memq month `(1 4 7 10)))
            6)
          ((and
              (eq displayed-month 1)
              (memq month `(2 5 8 11)))
            31)
          ((and
              (eq displayed-month 1)
              (memq month `(3 6 9 12)))
            56)
          ;;  2 3 4
          ;;  5 6 7
          ;;  8 9 10
          ;;  11 12 1
          ((and
              (eq displayed-month 2)
              (memq month `(2 5 8 11)))
            6)
          ((and
              (eq displayed-month 2)
              (memq month `(3 6 9 12)))
            31)
          ((and
              (eq displayed-month 2)
              (memq month `(4 7 10 1)))
            56)
          ;;  3 4 5
          ;;  6 7 8
          ;;  9 10 11
          ;;  12 1 2
          ((and
              (eq displayed-month 3)
              (memq month `(3 6 9 12)))
            6)
          ((and
              (eq displayed-month 3)
              (memq month `(4 7 10 1)))
            31)
          ((and
              (eq displayed-month 3)
              (memq month `(5 8 11 2)))
            56)
          ;;  4 5 6
          ;;  7 8 9
          ;;  10 11 12
          ;;  1 2 3
          ((and
              (eq displayed-month 4)
              (memq month `(4 7 10 1)))
            6)
          ((and
              (eq displayed-month 4)
              (memq month `(5 8 11 2)))
            31)
          ((and
              (eq displayed-month 4)
              (memq month `(6 9 12 3)))
            56)
          ;;  5 6 7
          ;;  8 9 10
          ;;  11 12 1
          ;;  2 3 4
          ((and
              (eq displayed-month 5)
              (memq month `(5 8 11 2)))
            6)
          ((and
              (eq displayed-month 5)
              (memq month `(6 9 12 3)))
            31)
          ((and
              (eq displayed-month 5)
              (memq month `(7 10 1 4)))
            56)
          ;;  6 7 8
          ;;  9 10 11
          ;;  12 1 2
          ;;  3 4 5
          ((and
              (eq displayed-month 6)
              (memq month `(6 9 12 3)))
            6)
          ((and
              (eq displayed-month 6)
              (memq month `(7 10 1 4)))
            31)
          ((and
              (eq displayed-month 6)
              (memq month `(8 11 2 5)))
            56)
          ;;  7 8 9
          ;;  10 11 12
          ;;  1 2 3
          ;;  4 5 6
          ((and
              (eq displayed-month 7)
              (memq month `(7 10 1 4)))
            6)
          ((and
              (eq displayed-month 7)
              (memq month `(8 11 2 5)))
            31)
          ((and
              (eq displayed-month 7)
              (memq month `(9 12 3 6)))
            56)
          ;;  8 9 10
          ;;  11 12 1
          ;;  2 3 4
          ;;  5 6 7
          ((and
              (eq displayed-month 8)
              (memq month `(8 11 2 5)))
            6)
          ((and
              (eq displayed-month 8)
              (memq month `(9 12 3 6)))
            31)
          ((and
              (eq displayed-month 8)
              (memq month `(10 1 4 7)))
            56)
          ;;  9 10 11
          ;;  12 1 2
          ;;  3 4 5
          ;;  6 7 8
          ((and
              (eq displayed-month 9)
              (memq month `(9 12 3 6)))
            6)
          ((and
              (eq displayed-month 9)
              (memq month `(10 1 4 7)))
            31)
          ((and
              (eq displayed-month 9)
              (memq month `(11 2 5 8)))
            56)
          ;;  10 11 12
          ;;  1 2 3
          ;;  4 5 6
          ;;  7 8 9
          ((and
              (eq displayed-month 10)
              (memq month `(10 1 4 7)))
            6)
          ((and
              (eq displayed-month 10)
              (memq month `(11 2 5 8)))
            31)
          ((and
              (eq displayed-month 10)
              (memq month `(12 3 6 9)))
            56)
          ;;  11 12 1
          ;;  2 3 4
          ;;  5 6 7
          ;;  8 9 10
          ((and
              (eq displayed-month 11)
              (memq month `(11 2 5 8)))
            6)
          ((and
              (eq displayed-month 11)
              (memq month `(12 3 6 9)))
            31)
          ((and
              (eq displayed-month 11)
              (memq month `(1 4 7 10)))
            56)
          ;;  12 1 2
          ;;  3 4 5
          ;;  6 7 8
          ;;  9 10 11
          ((and
              (eq displayed-month 12)
              (memq month `(12 3 6 9)))
            6)
          ((and
              (eq displayed-month 12)
              (memq month `(1 4 7 10)))
            31)
          ((and
              (eq displayed-month 12)
              (memq month `(2 5 8 11)))
            56) )
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
          (* 3 (mod
            (- (calendar-day-of-week date) calendar-week-start-day)
              7))))))

解决方案

I must be missing something because it looks like the formulas are as simple as (pseudocode):

first  = 9 * ( rows - 1 ) 
second = 6 + 25 * ( cols - 1 )

based on your edit, you can calculate the rows and cols to move with:

if target > display
   difference = target - display
else 
   difference = 12 + target - display
 rows = difference / 3 
 cols = difference % 3
 rowmove = 9 * rows 
 colmove = 6 + 25 * cols

And then use the formula above.

My attempt at elisp:

(let difference (if (>= target-month display-month) 
                      (- target-month display-month) 
                    (- (+ target-month 12) display-month)))
(let rows (/ difference 3))
(let cols (% difference 3))
(let rowmove (* 9 rows))   
(let colmove (+ 6 (* 25 cols)))

这篇关于将光标移动到Emacs中12个月轮换日历的日期的算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆