Starter Kit Window

This is part of the Emacs Starter Kit.

Starter Kit Window

Window default settings

Settings in relation with emacs window behavior1.

1

Magnars suggests to place all the UI stuff deactivation (tool-bar, scroll-bar) at the really beginning of the init.el file. Not really conclusive especially when emacs server is used.


(setq frame-title-format '(buffer-file-name "%b [%f]" "%b"))

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

(setq inhibit-startup-screen                t
      inhibit-startup-message               t
      line-number-mode                      t
      column-number-mode                    t
      icomplete-mode                        t
      read-buffer-completion-ignore-case    t
      read-file-name-completion-ignore-case t
      color-theme-is-global                 t
      save-place                            t)

Color themes

Emacs24 deftheme

Emacs24 has build in support for saving and loading themes.

A Theme builder is available at http://elpa.gnu.org/themes/ along with a list of pre-built themes at http://elpa.gnu.org/themes/view.html and themes are available through ELPA.

Downloaded themes may be saved to the themes/ directory in the base of the starter kit which ignored by git. Once downloaded and evaluated a theme is activated using the load-theme function.

(add-to-list 'custom-theme-load-path (concat starter-kit-dir "/themes"))
(setq custom-safe-themes t)
;;(load-theme 'solarized-light t)

Custom solarized theme

A light variant of the Solarized color theme. The basic idea is to keep the default solarized theme clean and up-to-date and just change some small part of it here. There is also some face changes for powerline (see below).

(require 'solarized)
(defun sk-solarized-childtheme ()
  (custom-theme-set-faces
   theme-name
   ;; Modeline and powerline
   `(mode-line           ((,class (:foreground ,solarized-bg
                                               :background ,blue :box nil))))
   `(mode-line-inactive  ((,class (:foreground ,solarized-bg
                                               :background ,blue-d :box nil))))
   `(mode-line-buffer-id ((,class (:foreground ,solarized-bg :box nil))))
   `(powerline-active1   ((,class (:background "gray25"))))
   `(powerline-inactive1 ((,class (:background "gray25"))))
   `(powerline-active2   ((,class (:background "gray40"))))
   `(powerline-inactive2 ((,class (:background "gray40"))))
   `(which-func ((,class (:foreground ,magenta :weight bold))))
   `(header-line         ((,class (:background ,solarized-bg
                                               :foreground ,solarized-fg
                                               :underline nil
                                               :overline nil))))
   ;; Change some org faces
   `(org-document-title        ((,class (:foreground ,blue-hc :weight bold))))
   `(org-document-info         ((,class (:foreground ,blue-hc))))
   `(org-document-info-keyword ((,class (:foreground ,blue-lc))))
   `(org-table ((,class (:foreground ,blue-d))))
   `(org-level-1 ((,class (:foreground ,orange))))
   `(org-level-2 ((,class (:foreground ,green))))
   `(org-level-3 ((,class (:foreground ,blue))))
   `(org-level-4 ((,class (:foreground ,yellow))))
   `(org-level-5 ((,class (:foreground ,cyan))))
   `(org-level-6 ((,class (:foreground ,green))))
   `(org-level-7 ((,class (:foreground ,red))))
   `(org-level-8 ((,class (:foreground ,blue))))
   ;; Autocomplete faces
   `(ac-candidate-face ((,class (:background ,solarized-hl :foreground ,yellow))))
   `(ac-selection-face ((,class (:background ,yellow-lc :foreground ,yellow-hc))))
   `(ac-candidate-mouse-face ((,class (:background ,yellow-hc :foreground ,yellow-lc))))
   `(ac-completion-face ((,class (:foreground ,solarized-emph :underline t))))
   `(ac-gtags-candidate-face ((,class (:background ,solarized-hl :foreground ,blue))))
   `(ac-gtags-selection-face ((,class (:background ,blue-lc :foreground ,blue-hc))))
   `(ac-yasnippet-candidate-face ((,class (:background ,solarized-hl :foreground ,orange))))
   `(ac-yasnippet-selection-face ((,class (:background ,orange-lc :foreground ,orange-hc))))
   ;; Linum & fringe
   `(linum  ((,class (:foreground ,solarized-comments :background ,solarized-bg))))
   `(fringe ((,class (:foreground ,solarized-comments :background ,solarized-bg))))
   ))

Define new theme (since definition occurs here it is loaded by default)

(deftheme sk-solarized-light)
(create-solarized-theme 'light 'sk-solarized-light 'sk-solarized-childtheme)

UI settings

Use space for tabulation

(set-default 'indent-tabs-mode nil)

Indicate empty lines

(set-default 'indicate-empty-lines t)

Fringe size

;;(setq-default left-fringe-width 5)

Setting default directories

First, set the temporary directory name and create it if it does not already exist.

(setq temporary-file-directory     (concat starter-kit-dir "/tmp/"))
(unless (file-exists-p temporary-file-directory)
  (make-directory temporary-file-directory))

Define several place where temporary files will be stored. For instance, SavePlace stores the position where the point was at the last visit of a given file. backup-directory-alist is related to the directory where emacs backup file will be stored.

(setq save-place-file              (concat temporary-file-directory "places"))
(setq recentf-save-file            (concat temporary-file-directory "recentf"))
(setq smex-save-file               (concat temporary-file-directory "smex-items"))
(setq ido-save-directory-list-file (concat temporary-file-directory "ido.last"))
(setq ac-comphist-file             (concat temporary-file-directory "ac-comphist.dat"))
(setq auto-save-list-file-prefix   (concat temporary-file-directory "auto-save-list/" ".auto-saves-"))
(setq auto-save-file-name-transforms `((".*" ,temporary-file-directory t)))
(setq backup-directory-alist         `(("." . ,(concat temporary-file-directory "backups"))))

Automatically save and restore sessions

(setq desktop-dirname             (concat temporary-file-directory "session")
      desktop-base-file-name      "emacs.desktop"
      desktop-base-lock-name      "lock"
      desktop-path                (list desktop-dirname)
      desktop-save                t
      desktop-files-not-to-save   "^$" ;reload tramp paths
      desktop-restore-frames      nil
      desktop-load-locked-desktop nil)
(unless (file-exists-p desktop-dirname)
  (make-directory desktop-dirname))
(desktop-save-mode 0)

UTF8 everywhere

(set-terminal-coding-system    'utf-8)
(set-keyboard-coding-system    'utf-8)
(prefer-coding-system          'utf-8)
(set-buffer-file-coding-system 'utf-8)

Uniquify settings

Change buffer name in case of various same name buffer previously : Makefile and Makefile<2> now : Makefile|directory1 Makefile|directory2

(require 'uniquify)
(setq uniquify-buffer-name-style 'reverse)
(setq uniquify-separator "|")
(setq uniquify-after-kill-buffer-p t) ; rename after killing uniquified
(setq uniquify-ignore-buffers-re "^\\*") ; don't muck with special buffers

Dired customization

Using 'a' to open a directory in the same buffer

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

Make dired less verbose

(require 'dired-details)
(setq-default dired-details-hidden-string "--- ")
(dired-details-install)

Refresh also dired buffer

From Magnars blog

(setq global-auto-revert-non-file-buffers t)
(setq auto-revert-verbose nil)

Activate hl-line minor mode

(add-hook 'dired-mode-hook
          (lambda ()
            (hl-line-mode t)))

Ibuffer customization

Use human readable size column (from coldnew)

(define-ibuffer-column size-h
  (:name "Size")
  (cond
   ((> (buffer-size) 1000)    (format "%7.1fk" (/ (buffer-size) 1000.0)))
   ((> (buffer-size) 1000000) (format "%7.1fM" (/ (buffer-size) 1000000.0)))
   (t  (format "%8d" (buffer-size)))))

(setq
 ibuffer-default-sorting-mode 'filename/process
 ibuffer-eliding-string "…"
 ibuffer-compile-formats t
 ibuffer-formats '((mark modified read-only
                         " " (name 25 25 :left :elide)
                         " " (size-h 9 -1 :right)
                         " " (mode 7 7 :left :elide)
                         ;;" " (git-status 8 8 :left)
                         " " filename-and-process)
                   (mark " " (name 16 -1) " " filename))
 ibuffer-show-empty-filter-groups nil
 ibuffer-saved-filter-groups
 (quote (("default"
          ("c++" (mode . c++-mode))
          ("shell script" (mode . sh-mode))
          ("emacs lisp" (mode . emacs-lisp-mode))
          ("python" (mode . python-mode))
          ("LaTeX" (or
                    (mode . latex-mode)
                    (mode . LaTeX-mode)
                    (mode . tex-mode)))
          ("ruby" (mode . ruby-mode))
          ("java-script" (or
                          (mode . js-mode)
                          (mode . js2-mode)))
          ("java" (mode . java-mode))
          ("html" (or
                   (mode . html-mode)
                   (mode . web-mode)
                   (mode . haml-mode)))
          ("xml" (mode . nxml-mode))
          ("css" (mode . css-mode))
          ("org agenda"  (mode . org-agenda-mode))
          ("org" (or
                  (mode . org-mode)
                  (name . "^\\*Calendar\\*$")
                  (name . "^diary$")))
          ("text misc" (or
                        (mode . text-mode)
                        (mode . rst-mode)
                        (mode . markdown-mode)))
          ("w3m" (mode . w3m-mode))
          ("git" (or
                  (mode . magit-log-edit-mode)
                  (mode . magit-log)))
          ("dired" (mode . dired-mode))
          ("help" (or
                   (mode . Info-mode)
                   (mode . help-mode)
                   (mode . Man-mode)))
          ("*buffer*" (name . "\\*.*\\*"))))))
(add-hook 'ibuffer-mode-hook
          #'(lambda ()
              (hl-line-mode t)
              (ibuffer-switch-to-saved-filter-groups "default")))

Powerline

(require 'powerline)
(defun sk-powerline-default-theme ()
  "Starter-kit default mode-line."
  (interactive)
  (setq-default mode-line-format
                '("%e"
                  (:eval
                   (let* ((active (powerline-selected-window-active))
                          (mode-line (if active 'mode-line 'mode-line-inactive))
                          (face1 (if active 'powerline-active1
                                   'powerline-inactive1))
                          (face2 (if active 'powerline-active2
                                   'powerline-inactive2))
                          (lhs (list
                                (powerline-raw "%*" nil 'l)
                                (powerline-buffer-size nil 'l)

                                ;;(powerline-raw mode-line-mule-info nil 'l)
                                (powerline-buffer-id nil 'l)

                                (powerline-raw " ")
                                (powerline-arrow-left mode-line face1)

                                (powerline-major-mode face1 'l)
                                (powerline-process face1)
                                (powerline-minor-modes face1 'l)
                                (powerline-narrow face1 'l)

                                (powerline-raw " " face1)
                                (powerline-arrow-left face1 face2)

                                (powerline-vc face2)))
                          (rhs (list
                                (powerline-raw global-mode-string face2 'r)

                                (powerline-arrow-left face2 face1)

                                (powerline-raw "%4l" face1 'l)
                                (powerline-raw ":" face1 'l)
                                (powerline-raw "%3c" face1 'r)

                                (powerline-arrow-left face1 mode-line)
                                (powerline-raw " ")

                                (powerline-raw "%6p" nil 'r)
                                )))
                     (concat
                      (powerline-render lhs)
                      (powerline-fill face2 (powerline-width rhs))
                      (powerline-render rhs)))))))
(sk-powerline-default-theme)

Diminish modeline clutter

;;(require 'diminish)

Buffer scrolling

Smooth keyboard scrolling

(setq
 redisplay-dont-pause t                 ;; scrolling
 scroll-step 1                          ;; scroll line per line (1 line instead of 3)
 scroll-margin 0                        ;; do smooth scrolling, ...
 scroll-conservatively 100000           ;; ... the defaults ...
;; scroll-up-aggressively 0               ;; ... are very ...
;;  scroll-down-aggressively 0             ;; ... annoying
 auto-window-vscroll nil
 )

Use inertial-scroll for a really smooth scrolling when using mouse wheel and next/prior keys.

(require 'inertial-scroll)
(inertias-global-minor-mode 1)
(setq inertias-rebound-flash nil
      inertias-initial-velocity-wheel 20)
(global-set-key [(mouse-5)] 'inertias-up-wheel)
(global-set-key [(mouse-4)] 'inertias-down-wheel)
(global-set-key (kbd "<next>")  'inertias-up)
(global-set-key (kbd "<prior>") 'inertias-down)

Naked emacs

Hide modeline

From http://bzg.fr/emacs-hide-mode-line.html

(defvar-local sk-hidden-mode-line-mode nil)

(define-minor-mode sk-hidden-mode-line-mode
  "Minor mode to hide the mode-line in the current buffer."
  :init-value nil
  :global nil
  :variable sk-hidden-mode-line-mode
  :group 'editing-basics
  (if sk-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))
  (force-mode-line-update)
  ;; Apparently force-mode-line-update is not always enough to
  ;; redisplay the mode-line
  (redraw-display)
  (when (and (called-interactively-p 'interactive)
             sk-hidden-mode-line-mode)
    (run-with-idle-timer
     0 nil 'message
     (concat "Hidden Mode Line Mode enabled.  "
             "Use M-x sk-hidden-mode-line-mode to make the mode-line appear."))))

Big fringe

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

;; Get rid of the indicators in the fringe
(mapcar (lambda(fb) (set-fringe-bitmap-face fb 'org-hide))
        fringe-bitmaps)

Shortcut

(defun sk-naked-emacs ()
  (interactive)
  (progn
    (if (not sk-hidden-mode-line-mode)
        (sk-hidden-mode-line-mode 1)
      (sk-hidden-mode-line-mode 0))
    (if (not sk-big-fringe-mode)
        (sk-big-fringe-mode 1)
      (sk-big-fringe-mode 0))
    ))
(global-set-key (kbd "C-s-SPC") 'sk-naked-emacs)

Misc.

(defalias 'yes-or-no-p 'y-or-n-p)

File under version control - commit 135971e - 2014-11-29