text:
#+TITLE: My emacs configuration file
#+ATTR_HTML: :alt emacs.png image :title emacs :align left :width 380px :hight 280px
[[file:images/emacs.png]]

** Set up load path

The variable =load-path= lists all the directories where Emacs should look for Elisp files.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(setq load-path
      (append
       (list
        (expand-file-name "~/.emacs.d")
        (expand-file-name "~/.emacs.d/elisp"))
       load-path))
#+END_SRC

** Common lisp primitives.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'cl)
#+END_SRC

** Packages

Following code adapted from [[https://github.com/bbatsov/prelude][emacs-prelude]] - [[http://batsov.com/articles/2012/02/19/package-management-in-emacs-the-good-the-bad-and-the-ugly/][package-management-in-emacs]] (The Good, the Bad and the Ugly).

*** Activate all the packages.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'package)
(package-initialize)
#+END_SRC

*** List of repositories containing packages.

1. [[http://melpa.milkbox.net/#/][melpa]] repo - contains packages updated daily.
2. [[http://melpa-stable.milkbox.net/#/][melpa-stable]] repo - [alternative to [[http://marmalade-repo.org/][Marmalade]]] It offers stable packages built automatically from git tags.
3. [[http://orgmode.org/elpa/][org]] repo - Org's package repository.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(add-to-list 'package-archives
             '("melpa" . "http://melpa.milkbox.net/packages/"))
(add-to-list 'package-archives
             '("melpa-stable" . "http://melpa-stable.milkbox.net/packages/"))
(add-to-list 'package-archives
             '("org" . "http://orgmode.org/elpa/"))
#+END_SRC

*** List of packages used in this configuration.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(setq required-packages
      (list
       'ac-slime ; auto-complete plugin for Slime.
       'ace-window ; GNU Emacs package for selecting a window to switch to
       'ace-jump-mode ; a quick cursor jump mode for emacs
       'auto-complete ; auto-completion extension for GNU Emacs.
       'auto-complete-clang ; nice C & C++ autocomplete for Emacs.
       'autopair ; automagically pair braces and quotes.
       'aurel ; Search and download AUR packages from Emacs.
       'deft ; mode for quickly browsing, filtering, and editing directories of plain text notes.
       'dired-details ; hide/show the details of each file or directory in DiredMode.
       'emms ; Emacs multimedia system.
       'elfeed ; An Emacs web feeds client.
       'elscreen ; GNU Emacs window session manager.
       'flycheck ; fly syntax checking for GNU Emacs.
       'flx-ido ; Fuzzy matching for Emacs ... a la Sublime Text.
       'guru-mode ; The Emacs guru way
       'htmlize ; Convert buffer text and decorations to HTML.
       'ido-vertical-mode ; makes ido-mode display vertically.
       'js2-mode ; javascript-mode for emacs.
       'magit ; Emacs mode for Git.
       'markdown-mode ; Emacs mode for Markdown-formatted files.
       'multi-term ; managing multiple terminal buffers in Emacs.
       'multiple-cursors ; Multiple cursors for emacs.
       'org ; an Emacs Mode for Notes, Planning, and Authoring.
       'org-plus-contrib ; contrib files for org.
       'paredit ; minor mode for editing parentheses.
       'pkgbuild-mode ; Major mode for editing PKGBUILD files.
       'rainbow-mode ; Colorize color names in buffers.
       'rainbow-delimiters ; rainbow delimiters mode.
       'recentf ; is a minor mode that builds a list of recently opened files.
       'slime ; Emacs mode for Common Lisp development.
       'smex ; M-x enhancement for Emacs. Built on top of IDO.
       'web-mode ; web template editing mode for emacs.
       'xkcd ; Read xkcd from emacs.
       'volatile-highlights ; highlights changes to the buffer.
       'zenburn-theme ; The Zenburn colour theme ported to Emacs.
       ))
#+END_SRC

*** Check if all packages are installed.

if not all packages are installed, check one by one and install the missing ones.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(defun packages-installed-p ()
  (loop for p in required-packages
        when (not (package-installed-p p)) do (return nil)
        finally (return t)))

;; if not all packages are installed, check one by one and install the missing ones.
(unless (packages-installed-p)
  ;; check for new packages (package versions)
  (message "%s" "Emacs is now refreshing its package database...")
  (package-refresh-contents)
  (message "%s" " done.")
  ;; install the missing packages
  (dolist (p required-packages)
    (when (not (package-installed-p p))
      (package-install p))))
#+END_SRC

** Visual appearance

I turn =off= mouse interface early in startup to avoid momentary display.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(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))
(if (fboundp 'blink-cursor-mode) (blink-cursor-mode -1))
(if (fboundp 'use-file-dialog) (setq use-file-dialog nil))
(if (fboundp 'use-dialog-box) (setq use-dialog-box nil))
#+END_SRC

For the most part I prefer to disable Emacs' fringe.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(fringe-mode '(0 . 0))
#+END_SRC

I have simple function to =Enable|Disable= fringe.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(defun enable-fringe ()
  (interactive)
  (fringe-mode '(nil . nil) ))

(defun disable-fringe ()
  (interactive)
  (fringe-mode '(0 . 0) ))
#+END_SRC

Set font for all windows.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(add-to-list 'default-frame-alist
                '(font . "DejaVu Sans Mono-10"))
#+END_SRC

Load theme [[https://github.com/bbatsov/zenburn-emacs][zenburn]].

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(load-theme 'zenburn t)
#+END_SRC

Make cursor a vertical bar.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(setq-default cursor-type 'bar)
#+END_SRC

Highlight the current line

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(global-hl-line-mode +1)
#+END_SRC

Hide mouse cursor while typing.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(setq make-pointer-invisible t)
#+END_SRC

Highlight matching parentheses when the point is on them.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(show-paren-mode t)
(setq show-paren-delay 0)
#+END_SRC

Volatile-highlight.
Highlight the latest changes in the buffer (like text inserted from: yank, undo, etc.) until the next command is run.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(when (require 'volatile-highlights nil 'noerror)
  (volatile-highlights-mode t))
#+END_SRC

Do not break lines.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(set-default 'truncate-lines t)
#+END_SRC

** Defaults

*** Prompt Behavior

Use y/n instead of yes/no in confirmation dialogs.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(fset 'yes-or-no-p 'y-or-n-p)
#+END_SRC

*** Settings

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(setq initial-scratch-message ";; scratch buffer created -- Happy Hacking ivo!!"
      inhibit-startup-message t       ; No splash screen please.
      visible-bell t                  ; blink instead of beep
      auto-image-file-mode 1          ; open graphic files such as JPEG/PNG format files.
      doc-view-continuous t           ; At page edge goto next/previous.
      frame-title-format '(buffer-file-name "%f" ("%b")) ; show the full file name in the title
      echo-keystrokes 0.1)            ; Show keystrokes in progress.
#+END_SRC

** Modeline settings

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(line-number-mode t)
(column-number-mode t)
(size-indication-mode t)
#+END_SRC

** Clipboard

Enable copy/paste from emacs to other apps.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(setq
 interprogram-cut-function 'x-select-text
 interprogram-paste-function 'x-selection-value
 save-interprogram-paste-before-kill t
 select-active-regions t
 x-select-enable-clipboard t
 x-select-enable-primary t)
#+END_SRC

** Files

Set UTF Encoding.

Make sure UTF-8 is used everywhere.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(set-language-environment 'UTF-8)
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(setq default-buffer-file-coding-system 'utf-8-unix)
#+END_SRC

[[http://emacsredux.com/blog/2014/05/16/opening-large-files/][Opening Large Files]] - Warn when opening files bigger than 100MB.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(setq large-file-warning-threshold 100000000)
#+END_SRC

Enable global-auto-revert-mode

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(global-auto-revert-mode 1)
(setq auto-revert-verbose nil)
(setq global-auto-revert-non-file-buffers t)
#+END_SRC

Remove ^M symbols

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(add-hook 'comint-output-filter-functions
          'comint-strip-ctrl-m)
#+END_SRC

[[http://emacsredux.com/blog/2013/05/09/keep-backup-and-auto-save-files-out-of-the-way/][Keep Backup and Auto-save Files Out of the Way]]

Store all backup and autosave files in the tmp/ dir.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(setq backup-directory-alist
      `((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
      `((".*" ,temporary-file-directory t)))
#+END_SRC

Move files to trash when deleting.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(setq delete-by-moving-to-trash t)
#+END_SRC

Automatically make scripts starting with =#!= executable.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(add-hook 'after-save-hook
          'executable-make-buffer-file-executable-if-script-p)
#+END_SRC

Lines.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(setq require-final-newline t
      kill-whole-line t
      indicate-empty-lines t)
#+END_SRC

Every buffer would be cleaned up before it’s saved.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(add-hook 'before-save-hook 'whitespace-cleanup)
#+END_SRC

Whitespaces.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'whitespace)
(global-whitespace-mode)
(setq whitespace-line-column 80) ;; limit line length
(setq whitespace-style '(face tabs empty trailing lines-tail))
#+END_SRC

1. Always use spaces for indentation
2. Default to 2-space tabs

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(setq indent-tabs-mode nil)
(setq-default tab-width 2)
#+END_SRC

** Start server

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'server)
(unless (server-running-p)
  (server-start))
#+END_SRC

** Modes
*** Autocomplete

Turn on auto complete.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'auto-complete-config)
(ac-config-default)
(setq ac-auto-show-menu 0.5)
(setq ac-quick-help-height 50)
(setq ac-quick-help-delay 1)
(setq ac-use-fuzzy t)
(setq ac-disable-faces nil)
(setq ac-quick-help-prefer-x nil)

(define-key ac-completing-map (kbd "C-n") 'ac-next)
(define-key ac-completing-map (kbd "C-p") 'ac-previous)
#+END_SRC

*** Flycheck mode

#+BEGIN_QUOTE
Modern on the fly syntax checking for GNU Emacs http://flycheck.rtfd.org/
#+END_QUOTE

The modes where flycheck should be enabled.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(add-hook 'php-mode-hook 'flycheck-mode)
(add-hook 'sh-mode-hook 'flycheck-mode)
(add-hook 'json-mode-hook 'flycheck-mode)
(add-hook 'nxml-mode-hook 'flycheck-mode)
(add-hook 'emacs-lisp 'flycheck-mode)
(add-hook 'ruby-mode-hook 'flycheck-mode)
(add-hook 'sass 'flycheck-mode)
(add-hook 'scss 'flycheck-mode)
#+END_SRC

*** Web-mode

#+BEGIN_QUOTE
web-mode.el is an emacs major mode for editing web templates aka HTML files
embedding parts (CSS/JavaScript) and blocks (pre rendered by client/server side engines).
#+END_QUOTE

Github: https://github.com/fxbois/web-mode

Enable web-mode for html buffers.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'web-mode)
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
#+END_SRC

*** Markdown-mode

I love org-mode, but lots of other systems use markdown, github wiki pages being a very good example.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'markdown-mode)
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
#+END_SRC

*** Rainbow mode

#+BEGIN_QUOTE
Useful for editing themes and CSS http://julien.danjou.info/rainbow-mode.html
#+END_QUOTE

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(add-hook 'css-mode-hook 'rainbow-mode)
#+END_SRC

*** Uniquify

#+BEGIN_QUOTE
Making buffer names unique.
#+END_QUOTE

When several buffers have the same name, make the name uniqe by including part of path in name.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward)
#+END_SRC

*** Org mode

Enable org-mode for .org, .org_archive and .txt files by default.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\)$" . org-mode))
#+END_SRC

Notes / Tasks / TODOs

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(setq org-todo-keywords
      '((sequence "TODO(t)" "WAIT(w@/!)" "|" "DONE(d!)" "CANCELED(c@)")))
#+END_SRC

Set global keys for the most important org commands.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-cc" 'org-capture)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
#+END_SRC

**** Org Publishing

The brilliance of =org-mode= is the ability to publish your notes as HTML files into a web server.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'htmlize)
(setq org-html-htmlize-output-type 'inline-css)
(setq org-html-validation-link nil)

(setq org-export-default-language "bg"
      org-export-html-extension "html"
)

(setq org-publish-project-alist
      '(("blog"
         :components ("blog-content" "blog-static"))
        ("blog-content"
         ;; Directory for source files in org format
         :base-directory "~/Dropbox/blog/org/"
         :base-extension "org"
         ;; Path to exported HTML files
         :publishing-directory "~/Dropbox/blog/public_html/"
         ;;:publishing-function org-publish-org-to-html
         :publishing-function org-html-publish-to-html
         :recursive t
         :htmlized-source t
         :headline-levels 4
;; :html-head "<link rel='stylesheet' href='css/blog.css' />"
         :auto-preamble t
         :auto-sitemap t
         :sitemap-title "Sitemap"
         :sitemap-filename "sitemap.org"
         :sitemap-sort-files anti-chronologically
         ;;:sitemap-file-entry-format "%t (%d)"
         )
        ;; Path to Static files
        ("blog-static"
         :base-directory "~/Dropbox/blog/files/"
         :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf"
         :publishing-directory "~/Dropbox/blog/public_html/files/"
         :recursive t
         :publishing-function org-publish-attachment
         )))
#+END_SRC

**** Org babel

Enable syntax highlighting in src blocks.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(setq-default org-src-fontify-natively t)
#+END_SRC

List of languages that may be evaluated in Org documents.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(org-babel-do-load-languages
 'org-babel-load-languages
 '(
   (C .t)
   (sh . t)
   (python . t)
   (R . t)
   (ruby . t)
   (emacs-lisp . t)
   (lisp .t)
   (scheme . t)
   (haskell . t)
   (perl . t)
   (js . t)
   ))
#+END_SRC

*** Slime

#+BEGIN_QUOTE
SLIME, the Superior Lisp Interaction Mode for Emacs, is an Emacs mode for developing Common Lisp applications.
#+END_QUOTE

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'ac-slime)
(add-hook 'slime-mode-hook 'set-up-slime-ac)
(add-hook 'slime-repl-mode-hook 'set-up-slime-ac)

(eval-after-load "auto-complete"
  '(add-to-list 'ac-modes 'slime-repl-mode))
#+END_SRC

*** Js2-mode

#+BEGIN_QUOTE
Improved JavaScript editing mode for GNU Emacs.
#+END_QUOTE

Github: https://github.com/mooz/js2-mode

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(autoload 'js2-mode "js2-mode" nil t)

(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.json$" . js2-mode))
(add-hook 'js2-mode-hook 'flycheck-mode)
#+END_SRC

*** cc-mode

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
;; c++
(add-hook 'c++-mode-hook
          '(lambda()
             (setq indent-tabs-mode nil)
             (c-set-style "cc-mode")
             (setq c-indent-level 4)
             (setq c-tab-width 4)
             (setq tab-width 4)
             (setq c-basic-offset tab-width)))
;; c
(add-hook 'c-mode-hook
          '(lambda()
             (setq indent-tabs-mode nil)
             (c-set-style "k&r") ;; What Kernighan and Ritchie, the authors of C used in their book
             (setq c-indent-level 4)
             (setq c-tab-width 4)
             (setq tab-width 4)
             (setq c-basic-indent 2)
             (setq c-basic-offset tab-width)))

(define-key c-mode-base-map (kbd "RET") 'newline-and-indent)

(require 'autopair)
(autopair-global-mode 1)
;; tells autopair to automatically wrap the selection region with the delimiters you’re trying to insert.
(setq autopair-autowrap t)

(require 'auto-complete-clang)
(define-key c++-mode-map (kbd "C-S-<return>") 'ac-complete-clang)
#+END_SRC

*** Dired mode

#+BEGIN_QUOTE
It shows a directory (folder) listing that you can use to perform various
operations on files and subdirectories in the directory.
#+END_QUOTE

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'dired)

;; refresh buffers
(setq-default dired-auto-revert-buffer t)
(setq global-auto-revert-non-file-buffers t)
(setq auto-revert-verbose nil)

;; listing options
(setq ired-listing-switches "-alhv --group-directories-first")

;; Move files between split panes
(setq dired-dwim-target t)

;; Delete or copy a whole directory
;;(setq dired-recursive-copies 'always) ; Always means no asking
;;(setq dired-recursive-deletes 'top) ; Top means ask once for top dir only

;; No confirmation on file delete - clever hack
;;(setq dired-deletion-confirmer '(lambda (x) t))

;; hide uninteresting files, such as backup files and AutoSave files
(setq-default dired-omit-mode t
dired-omit-files "^\\.?#\\|^\\.$\\|^\\.\\.$\\|^\\.")
#+END_SRC

**** Dired-detailts

#+BEGIN_QUOTE
Hide or show the file and directory details in a Dired listing, to save space and clutter.
#+END_QUOTE

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'dired-details)
(setq-default dired-details-hidden-string "..> ")
(define-key dired-mode-map (kbd "TAB") 'dired-details-toggle)
#+END_SRC

**** Dired+

#+BEGIN_QUOTE
Enable some really cool extensions like =C-x C-j(dired-jump)=
#+END_QUOTE

Jump from file to containing directory.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'dired-x)
(global-set-key (kbd "C-x C-j") 'dired-jump) (autoload 'dired-jump "dired")
#+END_SRC

*** Ido mode

Interactive do (or ido-mode) changes the way you switch buffers and open files/directories.
Instead of writing complete file paths and buffer names you can write a part of it
and select one from a list of possibilities.
Using ido-vertical-mode changes the way possibilities are displayed, and flx-ido-mode enables fuzzy matching.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'ido-vertical-mode)
(require 'flx-ido)

(dolist (mode
         '(ido-mode ; Interactivly do.
           ido-everywhere ; Use Ido for all buffer/file reading.
           ido-vertical-mode ; Makes ido-mode display vertically.
           flx-ido-mode)) ; Toggle flx ido mode.
  (funcall mode 1))

(setq ido-vertical-define-keys 'C-n-C-p-up-down)
#+END_SRC

*** Recenf

#+BEGIN_QUOTE
Recentf is a minor mode that builds a list of recently opened files. This list is
automatically saved across Emacs sessions.
#+END_QUOTE

Enable recentf

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'recentf)
(recentf-mode 1)
(setq recentf-max-saved-items 50)
#+END_SRC

Find a recent file using Ido.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(defun ido-recentf-open ()
  "Use `ido-completing-read' to \\[find-file] a recent file"
  (interactive)
  (if (find-file (ido-completing-read "Find recent file: " recentf-list))
      (message "Opening file...")
    (message "Aborting")))

(global-set-key (kbd "C-c f") 'ido-recentf-open)
#+END_SRC

*** Aurel

#+BEGIN_QUOTE
Search, vote and download AUR packages from Emacs.
#+END_QUOTE

Github: https://github.com/alezost/aurel

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'aurel)

;;; autoloads for the interactive functions.
(autoload 'aurel-package-info "aurel" nil t)
(autoload 'aurel-package-search "aurel" nil t)
(autoload 'aurel-maintainer-search "aurel" nil t)
(autoload 'aurel-installed-packages "aurel" nil t)

;;; directory where the packages will be downloaded.
(setq aurel-download-directory "~/abs")

(global-set-key [f6] 'aurel-package-search)
#+END_SRC

*** Pkgbuild-mode

#+BEGIN_QUOTE
Major mode for editing PKGBUILD files.
#+END_QUOTE

Github: https://github.com/juergenhoetzel/pkgbuild-mode

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'pkgbuild-mode)

;; enable autoloading of pkgbuild-mode and auto-recognition of "PKGBUILD" files:
(autoload 'pkgbuild-mode "pkgbuild-mode.el" "PKGBUILD mode." t)
(setq auto-mode-alist (append '(("/PKGBUILD$" . pkgbuild-mode))
                              auto-mode-alist))
#+END_SRC

*** Guru-mode

#+BEGIN_QUOTE
Guru mode disables some common keybindings and suggests the use of the established Emacs alternatives instead.
#+END_QUOTE

Enable guru-mode globally.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'guru-mode)
(guru-global-mode +1)
#+END_SRC

Github: https://github.com/bbatsov/guru-mode

*** Smex

#+BEGIN_QUOTE
A smart M-x enhancement for Emacs.
#+END_QUOTE

Built on top of Ido, it provides a convenient interface to your recently and most frequently used commands.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'smex)
(smex-initialize)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
;; This is your old M-x.
(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
#+END_SRC

Github: https://github.com/nonsequitur/smex

*** Multiple Cursors

#+BEGIN_QUOTE
Multiple cursors, for editing multiple lines.
#+END_QUOTE

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'multiple-cursors)
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
#+END_SRC

Github: https://github.com/magnars/multiple-cursors.el

*** Magit

#+BEGIN_QUOTE
Magit is an emacs mode for interacting with the Git version control system.
#+END_QUOTE

Magit-status shortcut.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'magit)
(global-set-key [f5] 'magit-status)
#+END_SRC

Github: https://github.com/magit/magit

*** Ace-window

#+BEGIN_QUOTE
Quickly switch windows using ace-jump-mode.
#+END_QUOTE

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'ace-window)
(global-set-key (kbd "C-x o") 'other-window)
(global-set-key [remap other-window] 'ace-window)
(setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l))
#+END_SRC

Github: https://github.com/abo-abo/ace-window

*** Ace-jump-mode

#+BEGIN_QUOTE
a quick cursor jump mode for emacs.
#+END_QUOTE

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'ace-jump-mode)
(define-key global-map (kbd "C-c SPC") 'ace-jump-mode)
#+END_SRC

Github: https://github.com/winterTTr/ace-jump-mode

*** Conkeror

Every fan of Emacs should use [[http://conkeror.org/][Conkeror]]. No exceptions.

Open URLs from GNU Emacs in Conkeror in a new buffer.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(setq browse-url-browser-function 'browse-url-generic
      browse-url-generic-program "conkeror"
      ido-handle-duplicate-virtual-buffers 2)
#+END_SRC

Dired function to view a file in a web browser.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(defun my-dired-browser-find-file ()
  "Dired function to view a file in a web browser"
  (interactive)
  (browse-url (browse-url-file-url (dired-get-filename))))

;; Bind a Key in Emacs's Dired-Mode to View a File in the Default Browser
(add-hook 'dired-mode-hook
          (lambda ()
            (define-key dired-mode-map "b" 'my-dired-browser-find-file)))
#+END_SRC

Edit conkeror-rc as Js-mode.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(add-to-list 'auto-mode-alist '(".conkerorrc" . js-mode))
#+END_SRC

*** Deft

[[http://jblevins.org/projects/deft/][Deft]] is an Emacs mode for quickly browsing, filtering, and editing directories of plain text notes.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(when (require 'deft nil 'noerror)
  (setq
     deft-use-filename-as-title t
     deft-extension "org"
     deft-directory "~/Dropbox/Enotes/"
     deft-text-mode 'org-mode))

(global-set-key [f8] 'deft)
#+END_SRC

*** Elfeed

#+BEGIN_QUOTE
Elfeed is an extensible web feed reader for Emacs, supporting both Atom and RSS.
#+END_QUOTE

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'elfeed)

(setq-default elfeed-search-filter "-junk @1-week-ago +unread")

;;; My Feed list
(setq elfeed-feeds
      '(("http://rss.gmane.org/gmane.comp.misc.suckless" dwm)
        ("http://rss.gmane.org/gmane.comp.window-managers.ratpoison.devel" gmane ratpoison)
        ("http://rss.gmane.org/gmane.comp.window-managers.stumpwm.devel" gmane stumpwm)
        ("http://onethingwell.org/rss" software)
        ("https://aur.archlinux.org/rss" archlunux software)
        ("http://news.ycombinator.com/rss" news)
        ("http://nullprogram.com/feed/" emacs)
        ("http://planet.emacsen.org/atom.xml" emacs )
        ("http://www.masteringemacs.org/feed" emacs)
        ("http://feeds.sachachua.com/sachac" emacs)
        ("http://emacsrocks.com/atom.xml" emacs)
        ("http://emacs-fu.blogspot.com/feeds/posts/default" emacs)))

;; global binding for elfeed
(global-set-key [f7] 'elfeed)
#+END_SRC

Show selected title in Ratpoison.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(defun rat-message (message)
  "Show MSG in Ratpoison"
  (call-process "ratpoison" nil 0 nil "-c" (concat "echo " (or message))))

(defun elfeed-ratpoison-message ()
  (interactive)
  (let ((entry (elfeed-search-selected :single)))
    (rat-message (elfeed-entry-title entry))))

(define-key elfeed-search-mode-map "x" #'elfeed-ratpoison-message)
#+END_SRC
*** Emms

#+BEGIN_QUOTE
EMMS is the Emacs Multimedia System.
#+END_QUOTE

Website: https://www.gnu.org/software/emms/

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'emms-setup)
(require 'emms-streams)
(require 'emms-info)
(require 'emms-info-mp3info)
(require 'emms-browser)
(emms-standard)
(emms-default-players)

;; When asked for emms-play-directory, always start from this one
(setq emms-source-file-default-directory "/home/ivo/Music/")
(add-to-list 'emms-info-functions 'emms-info-mp3info)

;; Show the current track each time EMMS
;; starts to play a track with "NP : "
(add-hook 'emms-player-started-hook 'emms-show)
        (setq emms-show-format "NP: %s"
              emms-repeat-playlist t)

;; Buffer name
(setq emms-playlist-buffer-name "*EMMS Playlist*"
      emms-playlist-mode-open-playlists t)
#+END_SRC

*** Mu4e

Email client http://www.djcbsoftware.nl/code/mu/mu4e.html

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'mu4e)

;; default's mu4e
(setq mu4e-maildir "~/Maildir"
      mu4e-drafts-folder "/[Gmail].Drafts"
      mu4e-sent-folder "/[Gmail].Sent Mail"
      mu4e-trash-folder "/[Gmail].Trash"
      ;; allow for updating mail using 'U' in the main view:
      mu4e-get-mail-command "offlineimap"
      ;; Number of seconds between automatic calls to retrieve mail and update the database:
      mu4e-update-interval 60
      ;; allow the mu4e user to disable the confirmation message when quitting mu4e
      mu4e-confirm-quit nil
      ;; Date format
      mu4e-headers-date-format "%d/%b/%Y %H:%M"
      ;; Displaying rich-text messages
      ;;mu4e-html2text-command "html2text -utf8 -width 72"
      mu4e-html2text-command "w3m -dump -T text/html"
      ;; display images
      mu4e-view-show-images t
      mu4e-view-image-max-width 800
      ;; Use fancy chars
      mu4e-headers-seen-mark '("S" . "☑")
      mu4e-headers-new-mark '("N" . "✉")
      mu4e-headers-replied-mark '("R" . "↵")
      mu4e-headers-passed-mark '("P" . "⇉")
      mu4e-headers-encrypted-mark '("x" . "⚷")
      mu4e-headers-signed-mark '("s" . "✍")
      mu4e-headers-empty-parent-prefix '("-" . "◆")
      mu4e-headers-first-child-prefix '("\\" . "▶")
      mu4e-use-fancy-chars t
      ;; don't save message to Sent Messages, Gmail/IMAP takes care of this
      mu4e-sent-messages-behavior 'delete
      ;; setup some handy shortcuts
      ;; you can quickly switch to your Inbox -- press ``ji''
      ;; then, when you want archive some messages, move them to
      ;; the 'All Mail' folder by pressing ``ma''.
      mu4e-maildir-shortcuts
      '( ("/INBOX" . ?i)
         ("/[Gmail].Sent Mail" . ?s)
         ("/[Gmail].Trash" . ?t)
         ("/[Gmail].All Mail" . ?a))
)

;; personal
(setq
 user-mail-address "ivkuzev@gmail.com"
 user-full-name "Ivaylo Kuzev"
 mu4e-compose-signature "Ivaylo Kuzev | @ivo")

;; use imagemagick, if available to display images in mu4e:
(when (fboundp 'imagemagick-register-types)
  (imagemagick-register-types))

;; Setting the default emacs mail program
(setq mail-user-agent 'mu4e-user-agent)

;; SMTP ;;
(require 'smtpmail)
(setq message-send-mail-function 'smtpmail-send-it
    smtpmail-stream-type 'starttls
    smtpmail-default-smtp-server "smtp.gmail.com"
    smtpmail-smtp-server "smtp.gmail.com"
    smtpmail-smtp-service 587)
#+END_SRC

**** Mu4e and Org Contacts

I want to use org-contacts.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'org)
(require 'org-contacts)
(setq mu4e-org-contacts-file "~/Dropbox/Org/contacts.org")
(add-to-list 'mu4e-headers-actions
             '("org-contact-add" . mu4e-action-add-org-contact) t)
(add-to-list 'mu4e-view-actions
             '("org-contact-add" . mu4e-action-add-org-contact) t)
#+END_SRC

**** And a hot key

And we want to be able to switch to mu4e quickly so let’s set =f9= to be the hot key.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(global-set-key [f9] 'mu4e)
#+END_SRC

*** Multiterm

Use Emacs terminfo, not system terminfo

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
;; tic -o ~/.terminfo /usr/share/emacs/24.3/etc/e/eterm-color.ti
(setq system-uses-terminfo nil)
#+END_SRC

Multiterm setup.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
;; http://www.emacswiki.org/emacs/MultiTerm
(when (require 'multi-term nil t)
  (global-set-key [f1] 'multi-term)
  (global-set-key (kbd "C-c n") 'multi-term-next)
  (global-set-key (kbd "C-c p") 'multi-term-prev)
      (setq multi-term-buffer-name "eterm"
      multi-term--program "/bin/zsh"))

;; Turn off current-line-highlighting and auto-pair.
(defadvice term-char-mode (after term-char-mode-fixes ())
  (autopair-mode -1)
  (set (make-local-variable 'hl-line-mode) nil)
  (set (make-local-variable 'global-hl-line-mode) nil))
(ad-activate 'term-char-mode)

;; fix copy/paste
(add-hook
 'term-mode-hook
 (lambda ()
   (define-key term-raw-map (kbd "C-y") 'term-paste)
   (define-key term-raw-map (kbd "C-v") 'term-paste)
   (define-key term-raw-map (kbd "s-v") 'term-paste)))

;; unlimited terminal buffer
(add-hook 'term-mode-hook
          (lambda ()
            (setq term-buffer-maximum-size 0)))
#+END_SRC

*** Ratpoison

#+BEGIN_QUOTE
Ratpoison support for Emacs.
#+END_QUOTE

You have to install [[http://www.nongnu.org/ratpoison/index.html][Ratpoison]] first.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(require 'ratpoison)
(add-to-list 'auto-mode-alist '("\\.ratpoisonrc$" . ratpoisonrc-mode))
#+END_SRC

*** Shell mode

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(setq shell-file-name "/bin/zsh")
(add-to-list 'auto-mode-alist '("\\.zsh\\'" . shell-script-mode))
#+END_SRC

** Useful functions

Hide the mode-line in the current buffer.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
;; http://bzg.fr/emacs-hide-mode-line.html
(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 nil
  :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))
  (when (and (called-interactively-p 'interactive)
             hidden-mode-line-mode)
    (run-with-idle-timer
     0 nil 'message
     (concat "Hidden Mode Line Mode enabled. "
             "Use M-x hidden-mode-line-mode RET to make the mode-line appear."))))
#+END_SRC

slick-copy: make copy-past a bit more intelligent.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
;; from: http://www.emacswiki.org/emacs/SlickCopy
(defadvice kill-ring-save (before slick-copy activate compile)
    "When called interactively with no active region, copy a single
line instead."
    (interactive
     (if mark-active (list (region-beginning) (region-end))
       (message "Copied line")
       (list (line-beginning-position)
             (line-beginning-position 2)))))
#+END_SRC

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(defadvice kill-region (before slick-cut activate compile)
    "When called interactively with no active region, kill a single
line instead."
    (interactive
     (if mark-active (list (region-beginning) (region-end))
       (list (line-beginning-position)
             (line-beginning-position 2)))))
#+END_SRC

enable slime with slime helper.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
;;(condition-case ex ; if slime-helper is not installed do not give an error
;; (progn
;; (load (expand-file-name "~/quicklisp/slime-helper.el"))

      ;; Replace "sbcl" with the path to your implementation
;; (setq inferior-lisp-program "sbcl")

      ;; connect slime automatically
      ;; when slime-mode is opened
;; (defun cliki:start-slime ()
;; (unless (slime-connected-p)
;; (save-excursion (slime))))
      ;; add full linking set
;; (add-hook 'slime-mode-hook 'cliki:start-slime))
;; ('error (message "slime could not be loaded")))
#+END_SRC

Search in Google.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
;; from @bbatsov
(defun google ()
  "Google the selected region if any, display a query prompt otherwise."
  (interactive)
  (browse-url
   (concat
    "http://www.google.com/search?ie=utf-8&oe=utf-8&q="
    (url-hexify-string (if mark-active
                           (buffer-substring (region-beginning) (region-end))
                         (read-string "Google: "))))))
#+END_SRC

Search in Youtube.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
;; http://emacsredux.com/blog/2013/08/26/search-youtube/
(defun youtube ()
  "Search YouTube with a query or region if any."
  (interactive)
  (browse-url
   (concat
    "http://www.youtube.com/results?search_query="
    (url-hexify-string (if mark-active
                           (buffer-substring (region-beginning) (region-end))
                         (read-string "Search YouTube: "))))))
#+END_SRC

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(defun kill-emacs-or-frame (arg)
  (interactive "P")
  (if (not server-buffer-clients)
      (if (and (not arg) (> (length (visible-frame-list)) 1))
          (delete-frame)
        (save-buffers-kill-emacs))
    (save-buffer)
    (server-buffer-done (current-buffer))))
#+END_SRC

rename buffer and file opened in emacs.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(defun rename-file-and-buffer (new-name)
  "Renames both current buffer and file it's visiting to NEW-NAME."
  (interactive "sNew name: ")
  (let ((name (buffer-name))
        (filename (buffer-file-name)))
    (if (not filename)
        (message "Buffer '%s' is not visiting a file!" name)
      (if (get-buffer new-name)
          (message "A buffer named '%s' already exists!" new-name)
        (progn
          (rename-file name new-name 1)
          (rename-buffer new-name)
          (set-visited-file-name new-name)
                    (set-buffer-modified-p nil))))))
#+END_SRC

Delete the current file, and kill the buffer.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
;; from @purcell
(defun delete-this-file ()
  "Delete the current file, and kill the buffer."
  (interactive)
  (or (buffer-file-name) (error "No file is currently being edited"))
  (when (yes-or-no-p (format "Really delete '%s'?"
                             (file-name-nondirectory buffer-file-name)))
    (delete-file (buffer-file-name))
    (kill-this-buffer)))
#+END_SRC

Move line =up|down=.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
;; http://emacsredux.com/blog/2013/04/02/move-current-line-up-or-down/
;; also check https://github.com/rejeep/drag-stuff.el
(defun move-line-up ()
  "Move up the current line."
  (interactive)
  (transpose-lines 1)
  (forward-line -2)
  (indent-according-to-mode))

(defun move-line-down ()
  "Move down the current line."
  (interactive)
  (forward-line 1)
  (transpose-lines 1)
  (forward-line -1)
  (indent-according-to-mode))
#+END_SRC

Insert date.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(defun insert-date ()
  "Insert the current date."
  (interactive)
  (insert (format-time-string "%Y-%m-%dT%T%z")))
#+END_SRC

Show line numbers temporarily, while prompting for the line number input.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
;; from @magnars https://gist.github.com/magnars/3292872
(defun goto-line-with-feedback (&optional line)
  "Show line numbers temporarily, while prompting for the line number input"
  (interactive "P")
  (if line
      (goto-line line)
    (unwind-protect
        (progn
          (linum-mode 1)
          (goto-line (read-number "Goto line: ")))
      (linum-mode -1))))
#+END_SRC

Kill other buffers.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
;; http://www.emacswiki.org/emacs/KillingBuffers
(defun kill-other-buffers ()
  "Kill all other buffers."
  (interactive)
  (mapc 'kill-buffer (delq (current-buffer) (buffer-list))))

(defun kill-all-dired-buffers ()
      "Kill all dired buffers."
      (interactive)
      (save-excursion
        (let ((count 0))
          (dolist (buffer (buffer-list))
            (set-buffer buffer)
            (when (equal major-mode 'dired-mode)
              (setq count (1+ count))
              (kill-buffer buffer)))
          (message "Killed %i dired buffer(s)." count))))
#+END_SRC

Create all the intermediate dirs if they weren't existing when save a file.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
;; https://stackoverflow.com/posts/6830894/revisions
(add-hook 'before-save-hook
          (lambda ()
            (let ((dir (file-name-directory buffer-file-name)))
              (unless (file-exists-p dir)
                (make-directory dir t)))))
#+END_SRC

Sudo edit.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(defun sudo-edit (&optional arg)
  "Open the current buffer (or prompt for file if ARG is non-nill) using sudo to edit as root."
  (interactive "p")
  (if (or arg (not buffer-file-name))
      (find-file (concat "/sudo::" (ido-read-file-name "File: ")))
    (find-alternate-file (concat "/sudo::" buffer-file-name))))
#+END_SRC

Insert a lorem ipsum.

#+BEGIN_SRC emacs-lisp :tagnle ~/.emacs
(defun lorem ()
  "Insert a lorem ipsum."
  (interactive)
  (insert "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
          "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim"
          "ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut "
          "aliquip ex ea commodo consequat. Duis aute irure dolor in "
          "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "
          "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in "
          "culpa qui officia deserunt mollit anim id est laborum."))
#+END_SRC

Translate the following region in lingvo.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
;; from @snosov1
(defun lingvo-it ()
  "Translate the following region in lingvo, display a query
prompt otherwise."
  (interactive)
  (browse-url
   (concat
    "http://lingvopro.abbyyonline.com/en/Translate/en-es/"
    (url-hexify-string (if mark-active
                           (buffer-substring (region-beginning) (region-end))
                         (read-string "Lingvo: "))))))
#+END_SRC

Edit the shell init file in another window.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
;; http://emacsredux.com/blog/page/2/
(defun find-shell-init-file ()
  "Edit the shell init file in another window."
  (interactive)
  (let* ((shell (car (reverse (split-string (getenv "SHELL") "/"))))
         (shell-init-file (cond
                           ((string-equal "zsh" shell) ".zshrc")
                           ((string-equal "bash" shell) ".bashrc")
                           (t (error "Unknown shell")))))
    (find-file-other-window (expand-file-name shell-init-file (getenv "HOME")))))
(global-set-key (kbd "C-c S") 'find-shell-init-file)
#+END_SRC

Create a new scratch buffer.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(defun create-scratch-buffer ()
  "Create a new scratch buffer."
  (interactive)
  (progn
    (switch-to-buffer
     (get-buffer-create (generate-new-buffer-name "*scratch*")))
    (emacs-lisp-mode)))
#+END_SRC

Smarter Navigation to the Beginning of a Line.

Read [[http://emacsredux.com/blog/2013/05/22/smarter-navigation-to-the-beginning-of-a-line/][this]] for details.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(defun smarter-move-beginning-of-line (arg)
  "Move point back to indentation of beginning of line.

Move point to the first non-whitespace character on this line.
If point is already there, move to the beginning of the line.
Effectively toggle between the first non-whitespace character and
the beginning of the line.

If ARG is not nil or 1, move forward ARG - 1 lines first.  If
point reaches the beginning or end of the buffer, stop there."
  (interactive "^p")
  (setq arg (or arg 1))

  ;; Move lines first
  (when (/= arg 1)
    (let ((line-move-visual nil))
      (forward-line (1- arg))))

  (let ((orig-point (point)))
    (back-to-indentation)
    (when (= orig-point (point))
      (move-beginning-of-line 1))))

;; remap C-a to `smarter-move-beginning-of-line'
(global-set-key [remap move-beginning-of-line]
                'smarter-move-beginning-of-line)
#+END_SRC

** Global key bindings.

Goto line with feedback.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(global-set-key (kbd "C-x g") 'goto-line)
(global-set-key [remap goto-line] 'goto-line-with-feedback)
#+END_SRC

Split window.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(global-set-key (kbd "M-3") 'split-window-horizontally)
(global-set-key (kbd "M-2") 'split-window-vertically)
(global-set-key (kbd "M-1") 'delete-other-windows)
(global-set-key (kbd "M-0") 'delete-window)
#+END_SRC

Resize window.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(global-set-key (kbd "C-c <up>") 'shrink-window)
(global-set-key (kbd "C-c <down>") 'enlarge-window)
(global-set-key (kbd "C-c <left>") 'shrink-window-horizontally)
(global-set-key (kbd "C-c <right>") 'enlarge-window-horizontally)
#+END_SRC

Buffer switching.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <left>") 'windmove-left)
#+END_SRC

Move-current-line-up-or-down.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(global-set-key (kbd "M-<up>") 'move-line-up)
(global-set-key (kbd "M-<down>") 'move-line-down)
#+END_SRC

iBuffer.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(autoload 'ibuffer "ibuffer" "List buffers." t)
(global-set-key (kbd "C-x C-b") 'ibuffer)
#+END_SRC

Kill buffer without questions.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(global-set-key (kbd "C-x k") 'kill-this-buffer)
#+END_SRC

Kills all buffers, except the current one.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(global-set-key (kbd "C-x M-k") 'kill-other-buffers)
#+END_SRC

Kill emacs or frame.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(global-set-key "\C-x\C-c" 'kill-emacs-or-frame)
#+END_SRC

Clipboard.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(global-set-key (kbd "C-w") 'clipboard-kill-region)
(global-set-key (kbd "M-w") 'clipboard-kill-ring-save)
(global-set-key (kbd "C-y") 'clipboard-yank)
#+END_SRC

Delete words with =C-w= and rebind kill region to =C-x C-k=

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(global-set-key (kbd "C-w") 'backward-kill-word)
(global-set-key "\C-x\C-k" 'kill-region)
(global-set-key "\C-c\C-k" 'kill-region)
#+END_SRC

Files.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(global-set-key (kbd "C-x f") 'ido-find-file)
(global-set-key (kbd "C-o") 'ido-find-file)
(global-set-key (kbd "C-x s") 'save-buffer)
(global-set-key (kbd "C-x C-s") 'save-some-buffers)
(global-set-key (kbd "C-x c") 'save-buffers-kill-emacs)
#+END_SRC

=increase|decrease= font size.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(define-key global-map (kbd "C-+") 'text-scale-increase)
(define-key global-map (kbd "C--") 'text-scale-decrease)
#+END_SRC

Browse Url.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(define-key global-map (kbd "C-x M-g") 'google)
(define-key global-map (kbd "C-x M-y") 'youtube)
(define-key global-map (kbd "C-x M-b") 'browse-url-at-point)
#+END_SRC

Proced.

#+BEGIN_SRC emacs-lisp :tangle ~/.emacs
(global-set-key (kbd "C-x p") 'proced)
#+END_SRC


text:
#+TITLE: dotfiles-organisation
#+AUTHOR: ivo

* TODO
** Tasks with unclassified time period
*** TODO Urxvt Ctrl+c (clipboard/copy) does not work well with emacs. Set another key or comment this line in .Xresources file.
*** TODO Make function to open man-pages in Conkeror
*** TODO Make function to take a full-length screenshot of a web page.
*** DONE Make function to switch to the buffer that has radio.
*** TODO Emacs (multi-term) keybinds + zsh - have to work better
*** CANCELLED Emacs (multiple-term) does not recognize ~/.dircolors
*** DONE Zenburn color-scheme configured for everything.
*** DONE A minimal console based workflow with editing, org mode, email, shell...

repo_language: Shell

file_name: PKGBUILD

mime_type: text/plain


text:
#+TITLE: My window manager configuration

#+ATTR_HTML: :alt ratpoison.png image :title ratpoison :align left :width 480px :hight 280px
[[file:images/ratpoison.png]]

** Disable "Welcome" message.

I disabled the default welcome message on start up RP.

#+begin_src sh :tangle ~/.ratpoisonrc
startup_message off
#+end_src

** Unmanaged windows.

List of unmanaged windows.

#+begin_src sh :tangle ~/.ratpoisonrc
unmanage xmessage
#+end_src

** Appearance.

#+begin_src sh :tangle ~/.ratpoisonrc
set font "Anonymous Pro-13"
set bgcolor LightGray
set bargravity ne
set barpadding 5 0
set winliststyle row
set winfmt [%n] %s %t
set winname class
set wingravity c
set maxsizegravity c
#+end_src

*** RP "The best wm for smaller screens!"

I use Ratpoison on tiny 10 inch screen. So I disabled borders/panels etc..

#+begin_src sh :tangle ~/.ratpoisonrc
set padding 0 0 0 0
set barborder 0
set border 0
#+end_src

** Other commands.

Don't change the cursor into a square when waiting for a key.

#+begin_src sh :tangle ~/.ratpoisonrc :padline no
set waitcursor 0
#+end_src

I like 3 seconds for messages.

#+begin_src sh :tangle ~/.ratpoisonrc :padline no
msgwait 3
#+end_src

** Rudeness.

#+begin_src sh :tangle ~/.ratpoisonrc
# Rudeness is a bitwise or of the following values:
# 1 Transient windows may raise.
# 2 Normal windows may raise.
# 4 New transient windows end up in the foreground.
# 8 New normal windows end up in the foreground.
rudeness 12
#+end_src

** Hooks.

1. Warp the rat to corner of the screen every time you press a top level bound key.
2. Display information about the current window when you switch to a different window.
3. Display information about the current window when you switch to a different frame.

#+begin_src sh :tangle ~/.ratpoisonrc
addhook key banish
addhook switchwin info [%n] %t
addhook switchframe info [%n] %t
#+end_src

** Key bindings.

*** Ratpoison Escape key

#+BEGIN_SRC sh :tangle ~/.ratpoisonrc
escape C-a
#+END_SRC

*** Groups/Windows/Frames

#+begin_src sh :tangle ~/.ratpoisonrc
bind z windows
bind o only
bind u undo
bind d dedicate
bind g groups
#+end_src

*** GnuScreen like keys for split frames

#+BEGIN_SRC sh :tangle ~/.ratpoisonrc
bind s hsplit
bind C-s hsplit
bind S split
bind C-S split
#+END_SRC

*** Using Other Window Manager

#+BEGIN_QUOTE
Use at your own risk ☠!!!
#+END_QUOTE

Temporarily gives control over to [[https://github.com/ivoarch/calavera-wm][Calavera]] window manager and regains control once it has terminated.
I use this when I have to play with floating windows.

#+BEGIN_SRC sh :tangle ~/.ratpoisonrc
bind W tmpwm calavera-wm
#+END_SRC

*** Run-or-raise

Emulate stumpwm run-or-raise with ratpoison.

Get the run-or-raise script form [[https://raw.github.com/ivoarch/bin/master/ratpoison/rp-run-or-raise.sh][here]].

1. =C-t c= run-or-raise to the Urxvt inside running Screen session. Set window 0 for default shell in your =~/.screenrc= config.
2. =C-t E= run-or-raise Emacs GUI
3. =C-t e= run-or-raise to the Emacs inside running Screen session. Set window 1 for emacs in your =~/.screenrc= config.
4. =C-t w= run-or-raise Conkeror

#+begin_src sh :tangle ~/.ratpoisonrc
bind c exec screen -X select 0; exec ~/bin/ratpoison/rp-run-or-raise.sh URxvt 'urxvt'
alias emacs exec ~/bin/ratpoison/rp-run-or-raise.sh Emacs 'emacsclient -ca emacs'
bind E emacs
alias escreen exec screen -X select 1; exec ~/bin/ratpoison/rp-run-or-raise.sh URxvt 'urxvt'
bind e escreen
alias conkeror exec ~/bin/ratpoison/rp-run-or-raise.sh Conkeror 'conkeror'
bind w conkeror
#+end_src

*** Function

Open *man* pages from RP.

#+begin_src sh :tangle ~/.ratpoisonrc :padline no
bind m exec ratpoison -c "exec urxvt -e man $(ratpoison -c "prompt Manpage:")"
#+end_src

Show Dropbox status.

#+begin_src sh :tangle ~/.ratpoisonrc :padline no
bind D exec ratpoison -c "echo `dropbox status`"
#+end_src

Displays the date with a calendar indicating today.

The script comes in the RP contrib dir ([[http://git.savannah.gnu.org/cgit/ratpoison.git/plain/contrib/ratdate.sh][here]]).

#+BEGIN_SRC sh :tangle ~/.ratpoisonrc :padline no
alias time exec /usr/share/ratpoison/ratdate.sh
bind t time
#+END_SRC

Show info script.

Get the ratpoison-info script from [[https://raw2.github.com/ivoarch/bin/master/ratpoison/rat_info.sh][here]].

#+begin_src sh :tangle ~/.ratpoisonrc :padline no
bind I exec ~/bin/ratpoison/rat_info.sh
#+end_src

Toggle =on|off= energy saving.

Get the script from [[https://raw2.github.com/ivoarch/bin/master/system/dpms-toggle.sh][here]].

#+begin_src sh :tangle ~/.ratpoisonrc
alias screensaver exec ~/bin/system/dpms-toggle.sh
bind Pause screensaver
#+end_src

Toggle =on|off= touchpad.

Get the script from [[https://raw2.github.com/ivoarch/bin/master/system/touchpad_toggle][here]].

#+BEGIN_SRC sh :tangle ~/.ratpoisonrc
alias toggletouchpad exec ~/bin/system/touchpad_toggle
bind BackSpace toggletouchpad
#+END_SRC

Take a screenshot.

#+begin_src sh :tangle ~/.ratpoisonrc
alias ratshot exec import -window root png:$HOME/Pictures/Screenshots/ratpoison-$(date +%s)$$.png && ratpoison -c "echo Ratshot saved!"
definekey top Print ratshot
#+end_src

*** Other.

Abort keystrokes.

#+begin_src sh :tangle ~/.ratpoisonrc
definekey root Escape abort
#+end_src

Prevent accidental closes.

#+BEGIN_SRC sh :tangle ~/.ratpoisonrc
unbind k
#+END_SRC

*** Multimedia keys.

Audio/Volume keys.

#+begin_src sh :tangle ~/.ratpoisonrc
definekey top XF86AudioRaiseVolume exec amixer -q set PCM 5+ unmute; ratpoison -c "echo RaiseVolume +5"
definekey top XF86AudioLowerVolume exec amixer -q set PCM 5- unmute;  ratpoison -c "echo LowerVolume -5"
definekey top XF86AudioMute exec amixer -q set PCM toggle; ratpoison -c "echo [ MUTE ]"
#+end_src

Control EMMS (emacs multimedia system)

#+begin_src sh :tangle ~/.ratpoisonrc
definekey top XF86AudioPlay exec urxvt -e emacsclient -e "(emms-pause)"; ratpoison -c "echo toggle EMMS"
definekey top XF86AudioPrev exec urxvt -e emacsclient -e "(emms-previous)"; ratpoison -c "echo EMMS << Previous song"
definekey top XF86AudioNext exec urxvt -e emacsclient -e "(emms-next)"; ratpoison -c "echo EMMS >> Next song"
#+end_src

** Aliases.

1. Edit the ratpoison(rc) config file (requiere emacs).
2. Quickly checks if I have new (g)mail (requiere xmessage).
3. Run skype with GSPCA webcams video support.
4. Create Note (requiere emacs-deft-mode).
5. Start shutdown/reboot menu (requiere xmessage).

Get the scripts (2) [[https://raw2.github.com/ivoarch/bin/master/mail/gmail.sh][gmail.sh]], (3) [[https://raw2.github.com/ivoarch/bin/master/system/run-skype.sh][run-skype]], (5) [[https://raw2.github.com/ivoarch/bin/master/system/poweroff.sh][poweroff.sh]]

#+begin_src sh :tangle ~/.ratpoisonrc
alias edit exec emacs $HOME/.ratpoisonrc
alias mail exec ~/bin/mail/gmail.sh
alias skype exec ~/bin/system/run-skype.sh
alias enote exec emacsclient -c --eval '(deft)'
alias poweroff exec ~/bin/system/poweroff.sh
#+end_src

** Initial commands.

List of programs that start when ratpoison starts.

#+begin_src sh :tangle ~/.ratpoisonrc
exec urxvt -e screen -RD
exec conkeror
#+end_src


text:
#+TITLE: My .gtkrc-2.0 file

** Completely remove icons from buttons and menus

#+BEGIN_SRC sh :tangle ~/.gtkrc-2.0
gtk-button-images = 0
gtk-menu-images = 0
#+END_SRC

** Use emacs keybindings everywhere

#+BEGIN_SRC sh :tangle ~/.gtkrc-2.0
gtk-key-theme-name = "Emacs"
include "/usr/share/themes/Emacs/gtk-2.0-key/gtkrc"
#+END_SRC

** Remove/Kill all scrollbars

This method eliminates all scrollbars in GTK apps, see [[http://conkeror.org/HideScrollbars][HideScrollbars]].

#+BEGIN_SRC sh :tangle ~/.gtkrc-2.0
style "noscrollbars" {
  GtkScrollbar::slider-width=0
  GtkScrollbar::trough-border=0
  GtkScrollbar::has-backward-stepper=0
  GtkScrollbar::has-forward-stepper=0
  GtkScrollbar::has-secondary-backward-stepper=0
  GtkScrollbar::has-secondary-forward-stepper=0
}
widget "MozillaGtkWidget.*" style "noscrollbars"
#+END_SRC


text:
#+TITLE: Gnu Screen RC file

** Turn welcome message off

#+begin_src sh :tangle ~/.screenrc
startup_message off
#+end_src

** Use 256 colors.

#+begin_src sh :tangle ~/.screenrc :padline no
term screen-256color
#+end_src

** Use 256 Colors with Rxvt-Unicode.

#+begin_src sh :tangle ~/.screenrc :padline no
terminfo rxvt-unicode 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
#+end_src

** Turn off visual bell.

#+begin_src sh :tangle ~/.screenrc :padline no
vbell off
#+end_src

** Message timeout in seconds.

#+begin_src sh :tangle ~/.screenrc :padline no
msgwait 2
#+end_src

** More scrollbacks.

#+begin_src sh :tangle ~/.screenrc :padline no
defscrollback 10000
#+end_src

** Turn off hardstatus.

#+begin_src sh :tangle ~/.screenrc :padline no
hardstatus off
#+end_src

** Create default windows.

1. window 0 is default shell
2. window 1 is for emacs
3. start screen from 0 my default shell

#+BEGIN_SRC sh :tangle ~/.screenrc
screen
screen -t emacs emacsclient -t
select 0
#+END_SRC

** Alternate screen support.

#+begin_src sh :tangle ~/.screenrc
altscreen on
#+end_src

** Set Escape key.

Emacs uses =C-a= for ‘beginning-of-line’, so =C-a= is too important to me to remap

#+begin_src sh :tangle ~/.screenrc
escape ^Zz
#+end_src


text:
#+TITLE: ZSH Configuration file

** Load Antigen
I use [[https://github.com/zsh-users/antigen][antigen]] as plugin manager for my zsh.

#+begin_src sh :tangle ~/.zshrc
source /usr/share/zsh/scripts/antigen/antigen.zsh
#+end_src

** Enable extra/plugins/modules

*** The "command not found" hook.

Automatically search the official repositories, if you enter an unrecognized command.

#+BEGIN_SRC sh :tangle ~/.zshrc
source /usr/share/doc/pkgfile/command-not-found.zsh
#+END_SRC

*** Fish shell like syntax highlighting for Zsh.

This one’s awesome. It highlights what you’re typing in real time.

#+begin_src sh :tangle ~/.zshrc
antigen bundle zsh-users/zsh-syntax-highlighting
#+end_src

Color the highlighting to your liking.

#+begin_src sh :tangle ~/.zshrc
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern)

# Aliases and functions
ZSH_HIGHLIGHT_STYLES[alias]='fg=blue,bold'
ZSH_HIGHLIGHT_STYLES[function]='fg=cyan,bold'

# Commands and builtins
ZSH_HIGHLIGHT_STYLES[command]="fg=green"
ZSH_HIGHLIGHT_STYLES[hashed-command]="fg=green,bold"
ZSH_HIGHLIGHT_STYLES[builtin]="fg=green,bold"
ZSH_HIGHLIGHT_STYLES[precommand]="fg=green,underline"
ZSH_HIGHLIGHT_STYLES[commandseparator]="none"

# Paths
ZSH_HIGHLIGHT_STYLES[path]='fg=white,underline'

# Globbing
ZSH_HIGHLIGHT_STYLES[globbing]='fg=yellow,bold'

# Options and arguments
ZSH_HIGHLIGHT_STYLES[single-hyphen-option]='fg=red'
ZSH_HIGHLIGHT_STYLES[double-hyphen-option]='fg=red'

ZSH_HIGHLIGHT_STYLES[back-quoted-argument]="fg=green"
ZSH_HIGHLIGHT_STYLES[single-quoted-argument]="fg=green"
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]="fg=green"
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]="fg=green"
ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]="fg=green"

# Patterns
ZSH_HIGHLIGHT_PATTERNS+=('mv *' 'fg=white,bold,bg=red')
ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red')
ZSH_HIGHLIGHT_PATTERNS+=('sudo ' 'fg=white,bold,bg=red')
#+end_src

*** ZSH port of Fish shell's history search feature.

Type part of a command that you have run in the past, push the =up|down= arrow, or using emacs style like =^N ^P=
and start going back in time to your previous commands that match that sub string.

#+begin_src sh :tangle ~/.zshrc
antigen bundle zsh-users/zsh-history-substring-search
#+end_src

Settings.

#+begin_src sh :tangle ~/.zshrc
# bind UP and DOWN arrow keys
for keycode in '[' '0'; do
bindkey "^[${keycode}A" history-substring-search-up
  bindkey "^[${keycode}B" history-substring-search-down
done
unset keycode

# bind P and N for EMACS mode
bindkey -M emacs '^P' history-substring-search-up
bindkey -M emacs '^N' history-substring-search-down
#+end_src

*** Tell antigen that you're done

You have to add this command after defining all bundles you need, in your zshrc. The completions defined by your bundles
will be loaded at this step.

#+begin_src sh :tangle ~/.zshrc
antigen-apply
#+end_src

** Quoting URLs

Functions to make it easier to type URLs as command line arguments.

#+begin_src sh :tangle ~/.zshrc
autoload -U url-quote-magic
zle -N self-insert url-quote-magic
#+end_src

** Fix Emacs multi-term colors

#+begin_src sh :tangle ~/.zshrc
if [ "$EMACS" ];then
    export TERM=Eterm-color
fi
#+end_src

** Glabal options

#+begin_src sh :tangle ~/.zshrc
setopt nobeep                  # i hate beeps
setopt alwaystoend             # when complete from middle, move cursor
setopt autopushd               # automatically append dirs to the push/pop list
setopt cdablevars              # avoid the need for an explicit $
setopt correct_all             # correct all the words in the command line
setopt noflowcontrol           # if I could disable Ctrl-s completely I would!
setopt RM_STAR_WAIT            # confirmation after 'rm *' etc..
#+end_src

** Completion stuff

Completion in =zsh= is awesome. One of the most complex parts of the shell.

*** Load completions

#+begin_src sh :tangle ~/.zshrc
autoload -U compinit
compinit
zmodload zsh/complist
#+end_src

*** Options

#+begin_src sh :tangle ~/.zshrc
setopt completealiases         # complete alisases
setopt extendedglob            # weird & wacky pattern matching - yay zsh!
setopt nolisttypes             # show types in completion
setopt autolist                # filename completion
setopt listpacked              # compact completion lists
setopt MARK_DIRS               # Append a trailing `/' to all directory names resulting from filename generation (globbing).
setopt completeinword          # not just at the end
#+end_src

*** Formatting and messages

#+begin_src sh :tangle ~/.zshrc
zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions' format $'%{\e[0;33m%} %B%d%b%{\e[0m%}'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d'
zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
zstyle ':completion:*' group-name ''
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*:default' list-prompt'%S%M matches%s'
zstyle ':completion:*:prefix:*' add-space true
#+end_src

*** Speed up zsh completion

#+begin_src sh :tangle ~/.zshrc
zstyle ':completion:*:paths' accept-exact '*(N)'
zstyle ':completion::complete:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache
#+end_src

*** Zsh auto rehash commands

Sometimes zsh not recognize the executable when installing a new program.
To rebuild the cache of executable commands, add the following line to your =~/.zshrc= file.

#+begin_src sh :tangle ~/.zshrc
zstyle ':completion:*' rehash true
#+end_src

*** Case sensitive, partial word and substring completion

#+begin_src sh :tangle ~/.zshrc
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
#+end_src

*** Activate menu selection

Autocompletion with an arrow-key driven interface.

#+begin_src sh :tangle ~/.zshrc
zstyle ':completion:*' menu select=2
#+end_src

*** Color/list

Get zsh to color the completed part of the results when using tab completion.

#+begin_src sh :tangle ~/.zshrc
zstyle ':completion:*' list-colors "=(#b) #([0-9]#)*=34=36"
#+end_src

*** My process (killer) completion

I really like the =kill|all= autocomplete functionality of zsh.

#+begin_src sh :tangle ~/.zshrc
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $(whoami) -o pid,%cpu,tty,cputime,cmd'
zstyle ':completion:*:*:killall:*' menu yes select
zstyle ':completion:*:killall:*' force-list always
#+end_src

** Starting and Stopping Processes: Signals, Job Control

*** Report CPU usage for commands running longer than 10 seconds.

#+begin_src sh :tangle ~/.zshrc
export TIMEFMT="%U user %S system %P cpu %*E total, running %J"
REPORTTIME=10
#+end_src

** Directory

Most of these commands are used for quick navigation.

*** Options

#+begin_src sh :tangle ~/.zshrc
setopt autocd                   # change to dirs without cd
setopt pushd_to_home            # Push to home directory when no argument is given.
setopt auto_pushd               # Push the old directory onto the stack on cd.
setopt auto_name_dirs           # Auto add variable-stored paths to ~ list.
setopt pushd_ignore_dups        # Do not store duplicates in the stack.
#+end_src

*** Functions

#+begin_src sh :tangle ~/.zshrc
cd () {
  if   [[ "x$*" == "x..." ]]; then
    cd ../..
  elif [[ "x$*" == "x...." ]]; then
    cd ../../..
  elif [[ "x$*" == "x....." ]]; then
    cd ../../..
  elif [[ "x$*" == "x......" ]]; then
    cd ../../../..
  else
    builtin cd "$@"
  fi
}

function mcd() {
    mkdir -p "$1" && cd "$1";
}
#+end_src
*** Aliases

#+begin_src sh :tangle ~/.zshrc
alias ..='cd ..'
alias cd..='cd ..'
alias cd...='cd ../..'
alias cd....='cd ../../..'
alias cd.....='cd ../../../..'
alias cd/='cd /'

alias 1='cd -'
alias 2='cd +2'
alias 3='cd +3'
alias 4='cd +4'
alias 5='cd +5'
alias 6='cd +6'
alias 7='cd +7'
alias 8='cd +8'
alias 9='cd +9'

alias d='dirs -v | head -10'
#+end_src

** History

*** Variables

#+begin_src sh :tangle ~/.zshrc
HISTFILE=$HOME/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
#+end_src

*** Options

#+begin_src sh :tangle ~/.zshrc
setopt append_history     # Allow multiple terminal sessions to all append to one zsh command history
setopt extended_history   # Include more information about when the command was executed, etc
setopt hist_ignore_dups   # Ignore duplication command history list
setopt hist_reduce_blanks # Remove extra blanks from each command line being added to history
setopt inc_append_history # Add comamnds as they are typed, don't wait until shell exit'
setopt hist_find_no_dups  # When searching history don't display results already cycled through twice'
setopt share_history      # Share command history data
#+end_src

** Terminal

*** dircolors

Configure the color of =ls= directory.

#+begin_src sh :tangle ~/.zshrc
eval `dircolors ~/.dircolors`
#+end_src

*** Aliases

**** Compile/Sources

#+begin_src sh :tangle ~/.zshrc
alias cm='./configure && make'
alias mmi='make && sudo make install'
alias pmmi='perl Makefile.PL && mmi'
alias maek='make'
alias mkae='make'
alias pipr='pip install --no-deps --ignore-installed'
#+end_src

**** Emacs

#+begin_src sh :tangle ~/.zshrc
alias emacs='emacsclient -ca'
alias ec='emacsclient -c'
alias et='emacsclient -t'
alias eamcs='emacs'
alias emcs='emacs'
alias em='emacsclient -n -a ""'
alias es="SUDO_EDITOR=\"emacsclient -t -a emacs\" sudoedit"
alias E='es'
alias magit='et -e "(magit-status \"$(pwd)\")"'
alias top='et -e "(proced)"'
alias efm='et -e "(dired-jump \"$(pwd)\")"'
alias emacs_compile="emacs -batch -f batch-byte-compile"
#+end_src

**** Apps

#+begin_src sh :tangle ~/.zshrc
alias sl="screen -list"  # GNU/Screen
alias wiki='wiki-search' # Archlinux-Wiki
alias rat='ratpoison'    # Ratpoison
alias itmages='itmages-upload' # Picture uploade script for ITmages.ru
alias stinth='printf "#%02X%02X%02X" $(stint)""' # suckless-style color grabber
#+end_src

**** PACMAN/AUR

#+begin_src sh :tangle ~/.zshrc
alias pacman='pacman --color=always'
alias pachist="awk -F' ' /\(starting\|upgraded\|downgraded\|installed\)/'{print \$1,\$2,\$5,\$6,\$7,\$8}' /var/log/pacman.log | sed 's/.*full.*//'"
alias pac_mirror_update='sudo mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup+`date +"%m-%d-%y"`; sudo reflector -l 10 --sort rate --save /etc/pacman.d/mirrorlist'
alias cower='cower --color=always'
alias cowerd='cower --download --force --target=/home/ivo/abs'
alias updates='checkupdates && cower -u'
#+end_src

**** PKGBUILD's

#+begin_src sh :tangle ~/.zshrc
alias mp='makepkg'
alias mpf='makepkg -f'
alias mpsi='makepkg -si'
alias mpg='makepkg -g >> PKGBUILD'
alias mps='makepkg -g >> PKGBUILD && makepkg -f'
alias ms='makepkg --source'
alias msf='makepkg --source -f'
#+end_src

**** Systemd

#+begin_src sh :tangle ~/.zshrc
alias ctl='sudo systemctl'
startd() { ctl start $1.service; ctl status $1.service; }
stopd() { ctl stop $1.service; ctl status $1.service; }
restartd() { ctl restart $1.service; ctl status $1.service; }
statusd() { ctl status $1.service; }
enabled() { ctl enable $1.service; listd; }
disabled() { ctl disable $1.service; listd; }
#+end_src

**** Maintenance

Show logs.

#+begin_src sh :tangle ~/.zshrc
alias journalctl-error='sudo journalctl -b --priority 0..3'
#+end_src

Trashes files.

1. Trash a file
2. Remove all files from the trashcan

#+BEGIN_SRC sh :tangle ~/.zshrc
alias rm='trash-put'
alias trash='trash-empty'
#+END_SRC

**** Auto extension stuff

#+begin_src sh :tangle ~/.zshrc
alias -s {ogg,mp3,wav,wma}="mplayer"
alias -s {avi,mpeg,mpg,mov,m2v,flv}="mplayer"
alias -s {png,gif,jpg,jpeg}="sxiv"
alias -s {doc,pdf}="xpdf"
alias -s {txt,c,h,conf,tex}=$EDITOR
alias -s PKGBUILD=$EDITOR
alias -s {html,php,com,net,org,gov}=$BROWSER
alias -s torrent='transmission-gtk'
#+end_src

**** No/Correct commands

#+begin_src sh :tangle ~/.zshrc
alias man='nocorrect man'
alias mv='nocorrect mv'
alias mysql='nocorrect mysql'
alias mkdir='nocorrect mkdir'
alias sudo='nocorrect sudo'
#+end_src

**** General

#+begin_src sh :tangle ~/.zshrc
alias cp='cp -RPv'
alias la='ls -a'
alias lsa='ls -lah'
alias l='ls -la'
alias ll='ls -l'
alias ls='ls -Xp --color=auto'
alias mk='mkdir -p'
alias mkdir='mk'
alias mv='mv -i'
alias wget='wget -c'
alias history='fc -l 1'
alias h='history'
alias ssh='ssh -X'
alias grep='grep --color=auto'
alias free='free -m'
alias open='xdg-open'
alias c='clear'
alias q='exit'
alias Q='q'
alias t='touch'
alias j='jobs'
#+end_src

**** Mount devices

#+begin_src sh :tangle ~/.zshrc
alias cdmount='sudo mount /dev/sr0 /mnt/cdrom/'
alias usb='sudo mount /dev/sdb1 /mnt/usb'
alias uusb='sudo umount /mnt/usb'
#+end_src

**** Wireless/Network

#+begin_src sh :tangle ~/.zshrc
alias myip='curl ifconfig.me'
alias pi='ping -c 4 archlinux.org'
alias fw='sudo iptables -L'
alias netctl='sudo netctl'
alias netctl-auto='sudo netctl-auto'
alias myserver='python -m SimpleHTTPServer 8000'
alias speedtest='speedtest-cli --simple'
#+end_src

**** Global aliases

#+begin_src sh :tangle ~/.zshrc
alias -g H="| head"
alias -g T="| tail"
alias -g G="| grep"
alias -g L="| less"
alias -g M="| most"
alias -g B="&|"
alias -g H="--help"
alias -g LL="2>&1 | less"
alias -g CA="2>&1 | cat -A"
alias -g NE="2> /dev/null"
alias -g NUL="> /dev/null 2>&1"
#+end_src

*** functions
**** Packing in the archive

#+begin_src sh :tangle ~/.zshrc
pk () {
    if [ $1 ] ; then
        case $1 in
            tbz) tar cjvf $2.tar.bz2 $2 ;;
            tgz) tar czvf $2.tar.gz $2 ;;
            tar) tar cpvf $2.tar $2 ;;
            bz2) bzip $2 ;;
            gz) gzip -c -9 -n $2 > $2.gz ;;
            zip) zip -r $2.zip $2 ;;
            7z) 7z a $2.7z $2 ;;
            *) echo "'$1' cannot be packed via pk()" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}
#+end_src

**** Extract files

#+begin_src sh :tangle ~/.zshrc
extract () {
    if [ -f $1 ] ; then
        case $1 in
            *.tar.bz2) tar xvjf $1 ;;
            *.tar.gz) tar xvzf $1 ;;
            *.bz2) bunzip2 $1 ;;
            *.rar) rar x $1 ;;
            *.gz) gunzip $1 ;;
            *.tar) tar xvf $1 ;;
            *.tbz2) tar xvjf $1 ;;
            *.tgz) tar xvzf $1 ;;
            *.zip) unzip $1 ;;
            *.Z) uncompress $1 ;;
            *.7z) 7z x $1 ;;
            *) echo "don't know how to extract '$1′…" ;;
        esac
     else
        echo "'$1′ is not a valid file!"
     fi
}
#+end_src

**** Remove orphans (Archlinux)

#+begin_src sh :tangle ~/.zshrc
orphans() {
    if [[ ! -n $(pacman -Qdt) ]]; then
        echo no orphans to remove
    else
        sudo pacman -Rs $(pacman -Qdtq)
    fi
}
#+end_src

**** Diff

#+begin_src sh :tangle ~/.zshrc
if command -v colordiff > /dev/null 2>&1; then
    alias diff="colordiff -Nuar"
else
    alias diff="diff -Nuar"
fi
#+end_src

** Profile

*** ENV

#+begin_src sh :tangle ~/.zshrc
export EDITOR="emacs"
export CC="/usr/bin/gcc"
export BROWSER="conkeror"
export HOMEPAGE="https://bbs.archlinux.org/search.php?action=show_new"
export SDL_AUDIODRIVER='alsa'
export GTK2_RC_FILES="$HOME/.gtkrc-2.0"
export XDG_CONFIG_HOME="$HOME/.config"
export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$HOME/bin"
#+end_src

**** Encoding

#+begin_src sh :tangle ~/.zshrc
export LANG="en_US.UTF-8"
export LC_ALL=$LANG
export LC_COLLATE=$LANG
export LC_CTYPE=$LANG
export LC_MESSAGES=$LANG
export LC_MONETARY=$LANG
export LC_NUMERIC=$LANG
export LC_TIME=$LANG
export LC_NAME=$LANG
export LC_TELEPHONE=$LANG
export LESSCHARSET="UTF-8"
#+end_src

** The Prompt

Setting up my zsh prompt.

*** prompt_subst is not set by default.

Turns on command substitution in the prompt (and parameter expansion and arithmetic expansion).

#+BEGIN_SRC sh :tangle ~/.zshrc
setopt prompt_subst
#+END_SRC

*** Load the colors

#+begin_src sh :tangle ~/.zshrc
autoload -U colors && colors
#+end_src

*** Git prompt

#+begin_src sh :tangle ~/.zshrc
function prompt_char {
    git branch >/dev/null 2>/dev/null && echo '±' && return
    hg root >/dev/null 2>/dev/null && echo '☿' && return
    echo '$'
}

function git_branch {
    BRANCH="$(git symbolic-ref HEAD 2>/dev/null | cut -d'/' -f3)"
    if ! test -z $BRANCH; then
        COL="%{$fg[green]%}" # Everything's fine
        [[ $(git log origin/master..HEAD 2> /dev/null ) != "" ]] && COL="%{$fg[red]%}" # We have changes to push
        [[ $(git status --porcelain 2> /dev/null) != "" ]] && COL="%{$fg[yellow]%}" # We have uncommited changes
        echo "%{$fg[green]%}(%{$fg[cyan]%}$(prompt_char) $COL$BRANCH%{$fg[green]%})"
    fi
}
#+end_src

*** Prompt

#+begin_src sh :tangle ~/.zshrc
PROMPT='$(git_branch)%{$fg[green]%}(%~)%{$reset_color%}%# '
RPROMPT="%(?,%{$fg[green]%};%),%{$fg[red]%};()%f"
#RPROMPT="%{$fg[green]%}%T%{$reset_color%}"
SPROMPT="Correct %{$fg[red]%}%R to %{$fg[green]%}%r?%{$reset_color%} ([%{$fg[green]%}Y%{$reset_color%}]es/[%{$fg[red]%}N%{$reset_color%}]o/[%{$fg[yellow]%}E%{$reset_color%}]dit/[%{$fg[red]%}A%{$reset_color%}]bort) "
#+end_src

** Keybindings

*** Use emacs style

#+begin_src sh :tangle ~/.zshrc
bindkey -e
bindkey '\ew' kill-region
bindkey -s '\el' "ls\n"
bindkey '^r' history-incremental-search-backward
bindkey "^[[5~" up-line-or-history
bindkey "^[[6~" down-line-or-history
bindkey '^[[A' up-line-or-search
bindkey '^[[B' down-line-or-search
bindkey "^[[H" beginning-of-line
bindkey "^[[1~" beginning-of-line
bindkey "^[OH" beginning-of-line
bindkey "^[[4~" end-of-line
bindkey "^[OF" end-of-line
bindkey ' ' magic-space
bindkey "^F" forward-word
bindkey "^B" backward-word
bindkey '^[[Z' reverse-menu-complete
bindkey '^?' backward-delete-char
bindkey "^[[3~" delete-char
bindkey "^[3;5~" delete-char
bindkey "\e[3~" delete-char
#+end_src


text:
#+TITLE: fontconfig

This is my =~/.config/fontconfig/fonts.conf= configuration file.

#+BEGIN_SRC xml :tangle ~/.config/fontconfig/fonts.conf :padline no
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

  <match target="font">
    <edit name="rgba" mode="assign"><const>rgb</const></edit>
    <edit name="antialias" mode="assign"><bool>true</bool></edit>
    <edit name="hinting" mode="assign"><bool>true</bool></edit>
    <edit name="hintstyle" mode="assign"><const>hintslight</const></edit>
    <edit name="lcdfilter" mode="assign"><const>lcddefault</const></edit>
  </match>

  <alias>
    <family>serif</family>
    <prefer>
      <family>DejaVu Serif</family>
      <family>Bitstream Vera Serif</family>
      <family>Times New Roman</family>
    </prefer>
  </alias>

  <alias>
    <family>sans-serif</family>
    <prefer>
      <family>DejaVu Sans</family>
      <family>Ubuntu</family>
      <family>Droid Sans</family>
      <family>Helvetica</family>
    </prefer>
  </alias>

  <alias>
    <family>monospace</family>
    <prefer>
      <family>DejaVu Sans Mono</family>
      <family>Inconsolata</family>
      <family>Bitstream Vera Sans Mono</family>
    </prefer>
  </alias>

<!-- Reject bitmap fonts in favour of Truetype, Postscript, etc. -->
 <selectfont>
    <rejectfont>
      <pattern>
        <patelt name="scalable">
          <bool>false</bool>
        </patelt>
      </pattern>
    </rejectfont>
  </selectfont>

<!-- Substitute truetype fonts for bitmap ones -->
 <match target="font">
         <edit name="prefer_outline"><bool>true</bool></edit>
 </match>

<!-- Prevent Gnome from using embedded bitmaps in fonts like Calibri -->
 <match target="font">
	 <edit name="embeddedbitmap" mode="assign"><bool>false</bool></edit>
 </match>

</fontconfig>
#+END_SRC


text:
#+TITLE: List of packages
#+KEYWORDS: archlinux,pacman,packages,aur,git,build,netbook

* Suite of programs used to create my shell working environment on my Archlinux netbook.

** Pacman
- *Administration* abs arch-wiki-lite htop pkgstats pkgfile pkgbuild-introspection reflector
- *Bootloader* syslinux
- *Codecs* gstreamer0.10 gstreamer
- *Development* git python-pip sbcl
- *Display* xorg-server xorg-xinit xorg-utils xorg-server-utils xorg-xfontsel
- *Document/Editor* emacs
- *Driver* xf86-video-intel xf86-input-synaptics
- *Fonts* ttf-dejavu xorg-xlsfonts terminus-font
- *Games* ?
- *Graphics* gimp imagemagick scrot
- *Hardware* dosfstools rfkill wireless_tools
- *Internet* w3m
- *Mail* offlineimap
- *Media* ffmpeg mplayer youtube-dl
- *Plugin* flashplugin
- *Server* openssh
- *Sound* alsa-oss alsa-plugins alsa-utils
- *Terminal* urxvt-perls xterm screen zsh
- *Utilities* acpi lsof moreutils mlocate p7zip unrar unzip zip xclip xdotool xdg-user-dirs xorg-xmessage xorg-xlsfonts
- *Wireless/Network* wget wpa_supplicant

** AUR
- *Administration* kernel-netbook profile-sync-daemon profile-cleaner speedtest-cli
- *Cloud* dropbox dropbox-cli
- *Fonts* ttf-monaco ttf-anonymous-pro
- *Internet* conkeror-git cower-git transmission-gtk2 itmages-upload.git
- *Mail* mu-git
- *Media* mps-youtube-git
- *Pdf* xpdf
- *Terminal* rxvt-unicode-patched urxvt-font-size-git
- *Utilities* stint-git antigen-git trash-cli-git lc-git
- *X11* ratpoison-patched-git

** Custom Build
- *calavera-wm* via *git*

** Emacs Apps

- *Aurel* (Search, vote and download AUR packages from Emacs.) via *melpa*
- *Elfeed* (Emacs web feeds client.) via *melpa*
- *Elscreen* (Emacs window session manager.) via *melpa*
- *Deft* (Quickly browse, filter, and edit plain text notes.) via *melpa*
- *Emms* (The Emacs Multimedia System.) via *melpa*
- *Mu4e* (E-mail client for emacs.) via *manual*
- *Multi-term* (Managing multiple terminal buffers in Emacs.) via *melpa*
- *Xkcd* (Read Xkcd form emacs) via *melpa*

** Depends
- *emacs* (needed for Emacs Apps) via *pacman*
- *python-pafy-git* (needed for mps-youtube-git) via *aur*
- *perl-config-general* (needed for itmages-upload) via *aur*
- *perl-getopt-long-descriptive* (needed for itmages-upload) via *aur*
- *dialog* (needed for the wifi-menu) via *pacman*
- *ghostscript* (needed for emacs/doc-view mode) via *pacman*
- *mu-git* (needed for emacs apps - mu4e) via *aur*
- *yajl* (needed for cower) via *pacman*
- *xulrunner* (needed for conkeror-git) via *pacman*

** Optdepends
- *calavera-wm* (opcional for ratpoison) via *git*


text:
#+TITLE: My color setup for ls

I also have this in another github repo [[https://github.com/ivoarch/dircolors-zenburn][here]] (visit for more info).

#+BEGIN_SRC conf :tangle ~/.dircolors
# Zenburn color theme for the color GNU ls utility.
# Ivaylo Kuzev <ivkuzev@gmail.com>, 2014

# Term Section
TERM Eterm
TERM ansi
TERM color-xterm
TERM con132x25
TERM con132x30
TERM con132x43
TERM con132x60
TERM con80x25
TERM con80x28
TERM con80x30
TERM con80x43
TERM con80x50
TERM con80x60
TERM cons25
TERM console
TERM cygwin
TERM dtterm
TERM eterm-color
TERM gnome
TERM gnome-256color
TERM jfbterm
TERM konsole
TERM kterm
TERM linux
TERM linux-c
TERM mach-color
TERM mlterm
TERM putty
TERM rxvt
TERM rxvt-256color
TERM rxvt-cygwin
TERM rxvt-cygwin-native
TERM rxvt-unicode
TERM rxvt-unicode256
TERM rxvt-unicode-256color
TERM screen
TERM screen-256color
TERM screen-256color-bce
TERM screen-bce
TERM screen-w
TERM screen.linux
TERM vt100
TERM xterm
TERM xterm-16color
TERM xterm-256color
TERM xterm-88color
TERM xterm-color
TERM xterm-debian
TERM xterm-termite

## Documentation
#
# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
#
# Text 256 color coding:
# 38;5;COLOR_NUMBER
# Background 256 color coding:
# 48;5;COLOR_NUMBER

# block device driver:
BLK 48;5;108;38;5;223;01
# file with capability:
CAPABILITY 01;38;5;95
# character device driver:
CHR 48;5;108;38;5;223;01
# directory:
DIR 01;38;5;223
# door:
DOOR 48;5;234;38;5;180;01
# This is for files with execute permission:
EXEC 01;38;5;108
# pipe:
FIFO 48;5;234;38;5;180;01
# regular file:
#FILE 00
# symbolic link:
LINK 48;5;234;38;5;223
# normal (nonfilename) text:
#NORMAL 00
# orphaned symbolic link:
ORPHAN 48;5;234;38;5;187
# directory that is other-writable (o+w) and not sticky:
OTHER_WRITABLE 48;5;234;38;5;180
# file that is setuid (u+s):
SETUID 48;5;234;38;5;66
# file that is setgid (g+s):
SETGID 48;5;234;38;5;66
# socket:
SOCK 48;5;234;38;5;180;01
# directory with the sticky bit set (+t) and not other-writable:
STICKY 48;5;180;38;5;234
# dir that is sticky and other-writable (+t,o+w):
STICKY_OTHER_WRITABLE 48;5;180;38;5;234

# archives
.7z 01;38;5;174
.arj 01;38;5;174
.bz2 01;38;5;174
.bz 01;38;5;174
.gz 01;38;5;174
.rar 01;38;5;174
.tar 01;38;5;174
.tgz 01;38;5;174
.tbz 01;38;5;174
.tbz2 01;38;5;174
.xz 01;38;5;174
.zip 01;38;5;174

# packaged apps
.apk 01;38;5;95
.deb 01;38;5;174
.jad 01;38;5;95
.jar 01;38;5;95
.rpm 01;38;5;174

# images|graphics
.bmp 00;38;5;109
.gif 00;38;5;109
.ico 00;38;5;109
.jpg 00;38;5;109
.JPG 00;38;5;109
.jpeg 00;38;5;109
.png 00;38;5;109
.svg 00;38;5;109
.xbm 00;38;5;109
.xpm 00;38;5;109

# audio formats
.aac 00;38;5;116
.au 00;38;5;116
.flac 00;38;5;116
.mid 00;38;5;116
.midi 00;38;5;116
.mka 00;38;5;116
.mp3 00;38;5;116
.mpc 00;38;5;116
.ogg 00;38;5;116
.ra 00;38;5;116
.wav 00;38;5;116

# video formats
.mov 00;38;5;66
.mpg 00;38;5;66
.mpeg 00;38;5;66
.m2v 00;38;5;66
.mkv 00;38;5;66
.ogm 00;38;5;66
.mp4 00;38;5;66
.m4v 00;38;5;66
.mp4v 00;38;5;66
.vob 00;38;5;66
.qt 00;38;5;66
.nuv 00;38;5;66
.wmv 00;38;5;66
.asf 00;38;5;66
.rm 00;38;5;66
.rmvb 01;38;5;66
.flc 00;38;5;66
.avi 00;38;5;66
.fli 00;38;5;66
.flv 00;38;5;66
.gl 00;38;5;66
.m2ts 00;38;5;66
.divx 00;38;5;66
.webm 00;38;5;66

# shell
.awk 00;38;5;151
.bash 00;38;5;151
.bat 00;38;5;151
.BAT 00;38;5;151
.sed 00;38;5;151
.sh 00;38;5;151
.zsh 00;38;5;151

# build
*CMakeLists.txt 00;38;5;187
.cabal 00;38;5;187
*Makefile 00;38;5;187
.mk 00;38;5;187
.make 00;38;5;187

# source files
.c 01;38;5;187
.h 01;38;5;187
.s 01;38;5;187
.cs 01;38;5;187
.java 01;38;5;187
.scala 01;38;5;187
.hs 01;38;5;187
.py 01;38;5;187
.rb 01;38;5;187
.php 01;38;5;187
.pl 01;38;5;187
.vim 01;38;5;187
.js 01;38;5;187
.coffee 01;38;5;187
.go 01;38;5;187
.lisp 01;38;5;187
.scm 01;38;5;187

# documents
.txt 04;38;5;188
.tex 04;38;5;188
.html 04;38;5;188
.xhtml 04;38;5;188
.xml 04;38;5;188
.md 04;38;5;188
.mkd 04;38;5;188
.markdown 04;38;5;188
.org 04;38;5;188
.pandoc 04;38;5;188
.pdc 04;38;5;188
.pdf 04;38;5;188

# meta
*README 04;38;5;187
*LICENSE 04;38;5;187
*AUTHORS 04;38;5;187

# version control
.gitignore 00;38;5;248
.gitmodules 00;38;5;248

# logs and backups
.log 00;38;5;234
.bak 00;38;5;234
.aux 00;38;5;234
.toc 00;38;5;234
*~ 00;38;5;234
*# 00;38;5;234
.swp 00;38;5;234
.tmp 00;38;5;234
.temp 00;38;5;234
.o 00;38;5;234
.pyc 00;38;5;234
.class 00;38;5;234
.cache 00;38;5;234

# pacman files
.pacnew 48;5;95;38;5;108
.pacsave 48;5;95;38;5;108
.pacorig 48;5;95;38;5;108
*PKGBUILD 00;38;5;110
#+END_SRC


text:
#+TITLE: Stumpwm configuration

** Header.

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
;; -*- Mode:p Lisp -*-
;;; .stumpwmrc --- StumpWM Init File
#+END_SRC

** Code.

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(in-package :stumpwm)
#+END_SRC

** Set Contrib Dir.

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(set-contrib-dir "/home/ivo/.stumpwm-contrib/")
#+END_SRC

** Disable "Welcome!" message.

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(setf *startup-message* nil)
#+END_SRC

** Configure Swank.

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(load "~/.emacs.d/elpa/slime-20140420.33/swank-loader.lisp")
(swank-loader:init)
(defcommand swank () ()
  "Creates a swank server in the stumpwm lisp process"
  (setf stumpwm:*top-level-error-action* :break)
  (swank:create-server :port 4005
           :style swank:*communication-style*
           :dont-close t)
(echo-string (current-screen)
         "Starting swank. M-x slime-connect RET RET, then (in-package stumpwm)."))
#+END_SRC

** Modeline setup.

*** Default timeout

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(setf *mode-line-timeout* 1)
#+END_SRC

*** Start modeline

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(if (not (head-mode-line (current-head)))
    (toggle-mode-line (current-screen) (current-head)))
#+END_SRC

*** BG time

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(defun pretty-time ()
  "Returns the date formatted as '17:19:51 Неделя, 27 Април 2014'."
  (defun stringify-dow (dow)
    (nth dow '("Понеделник" "Вторник" "Сряда" "Четвъртък" "Петъk" "Събота" "Неделя")))
  (defun stringify-mon (mon)
    (nth (- mon 1) '("Януари" "Февруари" "Март" "Април"
                     "Май" "Юни" "Юли" "Август"
                     "Септември" "Октомври" "Ноември" "Декември")))
(multiple-value-bind (sec min hr date mon yr dow dst-p tz)
      (get-decoded-time)
    (format NIL "~2,'0d:~2,'0d:~2,'0d ~a, ~d ~a ~d (GMT ~@d)"
            hr min sec
            (stringify-dow dow)
            date (stringify-mon mon)
             yr (- tz))))
#+END_SRC

*** Modeline format

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(setf *screen-mode-line-format*
      (list "[^B%n^b] %W " ; groups/windows
            "^>" ; right align
            " ^7* " '(:eval (pretty-time)); date
            ))
#+END_SRC

** Defaults.

Set the font for the message bar and input bar.

1. Load module for xft fonts.
2. Set xft font.

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(load-module "ttf-fonts")
(set-font (make-instance 'xft:font :family "Anonymous Pro" :subfamily "Regular" :size 13))
#+END_SRC

Group/window format

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(setf *group-format* "%s [%n] %t ")
(setf *window-format* "%m%n%s%c")
#+END_SRC

Window gravity

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(setf *message-window-gravity* :top-right)
(setf *input-window-gravity* :top-right)
#+END_SRC

Ignore size hints

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(setq *ignore-wm-inc-hints* t)
#+END_SRC

Default border style

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(setq *window-border-style* :thin)
#+END_SRC

I like 3 seconds for messages.

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(setf *timeout-wait* 5)
#+END_SRC

Mouse focus by click.

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(setf *mouse-focus-policy* :click)
#+END_SRC

Create groups

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(setf (group-name (first (screen-groups (current-screen)))) "Default")
(gnewbg-float "Float")
#+END_SRC

Shell program used by =run-shell-command=

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(setq *shell-program* (stumpwm::getenv "SHELL"))
#+END_SRC

** Commands.

1. run-or-raise - emacs
2. run-or-raise - conkeror
3. run-or-raise - urxvt/screen
4. show dropbox status
5. toggle =on=|=off= modeline

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(defcommand emacs () ()
  "run-or-raise emacs"
  (run-or-raise "emacsclient -ca emacs" '(:class "Emacs")))
(define-key *root-map* (kbd "e") "emacs")

(defcommand browser () ()
  "run or raise conkeror"
  (run-or-raise "conkeror" '(:class "Conkeror")))
(define-key *root-map* (kbd "w") "browser")

(defcommand terminal () ()
  "run or raise urxvt"
  (run-or-raise "urxvt -e screen" '(:class "URxvt")))
(define-key *root-map* (kbd "c") "terminal")

(defcommand dropbox-status () ()
  (run-shell-command "dropbox status"))

(defcommand mode-line-toggle () ()
  "Toggles the mode-line"
  (toggle-mode-line (current-screen) (current-head)))
(define-key *top-map* (kbd "M-m") "mode-line-toggle")
#+END_SRC

** Keys.

*** Multimedia keys

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(define-key *top-map* (kbd "XF86AudioLowerVolume") "exec amixer set Master 5%-")
(define-key *top-map* (kbd "XF86AudioRaiseVolume") "exec amixer set Master 5%+")
(define-key *top-map* (kbd "XF86AudioMute") "exec amixer set Master toggle")
#+END_SRC

*** Windows/Frames

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(define-key *root-map* (kbd "o") "only")
(define-key *root-map* (kbd "z") "windows")

(define-key *root-map* (kbd "C-Up") "move-window up")
(define-key *root-map* (kbd "C-Left") "move-window left")
(define-key *root-map* (kbd "C-Down") "move-window down")
(define-key *root-map* (kbd "C-Right") "move-window right")
#+END_SRC

Screenshot of the screen =using PrtSc=

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(define-key *top-map* (kbd "Print")
  "exec import -window root png:$HOME/Pictures/Screenshots/stumpwm-$(date +%s)$$.png")
#+END_SRC

** Start Commands.

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
(terminal)
(browser)
#+END_SRC

** Stumpwmrc ends here.

#+BEGIN_SRC lisp :tangle ~/.stumpwmrc
;; Local Variables:
;; coding: utf-8
;; mode: lisp
;; End:

;;; stumpwmrc ends here
#+END_SRC


text:
#+TITLE: MPlayer configuration file

** Video
#+BEGIN_SRC conf :tangle ~/.mplayer/config :mkdirp true
vo=xv
dvd-device=/dev/sr0
#+END_SRC

** Audio
#+BEGIN_SRC conf :tangle ~/.mplayer/config :mkdirp true
ao=pulse,alsa
mixer-channel="Master"
#+END_SRC

** Fullscreen
#+BEGIN_SRC conf :tangle ~/.mplayer/config :mkdirp true
fs=yes
#+END_SRC

** Buffer
#+BEGIN_SRC conf :tangle ~/.mplayer/config :mkdirp true
nocache=1
#+END_SRC

** Display and subtitles
#+BEGIN_SRC conf :tangle ~/.mplayer/config :mkdirp true
double="yes"
alang =bg,en,eng,english
slang =bg,en,eng,english
subcp =cp1251
framedrop="0"
monitoraspect=16:9 # 16:9 or 4:3
#+END_SRC

** Disable mouse
#+BEGIN_SRC conf :tangle ~/.mplayer/config :mkdirp true
mouse-movements=no
nomouseinput=yes
#+END_SRC

** Colorized terminal output
#+BEGIN_SRC conf :tangle ~/.mplayer/config :mkdirp true
msgmodule=1
msgcolor=1
#+END_SRC


text:
#!/bin/sh

function clone_repo() {
DOT_ORG_DIR=$HOME/.dot-org-files

if [ -e $DOT_ORG_DIR ] ; then
    echo "Updating .dot-org-files..."
    cd $DOT_ORG_DIR
    git pull
else
    echo "Cloning .dot-org-files..."
    git clone https://github.com/ivoarch/.dot-org-files.git $DOT_ORG_DIR
    cd $DOT_ORG_DIR
fi
}

#function install_deps() {
#    echo "Installing depends..."
#    makepkg --syncdeps --clean
#    rm -rf .dot-org-files
#}

function tangle_files() {
    echo "Tangle config files with org-mode..."
    DIR=`pwd`
    FILES=""

    # wrap each argument in the code required to call tangle on it
    #for i in $@; do
    for i in `ls | grep \.org`; do
        FILES="$FILES \"$i\""
    done

    emacs -Q --batch \
        --eval \
        "(progn
        (require 'org)(require 'ob)(require 'ob-tangle)
        (mapc (lambda (file)
        (find-file (expand-file-name file \"$DIR\"))
        (org-babel-tangle)
        (kill-buffer)) '($FILES)))"
    #2>&1 | grep Tangled
}

# Clone repo
clone_repo

# Install depends
#install_deps

# tangle config files
tangle_files

exit 0


text:
#+TITLE: My dot-org-files

* Table of Contents 																										:TOC:
 - [[#about][About]]
 - [[#org-files][Org files]]
 - [[#installation][Installation]]
     - [[#automated][Automated]]
     - [[#manual][Manual]]
 - [[#license][License]]

* About

Dotfiles, Emacs + Org-mode with babel and Literate programming.

* Org files

[[https://github.com/ivoarch/.dot-org-files/blob/master/packages.org][packages.org]]
- List of packages.

[[https://github.com/ivoarch/.dot-org-files/blob/master/todo.org][todo.org]]
- Tasks with unclassified time period.

[[https://github.com/ivoarch/.dot-org-files/blob/master/gtk.org][gtk.org]]
- My configuration file for Gtk.

[[https://github.com/ivoarch/.dot-org-files/blob/master/Xresources.org][Xresources.org]]
- Settings for multiple X programs.

[[https://github.com/ivoarch/.dot-org-files/blob/master/dircolors.org][dircolors.org]]
- My color setup for ls.

[[https://github.com/ivoarch/.dot-org-files/blob/master/fontconfig.org][fontconfig]]
- Fonts setup.

[[https://github.com/ivoarch/.dot-org-files/blob/master/xinitrc.org][xinitrc.org]]
- X initialization script.

[[https://github.com/ivoarch/.dot-org-files/blob/master/ratpoison.org][ratpoison.org]]
- Window manager configuration file.

[[https://github.com/ivoarch/.dot-org-files/blob/master/emacs.org][emacs.org]]
- My emacs setup.

[[https://github.com/ivoarch/.dot-org-files/blob/master/screen.org][screen.org]]
- Gnu Screen RC configuration file.

[[https://github.com/ivoarch/.dot-org-files/blob/master/zsh.org][zsh.org]]
- Shell configuration file.

[[https://github.com/ivoarch/.dot-org-files/blob/master/conkeror.org][conkeror.org]]
- Browser configuration file.

[[https://github.com/ivoarch/.dot-org-files/blob/master/mplayer.org][mplayer.org]]
- MPlayer configuration file.

[[https://github.com/ivoarch/.dot-org-files/blob/master/stumpwm.org][stumpwm.org]]
- StumpWM configuration file.

* Installation

** Automated

If you're using curl type the following command:

#+BEGIN_SRC sh
curl -L https://github.com/ivoarch/.dot-org-files/raw/master/install.sh | sh
#+END_SRC

** Manual

- Clone this repo:

#+BEGIN_SRC sh
~$ cd $HOME
~$ git clone https://github.com/ivoarch/.dot-org-files
#+END_SRC

- Tangle config files:

=C-c C-v f= or =M-x org-babel-tangle-file=

* License

- Unlicense - http://unlicense.org/


text:
# $Id: pkgbuild-mode.el,v 1.23 2007/10/20 16:02:14 juergen Exp $
# Maintainer: <ivo@arch>
pkgname=dot-org-files
pkgver=fe3ffc5
pkgrel=1
epoch=
pkgdesc="A package to set up my archlinux working environment"
arch=('i686')
url="https://github.com/ivoarch/.dot-org-files"
license=('UNLICENSE')
groups=()
depends=("abs"
   "arch-wiki-lite"
   "htop"
   "pkgstats"
   "pkgfile"
   "reflector"
   "gstreamer0.10"
   "gstreamer"
   "git"
   "python-pip"
   "sbcl"
   "sxiv"
   "xorg-server"
   "xorg-xinit"
   "xorg-utils"
   "xorg-server-utils"
   "xorg-xfontsel"
   "xorg-xlsfonts"
   "emacs"
   "xf86-video-intel"
   "xf86-input-synaptics"
   "ttf-dejavu"
   "xorg-xlsfonts"
   "terminus-font"
   "imagemagick"
   "scrot"
   "wireless_tools"
   "dosfstools"
   "rfkill"
   "w3m"
   "offlineimap"
   "ffmpeg"
   "mplayer"
   "youtube-dl"
   "flashplugin"
   "openssh"
   "alsa-oss"
   "alsa-plugins"
   "alsa-utils"
   "urxvt-perls"
   "xterm"
   "screen"
   "zsh"
   "acpi"
   "lsof"
   "moreutils"
   "mlocate"
   "p7zip"
   "unrar"
   "unzip"
   "zip"
   "xclip"
   "xdotool"
   "xdg-user-dirs"
   "xorg-xmessage"
   "wget"
   "wpa_supplicant"
   "ghostscript"
   "dialog"
   "xulrunner"
   "yajl"
   "pkgbuild-introspection"
# warning:
# Pacman can not resolve dependencies only found in the AUR for you.
# Look at using an AUR helper to automatically install dependencies from the AUR.
#
# From the AUR:
#  "kernel-netbook"
#  "profile-sync-daemon"
#  "profile-cleaner"
#  "speedtest-cli"
#  "dropbox"
#  "dropbox-cli"
#  "conkeror-git"
#  "cower-git"
#  "transmission-gtk2"
#  "itmages-upload.git"
#  "mu-git"
#  "stint-git"
#  "trash-cli-git"
#  "python-pafy-git"
#  "ttf-monaco"
#  "ttf-anonymous-pro"
#  "mps-youtube-git"
#  "antigen-git"
#  "ratpoison-patched-git"
#  "perl-config-general"
#  "perl-getopt-long-descriptive"
#  "lc-git"
#  "xpdf"
#  "urxvt-font-size-git"
#  "rxvt-unicode-patched"
)
makedepends=('git')
checkdepends=()
optdepends=()
provides=()
conflicts=()
replaces=()
backup=()
options=()
install=
changelog=
noextract=()
source=("git+https://github.com/ivoarch/.dot-org-files.git")
md5sums=('SKIP')

gitname=".dot-org-files"

pkgver() {
  cd $srcdir/$gitname
  git describe --always | sed 's|-|.|g'
}

package() {
  cd $srcdir/$gitname
  exit
}

# vim:set ts=2 sw=2 et: