From ee6ed90a8fb33743f5b6b987d2792d0c1752089f Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Sun, 15 Apr 2018 13:24:44 +0200 Subject: Add key-bindings to copy stuff MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I regularly used C-x C-f M-n C-SPC C-a C-w C-g to get the current buffer's filename in the kill-ring (and the clipboard). This had two issues: 1. It does not work with Ivy: C-a only moves back to the beginning of the basename; 2. M-n runs the find-file-at-point machinery; if point is on a word that looks like a domain (ends with ".com", ".net", …), ffap *attempts to contact the domain*, which is inconvenient for a bunch of reasons (locks up the editor, leaks data by sending it in DNS requests, opens 9/tcp connections to random domains…) The latter can be disabled by customizing ffap-machine-p-known; maybe I'll go ahead and do that someday. In the meantime, defining a proper function instead of relying on side-effects seems like a quick-win. my/kill-ring-pipe-region allows me to quickly run pandoc on a Markdown snippet and paste the resulting HTML in LWN's comment form. I'm sure I will find other uses for it. --- .emacs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.emacs b/.emacs index ab0e3e1..2142c31 100644 --- a/.emacs +++ b/.emacs @@ -40,6 +40,8 @@ (global-set-key (kbd "C-c c") 'compile) (global-set-key (kbd "C-c f") 'auto-fill-mode) +(global-set-key (kbd "C-c k f") 'my/kill-ring-filename) +(global-set-key (kbd "C-c k |") 'my/kill-ring-pipe-region) (global-set-key (kbd "C-c m") 'man) (global-set-key (kbd "C-c p") 'electric-pair-mode) (global-set-key (kbd "C-c t") 'toggle-truncate-lines) @@ -200,6 +202,19 @@ (set-variable 'tab-width new-width) (message "changed from %s to %s" old-width new-width))) +(defun my/kill-ring-filename () + (interactive) + (kill-new (or (buffer-file-name) default-directory))) + +(defun my/kill-ring-pipe-region (command) + (interactive (list (read-shell-command "Shell command on region: "))) + (let ((input (funcall region-extract-function nil))) + (with-temp-buffer + (insert input) + (call-process-region (point-min) (point-max) shell-file-name + t t nil shell-command-switch command) + (kill-new (buffer-string))))) + (defun my/froggify () (ispell-change-dictionary "fr") (setq-local colon-double-space nil) -- cgit v1.2.3