-
Notifications
You must be signed in to change notification settings - Fork 0
/
.emacs
2639 lines (2279 loc) · 93.6 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
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
;; -*- coding: utf-8 -*-
;;; Emacs of Thomas Riccardi. Homepage : http://github.com/Niluge-KiWi/dotfiles
;; Many things from http://github.com/antoine-levitt/perso, and some other things
;; Can be viewed in outline mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Base setup
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; increase garbage collecting start threshold
(setq gc-cons-threshold (* 20 1024 1024))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Path setup
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/"))
;;(add-to-list 'load-path (expand-file-name "~/.emacs.d/lisp/erc-5.3/"))
;;byte-recompile elisp files if they need to be
;;(byte-recompile-directory "~/.emacs.d" 0)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Package Management
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;-------ELPA
;; ;; This provides support for the package system and
;; ;; interfacing with ELPA, the package archive.
;; (unless (boundp 'list-packages)
;; (when
;; (load
;; (expand-file-name "~/.emacs.d/elpa/package.el"))
;; (package-initialize)))
;; several archives for elpa
(require 'package)
(setq package-archives
'(("gnu" . "https://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")
("melpa-stable" . "https://stable.melpa.org/packages/")
("org" . "http://orgmode.org/elpa/"))
package-archive-priorities
'(("gnu" . 5)
("melpa" . 0)
("melpa-stable" . 10)
("org" . 20)))
(package-initialize)
;;-------el-get
;; Manage the external elisp bits and pieces you depend upon
(add-to-list 'load-path (expand-file-name "~/.emacs.d/el-get/el-get"))
(unless (require 'el-get nil 'noerror)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.github.com/dimitri/el-get/master/el-get-install.el")
(goto-char (point-max))
(eval-print-last-sexp)))
(add-to-list 'el-get-recipe-path "~/.emacs.d/el-get-user/recipes")
(setq el-get-user-package-directory "~/.emacs.d/el-get-init-files/")
(setq el-get-sources
'(
ace-jump-mode
ace-window
ag
(:name cmake-font-lock :type git
:url "https://github.com/Lindydancer/cmake-font-lock.git")
apache-mode
(:name bpftrace-mode :type elpa
:repo ("melpa" . "https://melpa.org/packages/"))
browse-kill-ring
buffer-move
cmake-mode
(:name coffee-mode
:type git
:url "https://github.com/defunkt/coffee-mode"
:description "Emacs Major Mode for CoffeeScript"
:features coffee-mode
:prepare (progn
(add-to-list 'auto-mode-alist '("\\.coffee$" . coffee-mode))
(add-to-list 'auto-mode-alist '("Cakefile" . coffee-mode))))
color-theme-zenburn
(:name company :type elpa)
(:name company-quickhelp :type elpa)
(:name company-statistics :type elpa)
(:name company-terraform :type elpa)
(:name cucumber
:description "Emacs mode for editing Cucumber plain text stories"
:type git
:url "https://github.com/michaelklishin/cucumber.el.git")
(:name dash :type elpa
:repo ("melpa" . "https://melpa.org/packages/"))
(:name dockerfile-mode :type elpa)
(:name elpy :type elpa
:repo ("melpa" . "https://melpa.org/packages/"))
erc-view-log
(:name expand-region :type git
:url "https://github.com/magnars/expand-region.el.git")
flx
(:name flycheck :type elpa
(:name flycheck-aspell :type elpa
:repo ("melpa" . "https://melpa.org/packages/"))
:repo ("melpa" . "https://melpa.org/packages/"))
fold-dwim
(:name forge :type elpa)
(:name git-link :type elpa)
(:name gnuplot :type elpa)
go-def
go-eldoc
go-errcheck
go-flymake
go-imports
go-lint
go-mode
go-rename
go-template-mode
go-test
(:name graphviz-dot-mode :type elpa)
(:name grep-a-lot :type git
:url "https://github.com/emacsmirror/grep-a-lot.git"
:features grep-a-lot)
groovy-emacs-mode
(:name handlebars :type git
:url "https://github.com/danielevans/handlebars-mode.git"
:features handlebars-mode)
(:name hide-lines :type elpa
:repo ("melpa" . "https://melpa.org/packages/"))
(:name highlight-indentation :type elpa
:repo ("melpa" . "https://melpa.org/packages/"))
(:name highlight-parentheses :type elpa)
(:name highlight-symbol :type elpa
:repo ("melpa" . "https://melpa.org/packages/"))
(:name htmlize :type elpa)
ido-completing-read-plus
(:name iedit :type git
:url "https://github.com/victorhge/iedit.git")
(:name ioccur :type git
:url "https://github.com/thierryvolpiatto/ioccur.git")
(:name ivy :type elpa)
(:name jade :type git
:url "https://github.com/brianc/jade-mode.git")
(:name jinja2-mode :type elpa)
(:name js2 :type git
:url "https://github.com/mooz/js2-mode.git")
(:name jshint-mode :type git
:url "https://github.com/daleharvey/jshint-mode.git")
json-mode
(:name keychain-environment :type elpa)
keyfreq
(:name lsp-mode :type elpa
:repo ("melpa" . "https://melpa.org/packages/"))
(:name lsp-docker :type elpa)
lua-mode
(:name magit :type elpa)
markdown-mode
mediawiki
(:name miniedit :type git
:url "https://github.com/emacsmirror/miniedit.git")
(:name modern-cpp-font-lock :type elpa)
(:name multi-eshell :type git
:url "https://github.com/Niluge-KiWi/multi-eshell.git"
:features multi-eshell)
(:name mustache :type git
:url "https://github.com/mustache/emacs.git"
:features mustache-mode)
(:name nginx-mode :type elpa)
(:name org :type elpa)
(:name org-journal :type elpa)
(:name org-tree-slide :type elpa)
(:name ox-pandoc :type elpa
:repo ("melpa" . "https://melpa.org/packages/"))
(:name plantuml-mode :type elpa)
;; (:name powerline :type git
;; ;; :url "https://github.com/milkypostman/powerline.git"
;; :url "https://github.com/jonathanchu/emacs-powerline.git"
;; :features powerline)
(:name py-isort
:type github
:pkgname "dakra/py-isort.el"
:branch "isort-add-remove")
rainbow-mode
(:name rg :type elpa)
ruby-block
ruby-end
(:name s
:description "The long lost Emacs string manipulation library."
:type git
:url "https://github.com/magnars/s.el")
(:name smex :type elpa)
(:name solarized-theme :type elpa
:repo ("melpa" . "https://melpa.org/packages/"))
(:name sql-indent :type emacswiki)
(:name terraform-doc :type elpa)
(:name terraform-mode :type elpa)
(:name typescript-mode :type elpa)
(:name undo-tree :type git
:url "http://www.dr-qubit.org/git/undo-tree.git"
:features undo-tree)
web-mode
(:name widen-window :type emacswiki
:features widen-window)
(:name writeroom-mode :type elpa)
(:name wuxch-dired-copy-paste :type emacswiki
:features wuxch-dired-copy-paste)
yaml-mode
;;yasnippet
))
;; DOC: warning: :type: elpa with trailing `:` is ignored, merged with el-get upstream receipe
;; DOC: warning: no idea why but the elpa repo override seems ignored by el-get-install: always takes the package repo top priority: melpa stable
(setq my-packages (mapcar 'el-get-as-symbol (mapcar 'el-get-source-name el-get-sources)))
(el-get 'sync my-packages)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Base
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; start garbage collector less often
(setq gc-cons-threshold (* 20 1024 1024))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Desktop and server
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;if we are alone, run server, and load desktop
;;very crude hack
(defvar emacs-is-master nil
"Is emacs the server?")
(when (string= "1\n"
(shell-command-to-string
"ps x | grep emacs | grep -v grep | grep -v emacs-bin | grep -v emacsclient | wc -l"))
(setq emacs-is-master t)
;;(server-start)
)
;; desktop
(setq desktop-load-locked-desktop t
desktop-path '("~/.emacs.d/")
desktop-dirname "~/.emacs.d/"
desktop-base-file-name "desktop")
;;(desktop-save-mode 1)
;; save every 10mins
;; (setq desktop-save-timer (run-with-timer 600 600 (lambda () (cl-flet ((message (&rest args) nil))
;; (desktop-save-in-desktop-dir)))))
;; pipe to emacs
(defun fake-stdin-slurp (current-dir filename)
"Emulate stdin slurp using emacsclient hack"
;;; TODO tail mode on file: better for large pipes
(switch-to-buffer (generate-new-buffer "*stdin*"))
(cd current-dir)
(insert-file filename)
(end-of-buffer))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Graphical display
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; there is some stuff in customize, but can't move it
;; here for technical reasons
;; fullscreen
(defun toggle-fullscreen (&optional f)
(interactive)
(let ((current-value (frame-parameter nil 'fullscreen)))
(set-frame-parameter nil 'fullscreen
(if (equal 'fullboth current-value)
(if (boundp 'old-fullscreen) old-fullscreen nil)
(progn (setq old-fullscreen current-value)
'fullboth)))))
;; ;; one emacs to rule them all and in fullscreen bind them
;; (when emacs-is-master
;; (toggle-fullscreen))
;; new frames are maximized
(add-to-list 'default-frame-alist '(fullscreen . maximized))
(add-to-list 'default-frame-alist '(frame-resize-pixelwise . t))
;; (defadvice raise-frame (after make-it-work (&optional frame) activate)
;; "Work around some bug? in raise-frame/Emacs/GTK/Metacity/something.
;; Katsumi Yamaoka posted this in
;; http://article.gmane.org/gmane.emacs.devel:39702"
;; (call-process
;; "wmctrl" nil nil nil "-i" "-R"
;; (frame-parameter (or frame (selected-frame)) 'outer-window-id)))
;;(add-hook 'server-switch-hook 'raise-frame)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Colour theme and fonts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; add colors to zenburn
(setq zenburn-override-colors-alist
'(("zenburn-green-yellow-2" . "#89a610")
("zenburn-green-yellow-1" . "#99b32f")
("zenburn-green-yellow" . "#afd21c")
("zenburn-green-yellow+1" . "#d1ed5d")
("zenburn-green-yellow+2" . "#daed8d")
("zenburn-yellow-green-2" . "#a3ab10")
("zenburn-yellow-green-1" . "#b1b831")
("zenburn-yellow-green" . "#cfd81d")
("zenburn-yellow-green+1" . "#e8ef5e")
("zenburn-yellow-green+2" . "#eaef8f")
("zenburn-dark-blue-2" . "#1f3076")
("zenburn-dark-blue-1" . "#293c87")
("zenburn-dark-blue" . "#354897")
("zenburn-dark-blue+1" . "#4457a4")
("zenburn-dark-blue+2" . "#5666ab")
("zenburn-purple-2" . "#612e7e")
("zenburn-purple-1" . "#6d368a")
("zenburn-purple" . "#784097")
("zenburn-purple+1" . "#814c9e")
("zenburn-purple+2" . "#8959a4")
("zenburn-purple+3" . "#8f64a8")
("zenburn-purple+4" . "#9772ad")))
;; load-only
(load-theme 'zenburn t nil)
;; customize
(zenburn-with-color-variables
(custom-theme-set-faces
'zenburn
;;;;; basic coloring
`(cursor ((t (:background ,zenburn-fg :foreground ,zenburn-bg))))
;;;;; ioccur
`(ioccur-overlay-face ((t (:background ,zenburn-bg+1))))
`(ioccur-match-overlay-face ((t (:background ,zenburn-bg+1))))
`(ioccur-title-face ((t (:background ,zenburn-bg+1))))
`(ioccur-regexp-face ((t (:background "#506070" :underline t))))
`(ioccur-match-face ((t (:background "#506070"))))
;;;;; show-paren (less aggressive highlight for show-paren-style 'expression)
`(show-paren-mismatch ((t (:foreground ,zenburn-red+1 :background ,zenburn-bg+3))))
`(show-paren-match ((t (:background ,zenburn-bg-1))))
;;;;; org-mode levels
`(org-level-7 ((t (:foreground ,zenburn-red-2))))
`(org-level-8 ((t (:foreground ,zenburn-blue-3))))
))
;; finally, enable zenburn theme
;;(enable-theme 'zenburn)
;; solarized
;; make the fringe stand out from the background
(setq solarized-distinct-fringe-background t)
;; Don't change the font for some headings and titles
;;(setq solarized-use-variable-pitch nil)
;; Don't change size of org-mode headlines (but keep other size-changes)
;;(setq solarized-scale-org-headlines nil)
;; Change the size of markdown-mode headlines (off by default)
(setq solarized-scale-markdown-headlines t)
;; make the modeline high contrast
(setq solarized-high-contrast-mode-line t)
;; finally, load and enable the theme
(load-theme 'solarized-light-high-contrast t)
(setq font-use-system-font t) ;; since emacs 23.2
;; powerline
;; (require 'powerline)
;; (powerline-default-theme)
;; (setq powerline-arrow-shape 'arrow14)
;; (custom-set-faces
;; '(mode-line ((t (:foreground "#030303" :background "#bdbdbd" :box nil))))
;; '(mode-line-inactive ((t (:foreground "#f9f9f9" :background "#666666" :box nil)))))
;; (powerline-revert)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Mouse
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;(setq mouse-yank-at-point t)
(setq mouse-highlight t)
;; TODO better fix
(defun mouse-avoidance-point-position ()
"Return the position of point as (FRAME X . Y).
Analogous to `mouse-position'."
(let* ((inhibit-point-motion-hooks t)
(edges (window-inside-edges))
(x-y (posn-x-y (posn-at-point))))
(cons (selected-frame)
(cons (+ (car edges)
(/ (car x-y) (frame-char-width)))
(+ (car (cdr edges))
(/ (cdr x-y) (frame-char-height)))))))
;; control mouse clipboard. In particular, select-active-regions, activated in 23.2, sucks.
;; window selection is put in the X primary selection
(setq x-select-enable-primary t)
;; and not in X clipboard
(setq x-select-enable-clipboard nil)
(setq x-selection-timeout 10)
(setq mouse-drag-copy-region t)
(defun toggle-clipboard-selection ()
"Toggle clipboard/primary selection"
(interactive)
(if x-select-enable-clipboard
(progn
(setq x-select-enable-clipboard nil
x-select-enable-primary t)
(message "Primary selection"))
(setq x-select-enable-clipboard t
x-select-enable-primary nil)
(message "Clipboard")))
;; disable moving mouse when changing frame focus (desktop shortcut for emacsclient)
(setq focus-follows-mouse nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; General-purpose functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun toggle-variable (symb)
(set symb (not (eval symb))))
(defun current-mm ()
(buffer-local-value 'major-mode (current-buffer)))
(defun current-buffer-not-mini ()
"Return current-buffer if current buffer is not the *mini-buffer*
else return buffer before minibuf is activated."
(if (not (window-minibuffer-p)) (current-buffer)
(if (eq (get-lru-window) (next-window))
(window-buffer (previous-window)) (window-buffer (next-window)))))
(defun launch-command (command filename)
"Launches command with argument filename, discarding all output"
(let ((process-connection-type nil))
(start-process-shell-command command nil (concat "nohup " (shell-quote-argument command) " " (shell-quote-argument filename) " &"))))
(defun gnome-open-file (filename)
"gnome-opens the specified file."
(interactive "fFile to open: ")
(launch-command "/usr/bin/gnome-open" filename))
(defun basename-cons(f)
(cons (file-name-nondirectory f) f))
(defun sudo-edit (&optional arg)
"Edit a file as root"
(interactive "p")
(if arg
(find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: ")))
(find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
(defun toggle-alternate-file-as-root (&optional filename)
"Toggle between the current file as the default user and as root.
From http://atomized.org/2011/01/toggle-between-root-non-root-in-emacs-with-tramp/"
(interactive)
(let* ((filename (or filename (buffer-file-name)))
(parsed (when (tramp-tramp-file-p filename)
(coerce (tramp-dissect-file-name filename)
'list)))
(old-pnt (point)))
(unless filename
(error "No file in this buffer."))
(unwind-protect
(find-alternate-file
(if (equal '("sudo" "root") (butlast parsed 2))
;; As non-root
(if (or
(string= "localhost" (nth 2 parsed))
(string= (system-name) (nth 2 parsed)))
(nth 3 parsed)
(apply 'tramp-make-tramp-file-name
(append (list tramp-default-method nil) (cddr parsed))))
;; As root
(if parsed
(apply 'tramp-make-tramp-file-name
(append '("sudo" "root") (cddr parsed)))
(tramp-make-tramp-file-name "sudo" "root" "localhost" filename))))
(goto-char old-pnt))))
(global-set-key (kbd "C-c C-r") 'toggle-alternate-file-as-root)
;; copy-filename
(defun copy-filename()
"Copy filename to both kill ring and clipboard"
(interactive)
(let* ((filename (file-name-nondirectory (buffer-file-name)))
(line-number (line-number-at-pos))
(text (format "%s:%d" filename line-number)))
(x-select-text text)
(kill-new text)
(message "Copied %s" text)))
(defun reload-emacs () (interactive) (load-file "~/.emacs"))
(defun edit-emacs () (interactive) (find-file "~/.emacs"))
(defun indent-whole-buffer ()
"Indent whole buffer"
(interactive)
(delete-trailing-whitespace)
(indent-region (point-min) (point-max) nil))
(defun kill-whitespace ()
"Kill the whitespace between two non-whitespace characters"
(interactive "*")
(save-excursion
(save-restriction
(save-match-data
(progn
(re-search-backward "[^ \t\r\n]" nil t)
(re-search-forward "[ \t\r\n]+" nil t)
(replace-match "" nil nil))))))
(defun truncate-list (list n)
"Truncate LIST to at most N elements destructively."
(when n
(let ((here (nthcdr (1- n) list)))
(when (consp here)
(setcdr here nil))))
list)
(defun eval-and-replace ()
"Evaluate the sexp at point and replace it with its value
Taken from http://nflath.com/2009/08/easier-emacs/ by N Flath."
(interactive)
(backward-kill-sexp)
(condition-case nil
(prin1 (eval (read (current-kill 0)))
(current-buffer))
(error (message "Invalid expression")
(insert (current-kill 0)))))
(global-set-key (kbd "C-c C-e") 'eval-and-replace)
;; from http://www.emacswiki.org/emacs/AlignCommands#toc7
(defun align-repeat (start end regexp)
"Repeat alignment (for all columns) with respect to the given regular expression."
(interactive "r\nsAlign regexp: ")
(align-regexp start end
(concat "\\(\\s-*\\)" regexp) 1 1 t))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Misc. settings
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; instead of / or whatever
(setq default-directory (expand-file-name "~/"))
;; ;; OH MY GOD IT'S A SECURITY VULNERABILITY, WE ARE ALL GONNA DIE
;; (setq enable-local-variables :all)
;;automatic indent
(global-set-key (kbd "RET") 'newline-and-indent)
;;no transient mark
(transient-mark-mode -1)
;;blinking cursor is distracting and useless
(blink-cursor-mode -1)
;;display buffer name in title bar
(setq my-title '("%b" (:eval (if (buffer-file-name)
`(" - "
,(file-name-directory
(abbreviate-file-name (buffer-file-name))))))
" - " invocation-name "@" system-name))
(setq frame-title-format my-title)
(setq icon-title-format my-title)
;; stop creating #autosave# files
(setq auto-save-default nil)
;;please add a final newline each time I save a buffer
(setq require-final-newline 't)
;; hl current line everywhere
(global-hl-line-mode t)
;; tramp
(setq tramp-auto-save-directory "~/.emacs.d/tramp-autosave")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Occur
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; occur: force unique name
(add-hook 'occur-hook
#'(lambda ()
(occur-rename-buffer t)))
;;---- ioccur
(require 'ioccur)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Hide lines
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(autoload 'hide-lines "hide-lines" "Hide lines based on a regexp" t)
(global-set-key (kbd "C-c h") 'hide-lines)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Scrolling
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;scroll one line at a time
(setq scroll-conservatively 10000)
;;keep cursor at current position when scrolling
(setq scroll-preserve-screen-position t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Word wrapping
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; pour gérer les lignes trop longues
;; amazing new variable in e23. No need to worry about longlines any more
(setq-default word-wrap t)
;; ... but still use ll sometimes for reading dense text
(defalias 'll 'longlines-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Auto revert
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; automatically update buffers when changed
(global-auto-revert-mode t)
(setq global-auto-revert-non-file-buffers t)
(setq auto-revert-interval 30) ;30s is enough
(setq auto-revert-verbose nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Interactively Do Things
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;-------ido
;;makes C-x C-f and C-x b a lot easier
(require 'ido)
(setq ido-create-new-buffer 'always
ido-enable-flex-matching t
;;ido-max-prospects 12
ido-max-window-height 1
ido-save-directory-list-file "~/.emacs.d/ido.last")
(ido-mode 'both) ;; for buffers and files
(ido-everywhere 1)
;; open the buffers and files in the selected-window, like switch-to-buffer
(setq ido-default-file-method 'selected-window)
(setq ido-default-buffer-method 'selected-window)
;; ido-ubiquitous
(ido-ubiquitous-mode t)
;;-------icomplete
;; completion for commands that don't use ido (like help)
(icomplete-mode 1)
;; TODO test icicles
;;-------smex
;; super M-x : ido + frequency
(require 'smex)
(setq smex-history-length 7
smex-save-file "~/.emacs.d/smex-items")
(smex-initialize)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "<menu>") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
;; This is your old M-x.
;;(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
;; save every hour
(setq smex-save-to-file-timer (run-with-timer 3600 3600 'smex-save-to-file))
;;-------flx
(require 'flx-ido)
(flx-ido-mode t)
;; disable ido faces to see flx highlights.
(setq ido-use-faces nil)
(setq flx-ido-threshhold 1000)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Uniquify
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; uniquify buffer names
(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward)
;; plus some useful functions
(defun uniquify-get-filename (filename depth)
"Get 'uniquified' filename, given a filename and a prefix depth."
(let ((dir (file-name-directory filename))
(file (file-name-nondirectory filename)))
;; remove trailing slash
(if (string-match "/$" dir)
(setq dir (substring dir 0 -1)))
(if (string= "" dir) ;; hack to avoid "Debugger entered--Lisp error: (wrong-type-argument stringp nil)" on "/foo"
(setq dir "/"))
(uniquify-get-proposed-name file dir depth)))
(defun uniquify-filename-list (file-list &optional depth)
"Uniquify a list of filenames by returning an alist of filename and uniquified filenames.
Optional depth is for internal use."
(unless depth
(setq depth 0))
(let ((conflicting-list ())
(final-uniq-file-alist ())
(uniq-file-alist (mapcar
(lambda (file)
`(,file . ,(uniquify-get-filename file depth)))
file-list))
uniq-file-alist2
item
item2
conflict)
(while uniq-file-alist
(setq item (car uniq-file-alist)
uniq-file-alist (cdr uniq-file-alist)
conflict nil
uniq-file-alist2 uniq-file-alist)
;; Search for and remove all conflicts from remaining list
(while uniq-file-alist2
(setq item2 (car uniq-file-alist2)
uniq-file-alist2 (cdr uniq-file-alist2))
(when (string= (cdr item) (cdr item2))
;; Found conflict
(setq conflict t)
(push (car item2) conflicting-list)
(setq uniq-file-alist (delq item2 uniq-file-alist))
(setq uniq-file-alist2 (delq item2 uniq-file-alist2))))
(if conflict
(push (car item) conflicting-list)
(push item final-uniq-file-alist)))
;; now recurse with colliding files
(if conflicting-list
(setq final-uniq-file-alist
(append
final-uniq-file-alist
(uniquify-filename-list conflicting-list (+ 1 depth)))))
final-uniq-file-alist))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Undo-tree
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq undo-tree-mode-lighter "")
(global-undo-tree-mode)
(set-default 'undo-tree-visualizer-timestamps t)
(add-hook 'erc-mode-hook #'(lambda () (setq undo-tree-dont-activate t)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Highligh symbol
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'highlight-symbol)
;; (zenburn-with-color-variables
;; (setq highlight-symbol-colors
;; `(,zenburn-cyan
;; ,zenburn-green+4
;; ,zenburn-magenta
;; ,zenburn-yellow
;; ,zenburn-red-2
;; ,zenburn-blue-3
;; ,zenburn-orange
;; ,zenburn-purple+4
;; ,zenburn-yellow-green+2)))
(global-set-key (kbd "C-1") 'highlight-symbol-at-point)
(global-set-key (kbd "C-2") 'highlight-symbol-next)
(global-set-key (kbd "C-3") 'highlight-symbol-prev)
(global-set-key (kbd "C-0") 'highlight-symbol-remove-all)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Parenthesis editing
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;visual paren matching
(show-paren-mode t)
(setq show-paren-style 'expression)
(setq show-paren-delay 0)
;;rainbow parentheses highlighting ! \o/
(require 'highlight-parentheses)
;; (zenburn-with-color-variables
;; (setq hl-paren-colors
;; (list zenburn-red-4 zenburn-orange zenburn-yellow-green+1 zenburn-green zenburn-blue zenburn-dark-blue+2 zenburn-purple+2 nil)) ;; a final fake color, because the last one seems to be ignored
;; (setq hl-paren-background-colors
;; (make-list (length hl-paren-colors) zenburn-bg-1)))
;;highlight-parentheses is a buffer-local minor mode : create a global
;;minor mode of our own
(define-globalized-minor-mode global-highlight-parentheses-mode
highlight-parentheses-mode
(lambda ()
(highlight-parentheses-mode t)))
(global-highlight-parentheses-mode t)
; from http://emacswiki.org/emacs/ShowParenMode#toc1
(defadvice show-paren-function
(after show-matching-paren-offscreen activate)
"If the matching paren is offscreen, show the matching line in the
echo area. Has no effect if the character before point is not of
the syntax class ')'."
(interactive)
(let* ((cb (char-before (point)))
(matching-text (and cb
(char-equal (char-syntax cb) ?\) )
(blink-matching-open))))
(when matching-text (message matching-text))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Dired
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; misc. dired add-ons
(require 'dired-x)
;; omit hidden files + default
(setq-default dired-omit-files-p t) ; Buffer-local variable
(setq dired-omit-files (concat dired-omit-files "\\|^\\..+$"))
;;clean dired default view : don't display groups, use human-readable sizes
(setq dired-listing-switches "-alhG"
dired-free-space-args "-Pkm" ;; TODO k and m for what?
dired-auto-revert-buffer t)
;;add xdg-open as C-ret
(defun dired-xdg-open-file ()
"Opens the current file from a Dired buffer."
(interactive)
(launch-command "xdg-open" (dired-get-file-for-visit)))
(define-key dired-mode-map (kbd "<C-return>") 'dired-xdg-open-file)
;; LANG=Fr breaks the regexp that matches file sizes (, instead of . separator)
(add-hook 'dired-mode-hook '(lambda () (setenv "LC_NUMERIC" "C")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; VC
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; deactivate
(setq vc-handled-backends nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Magit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'magit)
(require 'forge)
(setq forge-pull-notifications nil)
;; hide untracked section by default
(push (cons [untracked status] 'hide) magit-section-initial-visibility-alist)
;; no buffer saving when magit-status
(setq magit-save-repository-buffers nil)
;; use ido in prompts
;; (setq magit-completing-read-function 'magit-ido-completing-read)
;; let's try ivy there
(ivy-mode)
(setq magit-completing-read-function 'magit-builtin-completing-read)
;; show process buffer for long operations
(setq magit-process-popup-time 5)
;; magit-status: switch to buffer instead of pop to buffer
(setq magit-display-buffer-function 'magit-display-buffer-same-window-except-diff-v1)
;; intra line diff highlight
(setq magit-diff-refine-hunk t)
;; "u" and "U" are already taken by unstage, set "o" in addition to uneasy "^" on azerty keyboards
(define-key magit-mode-map (kbd "o") 'magit-section-up)
(global-set-key (kbd "C-c s") 'magit-status)
(global-set-key (kbd "C-c C-s") 'magit-status)
(require 'git-commit)
;; flyspell on log
(add-hook 'git-commit-setup-hook '(lambda () (flyspell-lang "american")))
;; https://github.com/magit/magit/issues/2012#issuecomment-619366605
(with-eval-after-load 'magit
(transient-append-suffix 'magit-log "-A"
'("-1" "First parent" "--first-parent")))
;; ignore whitespace
;; TODO fix ignore whitespace
;; (defun magit-toggle-whitespace ()
;; (interactive)
;; (if (member "-w" (magit-diff-refresh-arguments))
;; (magit-dont-ignore-whitespace)
;; (magit-ignore-whitespace)))
;; (defun magit-ignore-whitespace ()
;; (interactive)
;; (message "Ignore whitespace diffs")
;; (let ((args (magit-diff-refresh-arguments)))
;; (add-to-list args "-w")
;; (add-to-list args "--ignore-blank-lines")
;; (magit-diff-refresh args)))
;; (defun magit-dont-ignore-whitespace ()
;; (interactive)
;; (message "Display whitespace diffs")
;; (magit-diff-refresh (remove "-w" (remove "--ignore-blank-lines" (magit-diff-refresh-arguments)))))
;;;(define-key magit-mode-map (kbd "W") 'magit-toggle-whitespace)
;; magit-git-wip
;; https://github.com/bartman/git-wip
;; see magit-wip.el to enable on per repo basis:
;; git config --add magit.extension wip-save
(require 'magit-wip)
(magit-wip-after-save-mode 1)
(magit-wip-after-apply-mode 1)
(magit-wip-before-change-mode 1)
;; magit-blame
(require 'magit-blame)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Window management
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;move between windows with meta-keypad
(windmove-default-keybindings 'meta)
;; TODO test this
;; widen window : widen selected window
;; (global-widen-window-mode t)
;; ;; et on ajoute les fonctions utilisées par windmove, comme ça on a tout ce qu'il faut!
;; (add-to-list 'ww-advised-functions 'windmove-up)
;; (add-to-list 'ww-advised-functions 'windmove-down)
;; (add-to-list 'ww-advised-functions 'windmove-right)
;; (add-to-list 'ww-advised-functions 'windmove-left)
;; resize windows
(global-set-key (kbd "S-C-<left>") 'shrink-window-horizontally)
(global-set-key (kbd "S-C-<right>") 'enlarge-window-horizontally)
(global-set-key (kbd "S-C-<down>") 'shrink-window)
(global-set-key (kbd "S-C-<up>") 'enlarge-window)
;; Cancel and redo windows configurations
;;C-c left/right to undo/redo changes in window configuration
(require 'winner)
(setq winner-dont-bind-my-keys t) ;; default bindings conflict with org-mode
(winner-mode t) ;; turn on the global minor mode
;; buffer move
(require 'buffer-move)
(global-set-key (kbd "S-M-<left>") 'buf-move-left)
(global-set-key (kbd "S-M-<right>") 'buf-move-right)
(global-set-key (kbd "S-M-<up>") 'buf-move-up)
(global-set-key (kbd "S-M-<down>") 'buf-move-down)
;; ace-window
(global-set-key (kbd "M-o") 'ace-window)
;; ace-jump
(require 'ace-jump-mode)
(setq ace-jump-mode-scope 'frame)
(global-set-key (kbd "C-c SPC") 'ace-jump-mode)
(global-set-key (kbd "C-c C-SPC") 'ace-jump-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Session Management
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;save the minibuffer input
(savehist-mode 1)
;;save last edit place in files
(require 'saveplace)
(setq-default save-place t)
(setq save-place-file "~/.emacs.d/places")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Recent files
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;recent files, interaction with ido
(require 'recentf)
(defcustom recentf-ido-max-items 200
"Maximum number of items of the recent list selection with ido
(recentf-ido-find-file-or-maybe-list).
If nil, do not limit."
:group 'recentf)
(defun recentf-ido-find-file-or-maybe-list (&optional arg)
"Find a recent file using Ido and uniquify,
or list all recent files if prefixed"
(interactive "P")
(if arg
(recentf-open-files)
(let* ((file-list (truncate-list
(copy-list recentf-list)
recentf-ido-max-items))
(uniq-file-alist (uniquify-filename-list file-list))
;; ask user
(file (ido-completing-read
(format "%s: " recentf-menu-title)
(mapcar (lambda (filename)
(cdr (assoc filename uniq-file-alist)))
file-list)
nil t)))