-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot-emacs
930 lines (775 loc) · 32.1 KB
/
dot-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
;; Copyright (C) 2025 Björn A. Lindqvist <bjourne@gmail.com>
;;
;; The idea is to replace the contents of .emacs with
;;
;; (load-file "~/pubwork/ConfigurationFiles/dot-emacs")
;;
(require 'cl)
(setq is-windows (string-equal system-type "windows-nt"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; XDG config
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq config-base "~/.config/emacs/")
(setq user-emacs-directory (concat config-base "lisp/"))
(setq package-user-dir (concat config-base "packages/"))
;; Must call this
(require 'package)
(package-initialize)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Startup config
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq inhibit-startup-message t)
(setq inhibit-splash-screen t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Frame customization -- widget removal
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(menu-bar-mode -1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
(setq frame-title-format "%b")
(setq icon-title-format frame-title-format)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; frame splitting
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; I prefer to split side-by-side rather than on top and below.
;; TODO: code here
(defun split-window-sensibly-prefer-horiz (&optional window)
(let ((window (or window (selected-window))))
(or (and (window-splittable-p window t)
;; Split window horizontally
(with-selected-window window
(split-window-right)))
(and (window-splittable-p window)
;; Split window vertically
(with-selected-window window
(split-window-below)))
(and
;; If WINDOW is the only usable window on its frame (it is
;; the only one or, not being the only one, all the other
;; ones are dedicated) and is not the minibuffer window, try
;; to split it horizontally disregarding the value of
;; `split-height-threshold'.
(let ((frame (window-frame window)))
(or
(eq window (frame-root-window frame))
(catch 'done
(walk-window-tree (lambda (w)
(unless (or (eq w window)
(window-dedicated-p w))
(throw 'done nil)))
frame)
t)))
(not (window-minibuffer-p window))
(let ((split-width-threshold 0))
(when (window-splittable-p window t)
(with-selected-window window
(split-window-right))))))))
(defun split-window-really-sensibly (&optional win)
(let ((win (or win (selected-window))))
(if (> (window-total-width win) (* 2 (window-total-height win)))
(with-selected-window win (split-window-sensibly-prefer-horiz win))
(with-selected-window win (split-window-sensibly win)))))
(setq
split-height-threshold 80
split-width-threshold 160
split-window-preferred-function 'split-window-really-sensibly)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; dired customization
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'dired-x)
(add-hook 'dired-load-hook
(function (lambda () (load "dired-x"))))
;; This shouldn't work on Windows
(setq dired-listing-switches "-al --group-directories-first")
(setf dired-kill-when-opening-new-dired-buffer t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ido!
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq ido-enable-flex-matching t)
(setq ido-everywhere t)
(ido-mode t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; org-mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq org-src-fontify-natively t
org-export-htmlize-output-type 'css)
(setq org-log-done t)
(setq-default org-display-custom-times t)
(setq org-time-stamp-custom-formats '("<%Y-%m-%d>" . "<%Y-%m-%d %H:%M>"))
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; geiser
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(when is-windows
(setq geiser-racket-binary "C:/Program Files (x86)/Racket/Racket.exe"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Improved fill-paragraph
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun toggle-fill-paragraph ()
(interactive)
(let ((pre (thing-at-point 'line))
(old-fill fill-column))
(fill-paragraph)
(when (string= (thing-at-point 'line) pre)
(setq-local fill-column 99999)
(fill-paragraph)
(setq-local fill-column old-fill))))
(global-set-key "\M-q" 'toggle-fill-paragraph)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Improved move to beginning of line
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun smarter-move-beginning-of-line (arg)
"Move point back to indentation of beginning of line.
Move point to the first non-whitespace character on this line.
If point is already there, move to the beginning of the line.
Effectively toggle between the first non-whitespace character and
the beginning of the line.
If ARG is not nil or 1, move forward ARG - 1 lines first. If
point reaches the beginning or end of the buffer, stop there."
(interactive "^p")
(setq arg (or arg 1))
;; Move lines first
(when (/= arg 1)
(let ((line-move-visual nil))
(forward-line (1- arg))))
(let ((orig-point (point)))
(back-to-indentation)
(when (= orig-point (point))
(move-beginning-of-line 1))))
(global-set-key [remap move-beginning-of-line]
'smarter-move-beginning-of-line)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; OS specific configuration.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if is-windows
(progn (setq default-directory "C:\\")
(add-to-list 'load-path "C:\\.emacs.d\\my-packages\\")
(setq exec-path
(append exec-path '("C:/Program Files (x86)/Git/bin")))
;;(setenv "HOME" (concat (getenv "HOMEDRIVE") (getenv "HOMEPATH")))
(setenv "GIT_ASKPASS" "git-gui--askpass"))
(progn (add-to-list 'load-path (expand-file-name "~/.config/emacs/"))))
(defmacro with-library (symbol &rest body)
`(condition-case nil
(progn
(require ', symbol)
,@body)
(error
(message (format "I guess we don't have %s available." ',symbol))
nil)))
(put 'with-library 'lisp-indent-function 1)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Package management
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; NXML
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'auto-mode-alist
(cons (concat "\\." (regexp-opt '("xml" "xsd") t) "\\'")
'nxml-mode))
(setq magic-mode-alist
(cons '("<\\?xml " . nxml-mode)
magic-mode-alist))
(fset 'xml-mode 'nxml-mode)
(fset 'html-mode 'nxml-mode)
;; Customizing
(add-hook 'nxml-mode-hook
'(lambda()
(set-face-foreground
'nxml-attribute-local-name-face "#bb6600")
(set-face-foreground
'nxml-processing-instruction-delimiter-face "purple")
(set-face-foreground
'nxml-processing-instruction-target-face "purple")
(set-face-foreground
'nxml-attribute-value-delimiter-face "RosyBrown")
(set-face-foreground
'nxml-attribute-value-face "RosyBrown")))
(defun config-auto-modes ()
"Setup lots of modes based on extensions."
(add-to-list 'auto-mode-alist '("samba\\.conf\\'" . samba-generic-mode))
(add-to-list 'auto-mode-alist '("smb\\.conf" . samba-generic-mode))
(add-to-list 'auto-mode-alist '("70-install-asterisk" . cfengine-mode))
(add-to-list 'auto-mode-alist '("access\\.conf\\'" . apache-mode))
(add-to-list 'auto-mode-alist '("apache2\\.conf\\'" . apache-mode))
(add-to-list 'auto-mode-alist '("httpd\\.conf\\'" . apache-mode))
(add-to-list 'auto-mode-alist
'("sites-\\(available\\|enabled\\)/" . apache-mode))
(add-to-list 'auto-mode-alist '("srm\\.conf\\'" . apache-mode))
(add-to-list 'auto-mode-alist '(".htaccess" . apache-mode))
(add-to-list 'auto-mode-alist '("\\.css\\'" . css-mode))
(add-to-list 'auto-mode-alist '("extensions\\.conf\\'" . conf-windows-mode))
)
(defun config-css-mode ()
(with-library css-mode
(setq cssm-mirror-mode nil)
(setq cssm-indent-function #'cssm-c-style-indenter)
(setq cssm-indent-level 4)))
(defun config-global-keybindings ()
;; Set some keyboard shortcuts
(global-set-key "\M-g" 'goto-line)
(global-set-key [f9] 'compile)
(global-set-key (kbd "M-<return>") 'complete-tag)
;; Dabbrev stuff
(global-set-key (kbd "M-SPC") 'hippie-expand)
;; comment-dwim on C-c c
(global-set-key (kbd "C-c c") 'comment-dwim)
;; Move fast between buffers. These pretty useful commands aren't
;; bound to anything by default.
(global-set-key (kbd "s-n") 'next-buffer)
(global-set-key (kbd "s-p") 'previous-buffer)
;; Basic stuff
(global-set-key "\C-z" 'undo)
(global-set-key "\C-?" 'backward-delete-char-untabify)
(global-set-key [delete] 'delete-horizontal-space-forward)
(global-set-key (kbd "C-c m") 'rename-file-and-buffer)
;; Move between windows
(windmove-default-keybindings)
;; Ibuffer
(global-set-key (kbd "C-x C-b") 'ibuffer))
(defun config-auto-insert-mode ()
(require 'autoinsert)
(auto-insert-mode)
(setq auto-insert-directory "~/.site-lisp/templates/")
(setq auto-insert-query nil)
(define-auto-insert "\.py" "python-template.py"))
(defun config-session ()
(with-library session
(add-hook 'after-init-hook 'session-initialize)))
(defun config-powershell-mode()
(with-library powershell-mode
(add-to-list 'auto-mode-alist '("\\.ps1\\'" . powershell-mode))
(add-to-list 'auto-mode-alist '("\\.psm1\\'" . powershell-mode))))
(config-auto-insert-mode)
;; This library is new in emacs 22 I think and gives me lots of
;; goodies. etc-fstab-generic-mode for example!
(load-library "generic-x")
;; Mouse wheel
(mouse-wheel-mode t)
;; Minor modes I like
(column-number-mode t)
;; Setup tab-stop-list
(setq tab-stop-list
(let ((i 4) list)
(while (< i 80)
(setq list (cons i list))
(setq i (+ i 4)))
(reverse list)))
;; Make text selections visible
(transient-mark-mode t)
;; Make it so yanked text is placed in xorg's clipboard buffer.
(setq x-select-enable-clipboard t)
(config-auto-modes)
;; Make it so tab indents in sgml-mode
(require 'sgml-mode)
(define-key sgml-mode-map "\t" 'tab-to-tab-stop)
;; emacs-lisp-mode
(define-key emacs-lisp-mode-map "\C-t" 'lisp-complete-symbol)
(with-library apache-mode)
(config-css-mode)
(config-powershell-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; verilog-mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'verilog-mode)
(setq verilog-auto-endcomments nil)
(setq verilog-auto-lineup nil)
(setq verilog-cexp-indent 4)
(setq verilog-indent-begin-after-if nil)
(setq verilog-indent-level 4)
(setq verilog-indent-level-declaration 4)
(setq verilog-indent-level-module 4)
(setq verilog-indent-lists nil)
(define-key verilog-mode-map [delete] nil)
(define-key verilog-mode-map [backspace] nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Typescript
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-ts-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; C-mode, Java, etc.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'cc-mode)
(setq tab-width 2)
(setq-default indent-tabs-mode nil)
(setq c-basic-offset 4)
(mapcar
(lambda (x)
(let* ((mode (car x))
(exts (cdr x))
(rx (concat "\\." (regexp-opt (append exts nil)) "\\'")))
(add-to-list 'auto-mode-alist
`(,rx . ,mode))
))
'((c++-mode . ["h" "cuh" "cu"])
(c-mode . ["cl"])))
(defun my-c-initialization-hook ()
(c-set-offset 'substatement-open 0)
(c-set-offset 'arglist-intro '+)
(c-set-offset 'innamespace [0])
(c-set-offset 'arglist-close 0)
(c-set-offset 'cpp-macro 0)
;;(c-set-offset 'bracelist-open 0)
;;(c-set-style "my-cc-style")
(define-key c-mode-base-map (kbd "C-c C-d") nil)
(define-key c-mode-base-map (kbd "C-c C-d C-d") 'man-follow))
(add-hook 'c-mode-common-hook 'my-c-initialization-hook)
(add-hook 'java-mode-hook (lambda ()
(c-set-offset 'arglist-close 0)
(c-set-offset 'arglist-intro '+)
(c-set-offset 'class-close -1)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; c-ts-mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Preprocessor directives are annoying.
(defun my-c-ts-indent-style ()
(let ((ofs c-ts-mode-indent-offset)
(half-ofs (/ c-ts-mode-indent-offset 2)))
`(
;; Always put these at col 0
((parent-is "translation_unit") column-0 0)
;; Don't indent function names
((node-is "function_declarator") column-0 0)
;; Preprocessor directives
((node-is "preproc_arg") column-0 ,ofs)
((node-is "preproc") column-0 0)
((node-is "#endif") column-0 0)
;; Like "retract"
((node-is ")") parent-bol 0)
((node-is "}") standalone-parent 0)
((parent-is "\\`declaration\\'") parent-bol 0)
;; Body
((parent-is "compound_statement") standalone-parent ,ofs)
;; Stupid hack for preprocessor
((n-p-gp nil "preproc" "compound_statement") standalone-parent ,ofs)
;; Magic stuff
(c-ts-mode--for-each-tail-body-matcher prev-line ,ofs)
(c-ts-mode--else-heuristic prev-line ,ofs)
;; This rule matches foo = \\nblah.
((parent-is "assignment_expression") parent-bol ,ofs)
;; Tertiary exprs
((node-is ":") (nth-sibling 1) 0)
;; Switch/case
((node-is "case") standalone-parent 0)
((parent-is "case_statement") standalone-parent ,ofs)
;; Goto labels
((node-is "labeled_statement") standalone-parent ,half-ofs)
;; For statements
((query "(for_statement initializer: (_) @indent)") parent-bol 5)
((query "(for_statement condition: (_) @indent)") parent-bol 5)
((query "(for_statement update: (_) @indent)") parent-bol 5)
;; If statements
((node-is "else") parent-bol 0)
((parent-is "if_statement") standalone-parent ,ofs)
((parent-is "else_clause") standalone-parent ,ofs)
;; While
((parent-is "while_statement") standalone-parent ,ofs)
;; Multi-line strings
((parent-is "concatenated_string") first-sibling 0)
;; Linup indentation or one-level indentation
((match nil "enumerator_list" nil 0 1) parent-bol ,ofs)
((match nil "enumerator_list" nil 2 nil) (nth-sibling 1) 0)
((match nil "parameter_list" nil 0 1) parent-bol ,ofs)
((match nil "parameter_list" nil 2 nil) (nth-sibling 1) 0)
((match nil "argument_list" nil 0 1) parent-bol ,ofs)
((match nil "argument_list" nil 2 nil) (nth-sibling 1) 0)
((match nil "initializer_list" nil 0 1) parent-bol ,ofs)
((match nil "initializer_list" nil 2 nil) (nth-sibling 1) 0)
((match nil "field_declaration_list" nil 0 1) parent-bol ,ofs)
((match nil "field_declaration_list" nil 2 nil) (nth-sibling 1) 0)
((match nil "parenthesized_expression" nil 0 1) parent-bol ,ofs)
((match nil "parenthesized_expression" nil 2 nil) (nth-sibling 1) 0)
;; IDK
((parent-is "binary_expression") parent 0)
)
)
)
(when (fboundp 'use-package)
(use-package c-ts-mode
:if (treesit-language-available-p 'c)
:custom
(c-ts-mode-indent-offset 4)
(c-ts-mode-indent-style #'my-c-ts-indent-style)
:init
;; Remap the standard C/C++ modes
(add-to-list 'major-mode-remap-alist
'(c-mode . c-ts-mode))
(add-to-list 'major-mode-remap-alist
'(c++-mode . c++-ts-mode))
(add-to-list 'major-mode-remap-alist
'(c-or-c++-mode . c-or-c++-ts-mode))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Auto saving backups. Stupid retarted emacs defaults. Why so angry?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar saves-dir (expand-file-name "~/.local/state/emacs/"))
(setq backup-by-copying t)
(setq backup-directory-alist `((".*" . ,saves-dir)))
(setq auto-save-default t)
(setq auto-save-list-file-prefix (concat saves-dir "save-"))
(setq auto-save-file-name-transforms `((".*" ,saves-dir t)))
(setq delete-old-versions nil)
(setq kept-new-versions 6)
(setq kept-old-versions 2)
; use versioned backups
(setq version-control t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Better editing
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq kill-whole-line t)
(setq backward-delete-char-untabify-method 'all)
(defun copy-buffer-file-path()
(interactive "*")
(kill-new buffer-file-name))
(defun delete-horizontal-space-forward()
(interactive "*")
(setq first-point (point))
(setq next-point (progn (skip-chars-forward " \t\n") (point)))
(if (eq first-point next-point)
(delete-char 1)
(delete-region first-point next-point))
)
(defun config-jinja2-mode ()
(with-library jinja2-mode ()))
;; End files with newlines
(setq require-final-newline t)
(setq next-line-add-newlines nil)
;; Makes it so the pointer returns to the position it was in last time
;; the file was open.
(require 'saveplace)
(setq-default save-place t)
(config-session)
(config-jinja2-mode)
;; Better uniquify
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
(defun rename-file-and-buffer (new-name)
"Renames both current buffer and file it's visiting to NEW-NAME."
(interactive "FMove to file: ")
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not filename)
(message "Buffer '%s' is not visiting a file!" name)
(if (get-buffer new-name)
(message "A buffer named '%s' already exists!" new-name)
(progn
(rename-file name new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil))))))
(defun pretty-print-xml-region (begin end)
"Pretty format XML markup in region. You need to have nxml-mode
http://www.emacswiki.org/cgi-bin/wiki/NxmlMode installed to do
this. The function inserts linebreaks to separate tags that have
nothing but whitespace between them. It then indents the markup
by using nxml's indentation rules."
(interactive "r")
(save-excursion
(goto-char begin)
(while (search-forward-regexp "\>[ \\t]*\<" nil t)
(backward-char) (insert "\n"))
(indent-region begin end))
(message "Ah, much better!"))
;; Graphviz-mode
(with-library graphviz-dot-mode)
;; Keybindings
(config-global-keybindings)
;; Improves performance on Windows
(setq w32-get-true-file-attributes nil)
;; Jade, Sws and Stylus modes
(with-library sws-mode)
(with-library jade-mode
(add-to-list 'auto-mode-alist '("\\.jade$" . jade-mode)))
(with-library stylus-mode
(add-to-list 'auto-mode-alist '("\\.styl$" . stylus-mode)))
(setq read-buffer-completion-ignore-case t)
(setq read-file-name-completion-ignore-case t)
(put 'downcase-region 'disabled nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ace-jump-mode, provisional. Not sure I like it yet
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(autoload
'ace-jump-mode
"ace-jump-mode"
"Emacs quick move minor mode"
t)
(define-key global-map (kbd "C-c ö") 'ace-jump-mode)
(autoload
'ace-jump-mode-pop-mark
"ace-jump-mode"
"Ace jump back:-)"
t)
(eval-after-load "ace-jump-mode"
'(ace-jump-mode-enable-mark-sync))
(define-key global-map (kbd "C-c å") 'ace-jump-mode-pop-mark)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Strip trailing whitespace on save
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Personal details
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Setup personal info. This is to make ChangeLog mode work
(setq user-mail-address "bjourne@gmail.com")
(setq user-full-name "Björn Lindqvist")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Magit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package magit
:ensure t
:init
(setq magit-last-seen-setup-instructions "1.4.0"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Shell
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'auto-mode-alist '("\\.conf$" . sh-mode))
(add-to-list 'auto-mode-alist '("\\.zsh$" . sh-mode))
(add-to-list 'auto-mode-alist '("\\(/\\|\\`\\)zshrc$" . sh-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Elisp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'auto-mode-alist '("dot-emacs$" . emacs-lisp-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Python
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun my-run-python (cmd &optional dedicated show)
(interactive "P")
(run-python cmd dedicated show)
(switch-to-buffer-other-window "*Python*"))
(require 'python)
(define-key python-mode-map "\C-c\C-p" 'my-run-python)
(setq python-shell-interpreter "python")
(defun nagy-python-style()
"This mode is used for waf code."
(interactive)
(setq python-indent 4)
(setq tab-width 4)
(setq indent-tabs-mode t))
;; Many auto mode alists
(add-to-list 'auto-mode-alist
'("SConstruct\\|SConscript\\|wscript\\|wscript_build"
. python-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; YAML
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; HTML mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'auto-mode-alist '("\\.kid\\'" . html-mode))
(add-to-list 'auto-mode-alist '("\\.tmpl\\'" . html-mode))
;; Setup html-mode
(define-key html-mode-map "\t" 'indent-according-to-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Javascript
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(autoload 'javascript-mode "javascript" nil t)
(add-to-list 'auto-mode-alist '("\\.js\\'" . javascript-mode))
(add-to-list 'auto-mode-alist '("\\.json\\'" . javascript-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Prolog
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'auto-mode-alist '("\\.pl\\'" . prolog-mode))
(setq prolog-indent-width 4)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CoffeeScript
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(with-library coffee-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Haskell
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Markdown
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'markdown-mode)
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(setq markdown-italic-underscore nil)
(custom-set-faces
'(markdown-code-face ((t (:inherit nil)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; VHDL
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'vhdl-mode)
(setq vhdl-basic-offset 4)
(vhdl-set-offset 'arglist-close 0)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Octave
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'octave)
(add-to-list 'auto-mode-alist '("\\.m$" . octave-mode))
(define-key octave-mode-map (kbd "C-c C-z") 'run-octave)
(setq inferior-octave-prompt-read-only t)
(setq octave-block-offset 4)
;; https://emacs.stackexchange.com/questions/15164/commented-lines-shoot-off-to-column-32-in-octave-mode
(setq octave-mode-hook
(lambda() (progn
(defun octave-indent-comment ()
"A function for `smie-indent-functions' (which see)."
(save-excursion
(back-to-indentation)
(cond
((octave-in-string-or-comment-p) nil)
((looking-at-p "\\(\\s<\\)\\1\\{2,\\}") 0)))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; grep - highlight matches
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Had to hack vc-git.el to add --color=always to the git grep command.
(require 'grep)
(require 'vc)
(defun my-vc-git-grep ()
(interactive)
(vc-git-grep (grep-read-regexp) "*" (vc-git-root default-directory))
(other-window 1))
(global-set-key (kbd "C-c g") 'my-vc-git-grep)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Persistent scratch
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun save-persistent-scratch ()
(with-current-buffer (get-buffer "*scratch*")
(write-region (point-min) (point-max)
(concat config-base "scratch"))))
(defun load-persistent-scratch ()
(if (file-exists-p (concat config-base "scratch"))
(with-current-buffer (get-buffer "*scratch*")
(delete-region (point-min) (point-max))
(insert-file (concat config-base "scratch")))))
(load-persistent-scratch)
(push #'save-persistent-scratch kill-emacs-hook)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Spelling
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(when is-windows
(add-to-list 'exec-path "C:/Program Files (x86)/Aspell/bin/")
(setq ispell-personal-dictionary "~/.ispell")
(setq ispell-program-name "aspell")
(require 'ispell))
;; Emacs spell-checking is unusable. :(
;; (add-hook 'text-mode-hook 'flyspell-mode)
(setq flyspell-issue-message-flag nil)
(defface ispell-alpha-num-choice-face
'((t (:background "black" :foreground "red")))
"Face for `ispell-alpha-num-choice-face`."
:group 'ispell)
(defface ispell-text-choice-face
'((t (:background "black" :foreground "forestgreen")))
"Face for `ispell-text-choice-face`."
:group 'ispell)
(defun set-language (code name)
(let* ((dir (expand-file-name "~/.config/aspell/"))
(pd (concat dir code ".pws"))
(rd (concat dir code ".prepl")))
(make-directory dir t)
(setq ispell-personal-dictionary pd)
(setq ispell-extra-args (list "--repl" rd)))
(ispell-change-dictionary code)
(flyspell-buffer)
(message (format "Switched to %s" name)))
;; This nice code comes from https://stackoverflow.com/questions/27544869/how-do-i-change-ispell-private-dictionary
(defun my-ispell-change-dictionaries ()
"Switch between language dictionaries."
(interactive)
(let ((choice (read-char-exclusive (concat
"["
(propertize "E" 'face 'ispell-alpha-num-choice-face)
"]"
(propertize "nglish" 'face 'ispell-text-choice-face)
" | ["
(propertize "S" 'face 'ispell-alpha-num-choice-face)
"]"
(propertize "venska" 'face 'ispell-text-choice-face)))))
(cond
((eq choice ?E)
(set-language "en" "English"))
((eq choice ?S)
(set-language "sv" "Svenska"))
(t (message "No changes have been made."))) ))
;; Keybinding to cycle between languages.
(add-hook 'flyspell-mode-hook
(lambda ()
(set-language "en" "English")
(local-set-key (kbd "C-c l") 'my-ispell-change-dictionaries)
(local-set-key (kbd "C-c a") 'flyspell-correct-word-before-point)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Theme, fonts and faces.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Helper functions to make it easier to select the right
;; customization for a particular computer.
(defun read-proc-cpuinfo ()
(with-temp-buffer
(insert-file-contents "/proc/cpuinfo")
(when (re-search-forward "^model name[\t\s]*: \\(.*\\)$" nil t)
(match-string 1))))
(defun device-identity ()
(cond
((file-readable-p "/proc/cpuinfo")
(read-proc-cpuinfo))
;; Fallback to host name if /proc/cpuinfo can't be read.
(t (system-name))))
;; Inconsolata with italic and bold variants:
;; https://github.com/MihailJP/Inconsolata-LGC
;; Comic Mono:
;; https://github.com/dtinth/comic-mono-font
;; Monaco:
;; https://github.com/mps/fonts/blob/master/MONACO.TTF
(setq-local device-configs
'(
("Intel(R) Core(TM) Ultra 9 185H" .
("Inconsolata LGC 12"
"~/"
["p/ConfigurationFiles/dot-emacs"
"p/ConfigurationFiles/zshrc"]))
("Intel(R) Xeon(R) W-2245 CPU @ 3.90GHz" .
("Monaco 23" "~/" ["p/ConfigurationFiles/dot-emacs"
"p/ConfigurationFiles/zshrc"]))
("unknown" .
("Inconsolata LGC 15" "~/" []))
)
)
(setq-local device-config
(cdr (assoc (device-identity) device-configs)))
(setq-local device-font (nth 0 device-config))
(setq-local device-auto-open-root (nth 1 device-config))
(setq-local device-auto-open-files (nth 2 device-config))
;; Theme, possibly a different init should be used on windows.
(global-font-lock-mode t)
;; Stop unnecessary warnings
(setq custom-safe-themes t)
(defun gui-theme ()
(set-face-attribute 'default nil
:font device-font)
(when (string= (device-identity) "Intel(R) Core(TM) Ultra 9 185H")
(progn (load-theme 'solarized-dark)
(setq-default line-spacing 8)))
(when (string= (device-identity) "Intel(R) Xeon(R) W-2245 CPU @ 3.90GHz")
(setq-default line-spacing 4))
)
(defun console-theme ()
(custom-set-faces
'(font-lock-comment-face ((t (:foreground "black" :weight bold))))
'(font-lock-constant-face ((t (:foreground "magenta" :weight bold))))
'(font-lock-keyword-face ((t (:foreground "magenta"))))
'(font-lock-preprocessor-face ((t (:foreground "red"))))
'(font-lock-string-face ((t (:foreground "yellow"))))
'(font-lock-type-face ((t (:foreground "cyan"))))
'(font-lock-variable-name-face
((t (:foreground "cyan" :weight bold))))))
(if (display-graphic-p)
(gui-theme)
(console-theme))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Frame configuration
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; It's better to use the -mm parameter
;;(when is-windows (w32-send-sys-command 61488))
(setq frame-resize-pixelwise t)
(toggle-frame-fullscreen)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Open some files automatically
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(mapcar
'find-file
(mapcar (lambda (x) (concat device-auto-open-root x))
device-auto-open-files))
(server-start)