-
Notifications
You must be signed in to change notification settings - Fork 0
/
ido.el
3538 lines (3154 loc) · 127 KB
/
ido.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; ido.el --- interactively do things with buffers and files.
;; Copyright (C) 1996-2001 Free Software Foundation, Inc.
;; Author: Kim F. Storm <[email protected]>
;; Based on: iswitchb by Stephen Eglen <[email protected]>
;; Maintainer: Kim F. Storm <[email protected]>
;; Location: http://www.cua.dk/
;; Version: 1.56
;; Keywords: extensions convenience
;; This file is (not yet) part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Acknowledgements
;; Infinite amounts of gratitude goes to Stephen Eglen <[email protected]>
;; who wrote iswitch-buffer mode - from which I ripped off 99% of the code
;; for ido-switch-buffer and found the inspiration for ido-find-file.
;; The ido package would never have existed without his work.
;; Also thanks to Klaus Berndl, Rohit Namjoshi, Robert Fenk, Alex Schroeder,
;; Bill Benedetto, and Stephen Eglen for bug fixes and improvements.
;;; History
;; Since I discovered Stephen Eglen's excellent iswitchb package, I just
;; couldn't live without it, but once being addicted to switching buffers
;; with a minimum of keystrokes, I soon found that opening files in the
;; old-fashioned way was just too slow - so I decided to write a package
;; which could open files with the same speed and ease as iswitchb could
;; switch buffers.
;; I originally wrote a separate ifindf.el package based on a copy of
;; iswitchb.el, which did for opening files what iswitchb did for
;; switching buffers. Along the way, I corrected a few errors in
;; ifindf which could have found its way back into iswitchb, but since
;; most of the functionality of the two package was practically
;; identical, I decided that the proper thing to do was to merge my
;; ifindf package back into iswitchb.
;;
;; This is basically what ido (interactively do) is all about; but I
;; found it ackward to merge my changes into the "iswitchb-" namespace,
;; so I invented a common "ido-" namespace for the merged packages.
;;
;; Versions:
;; 1.20: <[email protected]>
;; + Added prefix macthing in addition to the normal substring-matching
;; and a toggle function (`ido-enable-prefix' and `ido-toggle-prefix').
;; + Added highlighting for sub-directories in the alternative-list
;; for better and faster overview (`ido-subdir-face').
;; + Added possibilty to customize for what function-group (buffer-handling
;; or file-handling) ido should be enabled. Look at `ido-enabled'.
;; + Removed some bugs:
;; - file-functions (find, insert, write...) now handle correct the
;; default-directory of the current buffer.
;; - added compatiblity for emacs without customize for deface too.
;; 1.21: + Added support for emacs 21.0
;; 1.22: + Added ido-max-prospects to speed up prompting in big directories.
;; 1.23: + Cleanup for public release
;; 1.24: + Move visited files to end of file selection list
;; + Save ido-last-directory-list in ~/.ido.last
;; 1.25: + Move exact match to front of selection list (unless in prefix mode)
;; 1.26: + Kill .ido.last buffer after loading it.
;; 1.27: + Added ido-find-file-read-only from Rohit Namjoshi.
;; + Added misc fixes from Robert Fenk.
;; + Added ido-max-prompt-path.
;; + Rotate file list to get default item in front [up-dir only]
;; 1.28: + Added C-e to edit input string
;; 1.29: + Added ido-dired [C-x d] and ido-list-directory [C-x C-d].
;; If specifying a non-existing directory, offer to create it.
;; 1.30: + Disable show-paren-mode in minibuffer
;; + Dired now has . as default choice to make entering current directory easy.
;; + Fixed handling of / in directory paths
;; + "../" is now handled like backspace (updir).
;; + C-f now always falls back to non-ido version of current command.
;; + Handle $VAR expansion in file names
;; + Fixed unintended ange-ftp interaction in root directory.
;; 1.31 + Changed location & contact e-mail address
;; 1.32 + Added fixes and enhancements from Klaus Berndl:
;; - New ido-separator variable.
;; - Fixed documentation of various make-list-hooks.
;; - Don't backspace past root directory.
;; + Fixed: default-directory of current buffer was changed by find-file fallback.
;; + Added ido-make-file-prompt-hook and ido-rewrite-prompt-path-rules variables.
;; + Added work directory history for ido-find-file.
;; 1.33 + When using multiple frames, ido-switch-buffer now shows current frame's buffers first.
;; 1.34 + Selection with keyboard or mouse now works in completion buffer.
;; - New variable ido-completion-buffer (default *Ido Completion*).
;; - Completion buffer is automatically removed when context changes.
;; - Completion buffer contents are now sorted alphabetically.
;; + Fixed: ido-dired didn't put directory in work directory history.
;; + Added short description of how ido-find-file actually works.
;; + [M-backspace] now deletes word (if any) or last subdir like [backspace]
;; 1.35 + Added work file history (on M-o and M-b)
;; + Fixed: allow entering dired with wildcard filename.
;; + C-w now inserts current buffer's file name.
;; + More customization: ido-completion-buffer-all-completions
;; + Work file and directory lists can now be saved and loaded using
;; M-x ido-save-history and M-x ido-load-history.
;; 1.36 + Fixed handling of ~/ (was broken in 1.34)
;; + $VAR expansion how happens automatically when typing /
;; + Fixed: dired would store /path/./ in work directory history.
;; + ido-write-file now disables ido-work-directory-match-only.
;; 1.37 + Avoid corrupting .ido.last and check after load.
;; 1.40 + Added ido-work-directory-list-ignore-regexps.
;; + Added ido-dir-file-cache and ido-max-dir-file-cache.
;; + Added automatic lookup in work directory history for files when no match.
;; + Added ido-merge-work-directories and ido-auto-merge-work-directories-length.
;; 1.41 + Ignore text properties in minibuffer contents (if yanked)
;; + Fixed: don't auto-merge in root to allow entry of ange-ftp hostnames
;; 1.42 + Don't auto-merge in write-file, dired, and list-directory
;; + Restore pre-merge state when backspacing or no merged matches found
;; + C-z now undoes last merge and returns to the pre-merge directory
;; 1.43 + Added ido-merged-indicator and ido-indicator-face.
;; + Use directory file cache rather than work directory list when merging directories (ending in /)
;; 1.44 + Use directory cache contents when creating merged directory list.
;; + Added ido-ignore-directories-merge.
;; + Fixed customize type for ignore lists to choice of regexps or functions.
;; 1.45 + Added C-o command to ido-find-file to copy file name from current buffer.
;; + Modified C-w to no copy extension if current directory hasn't changed.
;; 1.46 + Added ido-auto-merge-delay to delay auto merge operation by 500 ms waiting for more input.
;; + Corrected minor problems related to cycling through merged lists.
;; 1.47 + Added ido-decorations to allow more customization of ido minibuffer.
;; + Enhanced ido-wash-history to remove text properties from strings.
;; + In match list, strings whose prefix matches are now placed first.
;; + Fixed: Clear previous input string when C-g is used to quit minibuffer.
;; + Fixed: Restore previous matches when undoing merge using [backspace].
;; + Fixed: Avoid duplicates in ido-work-file-list.
;; + No longer uses pp to save ido history file.
;; + Added ido-read-file-name and ido-read-directory-name functions.
;; 1.48 + In emacs 21, now resizes minibuffer according to max-mini-window-height.
;; + Added ido-max-window-height to override max-mini-window-height.
;; + Added fix from Alex Schroeder for ido-max-prompt-path customization.
;; 1.49 + Fixed: Input was not echoed in minibuffer when no matches; the fix
;; uses a timer to perform auto-merge delay rather than sit-for.
;; + Replaced ido-auto-merge-delay by ido-auto-merge-delay-time (seconds).
;; + Don't auto-merge with 1 character only (so don't auto-merge on ~).
;; + M-k removes current directory from ido-work-directory-list.
;; 1.50 + User input now interrupts auto merge.
;; + Fixed: maintain current input when switching between file and buffer selection.
;; 1.51 + Fixed ido-to-end: would clear ido-temp-list if called with entire list.
;; + C-backspace now goes to parent directory without clearing current file name.
;; + Disable print-level and print-length limitations when saving history.
;; + Now check proper formatting of all loaded history data in ido-wash-history.
;; Discard bogus elements.
;; + Added M-m to make-directory in current directory.
;; + Added M-f to search for a matching files using external find command.
;; + Added M-d to search for a matching directories using external find command.
;; 1.52 + Fixed: Ignore error messages from `find' command in ido-wide-find-dirs-or-files.
;; + Added ido-slow-ftp-hosts and ido-slow-ftp-host-regexps to automatically fallback
;; to standard find-file if visiting one of the matching hosts.
;; + Added ido-merge-ftp-work-directories; by default, ftp hosts are ignored when
;; searching work directories.
;; + Added ido-cache-ftp-work-directory-time; by default, ftp host directories are
;; cached for one hour without checking for new contents.
;; + Don't cache root directories on nt and ms-dos systems.
;; 1.53 + Immediately fallback to non-ido find-file if ido-find-file is activated
;; in a buffer whose default-directory is on a slow ftp host.
;; + C-k in ido-find-file offers to delete file at head of list.
;; 1.54 + Adapted key-binding fix from Bill Benedetto for (ido-mode 'buffer).
;; + Added find-file-read-only-other-window and find-file-read-only-other-frame.
;; + Adapted fix from Stephen Eglen to use select-frame-set-input-focus when available.
;; 1.55 + Fixed ido-minibuffer-setup for xemacs (but ido still has problems is some areas with xemacs).
;; + Automatically look in list of ignored files or buffers [C-a] when there are no matches.
;; Specifically, .. is now completed normally although it is ignored by default.
;; + Removed the ido-merge-work-directories variable which modified the functionality of M-p and M-n.
;; + The M-p and M-n commands now always go to the previous / next (matching) work directory in the history.
;; + New M-s command (ido-merge-work-directories) to actively search (and merge) the work directory history.
;; + Added ido-show-dot-for-dired to allow easy entry to dired from ido-find-file.
;; 1.56 + Don't use obsoleted insert-string in emacs 21.3
;; + Fixed: Don't bind backspace and M-backspace specifically for xemacs.
;;
;;; Commentary:
;; Installation:
;; To get the alternative switch-to-buffer and find-file functions in
;; this package bound to keys, do
;; (require 'ido)
;; (ido-mode t)
;; Substring matching (The default method)
;;
;; As you type in a substring, the list of buffers or files currently
;; matching the substring are displayed as you type. The list is
;; ordered so that the most recent buffers or files visited come at
;; the start of the list.
;; The buffer or file at the start of the list will be the one visited
;; when you press return. By typing more of the substring, the list is
;; narrowed down so that gradually the buffer or file you want will be
;; at the top of the list. Alternatively, you can use C-s and C-r (or
;; the right and left arrow keys) to rotate buffer or file names in the
;; list until the one you want is at the top of the list.
;; Completion is also available so that you can see what is common to
;; all of the matching buffers or files as you type.
;;
;; This code is based on the iswitchb package by Stephen Eglen, and
;; large parts of the code and comments is copied directly from iswitchb
;; with only editorial changes on my part.
;;
;; Prefix matching
;;
;; The standard way of completion with Unix-shells and Emacs is to insert a
;; PREFIX and then hitting TAB (or another completion key). Cause of this
;; behavior has become second nature to a lot of emacs users `ido' offers in
;; addition to the default substring-matching-method (look above) also the
;; prefix-matching-method. The kind of matching is the only difference to
;; the description of the substring-matching above.
;; Prefix matching was added by Klaus Berndl ([email protected]) based on
;; an idea of Yuji Minejima <[email protected]> and his mcomplete-package.
;;; Example
;; Substring matching
;;
;; If I have two buffers called "123456" and "123", with "123456" the
;; most recent, when I use ido-switch-buffer, I first of all get
;; presented with the list of all the buffers
;;
;; Buffer: {123456,123}
;;
;; If I then press 2:
;; Buffer: 2[3]{123456,123}
;;
;; The list in {} are the matching buffers, most recent first (buffers
;; visible in the current frame are put at the end of the list by
;; default). At any time I can select the item at the head of the
;; list by pressing RET. I can also bring the put the first element
;; at the end of the list by pressing C-s or [right], or put the last
;; element at the head of the list by pressing C-r or [left].
;; The item in [] indicates what can be added to my input by pressing TAB.
;; In this case, I will get "3" added to my input. So, press TAB:
;; Buffer: 23{123456,123}
;;
;; At this point, I still have two matching buffers.
;; If I want the first buffer in the list, I simply press RET. If I
;; wanted the second in the list, I could press C-s to move it to the
;; top of the list and then RET to select it.
;;
;; However, If I type 4, I only have one match left:
;; Buffer: 234[123456] [Matched]
;;
;; Since there is only one matching buffer left, it is given in [] and we
;; see the text [Matched] afterwards. I can now press TAB or RET to go
;; to that buffer.
;;
;; If however, I now type "a":
;; Buffer: 234a [No match]
;; There are no matching buffers. If I press RET or TAB, I can be
;; prompted to create a new buffer called "234a".
;;
;; Of course, where this function comes in really useful is when you
;; can specify the buffer using only a few keystrokes. In the above
;; example, the quickest way to get to the "123456" file would be
;; just to type 4 and then RET (assuming there isn't any newer buffer
;; with 4 in its name).
;;
;; Prefix matching
;;
;; If you have again two Buffers "123456" and "123" then hitting "2" does
;; not match because "2" is not a PREFIX in any of the buffer-names. This
;; is the only difference between the substring- and prefix-matching.
;; Additional functionalty
;;
;; To see a full list of all matching buffer in a separate buffer,
;; hit ? or press TAB when there are no further completions to the
;; substring. Repeated TAB presses will scroll you through this
;; separate buffer.
;; The buffer at the head of the list can be killed by pressing C-k.
;; If the buffer needs saving, you will be queried before the buffer
;; is killed.
;; If you find that the file you are after is not in a buffer, you can
;; press C-f to immediately drop into ido-find-file.
;; Likewise, if you use ido-find-file, the list of files and
;; directories in the current directory is provided in the same
;; fashion as the buffers above. However, the files and directories
;; are simply sorted in alphabetical order.
;;
;; In addition to scrolling through the list using [right] and [left],
;; you can use [up] and [down] to quickly scroll the list to the next
;; or previous subdirectory.
;;
;; To go down into a subdirectory, and continue the file selection on
;; the files in that directory, simply move it to the head of the list
;; and hit RET.
;;
;; To go up to the parent directory, delete any partial file name
;; already specified (e.g. using [backspace]) and hit [backspace].
;;
;; To go to the root directory (on the current drive), enter two slashes.
;; On MS-DOS or Windows, to select the root of another drive, enter X:/
;; where X is the drive letter.
;;
;; If for some reason you cannot specify the proper file using
;; ido-find-file, you can press C-f to enter the normal find-file.
;; You can also press C-b to drop into ido-switch-buffer.
;; See the doc string of ido-switch-buffer and ido-find-file for full
;; keybindings and features.
;; (describe-function 'ido-find-file)
;;; Customisation
;; See the User Variables section below for easy ways to change the
;; functionality of the program. These are accessible using the
;; custom package.
;; To modify the keybindings, use the hook provided. For example:
;;(add-hook 'ido-define-mode-map-hook 'ido-my-keys)
;;
;;(defun ido-my-keys ()
;; "Add my keybindings for ido."
;; (define-key ido-mode-map " " 'ido-next-match)
;; )
;;
;; Seeing all the matching files
;;
;; If you have many matching files, they may not all fit onto one
;; line of the minibuffer. In this case, you should use rsz-mini
;; (resize-minibuffer-mode). You can also limit ido so that it
;; only shows a certain number of lines -- see the documentation for
;; `ido-minibuffer-setup-hook'.
;; Changing the list of files
;; By default, the list of current files is most recent first,
;; oldest last, with the exception that the files visible in the
;; current frame are put at the end of the list. A hook exists to
;; allow other functions to order the list. For example, if you add:
;;
;; (add-hook 'ido-make-buffer-list-hook 'ido-summary-buffers-to-end)
;;
;; then all files matching "Summary" are moved to the end of the
;; list. (I find this handy for keeping the INBOX Summary and so on
;; out of the way.) It also moves files matching "output\*$" to the
;; end of the list (these are created by AUC TeX when compiling.)
;; Other functions could be made available which alter the list of
;; matching files (either deleting or rearranging elements.)
;; Highlighting
;; The highlighting of matching items is controlled via ido-use-faces.
;; The faces used are ido-first-match-face, ido-only-match-face and
;; ido-subdir-face.
;; Colouring of the matching item was suggested by
;; Carsten Dominik ([email protected]).
;; Replacement for read-buffer
;; ido-read-buffer has been written to be a drop in replacement
;; for the normal buffer selection routine `read-buffer'. To use
;; iswitch for all buffer selections in Emacs, add:
;; (setq read-buffer-function 'ido-read-buffer)
;; (This variable was introduced in Emacs 20.3)
;; XEmacs users can get the same behaviour by doing:
;; (defalias 'read-buffer 'ido-read-buffer)
;; since `read-buffer' is defined in lisp.
;; Regexp matching
;; There is limited provision for regexp matching within ido,
;; enabled through `ido-enable-regexp'. This allows you to type `c$'
;; for example and see all file names ending in `c'. This facility
;; is quite limited though in two respects. First, you can't
;; currently type in expressions like `[0-9]' directly -- you have to
;; type them in when ido-enable-regexp is nil and then toggle on the
;; regexp functionality. Likewise, don't enter an expression
;; containing `\' in regexp mode. If you try, ido gets confused,
;; so just hit C-g and try again. Secondly, no completion mechanism
;; is currently offered when regexp searching.
;;; Code:
(provide 'ido)
;; CL needed for cadr and last
(if (not (and (fboundp 'cadr)
(fboundp 'last)))
(require 'cl))
;; Set up the custom library.
;; taken from http://www.dina.kvl.dk/~abraham/custom/
(eval-and-compile
(condition-case ()
(require 'custom)
(error nil))
(unless (fboundp 'defgroup)
(defmacro defgroup (&rest rest) ()))
(unless (fboundp 'defcustom)
(defmacro defcustom (sym val str &rest rest) `(defvar ,sym ,val ,str)))
(unless (fboundp 'defface)
(defmacro defface (sym val str &rest rest)
`(defvar ,sym (make-face ',sym) ,str)))
(unless (fboundp 'minibuffer-prompt-end)
(defun minibuffer-prompt-end () (point-min))))
;;; User Variables
;;
;; These are some things you might want to change.
(defun ido-fractionp (n)
(and (numberp n) (> n 0.0) (<= n 1.0)))
(defgroup ido nil
"Switch between files using substrings."
:group 'extensions
:group 'convenience
:link '(emacs-commentary-link :tag "Commentary" "ido.el")
:link '(emacs-library-link :tag "Lisp File" "ido.el"))
;;;###autoload
(defcustom ido-enabled nil
"Determines for which functional group \(buffer and files) ido behavior
should be enabled. The following values are possible:
- 'buffer: Turn only on ido buffer behavior \(switching, killing,
displaying...)
- 'file: Turn only on ido file behavior \(finding, writing, inserting...)
- 'both: Turn on ido buffer and file behavior.
- nil: Turn off any ido switching.
Setting this variable directly does not take effect;
use either \\[customize] or the function `ido-mode'."
:set #'(lambda (symbol value)
(ido-mode value))
:initialize 'custom-initialize-default
:require 'ido
:link '(emacs-commentary-link "ido.el")
;; :version "20.5"
:type '(choice (const :tag "Turn on only buffer" buffer)
(const :tag "Turn on only file" file)
(const :tag "Turn on both buffer and file" both)
(const :tag "Switch off all" nil))
:group 'ido)
(defcustom ido-case-fold case-fold-search
"*Non-nil if searching of buffer and file names should ignore case."
:type 'boolean
:group 'ido)
(defcustom ido-ignore-buffers
'("\\` ")
"*List of regexps or functions matching buffer names to ignore.
For example, traditional behavior is not to list buffers whose names begin
with a space, for which the regexp is `\\` '. See the source file for
example functions that filter buffernames."
:type '(repeat (choice regexp function))
:group 'ido)
(defcustom ido-ignore-files
'("\\`CVS/" "\\`#" "\\`.#" "\\`\\.\\./" "\\`\\./")
"*List of regexps or functions matching file names to ignore.
For example, traditional behavior is not to list files whose names begin
with a #, for which the regexp is `\\`#'. See the source file for
example functions that filter filenames."
:type '(repeat (choice regexp function))
:group 'ido)
(defcustom ido-ignore-extensions t
"*Non-nil means ignore files in completion-ignored-extensions list."
:type 'boolean
:group 'ido)
(defcustom ido-show-dot-for-dired nil
"*Non-nil means to always put . as the first item in file name lists.
This allows the current directory to be opened immediate with `dired'."
:type 'boolean
:group 'ido)
(defcustom ido-ignore-directories
'("\\`CVS/" "\\`\\.\\./" "\\`\\./")
"*List of regexps or functions matching sub-directory names to ignore."
:type '(repeat (choice regexp function))
:group 'ido)
(defcustom ido-ignore-directories-merge nil
"*List of regexps or functions matching directory path names to ignore during merge.
Directory paths matched by one of the regexps in this list are not inserted
in merged file and directory lists."
:type '(repeat (choice regexp function))
:group 'ido)
;;; Examples for setting the value of ido-ignore-buffers
;(defun ido-ignore-c-mode (name)
; "Ignore all c mode buffers -- example function for ido."
; (save-excursion
; (set-buffer name)
; (string-match "^C$" mode-name)))
;
;(setq ido-ignore-buffers '("^ " ido-ignore-c-mode))
;;; Examples for setting the value of ido-ignore-files
;(setq ido-ignore-files '("^ " "\\.c$" "\\.h$"))
(defcustom ido-default-file-method 'always-frame
"*How to switch to new file when using `ido-find-file'.
Possible values:
`samewindow' Show new file in same window
`otherwindow' Show new file in another window (same frame)
`display' Display file in another window without switching to it
`otherframe' Show new file in another frame
`maybe-frame' If a file is visible in another frame, prompt to ask if you
you want to see the file in the same window of the current
frame or in the other frame.
`always-frame' If a file is visible in another frame, raise that
frame. Otherwise, visit the file in the same window."
:type '(choice (const samewindow)
(const otherwindow)
(const display)
(const otherframe)
(const maybe-frame)
(const always-frame))
:group 'ido)
(defcustom ido-default-buffer-method 'always-frame
"*How to switch to new buffer when using `ido-switch-buffer'.
See ido-default-file-method for details."
:type '(choice (const samewindow)
(const otherwindow)
(const display)
(const otherframe)
(const maybe-frame)
(const always-frame))
:group 'ido)
(defcustom ido-enable-regexp nil
"*Non-nil means that `ido' will do regexp matching.
Value can be toggled within `ido' using `ido-toggle-regexp'."
:type 'boolean
:group 'ido)
(defcustom ido-enable-prefix nil
"*Nil means that `ido' will match if the inserted text is an
arbitrary substring (default). If non-nil `ido' will only match if the inserted
text is a prefix \(this behavior is like the standard unix- or
emacs-completion works).
Value can be toggled within `ido' using `ido-toggle-prefix'."
:type 'boolean
:group 'ido)
(defcustom ido-record-commands t
"*Non-nil means that `ido' will record commands in command history.
Note that the non-ido equivalent command is recorded."
:type 'boolean
:group 'ido)
(defcustom ido-max-prospects 12
"*Non-zero means that the prospect list will be limited to than number of items.
For a long list of prospects, building the full list for the minibuffer can take a
non-negletable amount of time; setting this variable reduces that time."
:type 'integer
:group 'ido)
(defcustom ido-max-prompt-path 0.35
"*Non-zero means that the prompt string be limited to than number of characters.
If value is a floating point number, it specifies a fraction of the frame width."
:type '(choice
(integer :tag "Characters" :value 20)
(restricted-sexp :tag "Fraction of frame width"
:value 0.35
:match-alternatives (ido-fractionp)))
:group 'ido)
(defcustom ido-max-window-height nil
"*Non-nil specifies a value to override `max-mini-window-height'."
:type '(choice
(const :tag "Don't override" nil)
(integer :tag "Number of lines" :value 1)
(restricted-sexp
:tag "Fraction of window height"
:value 0.25
:match-alternatives (ido-fractionp)))
:group 'ido)
(defcustom ido-enable-last-directory-history t
"*Non-nil means that `ido' will remember latest selected directory paths.
See `ido-last-directory-list' and `ido-save-directory-list-file'."
:type 'boolean
:group 'ido)
(defcustom ido-max-work-directory-list 50
"*Maximum number of working directories to record.
This is the list of directories where files have most recently been opened.
See `ido-work-directory-list' and `ido-save-directory-list-file'."
:type 'integer
:group 'ido)
(defcustom ido-work-directory-list-ignore-regexps nil
"*List of regexps matching directories which should not be recorded.
Directory paths matched by one of the regexps in this list are not inserted in
the `ido-work-directory-list' list."
:type '(repeat regexp)
:group 'ido)
(defcustom ido-record-ftp-work-directories t
"*Non-nil means that ftp paths are recorded in work directory list."
:type 'boolean
:group 'ido)
(defcustom ido-merge-ftp-work-directories nil
"*Nil means that ftp paths in work directory list are ignored during merge."
:type 'boolean
:group 'ido)
(defcustom ido-cache-ftp-work-directory-time 1.0
"*Maximum time to cache contents of an ftp directory (in hours).
If zero, ftp directories are not cached."
:type 'number
:group 'ido)
(defcustom ido-slow-ftp-hosts nil
"*List of slow ftp hosts where ido prompting should not be used.
If an ftp host is on this list, ido automatically switches to the non-ido
equivalent function, e.g. find-file rather than ido-find-file."
:type '(repeat string)
:group 'ido)
(defcustom ido-slow-ftp-host-regexps nil
"*List of regexps matching slow ftp hosts (see `ido-slow-ftp-hosts')."
:type '(repeat regexp)
:group 'ido)
(defcustom ido-max-work-file-list 10
"*Maximum number of names of recently opened files to record.
This is the list the file names (sans directory) which have most recently
been opened. See `ido-work-file-list' and `ido-save-directory-list-file'."
:type 'integer
:group 'ido)
(defcustom ido-work-directory-match-only t
"*Non-nil means to skip non-matching directories in the directory history.
When some text is already entered at the `ido-find-file' prompt, using
\\[ido-prev-work-directory] or \\[ido-next-work-directory] will skip directories
without any matching entries."
:type 'boolean
:group 'ido)
(defcustom ido-auto-merge-work-directories-length 0
"*Automatically switch to merged work directories during file name input.
The value is number of characters to type before switching to merged mode.
If zero, the switch happens when no matches are found in the current directory.
Automatic merging is disabled if the value is negative."
:type 'integer
:group 'ido)
(defcustom ido-auto-merge-delay-time 0.70
"*Delay in seconds to wait for more input before doing auto merge."
:type 'number
:group 'ido)
(defcustom ido-merged-indicator "^"
"The string appended to first choice if it has multiple directory choices."
:type 'string
:group 'ido)
(defcustom ido-max-dir-file-cache 100
"*Maximum number of working directories to be cached.
This is a cache of file-name-all-completions results.
See `ido-dir-file-cache' and `ido-save-directory-list-file'."
:type 'integer
:group 'ido)
(defcustom ido-rotate-file-list-default nil
"*Non-nil means that `ido' will always rotate file list to get default in front."
:type 'boolean
:group 'ido)
(defcustom ido-create-new-buffer 'prompt
"*Specify whether a new buffer is created if no buffer matches substring.
Choices are 'always to create new buffers unconditionally, 'prompt to
ask user whether to create buffer, or 'never to never create new buffer."
:type '(choice (const always)
(const prompt)
(const never))
:group 'ido)
(defcustom ido-define-mode-map-hook nil
"*Hook to define keys in `ido-mode-map' for extra keybindings."
:type 'hook
:group 'ido)
(defcustom ido-separator nil
"*String used by ido to separate the alternatives in the minibuffer.
Obsolete. Set 3rd element of `ido-decorations' instead."
:type 'string
:group 'ido)
(defcustom ido-decorations '( "{" "}" " | " " | ..." "[" "]" " [No match]" " [Matched]")
"*List of strings used by ido to display the alternatives in the minibuffer.
There are 8 elements in this list, each is a pair of strings:
1st and 2nd elements are used as brackets around the prospect list,
3rd element is the separator between prospects (ignored if ido-separator is set),
4th element is the string inserted at the end of a truncated list of prospects,
5th and 6th elements are used as brackets around the common match string which
can be completed using TAB,
7th element is the string displayed when there are a no matches, and
8th element displayed if there is a single match (and faces are not used)."
:type '(repeat string)
:group 'ido)
(defcustom ido-use-faces t
"*Non-nil means use ido faces to highlighting first match, only match and
subdirs in the alternatives."
:type 'boolean
:group 'ido)
(defface ido-first-match-face '((t (:bold t)))
"*Font used by ido for highlighting first match."
:group 'ido)
(defface ido-only-match-face '((((class color))
(:foreground "ForestGreen"))
(t (:italic t)))
"*Font used by ido for highlighting only match."
:group 'ido)
(defface ido-subdir-face '((((class color))
(:foreground "red"))
(t (:underline t)))
"*Font used by ido for highlighting subdirs in the alternatives."
:group 'ido)
(defface ido-indicator-face '((((class color))
(:foreground "yellow"
:background "red"
:width condensed))
(t (:inverse-video t)))
"*Font used by ido for highlighting its indicators."
:group 'ido)
(defcustom ido-make-file-list-hook nil
"*List of functions to run when the list of matching files is created.
Each function on the list may modify the dynamically bound variable
`ido-temp-list' which contains the current list of matching files."
:type 'hook
:group 'ido)
(defcustom ido-make-dir-list-hook nil
"*List of functions to run when the list of matching directories is created.
Each function on the list may modify the dynamically bound variable
`ido-temp-list' which contains the current list of matching directories."
:type 'hook
:group 'ido)
(defcustom ido-make-buffer-list-hook nil
"*List of functions to run when the list of matching buffers is created.
Each function on the list may modify the dynamically bound variable
`ido-temp-list' which contains the current list of matching buffer names."
:type 'hook
:group 'ido)
(defcustom ido-make-file-prompt-hook nil
"*List of functions to run when the find-file prompt is created.
Each function on the list may modify the following dynamically bound
variables:
path - the (abbreviated) directory path
max-width - the max width of the path; set to nil to inhibit truncation
prompt - the basic prompt (e.g. \"Find File: \")
literal - the string shown if doing `literal' find; set to nil to omit
vc-off - the string shown if version control is inhibited; set to nit to omit
prefix - normally nil, but may be set to a fixed prefix for the path
The following variables are available, but should not be changed:
ido-current-directory - the unabbreviated directory path
item - equals 'file or 'dir depending on the current mode."
:type 'hook
:group 'ido)
(defvar ido-rewrite-prompt-path-rules nil
"*Alist of rewriting rules for file paths.
A list of elements of the form (FROM . TO) or (FROM . FUNC),
each meaning to rewrite the path if matched by FROM by either
substituting the matched string by TO or calling the function
FUNC with the current path as its only argument and using the
return value as the new path. In addition, each FUNC may
also modify the dynamic variables described for the
variable `ido-make-file-prompt-hook'.")
(defcustom ido-completion-buffer "*Ido Completions*"
"*Name of completion buffer used by ido.
Set to nil to disable completion buffers popping up."
:type 'string
:group 'ido)
(defcustom ido-completion-buffer-all-completions nil
"*Non-nil means to show all completions in completion buffer.
Otherwise, only the current list of matches is shown."
:type 'boolean
:group 'ido)
(defvar ido-all-frames 'visible
"*Argument to pass to `walk-windows' when finding visible files.
See documentation of `walk-windows' for useful values.")
(defcustom ido-minibuffer-setup-hook nil
"*Ido-specific customization of minibuffer setup.
This hook is run during minibuffer setup iff `ido' will be active.
It is intended for use in customizing ido for interoperation
with other packages. For instance:
\(add-hook 'ido-minibuffer-setup-hook
\(function
\(lambda ()
\(make-local-variable 'resize-minibuffer-window-max-height)
\(setq resize-minibuffer-window-max-height 3))))
will constrain rsz-mini to a maximum minibuffer height of 3 lines when
ido is running. Copied from `icomplete-minibuffer-setup-hook'."
:type 'hook
:group 'ido)
(defvar ido-save-directory-list-file "~/.ido.last"
"File in which the ido state is saved between invocations.
Variables stored are: ido-last-directory-list and ido-work-directory-list.
Must be set before enabling ido mode.")
;;; Internal Variables
;; Persistent variables
(defvar ido-mode-map nil
"Keymap for `ido-find-file' and `ido-switch-buffer'.")
(defvar ido-file-history nil
"History of files selected using `ido-find-file'.")
(defvar ido-buffer-history nil
"History of buffers selected using `ido-switch-buffer'.")
(defvar ido-xemacs (string-match "XEmacs" (emacs-version))
"Non-nil if we are running XEmacs. Otherwise, assume we are running Emacs.")
(defvar ido-last-directory-list nil
"List of last selected directory paths.
See `ido-enable-last-directory-history' for details.")
(defvar ido-work-directory-list nil
"List of actual working directory paths.
The current directory is inserted at the front of this list whenever a
file is opened with ido-find-file and family.")
(defvar ido-work-file-list nil
"List of actual work file names.
The current file name (sans path) is inserted at the front of this list
whenever a file is opened with ido-find-file and family.")
(defvar ido-dir-file-cache nil
"List of file-name-all-completions results.
Each element in the list is of the form (dir (mtime) file...).")
;; Temporary storage
(defvar ido-eoinput 1
"Point where minibuffer input ends and completion info begins.
Copied from `icomplete-eoinput'.")
(make-variable-buffer-local 'ido-eoinput)
(defvar ido-common-match-string nil
"Stores the string that is common to all matching files.")
(defvar ido-rescan nil
"Non-nil means we need to regenerate the list of matching items.")
(defvar ido-rotate nil
"Non-nil means we are rotating list of matches.")
(defvar ido-text nil
"Stores the users string as it is typed in.")
(defvar ido-text-init nil
"The initial string for the users string it is typed in.")
(defvar ido-matches nil
"List of files currently matching `ido-text'.")
(defvar ido-report-no-match t
"Report [No Match] when no completions matches ido-text.")
(defvar ido-exit nil
"Flag to monitor how `ido-find-file' exits.
If equal to `takeprompt', we use the prompt as the file name to be
selected.")
(defvar ido-current-directory nil
"Current directory for ido-find-file.")
(defvar ido-auto-merge-timer nil
"Delay timer for auto merge.")
;; The following variables are dynamic variables created by ido,
;; but they are declared here to keep the byte compiler quiet.
(eval-when-compile
(defvar ido-cur-item nil
"Stores the current ido item type ('file, 'dir or 'buffer).")
(defvar ido-cur-list nil
"Stores the current list of items that will be searched through.
The list is ordered, so that the most interesting item comes first,
although by default, the files visible in the current frame are put
at the end of the list. Created by `ido-make-item-list'.")
(defvar ido-ignored-list nil
"Stores the list of items which are ignored when building `ido-cur-list'.
It is in no specific order.")
(defvar ido-keep-item-list nil
"Keep current item list if non-nil")
(defvar ido-use-mycompletion-depth 0
"Non-nil means use `ido' completion feedback.
Is set by ido functions to the current minibuffer-depth, so that
it doesn't interfere with other minibuffer usage.")
(defvar ido-process-ignore-lists t
"Process ido-ignore- lists.")
(defvar ido-process-ignore-lists-inhibit nil
"Don't process ido-ignore- lists once.")
(defvar ido-default-item nil
"Default item for ido.")
(defvar ido-entry-buffer nil
"Buffer from which ido was entered.")
(defvar ido-require-match nil
"Non-nil if matching file must be selected.")
(defvar ido-temp-list nil
"Stores a temporary version of the file list being created.")
(defvar ido-rotate-temp nil
"Non-nil if default list element should be rotated into place.")
(defvar ido-work-directory-index nil
"Stores current index in ido-work-directory-list.")
(defvar ido-use-merged-list nil
"Set when merged work directory list is in use.")
(defvar ido-try-merged-list t
"Set when merged work directory list not yet built.")
(defvar ido-pre-merge-state nil
"Saved state prior to last work directory merge.
Value is a list (ido-text dir cur-list ignored-list matches).")
(defvar ido-work-file-index nil
"Stores current index in ido-work-file-list.")
(defvar ido-bufs-in-frame nil
"List of the files visible in the current frame.")
(defvar ido-change-word-sub nil
"Private variable used by `ido-word-matching-substring'.")
(defvar ido-saved-vc-mt nil
"Original value of vc-master-templates for use in ido-toggle-vc.")
(defvar ido-find-literal nil
"Stores temporary state of literal find file.")
)
;;; FUNCTIONS
(defun ido-active (&optional merge)
(if merge
ido-use-merged-list
(and (boundp 'ido-completing-read) (= ido-use-mycompletion-depth (minibuffer-depth)))))
(defvar ido-trace-enable nil)
(defun ido-trace (p &optional s retval)
(if ido-trace-enable
(let ((b (get-buffer-create " *IDO Trace*"))
(deactivate-mark deactivate-mark))
(save-excursion
(save-restriction
(set-buffer b)
(insert p ": " (if (stringp s) s (format "%S" s)) "\n")))))
retval)