Skip to content

Instantly share code, notes, and snippets.

(defun evil-cd (dir)
(interactive "D")
(if (file-exists-p dir)
(message dir)
(message "error")))
(evil-ex-define-cmd "cd" 'evil-cd)
(defmacro my-notmuch-search-creator (name &rest tags)
(let ((funname (intern (concat "my-notmuch-search-for-" (symbol-name name)))))
`(progn
(defun ,funname ()
(interactive)
(notmuch-search-tag (my-notmuch-toggle-tags-changes
(notmuch-search-get-tags)
tags)))
',funname)))
(defun evil-filter (count)
(interactive "p")
(evil-ex (if current-prefix-arg
(format ".,+%d!" count)
".!")))
(define-key evil-normal-state-map (kbd "!") #'evil-filter)
(defun switch-in-keymap (key1 key2 keymap)
(let ((cmd1 (lookup-key key1 keymap))
(cmd2 (lookup-key key2 keymap)))
(define-key keymap key1 cmd2)
(define-key keymap key2 cmd1)))
(mapc (lambda (map) (switch-in-keymap "x" "y" map))
(list evil-motion-state-map
evil-normal-state-map
evil-emacs-state-map
;; AceJump integration is now included in evil, this gist is only preserved for historical reasons.
;; Please use the provided integration (it's far more advanced)
;; AceJump is a nice addition to evil's standard motions.
;; The following definitions are necessary to define evil motions for ace-jump-mode (version 2).
;; ace-jump is actually a series of commands which makes handling by evil
;; difficult (and with some other things as well), using this macro we let it
;; appear as one.
@cofi
cofi / gist:3013327
Created June 28, 2012 19:22
Command using Helm to select spelling corrections
(defun cofi/helm-flyspell-correct ()
"Use helm for flyspell correction.
Adapted from `flyspell-correct-word-before-point'."
(interactive)
;; use the correct dictionary
(flyspell-accept-buffer-local-defs)
(let ((cursor-location (point))
(word (flyspell-get-word))
(opoint (point)))
(eval-when-compile
(require 'cl))
(defun cofi/inc-at-pt (amount)
"Increment the number at point by `amount'"
(interactive "p*")
(save-match-data
(or
;; find binary literals
(when (looking-back "0[bB][01]*")
import sys
import types
class Tee(object):
"""
Contextmanager for writing simulaniously to multiple files.
"""
def __init__(self, *args, **kwargs):
"""
args -- file names or open file-like objects
@cofi
cofi / gist:1070347
Created July 7, 2011 19:38
revert all(!!) buffers after git pull
(require 'cl)
(defadvice magit-pull (after refresh-buffers-after-pull activate)
(loop for buffer in (buffer-list)
when (buffer-file-name buffer)
do (with-current-buffer buffer
(if (buffer-modified-p buffer)
;; ask for confirmation on modified buffers
(revert-buffer)
(revert-buffer 'ignore-auto 'noconfirm)))))