-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path.emacs
More file actions
159 lines (129 loc) · 6.29 KB
/
.emacs
File metadata and controls
159 lines (129 loc) · 6.29 KB
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
(menu-bar-mode -1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
(setq inhibit-startup-screen t)
(add-to-list 'default-frame-alist '(fullscreen . maximized))
(load-theme 'wombat)
(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.
'(default-text-scale-amount 16)
'(default-text-scale-mode t nil (default-text-scale))
'(display-fill-column-indicator-column 80)
'(markdown-command "pandoc --from markdown --to html5 --mathjax --standalone")
'(org-support-shift-select t)
'(package-selected-packages
'(auctex auctex-latexmk clang-format cmake-font-lock cmake-mode
default-text-scale dockerfile-mode ejson-mode
exec-path-from-shell go-mode impatient-mode
latex-preview-pane magit markdown-mode org-modern
pdf-tools rust-mode)))
(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.
)
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;; Comment/uncomment this line to enable MELPA Stable if desired. See `package-archive-priorities`
;; and `package-pinned-packages`. Most users will not need or want to do this.
(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
;; (add-to-list 'package-archives
;; '("melpa-stable" . "https://stable.melpa.org/packages/"))
(package-initialize)
;; (package-refresh-contents)
;; (require 'rust-mode)
(setq-default indent-tabs-mode nil)
(define-key global-map (kbd "C-x O") 'previous-window-any-frame)
(add-hook 'c++-mode-hook 'hs-minor-mode)
;; (add-hook 'c++-mode-hook 'lsp)
;; (add-hook 'c-mode-hook 'lsp)
;; zoom at startup, was 113 by default
(set-face-attribute 'default nil :height 240)
;; zoom in/out is global, via CM=, CM-, CM0 (last resets)
(require 'default-text-scale)
(default-text-scale-mode 1)
;; thanks chatgpt
(defun my/org-latex-scale-and-render ()
"Save the buffer, set Org LaTeX previews to match current text scale, then re-render."
(interactive)
;; 1) Save the current buffer
(save-buffer)
;; 2) Derive a scale factor from the current `default` face height
(let ((new-scale (/ (float (face-attribute 'default :height nil)) 100.0)))
(setq org-format-latex-options
(plist-put org-format-latex-options :scale new-scale)))
;; ;; 3) Re-render all LaTeX in the buffer; `t` forces image regeneration
;; (org-latex-preview (point-min) (point-max) t))
(org-latex-preview '(64))
(org-latex-preview '(16)))
(with-eval-after-load 'org
(define-key org-mode-map (kbd "M-1") #'my/org-latex-scale-and-render))
;; (with-eval-after-load 'org
;; (define-key org-mode-map (kbd "M-2") #'org-clear-latex-preview))
(with-eval-after-load 'org
(defun my/org-clear-latex-preview (&optional beg end)
"Interactive wrapper around `org-clear-latex-preview'.
Removes LaTeX preview overlays in region or entire buffer."
(interactive "r")
;; If `org-clear-latex-preview' is missing or non-interactive,
;; you may see an error here. Upgrade Org or define a fallback.
(org-clear-latex-preview beg end))
;; Now bind our interactive wrapper to C-c C-x C-r in Org buffers
(define-key org-mode-map (kbd "M-2") #'my/org-clear-latex-preview))
;; ─── ~/.emacs or ~/.config/emacs/init.el ───
(require 'clang-format) ; make sure the function exists first
(defun my-clang-format-and-save ()
"Format the current buffer with clang-format, then save it."
(interactive)
(clang-format-buffer)
(save-buffer))
;; ;; *** place this near the very end of your init ***
;; (global-set-key (kbd "M-1") #'my-clang-format-and-save)
;; (add-hook 'c-mode-common-hook
;; (lambda ()
;; (local-set-key (kbd "M-1") #'my-clang-format-and-save)))
(add-hook 'c++-mode-hook ; runs when a C++ buffer starts
(lambda ()
(local-set-key (kbd "M-1")
#'my-clang-format-and-save)))
;; save temporaries in ~/.emacs.d/auto-save/ instead alongside
(setq auto-save-file-name-transforms
`((".*" ,(concat user-emacs-directory "auto-save/") t)))
;; (require 'whitespace)
;; (setq whitespace-line-column 80) ;; limit line length
;; (setq whitespace-style '(face lines-tail))
;; (add-hook 'prog-mode-hook 'whitespace-mode)
;; (setq-default indent-tabs-mode t)
;; (setq-default tab-width 8) ; Assuming you want your tabs to be four spaces wide
;; (defvaralias 'c-basic-offset 'tab-width)
;; https://stackoverflow.com/questions/151945/how-do-i-control-how-emacs-makes-backup-files/18330742#18330742
(defvar --backup-directory (concat user-emacs-directory "backups"))
(if (not (file-exists-p --backup-directory))
(make-directory --backup-directory t))
(setq backup-directory-alist `(("." . ,--backup-directory)))
(setq make-backup-files t ; backup of a file the first time it is saved.
backup-by-copying t ; don't clobber symlinks
version-control t ; version numbers for backup files
delete-old-versions t ; delete excess backup files silently
delete-by-moving-to-trash t
kept-old-versions 6 ; oldest versions to keep when a new numbered backup is made (default: 2)
kept-new-versions 9 ; newest versions to keep when a new numbered backup is made (default: 2)
auto-save-default t ; auto-save every buffer that visits a file
auto-save-timeout 20 ; number of seconds idle time before auto-save (default: 30)
auto-save-interval 200 ; number of keystrokes between auto-saves (default: 300)
)
;; (prefer-coding-system 'utf-8)
;; (set-default-coding-systems 'utf-8)
;; (setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
;; (setq default-buffer-file-coding-system 'utf-8)
;; (set-selection-coding-system 'utf-8)
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(define-coding-system-alias 'UTF-8 'utf-8)