dotfiles/home-manager/modules/emacs/.emacs.d/org/base.org

560 lines
16 KiB
Org Mode
Raw Normal View History

# SPDX-FileCopyrightText: 2022 Richard Brežák <richard@brezak.sk>
#
# SPDX-License-Identifier: LGPL-3.0-or-later
2021-02-01 00:13:31 +01:00
#+STARTUP: content
#+TITLE: Magic_RB's Emacs configuration
2021-02-01 00:13:31 +01:00
* Stuff That Needs Work
** TODO Spell checking
** TODO Calc mode
** TODO Org Agenda
*** Make it work on my phone
** TODO Org Roam
** TODO org-evil moving stuff, left, right with M-j M-; instead of M-h M-l
** Org Web Tools
https://github.com/alphapapa/org-web-tools
* Stuff
2021-02-01 12:00:24 +01:00
#+NAME: base
#+BEGIN_SRC emacs-lisp
(use-package pdf-tools
:straight t
:hook (('TeX-mode-hook . visual-line-mode))
:config
;; initialise
(pdf-tools-install)
(setq TeX-PDF-mode 1)
;; open pdfs scaled to fit page
(setq-default pdf-view-display-size 'fit-page)
;; automatically annotate highlights
(setq pdf-annot-activate-created-annotations t))
#+END_SRC
2021-02-01 12:00:24 +01:00
Enable =all-the-icons=, it's used by =treemacs= and =doom-modeline=.
2021-02-01 12:00:24 +01:00
#+BEGIN_SRC emacs-lisp
(use-package all-the-icons
:straight t)
#+END_SRC
2021-02-01 12:00:24 +01:00
Set ispell program to hunspell, this is very much a TODO, since the spelling configuration is rather minimal at this
point in time.
2021-02-01 12:00:24 +01:00
#+BEGIN_SRC emacs-lisp
(setq ispell-program-name "hunspell")
#+END_SRC
2021-02-01 12:00:24 +01:00
Fetch the ~SSH_AUTH_PATH~ from ~.profile~.
#+BEGIN_SRC emacs-lisp
(setenv "SSH_AUTH_SOCK" (shell-command-to-string ". ~/.profile && printf $SSH_AUTH_SOCK"))
#+END_SRC
* Look & Feel
** Color Themes
Create a function, which applies my font settings, and call it. Also branch on whether PGtk is in use, as fonts are a
bit bigger with it. Also enable variable pitch fonts, ~Iosevka~ is really nice.
#+BEGIN_SRC emacs-lisp
(setq magic_rb/fixed-width-font "Iosevka Term")
(setq magic_rb/variable-pitch-font "Iosevka Aile")
(with-eval-after-load 'dash
(defun magic_rb/apply-fonts ()
(interactive)
(if (-contains? (split-string system-configuration-features) "PGTK")
(set-face-attribute 'default nil :family magic_rb/fixed-width-font :slant 'normal :height 105)
(set-face-attribute 'default nil :family magic_rb/fixed-width-font :height 105))
(set-face-attribute 'fixed-pitch nil :family magic_rb/fixed-width-font :slant 'normal :height 1.0)
(set-face-attribute 'variable-pitch nil :family magic_rb/variable-pitch-font :height 1.0))
(magic_rb/apply-fonts))
#+END_SRC
#+RESULTS:
Load Modus Vivendi, but change the background color to not-black, it's a bit less depressing and in my opinion nicer
on the eyes.
2021-02-01 12:00:24 +01:00
#+BEGIN_SRC emacs-lisp
(setq modus-vivendi-theme-override-colors-alist
'(("bg-main" . "#111519")))
(load-theme 'modus-vivendi t)
#+END_SRC
** Modeline
2020-11-01 02:56:34 +01:00
Enable =doom-modeline=, much better than the default and unline =powerline= it's usable with TRAMP, so that's great.
#+BEGIN_SRC emacs-lisp
(use-package doom-modeline
:straight t
:config
(doom-modeline-mode))
#+END_SRC
You can also control, whether =doom-modeline= uses =all-the-icons= on a per frame basis. Especially useful when
running Emacs in daemon mode.
#+BEGIN_SRC emacs-lisp :tangle no
(make-variable-buffer-local 'doom-modeline-icon)
(add-hook 'after-make-frame-hook
(lambda ()
(setq doom-modeline-icon (display-graphic-p))))
#+END_SRC
Only show buffer encoding conditionally, there's no reason to have ~LF UTF-8~ down there, rather only show when the
encoding is something we don't expect, like ~CRLF~ or ~UTF-16~. Inspired by [[https://tecosaur.github.io/emacs-config/config.html#theme-modeline][tecosaur]].
#+BEGIN_SRC emacs-lisp
(defun tecosaur/doom-modeline-conditional-buffer-encoding ()
"We expect the encoding to be LF UTF-8, so only show the modeline when this is not the case"
(setq-local doom-modeline-buffer-encoding
(unless (or (eq buffer-file-coding-system 'utf-8-unix)
(eq buffer-file-coding-system 'utf-8)))))
(add-hook 'after-change-major-mode-hook #'tecosaur/doom-modeline-conditional-buffer-encoding)
#+END_SRC
** Miscelanious
Disable GTK decorations, as they are not "cool" as member of the Emacs mailing list would put it. Or actually my
reasoning, I don't want Emacs to be influenced by GTK theming, as I don't use almost any GTK programs.
#+BEGIN_SRC emacs-lisp
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(menu-bar-mode -1)
(scroll-bar-mode -1)
#+END_SRC
Enable compositor based transparency, low values will make text hard to read as everything, not just the background
is made transparent. It's also possible to set the alpha separately for when a frame is in focus and when it's not.
#+BEGIN_SRC emacs-lisp
(add-to-list 'default-frame-alist '(alpha 100 100))
(set-frame-parameter (selected-frame) 'alpha '(100 . 100))
#+END_SRC
Load =all-the-icons=, it's required used by =treemacs= and =doom-modeline=. You also must run
=all-the-icons-install-fonts= if you haven't already.
#+BEGIN_SRC emacs-lisp
(use-package all-the-icons
:straight t)
#+END_SRC
* Language
** Nix Expression Language
Enable ~nix-mode~.
#+BEGIN_SRC emacs-lisp
(use-package nix-mode
:straight t
:mode ("\\.nix\\'" . nix-mode)
:config
(add-hook 'nix-mode-hook #'lsp))
#+END_SRC
** HashiCorp
*** HashiCorp Configuration Language
#+BEGIN_SRC emacs-lisp
(use-package hcl-mode
:straight t)
#+END_SRC
*** Terraform Configuration Language
#+BEGIN_SRC emacs-lisp
(use-package terraform-mode
:straight t)
#+END_SRC
** YAML Configuration Language
Enable ~yaml-mode~.
#+BEGIN_SRC emacs-lisp
(use-package yaml-mode
:straight t
:mode ("\\.yml\\'" . yaml-mode)
:mode ("\\.yaml\\'" . yaml-mode))
#+END_SRC
** Dockerfile Configuration Language
Enable ~dockerfile-mode~
#+BEGIN_SRC emacs-lisp
(use-package dockerfile-mode
:straight t
:mode ("Dockerfile\\'" . dockerfile-mode))
#+END_SRC
** SCAD Programming Language
Enable ~scad-mode~
#+BEGIN_SRC emacs-lisp
(use-package scad-mode
:straight t)
#+END_SRC
** Web Development
*** HTML Markup Language
Enable ~web-mode~ for =.html=, =.xhtml= and hook ~lsp-mode~ on it.
#+BEGIN_SRC emacs-lisp
(use-package web-mode
:straight t
:mode ("\\.html\\'" . web-mode)
:mode ("\\.xhtml\\'" . web-mode)
:hook (web-mode . lsp-mode))
#+END_SRC
*** CSS Style Sheet Language
Enable ~css-mode~ for =.css=, =.scss= and hook ~lsp-mode~ on it. Also make ~flycheck~ happy.
#+BEGIN_SRC emacs-lisp
(use-package css-mode
:mode ("\\.css\\'" . css-mode)
:mode ("\\.scss\\'". css-mode)
:hook (css-mode . lsp-mode)
:config
(with-eval-after-load "flycheck"
(flycheck-add-mode 'javascript-eslint 'web-mode)))
#+END_SRC
*** Javascript Programming Language
#+BEGIN_WARNING
I do not personally do much Javascript development, so this mode might be completely broken or a better
alternative might be available.
#+END_WARNING
Enable ~rjsx-mode~ instead of ~javascript-mode~ or ~js2-mode~ as it properly handles inline HTML.
#+BEGIN_SRC emacs-lisp
(use-package rjsx-mode
:straight t
:config
:mode ("\\.js\\'" . rjsx-mode)
:mode ("\\.jsx\\'" . rjsx-mode)
:hook (rjsx-mode . lsp-mode))
#+END_SRC
*** Typescript Programming Language
Enable ~typescript-mode~ for =.ts=, =.tsx= and hook ~lsp-mode~ on it. It doesn't specifically support inline HTML,
but aside from minor indentation issues it works fine.
#+BEGIN_SRC emacs-lisp
(use-package typescript-mode
:straight t
:config
:mode ("\\.ts\\'" . typescript-mode)
:mode ("\\.tsx\\'" . typescript-mode)
:hook (typescript-mode . lsp-mode))
#+END_SRC
** Rust Programming Language
Enable ~rustic~ and more feature-full alternative to ~rust-mode~, actually a rather distant fork of it.
Also hook ~lsp-mode~ on it.
#+NAME: rust
#+BEGIN_SRC emacs-lisp
(use-package rustic
:straight t
:hook (rustic-mode . lsp-mode)
:mode ("\\.rs\\'" . rustic-mode))
#+END_SRC
* LSP
** envrc
Enable ~envrc~, which changes ENVs on a per buffer basis.
#+BEGIN_SRC emacs-lisp
(use-package envrc
:straight t
:init
(envrc-global-mode))
#+END_SRC
** lsp-mode
Increase GC threshold to avoid random freezes on garbage collection.
#+NAME: gc-cons-threshold
#+BEGIN_SRC emacs-lisp :tangle no
(setq gc-cons-threshold 100000000)
#+END_SRC
Increase the amount of data Emacs reads from a process in one go, default is 4KB, but some LSP servers produce responses up to 3MB.
#+NAME: read-process-output-max
#+BEGIN_SRC emacs-lisp :tangle no
(setq read-process-output-max (* (* 1024 1024) 3))
#+END_SRC
Switch completion provider to =capf=, even though it should be the default, but just to make sure it. =company-lsp=
is what =lsp-mode= switched away from.
#+NAME: lsp-completion-provider
#+BEGIN_SRC emacs-lisp :tangle no
(setq lsp-completion-provider :capf)
#+END_SRC
Set the minimum delay between LSP refreshes, should help with performance when typing really fast.
#+NAME: lsp-idle-delay
#+BEGIN_SRC emacs-lisp :tangle no
(setq lsp-idle-delay 0.500) ;; adjust me
#+END_SRC
Setup rustic to prefer ~rust-analyzer~ instead of ~rls~ and also don't format on save, it's really annoying.
#+NAME: lsp-rustic
#+BEGIN_SRC emacs-lisp :tangle no
(setq rustic-lsp-server 'rust-analyzer)
(setq rustic-compile-command "cargo build")
(setq rustic-format-trigger nil);'on-save
#+END_SRC
Enable inline type hints and disable chaining and parameter hints for Rust.
#+NAME: lsp-rust-analyzer
#+BEGIN_SRC emacs-lisp :tangle no
(setq lsp-rust-analyzer-display-chaining-hints nil)
(setq lsp-rust-analyzer-display-parameter-hints nil)
(setq lsp-rust-analyzer-server-display-inlay-hints t)
#+END_SRC
Finally enable ~lsp-mode~.
#+BEGIN_SRC emacs-lisp :noweb yes
(use-package lsp-mode
:straight t
:config
(setq lsp-prefer-flymake nil)
(setq lsp-ui-doc-enable nil)
:config
<<lsp-rustic>>
;; <<lsp-rust-analyzer>>
<<gc-cons-threshold>>
<<read-process-output-max>>
<<lsp-completion-provider>>
;; <<lsp-idle-delay>>
<<lsp-typescript-tramp>>
<<lsp-scala-tramp>>)
#+END_SRC
** lsp-pyright
Enable ~lsp-pyright~, the best Python language server, all of them are a bit lackluster, this one is the best
option.
#+BEGIN_SRC emacs-lisp
(use-package lsp-pyright
:straight t
:hook (python-mode . lsp))
#+END_SRC
** lsp-ui
Enable ~lsp-ui~, it adds doc frames, code actions at the side and other cool things, some of them are annoying and
need disabling.
#+BEGIN_SRC emacs-lisp
(use-package lsp-ui
:straight t
:after (company-box)
:config
;; disable focus on mouse over
(push '(no-accept-focus . t) lsp-ui-doc-frame-parameters)
(push '(no-accept-focus . t) company-box-frame-parameters)
(add-to-list 'lsp-ui-doc-frame-parameters '(no-accept-focus . t))
(add-to-list 'company-box-frame-parameters '(no-accept-focus . t))
(setq mouse-autoselect-window nil))
#+END_SRC
** flycheck
Enable ~flycheck~ for in-buffer hints and errors and warning and things.
#+BEGIN_SRC emacs-lisp
(use-package flycheck
:straight t
:init (global-flycheck-mode))
#+END_SRC
** origami
2021-02-01 00:13:31 +01:00
Enable ~origami~. It allows one to fold and unfold a section with =zc= and =zo= in ~evil-mode~. Hook it on both ~conf-mode~ and ~prog-mode~;
2021-02-01 00:13:31 +01:00
#+BEGIN_SRC emacs-lisp
(use-package origami
:straight t
:hook ((prog-mode . origami-mode)
(conf-mode . origami-mode)))
#+END_SRC
2021-02-01 00:13:31 +01:00
Enable ~origami-lsp~. Some LSP servers specify these folding ranges and this package makes ~origami~ understand that
and work with it.
2021-02-01 00:13:31 +01:00
#+BEGIN_SRC emacs-lisp
(use-package lsp-origami
:straight t
:hook (lsp-after-open-hook lsp-origami-try-enable))
#+END_SRC
2021-02-01 00:13:31 +01:00
* hledger
For hledger, it's possible to use =ledger-mode= instead of =hledger-mode=. We'll see how it goes. It does require some convincing though.
#+BEGIN_SRC emacs-lisp
(use-package ledger-mode
:straight t
:config
(setq ledger-binary-path "hledger")
(setq ledger-mode-should-check-version nil)
(add-to-list 'auto-mode-alist '("\\.\\(h?ledger\\|journal\\|j\\)$" . ledger-mode))
(setq ledger-report-balance
(list "bal" (concat ledger-binary-path " --strict -f %(ledger-file) bal")))
(setq ledger-report-reg
(list "reg" (concat ledger-binary-path " --strict -f %(ledger-file) reg")))
(setq ledger-report-payee
(list "payee" (concat ledger-binary-path " --strict -f %(ledger-file) reg @%(payee)")))
(setq ledger-report-account
(list "account" (concat ledger-binary-path " --strict -f %(ledger-file) reg %(account)")))
(setq ledger-reports
(list ledger-report-balance
ledger-report-reg
ledger-report-payee
ledger-report-account)))
#+END_SRC
* Projectile
Enable ~projectile~.
#+BEGIN_SRC emacs-lisp
(use-package projectile
:straight t
:config
(projectile-mode +1)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map))
#+END_SRC
* Random Bits and Bobs
Set keystrokes echo to something really low, it's useful to know what you're typing.
#+BEGIN_SRC emacs-lisp
(setq echo-keystrokes 0.01)
#+END_SRC
Set default major mode to org mode, it's much more useful than fundamental.
2021-02-01 12:00:24 +01:00
#+BEGIN_SRC emacs-lisp
(setq-default major-mode 'org-mode)
#+END_SRC
2021-02-01 12:00:24 +01:00
Delete files by moving to trash.
2021-02-01 00:13:31 +01:00
#+BEGIN_SRC emacs-lisp
(setq-default delete-by-moving-to-trash t)
#+END_SRC
2021-02-01 00:13:31 +01:00
Equalize windows after split.
#+BEGIN_SRC emacs-lisp
(setq-default window-combination-resize t)
#+END_SRC
Increase undo limit to 80MB and enable fine undo, Evil will no longer chunk all edits in =INSERT= mode into one big
undo blob.
#+BEGIN_SRC emacs-lisp
(setq undo-limit 80000000
evil-want-fine-undo t)
#+END_SRC
2021-02-01 00:13:31 +01:00
For now, don't autosave. Because editing on remote disks, not TRAMP, but just NFS or CIFS, becomes extremely painful.
2021-02-01 00:13:31 +01:00
#+BEGIN_SRC emacs-lisp :tangle no
(setq auto-save-default t)
#+END_SRC
Enable line numbers for both programming buffers (Rust, C, and such) and configuration buffers (Nix, Yaml, Json, and
such) and Org mode.
#+BEGIN_SRC emacs-lisp
(add-hook 'conf-mode-hook 'display-line-numbers-mode)
(add-hook 'prog-mode-hook 'display-line-numbers-mode)
#+END_SRC
Improve scrolling by:
1. disabling acceleration
2. making it so that the window under the pointer is scroller no matter the focused window
3. changing default scroll amount to 5 lines and 1 when shift is pressed
#+BEGIN_SRC emacs-lisp
(setq mouse-wheel-scroll-amount '(5 ((shift) . 1)))
(setq mouse-wheel-progressive-speed nil)
(setq mouse-wheel-follow-mouse 't)
#+END_SRC
Enable perentheses highlighting and pairing.
#+BEGIN_SRC emacs-lisp
(show-paren-mode 1)
(electric-pair-mode)
#+END_SRC
Set fill colum, horizontal indicator, for both =fill-paragraph=(=M-q=) and the visual horizontal indicator.
#+BEGIN_SRC emacs-lisp
(setq-default display-fill-column-indicator-column 120
fill-column 120)
#+END_SRC
Start Emacs server, unless it's already running. Starting a new Emacs instance while debugging and getting an error
about a server already running can be a bit annoying.
#+BEGIN_SRC emacs-lisp
(load "server")
(unless (server-running-p) (server-start))
#+END_SRC
#+BEGIN_SRC emacs-lisp
(setq backup-directory-alist
`(("." . ,(concat user-emacs-directory "backups"))))
#+END_SRC
** Windows
As [[https://github.com/tecosaur/][tecosaur]] has it in his [[https://tecosaur.github.io/emacs-config/config.html#windows][configuration]], I was to be asked which window to should be brought up when I split a
window in Emacs. So create a new advice which will run after evil split commands and brings up the buffer selector.
#+BEGIN_SRC emacs-lisp
(defadvice evil-window-vsplit (after activate compile)
(counsel-switch-buffer))
(defadvice evil-window-split (after activate compile)
(counsel-switch-buffer))
#+END_SRC
** PGTK neo2 fix
#+BEGIN_SRC emacs-lisp
(put 'none 'modifier-value 0)
(setq x-hyper-keysym 'none)
#+END_SRC