1
0
mirror of https://github.com/alrayyes/dotfiles/ synced 2023-11-14 15:56:30 +00:00
dotfiles/private_dot_config/emacs/config.org

12 KiB
Raw Permalink Blame History

Ryan's Emacs config

About

My personal Emacs config.

init.el

To load this config add the following to init.el

(org-babel-load-file
 (expand-file-name
  "config.org"
  user-emacs-directory))

Package Management

Archives

  (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))

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.

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

(require 'use-package)
  ;; "ensure" packages by default
  (setq use-package-always-ensure t)

Ensure

The :ensure keyword causes the package(s) to be installed automatically if not already present on your system

(require 'use-package-ensure)
(setq use-package-always-ensure t)

General Configuration

User Interface

Start with minimal interface

(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)

Enable line numbers and customize their format.

  (column-number-mode)
  (global-display-line-numbers-mode t)
  (setq display-line-numbers-type `relative)

Theme

(use-package doom-themes)
(load-theme 'doom-molokai t)

Font

  ;; 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")

Icons

(use-package all-the-icons)

Mode Line

Doom Modeline

    (use-package doom-modeline
  :init (doom-modeline-mode 1)
  :custom (doom-modeline-height 15))

Escape Cancels All

(global-set-key (kbd "<escape>") 'keyboard-escape-quit)

Evil Mode

General

  (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))

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.

  (use-package evil-collection
    :after evil
    :config
    (evil-collection-init))

General Keybindings

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.

   (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"))

Keybinding Panel (which-key)

which-key shows an overview of what keybindings are available based on the prefix keys you entered.

  (use-package which-key
    :init (which-key-mode)
  :config(setq which-key-idle-delay 0.3))

Ivy

General

    (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

Ivy-rich

ivy-rich comes with rich transformers for commands from ivy and counsel.

      (use-package ivy-rich
:after counsel
    :init
  (ivy-rich-mode 1))

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.

(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 ^

Development

Languages

Emacs Lisp

Helpful

Helpful is an alternative to the built-in Emacs help that provides much more contextual information.

  (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))

Productivity

Rainbow Delimiters

  (use-package rainbow-delimiters
    :hook (prog-mode . rainbow-delimiters-mode))

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).

(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)))

Counsel-projectile

Projectile has native support for using ivy as its completion system. 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.

  (use-package counsel-projectile
  :after projectile
  :config
  (counsel-projectile-mode))

Git

Magit

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.

(use-package magit)

Org Mode

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.

    (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 " ▾"))

Heading Bullets

org-bullets shows org-mode bullets as UTF-8 characters.

      (use-package org-bullets
  :hook
(org-bullets-mode t))

Better Font Faces

  (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)

Center Org Buffers

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.

  (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))

Org Agenda

    (setq
  org-agenda-files (directory-files-recursively "~/Documents/org/" "\.org$"))

Configure Babel Languages

To execute or export code in org-mode code blocks, youll need to set up org-babel-load-languages for each language youd like to use. This page documents all of the languages that you can use with org-babel.

(with-eval-after-load 'org
  (org-babel-do-load-languages
      'org-babel-load-languages
      '((emacs-lisp . t)
      (python . t)))

  (push '("conf-unix" . conf-unix) org-src-lang-modes))

Structure Templates

With just a few keystrokes, it is possible to insert empty structural blocks, such as #+BEGIN_SRC#+END_SRC, or to wrap existing text in such a block.

(with-eval-after-load 'org
  ;; This is needed as of Org 9.2
  (require 'org-tempo)

  (add-to-list 'org-structure-template-alist '("sh" . "src shell"))
  (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp"))
  (add-to-list 'org-structure-template-alist '("py" . "src python"))
  (add-to-list 'org-structure-template-alist '("ph" . "src php")))