-
-
Notifications
You must be signed in to change notification settings - Fork 391
/
helm-core.el
8131 lines (7272 loc) · 347 KB
/
helm-core.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-core.el --- Development files for Helm -*- lexical-binding: t -*-
;; Copyright (C) 2022 ~ 2023 Thierry Volpiatto
;; Author: Thierry Volpiatto <thievol@posteo.net>
;; URL: https://emacs-helm.github.io/helm/
;; Version: 4.0
;; Package-Requires: ((emacs "25.1") (async "1.9.8"))
;; 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 <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Contains the main code for Helm.
;; As a package helm-core provides the files helm-core.el, helm-lib.el,
;; helm-source.el and helm-multi-match.el.
;;; Code:
(require 'cl-lib)
(require 'async)
(require 'helm-lib)
(require 'helm-multi-match)
(require 'helm-source)
;; Setup completion styles for helm-mode
(helm--setup-completion-styles-alist)
(declare-function helm-comp-read "helm-mode.el")
(declare-function custom-unlispify-tag-name "cus-edit.el")
(declare-function helm-quit-and-find-file "helm-utils.el")
(declare-function linum-mode "linum.el")
(declare-function minibuffer-depth-setup "mb-depth.el")
(defvar helm-marked-buffer-name)
(defvar display-buffer-function)
(defvar minibuffer-follows-selected-frame)
(defvar minibuffer-depth-indicate-mode)
;;; Internal Variables
;;
;;
(defvar helm-source-filter nil
"A list of source names to be displayed.
Other sources won't appear in the search results.
If nil, no filtering is done.
Don't set this directly, use `helm-set-source-filter' during a
Helm session to modify it.")
(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-in-persistent-action nil
"Flag whether in persistent-action or not.")
(defvar helm-last-buffer nil
"`helm-buffer' of a previous 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 of alists.
The list of sources (symbols or alists) is normalized to alists
in `helm-initialize'.")
(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--candidate-buffer-alist nil)
(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-issued-errors nil)
(defvar helm--last-log-file nil
"The name of the log file of the last Helm session.")
(defvar helm--local-variables nil)
(defvar helm-split-window-state nil)
(defvar helm--window-side-state nil)
(defvar helm-selection-point nil
"The value of point at selection.")
(defvar helm-alive-p nil)
(defvar helm-visible-mark-overlays nil)
(defvar helm--force-updating-p nil
"[INTERNAL] Don't use this in your programs.")
(defvar helm-exit-status 0
"Flag to inform if Helm did exit or quit.
0 means Helm did exit when executing an action.
1 means Helm did quit with \\[keyboard-quit]
Knowing this exit-status could help restore a window config when
Helm aborts in some special circumstances. See
`helm-exit-minibuffer' and `helm-keyboard-quit'.")
(defvar helm-minibuffer-confirm-state nil)
(defvar helm--quit nil)
(defvar helm-buffers nil
"Helm buffers listed in order of most recently used.")
(defvar helm-current-position nil
"Cons of (point . window-start) when Helm is invoked.
`helm-current-buffer' uses this to restore position after
`helm-keyboard-quit'")
(defvar helm-last-frame-or-window-configuration nil
"Used to store window or frame configuration at 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 candidates. 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)
(defvar helm-maybe-use-default-as-input nil
"Flag to notify the use of use-default-as-input.
Use only in let-bindings.
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--temp-hooks nil
"Store temporary hooks added by `with-helm-temp-hook'.")
(defvar helm--prompt nil)
(defvar helm--file-completion-sources
'("Find Files" "Read File Name" "New file or directory")
"Sources that use the *find-files mechanism can be added here.
Sources generated by `helm-mode' don't need to be added here
because they are automatically added.
You should not modify this yourself unless you know what you are
doing.")
(defvar helm--completing-file-name nil
"Non nil when `helm-read-file-name' is running.
Used for `helm-file-completion-source-p'.")
;; Same as `ffap-url-regexp' but keep it here to ensure `ffap-url-regexp' is not nil.
(defvar helm--url-regexp "\\`\\(news\\(post\\)?:\\|mailto:\\|file:\\|\\(ftp\\|https?\\|telnet\\|gopher\\|www\\|wais\\)://\\)")
(defvar helm--ignore-errors nil
"Flag to prevent Helm popping up errors in candidates functions.
Should be set in candidates functions if needed, and will be
restored at end of session.")
(defvar helm--action-prompt "Select action: ")
(defvar helm--cycle-resume-iterator nil)
(defvar helm--buffer-in-new-frame-p nil)
(defvar helm-initial-frame nil
"[INTERNAL] The selected frame before starting Helm.
Helm use this internally to know in which frame it started, don't
modify this yourself.")
(defvar helm-popup-frame nil
"The frame where Helm is displayed.
This is only used when Helm is using
`helm-display-buffer-in-own-frame' as `helm-display-function' and
`helm-display-buffer-reuse-frame' is non nil.")
(defvar helm--nested nil)
(defconst helm--frame-default-attributes
'(width height tool-bar-lines left top
title undecorated vertical-scroll-bars
visibility fullscreen menu-bar-lines undecorated
alpha foreground-color background-color)
"Frame parameters to save in `helm--last-frame-parameters'.")
(defvar helm--last-frame-parameters nil
"Frame parameters to save for later resuming.
Local to `helm-buffer'.")
(defvar helm--executing-helm-action nil
"Non nil when action is triggering a new helm-session.
This may be let bounded in other places to notify the display
function to reuse the same frame parameters as the previous Helm
session just like resume would do.")
(defvar helm--current-buffer-narrowed nil)
(defvar helm--suspend-update-interactive-flag nil)
(defvar helm-persistent-action-window-buffer nil
"[INTERNAL] Store the buffer where helm is started.
It is generally `helm-current-buffer', but when this one is displayed
in a dedicated buffer, helm can't start in this window and use another
window handling a buffer, it is this one we store.")
(defvar helm--tramp-archive-maybe-loaded nil)
(defvar helm--original-dedicated-windows-alist nil
"[INTERNAL] Store all dedicated windows with their dedicated state on startup")
(defvar helm--deleting-minibuffer-contents-from nil
"[INTERNAL] Recenter when deleting minibuffer-contents and preselecting.
This is a flag used internally.")
(defvar helm--minibuffer-completing-file-name nil
"A flag notifying Helm is in file completion.
It is let-bounded in `helm-read-file-name'. Same as
`minibuffer-completing-file-name' but doesn't affect `file-directory-p'.")
;;; 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 runs sequentially for each KEY press.
If DELAY is specified, switch back to initial function of FUNCTIONS list
after DELAY seconds.
The functions in FUNCTIONS list take no args.
E.g.
(defun foo ()
(interactive)
(message \"Run foo\"))
(defun bar ()
(interactive)
(message \"Run bar\"))
(defun baz ()
(interactive)
(message \"Run baz\"))
\(helm-define-multi-key global-map (kbd \"<f5> q\") \\='(foo bar baz) 2)
Each time \"<f5> q\" is pressed, the next function is executed.
Waiting more than 2 seconds between key presses switches back to
executing the first function on the next hit."
(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 reinitialized.
See `helm-define-multi-key'."
(declare (indent 2) (doc-string 2))
(setq docstring (if docstring (concat docstring "\n\n")
"This is a helm-ish 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 in the FUNCTIONS list in turn when called within
DELAY seconds."
(declare (indent 1))
(let ((funs functions)
(iter (list nil)) ; ref-cell[1].
(timeout delay))
(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)
;; By passing a list containing a single 'nil' element [1] as ITERATOR we
;; avoid using a global var.
(unless (and (car iterator)
;; Reset iterator when another key is pressed.
(eq this-command real-last-command))
(setcar iterator (helm-iter-circular (funcall fn))))
(setq next (helm-iter-next (car iterator)))
(and next (car iterator)
(call-interactively (nth (1- next) functions)))
(when delay (run-with-idle-timer
delay nil (lambda ()
(setcar iterator nil))))))
(helm-multi-key-defun helm-toggle-resplit-and-swap-windows
"Multi key command to re-split and swap Helm window.
First call runs `helm-toggle-resplit-window',
and second call within 1s runs `helm-swap-windows'."
'(helm-toggle-resplit-window helm-swap-windows) 1)
(put 'helm-toggle-resplit-and-swap-windows 'helm-only t)
(defun helm-command-with-subkeys (map subkey command
&optional other-subkeys prompt exit-fn delay)
"Build a command that run COMMAND when SUBKEY is read.
The command runs a loop reading keys and exit when user stops typing after DELAY
seconds. After this DELAY EXIT-FN run if specified.
Arg OTHER-SUBKEYS should be an alist composed of (command . short-key) where
command is another command than COMMAND bound to short-key.
A PROMPT can be used to describe bindings of COMMAND and OTHER-SUBKEYS.
Return an anonymous interactive command to use with
`helm-define-key-with-subkeys'."
(lambda ()
(interactive)
(let (timer)
(call-interactively command)
(unless (or defining-kbd-macro executing-kbd-macro)
(unwind-protect
(progn
(when delay
(setq timer (run-with-idle-timer
delay nil (lambda () (keyboard-quit)))))
(while (let ((input (read-key prompt)) other kb com)
(setq last-command-event input)
(cond
((eq input subkey)
(call-interactively command)
(setq last-command command)
t)
((setq other (assoc input other-subkeys))
(call-interactively (cdr other))
(setq last-command (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)))))
(when timer (cancel-timer timer))
(and exit-fn (funcall exit-fn)))))))
;;;###autoload
(defun helm-define-key-with-subkeys (map key subkey command
&optional other-subkeys
prompt exit-fn delay
docstring)
"Define in MAP a KEY and SUBKEY to COMMAND.
This allows 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
key binding to call COMMAND.
Arg OTHER-SUBKEYS is an alist specifying other short key bindings
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 \"n\" will run this command again and subsequent \"p\"
will run `git-gutter:previous-hunk'.
If specified PROMPT can be displayed in minibuffer to describe
SUBKEY and OTHER-SUBKEYS. Arg EXIT-FN specifies a function to run
on exit.
For any other key pressed, run their assigned command as defined
in MAP and then exit the loop running EXIT-FN, if specified.
If DELAY is specified the command expires after DELAY seconds.
NOTE: SUBKEY and OTHER-SUBKEYS bindings support only char syntax
and vectors, so don't use strings to define them. While defining
or executing a kbd macro no SUBKEY or OTHER-SUBKEYS are provided,
i.e. the loop is not entered after running COMMAND."
(declare (indent 1))
(let ((fn (helm-command-with-subkeys
map subkey command other-subkeys prompt exit-fn delay))
(com (intern (format "helm-%s-with-subkeys"
(symbol-name command)))))
(defalias com fn
(or docstring
;; When no DOCSTRING, generate a basic one specifying
;; COMMAND, SUBKEY and OTHER-SUBKEYS.
(concat
(format "Run `%s' and bound it to `%s' for subsequent calls."
command (if (numberp subkey) (single-key-description subkey) subkey))
(if other-subkeys
(helm-basic-docstring-from-alist other-subkeys)
""))))
(define-key map key com)))
(defun helm-basic-docstring-from-alist (alist)
(let* ((len (length alist))
(osk (cl-loop for (k . v) in alist
for count from 1
for sep = (cond ((and (= count len) (> len 1))
" and ")
((> count 1) ",")
(t ""))
for key = (if (numberp k) (single-key-description k) k)
concat (format "%s`%s'" sep key) into ks
concat (format "%s`%s'" sep v) into kv
finally return (list ks kv))))
(format "\nBound as well %s to %s%s."
(car osk) (if (> len 1) "respectively " "") (cadr osk))))
;;; 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-scroll-up)
(define-key map (kbd "C-v") #'helm-scroll-down)
(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 "<RET>") #'helm-maybe-exit-minibuffer)
(define-key map (kbd "C-i") #'helm-select-action)
(define-key map (kbd "C-j") #'helm-execute-persistent-action)
(define-key map (kbd "C-o") #'helm-next-source)
(define-key map (kbd "M-o") #'helm-previous-source)
(define-key map (kbd "<right>") #'helm-next-source)
(define-key map (kbd "<left>") #'helm-previous-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-forward)
(define-key map (kbd "M-SPC") #'helm-toggle-visible-mark-backward)
(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-k") #'helm-delete-minibuffer-contents)
(define-key map (kbd "DEL") #'helm-delete-char-backward)
(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-M-a") #'helm-show-all-candidates-in-source)
(define-key map (kbd "C-M-e") #'helm-display-all-sources)
(define-key map (kbd "C-s") #'undefined)
(define-key map (kbd "M-s") #'undefined)
(define-key map (kbd "C-r") #'undefined)
(define-key map (kbd "C-M-r") #'undefined)
(define-key map (kbd "C-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 _") #'helm-toggle-full-frame)
(define-key map (kbd "C-z") #'helm-toggle-full-frame)
(define-key map (kbd "C-c %") #'helm-exchange-minibuffer-and-header-line)
(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-insert-or-copy)
(define-key map (kbd "C-c C-f") #'helm-follow-mode)
(define-key map (kbd "C-c C-u") #'helm-refresh)
(define-key map (kbd "C-c >") #'helm-toggle-truncate-line)
(define-key map (kbd "C-c l") #'helm-display-line-numbers-mode)
(define-key map (kbd "M-p") #'previous-history-element)
(define-key map (kbd "M-n") #'next-history-element)
;; Unbind `previous-matching-history-element' which is non sense for helm.
(define-key map (kbd "M-r") #'undefined)
(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)
(helm-define-key-with-subkeys map (kbd "C-c n") ?n #'helm-run-cycle-resume)
;; Disable `file-cache-minibuffer-complete'.
(define-key map (kbd "<C-tab>") #'undefined)
;; Multi keys
(define-key map (kbd "C-t") #'helm-toggle-resplit-and-swap-windows)
;; Debugging command
(define-key map (kbd "C-h C-d") #'helm-enable-or-switch-to-debug)
(define-key map (kbd "C-h c") #'helm-customize-group)
(define-key map (kbd "C-h d") #'helm-debug-output)
;; Allow to eval keymap without errors.
(define-key map [f1] nil)
(define-key map (kbd "C-h C-h") #'undefined)
(define-key map (kbd "C-h h") #'undefined)
(helm-define-key-with-subkeys map
(kbd "C-w") ?\C-w #'helm-yank-text-at-point
'((?\C-_ . helm-undo-yank-text-at-point)))
;; Use `describe-mode' key in `global-map'.
(dolist (k (where-is-internal #'describe-mode global-map))
(define-key map k #'helm-help))
;; Bind all actions from f1 to f12, `helm-select-nth-action'
;; counts from 0, i.e. (helm-select-nth-action 0) = action 1.
(dotimes (n 12)
(define-key map (kbd (format "<f%s>" (1+ n)))
(lambda ()
(interactive)
(helm-select-nth-action n))))
map)
"Keymap for helm.")
(defun helm-customize-group-1 (group)
(require 'cus-edit)
(let ((name (format "*Customize Group: %s*"
(custom-unlispify-tag-name group))))
(if (buffer-live-p (get-buffer name))
(switch-to-buffer name)
(custom-buffer-create
(list (list group 'custom-group))
name
(concat " for group "
(custom-unlispify-tag-name group))))))
(defun helm-customize-group ()
"Jump to customization group of current source.
Default to Helm group when group is not defined in source."
(interactive)
(let ((source (or (helm-get-current-source)
(helm-comp-read
"Customize variables for: "
(cl-loop for src in (with-helm-buffer helm-sources)
collect `(,(assoc-default 'name src) .
,src))
:allow-nest t
:exec-when-only-one t))))
(helm-run-after-exit 'helm-customize-group-1 (helm-get-attr 'group source))))
(put 'helm-customize-group 'helm-only t)
(defun helm--action-at-nth-set-fn-1 (value &optional negative)
(dotimes (n 9)
(let ((key (format value (1+ n)))
(fn (lambda ()
(interactive)
(helm-execute-selection-action-at-nth
(if negative (- (1+ n)) (1+ n))))))
(define-key helm-map (kbd key) nil)
(define-key helm-map (kbd key) fn))))
(defun helm--action-at-nth-set-fn- (var val)
(set var val)
(helm--action-at-nth-set-fn-1 val 'negative))
(defun helm--action-at-nth-set-fn+ (var val)
(set var val)
(helm--action-at-nth-set-fn-1 val))
(defcustom helm-action-at-nth-negative-prefix-key "C-x %d"
"The prefix key to execute default action on nth <-n> candidate.
This is a format spec where %d will be replaced by the candidate
number.
NOTE: `setq' have no effect until you restart Emacs, use
customize for immediate effect."
:group 'helm
:type 'string
:set #'helm--action-at-nth-set-fn-)
(defcustom helm-action-at-nth-positive-prefix-key "C-c %d"
"The prefix key to execute default action on nth <+n> candidate.
This is a format spec where %d will be replaced by the candidate
number.
NOTE: `setq' have no effect until you restart Emacs, use
customize for immediate effect."
:group 'helm
:type 'string
:set #'helm--action-at-nth-set-fn+)
(defgroup helm nil
"Open Helm."
:prefix "helm-" :group 'convenience)
;; Easy access to customize
;;;###autoload
(defun helm-configuration ()
"Customize Helm."
(interactive)
(customize-group "helm"))
(defcustom helm-completion-window-scroll-margin 5
"`scroll-margin' to use for Helm completion window.
Set to 0 to disable.
NOTE: This has no effect when `helm-display-source-at-screen-top'
id is non-nil."
:group 'helm
:type 'integer)
(defcustom helm-left-margin-width 0
"`left-margin-width' value for the `helm-buffer'."
:group 'helm
:type 'integer)
(defcustom helm-display-source-at-screen-top t
"Display candidates at the top of screen.
This happens with `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 500
"Global limit for number of candidates displayed.
When the pattern is empty, the number of candidates shown will be
as set here instead of the entire list, which may be hundreds or
thousands. Since narrowing and filtering rapidly reduces
available candidates, having a small list will keep the interface
responsive.
Set this value to nil for no limit."
:group 'helm
:type '(choice (const :tag "Disabled" nil) integer))
(defcustom helm-input-idle-delay 0.01
"Idle time before updating, specified in seconds."
:group 'helm
:type 'float)
(defcustom helm-exit-idle-delay 0
"Idle time before exiting minibuffer while Helm is updating.
Has no affect when helm-buffer is up to date (i.e. exit without
delay in this condition)."
:group 'helm
:type 'float)
(defvaralias 'helm-samewindow 'helm-full-frame)
(make-obsolete-variable 'helm-samewindow 'helm-full-frame "1.4.8.1")
(defcustom helm-full-frame nil
"Use current window for showing candidates.
If t, then Helm does not pop-up a new window."
:group 'helm
:type 'boolean)
(defcustom helm-candidate-separator
(if (fontp (char-displayable-p (read "#x2015")))
"――――――――――――――――――――――――――――――――――――――"
"--------------------------------------")
"Candidates separator of `multiline' source."
:group 'helm
:type 'string)
(defcustom helm-save-configuration-functions
'(set-window-configuration . current-window-configuration)
"Functions used to restore or save configurations for frames and windows.
Specified as a pair of functions, where car is the restore
function and cdr is the save function.
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 versions saves/restores frame configuration, but
the default has changed now to avoid flickering."
:group 'helm
:type 'sexp)
(defcustom helm-display-function 'helm-default-display-buffer
"Function used to display `helm-buffer'.
Local value in `helm-buffer' will take precedence on this default
value. Commands that are in `helm-commands-using-frame' will have
`helm-buffer' displayed in frame, `helm-display-function' being
ignored.
If no local value is found and current command is not one of
`helm-commands-using-frame' use this default value.
The function in charge of deciding which value use is
`helm-resolve-display-function'.
To set it locally to `helm-buffer' in Helm sources use
`helm-set-local-variable' in init function or use
:display-function slot in `helm' call."
:group 'helm
:type 'symbol)
(defcustom helm-case-fold-search 'smart
"Adds \\='smart' option to `case-fold-search'.
Smart option ignores case for searches as long as there are no
upper case characters in the pattern.
Use nil or t to turn off smart behavior and use
`case-fold-search' behavior.
Default is smart.
NOTE: Case fold search has no effect when searching asynchronous
sources, which relies on customized features implemented directly
into their execution process. See helm-grep.el for an example."
: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
"Use the same state of window split, vertical or horizontal.
`helm-toggle-resplit-window' for the next helm session will use
the same window scheme as the previous session unless
`helm-split-window-default-side' is \\='same or \\='other."
:group 'helm
:type 'boolean)
(defcustom helm-split-width-threshold nil
"The value of `split-width-threshold' for helm windows.
This affect the behavior of `helm-split-window-default-fn'.
When the value is an integer, `split-window-sensibly' is used inconditionally
and all the helm variables that affect window splitting are ignored."
:group 'helm
:type '(choice
(const :tag "Maybe use `split-window-sensibly'" nil)
(integer :tag "Inconditionally use `split-window-sensibly'")))
(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 displays
`helm-buffer' in current window and `other' that displays
`helm-buffer' below if only one window or in
`other-window-for-scrolling' when available.
A nil value has same effect as `below'. If `helm-full-frame' is
non-nil, it take precedence over this setting.
See also `helm-split-window-inside-p' and
`helm-always-two-windows' that take precedence over this.
NOTE: this has no effect if
`helm-split-window-preferred-function' is not
`helm-split-window-default-fn' unless this new function can
handle this."
:group 'helm
:type 'symbol)
(defcustom helm-split-window-other-side-when-one-window 'below
"Place for `helm-window' when `helm-split-window-default-side' is \\='other.
The default side to display `helm-buffer' when (1)
`helm-split-window-default-side' is \\='other and (2)
the current frame only has one window. Possible values
are acceptable args for `split-window' SIDE, that is `below',
`above', `left' or `right'.
If `helm-full-frame' is non-nil, it takes precedence over this
setting.
See also `helm-split-window-inside-p' and `helm-always-two-windows' that
takes precedence over this.
NOTE: this has no effect if
`helm-split-window-preferred-function' is not
`helm-split-window-default-fn' unless this new function can
handle this."
:group 'helm
:type 'symbol)
(defcustom helm-display-buffer-default-height nil
"Initial height of `helm-buffer', specified as an integer or a function.
The function should take one arg and be responsible for re-sizing
the window; function's return value is ignored. Note that this
has no effect when the split is vertical. See `display-buffer'
for more info."
:group 'helm
:type '(choice integer function))
(defcustom helm-display-buffer-default-width nil
"Initial width of `helm-buffer', specified as an integer or a function.
The function should take one arg and be responsible for re-sizing
the window; function's return value is ignored. Note that this
have no effect when the split is horizontal. See `display-buffer'
for more info."
:group 'helm
:type '(choice integer function))
(defvaralias 'helm-split-window-in-side-p 'helm-split-window-inside-p)
(make-obsolete-variable 'helm-split-window-in-side-p 'helm-split-window-inside-p "2.8.6")
(defcustom helm-split-window-inside-p nil
"Force split inside selected window when non-nil.
See also `helm-split-window-default-side'.
NOTE: this has no effect if
`helm-split-window-preferred-function' is not
`helm-split-window-default-fn' unless this new function can
handle this."
:group 'helm
:type 'boolean)
(defcustom helm-always-two-windows t
"When non-nil Helm uses two windows in this frame.
I.e. `helm-buffer' in one window and `helm-current-buffer'
in the other.
Note: this has no effect when `helm-split-window-inside-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.
Also when non-nil it overrides the effect of
`helm-split-window-default-side' set to `other'."
:group 'helm
:type 'boolean)
(defcustom helm-display-buffer-width 72
"Frame width when displaying helm-buffer in own frame."
:group 'helm
:type 'integer)
(defcustom helm-display-buffer-height 20
"Frame height when displaying helm-buffer in own frame."
:group 'helm
:type 'integer)
(defcustom helm-default-display-buffer-functions nil
"Action functions to pass to `display-buffer'.
See (info \"(elisp) Buffer Display Action Functions\").
It may override others helm window related variables settings like
`helm-always-two-windows', `helm-split-window-inside-p' etc..."
:group 'helm
:type '(repeat symbol))
(defcustom helm-default-display-buffer-alist nil
"Additional alist to pass to `display-buffer' action.
See (info \"(elisp) Action Alists for Buffer Display\").
It may override others helm window related variables settings like
`helm-always-two-windows', `helm-split-window-inside-p' etc...
Note that window-height and window-width have to be configured in
`helm-display-buffer-height' and `helm-display-buffer-width'."
:group 'helm
:type '(alist :key-type symbol :value-type sexp))
(defcustom helm-sources-using-default-as-input '(helm-source-imenu
helm-source-imenu-all
helm-source-info-elisp
helm-source-etags-select
helm-source-man-pages
helm-source-occur
helm-source-moccur
helm-source-grep-ag
helm-source-grep-git
helm-source-grep)
"List of Helm sources that need to use `helm-maybe-use-default-as-input'.
When a source is a 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' deletes region from `point'.
Otherwise it deletes `minibuffer-contents'.
See documentation for `helm-delete-minibuffer-contents'."
:group 'helm
:type 'boolean)
(defcustom helm-follow-mode-persistent nil
"When non-nil, save last state of `helm-follow-mode' for the next Emacs sessions.
Each time you turn on or off `helm-follow-mode', the current
source name will be stored or removed from
`helm-source-names-using-follow'.
Note that this may be disabled in some places where it is unsafe
to use because persistent action is changing according to
context."
:group 'helm
:type 'boolean)
(defcustom helm-source-names-using-follow nil
"A list of source names to have follow enabled.
This list of source names will be used only
when `helm-follow-mode-persistent' is non-nil.
You don't have to customize this yourself unless you really want
and know what you are doing, instead just set
`helm-follow-mode-persistent' to non-nil and as soon as you turn
on or off `helm-follow-mode' (C-c C-f) in a source, Helm will
save or remove source name in this variable."
:group 'helm
:type '(repeat (choice string)))
(defcustom helm-prevent-escaping-from-minibuffer t
"Prevent escaping from minibuffer with `other-window' during the Helm session."
:group 'helm
:type 'boolean)
(defcustom helm-allow-mouse t
"Allow mouse usage during the Helm session when non-nil.
Note that this also allows moving out of minibuffer when clicking
outside of `helm-buffer', so it is up to you to get back to Helm
by clicking back in `helm-buffer' or minibuffer."
:group 'helm
:type 'boolean)
(defcustom helm-move-to-line-cycle-in-source t
"Cycle to the beginning or end of the list after reaching the bottom or top.
This applies 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."
:group 'helm
:type 'function)
(defcustom helm-fuzzy-matching-highlight-fn #'helm-fuzzy-default-highlight-match
"The function to highlight fuzzy matches.
The function must have the same signature as
`helm-fuzzy-default-highlight-match' which is the default."
:group 'helm
:type 'function)
(defcustom helm-autoresize-max-height 40
"Specify maximum height and defaults to percent of Helm window's frame height.
See `fit-window-to-buffer' for more infos."
:group 'helm
:type 'integer)
(defcustom helm-autoresize-min-height 10
"Specify minimum height and defaults to percent of Helm window's frame height.
If nil, `window-min-height' is used.
See `fit-window-to-buffer' for details."
:group 'helm
:type 'integer)
(defcustom helm-input-method-verbose-flag nil
"The default value for `input-method-verbose-flag' used in Helm minibuffer.
It is nil by default, which does not turn off input method. Helm
updates and exits without interruption -- necessary for complex
methods.
If set to any other value as per `input-method-verbose-flag',
then use `C-\\' to disable the `current-input-method' to exit or
update Helm."
:group 'helm
:type '(radio :tag "A flag to control extra guidance for input methods in helm."
(const :tag "Never provide guidance" nil)
(const :tag "Always provide guidance" t)
(const :tag "Provide guidance only for complex methods" complex-only)))
(defcustom helm-display-header-line t
"Display header-line when non nil.
It has to be non nil when you want to display minibuffer contents in there with
`helm-echo-input-in-header-line'."
: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 and then toggle
`toggle-input-method'."
:group 'helm
:type 'boolean)
(defcustom helm-echo-input-in-header-line nil
"Send current input to header-line when non-nil.
Note that `helm-display-header-line' has to be non nil as well for this to take
effect."
:group 'helm
:type 'boolean)
(defcustom helm-header-line-space-before-prompt 'left-fringe
"Specify the space before prompt in header-line.
This will be used when `helm-echo-input-in-header-line' is
non-nil.
Value can be one of the symbols \\='left-fringe or \\='left-margin or
an integer specifying the number of spaces before prompt. Note
that on input longer that `window-width' the continuation string
will be shown on left side of window without taking care of
this."