Skip to content

Instantly share code, notes, and snippets.

@johnmastro
johnmastro / ibuffer-magit-repo-dir.el
Last active September 12, 2015 23:04
Show Magit repo directory in ibuffer
;; Turns out it's not necessary to define a new ibuffer column type. Both
;; `list-buffers' and `ibuffer' respect `list-buffers-directory', so just do
;; something like this:
(add-hook 'magit-mode-hook
(lambda ()
(let ((dir (abbreviate-file-name default-directory)))
(setq list-buffers-directory dir))))
@johnmastro
johnmastro / projectile-tags-cygwin-kludge.el
Created August 12, 2015 01:59
Kludge for projectile-regenerate-tags on Windows+Cygwin
(defun maybe-cygwinize-drive-letter (file)
"Return FILE in a Cygwin-friendly format.
For example, given \"c:/foo/bar\" return \"/foo/bar\", or given
\"e:/foo/bar\" return \"/e/foo/bar\"."
(cond ((string-match "\\`[Cc]:/" file)
(replace-match "/" t t file))
((string-match "\\`\\([A-Za-z]\\):/" file)
(replace-match (concat "/" (match-string 1 file) "/")
t t file))
(t file)))
@johnmastro
johnmastro / add-mc-cmds.el
Created May 23, 2015 01:54
add-mc-cmds.el
;; Just doodling on the topic of somewhat automatically initializing
;; `mc/cmds-to-run-for-all'.
;;
;; I always find the prompts a bit distracting when working on a new computer
;; but the file `multiple-cursors' maintains, .mc-lists.el, doesn't seem very
;; well-suited to version control.
(require 'pcase)
(defvar mc-paredit&sp-cmds-to-run-for-all-regexp
@johnmastro
johnmastro / cycle-case.el
Created May 23, 2015 01:34
cycle-case.el
(require 'pcase)
;; Based on Xah Lee's: http://ergoemacs.org/emacs/modernization_upcase-word.html
(defun cycle-case (beg end)
"Cycle the word case of the active region or word at point."
(interactive
(pcase-let ((`(,beg . ,end) (if (use-region-p)
(cons (region-beginning) (region-end))
(bounds-of-thing-at-point 'word))))
;; An attempt at this Emacs SX question:
;; https://emacs.stackexchange.com/questions/10359/delete-portion-of-isearch-string-that-does-not-match-or-last-char-if-complete-m
(defun isearch-delete-something ()
"Delete non-matching text or the last character."
;; Mostly copied from `isearch-del-char' and Drew's answer on the page above
(interactive)
(if (= 0 (length isearch-string))
(ding)
(setq isearch-string
@johnmastro
johnmastro / List.vim
Last active August 29, 2015 14:17 — forked from romainl/list.md
" This is an updated, more powerful, version of the function discussed here:
" http://www.reddit.com/r/vim/comments/1rzvsm/do_any_of_you_redirect_results_of_i_to_the/
" that shows ]I, [I, ]D, [D, :ilist and :dlist results in the quickfix window, even spanning multiple files.
function! List(command, selection, start_at_cursor, ...)
" derive the commands used below from the first argument
let excmd = a:command . "list"
let normcmd = toupper(a:command)
if a:selection
@johnmastro
johnmastro / iterm.el
Last active September 13, 2022 14:41
Send text from Emacs to iTerm
;;; iterm.el - Send text to a running iTerm instance
(require 'pcase)
(require 'thingatpt)
;; To match SublimeText's key binding:
;; (global-set-key (kbd "<C-return>") 'iterm-send-text)
(defvar iterm-default-thing 'line
"The \"thing\" to send if no region is active.
(require 'slime)
(require 'dash)
(require 'trident-mode)
(defvar trident-target-process nil
"The process that expansions will be sent to.")
(defun trident-list-process-buffers ()
"Return a list of all buffers with an associated process."
(-filter #'get-buffer-process (buffer-list)))
@johnmastro
johnmastro / filter-by-val.clj
Last active May 14, 2019 08:35
Filter Clojure maps by value
(defn filter-by-val-1
[pred m]
(into {} (filter (fn [[k v]] (pred v))
m)))
;; This one is a little faster
(defn filter-by-val-2
[pred m]
(persistent!
(reduce-kv (fn [acc k v]
@johnmastro
johnmastro / octopress.el
Created February 16, 2013 20:11
Some code I've been playing around with to automate the process of of creating a new Octopress page or post, with appropriate metadata, from an Emacs buffer's content.
;; -*- lexical-binding: t -*-
;; Some code I've been playing around with to automate the process of of
;; creating a new Octopress page or post, with appropriate metadata, from a
;; buffer's content.
;; The `octopress-rake`, `octopress-extract-filename`, and `octopress-new`
;; functions are derived from the octopress-emacs code here:
;; github.com/gfreezy/octopress-emacs