diff options
| author | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2018-04-15 13:24:44 +0200 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2018-04-15 13:24:44 +0200 |
| commit | ee6ed90a8fb33743f5b6b987d2792d0c1752089f (patch) | |
| tree | c165ce6b379b064035e32f28c8660d12a70f2e3c | |
| parent | 81debb519f7c448b7a5acea21fdb46eaaffe0afa (diff) | |
| download | dotfiles-ee6ed90a8fb33743f5b6b987d2792d0c1752089f.tar.xz | |
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.
| -rw-r--r-- | .emacs | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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) |
