作者:我摸你马匹 | 来源:互联网 | 2023-05-20 10:52
在emacs中,是否可以获得派生模式的父模式列表?
我找到了derived-mode-p,但这只允许我测试一个模式是否来自另一个模式.
1> tripleee..:
每个符号都有一个属性列表,对于派生模式,此列表包含derived-mode-parent
指示从哪个模式派生的组件.它似乎只是一个符号.
(define-derived-mode nst-mode text-mode "Testing")
=> nst-mode
(get 'nst-mode 'derived-mode-parent)
=> text-mode
我不知道怎么会有多个父母.
这是一个父母传递链的演示.
(define-derived-mode rope nil "Victim of mouse")
(define-derived-mode mouse rope "Victim of cat")
(define-derived-mode cat mouse "Victim of dog")
(define-derived-mode dog cat "Enough already")
(let ((mode 'dog) parents)
(while mode
(setq parents (cons mode parents)
mode (get mode 'derived-mode-parent)))
(reverse parents))
=> (dog cat mouse rope)
...或者,只是为了好玩,一个递归版本:
(defun derived-mode-parents (mode)
(and mode
(cons mode (derived-mode-parents
(get mode 'derived-mode-parent)))))
(derived-mode-parents 'dog)
=> (dog cat mouse rope)