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