0

Have several implementations for determining the dependence chain for a derived mode once the mode has been loaded. What would be the most convenient to use and what improvements can I do?

Have difficulty understanding the workings of dependence-chain-a, specifically the line (while (progn. How is the while loop functioning in the case of dependence-chain-a?

(defun dependence-chain-a (mode)
  "Return the chain of derived modes for MODE."
  (interactive)

  (let (chain)
    (while (progn
         (push mode chain)
         (let* ( (parent (get mode 'derived-mode-parent))
             (parentfn (symbol-function parent)) )
           (setq mode (if (and parentfn (symbolp parentfn))
                  parentfn
                parent)))))
    (nreverse chain)))

;;-------- 

(defun dependence-chain-b (mode)
  "Return a list of the ancestor modes that MODE is derived from."
  (interactive)

  (let ( (modes   ())
         (parent  nil) )

    (while (setq parent (get mode 'derived-mode-parent))
      (push parent modes)
      (setq mode parent))
    (setq modes (nreverse modes))))

;;--------

(defun dependence-chain-c (mode)
  (interactive (list major-mode))
  (defun iter (mode)
    (and mode
         (cons mode
               (iter (get mode 'derived-mode-parent)))))
  (message "%s" (iter mode))) 
Dilna
  • 1,173
  • 3
  • 10
  • That's for you to try out and decide for yourself. – NickD Aug 30 '22 at 19:47
  • > *"the most convenient to use and what improvements can I do"* What @NickD said. Please post such open-ended questions on a discussion site, such as Reddit or Facebook. – Drew Aug 30 '22 at 21:09

0 Answers0