dotfiles

🎜 Clone'em, tweak'em, stick'em in your $HOME 🎝
git clone https://git.kevinlegouguec.net/dotfiles
Log | Files | Refs | README

commit ee6ed90a8fb33743f5b6b987d2792d0c1752089f
parent 81debb519f7c448b7a5acea21fdb46eaaffe0afa
Author: Kévin Le Gouguec <kevin.legouguec@gmail.com>
Date:   Sun, 15 Apr 2018 13:24:44 +0200

Add key-bindings to copy stuff

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.

Diffstat:
M.emacs | 15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)

diff --git 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)