- Introduction
- Theme
- EVIL and keymap
- Search and filter
- Completion framework
- Utilities
- ORG mode
- Programming languages
- LaTeX
This file contains my custom emacs config to mimic doomemacs config as much as possible. It also tries to add a few more features I need.
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))exec-path is emacs path where shells in emacs search for executables. It is also used by emacs for finding executables for various commands. The below snippet is from emacswiki. More details can be found on the wiki page.
(defun set-exec-path-from-shell-PATH ()
"Set up Emacs' `exec-path' and PATH environment variable to match
that used by the user's shell.
This is particularly useful under Mac OS X and macOS, where GUI
apps are not started from a shell."
(interactive)
(let ((path-from-shell (replace-regexp-in-string
"[ \t\n]*$" "" (shell-command-to-string
"$SHELL --login -c 'echo $PATH'"
))))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
(setenv "PATH" (concat "/media/digvijay/39d16e25-cb72-4236-861c-c5e57ae445bb/digvijay/tmp/texlive/2022/bin/x86_64-linux:" (getenv "PATH")))
(set-exec-path-from-shell-PATH)(menu-bar-mode 1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
(column-number-mode 1)
(global-goto-address-mode 1);; Line numbers
(global-display-line-numbers-mode 1)
(setq display-line-numbers-type 'relative)
;; Visual line mode
(global-visual-line-mode 1)
(global-auto-revert-mode 1)
;; Split window vertically by default
(setq
split-width-threshold 0
split-height-threshold nil)
;; Replace yes-no answer options to y-n everywhere
(defalias 'yes-or-no-p 'y-or-n-p) (setq backup-directory-alist
`((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
`((".*" ,temporary-file-directory t)))(use-package dashboard
:ensure t
:custom
(dashboard-center-content 1)
:config
(dashboard-mode)
(dashboard-refresh-buffer))
(use-package leuven-theme
:ensure t)
(use-package doom-themes
:ensure t)
(load-theme 'leuven-dark t)
;;(use-package spacemacs-theme
;; :ensure t)
;;(load-theme 'spacemacs-dark t)
(use-package doom-modeline
:ensure t
:init
(doom-modeline-mode 1)
:config
(setq doom-modeline-height 15))
(set-face-attribute 'default nil :family "Fira Code" :height 140)Thinking of removing evil completely as I get used to emacs keychords. However, there are some vim motions that I find difficult to let go. So this section won’t have much updates. Any new keybindings I introduce will most likely be closer to emacs and in their own section.
(use-package evil-leader
:ensure t
:config
(global-evil-leader-mode)
(evil-leader/set-leader "<SPC>")
;; KEYBINDINGS
(evil-leader/set-key
"f f" 'counsel-find-file
"f r" 'counsel-recentf
"b b" 'counsel-switch-buffer
"b d" 'kill-this-buffer
"h v" 'counsel-describe-variable
"h f" 'counsel-describe-function
"h o" 'counsel-describe-symbol
"g g" 'magit
"w v" 'evil-window-vsplit
"w w" 'evil-window-next
"w c" 'evil-window-delete)
(evil-leader/set-key-for-mode 'org-mode
"m e" 'org-export-dispatch
"m @" 'org-ref-insert-cite-link
"m !" 'org-ref-insert-ref-link)
(evil-leader/set-key-for-mode 'julia-mode
"c c" 'julia-repl-send-region-or-line
"c b" 'julia-repl-send-buffer)
)
(use-package evil
:ensure t
:config
(evil-mode 1)
(setq evil-overriding-maps nil)
(setq evil-intercept-maps nil))(use-package counsel
:ensure t
:bind (("M-x" . counsel-M-x))
:config
(setq ivy-initial-inputs-alist nil)) ;; Dont start searches with ^
(use-package smex ;; recent commands in counsel-M-x
:ensure t
:after counsel)
(use-package ivy
:ensure t
:config
(ivy-mode)
(setq ivy-use-virtual-buffers t)
(setq enable-recursive-minibuffers t)
;; enable this if you want `swiper' to use it
(setq search-default-mode #'char-fold-to-regexp)
(global-set-key "\C-s" 'swiper-isearch)
;;(global-set-key (kbd "M-x") 'counsel-M-x)
(define-key minibuffer-local-map (kbd "C-r") 'counsel-minibuffer-history))
(use-package ivy-rich
:ensure t
:init
(ivy-rich-mode 1))
(use-package marginalia
:ensure t
:after vertico
:init
(marginalia-mode))Company mode
(add-hook 'after-init-hook 'global-company-mode)
(use-package company
:ensure t)(use-package vterm
:ensure t)This package is for better view of documentation. Currently I do not see any significant improvement but keeping it to try and tweak it further.
(use-package helpful ;; probably not needed. Can be commented
:ensure t
:custom
(counsel-describe-function-function #'helpful-callable)
(counsel-describe-variable-function #'helpful-variable)
:bind
([remap describe-function] . counsel-describe-function)
([remap describe-variable] . counsel-describe-variable)
([remap describe-symbol] . counsel-describe-symbol)
([remap describe-command] . helpful-command)
([remap describe-key] . helpful-key))An important package which gives possible keystrokes and corresponding actions in any mode.
(use-package which-key
:ensure t
:config
(which-key-mode))Not sure what it does now. Need to read about it.
(use-package orderless
:ensure t)Amazing package which shows matching brackets in same colour.
(use-package rainbow-delimiters
:ensure t
:hook (prog-mode . rainbow-delimiters-mode))(use-package flycheck
:ensure t
:init
(global-flycheck-mode +1))All the yasnippets can be activated using the first three letters of the snippet
followed by TAB. The mode is enabled globally.
(use-package yasnippet
:ensure t
:init
(yas-global-mode))
(use-package yasnippet-snippets
:ensure t)compat is equired by magit
(use-package compat
:ensure t)
(use-package magit
:ensure t)(use-package pdf-tools
:ensure t
:init
(pdf-loader-install))Colour output for code snippets in LaTeX using minted and some other LaTeX export stuff. Also includes for config for org-ref.
(use-package org
;;:ensure t
:config
;;(variable-pitch-mode nil)
(setq org-latex-listings 'minted) ;; or t
(add-to-list 'org-latex-packages-alist '("" "minted")) ;; or listings
(add-to-list 'org-latex-packages-alist '("" "xcolor"))
(setq bibtex-dialect 'biblatex)
(setq org-latex-compiler "lualatex")
(setq org-latex-pdf-process '("latexmk -shell-escape -%latex -bibtex -interaction=nonstopmode -f -pdf %f"))
(with-eval-after-load 'ox-latex
(add-to-list 'org-latex-classes
'("book-nodefaults"
"\\documentclass{book}"
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
))
(add-to-list 'org-latex-classes
'("exam"
"\\documentclass{exam}"
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
))
(add-to-list 'org-latex-classes
'("article-nodefaults"
"\\documentclass{article}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
)))
(add-hook 'org-mode-hook
(lambda () (add-hook 'after-save-hook #'org-babel-tangle
:append :local))))(use-package org-inline-pdf ;; For inline display of pdf files
:ensure t
:hook ((org-mode . org-inline-pdf-mode)))(use-package toc-org
:ensure t
:hook ((org-mode . toc-org-mode)))For fancy bullets in org mode. Org-bullets is outdated.
(use-package org-superstar
:ensure t
:after org
:custom
(org-superstar-headline-bullets-list '("◉" "○" "✿" "🞛" "✜" "◆" "▶" "✸" "☯" "☯" "☯" "☯" "☯" "☯" ))
:config
(set-face-attribute 'org-level-8 nil :weight 'bold :inherit 'default)
;; ;; Low levels are unimportant = no scaling
;; (set-face-attribute 'org-level-7 nil :inherit 'org-level-8)
;; (set-face-attribute 'org-level-6 nil :inherit 'org-level-8)
;; (set-face-attribute 'org-level-5 nil :inherit 'org-level-8)
;; (set-face-attribute 'org-level-4 nil :inherit 'org-level-8)
;; ;; Top ones get scaled the same as in LaTeX (\large, \Large, \LARGE)
(set-face-attribute 'org-level-3 nil :inherit 'org-level-8 :height 1.2) ;\large
(set-face-attribute 'org-level-2 nil :inherit 'org-level-8 :height 1.44) ;\Large
(set-face-attribute 'org-level-1 nil :inherit 'org-level-8 :height 1.728) ;\LARGE
;; ;; Only use the first 4 styles and do not cycle.
;; (org-cycle-level-faces nil)
;; (org-n-level-faces 4)
;; ;; Document Title, (\huge)
;; (set-face-attribute 'org-document-title nil
;; :height 2.074
;; :foreground 'unspecified
;; :inherit 'org-level-8)
:hook ((org-mode . org-superstar-mode)))The default citation type is autocite defined using org-ref-default-citation-link. Different citation types such as cite, citep etc can be given instead of autocite by changing the variable. The variable must be in :init block so that it can be evaluated before loading the package. Keeping it in the :config block doesn’t work. List of all such types can be seen in the documentation of org-ref-cite-types.
Org-ref provides multiple actions on cite keys such as open the bibentry, open pdf etc. Just click on the cite key to see the possible actions.
| Action | Keybinding | Function/command |
|---|---|---|
| insert citation | C-c c | org-ref-insert-cite-link |
| insert reference | C-c r | org-ref-insert-ref-link |
(use-package org-ref
:ensure t
:after org
:init
(require 'org-ref-helm) ;; helm plays well with org-ref
;;(require 'org-ref-ivy)
:custom
(org-ref-default-citation-link "autocite")
(org-ref-default-bibliography "/home/digvijay/Documents/manuscripts/report.bib")
:config
(setq bibtex-dialect 'biblatex)
:hook ((org-roam-mode . org-ref-mode))
:bind
(:map org-mode-map
(("C-c c" . org-ref-insert-cite-link)
("C-c r" . org-ref-insert-ref-link))))(use-package org-roam
:ensure t
:init
;;(setq org-roam-v2-ack t)
:custom
(org-roam-directory "~/RoamNotes")
(org-roam-completion-everywhere t)
:bind (("C-c n l" . org-roam-buffer-toggle)
("C-c n f" . org-roam-node-find)
("C-c n i" . org-roam-node-insert)
:map org-mode-map
("C-M-i" . completion-at-point)
:map org-roam-dailies-map
("Y" . org-roam-dailies-capture-yesterday)
("T" . org-roam-dailies-capture-tomorrow))
:bind-keymap
("C-c n d" . org-roam-dailies-map)
:config
(require 'org-roam-dailies) ;; Ensure the keymap is available
(org-roam-db-autosync-mode))
(use-package org-roam-bibtex
:ensure t
:after org-roam
:hook (org-roam-mode . org-roam-bibtex-mode))
(use-package org-roam-ui
:ensure t)
(use-package org-noter
:ensure t
:config
(setq org-noter-notes-search-path '("~/RoamNotes/")
org-noter-separate-notes-from-heading t)
:bind
(:map org-noter-doc-mode-map
("C-c n n" . org-noter-insert-note)))(add-to-list 'load-path "/usr/share/asymptote/")
(add-to-list 'load-path "/home/digvijay/emacs_custom_libs/")
(require 'ob-asymptote)
(autoload 'asy-mode "asy-mode.el" "Asymptote major mode." t)
(autoload 'lasy-mode "asy-mode.el" "hybrid Asymptote/Latex major mode." t)
(autoload 'asy-insinuate-latex "asy-mode.el" "Asymptote insinuate LaTeX." t)
(add-to-list 'auto-mode-alist '("\\.asy$" . asy-mode))
(org-babel-do-load-languages
'org-babel-load-languages
'((asymptote . t)))Install lsp-mode
(use-package lsp-mode
:ensure t
:hook
((python-mode . lsp-mode)
(julia-mode . lsp-mode)))| Action | Keybindings | Function/Command |
|---|---|---|
| Send a line to REPL | C-c C-c | |
| Send whole buffer to REPL | C-c C-b | |
| Switch to REPL/buffer | C-c C-z |
(use-package julia-repl
:ensure t
:config
;; For history in REPL on term other than vterm
(defun term-send-up () (interactive) (term-send-raw-string "\e[A"))
(defun term-send-down () (interactive) (term-send-raw-string "\e[B")))
(use-package julia-mode
:ensure t
:init
(add-hook 'julia-mode-hook 'julia-repl-mode))
;; UNICODE support
(add-hook 'term-exec-hook
(function
(lambda ()
(set-buffer-process-coding-system 'utf-8-unix 'utf-8-unix))))
(defadvice ansi-term (after advise-ansi-term-coding-system)
(set-process-coding-system 'utf-8-unix 'utf-8-unix))
(ad-activate 'ansi-term)
(set-terminal-coding-system 'utf-8)| Action | Keybinding | Function/Command |
|---|---|---|
| Get into a virtual environment | - | pyvenv-workon |
| Start ipython REPL | - | run-python |
| Send a line to REPL | C-c C-CR | |
| Send buffer to REPL | C-c C-c | elpy-shell-send-region-or-buffer |
| Switch to REPL | C-c C-z | elpy-shell-switch-to-shell |
| Switch to buffer | - | elpy-shell-switch-to-buffer |
(use-package elpy
:ensure t
:init
(elpy-enable))
;; Use jupyter for REPL
;; (setq python-shell-interpreter "jupyter"
;; python-shell-interpreter-args "console --simple-prompt"
;; python-shell-prompt-detect-failure-warning nil)
;; (add-to-list 'python-shell-completion-native-disabled-interpreters
;; "jupyter")
;; Use IPython for REPL
(setq python-shell-interpreter "ipython"
python-shell-interpreter-args
"-i --simple-prompt --InteractiveShell.display_page=True"
python-shell-prompt-detect-failure-warning nil)
(add-to-list 'python-shell-completion-native-disabled-interpreters "ipython")TCL setup for OpenSees. The tcl mode is autoloaded when opening a tcl file.
Start inferior tcl process (OpenSees in this case as defined in the config
below) with (M-x) run-tcl.
| Action | Keybinding | Function/command |
|---|---|---|
| Start inferior process | - | run-tcl |
| Switch to tcl repl | C-c C-s | switch-to-tcl |
| Load/source file in repl | C-c C-f | tcl-load-file |
(setq tcl-application "~/bin/OpenSees")I was just exploring rust and this part of config is bare minimal needed at that time. I am not actively monitoring this part of config.
(use-package rust-mode
:ensure t)
(use-package rustic
:ensure t)This is only for editing awesomewm config. Can be deleted if not using awesomewm.
(use-package lua-mode
:ensure t)LaTeX setup with live preview and snippets. To use snippets just type first
three characters of environment name (ex: fig for figure) and then hit
TAB.
The compiling process is handled by AUCTex. Any options to the latex command
should be passed using local variables at the end of file.
For ex: to define -shell-escape for a particular tex file, use following
code block.
%%% Local Variables: %%% TeX-engine: xetex %%% TeX-command-extra-options: "-shell-escape" %%% End:
For citations use any of the three from RefTeX, helm-bibtex and ivy-bibtex. Currently I am using helm and helm-bibtex for the purpose. Though using helm for only this thing seems odd, I do not have other working solution with ivy-bibtex or reftex which provides me with the necessary functionality. The config below for ivy-bibtex and reftex are sufficient for basic use cases.
| Action | Keybinding | Function/command |
|---|---|---|
| Compile document | C-c C-c | |
| live-preview at point | C-c C-p C-p |
'(TeX-PDF-mode t)
(add-hook 'LaTeX-mode-hook #'lsp-mode)
(use-package tex
:ensure auctex)
;; Use LatexMK for compiling and inheret pdf setting from auctex
(use-package auctex-latexmk
:ensure t
:config
(auctex-latexmk-setup)
(setq auctex-latexmk-inherit-TeX-PDF-mode t))
;; Add lualatex to the command list
(add-to-list 'TeX-command-list
'("LatexMK-lua" "latexmk -lualatex -pdflua %S%(mode) %(file-line-error) %(extraopts) %t" TeX-run-latexmk nil
(plain-tex-mode latex-mode doctex-mode)
:help "Run LatexMK-lua"))Use RefTeX for citations and references
;; Use RefTeX for citations and references
;;(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
;;(setq reftex-plug-into-AUCTeX t)Use helm with latex for citations. Use <Tab> on entries for actions.
;; Use helm-bibtex for citations
(use-package helm
:ensure t)
(use-package helm-bibtex
:ensure t
:config
(setq bibtex-completion-bibliography
'("/home/digvijay/Documents/manuscripts/report.bib"))
:bind
(("C-c c" . helm-bibtex)))
(autoload 'helm-bibtex "helm-bibtex" "" t)
(setq bibtex-completion-cite-prompt-for-optional-arguments nil) ;; Remove pre post note prompts
;; Insert citation by default instead of actions
(helm-delete-action-from-source "Insert Citation" helm-source-bibtex)
(helm-add-action-to-source "Insert Citation"
'helm-bibtex-insert-citation
helm-source-bibtex 0)Use ivy-bibtex for citations
;; ;; Use ivy-bibtex for citations
;; (use-package ivy-bibtex
;; :ensure t
;; :config
;; (autoload 'ivy-bibtex "ivy-bibtex" "" t)
;; ;; ivy-bibtex requires ivy's `ivy--regex-ignore-order` regex builder, which
;; ;; ignores the order of regexp tokens when searching for matching candidates.
;; ;; Add something like this to your init file:
;; (setq ivy-re-builders-alist
;; '((ivy-bibtex . ivy--regex-ignore-order)
;; (t . ivy--regex-plus)))
;; ;; Change default action to insert citation from open URL
;; (setq ivy-bibtex-default-action 'ivy-bibtex-insert-citation)
;; (setq ivy-bibtex-default-multi-action 'ivy-bibtex-insert-key)
;; (setq bibtex-completion-cite-prompt-for-optional-arguments nil)
;; :bind
;; (("C-c c" . ivy-bibtex-with-local-bibliography)))