Function: recentf-arrange-by-rule

recentf-arrange-by-rule is a byte-compiled function defined in recentf.el.gz.

Signature

(recentf-arrange-by-rule L)

Documentation

Filter the list of menu-elements L.

Arrange them in sub-menus following rules in recentf-arrange-rules.

Source Code

;; Defined in /usr/src/emacs/lisp/recentf.el.gz
(defun recentf-arrange-by-rule (l)
  "Filter the list of menu-elements L.
Arrange them in sub-menus following rules in `recentf-arrange-rules'."
  (when recentf-arrange-rules
    (let (menus others menu file min count)
      ;; Put menu items into sub-menus as defined by rules.
      (dolist (elt l)
        (setq file (recentf-menu-element-value elt)
              menu (recentf-match-rule file))
        (while (functionp (car menu))
          (setq menu (funcall (car menu) (cdr menu))))
        (if (not (stringp (car menu)))
            (push elt others)
          (setq menu (or (assoc (car menu) menus)
                         (car (push (list (car menu)) menus))))
          (recentf-set-menu-element-value
           menu (cons elt (recentf-menu-element-value menu)))))
      ;; Finalize each sub-menu:
      ;; - truncate it depending on the value of
      ;;   `recentf-arrange-by-rules-min-items',
      ;; - replace %d by the number of menu items,
      ;; - apply `recentf-arrange-by-rule-subfilter' to menu items.
      (setq min (if (natnump recentf-arrange-by-rules-min-items)
                    recentf-arrange-by-rules-min-items 0)
            l nil)
      (dolist (elt menus)
        (setq menu (recentf-menu-element-value elt)
              count (length menu))
        (if (< count min)
            (setq others (nconc menu others))
          (recentf-set-menu-element-item
           elt (format (recentf-menu-element-item elt) count))
          (recentf-set-menu-element-value
           elt (recentf-apply-menu-filter
                recentf-arrange-by-rule-subfilter (nreverse menu)))
          (push elt l)))
      ;; Add the menu items remaining in the `others' bin.
      (when (setq others (nreverse others))
        (setq l (nconc
                 l
                 ;; Put items in an sub menu.
                 (if (stringp recentf-arrange-by-rule-others)
                     (list
                      (recentf-make-menu-element
                       (format recentf-arrange-by-rule-others
                               (length others))
                       (recentf-apply-menu-filter
                        recentf-arrange-by-rule-subfilter others)))
                   ;; Append items to the main menu.
                   (recentf-apply-menu-filter
                    recentf-arrange-by-rule-subfilter others)))))))
  l)