Algorithms for moving the cursor to a date on a 12 month rotating calendar in Emacs

前端 未结 1 1727
余生分开走
余生分开走 2021-01-18 04:13

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-calend

1条回答
  •  囚心锁ツ
    2021-01-18 04:41

    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)))
    

    0 讨论(0)
提交回复
热议问题