Skip to content

Instantly share code, notes, and snippets.

;; In an effort to fix the poor new template system, introducing my own fix:
(defun jsm/org-src-block ()
"Better src block completion experience"
(interactive)
(org-insert-structure-template
(concat "src " (completing-read "Source type: " org-src-lang-modes))))
(define-key org-mode-map (kbd "C-c s") 'jsm/org-src-block)
@jonEbird
jonEbird / ivy-ag.el
Created September 12, 2016 21:13
Running counsel-ag while automatically ignoring git submoules
(defun jsm/projectile-counsel-ag ()
"Run counsel-ag within projectile root while ignoring git submodule paths."
(interactive)
(let ((default-directory (projectile-project-root))
(agignore-cmd "git config --file .gitmodules --get-regexp path | awk '{ print $2 }' > .agignore"))
(shell-command agignore-cmd nil nil)
(counsel-ag (thing-at-point 'symbol) (projectile-project-root))))
(define-key projectile-command-map (kbd "s s") 'jsm/projectile-counsel-ag)
@jonEbird
jonEbird / with_stderr_off.py
Created May 5, 2015 16:24
Python context manager to temporarily disable stderr
from contextlib import contextmanager
@contextmanager
def stderr_off():
import sys
stderr_orig = sys.stderr
sys.stderr = open('/dev/null', 'w')
yield
sys.stderr = stderr_orig
@jonEbird
jonEbird / use-package-el-get.el
Created April 16, 2015 04:28
Add :el-get option to use-package that mimics :ensure
(require 'use-package)
(defun use-package-normalize/:el-get (name-symbol keyword args)
(if (null args)
t
(use-package-only-one (symbol-name keyword) args
(lambda (label arg)
(if (symbolp arg)
arg
(use-package-error
@jonEbird
jonEbird / switch-to-project.el
Created April 2, 2015 15:46
Quickly split window and pull up your favorite projects file/buffer via keychord "PP"
;; Quickly split window and get to my projects File
(require 'key-chord)
(defvar my-projects-file "~/org/projects.org"
"My favorite projects file")
(defun switch-to-projects-other-window ()
"Quickly open my favorite projects buffer in other window"
(interactive)
(let* ((project-filename (expand-file-name my-projects-file))
@jonEbird
jonEbird / make-executable.el
Created March 13, 2015 19:26
Make scripts executable with conditions
;; Make files that should be executable, executable
(defun jsm:make-buffer-file-executable-if-script-p ()
"Limit the situations that I want scripts to be made executable"
(interactive)
(let ((parent-dir (file-name-base
(directory-file-name
(file-name-directory buffer-file-name)))))
(if (cond ((eq major-mode 'sh-mode) t)
((and (eq major-mode 'python-mode)
(string= parent-dir "scripts")) t)
@jonEbird
jonEbird / readme_preview.el
Created January 19, 2015 18:37
README Preview
;; README preview helper thanks to pandoc
;; ------------------------------
(defun readme-preview ()
"Preview the README rendered to html in a browser tab via pandoc"
(interactive)
(let* ((html-filename (format "%s.html" (file-name-base buffer-file-name)))
(input-format (cond
((derived-mode-p 'rst-mode) "rst")
((derived-mode-p 'markdown-mode) "markdown_github")))
(cmd (format "pandoc -f %s -t html -o %s %s"
@jonEbird
jonEbird / updatefile.py
Created December 2, 2014 18:42
Stage and commit local file updates
import os
import sys
import stat
import shutil
import tempfile
import logging as log
class UpdateFile(object):
"""Update a file atomically
@jonEbird
jonEbird / phi-search_mc.el
Created November 6, 2014 00:27
Only use phi-search when multiple cursors is enabled
;; Allow isearch functionality with multiple-cursors
(require 'phi-search)
(setq phi-search-limit 10000)
(add-hook 'multiple-cursors-mode-enabled-hook
(lambda ()
(interactive)
(global-set-key (kbd "C-s") 'phi-search)
(global-set-key (kbd "C-r") 'phi-search-backward)))
(add-hook 'multiple-cursors-mode-disabled-hook
(lambda ()
@jonEbird
jonEbird / mock_gnu_screen.el
Last active August 29, 2015 14:05
Simulate a GNU screen setup within Emacs
;; Simulate GNU Screen within Emacs using ansi-term
;; ------------------------------
(defun term-next ()
"Go to the next terminal based on the buffer name. Will extract the
number from the buffer-name, add 1 and go to a buffer of that name if it
exists."
(interactive)
(let ((cur-buffer (buffer-name)))
(if (string-match "\\([0-9]+\\)" cur-buffer)
(let* ((n (match-string-no-properties 0 cur-buffer))