el/dot-emacs.el (mdw-examine-fill-prefixes): Rewrite to be iterative.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 26 Jul 2020 21:44:56 +0000 (22:44 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 26 Jul 2020 21:44:56 +0000 (22:44 +0100)
Emacs Lisp is hopelessly deficient in terms of control flow, but this
seems like the best choice available.

el/dot-emacs.el

index c5742d0..5bde809 100644 (file)
@@ -1254,12 +1254,17 @@ See `mdw-fill-prefix' for details."
   "Given a list of dynamic fill prefixes, pick one which matches
 context and return the static fill prefix to use.  Point must be
 at the start of a line, and match data must be saved."
-  (cond ((not l) nil)
-       ((looking-at (car (car l)))
-        (mdw-maybe-tabify (apply #'concat
+  (let ((prefix nil))
+    (while (cond ((null l) nil)
+                ((looking-at (caar l))
+                 (setq prefix
+                         (mdw-maybe-tabify
+                          (apply #'concat
                                  (mapcar #'mdw-do-prefix-match
                                          (cdr (car l))))))
-       (t (mdw-examine-fill-prefixes (cdr l)))))
+                 nil))
+      (setq l (cdr l)))
+    prefix))
 
 (defun mdw-choose-dynamic-fill-prefix ()
   "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."