nix-dotfiles/home/programs/emacs/config.org

2135 lines
63 KiB
Org Mode
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#+TITLE: Org Mode Configuration
#+AUTHOR: h7x4
#+PROPERTY: header-args :emacs-lisp :tangle yes
#+STARTUP: org-startup-folded: t
#+BEGIN_SRC elisp
;;; ~/.emacs.d/config.el -*- lexical-binding: t; -*-
#+END_SRC
* Use-package
#+BEGIN_SRC elisp
; (setq user-emacs-directory (substitute-in-file-name "$HOME/.emacs.d"))
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(require 'use-package)
(setq use-package-always-ensure t)
#+END_SRC
* Keybindings
#+BEGIN_SRC elisp
(use-package general
:config
(general-evil-setup)
(general-create-definer leader-key
; :states 'normal
:states 'motion
:prefix "SPC"
:non-normal-prefix "C-SPC"))
#+END_SRC
Base keys
g - git
l - lsp
o - org
p - project management
w - multiple cursors
#+BEGIN_SRC elisp
(leader-key
"" nil
"c" (general-simulate-key "C-c" :which-key "C-c")
"u" (general-simulate-key "C-u" :which-key "C-u")
"x" (general-simulate-key "C-x" :which-key "C-x")
"m" '(:ignore t :which-key "mode")
"mx" 'nil
;; Help
"h" (general-simulate-key "<f1>" :which-key "C-h")
;; Insert
"i" '(:ignore t :which-key "C-h")
"ix" 'nil
;; Package manager
;; "p" '(:ignore t :which-key "packages")
;; "pl" 'list-packages
;; Quit operations
"q" '(:ignore t :which-key "quit emacs")
"qq" 'kill-emacs
"qz" 'delete-frame
;; Buffer operations
"b" '(:ignore t :which-key "buffer")
"bb" 'mode-line-other-buffer
"bk" 'kill-this-buffer
;; "bn" 'next-buffer
;; "bp" 'previous-buffer
"bq" 'kill-buffer-and-window
;; "bR" 'rename-file-and-buffer
"br" 'revert-buffer
;; Window operations
"w" '(:ignore t :which-key "window")
"wm" 'maximize-window
"wh" 'split-window-horizontally
"wg" 'split-window-vertically
;; "wu" 'winner-undo
"ww" 'other-window
"wk" 'delete-window
"wD" 'delete-other-windows
;; File operations
"f" '(:ignore t :which-key "find")
; "fc" 'write-file
; "fe" '(:ignore t :which-key "emacs")
;; "fed" 'find-user-init-file
;; "feR" 'load-user-init-file
; "fj" 'dired-jump
"fl" 'find-file-literally
;; "fR" 'rename-file-and-buffer
"fs" 'save-buffer
;; Applications
"a" '(:ignore t :which-key "apps")
"ad" 'dired
":" 'shell-command
";" 'eval-expression
"ac" 'calendar
"oa" 'org-agenda)
#+END_SRC
General keys
#+BEGIN_SRC emacs-lisp
; (global-set-key (kbd "<escape>") 'keyboard-escape-quit)
(general-define-key
"<escape>" 'keyboard-escape-quit
"C-o" 'previous-buffer
"C-p" 'next-buffer)
#+END_SRC
* Essentials
** Basic config
Stop emacs from using dialog windows
#+BEGIN_SRC emacs-lisp
(setq use-dialog-box nil)
#+END_SRC
Save sessions
#+BEGIN_SRC emacs-lisp
;; (desktop-save-mode 1)
#+END_SRC
Set spacing
#+BEGIN_SRC emacs-lisp
(setq-default
tab-width 2
c-basic-offset 2)
#+END_SRC
Put backup files in emacs.d/temp
#+BEGIN_SRC emacs-lisp
(setq backup-directory-alist
`(("." . ,(concat user-emacs-directory "/temp"))))
#+END_SRC
** Evil mode
#+BEGIN_SRC elisp
(use-package evil
:demand t
:init
(setq evil-want-integration t)
(setq evil-want-keybinding nil)
:general ; (leader-key
; "wh" '(evil-window-left :which-key "←")
; "wj" '(evil-window-down :which-key "↓")
; "wk" '(evil-window-up :which-key "↑")
; "wl" '(evil-window-right :which-key "→"))
([remap evil-ex-search-forward] 'swiper)
([remap evil-ex-search-backward] 'swiper-backward)
:bind (
("C-h" . evil-window-left)
("C-j" . evil-window-down)
("C-k" . evil-window-up)
("C-l" . evil-window-right)
:map evil-insert-state-map
("C-g" . evil-normal-state)
("C-h" . evil-delete-backward-char-and-join))
:config
;; :q should kill the current buffer rather than quitting emacs entirely
(evil-ex-define-cmd "q" 'kill-this-buffer)
;; Need to type out :quit to close emacs
(evil-ex-define-cmd "quit" 'evil-quit)
(evil-set-initial-state 'messages-buffer-mode 'normal)
(evil-set-initial-state 'dashboard-mode 'normal)
(evil-mode 1))
#+END_SRC
#+BEGIN_SRC elisp
(use-package evil-collection
:after (evil)
:config
(evil-collection-init)
(evil-collection-company-setup))
#+END_SRC
#+BEGIN_SRC elisp
(use-package evil-nerd-commenter
:bind ("M-/" . evilnc-comment-or-uncomment-lines)
:general (leader-key
"c" '(evilnc-comment-or-uncomment-lines :which-key "/* */"))
(general-nmap
"gc" 'evilnc-comment-operator))
#+END_SRC
Evil escape mode
#+BEGIN_SRC emacs-lisp
;; (use-package evil-escape
;; :after (evil company)
;; :diminish evil-escape-mode
;; :init
;; (with-eval-after-load 'company
;; (add-hook 'evil-normal-state-entry-hook #'company-cancel))
;; (setq evil-escape-key-sequence "jk"
;; evil-escape-unordered-key-sequence t)
;; :config
;; (evil-escape-mode))
#+END_SRC
** Ivy
#+BEGIN_SRC elisp
(use-package ivy
:bind (
:map ivy-minibuffer-map
("M-j" . ivy-next-line)
("M-k" . ivy-previous-line)
("M-l" . ivy-alt-done)))
#+END_SRC
Ivy-rich adds extra columns to a few of the Counsel commands to provide more information about each item.
#+BEGIN_SRC elisp
(use-package ivy-rich
:config (ivy-rich-mode 1))
#+END_SRC
** Counsel
#+BEGIN_SRC elisp
(use-package counsel
:general (leader-key
"ff" '(counsel-find-file :which-key "find file")
"f SPC" '(counsel-ag :which-key "Ag")
"ik" '(counsel-yank-pop :which-key "from kill-ring")
"bb" '(counsel-ibuffer :which-key "choose buffer")
"fe" '(counsel-flycheck :which-key "find error"))
:bind (("M-x" . counsel-M-x)
("C-x b" . counsel-ibuffer)
("C-x C-f" . counsel-find-file)
:map minibuffer-local-map
("C-r" . 'counsel-minibuffer-history)))
#+END_SRC
** Org mode
#+BEGIN_SRC emacs-lisp
(use-package org
:general (leader-key
"o" '(:ignore t :which-key "org")
"oa" '(org-agenda :which-key "agenda")
"ox" '(org-toggle-checkbox :which-key "[X]")
"oe" '(org-edit-src-code :which-key "Edit SRC")
; Insert
"io" '(:ignore t :which-key "org")
"ios" 'org-insert-structure-template)
:config
(setq org-src-tab-acts-natively nil))
#+END_SRC
Improved version of org-bullets
#+BEGIN_SRC emacs-lisp
(use-package org-superstar
:hook (org-mode-hook . org-superstar-mode)
:config
(setq org-startup-indented t) ;; Indent according to section
(setq org-startup-with-inline-images t)) ;; Display images in-buffer by default
#+END_SRC
Evil bindings for org mode
#+BEGIN_SRC emacs-lisp
(use-package evil-org
:after (evil org)
:hook
(org-mode-hook . evil-org-mode)
(evil-org-mode-hook . (lambda ()
(evil-org-set-key-theme '(navigation insert textobjects additional calendar))))
:config
(require 'evil-org-agenda)
(evil-org-agenda-set-keys)
(setq org-agenda-files '("~/org/agenda.org"))
(setq org-directory "~/org/"))
#+END_SRC
** Notes
*** Project notes
#+BEGIN_SRC emacs-lisp
(defvar notes-folder "~/.emacs.d/notes")
#+END_SRC
#+BEGIN_SRC emacs-lisp
(defun format-note-path (project-root)
(concat notes-folder (string-remove-suffix "/" (string-remove-prefix (getenv "HOME") project-root)) ".org"))
(defun get-notes ()
(interactive)
(if (projectile-project-p)
(let
((note-path (format-note-path (projectile-project-root))))
(unless (file-exists-p note-path)
(when (y-or-n-p (format "%s does not exist. Create it?" note-path))
(make-directory (file-name-directory note-path) t)
(make-empty-file note-path)))
(find-file note-path))
;; else
(message "Couldn't find project folder")))
(leader-key
"fn" '(get-notes :which-key "Get project notes"))
#+END_SRC
** Config files
#+BEGIN_SRC emacs-lisp
(setq dotfiles '(
("Emacs" . (concat user-emacs-directory "/config.org"))
("Xmonad" . "$HOME/.xmonad/xmonad.hs")
("Xmobar" . "$XDG_CONFIG_HOME/xmobar/xmobarrc")
("Awesome" . "$XDG_CONFIG_HOME/awesome/rc.lua")
("Stalonetray" . "$HOME/.stalonetrayrc")
("Termite" . "$XDG_CONFIG_HOME/termite/config")
("Kitty" . "$XDG_CONFIG_HOME/kitty/kitty.conf")
("Mpd" . "$XDG_CONFIG_HOME/mpd/mpd.conf")
("Ncmpcpp" . "$HOME/.ncmpcpp/config")
("Nnn" . "$XDG_CONFIG_HOME/nnn/")
("TeX-ntnu" . "$HOME/texmf/tex/latex/local/ntnu.sty")
("Tmux" . "$XDG_CONFIG_HOME/tmux/tmux.conf")
("Todo" . "$HOME/.todo")
("Qutebrowser" . "$XDG_CONFIG_HOME/qutebrowser/config.py")
("Vim" . "$XDG_CONFIG_HOME/nvim/init.lua")
("Zsh" . "$XDG_CONFIG_HOME/zsh/.zshrc")
("Config-selector" . "$HOME/.scripts/rofi/config-selector")
("Configfiles" . "$HOME/.scripts/rofi/configfiles")))
(defun find-config-file ()
"Chooses a config-file from dotfiles and opens it in a new buffer"
(interactive)
(ivy-read "Config: " dotfiles
:action (lambda (confpair) (find-file (substitute-in-file-name (eval (cdr confpair)))))))
(leader-key "fc" '(find-config-file :which-key "find config file"))
#+END_SRC
* Look and Feel
** Theme
doom-theme can be used to set a theme from the doom package
For every other theme, use load-theme
#+BEGIN_SRC emacs-lisp
(use-package monokai-theme
:config
(setq monokai-user-variable-pitch t)
(progn
(defvar after-load-theme-hook nil
"Hook run after a color theme is loaded using `load-theme'.")
(defadvice load-theme (after run-after-load-theme-hook activate)
"Run `after-load-theme-hook'."
(run-hooks 'after-load-theme-hook))
(defun customize-monokai ()
"Customize monokai theme"
(if (member 'monokai custom-enabled-themes)
(custom-theme-set-faces
'monokai
'(py-object-reference-face ((t (:foreground "#FFA500"))))
'(py-decorators-face ((t (:foreground "#FFA500"))))
'(py-variable-name-face ((t (:foreground "#FFA500"))))
'(py-exception-name-face ((:foreground "#FFA500")))
'(py-class-name-face ((:foreground "#FFA500")))
'(py-pseudo-keyword-face ((:foreground "#FFA500")))
'(py-builtins-face ((:foreground "#FFA500"))))))
(add-hook 'after-load-theme-hook 'customize-monokai)))
(load-theme 'monokai t)
#+END_SRC
** Centaur-tabs
#+BEGIN_SRC emacs-lisp
(use-package centaur-tabs
:demand
:config
(setq
centaur-tabs-set-icons t
centaur-tabs-gray-out-icons 'buffer
centaur-tabs-height 32
centaur-tabs-set-modified-marker t
centaur-tabs-modified-marker "•"
centaur-tabs-set-bar 'under
x-underline-at-descent-line t
centaur-tabs-style "wave")
(centaur-tabs-headline-match)
(centaur-tabs-mode t)
; TODO: configure centaur-tabs-active-bar-face and colors
:general (leader-key
"bg" '(centaur-tabs-counsel-switch-group :which-key "choose tab group")
"b M-p" '(centaur-tabs-backward-group :which-key "previous group")
"b M-n" '(centaur-tabs-forward-group :which-key "next group")
"bp" '(centaur-tabs-backward-tab :which-key "previous tab")
"bn" '(centaur-tabs-forward-tab :which-key "next tab")))
#+END_SRC
#+BEGIN_SRC emacs-lisp
(defun centaur-tabs-hide-tab (x)
"Do no to show buffer X in tabs."
(let ((name (format "%s" x)))
(or
;; Current window is not dedicated window.
(window-dedicated-p (selected-window))
;; Buffer name not match below blacklist.
(string-prefix-p "*epc" name)
(string-prefix-p "*helm" name)
(string-prefix-p "*Helm" name)
(string-prefix-p "*Compile-Log*" name)
(string-prefix-p "*lsp" name)
(string-prefix-p "*company" name)
(string-prefix-p "*Flycheck" name)
(string-prefix-p "*tramp" name)
(string-prefix-p " *Mini" name)
(string-prefix-p "*help" name)
(string-prefix-p "*straight" name)
(string-prefix-p " *temp" name)
(string-prefix-p "*Help" name)
(string-prefix-p "*mybuf" name)
;; Is not magit buffer.
(and (string-prefix-p "magit" name)
(not (file-name-extension name)))
)))
#+END_SRC
** Modeline
#+BEGIN_SRC emacs-lisp
(use-package doom-modeline
:init (doom-modeline-mode 1)
:config
;; How tall the mode-line should be. It's only respected in GUI.
;; If the actual char height is larger, it respects the actual height.
(setq doom-modeline-height 25)
;; How wide the mode-line bar should be. It's only respected in GUI.
(setq doom-modeline-bar-width 3)
;; The limit of the window width.
;; If `window-width' is smaller than the limit, some information won't be displayed.
(setq doom-modeline-window-width-limit fill-column)
;; How to detect the project root.
;; The default priority of detection is `ffip' > `projectile' > `project'.
;; nil means to use `default-directory'.
;; The project management packages have some issues on detecting project root.
;; e.g. `projectile' doesn't handle symlink folders well, while `project' is unable
;; to hanle sub-projects.
;; You can specify one if you encounter the issue.
(setq doom-modeline-project-detection 'project)
;; Determines the style used by `doom-modeline-buffer-file-name'.
;;
;; Given ~/Projects/FOSS/emacs/lisp/comint.el
;; auto => emacs/lisp/comint.el (in a project) or comint.el
;; truncate-upto-project => ~/P/F/emacs/lisp/comint.el
;; truncate-from-project => ~/Projects/FOSS/emacs/l/comint.el
;; truncate-with-project => emacs/l/comint.el
;; truncate-except-project => ~/P/F/emacs/l/comint.el
;; truncate-upto-root => ~/P/F/e/lisp/comint.el
;; truncate-all => ~/P/F/e/l/comint.el
;; truncate-nil => ~/Projects/FOSS/emacs/lisp/comint.el
;; relative-from-project => emacs/lisp/comint.el
;; relative-to-project => lisp/comint.el
;; file-name => comint.el
;; buffer-name => comint.el<2> (uniquify buffer name)
;;
;; If you are experiencing the laggy issue, especially while editing remote files
;; with tramp, please try `file-name' style.
;; Please refer to https://github.com/bbatsov/projectile/issues/657.
(setq doom-modeline-buffer-file-name-style 'relative-to-project)
;; Whether display icons in the mode-line.
;; While using the server mode in GUI, should set the value explicitly.
(setq doom-modeline-icon (display-graphic-p))
;; Whether display the icon for `major-mode'. It respects `doom-modeline-icon'.
(setq doom-modeline-major-mode-icon nil)
;; Whether display the colorful icon for `major-mode'.
;; It respects `all-the-icons-color-icons'.
(setq doom-modeline-major-mode-color-icon nil)
;; Whether display the icon for the buffer state. It respects `doom-modeline-icon'.
(setq doom-modeline-buffer-state-icon t)
;; Whether display the modification icon for the buffer.
;; It respects `doom-modeline-icon' and `doom-modeline-buffer-state-icon'.
(setq doom-modeline-buffer-modification-icon t)
;; Whether to use unicode as a fallback (instead of ASCII) when not using icons.
(setq doom-modeline-unicode-fallback nil)
;; Whether display the minor modes in the mode-line.
(setq doom-modeline-minor-modes nil)
;; If non-nil, a word count will be added to the selection-info modeline segment.
(setq doom-modeline-enable-word-count nil)
;; Major modes in which to display word count continuously.
;; Also applies to any derived modes. Respects `doom-modeline-enable-word-count'.
;; If it brings the sluggish issue, disable `doom-modeline-enable-word-count' or
;; remove the modes from `doom-modeline-continuous-word-count-modes'.
(setq doom-modeline-continuous-word-count-modes '(markdown-mode gfm-mode org-mode))
;; Whether display the buffer encoding.
(setq doom-modeline-buffer-encoding t)
;; Whether display the indentation information.
(setq doom-modeline-indent-info nil)
;; If non-nil, only display one number for checker information if applicable.
(setq doom-modeline-checker-simple-format t)
;; The maximum number displayed for notifications.
(setq doom-modeline-number-limit 99)
;; The maximum displayed length of the branch name of version control.
(setq doom-modeline-vcs-max-length 12)
;; Whether display the workspace name. Non-nil to display in the mode-line.
(setq doom-modeline-workspace-name t)
;; Whether display the perspective name. Non-nil to display in the mode-line.
(setq doom-modeline-persp-name t)
;; If non nil the default perspective name is displayed in the mode-line.
(setq doom-modeline-display-default-persp-name nil)
;; If non nil the perspective name is displayed alongside a folder icon.
(setq doom-modeline-persp-icon t)
;; Whether display the `lsp' state. Non-nil to display in the mode-line.
(setq doom-modeline-lsp t)
;; Whether display the GitHub notifications. It requires `ghub' package.
(setq doom-modeline-github nil)
;; The interval of checking GitHub.
(setq doom-modeline-github-interval (* 30 60))
;; Whether display the modal state icon.
;; Including `evil', `overwrite', `god', `ryo' and `xah-fly-keys', etc.
(setq doom-modeline-modal-icon nil)
;; Whether display the mu4e notifications. It requires `mu4e-alert' package.
(setq doom-modeline-mu4e nil)
;; Whether display the gnus notifications.
(setq doom-modeline-gnus t)
;; Whether gnus should automatically be updated and how often (set to 0 or smaller than 0 to disable)
(setq doom-modeline-gnus-timer 2)
;; Whether groups should be excludede when gnus automatically being updated.
(setq doom-modeline-gnus-excluded-groups '("dummy.group"))
;; Whether display the IRC notifications. It requires `circe' or `erc' package.
(setq doom-modeline-irc t)
;; Function to stylize the irc buffer names.
(setq doom-modeline-irc-stylize 'identity)
;; Whether display the environment version.
(setq doom-modeline-env-version t)
;; Or for individual languages
(setq doom-modeline-env-enable-python t)
(setq doom-modeline-env-enable-ruby t)
(setq doom-modeline-env-enable-perl t)
(setq doom-modeline-env-enable-go t)
(setq doom-modeline-env-enable-elixir t)
(setq doom-modeline-env-enable-rust t)
;; Change the executables to use for the language version string
(setq doom-modeline-env-python-executable "python") ; or `python-shell-interpreter'
(setq doom-modeline-env-ruby-executable "ruby")
(setq doom-modeline-env-perl-executable "perl")
(setq doom-modeline-env-go-executable "go")
(setq doom-modeline-env-elixir-executable "iex")
(setq doom-modeline-env-rust-executable "rustc")
;; What to dispaly as the version while a new one is being loaded
(setq doom-modeline-env-load-string "...")
;; Hooks that run before/after the modeline version string is updated
(setq doom-modeline-before-update-env-hook nil)
(setq doom-modeline-after-update-env-hook nil))
(column-number-mode)
#+END_SRC
** Fonts
#+BEGIN_SRC emacs-lisp
(set-face-attribute 'default nil
:family "Fira Code"
:height 130
:weight 'normal
:width 'normal)
; (setq doom-font (font-spec :family "Fira Code" :size 16 :weight 'regular)
; doom-variable-pitch-font (font-spec :family "Droid Sans" :size 13)
; doom-big-font (font-spec :family "Droid Sans" :size 16)) ;; Presentations or streaming
(set-fontset-font (frame-parameter nil 'font)
'japanese-jisx0208
'("Droid Sans Japanese" . "unicode-bmp"))
#+END_SRC
Use the fira-code-mode plugin for ligatures.
In order for this to work, the [[https://github.com/tonsky/FiraCode/issues/211#issuecomment-239058632][Fira Code Symbol]] font is needed
#+BEGIN_SRC emacs-lisp
(use-package fira-code-mode
:custom (fira-code-mode-disabled-ligatures '("x", "[]"))
:hook prog-mode)
#+END_SRC
** Dashboard
#+BEGIN_SRC emacs-lisp
(use-package dashboard
:init
(setq dashboard-set-heading-icons t)
(setq dashboard-set-file-icons t)
(setq dashboard-image-banner-max-height (/ (frame-pixel-height) 3))
(setq dashboard-startup-banner (concat user-emacs-directory "/logo.svg"))
; (setq dashboard-startup-banner (concat user-emacs-directory "/logo.svg"))
(setq dashboard-center-content t)
(setq dashboard-items '((recents . 10)
(projects . 5)
(agenda . 5)
(bookmarks . 10)))
(setq dashboard-projects-switch-function 'counsel-projectile-switch-project-by-name)
(dashboard-setup-startup-hook)
:custom
; (dashboard-banner-logo-title "Execution >> Idea")
(dashboard-banner-logo-title "Emacs")
:config
(set-face-attribute 'dashboard-banner-logo-title nil :font "Droid Sans" :height 300))
#+END_SRC
** Window
#+BEGIN_SRC emacs-lisp
(scroll-bar-mode -1)
(tool-bar-mode -1)
(menu-bar-mode -1)
#+END_SRC
** Editor
#+BEGIN_SRC emacs-lisp
(global-display-line-numbers-mode)
(setq
display-line-numbers-type 'relative
scroll-margin 5)
;; Disable line numbers for some modes
(dolist (mode '(term-mode-hook
shell-mode-hook
treemacs-mode-hook
eshell-mode-hook))
(add-hook mode (lambda () (display-line-numbers-mode 0))))
(setq display-line-numbers-type 'relative)
(setq evil-normal-state-cursor '(box "#66d9ef")
evil-insert-state-cursor '(bar "#a6e22e")
evil-visual-state-cursor '(hollow "orange"))
#+END_SRC
*** Rainbow parenthesis
#+BEGIN_SRC emacs-lisp
(use-package rainbow-delimiters
:hook (prog-mode . rainbow-delimiters-mode))
#+END_SRC
** Misc
* IDE Tools
** LSP
Setup to activate every time LSP gets activated
Adds the relative path to the project root into the header
#+BEGIN_SRC emacs-lisp
(defun lsp-mode-setup ()
(setq lsp-headerline-breadcrumb-segments '(path-up-to-project file symbols))
(lsp-headerline-breadcrumb-mode)
(general-nmap
"gr" 'lsp-find-references
"gd" 'lsp-find-definition
"gf" 'find-file-at-point))
#+END_SRC
#+BEGIN_SRC emacs-lisp
(use-package lsp-mode
:commands (lsp lsp-deferred)
:hook (
(lsp-mode . lsp-mode-setup)
(lsp-mode . lsp-enable-which-key-integration))
:init (setq
lsp-keymap-prefix "C-c l"
lsp-completion-provider :capf)
:config (setq
lsp-inhibit-message t
lsp-eldoc-render-all nil
lsp-enable-file-watchers t
lsp-enable-snippet t
lsp-enable-symbol-highlighting t
lsp-headerline-breadcrumb-enable t
lsp-highlight-symbol-at-point t
lsp-modeline-code-actions-enable t
lsp-modeline-diagnostics-enable t
lsp-ui-doc-position 'right
lsp-ui-doc-max-height 40
lsp-ui-doc-enable nil
lsp-ui-sideline-delay 0.05
lsp-ui-sideline-show-code-actions nil)
(lsp-enable-which-key-integration t)
(add-to-list 'company-backends '(company-capf company-dabbrev))
:bind (
:map lsp-mode-map
("M-RET" . lsp-execute-code-action))
:general (leader-key
"l" (general-simulate-key "C-c l" :which-key "LSP"))
([remap xref-find-references] #'lsp-ui-peek-find-references)
([remap xref-find-definitions] 'lsp-ui-peek-find-definitions)
(leader-key
"j" '(:ignore t :which-key "LSP OWN")
"ja" 'lsp-format-buffer
"jf" 'lsp-format-buffer
"jh" 'lsp-describe-thing-at-point
"jr" 'lsp-restart-workspace
"jd" 'lsp-goto-implementation
"jt" 'lsp-goto-type-definition
"jx" 'lsp-ui-doc-mode
"j <f2>" 'lsp-rename)
(general-nmap
"K" 'lsp-ui-doc-glance))
#+END_SRC
*** lsp-ui
All the config for lsp-ui can be found in the lsp block.
This is because lsp automatically loads lsp-ui and any code inside this block will not get executed.
This is only in order to install lsp-ui.
#+BEGIN_SRC emacs-lisp
(use-package lsp-ui)
#+END_SRC
*** lsp-treemacs
Treemacs integration for lsp-mode.
Mainly used in order to see the tree of objects, functions and so on.
#+BEGIN_SRC emacs-lisp
(use-package lsp-treemacs
:after (lsp treemacs)
:hook (lsp-mode . lsp-treemacs-sync-mode))
#+END_SRC
*** lsp-ivy
Ivy integration for lsp-mode.
Mainly used in order to choose from the tree of objects, functions and so on.
#+BEGIN_SRC emacs-lisp
(use-package lsp-ivy
:after lsp
:commands lsp-ivy-workspace-symbol)
#+END_SRC
** Completion
#+BEGIN_SRC emacs-lisp
(use-package company
:init (setq
company-idle-delay 0.1 ; show autocompletion after n seconds
company-async-timeout 15 ; completion may be slow
company-tooltip-idle-delay 0.1
company-minimum-prefix-length 1 ; show suggestions after only one character (insted of several)
company-tooltip-align-annotations t)
(add-to-list 'company-backends 'company-files)
:hook (prog-mode . company-mode)
:bind (("C-RET" . counsel-company)
:map prog-mode-map
("C-i" . company-indent-or-complete-common)
("C-;" . counsel-company)
("C-M-i" . counsel-company)
:map company-active-map
; ("C-o" . company-search-kill-others)
; ("C-h" . company-quickhelp-manual-begin)
("C-h" . company-show-doc-buffer)
("C-s" . company-search-candidates)
("M-s" . company-filter-candidates)
([C-tab] . company-complete-common-or-cycle)
([tab] . company-complete-common-or-cycle)
([backtab] . company-select-previous)
;; ("M-RET" . company-complete-selection)
("RET" . company-complete-selection)
:map company-search-map
;; ("M-j" . company-select-next)
;; ("M-k" . company-select-previous)
("C-p" . company-select-next-or-abort)
("C-n" . company-select-previous-or-abort))
;; ("C-n" . 'company-search-repeat-forward)
;; ("C-p" . 'company-search-repeat-backward)))
;; ("<esc>" . (cmd! (company-search-abort) (company-filter-candidates)))))
:config
(general-define-key
"C-SPC" 'company-capf))
#+END_SRC
Nice looking completions
#+BEGIN_SRC elisp
(use-package company-box
:hook (company-mode . company-box-mode))
#+END_SRC
** Debugging
*** Flycheck mode
#+BEGIN_SRC emacs-lisp
(use-package flycheck
:config
(setq
flycheck-highlighting-mode 'lines)
(set-face-attribute 'flycheck-error nil
:family "Fira Code"
:background "#773131"
:weight 'normal
:width 'normal)
(set-face-attribute 'flycheck-warning nil
:family "Fira Code"
:background "#767731"
:weight 'normal
:width 'normal)
:general (leader-key
"!" (general-simulate-key "C-u C-c !" :which-key "Flycheck")))
(global-flycheck-mode 1)
#+END_SRC
** Documentation
#+BEGIN_SRC elisp
#+END_SRC
*** Helpful
#+BEGIN_SRC elisp
(use-package helpful
:custom
(counsel-describe-function-function #'helpful-callable)
(counsel-describe-variable-function #'helpful-variable)
:bind
([remap describe-function] . counsel-describe-function)
([remap describe-command] . helpful-command)
([remap describe-variable] . counsel-describe-variable)
([remap describe-key] . helpful-key))
#+END_SRC
** Project Management
#+BEGIN_SRC elisp
(use-package projectile
:init
(setq projectile-project-search-path '("~/git/"
"~/git/temp/"
"~/git/appkom/"
"~/git/pvv/"))
(setq projectile-switch-project-action #'projectile-dired)
:custom ((projectile-completion-system 'ivy))
:bind-keymap ("C-c p" . projectile-command-map)
:config (projectile-mode)
:general (leader-key
;; File path
"fR" 'projectile-recentf
"fa" 'projectile-ag
;; "fyC" 'spacemacs/projectile-copy-file-path-with-line-column
;; "fyD" 'spacemacs/projectile-copy-directory-path
;; "fyL" 'spacemacs/projectile-copy-file-path-with-line
;; "fyY" 'spacemacs/projectile-copy-file-path
;; Project
"p" '(:ignore t :which-key "projectile")
"p!" 'projectile-run-shell-command-in-root
"p&" 'projectile-run-async-shell-command-in-root
"p%" 'projectile-replace-regexp
"pa" 'projectile-toggle-between-implementation-and-test
"pb" 'projectile-switch-to-buffer
"pc" 'projectile-compile-project
"pd" 'projectile-find-dir
"pD" 'projectile-dired
"pe" 'projectile-edit-dir-locals
"pf" 'projectile-find-file
"pF" 'projectile-find-file-dwim
"pg" 'projectile-find-tag
"pG" 'projectile-regenerate-tags
"pI" 'projectile-invalidate-cache
"pk" 'projectile-kill-buffers
"pp" 'projectile-switch-project
"pr" 'projectile-recentf
"pR" 'projectile-replace
"pT" 'projectile-test-project
"pv" 'projectile-vc))
#+END_SRC
** REST Client
restclient
** Search
Swiper is used for finding local occurences of a word inside a buffer.
#+BEGIN_SRC elisp
(use-package swiper
:general (leader-key
"s" '(swiper :which-key "search")))
#+END_SRC
Ag is used for project-wide search
** Snippets
Yasnippet
#+BEGIN_SRC emacs-lisp
(use-package yasnippet
:init (yas-global-mode t)
:config (yas-reload-all)
:general (leader-key
"y" '(:ignore t :which-key "yasnippet")
"yn" '(yas-new-snippet :which-key "New snippet")
;; "yi" '(yas-insert-snippet :which-key "Insert snippet")
"y/" '(yas-visit-snippet-file :which-key "Find global snippet")
"yr" '(yas-reload-all :which-key "Reload snippets")
"yv" '(yas-describe-tables :which-key "View loaded snippets")))
#+END_SRC
For easy selection of snippets
#+BEGIN_SRC emacs-lisp
(use-package ivy-yasnippet
:after yasnippet
:general (leader-key
"yi" '(ivy-yasnippet :which-key "Insert snippet")))
#+END_SRC
Add yasnippet support for all company backends
https://github.com/syl20bnr/spacemacs/pull/179
https://emacs.stackexchange.com/questions/10431/get-company-to-show-suggestions-for-yasnippet-names
#+BEGIN_SRC emacs-lisp
(defvar company-mode/enable-yas t
"Enable yasnippet for all backends.")
(defun company-mode/backend-with-yas (backend)
(if (or (not company-mode/enable-yas) (and (listp backend) (member 'company-yasnippet backend)))
backend
(append (if (consp backend) backend (list backend))
'(:with company-yasnippet))))
(setq company-backends (mapcar #'company-mode/backend-with-yas company-backends))
#+END_SRC
** Todo
#+BEGIN_SRC elisp
(use-package hl-todo
:ensure t
:custom-face
(hl-todo ((t (:inherit hl-todo :italic t))))
:hook ((prog-mode . hl-todo-mode)
(yaml-mode . hl-todo-mode)))
#+END_SRC
** Version Control
#+BEGIN_SRC emacs-lisp
(use-package magit
:general (leader-key
"g" '(:ignore t :which-key "git")
"g/" '(magit-dispatch :which-key "Magit dispatch")
"g." '(magit-file-dispatch :which-key "Magit file dispatch")
;; "g'" '(forge-dispatch :which-key "Forge dispatch")
"gg" '(magit-status :which-key "Magit status")
"gG" '(magit-status-here :which-key "Magit status here")
"gx" '(magit-file-delete :which-key "Magit file delete")
"gB" '(magit-blame-addition :which-key "Magit blame")
"gC" '(magit-clone :which-key "Magit clone")
"gF" '(magit-fetch :which-key "Magit fetch")
"gL" '(magit-log :which-key "Magit buffer log")
"gS" '(magit-stage-file :which-key "Git stage file")
"gU" '(magit-unstage-file :which-key "Git unstage file")
"gf" '(:ignore t :which-key "find")
"gff" '(magit-find-file :which-key "Find file")
"gfg" '(magit-find-git-config-file :which-key "Find gitconfig file")
"gfc" '(magit-show-commit :which-key "Find commit")
"gl" '(:ignore t :which-key "list")
;; "glg" '(gist-list :which-key "List gists")
"glr" '(magit-list-repositories :which-key "List repositories")
"gls" '(magit-list-submodules :which-key "List submodules")
;; "gli" '(forge-list-issues :which-key "List issues")
;; "glp" '(forge-list-pullreqs :which-key "List pull requests")
;; "gln" '(forge-list-notifications :which-key "List notifications")
"gc" '(:ignore t :which-key "create")
"gcr" '(magit-init :which-key "Initialize repo")
"gcR" '(magit-clone :which-key "Clone repo")
"gcc" '(magit-commit-create :which-key "Commit")
"gcf" '(magit-commit-fixup :which-key "Fixup")))
;; "gci" '(forge-create-issue :which-key "Issue")
;; "gcp" '(forge-create-pullreq :which-key "Pull request")))
#+END_SRC
#+BEGIN_SRC emacs-lisp
(use-package git-gutter
:init
(global-git-gutter-mode 1))
#+END_SRC
* Langugages
** C/C++
** Dart / Flutter
#+BEGIN_SRC emacs-lisp
(use-package dart-mode
:mode "\\.dart\\'")
(use-package lsp-dart
:hook 'dart-mode-hook)
#+END_SRC
** Elm
Major mode for elm
#+BEGIN_SRC emacs-lisp
(use-package elm-mode
:mode ("\\.elm\\'" . elm-mode)
:after (company)
:config (add-to-list 'company-backends 'elm-company)
:general (leader-key elm-mode-map
"mc" '(:ignore t :which-key "compile")
"mcb" 'elm-compile-buffer
"mcm" 'elm-compile-main
"mct" 'elm-test-project
"mcr" 'elm-reactor
"mcb" 'elm-preview-buffer
"mcp" 'elm-preview-main
"mh" '(:ignore t :which-key "docs")
"mhd" 'elm-documentation-lookup
"mhh" 'elm-oracle-doc-at-point
"mht" 'elm-oracle-type-at-point
"m." 'elm-repl-load
"mp" 'elm-repl-push
"md" 'elm-repl-push-decl
"mi" 'elm-import
"me" 'elm-expose-at-point
"ms" 'elm-sort-imports
"mf" 'elm-format-buffer
"mv" 'elm-package-catalog))
#+END_SRC
Proper error-providing to flycheck to flycheck
#+BEGIN_SRC emacs-lisp
(use-package flycheck-elm
:after (flycheck elm-mode)
:hook (elm-mode-hook . flycheck-elm-setup))
#+END_SRC
LSP mode
install via
#+BEGIN_SRC bash :tangle no
npm i -g @elm-tooling/elm-language-server
#+END_SRC
#+BEGIN_SRC emacs-lisp
(add-hook 'elm-mode-hook 'lsp)
#+END_SRC
** Emacs Lisp
Package for highlighting defined macros/functions/variables/symbols in emacs
#+BEGIN_SRC emacs-lisp
(use-package highlight-defined
:config
(add-hook 'emacs-lisp-mode-hook 'highlight-defined-mode))
#+END_SRC
** Haskell
Major mode for haskell
#+BEGIN_SRC emacs-lisp
(use-package haskell-mode
:general (leader-key haskell-mode-map
"mh" '(haskell-hide-toggle :which-key "hide")
"mH" '(haskell-hide-toggle-all :which-key "hide all")
"mc" '(:ignore t :which-key "cabal")
"mcf" '(haskell-cabal-visit-file :which-key "cabal file")
"mcb" '(haskell-process-cabal-build :which-key "build")))
#+END_SRC
Hlint is a linter for suggesting better ways to write certain pieces of code.
It requires [[https://github.com/mpickering/apply-refact][apply-refact]] to be installed
#+BEGIN_SRC emacs-lisp
(use-package hlint-refactor
:hook (haskell-mode-hook . hlint-refactor-mode)
:general (leader-key haskell-mode-map
"mr" '(hlint-refactor-refactor-buffer :which-key "refactor suggestion")))
#+END_SRC
Hindent is a reformatter for properly indenting haskell code (haskell can be quite picky about the indentation, so this is actually pretty useful not only for readability).
It requires the hindent executable
#+BEGIN_SRC emacs-lisp
(use-package hindent
:hook (haskell-mode-hook . hindent-mode))
#+END_SRC
#+BEGIN_SRC emacs-lisp
(use-package lsp-haskell
:hook (haskell-mode-hook . lsp)
(haskell-literate-mode-hook . lsp))
#+END_SRC
flycheck-haskell?
ghc ?
** Java
Java LSP using the Eclipse JDT Language server
install jdtls from AUR
#+BEGIN_SRC emacs-lisp
(use-package lsp-java
:init
; (setq lsp-java-server-install-dir "/usr/share/java/jdtls/")
(setenv "JAVA_HOME" "/usr/lib/jvm/default")
(setq
lsp-java-java-path (substitute-in-file-name "$JAVA_HOME/bin/java")
lsp-java-jdt-download-url "https://download.eclipse.org/jdtls/snapshots/jdt-language-server-latest.tar.gz")
; :hook (java-mode-hook . lsp)
:config
(add-hook 'java-mode-hook 'flycheck-mode)
(add-hook 'java-mode-hook 'company-mode)
(add-hook 'java-mode-hook 'lsp)
:general (leader-key java-mode-map
;; LSP Java commands
"mi" '(lsp-java-organize-imports :which-key "Organize imports")
"mc" '(lsp-java-build-project :which-key "Perform partial or full build for the projects")
;; lsp-java-update-project-configuration - Update project configuration
;; lsp-java-actionable-notifications - Resolve actionable notifications
;; lsp-java-update-user-settings - Update user settings (Check the options in the table bellow.)
;; lsp-java-update-server - Update server instalation.
"mg" '(:ignore t :which-key "Generate")
"mgs" '(lsp-java-generate-to-string :which-key "Generate toString method")
"mge" '(lsp-java-generate-equals-and-hash-code :which-key "Generate equals and hashCode methods")
"mgo" '(lsp-java-generate-overrides :which-key "Generate method overrides")
"mgg" '(lsp-java-generate-getters-and-setters :which-key "Generate getters and setters")
;; Refactoring
;; LSP Java provides rich set of refactorings via Eclipse JDT Language Server code actions and some of them are bound to Emacs commands:
"mr" '(:ignore t :which-key "Refactor")
"mr" '(lsp-java-extract-to-constant :which-key "Extract constant refactoring")
"mr" '(lsp-java-add-unimplemented-methods :which-key "Extract constant refactoring")
"mr" '(lsp-java-create-parameter :which-key "Create parameter refactoring")
"mr" '(lsp-java-create-field :which-key "Create field refactoring")
"mr" '(lsp-java-create-local :which-key "Create local refactoring")
"mr" '(lsp-java-extract-method :which-key "Extract method refactoring")
"mr" '(lsp-java-add-import :which-key "Add missing import")
;; Testing support
"mt" '(:ignore t :which-key "JUnit")
"mtr" '(lsp-jt-report-open :which-key "open test report")
"mtb" '(lsp-jt-browser :which-key "Browse tests and run/debug them.")
;; ^^^ ** Use x to run the test(s) under point; d to debug the tests under point. R to refresh. ** Support for GUI operations.
"mtl" '(lsp-jt-lens-mode :which-key "test lenses mode")
;; Dependency viewer
"md" '(lsp-java-dependency-list :which-key "View java dependencies")))
#+END_SRC
Maven integration
#+BEGIN_SRC emacs-lisp
(use-package maven-test-mode
:hook (java-mode-hook . maven-test-mode)
;; (spacemacs/declare-prefix-for-mode 'java-mode "mm" "maven")
;; (spacemacs/declare-prefix-for-mode 'java-mode "mmg" "goto")
;; (spacemacs/declare-prefix-for-mode 'java-mode "mmt" "tests"))
;; :config
;; (progn
;; (spacemacs|hide-lighter maven-test-mode)
;; (spacemacs/set-leader-keys-for-minor-mode 'maven-test-mode
:general (leader-key maven-test-mode-map
"mm" '(:ignore t :which-key "Maven")
"mmga" 'maven-test-toggle-between-test-and-class
"mmgA" 'maven-test-toggle-between-test-and-class-other-window
"mmta" 'maven-test-all
"mmt C-a" 'maven-test-clean-test-all
"mmtb" 'maven-test-file
"mmti" 'maven-test-install
"mmtt" 'maven-test-method))
#+END_SRC
#+BEGIN_SRC emacs-lisp
#+END_SRC
malabar-mode
emacs-eclim ?
** JavaScript / TypeScript
Typescript mode and hook for activating lsp
#+BEGIN_SRC emacs-lisp
(use-package typescript-mode
:mode "\\.ts\\'"
:hook (typescript-mode . lsp)
:config
(setq typescript-indent-level 2))
#+END_SRC
Install lsp server with
#+BEGIN_SRC bash :tangle no
npm i -g typescript-language-server; npm i -g typescript
#+END_SRC
js2-mode
js-doc
js2-refactor
npm.el
** Json
#+BEGIN_SRC emacs-lisp
(use-package json-mode
:mode "\\.js\\(?:on\\|[hl]int\\(?:rc\\)?\\)\\'"
:hook (json-mode . lsp)
; :config
; (set-electric! 'json-mode :chars '(?\n ?: ?{ ?}))
:general (leader-key json-mode-map
"mp" '(json-mode-show-path :which-key "Copy path")
"mt" 'json-toggle-boolean
"md" 'json-mode-kill-path
"mx" 'json-nullify-sexp
"m+" 'json-increment-number-at-point
"m-" 'json-decrement-number-at-point
"mf" 'json-mode-beautify))
#+END_SRC
(use-package! counsel-jq
:when (featurep! :completion ivy)
:defer t
:init
(map! :after json-mode
:map json-mode-map
:localleader
"s" #'counsel-jq))
** LaTeX
AUCTeX
The reason the package is called "tex" and not "auctex" is explained [[https://emacs.stackexchange.com/questions/41321/when-to-specify-a-package-name-in-use-packages-ensure-tag/41324#41324][here]]
#+BEGIN_SRC emacs-lisp
(use-package tex
;; :after (pdf-tools)
:ensure auctex
:mode ("\\.tex\\'" . LaTeX-mode)
:config
(setq
TeX-source-correlate-method 'synctex
TeX-source-correlate-start-server t
TeX-auto-save t
TeX-parse-self t
; reftex-plug-into-AUCTeX t
TeX-PDF-mode t) ; Use PDF instead of DVI
(setq-default
TeX-master "main.tex"
TeX-engine 'default) ; default | xetex | luatex
(TeX-source-correlate-mode t) ;
(add-hook 'LaTeX-mode-hook
(lambda ()
(reftex-mode t)
(flyspell-mode t)))
:general (leader-key
"mc" '(TeX-command-run-all :which-key "Compile")
"me" '(TeX-engine-set :which-key "Set engine")
"mv" '(TeX-view :which-key "view")))
#+END_SRC
Completions for AUCTeX
#+BEGIN_SRC emacs-lisp
(use-package company-auctex
:after auctex
:hook LaTeX-mode
:config
(company-auctex-init)
(add-to-list 'company-backends 'company-yasnippet)
(company-mode))
;; :config
;; (add-to-list '+latex--company-backends #'company-auctex-environments nil #'eq)
;; (add-to-list '+latex--company-backends #'company-auctex-macros nil #'eq))
#+END_SRC
Support for compiling documents with the LaTeXmk tool
#+BEGIN_SRC emacs-lisp
(use-package auctex-latexmk
:after auctex
(auctex-latexmk-setup)
(setq auctex-latexmk-inherit-TeX-PDF-mode t))
#+END_SRC
PDF viewer
#+BEGIN_SRC emacs-lisp
(use-package pdf-tools
;; :hook
;; (add-hook 'pdf-view-mode-hook (lambda ()
;; (bms/pdf-midnite-amber))) ; automatically turns on midnight-mode for pdfs
:init
;; (pdf-tools-install)
(setq
TeX-view-program-selection '((output-pdf "pdf-tools"))
TeX-view-program-list '(("pdf-tools" "TeX-pdf-tools-sync-view")))
:config
(setq-default pdf-view-display-size 'fit-page)
(setq pdf-annot-activate-created-annotations t)
(add-hook 'TeX-after-compilation-finished-functions ;; Update PDF buffers after successful LaTeX runs
#'TeX-revert-document-buffer)
:general (leader-key pdf-view-mode-map
"mf" 'isearch-forward
"mb" 'isearch-backward))
#+END_SRC
Some functions to help with efficient writing of environments etc.
#+BEGIN_SRC emacs-lisp
(use-package cdlatex
:general (leader-key
"mis" 'cdlatex-sub-superscript
"mip" 'cdlatex-lr-pair
"mie" 'cdlatex-environment))
#+END_SRC
Preview math inside the buffer
#+BEGIN_SRC emacs-lisp
;; (use-package math-preview)
;; (use-package preview-latex)
#+END_SRC
Preview pane
#+BEGIN_SRC emacs-lisp
; (use-package latex-preview-pane)
#+END_SRC
#+BEGIN_SRC emacs-lisp
; (use-package lsp-latex)
#+END_SRC
Some math functions
#+BEGIN_SRC emacs-lisp
(leader-key LaTeX-mode-map
"mm" '(:ignore t :which-key "Insert math")
"mm^" '(LaTeX-math-wedge :which-key "")
"mmv" '(LaTeX-math-vee :which-key "")
"mm=>" '(LaTeX-math-Rightarrow :which-key "=>")
"mm->" '(LaTeX-math-rightarrow :which-key "->")
"mm<==" '(LaTeX-math-Leftarrow :which-key "<=")
"mm<-" '(LaTeX-math-leftarrow :which-key "<-")
"mm<=>" '(LaTeX-math-Leftrightarrow :which-key "<=>")
"mm==" '(LaTeX-math-equiv :which-key "")
"mm!=" '(LaTeX-math-neq :which-key "")
"mmn" '(LaTeX-math-neg :which-key "¬")
"mma" '(LaTeX-math-forall :which-key "")
"mme" '(LaTeX-math-exists :which-key "")
"mmt" '(LaTeX-math-top :which-key "")
"mmT" '(LaTeX-math-bot :which-key "")
"mm." '(LaTeX-math-therefore :which-key "")
"mm," '(LaTeX-math-because :which-key ""))
#+END_SRC
;; Nicely indent lines that have wrapped when visual line mode is activated
(use-package! adaptive-wrap
:hook (LaTeX-mode . adaptive-wrap-prefix-mode)
:init (setq-default adaptive-wrap-extra-indent 0))
(use-package! auctex-latexmk
:when (featurep! +latexmk)
:after latex
:init
;; Pass the -pdf flag when TeX-PDF-mode is active
(setq auctex-latexmk-inherit-TeX-PDF-mode t)
;; Set LatexMk as the default
(setq-hook! LaTeX-mode TeX-command-default "LatexMk")
:config
;; Add latexmk as a TeX target
(auctex-latexmk-setup))
(use-package! evil-tex
:when (featurep! :editor evil +everywhere)
:hook (LaTeX-mode . evil-tex-mode))
(use-package! company-auctex
:when (featurep! :completion company)
:defer t
:init
(add-to-list '+latex--company-backends #'company-auctex-environments nil #'eq)
(add-to-list '+latex--company-backends #'company-auctex-macros nil #'eq))
(use-package! company-math
:when (featurep! :completion company)
:defer t
:init
(add-to-list '+latex--company-backends #'+latex-symbols-company-backend nil #'eq))
*** NTNU style macros
- [ ] TODO: add support for indentation
#+BEGIN_SRC emacs-lisp
(defun ntnu/expand-truth-table ()
(interactive)
(save-excursion
(let
(start
end
(l/rep (lambda (pat repl)
(setq
start (evil-range-beginning (evil-visual-range))
end (evil-range-end (evil-visual-range)))
(replace-regexp pat repl nil start end))))
;; (evil-ex-substitute start end '("[tT]") "\\\\T" '("g")))))
(funcall l/rep "[tT]" "\\\\T")
(funcall l/rep "[fF]" "\\\\F")
(funcall l/rep " " " & ")
(funcall l/rep "$" " \\\\\\\\"))))
#+END_SRC
** Lua
** Markdown
#+BEGIN_SRC emacs-lisp
(use-package markdown-mode
:commands (markdown-mode gfm-mode)
:mode (("README\\.md\\'" . gfm-mode)
("\\.md\\'" . markdown-mode)
("\\.markdown\\'" . markdown-mode))
:init
(setq markdown-enable-math t ; syntax highlighting for latex fragments
markdown-enable-wiki-links t
markdown-italic-underscore t
markdown-asymmetric-header t
markdown-fontify-code-blocks-natively t
markdown-gfm-additional-languages '("sh")
markdown-make-gfm-checkboxes-buttons t
markdown-content-type "application/xhtml+xml"
markdown-css-paths
; markdown-command "multimarkdown"
'("https://cdn.jsdelivr.net/npm/github-markdown-css/github-markdown.min.css"
"https://cdn.jsdelivr.net/gh/highlightjs/cdn-release/build/styles/github.min.css")
markdown-xhtml-header-content
(concat "<meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'>"
"<style> body { box-sizing: border-box; max-width: 740px; width: 100%; margin: 40px auto; padding: 0 10px; } </style>"
"<script id='MathJax-script' async src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'></script>"
"<script src='https://cdn.jsdelivr.net/gh/highlightjs/cdn-release/build/highlight.min.js'></script>"
"<script>document.addEventListener('DOMContentLoaded', () => { document.body.classList.add('markdown-body'); document.querySelectorAll('pre[lang] > code').forEach((code) => { code.classList.add(code.parentElement.lang); }); document.querySelectorAll('pre > code').forEach((code) => { hljs.highlightBlock(code); }); });</script>"))
:general (leader-key markdown-mode-map
"m'" 'markdown-edit-code-block
"mo" 'markdown-open
"mp" 'markdown-preview
"me" 'markdown-export
; "mp" 'grip-mode)
"mi" '(:ignore t :which-key "insert")
; "mit" 'markdown-toc-generate-toc
"mii" 'markdown-insert-image
"mil" 'markdown-insert-link))
#+END_SRC
** Python
Major mode for python
#+BEGIN_SRC emacs-lisp
(use-package python-mode)
#+END_SRC
Palintirs python LSP server
To be installed from the arch community repos: python-language-server
#+BEGIN_SRC emacs-lisp
(setq lsp-pyls-plugins-autopep8-enabled nil)
(setq lsp-pyls-plugins-yapf-enabled t)
(add-hook 'python-mode-hook 'lsp)
#+END_SRC
#+BEGIN_SRC emacs-lisp
(defun prettify-python ()
(set-face-attribute font-lock-keyword-face nil :font "CMU Serif" :slant 'italic :height 160)
(setq prettify-symbols-alist '(
("def" . "f")
("lambda" . "λ")
("delta" . "Δ")
("for" . "")
("not in" . "")
("in" . "")
("return" . "")
("->" . "")
("\\n" . "")
("!=" . "")
("not" . "¬")
("and" . "^")
("or" . "")
("pi" . "π"))))
;; (add-hook 'python-mode-hook 'prettify-symbols-mode)
;; (add-hook 'python-mode-hook 'prettify-python)
#+END_SRC
** Rust
#+BEGIN_SRC emacs-lisp
(use-package rustic
:bind (:map rustic-mode-map
("M-j" . lsp-ui-imenu)
("M-?" . lsp-find-references)
("C-c C-c l" . flycheck-list-errors)
("C-c C-c a" . lsp-execute-code-action)
("C-c C-c r" . lsp-rename)
("C-c C-c q" . lsp-workspace-restart)
("C-c C-c Q" . lsp-workspace-shutdown)
("C-c C-c s" . lsp-rust-analyzer-status))
:config
;; uncomment for less flashiness
;; (setq lsp-eldoc-hook nil)
;; (setq lsp-enable-symbol-highlighting nil)
;; (setq lsp-signature-auto-activate nil)
;; comment to disable rustfmt on save
(setq rustic-format-on-save t)
(add-hook 'rustic-mode-hook 'rk/rustic-mode-hook))
(defun rk/rustic-mode-hook ()
;; so that run C-c C-c C-r works without having to confirm, but don't try to
;; save rust buffers that are not file visiting. Once
;; https://github.com/brotzeit/rustic/issues/253 has been resolved this should
;; no longer be necessary.
(when buffer-file-name
(setq-local buffer-save-without-query t)))
#+END_SRC
flycheck-rust
cargo.el - Cargo support for Emacs.
** Shellscripts
** Yaml
** Web-dev
#+BEGIN_SRC emacs-lisp
(use-package emmet-mode
:hook (sgml-mode-hook . emmet-mode)
(html-mode-hook . emmet-mode)
(css-mode-hook . emmet-mode))
#+END_SRC
web-m
** Config file languages
** Others
* Packages
** Drag stuff
#+BEGIN_SRC emacs-lisp
(use-package drag-stuff
:bind (("M-j" . drag-stuff-down)
("M-k" . drag-stuff-up)
;; ("M-h" . drag-left-stuff)
;; ("M-l" . drag-stuff-right)
))
#+END_SRC
** Emoji
#+BEGIN_SRC emacs-lisp
(use-package emojify
:hook (after-init-hook . global-emojify-mode)
:general (leader-key
"ie" 'emojify-insert-emoji))
#+END_SRC
** Lorem-Ipsum
#+BEGIN_SRC emacs-lisp
(use-package lorem-ipsum
:general (leader-key
"il" '(:ignore t :which-key "lorem ipsum")
"ill" 'lorem-ipsum-insert-list
"ils" 'lorem-ipsum-insert-sentences
"ilp" 'lorem-ipsum-insert-paragraphs))
#+END_SRC
** Multiple Cursors
evil-mc
#+BEGIN_SRC emacs-lisp
;; (use-package multiple-cursors
;; :general (leader-key
;; "d" '(:ignore t :which-key "multiple cursors")
;; "dl" '(mc/edit-lines :which-key "edit lines")
;; "dn" '(mc/mark-next-like-this :which-key "mark next")
;; "dN" '(mc/unmark-next-like-this :which-key "unmark next")
;; "dp" '(mc/mark-previous-like-this :which-key "mark previous")
;; "dP" '(mc/unmark-previous-like-this :which-key "unmark previous")
;; "dt" '(mc/mark-all-like-this :which-key "mark all")
;; "dm" '(mc/mark-all-like-this-dwim :which-key "mark all DWIM")
;; "de" '(mc/edit-ends-of-lines :which-key "edit line endings")
;; "da" '(mc/edit-beginnings-of-lines :which-key "edit line starts")
;; "ds" '(mc/mark-sgml-tag-pair :which-key "mark tag")
;; "dd" '(mc/mark-all-like-this-in-defun :which-key "mark in defun")))
;; "w<mouse-1>" '(mc/add-cursor-on-click :which-key "add cursor w/mouse")))
#+END_SRC
** Recentf
#+BEGIN_SRC emacs-lisp
(use-package recentf
:init (recentf-mode t)
:config
(add-to-list 'recentf-exclude (format "%s/\\.emacs\\.d/elpa/.*" (getenv "HOME")))
(add-to-list 'recentf-exclude "~/\\.emacs\\.d/elpa/.*")
:general (leader-key
"fr" 'counsel-recentf))
#+END_SRC
** Treemacs
#+BEGIN_SRC emacs-lisp
(use-package treemacs
:init
(with-eval-after-load 'winum
(define-key winum-keymap (kbd "M-0") 'treemacs-select-window))
:config
(progn
(setq treemacs-collapse-dirs (if (executable-find "python") 3 0)
treemacs-deferred-git-apply-delay 0.5
treemacs-display-in-side-window t
treemacs-file-event-delay 5000
treemacs-file-follow-delay 0.2
treemacs-follow-after-init t
treemacs-follow-recenter-distance 0.1
treemacs-git-command-pipe ""
treemacs-goto-tag-strategy 'refetch-index
treemacs-indentation 2
treemacs-indentation-string " "
treemacs-is-never-other-window nil
treemacs-max-git-entries 5000
treemacs-no-png-images nil
treemacs-no-delete-other-windows t
treemacs-project-follow-cleanup nil
treemacs-persist-file (expand-file-name ".cache/treemacs-persist" user-emacs-directory)
treemacs-recenter-after-file-follow nil
treemacs-recenter-after-tag-follow nil
treemacs-show-cursor nil
treemacs-show-hidden-files nil
treemacs-silent-filewatch nil
treemacs-silent-refresh nil
treemacs-sorting 'alphabetic-desc
treemacs-space-between-root-nodes t
treemacs-tag-follow-cleanup t
treemacs-tag-follow-delay 1.5
treemacs-width 35)
;; The default width and height of the icons is 22 pixels. If you are
;; using a Hi-DPI display, uncomment this to double the icon size.
;;(treemacs-resize-icons 44)
(treemacs-follow-mode t)
(treemacs-filewatch-mode t)
(treemacs-fringe-indicator-mode t)
(pcase (cons (not (null (executable-find "git")))
(not (null (executable-find "python3"))))
(`(t . t)
(treemacs-git-mode 'deferred))
(`(t . _)
(treemacs-git-mode 'simple))))
:bind
(:map global-map
("M-0" . treemacs-select-window)
("C-x t 1" . treemacs-delete-other-windows)
("C-x t t" . treemacs)
("C-x t B" . treemacs-bookmark)
("C-x t C-t" . treemacs-find-file)
("C-x t M-t" . treemacs-find-tag)))
:general (leader-key
"t" '(:ignore t :which-key "treemacs")
"tt" 'treemacs)
#+END_SRC
Evil navigation
#+BEGIN_SRC emacs-lisp
(use-package treemacs-evil
:after (treemacs evil))
#+END_SRC
Projectile integration
#+BEGIN_SRC emacs-lisp
(use-package treemacs-projectile
:after (treemacs projectile))
#+END_SRC
LSP integration
#+BEGIN_SRC emacs-lisp
(use-package lsp-treemacs
:after (treemacs lsp)
:config (lsp-treemacs-sync-mode 1))
#+END_SRC
Magit integration
#+BEGIN_SRC emacs-lisp
(use-package treemacs-magit
:after (treemacs magit))
#+END_SRC
Icons for dired
#+BEGIN_SRC emacs-lisp
(use-package treemacs-icons-dired
:after treemacs)
#+END_SRC
** Unicode
** Which-key
#+BEGIN_SRC emacs-lisp
(use-package which-key
:config
(setq which-key-idle-delay 0.3)
(setq which-key-popup-type 'frame)
(which-key-mode)
(which-key-setup-side-window-right-bottom)
; (which-key-setup-minibuffer)
(set-face-attribute 'which-key-local-map-description-face nil
:weight 'bold))
#+END_SRC
** Zen mode
Turns out 'zen-mode' was actually reserved for a programming language called Zen. Never heard of.
This will be covering the writeroom-mode package
#+BEGIN_SRC emacs-lisp
(use-package writeroom-mode
:config (setq fringes-outside-margins 1)
:general (leader-key
"z" '(writeroom-mode :which-key "zen")))
#+END_SRC
* Misc
** Input Methods
#+BEGIN_SRC emacs-lisp
(setq default-input-method nil)
;; (map! :leader
;; (:prefix-map ("l" . "language")
;; :desc "English" "e" (lambda () (interactive) (deactivate-input-method))
;; :desc "Japanese" "j" (lambda () (interactive) (set-input-method 'japanese))
;; :desc "Norwegian" "n" (lambda () (interactive) (set-input-method 'norwegian-keyboard))
;; :desc "Latin" "l" (lambda () (interactive) (set-input-method 'latin-1-postfix))
;; :desc "TeX" "t" (lambda () (interactive) (set-input-method 'TeX))))
#+END_SRC
** Comment Utils
Make a header comment using the [[https://github.com/cacalabs/toilet][toilet]] utility with the font pagga
░█▀█░█▀█░█▀▀░█▀▀░█▀█
░█▀▀░█▀█░█░█░█░█░█▀█
░▀░░░▀░▀░▀▀▀░▀▀▀░▀░▀
#+BEGIN_SRC emacs-lisp
(defun header_comment ()
"Function to make a header comment"
(interactive)
(save-excursion
(let (start end commentString)
(setq start (line-beginning-position) )
(setq end (line-end-position) )
(setq commentString (thing-at-point 'line) )
(delete-region start end)
(insert
(concat
(cdr (call-process "toilet" nil t nil "-f" "pagga" commentString)) "\n"
commentString))
(comment-region start (line-end-position))
)))
(leader-key
"ic" '(header_comment :which-key "header comment"))
#+END_SRC
** Other
#+BEGIN_SRC emacs-lisp
;; (use-package! flycheck-popup-tip
;; :config (flycheck-popup-tip-error-prefix "E -> "))
;;
;; (defun scroll-error-up ()
;; (interactive)
;; (message (prin1-to-string flycheck-popup-tip-object))
;; (popup-scroll-up flycheck-popup-tip-object))
;;
;; (defun scroll-error-down ()
;; (interactive)
;; (popup-scroll-down flycheck-popup-tip-object))
;; (map!
;; (:after flycheck-popup-tip
;; :en "C-j" #'scroll-error-down
;; :en "C-k" #'scroll-error-up))
#+END_SRC
* Sources
** Articles
https://protesilaos.com/
https://writequit.org/denver-emacs/presentations/2017-04-11-ivy.html
https://robert.kra.hn/posts/2021-02-07_rust-with-emacs/
** Configs
*** Quinoa42
https://quinoa42.github.io/en/dot-emacs/
*** Yang Haoxie
Evil escape mode
https://github.com/yanghaoxie/emacs.d
*** Rohit Goswami
Anki, viewnior, PKGBUILD mode, Docker-mode
https://dotdoom.rgoswami.me/config.html
** Distributions
Dots and pieces (especially language-specific package configs) were taken from spacemacs and doom
Doom bindings: https://github.com/hlissner/doom-emacs/blob/develop/modules/config/default/%2Bemacs-bindings.el
(evil) https://github.com/hlissner/doom-emacs/blob/develop/modules/editor/evil/config.el
https://github.com/hlissner/doom-emacs/blob/develop/modules/config/default/%2Bevil-bindings.el
** Youtube
*** System crafters
Most of the config is made with great help from a video series made by System Crafters called "Emacs from Scratch"
Config: https://github.com/daviwil/emacs-from-scratch
*** Matheus Augusto da Silva
Several configuration options and explanations was given by Matheus Augusto da Silva
*** Uncle Dave
*** Talks
The Spacemacs based way of handling shortcuts was made with help from a talk by Suyash Bire
https://www.youtube.com/watch?v=6INMXmsCCC8
https://github.com/suyashbire1/emacs.d/blob/master/init.el
* TODO: [0/6]
*** Prioritized [1/5]
- [-] IDE stuff [3/5]
- [ ] magit [0/1]
- [ ] evil keybindings
- [-] company-mode [2/6]
- [X] LSP integration
- [X] open on CTRL-SPC
- [ ] scroll with M-[jk]
- [ ] close on enter
- [ ] Path autocompletion company
- [ ] Yasnippets in company
- [X] helpful
- [X] projectile
- [X] flycheck
- [-] Add several bindings [2/9]
- [ ] counsel
- [ ] swiper
- [ ] pdf tools
- [ ] LaTeX
- [ ] org
- [ ] treemacs
- [X] look through doom
- [ ] look through spacemacs
- [X] emacs control [4/4]
- [X] windows
- [X] quit
- [X] files
- [X] config files
- [-] LaTeX config [3/6]
- [X] synctex (zathura or pdf-tools)
- [ ] preview math
- [X] conceal levels (prettify-symbols)
- [X] snippets
- [ ] bibtex [0/1]
- [ ] set up reftex
- [ ] Castel like way of opening geogebra/inkscape
- [X] Shortcut to config files
- [ ] Add toggler for menubar
*** Fix LSP mode [1/4]
- [X] Fix LSP UI
- [ ] Fix LSP UI bindings [0/8]
- [ ] toggle doc mode
- [ ] scroll in doc mode
- [ ] toggle sideline [0/3]
- [ ] diagnostics
- [ ] hover
- [ ] code-actions
- [ ] toggle flycheckers
- [ ] toggle breadcrumb
- [ ] peek-definitions
- [ ] peek-references
- [ ] lsp-ui-imenu
- [-] Fix some languages [3/8]
- [X] Elm
- [X] Java
- [X] Python
- [ ] Haskell
- [ ] Dart / Flutter
- [ ] C / C++
- [ ] Yaml
- [ ] Json
- [ ] Toggle error modes in flycheck (warnings, suggestions, errors, ...)
*** Research [1/2]
- [-] Research org mode [3/5]
- [X] How to add agenda entries
- [ ] Vimwiki like stuff?
- [X] Project specific todo-lists?
I'm planning on making a folder in ~/org called notes which hosts the relative paths to all project folders (as in "~/git/project" -> "~/org/notes/git/project.org")
- [ ] Links and images?
- [X] SRC block shortcut -> C-c C-,
- [X] Research yasnippets [2/2]
- [X] How to add language specific snippets?
- [X] Snippet format
*** Smaller tasks [1/9]
- [ ] remove star buffers from tab line -> https://www.emacswiki.org/emacs/TabBarMode
- [ ] make :q close a window [delete-window] whenever there is more than one window (except treemacs)
- [ ] solve drag mode in org mode (conflict with evil-org dragging)
- [-] Dired / *messages* leader-key usage
- [ ] Dired
- [X] *messages*
- [ ] Fix esc key
- [ ] ag-search-file
- [X] Lambda conceal
- [ ] remove collision between fira-code-mode and prettify-symbols
- [ ] disable next-buffer/pre in treemacs-mode-map (if exists?)
*** Less Prioritized [1/10]
- [X] Make a nice dashboard
- [ ] Customize dashboard-heading face size (and maybe font type?)
- [ ] Customize dashboard-item placement (logo in middle, items on sides)
- [ ] Add "go to previous file" type of function (instead of C-o)
- [ ] Add borders to zen mode
- [ ] Edit modeline items?
- [ ] Emoji
- [ ] Unicode
- [ ] Add images to plugin descriptions
- [ ] Add Japanese support [0/2]
- [ ] DDSKK
- [ ] pangu-spacing
*** Set up packages [0/12]
- [ ] popup
- [ ] magit-popup
- [ ] gitignore-mode
- [ ] dotenv-mode
- [ ] smooth-scrolling
- [ ] gist
- [ ] docker
- [ ] treemacs-magit?
- [ ] move-text vs dragstuff
- [ ] visual-regexp - Replace via RegExp, with real-time visual feedback directly in the buffer.
- [ ] visual-regexp-steroids - The same as visual-regexp, but use modern regular expressions instead of Emacs-style.
- [ ] From doom [0/9]
- [ ] ligatures
- [ ] ophints?
- [ ] unicode
- [ ] fold
- [ ] word-wrapping (soft wordwrap indent)
- [ ] vc-gutter (+ or - on the side of the code based on git status)
- [ ] electric ?
- [ ] editorconfig ?
- [ ] lookup
;; Local Variables:
;; eval: (add-hook 'after-save-hook (lambda ()(if (y-or-n-p "Reload?")(load-file user-init-file))) nil t)
;; eval: (add-hook 'after-save-hook (lambda ()(if (y-or-n-p "Tangle?")(org-babel-tangle))) nil t)
;; End: