<commit_before>#+TITLE: <NAME>'s Emacs configuration
#+OPTIONS: toc:4 h:4
* Introduction
Using [[http://orgmode.org/][org-mode]] for emacs config feels like cheating. Thanks [[https://github.com/mwfogleman/config/blob/master/home/.emacs.d/michael.org][Michael]] for the
inspiration!

* Settings
** Personal information
#+BEGIN_SRC emacs-lisp
(setq user-full-name "<NAME>"
      user-mail-address "<EMAIL>")
#+END_SRC

** General settings
*** Debug
#+BEGIN_SRC emacs-lisp
(setq debug-on-error t)
#+END_SRC

*** Other settings
#+BEGIN_SRC emacs-lisp
;; Turn off mouse interface early in startup to avoid momentary display
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))

(setq inhibit-startup-message t)
(setq browse-url-browser-function 'browse-url-generic
      browse-url-generic-program "open"
      custom-file (expand-file-name "~/.emacs.d/custom.el")
      ido-handle-duplicate-virtual-buffers 2)
#+END_SRC
*** Setup directories
Make it easy to reference the dotfiles.
#+BEGIN_SRC emacs-lisp
(setq dotfiles-dir (file-name-directory
                    (or (buffer-file-name) load-file-name)))
#+END_SRC
** Enable package support
I set up packages, Melpa, and use-package bright and early so that I can make
use of use-package's bind-key macro.

When I first copy this set-up into a new machine, I still have to require
package, add MELPA, initialize package, and grab use-package, and a couple of
others from the package archives and the internet. This could be improved.

#+BEGIN_SRC emacs-lisp
(require 'package)

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

(setq load-prefer-newer t)
(require 'use-package) ;; currently you have to evaluate everything up to here, and grab use-package manually :/
#+END_SRC
*** Paradox
#+BEGIN_SRC emacs-lisp
  (use-package paradox
    :ensure t
    :config
    (setq paradox-execute-asynchronously t))
#+END_SRC

*** Diminish
Reduce mode line clutter: http://www.emacswiki.org/emacs/DiminishedModes
#+BEGIN_SRC emacs-lisp
(use-package diminish
  :ensure t
  :init
  (defmacro rename-modeline (package-name mode new-name)
    `(eval-after-load ,package-name
       '(defadvice ,mode (after rename-modeline activate)
          (setq mode-name ,new-name)))))
#+END_SRC

*** TODO Other package setup
#+BEGIN_SRC emacs-lisp
; TODO - setup packages
(defvar my-packages '(clojure-mode clojure-test-mode
                      markdown-mode yaml-mode tuareg
		      color-theme magit deft
		      paredit python-mode
		      haskell-mode go-mode
                      js2-mode
                      color-theme-railscasts
                      color-theme-ir-black
                      yasnippet
                      ess flycheck projectile
		      ;; ruby-mode inf-ruby
		      scala-mode php-mode
                      workgroups
                      smart-tab protobuf-mode
                      marmalade oddmuse scpaste))
;(dolist (p my-packages)
;  (when (not (package-installed-p p))
;    (package-install p)))

#+END_SRC

* Emacs
** Scratch file
See: http://emacsredux.com/blog/2014/07/25/configure-the-scratch-buffers-mode/
#+BEGIN_SRC emacs-lisp
(setq initial-scratch-message "")
(setq initial-major-mode 'lisp-interaction-mode)
#+END_SRC
** Highlight trailing whitespace
#+BEGIN_SRC emacs-lisp
(setq-default show-trailing-whitespace t)
(global-set-key "\C-c\C-w" 'whitespace-cleanup)
#+END_SRC

** Auto fill
Always fill at 78 chars.
#+BEGIN_SRC emacs-lisp
(add-hook 'text-mode-hook #'turn-on-auto-fill)
(setq-default fill-column 78)
#+END_SRC
** File encoding
Set default file encoding to utf-8 (http://nakkaya.com/2009/11/29/emacs-and-international-characters/)
#+BEGIN_SRC emacs-lisp
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
#+END_SRC

** Tramp mode
http://www.gnu.org/software/tramp/#Connection-types
#+BEGIN_SRC emacs-lisp
(setq tramp-default-method "scpx")
#+END_SRC

** Backup files
Auto Save files to temp dir: http://emacswiki.org/emacs/AutoSave
#+BEGIN_SRC emacs-lisp
(setq backup-directory-alist
      `((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
      `((".*" ,temporary-file-directory t)))
#+END_SRC

Make backups of files, even when they're in version control.
#+BEGIN_SRC emacs-lisp
(setq vc-make-backup-files t)
#+END_SRC

** Mode line
See: http://www.lunaryorn.com/2014/07/26/make-your-emacs-mode-line-more-useful.html
#+BEGIN_SRC emacs-lisp
;; More compact position display
(setq-default mode-line-position
              '((-3 "%p") (size-indication-mode ("/" (-4 "%I")))
                " "
                (line-number-mode
                 ("%l" (column-number-mode ":%c")))))

(defvar gmwils-projectile-mode-line
  '(:propertize
    (:eval (when (ignore-errors (projectile-project-root))
             (concat " " (projectile-project-name))))
    face font-lock-constant-face)
  "Mode line format for Projectile.")
(put 'gmwils-projectile-mode-line 'risky-local-variable t)

;; Shorter VC mode line
(defvar gmwils-vc-mode-line
  '(" " (:propertize
         ;; Strip the backend name from the VC status information
         (:eval (let ((backend (symbol-name (vc-backend (buffer-file-name)))))
                  (substring vc-mode (+ (length backend) 2))))
         face font-lock-variable-name-face))
  "Mode line format for VC Mode.")
(put 'gmwils-vc-mode-line 'risky-local-variable t)

(setq-default mode-line-format
              '("%e" mode-line-front-space
                mode-line-mule-info
                mode-line-client
                mode-line-modified
                mode-line-remote
                mode-line-buffer-identification
                " " mode-line-position
                gmwils-projectile-mode-line
                gmwils-vc-mode-line
                (flycheck-mode flycheck-mode-line) ; Flycheck status
                " "
                mode-line-misc-info
                " "
                mode-line-modes
                mode-line-end-spaces))
#+END_SRC
* Packages
#+BEGIN_SRC emacs-lisp
<commit_msg>Refactoring.<commit_after>#+TITLE: <NAME>'s Emacs configuration
#+OPTIONS: toc:4 h:4
* Introduction
Using [[http://orgmode.org/][org-mode]] for emacs config feels like cheating. Thanks [[https://github.com/mwfogleman/config/blob/master/home/.emacs.d/michael.org][Michael]] for the
inspiration!

* Settings
** Personal information
#+BEGIN_SRC emacs-lisp
(setq user-full-name "<NAME>"
      user-mail-address "<EMAIL>")
#+END_SRC

** General settings
*** Debug
#+BEGIN_SRC emacs-lisp
(setq debug-on-error t)
#+END_SRC

*** Other settings
#+BEGIN_SRC emacs-lisp
;; Turn off mouse interface early in startup to avoid momentary display
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))

(setq inhibit-startup-message t)
(setq browse-url-browser-function 'browse-url-generic
      browse-url-generic-program "open"
      custom-file (expand-file-name "~/.emacs.d/custom.el")
      ido-handle-duplicate-virtual-buffers 2)
#+END_SRC
*** Setup directories
Make it easy to reference the dotfiles.
#+BEGIN_SRC emacs-lisp
(setq dotfiles-dir (file-name-directory
                    (or (buffer-file-name) load-file-name)))
#+END_SRC
** Enable package support
I set up packages, Melpa, and use-package bright and early so that I can make
use of use-package's bind-key macro.

When I first copy this set-up into a new machine, I still have to require
package, add MELPA, initialize package, and grab use-package, and a couple of
others from the package archives and the internet. This could be improved.

#+BEGIN_SRC emacs-lisp
(require 'package)

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

(setq load-prefer-newer t)
(require 'use-package) ;; currently you have to evaluate everything up to here, and grab use-package manually :/
#+END_SRC
*** Paradox
#+BEGIN_SRC emacs-lisp
  (use-package paradox
    :ensure t
    :config
    (setq paradox-execute-asynchronously t))
#+END_SRC

*** Diminish
Reduce mode line clutter: http://www.emacswiki.org/emacs/DiminishedModes
#+BEGIN_SRC emacs-lisp
(use-package diminish
  :ensure t
  :init
  (defmacro rename-modeline (package-name mode new-name)
    `(eval-after-load ,package-name
       '(defadvice ,mode (after rename-modeline activate)
          (setq mode-name ,new-name)))))
#+END_SRC

*** TODO Other package setup
#+BEGIN_SRC emacs-lisp
; TODO - setup packages
(defvar my-packages '(clojure-mode clojure-test-mode
                      markdown-mode yaml-mode tuareg
		      color-theme magit deft
		      paredit python-mode
		      haskell-mode go-mode
                      js2-mode
                      color-theme-railscasts
                      color-theme-ir-black
                      yasnippet
                      ess flycheck projectile
		      ;; ruby-mode inf-ruby
		      scala-mode php-mode
                      workgroups
                      smart-tab protobuf-mode
                      marmalade oddmuse scpaste))
;(dolist (p my-packages)
;  (when (not (package-installed-p p))
;    (package-install p)))

#+END_SRC

* Emacs
** Scratch file
See: http://emacsredux.com/blog/2014/07/25/configure-the-scratch-buffers-mode/
#+BEGIN_SRC emacs-lisp
(setq initial-scratch-message "")
(setq initial-major-mode 'lisp-interaction-mode)
#+END_SRC
** Highlight trailing whitespace
#+BEGIN_SRC emacs-lisp
(setq-default show-trailing-whitespace t)
(global-set-key "\C-c\C-w" 'whitespace-cleanup)
#+END_SRC

** Auto fill
Always fill at 78 chars.
#+BEGIN_SRC emacs-lisp
(add-hook 'text-mode-hook #'turn-on-auto-fill)
(setq-default fill-column 78)
#+END_SRC
** File encoding
Set default file encoding to utf-8 (http://nakkaya.com/2009/11/29/emacs-and-international-characters/)
#+BEGIN_SRC emacs-lisp
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
#+END_SRC

** Tramp mode
http://www.gnu.org/software/tramp/#Connection-types
#+BEGIN_SRC emacs-lisp
(setq tramp-default-method "scpx")
#+END_SRC

** Backup files
Auto Save files to temp dir: http://emacswiki.org/emacs/AutoSave
#+BEGIN_SRC emacs-lisp
(setq backup-directory-alist
      `((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
      `((".*" ,temporary-file-directory t)))
#+END_SRC

Make backups of files, even when they're in version control.
#+BEGIN_SRC emacs-lisp
(setq vc-make-backup-files t)
#+END_SRC

** Mode line
See: http://www.lunaryorn.com/2014/07/26/make-your-emacs-mode-line-more-useful.html


More compact position display.
#+BEGIN_SRC emacs-lisp
(setq-default mode-line-position
              '((-3 "%p") (size-indication-mode ("/" (-4 "%I")))
                " "
                (line-number-mode
                 ("%l" (column-number-mode ":%c")))))
#+END_SRC

Mode line formating for projectile.
#+BEGIN_SRC emacs-lisp
(defvar gmwils-projectile-mode-line
  '(:propertize
    (:eval (when (ignore-errors (projectile-project-root))
             (concat " " (projectile-project-name))))
    face font-lock-constant-face)
  "Mode line format for Projectile.")
(put 'gmwils-projectile-mode-line 'risky-local-variable t)
#+END_SRC

Shorter version control (VC) mode line.
#+BEGIN_SRC emacs-lisp
(defvar gmwils-vc-mode-line
  '(" " (:propertize
         ;; Strip the backend name from the VC status information
         (:eval (let ((backend (symbol-name (vc-backend (buffer-file-name)))))
                  (substring vc-mode (+ (length backend) 2))))
         face font-lock-variable-name-face))
  "Mode line format for VC Mode.")
(put 'gmwils-vc-mode-line 'risky-local-variable t)
#+END_SRC

Set the actual mode line.
#+BEGIN_SRC emacs-lisp
(setq-default mode-line-format
              '("%e" mode-line-front-space
                mode-line-mule-info
                mode-line-client
                mode-line-modified
                mode-line-remote
                mode-line-buffer-identification
                " " mode-line-position
                gmwils-projectile-mode-line
                gmwils-vc-mode-line
                (flycheck-mode flycheck-mode-line) ; Flycheck status
                " "
                mode-line-misc-info
                " "
                mode-line-modes
                mode-line-end-spaces))
#+END_SRC
* Packages
#+BEGIN_SRC emacs-lisp

{'fraction_non_alphanumeric': 0.13606582355630048, 'fraction_numerical': 0.006704251104677739, 'mean_word_length': 2.67703081232493, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '762909', 'n_tokens_mistral': 4645, 'n_tokens_neox': 4353, 'n_words': 1025}