-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinit-helm.el
796 lines (716 loc) · 31.6 KB
/
init-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
;;; init-helm.el --- My startup file for helm. -*- lexical-binding: t -*-
;;; Code:
;;; Set up helm first (will load helm-autoloads.el)
(require 'helm)
;; Only needed when installed from source.
;; NOTE: package.el creates an autoload file without a provide whereas
;; make creates it with a provide, so require helm-autoloads is
;; supported only when building with make from source.
(require 'helm-autoloads)
(setq helm-input-idle-delay 0.01
helm-reuse-last-window-split-state t
helm-always-two-windows t
helm-split-window-inside-p nil
helm-commands-using-frame '(completion-at-point helm-imenu
helm-imenu-in-all-buffers)
helm-actions-inherit-frame-settings t
helm-use-frame-when-more-than-two-windows t
helm-use-frame-when-no-suitable-window t
helm-frame-background-color "DarkSlateGray"
helm-show-action-window-other-window 'left
helm-allow-mouse t
helm-move-to-line-cycle-in-source t
helm-autoresize-max-height 80 ; it is %.
helm-autoresize-min-height 20 ; it is %.
helm-debug-root-directory "/home/thierry/tmp/helm-debug"
helm-follow-mode-persistent t
helm-candidate-number-limit 500
helm-visible-mark-prefix "✓")
(set-face-foreground 'helm-mark-prefix "Gold1")
(add-to-list 'helm-sources-using-default-as-input 'helm-source-info-bash)
(helm-define-key-with-subkeys global-map (kbd "C-c n") ?n 'helm-cycle-resume)
(define-key helm-map (kbd "C-%") #'helm-exchange-minibuffer-and-header-line)
(define-key helm-map (kbd "C--") #'helm-swap-windows)
(defun helm-add-to-list (var elm index)
"Add or move ELM to the value of VAR at INDEX unless already here.
If ELM is member of var value and at index INDEX, return var value
unchanged, if INDEX value is different move ELM at this `nth' INDEX value.
If ELM is not present in list add it at `nth' INDEX.
Do not use this function in helm code, use `helm-append-at-nth'
instead. It is meant to be used in config files only."
(cl-assert (boundp var) nil "Unbound variable `%s'" var)
(let ((val (symbol-value var))
flag)
(cond ((and (member elm val) (equal elm (nth index val)))
val)
((member elm val)
(setq val (delete elm val) flag t))
(t (setq flag t)))
(if flag
(set var (helm-append-at-nth val elm index))
val)))
;;; Load all autoloads for helm extensions
;;
;;
(load "/home/thierry/elisp/helm-extensions/helm-extensions-autoloads.el")
(defun helm/debug-toggle ()
(interactive)
(setq helm-debug (not helm-debug))
(message "Helm Debug is now %s"
(if helm-debug "Enabled" "Disabled")))
(defun helm/occur-which-func ()
(interactive)
(with-current-buffer
(or (helm-aif (with-helm-buffer
(window-buffer helm-persistent-action-display-window))
(and (null (minibufferp it)) it))
helm-current-buffer)
(when (eq major-mode 'emacs-lisp-mode)
(message "[%s]" (which-function)))))
(defun helm/bash-history ()
(interactive)
(helm :sources (helm-build-in-file-source "Bash history" "~/.bash_history"
:action '(("Kill new" . kill-new)
("Send command to Tmux" . emamux:send-command)))
:buffer "*helm bash history*"))
;;; Package declarations.
;;
;;; Helm-mode (it is loading nearly everything)
;;
(with-eval-after-load 'help-fns
(setq help-enable-completion-autoload nil))
(add-hook 'helm-mode-hook
(lambda ()
(setq completion-styles
(cond ((assq 'helm-flex completion-styles-alist)
'(helm-flex)) ;; emacs-26.
((assq 'flex completion-styles-alist)
'(flex)))))) ;; emacs-27+.
(setq helm-completion-mode-string " ⎈")
(helm-mode 1)
(setq helm-completing-read-handlers-alist
'((find-tag . helm-completing-read-default-find-tag)
(ggtags-find-tag-dwim . helm-completing-read-default-find-tag)
(tmm-menubar)
(find-file)
(execute-extended-command)
(shell) ; Fixed by c04b867a but completion is useless here.
(cancel-debug-on-entry)
(org-capture . helm-org-completing-read-tags)
(org-set-tags . helm-org-completing-read-tags)
(dired-do-rename . helm-read-file-name-handler-1)
(dired-do-copy . helm-read-file-name-handler-1)
(dired-do-symlink . helm-read-file-name-handler-1)
(dired-do-relsymlink . helm-read-file-name-handler-1)
(dired-do-hardlink . helm-read-file-name-handler-1)
(dired-do-touch . nil)
(read-multiple-choice--long-answers . nil)
(basic-save-buffer . helm-read-file-name-handler-1)
(write-file . (default helm-read-file-name-handler-1))
(write-region . (default helm-read-file-name-handler-1))
(all-the-icons-insert . helm-mode-all-the-icons-handler)))
;; Fix CAP with LSP in python.
(add-to-list 'helm-completion-styles-alist '(python-mode . (emacs helm helm-flex)))
;; Custom completion matching
;; (add-to-list 'helm-completion-styles-alist '(wfnames-mode . (emacs helm flex)))
(add-to-list 'helm-completion-styles-alist '(switch-to-buffer . helm-fuzzy))
;; `completions-detailed' works now with both
;; `helm-completing-read-default-1' and
;; `helm-completing-read-default-2'. To test it with *default-2 add
;; the describe-* fns to helm-completion-styles-alist
;; i.e. (fun . (emacs helm flex)).
(if (boundp 'completions-detailed)
(setq completions-detailed t)
;; Emacs-27<
(setq helm-completions-detailed t))
;;; Helm-adaptive
;;
(require 'helm-adaptive)
(setq helm-adaptive-history-file nil)
(helm-adaptive-mode 1)
;;; Helm-bookmark
;;
(with-eval-after-load 'helm-bookmark
(customize-set-variable 'helm-bookmark-use-icon t)
(customize-set-variable 'helm-bookmark-annotation-sign "✫"))
;;; Helm-utils
;;
(with-eval-after-load 'helm-utils
;; Popup buffer-name or filename in grep/moccur/imenu-all etc...
(helm-popup-tip-mode 1)
(setq helm-highlight-matches-around-point-max-lines '(30 . 30))
(add-hook 'find-file-hook 'helm-save-current-pos-to-mark-ring))
;;; Helm-sys
;;
(helm-top-poll-mode 1)
;;; Helm-ring
;;
(with-eval-after-load 'helm-ring
(setq helm-kill-ring-threshold 1)
;; Actions for helm kill-ring
(defun helm-ring-split-block (string)
(with-temp-buffer
(insert string)
(goto-char (point-min))
(helm-awhile (read (current-buffer))
(kill-new (prin1-to-string it)))))
(defun helm-kill-ring-insert-hunk (hunk)
"Yank string HUNK copied from a diff buffer."
(helm-kill-ring-action-yank-1
(with-temp-buffer
(insert hunk)
(goto-char (point-min))
(while (re-search-forward "^[+-]" nil t)
(replace-match ""))
(buffer-string))))
(add-to-list 'helm-kill-ring-actions '("Split block" . helm-ring-split-block) t)
(add-to-list 'helm-kill-ring-actions '("Insert hunk" . helm-kill-ring-insert-hunk) t)
(define-key helm-kill-ring-map (kbd "C-d") 'helm-kill-ring-run-persistent-delete))
;;; Helm-buffers
;;
(with-eval-after-load 'helm-buffers
(setq helm-buffers-favorite-modes
(append helm-buffers-favorite-modes '(picture-mode artist-mode))
helm-buffer-skip-remote-checking t
helm-buffer-max-length 36
helm-buffers-fuzzy-matching t
helm-mini-default-sources '(helm-source-buffers-list
helm-source-buffer-not-found)
helm-boring-buffer-regexp-list
'("\\` " "\\`\\*helm" "\\`\\*Echo Area" "\\`\\*Minibuf"
"\\`\\*Messages" "\\`\\*Magit" "\\`\\*git-gutter" "\\`\\*Help" "\\`\\*skitour"))
(customize-set-variable 'helm-buffers-maybe-switch-to-tab t)
(customize-set-variable 'helm-buffers-show-icons t)
(define-key helm-buffer-map (kbd "C-d") 'helm-buffer-run-kill-persistent))
;;; Helm-files
;;
(with-eval-after-load 'helm-files
(setq helm-ff-auto-update-initial-value t
helm-ff-allow-non-existing-file-at-point t
helm-trash-remote-files t
helm-dwim-target 'next-window
helm-locate-recursive-dirs-command "fdfind --hidden --type d --glob '*%s*' %s"
helm-ff-eshell-unwanted-aliases '("sudo" "cdu" "man"
"gpg-pubkey-export-armor" "gpg-secretkey-export-armor")
helm-ff-drag-and-drop-default-directory "/home/thierry/Bureau/"
helm-file-name-history-hide-deleted t
helm-ff-ignore-following-on-directory t
helm-rsync-progress-bar-function #'helm-rsync-svg-progress-bar)
(customize-set-variable 'helm-ff-nohighlight-matches nil)
(require 'image-dired)
(setq image-dired-thumbnail-storage 'standard
;; Be consistent with emacs-29.
image-dired-cmd-pngnq-program "pngquant"
image-dired-cmd-pngnq-options '("--ext" "-nq8.png" "%t"))
(setq helm-ff-edit-marked-files-fn #'helm-ff-wfnames)
(defun helm-ff-dragon (files)
"Create a small window with FILES ready to drag and drop.
Use this to drop files on externals applications or desktop.
Dropping on emacs buffers with this is not supported.
Needs `dragon' executable: https://github.com/mwh/dragon."
(interactive (list (helm-marked-candidates)))
(cl-assert (executable-find "dragon") nil "Dragon executable not found")
(apply #'call-process "dragon" nil nil nil "--all" "--and-exit" files))
(define-key helm-find-files-map (kbd "C-c m") 'helm-ff-dragon)
(customize-set-variable 'helm-ff-lynx-style-map t)
(define-key helm-read-file-map (kbd "RET") 'helm-ff-RET)
(define-key helm-find-files-map (kbd "C-i") nil)
(define-key helm-find-files-map (kbd "C-d") 'helm-ff-persistent-delete)
(defun helm/insert-date-in-minibuffer ()
(interactive)
(with-selected-window (or (active-minibuffer-window)
(minibuffer-window))
(unless (or (helm-follow-mode-p)
helm--temp-follow-flag)
(insert (format-time-string "%Y-%m-%d-%H:%M")))))
(define-key helm-find-files-map (kbd "C-c y") 'helm/insert-date-in-minibuffer)
(define-key helm-read-file-map (kbd "C-c y") 'helm/insert-date-in-minibuffer)
(defun helm/ff-candidates-lisp-p (candidate)
(cl-loop for cand in (helm-marked-candidates)
always (string-match "\\.el$" cand)))
(defun helm-ff-recoll-index-directory (directory)
"Create a recoll index directory from DIRECTORY.
Add the new created directory to `helm-recoll-directories' using the
basename of DIRECTORY as name.
By using `customize-set-variable', a new source is created for this
new directory."
(cl-assert (boundp 'helm-recoll-directories) nil
"Package helm-recoll not installed or configured")
(let* ((bn (helm-basename (expand-file-name directory)))
(index-dir (format "~/.recoll-%s" bn))
(conf-file (expand-file-name "recoll.conf" index-dir)))
(mkdir index-dir)
(with-current-buffer (find-file-noselect conf-file)
(insert (format "topdirs = %s" (expand-file-name directory)))
(save-buffer)
(kill-buffer))
(customize-set-variable 'helm-recoll-directories
(append `((,bn . ,index-dir)) helm-recoll-directories))
(message "Don't forget to index config directory with 'recollindex -c %s'" index-dir)))
(defun helm-ff-recoll-index-directories (_candidate)
(let ((dirs (helm-marked-candidates)))
(cl-loop for dir in dirs
when (file-directory-p dir)
do (helm-ff-recoll-index-directory dir))))
(defun tv:change-xfce-background (file)
(let* ((screen (getenv "DISPLAY"))
(monitor (shell-command-to-string
"echo -n $(xrandr | awk '/\\w* connected/ {print $1}')"))
(desktop (and (display-graphic-p)
(x-window-property "_NET_CURRENT_DESKTOP" nil "CARDINAL" 0 nil t)))
(prop (format "/backdrop/screen%s/monitor%s/workspace%s/last-image"
(substring screen (1- (length screen)))
monitor
(or desktop 0)))
(proc (apply #'start-process "set background" nil "xfconf-query"
`("-c" "xfce4-desktop" "-p" ,prop "-s" ,file))))
(set-process-sentinel
proc (lambda (_proc event)
(if (string= event "finished\n")
(message "Background changed successfully to %s" (helm-basename file))
(message "Failed to change background"))))))
(defun helm-ff-csv2ledger (candidate)
(csv2ledger "Socgen" candidate "/home/thierry/finance/ledger.dat"))
(defun helm/update-directory-autoloads (candidate)
(let ((default-directory helm-ff-default-directory)
(file
(read-file-name "Write autoload definitions to file: "
helm-ff-default-directory
nil nil nil
(lambda (f)
(string-match "autoloads\\|loaddefs" f)))))
(if (fboundp 'loaddefs-generate)
(loaddefs-generate default-directory file)
(let ((generated-autoload-file file))
(update-directory-autoloads default-directory)))))
(defun helm-restore-backups (_candidate)
(let ((mkd (helm-marked-candidates))
(copied 0)
ovw)
(cl-dolist (file mkd)
(let (dest)
(when (string-match "\\(?:\\`\\([!]\\)[^!]*\\1.*\\)\\|\\(?:~\\'\\)"
(helm-basename file))
(setq dest (helm-aand (replace-regexp-in-string
"\\.~[[:digit:]]*~?"
"" (helm-basename file))
(helm--normalize-backup-name it)
(if (string-match "\\`/" it)
it
;; If basename doesn't contain now
;; "/", that's mean it was a backup file
;; stored in current directory, just
;; expand it to this directory.
(expand-file-name it helm-ff-default-directory))))
(if (and (file-exists-p dest) (null ovw))
(helm-acase (helm-read-answer
(format "Overwrite `%s' (answer [y,n,!,q])? " dest)
'("y" "n" "!" "q"))
("y" (cl-incf copied) (copy-file file dest t t t t))
("n" (ignore))
("!" (setq ovw t) (cl-incf copied) (copy-file file dest t t t t))
("q" (setq copied nil) (cl-return (message "Abort restoring files"))))
(cl-incf copied)
(copy-file file dest t t t t)))))
(when (numberp copied)
(message "(%s/%s) files copied" copied (length mkd)))))
(defun helm--normalize-backup-name (fname)
"Normalize backup FNAME to its original name."
;; When Emacs build a backup filename for the backup directory it
;; replace "/" by "!" in the basedir of file and double the "!" in
;; the basename, this is done by `make-backup-file-name-1'. We want
;; to replace only the "!" in the basedir part of FNAME.
(with-temp-buffer
(insert fname)
(goto-char (point-min))
(save-excursion
(when (looking-at "!") (replace-match "/"))
(while (re-search-forward "[^!]\\([!]\\)[^!]" nil t)
(replace-match "/" nil nil nil 1)))
(let ((count 0) rep)
(while (re-search-forward "!" nil t)
(cl-incf count))
(setq rep (make-string (/ count 2) ?!))
(replace-regexp-in-string "[!]+" rep (buffer-string)))))
;; Add actions to `helm-source-find-files' IF:
(cl-defmethod helm-setup-user-source ((source helm-source-ffiles))
"Adds additional actions and settings to `helm-find-files'.
- Byte compile file(s) async
- Byte recompile directory async
- Open info file
- Patch region on directory
- Open in emms
- Update directory autoloads
- Recoll directory creation
- Epa encrypt file
- Change background
- Csv2ledger
- Restore backup files"
(helm-aif (slot-value source 'match)
(setf (slot-value source 'match)
(append it
'((lambda (candidate)
(string-match (concat (helm-basedir helm-input)
(char-fold-to-regexp
(helm-basename helm-input)))
candidate))))))
;; Byte compile file async
(helm-source-add-action-to-source-if
"Byte compile file(s) async"
(lambda (_candidate)
(cl-loop for file in (helm-marked-candidates)
do (async-byte-compile-file file)))
source
'helm/ff-candidates-lisp-p)
;; Recover file from its autoload file
(helm-source-add-action-to-source-if
"Recover file"
(lambda (candidate)
(recover-file candidate))
source
(lambda (candidate)
(file-exists-p (expand-file-name
(format "#%s#" (helm-basename candidate))
(helm-basedir candidate)))))
;; Restore backup files
(helm-source-add-action-to-source-if
"Restore backup file(s)"
#'helm-restore-backups
source
(lambda (_candidate)
(cl-loop for file in (helm-marked-candidates)
always (string-match "\\(?:\\`\\([!]\\)[^!]*\\1.*\\)\\|\\(?:~\\'\\)"
(helm-basename file)))))
;; Byte recompile dir async
(helm-source-add-action-to-source-if
"Byte recompile directory (async)"
'async-byte-recompile-directory
source
'file-directory-p)
;; Info on .info files
(helm-source-add-action-to-source-if
"Open info file"
(lambda (candidate) (info candidate))
source
(lambda (candidate) (helm-aif (file-name-extension candidate)
(string= it "info")))
1)
;; Patch region on dir
(helm-source-add-action-to-source-if
"Patch region on directory"
(lambda (_candidate)
(with-helm-current-buffer
(shell-command-on-region (region-beginning) (region-end)
(format "patch -d %s -p1"
helm-ff-default-directory))))
source
(lambda (_candidate)
(with-helm-current-buffer
(and (or (eq major-mode 'mu4e-view-mode)
(eq major-mode 'diff-mode))
(region-active-p))))
1)
;; Emms
(helm-source-add-action-to-source-if
"Open in emms"
(lambda (candidate)
(if (file-directory-p candidate)
(emms-play-directory candidate)
(emms-play-file candidate)))
source
(lambda (candidate)
(or (and (file-directory-p candidate)
(directory-files
candidate
nil ".*\\.\\(mp3\\|ogg\\|flac\\)$" t))
(string-match-p ".*\\.\\(mp3\\|ogg\\|flac\\)$" candidate)))
1)
;; update-directory-autoloads
(helm-source-add-action-to-source-if
"Update directory autoloads"
#'helm/update-directory-autoloads
source
(lambda (candidate)
(and (file-directory-p candidate)
(string= (helm-basename candidate) ".")))
1)
;; Setup recoll dirs
(when (executable-find "recoll")
(helm-source-add-action-to-source-if
"Recoll index directory"
'helm-ff-recoll-index-directories
source
'file-directory-p
3))
;; Encrypt file
(helm-source-add-action-to-source-if
"Epa encrypt file"
(lambda (candidate)
(require 'epg) (require 'epa)
(epa-encrypt-file candidate
(helm :sources (helm-build-sync-source
"Select recipient for encryption: "
:persistent-action 'ignore
:candidates 'helm-epa-get-key-list))))
source
'file-exists-p
3)
;; Background
(helm-source-add-action-to-source-if
"Change background"
(if (fboundp 'image-dired-wallpaper-set)
#'image-dired-wallpaper-set #'tv:change-xfce-background)
source
(lambda (candidate)
(member (file-name-extension candidate) '("jpg" "jpeg" "png")))
3)
(helm-source-add-action-to-source-if
"Csv2Ledger"
'helm-ff-csv2ledger
source
(lambda (candidate)
(member (file-name-extension candidate) '("csv")))
3))
(helm-ff-icon-mode 1))
;;; Helm-dictionary
;;
(with-eval-after-load 'helm-dictionary ; Its autoloads are already loaded.
(setq helm-dictionary-database
'(("en-fr" . "~/helm-dictionary/dic-en-fr.iso")
("fr-en" . "~/helm-dictionary/dic-fr-en.iso"))
helm-dictionary-online-dicts
'(("translate.reference.com en->fr" .
"http://translate.reference.com/translate?query=%s&src=en&dst=fr")
("translate.reference.com fr->en" .
"http://translate.reference.com/translate?query=%s&src=fr&dst=en")
("en.wiktionary.org" . "http://en.wiktionary.org/wiki/%s")
("fr.wiktionary.org" . "http://fr.wiktionary.org/wiki/%s"))
helm-dictionary-ignore-diacritics t)
(helm-add-to-list 'helm-dictionary-actions '("sdcv" . helm-dictionary-sdcv) 2))
(defun helm-dictionary-sdcv (entry)
"Search ENTRY in french dictionary.
Need sdcv and stardict-xmlittre packages as dependencies."
(let* ((src (helm-get-current-source))
(name (if (string= (helm-get-attr 'name src) "en-fr")
(helm-dictionary-get-candidate entry 2)
(helm-dictionary-get-candidate entry 1)))
;; All dictionaries are copied in separate directories dir1,
;; dir2 etc... to avoid duplicates in sdcv output.
(dir "/home/thierry/.stardict/")
(args '("--non-interactive" "--color" "--data-dir")))
(when (string-match ", " name)
(setq name (completing-read "Name: " (split-string name ", " t)))
(when (string-match "\\(.*\\) +[[({]" name)
(setq name (match-string 1 name))))
(with-current-buffer (get-buffer-create "*sdcv*")
(let ((inhibit-read-only t))
(erase-buffer)
(save-excursion
(apply #'call-process "sdcv" nil t nil (append args (list dir name)))
(ansi-color-apply-on-region (point-min) (point-max)))
(while (re-search-forward (regexp-quote name) nil t)
(add-face-text-property
(match-beginning 0) (match-end 0) 'font-lock-constant-face))
(goto-char (point-min))
(fill-region (point-min) (point-max)))
(special-mode))
(pop-to-buffer "*sdcv*")))
;;; Helm-wikipedia
;;
(with-eval-after-load 'helm-wikipedia
(setq helm-wikipedia-summary-url
"https://fr.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&titles=%s&exintro=1&explaintext=1&redirects=1"
helm-wikipedia-suggest-url
"https://fr.wikipedia.org/w/api.php?action=opensearch&search=%s"))
;;; Helm-descbinds
;;
(helm-descbinds-mode 1)
;;; Helm-lib
;;
(with-eval-after-load 'helm-lib
(autoload 'isl-search "isl" nil t)
(advice-add 'cl--print-table :override #'helm-source--cl--print-table '((depth . 100)))
(setq helm-scroll-amount 4)
(setq helm-find-function-default-project
'("~/work/emacs/lisp/" "~/work/github/"))
(helm-help-define-key "C-x" 'exchange-point-and-mark)
(helm-help-define-key "C-l" 'recenter-top-bottom)
(helm-help-define-key "C-s" nil)
(helm-help-define-key "C-r" nil)
(helm-help-define-key "C-s" 'isl-search))
;;; Helm-net
;;
(with-eval-after-load 'helm-net
(setq helm-net-prefer-curl nil
helm-surfraw-duckduckgo-url "https://duckduckgo.com/?q=%s&ke=-1&kf=fw&kl=fr-fr&kr=b&k1=-1&k4=-1"
helm-google-suggest-search-url helm-surfraw-duckduckgo-url))
;;; Helm-external
;;
(with-eval-after-load 'helm-external
(setq helm-raise-command "wmctrl -xa %s"
helm-default-external-file-browser "thunar")
(require 'emms-config)
(add-hook 'helm-open-file-externally-after-hook #'tv:emms-player-start-hook)
(add-hook 'helm-open-file-externally-after-finish-hook #'tv:emms-player-stop-hook))
;;; Helm-grep
;;
(with-eval-after-load 'helm-grep
(setq helm-pdfgrep-default-read-command
"xreader --page-label=%p '%f'"
helm-grep-default-command
"ack -Hn --color --smart-case --no-group %e -- %p %f"
helm-grep-default-recurse-command
"ack -H --color --smart-case --no-group %e -- %p %f"
helm-grep-ag-command
"rg --color=always --colors 'match:bg:yellow' --colors 'match:fg:black' --smart-case --search-zip --no-heading --line-number %s -- %s %s"
helm-grep-ag-pipe-cmd-switches
'("--colors 'match:bg:yellow' --colors 'match:fg:black'")
helm-grep-git-grep-command
"git --no-pager grep -n%cH --color=always --exclude-standard --no-index --full-name -e %p -- %f")
(add-hook 'helm-grep-mode-hook 'hl-line-mode)
(define-key helm-grep-map (kbd "C-M-a") 'helm/occur-which-func))
;;; Helm-occur
;;
(with-eval-after-load 'helm-occur
(setq helm-occur-keep-closest-position t)
(setq helm-occur-match-shorthands t)
(add-hook 'helm-occur-mode-hook 'hl-line-mode)
(define-key helm-occur-map (kbd "C-M-a") 'helm/occur-which-func))
;;; Helm-elisp
;;
(helm-multi-key-defun helm-multi-lisp-complete-at-point
"Multi key function for completion in emacs lisp buffers.
First call indent, second complete symbol, third complete fname."
'(helm-lisp-indent
helm-lisp-completion-at-point)
0.3)
(define-key emacs-lisp-mode-map (kbd "TAB") 'helm-multi-lisp-complete-at-point)
(define-key lisp-interaction-mode-map (kbd "TAB") 'helm-multi-lisp-complete-at-point)
(with-eval-after-load 'helm-elisp
(setq helm-show-completion-display-function #'helm-display-buffer-in-own-frame
helm-apropos-show-short-doc t))
;;; Helm-locate
;;
(with-eval-after-load 'helm-locate
(setq helm-locate-fuzzy-match nil))
;;; Helm-org
;;
(with-eval-after-load 'helm-org
(setq helm-org-headings-fontify t))
;;; Helm-emms
;;
(with-eval-after-load 'helm-emms
(setq helm-emms-use-track-description-function t)
(helm-set-attr 'candidate-number-limit 500 helm-source-emms-dired)
(add-to-list 'helm-emms-music-extensions "mp4"))
;;; Helm-find
;;
(with-eval-after-load 'helm-find
(setq helm-find-noerrors t))
;;; Helm-imenu
;;
(with-eval-after-load 'helm-imenu
(add-to-list 'helm-imenu-type-faces
'("^Use package$" . font-lock-keyword-face))
(add-to-list 'helm-imenu-icon-type-alist
'("Use package" . (all-the-icons-octicon
"package" :face font-lock-keyword-face)))
(setq helm-imenu-extra-modes '(org-mode markdown-mode))
(customize-set-variable 'helm-imenu-lynx-style-map t)
(customize-set-variable 'helm-imenu-use-icon t)
(customize-set-variable 'helm-imenu-hide-item-type-name t))
;;; Helm-misc
;;
(with-eval-after-load 'helm-misc
;; Minibuffer history (Rebind to M-s).
(customize-set-variable 'helm-minibuffer-history-key [remap next-matching-history-element]))
;;; helm-bm
;;
(with-eval-after-load 'helm-bm
(setq helm-bm-sort-from-pos nil)
(define-key helm-bm-map (kbd "<f12>") 'helm-next-line)
(define-key helm-bm-map (kbd "S-<f12>") 'helm-previous-line))
;;; Helm-epa
;;
(helm-epa-mode 1)
;;; Helm-fd
;;
(with-eval-after-load 'helm-fd
(setq helm-fd-executable "fdfind")
(defun helm-fd-pa (candidate)
(with-helm-buffer
(helm-ff-kill-or-find-buffer-fname
(expand-file-name candidate))))
(cl-defmethod helm-setup-user-source ((source helm-fd-class))
(setf (slot-value source 'persistent-action) 'helm-fd-pa)))
;;; Helm-ls-git
;;
(with-eval-after-load 'helm-ls-git
(setq helm-ls-git-delete-branch-on-remote t
helm-ls-git-auto-refresh-at-eob t))
;;; Helm-mu
;;
(with-eval-after-load 'helm-mu
(setq helm-mu-contacts-after "01-Jan-2020 00:00:01"
helm-mu-contacts-personal t
helm-mu-contacts-ignore-candidates-regexp
"\\`\\(reply.*reply\\.github\\.com\\)\\|\\(no[.-]?reply\\|ne-pas-repondre\\)"))
;;; Helm-command-map
;;
;;
(define-key helm-command-map (kbd "g") 'helm-apt-search)
(define-key helm-command-map (kbd "z") 'helm-complex-command-history)
(define-key helm-command-map (kbd "x") 'helm-firefox-bookmarks)
(define-key helm-command-map (kbd "w") 'helm-wikipedia-suggest)
(define-key helm-command-map (kbd "#") 'helm-emms)
(define-key helm-command-map (kbd "I") 'helm-imenu-in-all-buffers)
;;; Global-map
;;
;;
(global-set-key (kbd "C-h r") 'helm-info-emacs)
(global-set-key (kbd "M-x") 'undefined)
(global-set-key (kbd "M-x") 'helm-M-x)
(global-set-key (kbd "M-y") 'helm-show-kill-ring)
(global-set-key (kbd "C-x C-f") 'helm-find-files)
(global-set-key (kbd "C-c <SPC>") 'helm-mark-ring)
(global-set-key [remap bookmark-jump] 'helm-filtered-bookmarks)
(global-set-key (kbd "C-c i") 'helm-imenu)
(global-set-key (kbd "C-c I") 'helm-imenu-in-all-buffers)
(global-set-key (kbd "C-:") 'helm-eval-expression-with-eldoc)
(global-set-key (kbd "C-,") 'helm-calcul-expression)
(global-set-key (kbd "C-h d") 'helm-info-at-point)
(global-set-key (kbd "C-h i") 'helm-info)
(global-set-key (kbd "C-x C-d") 'helm-browse-project)
(global-set-key (kbd "<f1>") 'helm-resume)
(global-set-key (kbd "C-h C-f") 'helm-apropos)
(global-set-key (kbd "C-h a") 'helm-apropos)
(global-set-key (kbd "C-h C-d") 'helm-debug-open-last-log)
(global-set-key (kbd "<f5> s") 'helm-find)
(global-set-key (kbd "S-<f4>") 'helm-execute-kmacro)
(global-set-key (kbd "<f11>") nil)
(global-set-key (kbd "<f11> o") 'helm-org-agenda-files-headings)
(global-set-key (kbd "M-s") nil)
(global-set-key (kbd "M-s") 'helm-occur-visible-buffers)
(global-set-key (kbd "<f6> h") 'helm-emms)
(define-key global-map [remap bookmark-bmenu-list] 'helm-register)
(define-key global-map [remap list-buffers] 'helm-mini)
(define-key global-map [remap dabbrev-expand] 'helm-dabbrev)
(define-key global-map [remap find-tag] 'helm-etags-select)
(define-key global-map [remap xref-find-definitions] 'helm-etags-select)
(define-key global-map (kbd "M-g a") 'helm-do-grep-ag)
(define-key global-map (kbd "M-g l") 'goto-line)
(define-key global-map (kbd "M-g g") 'helm-grep-do-git-grep)
(define-key global-map (kbd "M-g M-g") 'helm-revert-next-error-last-buffer)
(define-key global-map (kbd "M-g i") 'helm-gid)
(define-key global-map (kbd "C-x r p") 'helm-projects-history)
(define-key global-map (kbd "C-x r c") 'helm-addressbook-bookmarks)
(define-key global-map (kbd "C-c t r") 'helm-dictionary)
;; Indent or complete with completion-at-point
;; (setq tab-always-indent 'complete)
;; (define-key global-map (kbd "<backtab>") 'completion-at-point)
;; Avoid hitting forbidden directories when using find.
(add-to-list 'completion-ignored-extensions ".gvfs/")
(add-to-list 'completion-ignored-extensions ".dbus/")
(add-to-list 'completion-ignored-extensions "dconf/")
(provide 'init-helm)
;;; init-helm.el ends here