-
Notifications
You must be signed in to change notification settings - Fork 5
/
.emacs
756 lines (633 loc) · 26.9 KB
/
.emacs
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
;;; .emacs --- Emacs conf file -*- coding: utf-8; lexical-binding: t -*-
;; Téléchargez et placez ce fichier à la racine de votre homedir (=> ~/.emacs)
;; puis lancez GNU Emacs en exécutant la commande "emacs &" dans un terminal.
;; L'installation des modes Emacs pour OCaml et Coq devrait se lancer
;; automatiquement et durer environ 2'30.
;; En cas de souci, faites "M-x package-install-selected-packages RET"
;; (M-x désignant Alt+X et RET la touche Entrée) et redémarrez emacs.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Wrapper for macOS native fullscreen
(defun tapfa-frame-maximize (prefix)
"Toggle the current frame fullscreen (resp. maximized if PREFIX holds)."
(interactive "P")
(if prefix (toggle-frame-maximized)
(toggle-frame-fullscreen)))
;; Config des touches Option dans GNU Emacs 28 pour macOS
;; Utilisez la touche Option-de-gauche pour activer la touche Meta d'Emacs (M-)
;; Utilisez la touche Option-de-droite (⌥-) pour saisir des caractères spéciaux
;; & Corrige "Invalid image type: 'svg" https://emacs.stackexchange.com/a/77324
(when (eq system-type 'darwin)
(setq mac-option-modifier 'meta)
(setq mac-right-option-modifier 'none)
(add-to-list 'image-types 'svg t)
(global-set-key (kbd "C-s-f") #'tapfa-frame-maximize))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Config de package.el, MELPA et use-package
;; In Emacs-28, `magit` raises an emergency warning "requires seq >= 2.24".
;; Stefan: `transient` manque à l'appel dans le `package--builtin-versions`
;; de Emacs-28.
(and (not (assq 'transient package--builtin-versions))
(>= emacs-major-version 28)
(push '(transient 0 3 7) package--builtin-versions))
(require 'package)
;; Si vous avez Emacs 26.1 (qui est la version fournie dans Debian 10)
;; vous pourriez avoir le message d'erreur "Failed to download 'melpa'
;; archive during the package refresh step". C'est un bug connu
;; (https://debbugs.gnu.org/cgi/bugreport.cgi?bug=34341) qui a été
;; corrigé dans Emacs 26.3 et 27.1; un contournement simple est
;; implémenté ci-dessous.
(when (eval-when-compile (version= emacs-version "26.1"))
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3"))
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;; See https://www.reddit.com/r/emacs/comments/9rj5ou/comment/e8ibi8e/
(when (eval-when-compile (version< emacs-version "27"))
;; (load "~/.emacs.d/early-init.el")
(package-initialize))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(diff-switches "-u")
'(package-selected-packages
(quote (learn-ocaml company merlin-iedit merlin-eldoc merlin tuareg auctex magit-gitflow magit yaml-mode markdown-mode helpful discover-my-major which-key centaur-tabs use-package))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(proof-locked-face ((t (:background "#add8e6"))))
'(region ((t (:background "gold1" :distant-foreground "dim gray")))))
;; Install https://elpa.gnu.org/packages/gnu-elpa-keyring-update.html
;; to fix the bad-signature error that occurs in Debian GNU/Linux 12
;; (cf. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1070664)
(unless (package-installed-p 'gnu-elpa-keyring-update)
;; over-approximation: Unset package-check-signature temporarily for
;; GNU/Linux, emacs < 29.3 (cf. https://packages.debian.org/emacs)
(if (and (string-equal system-type "gnu/linux")
(version< emacs-version "29.3"))
(let ((package-check-signature nil))
(package-refresh-contents)
(package-install 'gnu-elpa-keyring-update))
(progn (package-refresh-contents)
(package-install 'gnu-elpa-keyring-update))))
;; Bootstrap use-package
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(eval-when-compile
(require 'use-package))
(defgroup tapfa-init nil
"Tapfa-Init Emacs Settings."
:group 'convenience
:prefix "tapfa-init-")
(use-package diminish
:ensure t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Custom spacemacs theme with nice tabs
;; (menu-bar-mode -1) Keep it!
(tool-bar-mode -1)
;; M-x minor-mode-menu-from-indicator RET
(use-package spacemacs-theme
:ensure t
:init
(setq spacemacs-theme-comment-bg nil))
(use-package spaceline
:ensure t
:config
(use-package spaceline-config
:config
(spaceline-emacs-theme)))
(defcustom tapfa-init-darkness nil
"Should dark mode be enabled?
The following values are meaningful:
nil ask on startup
-1 setup dark mode
1 setup light mode"
:type '(choice (const :tag "Ask on startup" nil)
(const :tag "Setup spacemacs-light theme" -1)
(const :tag "Setup spacemacs-dark theme" 1))
:group 'tapfa-init)
(defun tapfa-init-darkness-apply ()
"Load themes accordingly as per `tapfa-init-darkness'."
(load-theme (if (eq tapfa-init-darkness -1) 'spacemacs-dark 'spacemacs-light) t)
(spaceline-emacs-theme))
(defun tapfa-init-darkness (&optional batch)
"Ask to set tapfa-init-darkness to 1 or -1 or to ask again.
Always ask if BATCH is nil, e.g., called interactively."
(interactive)
(if (or (null batch) (null tapfa-init-darkness))
(let ((newval
(condition-case _sig
(x-popup-dialog
t '("Quel thème spacemacs voulez-vous activer ?\n"
("Light" . 1) ("Dark" . -1)
("Redemander" . nil)))
(quit nil))))
(customize-save-variable 'tapfa-init-darkness newval)
(let ((sdark "Thème enregistré : spacemacs-dark.\n\n")
(slight "Thème enregistré : spacemacs-light.\n\n")
(sdflt "Thème par défaut : spacemacs-light.\n\n")
(ssaved-end "Si jamais vous voulez rechanger, tapez M-x tapfa-init-darkness RET")
(sdflt-end "Si jamais vous voulez changer, tapez M-x tapfa-init-darkness RET\nou redémarrez Emacs."))
(cond ((eq tapfa-init-darkness 1)
(message-box (concat slight ssaved-end)))
((eq tapfa-init-darkness -1)
(message-box (concat sdark ssaved-end)))
(t
(message-box (concat sdflt sdflt-end)))))))
(tapfa-init-darkness-apply))
(tapfa-init-darkness t)
(defun tapfa-init-fix-centaur-tabs-excluded-prefixes ()
"Fix `centaur-tabs-excluded-prefixes'."
(when (or
;; (member "*Keep" centaur-tabs-excluded-prefixes)
(not (member "*tapfa" centaur-tabs-excluded-prefixes)))
(customize-save-variable 'centaur-tabs-excluded-prefixes
(append '("*tapfa")
(seq-filter
(lambda (s)
(not (member s '(;;"*Keep"
))))
centaur-tabs-excluded-prefixes)))))
(use-package centaur-tabs
:ensure t
:init
(setq centaur-tabs-enable-key-bindings nil
centaur-tabs-show-count nil
centaur-tabs-show-navigation-buttons t
centaur-tabs-height 32
centaur-tabs-left-edge-margin nil
centaur-tabs-set-icons nil ;; improve?
;; centaur-tabs-label-fixed-length 14
;; centaur-tabs-gray-out-icons 'buffer
;; centaur-tabs-plain-icons t
centaur-tabs-style "bar"
centaur-tabs-set-bar 'under
x-underline-at-descent-line t
centaur-tabs-set-modified-marker t
centaur-tabs-show-new-tab-button nil
centaur-tabs-down-tab-text " ⋮ "
centaur-tabs-backward-tab-text "(←)"
centaur-tabs-forward-tab-text "(→)")
:hook
(dashboard-mode . centaur-tabs-local-mode)
(term-mode . centaur-tabs-local-mode)
(calendar-mode . centaur-tabs-local-mode)
(org-agenda-mode . centaur-tabs-local-mode)
:bind
("<C-f5>" . centaur-tabs-extract-window-to-new-frame)
("<C-prior>" . centaur-tabs-backward)
("<C-next>" . centaur-tabs-forward)
("C-c <left>" . centaur-tabs-backward)
("C-c <right>" . centaur-tabs-forward)
("C-c <C-left>" . centaur-tabs-backward)
("C-c <C-right>" . centaur-tabs-forward)
("<C-S-prior>" . centaur-tabs-move-current-tab-to-left)
("<C-S-next>" . centaur-tabs-move-current-tab-to-right)
("C-c <C-S-left>" . centaur-tabs-move-current-tab-to-left)
("C-c <C-S-right>" . centaur-tabs-move-current-tab-to-right)
:demand t
:config
(centaur-tabs-mode t)
;; (centaur-tabs-headline-match)
(centaur-tabs-change-fonts (face-attribute 'default :font) 110)
(tapfa-init-fix-centaur-tabs-excluded-prefixes)
(defun centaur-tabs-buffer-groups ()
"`centaur-tabs-buffer-groups' control buffers' group rules.
Group centaur-tabs with mode if buffer is derived from `eshell-mode'
`emacs-lisp-mode' `dired-mode' `org-mode' `magit-mode'.
All buffer name start with * will group to \"Emacs\".
Other buffer group by `centaur-tabs-get-group-name' with project name."
(list
(cond
;; ((memq major-mode '(org-mode org-agenda-mode diary-mode)) "OrgMode")
((memq major-mode '(org-mode
org-agenda-clockreport-mode
org-src-mode
org-agenda-mode
org-beamer-mode
org-indent-mode
org-bullets-mode
org-cdlatex-mode
org-agenda-log-mode
diary-mode)) "OrgMode")
((memq major-mode '(tex-mode latex-mode)) "TeX")
((memq major-mode '(tuareg-mode caml-mode)) "OCaml")
((memq major-mode '(coq-mode
proof-splash-mode
coq-shell-mode
coq-goals-mode
coq-response-mode)) "Coq")
((memq major-mode '(helpful-mode help-mode)) "Help")
;; ((derived-mode-p 'prog-mode) "Editing")
;; ((and (buffer-file-name) (file-remote-p (buffer-file-name))) "Remote")
((or (string-equal "*" (substring (buffer-name) 0 1))
(memq major-mode '( magit-process-mode
magit-status-mode
magit-diff-mode
magit-log-mode
magit-file-mode
magit-blob-mode
magit-blame-mode)))
"Emacs")
((derived-mode-p 'shell-mode) "Shell")
((derived-mode-p 'eshell-mode) "EShell")
((derived-mode-p 'emacs-lisp-mode) "Elisp")
((derived-mode-p 'dired-mode) "Dired")
(t
(centaur-tabs-get-group-name (current-buffer)))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Config pour afficher au démarrage un dashboard + joli et utile
(use-package page-break-lines
:ensure t
:hook
(dashboard-mode . page-break-lines-mode))
(use-package dashboard
:ensure t
:config
(dashboard-setup-startup-hook)
:custom
(dashboard-banner-logo-title "Welcome to GNU Emacs!")
(dashboard-page-separator "\f\n")
(dashboard-items '((recents . 5)
(bookmarks . 10))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Config pour afficher une aide sur les raccourcis de base (C-f1)
(defun tapfa-init-help-display ()
(interactive)
(let ((buf (get-buffer-create "*tapfa-init-help*")))
(with-current-buffer buf
(when (<= (point-max) 1)
;; Only do things once, even if this might prevent a text update
(insert
"Principaux raccourcis à connaître — taper \"q\" pour fermer cette aide :
C-x C-f … ; ouvrir un fichier existant ou créer un nouveau fichier
C-x C-s ; sauvegarder le fichier courant
Ctrl+X Ctrl+S ; idem (conseil : on peut garder la touche Ctrl appuyée)
C-x 2 ; découper la vue courante en une \"mosaïque horizontale\"
C-x o ; déplacer le curseur d'une zone à l'autre
C-x 1 ; maximiser le buffer courant et masquer les autres vues
C-c … ; préfixe spécifique au mode courant (dépend du langage)
C-g ; annule la commande en cours de saisie dans le minibuffer
ESC ESC ESC ; signal d'échappement (+ puissant que le raccourci \"C-g\")
"
)
(read-only-mode)
(goto-char (point-min))
(lisp-mode)
(local-set-key (kbd "q") (lambda () (interactive) (quit-window t))))
(switch-to-buffer-other-window buf))))
;; (spaceline-define-segment ?)
(defvar tapfa-init-help-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-<f1>") #'tapfa-init-help-display)
map)
"Keymap for tapfa-init-help.")
(define-minor-mode tapfa-init-help-mode
"Minor mode to display basic key bindings help (in French)."
:lighter " (?)"
:global t
:keymap tapfa-init-help-map
(if tapfa-init-help-mode
(message "Tapez C-<f1> (Ctrl+F1) pour plus d'aide sur les raccourcis de base")))
;; (define-globalized-minor-mode global-tapfa-init-help-mode tapfa-init-help-mode
;; (lambda () (tapfa-init-help-mode 1)))
(easy-menu-define
tapfa-init-help-mode--menu
tapfa-init-help-map
"tapfa-init help menu"
(list "(?) - Tapfa Init Help"
:label "(?)"
["Sauver la position dans un signet"
bookmark-set
:help "bookmark-set"]
["Ouvrir un signet existant"
bookmark-jump
:help "bookmark-jump"]
["Afficher la liste des signets"
bookmark-bmenu-list
:help "bookmark-bmenu-list"]
"-------"
["Afficher le dashboard d'Emacs"
dashboard-open
:help "M-x dashboard-open RET"]
"-------"
["Changer le thème spacemacs : light / dark"
tapfa-init-darkness
:help "M-x tapfa-init-darkness RET"]
["Changer les raccourcis : shell / windows"
tapfa-init-cua
:help "M-x tapfa-init-cua RET"]
["Installer les modes Coq - si nécessaire"
tapfa-init-coq
:help "M-x tapfa-init-coq RET"]
"-------"
["Aide sur les raccourcis de base"
tapfa-init-help-display
:help "Afficher les principaux raccourcis à connaître"]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Config pour alternative à dired-mode
;;; (use-package neotree
;;; :ensure t
;;; :config
;;; (global-set-key (kbd "<f6>") #'neotree-toggle))
;;; ;; cf. https://github.com/jaypei/emacs-neotree#keybindings
;;; ;; pour les raccourcis du buffer Neotree
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Config pour augmenter la découvrabilité
(use-package which-key
:ensure t
:diminish
:config
(which-key-mode))
(use-package discover-my-major
:ensure t
:config
(global-set-key (kbd "C-h C-m") #'discover-my-major)
(global-set-key (kbd "C-h M-m") #'discover-my-mode))
;; Recall we also have the standard keybinding "C-h m".
(use-package helpful
:ensure t
:config
(global-set-key (kbd "C-h f") #'helpful-callable)
(global-set-key (kbd "C-h v") #'helpful-variable)
(global-set-key (kbd "C-h k") #'helpful-key)
;;; Look up Functions (excludes macros).
;; (global-set-key (kbd "C-h F") #'helpful-function)
;;; Look up Commands (= keybindings).
;; (global-set-key (kbd "C-h K") #'helpful-command)
;;; COMMENTED-OUT as "Info-goto-emacs[-key]-command-node" are more useful.
(add-hook 'emacs-lisp-mode-hook #'(lambda ()
(local-set-key (kbd "C-c C-.") #'helpful-at-point))))
;; Note we can also type "C-h" after a prefix to list its expansions.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Config de markdown-mode (to edit README.md files easily!) and yaml-mode
(use-package markdown-mode
:ensure t)
(use-package yaml-mode
:ensure t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Config d'AUCTeX
(use-package tex
:ensure auctex)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Config de Magit
;; Copied-from: https://gist.github.com/erikmd/82c4b2a50a77c98e8fe6318530c531b7
;;; Pour plus d'infos :
;; https://github.com/magit/magit et https://magit.vc (doc officielle)
;; https://youtu.be/mtliRYQd0j4 (tuto vidéo sur git-rebase avec Magit)
(use-package magit
:ensure t
:defer t
:config
(setq magit-diff-refine-hunk 'all)
:bind (("C-x g" . magit-status)
("C-x M-g" . magit-dispatch-popup)))
(use-package magit-gitflow
:ensure t
:after magit
:config (add-hook 'magit-mode-hook 'turn-on-magit-gitflow))
;; Protect against accident pushes to upstream/pushremote
;; compatible with https://github.com/magit/magit/pull/3813
;; tested with magit-20200927.1644
(defadvice magit-push-current-to-upstream
(around my-protect-accidental-magit-push-current-to-upstream)
"Protect against accidental push to upstream.
Causes `magit-run-git-async' to ask the user for confirmation first."
(let ((my-magit-ask-before-push t))
ad-do-it))
(defadvice magit-push-current-to-pushremote
(around my-protect-accidental-magit-push-current-to-pushremote)
"Protect against accidental push to upstream.
Causes `magit-run-git-async' to ask the user for confirmation first."
(let ((my-magit-ask-before-push t))
ad-do-it))
(defun magit-git-to-string (args)
"Pretty-print the `magit-run-git-async' arguments.
Quote the substrings if need be."
(cond ((not args)
"")
((stringp args)
(shell-quote-argument args))
((listp args)
(mapconcat #'magit-git-to-string args " "))
(t (error "Unrecognized: %s" (pp-to-string args)))))
;(magit-git-to-string '("push" "-v" ("--force-with-lease") "origin" "master:refs/heads/master"))
(defadvice magit-run-git-async (around my-protect-accidental-magit-run-git-async)
"Maybe ask the user for confirmation before pushing.
Advices to `magit-push-current-to-*' trigger this query."
(if (bound-and-true-p my-magit-ask-before-push)
;; Arglist is (ARGS)
(if (y-or-n-p (format "Run 'git %s'? "
(magit-git-to-string (ad-get-args 0))))
ad-do-it
(error "Push aborted by user"))
ad-do-it))
(setq ad-redefinition-action 'accept)
(ad-activate 'magit-push-current-to-upstream)
(ad-activate 'magit-push-current-to-pushremote)
(ad-activate 'magit-run-git-async)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Config de Tuareg, Merlin et Company
(setq tapfa-opam-available
(let* ((temp (get-buffer-create " *temp"))
(status (shell-command "opam var bin" temp)))
(kill-buffer temp)
(eq status 0)))
(when tapfa-opam-available
(use-package opam-switch-mode
:ensure t
:hook
((coq-mode tuareg-mode) . opam-switch-mode)))
(use-package tuareg
:ensure t
:defer t)
;;; Désactivé car le raccourci associé à <home> est malencontreux
;; (use-package bifocal
;; :ensure t
;; :hook
;; (tuareg-interactive-mode . bifocal-mode))
(use-package merlin
:ensure t
:hook
((tuareg-mode caml-mode) . merlin-mode))
(use-package whitespace
:defer t
:diminish whitespace-mode)
(use-package eldoc
:defer t
:diminish)
(use-package merlin-eldoc
:ensure t
:hook
((tuareg-mode caml-mode) . merlin-eldoc-setup)
:bind (:map merlin-mode-map
("C-c <left>" . merlin-eldoc-jump-to-prev-occurrence)
("C-c <right>" . merlin-eldoc-jump-to-next-occurrence)))
(use-package merlin-iedit
:ensure t
:after merlin-eldoc
:bind (:map merlin-mode-map
("C-c C-o" . merlin-iedit-occurrences)))
(use-package company
:ensure t
:diminish
:hook
((tuareg-mode caml-mode) . company-mode)
:config
(bind-key "<backtab>" 'company-complete))
(use-package learn-ocaml
:ensure t)
(global-set-key (kbd "<f12>") #'learn-ocaml-mode)
;; Useful toggle when copying in Gitpod Browser Terminal
(global-set-key (kbd "<f7>") #'xterm-mouse-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Proposition d'installer les modes (proof-general, company-coq) pour Coq
(defcustom tapfa-init-coq nil
"Should coq modes be installed?
The following values are meaningful:
nil ask on startup
-1 do not install coq related packages
1 install proof-general + company-coq"
:type '(choice (const :tag "Ask on startup" nil)
(const :tag "Do not install coq related packages" -1)
(const :tag "Install proof-general + company-coq" 1))
:group 'tapfa-init)
(defun tapfa-init-coq (&optional batch)
"Ask to set tapfa-init-coq to 1 or -1 or to ask again.
Always ask if BATCH is nil, e.g., called interactively."
(interactive)
(if (or (null batch) (null tapfa-init-coq))
(let ((newval
(condition-case _sig
(x-popup-dialog
t '("Voulez-vous installer les modes (plugins) associés au langage Coq ?\n"
("Oui" . 1) ("Non" . -1)
("Plus tard" . nil)))
(quit nil))))
(customize-save-variable 'tapfa-init-coq newval)
(cond ((eq tapfa-init-coq 1)
(package-refresh-contents))
((eq tapfa-init-coq -1)
t)
(t
(message-box "Saute l'installation des modes liés à Coq.\n\nPour les installer tout de même plus tard, tapez M-x tapfa-init-coq RET\n"))))))
(tapfa-init-coq t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Config de ProofGeneral et company-coq
(when (eq tapfa-init-coq 1)
(use-package proof-general
:ensure t
:mode ("\\.v\\'" . coq-mode)
:init
(setq overlay-arrow-string ""
coq-double-hit-enable t))
(use-package company-coq
:ensure t
:hook
(coq-mode . company-coq-mode)
:init
(setq company-coq-disabled-features '(hello))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Config générale
(setq column-number-mode t
line-number-mode t
isearch-allow-scroll t
enable-recursive-minibuffers t
require-final-newline t)
(global-set-key (kbd "C-x C-S-q") #'view-mode)
;; Enable XTerm mouse support for menus in "emacs -nw" and so on
(xterm-mouse-mode 1)
;; Adapted from: https://emacs.stackexchange.com/a/78288/19818
(defun tapfa-init--menu-bar-get-minimal-x (menu-symbol x y)
(let ((xx (- x 1)))
(if (< xx tty-menu--initial-menu-x)
x
(if (equal (menu-bar-menu-at-x-y xx y (selected-frame)) menu-symbol)
(tapfa-init--menu-bar-get-minimal-x menu-symbol xx y)
x))))
(defun tapfa-init--menu-bar-open-x-y (mouse-event)
(interactive "e")
(pcase mouse-event
(`(mouse-1 (,_ menu-bar (,x . ,y) . ,_))
(let ((menu (menu-bar-menu-at-x-y x y)))
(popup-menu (or
(lookup-key-ignore-too-long
global-map (vector 'menu-bar menu))
(lookup-key-ignore-too-long
(current-local-map) (vector 'menu-bar menu))
(cdar (minor-mode-key-binding (vector 'menu-bar menu)))
(mouse-menu-bar-map))
(posn-at-x-y (tapfa-init--menu-bar-get-minimal-x menu x y) y nil t)
nil t)))
(_ (message "unsupported event %S" (car mouse-event)))))
(define-key global-map (kbd "<menu-bar> <mouse-1>")
(lambda (ev) (interactive "e")
(if tty-menu-open-use-tmm (tmm-menubar-mouse ev) (tapfa-init--menu-bar-open-x-y ev))))
;; Marquage des parenthèses
(load-library "paren")
(show-paren-mode 1)
;; Marquage des problèmes d'espace
(require 'whitespace)
(setq whitespace-line-column 80)
(setq whitespace-style '(face empty tabs trailing space-after-tab space-before-tab))
(add-hook 'prog-mode-hook #'whitespace-mode)
(add-hook 'prog-mode-hook #'(lambda () (unless (derived-mode-p 'makefile-mode)
(setq indent-tabs-mode nil))))
(add-hook 'sgml-mode-hook #'(lambda () (setq indent-tabs-mode nil)))
(add-hook 'nxml-mode-hook #'(lambda () (setq indent-tabs-mode nil)))
;; Adapted from:
;; https://www.gnu.org/software/emacs/manual/html_node/efaq/Matching-parentheses.html
(defun tapfa-match-paren-direct (arg)
"Go to the matching paren if on a paren; otherwise insert µ."
(interactive "p")
(cond ((looking-back "[])}]") ;;(forward-char 1)
(backward-list 1))
((looking-at "[{([]") (forward-list 1) ;;(backward-char 1)
)
(t (self-insert-command (or arg 1)))))
(global-set-key "µ" #'tapfa-match-paren-direct)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Proposition des "raccourcis Windows" C-c/C-x/C-v/C-z
;; au lieu de M-w/C-w/C-y/C-_ par défaut dans GNU Emacs
(defcustom tapfa-init-cua nil
"Initial setup for `cua-mode'.
The following values are meaningful:
nil ask on startup
-1 `cua-mode' is disabled
1 `cua-mode' is enabled"
:type '(choice (const :tag "Ask on startup" nil)
(const :tag "Disabled (emacs expert mode)" -1)
(const :tag "Enabled (windows' shortcuts)" 1))
:group 'tapfa-init)
(defun tapfa-init-cua (&optional batch)
"Ask to set (cua-mode 1) or (cua-mode -1) or to ask again.
Always ask if BATCH is nil, e.g., called interactively."
(interactive)
(if (or (null batch) (null tapfa-init-cua))
(let ((newval
(condition-case _sig
(x-popup-dialog
t '("Presse-papier & Annulation :\n\nVoulez-vous forcer l'utilisation des raccourcis Windows ?\n(C-c, C-x, C-v, et C-z)\n\nOu garder les raccourcis Emacs/shell standards\n(M-w, C-w, C-y, et C-_)\n"
("Emacs/shell" . -1) ("Windows" . 1)
("Me redemander" . nil)))
(quit nil))))
(customize-save-variable 'tapfa-init-cua newval)
(let ((ssaved "Configuration enregistrée.\n\n")
(sremov "Pas de configuration stockée.\n\n")
(swindo "Utilise : raccourcis Windows\n(C-c, C-x, C-v, et C-z)\n\n")
(semacs "Utilise : raccourcis Emacs/shell standards\n( M-w pour copier, c.-à-d. Alt+w,\n C-w pour couper, c.-à-d. Ctrl+w,\n C-y pour coller, c.-à-d. Ctrl+y,\n C-_ pour annuler, c.-à-d. Ctrl+_)\n\n")
(ssaved-end "Si jamais vous voulez rechanger, tapez M-x tapfa-init-cua RET")
(sremov-end "Si jamais vous voulez rechanger, tapez M-x tapfa-init-cua RET\nou redémarrez Emacs."))
(cond ((eq newval 1)
(message-box (concat ssaved swindo ssaved-end)))
((eq newval -1)
(message-box (concat ssaved semacs ssaved-end)))
(t
(message-box (concat sremov sremov-end)))))))
(cond ((eq tapfa-init-cua 1) (cua-mode 1))
((eq tapfa-init-cua -1) (cua-mode -1))
(t (cua-mode -1))))
(tapfa-init-cua t)
(add-hook 'emacs-startup-hook (lambda () (tapfa-init-help-mode 1))) ;; after dashboard-initialize