-
Notifications
You must be signed in to change notification settings - Fork 3
/
emacs
966 lines (815 loc) · 37.5 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
;;; package --- Emacs configuration
;; -*- coding: utf-8; lexical-binding: t -*
;;; Commentary:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; .emacs ;;
;; Author: Jon Atack ;;
;; Licence: MIT ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; This file configures Emacs 26 with an emphasis on Common Lisp, Ruby, C, C++.
;; Feel free to customize it.
;;; Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Section I: Generic settings ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq user-full-name "Jon Atack" user-mail-address "[email protected]")
(defun turn-off-gc ()
"No GC while the minibuffer is open."
(setq gc-cons-threshold most-positive-fixnum)
(setq gc-cons-percentage 0.6))
(defun turn-on-gc ()
"Back to normal GC when the minibuffer is closed."
(setq gc-cons-threshold 30 * 1000 * 1000)
(setq gc-cons-percentage 0.2))
;; Turn off GC during Emacs startup and then back on again.
(turn-off-gc)
(add-hook 'after-init-hook #'turn-on-gc)
;; GC tweaking according to
;; https://bling.github.io/blog/2016/01/18/why-are-you-changing-gc-cons-threshold/
(add-hook 'minibuffer-setup-hook #'turn-off-gc)
(add-hook 'minibuffer-exit-hook #'turn-on-gc)
;; Display GC messages in the mini-buffer
(setq garbage-collection-messages nil)
;; Display Emacs startup stats
(add-hook 'emacs-startup-hook
(lambda () (message "Emacs ready in %s with %d garbage collections."
(format (emacs-init-time)) gcs-done)))
;; Resize the window to my screen
(if (display-graphic-p)
(progn
(setq initial-frame-alist
'(
; (tool-bar-lines . 0)
(width . 128) ; chars
(height . 101) ; lines
; (background-color . "honeydew")
(left . 0)
(top . 0)))
(setq default-frame-alist
'(
; (tool-bar-lines . 0)
(width . 105)
(height . 88)
; (background-color . "honeydew")
(left . 0)
(top . 0))))
(progn
(setq initial-frame-alist '( (tool-bar-lines . 0)))
(setq default-frame-alist '( (tool-bar-lines . 0)))))
;; Typography
;; (set-face-attribute 'default nil
;; :family "Source Code Pro"
;; :height 150
;; :weight 'normal
;; :width 'normal)
;; Set Emacs display to be transparent
;; (set-frame-parameter (selected-frame) 'alpha '(<active> [<inactive>]))
;; (set-frame-parameter (selected-frame) 'alpha '(88 70))
;; (add-to-list 'default-frame-alist '(alpha 88 70))
;; Disable the menu bar, the tool bar and the scroll bar
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(blink-cursor-mode 0) ; Disable cursor blink
(global-display-line-numbers-mode) ; Globally display line numbers
(column-number-mode 1)
(setq scroll-preserve-screen-position 'always)
;; (global-hl-line-mode t) ; Highlight current line
;; Word-wrap (filling) in Emacs:
;; http://johnlaudun.org/20080321-word-wrap-filling-in-emacs/
;; http://ergoemacs.org/emacs/emacs_unfill-paragraph.html
;; (setq-default word-wrap t)
;;
;; Visual Line mode provides support for editing by visual lines.
;; See: http://ergoemacs.org/emacs/emacs_long_line_wrap.html
;; It turns on word-wrapping in the buffer, and rebinds C-a, C-e, and C-k
;; to commands that operate by visual lines instead of logical lines.
;; (global-visual-line-mode 1)
;;(setq visual-line-fringe-indicators '(left-curly-arrow right-curly-arrow))
;; Auto-insert newline at end of file
(setq-default require-final-newline t mode-require-final-newline t)
;; Display full file path in emacs frame title bar.
(setq-default frame-title-format '((:eval (if (buffer-file-name)
(abbreviate-file-name (buffer-file-name)) "%f"))))
;; Show system name and full file path in emacs frame title bar.
;; (setq frame-title-format
;; (list (format "%s %%S: %%j " (system-name))
;; '(buffer-file-name "%f" (dired-directory dired-directory "%b"))))
(setq inhibit-startup-screen t) ; Don’t display the Emacs splash screen
(setq initial-scratch-message nil) ; Don't show scratch buffer on startup
;; Highlight/blink matching parentheses globally.
(run-with-idle-timer 2 nil (lambda ()
(setf blink-matching-paren t
show-paren-mode t
show-paren-ring-bell-on-mismatch nil)))
;; Display “lambda” as “λ”
(run-with-idle-timer 3 nil (lambda () (global-prettify-symbols-mode t)))
;; (setq case-fold-search t) ; Make searches case-insensitive
(setq browse-url-browser-function 'eww-browse-url)
;; (set-face-attribute 'default nil :height 90) ; Make the default font slightly smaller.
(setq-default indent-tabs-mode nil) ; Make indentation use spaces.
;; Use 2 spaces for indentation
(setq-default tab-width 2)
(setq sh-basic-offset 2)
(setq css-indent-offset 2)
(setq js-indent-level 2)
(setq web-mode-markup-indent-offset 2)
(setq web-mode-code-indent-offset 2)
(setq web-mode-css-indent-offset 2)
(setq-default fill-column 80) ; Set max character line length
(setq large-file-warning-threshold nil) ; Don’t warn me about opening large files
(setq select-enable-clipboard t) ; Enable copy/past-ing from clipboard
(setq system-uses-terminfo nil) ; Fix weird color escape sequences
(setq confirm-kill-emacs 'yes-or-no-p) ; Ask for confirmation before closing emacs
(fset 'yes-or-no-p 'y-or-n-p) ; Enable answering with y/n instead of yes/no
;; Always reload the file if it changed on disk
(run-with-idle-timer 2 nil (lambda () (global-auto-revert-mode t)))
;; (setq-default line-spacing t) ; A nice line height
;; (setq mac-command-modifier 'meta) ; Treat the CMD key like meta on OSX
;; (setq ns-use-srgb-colorspace t) ; SRGB support for OSX
;; Open splits horizontally
(setq split-height-threshold 0)
(setq split-width-threshold nil)
(set-fringe-mode '(5 . 4)) ; Show a fringe
;; Remove the fringe indicators
(when (boundp 'fringe-indicator-alist)
(setq-default fringe-indicator-alist
'(
(continuation . nil)
(overlay-arrow . nil)
(up . nil)
(down . nil)
(top . nil)
(bottom . nil)
(top-bottom . nil)
(empty-line . nil)
(unknown . nil))))
;; Save desktop between sessions
;;
;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Saving-Emacs-Sessions.html
;;
;; M-x desktop-save -> saves the desktop manually
;;
(setq desktop-path '("~/.emacs.d/")) ; Load/save desktop in .emacs.d directory
;; (setq desktop-path '(".")) ; Load/save desktop in dir Emacs opened from
;;
;; (desktop-save-mode t) ; Auto-save desktop on exiting, and reload on startup
;; (setq default-directory "/")
;; A simple backup setup to ensure sure I don't foo~ and #.foo files in
;; directories with edited files.
(setq
backup-by-copying t ; don't clobber symlinks-
backup-directory-alist
'(("." . "~/.saves")) ; don't litter my fs tree
auto-save-file-name-transforms
`((".*" ,temporary-file-directory t))
delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t) ; use versioned backups
;; Store all backup and autosave files in the tmp dir
;;(setq backup-directory-alist
;; '((".*" . ,temporary-file-directory)))
;;(setq auto-save-file-name-transforms
;; '((".*" ,temporary-file-directory t)))
;; Making dabbrev a bit nicer
(setq dabbrev-abbrev-skip-leading-regexp ":")
(setq dabbrev-backward-only t)
;; Mute beep sound and display message instead
(setq visible-bell nil)
(setq ring-bell-function (lambda () (message "*beep*")))
(put 'upcase-region 'disabled nil) ; enable using upcase-region without warnings
;; UTF-8
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-language-environment "UTF-8")
(setenv "LANG" "en_US.UTF-8")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Section II: Packages ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; No GC during this memory-heavy init phase
(let ((gc-cons-threshold most-positive-fixnum))
(package-initialize)
(setq use-package-always-ensure t)
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")))
(unless (assoc-default "melpa" package-archives)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t))
(unless (assoc-default "marmalade" package-archives)
(add-to-list 'package-archives '("marmalade" . "https://marmalade-repo.org/packages/") t))
(unless (assoc-default "org" package-archives)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t))
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/")
;; Fetch the list of packages available if needed
(unless package-archive-contents (package-refresh-contents))
;; Install any missing packages
;;
(dolist (package package-selected-packages)
(unless (package-installed-p package)
(package-refresh-contents)
(package-install package)))
;; Ensure the Use Package library is installed and configured.
;; Repository: https://github.com/jwiegley/use-package
;;
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
;; (setq use-package-verbose t)
(setq use-package-always-ensure t)
(require 'use-package)
(use-package auto-compile :config (auto-compile-on-load-mode))
(setq load-prefer-newer t)
(use-package spaceline
:demand t
:init
(setq powerline-default-separator 'arrow-fade)
:config
(require 'spaceline-config)
(spaceline-spacemacs-theme))
(use-package better-defaults)
;; Saveplace saves the cursor position between sessions
(use-package saveplace
:defer t
:ensure t
:init
(setq save-place-file (expand-file-name ".places" user-emacs-directory)
save-place-mode t))
(use-package flx-ido
:defer t
:ensure t
:init
(ido-mode t)
;; (ido-everywhere t)
(flx-ido-mode t)
(setq ido-enable-flex-matching t
;; Disable ido faces to see flx highlights:
;; (setq ido-use-faces nil)
;; If you don't want to use the flx's highlights you can turn them off like this:
flx-ido-use-faces nil))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Ivy config
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (use-package ivy
;; :ensure t
;; :commands (ivy-mode)
;; :config (require 'ivy)
;; (ivy-mode t)
;; (setq ivy-use-virtual-buffers t)
;; (setq enable-recursive-minibuffers t)
;; (setq ivy-wrap t)
;; (global-set-key (kbd "C-c C-r") 'ivy-resume)
;; Show #/total when scrolling buffers
;;(setq ivy-count-format "%d/%d "))
(use-package swiper
:ensure t
:bind (("C-s" . swiper)
("C-r" . swiper)))
(use-package counsel
:ensure t
:bind (("M-x" . counsel-M-x)
("C-x C-f" . counsel-find-file)
("<f1> f" . counsel-describe-function)
("<f1> v" . counsel-describe-variable)
("<f1> l" . counsel-find-library)
("<f2> i" . counsel-info-lookup-symbol)
("<f2> u" . counsel-unicode-char)
("C-c g" . counsel-git-grep) ; git grepping!
("C-c j" . counsel-git) ; find file?
("C-c k" . counsel-ag)
("C-c r" . counsel-rg) ; grep
("C-x l" . counsel-locate) ; find files
:map minibuffer-local-map
("C-r" . counsel-minibuffer-add)
)
:config
(if (executable-find "rg")
;; use ripgrep instead of grep because it's way faster
(setq counsel-grep-base-command "rg -i -M 120 --no-heading --line-number --color never '%s' %s"
counsel-rg-base-command "rg -i -M 120 --no-heading --line-number --color never %s .")
(warn "\nWARNING: Could not find the ripgrep executable. It is recommended you install ripgrep.")))
;; Use universal ctags to build the tags database for the project.
;; When you first want to build a TAGS database run 'touch TAGS'
;; in the root directory of your project.
(use-package counsel-etags
:ensure t
:init
(eval-when-compile
;; Silence missing function warnings
(declare-function counsel-etags-virtual-update-tags "counsel-etags.el")
(declare-function counsel-etags-guess-program "counsel-etags.el")
(declare-function counsel-etags-locate-tags-file "counsel-etags.el"))
:bind (
("M-." . counsel-etags-find-tag-at-point)
("M-t" . counsel-etags-grep-symbol-at-point)
("M-s" . counsel-etags-find-tag))
:config
;; Ignore files above 800kb
(setq counsel-etags-max-file-size 800)
;; Ignore build directories for tagging
(add-to-list 'counsel-etags-ignore-directories '"build*")
(add-to-list 'counsel-etags-ignore-directories '".vscode")
(add-to-list 'counsel-etags-ignore-filenames '".clang-format")
;; Don't ask before rereading the TAGS files if they have changed
(setq tags-revert-without-query t)
;; Don't warn when TAGS files are large
(setq large-file-warning-threshold nil)
;; How many seconds to wait before rerunning tags for auto-update
(setq counsel-etags-update-interval 180)
;; Set up auto-update
(add-hook 'prog-mode-hook
(lambda () (add-hook 'after-save-hook
(lambda ()
(counsel-etags-virtual-update-tags))))))
;; Projectile key bindings:
;;
;; Grep -> C-c p s g
;; Grep all project -> M-- C-c p s g
(use-package projectile
:ensure t
:config
(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
(setq projectile-project-search-path '("~/projects/" "~/common-lisp/"))
;; projectile-keymap-prefix (kbd "C-c C-p")
;; projectile-completion-system 'grizzl)
(projectile-mode +1))
;; (projectile-global-mode))
;; (add-hook 'enh-ruby-mode-hook 'projectile-mode))
;; (add-hook 'clojure-mode-hook #'smartparens-strict-mode)
;; (setq ns-pop-up-frames nil)
(setq resize-mini-windows nil) ; Do not allow resizing the mini-buffer; keep it to one line.
;; SLIME
;; (add-to-list 'load-path "~/quicklisp/dists/quicklisp/software/slime-v2.27")
;; (load (expand-file-name "~/quicklisp/slime-helper.el"))
;; (require 'slime-autoloads)
(slime-setup '(slime-fancy))
(setq slime-contribs '(slime-fancy slime-indentation slime-repl
slime-cl-indent slime-banner slime-tramp
slime-mdot-fu slime-editing-commands
slime-quicklisp slime-presentations
slime-repl-ansi-color slime-company)) ; slime-asdf
;;
;; Note: If slime-repl-ansi-color.el is not loading, it needs to be copied from
;; ~/.emacs.d/vendor/ to the elpa/slime-XXXX directory, e.g. from ~/.emacs.d do:
;; cp vendor/slime-repl-ansi-color.el elpa/slime-XXXX
;; (setq slime-contribs '(slime-repl)) ; repl only
(setq slime-startup-animation nil)
;; (setq inferior-lisp-program "/usr/bin/sbcl --noinform")
;; (setq inferior-lisp-program "/usr/local/bin/ccl -K utf-8")
;; (setq inferior-lisp-program "ecl")
;; Load Swank faster, as per:
;; https://common-lisp.net/project/slime/doc/html/Loading-Swank-faster.html
;;
;; For SBCL, we recommend that you create a custom core file with socket
;; support and POSIX bindings included because those modules take the most
;; time to load. To create such a core, execute the following steps:
;;
;; $ sbcl
;; * (mapc 'require '(sb-bsd-sockets sb-posix sb-introspect sb-cltl2 asdf))
;; * (save-lisp-and-die "sbcl.core-for-slime")
;;
;; After that, add something like this to your .emacs:
;;
;; (setq slime-lisp-implementations '((sbcl ("sbcl" "--core" "sbcl.core-for-slime"))))
;;
;; For maximum startup speed you can include the Swank server directly in a core file.
;; This setup is a bit more involved and you need to create a new core file after
;; updating SLIME or SBCL. The steps to execute are:
;;
;; $ cd ~/quicklisp/local-projects
;; (or ~/quicklisp/dists/quicklisp/software or whichever directory contains Slime)
;;
;; $ sbcl
;; * (load "slime/swank-loader.lisp")
;; * (swank-loader:dump-image "sbcl.core-with-swank")
;;
;; Then add this to your .emacs:
;;
;; (setq slime-lisp-implementations
;; '((sbcl ("sbcl" "--core" "path-to.../sbcl.core-with-swank")
;; :init (lambda (port-file _)
;; (format "(swank:start-server %S)\n" port-file)))))
(setq slime-lisp-implementations
'((sbcl ("sbcl" "--core" "/home/jon/quicklisp/local-projects/sbcl.core-with-swank")
:init (lambda (port-file _)
(format "(swank:start-server %S)\n" port-file)))))
(setf slime-default-lisp 'sbcl)
(setq slime-net-coding-system 'utf-8-unix)
(eval-after-load 'slime
`(define-key slime-prefix-map (kbd "M-h") 'slime-documentation-lookup))
;; I recommend you install the following packages: smex, which adds an
;; improved version of M-x. You can read more about smex at:
;; https://github.com/nonsequitur/smex/
;; Another often used mode is magit, which is an interface to git, allowing
;; you to manage your repos through emacs. You can read more about it at:
;; http://magit.vc/ It is one of the most useful modes available for emacs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Section III: Global Key Bindings ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Set the enter key to newline-and-indent which inserts a new line and then
;; indents according to the major mode. This is very convenient.
;; (global-set-key (kbd "RET") 'newline-and-indent)
;; (define-key global-map (kbd "RET") 'newline-and-indent)
;; By default C-x o is bound to 'other window, but I find I use it much more
;; ofther than open-line, which is bound to C-o, so I swap their definitions
(global-set-key (kbd "C-o") 'other-window)
(global-set-key (kbd "C-x o") 'open-line)
;; Make "C-t" act like "C-x", so it's easier to type on Dvorak layout
(keyboard-translate ?\C-t ?\C-x)
;; (keyboard-translate ?\C-x ?\C-t) ; inversely, make "C-x" act like "C-t"
;; Make function-8 act like "C-x" as a shortcut to avoid left pinky stress
(global-set-key (kbd "<f8>") ctl-x-map)
;; Toggle S-expression comments on/off with auto-formatting
(global-set-key (kbd "C-M-;") #'comment-or-uncomment-sexp)
;; Control-i to open a Ruby/Rails console in a new buffer
;; (global-set-key (kbd "C-i") 'inf-ruby-console-rails)
;; M-0..3 are bound to 'digit-argument. To be used with C-u. I don't use them
;; often, so I prefer to rebind them to the window commands, since M-1 is
;; easier to type than C-x 1.
;; (global-set-key (kbd "M-1") 'delete-other-windows)
;; (global-set-key (kbd "M-2") 'split-window-vertically)
;; (global-set-key (kbd "M-3") 'split-window-horizontally)
;; (global-set-key (kbd "M-0") 'delete-window)
;; If you have installed smex, you can uncomment the following lines. To
;; activate it without restarting Emacs select the lines and type
;; M-x eval-region:
;; (require 'smex)
;; (global-set-key (kbd "M-x") 'smex)
;; (global-set-key (kbd "M-X") 'smex-major-mode-commands)
;; (global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
;; find-in-project and cmd-t
;; “Cmd-T”-style command to fuzzily open a file in the current project
;; Find-in-Project text search for finding an arbitrary string in the current project
;; (global-set-key (kbd "M-x") #'helm-M-x)
;; (global-set-key (kbd "C-i") #'helm-projectile-ag)
;; (global-set-key (kbd "s-t") #'helm-projectile-find-file-dwim)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Section IV: Emacs Lisp mode behavior ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'auto-mode-alist
'("\\(?:\\.elisp\\|emacs\\|/\\(?:emacs\\)\\)\\'"
. emacs-lisp-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Section V: Lisp mode behavior ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Ensure Lisp mode for Lisp files
(add-to-list 'auto-mode-alist '("\\.cl" . lisp-mode))
(add-to-list 'auto-mode-alist '("\\.lisp" . lisp-mode))
(add-to-list 'auto-mode-alist '("\\.lps" . lisp-mode))
;; Ensure Lisp mode for Lisp init files
(add-to-list 'auto-mode-alist '("\\clrc" . lisp-mode))
(add-to-list 'auto-mode-alist '("\\lisprc" . lisp-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Section VI: Slime Lisp mode behavior ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun lisp-hook-fn ()
(interactive)
(slime-mode) ; start slime mode
(local-set-key [tab] 'slime-complete-symbol) ; bind tab key to slime-complete-symbol
;; Available styles are: basic, classic, modern and sbcl.
;; All of them are defined in slime-cl-indent.el file,
;; but you can define your own style as well.
(setq common-lisp-style "sbcl")
;; Common Lisp indentation
;;
;; C-M-q on the first paren reindents an expression
;; C-c M-q reindents a function
;;
(local-set-key (kbd "M-q") #'slime-reindent-defun)
(local-set-key (kbd "<f12>") #'slime-selector)
(local-set-key (kbd "C-c s") #'slime-selector)
(local-set-key (kbd "C-c r") #'slime-pop-find-definition-stack)
;;
;; Set indent function so common-lisp-indent-function will indent correctly
(set (make-local-variable lisp-indent-function) 'common-lisp-indent-function)
(setq lisp-indent-function 'common-lisp-indent-function)
(setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol)
(setq slime-load-failed-fasl 'never)) ; never load code that failed to compile
;; Finally we tell lisp-mode to run our function on startup
(add-hook 'lisp-mode-hook 'lisp-hook-fn)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Section VII: C modes (C, C++, Java, etc.) behavior ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CC mode links:
;; https://www.gnu.org/software/emacs/manual/html_node/ccmode/Getting-Started.html
;; http://kirste.userpage.fu-berlin.de/chemnet/use/info/cc-mode/cc-mode_6.html
;; CC modes code styles:
;;
;; gnu - Blessed by the Free Software Foundation for C code in GNU programs.
;;
;; k&r - Classic Kernighan and Ritchie style for C code. If you're looking
;; for the style used in the 2nd Ed. of “The C Programming Language”,
;; then check out the stroustrup style.
;;
;; bsd - Also known as “Allman style” after Eric Allman.
;;
;; whitesmith - popularized by the examples that came with Whitesmiths C, an early
;; commercial C compiler.
;;
;; stroustrup - The classic Stroustrup style for C++ code.
;;
;; ellemtel - Popular C++ style defined in “Programming in C++, Rules and
;; Recommendations” by Erik Nyquist and Mats Henricson.
;; Link: https://www.doc.ic.ac.uk/lab/cplus/c++.rules/
;;
;; linux - C coding standard for Linux (the kernel).
;;
;; python - C coding standard for Python extension modules.
;;
;; java - By default c-default-style installs it when you enter java-mode.
;;
;; awk - By default c-default-style installs it when you enter awk-mode.
;;
;; user - Consists of the factory defaults for all the style variables as
;; modified by the customizations you do either with the Customization
;; interface or by writing setqs and c-set-offsets at the top level of
;; your .emacs file (see Config Basics). The style system creates this
;; style as part of its initialization & doesn't modify it afterwards.
;;
;; Customizations for all of c-mode, c++-mode, objc-mode, java-mode, etc.
(setq c-default-style '((c-mode . "gnu")
(c++-mode . "stroustrup")
(java-mode . "java")
(awk-mode . "awk")
(other . "linux")))
;; (setq-default c-basic-offset 4) ; Use 4 spaces for indentation
(add-to-list 'auto-mode-alist '("\\.c$" . c-mode))
(add-to-list 'auto-mode-alist '("\\.cpp$" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.cc$" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.cxx$" . c++-mode))
;; By default Emacs treats files ending in .h as C files.
;; The following line inverses that to treat them as C++ files instead:
(add-to-list 'auto-mode-alist '("\\.h$" . c++-mode));
(use-package cc-mode
:mode (("\\.[hH]\\'" . c++-mode)
("\\.cpp\\'" . c++-mode)
("\\.hpp\\'" . c++-mode)
("\\.cc\\'" . c++-mode)))
;; :init (add-hook 'c++-mode-hook (lambda () (setq flycheck-clang-language-standard "c++17"))))
(use-package clang-format
:after cc-mode
:commands (clang-format-buffer))
(use-package modern-cpp-font-lock
:after cc-mode
:commands modern-c++-font-lock-mode
:init (add-hook 'c++-mode-hook 'modern-c++-font-lock-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Section VIII: Python mode behavior ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; C-c C-c elpy-shell-send-region-or-buffer
;; Send code to the REPL (the region, if selected, otherwise whole buffer)
;; C-c C-d elpy-doc
;; Show documentation of the function/class under cursor in a new window
;; M-. elpy-goto-definition (of the function/class under cursor)
;; M-(left/right) elpy-nav-indent-shift-(left/right)
;; C-M-(n/p) elpy-nav-(forward/backward)-block
;; M-(up/down) elpy-nav-move-line-or-region-(up/down)
;; Move an entire block of code up/down. This is helpful for moving code around.
(use-package elpy
:ensure t
:defer t
:bind
(:map elpy-mode-map
("C-M-n" . elpy-nav-forward-block)
("C-M-p" . elpy-nav-backward-block))
:hook ((elpy-mode . (lambda ()
(set (make-local-variable 'company-backends)
'((elpy-company-backend :with company-yasnippet))))))
:init
(elpy-enable)
:config
(setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
;; fix for MacOS, see https://github.com/jorgenschaefer/elpy/issues/1550
(setq elpy-shell-echo-output nil)
(setq elpy-rpc-python-command "python3")
(setq elpy-rpc-timeout 2))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Section IV: Ruby mode behavior ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Doubt this is needed with the auto hooks.
;; (setq initial-major-mode 'ruby-mode)
;; Apply enh-ruby-mode to files with these extensions
(add-to-list 'auto-mode-alist '("\\.rb$" . enh-ruby-mode))
(add-to-list 'auto-mode-alist '("\\.rake$" . enh-ruby-mode))
(add-to-list 'auto-mode-alist '("Rakefile$" . enh-ruby-mode))
(add-to-list 'auto-mode-alist '("\\.gemspec$" . enh-ruby-mode))
(add-to-list 'auto-mode-alist '("\\.ru$" . enh-ruby-mode))
(add-to-list 'auto-mode-alist '("Gemfile$" . enh-ruby-mode))
(add-to-list 'auto-mode-alist '("Guard$" . enh-ruby-mode))
;; (add-to-list 'auto-mode-alist
;; '("\\(?:\\.rb\\|ru\\|rake\\|thor\\|jbuilder\\|gemspec\\|podspec\\|/\\(?:Gem\\|Rake\\|Cap\\|Thor\\|Vagrant\\|Guard\\|Pod\\)file\\)\\'" . enh-ruby-mode))
;; Auto-close paired syntax elements like parens, quotes, when in ruby-mode
;; (require 'ruby-electric)
;; (add-hook 'ruby-mode-hook 'ruby-electric-mode)
;; When folding, take these delimiters into consideration
(add-to-list 'hs-special-modes-alist
'(enh-ruby-mode
"\\(class\\|def\\|do\\|if\\)" "\\(end\\)" "#"
(lambda (arg) (ruby-end-of-block)) nil))
;; Projectile-rails key bindings:
;;
;; M-x projectile-rails-find-model -> C-c r m
;; M-x projectile-rails-find-current-model -> C-c r M
;; M-x projectile-rails-find-current-test -> C-c r T
;;
(use-package projectile-rails
:defer t
:ensure t
:init
(setq projectile-rails-vanilla-command "bin/rails"
projectile-rails-spring-command "bin/spring"
projectile-rails-zeus-command "bin/zeus")
;; (projectile-rails-global-mode))
(add-hook 'projectile-mode-hook 'projectile-rails-on))
(autoload 'inf-ruby-minor-mode "inf-ruby" "Run an inferior Ruby process" t)
(add-hook 'enh-ruby-mode-hook 'inf-ruby-minor-mode)
(add-hook 'compilation-filter-hook 'inf-ruby-auto-enter)
;; Switch the compilation buffer mode with C-x C-q
;; (useful when interacting with a debugger)
(add-hook 'after-init-hook 'inf-ruby-switch-setup)
;; rbenv
;; (use-package rbenv
;; :defer t
;; :ensure t
;; :init
;; (add-to-list 'load-path "~/emacs.d/vendor/rbenv.el")
;; ;; searches for .ruby-version and activates the corresponding ruby
;; (rbenv-use-corresponding)
;; (setq rbenv-modeline-function 'rbenv--modeline-plain) ; remove colors
;; ;; (global-rbenv-mode)
;; (add-hook 'enh-ruby-mode-hook 'global-rbenv-mode))
;; (setq rbenv-show-active-ruby-in-modeline nil)
;; (rbenv-use-global) ; activates global ruby
;; (rbenv-use) ; allows you to choose what ruby version you want to use
;; Optional -- if your RBENV installation is located somewhere besides
;; ~/.rbenv, you will need to configure this:
;;(setq rbenv-installation-dir "/usr/local/rbenv")
;; (use-package bundler)
;; (add-to-list 'load-path "~/.emacs.d/vendor/bundler.el")
;; (add-hook 'ruby-mode-hook 'bundler)
;; Minitest key bindings:
;;
;; M-x minitest-verify -> C-c , v
;; M-x minitest-verify-all -> C-c , a
;; M-x minitest-rerun -> C-c , r
;;
(use-package minitest
:defer t
:ensure t
:init (add-hook 'enh-ruby-mode-hook 'minitest-mode)
:config (minitest-enable-appropriate-mode))
;; Evaluate tests in the current buffer with “C-c C-,”
;; (use-package 'ruby-test-mode)
;; (add-to-list 'load-path "~/.emacs.d/vendor/ruby-test-mode.el")
;; (add-hook 'enh-ruby-mode-hook 'ruby-test-mode)
;; Rubocop keybindings:
;;
;; M-x rubocop-check-project -> C-c C-r p
;; M-x rubocop-check-current-file -> C-c C-r f
;;
;; M-x rubocop-autocorrect-project -> C-c C-r P
;; M-x rubocop-autocorrect-current-file -> C-c C-r F
;;
(use-package rubocop
:defer t :ensure t :init (add-hook 'enh-ruby-mode-hook 'rubocop-mode))
;; This function switches to the new buffer and permits killing it easily with "k":
(add-hook 'compilation-finish-functions
(lambda (new-buffer strg)
(switch-to-buffer-other-window new-buffer)
(read-only-mode)
(goto-char (point-max))
(local-set-key (kbd "k")
(lambda () (interactive) (kill-buffer-and-window))))) ; kills it
;; (lambda () (interactive) (quit-restore-window))))) ; closes window
;; Functions to help with refactoring
;; (require 'ruby-refactor)
;; (add-hook 'enh-ruby-mode-hook 'ruby-refactor-mode-launch)
;; Easily toggle ruby's hash syntax with "M-x ruby-hash-syntax-toggle"
(use-package ruby-hash-syntax :defer t :ensure t)
;; Ruby rdoc helpers mostly
(use-package ruby-additional :defer t :ensure t)
;; Helpers to deal with strings and symbols
(use-package ruby-tools :defer t :ensure t)
;; Support for YARD
;; (require 'yard-mode)
;; (add-hook 'ruby-mode-hook 'yard-mode)
;; Support for running rspec tests
;; (require 'rspec-mode)
;; Ruby buffer interaction
;; (setq seeing-is-believing-prefix "C-.")
;; (add-hook 'ruby-mode-hook 'seeing-is-believing)
;; (require 'seeing-is-believing)
;; rails-minor-mode
;; (add-to-list 'load-path (expand-file-name "~/.emacs.d/rails-minor-mode"))
;; (require 'rails)
(use-package whitespace
:defer t
:ensure t
:init
(setq whitespace-style
'(face empty tabs lines-tail trailing)
whitespace-global-modes
'(not org-mode web-mode fundamental-mode "Web" emacs-lisp-mode)
;; whitespace-line-column 80
whitespace-display-mappings
;; all numbers are Unicode codepoint in decimal. e.g. (insert-char 182 1)
'(
(space-mark nil) ; 32 SPACE, 183 MIDDLE DOT
(newline-mark 10 [172 10]) ; 10 LINE FEED
(tab-mark 9 [9654 9] [92 9])
(tab-mark 9 [183 9] [92 9]) ; 9 TAB, MIDDLE DOT
))
(global-whitespace-mode t))
;; (require 'whitespace-cleanup-mode)
;; (setq whitespace-line-column 80) ;; limit line length
;; (setq whitespace-style '(spaces tabs newline space-mark tab-mark newline-mark face lines-tail))
;; (setq whitespace-style '(newline newline-mark face lines-tail))
;; (setq whitespace-global-modes '(not org-mode web-mode fundamental-mode "Web" emacs-lisp-mode))
;; (global-whitespace-mode)
;; Disable ruby-mode and enh-ruby-mode auto-adding utf-8 magic comments
(setq ruby-insert-encoding-magic-comment nil
enh-ruby-add-encoding-comment-on-save nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Section X: Text mode behavior ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (setq default-major-mode 'text-mode)
(add-hook 'text-mode-hook 'turn-on-auto-fill 'turn-on-visual-line-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Section XI: Other programming languages ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Markdown
(use-package markdown-mode
:defer t
:mode (("\\.markdown\\'" . markdown-mode)
("\\.md\\'" . markdown-mode)
("\\.mmd\\'" . markdown-mode)))
;; Mediawiki
;; (use-package mediawiki-mode
;; :defer t
;; :mode (("\\.mediawiki\\'" . mediawiki-mode)))
;; YAML
(use-package yaml-mode
:defer t
:mode (("\\.yml\\'" . yaml-mode)
("\\.yaml\\'" . yaml-mode)))
;; Gitignore files
(use-package gitignore-mode
:defer t
:mode "\\.gitignore\\'")
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Section X: General behavior ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(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.
'(ansi-color-names-vector
["#0a0814" "#f2241f" "#67b11d" "#b1951d" "#4f97d7" "#a31db1" "#28def0" "#b2b2b2"])
'(company-idle-delay 0)
'(company-minimum-prefix-length 2)
'(company-tooltip-limit 20)
'(custom-enabled-themes '(spacemacs-dark))
'(custom-safe-themes
'("8aebf25556399b58091e533e455dd50a6a9cba958cc4ebb0aab175863c25b9a4" "bffa9739ce0752a37d9b1eee78fc00ba159748f50dc328af4be661484848e476" "5c9bd73de767fa0d0ea71ee2f3ca6fe77261d931c3d4f7cca0734e2a3282f439" default))
'(fci-rule-color "gray71")
'(fci-rule-width 1)
'(fill-column 80)
'(haskell-interactive-popup-errors nil t)
'(hl-todo-keyword-faces
'(("TODO" . "#dc752f")
("NEXT" . "#dc752f")
("THEM" . "#2d9574")
("PROG" . "#4f97d7")
("OKAY" . "#4f97d7")
("DONT" . "#f2241f")
("FAIL" . "#f2241f")
("DONE" . "#86dc2f")
("NOTE" . "#b1951d")
("KLUDGE" . "#b1951d")
("HACK" . "#b1951d")
("TEMP" . "#b1951d")
("FIXME" . "#dc752f")
("XXX+" . "#dc752f")
("\\?\\?\\?+" . "#dc752f")))
'(package-selected-packages
'(nhexl-mode clang-format+ clang-capf mediawiki minimap projectile-ripgrep ripgrep counsel-gtags counsel-etags clang-format gnu-elpa-keyring-update markdown-mode comment-or-uncomment-sexp grizzl enh-ruby-mode popwin ruby-tools rubocop minitest slime flx-ido scpaste smex magit whitespace-cleanup-mode select-themes oceanic-theme projectile projectile-rails seeing-is-believing inf-ruby saveplace))
'(pdf-view-midnight-colors '("#b2b2b2" . "#292b2e"))
'(safe-local-variable-values
'((cmake-ide-build-dir . /build-aux/)
(syntax . common-lisp)
(encoding . utf-8)))
'(show-trailing-whitespace t)
'(typescript-indent-level 2 t))
(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.
)
;; Local Variables:
;; byte-compile-warnings: (not free-vars)
;; End:
;;; emacs ends here