Commits

Fuco  committed af13872

Add new files

  • Participants
  • Parent commits b65bb3a

Comments (0)

Files changed (8)

File files/eshell-defs.el

+;;;; git config
+(defun my--get-git-branches (&optional all)
+  (let ((branches (-map 'car (magit-list-interesting-refs))))
+    (if all
+        branches
+      (--filter (not (string-match-p "/" it)) branches))))
+
+(defun pcomplete/eshell-mode/gc ()
+  (pcomplete-here (my--get-git-branches)))
+
+(defun pcomplete/eshell-mode/git ()
+  (pcomplete-here '("add"
+                    "bisect"
+                    "branch"
+                    "checkout"
+                    "clone"
+                    "commit"
+                    "diff"
+                    "fetch"
+                    "grep"
+                    "init"
+                    "log"
+                    "merge"
+                    "mv"
+                    "pull"
+                    "push"
+                    "rebase"
+                    "remote"
+                    "reset"
+                    "rm"
+                    "show"
+                    "status"
+                    "tag"))
+  (pcomplete-here
+   (let ((last-cmd (nth (1- pcomplete-last) pcomplete-args)))
+     (cond
+      ((equal "checkout" last-cmd)
+       (my--get-git-branches))
+      ((equal "add" last-cmd)
+       (pcomplete-entries))
+      ((equal "merge" last-cmd)
+       (my--get-git-branches t))))))
+
+;;;; hg config
+(defun pcomplete/eshell-mode/hg ()
+  (pcomplete-here '("add"
+                    "annotate"
+                    "clone"
+                    "commit"
+                    "diff"
+                    "export"
+                    "forget"
+                    "init"
+                    "log"
+                    "merge"
+                    "pull"
+                    "push"
+                    "remove"
+                    "serve"
+                    "status"
+                    "summary"
+                    "update")))

File files/ibuffer-defs.el

+(bind-key "M-o" 'elwm-activate-window ibuffer-mode-map)
+
+;; filter groups
+(setq ibuffer-saved-filter-groups
+      (quote (("default"
+               ("Org" ;; all org-related buffers
+                (mode . org-mode))
+               ("emacs-elpa"
+                (or (predicate
+                     .
+                     (let ((bfn (buffer-file-name (current-buffer))))
+                       (when bfn
+                         (and (string-match-p "\\.emacs\\.d/elpa" bfn)
+                              (eq major-mode 'emacs-lisp-mode)))))))
+               ("emacs-config"
+                (or (predicate
+                     .
+                     (let ((bfn (buffer-file-name (current-buffer))))
+                       (when bfn
+                         (and (string-match-p "\\.emacs\\.d" bfn)
+                              (eq major-mode 'emacs-lisp-mode)))))))
+               ("emacs"
+                (or (mode . emacs-lisp-mode)
+                    (mode . lisp-interaction-mode)
+                    (mode . inferior-emacs-lisp-mode)))
+               ("TeX"
+                (or (mode . tex-mode)
+                    (mode . plain-tex-mode)
+                    (mode . latex-mode)))
+               ("Markdown" (or (mode . markdown-mode)
+                               (mode . gfm-mode)))
+               ("Web"
+                (or (mode . html-mode)
+                    (mode . css-mode)
+                    (mode . php-mode)
+                    (mode . js-mode)))
+               ("Dired"
+                (mode . dired-mode))
+               ("Langs"
+                (or (predicate
+                     .
+                     (let ((bfn (buffer-file-name (current-buffer))))
+                       (when bfn
+                         (string-match-p "d:/languages" bfn))))))
+               ("Images"
+                (or (mode . image-dired-display-image-mode)
+                    (mode . image-dired-thumbnail-mode)
+                    (mode . image-mode)))
+               ("Tramp"
+                (or (name . "tramp")))
+               ("Programming" ;; prog stuff not already in MyProjectX
+                (or
+                 (mode . c-mode)
+                 (mode . cc-mode)
+                 (mode . c++-mode)
+                 (mode . perl-mode)
+                 (mode . python-mode)
+                 (mode . haskell-mode)
+                 ;; etc
+                 ))
+               ("IRC"
+                (or (mode . erc-mode)
+                    (mode . rcirc-mode)))
+               ("Search"
+                (or (mode . ag-mode)))
+               ))))
+
+;; (define-ibuffer-filter in-directory
+;;   "Toggle current view to buffers whose default-directory is in QUALIFIER."
+;;   (:description "in-directory"
+;;    :reader (read-directory-name "Directory: "))
+;;   (with-current-buffer buf (file-in-directory-p default-directory qualifier)))
+
+(define-ibuffer-column size-h
+  (:name "Size"
+         :inline t
+         :summarizer
+         (lambda (column-strings)
+           (let ((total 0))
+             (dolist (string column-strings)
+               (setq total
+                     ;; like, ewww ...
+                     (+
+                      (let ((number (float (string-to-number string))))
+                        (cond
+                         ((string-match-p "K" string)
+                          (* number 1000))
+                         ((string-match-p "M" string)
+                          (* number 1000000))
+                         (t number)))
+                      total)))
+             (file-size-human-readable total 'si))))
+  (file-size-human-readable (buffer-size) 'si))
+
+;; Modify the default ibuffer-formats
+(setq ibuffer-formats
+      '((mark modified vc-status-mini read-only
+              " " (name 25 25 :left :elide)
+              " " (size-h 9 -1 :right)
+              " " (mode 16 16 :left :elide)
+
+              " " filename-and-process)
+        (mark " " (name 16 -1)
+              " " filename)))
+
+;; Switching to ibuffer puts the cursor on the most recent buffer
+(defadvice ibuffer (around ibuffer-point-to-most-recent activate) ()
+  "Open ibuffer with cursor pointed to most recent buffer name"
+  (let ((recent-buffer-name (buffer-name)))
+    ad-do-it
+    (ibuffer-jump-to-buffer recent-buffer-name)))

File files/ido-defs.el

+(use-package flx-ido
+  :defer t)
+
+;; Display ido results vertically, rather than horizontally
+(setq ido-decorations (quote ("\n-> " "" "\n   " "\n   ..." "[" "]" " [No match]" " [Matched]" " [Not readable]" " [Too big]" " [Confirm]")))
+(defun ido-disable-line-trucation () (set (make-local-variable 'truncate-lines) nil))
+(add-hook 'ido-minibuffer-setup-hook 'ido-disable-line-trucation)
+
+;; see: http://emacswiki.org/emacs/InteractivelyDoThings#toc25
+(defun ido-smart-select-text ()
+  "Select the current completed item.  Do NOT descend into directories."
+  (interactive)
+  (when (and (or (not ido-require-match)
+                 (if (memq ido-require-match
+                           '(confirm confirm-after-completion))
+                     (if (or (eq ido-cur-item 'dir)
+                             (eq last-command this-command))
+                         t
+                       (setq ido-show-confirm-message t)
+                       nil))
+                 (ido-existing-item-p))
+             (not ido-incomplete-regexp))
+    (when ido-current-directory
+      (setq ido-exit 'takeprompt)
+      (unless (and ido-text (= 0 (length ido-text)))
+        (let ((match (ido-name (car ido-matches))))
+          (throw 'ido
+                 (setq ido-selected
+                       (if match
+                           (replace-regexp-in-string "/\\'" "" match)
+                         ido-text)
+                       ido-text ido-selected
+                       ido-final-text ido-text)))))
+    (exit-minibuffer)))
+
+(defun my-ido-keys ()
+  (bind-key "C-<tab>" 'ido-smart-select-text ido-file-dir-completion-map))
+
+(add-hook 'ido-setup-hook 'my-ido-keys)
+
+;; ido and imenu integration
+(defun ido-goto-symbol (&optional symbol-list)
+  "Refresh imenu and jump to a place in the buffer using Ido."
+  (interactive)
+  (unless (featurep 'imenu)
+    (require 'imenu nil t))
+  (cond
+   ((not symbol-list)
+    (let ((ido-mode ido-mode)
+          (ido-enable-flex-matching
+           (if (boundp 'ido-enable-flex-matching)
+               ido-enable-flex-matching t))
+          name-and-pos symbol-names position)
+      (unless ido-mode
+        (ido-mode 1)
+        (setq ido-enable-flex-matching t))
+      (while (progn
+               (imenu--cleanup)
+               (setq imenu--index-alist nil)
+               (ido-goto-symbol (imenu--make-index-alist))
+               (setq selected-symbol
+                     (ido-completing-read "Symbol? " symbol-names))
+               (string= (car imenu--rescan-item) selected-symbol)))
+      (unless (and (boundp 'mark-active) mark-active)
+        (push-mark nil t nil))
+      (setq position (cdr (assoc selected-symbol name-and-pos)))
+      (cond
+       ((overlayp position)
+        (goto-char (overlay-start position)))
+       (t
+        (goto-char position)))))
+   ((listp symbol-list)
+    (dolist (symbol symbol-list)
+      (let (name position)
+        (cond
+         ((and (listp symbol) (imenu--subalist-p symbol))
+          (ido-goto-symbol symbol))
+         ((listp symbol)
+          (setq name (car symbol))
+          (setq position (cdr symbol)))
+         ((stringp symbol)
+          (setq name symbol)
+          (setq position
+                (get-text-property 1 'org-imenu-marker symbol))))
+        (unless (or (null position) (null name)
+                    (string= (car imenu--rescan-item) name))
+          (setq word-under-cursor (thing-at-point 'symbol))
+          (setq fix-the-order (not (null (member word-under-cursor symbol-names))))
+          (add-to-list 'symbol-names name)
+          (when fix-the-order
+            (delete word-under-cursor symbol-names)
+            (add-to-list 'symbol-names word-under-cursor))
+          (add-to-list 'name-and-pos (cons name position))))))))
+
+;; sort ido filelist by mtime instead of alphabetically
+(defun ido-sort-mtime ()
+  (setq ido-temp-list
+        (sort ido-temp-list
+              (lambda (a b)
+                (time-less-p
+                 (sixth (file-attributes (concat ido-current-directory b)))
+                 (sixth (file-attributes (concat ido-current-directory a)))))))
+  (ido-to-end  ;; move . files to end (again)
+   (--select (char-equal (string-to-char it) ?.) ido-temp-list))
+  (when ido-show-dot-for-dired
+    (setq ido-temp-list
+          (cons "." (--remove (equal it ".") ido-temp-list)))))
+
+(add-hook 'ido-make-file-list-hook 'ido-sort-mtime)
+(add-hook 'ido-make-dir-list-hook 'ido-sort-mtime)

File files/isearch-defs.el

+(use-package flex-isearch
+  :defer t
+  :load-path "~/.emacs.d/vendor/flex-isearch/"
+  :config
+  (progn
+    (defadvice isearch-forward-regexp (around flex-isearch activate)
+      (when (and flex-isearch-mode
+                 (equal (ad-get-arg 0) '(16)))
+        (flex-isearch-activate)
+        (ad-set-arg 0 '(4)))
+      ad-do-it)
+
+    (defadvice isearch-backward-regexp (around flex-isearch activate)
+      (when (and flex-isearch-mode
+                 (equal (ad-get-arg 0) '(16)))
+        (flex-isearch-activate)
+        (ad-set-arg 0 '(4)))
+      ad-do-it)))
+
+(defun my-isearch-forward ()
+  "Repeat the forward search.
+
+If called from backward search, immediately jump to the following
+occurance instead of jumping to the end of current one."
+  (interactive)
+  (when (not isearch-forward)
+    (isearch-repeat 'forward))
+  (isearch-repeat 'forward))
+
+(defun my-isearch-backward ()
+  "Repeat the backward search.
+
+If called from forward search, immediately jump to the previous
+occurance instead of jumping to the beginning of current one."
+  (interactive)
+  (when (and isearch-forward
+             (/= (point) isearch-other-end))
+    (isearch-repeat 'backward))
+  (isearch-repeat 'backward))
+
+(defun my-isearch-forward-to-beginning ()
+  "Repeat the forward search and place the point before the
+matched text."
+  (interactive)
+  (when (not isearch-forward)
+    (isearch-repeat 'forward))
+  (isearch-repeat 'forward)
+  (goto-char isearch-other-end))
+
+(defun my-isearch-kill-match ()
+  "Kill the text last matched by isearch."
+  (interactive)
+  (isearch-exit)
+  (kill-region (point) isearch-other-end))
+
+(defun my-isearch-zap-to-match ()
+  "Kill the region between the point of origin of isearch and the
+closest portion of the isearch match string.  The behaviour is
+meant to be analogous to zap-to-char.  The deleted region does
+not include the isearch word.  This is meant to be bound only in
+isearch mode."
+  (interactive)
+  (let* ((isearch-bounds (list isearch-other-end (point)))
+         (ismin (apply 'min isearch-bounds))
+         (ismax (apply 'max isearch-bounds))
+         (beg isearch-opoint))
+    (cond
+     ((< beg ismin)
+      (goto-char ismin)
+      (kill-region beg ismin))
+     ((> beg ismax)
+      (goto-char beg)
+      (kill-region ismax beg))
+     (t
+      (error "Internal error in isearch kill function.")))
+    (isearch-exit)))
+
+(defun my-isearch-exit-other-end ()
+  "Exit isearch, but at the other end of the search string.
+This is useful when followed by an immediate kill."
+  (interactive)
+  (isearch-exit)
+  (goto-char isearch-other-end))
+
+(defun my-isearch-yank-symbol ()
+  "Pull next symbol from buffer into search string."
+  (interactive)
+  (isearch-yank-internal (lambda () (sp-forward-symbol) (point))))
+
+(defun my-isearch-exit ()
+  "Exit search normally.
+
+If in dired buffer, find file under cursor.  If it is a
+directory, go right back into search."
+  (interactive)
+  (isearch-exit)
+  (if (eq major-mode 'dired-mode)
+      ;; we're assuming no files are marked
+      (let ((d (car (dired-get-marked-files))))
+        (dired-find-file)
+        (when (file-directory-p d)
+          (dired-isearch-filenames)))))
+
+;; keybindings
+(bind-key "<f6>" 'replace-regexp)
+
+(bind-key "C-v" 'my-isearch-forward-to-beginning isearch-mode-map)
+(bind-key "C-r" 'my-isearch-backward             isearch-mode-map)
+(bind-key "C-s" 'my-isearch-forward              isearch-mode-map)
+(bind-key "C-2" 'my-isearch-kill-match           isearch-mode-map)
+(bind-key "C-3" 'my-isearch-exit-other-end       isearch-mode-map)
+(bind-key "C-w" 'my-isearch-yank-symbol          isearch-mode-map)
+(bind-key "C-M-w" 'isearch-yank-word-or-char     isearch-mode-map)
+(bind-key "M-z" 'my-isearch-zap-to-match         isearch-mode-map)
+(bind-key "<f2>" 'isearch-occur                  isearch-mode-map)
+(bind-key "\r" 'my-isearch-exit                  isearch-mode-map)
+
+(bind-key "C-S-s" 'flex-isearch-forward)
+(bind-key "C-S-r" 'flex-isearch-backward)

File files/latex-defs.el

+(use-package latex
+  :defer t
+  :config
+  (progn
+    (use-package reftex
+      :defer t
+      :diminish reftex-mode)
+    ;; fix the "bug" in SP regexp wrap that treats ' as "word"
+    (modify-syntax-entry ?' ".")
+
+    (require 'smartparens-latex)
+    (sp-local-pair 'latex-mode "\\begin" "\\end")
+    (sp-local-tag 'latex-mode "\\ba" "\\begin{align*}" "\\end{align*}")
+
+    (use-package preview)
+    (use-package font-latex)
+    (fset 'tex-font-lock-suscript 'ignore)
+
+    (sp-with-modes '(tex-mode plain-tex-mode latex-mode)
+      (sp-local-pair "\\[" nil :post-handlers '(my-latex-math-block-indent)))
+
+    (defun my-latex-math-block-indent (a action c)
+      (when (eq action 'insert)
+        (newline-and-indent)
+        (save-excursion (newline))))
+
+    (defun my-latex-compile ()
+      (interactive)
+      (save-buffer)
+      (TeX-command "LaTeX" 'TeX-master-file nil))
+    (bind-key "C-M-x" 'my-latex-compile LaTeX-mode-map)
+
+    (defvar my-latex-wrap-choices '("emph"
+                                    "textsc"))
+    (defvar my-latex-wrap-history nil)
+
+    (defun my-latex-wrap (macro-name)
+      (interactive (list (ido-completing-read
+                          "Macro> "
+                          my-latex-wrap-choices
+                          nil 'confirm nil my-latex-wrap-history)))
+      (when (use-region-p)
+        (let ((b (region-beginning))
+              (e (region-end)))
+          (goto-char e)
+          (insert "}")
+          (goto-char b)
+          (insert "\\" macro-name "{"))))
+    (bind-key "C-c w" 'my-latex-wrap LaTeX-mode-map)
+
+    (defun my-end-of-environment ()
+      (interactive)
+      (LaTeX-mark-environment)
+      (end-of-region))
+
+    (defun my-beginning-of-environment ()
+      (interactive)
+      (LaTeX-mark-environment)
+      (beginning-of-region)
+      (deactivate-mark))
+
+    (bind-key "M-n" 'my-end-of-environment LaTeX-mode-map)
+    (bind-key "M-p" 'my-beginning-of-environment LaTeX-mode-map)
+
+    ;; fix italian quote highlight
+    (push '("\"<" "\">") font-latex-quote-list)
+
+    (defun my-latex-remove-command ()
+      "Unwrap the expression that point is in or before, also
+removing the command name.  By command we understand a symbol
+starting with \\ and followed by a block of text enclosed in {}."
+      (interactive)
+      (let ((ok (sp-get-enclosing-sexp)))
+        (cond
+         ;; we're inside the { } block
+         (ok
+          (progn
+            (save-excursion
+              (goto-char (sp-get ok :beg))
+              (zap-to-char -1 ?\\ ))
+            (sp-splice-sexp)))
+         ;; test if we are in looking at the command fromt he front
+         ((looking-at "\\\\")
+          (zap-up-to-char 1 ?{)
+          (sp-unwrap-sexp))
+         ;; otherwise we're inside the command name
+         (t
+          (zap-to-char -1 ?\\ )
+          (zap-up-to-char 1 ?{)
+          (sp-unwrap-sexp)))))
+    (bind-key "C-c d" 'my-latex-remove-command LaTeX-mode-map)
+    (bind-key "M-RET" 'LaTeX-insert-item LaTeX-mode-map)
+
+    (defun my-LaTeX-preview-math ()
+      (interactive)
+      (let ((b (save-excursion (while (texmathp) (backward-char 1)) (1- (point))))
+            (e (save-excursion (while (texmathp) (forward-char 1)) (point))))
+        (preview-region b e)))
+    (bind-key "C-<m-key>" 'my-LaTeX-preview-math preview-map)
+
+    (defun my-LaTeX-mode-init ()
+      (setq TeX-auto-save t)
+      (setq TeX-parse-self t)
+      (TeX-PDF-mode t)
+      (setq reftex-plug-into-AUCTeX t)
+      (reftex-mode t)
+      (TeX-fold-mode t)
+
+      (keyadvice-mode t)
+
+      (LaTeX-add-environments
+       '("derivation" LaTeX-env-label))
+      (TeX-add-symbols '("emph" 1))
+
+      (setq fill-column 100000)
+
+      (message "LaTeX mode init complete."))
+    ;; ACUTeX replaces latex-mode-hook with LaTeX-mode-hook
+    (add-hook 'LaTeX-mode-hook 'my-LaTeX-mode-init)
+
+    (keyadvice-add-advice (kbd "`")
+      (if (and (eq major-mode 'latex-mode) (texmathp))
+          (let* ((events (let ((overriding-local-map LaTeX-math-keymap))
+                           (read-key-sequence "math: ")))
+                 (binding (lookup-key LaTeX-math-keymap events)))
+            (call-interactively binding))
+        keyadvice-do-it))))

File files/markdown-defs.el

+(defun my-markdown-init ()
+  (modify-syntax-entry ?\" "$\""))
+(add-hook 'gfm-mode-hook 'my-markdown-init)
+
+(defun -repeat (n x)
+  "Return a list with X repeated N times.
+Returns nil if N is less than 1."
+  (let (ret)
+    (--dotimes n (!cons x ret))
+    ret))
+
+(defun my-markdown-toc ()
+  "Generate table of content from # to ####### headers."
+  (interactive)
+  (let ((n 'nil)
+        (last-m nil)
+        (toc ""))
+    (save-excursion
+      (while (re-search-forward "^\\(#+\\) \\(.*\\)" nil t)
+        (if (equal last-m (match-string 1))
+            (progn
+              (setcar n (1+ (car n))))
+          (if (< (length last-m) (length (match-string 1)))
+              (!cons 1 n)
+            (!cdr n)
+            (setcar n (1+ (car n))))
+          (setq last-m (match-string 1)))
+        (setq toc (concat
+                   toc
+                   (apply #'concat (-repeat (* 4 (1- (length (match-string 1)))) " "))
+                   (int-to-string (car n))
+                   ". ["
+                   (match-string 2)
+                   "]"
+                   "(#"
+                   (replace-regexp-in-string " " "-" (downcase (match-string 2)))
+                   ")
+"
+                   ))))
+    (insert toc)))
+
+(defun my-markdown-generate-anchors ()
+  "Add anchors above each header.  If an anchor is present,
+delete it and re-insert new one."
+  (interactive)
+  (let (m)
+    (while (re-search-forward "^\\(#+\\) \\(.*\\)" nil t)
+      (setq m (match-string 2))
+      (beginning-of-line)
+      (previous-line)
+      (if (looking-at "<a")
+          (delete-region (point) (line-end-position))
+        (newline))
+      (insert (concat
+               "<a name=\""
+               (replace-regexp-in-string " " "-" (downcase m))
+               "\" />"))
+      (next-line 2))))

File files/org-defs.el

+(use-package org-drill
+  :commands org-drill
+  :defer t
+  :config
+  (progn
+    (defun org-drill-present-two-sided-card-no-cloze ()
+      (with-hidden-comments
+       (let ((drill-sections (org-drill-hide-all-subheadings-except nil)))
+         (when drill-sections
+           (save-excursion
+             (goto-char (nth (random* (min 2 (length drill-sections)))
+                             drill-sections))
+             (org-show-subtree)))
+         (ignore-errors
+           (org-display-inline-images t))
+         (org-cycle-hide-drawers 'all)
+         (prog1 (org-drill-presentation-prompt)
+           (org-drill-hide-subheadings-if 'org-drill-entry-p)))))))
+(defface my-org-bold
+  '((t (:weight bold :inherit font-lock-variable-name-face)))
+  "The face used to highlight pair overlays.")
+
+(defface my-org-italic
+  '((t (:slant italic :inherit font-lock-variable-name-face)))
+  "The face used to highlight pair overlays.")
+
+(defface my-org-code
+  '((t (:family "Consolas" :inherit font-lock-constant-face)))
+  "The face used to highlight pair overlays.")
+
+(bind-key "TAB" 'smart-tab org-mode-map)
+(bind-key "C-e" 'my-end-of-code-or-line org-mode-map)
+(bind-key "C-a" 'my-back-to-indentation-or-beginning org-mode-map)
+(bind-key "C-c C-x r" 'org-clock-remove-overlays org-mode-map)
+;; TODO lepsia mapa pre "toggle prikazy?"
+(bind-key "C-c C-x L" 'org-toggle-link-display org-mode-map)
+(bind-key "C-c R" 'org-remove-occur-highlights org-mode-map)
+
+(defun my-org-open-at-point (&optional arg)
+  "Just like `org-open-at-point', but open link in this window."
+  (interactive "P")
+  (if (equal arg '(16))
+      (org-open-at-point arg)
+    (let ((current-prefix-argument nil))
+      (if arg
+          (org-open-at-point '(4))
+        (let ((org-link-frame-setup (acons 'file 'find-file org-link-frame-setup)))
+          (org-open-at-point '(4)))))))
+(bind-key "C-c C-o" 'my-org-open-at-point org-mode-map)
+(bind-key "C-c C-=" 'org-open-at-point org-mode-map)
+
+(defun my-goto-current-clocked-task ()
+  (interactive)
+  (org-goto-marker-or-bmk org-clock-marker))
+(bind-key "<f1> <f10>" 'my-goto-current-clocked-task)
+
+(defun my-org-narrow-to-top-heading ()
+  (interactive)
+  (save-excursion
+    (ignore-errors (while (outline-up-heading 1)))
+    (org-narrow-to-subtree)))
+(bind-key "C-x n t" 'my-org-narrow-to-top-heading org-mode-map)
+
+(defun my-org-metacontrolreturn ()
+  "Execute `org-meta-return' followed by `org-meta-right'.
+This usually makes new item indented one level deeper."
+  (interactive)
+  (org-meta-return)
+  (org-metaright))
+(bind-key "<C-M-return>" 'my-org-metacontrolreturn)
+
+(require 'org-table)
+;; org/orgtbl bindings
+(defvar my-org-table-map)
+(define-prefix-command 'my-org-table-map)
+(bind-key "C-c t" 'my-org-table-map org-mode-map)
+(bind-key "C-c t" 'my-org-table-map orgtbl-mode-map)
+(defvar my-org-table-insert-map)
+(define-prefix-command 'my-org-table-insert-map)
+(bind-key "C-c t i" 'my-org-table-insert-map org-mode-map)
+(bind-key "C-c t i" 'my-org-table-insert-map orgtbl-mode-map)
+(bind-key "C-c t i i" 'orgtbl-insert-radio-table orgtbl-mode-map)
+(defvar my-org-table-delete-map)
+(define-prefix-command 'my-org-table-delete-map)
+(bind-key "C-c t d" 'my-org-table-delete-map org-mode-map)
+(bind-key "C-c t d" 'my-org-table-delete-map orgtbl-mode-map)
+
+(let ((bindings '(("C-c t i c" org-table-insert-column)
+                  ("C-c t i r" org-table-insert-row)
+                  ("C-c t d c" org-table-delete-column)
+                  ("C-c t d r" org-table-kill-row)))
+      (n 1000))
+  (dolist (b bindings)
+    (define-key org-mode-map (kbd (car b)) (cadr b))
+    (org-defkey orgtbl-mode-map (kbd (car b)) (orgtbl-make-binding (cadr b) n (kbd (car b))))
+    (setq n (1+ n))))
+
+(defun my-org-select-cell ()
+  "Select the cell in org table the point is in."
+  (interactive)
+  (let ((b (save-excursion
+             (re-search-forward "|")
+             (backward-char 1)
+             (skip-chars-backward " ")
+             (point)))
+        (e (save-excursion
+             (re-search-backward "|")
+             (forward-char 1)
+             (skip-chars-forward " ")
+             (point))))
+    (push-mark b t t)
+    (goto-char e)))
+(bind-key "C-c t" 'my-org-select-cell org-mode-map)
+
+(defun my-markdown-to-org-link (b e)
+  (interactive "r")
+  (goto-char b)
+  (sp-down-sexp)
+  (let ((desc (sp-get (sp--next-thing-selection 0)
+                (buffer-substring-no-properties :beg :end)))
+        (link (progn
+                (sp-beginning-of-sexp 2)
+                (sp-get (sp--next-thing-selection 0)
+                  (buffer-substring-no-properties :beg :end)))))
+    (delete-region b e)
+    (insert (format "[[%s][%s]]" link desc))))
+
+(defun my-org-make-numbered-list (beg end)
+  (interactive "r")
+  (string-rectangle beg end "- ")
+  (beginning-of-line)
+  (org-call-with-arg 'org-cycle-list-bullet 'previous)
+  (org-call-with-arg 'org-cycle-list-bullet 'previous))
+(bind-key "C-c 1" 'my-org-make-numbered-list org-mode-map)
+
+;; custom filter bindings
+(defvar my-org-filter-map)
+(define-prefix-command 'my-org-filter-map)
+(bind-key "C-c F" 'my-org-filter-map org-mode-map)
+
+;; write a macro to abstract this pattern
+(defun my-org-books-filter ()
+  (interactive)
+  (org-match-sparse-tree nil "+BOOKS"))
+(bind-key "C-c F b" 'my-org-books-filter org-mode-map)
+(defun my-org-books-no-done-filter ()
+  (interactive)
+  (org-match-sparse-tree nil "+BOOKS-TODO=\"DONE\""))
+(bind-key "C-c F B" 'my-org-books-no-done-filter org-mode-map)
+(defun my-org-mov-filter ()
+  (interactive)
+  (org-match-sparse-tree nil "+MOV"))
+(bind-key "C-c F m" 'my-org-mov-filter org-mode-map)
+(defun my-org-mov-no-done-filter ()
+  (interactive)
+  (org-match-sparse-tree nil "+MOV-TODO=\"DONE\""))
+(bind-key "C-c F M" 'my-org-mov-no-done-filter org-mode-map)
+
+(load "files/org-clock")
+(load "files/org-project")
+
+(set-face-attribute 'org-table nil :inherit 'fixed-pitch)
+
+;; Enable modules
+(setq org-modules (quote (org-bbdb
+                          org-bibtex
+                          org-crypt
+                          org-gnus
+                          org-id
+                          org-info
+                          org-jsinfo
+                          org-habit
+                          org-inlinetask
+                          org-irc
+                          org-mew
+                          org-mhe
+                          org-protocol
+                          org-rmail
+                          org-vm
+                          org-wl
+                          org-w3m
+                          org-drill)))
+
+;; position the habit graph on the agenda to the right of the default
+(setq org-habit-graph-column 81)
+
+;;;;;;;;;;;;;;;;;;;;; CAPTURE
+(setq org-directory "~/org")
+(setq org-default-notes-file "~/org/refile.org")
+
+;; I use C-M-r to start capture mode
+(bind-key "C-M-r" 'org-capture)
+
+;; Capture templates for: TODO tasks, Notes, appointments, phone calls, and org-protocol
+(setq org-capture-templates
+      (quote (("t" "todo" entry (file "~/org/refile.org")
+               "* TODO %?\n%U\n%a\n" :clock-keep t)
+              ("s" "someday" entry (file "~/org/refile.org")
+               "* SOMEDAY %?\n%U\n%a\n" :clock-keep t)
+              ("n" "note" entry (file "~/org/refile.org")
+               "* %? :NOTE:\n%U\n%a\n" :clock-keep t)
+              ("j" "Journal" entry (file+datetree "~/org/diary.org")
+               "* %?\n%U\n" :clock-keep t))))
+
+;; Remove empty LOGBOOK drawers on clock out
+(defun bh/remove-empty-drawer-on-clock-out ()
+  (interactive)
+  (save-excursion
+    (beginning-of-line 0)
+    (org-remove-empty-drawer-at "LOGBOOK" (point))))
+
+(add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
+
+;;;;;;;;;;;;;;;;; REFILING
+;; Targets include this file and any file contributing to the agenda - up to 9 levels deep
+(setq org-refile-targets (quote ((nil :maxlevel . 9)
+                                 (org-agenda-files :maxlevel . 9))))
+
+;; Use full outline paths for refile targets - we file directly with IDO
+(setq org-refile-use-outline-path t)
+
+;; Targets complete directly with IDO
+(setq org-outline-path-complete-in-steps nil)
+
+;; Allow refile to create parent tasks with confirmation
+(setq org-refile-allow-creating-parent-nodes (quote confirm))
+
+;; Use IDO for both buffer and file completion and ido-everywhere to t
+(setq org-completion-use-ido t)
+
+;;;; Refile settings
+;; Exclude DONE state tasks from refile targets
+(defun bh/verify-refile-target ()
+  "Exclude todo keywords with a done state from refile targets"
+  (not (member (nth 2 (org-heading-components)) org-done-keywords)))
+
+(setq org-refile-target-verify-function 'bh/verify-refile-target)
+
+(setq org-log-done 'time)
+(setq org-log-done 'note)
+
+;; english locale
+(setq system-time-locale "C")
+(setq org-completion-use-ido t)
+
+;; support selecting with shift+arrows
+(setq org-support-shift-select t)
+
+;; fast state selection
+(setq org-use-fast-todo-selection t)
+
+(setq org-agenda-files (quote ("~/org/")))
+
+;; TODO KEYWORDS SETTINGS
+(setq org-todo-keywords
+      '((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!)")
+        (sequence "WAITING(w@/!)" "HOLD(h@/!)" "|" "CANCELLED(c@/!)")
+        (sequence "SOMEDAY(S)" "|")))
+
+(setq org-todo-keyword-faces
+      (quote (("TODO" :foreground "IndianRed1" :weight bold)
+              ("NEXT" :foreground "RoyalBlue" :weight bold)
+              ("DONE" :foreground "LimeGreen" :weight bold)
+              ("WAITING" :foreground "orange" :weight bold)
+              ("HOLD" :foreground "orange" :weight bold)
+              ("CANCELLED" :foreground "LimeGreen" :weight bold)
+              ("SOMEDAY" :foreground "pink" :weight bold))))
+
+(setq org-todo-state-tags-triggers
+      (quote (("CANCELLED" ("CANCELLED" . t))
+              ("WAITING" ("WAITING" . t))
+              ("HOLD" ("WAITING" . t) ("HOLD" . t))
+              (done ("WAITING") ("HOLD"))
+              ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
+              ("SOMEDAY" ("WAITING") ("CANCELLED") ("HOLD"))
+              ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
+              ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
+
+;; Tags shortcuts
+(setq org-tag-alist (quote ((:startgroup)
+                            ("@errand" . ?e)
+                            ("@school" . ?o)
+                            ("@home" . ?H)
+                            (:endgroup)
+                            ("READING" . ?r)
+                            ("LATIN" . ?l))))
+
+;; Allow setting single tags without the menu
+(setq org-fast-tag-selection-single-key (quote expert))
+
+;; Archiving settings
+(setq org-archive-mark-done nil)
+(setq org-archive-location "%s_archive::* Archived Tasks")
+
+(defun bh/skip-non-archivable-tasks ()
+  "Skip trees that are not available for archiving"
+  (save-restriction
+    (widen)
+    (let ((next-headline (save-excursion (or (outline-next-heading) (point-max)))))
+      ;; Consider only tasks with done todo headings as archivable candidates
+      (if (member (org-get-todo-state) org-done-keywords)
+          (let* ((subtree-end (save-excursion (org-end-of-subtree t)))
+                 (daynr (string-to-int (format-time-string "%d" (current-time))))
+                 (a-month-ago (* 60 60 24 (+ daynr 1)))
+                 (last-month (format-time-string "%Y-%m-" (time-subtract (current-time) (seconds-to-time a-month-ago))))
+                 (this-month (format-time-string "%Y-%m-" (current-time)))
+                 (subtree-is-current (save-excursion
+                                       (forward-line 1)
+                                       (and (< (point) subtree-end)
+                                            (re-search-forward (concat last-month "\\|" this-month) subtree-end t)))))
+            (if subtree-is-current
+                next-headline ; Has a date in this month or last month, skip it
+              nil))  ; available to archive
+        (or next-headline (point-max))))))
+
+;;;;;;;;;;;;;;;;;;;;;;;;; AGENDA VIEW
+;; Compact the block agenda view
+;; (setq org-agenda-compact-blocks t)
+
+;; Custom agenda command definitions
+(setq org-agenda-custom-commands
+      (quote (("N" "Notes" tags "NOTE"
+               ((org-agenda-overriding-header "Notes")
+                (org-tags-match-list-sublevels t)))
+              ("h" "Habits" tags-todo "STYLE=\"habit\""
+               ((org-agenda-overriding-header "Habits")
+                (org-agenda-sorting-strategy
+                 '(todo-state-down effort-up category-keep))))
+              (" " "Agenda"
+               ((agenda "" nil)
+                (tags "REFILE"
+                      ((org-agenda-overriding-header "Tasks to Refile")
+                       (org-tags-match-list-sublevels nil)))
+                (tags-todo "-CANCELLED/!"
+                           ((org-agenda-overriding-header "Stuck Projects")
+                            (org-agenda-skip-function 'bh/skip-non-stuck-projects)))
+                (tags-todo "-WAITING-CANCELLED/!NEXT"
+                           ((org-agenda-overriding-header "Next Tasks")
+                            (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
+                            (org-agenda-todo-ignore-scheduled t)
+                            (org-agenda-todo-ignore-deadlines t)
+                            (org-agenda-todo-ignore-with-date t)
+                            (org-tags-match-list-sublevels t)
+                            (org-agenda-sorting-strategy
+                             '(todo-state-down effort-up category-keep))))
+                (tags-todo "-REFILE-CANCELLED/!-HOLD-WAITING-SOMEDAY"
+                           ((org-agenda-overriding-header "Tasks")
+                            (org-agenda-skip-function 'bh/skip-project-tasks-maybe)
+                            (org-agenda-todo-ignore-scheduled t)
+                            (org-agenda-todo-ignore-deadlines t)
+                            (org-agenda-todo-ignore-with-date t)
+                            (org-agenda-sorting-strategy
+                             '(category-keep))))
+                (tags-todo "-HOLD-CANCELLED/!"
+                           ((org-agenda-overriding-header "Projects")
+                            (org-agenda-skip-function 'bh/skip-non-projects)
+                            (org-agenda-sorting-strategy
+                             '(category-keep))))
+                (tags-todo "-CANCELLED+WAITING/!"
+                           ((org-agenda-overriding-header "Waiting and Postponed Tasks")
+                            (org-agenda-skip-function 'bh/skip-stuck-projects)
+                            (org-tags-match-list-sublevels nil)
+                            (org-agenda-todo-ignore-scheduled 'future)
+                            (org-agenda-todo-ignore-deadlines 'future))))
+               nil)
+              ("r" "Tasks to Refile" tags "REFILE"
+               ((org-agenda-overriding-header "Tasks to Refile")
+                (org-tags-match-list-sublevels nil)))
+              ("#" "Stuck Projects" tags-todo "-CANCELLED/!"
+               ((org-agenda-overriding-header "Stuck Projects")
+                (org-agenda-skip-function 'bh/skip-non-stuck-projects)))
+              ("n" "Next Tasks" tags-todo "-WAITING-CANCELLED/!NEXT"
+               ((org-agenda-overriding-header "Next Tasks")
+                (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
+                (org-agenda-todo-ignore-scheduled t)
+                (org-agenda-todo-ignore-deadlines t)
+                (org-agenda-todo-ignore-with-date t)
+                (org-tags-match-list-sublevels t)
+                (org-agenda-sorting-strategy
+                 '(todo-state-down effort-up category-keep))))
+              ("R" "Tasks" tags-todo "-REFILE-CANCELLED/!-HOLD-WAITING"
+               ((org-agenda-overriding-header "Tasks")
+                (org-agenda-skip-function 'bh/skip-project-tasks-maybe)
+                (org-agenda-sorting-strategy
+                 '(category-keep))))
+              ("S" "Someday" todo "SOMEDAY"
+               ((org-agenda-overriding-header "Someday")
+                (org-tags-match-list-sublevels nil)))
+              ("p" "Projects" tags-todo "-HOLD-CANCELLED/!"
+               ((org-agenda-overriding-header "Projects")
+                (org-agenda-skip-function 'bh/skip-non-projects)
+                (org-agenda-sorting-strategy
+                 '(category-keep))))
+              ("w" "Waiting Tasks" tags-todo "-CANCELLED+WAITING/!"
+               ((org-agenda-overriding-header "Waiting and Postponed tasks"))
+               (org-tags-match-list-sublevels nil))
+              ("A" "Tasks to Archive" tags "-REFILE/"
+               ((org-agenda-overriding-header "Tasks to Archive")
+                (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
+                (org-tags-match-list-sublevels nil))))))
+
+(defun my-org-add-drill-entry ()
+  (interactive)
+  (insert
+   (format
+    "* Word :drill:
+    :PROPERTIES:
+    :DRILL_CARD_TYPE: twosidednocloze
+    :END:
+** %s
+
+** English
+
+** Examples
+
+** Notes
+
+"
+    my-org-drill-language))
+  (re-search-backward ":PROPERTIES:" nil t)
+  (org-cycle)
+  (re-search-forward ":END:" nil t)
+  (forward-line 2))
+
+(defun my-format-russian-verb ()
+  (interactive)
+  (beginning-of-line)
+  (forward-word)
+  (kill-sexp)
+  (delete-char 1)
+  (save-excursion (insert " "))
+  (transpose-words 1)
+  (backward-word 2)
+  (insert "- ")
+  (forward-word)
+  (insert ":")
+  (forward-word)
+  (newline)
+  (delete-char 2)
+  (insert "- ")
+  (forward-char 4)
+  (kill-word 1)
+  (insert ":")
+  (end-of-line)
+  (delete-char -1))
+
+(defun my-format-meaning ()
+  (interactive)
+  (cond
+    ((equal my-org-drill-language "Russian") (my-format-russian-meaning))
+    ((equal my-org-drill-language "Latin") (my-format-latin-meaning))))
+
+(defun my-format-russian-meaning ()
+  (interactive)
+  (delete-char -1)
+  (outline-previous-visible-heading 1)
+  (forward-line)
+  (delete-char 1)
+  (let ((beg (point))
+        (end (progn
+               (outline-next-visible-heading 1)
+               (forward-line -1)
+               (point))))
+    (my-org-make-numbered-list beg end)))
+
+(defun my-format-latin-meaning ()
+  (interactive)
+  (let ((end (1- (cdr (bounds-of-thing-at-point 'line)))))
+    (ignore-errors
+      (while (search-forward ";" end t)
+        (delete-char -1)
+        (forward-char)
+        (newline)))
+    (delete-char -1)
+    (forward-line -1)
+    (let ((end (point))
+          (start (progn
+                   (outline-next-visible-heading -1)
+                   (forward-line)
+                   (point))))
+      (my-org-make-numbered-list start end))))
+
+(defun my-org-drill-fulltext (word)
+  (interactive "sWord: ")
+  (widen)
+  (occur word)
+  (other-window 1)
+  (when (re-search-forward (concat "[0-9]:" word) nil t)
+    (end-of-line)))
+
+(bind-key "a" 'my-occur-mode-goto-card-occurrence occur-mode-map)
+(defun my-occur-mode-goto-card-occurrence ()
+  (interactive)
+  (occur-mode-goto-occurrence)
+  (outline-up-heading 1)
+  (org-narrow-to-subtree)
+  (org-show-subtree)
+  (org-cycle-hide-drawers t))
+
+(defun my-org-status ()
+  (cond
+   ((not (marker-buffer org-clock-marker))
+    "<fc=#d3d7cf>-:--</fc>")
+   (t
+    (let* ((status (substring-no-properties org-mode-line-string 1
+                                            (1- (length org-mode-line-string))))
+           (split-status (split-string status " (")))
+      (concat "<fc=#8ae234>" (car split-status) "</fc>")))))

File files/recentf-defs.el

+(defun my-recentf-setup ()
+  (bind-key "n" 'my-recentf-next-file recentf-dialog-mode-map)
+  (bind-key "p" 'my-recentf-previous-file recentf-dialog-mode-map)
+  (bind-key "C-s" 'my-recentf-isearch-forward recentf-dialog-mode-map))
+
+(add-hook 'recentf-dialog-mode-hook 'my-recentf-setup)
+
+(defun my-recentf-next-file (&optional arg)
+  (interactive "p")
+  (forward-line arg)
+  (re-search-forward ".*/\\(.*?\\)$" nil t)
+  (goto-char (match-beginning 1)))
+
+(defun my-recentf-previous-file (&optional arg)
+  (interactive "p")
+  (forward-line (- arg))
+  (re-search-forward ".*/\\(.*?\\)$" nil t)
+  (goto-char (match-beginning 1)))
+
+(defvar recentf-isearch-filter-predicate-orig nil)
+(defvar recentf-isearch-filenames nil)
+
+(defun recentf-isearch-filenames-setup ()
+  "Set up isearch to search in recentf file names.
+Intended to be added to `isearch-mode-hook'."
+  (when recentf-isearch-filenames
+    (setq isearch-message-prefix-add "filename ")
+    (setq recentf-isearch-filter-predicate-orig
+          (default-value 'isearch-filter-predicate))
+    (setq-default isearch-filter-predicate 'recentf-isearch-filter-filenames)
+    (add-hook 'isearch-mode-end-hook 'recentf-isearch-filenames-end nil t)))
+
+(add-hook 'isearch-mode-hook 'recentf-isearch-filenames-setup)
+
+(defun recentf-isearch-filenames-end ()
+  "Clean up the Recentf file name search after terminating isearch."
+  (setq isearch-message-prefix-add nil)
+  (setq-default isearch-filter-predicate recentf-isearch-filter-predicate-orig)
+  (setq recentf-isearch-filenames nil)
+  (remove-hook 'isearch-mode-end-hook 'recentf-isearch-filenames-end t))
+
+(defun recentf-isearch-filter-filenames (beg end)
+  "Test whether the current search hit is a visible file name.
+Return non-nil if the text from BEG to END is part of a file
+name (has the text property `recentf-filename') and is visible."
+  (and (isearch-filter-visible beg end)
+       (if recentf-isearch-filenames
+           (text-property-not-all (min beg end) (max beg end)
+                                  'recentf-filename nil)
+         t)))
+
+(defun my-recentf-isearch-forward ()
+  (interactive)
+  (setq recentf-isearch-filenames t)
+  (isearch-forward nil t))
+
+;; redefine from recentf.el to add the property to filename, so we can
+;; search filter
+(defun recentf-open-files-item (menu-element)
+  "Return a widget to display MENU-ELEMENT in a dialog buffer."
+  (if (consp (cdr menu-element))
+      ;; Represent a sub-menu with a tree widget
+      `(tree-widget
+        :open t
+        :match ignore
+        :node (item :tag ,(car menu-element)
+                    :sample-face bold
+                    :format "%{%t%}:\n")
+        ,@(mapcar 'recentf-open-files-item
+                  (cdr menu-element)))
+    ;; Represent a single file with a link widget
+    (let ((str (car menu-element)))
+      ;; add the text property to help the search fitler
+      (string-match ".*/\\(.*?\\)$" str)
+      (put-text-property (match-beginning 1) (match-end 1)
+                         'recentf-filename t str)
+      (message "%s" str)
+      `(link :tag ,str
+             :button-prefix ""
+             :button-suffix ""
+             :button-face default
+             :format "%[%t\n%]"
+             :help-echo ,(concat "Open " (cdr menu-element))
+             :action recentf-open-files-action
+             ,(cdr menu-element)))))