-
Notifications
You must be signed in to change notification settings - Fork 0
/
work-emacs
588 lines (516 loc) · 19.7 KB
/
work-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
;; -*- mode: emacs-lisp -*-
(when (< emacs-major-version 27)
(package-initialize))
(setq-default inhibit-startup-message 't
tool-bar-mode nil
scroll-margin 0
scroll-preserve-screen-position nil
cursor-in-non-selected-windows nil)
; 💩 pile of happy poo
; 💣 bomb emoji
; nerd font git branch
(setq default-frame-alist '((font-backend . "xft")
;; (font . "DejaVu Sans Mono-9")
;; (font . "Inconsolata-11")
(font . "IBM Plex Mono-10")
;; (font . "BlexMono Nerd Font Mono-10")
(vertical-scroll-bars . right)
(scroll-bar-width . 12)
(tool-bar-lines . 0)))
; Noto as fallback font
(set-fontset-font "fontset-default" nil
(font-spec :size 11 :name "Noto Color Emoji"))
;; no toolbar, no menu for me
(tool-bar-mode -1)
(menu-bar-mode -1)
(set-scroll-bar-mode 'right)
;; Set Zmacs mode (highlight marked text)
(transient-mark-mode t)
;; parentheses
(show-paren-mode t)
(setq parens-require-spaces nil)
(setq show-paren-style 'expression)
;; Show Row and Column
(line-number-mode t)
(column-number-mode t)
;; always make a backup~ (except for VCd files)
(setq backup-inhibited nil)
(setq make-backup-files t)
;; no more "command attempted to use minibuffer while in minibuffer"
(setq enable-recursive-minibuffers t)
;; save history of minibuffer between sessions
(savehist-mode 1)
(setq history-length 1000)
(prefer-coding-system 'utf-8)
(delete-selection-mode -1)
(blink-cursor-mode nil)
(setq shift-select-mode nil
save-interprogram-paste-before-kill t
mouse-yank-at-point t
inhibit-startup-screen nil
diff-switches '("-u" "-w")
ediff-split-window-function 'split-window-horizontally
ediff-merge-split-window-function 'split-window-horizontally
fill-column 72
search-whitespace-regexp nil)
(defun move-line-up ()
"Move up the current line."
(interactive)
(transpose-lines 1)
(forward-line -2)
(indent-according-to-mode))
(defun move-line-down ()
"Move down the current line."
(interactive)
(forward-line 1)
(transpose-lines 1)
(forward-line -1)
(indent-according-to-mode))
(global-set-key [(meta shift up)] 'move-line-up)
(global-set-key [(meta shift down)] 'move-line-down)
;; MUST BE BEFORE ANY REQUIRE ETC.
;; load the newer file of .el / .elc
(setq load-prefer-newer t)
(require 'cl)
(require 'hippie-exp)
;; custom keybindings
(global-unset-key (kbd "C-x f"))
(global-unset-key "\C-x\C-k") ; disable macro keymap
;(global-set-key "\C-x\C-k" 'kill-buffer)
(global-set-key [C-tab] 'other-window)
(global-set-key [XF86Save] 'save-buffer)
(global-set-key (kbd "C-x O") (lambda () (interactive) (other-window -1)))
(global-set-key "\M-g" 'goto-line)
(global-set-key "\M-E" 'hippie-expand) ; for the Mac
(global-set-key "\C-cf" 'ag-project)
(global-set-key [(super e)] 'hippie-expand)
(global-set-key [(super s)] 'isearch-forward-regexp)
(global-set-key [(hyper <)] 'end-of-buffer)
(global-set-key [(super r)] (lambda () (interactive) (revert-buffer nil t)))
(global-set-key [S-iso-lefttab] (lambda () (interactive) (let ((indent-tabs-mode t)) (insert-tab))))
(global-set-key (kbd "C-c C-SPC") 'delete-horizontal-space)
(global-set-key [(hyper .)] 'xref-find-definitions-other-window)
(global-set-key [C-M-backspace] 'backward-kill-sexp) ; WARNING: by default this kills the X server!!
(global-set-key "[" 'insert-pair)
(global-set-key "\"" 'insert-pair)
(global-set-key "\M-'" 'insert-pair)
(global-set-key "(" 'insert-parentheses)
(global-set-key (kbd "C-M-z") 'kill-backward-up-list)
(global-set-key "\M-_" 'align-regexp)
(global-set-key (kbd "<f9>") 'compile)
(global-set-key (kbd "C-c \"")
(lambda (arg)
(interactive "P")
(if arg (setq arg (prefix-numeric-value arg))
(setq arg 0))
(insert-pair arg ?„ ?“)))
(global-set-key [M-menu] 'eval-expression)
(global-unset-key [f11]) ; use M-x toogle-frame-fullscreen instead
;; M-% = query-replace
;; M-& = query-replace-regexp
(global-set-key "\M-&" 'query-replace-regexp)
;; Non-nil means `query-replace' should preserve case in replacements.
(setq case-replace nil)
;;; Various indentation settings
(setq-default c-basic-offset 4)
(setq-default tab-width 4)
(setq-default indent-tabs-mode nil)
(setq-default tab-always-indent t)
(setq-default truncate-lines nil)
(electric-indent-mode -1)
;; start server for emacsclient ()
;; (server-start)
(setq server-visit-hook 'raise-frame)
(setq gnuserv-frame (selected-frame))
;; maximum font lock
(require 'font-lock)
;; (require 'lazy-lock)
;; (setq font-lock-support-mode '((php-mode . lazy-lock-mode) (t . jit-lock-mode)))
(setq font-lock-support-mode 'jit-lock-mode)
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)
;; change buffer naming strategy from file<2> to file:dir/dir
(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward
uniquify-separator ":")
;;; Set up load-path
(add-to-list 'load-path "~/.emacs.d/libs/")
(let ((default-directory "~/.emacs.d/libs/"))
(normal-top-level-add-subdirs-to-load-path))
;; Mac stuff
(when (eq system-type 'darwin)
(when (memq window-system '(mac ns))
(require 'exec-path-from-shell)
(exec-path-from-shell-initialize))
;; Allow alt-n on the mac to produce [],|,{}, etc
;; (has to be done after after modifying load-path)
(setq mac-command-modifier 'meta
mac-option-modifier nil))
;;: this function is buggy and doesn't work as a hook for php-mode
;;; messes with font-lock somehow
(defun ees/find-local-tags-file ()
"When the current `tags-file-name' is nil or isn't in a parent
directory of the current `buffer-file-name', locate a valid TAGS
file in a parent directory and make it the buffer local
`tags-file-name'"
(when (and buffer-file-name
(or (not tags-file-name)
(not (string-prefix-p
(file-name-directory (file-truename tags-file-name))
(file-truename buffer-file-name)))))
(let* ((tags-dir (locate-dominating-file default-directory "TAGS"))
(tags-file (and tags-dir (file-truename (concat tags-dir "TAGS")))))
(when (and tags-file (save-excursion (tags-verify-table tags-file)))
(visit-tags-table tags-file t)))))
;; always start a new list of tags tables
(setq tags-add-tables nil)
(require 'xref)
(defun ees/mouse-xref (click)
"Call xref-find-definitions with a mouse event"
(interactive "e")
(with-selected-window (posn-window (event-start click))
(save-excursion
(goto-char (posn-point (event-start click)))
(call-interactively #'xref-find-definitions))))
(add-to-list 'xref-prompt-for-identifier 'ees/mouse-xref t)
(global-set-key [(hyper mouse-1)] 'ees/mouse-xref)
;;; Set up major/minor-modes
;(require 'elisp-slime-nav)
;(dolist (hook '(emacs-lisp-mode-hook ielm-mode-hook))
; (add-hook hook 'elisp-slime-nav-mode))
;;; Tramp
(setq tramp-default-method "ssh")
;;; Abbrev
;; ensure abbrev mode is always on
(setq-default abbrev-mode t)
;; do not bug me about saving my abbreviations
(setq save-abbrevs nil)
;;; C Modes
(add-hook 'c-mode-common-hook
(lambda ()
(c-set-offset 'case-label '+) ; case n: is indented
(c-set-offset 'substatement-open 0)
(c-set-offset 'cpp-macro 0)
(c-set-offset 'arglist-intro '+)
;; funktion um else/if ( => ++, sonst => + zu erwirken
(c-set-offset 'arglist-cont-nonempty '+)))
(setq c-default-style
'((java-mode . "java")
(awk-mode . "awk")
(c-mode . "bsd")
(other . "gnu")))
;;; Packaging
(require 'package)
;; (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/"))
(use-package which-key
:ensure t
:defer t
:config (which-key-mode 1))
(use-package js2-mode
:ensure t)
;; js2-mode rebinds this to some debugging aid instead of
;; mouse-set-point and thus C-s begins a region
;;(define-key js2-mode-map [mouse-1] nil)
(use-package auto-complete
:ensure t
:config (ac-config-default))
(use-package yasnippet
:ensure t)
(use-package yatemplate
:ensure t
:after (yasnippet))
(use-package markdown-mode
:ensure t)
(use-package magit
:ensure t
:config (progn
(setq magit-revert-buffers nil
magit-push-always-verify nil
magit-last-seen-setup-instructions "1.4.0"
magit-diff-paint-whitespace t
magit-diff-refine-hunk t
magit-diff-highlight-trailing t
magit-diff-hide-trailing-cr-characters nil
magit-log-arguments (quote ("-n256" "--graph" "--decorate"))
magit-diff-options (quote ("--ignore-all-space"))
magit-log-margin (quote (t "%Y-%m-%d %H:%M " magit-log-margin-width t 18))
magit-section-initial-visibility-alist (quote ((stashes . hide) (status . show)))
magit-status-initial-section (quote (((unpushed . "@{upstream}..") (status)) 1)))
(magit-auto-revert-mode nil)
(require 'magit-extras)
(put 'magit-diff-edit-hunk-commit 'disabled nil))
:bind (("C-x g" . 'magit-status)
:map magit-mode-map
("C-c t" . ees/magit-edit-note-at-point)))
(defun ees/magit-edit-note-at-point ()
(interactive)
(magit-notes-edit (magit-branch-or-commit-at-point)))
;; (use-package forge
;; :after magit)
;;; PHP
(use-package phpunit
:ensure t)
(use-package php-mode
:ensure t
;; php-mode appends, this prepends to avoid conf-mode
:mode ("\\.php\\(\\.dist\\)?\\'" . php-mode)
:config (setq php-template-compatibility nil
php-lineup-cascaded-calls nil
php-mode-warn-if-mumamo-off "Don't warn"
php-search-url nil
php-manual-url 'en
;; php-mode-coding-style 'default
php-search-documentation-browser-function 'eww-browse-url
php-mode-coding-style 'psr2) ;; what about psr12?
:bind (:map php-mode-map
("'" . 'insert-pair)
("(" . 'insert-parentheses)
("C-c C-d" . 'php-search-documentation)
("<f10>" . 'php-debug-file)
("C-c C-y" . 'yas/create-php-snippet)
("C-c t t" . 'phpunit-current-test)
("C-c t c" . 'phpunit-current-class))
:hook ((php-mode . (lambda ()
(yas-minor-mode 1)
(ees/find-local-tags-file)))))
(use-package php-auto-yasnippets
:ensure t
:after (yasnippet autocomplete php-mode)
:config (payas/ac-setup))
;;; PHP debugger
;; (use-package geben
;; :ensure t
;; :config (setq geben-source-coding-system 'latin-9))
;;; Flycheck
(defun ees/ignore-flycheck-risky (orig-fun sym &optional _ignored)
"Ignore that setting flycheck-php-executable locally is risky"
(if (eq sym 'flycheck-php-executable)
nil
(apply orig-fun (list sym _ignored))))
(use-package flycheck
:ensure t
:commands flycheck-mode
:hook (php-mode . flycheck-mode)
:config (progn
(setq flycheck-php-phpmd-executable "~/.composer/vendor/bin/phpmd"
flycheck-php-phpcs-executable "~/.composer/vendor/bin/phpcs"
flycheck-phpcs-standard "PSR12")
;; not necessary when var & val are added to safe-local-variable-values
;(advice-add 'risky-local-variable-p :around #'ees/ignore-flycheck-risky)
))
(use-package dired-git-info
:ensure t
:bind (:map dired-mode-map (")" . dired-git-info-mode)))
(use-package diredfl
:ensure t
:config (diredfl-global-mode))
;; Docker stuff
(use-package docke-tramp)
(use-package dockerfile-mode)
;;; SQL Mode
(setq sql-product 'mysql)
(add-hook 'sql-mode-hook
(lambda ()
(sql-highlight-mysql-keywords)))
;;; Hide-Show
(require 'hideshow)
(add-to-list 'hs-special-modes-alist
'(php-mode "{" "}" "/[*/]" nil hs-c-like-adjust-block-beginning))
(define-key hs-minor-mode-map [(super c)] 'hs-toggle-hiding)
(define-key hs-minor-mode-map (kbd "C-c q C-c") 'hs-toggle-hiding)
(define-key hs-minor-mode-map (kbd "C-c q C-l") 'hs-hide-level)
(define-key hs-minor-mode-map (kbd "C-c q C-M-s") 'hs-show-all)
;;; org mode
(require 'org)
(add-hook 'org-mode-hook 'visual-line-mode)
(defun org-summary-todo (n-done n-not-done)
"Switch entry to DONE when all subentries are done, to TODO otherwise."
(let (org-log-done org-log-states) ; turn off logging
(org-todo (if (= n-not-done 0) "DONE" "TODO"))))
(add-hook 'org-after-todo-statistics-hook 'org-summary-todo)
(setq org-fontify-done-headline t)
(setq org-enforce-todo-dependencies t)
(setq org-agenda-todo-list-sublevels nil) ; only top-level todos in agenda
(setq org-log-done 'time)
(setq org-descriptive-links t) ; show literal links, nicer for tex citation
(define-key org-mode-map (kbd "<mouse-6>") 'outline-previous-visible-heading)
(define-key org-mode-map (kbd "<mouse-7>") 'outline-next-visible-heading)
(define-key org-mode-map (kbd "C-<mouse-6>") 'outline-up-heading)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cl" 'org-store-link)
;; Org LaTeX setup
(setq org-latex-default-packages-alist
'(("" "fontspec" t)
("" "xunicode" t)
("" "url" t)
("xetex,hidelinks" "hyperref" nil) ; hidelinks not in this version
("" "fixltx2e" nil)
("" "graphicx" t)
("" "longtable" nil)
("" "float" nil)
("" "wrapfig" nil)
("" "soul" t)
("" "changes" t)
("babel" "csquotes" t)
"\\tolerance=1000"))
(setq org-latex-pdf-process '("latexmk -xelatex -bibtex-cond -f %f" "latexmk -xelatex -bibtex-cond -f -c %f"))
(defun ees/org-sort-todo-list ()
"Sort buffer in alphabetical order, then priority, then by TODO."
(interactive)
(save-excursion
(mark-whole-buffer)
(org-sort-entries nil ?a)
(org-sort-entries nil ?p)
(org-sort-entries nil ?O))
(org-overview))
;;; RFCview
(add-to-list 'auto-mode-alist
'("/\\(rfc\\|std\\)[0-9]+\\.txt\\'" . rfcview-mode))
(autoload 'rfcview-mode "rfcview" nil t)
;;; ack - better than grep
(autoload 'ack-same "full-ack" nil t)
(autoload 'ack "full-ack" nil t)
(autoload 'ack-find-same-file "full-ack" nil t)
(autoload 'ack-find-file "full-ack" nil t)
;;; ag even better than ack
(setq ag-highlight-search t)
;;; LUA
(autoload 'lua-mode "lua-mode" "Lua editing mode." t)
(add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode))
(add-to-list 'interpreter-mode-alist '("lua" . lua-mode))
(setq lua-indent-level 2) ; because that's easier ingame
;;; TeX
(setq tex-run-command "xetex")
(setq latex-run-command "xelatex")
;;; Projekt Mode
(require 'projekt)
;; smerge - merging conflicts made easy
(autoload 'smerge-mode "smerge-mode" nil t)
(defun sm-try-smerge ()
(save-excursion
(goto-char (point-min))
(when (re-search-forward "^<<<<<<< " nil t)
(smerge-mode 1))))
(add-hook 'find-file-hook 'sm-try-smerge t)
;;; Markdown
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdown files" t)
(autoload 'gfm-mode "markdown-mode"
"Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.text\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("README\\.md\\'" . gfm-mode))
;;; My own simple functions
;;; aka kleine Helferlein
(defun kill-whitespace ()
"Kills whitespace at the end of a line in the buffer"
(interactive)
(push-mark)
(goto-char (point-min))
(let ((eol (coding-system-eol-type buffer-file-coding-system)))
(if (and (numberp eol) (= 0 eol))
(replace-regexp "[ \t\r]+$" "") ; eliminate CR in unix files
(replace-regexp "[ \t]+$" "")))
(set-mark-command t)
(set-mark-command t))
(global-set-key "\C-cw" 'kill-whitespace)
(defun insert-curly (arg)
"Like insert-parenthesis, nah, it does indenting and doesn't move over
words but lines"
(interactive "P")
(if arg (setq arg (prefix-numeric-value arg))
(setq arg 0))
(cond ((> arg 0) (skip-chars-forward " \t"))
((< arg 0) (forward-sexp arg) (setq arg (- arg))))
(insert "{")
(let ((point (point)))
(save-excursion
(or (eq arg 0) (forward-line (1+ arg)))
;; (and (eq arg 0) (insert "\n"))
(insert "}\n")
(indent-region point (+ 1 (point)) nil)
(backward-char -2))))
(global-set-key "\M-{" 'insert-curly)
(defun toggle-line-comment ()
(interactive)
(save-excursion
(beginning-of-line)
(let ((beg (point)))
(end-of-line)
(comment-or-uncomment-region beg (point)))))
(global-set-key [?\C-7] 'toggle-line-comment)
(defun insert-buffer-name ()
(interactive)
(insert (buffer-name)))
(defun insert-buffer-file-name ()
(interactive)
(insert (buffer-file-name)))
(defun kill-buffer-and-delete-frame ()
(interactive)
(when (kill-buffer)
(delete-frame)))
(global-set-key (kbd "C-x 5 k") 'kill-buffer-and-delete-frame)
;; erm something to read...
(defun jargon ()
(interactive)
(find-file "~/doc/jargon-1.5.0.dos.txt"))
(defun explorer (alt)
"Open file browser window at the buffers current directory."
(interactive "P")
(let ((dir default-directory))
(case window-system
('w32 (w32-shell-execute "open" "explorer" (concat "/e,/select," dir)))
('ns (shell-command (format "open %s" dir) nil))
('x (if alt
(dired dir)
(call-process "x-terminal-emulator" nil 0 nil))))))
;(setq Info-dir-contents nil) ;; to reset & reread info dirs
;;; LOAD custom libraries
(let ((host-file (format "~/.emacs.d/%s.el" system-name)))
(when (file-exists-p host-file)
(load-file host-file)))
;;; Stuff that emacs modifies herself
(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.
'(variable-pitch ((t (:family "IBM Plex Mono")))))
(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.
'(css-indent-level 2)
'(css-indent-offset 2)
'(custom-safe-themes
(quote
("b9a06c75084a7744b8a38cb48bc987de10d68f0317697ccbd894b2d0aca06d2b" "26d49386a2036df7ccbe802a06a759031e4455f07bda559dcf221f53e8850e69" default)))
'(js2-allow-keywords-as-property-names nil)
'(js2-highlight-level 3)
'(js2-use-font-lock-faces t)
'(keyboard-coding-system (quote iso-8859-1))
'(magit-status-initial-section (quote (2)))
'(package-selected-packages
(quote
(dockerfile-mode forge composer php-runtime company-phpactor transient magit-extras diredfl dired-git-info geben flycheck-plantuml plantuml-mode yasnippet-snippets which-key markdown-mode php-auto-yasnippets yatemplate moe-theme php-mode flycheck flycheck-phpstan use-package powerline yasnippet auto-complete js2-mode docker-tramp magit phpunit ag)))
'(safe-local-variable-values
(quote
((flycheck-php-executable . "php-dev_suite_1")
(flycheck-php-executable . "php-localhost")
(org-confirm-babel-evaluate)
(buffer-file-coding-system . latin-9)
(Syntax . COMMON-LISP)
(Package . CL-USER)
(Base . 10)
(sql-product . mysql)
(c-basic-indent . 4)
(mule-coding . latin-9)
(c-basic-indent . 2))))
'(tramp-syntax (quote default) nil (tramp)))
(put 'narrow-to-region 'disabled nil)
(put 'scroll-left 'disabled nil)
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)