-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanything.el
4520 lines (3923 loc) · 179 KB
/
anything.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.el --- open anything / QuickSilver-like candidate-selection framework
;; Copyright (C) 2007 Tamas Patrovics
;; 2008 ~ 2016 rubikitch <[email protected]>
;; 2011 ~ 2012 Thierry Volpiatto <[email protected]>
;; Author: Tamas Patrovics
;; Maintainers: rubikitch <[email protected]>
;; Thierry Volpiatto <[email protected]>
;; Keywords: files, frames, help, matching, outlines,
;; processes, tools, convenience, anything
;; X-URL: <http://repo.or.cz/w/anything-config.git>
;; Site: <http://www.emacswiki.org/cgi-bin/emacs/Anything>
;; MailingList: <https://groups.google.com/group/emacs-anything?hl=en>
;;; This file is NOT part of GNU Emacs
;;; License
;;
;; This file 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.
;; This file 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.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Autodoc documentation:
;; ---------------------
;; * Commands defined here are:
;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "anything" :docstring t)
;; `anything-open-last-log'
;; Open anything log file of last anything session.
;; `anything'
;; Main function to execute anything sources.
;; `anything-resume'
;; Resurrect previously invoked `anything'.
;; `anything-resume-window-only'
;;
;; `anything-at-point'
;; Call anything with symbol at point as initial input.
;; `anything-force-update'
;; Force recalculation and update of candidates.
;; `anything-select-action'
;; Select an action for the currently selected candidate.
;; `anything-previous-line'
;; Move selection to the previous line.
;; `anything-next-line'
;; Move selection to the next line.
;; `anything-previous-page'
;; Move selection back with a pageful.
;; `anything-next-page'
;; Move selection forward with a pageful.
;; `anything-beginning-of-buffer'
;; Move selection at the top.
;; `anything-end-of-buffer'
;; Move selection at the bottom.
;; `anything-previous-source'
;; Move selection to the previous source.
;; `anything-next-source'
;; Move selection to the next source.
;; `anything-select-with-prefix-shortcut'
;; Invoke default action with prefix shortcut.
;; `anything-select-with-digit-shortcut'
;; Invoke default action with digit/alphabet shortcut.
;; `anything-confirm-and-exit-minibuffer'
;; Maybe ask for confirmation when exiting anything.
;; `anything-exit-minibuffer'
;; Select the current candidate by exiting the minibuffer.
;; `anything-keyboard-quit'
;; Quit minibuffer in anything.
;; `anything-help'
;; Help of `anything'.
;; `anything-debug-output'
;; Show all anything-related variables at this time.
;; `anything-delete-current-selection'
;; Delete the currently selected item.
;; `anything-delete-minibuffer-contents'
;; Same as `delete-minibuffer-contents' but this is a command.
;; `anything-toggle-resplit-window'
;; Toggle resplit anything window, vertically or horizontally.
;; `anything-narrow-window'
;; Narrow anything window.
;; `anything-enlarge-window'
;; Enlarge anything window.
;; `anything-select-2nd-action'
;; Select the 2nd action for the currently selected candidate.
;; `anything-select-3rd-action'
;; Select the 3rd action for the currently selected candidate.
;; `anything-select-4th-action'
;; Select the 4th action for the currently selected candidate.
;; `anything-select-2nd-action-or-end-of-line'
;; Select the 2nd action for the currently selected candidate.
;; `anything-execute-persistent-action'
;; Perform the associated action ATTR without quitting anything.
;; `anything-scroll-other-window'
;; Scroll other window (not *Anything* window) upward.
;; `anything-scroll-other-window-down'
;; Scroll other window (not *Anything* window) downward.
;; `anything-toggle-visible-mark'
;; Toggle anything visible mark at point.
;; `anything-display-all-visible-marks'
;; Show all `anything' visible marks strings.
;; `anything-next-visible-mark'
;; Move next anything visible mark.
;; `anything-prev-visible-mark'
;; Move previous anything visible mark.
;; `anything-yank-selection'
;; Set minibuffer contents to current selection.
;; `anything-kill-selection-and-quit'
;; Store current selection to kill ring.
;; `anything-follow-mode'
;; If this mode is on, persistent action is executed everytime the cursor is moved.
;; `anything-migrate-sources'
;; Help to migrate to new `anything' way.
;; `anything-describe-anything-attribute'
;; Display the full documentation of ANYTHING-ATTRIBUTE.
;; `anything-send-bug-report'
;; Send a bug report of anything.el.
;; `anything-send-bug-report-from-anything'
;; Send a bug report of anything.el in anything session.
;; * Variables defined here are:
;; [EVAL] (autodoc-document-lisp-buffer :type 'internal-variable :prefix "anything-" :docstring t)
;; `anything-version'
;; Not documented.
;; `anything-sources'
;; A list of sources to use with `anything'.
;; `anything-type-attributes'
;; It's a list of (TYPE ATTRIBUTES ...).
;; `anything-enable-shortcuts'
;; *Whether to use digit/alphabet shortcut to select the first nine matches.
;; `anything-shortcut-keys-alist'
;; Not documented.
;; `anything-display-source-at-screen-top'
;; *Display candidates at the top of screen.
;; `anything-candidate-number-limit'
;; Apply candidate-number-limit attribute value.
;; `anything-idle-delay'
;; *Be idle for this many seconds, before updating in delayed sources.
;; `anything-input-idle-delay'
;; Be idle for this many seconds, before updating.
;; `anything-samewindow'
;; Use current window to show the candidates.
;; `anything-source-filter'
;; A list of source names to be displayed.
;; `anything-map'
;; Keymap for anything.
;; `anything-header-face'
;; *Face for header lines in the anything buffer.
;; `anything-selection-face'
;; *Face for currently selected item.
;; `anything-buffer'
;; Buffer showing completions.
;; `anything-action-buffer'
;; Buffer showing actions.
;; `anything-selection-overlay'
;; Overlay used to highlight the currently selected item.
;; `anything-digit-overlays'
;; Overlays for digit shortcuts. See `anything-enable-shortcuts'.
;; `anything-candidate-cache'
;; Holds the available candidate withing a single anything invocation.
;; `anything-pattern'
;; Not documented.
;; `anything-input'
;; Not documented.
;; `anything-async-processes'
;; List of information about asynchronous processes managed by anything.
;; `anything-digit-shortcut-count'
;; Number of digit shortcuts shown in the anything buffer.
;; `anything-before-initialize-hook'
;; Run before anything initialization.
;; `anything-after-initialize-hook'
;; Run after anything initialization.
;; `anything-update-hook'
;; Run after the anything buffer was updated according the new input pattern.
;; `anything-after-update-hook'
;; Run after the anything buffer was updated according the new input pattern.
;; `anything-cleanup-hook'
;; Run after anything minibuffer is closed.
;; `anything-select-action-hook'
;; Run when opening the action buffer.
;; `anything-before-action-hook'
;; Run before executing action.
;; `anything-after-action-hook'
;; Run after executing action.
;; `anything-after-persistent-action-hook'
;; Run after executing persistent action.
;; `anything-move-selection-before-hook'
;; Run before moving selection in `anything-buffer'.
;; `anything-move-selection-after-hook'
;; Run after moving selection in `anything-buffer'.
;; `anything-restored-variables'
;; Variables which are restored after `anything' invocation.
;; `anything-saved-selection'
;; Value of the currently selected object when the action list is shown.
;; `anything-current-prefix-arg'
;; Record `current-prefix-arg' when exiting minibuffer.
;; `anything-candidate-separator'
;; Candidates separator of `multiline' source.
;; `anything-current-buffer'
;; Current buffer when `anything' is invoked.
;; `anything-buffer-file-name'
;; Variable `buffer-file-name' when `anything' is invoked.
;; `anything-saved-action'
;; Saved value of the currently selected action by key.
;; `anything-last-sources'
;; OBSOLETE!! Sources of previously invoked `anything'.
;; `anything-saved-current-source'
;; Value of the current source when the action list is shown.
;; `anything-compiled-sources'
;; Compiled version of `anything-sources'.
;; `anything-in-persistent-action'
;; Flag whether in persistent-action or not.
;; `anything-quick-update'
;; If non-nil, suppress displaying sources which are out of screen at first.
;; `anything-last-sources-local'
;; Buffer local value of `anything-sources'.
;; `anything-last-buffer'
;; `anything-buffer' of previously `anything' session.
;; `anything-save-configuration-functions'
;; The functions used to restore/save window or frame configurations.
;; `anything-persistent-action-use-special-display'
;; If non-nil, use `special-display-function' in persistent action.
;; `anything-execute-action-at-once-if-one'
;; Execute default action and exit when only one candidate is remaining.
;; `anything-quit-if-no-candidate'
;; Quit when there is no candidates when non--nil.
;; `anything-scroll-amount'
;; Scroll amount when scrolling other window in an anything session.
;; `anything-display-function'
;; Function to display *anything* buffer.
;; `anything-delayed-init-executed'
;; Not documented.
;; `anything-mode-line-string'
;; Help string displayed in mode-line in `anything'.
;; `anything-help-message'
;; Detailed help message string for `anything'.
;; `anything-source-in-each-line-flag'
;; Non-nil means add anything-source text-property in each candidate.
;; `anything-debug-forms'
;; Forms to show in `anything-debug-output'.
;; `anything-debug'
;; If non-nil, write log message into *Anything Log* buffer.
;; `anything-test-candidate-list'
;; Not documented.
;; `anything-test-mode'
;; Not documented.
;; `anything-source-name'
;; Not documented.
;; `anything-candidate-buffer-alist'
;; Not documented.
;; `anything-check-minibuffer-input-timer'
;; Not documented.
;; `anything-match-hash'
;; Not documented.
;; `anything-cib-hash'
;; Not documented.
;; `anything-tick-hash'
;; Not documented.
;; `anything-issued-errors'
;; Not documented.
;; `anything-shortcut-keys'
;; Not documented.
;; `anything-once-called-functions'
;; Not documented.
;; `anything-follow-mode'
;; If this mode is on, persistent action is executed everytime the cursor is moved.
;; `anything-let-variables'
;; Not documented.
;; `anything-split-window-state'
;; Not documented.
;; `anything-selection-point'
;; Not documented.
;; `anything-last-log-file'
;; Not documented.
;; `anything-compile-source-functions'
;; Functions to compile elements of `anything-sources' (plug-in).
;; `anything-quit'
;; Not documented.
;; `anything-additional-attributes'
;; List of all `anything' attributes.
;; `anything-buffers'
;; All of `anything-buffer' in most recently used order.
;; `anything-current-position'
;; Restore or save current position in `anything-current-buffer'.
;; `anything-last-frame-or-window-configuration'
;; Used to store window or frame configuration when anything start.
;; `anything-reading-pattern'
;; Whether in `read-string' in anything or not.
;; `anything-compile-source-functions-default'
;; Plug-ins this file provides.
;; `anything-input-local'
;; Not documented.
;; `anything-process-delayed-sources-timer'
;; Not documented.
;; `anything-mode-line-string-real'
;; Not documented.
;; `anything-exit-status'
;; Flag to inform whether anything have exited or quitted.
;; `anything-minibuffer-confirm-state'
;; Not documented.
;; `anything-types'
;; Not documented.
;; `anything-orig-enable-shortcuts'
;; Not documented.
;; `anything-persistent-action-display-window'
;; Return the window that will be used for presistent action.
;; `anything-visible-mark-face'
;; Not documented.
;; `anything-visible-mark-overlays'
;; Not documented.
;; `anything-marked-candidates'
;; Return marked candidates of current source if any.
;; `anything-maintainer-mail-address'
;; Not documented.
;; `anything-bug-report-salutation'
;; Not documented.
;; `anything-no-dump-variables'
;; Variables not to dump in bug report.
;; *** END auto-documentation
;; [EVAL] (autodoc-update-all)
;;; Commentary:
;;
;; Start with M-x anything, narrow the list by typing some pattern,
;; select with up/down/pgup/pgdown/C-p/C-n/C-v/M-v, choose with enter,
;; left/right moves between sources. With TAB actions can be selected
;; if the selected candidate has more than one possible action.
;;
;; Note that anything.el provides only the framework and some example
;; configurations for demonstration purposes. See anything-config.el
;; for practical, polished, easy to use configurations which can be
;; used to assemble a custom personalized configuration.
;;
;; NOTE: What you find on Emacswiki is mostly deprecated and not maintained,
;; don't complain if you use such code or configuration and something
;; doesn't work.
;;
;; Here is Japanese translation of `anything-sources' attributes. Thanks.
;; http://d.hatena.ne.jp/sirocco634/20091012/1255336649
;;; Bug Report:
;;
;; If you have problems, send a bug report via C-c C-x C-b in anything session (best)
;; or M-x anything-send-bug-report outside anything session.
;; I implemented bug report feature because I want to know your current state.
;; It helps me to solve problems easily.
;; The step is:
;; 0) Setup mail in Emacs, the easiest way is:
;; (setq user-mail-address "[email protected]")
;; (setq user-full-name "Your Full Name")
;; (setq smtpmail-smtp-server "your.smtp.server.jp")
;; (setq mail-user-agent 'message-user-agent)
;; (setq message-send-mail-function 'message-smtpmail-send-it)
;; 1) Be sure to use the LATEST version of anything.el.
;; 2) Enable debugger. M-x toggle-debug-on-error or (setq debug-on-error t)
;; 3) Use Lisp version instead of compiled one: (load "anything.el")
;; 4) Do it!
;; 5) If you got an error, please do not close *Backtrace* buffer.
;; 6) Type C-c C-x C-b (anything session, best!)
;; or M-x anything-send-bug-report (outside)
;; then M-x insert-buffer *Backtrace* (if you got error)
;; 7) Describe the bug using a precise recipe.
;; 8) Type C-c C-c to send.
;;
;; You can also just report bug to:
;; https://groups.google.com/group/emacs-anything?hl=en
;; You can extend `anything' by writing plug-ins. As soon as
;; `anything' is invoked, `anything-sources' is compiled into basic
;; attributes, then compiled one is used during invocation.
;;
;; The oldest built-in plug-in is `type' attribute: appends
;; appropriate element of `anything-type-attributes'. Second built-in
;; plug-in is `candidates-in-buffer': selecting a line from candidates
;; buffer.
;;
;; To write a plug-in:
;; 1. Define a compiler: anything-compile-source--*
;; 2. Add compier function to `anything-compile-source-functions'.
;; 3. (optional) Write helper functions.
;
;; Tested on Emacs 22/23/24.
;;
;;
;; Thanks to Vagn Johansen for ideas.
;; Thanks to Stefan Kamphausen for fixes and XEmacs support.
;; Thanks to Tassilo Horn for fixes.
;; Thanks to Drew Adams for various fixes
;; Thanks to IMAKADO for candidates-in-buffer idea.
;; Thanks to Tomohiro MATSUYAMA for multiline patch.
;;
;;; (@* "Index")
;; If you have library `linkd.el', load
;; `linkd.el' and turn on `linkd-mode' now. It lets you easily
;; navigate around the sections Linkd mode will
;; highlight this Index. You can get `linkd.el' here:
;; http://www.emacswiki.org/cgi-bin/wiki/download/linkd.el
;;
;;; (@* "Tips")
;;
;; `anything' accepts keyword arguments. See docstring.
;; [EVAL IT] (describe-function 'anything)
;;
;; `anything-enable-shortcuts' enables us to select candidate easily.
;; If 'prefix then they can be selected using <prefix-key> <alnum>.
;; The prefix key is `anything-select-with-prefix-shortcut'.
;; If the <prefix-key> is a letter, pressing twice inputs the letter itself.
;; e.g.
;; (setq anything-enable-shortcuts 'prefix)
;; (define-key anything-map \"@\" 'anything-select-with-prefix-shortcut)
;;
;; You can edit current selection using `anything-edit-current-selection'.
;; It is useful after persistent-action.
;;
;; For `anything' users, setting `anything-sources' directly and
;; invoke M-x anything is obsolete way for now. Try M-x
;; `anything-migrate-sources'!
;;
;; If you want to create anything sources, yasnippet would help you.
;; http://yasnippet.googlecode.com/
;;
;; Then get the snippet from
;; http://www.emacswiki.org/cgi-bin/wiki/download/anything-source.yasnippet
;;
;; Put it in ~/.emacs.d/plugins/yasnippet/snippets/text-mode/emacs-lisp-mode/
;;
;; `anything-interpret-value' is useful function to interpret value
;; like `candidates' attribute.
;;
;; (anything-interpret-value "literal") ; => "literal"
;; (anything-interpret-value (lambda () "lambda")) ; => "lambda"
;; (let ((source '((name . "lambda with source name"))))
;; (anything-interpret-value
;; (lambda () anything-source-name)
;; source)) ; => "lambda with source name"
;; (flet ((f () "function symbol"))
;; (anything-interpret-value 'f)) ; => "function symbol"
;; (let ((v "variable symbol"))
;; (anything-interpret-value 'v)) ; => "variable symbol"
;; (anything-interpret-value 'unbounded-1) ; error
;;
;; Now symbols are acceptable as candidates. So you do not have to use
;; `symbol-name' function. The source is much simpler. For example,
;; `apropos-internal' returns a list of symbols.
;;
;; (anything
;; '(((name . "Commands")
;; (candidates . (lambda () (apropos-internal anything-pattern 'commandp)))
;; (volatile)
;; (action . describe-function))))
;;
;; To mark a candidate, press C-SPC as normal Emacs marking. To go to
;; marked candidate, press M-[ or M-].
;;
;; `anything-map' is now Emacs-standard key bindings by default.
;;
;; There are many `anything' applications, using `anything' for
;; selecting candidate. In this case, if there is one candidate or no
;; candidate, popping up *anything* buffer is irritating. If one
;; candidate, you want to select it at once. If no candidate, you want
;; to quit `anything'. Set `anything-execute-action-at-once-if-one'
;; and `anything-quit-if-no-candidate' to non-nil to remedy it. Note
;; that setting these variables GLOBALLY is bad idea because of
;; delayed sources. These are meant to be let-binded.
;;
;; ex.
;; (let ((anything-execute-action-at-once-if-one t)
;; (anything-quit-if-no-candidate (lambda () (message "No candidate"))))
;; (anything temporary-sources input))
;;
;; `set-frame-configuration' arises flickering. If you hate
;; flickering, eval:
;; (setq anything-save-configuration-functions
;; '(set-window-configuration . current-window-configuration))
;; at the cost of restoring frame configuration (only window configuration).
;;
;; `anything-delete-current-selection' deletes the current line.
;; It is useful when deleting a candidate in persistent action.
;; eg. `kill-buffer'.
;;
;; [EVAL IT] (describe-function 'anything-delete-current-selection)
;;
;; `anything-attr' gets the attribute. `anything-attrset' sets the
;; attribute. `anything-attr-defined' tests whether the attribute is
;; defined. They handles source-local variables.
;;
;; [EVAL IT] (describe-function 'anything-attr)
;; [EVAL IT] (describe-function 'anything-attrset)
;; [EVAL IT] (describe-function 'anything-attr-defined)
;;
;; `anything-sources' accepts many attributes to make your life easier.
;; Now `anything-sources' accepts a list of symbols.
;;
;; [EVAL IT] (describe-variable 'anything-sources)
;;
;; `anything' has optional arguments. Now you do not have to let-bind
;; `anything-sources'.
;;
;; [EVAL IT] (describe-function 'anything)
;;
;; `anything-resume' resumes last `anything' session. Now you do not
;; have to retype pattern.
;;
;; [EVAL IT] (describe-function 'anything-resume)
;;
;; `anything-execute-persistent-action' executes action without
;; quitting `anything'. When popping up a buffer in other window by
;; persistent action, you can scroll with `anything-scroll-other-window' and
;; `anything-scroll-other-window-down'. See also `anything-sources' docstring.
;;
;; [EVAL IT] (describe-function 'anything-execute-persistent-action)
;; [EVAL IT] (describe-variable 'anything-sources)
;;
;; `anything-select-2nd-action', `anything-select-3rd-action' and
;; `anything-select-4th-action' select other than default action
;; without pressing Tab.
;;
;; Using `anything-candidate-buffer' and the candidates-in-buffer
;; attribute is much faster than traditional "candidates and match"
;; way. And `anything-current-buffer-is-modified' avoids to
;; recalculate candidates for unmodified buffer. See docstring of
;; them.
;;
;; [EVAL IT] (describe-function 'anything-candidate-buffer)
;; [EVAL IT] (describe-function 'anything-candidates-in-buffer)
;; [EVAL IT] (describe-function 'anything-current-buffer-is-modified)
;;
;; `anything-current-buffer' and `anything-buffer-file-name' stores
;; `(current-buffer)' and `buffer-file-name' in the buffer `anything'
;; is invoked. Use them freely.
;;
;; [EVAL IT] (describe-variable 'anything-current-buffer)
;; [EVAL IT] (describe-variable 'anything-buffer-file-name)
;;
;; `anything-completing-read' and `anything-read-file-name' are
;; experimental implementation. If you are curious, type M-x
;; anything-read-string-mode. It is a minor mode and toggles on/off.
;;
;; Use `anything-test-candidates' to test your handmade anything
;; sources. It simulates contents of *anything* buffer with pseudo
;; `anything-sources' and `anything-pattern', without side-effect. So
;; you can unit-test your anything sources! Let's TDD!
;;
;; [EVAL IT] (describe-function 'anything-test-candidates)
;;
;; For anything developpers:
;;
;; There are many unit-testing framework in Emacs Lisp. See the EmacsWiki.
;; http://www.emacswiki.org/cgi-bin/emacs/UnitTesting
;; There is an unit-test by Emacs Lisp Expectations in developper-tools directory.
;; http://www.emacswiki.org/cgi-bin/wiki/download/el-expectations.el
;; http://www.emacswiki.org/cgi-bin/wiki/download/el-mock.el
;;
;; If you want to create anything sources, see anything-config.el.
;; It is huge collection of sources. You can learn from examples.
;; (@* "TODO")
;;
;; - process status indication
;;
;; - async sources doesn't honor digit-shortcut-count
;;
;; - anything-candidate-number-limit can't be nil everywhere
;; (@* "HISTORY")
;;
;; Change log of this file is found at
;; http://repo.or.cz/w/anything-config.git/history/master:/anything.el
;;
;; Change log of this project is found at
;; http://repo.or.cz/w/anything-config.git?a=shortlog
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Code:
(require 'cl)
(defvar anything-version "1.3.9")
;; (@* "User Configuration")
;;; Variables
;;
;;
;; [DEPRECATED]
;; A default value is provided in anything-config.el
(defvar anything-sources nil
"A list of sources to use with `anything'.
It is deprecated, you should not use this.
Use instead individual sources or list of sources of your choice.")
;; Default values are provided in anything-config.el.
(defvar anything-type-attributes nil
"It's a list of \(TYPE ATTRIBUTES ...\).
ATTRIBUTES are the same as attributes for `anything-sources'.
TYPE connects the value to the appropriate sources.
Don't set this directly, use instead `define-anything-type-attribute'.
This allows specifying common attributes for several sources.
For example, sources which provide files can specify
common attributes with a `file' type.")
(defvaralias 'anything-enable-digit-shortcuts 'anything-enable-shortcuts
"Same as `anything-enable-shortcuts'.
Alphabet shortcuts are available now in `anything-enable-shortcuts'.
`anything-enable-digit-shortcuts' is retained for compatibility.")
(defvar anything-enable-shortcuts 'prefix
"*Whether to use digit/alphabet shortcut to select the first nine matches.
If t then they can be selected using Ctrl+<number>.
If 'prefix then they can be selected using <prefix-key> <alnum>.
The prefix key is `anything-select-with-prefix-shortcut'.
If the <prefix-key> is a letter, pressing twice inputs the letter itself.
e.g.
(setq anything-enable-shortcuts 'prefix)
(define-key anything-map \"@\" 'anything-select-with-prefix-shortcut)
If 'alphabet then they can be selected using Shift+<alphabet> (deprecated).
It is not recommended because you cannot input capital letters in pattern.
Keys (digit/alphabet) are listed in `anything-shortcut-keys-alist'.")
(defvar anything-shortcut-keys-alist
'((alphabet . "asdfghjklzxcvbnmqwertyuiop")
(prefix . "asdfghjklzxcvbnmqwertyuiop")
(t . "123456789")))
(defvar anything-display-source-at-screen-top t
"*Display candidates at the top of screen.
This happen when using `anything-next-source' and `anything-previous-source'.")
(defvar anything-candidate-number-limit 50
"*Limit candidate number globally.
Do not show more candidates than this limit from individual sources.
It is usually pointless to show hundreds of matches
when the pattern is empty, because it is much simpler to type a
few characters to narrow down the list of potential candidates.
Set it to nil if you don't want this limit.")
(defvar anything-idle-delay 0.3
"*Be idle for this many seconds, before updating in delayed sources.
This is useful for sources involving heavy operations
\(like launching external programs\), so that candidates
from the source are not retrieved unnecessarily if the user keeps typing.
It also can be used to declutter the results anything displays,
so that results from certain sources are not shown with every
character typed, only if the user hesitates a bit.")
(defvar anything-input-idle-delay 0.3
"Be idle for this many seconds, before updating.
Unlike `anything-idle-delay', it is also effective for non-delayed sources.
If nil, candidates are collected immediately.
Note: If this value is too low compared to `anything-idle-delay',
you may have duplicated sources when using multiples sources.
Safe value is always >= `anything-idle-delay'.
Default settings are equal value for both.")
(defvar anything-samewindow nil
"Use current window to show the candidates.
If t then Anything doesn't pop up a new window.")
(defvar anything-source-filter nil
"A list of source names to be displayed.
Other sources won't appear in the search results.
If nil then there is no filtering.
See also `anything-set-source-filter'.")
(defvar anything-map
(let ((map (copy-keymap minibuffer-local-map)))
(define-key map (kbd "<down>") 'anything-next-line)
(define-key map (kbd "<up>") 'anything-previous-line)
(define-key map (kbd "C-n") 'anything-next-line)
(define-key map (kbd "C-p") 'anything-previous-line)
(define-key map (kbd "<prior>") 'anything-previous-page)
(define-key map (kbd "<next>") 'anything-next-page)
(define-key map (kbd "M-v") 'anything-previous-page)
(define-key map (kbd "C-v") 'anything-next-page)
(define-key map (kbd "M-<") 'anything-beginning-of-buffer)
(define-key map (kbd "M->") 'anything-end-of-buffer)
(define-key map (kbd "C-g") 'anything-keyboard-quit)
(define-key map (kbd "<right>") 'anything-next-source)
(define-key map (kbd "<left>") 'anything-previous-source)
(define-key map (kbd "<RET>") 'anything-exit-minibuffer)
(define-key map (kbd "C-1") 'anything-select-with-digit-shortcut)
(define-key map (kbd "C-2") 'anything-select-with-digit-shortcut)
(define-key map (kbd "C-3") 'anything-select-with-digit-shortcut)
(define-key map (kbd "C-4") 'anything-select-with-digit-shortcut)
(define-key map (kbd "C-5") 'anything-select-with-digit-shortcut)
(define-key map (kbd "C-6") 'anything-select-with-digit-shortcut)
(define-key map (kbd "C-7") 'anything-select-with-digit-shortcut)
(define-key map (kbd "C-8") 'anything-select-with-digit-shortcut)
(define-key map (kbd "C-9") 'anything-select-with-digit-shortcut)
(loop for c from ?A to ?Z do
(define-key map (make-string 1 c) 'anything-select-with-digit-shortcut))
(define-key map (kbd "C-i") 'anything-select-action)
(define-key map (kbd "C-z") 'anything-execute-persistent-action)
(define-key map (kbd "C-e") 'anything-select-2nd-action-or-end-of-line)
(define-key map (kbd "C-j") 'anything-select-3rd-action)
(define-key map (kbd "C-o") 'anything-next-source)
(define-key map (kbd "C-M-v") 'anything-scroll-other-window)
(define-key map (kbd "M-<next>") 'anything-scroll-other-window)
(define-key map (kbd "C-M-y") 'anything-scroll-other-window-down)
(define-key map (kbd "C-M-S-v") 'anything-scroll-other-window-down)
(define-key map (kbd "M-<prior>") 'anything-scroll-other-window-down)
(define-key map (kbd "<C-M-down>") 'anything-scroll-other-window)
(define-key map (kbd "<C-M-up>") 'anything-scroll-other-window-down)
(define-key map (kbd "C-SPC") 'anything-toggle-visible-mark)
(define-key map (kbd "M-SPC") 'anything-toggle-visible-mark)
(define-key map (kbd "M-[") 'anything-prev-visible-mark)
(define-key map (kbd "M-]") 'anything-next-visible-mark)
(define-key map (kbd "C-k") 'anything-delete-minibuffer-contents)
(define-key map (kbd "C-r") 'undefined)
(define-key map (kbd "C-t") 'anything-toggle-resplit-window)
(define-key map (kbd "C-}") 'anything-narrow-window)
(define-key map (kbd "C-{") 'anything-enlarge-window)
(define-key map (kbd "C-c C-d") 'anything-delete-current-selection)
(define-key map (kbd "C-c C-y") 'anything-yank-selection)
(define-key map (kbd "C-c C-k") 'anything-kill-selection-and-quit)
(define-key map (kbd "C-c C-f") 'anything-follow-mode)
(define-key map (kbd "C-c C-u") 'anything-force-update)
(define-key map (kbd "M-p") 'previous-history-element)
(define-key map (kbd "M-n") 'next-history-element)
(define-key map (kbd "M-a") 'anything-mark-all)
;; Debugging command
(define-key map "\C-c\C-x\C-d" 'anything-debug-output)
(define-key map "\C-c\C-x\C-m" 'anything-display-all-visible-marks)
(define-key map "\C-c\C-x\C-b" 'anything-send-bug-report-from-anything)
;; Use `describe-mode' key in `global-map'.
(define-key map [f1] nil) ; Allow to eval keymap whithout errors.
(dolist (k (where-is-internal 'describe-mode global-map))
(define-key map k 'anything-help))
map)
"Keymap for anything.")
(defgroup anything nil
"Open anything."
:prefix "anything-" :group 'convenience)
(defface anything-header
'((t (:inherit header-line)))
"Face for header lines in the anything buffer."
:group 'anything)
(defvar anything-header-face 'anything-header
"*Face for header lines in the anything buffer.")
(defface anything-candidate-number
'((t (:background "Yellow" :foreground "black")))
"Face for candidate number in mode-line." :group 'anything)
(defvar anything-selection-face 'highlight
"*Face for currently selected item.")
(defvar anything-buffer "*anything*"
"Buffer showing completions.")
(defvar anything-action-buffer "*anything action*"
"Buffer showing actions.")
(defvar anything-selection-overlay nil
"Overlay used to highlight the currently selected item.")
(defvar anything-digit-overlays nil
"Overlays for digit shortcuts. See `anything-enable-shortcuts'.")
(defvar anything-candidate-cache nil
"Holds the available candidate withing a single anything invocation.")
(defvar anything-pattern
"The input pattern used to update the anything buffer.")
(defvar anything-input
"The input typed in the candidates panel.")
(defvar anything-async-processes nil
"List of information about asynchronous processes managed by anything.")
(defvar anything-digit-shortcut-count 0
"Number of digit shortcuts shown in the anything buffer.")
(defvar anything-before-initialize-hook nil
"Run before anything initialization.
This hook is run before init functions in `anything-sources'.")
(defvar anything-after-initialize-hook nil
"Run after anything initialization.
Global variables are initialized and the anything buffer is created.
But the anything buffer has no contents.")
(defvar anything-update-hook nil
"Run after the anything buffer was updated according the new input pattern.
This hook is run at the beginning of buffer.
The first candidate is selected after running this hook.
See also `anything-after-update-hook'.")
(defvar anything-after-update-hook nil
"Run after the anything buffer was updated according the new input pattern.
This is very similar to `anything-update-hook' but selection is not moved.
It is useful to select a particular object instead of the first one.")
(defvar anything-cleanup-hook nil
"Run after anything minibuffer is closed.
IOW this hook is executed BEFORE performing action.")
(defvar anything-select-action-hook nil
"Run when opening the action buffer.")
(defvar anything-before-action-hook nil
"Run before executing action.
Contrarily to `anything-cleanup-hook',
this hook run before anything minibuffer is closed
and before performing action.")
(defvar anything-after-action-hook nil
"Run after executing action.")
(defvar anything-after-persistent-action-hook nil
"Run after executing persistent action.")
(defvar anything-move-selection-before-hook nil
"Run before moving selection in `anything-buffer'.")
(defvar anything-move-selection-after-hook nil
"Run after moving selection in `anything-buffer'.")
(defvar anything-restored-variables
'(anything-candidate-number-limit
anything-source-filter
anything-source-in-each-line-flag
anything-map
anything-sources)
"Variables which are restored after `anything' invocation.")
(defvar anything-saved-selection nil
"Value of the currently selected object when the action list is shown.")
(defvar anything-current-prefix-arg nil
"Record `current-prefix-arg' when exiting minibuffer.")
(defvar anything-candidate-separator
"--------------------"
"Candidates separator of `multiline' source.")
(defvar anything-current-buffer nil
"Current buffer when `anything' is invoked.")
(defvar anything-buffer-file-name nil
"Variable `buffer-file-name' when `anything' is invoked.")
(defvar anything-saved-action nil
"Saved value of the currently selected action by key.")
(defvar anything-last-sources nil
"OBSOLETE!! Sources of previously invoked `anything'.")
(defvar anything-saved-current-source nil
"Value of the current source when the action list is shown.")
(defvar anything-compiled-sources nil
"Compiled version of `anything-sources'.")
(defvar anything-in-persistent-action nil
"Flag whether in persistent-action or not.")
(defvar anything-quick-update nil
"If non-nil, suppress displaying sources which are out of screen at first.
They are treated as delayed sources at this input.
This flag makes `anything' a bit faster with many sources.")
(defvar anything-last-sources-local nil
"Buffer local value of `anything-sources'.")
(defvar anything-last-buffer nil
"`anything-buffer' of previously `anything' session.")
(defvar anything-save-configuration-functions
'(set-window-configuration . current-window-configuration)
"The functions used to restore/save window or frame configurations.
It is a pair where the car is the function to restore window or frame config,
and the cdr is the function to save the window or frame config.
If you want to save and restore frame configuration, set this variable to
'\(set-frame-configuration . current-frame-configuration\)
Older version saves/restores frame configuration, but the default is changed now
because flickering can occur in some environment. ")
(defvar anything-persistent-action-use-special-display nil
"If non-nil, use `special-display-function' in persistent action.")
(defvar anything-execute-action-at-once-if-one nil
"Execute default action and exit when only one candidate is remaining.
It is useful for `anything' applications.")
(defvar anything-quit-if-no-candidate nil
"Quit when there is no candidates when non--nil.
This variable accepts a function, which is executed if no candidate.
It is useful for `anything' applications.")
(defvar anything-scroll-amount nil
"Scroll amount when scrolling other window in an anything session.
It is used by `anything-scroll-other-window'
and `anything-scroll-other-window-down'.
If you prefer scrolling line by line, set this value to 1.")
(defvar anything-display-function 'anything-default-display-buffer
"Function to display *anything* buffer.
It is `anything-default-display-buffer' by default,
which affects `anything-samewindow'.")
(defvar anything-delayed-init-executed nil)
(defvar anything-mode-line-string nil
"Help string displayed in mode-line in `anything'.
It can be a string or a list of two args, in this case,
first arg is a string that will be used as name for candidates number,
second arg any string to display in mode line.
If nil, use default `mode-line-format'.")
(defvar anything-help-message
"\\<anything-map>The keys that are defined for `anything' are:
\\{anything-map}"
"Detailed help message string for `anything'.
It also accepts function or variable symbol.")
(defvar anything-source-in-each-line-flag nil
"Non-nil means add anything-source text-property in each candidate.
experimental feature.")
(defvaralias 'anything-debug-variables 'anything-debug-forms)
(defvar anything-debug-forms nil