Files
DoomConfig/config.el
2025-04-12 09:42:15 +02:00

380 lines
14 KiB
EmacsLisp

;;; $DOOMDIR/config.el -*- lexical-binding: t; -*-
;; Place your private configuration here! Remember, you do not need to run 'doom
;; sync' after modifying this file!
;; Some functionality uses this to identify you, e.g. GPG configuration, email
;; clients, file templates and snippets. It is optional.
;; (setq user-full-name "John Doe"
;; user-mail-address "john@doe.com")
;; Doom exposes five (optional) variables for controlling fonts in Doom:
;;
;; - `doom-font' -- the primary font to use
;; - `doom-variable-pitch-font' -- a non-monospace font (where applicable)
;; - `doom-big-font' -- used for `doom-big-font-mode'; use this for
;; presentations or streaming.
;; - `doom-symbol-font' -- for symbols
;; - `doom-serif-font' -- for the `fixed-pitch-serif' face
;;
;; See 'C-h v doom-font' for documentation and more examples of what they
;; accept. For example:
;;
;;(setq doom-font (font-spec :family "Fira Code" :size 12 :weight 'semi-light)
;; doom-variable-pitch-font (font-spec :family "Fira Sans" :size 13))
;;
;; If you or Emacs can't find your font, use 'M-x describe-font' to look them
;; up, `M-x eval-region' to execute elisp code, and 'M-x doom/reload-font' to
;; refresh your font settings. If Emacs still can't find your font, it likely
;; wasn't installed correctly. Font issues are rarely Doom issues!
;; There are two ways to load a theme. Both assume the theme is installed and
;; available. You can either set `doom-theme' or manually load a theme with the
;; `load-theme' function. This is the default:
(setq doom-theme 'doom-one)
;;(load-theme 'catppuccin :no-confirm)
;; 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 t)
;; If you use `org' and don't want your org files in the default location below,
;; change `org-directory'. It must be set before org loads!
(setq org-directory "~/Documents/Org")
(setq org-roam-directory (file-truename "~/Documents/Org/roam")) ;; Set the directory for your notes
;;(setq doom-font (font-spec :family "Roboto Mono" :size 13))
(when (member "Roboto Mono" (font-family-list))
(set-face-attribute 'default nil :font "Roboto Mono" :height 110)
(set-face-attribute 'fixed-pitch nil :family "Roboto Mono"))
(when (member "Source Sans 3" (font-family-list))
(set-face-attribute 'variable-pitch nil :family "Source Sans 3" :height 1.25))
;; Whenever you reconfigure a package, make sure to wrap your config in an
;; `after!' block, otherwise Doom's defaults may override your settings. E.g.
;;
;; (after! PACKAGE
;; (setq x y))
;;
;; The exceptions to this rule:
;;
;; - Setting file/directory variables (like `org-directory')
;; - Setting variables which explicitly tell you to set them before their
;; package is loaded (see 'C-h v VARIABLE' to look up their documentation).
;; - Setting doom variables (which start with 'doom-' or '+').
;;
;; Here are some additional functions/macros that will help you configure Doom.
;;
;; - `load!' for loading external *.el files relative to this one
;; - `use-package!' for configuring packages
;; - `after!' for running code after a package has loaded
;; - `add-load-path!' for adding directories to the `load-path', relative to
;; this file. Emacs searches the `load-path' when you load packages with
;; `require' or `use-package'.
;; - `map!' for binding new keys
;;
;; To get information about any of these functions/macros, move the cursor over
;; the highlighted symbol at press 'K' (non-evil users must press 'C-c c k').
;; This will open documentation for it, including demos of how they are used.
;; Alternatively, use `C-h o' to look up a symbol (functions, variables, faces,
;; etc).
;;
;; You can also try 'gd' (or 'C-c c d') to jump to their definition and see how
;; they are implemented.
;;
(use-package! copilot
:hook (prog-mode . copilot-mode)
:bind (:map copilot-completion-map
("<tab>" . 'copilot-accept-completion)
("TAB" . 'copilot-accept-completion)
("C-TAB" . 'copilot-accept-completion-by-word)
("C-<tab>" . 'copilot-accept-completion-by-word)
("C-n" . 'copilot-next-completion)
("C-p" . 'copilot-previous-completion))
:config
(add-to-list 'copilot-indentation-alist '(prog-mode 2))
(add-to-list 'copilot-indentation-alist '(org-mode 2))
(add-to-list 'copilot-indentation-alist '(text-mode 2))
(add-to-list 'copilot-indentation-alist '(closure-mode 2))
(add-to-list 'copilot-indentation-alist '(emacs-lisp-mode 2)))
;; ==============================================================
;; Shortcuts
;; ==============================================================
;; check OS type
(cond
((string-equal system-type "windows-nt") ; Microsoft Windows
(progn
(message "Microsoft Windows")))
((string-equal system-type "darwin") ; Mac OS X
(progn
(setq mac-option-key-is-meta nil)
(setq mac-command-key-is-meta t)
(setq mac-command-modifier 'meta)
(setq mac-option-modifier nil)
(message "Mac OS X")))
((string-equal system-type "gnu/linux") ; linux
(progn
(message "Linux"))))
;; Copy to system clipboard with M-c
(global-set-key (kbd "M-c") 'clipboard-kill-ring-save)
;; Paste from system clipboard with M-v
(global-set-key (kbd "M-v") 'clipboard-yank)
;; Zoom in with C-+
(global-set-key (kbd "C-=") 'text-scale-increase)
;; Zoom out with C--
(global-set-key (kbd "C--") 'text-scale-decrease)
;; Scroll up one screen with C-S-v
(global-set-key (kbd "C-S-v") 'scroll-down-command)
;; Select next occurences of a word
(global-set-key (kbd "C-d") 'mc/mark-next-like-this-symbol)
;; ==============================================================
;; Coq
;; ==============================================================
(add-hook 'coq-mode-hook #'company-coq-mode)
(add-hook 'coq-mode-hook (lambda () (local-set-key (kbd "C-<down>") #'proof-assert-next-command-interactive)))
(add-hook 'coq-mode-hook (lambda () (local-set-key (kbd "C-<up>") #'proof-retract-until-point-interactive)))
;;==============================================================
;; Org mode
;; =============================================================
(use-package vulpea
:ensure t
;; hook into org-roam-db-autosync-mode you wish to enable
;; persistence of meta values (see respective section in README to
;; find out what meta means)
:hook ((org-roam-db-autosync-mode . vulpea-db-autosync-enable)))
;; ================== Appearance ==================
;; Improve org mode looks
(use-package org-indent)
(set-face-attribute 'org-indent nil :inherit '(org-hide fixed-pitch))
(use-package olivetti)
(use-package org-appear
:hook
(org-mode . org-appear-mode))
(use-package! org-modern
:hook
(org-mode . global-org-modern-mode)
:config
(setq
org-auto-align-tags t
org-tags-column 0
org-fold-catch-invisible-edits 'show-and-error
org-special-ctrl-a/e t
org-insert-heading-respect-content t
;; Don't style the following
org-modern-tag nil
org-modern-todo nil
org-modern-priority nil)
(global-org-modern-mode))
;; Resize Org headings
(dolist (face '((org-level-1 . 1.4)
(org-level-2 . 1.3)
(org-level-3 . 1.2)
(org-level-4 . 1.1)
(org-level-5 . 1.1)
(org-level-6 . 1.1)
(org-level-7 . 1.1)
(org-level-8 . 1.1)))
(set-face-attribute (car face) nil :family "Source Sans 3" :weight 'bold :height (cdr face)))
;; Make the document title a bit bigger
(set-face-attribute 'org-document-title nil
:family "Source Sans 3"
:weight 'bold
:height 1.8)
(add-hook 'org-mode-hook 'variable-pitch-mode)
(add-hook 'org-mode-hook 'visual-line-mode)
(add-hook 'org-mode-hook (lambda () (display-line-numbers-mode 0)))
(set-face-attribute 'org-block nil :foreground nil :inherit
'fixed-pitch :height 0.85)
(set-face-attribute 'org-code nil :inherit '(shadow fixed-pitch) :height 0.85)
(set-face-attribute 'org-indent nil :inherit '(org-hide fixed-pitch) :height 0.85)
(set-face-attribute 'org-verbatim nil :inherit '(shadow fixed-pitch) :height 0.85)
(set-face-attribute 'org-special-keyword nil :inherit '(font-lock-comment-face
fixed-pitch))
(set-face-attribute 'org-meta-line nil :inherit '(font-lock-comment-face fixed-pitch))
(set-face-attribute 'org-checkbox nil :inherit 'fixed-pitch)
(set-face-attribute 'org-table nil :inherit 'fixed-pitch)
(plist-put org-format-latex-options :scale 2)
;; Use major mode of a specific language in an SRC block
(setq org-src-fontify-natively t
org-src-tab-acts-natively t
org-edit-src-content-indentation 0)
(add-hook 'org-mode-hook 'olivetti-mode)
;; ORG TODO
(setq org-lowest-priority ?F) ;; Gives us priorities A through F
(setq org-default-priority ?E) ;; If an item has no priority, it is considered [#E].
(setq org-priority-faces
'((65 . "#BF616A")
(66 . "#EBCB8B")
(67 . "#B48EAD")
(68 . "#81A1C1")
(69 . "#5E81AC")
(70 . "#4C566A")))
(setq org-todo-keywords
'((sequence
"TODO" "PROJ" "READ" "CHECK" "IDEA" ; Needs further action
"|"
"DONE"))) ; Needs no action currently
(setq org-todo-keyword-faces
'(("TODO" :inherit (org-todo region) :foreground "#A3BE8C" :weight bold)
("PROJ" :inherit (org-todo region) :foreground "#88C0D0" :weight bold)
("READ" :inherit (org-todo region) :foreground "#8FBCBB" :weight bold)
("CHECK" :inherit (org-todo region) :foreground "#81A1C1" :weight bold)
("IDEA" :inherit (org-todo region) :foreground "#EBCB8B" :weight bold)
("DONE" :inherit (org-todo region) :foreground "#30343d" :weight bold)))
(setq org-startup-indented t
org-pretty-entities t
org-use-sub-superscripts "{}"
org-hide-emphasis-markers t
org-startup-with-inline-images t
org-image-actual-width '(300))
(setq org-support-shift-select t)
(add-to-list 'load-path "~/.doom.d/")
(setq org-startup-truncated nil)
(with-eval-after-load "org"
(require 'org-phscroll))
;; ================== ORG Roam ==================
(use-package! org-roam
:config
(org-roam-db-autosync-mode)) ;; Automatically sync the roam database
(setq org-roam-completion-everywhere t) ;; Enable Org-roam completions globally
(setq org-roam-mode-sections
'(org-roam-backlinks-section ;; Show backlinks
org-roam-reflinks-section ;; Show references (if applicable)
org-roam-unlinked-references-section)) ;; Show unlinked references
;; ================== Shortcuts ==================
(global-set-key (kbd "C-o") 'org-open-at-point)
(global-set-key (kbd "M-o") 'org-mark-ring-goto)
;; Insert a not without opening it
(defun org-roam-node-insert-immediate (arg &rest args)
(interactive "P")
(let ((args (cons arg args))
(org-roam-capture-templates (list (append (car org-roam-capture-templates)
'(:immediate-finish t)))))
(apply #'org-roam-node-insert args)))
(global-set-key (kbd "C-c n r I") 'org-roam-node-insert-immediate)
;;paste image from clipboard
(use-package! org-download)
(setq org-download-image-dir "images")
(after! org-download
(setq org-download-method 'directory))
(setq org-download-heading-lvl nil)
(setq org-download-timestamp "%Y%m%d-%H%M%S_")
(setq org-image-actual-width 300)
(map! :map org-mode-map
"C-c n r v" 'org-download-clipboard)
;; ================== Agenda ==================
;; Auto add roam file with TODO to the agenda
(defun vulpea-project-p ()
"Return non-nil if current buffer has any todo entry.
TODO entries marked as done are ignored, meaning the this
function returns nil if current buffer contains only completed
tasks."
(seq-find ; (3)
(lambda (type)
(eq type 'todo))
(org-element-map ; (2)
(org-element-parse-buffer 'headline) ; (1)
'headline
(lambda (h)
(org-element-property :todo-type h)))))
(defun vulpea-project-update-tag ()
"Update PROJECT tag in the current buffer."
(when (and (not (active-minibuffer-window))
(vulpea-buffer-p))
(save-excursion
(goto-char (point-min))
(let* ((tags (vulpea-buffer-tags-get))
(original-tags tags))
(if (vulpea-project-p)
(setq tags (cons "project" tags))
(setq tags (remove "project" tags)))
;; cleanup duplicates
(setq tags (seq-uniq tags))
;; update tags if changed
(when (or (seq-difference tags original-tags)
(seq-difference original-tags tags))
(apply #'vulpea-buffer-tags-set tags))))))
(defun vulpea-buffer-p ()
"Return non-nil if the currently visited buffer is a note."
(and buffer-file-name
(string-prefix-p
(expand-file-name (file-name-as-directory org-roam-directory))
(file-name-directory buffer-file-name))))
(defun vulpea-project-files ()
"Return a list of note files containing 'project' tag." ;
(seq-uniq
(seq-map
#'car
(org-roam-db-query
[:select [nodes:file]
:from tags
:left-join nodes
:on (= tags:node-id nodes:id)
:where (like tag (quote "%\"project\"%"))]))))
(defun vulpea-agenda-files-update (&rest _)
"Update the value of `org-agenda-files'."
(setq org-agenda-files (vulpea-project-files)))
(add-hook 'find-file-hook #'vulpea-project-update-tag)
(add-hook 'before-save-hook #'vulpea-project-update-tag)
(advice-add 'org-agenda :before #'vulpea-agenda-files-update)
(advice-add 'org-todo-list :before #'vulpea-agenda-files-update)