Skip to content

dileban/.emacs.d

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Emacs Configuration

Emacs configuration specified in Literate Programming using Emacs Org mode.

Dependency Management

Define Package Repositories

List of default package repositories to search from.

(require 'package)
(setq package-archives
		  '(("gnu" . "https://elpa.gnu.org/packages/")
			 ("melpa" . "https://melpa.org/packages/")))

Import Package Install Utility

The function ‘use-package’ simplifies importing and configuring packages. Import packages “in-line” and configure at the same time, as opposed to separate these activities in two different parts of the file.

(unless (package-installed-p 'use-package)
	 (package-refresh-contents)
	 (package-install 'use-package))

Try Package Before Installing

Utility for trying packages before installing.

(use-package try
	 :ensure t)

Customizations

Save all custom-settings to a separate file

(setq custom-file "~/.emacs.d/custom-settings.el")
(load custom-file t)

Environment

Environment Variables

(setq user-full-name "Dileban Karunamoorthy")
(setq user-mail-address "[email protected]")

Load system dependent variables from env.el.

(defvar env-file "~/.emacs.d/env.el")
(when (file-exists-p env-file)
	 (load-file env-file))

Default Appearance

Inhibit Startup Screen and Message

(setq inhibit-splash-screen t)
(setq inhibit-startup-message t)

Yes/No to Y/N

(fset 'yes-or-no-p 'y-or-n-p)

Display Current Time

(display-time-mode t)

Tab Width

(setq-default tab-width 3)

Hide Tool Bar

(tool-bar-mode 0)

Hide Menu Bar

(menu-bar-mode 0)

Disable Scroll Bars

(scroll-bar-mode 0)

Theme

See Emacs Themes for a collection of themes.

;; (use-package solarized-theme
;;   :ensure t
;;   :config
;;   (load-theme 'solarized-dark)
;; )

(use-package dracula-theme
	 :ensure t
	 :config
	 (load-theme 'dracula)
)

;; (use-package base16-theme
;;   :ensure t
;;   :config
;;   (load-theme 'base16-railscasts))

Dashboard

Emacs Dashboard provides a startup screen with important locations.

(use-package dashboard
	 :ensure t
	 :config
	 (dashboard-setup-startup-hook)
	 (setq
	  dashboard-items
	  '((recents . 5)
		 (bookmarks . 5)
		 (projects . 5))))

Save/Restore Desktop

(desktop-save-mode 1)

Key Management

Assitance for key completions

which-key displays possible key-bindings for partially completed commands.

(use-package which-key
	 :ensure t
	 :config
	 (which-key-mode))

Backup Settings

Disable Backups and Auto-Saves

(setq make-backup-files nil)
(setq auto-save-default nil)

File and Buffer Management

Default Encoding System

Default all new buffers to the utf-8-unix encoding. Also applies to creating new files with C-x C-f.

(prefer-coding-system 'utf-8-unix)
(set-default-coding-systems 'utf-8-unix)
(set-terminal-coding-system 'utf-8-unix)
(set-keyboard-coding-system 'utf-8-unix)
(setq-default buffer-file-coding-system 'utf-8-unix)

Dired

(setq dired-listing-switches "-al")
(global-set-key (kbd "C-c d") 'dired-jump)

(use-package dired
	 :bind
	 (:map
	  dired-mode-map
	  ("u" . dired-up-directory)
	  ("i" . dired-previous-line)
	  ("k" . dired-next-line)))

Killing Buffers

Kill current buffer without prompting for buffer name.

(defun kill-current-buffer ()
	 "Kills the current buffer."
	 (interactive)
	 (kill-buffer (current-buffer)))
(global-set-key (kbd "C-x k") 'kill-current-buffer)

Enable ‘ibuffers’ by Default

(global-set-key (kbd "C-x C-b") 'ibuffer)

Recent Files

Enables quick access to recent (previous/past) files.

(recentf-mode 1)
(global-set-key (kbd "C-x p") 'helm-recentf)

Auto Insert

Default auto-insert settings when creating new buffers

(auto-insert-mode)
;;  Trailing slash important
(setq auto-insert-directory "~/.emacs.d/templates/")
;; Disable prompt before insertion
(setq auto-insert-query nil)

Basic Editing

Highlight Current Line

Highlights current line when using the windowing system. Not enabled for command line.

(when window-system (add-hook 'prog-mode-hook 'hl-line-mode))

Text Scrolling

Scroll text in current window one line at a time.

(global-set-key (kbd "C-0") (lambda () (interactive) (scroll-down 1)))
(global-set-key (kbd "C-9") (lambda () (interactive) (scroll-up 1)))

Multiple Cursors

Multiple cursors for uber text manipulation. Also see John Wiegley’s configuration for interesting workflows.

(use-package multiple-cursors
	 :ensure t
	 :bind
	 ("C-S-c C-S-c" . 'mc/edit-lines)
	 ("C->" . 'mc/mark-next-like-this)
	 ("C-<" . 'mc/mark-previous-like-this)
	 ("C-c C-<" . 'mc/mark-all-like-this))

Moving Point Quickly Within Screen Area

Moves point quickly within the visible screen area.

(use-package avy
	 :ensure t
	 :bind ("M-s" . avy-goto-char))

Finding Stuff

Finding stuff includes searching text within buffers, as well as finding buffers, files, and commonly used commands.

Swiper is a replacement for the default search, which shows a convenient overview of all matches.

;; Commented out. Prefer using Helm Swoop instead.
;; (use-package swiper
;;  :ensure t
;;  :bind ("C-s" . swiper)
;;  :config)

Helm Swoop is a replacement for the default search, which shows a convenient overview of all matches.

(use-package helm-swoop
	 :ensure t
	 :bind ("C-s" . helm-swoop-without-pre-input)
	 :config
	 (define-key helm-swoop-map (kbd "C-r") 'helm-previous-line)
	 (define-key helm-swoop-map (kbd "C-s") 'helm-next-line)
	 (define-key helm-multi-swoop-map (kbd "C-r") 'helm-previous-line)
	 (define-key helm-multi-swoop-map (kbd "C-s") 'helm-next-line)
	 (setq helm-swoop-use-line-number-face t)
	 (setq helm-swoop-split-with-multiple-windows t)
	 (set-face-attribute
	  'helm-swoop-target-word-face nil
	  :weight 'bold
	  :foreground "deep pink"))

Ivy is a generic completion system for Emacs, while Counsel builds on Ivy to add completions to a number of commonly used emacs commands. This enhances searchability of buffers, files, commands, functions, variables, etc.

(use-package ivy
	 :ensure t
	 :config
	 (ivy-mode 1))

(use-package counsel
	 :ensure t
	 :bind
	 (("M-y" . counsel-yank-pop)
	  :map ivy-minibuffer-map
	  ("M-y" . ivy-next-line)))

Override default bindings added by Counsel with Helm for M-x, finding files, buffers, and bookmarks.

(use-package helm
	 :ensure t
	 :init
	 (helm-mode 1)
	 (setq helm-bookmark-show-location t)
	 :bind
	 ("M-x" . helm-M-x)
	 ("C-x C-f" . helm-find-files)
	 ("C-x C-b" . helm-buffers-list)
	 ("C-x b" . helm-buffers-list)
	 ("C-x r b" . helm-bookmarks)
	 :config
	 (setq
	  helm-autoresize-max-height 30
	  helm-autoresize-min-height 30
	  helm-split-window-inside-p t) ; https://github.com/Alexander-Miller/treemacs/issues/808
	 (helm-autoresize-mode 1)
	 (set-face-attribute
	  'helm-selection nil
	  :background "violet red"
	  :foreground "white")
	 (global-set-key (kbd "C-h v") 'helm-apropos)
	 (global-set-key (kbd "C-h f") 'helm-apropos))

Expand Region and Replace

Expand region and replace

(use-package expand-region
	 :ensure t
	 :bind
	 ("C-`" . er/expand-region)
	 :config
	 (pending-delete-mode t))

Unfil Region

The reverse of fill-region. Useful when copying text from emacs to other destinations.

(use-package unfill
	 :ensure t)

Spell Checker

See here for instructions on setting up hunspell

 (setq
	ispell-program-name
	(locate-file
	 "hunspell"
	 exec-path exec-suffixes
	 'file-executable-p))
 (global-set-key (kbd "C-c s") 'ispell-word)

Crux

Crux provides an number of useful productivity features. The followig are being used here:

  • Smarter move to begining of line
  • Smarter opening of new line
  • Killing lines backwards
(use-package crux
	 :ensure t
	 :bind
	 ("M-o" . crux-smart-open-line-above)
	 ("C-<backspace>" . crux-kill-line-backwards)
	 ("C-c f" . crux-recentf-find-file)
	 ("C-c r" . crux-rename-file-and-buffer)
	 ("C-c K" . crux-kill-other-buffers)
	 ([remap move-beginning-of-line] . crux-move-beginning-of-line))

Highlight indentation

Enables visual cues for indentation

(use-package highlight-indent-guides
	 :ensure t
	 :config
	 (setq highlight-indent-guides-method 'character))

Jump between multiple windows

(global-set-key (kbd "C-c w") 'ace-window)

Typesetting Systems

Org Mode

Styling orgmode, inspired by this. For a list of symbols see here.

(use-package org-bullets
	 :ensure t
	 :init
	 (setq org-bullets-bullet-list
			 '("" "" "" "" ""))
	 :config
	 (add-hook
	  'org-mode-hook
	  (lambda () (org-bullets-mode 1)))
	 (setq org-ellipsis ""))
(setq org-image-actual-width (list 750))

Insert default header when creating new files

;;  (define-auto-insert "\.org" "default.org")

Other org mode defaults

(setq org-startup-folded t)

Markdown Mode

Setup major mode for Markdown.

(use-package markdown-mode
	 :ensure t
	 :commands (markdown-mode gfm-mode)
	 :mode (("README\\.md\\'" . gfm-mode))
	 :init
	 (setq markdown-home
			 (concat "file:///"
						(file-name-directory user-init-file)
						"markdown/"))
	 (setq markdown-command (getenv "MDCMD"))
	 (setq markdown-css-paths
			 (list (concat markdown-home "github.css")))
	 (setq markdown-xhtml-header-content
			 (concat "<style>"
						" .markdown-body {"
						"   box-sizing: border-box;"
						"   min-width: 200px;"
						"   max-width: 980px;"
						"   margin: 0 auto;"
						"   padding: 45px;"
						" }"
						"</style>"
						"<script src='"
						markdown-home
						"github.js' defer></script>")))

Research and Journaling

LaTex and Bibtex

Using AUCTeX for producing TeX based content, including LaTex, requires a TeX system such as TeX Live. To acquire TeX Live for Windows, download the installer from here. On Ubuntu, install (texlive-full) from repositories.

Helpful links:

(use-package auctex
	 :ensure t
	 :mode ("\\.tex\\'" . TeX-latex-mode))
(use-package helm-bibtex
	 :ensure t
	 :bind (
			  :map
			  bibtex-mode-map
			  ("M-q" . bibtex-reformat))
	 :config
	 (global-set-key (kbd "C-c b") 'helm-bibtex))

Org References

(use-package org-ref
	 :ensure t
	 :config
	 (setq
	  reftex-default-bibliography
	  '(concat (getenv "JOURNAL_DIR") "\\bibliography\\default.bib"))
	 (setq
	  org-ref-bibliography-notes (concat (getenv "JOURNAL_DIR") "\\bibliography\\notes.org")
	  org-ref-default-bibliography (list (concat (getenv "JOURNAL_DIR") "\\bibliography\\default.bib"))
	  org-ref-pdf-directory (concat (getenv "JOURNAL_DIR") "\\bibliography\\pdfs"))
	 (setq
	  bibtex-completion-bibliography (concat (getenv "JOURNAL_DIR") "\\bibliography\\default.bib")
	  bibtex-completion-library-path (concat (getenv "JOURNAL_DIR") "\\bibliography\\pdfs")
	  bibtex-completion-notes-path (getenv "JOURNAL_DIR")))

(require 'org-ref-arxiv)

Org Roam

(use-package org-roam
	 :ensure t
	 :init
	 (setq org-roam-v2-ack t)
	 :custom
	 (org-roam-directory (concat (getenv "JOURNAL_DIR") "\\roam"))
	 :bind (("C-c n l" . org-roam-buffer-toggle)
			  ("C-c n f" . org-roam-node-find)
			  ("C-c n g" . org-roam-graph)
			  ("C-c n i" . org-roam-node-insert)
			  ("C-c n c" . org-roam-capture)
			  ("C-c n t" . org-roam-tag-add)
			  ;; Dailies
			  ("C-c n j" . org-roam-dailies-capture-today))
	 :config
	 (org-roam-db-autosync-mode)
	 (setq org-roam-graph-executable (getenv "GRAPHVIZ"))
	 ;; If using org-roam-protocol
	 (require 'org-roam-protocol))
	 (setq org-roam-capture-templates
			 '(("l" "Literature" plain "%?"
				 :target (file+head "${slug}.org"
										  "#+title: ${title}\n#+author: %(concat user-full-name)\n#+email: %(concat user-mail-address)\n#+created: %(format-time-string \"%Y-%m-%d %H:%M\")\n#+notetype: literature\n#+filetags:\n\n")
				 :unnarrowed t)
				("f" "Fleeting" plain "%?"
				 :target (file+head "${slug}.org"
										  "#+title: ${title}\n#+author: %(concat user-full-name)\n#+email: %(concat user-mail-address)\n#+created: %(format-time-string \"%Y-%m-%d %H:%M\")\n#+notetype: fleeting\n#+filetags:\n\n")
				 :unnarrowed t)
				("p" "Permanent" plain "%?"
				 :target (file+head "${slug}.org"
										  "#+title: ${title}\n#+author: %(concat user-full-name)\n#+email: %(concat user-mail-address)\n#+created: %(format-time-string \"%Y-%m-%d %H:%M\")\n#+notetype: permanent\n#+filetags:\n\n")
				 :unnarrowed t)))

Org Roam Bibtex

(use-package org-roam-bibtex
	 :ensure t)
(org-roam-bibtex-mode)

Org Roam UI

(use-package websocket
	 :ensure t)

(use-package simple-httpd
	 :ensure t)

(use-package org-roam-ui
	 :ensure t)
(setq org-roam-ui-follow nil)
(setq org-roam-ui-open-on-start nil)

Publishing

(require 'find-lisp)
(setq org-export-with-section-numbers nil)
(setq org-export-with-drawers t)
(setq org-html-postamble-format 
	 '(("en"
		 "<span class=\"zettel-postamble\">author:%a;modified:%C</span>")))
(setq org-id-extra-files (find-lisp-find-files org-roam-directory "\.org$"))
(setq org-publish-project-alist
	 `(
		("journal",
		 :base-directory ,org-roam-directory
		 :base-extension "org"
		 :publishing-directory ,(concat (getenv "JOURNAL_DIR") "\\build")
		 :recursive t
		 :publishing-function org-html-publish-to-html
		 :with-properties nil
		 :with-author t
		 :with-tags t
		 :with-date t
		 :with-email nil
		 :auto-preamble t
		 :auto-sitemap t
		 :sitemap-title "Zettelkasten"
		 :sitemap-filename "zettelkasten.org"
		 :html-doctype "html5"
		 :html-head "<link rel=\"stylesheet\" href=\"../css/style.css\" type=\"text/css\"/>"
		 :html-preamble t
		 :html-postamble t
		 :html-link-up "./zettelkasten.html"
		 :html-link-home "./zettelkasten.html"
		 )
	 ))

Programming

General

;;  (setq warning-minimum-level :error)

Flycheck is a syntax checking extension that supports over 50 languages.

(use-package flycheck
	 :ensure t
	 :init (global-flycheck-mode))

yasnippet template system for convenient expansions.

(use-package yasnippet
	 :ensure t
	 :config
	 (yas-global-mode t))

auto-complete enables auto-completion feature for various modes in Emacs.

company-mode for text completion in emacs.

(use-package company
	 :ensure t
	 :config
	 (setq company-idle-delay 0)
	 (setq company-minimum-prefix-length 3)
	 (global-company-mode t))

Show matching parentheses.

(show-paren-mode 1)

Language Server Protocol

(use-package lsp-mode
	 :init
	 (setq lsp-keymap-prefix "C-c l")
	 :hook
	 ((rust-mode . lsp)
	  (lsp-mode . lsp-enable-which-key-integration))
	 :bind
	 (:map
	  lsp-mode-map
	  ("C-." . lsp-describe-thing-at-point))
	 :commands lsp)
(use-package lsp-ui
	 :config
	 (setq lsp-ui-doc-delay 1))
(use-package helm-lsp
	 :commands
	 helm-lsp-workspace-symbol)
(use-package lsp-treemacs
	 :ensure t
	 :config
	 (define-key treemacs-mode-map [mouse-1] #'treemacs-single-click-expand-action))

Working with Projects

Projectile, a useful project interaction extension that makes working with projects (e.g. any directory with .git) easy.

(use-package projectile
	 :ensure t
	 :init
	 (projectile-mode 1)
	 :config
	 (setq projectile-completion-system 'helm)
	 (define-key projectile-mode-map (kbd "M-p") 'projectile-command-map))

helm-projectile is helm mode for projectile.

(use-package helm-projectile
	 :ensure t
	 :init
	 (helm-projectile-on))

Magit

Magit is a Git porcelain for Emacs.

(use-package magit
	 :ensure t
	 :config
	 (setq magit-push-always-verify nil))

Docker

(use-package dockerfile-mode
	 :ensure t)

Protocol Buffers

(use-package protobuf-mode
	 :ensure t)

Solidity

(use-package solidity-mode
	 :ensure t)

Golang

Setup go-mode for editing Go code. In order to use go-mode effectively install the following tools and ensure they are availalbe in the PATH:

  • goimports: go get golang.org/x/tools/cmd/goimports
  • godef: go get github.com/rogpeppe/godef
  • golint: go get -u golang.org/x/lint/golint
  • errcheck: go get -u github.com/kisielk/errcheck
  • guru: go get golang.org/x/tools/cmd/guru

NOTE: Go imports relies on existence of the GNU `diff` util in PATH.

(use-package go-mode
	 :ensure t
	 :bind
	 :config
	 (add-hook
	  'go-mode-hook
	  (lambda ()
		 (define-key go-mode-map (kbd "M-.") 'godef-jump)
		 (setq gofmt-command "goimports")
		 (add-hook 'before-save-hook 'gofmt-before-save))))
(use-package go-guru
	 :ensure t)

To get auto complete working, install gocode along with auto-complete (see above) and go-autocomplete.

(use-package go-autocomplete
	 :ensure t)

Haskell

(use-package haskell-mode
	 :ensure t)
(add-hook 'haskell-mode-hook #'interactive-haskell-mode)
(use-package hindent
	 :ensure t)
(add-hook 'haskell-mode-hook #'hindent-mode)

Racket

Setup major mode for Racket source files and Racket REPL.

(use-package racket-mode
	 :ensure t)

Rust

Setup major mode for programming with Rust

(use-package rust-mode
	 :ensure t
	 :config
	 (setq rust-format-on-save t)
	 (add-hook
	  'rust-mode-hook
	  (lambda ()
		 (setq indent-tabs-mode nil)
		 (define-key rust-mode-map (kbd "C-c C-c") 'rust-run)
		 (display-line-numbers-mode t))))
(use-package cargo
	 :ensure t
	 :config
	 (add-hook 'rust-mode-hook 'cargo-minor-mode))

Yaml

Setup major mode for editing YAML files.

(use-package yaml-mode
	 :ensure t
	 :mode "\\.ya?ml\\'"
	 :config
	 (define-key yaml-mode-map "\C-m" #'newline-and-indent)
	 (add-hook 'yaml-mode-hook #'highlight-indent-guides-mode))

References

List of emacs configurations for inspiration

About

Custom configuration for Emacs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published