Git Product home page Git Product logo

emacs.d's Introduction

Introduction to awesome JCFFlores Emacs config

The purpose of this emacs config file is to learn more about emacs lisp and the internals of emacs, as well as to leverage the opportunity to toy a little bit with literate programming.

Initial setup

Package configuration

Require package.el before continuing

(require 'package)

Add archives

The melpa archive is required to install most packages, the org archive is required to install org-plus-contrib package later on

(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)

Initialize packages

This is required for the package initialization to work, for Emacs 27 this line won’t be needed and it’s gonna be necessary to check if some reordering is to be applied to the config

(package-initialize)

Custom configuration

Set the custom-file variable, check if the custom file already exists and then load it. This should prevent errors when running this config for the first time.

(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(when (file-exists-p custom-file)
  (load custom-file))

Use-package installation

use-package is used throught the config to lazily load and configure packages, as well as to ensure they are always installed.

Conditionally install use-package

The rest of the configuration will not work if use-package is not available, the next piece of code ensures it’s present.

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

Require use-package

The next line ensures there are no errors/warnings if byte-compiling the config

(eval-when-compile (require 'use-package))

Required packages

This are packages that come bundled with emacs, for packages downloaded from an archive use-package is used.

(require 'subr-x)

General configuration

This is configuration that is not specific to a package or is not big enough to merit its own headline at the top level of the file.

Spellcheck configuration

For flyspell to work it’s necessary to have the ispell command, save its name on a variable first. The configuration will always check that ispell is available before adding flyspell as a hook.

(setq ispell-command "ispell")

For all text based modes have flyspell running.

(when (executable-find ispell-command)
 (add-hook 'text-mode-hook 'flyspell-mode))

For all programming modes having flyspell running would cause a lot of visual clutter, this makes it only check comments in code.

(when (executable-find ispell-command)
 (add-hook 'text-mode-hook 'flyspell-prog-mode))

Package configurations

Markdown configuration

The only reason to have markdown configured is because it’s more widespread than org-mode for markup.

(use-package markdown-mode
  :ensure t
  :mode (("README\\.md\\'" . gfm-mode)
	 ("\\.md\\'" . markdown-mode)
	 ("\\.markdown\\'" . markdown-mode))
  :init (setq markdown-command "pandoc"))

Rainbow delimiters

Add rainbow-delimiters and enable it for every programming related mode

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

All the icons

All the icons is a package used as dependency for other packages, it guarants its own space on the configuration.

(use-package all-the-icons
  :ensure t)

Dired configuration

All the icons in dired

Give dired some eye-candy by having icons next to file names.

(use-package all-the-icons-dired
  :ensure t
  :hook (dired-mode . all-the-icons-dired-mode))

Magit configuration

Magit is the one true way of interfacing with git. Lazily load magit when pressing C-x g.

(use-package magit
  :ensure t
  :bind (("C-x g" . magit-status)))

Fish configuration

Enable fish-mode and load it for .fish files.

(use-package fish-mode
  :ensure t
  :mode (("\\.fish\\'" . fish-mode)))

Haskell configuration

(use-package haskell-mode
  :ensure t)

Javascript configuration

Ensure js2-mode is installed and add an imenu hook for javascript.

(use-package js2-mode
  :ensure t
  :hook (js2-mode . js2-imenu-extras-mode))

Add js2-refactor to the javascript capabilities

(use-package js2-refactor-mode
  :ensure js2-refactor
  :hook js2-mode)

Org configuration

Require the org package and make a binding for org-agenda to be callable, also make a binding for org-capture and org-store-link. Ensure that .org files will be opened with org-mode. Set the location of the agenda files to the value of the environment variable ORG_AGENDA. Set TODO and IN-PROGRESS as states, and DONE, CANCELED and MISSED as the completed states for an agenda item; also give color to CANCELED and MISSED state. Make the agenda buffer cover 14 days and make it start on the current day.

(use-package org
  :ensure t
  :bind (("C-c a" . org-agenda)
	     ("C-c c" . org-capture)
	     ("C-c l" . org-store-link))
  :mode (("\\.org\\'" . org-mode))
  :init
  (setq org-agenda-files (list (getenv "ORG_AGENDA"))
	    org-todo-keywords '((sequence "TODO(t)" "IN-PROGRESS(i)" "|" "DONE(d)" "CANCELED(c)" "MISSED(m)"))
	    org-todo-keyword-faces '(("CANCELED" . "magenta") ("MISSED" . "red"))
	    org-agenda-span 14
	    org-agenda-start-on-weekday nil)
  :config
  (add-to-list 'org-modules 'org-habit))

Swiper configuration

Use swiper as a superior alternative to I-search. Bind it to C-s to use it every time a search is performed in a buffer.

(use-package swiper
  :ensure t
  :bind (("\C-s" . swiper)))

Counsel configuration

Require the counsel package and enable both counsel and ivy, the latter comes bundled with counsel.

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

Paredit configuration

Paredit is going to be used as part of the extensions for parinfer, we only need to ensure the package is available.

(use-package paredit
  :ensure t)

Parinfer configuration

Parinfer is a package that makes it easier to edit lisp code by infering indentation and parenthesis depth changes. Add a binding for it and hooks for lisp modes.

(use-package parinfer-mode
  :ensure parinfer
  :bind (("C-," . parinfer-toggle-mode))
  :init
  (setq parinfer-extensions
  '(defaults
     pretty-parens
     paredit
     smart-tab
     smart-yank))
  :hook (emacs-lisp-mode lisp-mode))

Multiple cursors configuration

Include the multiple-cursors package and add a key-binding for mc/edit-lines to C-c m c as a mnemonic for multiple cursors.

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

Usability configuration

Clear screen

Remove menu bar, tool bar and scroll bar to have a clearer editing screen.

(menu-bar-mode -1)
(tool-bar-mode -1)
(toggle-scroll-bar -1)

Add line numbers

Use display-line-numbers-mode to give line numbers to emacs buffers

(global-display-line-numbers-mode 1)

Parenthesis matching

Match parenthesis on every programming mode using electric-pair-mode.

(add-hook 'prog-mode-hook 'electric-pair-mode)

Mac usability

Working on mac gets very awkward as the option key is used for META making it unusable for the rest of uses that it has on mac. If for some reason I am forced to work on a mac again make only command work as the META key.

(when (eq system-type 'darwin)
  (setq ns-command-modifier 'meta
	ns-alternate-modifier nil))

Font configuration

Safe set font

The following font serves to set the font without the program crashing for not finding it

(defun safe-set-font (font-name)
  "If the font exists set it to be used in all frames"
  (when (member font-name (font-family-list))
    (set-frame-font font-name t t)))

Set font

Come up with a way to not have the font hard coded

The font used is hardcoded to FuraCode from Nerd fonts.

(setq font-name "FuraCode Nerd Font")
(safe-set-font font-name)

Miscellaneous configuration

This section of the configuration pertains to small usability configuration that is not big enough to have its own section on the usability section.

Symlinks configuration

Always follow symlinks when opening files

(setq vc-follow-symlinks t)

Column size

Set the column size to 80 characters

(setq-default fill-column 80)

Limit VC

Only use VC for git.

(setq vc-handled-backends '(Git))

Enable auto-fill-mode

Enable auto-fill-mode for modes based on text-mode.

(add-hook 'text-mode-hook 'turn-on-auto-fill)

emacs.d's People

Contributors

jcfflores avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.