Skip to content

Instantly share code, notes, and snippets.

@jsscclr
Created Oct 3, 2016
Embed
What would you like to do?

Emacs Configuration File

Initialisation

  • hack :O
(setq with-editor-file-name-history-exclude 1)

(load-theme 'leuven)
(package-initialize)
(setq-default c-basic-offset 2)
(electric-pair-mode 1)
(setq-default indent-tabs-mode nil)
(setq tab-width 2)
(setq standard-indent 2)
(global-auto-revert-mode t)
(tool-bar-mode -1)

Appearance

(set-face-attribute 'default nil :font "Fira Code" )
(set-frame-font "Fira Code" nil t)
(set-face-font 'variable-pitch "Fira Sans")
  • Emoji~
(defun --set-emoji-font (frame)
"Adjust the font settings of FRAME so Emacs can display emoji properly."
(if (eq system-type 'darwin)
    ;; For NS/Cocoa
    (set-fontset-font t 'symbol (font-spec :family "Apple Color Emoji") frame 'prepend)
  ;; For Linux
  (set-fontset-font t 'symbol (font-spec :family "Symbola") frame 'prepend)))

;; For when Emacs is started in GUI mode:
(--set-emoji-font nil)
;; Hook for when a frame is created with emacsclient
;; see https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Frames.html
(add-hook 'after-make-frame-functions '--set-emoji-font)

Packages

(setq package-archives
      '(("gnu" . "http://elpa.gnu.org/packages/")
        ("org" . "http://orgmode.org/elpa/")
        ("melpa" . "http://melpa.milkbox.net/packages/")))

Set-up

(setq backup-directory-alist
      `((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
      `((".*" ,temporary-file-directory t)))
(add-to-list 'exec-path "usr/local/bin")
  • unicode
(prefer-coding-system 'utf-8)
(set-charset-priority 'unicode)
(setq default-process-coding-system '(utf-8-unix . utf-8-unix))

Org

;; Fontify the whole line for headings (with a background color).
(setq org-fontify-whole-heading-line t)
;; You can turn off the display of all the asterisks in a heading but the last one
(setq org-hide-leading-stars t)
;; active Babel languages
(org-babel-do-load-languages
 'org-babel-load-languages
 '((js . t)
   (C . t)
   (sh . t)
   (ruby . t)
   ))

;; stop asking me!
(setq org-confirm-babel-evaluate nil)
  • add link
(global-set-key (kbd "C-x p i") 'org-cliplink)
  • store and insert link keybindings
    (global-set-key (kbd "C-c l") 'org-store-link)
    (global-set-key (kbd "C-c C-l") 'org-insert-link)
        

org-ref

(use-package org-ref
  :ensure t
  :config
  (setq org-ref-notes-directory "~/lib/references/notes"
        org-ref-bibliography-notes "~/lib/references/references.org"
        org-ref-default-bibliography '("~/lib/references/references.bib")
        org-ref-pdf-directory "~/lib/references/pdfs/"))

bog

  • enable Bog in all org buffers
(add-hook 'org-mode-hook 'bog-mode)

org-board

  • set up prefix key
    (use-package org-board
      :ensure t
      :config
      (global-set-key (kbd "C-c b") org-board-keymap))
        

Webmode

(add-to-list 'auto-mode-alist '("\\.php\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
(with-eval-after-load 'web-mode
  '(setq web-mode-markup-indent-offset 2)
  '(setq web-mode-css-indent-offset 2)
  '(setq web-mode-code-indent-offset 2)
  '(setq web-mode-style-padding 1)
  '(setq web-mode-script-padding 1)
  '(setq web-mode-enable-css-colorization t))

company

  • enable globally
(add-hook 'after-init-hook 'global-company-mode)
  • recommended set-up
    (setq company-tooltip-limit 20)                      ; bigger popup window
    (setq company-tooltip-align-annotations 't)          ; align annotations to the right tooltip border
    (setq company-idle-delay .3)                         ; decrease delay before autocompletion popup shows
    (setq company-begin-commands '(self-insert-command)) ; start autocompletion only after typing
    (global-set-key (kbd "C-c /") 'company-files)        ; Force complete file names on "C-c /" key
        

company-quick-help

(with-eval-after-load 'company
  (company-quickhelp-mode 1))

company-emoji

(with-eval-after-load 'company
  (add-to-list 'company-backends 'company-emoji))
  • Font support.
    (defun --set-emoji-font (frame)
      "Adjust the font settings of FRAME so Emacs can display emoji properly."
      (if (eq system-type 'darwin)
          ;; For NS/Cocoa
          (set-fontset-font t 'symbol (font-spec :family "Apple Color Emoji") frame 'prepend)
        ;; For Linux
        (set-fontset-font t 'symbol (font-spec :family "Noto Emoji") frame 'prepend)))
    
    ;; For when Emacs is started in GUI mode:
    (--set-emoji-font nil)
    ;; Hook for when a frame is created with emacsclient
    ;; see https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Frames.html
    (add-hook 'after-make-frame-functions '--set-emoji-font)
        

company-ngram

(with-eval-after-load 'company-ngram            ; ~/data/ngram/*.txt are used as data
  (setq company-ngram-data-dir "~/data/ngram")  ; company-ngram supports python 3 or newer
(setq company-ngram-python "python3")
(company-ngram-init)
(cons 'company-ngram-backend company-backends)
                                        ; or use `M-x turn-on-company-ngram' and
                                        ; `M-x turn-off-company-ngram' on individual buffers
                                        ;
                                        ; save the cache of candidates
(run-with-idle-timer 3600 t
                     (lambda ()
                       (company-ngram-command "save_cache")
                       ))
)

company-shell

(with-eval-after-load 'company
  '(add-to-list 'company-backends 'company-shell))

company-statistics

(add-hook 'after-init-hook 'company-statistics-mode)

company-tern

  • Add company-tern to company-mode backend list.
    (with-eval-after-load 'company
      '(add-to-list 'company-backends 'company-tern))
        

company-web

  • tern completion support
    ;; Enable JavaScript completion between <script>...</script> etc.
    (defadvice company-tern (before web-mode-set-up-ac-sources activate)
      "Set `tern-mode' based on current language before running company-tern."
      (message "advice")
      (if (equal major-mode 'web-mode)
          (let ((web-mode-cur-language
                 (web-mode-language-at-pos)))
            (if (or (string= web-mode-cur-language "javascript")
                    (string= web-mode-cur-language "jsx")
                    )
                (unless tern-mode (tern-mode))
              (if tern-mode (tern-mode -1))))))
        

ac-html-csswatcher

(company-web-csswatcher-setup)

css

csscomb

(with-eval-after-load 'css-comb
   (define-key 'css-mode-map (kbd "C-c C-x c") 'css-comb))

showcss-mode

(defun sm/toggle-showcss()
  "Toggle showcss-mode"
  (interactive)
  (if (derived-mode-p
       'html-mode
       'nxml-mode
       'nxhtml-mode
       'web-mode
       'handlebars-mode)
      (showcss-mode 'toggle)
    (message "Not in an html mode")))
(global-set-key (kbd "C-c C-k") 'sm/toggle-showcss)

elfeed

  • tell elfeed to use org file
(use-package elfeed-org
  :ensure t
  :config
  (elfeed-org)
  (setq rmh-elfeed-org-files (list "~/log/elfeed.org")))
  • install elfeed
    (use-package elfeed
      :ensure t)
        
  • shortcuts
    (defun elfeed-show-all ()
      (interactive)
      (bookmark-maybe-load-default-file)
      (bookmark-jump "elfeed-all"))
        
  • load db
    (defun elfeed-load-db-and-open ()
      "Wrapper to load the elfeed db from disk before opening"
      (interactive)
      (elfeed-db-load)
      (elfeed)
      (elfeed-search-update--force))
        

flycheck

  • Enable global flycheck mode.
    (add-hook 'after-init-hook #'global-flycheck-mode)
        

flycheck-css-colorguard

(eval-after-load 'flycheck
  '(progn
     (require 'flycheck-css-colorguard)
     (flycheck-add-next-checker 'css-csslint
                                'css-colorguard 'append)))

flycheck-pos-top

(with-eval-after-load 'flycheck
  (flycheck-pos-tip-mode))

flycheck-status-emoji

(with-eval-after-load 'flycheck
  (flycheck-status-emoji-mode))

flyspell

flyspell-correct-ivy

(with-eval-after-load "flyspell"
  '(define-key flyspell-mode-map (kbd "C-;") 'flyspell-correct-previous-word-generic))
  • Auto correction mode
    (with-eval-after-load "flyspell"
      '(add-hook flyspell-mode-hook #'flyspell-correct-auto-mode))
        

ivy / counsel

  • enable ivy completion everywhere
    (ivy-mode 1)
        
  • recommended defaults
    (with-eval-after-load 'ivy
      '(setq ivy-use-virtual-buffers t)
      '(setq ivy-count-format "(%d/%d) ")
      )
    
        
  • key bindings
(global-set-key "\C-s" 'swiper)
(global-set-key (kbd "C-c C-r") 'ivy-resume)
(global-set-key (kbd "<f6>") 'ivy-resume)
(global-set-key (kbd "M-x") 'counsel-M-x)
(global-set-key (kbd "C-x C-f") 'counsel-find-file)
(global-set-key (kbd "<f1> f") 'counsel-describe-function)
(global-set-key (kbd "<f1> v") 'counsel-describe-variable)
(global-set-key (kbd "<f1> l") 'counsel-load-library)
(global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
(global-set-key (kbd "<f2> u") 'counsel-unicode-char)
(global-set-key (kbd "C-c g") 'counsel-git)
(global-set-key (kbd "C-c j") 'counsel-git-grep)
(global-set-key (kbd "C-c k") 'counsel-ag)
(global-set-key (kbd "C-x l") 'counsel-locate)
(global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
(define-key read-expression-map (kbd "C-r") 'counsel-expression-history)

counsel

counsel-dash

(with-eval-after-load 'counsel-dash
  '(setq counsel-dash-min-length 3)
  '(setq counsel-dash-candidate-format "%d %n (%t)"))

javascript

js2-mode

  • Use js2-mode as major mode for JavaScript editing.
    (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
        
  • Use js2-mode with shell scripts running via Node.JS.
    (add-to-list 'interpreter-mode-alist '("node" . js2-mode))
        
  • Use js2-jsx-mode for jsx support.
    (add-to-list 'auto-mode-alist '("\\.jsx?\\'" . js2-jsx-mode))
        

js2-highlight-vars

(eval-after-load "js2-highlight-vars-autoloads"
  '(add-hook 'js2-mode-hook (lambda () (js2-highlight-vars-mode))))

js2-refactor

  • enable js2-refactor mode when js2-mode is active
    (add-hook 'js2-mode-hook #'js2-refactor-mode)
        
  • add keybinding prefix
    (js2r-add-keybindings-with-prefix "C-c C-m")
        

xref-js2

  • add xref backend to js2-mode
(add-hook 'js2-mode-hook (lambda ()
                           (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t)))

eslint

eslint-fix

  • automatically fix files with eslint.
(eval-after-load 'js2-mode
      '(add-hook 'js2-mode-hook (lambda () (add-hook 'after-save-hook 'eslint-fix nil t))))

jade

  • Enable evaluation via Jade in all js2-mode buffers.
    (with-eval-after-load 'js2-mode
      '(add-hook 'js2-mode-hook #'jade-interaction-mode))
        

tern

  • Use Tern with js2-mode.
    (add-hook 'js2-mode-hook (lambda () (tern-mode t)))      
        

tern-context-coloring

(eval-after-load 'context-coloring
  '(tern-context-coloring-setup))

counsel-dash

(add-hook 'js2-mode-hook (lambda () (setq-local counsel-dash-docsets '("JavaScript"))))

magit

  • Display information about the current git repository.
    (global-set-key (kbd "C-x g") 'magit-status)
    (global-set-key (kbd "C-x M-g") 'magit-dispatch-popup)
        

magit-gitflow

(add-hook 'magit-mode-hook 'turn-on-magit-gitflow)

magithub

(use-package magithub
  :after magit)

mode-icons

(mode-icons-mode)

projectile

  • Enable Projectile globally.
    (projectile-global-mode)
        

counsel-projectile

  • install replacements for standard projectile commands
(counsel-projectile-on)

org-projectile

  • recommended configuration for per repo files
    (with-eval-after-load 'org-projectile
      '(add-to-list 'org-capture-templates (org-projectile:project-todo-entry))
      '(setq org-agenda-files (append org-agenda-files (org-projectile:todo-files)))
      '(setq org-projectile:projects-file "~/projects.org"))
    
    
        
  • recommended keybindings
    (global-set-key (kbd "C-c c") 'org-capture)
    (global-set-key (kbd "C-c n p") 'org-projectile:project-todo-completing-read)
        

web

web-beautify

(eval-after-load 'js2-mode
  '(add-hook 'js2-mode-hook
             (lambda ()
               (add-hook 'before-save-hook 'web-beautify-js-buffer t t))))

(eval-after-load 'json-mode
  '(add-hook 'json-mode-hook
             (lambda ()
               (add-hook 'before-save-hook 'web-beautify-js-buffer t t))))

(eval-after-load 'web-mode
  '(add-hook 'web-mode-hook
             (lambda ()
               (add-hook 'before-save-hook 'web-beautify-html-buffer t t))))

(eval-after-load 'css-mode
  '(add-hook 'css-mode-hook
             (lambda ()
               (add-hook 'before-save-hook 'web-beautify-css-buffer t t))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment