From fa803b2c14de326880faaaf2cdf6d1cd6ed271cb Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Sun, 28 Jun 2015 23:30:39 -0700 Subject: [PATCH] imalison:shell-command-on-region --- dotfiles/emacs.d/init.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/dotfiles/emacs.d/init.el b/dotfiles/emacs.d/init.el index 37483d65..053422cb 100644 --- a/dotfiles/emacs.d/init.el +++ b/dotfiles/emacs.d/init.el @@ -244,6 +244,26 @@ buffer is not visiting a file." (lambda (frame) (assoc 'display (frame-parameters frame))) (frame-list))) +(defun imalison:copy-shell-command-on-region (start end command) + (interactive (list (region-beginning) (region-end) + (read-shell-command "Shell command on region: "))) + (let ((original-buffer (current-buffer))) + (with-temp-buffer + (let ((temp-buffer (current-buffer))) + (with-current-buffer original-buffer + (shell-command-on-region start end command temp-buffer)) + (kill-ring-save (point-max) (point-min)))))) + +(defun imalison:shell-command-on-region-replace (start end command) + (interactive (list (region-beginning) (region-end) + (read-shell-command "Shell command on region: "))) + (shell-command-on-region start end command nil t)) + +(defun imalison:shell-command-on-region (arg) + (interactive "P") + (call-interactively (if arg 'imalison:shell-command-on-region-replace + 'imalison:copy-shell-command-on-region))) + (defun make-frame-if-none-exists () (let* ((existing-frame (frame-exists))) (if existing-frame @@ -1829,6 +1849,7 @@ window is active in the perspective." (bind-key "M-z" 'zap-to-char) (bind-key "C-M-" 'backward-kill-sexp) (bind-key "s-" 'toggle-frame-fullscreen) +(bind-key "M-|" 'imalison:shell-command-on-region) (fset 'global-set-key-to-use-package (lambda (&optional arg) "Keyboard macro." (interactive "p")