1
0
mirror of https://github.com/alrayyes/dotfiles/ synced 2023-11-14 15:56:30 +00:00
dotfiles/emacs/.emacs.d/config.org
2021-05-14 19:39:21 +02:00

326 lines
11 KiB
Org Mode

#+TITLE: Ryan's Emacs config
#+AUTHOR: Ryan Kes
#+DESCRIPTION: There are many Emacs configs, this one is mine
* About
My personal Emacs config.
* init.el
To load this config add the following to ~init.el~
#+begin_example
(org-babel-load-file
(expand-file-name
"config.org"
user-emacs-directory))
#+end_example
* Package Management
** Archives
#+begin_src emacs-lisp
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("org" . "https://orgmode.org/elpa/")
("elpa" . "https://elpa.gnu.org/packages/")))
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))
#+end_src
** Use-Package
The ~use-package~ macro allows you to isolate package configuration in your ~.emacs~ file in a way that is both performance-oriented and, well, tidy.
#+begin_src emacs-lisp
(unless (package-installed-p 'use-package)
(package-install 'use-package))
(require 'use-package)
;; "ensure" packages by default
(setq use-package-always-ensure t)
#+end_src
** Ensure
The ~:ensure~ keyword causes the package(s) to be installed automatically if not already present on your system
#+begin_src emacs-lisp
(require 'use-package-ensure)
(setq use-package-always-ensure t)
#+end_src
* General Configuration
** User Interface
*** Start with minimal interface
#+begin_src emacs-lisp
(setq inhibit-startup-message t) ;; Disable startup message
(scroll-bar-mode -1) ; Disable visible scrollbar
(tool-bar-mode -1) ; Disable the toolbar
(tooltip-mode -1) ; Disable tooltips
(menu-bar-mode -1) ; Disable the menu bar
;; Set up the visible bell
(setq visible-bell t)
#+end_src
*** Enable line numbers and customize their format.
#+begin_src emacs-lisp
(column-number-mode)
(global-display-line-numbers-mode t)
(setq display-line-numbers-type `relative)
#+end_src
** Theme
#+begin_src emacs-lisp
(use-package doom-themes)
(load-theme 'doom-molokai t)
#+end_src
** Font
#+begin_src emacs-lisp
;; Default pitch face
(set-face-attribute 'default nil :font "JetBrainsMono Nerd Font")
;; Fixed pitch face
(set-face-attribute 'fixed-pitch nil :font "JetBrainsMono Nerd Font")
;; Variable pitch face
(set-face-attribute 'variable-pitch nil :font "Cantarell")
#+end_src
** Icons
#+begin_src emacs-lisp
(use-package all-the-icons)
#+end_src
** Mode Line
*** Doom Modeline
#+begin_src emacs-lisp
(use-package doom-modeline
:init (doom-modeline-mode 1)
:custom (doom-modeline-height 15))
#+end_src
** Escape Cancels All
#+begin_src emacs-lisp
(global-set-key (kbd "<escape>") 'keyboard-escape-quit)
#+end_src
** Evil Mode
*** General
#+begin_src emacs-lisp
(use-package evil
:init ;; tweak evil's configuration before loading it
(setq evil-want-keybinding nil)
(setq evil-want-C-u-scroll t)
(evil-mode))
#+end_src
*** Evil Collection
Evil Collection is also installed since it adds 'evil' bindings to parts of Emacs that the standard Evil package does not cover, such as: calendar, help-mode and ibuffer.
#+begin_src emacs-lisp
(use-package evil-collection
:after evil
:config
(evil-collection-init))
#+end_src
** General Keybindings
[[https://github.com/noctuid/general.el][general.el]] provides a more convenient way to bind keys in emacs for both evil and non-evil users. ~general-define-key~ allows defining multiple keys at once, implicitly wrapping key strings with (kbd ...), having named prefix key sequences (like the leader key in vim), and more.
#+begin_src emacs-lisp
(use-package general
:config
(general-evil-setup t)
(general-create-definer dw/leader-key-def
:keymaps '(normal insert visual emacs)
:prefix "SPC"
:global-prefix "C-SPC"))
#+end_src
** Keybinding Panel (which-key)
[[https://github.com/justbur/emacs-which-key][which-key]] shows an overview of what keybindings are available based on the prefix keys you entered.
#+begin_src emacs-lisp
(use-package which-key
:init (which-key-mode)
:config(setq which-key-idle-delay 0.3))
#+end_src
* Ivy
** General
#+begin_src emacs-lisp
(use-package ivy
:diminish
:bind (("C-s" . swiper)
:map ivy-minibuffer-map
("TAB" . ivy-alt-done)
("C-l" . ivy-alt-done)
("C-j" . ivy-next-line)
("C-k" . ivy-previous-line)
:map ivy-switch-buffer-map
("C-k" . ivy-previous-line)
("C-l" . ivy-done)
("C-d" . ivy-switch-buffer-kill)
:map ivy-reverse-i-search-map
("C-k" . ivy-previous-line)
("C-d" . ivy-reverse-i-search-kill))
:init
(ivy-mode 1)) ;; Load keybindings
#+end_src
** Ivy-rich
[[https://github.com/Yevgnen/ivy-rich][ivy-rich]] comes with rich transformers for commands from ~ivy~ and ~counsel~.
#+begin_src emacs-lisp
(use-package ivy-rich
:after counsel
:init
(ivy-rich-mode 1))
#+end_src
** Counsel ~ivy-mode~ ensures that any Emacs command using ~completing-read-function~ uses ivy for completion. Counsel takes this further, providing versions of common Emacs commands that are customised to make the best use of Ivy. For example, ~counsel-find-file~ has some additional keybindings. Pressing ~DEL~ will move you to the parent directory.
#+begin_src emacs-lisp
(use-package counsel
:demand t
:bind (("M-x" . counsel-M-x)
("C-x b" . counsel-ibuffer)
("C-x C-f" . counsel-find-file)
;; ("C-M-j" . counsel-switch-buffer)
("C-M-l" . counsel-imenu)
:map minibuffer-local-map
("C-r" . 'counsel-minibuffer-history))
:custom
(counsel-linux-app-format-function #'counsel-linux-app-format-function-name-only)
:config
(setq ivy-initial-inputs-alist nil)) ;; Don't start searches with ^
#+end_src
* Development
** Languages
*** Emacs Lisp
**** Helpful
[[https://github.com/Wilfred/helpful][Helpful]] is an alternative to the built-in Emacs help that provides much more contextual information.
#+begin_src emacs-lisp
(use-package helpful
:custom
(counsel-describe-function-function #'helpful-callable)
(counsel-describe-variable-function #'helpful-variable)
:bind
([remap describe-function] . helpful-function)
([remap describe-symbol] . helpful-symbol)
([remap describe-variable] . helpful-variable)
([remap describe-command] . helpful-command)
([remap describe-key] . helpful-key))
#+end_src
** Productivity
*** Rainbow Delimiters
#+begin_src emacs-lisp
(use-package rainbow-delimiters
:hook (prog-mode . rainbow-delimiters-mode))
#+end_src
** Projectile
[[https://github.com/bbatsov/projectile][Projectile]] is a project interaction library for Emacs. Its goal is to provide a nice set of features operating on a project level without introducing external dependencies (when feasible). For instance - finding project files has a portable implementation written in pure Emacs Lisp without the use of GNU ~find~ (but for performance sake an indexing mechanism backed by external commands exists as well).
#+begin_src emacs-lisp
(use-package projectile
:ensure t
:init
(projectile-mode +1)
(setq projectile-project-search-path '("~/devel/" "~/dotfiles/" "~/Documents/"))
:bind (:map projectile-mode-map
("s-p" . projectile-command-map)
("C-c p" . projectile-command-map)))
#+end_src
*** Counsel-projectile
[[https://github.com/bbatsov/projectile][Projectile]] has native support for using [[https://github.com/abo-abo/swiper][ivy]] as its completion system. [[https://github.com/ericdanan/counsel-projectile][Counsel-projectile]] provides further ivy integration into projectile by taking advantage of ivy's support for selecting from a list of actions and applying an action without leaving the completion session. Concretely, counsel-projectile defines replacements for existing projectile commands as well as new commands that have no projectile counterparts. A minor mode is also provided that adds key bindings for all these commands on top of the projectile key bindings.
#+begin_src emacs-lisp
(use-package counsel-projectile
:after projectile
:config
(counsel-projectile-mode))
#+end_src
** Git
*** Magit
[[https://magit.vc/][Magit]] is a complete text-based user interface to Git. It fills the glaring gap between the Git command-line interface and various GUIs, letting you perform trivial as well as elaborate version control tasks with just a couple of mnemonic key presses.
#+begin_src emacs-lisp
(use-package magit)
#+end_src
* Org Mode
[[https://orgmode.org/][Org]] is a highly flexible structured plain text file format, composed of a few simple, yet versatile, structures — constructed to be both simple enough for the novice and powerful enough for the expert.
#+begin_src emacs-lisp
(defun efs/org-mode-setup ()
(org-indent-mode)
(variable-pitch-mode 1)
(visual-line-mode 1))
(use-package org
:hook
(org-mode . efs/org-mode-setup)
:config
(setq org-ellipsis ""))
#+end_src
** Heading Bullets
[[https://github.com/sabof/org-bullets][org-bullets]] shows org-mode bullets as UTF-8 characters.
#+begin_src emacs-lisp
(use-package org-bullets
:hook
(org-bullets-mode t))
#+end_src
** Better Font Faces
#+begin_src emacs-lisp
(dolist (face '((org-level-1 . 1.2)
(org-level-2 . 1.1)
(org-level-3 . 1.05)
(org-level-4 . 1.0)
(org-level-5 . 1.1)
(org-level-6 . 1.1)
(org-level-7 . 1.1)
(org-level-8 . 1.1)))
(set-face-attribute (car face) nil :font "Cantarell" :weight 'regular :height (cdr face)))
;; Ensure that anything that should be fixed-pitch in Org files appears that way
(set-face-attribute 'org-block nil :foreground nil :inherit 'fixed-pitch)
(set-face-attribute 'org-table nil :inherit 'fixed-pitch)
(set-face-attribute 'org-formula nil :inherit 'fixed-pitch)
(set-face-attribute 'org-code nil :inherit '(shadow fixed-pitch))
(set-face-attribute 'org-table nil :inherit '(shadow fixed-pitch))
(set-face-attribute 'org-verbatim nil :inherit '(shadow fixed-pitch))
(set-face-attribute 'org-special-keyword nil :inherit '(font-lock-comment-face fixed-pitch))
(set-face-attribute 'org-meta-line nil :inherit '(font-lock-comment-face fixed-pitch))
(set-face-attribute 'org-checkbox nil :inherit 'fixed-pitch)
(set-face-attribute 'line-number nil :inherit 'fixed-pitch)
(set-face-attribute 'line-number-current-line nil :inherit 'fixed-pitch)
#+end_src
** Center Org Buffers
[[https://github.com/joostkremers/visual-fill-column][visual-fill-column-mode]] is a small Emacs minor mode that mimics the effect of ~fill-column~ in ~visual-line-mode~. Instead of wrapping lines at the window edge, which is the standard behaviour of ~visual-line-mode~, it wraps lines at ~fill-column~. If ~fill-column~ is too large for the window, the text is wrapped at the window edge.
#+begin_src emacs-lisp
(defun efs/org-mode-visual-fill ()
(setq visual-fill-column-width 120
visual-fill-column-center-text t)
(visual-fill-column-mode 1))
(use-package visual-fill-column
:hook (org-mode . efs/org-mode-visual-fill))
#+end_src
** Org Agenda
#+begin_src emacs-lisp
(setq
org-agenda-files (directory-files-recursively "~/Documents/org/" "\.org$"))
#+end_src