doom-emacs-config/config.el

499 lines
15 KiB
EmacsLisp
Raw Normal View History

2023-08-02 23:38:31 +02:00
;;; $DOOMDIR/config.el -*- lexical-binding: t; -*-
;;;; Misc settings
2023-08-28 07:35:48 +02:00
;; start Emacs as a server process
(server-start)
2023-08-20 22:45:21 +02:00
(setq doom-user-dir "~/sync/doom/")
(after! projectile
(setq projectile-project-root-files-bottom-up
(remove ".git" projectile-project-root-files-bottom-up)))
;; This sets the frame dimensions and position take up the right half
;; of the screen when the host is default.ravenwatch, which has an
;; ultra-wide monitor.
2024-03-29 15:58:00 +01:00
(when (string= (system-name) "ravenwatch")
2023-08-10 03:02:01 +02:00
(setq default-frame-alist
'((height . 55)
2023-08-10 03:02:01 +02:00
(width . 154)
(left . 1720)
(top . 0)
(vertical-scroll-bars . nil)
(horizontal-scroll-bars . nil))))
;; This sets the frame to be fullscreen and maximized when the host is
;; default.evergloam, which is my 15-inch screen laptop.
2024-03-29 15:58:00 +01:00
(when (string= (system-name) "evergloam")
2023-08-10 03:02:01 +02:00
(add-to-list 'default-frame-alist '(fullscreen . maximized)))
2023-08-11 04:44:56 +02:00
;; Set fonts
(setq fontsize 18)
2023-08-11 04:44:56 +02:00
(setq monofontfam "JetBrainsMono Nerd Font Mono")
(setq doom-font (font-spec :family monofontfam :size fontsize)
doom-variable-pitch-font (font-spec :family monofontfam :size fontsize)
doom-symbol-font (font-spec :family monofontfam :size fontsize)
2023-08-11 04:44:56 +02:00
doom-big-font (font-spec :family monofontfam :size fontsize))
2023-08-02 23:38:31 +02:00
;; Use catppuccin-mocha theme
(setq doom-theme 'catppuccin)
(setq catppuccin-flavor 'mocha)
2023-08-28 07:35:48 +02:00
;; Backups
(setq backup-directory-alist '(("." . "~/sync/emacs/backups")))
(with-eval-after-load 'tramp
(add-to-list 'tramp-backup-directory-alist
(cons tramp-file-name-regexp nil)))
(setq delete-old-versions -1)
(setq version-control t)
(setq vc-make-backup-files t)
(setq auto-save-file-name-transforms '((".*" "~/sync/emacs/auto-save-list/" t)))
;; History
(setq savehist-file "~/sync/emacs/savehist")
(savehist-mode 1)
(setq history-length t)
(setq history-delete-duplicates t)
(setq savehist-save-minibuffer-history 1)
(setq savehist-additional-variables
'(kill-ring
search-ring
regexp-search-ring))
;; Display time in the modeline
(display-time-mode 1)
;; Sentences end with a single space because it's right and proper
(setq sentence-end-double-space nil)
2023-08-02 23:38:31 +02:00
;; This determines the style of line numbers in effect. If set to `nil', line
;; numbers are disabled. For relative line numbers, set this to `relative'.
(setq display-line-numbers-type 'relative)
;; Make vterm open in another window
(setq vterm-other-window 1)
;; Keybinding to kill-whole-line
(global-set-key (kbd "M-9") 'kill-whole-line)
2023-08-28 07:35:48 +02:00
;; trim newline from string output
(defun string-trim-final-newline (string)
"Trim the last newline character from string.
Used with `shell-command-to-string'.
Source: https://emacs.stackexchange.com/a/21906"
(let ((len (length string)))
(cond
((and (> len 0) (eql (aref string (- len 1)) ?\n))
(substring string 0 (- len 1)))
(t string))))
;; wrapper around `shell-command-to-string' to remove newline
(defun shell-command-output-string (command)
(string-trim-final-newline (shell-command-to-string command)))
2023-08-02 23:38:31 +02:00
;; Copy all or text selection
(defun xah-copy-all-or-region ()
2023-10-14 00:26:17 +02:00
"Put the whole buffer content to `kill-ring', or text selection if there's one.
2023-08-02 23:38:31 +02:00
Respects `narrow-to-region'.
URL `https://ergomacs.org/emacs/emacs_copy_cut_all_or_region.html'
Version 2015-08-22"
2023-10-14 00:26:17 +02:00
(interactive)
(if (use-region-p)
(progn
(kill-new (buffer-substring (region-beginning) (region-end)))
(message "Text selection copied."))
(progn
(kill-new (buffer-string))
(message "Buffer content copied."))))
2023-08-02 23:38:31 +02:00
;; Cut all or text selection
(defun xah-cut-all-or-region ()
2023-10-14 00:26:17 +02:00
"Cut the whole buffer content to `kill-ring', or text selection if there's one.
2023-08-02 23:38:31 +02:00
Respects `narrow-to-region'.
URL `https://ergomacs.org/emacs/emacs_copy_cut_all_or_region.html'
Version 2015-08-22"
2023-10-14 00:26:17 +02:00
(interactive)
(if (use-region-p)
(progn
(kill-new (buffer-substring (region-beginning) (region-end)))
(delete-region (region-beginning) (region-end)))
(progn
(kill-new (buffer-string))
(delete-region (point-min) (point-max)))))
;; open URL in Firefox/LibreWolf
2024-03-29 15:58:00 +01:00
(defun browse-host-web (url)
2023-10-14 00:26:17 +02:00
"Browse URL with Firefox/LibreWolf"
(interactive "sURL: ")
2024-03-29 15:58:00 +01:00
(shell-command (concat "firefox " url)))
2023-10-14 00:26:17 +02:00
(setq browse-url-browser-function 'browse-host-web)
2023-08-02 23:38:31 +02:00
;; after copy Ctrl+c in Linux X11, you can paste by `yank' in emacs
(setq select-enable-clipboard t)
;; after mouse selection copy in X11, you can paste by `yank' in emacs
(setq select-enable-primary t)
;; set keybinding for paste
(global-set-key (kbd "C-S-V") #'clipboard-yank)
;; Smart home key
(defun smart-beginning-of-line ()
2023-10-14 00:26:17 +02:00
"Move point to first non-whitespace character or beginning-of-line.
2023-08-02 23:38:31 +02:00
Move point to the first non-whitespace character on this line.
If point was already at that position, move point to beginning of line."
2023-10-14 00:26:17 +02:00
(interactive "^")
(let ((oldpos (point)))
(back-to-indentation)
(and (= oldpos (point))
(beginning-of-line))))
2023-08-02 23:38:31 +02:00
(global-set-key (kbd "<home>") 'smart-beginning-of-line)
(global-set-key (kbd "<end>") 'end-of-line)
;; Autoformat on save
(setq +format-on-save-enabled-modes
2023-10-14 00:26:17 +02:00
'(emacs-lisp-mode
python-mode))
2023-08-02 23:38:31 +02:00
2023-08-28 07:35:48 +02:00
;; UTF-8
(prefer-coding-system 'utf-8)
(when (display-graphic-p)
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)))
;;;; undo-tree-mode - visualize undos and branches
(global-undo-tree-mode)
(setq undo-tree-visualizer-timestamps t)
(setq undo-tree-visualizer-diff t)
(setq undo-tree-history-directory-alist '(("." . "~/sync/emacs/backups/undo-tree")))
2023-08-02 23:38:31 +02:00
2023-08-10 03:02:01 +02:00
;;;; evil-nerd-commenter
2023-08-02 23:38:31 +02:00
(global-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines)
(global-set-key (kbd "C-c l") 'evilnc-quick-comment-or-uncomment-to-the-line)
(global-set-key (kbd "C-c c") 'evilnc-copy-and-comment-lines)
(global-set-key (kbd "C-c p") 'evilnc-comment-or-uncomment-paragraphs)
2023-08-10 03:02:01 +02:00
;;;; org-mode
2023-08-11 04:44:56 +02:00
(add-hook 'org-mode-hook (lambda () (org-superstar-mode 1)))
2023-08-28 07:35:48 +02:00
(require 'org-protocol)
2023-08-02 23:38:31 +02:00
2023-08-11 04:44:56 +02:00
(setq org-modules '(org-agenda
2023-08-02 23:38:31 +02:00
org-annotate-file
2023-08-11 04:44:56 +02:00
org-choose
2023-08-02 23:38:31 +02:00
org-collector
))
(eval-after-load 'org
'(org-load-modules-maybe t))
(setq org-directory "~/sync/org/")
2023-08-28 07:35:48 +02:00
(setq org-default-notes-file "~/sync/org/inbox.org")
2023-09-15 23:00:22 +02:00
(setq org-agenda-files '("~/sync/org/inbox.org"))
2023-08-02 23:38:31 +02:00
;; support selecting lines by using shift
(setq org-support-shift-select t)
;; org-mode tags
2024-03-29 15:58:00 +01:00
;; I hardly use these but whatever
2023-09-03 11:05:53 +02:00
(setq org-tag-alist (quote (("@archiving" .?a)
2023-10-14 00:26:17 +02:00
("@calendar" .?t)
2023-09-15 23:00:22 +02:00
("@config" . ?c)
2023-10-14 00:26:17 +02:00
("@devel" . ?d)
2023-09-03 11:05:53 +02:00
("@errand" . ?e)
2023-08-02 23:38:31 +02:00
("@fedora" . ?f)
2023-09-03 11:05:53 +02:00
("@homelab" . ?l)
("@homemaking" . ?m)
("@journal" . ?j)
("@log" . ?w)
("@reading" . ?r)
("@selfcare" . ?s))))
2023-08-02 23:38:31 +02:00
;; org-mode keybindings
(with-eval-after-load 'org
2023-08-10 03:02:01 +02:00
(bind-key "C-c $" 'org-archive-subtree)
2023-08-02 23:38:31 +02:00
(bind-key "C-c r" 'org-capture)
(bind-key "C-c R" 'org-roam-capture)
(bind-key "C-c a" 'org-agenda)
(bind-key "C-c l" 'org-store-link)
(bind-key "C-c L" 'org-insert-link-global)
(bind-key "C-c O" 'org-open-at-point-global))
(setq org-use-effective-time t)
;; org-refile
(setq org-reverse-note-order t) ; new notes prepended
(setq org-refile-use-outline-path 'file)
(setq org-outline-path-complete-in-steps nil)
(setq org-refile-allow-creating-parent-nodes 'confirm)
(setq org-refile-use-cache nil)
(setq org-blank-before-new-entry '((heading . t) (plain-list-item . t)))
(setq org-refile-targets
`((("~/sync/org/inbox.org"
2024-03-29 15:58:00 +01:00
"~/sync/org/computing.org"
"~/sync/org/todos.org")
. (:maxlevel . 5))))
2023-08-02 23:38:31 +02:00
;; org-todo-keywords
(with-eval-after-load 'org
(setq org-todo-keywords
'((sequence
"STARTED(s)"
"TODO(t)"
"WAITING(w@/!)"
"IDEA(i)"
2023-08-11 04:44:56 +02:00
"SOMEDAY(.)"
"BLOCKED(k@/!)"
"|"
"DONE(x!)"
"CANCELLED(c)")
2023-08-02 23:38:31 +02:00
(sequence "PROJECT" "|" "DONE(x)")
2023-08-11 04:44:56 +02:00
(sequence "MAYBE(,0)" "CHOSEN(c,+)" "|" "REJECTED")))
2023-08-02 23:38:31 +02:00
2023-08-11 04:44:56 +02:00
;; catppuccin palette
2023-08-02 23:38:31 +02:00
(setq org-todo-keyword-faces
2023-08-11 04:44:56 +02:00
'(("STARTED" . (:foreground "#a6d189" :weight bold))
("TODO" . (:foreground "#a6e3a1" :weight bold))
("WAITING" . (:foreground "#f9e2af" :weight bold))
2023-08-02 23:38:31 +02:00
("IDEA" . (:foreground "#74c7ec" :weight bold))
2023-08-11 04:44:56 +02:00
("SOMEDAY" . (:foreground "#f2cdcd" :weight bold))
("BLOCKED" . (:foreground "#c6d0f5" :weight bold))
2023-08-02 23:38:31 +02:00
("DONE" . (:foreground "#f38ba8" :weight bold))
2023-08-11 04:44:56 +02:00
("CANCELLED" . (:foreground "#e78284" :weight bold))
("MAYBE" . (:foreground "#c6d0f5" :weight bold))
("CHOSEN" . (:foreground "#89b4fa" :weight bold))
("REJECTED" . (:foreground "#d20f39" :weight bold)))))
2023-08-02 23:38:31 +02:00
(setq org-log-done 'time)
2023-09-03 11:05:53 +02:00
(setq org-popup-calendar-for-date-prompt nil)
2023-08-02 23:38:31 +02:00
2023-08-28 07:35:48 +02:00
;; org-roam
2023-08-02 23:38:31 +02:00
(setq org-roam-directory "~/sync/org-roam")
(org-roam-db-autosync-mode)
2023-08-10 03:02:01 +02:00
;;;; python-mode
2023-08-02 23:38:31 +02:00
2023-08-28 07:35:48 +02:00
;; set bpython as python shell interpreter
2023-08-02 23:38:31 +02:00
(add-hook! python-mode-hook
2023-10-14 00:26:17 +02:00
(setq python-shell-interpreter "bpython"))
2023-08-02 23:38:31 +02:00
2023-08-28 07:35:48 +02:00
;; set tab width; use flake8 as python-flymake-command, python-check-command
(setq python-indent-offset 4)
(add-hook 'python-mode-hook
(lambda ()
(setq-local tab-width 4)
(setq-local python-flymake-command '("flake8" "--max-doc-length=72", "--ignore=E211,E999,F401,F821,W503"))
(setq-local python-check-command "flake8 --max-doc-length=72 --ignore=E211,E999,F401,F821,W503"))
70)
;; use Pyright LSP
(add-hook 'python-mode-hook
(lambda ()
(require 'lsp-pyright)
(lsp)))
2023-09-15 23:00:22 +02:00
(defun run-black-pep8 ()
"Run `black -l 79' on the current Python file."
(interactive)
(shell-command-to-string
(format "black -l 79 %s"
(shell-quote-argument (buffer-file-name)))))
;; autoformat on save with `run-black-pep8'
2023-08-28 07:35:48 +02:00
(add-hook 'elpy-mode-hook
(lambda ()
(add-hook 'before-save-hook
2023-09-15 23:00:22 +02:00
'run-black-pep8)))
2023-08-28 07:35:48 +02:00
;; colorize compilation buffer
;; from https://sachachua.com/dotemacs/index.html#orga33bac5
(require 'ansi-color)
(defun colorize-compilation-buffer ()
(when (eq major-mode 'compilation-mode)
(let ((inhibit-read-only t))
(ansi-color-apply-on-region compilation-filter-start (point-max)))))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
2023-08-02 23:38:31 +02:00
2023-08-10 03:02:01 +02:00
;;;; go-mode
2023-08-02 23:38:31 +02:00
;; completion for GoLang
(add-hook 'completion-at-point-functions 'go-complete-at-point)
;; Go - lsp-mode
(defun lsp-go-install-save-hooks ()
(add-hook 'before-save-hook #'lsp-format-buffer t t)
(add-hook 'before-save-hook #'lsp-organize-imports t t))
(add-hook 'go-mode-hook #'lsp-go-install-save-hooks)
;; Start LSP Mode
(add-hook 'go-mode-hook #'lsp-deferred)
2023-08-28 07:35:48 +02:00
;;;; helpful
2023-08-28 07:35:48 +02:00
(global-set-key (kbd "C-h f") #'helpful-callable)
(global-set-key (kbd "C-h v") #'helpful-variable)
(global-set-key (kbd "C-h k") #'helpful-key)
(global-set-key (kbd "C-h x") #'helpful-command)
(global-set-key (kbd "C-c C-d") #'helpful-at-point)
2023-08-10 03:02:01 +02:00
;;;; dired
2023-08-02 23:38:31 +02:00
(after! dired
(setq dired-listing-switches "-laGh1v --group-directories-first")
(setq dired-confirm-shell-command nil
dired-no-confirm t
dired-deletion-confirmer '(lambda (x) t)
dired-recursive-deletes 'always))
2023-08-20 22:45:21 +02:00
;;;; dictionary
(global-set-key (kbd "C-c l") #'dictionary-lookup-definition)
(setq dictionary-server "dict.org")
;;;; centaur-tabs
(global-set-key (kbd "s-{") 'centaur-tabs-switch-group)
2023-08-21 09:23:12 +02:00
(global-set-key (kbd "s-h") 'centaur-tabs-backward-tab)
(global-set-key (kbd "s-l") 'centaur-tabs-forward-tab)
2023-08-20 22:45:21 +02:00
(setq centaur-tabs-buffer-show-groups t)
2023-10-14 00:26:17 +02:00
(defun my-centaur-tabs-buffer-groups ()
"Create centaur-tabs groups."
(cond
((string-equal "*" (substring (buffer-name) 0 1))
'("Emacs"))
((memq major-mode '(org-mode
org-agenda-clockreport-mode
org-src-mode
org-beamer-mode
org-indent-mode
org-bullets-mode
org-agenda-log-mode
diary-mode
org-roam-mode))
'("OrgMode"))
((memq major-mode '(dired-mode))
'("Dired"))
((memq major-mode '(helpful-mode
help-mode))
'("Help"))
((memq major-mode '(vterm-mode))
'("VTerm"))))
(setq centaur-tabs-buffer-groups-function 'my-centaur-tabs-buffer-groups)
2023-08-20 22:45:21 +02:00
;; prevent access to specified buffers
(defun centaur-tabs-hide-tab (x)
"Do not show given buffer in tabs."
(let ((name (format "%s" x)))
(or
;; Current window is not dedicated window.
(window-dedicated-p (selected-window))
;; Buffer name does not match blacklisted buffers.
(string-prefix-p "*epc" name)
(string-prefix-p "*Compile-Log*" name)
(string-prefix-p "*lsp" name)
(string-prefix-p "*tramp" name)
(string-prefix-p "*help" name)
(string-prefix-p "*Help" name)
2023-10-14 00:26:17 +02:00
(string-prefix-p "*vterminal" name)
2023-08-20 22:45:21 +02:00
;; Buffer is not a magit buffer.
(and (string-prefix-p "magit" name)
(not (file-name-extension name)))
)))
2023-10-14 00:26:17 +02:00
;; ;; elpher
(setq elpher-certificate-directory "~/sync/elpher/certs")
(setq elpher-default-url-type "gemini")
;;;; vterm
(setq vterm-kill-buffer-on-exit t)
(setq vterm-always-compile-module t)
(setq multi-vterm-buffer-name "localhost")
(defun hyperreal/create-mvterm-buffer ()
"Create new multi-vterm buffer and rename it to localhost<i>
and switch to it."
(interactive)
(let ((index 1)
(buffer-name "localhost"))
;; Find the next available index number
(while (get-buffer (format "%s<%d>" buffer-name index))
(setq index (1+ index)))
(multi-vterm)
(setq mvterm-buffer-name (format "%s<%d>" buffer-name index))
(rename-buffer mvterm-buffer-name)
(message "Created and started: %s" mvterm-buffer-name)
(switch-to-buffer mvterm-buffer-name)))
2024-03-29 15:58:00 +01:00
;;;; org-publish
(require 'ox-gemini)
(setq org-publish-project-alist
'(("techne"
:base-directory "~/sync/sites/techne-org"
:base-extension "org"
:publishing-directory "/sshx:jas@192.168.2.102:/home/jas/public/techne"
:publishing-function org-html-publish-to-html
:headline-levels 3
:section-numbers nil
:with-toc nil
:html-head "<link rel=\"stylesheet\"
href=\"style.css\"
type=\"text/css\"/>"
:html-postamble t
:html-postamble-format (("en"
"<p class=\"author\">Collected with ❤ by %a</p>
<p class=\"date\">Last updated: %T</p>
<p class=\"creator\">%c</p>
<p class=\"validation\">%v</p>")))
("gemini"
:base-directory "~/sync/sites/techne-org"
:base-extension "org"
:publishing-directory "/sshx:jas@192.168.2.102:/home/jas/public/gemini/hyperreal.coffee/techne"
:publishing-function org-gemini-publish-to-gemini)))
(setq org-publish-use-timestamps-flag nil)
;;;; nushell
(add-to-list 'auto-mode-alist '("\\.nu\\'" . nushell-ts-mode))
;;;; tramp-mode
(require 'tramp)
;; change the default remote shell
(setq host-list '("/sshx:jas@192.168.1.12:"
"/sshx:jas@192.168.2.102:"))
(dolist (host host-list) (add-to-list 'tramp-connection-properties
(list (regexp-quote host)
"remote-shell" "/bin/bash")))