Skip to content

Latest commit

 

History

History
590 lines (531 loc) · 25.5 KB

starter-kit-window.org

File metadata and controls

590 lines (531 loc) · 25.5 KB

Starter Kit Window

This is part of the Emacs Starter Kit.

Starter Kit Window

Window default settings

Settings in relation with emacs window behavior[1].

(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 'load-path (concat starter-kit-dir "/themes"))
(add-to-list 'custom-theme-load-path (concat starter-kit-dir "/themes"))
(setq custom-safe-themes 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).

(setq sk-solarized-faces
      '("My personal solarized theme customization."
        (let* ((solarized-fg (if (eq variant 'light) s-base00 "#FFFFFF"))
               ;; (solarized-bg (if (eq variant 'light) s-base3 "#2D2D2D"))
               (solarized-bg (if (eq variant 'light) s-base3 "#2F343F"))
               (modeline-fg (if (eq variant 'light) solarized-bg solarized-fg))
               (solarized-hl (if (eq variant 'light) s-base2 s-base02))
               (solarized-emph (if (eq variant 'light) s-base01 s-base1))
               (solarized-comments (if (eq variant 'light) s-base1 s-base01))
               (solarized-fg-hc (if (eq variant 'light) s-base3 s-base03))
               (solarized-fg-lc (if (eq variant 'light) s-base03 s-base3)))
          (custom-theme-set-faces
           theme-name
           `(default ((,class (:foreground ,solarized-fg :background ,solarized-bg))))

           ;; Modeline and powerline
           `(mode-line           ((,class (:foreground ,modeline-fg :background ,green-d
                                                       :box nil :overline nil :underline nil))))
           `(mode-line-inactive  ((,class (:foreground ,modeline-fg :background ,blue-d
                                                       :box nil :overline nil :underline nil))))
           `(mode-line-buffer-id ((,class (:foreground ,modeline-fg :box nil :weight normal))))
           `(powerline-active1   ((,class (:background "gray25" :foreground ,modeline-fg))))
           `(powerline-inactive1 ((,class (:background "gray25" :foreground ,modeline-fg))))
           `(powerline-active2   ((,class (:background "gray40" :foreground ,modeline-fg))))
           `(powerline-inactive2 ((,class (:background "gray40" :foreground ,modeline-fg))))
           `(which-func          ((,class (:foreground ,magenta :weight bold))))
           `(header-line         ((,class (:background ,solarized-bg
                                                       :foreground ,solarized-fg
                                                       :underline nil
                                                       :overline nil
                                                       :box nil))))
           ;; Change some org faces
           `(org-block ((,class (:foreground ,solarized-fg))))
           `(org-document-title        ((,class (:foreground ,blue-hc :weight bold :height 1.0))))
           `(org-document-info         ((,class (:foreground ,blue-hc))))
           `(org-document-info-keyword ((,class (:foreground ,blue-lc))))
           `(org-block-begin-line ((,class (:inherit org-meta-line :underline nil))))
           `(org-block-end-line ((,class (:inherit org-meta-line :overline nil))))
           `(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))))
           ;; `(org-latex-and-related ((,class (:inherit org-latex-and-export-specials))))
           ;; 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))))
           ;; mu4e faces
           `(mu4e-cited-1-face ((,class (:foreground ,green :slant italic :weight normal))))
           `(mu4e-cited-2-face ((,class (:foreground ,blue :slant italic :weight normal))))
           `(mu4e-cited-3-face ((,class (:foreground ,orange :slant italic :weight normal))))
           `(mu4e-cited-4-face ((,class (:foreground ,yellow :slant italic :weight normal))))
           `(mu4e-cited-5-face ((,class (:foreground ,cyan :slant italic :weight normal))))
           `(mu4e-cited-6-face ((,class (:foreground ,green :slant italic :weight normal))))
           `(mu4e-cited-7-face ((,class (:foreground ,blue :slant italic :weight normal))))
           `(mu4e-flagged-face ((,class (:foreground ,red-l :weight bold))))
           `(mu4e-header-face ((,class (:foreground ,solarized-comments))))
           `(mu4e-unread-face ((,class (:foreground ,blue-l :weight bold))))
           `(mu4e-replied-face ((,class (:foreground ,yellow-l :weight bold))))
           `(mu4e-forwarded-face ((,class (:foreground ,green-l :weight bold))))
           `(mu4e-view-url-number-face ((,class (:foreground ,yellow :weight normal))))
           `(mu4e-warning-face ((,class (:foreground ,red :slant normal :weight bold))))
           `(mu4e-system-face ((,class (:foreground ,solarized-comments :slant italic :weight bold))))
           `(mu4e-header-marks-face ((,class (:foreground ,solarized-comments :slant normal :weight bold))))
           `(mu4e-header-highlight-face
             ((,class (:inherit unspecified :foreground unspecified :background ,solarized-hl
                                :underline unspecified  :weight bold :box nil))))
           `(mu4e-view-contact-face ((,class (:foreground ,base0  :weight normal))))
           `(mu4e-view-header-key-face ((,class (:inherit message-header-name :weight normal))))
           `(mu4e-view-header-value-face ((,class (:foreground ,yellow :weight normal :slant normal))))
           `(mu4e-view-link-face ((,class (:inherit link))))
           `(mu4e-view-special-header-value-face ((,class (:foreground ,blue :weight normal :underline nil))))
           `(mu4e-modeline-face ((,class (:foreground ,modeline-fg))))
           ))))

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

(setq solarized-scale-org-headlines nil)
(setq solarized-use-variable-pitch nil)
(load-theme 'solarized-light t)
(deftheme sk-solarized "A slightly modified version of solarized theme.")
(require 'solarized-palettes)
(solarized-with-color-variables 'light 'sk-solarized solarized-light-color-palette-alist sk-solarized-faces)

Create interactive functions to easily switch from one theme to another

(defun sk-switch-to-dark-theme ()
  (interactive)
  (solarized-with-color-variables 'dark 'sk-solarized solarized-dark-color-palette-alist sk-solarized-faces)
  (fci-make-overlay-strings)
  (fci-update-all-windows t)
  )
(defun sk-switch-to-light-theme ()
  (interactive)
  (solarized-with-color-variables 'light 'sk-solarized solarized-light-color-palette-alist sk-solarized-faces)
  (fci-make-overlay-strings)
  (fci-update-all-windows t))
(global-set-key (kbd "C-c l") 'sk-switch-to-light-theme)
(global-set-key (kbd "C-c d") 'sk-switch-to-dark-theme)

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)))

Jump to a file with ido

(define-key dired-mode-map "i" 'ido-find-file)

Files size

(defun dired-get-size ()
  (interactive)
  (let ((files (dired-get-marked-files)))
    (with-temp-buffer
      (apply 'call-process "/usr/bin/du" nil t nil "-sch" files)
      (message
       "Size of all marked files: %s"
       (progn
         (re-search-backward "\\(^[0-9.,]+[A-Za-z]+\\).*total$")
         (match-string 1))))))
(define-key dired-mode-map (kbd "z") 'dired-get-size)

Dired subtree

(require 'dired-subtree)
(define-key dired-mode-map "+" 'dired-subtree-insert)
(define-key dired-mode-map "-" 'dired-subtree-remove)

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

Requirement

(defadvice powerline-major-mode (around delight-powerline-major-mode activate)
  "Ensure that powerline's major mode names are delighted.

  See `delight-major-mode'."
  (let ((inhibit-mode-name-delight nil))
    ad-do-it))
(require 'powerline)

Function to update git modeline status

The following function checks if a current buffer is under git and if yes, checks if it is a clean repository (nothing to stage) or a dirty one. Given the result, the color for the git branch is accordingly changed. This function is called every time a file is changed (through after-save-hook hook).

(defun sk-git-modeline-status ()
  (when vc-mode
    (setq git-clean
          (shell-command-to-string "git status -s --ignore-submodules=dirty -uno 2> /dev/null | tail -n1"))
    (if (string= "" git-clean)
        (progn
          (if (boundp 'powerline-git-face)
              (face-remap-remove-relative powerline-git-face))
          (setq powerline-git-face (face-remap-add-relative 'powerline-inactive1 :foreground "#FFFFFF")))
      (progn
        (setq powerline-git-face (face-remap-add-relative 'powerline-inactive1 :foreground "#DEB542"))
        (sk-popup "git status" (concat "" (format-mode-line mode-line-buffer-identification)) "low"))
      )))

;;(add-hook 'focus-in-hook 'sk-git-modeline-status)
(add-hook 'after-save-hook 'sk-git-modeline-status)

Powerline function to improve version control status

(defpowerline sk-powerline-vc
  (when (and (buffer-file-name (current-buffer))
             vc-mode)
    (format-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))))
                                ) ""))))

Powerline theme

(setq powerline-height 24)
(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 'powerline-active1)
                          (face2 'powerline-active2)
                          (face3 'powerline-inactive1)
                          (lhs (list
                                ;; (powerline-raw "%*" nil 'l)
                                ;; (powerline-buffer-size nil 'l)

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

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

                                (powerline-process face1)
                                (powerline-minor-modes face1 'l)
                                (sk-powerline-vc face3)
                                (powerline-narrow face1 'l)

                                (powerline-raw " " face1)
                                (powerline-arrow-left face1 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 "" face1)
                                (powerline-raw "%4l|%0c" face1 'r)

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

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

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

From http://bzg.fr/emacs-strip-tease.html

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)

Hide async-shell-command buffer

(add-to-list 'display-buffer-alist '("^*Async Shell Command*" . (display-buffer-no-window)))

Copy text selected with the mouse

(setq mouse-drag-copy-region t)
(setq save-interprogram-paste-before-kill t)

Misc.

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

Footnotes

[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.