jmn's Emacs configuration

Table of Contents


1 Configuration

1.1 About

1.1.1 Install this config

  1. Install req-package from Melpa

    (add-to-list 'package-archives
                 '("melpa-stable" . "") t)
    (package-install 'req-package)
  2. Provide a basic loader configuration in ~/.emacs.d/init.el:

    ; -*- coding: utf-8 -*-
    (defconst emacs-start-time (current-time))      ; Clocking startup time to message buf.
    (unless noninteractive
      (message "Loading %s..." load-file-name))
    (setq gc-cons-threshold 100000000) ; Reduce GC - see
    (setq custom-file "~/.emacs.d/my-custom-file.el") ; Set up the load path so that we can override it
    (load custom-file)
    (load "~/.gnus")
    ;; Override the packages with the git version of Org and other packages
    (add-to-list 'load-path (expand-file-name "~/git/org-mode/lisp"))
    (add-to-list 'load-path (expand-file-name "~/git/org-mode/contrib/lisp"))
    (add-to-list 'auto-mode-alist '("\\.\\(org\\  |org_archive\\|txt\\)$" . org-mode))
    (setq org-agenda-files '("~/org/"))
    (package-initialize nil)
    (require 'req-package)
    (req-package org-mode
                 :require ob-tangle org-habit org-install
                 :loader :path)
    (let ((file-name-handler-alist nil)) ; speedup, see link above
      (org-babel-load-file "~/git/notes/")
    ;;; End Minimal
    ; Local settings
    (sml/apply-theme 'respectful)
    ; (load-theme 'heroku t)
    ; (load-theme 'tsdh-dark t)
                                            ; (load-theme 'sanityinc-tomorrow-blue t)
    (req-package sanityinc-tomorrow-night
      (load-theme 'sanityinc-tomorrow-night t)
    ;; Bright themes: light-soap
    ;; (set-frame-font "Consolas-14")               ; Font (See also, Source Code Pro, Monaco)
    (when window-system
      (let ((elapsed (float-time (time-subtract (current-time)
        (message "Loading %s...done (%.3fs)" load-file-name elapsed))
      (add-hook 'after-init-hook
                `(lambda ()
                   (let ((elapsed (float-time (time-subtract (current-time)
                     (message "Loading %s...done (%.3fs) [after-init]"
                              ,load-file-name elapsed)))

    These are the bare minimums:

    (package-initialize nil)
    (require 'req-package)
    (req-package org-mode
                 :require ob-tangle org-habit org-install
                 :loader :path)
    (let ((file-name-handler-alist nil)) ; speedup, see link above
      (org-babel-load-file "~/git/notes/")
  3. Lastly, after configuring, Emacs will download the packages it can via the packaging system.

You will want to run this to make req-package fetch some dependencies via el-get:

(require 'req-package)

(req-package el-get ;; prepare el-get (optional)
  :force t ;; load package immediately, no dependency resolution
  (add-to-list 'el-get-recipe-path "~/.emacs.d/el-get/el-get/recipes")
  (el-get 'sync))

That's it. The end.

1.1.2 Note

Configuration for GNU Emacs. [Dominik201408] This is my dotemacs. There are many like it, but this one is mine.. [kitchin-2015-examp]


This is my dotemacs. There are many like it, but this one is mine..

My dotemacs is my best file. It is on my harddrive. I must master it as I must master my life.

My dotemacs, without me, is useless. Without my dotemacs, I am useless. I must edit my dotemacs true. I must edit more efficiently than I did before. I Will..

My dotemacs and I know that what counts in editing is not the buttons we press, the smattering of the keys, nor the keyboards we wear out. We know that it is the edits that count. We will edit…

My dotemacs is human, even as I, because it is my life. Thus, I will learn it as a brother. I will learn its weaknesses, its strength, its parts, its accessories, its modes and its functions. I will keep my dotemacs clean and ready, even as I am clean and ready. We will become part of each other. We will…

Before Richard M. Stallman, I swear this creed. My dotemacs and I are the editors of my files. We are the masters of our text. We are the saviors of my data.

So be it, until editing is done and there is no text, but peace!

Load using: (org-babel-load-file "/path/to/file"),


  • To edit source code blocks in org-mode: C-c ' (org-edit-special).
  • To show syntax highligting in code blocks use M-x org-src-fontify-buffer

1.1.3 Configure ~/.emacs.d/init.el

To load this file when Emacs starts I put the following code into ~/.emacs.d/init.el:

    (defconst emacs-start-time (current-time))
    (unless noninteractive
      (message "Loading %s..." load-file-name))

    (setq message-log-max 16384)

    (setq package-enable-at-startup nil)
    (package-initialize nil)
    (setq custom-file "~/.emacs.d/emacs-custom.el") ; Set up the load path so that we can override it
    (load custom-file)

    ;; Override the packages with the git version of Org and other packages
    (add-to-list 'load-path "~/git/org-mode/lisp")
    (add-to-list 'load-path "~/git/org-mode/contrib/lisp")
    ;; Load the rest of the packages
    (package-initialize t)

    (require 'req-package)
    (req-package org
     :require ob-tangle
     :loader :path)
;;    (require 'org)
;;    (require 'ob-tangle)

    (org-babel-load-file (expand-file-name "~/git/notes/"))
    ;; Local Options:
    (req-package-finish)                        ; load all the packages in order
    (load-theme 'tango-dark t)              ; set a theme
    (set-frame-font "Monaco 16")                ; set font

    (when window-system
      (let ((elapsed (float-time (time-subtract (current-time)
        (message "Loading %s...done (%.3fs)" load-file-name elapsed))

      (add-hook 'after-init-hook
                `(lambda ()
                   (let ((elapsed (float-time (time-subtract (current-time)
                     (message "Loading %s...done (%.3fs) [after-init]"
                              ,load-file-name elapsed)))

1.1.4 Personal information

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

1.2 Emacs initialization

1.2.1 General coding settings

Character encoding can be tricky to get right.

(setq utf-translate-cjk-mode nil) ; disable CJK coding/encoding (Chinese/Japanese/Korean characters)
(set-language-environment 'utf-8)
(setq locale-coding-system 'utf-8)
(set-locale-environment "sv_SE.UTF-8")
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
;; (setq locale-coding-system 'cp1252)

(unless (eq system-type 'windows-nt)    ; On windows the selection coding should be default (utf-16-le).
  (set-selection-coding-system 'utf-8)
  ;; Treat clipboard input as UTF-8 string first; compound text next, etc.
  (setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)))

(prefer-coding-system 'utf-8)
(modify-coding-system-alist 'file "" 'utf-8)

(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)

;; backwards compatibility as default-buffer-file-coding-system
;; is deprecated in 23.2.
(if (boundp 'buffer-file-coding-system)
    (setq-default buffer-file-coding-system 'utf-8)
  (setq default-buffer-file-coding-system 'utf-8))

On Windows, it's best to avoid (set-selection-coding-system 'utf-8) as it alters the clipboard behavior in Emacs. The correct value for selection-coding-system (aka clipboard-coding-system) on Windows should be 'utf-16-le (the default) in order to allow Emacs to cooperate with other Unicode programs.

SO: Which coding system should I use in Emacs?

SO: Encoding

(source: Working with Coding Systems and Unicode in Emacs - Mastering Emacs)

1.2.2 Add elisp directory and other files

    (add-to-list 'load-path "~/.emacs.d/elisp")
    (add-to-list 'load-path "~/elisp")
    ; (load-file "~/.emacs.secrets")        ; Contains private information
    ;(add-to-list 'package-archives '("org" . "") t)
    (add-to-list 'package-archives '("melpa" . "") t)
(add-to-list 'package-archives '("marmalade" . ""))

1.2.3 TODO Just load all .el -files in ~/.emacs.d/elisp/

1.2.4 Basic convenience functions

(defun jlp/add-to-list-multiple (list tzo-add)
  "Adds multiple items to LIST.
Allows for adding a sequence of items to the same list, rather
than having to call `add-to-list' multiple times."
  (dolist (item tzo-add)
    (add-to-list list item)))

1.2.5 Paths

(setq exec-path (append exec-path '("/usr/local/bin")))

1.2.6 Inhibit startup message

(setq inhibit-startup-buffer-menu t)
 (setq inhibit-startup-echo-area-message nil)
 (setq inhibit-startup-screen t)
 (setq initial-scratch-message ";; Scratch buffer 

1.2.7 Packages

  1. Basics
    (defun require-package (package)
      "refresh package archives, check package presence and install if it's not installed"
      (if (null (require package nil t))
          (progn (let* ((ARCHIVES (if (null package-archive-contents)
                                      (progn (package-refresh-contents)
                        (AVAIL (assoc package ARCHIVES)))
                   (if AVAIL
                       (package-install package)))
                 (require package))))
    (require-package 'use-package)
    (require-package 'req-package)
    (require 'use-package)
        (unless (package-installed-p 'use-package)
          (package-install 'use-package))
        (require 'use-package)
  2. El-get configuration and packages

    El-get recipes Search for existing recipes here:✓&q=recipe

    (use-package el-get
                    '(:name org-reveal
                            :type github
                            :pkgname "yjwen/org-reveal"
                            :description "Exports Org-mode contents to Reveal.js HTML presentation."
                            :depends org-mode
                            :features ox-reveal)
                    '(:name adoc-mode
                            :website ""
                            :description "A major-mode for editing AsciiDoc files in Emacs."
                            :type github
                            :pkgname "sensorflo/adoc-mode"
                            :depends markup-faces)
                    '(:name markup-faces
                            :description "Collection of faces for markup language modes."
                            :type github
                            :pkgname "sensorflo/markup-faces")
                    '(:name auto-complete
                            :website ""
                            :description "The most intelligent auto-completion extension."
                            :type github
                            :pkgname "auto-complete/auto-complete")  
                  ;;                (el-get 'sync)

1.2.8 Start the edit server

For use with "emacsclient".


1.3 General configuration

1.3.1 Buffer interaction

  1. Resize fonts using control + mousewheel

    Configures control + mousewheel to adjust text size. Text size can also be increased/decreased using C-x C-+ and C-x C-- (M-x text-scale-adjust). Use C-h c (M-x describe-key) and use the scroll wheel on your mouse to see what the mousewheel is called on your system.


    (require 'mwheel)
    (if (eq system-type 'gnu/linux)  ; GNU/Linux uses the fullscreen-mode package
          (global-set-key (kbd "<C-mouse-4>") 'text-scale-decrease)
          (global-set-key (kbd "<C-mouse-5>") 'text-scale-increase)
        (global-set-key [C-wheel-up]    'text-scale-increase)
        (global-set-key [C-wheel-down]  'text-scale-decrease)
  2. Mousewheel scrolling


    (setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) ;; one line at a time
    (setq mouse-wheel-progressive-speed nil) ;; don't accelerate scrolling
    (setq mouse-wheel-follow-mouse 't) ;; scroll window under mouse
    (setq scroll-step 1) ;; keyboard scroll one line at a timeou
    (defun scroll-up-10-lines ()
      "Scroll up 10 lines"
      (scroll-up 10))
    (defun scroll-down-10-lines ()
      "Scroll down 10 lines"
      (scroll-down 10))
    ;; for Windows.
    ;; See http://ergoemacs.orgx/emacs/emacs_mouse_wheel_config.html
    (global-set-key (kbd "<wheel-up>") 'scroll-down-10-lines)
    (global-set-key (kbd "<wheel-down>") 'scroll-up-10-lines)
  3. Multiple cursors

    Mark region and use mc/edit-lines, to create multiple cursors, finish with C-g or RET. Or try mc/mark-all-like-this-dwim. There are many more functions, see:

    (req-package multiple-cursors
      :ensure t)
  4. Folding

    Selective hide/showing of parts of the buffer.

    `fold-dwim-org/minor-mode' Minor Mode Bindings: key binding

    With fold-dwim-org/minor-mode you can fold sexps in lisp using TAB.

    • DWIM (Do what I mean) (tab) folding in all programming modes:
    (req-package fold-dwim-org
      :ensure t
      ;; Toggle vimish-fold with Tab key.
      (defadvice fold-dwim-org/toggle (after my-fold-dwim-org/toggle (&optional key lst-point) activate)
        "Call vimish-fold-toggle after fold-dwim-org/toggle"

    FIXME: "Prog mode doesn't support hideshow-mode"

    (add-hook 'emacs-lisp-mode-hook 'hs-minor-mode)
    (add-hook 'python-mode-hook 'hs-minor-mode)
    (add-hook 'lisp-mode-hook 'hs-minor-mode)
    (add-hook 'clojure-mode-hook 'hs-minor-mode)
    (add-hook 'prog-mode-hook 
              (lambda () 

    See also: hs-minor-mode, org-struct-mode, vimish-fold-mode

    1. Lisp Folding

      With fold-dwim-org/minor-mode you can fold sexps in lisp using TAB.

    2. TODO Haskell folding

      Pressing TAB while on a comment could hide code following it until the next paragraph/comment. fold-dwim-org/minor-mode? vimish-folding smart tab??

1.3.2 Performance

Do not reorder bidirectional text for display in the visual order. (source)

This somewhat improves performance when dealing with long lines.

(setq bidi-display-reordering nil)

1.3.3 Backups

By default, Emacs saves backup files in the current directory. These are the files ending in ~ that are cluttering up your directory lists. The following code stashes them all in ~/.emacs.d/backups, where I can find them with C-x C-f (find-file) if I really need to.

(setq backup-directory-alist '(("." . "~/.emacs.d/backups")))

Disk space is cheap. Save lots.

(setq delete-old-versions -1)
(setq version-control t)
(setq vc-make-backup-files t)
(setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save-list/" t)))

1.3.4 Window configuration

  1. Toolbars, menus et c
    (when window-system
      (tooltip-mode -1)
      (tool-bar-mode -1)
      (set-fringe-mode 0)
    (menu-bar-mode -1)
  2. Window Transparency
    ;; Emacs Transparency
    ;;(set-frame-parameter (selected-frame) 'alpha '(<active> [<inactive>]))
    (set-frame-parameter (selected-frame)  'alpha '(100 100))
    ;; (set-frame-parameter (selected-frame) 'alpha '(85 50))
    (add-to-list 'default-frame-alist '(alpha 100 100))
     (eval-when-compile (require 'cl))
     (defun toggle-transparency ()
       (if (/=
            (cadr (frame-parameter nil 'alpha))
           (set-frame-parameter nil 'alpha '(100 100))
         (set-frame-parameter nil 'alpha '(84 50))))
    (global-set-key (kbd "C-c t") 'toggle-transparency)
  3. Fullscreen
    (if (eq system-type 'gnu/linux)  ; GNU/Linux uses the fullscreen-mode package
     (req-package fullscreen-mode
     :ensure fullscreen-mode
     (("<f4>" . fullscreen-mode-fullscreen-toggle))

1.3.5 Modes

  1. Mode hooks

    I want linum mode (line numbers) enabled in these modes:

    (add-hook 'python-mode-hook 'nlinum-mode)


    (add-hook 'python-mode-hook 'fringe-mode)

    Trying auto-complete-mode in these modes:

    (add-hook 'text-mode-hook 'auto-complete-mode)
  2. Version Control
    1. Magit
      (req-package magit
      :ensure magit
      :bind ("C-c m" . magit-status)
      (setq magit-last-seen-setup-instructions "1.4.0")
    2. git-auto-commit-mode

      I like to use auto-commit for some minor personal repositories.

      (req-package git-auto-commit-mode
        :ensure git-auto-commit-mode
        (setq gac-automatically-push-p t)
        (add-hook 'org-capture-mode-hook 'git-auto-commit-mode)
        (add-hook 'org-mode-hook 'git-auto-commit-mode)
    3. vc-check-status

      vc-check-status reminds about uncommitted and unpushed changes when exiting Emacs.

      (req-package vc-check-status
      :ensure vc-check-status
      (vc-check-status-activate 1))
  3. Twittering-mode

    View Twitter timelines or send tweets using M-x tweet.

    (req-package twittering-mode
      :ensure twittering-mode 
      (defalias 'tweet 'twittering-update-status-interactive)
      (setq twittering-use-master-password t)
      ;; Don't show the client type in feed:
      (setq twittering-status-format "%i %s,  %@: 
    %FILL[  ]{%T %L%r%R}
      (add-hook 'twittering-mode-hook 'variable-pitch-mode)
      (setq twittering-icon-mode t)               ; Show icons

1.3.6 Useful extra functions

  1. Sudoedit, edit file as root

    m-x sudoedit reopens the file as root. (source:

    Tip: It is also possible to do:

    alias E="SUDO_EDITOR=\"emacsclient -t -a emacs\" sudoedit"

    in your shell.

    (defun sudo-edit (&optional arg)
      "Edit currently visited file as root.
    With a prefix ARG prompt for a file to visit.
    Will also prompt for a file to visit if current
    buffer is not visiting a file."
      (interactive "P")
      (if (or arg (not buffer-file-name))
          (find-file (concat "/sudo:[email protected]:"
                             (ido-read-file-name "Find file(as root): ")))
        (find-alternate-file (concat "/sudo:[email protected]:" buffer-file-name))))

1.3.7 Files

Open filenames under cursor with M-x find-file-at-point or M-x ffap

(use-package ffap
  :bind ("C-x RET" . find-file-at-point))

1.3.8 Parens

(req-package smartparens :ensure t :config
        (smartparens-global-mode t)
        :require smartparens-config

1.3.9 Encoding

Prefer UTF-8. (source)

(prefer-coding-system 'utf-8)
(when (display-graphic-p)
  (setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)))

1.3.10 Auto completion

    (req-package popup :ensure t)
    (req-package pos-tip :ensure t)
    (req-package popup-kill-ring :ensure t)
    (req-package auto-complete
      :loader :el-get
      :ensure t
      ;; (add-to-list 'ac-dictionary-directories (concat libfiles-dir "/ac-dict"))
      (setq ac-use-menu-map t)
      (define-key ac-menu-map (kbd "ESC") 'viper-exit-popup-menu)
      (define-key ac-complete-mode-map  (kbd "ESC") 'viper-exit-popup-menu)

   (global-set-key "\M-y" 'popup-kill-ring)

    ;;(setq popup-kill-ring-interactive-insert t)

    ;;; describe inline
    ;; (defun my-describe-function (function)
    ;;   "Display the full documentation of FUNCTION (a symbol) in tooltip."
    ;;   (interactive (list (function-called-at-point)))
    ;;   (if (null function)
    ;;       (pos-tip-show
    ;;        "** You didn't specify a function! **" '("red"))
    ;;     (pos-tip-show
    ;;      (with-temp-buffer
    ;;        (let ((standard-output (current-buffer))
    ;;              (help-xref-following t))
    ;;          (prin1 function)
    ;;          (princ " is ")
    ;;          (describe-function-1 function)
    ;;          (buffer-string)))
    ;;      nil nil nil 0)))
    ;; (define-key emacs-lisp-mode-map (kbd "C-;") 'my-describe-function)

    ;;; autocomplete advice
;;    (req-package  popup-pos-tip :ensure t)
    (defadvice popup-tip
      (around popup-pos-tip-wrapper (string &rest args) activate)
      (if (eq window-system 'ns)
          (apply 'popup-pos-tip string args)

    (setq default-frame-alist
          '((width             . 155)
            (height            . 44)
            (tool-bar-lines . 0)
            (menu-bar-lines . 1)
            (background-color . "#111111")
            (background-mode . dark)
            (border-color . "black")
            (cursor-color . "white")
            (foreground-color . "white")

    ;; tab expansion with hippie and yas
    ;; from

    (setq hippie-expand-try-functions-list

    (req-package yasnippet :ensure t
      (setq yas/root-directory "~/.emacs.d/snippets")
      (yas/load-directory yas/root-directory)
      (yas/global-mode 1)

    ;; Helps when debugging which try-function expanded
    (setq hippie-expand-verbose t)

    (defvar smart-tab-using-hippie-expand t
      "turn this on if you want to use hippie-expand completion.")

    (defun smart-tab (prefix)
      "Needs `transient-mark-mode' to be on. This smart tab is
      minibuffer compliant: it acts as usual in the minibuffer.
      In all other buffers: if PREFIX is \\[universal-argument], calls
      `smart-indent'. Else if point is at the end of a symbol,
      expands it. Else calls `smart-indent'."
      (interactive "P")
      (labels ((smart-tab-must-expand (&optional prefix)
                                      (unless (or (consp prefix)
                                        (looking-at "\\_>"))))
        (cond ((minibufferp)
              ((smart-tab-must-expand prefix)
               (if smart-tab-using-hippie-expand
                   (hippie-expand prefix)
                 (dabbrev-expand prefix)))

    (defun smart-indent ()
      "Indents region if mark is active, or current line otherwise."
      (if mark-active
        (indent-region (region-beginning)

    ;; Bind tab everywhere
    (global-set-key (kbd "TAB") 'smart-tab)

    ;; Enables tab completion in the `eval-expression` minibuffer
    (define-key read-expression-map [(tab)] 'hippie-expand)
    (define-key read-expression-map [(shift tab)] 'unexpand)

    ;; Replace yasnippets's TAB
    (add-hook 'yas/minor-mode-hook
              (lambda () (define-key yas/minor-mode-map
                           (kbd "TAB") 'smart-tab))) ; was yas/expand

    (provide 'ej-autocomplete)

1.3.11 Dired

(put 'dired-find-alternate-file 'disabled nil)

1.3.12 Modeline

  1. Display total number of lines in the modeline

    A hack to display the total number of lines of files in the modeline. It only updates when opening and saving files for performance reasons. (source)

    FIXME: Disabled because it conflicts with smart-mode-line

    (defvar my-mode-line-buffer-line-count nil)
    (make-variable-buffer-local 'my-mode-line-buffer-line-count)
    (setq-default mode-line-format
                  '("  " mode-line-modified
                    (list 'line-number-mode "  ")
                    (:eval (when line-number-mode
                             (let ((str "L%l"))
                               (when (and (not (buffer-modified-p)) my-mode-line-buffer-line-count)
                                 (setq str (concat str "/" my-mode-line-buffer-line-count)))
                    "  %p"
                    (list 'column-number-mode "  C%c")
                    "  " mode-line-buffer-identification
                    "  " mode-line-modes))
    (defun my-mode-line-count-lines ()
      (setq my-mode-line-buffer-line-count (int-to-string (count-lines (point-min) (point-max)))))
    (add-hook 'find-file-hook 'my-mode-line-count-lines)
    (add-hook 'after-save-hook 'my-mode-line-count-lines)
    (add-hook 'after-revert-hook 'my-mode-line-count-lines)
    (add-hook 'dired-after-readin-hook 'my-mode-line-count-lines)
  2. unique file names in modeline

    Very useful if operating on files which have the same name but are placed in different directories.

    (require 'uniquify)
    (setq uniquify-buffer-name-style 'post-forward-angle-brackets)

1.3.13 Miscellaneous

Unsorted general configuration.

  1. Minimap
    minimap-width-fraction 0.2)
    minimap-window-location (quote right))
  2. Nlinum
    (setq global-nlinum-mode nil)

1.4 Appearance

1.4.1 Theme

Good themes (dark): tango-dark, monokai, solarized-dark, heroku, minimal (no colors), monochrome (same, misterioso), cyberpunk. brighter themes: solarized-light, anti-zenburn

Tip: Check for a theme gallery

(setq monokai-use-variable-pitch nil)
(setq visible-bell 1)                   ; Disables the audible bell.

1.4.2 Line numbers

nlinum is appearantly faster than the normal linum-mode.

(req-package nlinum
  :ensure nlinum

  (defun fix-linum-size ()
    (set-face-attribute 'linum nil :height 120))

  (add-hook 'nlinum-mode-hook 'fix-linum-size)
  (setq linum-format " %4d   ")
  (setq nlinum-format " %4d   ")

1.4.3 Big Fringe (Margins)

;; From "Emacs, Naked."

(defvar bzg-big-fringe-mode nil)
(define-minor-mode bzg-big-fringe-mode
  "Minor mode to hide the mode-line in the current buffer."
  :init-value nil
  :global t
  :variable bzg-big-fringe-mode
  :group 'editing-basics
  (if (not bzg-big-fringe-mode)
      (set-fringe-style nil)
     (/ (- (frame-pixel-width)
           (* 100 (frame-char-width)))

1.4.4 Mode-line

  1. Beautify mode-line
    (req-package smart-mode-line            ; maybe a better modeline
                 :ensure t
                 :require nyan-mode smart-mode-line-powerline-theme
                 :init (sml/setup)
                    (sml/apply-theme 'powerline)
  2. Toggle mode-line with hidden-mode-line-mode

    bzg writes:

    Sometimes I don't want to display the mode-line.

    This minor mode helps me switching it on and off:

    (defvar-local hidden-mode-line-mode nil)
    (define-minor-mode hidden-mode-line-mode
      "Minor mode to hide the mode-line in the current buffer."
      :init-value nil
      :global t
      :variable hidden-mode-line-mode
      :group 'editing-basics
      (if hidden-mode-line-mode
          (setq hide-mode-line mode-line-format
                mode-line-format nil)
        (setq mode-line-format hide-mode-line
              hide-mode-line nil))
      ;; Apparently force-mode-line-update is not always enough to
      ;; redisplay the mode-line
      (when (and (called-interactively-p 'interactive)
         0 nil 'message
         (concat "Hidden Mode Line Mode enabled.  "
                 "Use M-x hidden-mode-line-mode to make the mode-line appear."))))

1.4.5 Fonts and faces

The default font is used for most faces. Sometimes I want to use a serif font non-monospace font such as Times New roman or Gotham HTF and other times I prefer a monospace font such as Consolas (Windows), Monaco (Mac) or Dejavu Sans (GNU/Linux).

  1. Font helper function

    Note: To experiment with font selection, use the menu then the C-u C-x = command to find the name of the font used.

    Other faces, besides "default" which you might want to set fonts for are: "fixed-pitch" and "linum".

    (require 'cl)
      (defun font-candidate (&rest fonts)
         "Return existing font which first match."
         (find-if (lambda (f) (find-font (font-spec :name f))) fonts))
  2. Default font (monospace)

    Choose which block to tangle depending on font preference. See also the variable-pitch-mode for when you want to default to monospace but sometimes toggle to use "variable pitch".

    Alternative serif fonts on Windows: Cambria, Times New Roman, Gotham HTF Light (?)

    1. Serif font as default font [disabled]:
      (when window-system
      (set-face-attribute 'default nil :font (font-candidate '
                                              "Times New Roman-14:weight=normal:height:120" 
                                              "Liberation Serif-12" 
                                              "DejaVu Sans Mono-10:weight=normal" 
                                              "Gill Sans-14"
    2. Monospace as default font:
      (when window-system
        (set-face-attribute 'default nil :font (font-candidate '
                                                "Anonymous Pro-14"
                                                "DejaVu Sans Mono-14"
                                                "PT Mono-14"
                                                "Source Code Pro-11" 
                                                "DejaVu Sans Mono-11:weight=normal"
        (set-face-attribute 'fixed-pitch nil :font (font-candidate '
                                                    "Source Code Pro-14" 
                                                    "DejaVu Sans Mono-11:weight=normal"
    3. Use a different default font when on Mac
      (if (eq system-type 'darwin)
          (when window-system
            (set-face-attribute 'default nil :font (font-candidate '
                                                    "Source Code Pro-14" 
                                                    "DejaVu Sans Mono-11:weight=normal"
            (set-face-attribute 'fixed-pitch nil :font (font-candidate '
                                                        "Source Code Pro-14" 
                                                        "DejaVu Sans Mono-11:weight=normal"
  3. Variable pitch font
    1. Monospace as variable pitch font [disabled]
      (when window-system 
        (set-face-attribute 'variable-pitch nil :font (font-candidate '
                                                       "DejaVu Sans Mono-10:weight=normal"
    2. Serif font as variable pitch font
      (when window-system
        (set-face-attribute 'variable-pitch nil :font (font-candidate '
                                                       "Gill Sans MT-16"
                                                       "Hoefler Text-16"
                                                       "Segoe Script-14"                                                      
                                                       "Liberation Serif-12" 
                                                       "Times New Roman-14:weight=normal:height=120" 
                                                       "DejaVu Sans Mono-10:weight=normal" 
    3. Variable pitch for Mac
      (if (eq system-type 'darwin)
          (when window-system
            (set-face-attribute 'variable-pitch nil :font (font-candidate '
                                                           "Helvetica Neue-14"
                                                           "Gill Sans-14"
                                                           "Times New Roman-14:weight=normal:height=120" 
                                                           "DejaVu Sans Mono-10:weight=normal" 
  4. Text mode font
        (add-hook 'text-mode-hook 'variable-pitch-mode)
    ;;    (add-hook 'gnus-article-mode-hook 'variable-pitch-mode)
  5. Font for org-mode tables and code blocks


    (defun my-adjoin-to-list-or-symbol (element list-or-symbol)
      (let ((list (if (not (listp list-or-symbol))
                      (list list-or-symbol)
        (require 'cl-lib)
        (cl-adjoin element list)))
    (eval-after-load "org"
        (lambda (face)
           face nil
            (face-attribute face :inherit))))
        (list 'org-code 'org-block 'org-table)))
  6. Linum font
    ;; (set-face-attribute 'linum nil :font (font-candidate '"Cambria-14" "Times New Roman-14:weight=normal:height:120" "DejaVu Sans Mono-10:weight=normal" "Gill Sans-14"))
    ;; (set-face-attribute 'linum nil :font (font-candidate ' "Times New Roman-14:weight=normal:height:120" "DejaVu Sans Mono-10:weight=normal" "Gill Sans-14"))
  7. Pretty lambda

    Display the greek character lambda instead of the word.

    (req-package pretty-lambdada
      :ensure pretty-lambdada)

1.4.6 Rainbow delimiters

(req-package rainbow-delimiters)

1.4.7 Zooming (text size et. c)

Global text size config using Solves: Command to resize font for entire frame (as opposed to on a buffer by buffer basis.) Issue: Doesn't handle full screen mode properly. Issue: Resizes the frame.

(req-package zoom-frm
  (define-key ctl-x-map [(control ?+)] 'zoom-in/out)
    (define-key ctl-x-map [(control ?-)] 'zoom-in/out)
    (define-key ctl-x-map [(control ?=)] 'zoom-in/out)
    (define-key ctl-x-map [(control ?0)] 'zoom-in/out)

1.5 Platform specific configuration

1.5.1 Windows specific settings

Setting the PATH so that GNU find, grep and other programs will work properly.

  (if (eq system-type 'windows-nt)  ; Windows settings
     (setq home "c:/Users/jmn") 
     (setq default-directory "c:/Users/jmn") 
(setenv "PATH"
   ;; Change this with your path to MSYS bin directory
   "C:\\Program Files (x86)\\GnuWin32\\bin;"
   (getenv "PATH")))))

1.5.2 MacOS specific settings

  1. Notes

    Note: To work effectively with Emacs on Mac you might want to reconfigure a few things in MacOS, namely:

    • Rebind Caps lock to function as a control key
    • Free C-Space from being bound to spotlight (it's used in Emacs to mark region). To do this see: System Preferences > Keyboard > Keyboard Shortcuts > Spotlight. Rebind Spotlight to something else (i.e C-Option-Space).
    1. Problematic keybindings / conflicts

      With paredit: On Mac, C-<left arrow>/<right arrow> is already bound.

  2. Configuration
      (if (eq system-type 'darwin)
           (setq mac-option-modifier nil
              mac-command-modifier 'meta
              x-select-enable-clipboard t)
    (when (memq window-system '(mac ns))

    Launching Emacs from Mac OS Spotlight (launchd) will not provide the same paths as if you would launch it from bash, the exec-path-from-shell package fixes this (useful for tools like leiningen and others)

1.6 Keybindings

  1. Fonts, themes et c
    (global-set-key '[f12] 'variable-pitch-mode)
    (global-set-key '[f8]  '(lambda () (interactive) (auto-complete-mode)))
    (global-set-key '[f9]  '(lambda () (interactive) (load-theme 'anti-zenburn t)))
    (global-set-key '[f10] '(lambda () (interactive) (load-theme 'yellow-postits t)))
  2. Global org-mode bindings
    (global-set-key (kbd "C-c c") 'org-capture)
    (global-set-key (kbd "C-c o") 'org-capture-goto-last-stored)
    (global-set-key (kbd "C-c a") 'org-agenda)

1.7 Activity specific configuration

('cuz polycephaly)

1.7.1 Writing

  1. ASCIIDoc mode (adoc-mode)
    (req-package adoc-mode
    :ensure adoc-mode
    :mode "\\.asciidoc\\'"
    (add-hook 'adoc-mode-hook (lambda() (buffer-face-mode t))))
  2. Visual line mode in text (and org) files

    visual-line-mode is so much better than auto-fill-mode. It doesn't actually break the text into multiple lines - it only looks that way.

    (remove-hook 'text-mode-hook #'turn-on-auto-fill)
    (add-hook 'text-mode-hook 'turn-on-visual-line-mode)
    (global-visual-fill-column-mode t) ;; Trying this setting
  3. Writeroom-mode

    Writeroom-mode hides most UI elements.

    (use-package writeroom-mode
      :ensure writeroom-mode

1.7.2 Reading News and feeds

  1. elfeed
    (req-package elfeed
    :ensure elfeed
        (add-hook 'elfeed-show-mode-hook 'variable-pitch-mode)
  2. Newsticker

    Use variable pitch fonts for reading feeds with newsticker.

    (add-hook 'newsticker-treeview-item-mode-hook 'variable-pitch-mode)

1.7.3 org-mode

note-taking, activity management et c.

  1. Keybindings (global)
    (global-set-key "\C-cl" 'org-store-link)
    (global-set-key "\C-ca" 'org-agenda)
    (global-set-key "\C-cb" 'org-iswitchb)
  2. Todos

    Record a completion message when closing todos.

    (setq org-log-done 'note)
  3. org-related packages
    1. Bibtex export
      (require 'ox-bibtex)
    2. org-protocol

      Org-protocol allow for OS links to be opened in emacs, provided the environment has been configured correctly. For Windows, put this in a .reg file and execute it (make sure to set the correct path to emacsclientw.exe): See documentation.

      (require 'org-protocol)
    3. Some firefox issue handling

      For some reason, the argument passed to emacs by firefox javascript is improperly encoded. Here are some ways to solve that.

      ;; If the org property value of CODING is not nil, mark the (capture) buffer it and use recode-region to recode it to UTF-8.
      (defun jmn/recode-buffer-from-cp1252-to-utf-8 () 
        (message "recoding buffer!")
        (recode-region (region-beginning) (region-end) 'cp1252 'utf-8)
      (add-hook 'org-capture-prepare-finalize-hook 
                '(lambda () 
                   (if (cdr(assoc "CODING" (org-entry-properties nil 'standard)))
                     (org-delete-property "CODING")
    4. Windows registry setup
      @="URL:Org Protocol"
      "URL Protocol"=""
      @="\"C:\\Program Files\\emacs-25\\bin\\emacsclientw.exe\" \"%1\""
  4. General org-mode buffer settings

    Change the font-face so that only the last star indicating an org-mode headline is displayed. This is less resource intensive - and slightly different from - org-indent-mode).

    (setq org-hide-leading-stars 't)

    Enable ignore tags to hide headlines when publishing and just show content. (Source)

    (require 'ox-extra)
    (ox-extras-activate '(ignore-headlines))
  5. Inline code (org-babel)
    1. Load languages
        ;; Load relevant languages
         '((emacs-lisp . t)
    2. Language mode specific settings
      1. Clojure

        Use cider as the clojure execution backend.

        ;;    (setq org-babel-clojure-backend 'cider)
    3. Indention and tabs, Tabs and indentation, in code blocks
      ;; Let's have pretty source code blocks
      ;; FIXME:  org-src-fontify-natively t -- Problem with variable pitch fonts.
      (setq org-src-fontify-natively nil)
      (setq org-edit-src-content-indentation 4        ;; Controls indentation in org-mode code blocks.
            org-src-tab-acts-natively t
            org-confirm-babel-evaluate nil)
    4. Code block expansion templates

      Type <s [TAB] , <el [TAB et c to create code blocks. (source)

      ;; add <p for python expansion
      (add-to-list 'org-structure-template-alist
                   '("p" "#+BEGIN_SRC python\n?\n#+END_SRC " "<src lang=\"python\">\n?\n</src>"))
      ;; add <el for emacs-lisp expansion
      (add-to-list 'org-structure-template-alist
                   '("el" "#+BEGIN_SRC emacs-lisp \n?\n#+END_SRC " "<src lang=\"emacs-lisp\">\n?\n</src>"))
    5. Evaluation

      To make code blocks evaluate silently by default:

      (setq org-babel-default-header-args
                '((:results . "silent")
  6. org-capture templates
    (setq org-capture-templates
         ("n" "Short note" entry (file+datetree "~/org/") 
          "* %?\n  %i\n  %a")
         ("b" "Weblog post" entry (file+datetree "~/org/") 
          "* %^{Title}\n :PROPERTIES:\n:on: %T\n:END:\n  %? %i" :empty-lines 1)
         ("B" "Bookmark" entry (file+datetree "~/org/")
         "* %(concat \"[[\" (jk/moz-url) \"][\" (jk/moz-title) \"]]\")\n Entered on %U\n")
         ("t" "Todo" entry (file+headline "~/org/" "Tasks")
              "* TODO %?\n  %i\n  %a")
         ("h" "htfdi" entry (file+headline "~/git/notes/" "htfdi")
          "* TODO %?\n  %i\n  %a")
         ("f" "Capture bookmark from firefox" entry (file+datetree "~/org/") 
          "* %?\n:PROPERTIES:\n:CODING: cp1252\n:END:\n%i\n  %a" :empty-lines 1)
  7. Notes

    My bindings for org-mode

    binding M-x description
    C-c a org-agenda Agenda view
    C-c c org-capture-goto-last-stored Capture via templates
    C-c o org-revisit  
    • TODO It would be neat if the above table could be used to generate the required emacs-lisp for the keybindings.
  8. Faces

    Even if I sometimes use variable-pitch-mode when reading org-files, I still want the tables and code blocks to use fixed pitch (monospaced fonts).

  9. Monospace fonts for tables, quotes et c
    (set-face-attribute 'org-table nil :inherit 'fixed-pitch)
    (set-face-attribute 'org-code nil :inherit 'fixed-pitch)
    (set-face-attribute 'org-block nil :inherit 'fixed-pitch)
    (set-face-attribute 'org-verbatim nil :inherit 'fixed-pitch)
    (set-face-attribute 'org-block-begin-line nil :inherit 'fixed-pitch)
    (set-face-attribute 'org-block-end-line nil :inherit 'fixed-pitch)
    (set-face-attribute 'font-lock-builtin-face nil :inherit 'fixed-pitch)
  10. Encryption

    With org-crypt loaded, the text of an entry can be encrypted if there is a :crypt: tag set on the headline. Use M-x org-set-tags to set crypt. To read the entry use M-x org-decrypt-entry. (source)

    (require 'org-crypt)
    (setq org-tags-exclude-from-inheritance (quote ("crypt")))
    ;; GPG key to use for encryption
    ;; Either the Key ID or set to nil to use symmetric encryption.
    (setq org-crypt-key nil)
  11. Citing

    See Github:jkitchin/org-ref

    (req-package org-ref
      :ensure t)

    Customize org-ref-bibliography-entry-format to match your BibTeX entries. See org-ref-reftex-format-citation for more information.

       (("article" . "%a, %t, <i>%j</i>, <b>%v(%n)</b>, %p (%y). <a href=\"%U\">link</a>. <a href=\"\">doi</a>.")
        ("book" . "%a, %t, %u (%y).")
        ("techreport" . "%a, %t, %i, %u (%y).")
        ("proceedings" . "%e, %t in %S, %u (%y).")
        ("inproceedings" . "%a, %t, %p, in %b, edited by %e, %u (%y)")
        ("misc" . "%a</a>, %t, <a href=\"%U\">%U</a>, %N")
        ("online" . "%a, %t, <a href=\"%U\">%U</a>, %N, %Y"))))
  12. Publishing, Export
    1. General export settings
      1. HTML Export - An attempt at an export-as html.

        Ideally org-html-export-as-html should take the universal argument to prompt the user for a filename.

        Helper function for exporting HTML with user specified filename.

        (defun jmn/org-export-html ()
          ;;  First kill the HTML export buffer
          (let ((exportBuffer  "*Org HTML Export*"))
            (when (buffer-live-p exportBuffer)
              ((kill-buffer exportBuffer)
              (set-buffer exportBuffer)
              (command-execute 'write-file "foo.html")
              (browse-url-of-file "foo.html")
      2. Custom export backends
        1. Org-reveal (ox-reveal): for Reveal.js slide presentations.
          (req-package ox-reveal
          :load-path "~/git/org-reveal/"
          (setq org-reveal-root "")
      3. Source code highlighting

        Don't create inline CSS source code highlighting by default.

        (setq org-html-htmlize-output-type 'css)
    2. Publish projects
      (setq org-publish-project-alist
               :base-directory "~/Dropbox/notes"
               :base-extension "org"
               :publishing-directory "~/git/"
               :publishing-function org-html-publish-to-html
               :completion-function ((lambda (x) (let ((fromF "~/git/")
                                                  (toF "~/git/"))
                                              (when (file-exists-p fromF)
                                                (rename-file fromF toF t)
                                                (message "Made a file ~/git/")
               :html-extension "html"
               :recursive nil
               :include ("" "")
               :exclude "\\.org$"
               :base-directory "~/git/notes/"
               :base-extension "org"
               :publishing-directory "~/git/"
               :recursive nil
               :publishing-function org-html-publish-to-html
               :include ("" "" "" "")
               :exclude "\\.org$"
               :base-directory "~/git/notes/"
               :base-extension "org"
               :publishing-directory "~/git/"
               :recursive nil
               :publishing-function org-org-publish-to-org
               :include ("" "~/git/notes/")
               :exclude "\\.org$"
    3. Org-jekyll

      Export configuration for Juan Reyeros org-jekyll to export org subtrees to Jekyll. The subtrees must have the tag "blog" and a property "on" with a timestamp.

      1. Helper function "blogthis" to export org subtrees to jekyll via org-jekyll.
        (require 'ox)
            (defun blogthis ()
              "add the necessary tags and properties to publish an org subtree"
              (org-back-to-heading t)
              (org-set-tags-to "blog")
              (org-set-property "on" (format-time-string "%Y-%m-%d %H:%M" (current-time)))
      2. Org-jekyll configuration

        Note: Org-jekyll is not maintained. Use my branch of org-jekyll. (The ELPA version creates bad YAML front-matter.) See PR on github.

        (req-package org-jekyll
          :load-path "~/git/org-jekyll"
          :loader "built-in"
          (add-to-list 'org-publish-project-alist
                         :base-directory "~/org"
                         :recursive t
                         :base-extension "org"
                         :publishing-directory "~/git/"
                         :exclude "^blog\\|^bitacora\\|"
                         :site-root ""
                         :jekyll-sanitize-permalinks t
                         :publishing-function org-html-publish-to-html
                         :section-numbers nil
                         :headline-levels 4
                         :table-of-contents t
                         :auto-index nil
                         :auto-preamble nil
                         :body-only nil
                         :auto-postamble nil))
          (add-to-list 'org-publish-project-alist
                       '("jmn" :components ("jmn-org")))
      3. Run jekyll after org-capture
                                                ; FIXME: This currently does not work as ork-jekyll-export-current-entry
                                                ; uses the filename to get the org project and the capture buffer has no 
                                                ; file name.
        (add-hook 'org-capture-after-finalize-hook 'org-jekyll-export-current-entry)
    4. Jekyll

      Function to insert a YAML front matter (at cursor point).

      (defun insert-YAML-front-matter (string)
        "Insert \label{ARG} \index{\nameref{ARG}} at point"
        (interactive "sString for \\title: ")
        (insert "#+BEGIN_HTML
      layout: post
      title: \"" string "\" 
    5. Blogging, with org2blog

      I have a blog and use org2blog to publish posts. Authentication info is in ~/.authinfo and follows the following form: machine myblog login myusername password myrealpassword

      See the org2blog webpage for more information.

      To blog I usually just use M-x org2blog/wp-post-subtree from an org-mode subtree.

      (unless (package-installed-p 'org2blog)  
        (package-install 'org2blog))     
      (require 'org2blog-autoloads)
      (setq org2blog/wp-blog-alist
               :url ""
               :username "jmnoz"
               :default-title "Hello World"
               :default-categories ("org2blog" "emacs")
               :tags-as-categories nil)
      (require 'auth-source) ;; or nothing if already in the load-path
      (let (credentials)
        ;; only required if your auth file is not already in the list of auth-sources
        (add-to-list 'auth-sources "~/.authinfo")
        (setq credentials (auth-source-user-and-password "wordpress"))
        (setq org2blog/wp-blog-alist
                 :url ""
                 :username ,(car credentials)
                 :password ,(cadr credentials)))))

1.7.4 Programming

  1. General programming settings
    1. Parentheses
      (add-hook 'prog-mode-hook 'show-paren-mode)
    2. Enable line number mode
      (add-hook 'prog-mode-hook
                    '(lambda () (nlinum-mode 1)))
    3. Fringe

      Enable the fringe in programming modes

      (add-hook 'prog-mode-hook
                    '(lambda () (set-fringe-mode `(8 . 0))))
    4. Highlight keywords such as "FIXME"
      ;; FIXME: This highlights FIXME:'s 
      (add-hook 'prog-mode-hook
                (lambda ()
                  (font-lock-add-keywords nil
                                          '(("\\<\\(FIXME\\|TODO\\|BUG\\):" 1 font-lock-warning-face t)))))
    5. Highlight changes mode

      Launch highlight-changes-mode in an invisible state for all programming modes, use M-x highlight-changes-visible-mode to show any changes made.

      (setq highlight-changes-visibility-initial-state nil)
      (add-hook 'prog-mode-hook
                '(lambda () (highlight-changes-mode 1)))
      (add-hook 'org-mode-hook
                '(lambda () (highlight-changes-mode 1)))
      1. Visual configuration of highlight changes mode
        1. Faces
          (set-face-attribute 'highlight-changes nil)
        2. Display in fringe

          (source) Thanks to SO user d5884

          (eval-after-load "hilit-chg"
               (defvar highlight-fringe-mark 'filled-square
                 "The fringe bitmap name marked at changed line.
          Should be selected from `fringe-bitmaps'.")
               (defadvice hilit-chg-make-ov (after hilit-chg-add-fringe activate)
                 (mapc (lambda (ov)
                     (if (overlay-get ov 'hilit-chg)
                     (let ((fringe-anchor (make-string 1 ?x)))
                       (put-text-property 0 1 'display
                              (list 'left-fringe highlight-fringe-mark)
                       (overlay-put ov 'before-string fringe-anchor))
                   (overlays-at (ad-get-arg 1))))))
  2. Haskell
    (req-package intero-mode
      (add-hook 'haskell-mode-hook 'intero-mode)
    1. Mediocre code-folding

      Use C-Tab (M-x outline-cycle) to fold outlines.

      (req-package outline-magic
      (eval-after-load 'outline
          (require 'outline-magic)
          (define-key outline-minor-mode-map (kbd "<C-tab>") 'outline-cycle)))
      (defun haskell-outline-level ()
        (let (buffer-invisibility-spec)
            (skip-chars-forward "    \n")
      (add-hook 'haskell-mode-hook (lambda ()
                                     (set (make-local-variable 'outline-regexp)
                                          (rx (* anything) (or "do" "mdo" "where")
                                     (set (make-local-variable 'outline-level) #'haskell-outline-level)
  3. Web programming: ASP
    (req-package asp-mode
        (autoload 'asp-mode "asp-mode")
        (setq auto-mode-alist 
           (cons '("\\.asp\\'" . asp-mode) auto-mode-alist))
        (add-hook 'asp-mode-hook 'nlinum-mode)
  4. HTML mode
    (add-hook 'html-mode-hook 'prog-mode)
    1. Browser communication
      1. Communicate via firefox using mozrepl (telnet)
        1. Hack to get org-mode links from the current firefox tab

          The following requires a repl to be connected, start it using the firefox toolbar and in Emacs: M-x run-mozilla. (source).

              (req-package moz
              :ensure moz
              (defun jk/moz-get (attr)
                (comint-send-string (inferior-moz-process) attr)
                ;; try to give the repl a chance to respond
                (sleep-for 0 100))
              (defun jk/moz-get-current-url ()
                (jk/moz-get "repl._workContext.content.location.href"))
              (defun jk/moz-get-current-title ()
                (jk/moz-get "repl._workContext.content.document.title"))
              (defun jk/moz-get-current (moz-fun)
                (funcall moz-fun)
                ;; doesn't work if repl takes too long to output string
                  (set-buffer (process-buffer (inferior-moz-process)))
                  (goto-char (point-max))
                  (setq jk/moz-current (buffer-substring-no-properties
                                        (+ (point-at-bol) (length moz-repl-name) 3)
                                        (- (point-at-eol) 1))))
                (message "%s" jk/moz-current)
              (defun jk/moz-url ()
                (jk/moz-get-current 'jk/moz-get-current-url)
              (defun jk/moz-title ()
                (jk/moz-get-current 'jk/moz-get-current-title)
              (defun jmn/org-link-from-firefox ()
                (insert (concat "[[" (jk/moz-url) "][" (jk/moz-title) "]]"))
    2. Colors helper function

      Colors hexadecimal RGB (e.g. #ff0033)values by their value (source).

      (defun xah-syntax-color-hex ()
      "Syntax color hex color spec such as 「#ff1100」 in current buffer."
            (0 (put-text-property
                (match-beginning 0)
                (match-end 0)
                'face (list :background (match-string-no-properties 0)))))))
  5. Go autocomplete


    ;;    (req-package auto-complete
    ;;    :ensure t
    ;; :loader elpa)
        (req-package go-mode
        :ensure go-mode)
        (req-package go-autocomplete
        :ensure go-autocomplete)
    ;;    (require 'auto-complete-config)
        (add-hook 'go-mode-hook 'auto-complete-mode)
  6. Javascript
    (setq js-indent-level 2)
  7. Clojure
    1. Hooks

      By using orgstruct-mode in Clojure-mode, we can fold away sexps with f{org-cycle}.

      ; (add-hook 'clojure-mode-hook 'turn-on-orgstruct)
    2. Paredit

      Enable paredit-mode in clojure-mode and the cider REPL.

      ;;    (use-package cider 
      ;        :config
      ;;    (setq nrepl-hide-special-buffers t
      ;;          cider-repl-pop-to-buffer-on-connect nil
      ;;          cider-popup-stacktraces nil
      ;;          cider-repl-popup-stacktraces t)
  8. Visual Dataflex
    ;; Visual Dataflex temporary setup FIXME: Cleanup redundant code.
    (add-to-list 'auto-mode-alist '("\\.sws\\'" . prog-mode))
    (add-to-list 'auto-mode-alist '("\\.src\\'" . prog-mode))
    (add-to-list 'auto-mode-alist '("\\.pkg\\'" . prog-mode))
    (add-to-list 'auto-mode-alist '("\\.dfo\\'" . prog-mode))
    (add-to-list 'auto-mode-alist '("\\.wo\\'" . prog-mode))
    (add-to-list 'auto-mode-alist '("\\.wv\\'" . prog-mode))
    (add-to-list 'auto-mode-alist '("\\.sl\\'" . prog-mode))
    (modify-coding-system-alist 'file "\\.\\(sve\\|src\\|inc\\|[pP][kK][gG]\\|vw\\|bp\\|SL\\|dg\\|rv\\|frm\\|wo\\)\\'" 'cp437)
  9. Magit - nice git interface
    1. Notes, set up

      To perform push/pull to remote repositories over SSH you need to configure your local key management.

      1. How to configure ssh keys on MS Windows

        See here:

        You will need to launch git bash to get ssh-agent running before starting Emacs, then (load-file "~/.ssh/agent.env.el").

        (if (eq system-type 'windows-nt)  ; Windows settings
            (load-file "~/.ssh/agent.env.el")
        1. Install Git for Windows (msysgit)

        Authentication is usually the tricky part (it can cause the git process to appear to hang on pull/push)

        For HTTPS authentication see:

      2. How to configure SSH keys on Mac

1.7.5 Editing

By default the C-x C-u binding for upcase-region is disabled.

(put 'upcase-region 'disabled nil)
  1. Digits increment/decrement

    This function can be used with C-u to decrement or increment by a given number. Source: Emacswiki IncrementNumber

    (defun my-increment-number-decimal (&optional arg)
      "Increment the number forward from point by 'arg'."
      (interactive "p*")
          (let (inc-by field-width answer)
            (setq inc-by (if arg arg 1))
            (skip-chars-backward "0123456789")
            (when (re-search-forward "[0-9]+" nil t)
              (setq field-width (- (match-end 0) (match-beginning 0)))
              (setq answer (+ (string-to-number (match-string 0) 10) inc-by))
              (when (< answer 0)
                (setq answer (+ (expt 10 field-width) answer)))
              (replace-match (format (concat "%0" (int-to-string field-width) "d")
    (global-set-key (kbd "C-c i") 'my-increment-number-decimal)

1.7.6 Diffing (ediff)

  1. Ediff for org-files

    Running ediff on org files might cause trouble with hidden lines. This code attempts to remedy that. (source)

    (add-hook 'ediff-prepare-buffer-hook 'f-ediff-prepare-buffer-hook-setup)
    (defun f-ediff-prepare-buffer-hook-setup ()
      ;; specific modes
      (cond ((eq major-mode 'org-mode)
            ;; room for more modes
      ;; all modes
      (setq truncate-lines nil))
    (defun f-org-vis-mod-maximum ()
      "Visibility: Show the most possible."
       ((eq major-mode 'org-mode)
        (visible-mode 1)  ; default 0
        (setq truncate-lines nil)  ; no `org-startup-truncated' in hook
        (setq org-hide-leading-stars t))  ; default nil
        (message "ERR: not in Org mode")

1.7.7 Communication

  1. IRC
    • CLOSING NOTE [2015-11-27 Fri 21:07]

    Use M-x erc-tls to connect

    Suppress some information:

    ;; Hide Join/part/quit messages from IRC "lurkers" (people who aren't active).
    (setq erc-lurker-hide-list '("JOIN" "PART" "QUIT"))
    ;; Hide user lists when joining channels
    (setq erc-hide-list '("353" "366"))

    Try to align messages to eachother and right align nicknames in messages.

    (setq erc-fill-function 'erc-fill-static)
    (setq erc-fill-static-center 15)
    1. Be more like irssi
      (req-package erc)
  2. Jabber (XMPP)
    (req-package jabber
    :ensure jabber
    (setq jabber-invalid-certificate-servers '(""))
  3. E-mail and feeds (gnus and Gmail)

    For more info See here.

    1. Address book - bbdb

      see Emacswiki for documentation.

      (req-package bbdb
      :ensure bbdb
      (setq bbdb/news-auto-create-p t)
      (setq bbdb/mail-auto-create-p nil)
      (add-hook 'message-setup-hook 'bbdb-mail-aliases)
    2. The group mode

      By using %C in the modeline, the group's "comment" will be displayed if there is one. If there is no comment, the group name will be displayed. Documentation

      To set the comment of a group, press G c to edit via interface (or G p to edit as emacs-lisp)

      ;;    (setq gnus-group-line-format "%M%S%5y/%-5t: %C\n")
      (setq gnus-group-line-format "%M%S%5y: %C\n")
    3. Topics

      I like to use topics to organize groups in gnus.

      You can organize your groups into different topics in the Group buffer. First make sure gnus-topic-mode is added to the gnus-group-mode-hook, then use the options in the Topics menu to organize your groups into topics.

      (add-hook 'gnus-group-mode-hook 'gnus-topic-mode)

      Another annoyance for me is that by default the <tab> key is bound to gnus-topic-indent, and I often found myself pressing it by mistake when I meant to fold a topic. By default topics can only be folded when the cursor is on a topic line. The following command fixes that: (source) I bind this command to <tab> to avoid the previously mentioned annoyance.

      (defun gnus-topic-fold-this-topic nil
            "Toggle folding of current topic."
            (gnus-topic-goto-topic (gnus-current-topic))
    4. .authinfo

      This is how the .authinfo should look. Note: make sure to make it readable to your user only (chmod 0600) i.e. using M-x set-file-modes.

      machine gmail login [email protected] password mypassword
      machine login [email protected] password mypassword port 993
      machine login [email protected] password mypassword port 587
      machine wordpress login myuser password mypassword
    5. Reading feeds with gwene

      Use ^ to enter gwene, search for feeds and subscribe with u Use G c and add a comment to "rename the feed".

      (add-to-list 'gnus-secondary-select-methods '(nntp ""))
      ;; (setq gnus-group-line-format "%M%S%5y/%-5t: %D\n")
        (setq gnus-user-date-format-alist
                '(((gnus-seconds-today) . "Today, %H:%M")
                  ((+ 86400 (gnus-seconds-today)) . "Yesterday, %H:%M")
                  (604800 . "%A %H:%M") ;;that's one week
                  ((gnus-seconds-month) . "%A %d")
                  ((gnus-seconds-year) . "%B %d")
                  (t . "%B %d '%y"))) ;;this one is used when no other does match
          (setq gnus-summary-line-format
            (concat "%U%R %~(pad-right 2)t%* %B%~(max-right 30)~(pad-right 30)n  "
                    "%~(max-right 90)~(pad-right 90)s %-135=%&user-date;\n"))
      ;; (setq
      ;;  gnus-summary-line-format
      ;;  "%U%R %~(pad-right 2)t%* %B%~(max-right 20)~(pad-right 20)n %s\n")
    6. .gnus

      Create a file ~/.gnus and put in it this:

      1. TODO Sending mail from windows

        This is the config. I use on my Windows machine, i use the msmtp.exe program:

      2. Gmail configuration
        (setq gnus-select-method
              '(nnimap "gmail"
                       (nnimap-address "")
                       (nnimap-server-port 993)
                       (nnimap-authinfo-file "~/.authinfo")
                       (nnimap-stream ssl)))
      3. Sending mail from other systems (GNU/Linux…)

        (source) Add this to your ~/.gnus to enable encrypted SMTP mail sending through GMail.

        (setq message-send-mail-function 'smtpmail-send-it
              smtpmail-starttls-credentials '(("" 587 nil nil))
              smtpmail-auth-credentials '(("" 587 "[email protected]" nil))
              smtpmail-default-smtp-server ""
              smtpmail-smtp-server ""
              smtpmail-smtp-service 587)

        Send mail using C-x m.

Author: jmn

Created: 2016-12-07 Wed 04:50