-
Notifications
You must be signed in to change notification settings - Fork 0
/
anything-config.el
3518 lines (3158 loc) · 142 KB
/
anything-config.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
;;; anything-config.el --- Predefined configurations for `anything.el'
;; Filename: anything-config.el
;; Description: Predefined configurations for `anything.el'
;; Author: Tassilo Horn <[email protected]>
;; Maintainer: Tassilo Horn <[email protected]>
;; Andy Stewart <[email protected]>
;; rubikitch <[email protected]>
;; Thierry Volpiatto <[email protected]>
;; Copyright (C) 2007 ~ 2009, Tassilo Horn, all rights reserved.
;; Copyright (C) 2009, Andy Stewart, all rights reserved.
;; Copyright (C) 2009, rubikitch, all rights reserved.
;; Copyright (C) 2009, Thierry Volpiatto, all rights reserved.
;; Created: 2009-02-16 21:38:23
;; Version: 0.4.0
;; URL: http://www.emacswiki.org/emacs/download/anything-config.el
;; Keywords: anything, anything-config
;; Compatibility: GNU Emacs 22 ~ 23
;;
;; Features that might be required by this library:
;;
;; `anything'
;;
;;; This file is NOT part of GNU Emacs
;;; License
;;
;; 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 this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;; !NOTICE!
;;
;; If this file does not work, upgrade anything.el!
;; http://www.emacswiki.org/cgi-bin/wiki/download/anything.el
;;; Commentary:
;;
;; Predefined configurations for `anything.el'
;;
;; For quick start, try `anything-for-files' to open files.
;;
;; To configure anything you should setup `anything-sources'
;; with specify source, like below:
;;
;; (setq anything-sources
;; '(anything-c-source-buffers
;; anything-c-source-buffer-not-found
;; anything-c-source-file-name-history
;; anything-c-source-info-pages
;; anything-c-source-info-elisp
;; anything-c-source-man-pages
;; anything-c-source-locate
;; anything-c-source-emacs-commands
;; ))
;;
;; Below are complete source list you can setup in `anything-sources':
;;
;; Buffer:
;; `anything-c-source-buffers' (Buffers)
;; `anything-c-source-buffer-not-found' (Create buffer)
;; `anything-c-source-buffers+' (Buffers)
;; File:
;; `anything-c-source-file-name-history' (File Name History)
;; `anything-c-source-files-in-current-dir' (Files from Current Directory)
;; `anything-c-source-files-in-current-dir+' (Files from Current Directory)
;; `anything-c-source-file-cache' (File Cache)
;; `anything-c-source-locate' (Locate)
;; `anything-c-source-recentf' (Recentf)
;; `anything-c-source-ffap-guesser' (File at point)
;; `anything-c-source-ffap-line' (File/Lineno at point)
;; Help:
;; `anything-c-source-man-pages' (Manual Pages)
;; `anything-c-source-info-pages' (Info Pages)
;; `anything-c-source-info-elisp' (Info Elisp)
;; `anything-c-source-info-cl' (Info Common-Lisp)
;; Command:
;; `anything-c-source-complex-command-history' (Complex Command History)
;; `anything-c-source-extended-command-history' (Emacs Commands History)
;; `anything-c-source-emacs-commands' (Emacs Commands)
;; `anything-c-source-lacarte' (Lacarte)
;; Function:
;; `anything-c-source-emacs-functions' (Emacs Functions)
;; `anything-c-source-emacs-functions-with-abbrevs' (Emacs Functions)
;; Variable:
;; `anything-c-source-emacs-variables' (Emacs Variables)
;; Bookmark:
;; `anything-c-source-bookmarks' (Bookmarks)
;; `anything-c-source-bookmark-set' (Set Bookmark)
;; `anything-c-source-bookmarks-ssh' (Bookmarks-ssh)
;; `anything-c-source-bookmarks-su' (Bookmarks-root)
;; `anything-c-source-bookmarks-local' (Bookmarks-Local)
;; `anything-c-source-w3m-bookmarks' (W3m Bookmarks)
;; Library:
;; `anything-c-source-elisp-library-scan' (Elisp libraries (Scan))
;; Programming:
;; `anything-c-source-imenu' (Imenu)
;; `anything-c-source-ctags' (Exuberant ctags)
;; `anything-c-source-semantic' (Semantic Tags)
;; `anything-c-source-simple-call-tree-functions-callers' (Function is called by)
;; `anything-c-source-simple-call-tree-callers-functions' (Function calls)
;; `anything-c-source-commands-and-options-in-file' (Commands/Options in file)
;; Color and Face:
;; `anything-c-source-customize-face' (Customize Face)
;; `anything-c-source-colors' (Colors)
;; Search Engine:
;; `anything-c-source-tracker-search' (Tracker Search)
;; `anything-c-source-mac-spotlight' (mdfind)
;; Kill ring:
;; `anything-c-source-kill-ring' (Kill Ring)
;; Register:
;; `anything-c-source-register' (Registers)
;; Headline Extraction:
;; `anything-c-source-fixme' (TODO/FIXME/DRY comments)
;; `anything-c-source-rd-headline' (RD HeadLine)
;; `anything-c-source-oddmuse-headline' (Oddmuse HeadLine)
;; `anything-c-source-emacs-source-defun' (Emacs Source DEFUN)
;; `anything-c-source-emacs-lisp-expectations' (Emacs Lisp Expectations)
;; `anything-c-source-emacs-lisp-toplevels' (Emacs Lisp Toplevel / Level 4 Comment / Linkd Star)
;; `anything-c-source-org-headline' (Org HeadLine)
;; Misc:
;; `anything-c-source-picklist' (Picklist)
;; `anything-c-source-bbdb' (BBDB)
;; `anything-c-source-evaluation-result' (Evaluation Result)
;; `anything-c-source-calculation-result' (Calculation Result)
;; `anything-c-source-google-suggest' (Google Suggest)
;; `anything-c-source-surfraw' (Surfraw)
;; `anything-c-source-emms-streams' (Emms Streams)
;; `anything-c-source-emms-dired' (Music Directory)
;; `anything-c-source-jabber-contacts' (Jabber Contacts)
;; `anything-c-source-call-source' (Call anything source)
;; `anything-c-source-occur' (Occur)
;; `anything-c-source-create' (Create)
;; `anything-c-source-minibuffer-history' (Minibuffer History)
;; System:
;; `anything-c-source-gentoo' (Portage sources)
;; `anything-c-source-use-flags' (Use Flags)
;; `anything-c-source-emacs-process' (Emacs Process)
;;; Commands:
;;
;; Below are complete command list:
;;
;; `anything-for-files'
;; Preconfigured `anything' for opening files.
;; `anything-info-at-point'
;; Preconfigured `anything' for searching info at point.
;; `anything-show-kill-ring'
;; Show `kill-ring'. It is drop-in replacement of `yank-pop'.
;; `anything-minibuffer-history'
;; Show `minibuffer-history'.
;; `anything-gentoo'
;; Start anything with only gentoo sources.
;; `anything-surfraw-only'
;; Launch only anything-surfraw.
;; `anything-kill-buffers'
;; You can continuously kill buffer you selected.
;; `anything-insert-buffer-name'
;; Insert buffer name.
;; `anything-insert-symbol'
;; Insert current symbol.
;; `anything-insert-selection'
;; Insert current selection.
;; `anything-show-buffer-only'
;; Only show sources about buffer.
;; `anything-show-bbdb-only'
;; Only show sources about BBDB.
;; `anything-show-locate-only'
;; Only show sources about Locate.
;; `anything-show-info-only'
;; Only show sources about Info.
;; `anything-show-imenu-only'
;; Only show sources about Imenu.
;; `anything-show-files-only'
;; Only show sources about File.
;; `anything-show-w3m-bookmarks-only'
;; Only show source about w3m bookmark.
;; `anything-show-colors-only'
;; Only show source about color.
;; `anything-show-kill-ring-only'
;; Only show source about kill ring.
;; `anything-show-this-source-only'
;; Only show this source.
;; `anything-test-sources'
;; List all anything sources for test.
;; `anything-select-source'
;; Select source.
;; `anything-emms-stream-edit-bookmark'
;; Change the information of current emms-stream bookmark from anything.
;; `anything-emms-stream-delete-bookmark'
;; Delete an emms-stream bookmark from anything.
;; `anything-call-source'
;; Call anything source.
;; `anything-call-source-from-anything'
;; Call anything source within `anything' session.
;; `anything-create-from-anything'
;; Run `anything-create' from `anything' as a fallback.
;; `anything-create'
;; Do many create actions from STRING.
;; `anything-c-set-variable'
;; Set value to VAR interactively.
;; `anything-c-adaptive-save-history'
;; Save history information to file given by `anything-c-adaptive-history-file'.
;;
;;; Customizable Options:
;;
;; Below are customizable option list:
;;
;; `anything-c-use-standard-keys'
;; Whether use standard keybindings. (no effect)
;; default = nil
;; `anything-c-adaptive-history-file'
;; Path of file where history information is stored.
;; default = "~/.emacs.d/anything-c-adaptive-history"
;; `anything-c-adaptive-history-length'
;; Maximum number of candidates stored for a source.
;; default = 50
;; `anything-c-google-suggest-url'
;; URL used for looking up suggestions.
;; default = "http://www.google.com/complete/search?hl=en&js=true&qu="
;; `anything-c-google-suggest-search-url'
;; URL used for searching.
;; default = "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
;; `anything-c-boring-buffer-regexp'
;; The regexp that match boring buffers.
;; default = (rx (or (group bos " ") "*anything" " *Echo Area" " *Minibuf"))
;; `anything-c-boring-file-regexp'
;; The regexp that match boring files.
;; default = (rx (or (and "/" ... ...) (and line-start ".#") (and ... eol)))
;; `anything-kill-ring-threshold'
;; *Minimum length to be listed by `anything-c-source-kill-ring'.
;; default = 10
;; `anything-su-or-sudo'
;; What command to use for root access.
;; default = "su"
;; `anything-create--actions-private'
;; User defined actions for `anything-create' / `anything-c-source-create'.
;; default = nil
;;; Change log:
;;
;; Change log of this file is found at
;; http://repo.or.cz/w/anything-config.git?a=shortlog;h=b30091a6bb64828eb3d70007db5b68d51b868bcc
;;; Contributors:
;;
;; Tamas Patrovics
;; Tassilo Horn <[email protected]>
;; Vagn Johansen <[email protected]>
;; Mathias Dahl <[email protected]>
;; Bill Clementson <[email protected]>
;; Stefan Kamphausen (see http://www.skamphausen.de for more informations)
;; Drew Adams <[email protected]>
;; Jason McBrayer <[email protected]>
;; Andy Stewart <[email protected]>
;; Thierry Volpiatto <[email protected]>
;; rubikitch <[email protected]>
;; Scott Vokes <[email protected]>
;;
;;; For Maintainers:
;;
;; Evaluate (anything-c-insert-summary) before commit. This function
;; generates anything-c-source-* list.
;;
;; Install also http://www.emacswiki.org/emacs/auto-document.el
;; And eval it or run interactively.
;;
;; [EVAL IT] (anything-c-insert-summary)
;; [EVAL IT] (auto-document)
;;
;; Please write details documentation about function, then others will
;; read code more easier. -- Andy Stewart
;;
;;; TODO
;;
;; - anything-c-adaptive stores infos for sources/types that don't have
;; set it as `filtered-candidate-transformer'.
;;
;; - Fix documentation, now many functions haven't documentations.
;;
;;; Require
(require 'anything)
(require 'thingatpt)
;;; Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defgroup anything-config nil
"Predefined configurations for `anything.el'."
:group 'anything)
(defcustom anything-c-use-standard-keys nil
"Whether use standard keybindings. (no effect)
Key definitions in anything-config.el are removed because
anything.el uses Emacs-standard keys by default. e.g. M-p/M-n for
minibuffer history, C-s for isearch, etc.
If you use `iswitchb' with `anything',
evaluate (anything-iswitchb-setup) . Then some bindings that
conflict with `iswitchb', e.g. C-p/C-n for the minibuffer
history, are removed from `anything-map'. "
:type 'boolean
:group 'anything-config)
(defcustom anything-c-adaptive-history-file "~/.emacs.d/anything-c-adaptive-history"
"Path of file where history information is stored."
:type 'string
:group 'anything-config)
(defcustom anything-c-adaptive-history-length 50
"Maximum number of candidates stored for a source."
:type 'number
:group 'anything-config)
(defcustom anything-c-google-suggest-url
"http://www.google.com/complete/search?hl=en&js=true&qu="
"URL used for looking up suggestions."
:type 'string
:group 'anything-config)
(defcustom anything-c-google-suggest-search-url
"http://www.google.com/search?ie=utf-8&oe=utf-8&q="
"URL used for searching."
:type 'string
:group 'anything-config)
(defcustom anything-c-boring-buffer-regexp
(rx (or
(group bos " ")
;; anything-buffer
"*anything"
;; echo area
" *Echo Area" " *Minibuf"))
"The regexp that match boring buffers.
Buffer candidates matching this regular expression will be
filtered from the list of candidates if the
`anything-c-skip-boring-buffers' candidate transformer is used, or
they will be displayed with face `file-name-shadow' if
`anything-c-shadow-boring-buffers' is used."
:type 'string
:group 'anything-config)
;; (string-match anything-c-boring-buffer-regexp "buf")
;; (string-match anything-c-boring-buffer-regexp " hidden")
;; (string-match anything-c-boring-buffer-regexp " *Minibuf-1*")
(defcustom anything-c-boring-file-regexp
(rx (or
;; Boring directories
(and "/" (or ".svn" "CVS" "_darcs" ".git" ".hg") (or "/" eol))
;; Boring files
(and line-start ".#")
(and (or ".class" ".la" ".o" "~") eol)))
"The regexp that match boring files.
File candidates matching this regular expression will be
filtered from the list of candidates if the
`anything-c-skip-boring-files' candidate transformer is used, or
they will be displayed with face `file-name-shadow' if
`anything-c-shadow-boring-files' is used."
:type 'string
:group 'anything-config)
(defcustom anything-kill-ring-threshold 10
"*Minimum length to be listed by `anything-c-source-kill-ring'."
:type 'integer
:group 'anything-config)
(defcustom anything-su-or-sudo "su"
"What command to use for root access."
:type 'string
:group 'anything-config)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Preconfigured Anything ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun anything-for-files ()
"Preconfigured `anything' for opening files.
ffap -> recentf -> buffer -> bookmark -> file-cache -> files-in-current-dir -> locate"
(interactive)
(anything '(anything-c-source-ffap-line
anything-c-source-ffap-guesser
anything-c-source-recentf
anything-c-source-buffers+
anything-c-source-bookmarks
anything-c-source-file-cache
anything-c-source-files-in-current-dir+
anything-c-source-locate)))
(defun anything-info-at-point ()
"Preconfigured `anything' for searching info at point."
(interactive)
(anything '(anything-c-source-info-elisp
anything-c-source-info-cl
anything-c-source-info-pages)
(thing-at-point 'symbol)))
(defun anything-show-kill-ring ()
"Show `kill-ring'. It is drop-in replacement of `yank-pop'.
You may bind this command to M-y."
(interactive)
(anything 'anything-c-source-kill-ring nil nil nil nil "*anything kill-ring*"))
(defun anything-minibuffer-history ()
"Show `minibuffer-history'.
You may bind this command to C-r in minibuffer-local-map / minibuffer-local-completion-map."
(interactive)
(anything 'anything-c-source-minibuffer-history nil nil nil nil
"*anything minibuffer-history*"))
;; (define-key minibuffer-local-map "\C-r" 'anything-minibuffer-history)
;; (define-key minibuffer-local-completion-map "\C-r" 'anything-minibuffer-history)
(defun anything-gentoo ()
"Start anything with only gentoo sources."
(interactive)
(anything '(anything-c-source-gentoo
anything-c-source-use-flags)))
(defun anything-surfraw-only ()
"Launch only anything-surfraw.
If region is marked set anything-pattern to region.
With one prefix arg search symbol at point.
With two prefix args allow choosing in which symbol to search."
(interactive)
(let (search pattern)
(cond ((region-active-p)
(setq pattern (buffer-substring (region-beginning) (region-end))))
((equal current-prefix-arg '(4))
(setq pattern (thing-at-point 'symbol)))
((equal current-prefix-arg '(16))
(setq search
(intern
(completing-read "Search in: "
(list "symbol" "sentence" "sexp" "line" "word"))))
(setq pattern (thing-at-point search))))
(if pattern
(progn
(setq pattern (replace-regexp-in-string "\n" "" pattern))
(anything 'anything-c-source-surfraw pattern))
(anything 'anything-c-source-surfraw))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Applications ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun anything-kill-buffers ()
"You can continuously kill buffer you selected."
(interactive)
(anything
'(((name . "Kill Buffers")
(candidates . anything-c-buffer-list)
(action
("Kill Buffer" . (lambda (candidate)
(kill-buffer candidate)
(anything-kill-buffers)
)))))
nil nil))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun anything-insert-buffer-name ()
"Insert buffer name."
(interactive)
(anything-insert-string
(with-current-buffer anything-current-buffer
(if buffer-file-name (file-name-nondirectory buffer-file-name)
(buffer-name)))))
(defun anything-insert-symbol ()
"Insert current symbol."
(interactive)
(anything-insert-string
(with-current-buffer anything-current-buffer
(save-excursion
(buffer-substring (beginning-of-thing 'symbol)
(end-of-thing 'symbol))))))
(defun anything-insert-selection ()
"Insert current selection."
(interactive)
(anything-insert-string
(with-current-buffer anything-current-buffer
(anything-get-selection))))
(defun anything-show-buffer-only ()
"Only show sources about buffer."
(interactive)
(anything-set-source-filter '("Buffers")))
(defun anything-show-bbdb-only ()
"Only show sources about BBDB."
(interactive)
(anything-set-source-filter '("BBDB")))
(defun anything-show-locate-only ()
"Only show sources about Locate."
(interactive)
(anything-set-source-filter '("Locate")))
(defun anything-show-info-only ()
"Only show sources about Info."
(interactive)
(anything-set-source-filter '("Info Pages"
"Info Elisp"
"Info Common-Lisp")))
(defun anything-show-imenu-only ()
"Only show sources about Imenu."
(interactive)
(anything-set-source-filter '("Imenu")))
(defun anything-show-files-only ()
"Only show sources about File."
(interactive)
(anything-set-source-filter '("File Name History"
"Files from Current Directory"
"Recentf")))
(defun anything-show-w3m-bookmarks-only ()
"Only show source about w3m bookmark."
(interactive)
(anything-set-source-filter '("W3m Bookmarks")))
(defun anything-show-colors-only ()
"Only show source about color."
(interactive)
(anything-set-source-filter '("Colors"
"Customize Faces")))
(defun anything-show-kill-ring-only ()
"Only show source about kill ring."
(interactive)
(anything-set-source-filter '("Kill Ring")))
(defun anything-show-this-source-only ()
"Only show this source."
(interactive)
(setq anything-candidate-number-limit 9999)
(anything-set-source-filter
(list (assoc-default 'name (anything-get-current-source)))))
(defun anything-test-sources ()
"List all anything sources for test.
The output is sexps which are evaluated by \\[eval-last-sexp]."
(interactive)
(with-output-to-temp-buffer "*Anything Test Sources*"
(mapc (lambda (s) (princ (format ";; (anything '%s)\n" s)))
(apropos-internal "^anything-c-source" #'boundp))
(pop-to-buffer standard-output)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun anything-nest (&rest same-as-anything)
"Nested `anything'. If you use `anything' within `anything', use it."
(with-selected-window (anything-window)
(let (anything-current-position
anything-current-buffer
(orig-anything-buffer anything-buffer)
anything-pattern
anything-buffer
anything-sources
anything-compiled-sources
anything-buffer-chars-modified-tick
(anything-samewindow t)
(enable-recursive-minibuffers t))
(unwind-protect
(apply #'anything same-as-anything)
(anything-initialize-overlays orig-anything-buffer)
(add-hook 'post-command-hook 'anything-check-minibuffer-input)))))
(defun anything-displaying-source-names ()
"Display sources name."
(with-current-buffer anything-buffer
(goto-char (point-min))
(loop with pos
while (setq pos (next-single-property-change (point) 'anything-header))
do (goto-char pos)
collect (buffer-substring-no-properties (point-at-bol)(point-at-eol))
do (forward-line 1))))
(defun anything-select-source ()
"Select source."
(interactive)
(let ((default (assoc-default 'name (anything-get-current-source)))
(source-names (anything-displaying-source-names))
(all-source-names (mapcar (lambda (s) (assoc-default 'name s))
(anything-get-sources))))
(setq anything-candidate-number-limit 9999)
(anything-aif
(let (anything-source-filter)
(anything-nest '(((name . "Anything Source")
(candidates . source-names)
(action . identity))
((name . "Anything Source (ALL)")
(candidates . all-source-names)
(action . identity)))
nil "Source: " nil
default "*anything select source*"))
(anything-set-source-filter (list it))
(anything-set-source-filter nil))))
(defun anything-insert-string (str)
"Insert STR."
(delete-minibuffer-contents)
(insert str))
(defun anything-c-match-on-file-name (candidate)
"Return non-nil if `anything-pattern' match the filename (without directory part) of CANDIDATE."
(string-match anything-pattern (file-name-nondirectory candidate)))
(defun anything-c-match-on-directory-name (candidate)
"Return non-nil if `anything-pattern' match the directory part of CANDIDATE (a file)."
(anything-aif (file-name-directory candidate)
(string-match anything-pattern it)))
(defun anything-c-string-match (candidate)
"Return non-nil if `anything-pattern' match CANDIDATE.
The match is done with `string-match'."
(string-match anything-pattern candidate))
;; `anything-c-compose' is no more needed, it is for compatibility.
(defalias 'anything-c-compose 'anything-compose)
(defun anything-c-skip-entries (list regexp)
"Remove entries which matches REGEXP from LIST."
(remove-if (lambda (x) (and (stringp x) (string-match regexp x)))
list))
(defun anything-c-shadow-entries (list regexp)
"Elements of LIST matching REGEXP will be displayed with the `file-name-shadow' face if available."
(mapcar (lambda (file)
;; Add shadow face property to boring files.
(let ((face (if (facep 'file-name-shadow)
'file-name-shadow
;; fall back to default on XEmacs
'default)))
(if (string-match regexp file)
(setq file (propertize file 'face face))))
file)
list))
(defsubst anything-c-stringify (str-or-sym)
"Get string of STR-OR-SYM."
(if (stringp str-or-sym)
str-or-sym
(symbol-name str-or-sym)))
(defsubst anything-c-symbolify (str-or-sym)
"Get symbol of STR-OR-SYM."
(if (symbolp str-or-sym)
str-or-sym
(intern str-or-sym)))
(defun anything-c-describe-function (func)
"FUNC is symbol or string."
(describe-function (anything-c-symbolify func)))
(defun anything-c-describe-variable (var)
"VAR is symbol or string."
(describe-variable (anything-c-symbolify var)))
(defun anything-c-find-function (func)
"FUNC is symbol or string."
(find-function (anything-c-symbolify func)))
(defun anything-c-find-variable (var)
"VAR is symbol or string."
(find-variable (anything-c-symbolify var)))
(defun anything-c-kill-new (string &optional replace yank-handler)
"STRING is symbol or string."
(kill-new (anything-c-stringify string) replace yank-handler))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Prefix argument in action ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TODO
(defvar anything-current-prefix-arg nil
"`current-prefix-arg' when selecting action.
It is cleared after executing action.")
(defadvice anything-exit-minibuffer (before anything-current-prefix-arg activate)
(unless anything-current-prefix-arg
(setq anything-current-prefix-arg current-prefix-arg)))
(add-hook 'anything-after-action-hook
(lambda () (setq anything-current-prefix-arg nil)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Document Generator ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun anything-c-create-summary ()
"Create `anything' summary."
(save-excursion
(goto-char (point-min))
(loop while (re-search-forward "^;;;; <\\(.+?\\)>$\\|^;; (anything '\\(.+?\\))$" nil t)
collect (if (match-beginning 1)
(cons 'section (match-string-no-properties 1))
(cons 'source
(cons (match-string-no-properties 2)
(assoc-default 'name (symbol-value (intern (match-string-no-properties 2))))))))))
;; (find-epp (anything-c-create-summary))
(defun anything-c-insert-summary ()
"Insert `anything' summary."
(save-excursion
(goto-char (point-min))
(search-forward ";; Below are complete source list you can setup in")
(forward-line 1)
(delete-region (point)
(progn (search-forward ";;; Change log:" nil t)
(forward-line -1) (point)))
(insert ";;\n")
(loop with beg
for (kind . value) in (anything-c-create-summary)
for i from 0
do (cond ((eq kind 'section)
(unless (zerop i)
(align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))
(insert ";; " value ":\n")
(setq beg (point)))
(t
(insert ";; `" (car value) "' (" (cdr value) ")\n")))
finally (align-regexp beg (point) "\\(\\s-*\\)(" 1 1 nil))))
;; (anything-c-insert-summary)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Anything Sources ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; <Buffer>
(defun anything-c-buffer-list ()
"Return the list of names of buffers with boring buffers filtered out.
Boring buffers is specified by `anything-c-boring-buffer-regexp'.
The first buffer in the list will be the last recently used
buffer that is not the current buffer."
(let ((buffers (mapcar 'buffer-name (buffer-list))))
(append (cdr buffers) (list (car buffers)))))
(defvar anything-c-source-buffers
'((name . "Buffers")
(candidates . anything-c-buffer-list)
(volatile)
(type . buffer)))
;; (anything 'anything-c-source-buffers)
(defvar anything-c-source-buffer-not-found
'((name . "Create buffer")
(dummy)
(type . buffer)))
;; (anything 'anything-c-source-buffer-not-found)
;;; Buffers+
(defface anything-dir-heading '((t (:foreground "Blue" :background "Pink")))
"*Face used for directory headings in dired buffers."
:group 'anything)
(defface anything-file-name
'((t (:foreground "Blue")))
"*Face used for file names (without suffixes) in dired buffers."
:group 'anything)
(defface anything-dir-priv
'((t (:foreground "DarkRed" :background "LightGray")))
"*Face used for directory privilege indicator (d) in dired buffers."
:group 'anything)
(defvar anything-c-buffers-face1 'anything-dir-priv)
(defvar anything-c-buffers-face2 'font-lock-type-face)
(defvar anything-c-buffers-face3 'italic)
(eval-when-compile (require 'dired))
(defun anything-c-highlight-buffers (buffers)
(require 'dired)
(loop for i in buffers
if (rassoc (get-buffer i) dired-buffers)
collect (propertize i
'face anything-c-buffers-face1
'help-echo (car (rassoc (get-buffer i) dired-buffers)))
if (buffer-file-name (get-buffer i))
collect (propertize i
'face anything-c-buffers-face2
'help-echo (buffer-file-name (get-buffer i)))
if (and (not (rassoc (get-buffer i) dired-buffers))
(not (buffer-file-name (get-buffer i))))
collect (propertize i
'face anything-c-buffers-face3)))
(defvar anything-c-source-buffers+
'((name . "Buffers")
(candidates . anything-c-buffer-list)
(volatile)
(type . buffer)
(candidate-transformer anything-c-highlight-buffers
anything-c-skip-boring-buffers)
(persistent-action . anything-c-buffers+-persistent-action)))
(defun anything-c-buffers+-persistent-action (name)
(flet ((kill (item)
(with-current-buffer item
(if (and (buffer-modified-p)
(buffer-file-name (current-buffer)))
(progn
(save-buffer)
(kill-buffer item))
(kill-buffer item))))
(goto (item)
(switch-to-buffer item)))
(if current-prefix-arg
(progn
(kill name)
(anything-delete-current-selection))
(goto name))))
;; (anything 'anything-c-source-buffers+)
;;;; <File>
;;; File name history
(defvar anything-c-source-file-name-history
'((name . "File Name History")
(candidates . file-name-history)
(match anything-c-match-on-file-name
anything-c-match-on-directory-name)
(type . file)))
;; (anything 'anything-c-source-file-name-history)
;;; Files in current dir
(defvar anything-c-source-files-in-current-dir
'((name . "Files from Current Directory")
(init . (lambda () (setq anything-c-default-directory default-directory)))
(candidates . (lambda () (directory-files anything-c-default-directory)))
(volatile)
(type . file)))
;; (anything 'anything-c-source-files-in-current-dir)
(defvar anything-c-files-face1 'anything-dir-priv)
(defvar anything-c-files-face2 'anything-file-name)
(defun anything-c-highlight-files (files)
(loop for i in files
if (file-directory-p i)
collect (propertize (file-name-nondirectory i)
'face anything-c-files-face1
'help-echo (expand-file-name i))
else
collect (propertize (file-name-nondirectory i)
'face anything-c-files-face2
'help-echo (expand-file-name i))))
(defvar anything-c-source-files-in-current-dir+
'((name . "Files from Current Directory")
(init . (lambda ()
(setq anything-c-default-directory
(expand-file-name default-directory))))
(candidates . (lambda ()
(directory-files
anything-c-default-directory t)))
(candidate-transformer anything-c-highlight-files)
(volatile)
(type . file)))
;; (anything 'anything-c-source-files-in-current-dir+)
;;; File Cache
(defvar anything-c-source-file-cache-initialized nil)
(defvar anything-c-file-cache-files nil)
(defvar anything-c-source-file-cache
'((name . "File Cache")
(init . (lambda ()
(require 'filecache nil t)
(unless anything-c-source-file-cache-initialized
(setq anything-c-file-cache-files
(loop for item in file-cache-alist append
(destructuring-bind (base &rest dirs) item
(loop for dir in dirs collect
(concat dir base)))))
(defadvice file-cache-add-file (after file-cache-list activate)
(add-to-list 'anything-c-file-cache-files (expand-file-name file)))
(setq anything-c-source-file-cache-initialized t))))
(candidates . anything-c-file-cache-files)
(match anything-c-match-on-file-name
anything-c-match-on-directory-name)
(type . file)))
;; (anything 'anything-c-source-file-cache)
;;; Locate
(defvar anything-c-locate-options
(cond
((eq system-type 'darwin) '("locate"))
((eq system-type 'berkeley-unix) '("locate" "-i"))
(t '("locate" "-i" "-r")))
"A list where the `car' is the name of the locat program followed by options.
The search pattern will be appended, so the
\"-r\" option should be the last option.")
(defvar anything-c-source-locate
'((name . "Locate")
(candidates . (lambda ()
(apply 'start-process "locate-process" nil
(append anything-c-locate-options
(list anything-pattern)))))
(type . file)
(requires-pattern . 3)
(delayed))
"Source for retrieving files matching the current input pattern with locate.")
;; (anything 'anything-c-source-locate)
;;; Recentf files
(defvar anything-c-source-recentf
'((name . "Recentf")
(init . (lambda ()
(require 'recentf)
(or recentf-mode (recentf-mode 1))
;; Big value empowers anything/recentf
(when (and (numberp recentf-max-saved-items)
(<= recentf-max-saved-items 20))
(setq recentf-max-saved-items 500))))
(candidates . recentf-list)
(match anything-c-match-on-file-name
anything-c-match-on-directory-name)
(type . file))
"See (info \"(emacs)File Conveniences\").
if `recentf-max-saved-items' is too small, set it to 500.")
;; (anything 'anything-c-source-recentf)
;;; ffap
(eval-when-compile (require 'ffap))
(defvar anything-c-source-ffap-guesser
'((name . "File at point")
(init . (lambda () (require 'ffap)))
(candidates . (lambda ()
(anything-aif
(with-current-buffer anything-current-buffer
(ffap-guesser))
(list it))))
(type . file)))
;; (anything 'anything-c-source-ffap-guesser)
;;; ffap with line number
(defun anything-c-ffap-file-line-at-point ()
"Get (FILENAME . LINENO) at point."
(anything-aif (let (ffap-alist) (ffap-file-at-point))
(save-excursion
(beginning-of-line)
(when (and (search-forward it nil t)
(looking-at ":\\([0-9]+\\)"))
(cons it (string-to-number (match-string 1)))))))
(defvar anything-c-ffap-line-location nil
"(FILENAME . LINENO) used by `anything-c-source-ffap-line'.
It is cleared after jumping line.")
(defun anything-c-ffap-line-candidates ()
(with-current-buffer anything-current-buffer
(setq anything-c-ffap-line-location (anything-c-ffap-file-line-at-point)))
(when anything-c-ffap-line-location
(destructuring-bind (file . line) anything-c-ffap-line-location
(list (cons (format "%s (line %d)" file line) file)))))
;;; Goto line after opening file by `anything-c-source-ffap-line'.
(defun anything-c-ffap-line-goto-line ()
(when (car anything-c-ffap-line-location)
(unwind-protect
(ignore-errors
(with-selected-window (get-buffer-window
(get-file-buffer (car anything-c-ffap-line-location)))
(goto-line (cdr anything-c-ffap-line-location))))
(setq anything-c-ffap-line-location nil))))
(add-hook 'anything-after-action-hook 'anything-c-ffap-line-goto-line)
(defvar anything-c-source-ffap-line
'((name . "File/Lineno at point")
(init . (lambda () (require 'ffap)))
(candidates . anything-c-ffap-line-candidates)
(type . file)))
;; (anything 'anything-c-source-ffap-line)
;;;; <Help>
;;; Man Pages
(defvar anything-c-man-pages nil
"All man pages on system.
Will be calculated the first time you invoke anything with this
source.")
(defvar anything-c-source-man-pages
`((name . "Manual Pages")
(candidates . (lambda ()
(if anything-c-man-pages
anything-c-man-pages
;; XEmacs doesn't have a woman :)
(setq anything-c-man-pages
(ignore-errors