summaryrefslogtreecommitdiff
path: root/config/emacs/site-lisp/my-builtins.el
blob: bc29beb2dd536f3381cbf0d084e6558bf215d22e (plain)
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
;;; Builtin config:  -*- lexical-binding: t; -*-

(use-package server ; allow emacsclient
  :demand t
  :config
  (unless (server-running-p) (server-start)))

(use-package proced ; process editor
  :commands (proced)
  :config
  (setq-default proced-auto-update-flag t)
  (setq-default proced-auto-update-interval 1))

(use-package dabbrev ; dynamic abbreviations
  :demand t
  :config
  (add-to-list 'dabbrev-ignored-buffer-modes 'exwm-mode)
  (add-to-list 'dabbrev-ignored-buffer-modes 'pdf-view-mode)
  (add-to-list 'dabbrev-ignored-buffer-modes 'tags-table-mode)
  (add-to-list 'dabbrev-ignored-buffer-modes 'doc-view-mode))

(progn ; dired directory editor
  (require 'dired)
  (defun dired-do-find-marked-files ()
    (interactive)
    (seq-do 'find-file (dired-get-marked-files)))
  (define-key dired-mode-map (kbd "C-o") 'dired-display-file)
  (define-key dired-mode-map (kbd "F") 'dired-do-find-marked-files))

(use-package ibuffer ; give a nice list of buffers with extra info
  :commands (ibuffer)
  :custom
  (ibuffer-expert t)
  (ibuffer-formats
   '((mark modified read-only " "
           (name 50 50 :left :elide) ; was originally 18
           " "
           (size 9 -1 :right)
           " "
           (mode 16 16 :left :elide)
           " " filename-and-process)
     (mark " "
           (name 16 -1)
           " " filename)))
  :bind
  ("C-x C-b" . ibuffer))

(progn ; isearch search in buffer
  ;; swap basic and regex binds
  (keymap-set global-map "C-s" 'isearch-forward-regexp)
  (keymap-set global-map "C-r" 'isearch-backward-regexp)
  (keymap-set global-map "C-M-s" 'isearch-forward)
  (keymap-set global-map "C-M-r" 'isearch-backward))

(use-package eshell ; emacs shell
  :demand t
  :config
  (use-package esh-help)
  (require 'em-hist)
  (require 'em-term)
  (setup-esh-help-eldoc)
  :bind (:map eshell-mode-map
              ("C-l" . my/eshell-clear-or-center))   ; todo make smarter with centering
  :hook (eshell-mode . eldoc-mode))

(use-package ediff ; emacs interactive diff
  :custom
  (ediff-window-setup-function 'ediff-setup-windows-plain))

(progn ; comint, doesn't play with use-package
  (require 'comint)
  (setq-default comint-scroll-to-bottom-on-input t)
  (setq-default comint-scroll-to-bottom-on-output t)
  (setq-default comint-buffer-maximum-size 1048576)
  (add-to-list 'comint-output-filter-functions #'comint-truncate-buffer)
  (add-to-list 'comint-output-filter-functions #'ansi-color-process-output))

(use-package tramp ; remote access for files
  :demand t
  :custom
  (tramp-allow-unsafe-temporary-files t))

(use-package asm-mode ; asm comments and tags generation
  :demand t
  :custom
  (asm-comment-char ?#) ; prefer # over ; for asm comments
  :init
  (defun add-asm-label-tag-generation-hook ()
    (add-hook 'after-save-hook
              (lambda ()
                (shell-command
                 "find . -iregex '.*\\.[sS]' -exec etags -l none -r '/\\([a-zA-Z0-9\\-_]+\\):/\1/' {} +"))
              0 t))
  :hook
  (asm-mode . 'add-asm-label-tag-generation-hook))

(use-package compile ; compliation buffers and easy bind
  :custom
  (compilation-always-kill t)
  (compilation-scroll-output t)
  :bind (:map my/keys-mode-map ("M-M" . 'recompile))
  :config
  ;; Allow compilation buffer to be dedicated across frames
  (add-to-list 'display-buffer-alist '("\\*compilation\\*" nil (reusable-frames . t)))
  (add-hook 'compilation-filter-hook #'ansi-color-compilation-filter))

(use-package man ; view manuals in emacs
  :custom
  (Man-switches "-a"))

(use-package imenu ; jump to items in the current buffer
  :bind
  ("M-i" . imenu)
  :custom
  (imenu-auto-rescan t)
  (imenu-flatten t))

(use-package xref ; jump to syntactic elements in project
  ;; (add-hook 'xref-backend-functions 'gxref-xref-backend)
  :bind ("M-I" . xref-find-definitions))

(use-package time ; time if I want it in the modeline etc
  :custom
  (display-time-day-and-date t)
  (display-time-24hr-format t))

(use-package battery ; battery in modeline etc
  )

(progn ; indent code when pasting
  (require 'dash)
  (defvar yank-indent-modes '(prog-mode LaTeX-mode TeX-mode)
    "Modes in which to indent regions that are yanked (or yank-popped).")

  (defun yank-indent-func (&optional arg)
    (let* ((parents (derived-mode-all-parents major-mode))
           (helper (lambda (acc v) (or acc (member v yank-indent-modes))))
           (included (-reduce helper parents)))
      (when (and (not arg) included)
        (indent-region (region-beginning) (region-end)))))

  (advice-add 'yank :after 'yank-indent-func)
  (advice-add 'yank-pop :after 'yank-indent-func))

(progn ; better commenting binds
  (global-set-key (kbd "C-x C-;") 'comment-or-uncomment-region)
  (global-set-key (kbd "C-x ;") 'comment-line)
  (global-set-key (kbd "C-x :") 'comment-or-uncomment-region)
  ;; ^ duped for terminal w/o C-;
  )

(progn ; default modeline config additions
  (let ((dir '("" (:eval (let ((str (concat (format " [%s]  " (my/shorten-path default-directory)))))
                           (add-face-text-property
                            0 (length str)
                            '(:weight bold :foreground "green2")
                            t str)
                           str)))))
    (add-to-list 'mode-line-misc-info dir)))

(progn ; comfy scratch buffer
  (require 'iimage)
  (setq inhibit-startup-screen t)
  (setq initial-scratch-message
        (concat (propertize ";; " 'invisible t)
                "</home/tmu/.emacs.d/splashLaputa.png>
;; scratch for lisp evaluation and unsaved text

"))
  (add-hook 'emacs-startup-hook
            (lambda ()
              (with-current-buffer "*scratch*"
                (emacs-lock-mode 'kill)
                (iimage-mode 1)))))

(use-package which-func ; headline
  :custom
  (which-func-display 'header)
  (which-func-modes '(c-mode c++-mode))
  :config
  (set-face-foreground 'which-func "sky-blue")
  (which-function-mode))

(progn ; vc and related binds
  (setq vc-follow-symlinks t)
  (setq vc-dir-allow-mass-mark-changes t)
  (vc-auto-revert-mode 1)
  (add-hook 'prog-mode-hook 'smerge-mode))

(progn ; confirm fewer things
  (setq kill-buffer-query-functions
        (delq 'process-kill-buffer-query-function kill-buffer-query-functions))
  (setq confirm-kill-processes nil)
  (setq async-shell-command-buffer 'new-buffer))

;; misc vars
(setq delete-pair-blink-delay 0
      enable-recursive-minibuffers t
      frame-resize-pixelwise t
      c-guess-region-max 5000)
(electric-pair-mode 1)
(electric-indent-mode 1)