diff options
| author | Kim F. Storm | 2005-02-08 23:51:31 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2005-02-08 23:51:31 +0000 |
| commit | 1de0ae85b33c8d8cb77ab839f66d2df4f9aa7b94 (patch) | |
| tree | 47809dd5501d35fcc7d8066c5cf71a33d8191a9a | |
| parent | 44042fe7e2825b2a9b2dd1bf65d15f2878e7b181 (diff) | |
| download | emacs-1de0ae85b33c8d8cb77ab839f66d2df4f9aa7b94.tar.gz emacs-1de0ae85b33c8d8cb77ab839f66d2df4f9aa7b94.zip | |
(ido-file-extensions-order): New defcustom.
(ido-file-extension-lessp, ido-file-extension-aux)
(ido-file-extension-order): New advanced file ordering.
(ido-file-lessp): New simple file ordering.
(ido-sort-list): Remove.
(ido-make-file-list): Use ido-file-lessp or ido-file-extension-lessp.
(ido-make-dir-list, ido-completion-help): Use ido-file-lessp.
| -rw-r--r-- | lisp/ido.el | 88 |
1 files changed, 80 insertions, 8 deletions
diff --git a/lisp/ido.el b/lisp/ido.el index 10fac08196a..996eb2c47bc 100644 --- a/lisp/ido.el +++ b/lisp/ido.el | |||
| @@ -410,6 +410,15 @@ This allows the current directory to be opened immediate with `dired'." | |||
| 410 | :type 'boolean | 410 | :type 'boolean |
| 411 | :group 'ido) | 411 | :group 'ido) |
| 412 | 412 | ||
| 413 | (defcustom ido-file-extensions-order nil | ||
| 414 | "*List of file extensions specifying preferred order of file selections. | ||
| 415 | Each element is either a string with `.' as the first char, an empty | ||
| 416 | string matching files without extension, or t which is the default order | ||
| 417 | of for files with an unlisted file extension." | ||
| 418 | :type '(repeat (choice string | ||
| 419 | (const :tag "Default order" t))) | ||
| 420 | :group 'ido) | ||
| 421 | |||
| 413 | (defcustom ido-ignore-directories | 422 | (defcustom ido-ignore-directories |
| 414 | '("\\`CVS/" "\\`\\.\\./" "\\`\\./") | 423 | '("\\`CVS/" "\\`\\.\\./" "\\`\\./") |
| 415 | "*List of regexps or functions matching sub-directory names to ignore." | 424 | "*List of regexps or functions matching sub-directory names to ignore." |
| @@ -2629,10 +2638,69 @@ for first matching file." | |||
| 2629 | (t nil)))) | 2638 | (t nil)))) |
| 2630 | 2639 | ||
| 2631 | 2640 | ||
| 2632 | (defun ido-sort-list (items) | 2641 | ;; File list sorting |
| 2633 | ;; Simple list of file or buffer names | 2642 | |
| 2634 | (sort items (lambda (a b) (string-lessp (ido-no-final-slash a) | 2643 | (defun ido-file-lessp (a b) |
| 2635 | (ido-no-final-slash b))))) | 2644 | ;; Simple compare two file names. |
| 2645 | (string-lessp (ido-no-final-slash a) (ido-no-final-slash b))) | ||
| 2646 | |||
| 2647 | |||
| 2648 | (defun ido-file-extension-lessp (a b) | ||
| 2649 | ;; Compare file names according to ido-file-extensions-order list. | ||
| 2650 | (let ((n (compare-strings a 0 nil b 0 nil nil)) | ||
| 2651 | lessp p) | ||
| 2652 | (if (eq n t) | ||
| 2653 | nil | ||
| 2654 | (if (< n 0) | ||
| 2655 | (setq n (1- (- n)) | ||
| 2656 | p a a b b p | ||
| 2657 | lessp t) | ||
| 2658 | (setq n (1- n))) | ||
| 2659 | (cond | ||
| 2660 | ((= n 0) | ||
| 2661 | lessp) | ||
| 2662 | ((= (aref a n) ?.) | ||
| 2663 | (ido-file-extension-aux a b n lessp)) | ||
| 2664 | (t | ||
| 2665 | (while (and (> n 2) (/= (aref a n) ?.)) | ||
| 2666 | (setq n (1- n))) | ||
| 2667 | (if (> n 1) | ||
| 2668 | (ido-file-extension-aux a b n lessp) | ||
| 2669 | lessp)))))) | ||
| 2670 | |||
| 2671 | (defun ido-file-extension-aux (a b n lessp) | ||
| 2672 | (let ((oa (ido-file-extension-order a n)) | ||
| 2673 | (ob (ido-file-extension-order b n))) | ||
| 2674 | (cond | ||
| 2675 | ((= oa ob) | ||
| 2676 | lessp) | ||
| 2677 | ((and oa ob) | ||
| 2678 | (if lessp | ||
| 2679 | (> oa ob) | ||
| 2680 | (< oa ob))) | ||
| 2681 | (oa | ||
| 2682 | (not lessp)) | ||
| 2683 | (ob | ||
| 2684 | lessp) | ||
| 2685 | (t | ||
| 2686 | lessp)))) | ||
| 2687 | |||
| 2688 | (defun ido-file-extension-order (s n) | ||
| 2689 | (let ((l ido-file-extensions-order) | ||
| 2690 | (i 0) o do) | ||
| 2691 | (while l | ||
| 2692 | (cond | ||
| 2693 | ((eq (car l) t) | ||
| 2694 | (setq do i | ||
| 2695 | l (cdr l))) | ||
| 2696 | ((eq (compare-strings s n nil (car l) 0 nil nil) t) | ||
| 2697 | (setq o i | ||
| 2698 | l nil)) | ||
| 2699 | (t | ||
| 2700 | (setq l (cdr l)))) | ||
| 2701 | (setq i (1+ i))) | ||
| 2702 | (or o do))) | ||
| 2703 | |||
| 2636 | 2704 | ||
| 2637 | (defun ido-sort-merged-list (items promote) | 2705 | (defun ido-sort-merged-list (items promote) |
| 2638 | ;; Input is list of ("file" . "dir") cons cells. | 2706 | ;; Input is list of ("file" . "dir") cons cells. |
| @@ -2905,7 +2973,10 @@ for first matching file." | |||
| 2905 | ;; created to allow the user to further modify the order of the file names | 2973 | ;; created to allow the user to further modify the order of the file names |
| 2906 | ;; in this list. | 2974 | ;; in this list. |
| 2907 | (let ((ido-temp-list (ido-make-file-list1 ido-current-directory))) | 2975 | (let ((ido-temp-list (ido-make-file-list1 ido-current-directory))) |
| 2908 | (setq ido-temp-list (ido-sort-list ido-temp-list)) | 2976 | (setq ido-temp-list (sort ido-temp-list |
| 2977 | (if ido-file-extensions-order | ||
| 2978 | #'ido-file-extension-lessp | ||
| 2979 | #'ido-file-lessp))) | ||
| 2909 | (let ((default-directory ido-current-directory)) | 2980 | (let ((default-directory ido-current-directory)) |
| 2910 | (ido-to-end ;; move ftp hosts and visited files to end | 2981 | (ido-to-end ;; move ftp hosts and visited files to end |
| 2911 | (delq nil (mapcar | 2982 | (delq nil (mapcar |
| @@ -2954,7 +3025,7 @@ for first matching file." | |||
| 2954 | ;; created to allow the user to further modify the order of the | 3025 | ;; created to allow the user to further modify the order of the |
| 2955 | ;; directory names in this list. | 3026 | ;; directory names in this list. |
| 2956 | (let ((ido-temp-list (ido-make-dir-list1 ido-current-directory))) | 3027 | (let ((ido-temp-list (ido-make-dir-list1 ido-current-directory))) |
| 2957 | (setq ido-temp-list (ido-sort-list ido-temp-list)) | 3028 | (setq ido-temp-list (sort ido-temp-list #'ido-file-lessp)) |
| 2958 | (ido-to-end ;; move . files to end | 3029 | (ido-to-end ;; move . files to end |
| 2959 | (delq nil (mapcar | 3030 | (delq nil (mapcar |
| 2960 | (lambda (x) (if (string-equal (substring x 0 1) ".") x)) | 3031 | (lambda (x) (if (string-equal (substring x 0 1) ".") x)) |
| @@ -3184,14 +3255,15 @@ for first matching file." | |||
| 3184 | (setq display-it t)) | 3255 | (setq display-it t)) |
| 3185 | (if display-it | 3256 | (if display-it |
| 3186 | (with-output-to-temp-buffer ido-completion-buffer | 3257 | (with-output-to-temp-buffer ido-completion-buffer |
| 3187 | (let ((completion-list (ido-sort-list | 3258 | (let ((completion-list (sort |
| 3188 | (cond | 3259 | (cond |
| 3189 | (ido-use-merged-list | 3260 | (ido-use-merged-list |
| 3190 | (ido-flatten-merged-list (or ido-matches ido-cur-list))) | 3261 | (ido-flatten-merged-list (or ido-matches ido-cur-list))) |
| 3191 | ((or full-list ido-completion-buffer-all-completions) | 3262 | ((or full-list ido-completion-buffer-all-completions) |
| 3192 | (ido-all-completions)) | 3263 | (ido-all-completions)) |
| 3193 | (t | 3264 | (t |
| 3194 | (copy-sequence (or ido-matches ido-cur-list))))))) | 3265 | (copy-sequence (or ido-matches ido-cur-list)))) |
| 3266 | #'ido-file-lessp))) | ||
| 3195 | (if (featurep 'xemacs) | 3267 | (if (featurep 'xemacs) |
| 3196 | ;; XEmacs extents are put on by default, doesn't seem to be | 3268 | ;; XEmacs extents are put on by default, doesn't seem to be |
| 3197 | ;; any way of switching them off. | 3269 | ;; any way of switching them off. |