aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Ponce2005-11-25 07:57:21 +0000
committerDavid Ponce2005-11-25 07:57:21 +0000
commitd973cf9cdbe9d032383c4da89e582089ab3932e0 (patch)
tree1a99f77eba5dacf6f1130a19547d769ed3095a90
parentf81b92f259a6e7287f89b48db361a1b89ba07578 (diff)
downloademacs-d973cf9cdbe9d032383c4da89e582089ab3932e0.tar.gz
emacs-d973cf9cdbe9d032383c4da89e582089ab3932e0.zip
(recentf-arrange-by-rule): Handle a special `auto-mode-alist'-like
"strip suffix" rule. (recentf-build-mode-rules): Handle second level auto-mode entries.
-rw-r--r--lisp/recentf.el85
1 files changed, 51 insertions, 34 deletions
diff --git a/lisp/recentf.el b/lisp/recentf.el
index b14997d604f..287ab3014cb 100644
--- a/lisp/recentf.el
+++ b/lisp/recentf.el
@@ -813,39 +813,49 @@ See `recentf-arrange-rules' for details on MATCHER."
813Arrange them in sub-menus following rules in `recentf-arrange-rules'." 813Arrange them in sub-menus following rules in `recentf-arrange-rules'."
814 (if (not recentf-arrange-rules) 814 (if (not recentf-arrange-rules)
815 l 815 l
816 (let ((menus (mapcar #'(lambda (r) (list (car r))) 816 (let* ((strip (assq t recentf-arrange-rules))
817 recentf-arrange-rules)) 817 (rules (remq strip recentf-arrange-rules))
818 menu others min file rules elts count) 818 (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.
819 (dolist (elt l) 821 (dolist (elt l)
820 (setq file (recentf-menu-element-value elt) 822 (setq l1 menus ;; List of sub-menus
821 rules recentf-arrange-rules 823 l2 rules ;; List of corresponding matchers.
822 elts menus 824 file (recentf-menu-element-value elt)
823 menu nil) 825 menu nil)
824 (while (and (not menu) rules) 826 ;; Apply the strip suffix rule.
825 (when (recentf-match-rule-p (cdar rules) file) 827 (while (recentf-match-rule-p (cdr strip) file)
826 (setq menu (car elts)) 828 (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))
827 (recentf-set-menu-element-value 833 (recentf-set-menu-element-value
828 menu (cons elt (recentf-menu-element-value menu)))) 834 menu (cons elt (recentf-menu-element-value menu))))
829 (setq rules (cdr rules) 835 (setq l1 (cdr l1)
830 elts (cdr elts))) 836 l2 (cdr l2)))
831 (unless menu 837 ;; Put unmatched menu items in the `others' bin.
832 (push elt others))) 838 (or menu (push elt others)))
833 839 ;; Finalize the sub-menus. That is, for each one:
834 (setq l nil 840 ;; - truncate it depending on the value of
835 min (if (natnump recentf-arrange-by-rules-min-items) 841 ;; `recentf-arrange-by-rules-min-items',
836 recentf-arrange-by-rules-min-items 0)) 842 ;; - 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)
837 (dolist (menu menus) 847 (dolist (menu menus)
838 (when (setq elts (recentf-menu-element-value menu)) 848 (when (setq l1 (recentf-menu-element-value menu))
839 (setq count (length elts)) 849 (setq count (length l1))
840 (if (< count min) 850 (if (< count min)
841 (setq others (nconc elts others)) 851 (setq others (nconc l1 others))
842 (recentf-set-menu-element-item 852 (recentf-set-menu-element-item
843 menu (format (recentf-menu-element-item menu) count)) 853 menu (format (recentf-menu-element-item menu) count))
844 (recentf-set-menu-element-value 854 (recentf-set-menu-element-value
845 menu (recentf-apply-menu-filter 855 menu (recentf-apply-menu-filter
846 recentf-arrange-by-rule-subfilter (nreverse elts))) 856 recentf-arrange-by-rule-subfilter (nreverse l1)))
847 (push menu l)))) 857 (push menu l2))))
848 858 ;; Add the menu items remaining in the `others' bin.
849 (if (and (stringp recentf-arrange-by-rule-others) others) 859 (if (and (stringp recentf-arrange-by-rule-others) others)
850 (nreverse 860 (nreverse
851 (cons 861 (cons
@@ -853,12 +863,11 @@ Arrange them in sub-menus following rules in `recentf-arrange-rules'."
853 (format recentf-arrange-by-rule-others (length others)) 863 (format recentf-arrange-by-rule-others (length others))
854 (recentf-apply-menu-filter 864 (recentf-apply-menu-filter
855 recentf-arrange-by-rule-subfilter (nreverse others))) 865 recentf-arrange-by-rule-subfilter (nreverse others)))
856 l)) 866 l2))
857 (nconc 867 (nconc
858 (nreverse l) 868 (nreverse l2)
859 (recentf-apply-menu-filter 869 (recentf-apply-menu-filter
860 recentf-arrange-by-rule-subfilter (nreverse others))))) 870 recentf-arrange-by-rule-subfilter (nreverse others)))))))
861 ))
862 871
863;;; Predefined rule based menu filters 872;;; Predefined rule based menu filters
864;; 873;;
@@ -870,12 +879,20 @@ Rules obey `recentf-arrange-rules' format."
870 (dolist (mode auto-mode-alist) 879 (dolist (mode auto-mode-alist)
871 (setq regexp (car mode) 880 (setq regexp (car mode)
872 mode (cdr mode)) 881 mode (cdr mode))
873 (when (symbolp mode) 882 (when mode
874 (setq rule-name (symbol-name mode)) 883 (cond
875 (if (string-match "\\(.*\\)-mode$" rule-name) 884 ;; Build a special "strip suffix" rule from entries of the
876 (setq rule-name (match-string 1 rule-name))) 885 ;; form (REGEXP FUNCTION NON-NIL). Notice that FUNCTION is
877 (setq rule-name (concat rule-name " (%d)") 886 ;; ignored by the menu filter. So in some corner cases a
878 rule (assoc rule-name rules)) 887 ;; 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))
879 (if rule 896 (if rule
880 (setcdr rule (cons regexp (cdr rule))) 897 (setcdr rule (cons regexp (cdr rule)))
881 (push (list rule-name regexp) rules)))) 898 (push (list rule-name regexp) rules))))