(Emacs)~loads of indenting changes and auto-save changes

This commit is contained in:
2023-06-10 06:24:27 +01:00
parent 8f4018b39f
commit 36d56f9e89

View File

@@ -507,46 +507,45 @@ code.
*** Some binds in Emacs *** Some binds in Emacs
Some bindings that I couldn't fit elsewhere easily. Some bindings that I couldn't fit elsewhere easily.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(use-package emacs (use-package emacs
:straight nil :straight nil
:general :general
(general-def (general-def
"C-x d" #'delete-frame) "C-x d" #'delete-frame)
(nmmap (nmmap
"C--" #'text-scale-decrease "C--" #'text-scale-decrease
"C-=" #'text-scale-increase) "C-=" #'text-scale-increase)
(leader (leader
"SPC" '(execute-extended-command :which-key "M-x") "SPC" '(execute-extended-command :which-key "M-x")
"'" '(browse-url-emacs :which-key "Open url in Emacs") "'" '(browse-url-emacs :which-key "Open url in Emacs")
"u" 'universal-argument ";" 'eval-expression
";" 'eval-expression ":" `(,(proc (interactive) (switch-to-buffer "*scratch*"))
":" `(,(proc (interactive) (switch-to-buffer "*scratch*")) :which-key "Switch to *scratch*")
:which-key "Switch to *scratch*") "!" '(async-shell-command :which-key "Async shell command")
"!" '(async-shell-command :which-key "Async shell command") "h" '(help-command :which-key "Help"))
"h" '(help-command :which-key "Help"))
(mode-leader (mode-leader
"t" #'+oreo/switch-theme) "t" #'+oreo/switch-theme)
(code-leader (code-leader
"F" (list (proc (interactive) (find-file "~/Code/")) ':which-key "Open ~/Code/")) "F" (list (proc (interactive) (find-file "~/Code/")) ':which-key "Open ~/Code/"))
(file-leader (file-leader
"f" #'find-file "f" #'find-file
"F" #'find-file-other-frame "F" #'find-file-other-frame
"s" #'save-buffer "s" #'save-buffer
"p" (list (proc (interactive) (find-file (concat user-emacs-directory "config.org"))) "p" (list (proc (interactive) (find-file (concat user-emacs-directory "config.org")))
':which-key "Open config.org")) ':which-key "Open config.org"))
(quit-leader (quit-leader
"q" #'save-buffers-kill-terminal "q" #'save-buffers-kill-terminal
"c" #'+literate/compile-config "c" #'+literate/compile-config
"l" #'+literate/load-config "l" #'+literate/load-config
"d" #'delete-frame) "d" #'delete-frame)
(search-leader "i" #'imenu)) (search-leader "i" #'imenu))
#+end_src #+end_src
** Evil ** Evil
My editor journey started off with Vim rather than Emacs, so my brain My editor journey started off with Vim rather than Emacs, so my brain
@@ -1118,29 +1117,30 @@ and a Makefile skeleton.
'auto-insert-alist 'auto-insert-alist
'(("Makefile" . "Makefile skeleton") '(("Makefile" . "Makefile skeleton")
"" ""
"CC=g++ "CC=gcc
CFLAGS=-Wall -ggdb CFLAGS=-Wall -ggdb
OBJECTS=main.o OBJECTS=main.o
OUT=main OUT=main
ARGS= ARGS=
%.o: %.cpp %.o: %.c
$(CC) $(CFLAGS) -c $^ -o $@ $(CC) $(CFLAGS) -c $^ -o $@
$(OUT): $(OBJECTS) $(OUT): $(OBJECTS)
$(CC) $(CFLAGS) $^ -o $@ $(CC) $(CFLAGS) $^ -o $@
.PHONY: .PHONY:
clean: clean:
rm -rfv $(OUT) $(OBJECTS) rm -rfv $(OUT) $(OBJECTS)
.PHONY: run .PHONY: run
run: $(OUT) run: $(OUT)
./$^ $(ARGS) ./$^ $(ARGS)
.PHONY: memcheck .PHONY: memcheck
memcheck: $(OUT) memcheck: $(OUT)
sh /etc/profile.d/debuginfod.sh && valgrind --leak-check=full -s --tool=memcheck ./$^ $(ARGS)" sh /etc/profile.d/debuginfod.sh && valgrind --leak-check=full -s --tool=memcheck ./$^ $(ARGS)"
_))) _)))
#+end_src #+end_src
*** Yasnippet default *** Yasnippet default
@@ -1610,9 +1610,9 @@ integrate it into my workflow just a bit better.
(when (eq beg end) (when (eq beg end)
(notmuch-search-next-thread))) (notmuch-search-next-thread)))
(advice-add #'notmuch-poll-and-refresh-this-buffer :before (advice-add #'notmuch-poll-and-refresh-this-buffer :before
#'+mail/sync-mail) #'+mail/sync-mail)
(advice-add #'notmuch-poll-and-refresh-this-buffer :after (advice-add #'notmuch-poll-and-refresh-this-buffer :after
#'+mail/trash-junk) #'+mail/trash-junk)
(with-eval-after-load "evil-collection" (with-eval-after-load "evil-collection"
(evil-collection-notmuch-setup))) (evil-collection-notmuch-setup)))
#+end_src #+end_src
@@ -2238,7 +2238,7 @@ would be describing changes...
(setq undo-tree-auto-save-history t) (setq undo-tree-auto-save-history t)
:general :general
(leader (leader
"U" #'undo-tree-visualize)) "u" #'undo-tree-visualize))
#+end_src #+end_src
*** Whitespace *** Whitespace
Deleting whitespace, highlighting when going beyond the 80th character Deleting whitespace, highlighting when going beyond the 80th character
@@ -2372,6 +2372,9 @@ and when I don't.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(use-package flycheck (use-package flycheck
:commands (flycheck-mode flycheck-list-errors) :commands (flycheck-mode flycheck-list-errors)
:hook
(c-mode-hook . flycheck-mode)
(c++-mode-hook . flycheck-mode)
:general :general
(mode-leader (mode-leader
"f" #'flycheck-mode) "f" #'flycheck-mode)
@@ -2907,6 +2910,13 @@ Setup for C and C++ modes via the cc-mode package. C and C++ are
great languages for general purpose programming. My preferred choice great languages for general purpose programming. My preferred choice
when I want greater control over memory management. when I want greater control over memory management.
*** cc-mode *** cc-mode
Tons of stuff, namely:
+ ~auto-fill-mode~ for 80 char limit
+ Some keybindings to make evil statement movement is easy
+ Lots of pretty symbols
+ Indenting options and a nice (for me) code style for C (though
aggressive indent screws with this a bit)
+ Auto inserts to get a C file going
#+begin_src emacs-lisp #+begin_src emacs-lisp
(use-package cc-mode (use-package cc-mode
:defer t :defer t
@@ -2954,25 +2964,24 @@ when I want greater control over memory management.
(setq-default c-default-style '((other . "user"))) (setq-default c-default-style '((other . "user")))
(with-eval-after-load "autoinsert" (with-eval-after-load "autoinsert"
(define-auto-insert (let ((skeleton
'("\\.c\\'" . "C skeleton") '(""
'("" "/* " (file-name-nondirectory (buffer-file-name (current-buffer))) "\n"
"/* " (file-name-nondirectory (buffer-file-name (current-buffer))) "\n" " * Created: " (format-time-string "%Y-%m-%d") "\n"
" * Created: " (format-time-string "%Y-%m-%d") "\n" " * Author: " user-full-name "\n"
" * Author: " user-full-name "\n" " */\n"
" */\n" "#include <stdio.h>\n"
"\n" "#include <stdlib.h>\n"
_)) "#include <malloc.h>\n"
"#include <string.h>\n"
(define-auto-insert "\n"
'("\\.cpp\\'" . "C++ skeleton") _)))
'("" (define-auto-insert
"/* " (file-name-nondirectory (buffer-file-name (current-buffer))) "\n" '("\\.c\\'" . "C skeleton")
" * Created: " (format-time-string "%Y-%m-%d") "\n" skeleton)
" * Author: " user-full-name "\n" (define-auto-insert
" */\n" '("\\.cpp\\'" . "C++ skeleton")
"\n" skeleton)))
_)))
:config :config
(c-add-style (c-add-style
"user" "user"
@@ -3002,22 +3011,24 @@ format [[file:~/Dotfiles/ClangFormat/.clang-format][config file]] in my dotfiles
:straight nil :straight nil
:load-path "/usr/share/clang/" :load-path "/usr/share/clang/"
:after cc-mode :after cc-mode
:commands (+code/clang-format-region-or-buffer) :commands (+code/clang-format-region-or-buffer
clang-format-mode)
:hook
(c-mode-hook . clang-format-mode)
(c++-mode-hook . clang-format-mode)
:general :general
(code-leader (code-leader
:keymaps '(c-mode-map c++-mode-map) :keymaps '(c-mode-map c++-mode-map)
"f" #'+code/clang-format-region-or-buffer) "f" #'+code/clang-format-region-or-buffer)
:config :config
(defvar +code/clang-format-automatically t (define-minor-mode clang-format-mode
"Automatically call clang-format every time save occurs in C/C++ "On save formats the current buffer via clang-format."
buffer") :lighter nil
(let ((save-func (proc (interactive)
(+oreo/create-auto-save (clang-format-buffer))))
(and +code/clang-format-automatically (if clang-format-mode
(or (eq major-mode 'c-mode) (add-hook 'after-save-hook save-func nil t)
(eq major-mode 'c++-mode))) (remove-hook 'after-save-hook save-func t))))
(clang-format-buffer))
(defun +code/clang-format-region-or-buffer () (defun +code/clang-format-region-or-buffer ()
(interactive) (interactive)
(if (mark) (if (mark)
@@ -3268,6 +3279,8 @@ development on Emacs.
sly-mrepl sly-mrepl
nil) nil)
:general :general
(shell-leader
"s" #'+shell/toggle-sly)
(nmap (nmap
:keymaps '(lisp-mode-map sly-mrepl-mode-map) :keymaps '(lisp-mode-map sly-mrepl-mode-map)
"gr" #'sly-eval-buffer "gr" #'sly-eval-buffer