-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor-moccur.el
3806 lines (3457 loc) · 129 KB
/
color-moccur.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
;;; color-moccur.el --- multi-buffer occur (grep) mode
;; -*- Mode: Emacs-Lisp -*-
;; $Id: color-moccur.el,v 2.73 2010-07-23 23:52:29 Akihisa Exp $
;; This program 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 3, or (at
;; your option) any later version.
;; This program 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., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;;; for hi-lock
;; Hi-lock: (("^;;; .*" (0 (quote hi-black-hb) t)))
;; Hi-lock: (("^;;;; .*" (0 (quote hi-black-b) t)))
;; Hi-lock: (("make-variable-buffer-\\(local\\)" (0 font-lock-keyword-face)(1 'italic append)))
;; Hi-lock: end
;;; Commentary:
;; If this program doesn't run, I might change the program for the
;; worse. So please send mail to [email protected] .
;; This elisp is the extention of moccur.el.
;; Thanks to the authors for writing moccur.el
;; With color-moccur, you can search a regexp in all buffers. And you
;; can search files like grep(-find) without grep (and find) command.
;;; Motivation
;; moccur is a major mode modelled after the 'Occur' mode of the
;; standard distribution. It is quite nice to use when you need to
;; work with a lot of buffers.
;;
;; Incompatibilites to Occur mode:
;; a) it browses through *all* buffers that have a file name
;; associated with them; those may or may not include the current
;; buffer. Especially, while standard occur works
;; on 'all lines following point', Moccur does not.
;; b) there is no support for the 'NLINE' argument.
;;; Install:
;; Put this file into load-path'ed directory, and byte compile it if
;; desired. And put the following expression into your ~/.emacs.
;;
;; (require 'color-moccur)
;; The latest version of this program can be downloaded from
;; http://www.bookshelf.jp/elc/color-moccur.el
;; moccur-edit.el
;; With this packege, you can edit *moccur* buffer and apply
;; the changes to the files.
;; You can get moccur-edit.el at
;; http://www.bookshelf.jp/elc/moccur-edit.el
;;; Functions
;; moccur, dmoccur, dired-do-moccur, Buffer-menu-moccur,
;; grep-buffers, search-buffers, occur-by-moccur
;; isearch-moccur
;; moccur-grep, moccur-grep-find
;;; usage:moccur
;; moccur <regexp> shows all occurrences of <regexp> in all buffers
;; currently existing that refer to files.
;; The occurrences are displayed in a buffer running in Moccur mode;
;;;; keybind
;; C-c C-c or RET gets you to the occurrence
;; q : quit
;; <up>, n, j : next matches
;; <down>, p, k : previous matches
;; b :scroll-down in matched buffer
;; SPC : scroll-up in matched buffer
;; M-v :scroll-down in moccur buffer
;; C-v : scroll-up in moccur buffer
;; < : M-< in matched buffer
;; > : M-> in matched buffer
;; t : toggle whether a searched buffer is displayed to other window.
;; r : re-search in only matched buffers.
;; d,C-k : kill-line
;; M-x moccur-flush-lines : flush-lines for moccur
;; M-x moccur-keep-lines : keep-lines for moccur
;; / : undo (maybe doesn't work)
;; s : run moccur by matched bufffer only.
;; u : run moccur by prev condition
;;; usage:moccur-grep, moccur-grep-find
;; moccur-grep <regexp> shows all occurrences of <regexp> in files of current directory
;; moccur-grep-find <regexp> shows all occurrences of <regexp>
;; in files of current directory recursively.
;;
;;;; Variables of M-x moccur-grep(-find)
;; dmoccur-exclusion-mask : if filename matches the regular
;; expression, dmoccur/moccur-grep *doesn't* open the file.
;;
;; dmoccur-maximum-size: Maximum size (kB) of a buffer for dmoccur and
;; moccur-grep(-find).
;;
;; moccur-following-mode-toggle :
;; If this value is t, cursor motion in the moccur buffer causes
;; automatic display of the corresponding buffer location.
;;
;; moccur-grep-following-mode-toggle :
;; If this value is t, cursor motion in the moccur-grep buffer causes
;; automatic display of the corresponding source code location.
;;
;; moccur-grep-default-word-near-point :
;; If this value is t, moccur-grep(-find) command get a word near the
;; point as default regexp string
;;
;; moccur-grep-default-mask :
;; example in .emacs: (setq-default moccur-grep-default-mask ".el")
;; File-mask string used for default in moccur-grep and moccur-grep-find
;; Run moccur-grep, and chose directory, in minibuffer, following text is displayed
;; Input Regexp and FileMask: .el
;;; usage:isearch-moccur
;; isearch and M-o
;; Run `moccur' with current isearch string.
;; isearch and M-O
;; Run `moccur' with current isearch string in all buffers.
;;; usage:M-x occur-by-moccur
;; suearch current buffer by moccur
;;; usage:Buffer-menu-moccur
;; `Buffer-menu-moccur' command searches buffers marked in
;; buffer-menu or ibuffer.
;;; usage:dired-do-moccur
;; Search through all marked files in dired buffer.
;;; usage:search-buffers <regexp>
;; junk tool. To search all buffers, type in
;; a few descriptive words like "setq gnus" hit the 'enter' key.
;; This program only returns web pages that contain all the words in
;; your query. And Type RET in the result buffer to call moccur.
;;; usage:grep-buffers <regexp>
;; Run grep on all visited files.
;;; usage:M-x dmoccur
;; dmoccur opens files under current directory, and searches your
;; regular expression by moccur.
;;;; Variables of M-x dmoccur
;; dmoccur-mask : if filename matches the regular expression, dmoccur
;; opens the file.
;; dmoccur-exclusion-mask : if filename matches the regular
;; expression, dmoccur/moccur-grep *doesn't* open the file.
;; dmoccur-maximum-size : Only buffers less than this can be opend.
;;;; C-u M-x dmoccur
;; Probably you will search same directory many times. So dmoccur has
;; your favorite directory list. And if you input a name, dmoccur can
;; search files under a directory.
;;;; variable:dmoccur-mask
;; dmoccur-mask is masks for searched file. defult is (".*").
;;;; variable:dmoccur-maximum-size
;; Maximum size (kB) of a searched buffer by dmoccur.
;;;; variable:dmoccur-exclusion-mask
;; dmoccur-exclusion-mask is masks for *not* searched file by dmoccur and moccur-grep(-find).
;;;; Variables of C-u M-x dmoccur
;; dmoccur-list : Your favorite directory list. This valiable is used
;; as bellow.
;; (setq dmoccur-list
;; '(
;; ;;name directory mask option
;; ("dir" default-directory (".*") dir)
;; ("config" "~/mylisp/" ("\\.js" "\\.el$") nil)
;; ("multi" (("~/mylisp/")
;; ("~/lisp/")) ("\\.js" "\\.el$") nil)
;; ("emacs" "d:/unix/emacs/" (".*") sub)
;; ))
;; name : Input your favorite name
;; directory : Directory you'd like to search
;; mask : list of file-mask (regular expression).
;; option : usually option is nil. If option is "dir", you can select
;; directory like find-file. If option is "sub", you can select sub
;; directory.
;; Moreover you can also customize dmoccur-list as bellow.
;; (setq dmoccur-list
;; '(
;; ;; multi-directory can be setted if option is nil
;; ("soft"
;; (
;; ("~/www/soft/")
;; ("~/mylisp/")
;; )
;; ("\\.texi$") nil)
;;
;; ;; In ~/mylisp, dmoccur search files recursively.
;; ;; and dmoccur search files in ~/user.
;; ("test-recursive"
;; (("~/mylisp" t)
;; ("~/user"))
;; (".*") nil)
;;
;; ;; In ~/mylisp, dmoccur search files recursively
;; ;; but if (string-match ".+.txt" filename)
;; ;; or (string-match ".+.el" filename) is t,
;; ;; the file is *not* searched.
;; ("ignore-txt"
;; (("~/mylisp" t (".+.txt" ".+.el"))
;; ("~/user"))
;; (".*") nil)
;;
;; ;; if option is dir (or sub),
;; ;; you can set single directory only.
;; ("dir-recursive" ((default-directory t)) (".*") dir)
;; ))
;;; variables
;;;; moccur-split-word
;; non-nil means to input word splited by space. You can search
;; "defun color-moccur (regexp)" by "defun regexp" or "regexp defun".
;; You don't need to input complicated regexp.
;; And you can search "defun" in buffers whose name match "moccur".
;;;; dmoccur-use-list
;; if non-nill, M-x dmoccur is equal to C-u M-x dmoccur.
;;;; dmoccur-use-project
;; dmoccur need a name of dmoccur-list. If dmoccur-use-project is nil,
;; you have to type a name every time. If dmoccur-use-project is
;; non-nil and you searched current buffer by a name of dmoccur,
;; dmoccur use the name.
;;;; moccur-use-ee
;; non-nil means to display a result by ee.
;; ee: http://www.jurta.org/emacs/ee/
;; if you use allout.el, it's not displayed by ee.
;;; sample settings
;; (load "color-moccur")
;; (setq *moccur-buffer-name-exclusion-list*
;; '(".+TAGS.+" "*Completions*" "*Messages*"
;; "newsrc.eld" ".bbdb"))
;; (setq moccur-split-word t)
;; (setq dmoccur-use-list t)
;; (setq dmoccur-use-project t)
;; (setq dmoccur-list
;; '(
;; ("dir" default-directory (".*") dir)
;; ("soft" "~/www/soft/" ("\\.texi$") nil)
;; ("config" "~/mylisp/" ("\\.js" "\\.el$") nil)
;; ("1.99" "d:/unix/Meadow2/1.99a6/" (".*") sub)
;; ))
;; (global-set-key "\C-x\C-o" 'occur-by-moccur)
;; (define-key Buffer-menu-mode-map "O" 'Buffer-menu-moccur)
;; (define-key dired-mode-map "O" 'dired-do-moccur)
;; (global-set-key "\C-c\C-x\C-o" 'moccur)
;; (global-set-key "\M-f" 'grep-buffers)
;; (global-set-key "\C-c\C-o" 'search-buffers)
;;; Furthermore
;;;; Function for regexp
;; (moccur-set-regexp)
;; function to set up regexp.
;; if moccur-split-word is non-nil,
;; *moccur-regexp-list* is list of regexp.
;; ex. "defun search" -> moccur-regexp-list = '("defun" "search")
;; "^[ ]+( search" -> moccur-regexp-list = '("^[ ]+(" "search")
;;;; Search Function
;; (moccur-search-line <regexp>) : my original function.
;; basically (re-search-forward regexp nil t) (default)
;; If moccur-split-word is non-nil,
;; regexp for *moccur-search-line* is created by *moccur-set-regexp*
;; and *moccur-search-line* returns lines that include all of your search terms.
;; ex. (moccur-search-line "moccur defun line") matches
;; (defun moccur-search-line
;; and
;; (defun test () (moccur-search-line regexp))
;; (moccur-search-buffer (&optional regexp currbuf name))
;; Search <regexp> in <currbuf>, and output result.
;; Special feature
;; if moccur-split-word is non-nil, first word is special.
;; if first word is ";", that is, "; function",
;; moccur-search-buffer returns lines that is comment.
;; "! function" -> return lines that is function.
;; "" string" -> return lines that is string.
;; "/ comment" -> return lines that is comment.
;; moccur-set-regexp
;; convert regexp for moccur.
;; if moccur-use-keyword is non-nil and
;; keyword of moccur-search-keyword-alist is in regexp,
;; convert keyword to <regexp>
;; ex. "url" -> "[fht]*ttp://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+"
;;; Idea and Todo
;; if you have idea or function you want,
;; please mail to [email protected]
;;
;; Document
;; --> Add doc-string :)
;; --> defvar to defcustom
;;
;; Search
;; --> speed up
;; --> restrict ee
;; --> ee is slow, if count of matches is large
;; --> moccur stop, if result is large
;; --> search word
;; --> use history like \1 (latest word)
;; --> multiline search
;;
;; Buffers
;; --> M-x dmoccur M-x moccur : many buffers are displayed
;; --> I'd like to make variable to select buffers to search.
;; --> e.g. if current buffer is emacs-lisp-mode,
;; buffers which is emacs-lisp-mode are searched in moccur.
;;
;; Usability
;; --> in moccur buffer, I have to type "lllllll" or "C-u 7 l".
;; I'd like to change to displayed buffer like iswitch.
;; --> matched buffer list
;; --> add keybind (e.g. mouse...)
;;
;; moccur buffer
;; --> Add sort method (now alphabetic order of buffer-name)
;; --> probably
;; buffers with same major-mode have relations...
;; files in same directory have relations
;; same extention?
;;
;; Bug
;; --> with ee, can't undo step by step
;;
;; dmoccur
;; --> very difficult
;; --> Add dired-d:/home/memo/, when I searched in a directory.
;; --> customize buffer-menu.
;; with many buffers, buffer-menu overflow.
;;; History:
;; 2010/05/06
;; Add user variable (moccur-following-mode-toggle)
;; 2010/04/14
;; Bug fix
;; I changed next-line to forward-line in moccur-prev and moccur-next
;; 2010/02/23
;; Bug fix.
;; line 2199
;; (cdr (reverse inputs))) -> (reverse (cdr (reverse inputs))))
;; Thanks for patch!
;; 2008/7/27
;; Bug fix.
;; Add wheel mouse keybind.
;; 2008/7/25
;; Turned (back) on the key binding "t" to "moccur-toggle-view" command in moccur-grep-mode
;; Command "moccur-narrow-down" now also works in moccur-grep-mode.
;; Thanks Mr. Lin. Your changes are great.
;; 2007/12/22
;; Add command "g" (moccur-search-update) in *moccur* buffer
;; Abd bug fix (Thanks Mr. Lin)
;; 2007/12/16
;; Add command "u" (moccur-search-undo) in *moccur* buffer
;; Update regexp (Thanks Mr. Lin)
;; 2007/09/05
;; Remove obsolete function
;; 2005/11/16
;; Add option:moccur-grep-following-mode-toggle
;; 2004/09/23
;; Bug fix
;; 2004/04/30
;; Add moccur-grep and moccur-grep-find
;; 2004/01/13
;; defvar -> defcustom
;; 2004/01/05
;; Add moccur-search-keyword-alist
;; 2003/12/24
;; changed value of *moccur-buffer-name-exclusion-list*
;; New functions:isearch-moccur-all ("M-O" isearch-mode-map)
;; Add moccur-kill-buffer-after-goto
;; 2003/12/17
;; Bug fix: moccur-prev didn't move the cursor to another buffer.
;; Bug fix: if moccur-split-word is nil, special-word was used.
;; 2003/12/16
;; Update: moccur-color-view
;; Update: search-buffers-mode
;; RET: changed search-buffers-goto to search-buffers-call-moccur
;; 2003/12/15
;; Bug fix: moccur-split-string
;; 2003/12/12
;; dmoccur-list: can set file-name instead of directory
;; sample
;; (setq dmoccur-list
;; '(
;; ("memo" (("~/clmemo.txt") ;; filename
;; ("~/memo/" t) ;; directory
;; ) (".*") nil nil)
;; ))
;; Removed internal variable, moccur-regexp
;; New variable: moccur-special-word-list
;; if moccur-split-word is t, first word is special.
;; Example:
;; List lines matching regexp: ; moccur
;; This regexp matches comment only.
;; List lines matching regexp: " moccur
;; This regexp matches string only like "moccur"
;; List lines matching regexp: ! moccur
;; This regexp matches function only like defun moccur.
;; 2003/11/30
;; New functions:occur-by-moccur,isearch-moccur
;; 2003/11/28
;; Bug fix: if moccur-split-word is t, when "[" is searched, error
;; 2003/11/26
;; Bug fix: set kill-buffer-after-dired-do-moccur to t and run
;; dired-do-moccur. After that, if you run moccur, buffers were killed.
;; New function:
;; In dired buffer, if a directory is marked and you run
;; dired-do-moccur, you can search files in the directory.
;; 2003/11/25
;; Upgrade many functions. But I can't remember changes :)
;; 2003/06/13
;; Matsushita Akihisa <[email protected]> improved moccur.
;; Add dmoccur, dired-do-moccur, Buffer-menu-moccur, and so on.
;; 2002 or 2003
;; color-moccur 1.0 was released to the net
;; moccur 1.0 was released to the net on August 1st, 1991
;; [email protected] (Craig Steury) provided the exclusion list
;; facility, which was changed to to regexps and enhanced with a
;; inclusion list.
;;; Code:
(eval-when-compile (require 'cl))
(defgroup color-moccur nil
"Customize color-moccur"
:group 'matching)
;;; variables
;;;; user variables
(defface moccur-face
'((((class color)
(background dark))
(:background "light grey" :bold t :foreground "Black"))
(((class color)
(background light))
(:background "light cyan" :bold t))
(t
()))
"*Face used by moccur to show the text that matches."
:group 'color-moccur
)
(defface moccur-current-line-face
'((((class color)
(background dark))
(:underline t))
(((class color)
(background light))
(:underline t))
(t
()))
"*Face used by moccur."
:group 'color-moccur
)
(defcustom moccur-kill-moccur-buffer nil
"*Non-nil means to kill *Moccur* buffer automatically when you exit *Moccur* buffer."
:group 'color-moccur
:type 'boolean
)
(defcustom moccur-use-migemo nil
"*Non-nil means to use migemo (for Japanese). migemo.el is required."
:group 'color-moccur
:type 'boolean
)
(defcustom moccur-split-word nil
"*Non-nil means means to input word splited by space.
You can search \"defun color-moccur (regexp)\" by \"defun regexp\" or
\"regexp defun\". You don't need to input complicated regexp. But
you can not input regexp including space.."
:group 'color-moccur
:type 'boolean
)
(defcustom color-moccur-default-ime-status t
"*Non-nil means to inherit ime status."
:group 'color-moccur
:type 'boolean
)
(defcustom *moccur-buffer-name-exclusion-list*
'("TAGS" "*Completions*" "*Messages*" "^[ ].+")
"Contains a list of regexps which don't search by moccur.
Matching buffers are *not* searched for occurrences. Per default, the
TAGS file is excluded."
:group 'color-moccur
:type '(repeat regexp)
)
(defcustom *moccur-buffer-name-inclusion-list* '("[^ ].*")
"Contains a list of regexps. *Only* matching buffers are searched.
Per default, this var contains only a \".*\" catchall-regexp."
:group 'color-moccur
:type '(repeat regexp)
)
(defcustom dmoccur-mask '(".*")
"Mask for dmoccur."
:group 'color-moccur
:type '(repeat regexp)
)
(defcustom dmoccur-maximum-size nil
"*Maximum size (kB) of a buffer for dmoccur and moccur-grep(-find)."
:group 'color-moccur
:type '(choice
number
(const :tag "infinite" nil))
)
(defcustom dmoccur-exclusion-mask
'( ;; binary
"\\.elc$" "\\.exe$" "\\.dll$" "\\.lib$" "\\.lzh$"
"\\.zip$" "\\.deb$" "\\.gz$" "\\.pdf$" "\\.tar$"
"\\.gz$" "\\.7z$" "\\.o$" "\\.a$" "\\.mod$"
"\\.nc$" "\\.obj$" "\\.ai$" "\\.fla$" "\\.swf$"
"\\.dvi$" "\\.pdf$" "\\.bz2$" "\\.tgz$" "\\.cab$"
"\\.sea$" "\\.bin$" "\\.fon$" "\\.fnt$" "\\.scr$"
"\\.tmp$" "\\.wrl$" "\\.Z$"
;; sound & movie
"\\.aif$" "\\.aiff$" "\\.mp3$" "\\.wma$" "\\.mpg$"
"\\.mpeg$" "\\.aac$" "\\.mid$" "\\.au$" "\\.avi$" "\\.dcr$"
"\\.dir$" "\\.dxr$" "\\.midi$" "\\.mov$" "\\.ra$" "\\.ram$"
"\\.vdo$" "\\.wav$"
;; Microsoft
"\\.doc$" "\\.xls$" "\\.ppt$" "\\.mdb$" "\\.adp$"
"\\.wri$"
;; image
"\\.jpg$" "\\.gif$" "\\.tiff$" "\\.tif$" "\\.bmp$"
"\\.png$" "\\.pbm$" "\\.jpeg$" "\\.xpm$" "\\.pbm$"
"\\.ico$" "\\.eps$" "\\.psd$"
;;etc
"/TAGS$"
;; backup file
"\\~$"
;; version control
"\\.svn/.+" "CVS/.+" "\\.git/.+"
)
"*List of file extensions which are excepted to search by dmoccur and moccur-grep(-find)."
:group 'color-moccur
:type '(repeat regexp)
)
(defcustom dmoccur-use-list nil
"Non-nil means to use your favorite directory list."
:group 'color-moccur
:type 'boolean
)
(defcustom dmoccur-use-project nil
"Non-nil means to use your favorite directory list."
:group 'color-moccur
:type 'boolean
)
(defcustom moccur-use-ee nil
"Non-nil means to use ee. However, this feature doesn't work now"
:group 'color-moccur
:type 'boolean
)
(defcustom kill-buffer-after-dired-do-moccur nil
"Non-nil means to kill buffer after dired do moccur."
:group 'color-moccur
:type 'boolean
)
(defcustom dmoccur-list
'(
;; name directory mask option
;; option = nil , dir , sub
("dir" default-directory (".*") dir)
("lisp" "~/mylisp/" ("\\.el" "\\.*texi") nil))
"*List of directory which are searched by dmoccur."
:group 'color-moccur
:type '(repeat
(list (string :tag "Name")
(choice
(directory :tag "Directory")
(file :tag "Filename")
(symbol :tag "Variable")
(repeat :tag "Advanced setting"
(list
(choice
(directory :tag "Directory")
(symbol :tag "Variable"))
(boolean :tag "Recursively" nil)
(repeat :tag "File Mask"
(regexp :tag "File Mask not to search")))))
(repeat :tag "File Mask" :default nil
(regexp :tag "File Mask" ".*"))
(choice :tag "Option" :default nil
(const :tag "Default" nil)
(const :tag "Directory" dir)
(const :tag "Subdirectory" sub))
(choice :tag "Control Migemo and Split" :default nil
(const :tag "Default" nil)
(list (boolean :tag "Use Migemo" nil)
(boolean :tag "Split Regexp" nil)))
(choice :tag "Default regexp" :default nil
(const :tag "Empty" nil)
(string :tag "Regexp" "")
(symbol :tag "Function to make regexp")))))
(defcustom moccur-maximum-displayed-with-color 500
"Max number that is displayed with color."
:group 'color-moccur
:type 'number
)
(defcustom dmoccur-recursive-search nil
"Non-nil means to search files recursively."
:group 'color-moccur
:type 'boolean
)
(defcustom moccur-buffer-sort-method 'moccur-filepath-string<
"Function to sort buffers."
:group 'color-moccur
:type 'symbol
)
(defcustom moccur-special-word-list
'(
(";"
moccur-face-initialization
moccur-comment-check)
("/"
moccur-face-initialization
moccur-comment-check)
("\""
moccur-face-initialization
moccur-string-check)
("!"
moccur-face-initialization
moccur-function-check)
(t ;; default
moccur-default-initial-function
moccur-default-check-function
)
)
"Special-word function-to-initialize function-to-check."
:group 'color-moccur
:type '(repeat
(list (choice (string :tag "Keyword")
(const :tag "Default" t))
(symbol :tag "Function to initialize")
(symbol :tag "Function to check")
)))
(defcustom moccur-kill-buffer-after-goto nil
"Non-nil means to kill *moccur* buffer after goto-occurrence."
:group 'color-moccur
:type 'boolean
)
(defcustom moccur-search-keyword-alist
'(("url" . "[fht]*ttp://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+")
("mail" . "[^][<>@ \n]+@[-_!~*'()a-zA-Z0-9?@&=+$,%#]+\\.[-_.!~*'()a-zA-Z0-9?@&=+$,%#]+"))
"*Alist of KEYWORD and REGEXP."
:group 'color-moccur
:type '(repeat
(cons (string :tag "Keyword")
(regexp :tag "Regexp"))))
(defcustom moccur-use-keyword nil
"Non-nil means to use moccur-search-keyword-alist."
:group 'color-moccur
:type 'boolean
)
(defcustom moccur-use-xdoc2txt
(if
(and
(locate-library "xdoc2txt.exe" nil exec-path)
(if (file-name-extension shell-file-name)
(locate-library shell-file-name nil exec-path)
(locate-library (concat shell-file-name ".exe") nil exec-path)))
t
nil)
"Non-nil means to use xdoc2txt.
xdoc2txt is Windows software to convert Word/Excel/PDF etc to Text file.
http://www31.ocn.ne.jp/~h_ishida/xdoc2txt.html (Japanese site)"
:group 'color-moccur
:type 'boolean
)
(defcustom moccur-grep-xdoc2txt-maximum-size 1000
"*Maximum size (kB) of a buffer for xdoc2txt."
:group 'color-moccur
:type 'number
)
(defcustom moccur-grep-xdoc2txt-exts '(
"\\.rtf" "\\.doc" "\\.xls" "\\.ppt"
"\\.jaw" "\\.jtw" "\\.jbw" "\\.juw"
"\\.jfw" "\\.jvw" "\\.jtd" "\\.jtt"
"\\.oas" "\\.oa2" "\\.oa3" "\\.bun"
"\\.wj2" "\\.wj3" "\\.wk3" "\\.wk4"
"\\.123" "\\.wri" "\\.pdf" "\\.mht")
"*List of file extensions which are handled by xdoc2txt."
:type '(repeat string)
:group 'Meadow-Memo)
(defcustom moccur-following-mode-toggle t
"When t, cursor motion in the moccur buffer causes
automatic display of the corresponding buffer location."
:group 'color-moccur
:type 'boolean)
(defcustom moccur-grep-following-mode-toggle t
"When t, cursor motion in the moccur-grep buffer causes
automatic display of the corresponding source code location."
:group 'color-moccur
:type 'boolean)
(defcustom moccur-grep-default-word-near-point nil
"When t, get a word near the point as default regexp string"
:group 'color-moccur
:type 'boolean)
(defvar moccur-grep-default-mask nil
"File-mask string used for default in moccur-grep and moccur-grep-find")
(make-variable-buffer-local 'moccur-grep-default-mask)
;;; Internal variables
;;;; moccur
(defvar moccur-buffer-heading-regexp "^[-+ ]*Buffer: \\([^\r\n]+\\) File: \\([^\r\n]+\\)$"
"Regexp for matching buffer heading line in moccur-mode buffer.")
(defvar moccur-grep-buffer-heading-regexp "^[-+ ]*Buffer: File (grep): \\([^\r\n]+\\)$"
"Regexp for matching buffer heading line in moccur-grep-mode buffer.")
(defvar moccur-line-number-regexp "^[ ]*\\([0-9]+\\) "
"Regexp for matching line numbers in moccur buffer.")
(defvar regexp nil)
(defvar moccur-list nil)
(defvar moccur-overlays nil)
(make-variable-buffer-local 'moccur-overlays)
(defvar moccur-current-line-overlays nil)
(defvar moccur-regexp-color "")
(defvar moccur-regexp-list nil)
(defvar moccur-file-name-regexp nil)
(defvar moccur-regexp-input "")
(defvar moccur-buffer-name "")
(defvar moccur-buffer-match-count nil)
(defvar moccur-before-buffer-name "")
(defvar moccur-line nil)
(defvar buffer-menu-moccur nil)
(defvar moccur-view-other-window t)
(make-variable-buffer-local 'moccur-view-other-window)
(defvar moccur-view-other-window-nobuf t)
(make-variable-buffer-local 'moccur-view-other-window-nobuf)
(defvar moccur-current-buffer nil)
(defvar moccur-buffer-position nil)
(make-variable-buffer-local 'moccur-buffer-position)
(defvar moccur-buffers nil)
(defvar moccur-match-buffers nil)
(defvar moccur-buffers-before-moccur nil)
(defvar moccur-matches nil)
(defvar moccur-mocur-buffer nil)
(defvar moccur-last-command nil)
(defvar moccur-windows-conf nil)
(defvar moccur-special-word nil)
(defvar moccur-fontlock-buffer nil)
(make-variable-buffer-local 'moccur-fontlock-buffer)
;;;; dmoccur
(defvar dmoccur-mask-internal nil)
(defvar dmoccur-history nil)
(defvar dmoccur-list-history nil)
(defvar dmoccur-buffer-project nil)
(make-variable-buffer-local 'dmoccur-buffer-project)
(defvar dmoccur-project-name nil)
(defvar dmoccur-project-list nil)
(defvar dmoccur-recursive-ignore-dir nil)
;;;; moccur-grep
(defvar moccur-grep-buffer-list nil)
(make-variable-buffer-local 'moccur-grep-buffer-list)
(defvar moccur-xdoc2txt-buffers nil)
(make-variable-buffer-local 'moccur-xdoc2txt-buffers)
(defvar moccur-run-meadow-onwin
(and
;; run win32
(and
(null
(or (equal system-type 'gnu/linux)
(equal system-type 'usg-unix-v)))
(or (equal system-type 'windows-nt)
(equal system-type 'ms-dos)))
;; meadow
(featurep 'meadow)))
(defvar moccur-grep-search-file-pos nil)
;;; For All Emacs
(defmacro string> (a b) (list 'not (list 'or (list 'string= a b)
(list 'string< a b))))
(autoload 'migemo-get-pattern "migemo" "migemo-get-pattern" nil)
;;; For xemacs
(unless (fboundp 'match-string-no-properties)
(defalias 'match-string-no-properties 'match-string))
(when (and (boundp 'running-xemacs) running-xemacs)
(require 'overlay)
(if (not (functionp 'line-beginning-position))
(fset 'line-beginning-position 'point-at-bol))
(if (not (functionp 'line-end-position))
(fset 'line-end-position 'point-at-eol)))
;;; moccur and other packages
;;;; moccur + isearch
(defun isearch-moccur ()
"Invoke `moccur' from isearch within `current-buffer'."
(interactive)
(let ((case-fold-search isearch-case-fold-search) (isearch-buffer (current-buffer)))
(isearch-exit)
(moccur-setup)
(moccur-search
(if isearch-regexp
isearch-string
(regexp-quote isearch-string))
t
(list isearch-buffer))))
(defun isearch-moccur-all ()
"Invoke `moccur' from isearch in all buffers."
(interactive)
(let ((case-fold-search isearch-case-fold-search)
(buffers (moccur-filter-buffers (buffer-list))))
;; sort
(setq buffers (sort buffers moccur-buffer-sort-method))
(isearch-exit)
(moccur-setup)
(moccur-search
(if isearch-regexp
isearch-string
(regexp-quote isearch-string))
t
buffers)))
(define-key isearch-mode-map (kbd "M-o") 'isearch-moccur)
(define-key isearch-mode-map (kbd "M-O") 'isearch-moccur-all)
;;;; occur
(defun occur-by-moccur (regexp arg)
"Use this instead of occur.
Argument REGEXP regexp.
Argument ARG whether buffers which is not related to files are searched."
(interactive (list (moccur-regexp-read-from-minibuf)
current-prefix-arg))
(moccur-setup)
(setq moccur-regexp-input regexp)
(let ((buffers (list (current-buffer))))
(moccur-search regexp t buffers)))
;;; moccur:function
;;;; utility
(defun moccur-filepath-string< (buf1 buf2)
"String< by function `buffer-file-name'.
Argument BUF1 BUFFER.
Argument BUF2 BUFFER."
(if (and (buffer-file-name buf1)
(buffer-file-name buf2))
(string< (buffer-file-name buf1) (buffer-file-name buf2))
(if (buffer-file-name buf1)
buf1
(if (buffer-file-name buf2)
buf2
(string< (buffer-name buf1) (buffer-name buf2))))))
(defun moccur-buffer-string< (buf1 buf2)
"String< by `buffer-name'.
Argument BUF1 BUFFER.
Argument BUF2 BUFFER."
(string< (buffer-name buf1) (buffer-name buf2)))
(defun moccur-buffer-string> (buf1 buf2)
"String> by `buffer-name'.
Argument BUF1 BUFFER.
Argument BUF2 BUFFER."
(string> (buffer-name buf1) (buffer-name buf2)))
(defun moccur-buffer-in-list-p (buffer-name buffer-name-regexps)
"Return t, if BUFFER-NAME match BUFFER-NAME-REGEXPS (list)."
(cond ((null buffer-name-regexps) nil)
((eq (string-match (car buffer-name-regexps) buffer-name)
0) t)
(t (moccur-buffer-in-list-p
buffer-name (cdr buffer-name-regexps)))))
(defun moccur-filter-buffers (buffer-list)
"Return BUFFER-LIST which is filtered by some variables."
(let ((moccur-buffers nil))
(while buffer-list
(if (and (moccur-buffer-in-list-p
(buffer-name (car buffer-list))
*moccur-buffer-name-inclusion-list*)
(not (moccur-buffer-in-list-p
(buffer-name (car buffer-list))
*moccur-buffer-name-exclusion-list*)))
(setq moccur-buffers
(cons (car buffer-list)
moccur-buffers)))
(setq buffer-list (cdr buffer-list)))
moccur-buffers))
(defun moccur-kill-buffer-func ()
(when (get-buffer "*Moccur*") ;; there ought to be just one of these
(let ((cur-buffer (current-buffer)))
(save-excursion
(set-buffer "*Moccur*")
;; remove current buffer from moccur-grep-buffer-list so it won't get killed in
;; moccur-grep-sync-kill-buffers
(setq moccur-grep-buffer-list (remq cur-buffer moccur-grep-buffer-list))))
(kill-buffer "*Moccur*"))
(if (get-buffer "*ee-outline*/*Moccur*")
(kill-buffer "*ee-outline*/*Moccur*")))
(defun moccur-kill-buffer (arg)
"Kill buffers related moccur."
(if arg
(moccur-kill-buffer-func)
(if moccur-kill-moccur-buffer
(moccur-kill-buffer-func)
(bury-buffer))))
(defun moccur-bury-buffer ()
"Kill buffers related moccur."
(if (get-buffer "*Moccur*") ;; there ought to be just one of these
(bury-buffer (get-buffer "*Moccur*")))
(if (get-buffer "*ee-outline*/*Moccur*")
(bury-buffer (get-buffer "*ee-outline*/*Moccur*"))))
(autoload 'ee-outline "ee-autoloads" nil t)
(defun moccur-setup ()
"Initialization of moccur."
;;(setq moccur-last-command 'moccur)
(if moccur-use-migemo
(require 'migemo))
(if moccur-use-ee
(require 'ee-autoloads))
(if (string= "*Moccur*"
(buffer-name (current-buffer)))
(moccur-quit))
(moccur-kill-buffer t)
(setq moccur-current-buffer (current-buffer))
(setq moccur-windows-conf (current-window-configuration)))