请教timer-list变量?

timer-list 变量,能帮忙解释一下里面的参数的含义? 第一个参数,nil, 24388, 54032 ,894622,等, 第5个参数是repeat 次数,2/3/4参数好像是时间,这种如何输出可读格式的时间?

timer-list is a variable defined in ‘C source code’.
Its value is
([nil 24388 24178 95578 nil sis--respect-post-cmd-timer-fn nil nil 0]
 [nil 24388 24186 430483 nil undo-auto--boundary-timer nil nil 0]
 [nil 24388 24201 894622 60 ac-clear-variables-every-minute nil nil 0]
 [nil 24388 54032 0 nil circadian-activate-latest-theme nil nil 0])

timer是一个用cl-defstruct定义的格式为vector的struct(定义为vector应该是为了兼容),所以用timer--triggered这些accessor来访问就好了

C-h o timer

timer is a type (of kind cl-structure-class') in timer.el’. Instance Allocated Slots:

Name	Type	Default
————	————	———————
triggered	t	t
high-seconds	t	nil
low-seconds	t	nil
usecs	t	nil
repeat-delay	t	nil
function	t	nil
args	t	nil
idle-delay	t	nil
psecs	t	nil

(high-seconds low-seconds usecs) 这三个正好是 Emacs 时间值((elisp) Time of Day),所以直接用 format-time-string

(format-time-string "%Y-%m-%d %H:%M:%S %z"
                    '(24388 54032 894622))
;; => "2020-08-25 17:00:00 +0800"

(format-time-string
 "%Y-%m-%d %H:%M:%S %z"
 (seq-into (seq-subseq (car timer-list) 1 4) 'list))
;; => "2020-08-25 11:45:50 +0800"

如楼上所说,timer 是个结构体,应该用专门的 getter 访问

(mapcar (lambda (f)
          (funcall f (car timer-list)))
        '(timer--high-seconds
          timer--low-seconds
          timer--usecs))
;; => (24388 35328 312834)
2 个赞