在emacs中,是否可以获得派生模式的父模式列表?
我找到了derived-mode-p,但这只允许我测试模式是否来自另一个模式。
答案 0 :(得分:7)
每个symbol has a property list和派生模式,此列表包含组件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)