813 |
Arrange them in sub-menus following rules in `recentf-arrange-rules'." |
Arrange them in sub-menus following rules in `recentf-arrange-rules'." |
814 |
(if (not recentf-arrange-rules) |
(if (not recentf-arrange-rules) |
815 |
l |
l |
816 |
(let ((menus (mapcar #'(lambda (r) (list (car r))) |
(let* ((strip (assq t recentf-arrange-rules)) |
817 |
recentf-arrange-rules)) |
(rules (remq strip recentf-arrange-rules)) |
818 |
menu others min file rules elts count) |
(menus (mapcar #'(lambda (r) (list (car r))) rules)) |
819 |
|
others l1 l2 menu file min count) |
820 |
|
;; Put menu items into sub-menus as defined by rules. |
821 |
(dolist (elt l) |
(dolist (elt l) |
822 |
(setq file (recentf-menu-element-value elt) |
(setq l1 menus ;; List of sub-menus |
823 |
rules recentf-arrange-rules |
l2 rules ;; List of corresponding matchers. |
824 |
elts menus |
file (recentf-menu-element-value elt) |
825 |
menu nil) |
menu nil) |
826 |
(while (and (not menu) rules) |
;; Apply the strip suffix rule. |
827 |
(when (recentf-match-rule-p (cdar rules) file) |
(while (recentf-match-rule-p (cdr strip) file) |
828 |
(setq menu (car elts)) |
(setq file (substring file 0 (match-beginning 0)))) |
829 |
|
;; Search which sub-menu to put the menu item into. |
830 |
|
(while (and (not menu) l2) |
831 |
|
(when (recentf-match-rule-p (cdar l2) file) |
832 |
|
(setq menu (car l1)) |
833 |
(recentf-set-menu-element-value |
(recentf-set-menu-element-value |
834 |
menu (cons elt (recentf-menu-element-value menu)))) |
menu (cons elt (recentf-menu-element-value menu)))) |
835 |
(setq rules (cdr rules) |
(setq l1 (cdr l1) |
836 |
elts (cdr elts))) |
l2 (cdr l2))) |
837 |
(unless menu |
;; Put unmatched menu items in the `others' bin. |
838 |
(push elt others))) |
(or menu (push elt others))) |
839 |
|
;; Finalize the sub-menus. That is, for each one: |
840 |
(setq l nil |
;; - truncate it depending on the value of |
841 |
min (if (natnump recentf-arrange-by-rules-min-items) |
;; `recentf-arrange-by-rules-min-items', |
842 |
recentf-arrange-by-rules-min-items 0)) |
;; - replace %d by the number of menu items, |
843 |
|
;; - apply `recentf-arrange-by-rule-subfilter' to menu items. |
844 |
|
(setq min (if (natnump recentf-arrange-by-rules-min-items) |
845 |
|
recentf-arrange-by-rules-min-items 0) |
846 |
|
l2 nil) |
847 |
(dolist (menu menus) |
(dolist (menu menus) |
848 |
(when (setq elts (recentf-menu-element-value menu)) |
(when (setq l1 (recentf-menu-element-value menu)) |
849 |
(setq count (length elts)) |
(setq count (length l1)) |
850 |
(if (< count min) |
(if (< count min) |
851 |
(setq others (nconc elts others)) |
(setq others (nconc l1 others)) |
852 |
(recentf-set-menu-element-item |
(recentf-set-menu-element-item |
853 |
menu (format (recentf-menu-element-item menu) count)) |
menu (format (recentf-menu-element-item menu) count)) |
854 |
(recentf-set-menu-element-value |
(recentf-set-menu-element-value |
855 |
menu (recentf-apply-menu-filter |
menu (recentf-apply-menu-filter |
856 |
recentf-arrange-by-rule-subfilter (nreverse elts))) |
recentf-arrange-by-rule-subfilter (nreverse l1))) |
857 |
(push menu l)))) |
(push menu l2)))) |
858 |
|
;; Add the menu items remaining in the `others' bin. |
859 |
(if (and (stringp recentf-arrange-by-rule-others) others) |
(if (and (stringp recentf-arrange-by-rule-others) others) |
860 |
(nreverse |
(nreverse |
861 |
(cons |
(cons |
863 |
(format recentf-arrange-by-rule-others (length others)) |
(format recentf-arrange-by-rule-others (length others)) |
864 |
(recentf-apply-menu-filter |
(recentf-apply-menu-filter |
865 |
recentf-arrange-by-rule-subfilter (nreverse others))) |
recentf-arrange-by-rule-subfilter (nreverse others))) |
866 |
l)) |
l2)) |
867 |
(nconc |
(nconc |
868 |
(nreverse l) |
(nreverse l2) |
869 |
(recentf-apply-menu-filter |
(recentf-apply-menu-filter |
870 |
recentf-arrange-by-rule-subfilter (nreverse others))))) |
recentf-arrange-by-rule-subfilter (nreverse others))))))) |
|
)) |
|
871 |
|
|
872 |
;;; Predefined rule based menu filters |
;;; Predefined rule based menu filters |
873 |
;; |
;; |
879 |
(dolist (mode auto-mode-alist) |
(dolist (mode auto-mode-alist) |
880 |
(setq regexp (car mode) |
(setq regexp (car mode) |
881 |
mode (cdr mode)) |
mode (cdr mode)) |
882 |
(when (symbolp mode) |
(when mode |
883 |
(setq rule-name (symbol-name mode)) |
(cond |
884 |
(if (string-match "\\(.*\\)-mode$" rule-name) |
;; Build a special "strip suffix" rule from entries of the |
885 |
(setq rule-name (match-string 1 rule-name))) |
;; form (REGEXP FUNCTION NON-NIL). Notice that FUNCTION is |
886 |
(setq rule-name (concat rule-name " (%d)") |
;; ignored by the menu filter. So in some corner cases a |
887 |
rule (assoc rule-name rules)) |
;; wrong mode could be guessed. |
888 |
|
((and (consp mode) (cadr mode)) |
889 |
|
(setq rule-name t)) |
890 |
|
((and mode (symbolp mode)) |
891 |
|
(setq rule-name (symbol-name mode)) |
892 |
|
(if (string-match "\\(.*\\)-mode$" rule-name) |
893 |
|
(setq rule-name (match-string 1 rule-name))) |
894 |
|
(setq rule-name (concat rule-name " (%d)")))) |
895 |
|
(setq rule (assoc rule-name rules)) |
896 |
(if rule |
(if rule |
897 |
(setcdr rule (cons regexp (cdr rule))) |
(setcdr rule (cons regexp (cdr rule))) |
898 |
(push (list rule-name regexp) rules)))) |
(push (list rule-name regexp) rules)))) |