forked from emacs-helm/helm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helm.el
5222 lines (4688 loc) · 213 KB
/
helm.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
;;; helm.el --- Emacs incremental and narrowing framework -*- lexical-binding: t -*-
;; Copyright (C) 2007 Tamas Patrovics
;; 2008 ~ 2011 rubikitch <[email protected]>
;; 2011 ~ 2015 Thierry Volpiatto <[email protected]>
;; This is a fork of anything.el wrote by Tamas Patrovics.
;; Authors of anything.el: Tamas Patrovics
;; rubikitch <[email protected]>
;; Thierry Volpiatto <[email protected]>
;; Author: Thierry Volpiatto <[email protected]>
;; URL: http://github.com/emacs-helm/helm
;; 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 of the License, 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. If not, see <http://www.gnu.org/licenses/>.
;;; Code:
(require 'cl-lib)
(require 'helm-source)
(defmacro helm-with-gensyms (symbols &rest body)
"Bind the SYMBOLS to fresh uninterned symbols and eval BODY."
(declare (indent 1))
`(let ,(mapcar (lambda (s) `(,s (make-symbol (concat "--" (symbol-name ',s)))))
symbols)
,@body))
;;; Multi keys
;;
;;
;;;###autoload
(defun helm-define-multi-key (keymap key functions &optional delay)
"In KEYMAP, define key sequence KEY for function list FUNCTIONS.
Each function run sequentially each time the key KEY is pressed.
If DELAY is specified switch back to initial function of FUNCTIONS list
after DELAY seconds.
The functions in FUNCTIONS list are functions with no args.
e.g
\(defun foo ()
(message \"Run foo\"))
\(defun bar ()
(message \"Run bar\"))
\(defun baz ()
(message \"Run baz\"))
\(helm-define-multi-key global-map \"<f5> q\" '(foo bar baz) 2)
Each time \"<f5> q\" is pressed the next function is executed, if you wait
More than 2 seconds, next hit will run again the first function and so on."
(define-key keymap key (helm-make-multi-command functions delay)))
;;;###autoload
(defmacro helm-multi-key-defun (name docstring funs &optional delay)
"Define NAME as a multi-key command running FUNS.
After DELAY seconds the FUNS list is reinitialised.
See `helm-define-multi-key'."
(declare (indent 2))
(setq docstring (if docstring (concat docstring "\n\n")
"This is a helmish multi-key command."))
`(defalias (quote ,name) (helm-make-multi-command ,funs ,delay) ,docstring))
(defun helm-make-multi-command (functions &optional delay)
"Return an anonymous multi-key command running FUNCTIONS.
Run each function of FUNCTIONS list in turn when called within DELAY seconds."
(declare (indent 1))
(let ((funs functions)
(iter (cl-gensym "helm-iter-key"))
(timeout delay))
(eval (list 'defvar iter nil))
#'(lambda () (interactive) (helm-run-multi-key-command funs iter timeout))))
(defun helm-run-multi-key-command (functions iterator delay)
(let ((fn #'(lambda ()
(cl-loop for count from 1 to (length functions)
collect count)))
next)
(unless (and (symbol-value iterator)
;; Reset iterator when another key is pressed.
(eq this-command real-last-command))
(set iterator (helm-iter-list (funcall fn))))
(setq next (helm-iter-next (symbol-value iterator)))
(unless next
(set iterator (helm-iter-list (funcall fn)))
(setq next (helm-iter-next (symbol-value iterator))))
(and next (symbol-value iterator) (call-interactively (nth (1- next) functions)))
(when delay (run-with-idle-timer delay nil `(lambda ()
(setq ,iterator nil))))))
(defun helm-iter-list (seq)
"Return an iterator object from SEQ."
(let ((lis seq))
(lambda ()
(let ((elm (car lis)))
(setq lis (cdr lis))
elm))))
(defun helm-iter-next (iterator)
"Return next elm of ITERATOR."
(funcall iterator))
(helm-multi-key-defun helm-toggle-resplit-and-swap-windows
"Multi key command to resplit and swap helm window.
First call run `helm-toggle-resplit-window',
second call within 0.5s run `helm-swap-windows'."
'(helm-toggle-resplit-window helm-swap-windows) 1)
;;;###autoload
(defun helm-define-key-with-subkeys (map key subkey command
&optional other-subkeys menu exit-fn)
"Allow defining in MAP a KEY and SUBKEY to COMMAND.
This allow typing KEY to call COMMAND the first time and
type only SUBKEY on subsequent calls.
Arg MAP is the keymap to use, SUBKEY is the initial short keybinding to
call COMMAND.
Arg OTHER-SUBKEYS is an alist specifying other short keybindings
to use once started.
e.g:
\(helm-define-key-with-subkeys global-map
\(kbd \"C-x v n\") ?n 'git-gutter:next-hunk '((?p . git-gutter:previous-hunk))\)
In this example, `C-x v n' will run `git-gutter:next-hunk'
subsequent hits on \"n\" will run this command again
and subsequent hits on \"p\" will run `git-gutter:previous-hunk'.
Arg MENU is a string to display in minibuffer
to describe SUBKEY and OTHER-SUBKEYS.
Arg EXIT-FN specify a function to run on exit.
Any other keys pressed run their assigned command defined in MAP
and exit the loop running EXIT-FN if specified.
NOTE: SUBKEY and OTHER-SUBKEYS bindings support
only char syntax actually (e.g ?n)
so don't use strings, vectors or whatever to define them."
(declare (indent 1))
(define-key map key
(lambda ()
(interactive)
(unwind-protect
(progn
(call-interactively command)
(while (let ((input (read-key menu)) other kb com)
(setq last-command-event input)
(cond
((eq input subkey)
(call-interactively command)
t)
((setq other (assoc input other-subkeys))
(call-interactively (cdr other))
t)
(t
(setq kb (vector last-command-event))
(setq com (lookup-key map kb))
(if (commandp com)
(call-interactively com)
(setq unread-command-events
(nconc (mapcar 'identity kb)
unread-command-events)))
nil)))))
(and exit-fn (funcall exit-fn))))))
;;; Keymap
;;
;;
(defvar helm-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map minibuffer-local-map)
(define-key map (kbd "<down>") 'helm-next-line)
(define-key map (kbd "<up>") 'helm-previous-line)
(define-key map (kbd "C-n") 'helm-next-line)
(define-key map (kbd "C-p") 'helm-previous-line)
(define-key map (kbd "<C-down>") 'helm-follow-action-forward)
(define-key map (kbd "<C-up>") 'helm-follow-action-backward)
(define-key map (kbd "<prior>") 'helm-previous-page)
(define-key map (kbd "<next>") 'helm-next-page)
(define-key map (kbd "M-v") 'helm-previous-page)
(define-key map (kbd "C-v") 'helm-next-page)
(define-key map (kbd "M-<") 'helm-beginning-of-buffer)
(define-key map (kbd "M->") 'helm-end-of-buffer)
(define-key map (kbd "C-g") 'helm-keyboard-quit)
(define-key map (kbd "<right>") 'helm-next-source)
(define-key map (kbd "<left>") 'helm-previous-source)
(define-key map (kbd "<RET>") 'helm-maybe-exit-minibuffer)
(define-key map (kbd "C-i") 'helm-select-action)
(define-key map (kbd "C-z") 'helm-execute-persistent-action)
(define-key map (kbd "C-j") 'helm-execute-persistent-action)
(define-key map (kbd "C-o") 'helm-next-source)
(define-key map (kbd "C-l") 'helm-recenter-top-bottom-other-window)
(define-key map (kbd "M-C-l") 'helm-reposition-window-other-window)
(define-key map (kbd "C-M-v") 'helm-scroll-other-window)
(define-key map (kbd "M-<next>") 'helm-scroll-other-window)
(define-key map (kbd "C-M-y") 'helm-scroll-other-window-down)
(define-key map (kbd "C-M-S-v") 'helm-scroll-other-window-down)
(define-key map (kbd "M-<prior>") 'helm-scroll-other-window-down)
(define-key map (kbd "<C-M-down>") 'helm-scroll-other-window)
(define-key map (kbd "<C-M-up>") 'helm-scroll-other-window-down)
(define-key map (kbd "C-@") 'helm-toggle-visible-mark)
(define-key map (kbd "C-SPC") 'helm-toggle-visible-mark)
(define-key map (kbd "M-SPC") 'helm-toggle-visible-mark)
(define-key map (kbd "M-[") nil)
(define-key map (kbd "M-(") 'helm-prev-visible-mark)
(define-key map (kbd "M-)") 'helm-next-visible-mark)
(define-key map (kbd "C-x C-f") 'helm-quit-and-find-file)
(define-key map (kbd "M-m") 'helm-toggle-all-marks)
(define-key map (kbd "M-a") 'helm-mark-all)
(define-key map (kbd "M-u") 'helm-unmark-all)
(define-key map (kbd "C-w") 'helm-yank-text-at-point)
(define-key map (kbd "C-M-a") 'helm-show-all-in-this-source-only)
(define-key map (kbd "C-M-e") 'helm-display-all-sources)
(define-key map (kbd "C-r") 'undefined)
(define-key map (kbd "C-s") 'undefined)
(define-key map (kbd "M-s") 'undefined)
(define-key map (kbd "C-}") 'helm-narrow-window)
(define-key map (kbd "C-{") 'helm-enlarge-window)
(define-key map (kbd "C-c -") 'helm-swap-windows)
(define-key map (kbd "C-c C-d") 'helm-delete-current-selection)
(define-key map (kbd "C-c C-y") 'helm-yank-selection)
(define-key map (kbd "C-c C-k") 'helm-kill-selection-and-quit)
(define-key map (kbd "C-c C-i") 'helm-copy-to-buffer)
(define-key map (kbd "C-c C-f") 'helm-follow-mode)
(define-key map (kbd "C-c C-u") 'helm-force-update)
(define-key map (kbd "M-p") 'previous-history-element)
(define-key map (kbd "M-n") 'next-history-element)
(define-key map (kbd "C-!") 'helm-toggle-suspend-update)
(define-key map (kbd "C-x b") 'helm-resume-previous-session-after-quit)
(define-key map (kbd "C-x C-b") 'helm-resume-list-buffers-after-quit)
;; Disable `file-cache-minibuffer-complete'.
;; (define-key map (kbd "<C-tab>") 'undefined)
(define-key map (kbd "<C-tab>") 'helm-execute-persistent-action)
;; Multi keys
;; (define-key map (kbd "C-t") 'helm-toggle-resplit-and-swap-windows)
;; Debugging command
;; (define-key map (kbd "C-h C-d") 'undefined)
;; (define-key map (kbd "C-h C-d") 'helm-debug-output)
;; Use `describe-mode' key in `global-map'.
(define-key map [f1] nil) ; Allow to eval keymap without errors.
;; (define-key map (kbd "C-h C-h") 'undefined)
;; (define-key map (kbd "C-h h") 'undefined)
(cl-dolist (k (where-is-internal 'describe-mode global-map))
(define-key map k 'helm-help))
;; Bind all actions from 1 to 12 to their corresponding nth index+1.
(cl-loop for n from 0 to 12 do
(define-key map (kbd (format "<f%s>" (1+ n)))
`(lambda ()
(interactive)
(helm-select-nth-action ,n))))
;; for old interface
(define-key map (kbd "C-z")
`(lambda ()
(interactive)
(helm-select-nth-action 1)))
(define-key map (kbd "C-j")
`(lambda ()
(interactive)
(helm-select-nth-action 2)))
(define-key map (kbd "\C-h") 'backward-delete-char) ;; overwrite C-h by backward-delete-char
map)
"Keymap for helm.")
(defgroup helm nil
"Open helm."
:prefix "helm-" :group 'convenience)
(defcustom helm-completion-window-scroll-margin 5
" `scroll-margin' to use for helm completion window.
Which see. Set to 0 to disable.
NOTE: This have no effect when `helm-display-source-at-screen-top'
id non--nil."
:group 'helm
:type 'integer)
(defcustom helm-display-source-at-screen-top t
"Display candidates at the top of screen.
This happen when using `helm-next-source' and `helm-previous-source'.
NOTE: When non--nil (default) disable `helm-completion-window-scroll-margin'."
:group 'helm
:type 'boolean)
(defcustom helm-candidate-number-limit 100
"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."
:group 'helm
:type '(choice (const :tag "Disabled" nil) integer))
(defcustom helm-idle-delay 0.01
"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 helm displays,
so that results from certain sources are not shown with every
character typed, only if the user hesitates a bit.
Be sure to know what you are doing when modifying this."
:group 'helm
:type 'float)
(defcustom helm-input-idle-delay 0.01
"Be idle for this many seconds, before updating.
Unlike `helm-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 `helm-idle-delay',
you may have duplicated sources when using multiples sources.
Safe value is always >= `helm-idle-delay'.
Default settings are equal value for both.
Be sure to know what you are doing when modifying this."
:group 'helm
:type 'float)
(defcustom helm-exit-idle-delay 0
"Be idle for this many seconds before exiting minibuffer while helm is updating.
Note that this does nothing when helm-buffer is up to date
\(i.e exit without delay in this condition\)."
:group 'helm
:type 'float)
(defcustom helm-full-frame nil
"Use current window to show the candidates.
If t then Helm doesn't pop up a new window."
:group 'helm
:type 'boolean)
(defvaralias 'helm-samewindow 'helm-full-frame)
(make-obsolete-variable 'helm-samewindow 'helm-full-frame "1.4.8.1")
(defcustom helm-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 `helm' a bit faster with many sources."
:group 'helm
:type 'boolean)
(defcustom helm-candidate-separator
"--------------------"
"Candidates separator of `multiline' source."
:group 'helm
:type 'string)
(defcustom helm-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\)
NOTE: This may not work properly with own-frame minibuffer settings.
Older version saves/restores frame configuration, but the default is changed now
because flickering can occur in some environment."
:group 'helm
:type 'sexp)
(defcustom helm-persistent-action-use-special-display nil
"If non-nil, use `special-display-function' in persistent action."
:group 'helm
:type 'boolean)
(defcustom helm-scroll-amount nil
"Scroll amount when scrolling other window in a helm session.
It is used by `helm-scroll-other-window'
and `helm-scroll-other-window-down'.
If you prefer scrolling line by line, set this value to 1."
:group 'helm
:type 'integer)
(defcustom helm-display-function 'helm-default-display-buffer
"Function to display *helm* buffer.
It is `helm-default-display-buffer' by default,
which affects `helm-full-frame'."
:group 'helm
:type 'symbol)
(defcustom helm-case-fold-search 'smart
"Add 'smart' option to `case-fold-search'.
When smart is enabled, ignore case in the search strings
if pattern contains no uppercase characters.
Otherwise, with a nil or t value, the behavior is same as
`case-fold-search'.
Default value is smart, other possible values are nil and t.
NOTE: This have no effect in asynchronous sources, you will
have to implement a similar feature directly in the process.
See in helm-grep.el how it is implemented."
:group 'helm
:type '(choice (const :tag "Ignore case" t)
(const :tag "Respect case" nil)
(other :tag "Smart" 'smart)))
(defcustom helm-file-name-case-fold-search
(if (memq system-type
'(cygwin windows-nt ms-dos darwin))
t
helm-case-fold-search)
"Local setting of `helm-case-fold-search' for reading filenames.
See `helm-case-fold-search' for more info."
:group 'helm
:type 'symbol)
(defcustom helm-reuse-last-window-split-state nil
"Reuse the last state of window split, vertical or horizontal.
That is when you use `helm-toggle-resplit-window' the next helm session
will reuse the same window scheme than the one of last session unless
`helm-split-window-default-side' is 'same or 'other."
:group 'helm
:type 'boolean)
(defcustom helm-split-window-preferred-function 'helm-split-window-default-fn
"Default function used for splitting window."
:group 'helm
:type 'function)
(defcustom helm-split-window-default-side 'below
"The default side to display `helm-buffer'.
Must be one acceptable arg for `split-window' SIDE,
that is 'below, 'above, 'left or 'right.
Other acceptable values are 'same which always display `helm-buffer'
in current window and 'other that display `helm-buffer' below if only one
window or in `other-window-for-scrolling' if available.
A nil value as same effect as 'below.
If `helm-full-frame' is non--nil, it take precedence on this.
See also `helm-split-window-in-side-p' and `helm-always-two-windows' that
take precedence on this.
NOTE: this have no effect if `helm-split-window-preferred-function' is not
`helm-split-window-default-fn' unless this new function handle this."
:group 'helm
:type 'symbol)
(defcustom helm-split-window-in-side-p nil
"Force splitting inside selected window when non--nil.
See also `helm-split-window-default-side'.
NOTE: this have no effect if `helm-split-window-preferred-function' is not
`helm-split-window-default-fn' unless this new function handle this."
:group 'helm
:type 'boolean)
(defcustom helm-always-two-windows nil
"When non--nil helm will use two windows in this frame.
That is one window to display `helm-buffer' and one to display
`helm-current-buffer'.
Note: this have no effect when `helm-split-window-in-side-p' is non--nil,
or when `helm-split-window-default-side' is set to 'same.
When `helm-autoresize-mode' is enabled, setting this to nil
will have no effect until this mode will be disabled."
:group 'helm
:type 'boolean)
(defcustom helm-sources-using-default-as-input '(helm-source-imenu
helm-source-info-elisp
helm-source-etags-select)
"List of helm sources that need to use `helm-maybe-use-default-as-input'.
When a source is member of this list, default `thing-at-point'
will be used as input."
:group 'helm
:type '(repeat (choice symbol)))
(defcustom helm-delete-minibuffer-contents-from-point t
"When non--nil, `helm-delete-minibuffer-contents' delete region from `point'.
Otherwise delete `minibuffer-contents'.
See documentation of `helm-delete-minibuffer-contents'."
:group 'helm
:type 'boolean)
(defcustom helm-follow-mode-persistent nil
"Retrieve last state of `helm-follow-mode' in next helm session when non--nil.
This will not make it persistent through emacs sessions though,
you will have to set explicitely the `follow' attribute in the source where
you want this mode enabled definitely."
:group 'helm
:type 'boolean)
(defcustom helm-prevent-escaping-from-minibuffer t
"Prevent escaping from minibuffer during helm session."
:group 'helm
:type 'boolean)
(defcustom helm-truncate-lines nil
"Truncate long lines when non--nil.
See `truncate-lines'."
:group 'helm
:type 'boolean)
(defcustom helm-move-to-line-cycle-in-source nil
"Move to end or beginning of source when reaching top or bottom of source.
This happen when using `helm-next/previous-line'."
:group 'helm
:type 'boolean)
(defcustom helm-fuzzy-match-fn 'helm-fuzzy-match
"The function for fuzzy matching in `helm-source-sync' based sources."
:group 'helm
:type 'function)
(defcustom helm-fuzzy-search-fn 'helm-fuzzy-search
"The function for fuzzy matching in `helm-source-in-buffer' based sources."
:group 'helm
:type 'function)
(defcustom helm-fuzzy-sort-fn 'helm-fuzzy-matching-default-sort-fn
"The sort transformer function used in fuzzy matching.
When nil no sorting will be done."
:group 'helm
:type 'function)
(defcustom helm-fuzzy-matching-highlight-fn 'helm-fuzzy-default-highlight-match
"The function to highlight matches in fuzzy matching.
When nil no highlighting will be done."
:group 'helm
:type 'function)
(defcustom helm-autoresize-max-height 40
"Specifies a maximum height and defaults to the height of helm window's frame in percentage.
See `fit-window-to-buffer' for more infos."
:group 'helm
:type 'integer)
(defcustom helm-autoresize-min-height 10
"Specifies a minimum height and defaults to the height of helm window's frame in percentage.
If nil the default of `window-min-height' is used
See `fit-window-to-buffer' for more infos."
:group 'helm
:type 'integer)
(defcustom helm-input-method-verbose-flag nil
"The default value of `input-method-verbose-flag' to use in helm minibuffer.
It is nil by default to allow helm updating and exiting without turning off
the input method when complex methods are in use, if you set it to any other
value allowed by `input-method-verbose-flag' you will have at each time you want
to exit or helm update to disable the `current-input-method' with `C-\\'."
:group 'helm
:type '(radio :tag "A flag to control extra guidance given by input methods in helm."
(const :tag "Never provide guidance" nil)
(const :tag "Always provide guidance" t)
(const :tag "Provide guidance only in complex methods" complex-only)))
(defcustom helm-display-header-line t
"Display header-line when non nil."
:group 'helm
:type 'boolean)
(defcustom helm-file-globstar t
"Same as globstar bash shopt option.
When non--nil a pattern beginning with two stars will expand recursively.
Directories expansion is not supported yet."
:group 'helm
:type 'boolean)
(defcustom helm-inherit-input-method t
"Inherit `current-input-method' from `current-buffer' when non--nil.
The default is to enable this by default, the user can toggle the current
input method with `toggle-input-method'."
:group 'helm
:type 'boolean)
;;; Faces
;;
;;
(defgroup helm-faces nil
"Customize the appearance of helm."
:prefix "helm-"
:group 'faces
:group 'helm)
(defface helm-source-header
'((((background dark))
:background "#22083397778B"
:foreground "white"
:weight bold :height 1.3 :family "Sans Serif")
(((background light))
:background "#abd7f0"
:foreground "black"
:weight bold :height 1.3 :family "Sans Serif"))
"Face for source header in the helm buffer."
:group 'helm-faces)
(defface helm-visible-mark
'((((min-colors 88) (background dark))
(:background "green1" :foreground "black"))
(((background dark))
(:background "green" :foreground "black"))
(((background light)) :background "#d1f5ea")
(((min-colors 88))
(:background "green1"))
(t (:background "green")))
"Face for visible mark."
:group 'helm-faces)
(defface helm-header
'((t (:inherit header-line)))
"Face for header lines in the helm buffer."
:group 'helm-faces)
(defface helm-candidate-number
'((((background dark)) :background "Yellow" :foreground "black")
(((background light)) :background "#faffb5" :foreground "black"))
"Face for candidate number in mode-line." :group 'helm-faces)
(defface helm-selection
'((((background dark)) :background "ForestGreen"
:distant-foreground "black")
(((background light)) :background "#b5ffd1"
:distant-foreground "black"))
"Face for currently selected item in the helm buffer."
:group 'helm-faces)
(defface helm-separator
'((((background dark)) :foreground "red")
(((background light)) :foreground "#ffbfb5"))
"Face for multiline source separator."
:group 'helm-faces)
(defface helm-action
'((t (:underline t)))
"Face for action lines in the helm action buffer."
:group 'helm-faces)
(defface helm-prefarg
'((((background dark)) :foreground "green")
(((background light)) :foreground "red"))
"Face for showing prefix arg in mode-line."
:group 'helm-faces)
(defface helm-match
'((((background light)) :foreground "#b00000")
(((background dark)) :foreground "gold1"))
"Face used to highlight matches."
:group 'helm)
;;; Variables.
;;
;;
(defvar helm-type-attributes nil
"It's a list of \(TYPE ATTRIBUTES ...\).
ATTRIBUTES are the same as attributes for `helm-sources'.
TYPE connects the value to the appropriate sources.
Don't set this directly, use instead `define-helm-type-attribute'.
This allows specifying common attributes for several sources.
For example, sources which provide files can specify
common attributes with a `file' type.")
(defvar helm-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 `helm-set-source-filter'.")
(defvar helm-action-buffer "*helm action*"
"Buffer showing actions.")
(defvar helm-selection-overlay nil
"Overlay used to highlight the currently selected item.")
(defvar helm-async-processes nil
"List of information about asynchronous processes managed by helm.")
(defvar helm-before-initialize-hook nil
"Run before helm initialization.
This hook is run before init functions in `helm-sources',
that is before creation of `helm-buffer'.
Local variables for `helm-buffer' that need a value from `current-buffer'
can be set here with `helm-set-local-variable'.")
(defvar helm-after-initialize-hook nil
"Run after helm initialization.
This hook run inside `helm-buffer' once created.
Variables are initialized and the `helm-buffer' is created.
But the `helm-buffer' has no contents.")
(defvar helm-update-hook nil
"Run after the helm 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 `helm-after-update-hook'.")
(defvar helm-after-update-hook nil
"Run after the helm buffer was updated according the new input pattern.
This is very similar to `helm-update-hook' but selection is not moved.
It is useful to select a particular object instead of the first one.")
(defvar helm-cleanup-hook nil
"Run after helm minibuffer is closed.
IOW this hook is executed BEFORE performing action.")
(defvar helm-select-action-hook nil
"Run when opening the action buffer.")
(defvar helm-before-action-hook nil
"Run before executing action.
Contrarily to `helm-cleanup-hook',
this hook run before helm minibuffer is closed
and before performing action.")
(defvar helm-after-action-hook nil
"Run after executing action.")
(defvar helm-exit-minibuffer-hook nil
"Run just before exiting minibuffer.")
(defvar helm-after-persistent-action-hook nil
"Run after executing persistent action.")
(defvar helm-move-selection-before-hook nil
"Run before moving selection in `helm-buffer'.")
(defvar helm-move-selection-after-hook nil
"Run after moving selection in `helm-buffer'.")
(defvar helm-window-configuration-hook nil
"Run when switching to and back from action buffer.")
(defconst helm-restored-variables
'(helm-candidate-number-limit
helm-source-filter
helm-source-in-each-line-flag
helm-map
helm-sources)
"Variables which are restored after `helm' invocation.")
(defvar helm-execute-action-at-once-if-one nil
"Execute default action and exit when only one candidate is remaining.")
(defvar helm-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.")
(defvar helm-maybe-use-default-as-input nil
"Use :default arg of `helm' as input to update display.
Note that if also :input is specified as `helm' arg, it will take
precedence on :default.")
(defvar helm-source-in-each-line-flag nil
"Non-nil means add helm-source text-property in each candidate.
experimental feature.")
(defvar helm-debug-variables nil
"A list of helm variables to show in `helm-debug-output'.
Otherwise all variables started with `helm-' are shown.")
(defvar helm-debug-buffer "*Debug Helm Log*")
(defvar helm-debug nil
"If non-nil, write log message into `helm-debug-buffer' buffer.
It is disabled by default because `helm-debug-buffer' grows quickly.")
(defvar helm-compile-source-functions
'(helm-compile-source--type
helm-compile-source--dummy
helm-compile-source--candidates-in-buffer)
"Functions to compile elements of `helm-sources' (plug-in).")
(defvar helm-mode-line-string "\
\\<helm-map>\
\\[helm-help]:Help \
\\[helm-select-action]:Act \
\\[helm-maybe-exit-minibuffer]/\
f1/f2/f-n:NthAct"
"Help string displayed in mode-line in `helm'.
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'.")
;;; Internal Variables
;;
;;
(defvar helm-current-prefix-arg nil
"Record `current-prefix-arg' when exiting minibuffer.")
(defvar helm-saved-action nil
"Saved value of the currently selected action by key.")
(defvar helm-saved-current-source nil
"Value of the current source when the action list is shown.")
(defvar helm-compiled-sources nil
"Compiled version of `helm-sources'.")
(defvar helm-in-persistent-action nil
"Flag whether in persistent-action or not.")
(defvar helm-last-buffer nil
"`helm-buffer' of previously `helm' session.")
(defvar helm-saved-selection nil
"Value of the currently selected object when the action list is shown.")
(defvar helm-sources nil
"[INTERNAL] Value of current sources in use, a list.")
(defvar helm-buffer "*helm*"
"Buffer showing completions.")
(defvar helm-current-buffer nil
"Current buffer when `helm' is invoked.")
(defvar helm-buffer-file-name nil
"Variable `buffer-file-name' when `helm' is invoked.")
(defvar helm-candidate-cache (make-hash-table :test 'equal)
"Holds the available candidate within a single helm invocation.")
(defvar helm-pattern ""
"The input pattern used to update the helm buffer.")
(defvar helm-input ""
"The input typed in the candidates panel.")
(defvar helm-input-local nil
"Internal, store locally `helm-pattern' value for later use in `helm-resume'.")
(defvar helm-source-name nil)
(defvar helm-current-source nil)
(defvar helm-candidate-buffer-alist nil)
(defvar helm-match-hash (make-hash-table :test 'equal))
(defvar helm-cib-hash (make-hash-table :test 'equal))
(defvar helm-tick-hash (make-hash-table :test 'equal))
(defvar helm-issued-errors nil)
(defvar helm-debug-root-directory nil
"When non--nil, save helm log to `helm-last-log-file'.
Be aware that if you set that, you will end up with a huge directory
of log files, so use that only for debugging purpose.
See `helm-log-save-maybe' for more info.")
(defvar helm-last-log-file nil
"The name of the last helm session log file.")
(defvar helm-follow-mode nil)
(defvar helm--local-variables nil)
(defvar helm-split-window-state nil)
(defvar helm--window-side-state nil)
(defvar helm-selection-point nil)
(defvar helm-alive-p nil)
(defvar helm-visible-mark-overlays nil)
(defvar helm-update-blacklist-regexps '("^" "^ *" "$" "!" " " "\\b"
"\\<" "\\>" "\\_<" "\\_>" ".*"))
(defvar helm-suspend-update-flag nil)
(defvar helm-force-updating-p nil)
(defvar helm-exit-status 0
"Flag to inform whether helm have exited or quitted.
Exit with 0 mean helm have exited executing an action.
Exit with 1 mean helm have quitted with \\[keyboard-quit]
It is useful for example to restore a window config if helm abort
in special cases.
See `helm-exit-minibuffer' and `helm-keyboard-quit'.")
(defvar helm-minibuffer-confirm-state nil)
(defvar helm-quit nil)
(defvar helm-attributes nil "List of all `helm' attributes.")
(defvar helm-buffers nil
"All of `helm-buffer' in most recently used order.")
(defvar helm-current-position nil
"Cons of \(point . window-start\) when `helm' is invoked.
It is needed to restore position in `helm-current-buffer'
when `helm' is keyboard-quitted.")
(defvar helm-last-frame-or-window-configuration nil
"Used to store window or frame configuration when helm start.")
(defvar helm-onewindow-p nil)
(defvar helm-types nil)
(defvar helm--mode-line-string-real nil) ; The string to display in mode-line.
(defvar helm-persistent-action-display-window nil)
(defvar helm-marked-candidates nil
"Marked candadates. List of \(source . real\) pair.")
(defvar helm--mode-line-display-prefarg nil)
(defvar helm--temp-follow-flag nil
"[INTERNAL] A simple flag to notify persistent action we are following.")
(defvar helm--reading-passwd-or-string nil)
(defvar helm--in-update nil)
(defvar helm--in-fuzzy nil)
;; Utility: logging
(defun helm-log (format-string &rest args)
"Log message `helm-debug' is non-nil.
Messages are written to the `helm-debug-buffer' buffer.
Argument FORMAT-STRING is a string to use with `format'.
Use optional arguments ARGS like in `format'."
(when helm-debug
(with-current-buffer (get-buffer-create helm-debug-buffer)
(outline-mode)
(buffer-disable-undo)
(set (make-local-variable 'inhibit-read-only) t)
(goto-char (point-max))
(insert (let ((tm (current-time)))
(format (concat (if (string-match "Start session" format-string)
"* " "** ")
"%s.%06d (%s)\n %s\n")
(format-time-string "%H:%M:%S" tm)
(nth 2 tm)
(helm-log-get-current-function)
(apply #'format (cons format-string args))))))))
(defun helm-log-run-hook (hook)
"Run HOOK like `run-hooks' but write these actions to helm log buffer."
(helm-log "Executing %s with value = %S" hook (symbol-value hook))
(helm-log "Executing %s with global value = %S" hook (default-value hook))
(run-hooks hook)
(helm-log "executed %s" hook))
(defun helm-log-get-current-function ()
"Get function name calling `helm-log'.
The original idea is from `tramp-debug-message'."
(cl-loop with exclude-func-re = "^helm-\\(?:interpret\\|log\\|.*funcall\\)"
for btn from 1 to 40
for btf = (cl-second (backtrace-frame btn))
for fn = (if (symbolp btf) (symbol-name btf) "")
if (and (string-match "^helm" fn)
(not (string-match exclude-func-re fn)))
return fn))
(defun helm-log-error (&rest args)
"Accumulate error messages into `helm-issued-errors'.
ARGS are args given to `format'.
e.g (helm-log-error \"Error %s: %s\" (car err) (cdr err))."
(apply 'helm-log (concat "ERROR: " (car args)) (cdr args))
(let ((msg (apply 'format args)))
(unless (member msg helm-issued-errors)
(add-to-list 'helm-issued-errors msg))))
(defun helm-log-save-maybe ()
"May be save log buffer to `helm-last-log-file'.
If `helm-debug-root-directory' is non--nil and a valid directory,
a directory named 'helm-debug-<date of today>'
will be created there and the log recorded in a file named
at the date and time of today in this directory."
(when (and (stringp helm-debug-root-directory)
(file-directory-p helm-debug-root-directory)
helm-debug)
(let ((logdir (expand-file-name (concat "helm-debug-"
(format-time-string "%Y%m%d"))
helm-debug-root-directory)))
(make-directory logdir t)
(with-current-buffer (get-buffer-create helm-debug-buffer)
(write-region (point-min) (point-max)
(setq helm-last-log-file
(expand-file-name
(format-time-string "%Y%m%d-%H%M%S")
logdir))
nil 'silent)
(kill-buffer)))))
;;;###autoload
(defun helm-debug-open-last-log ()
"Open helm log file of last helm session.
If `helm-last-log-file' is nil, switch to `helm-debug-buffer' ."
(interactive)
(if helm-last-log-file
(view-file helm-last-log-file)
(switch-to-buffer helm-debug-buffer)
(view-mode 1) (visual-line-mode 1)))
(defun helm-print-error-messages ()
"Print error messages in `helm-issued-errors'."
(and helm-issued-errors
(message "Helm issued errors: %s"
(mapconcat 'identity (reverse helm-issued-errors) "\n"))))
;; Programming Tools
(defmacro helm-aif (test-form then-form &rest else-forms)
"Like `if' but set the result of TEST-FORM in a temprary variable called `it'.
THEN-FORM and ELSE-FORMS are then excuted just like in `if'."
(declare (indent 2) (debug t))
`(let ((it ,test-form))
(if it ,then-form ,@else-forms)))
(defun helm-mklist (obj)
"If OBJ is a list \(but not lambda\), return itself.
Otherwise make a list with one element."
(if (and (listp obj) (not (functionp obj)))
obj
(list obj)))
(defun helm-this-command ()
"Return the actual command in action.
Like `this-command' but return the real command,
not `exit-minibuffer' or unwanted functions."
(cl-loop with bl = '(helm-maybe-exit-minibuffer
helm-confirm-and-exit-minibuffer
helm-exit-minibuffer
exit-minibuffer)