Created
May 11, 2020 08:15
-
-
Save nobrowser/b8dc8fca0aee38895fd0062bb863c838 to your computer and use it in GitHub Desktop.
Emacs global minor mode to replace kill-FOO commands with delete-FOO (useful when I don't want to touch the kill ring)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; deleterious.el --- minor move to delete things instead of killing them | |
;; Copyright (C) Ian Zimmerman 2015 | |
;; Terms: GNU General Public License, Version 2 | |
(require 'thingatpt) | |
(defconst deleterious-mode-map | |
(let ((k (make-sparse-keymap))) | |
(define-key k [remap kill-region] 'delete-region) | |
k) | |
"Keymap to use in Deleterious minor mode.") | |
(defsubst deleterious-del (thing n) | |
(let ((bound (save-excursion (forward-thing thing n) (point)))) | |
(if (< (point) bound) (delete-region (point) bound) | |
(delete-region bound (point))))) | |
(defsubst deleterious-help (thing pos neg) | |
(concat | |
(format "Delete a %s %s without adding to the kill ring.\n" thing pos) | |
(format "Numeric prefix arg means delete that many %ss.\n" thing) | |
(format "Negative arg means delete %s." neg))) | |
(defmacro deleterious-def (thing) | |
(let ((forward-sym (intern (format "deleterious-delete-%s" thing))) | |
(backward-sym (intern (format "deleterious-backward-delete-%s" thing))) | |
(kill-sym (intern (format "kill-%s" thing))) | |
(backward-kill-sym (intern (format "backward-kill-%s" thing))) | |
(forward-doc (deleterious-help thing "forward" "backward")) | |
(backward-doc (deleterious-help thing "backward" "forward"))) | |
`(let ((forward-fun | |
(lambda (n) (interactive "p") | |
(deleterious-del (quote ,thing) n))) | |
(backward-fun | |
(lambda (n) (interactive "p") | |
(deleterious-del (quote ,thing) (- n))))) | |
(fset (quote ,forward-sym) forward-fun) | |
(put (quote ,forward-sym) 'function-documentation ,forward-doc) | |
(define-key deleterious-mode-map [remap ,kill-sym] forward-fun) | |
(fset (quote ,backward-sym) backward-fun) | |
(put (quote ,backward-sym) 'function-documentation ,backward-doc) | |
(define-key deleterious-mode-map [remap ,backward-kill-sym] backward-fun) | |
))) | |
(deleterious-def line) | |
(deleterious-def sentence) | |
(deleterious-def sexp) | |
(deleterious-def word) | |
;;;###autoload | |
(define-minor-mode deleterious-mode | |
"Set or toggle Deleterious minor mode. It deletes instead of killing. | |
This global minor mode rebinds a few keys to commands which remove bits | |
of text but *do not* put them on the kill ring. It is useful for | |
repetitive tasks involving multiple yanks of the same string; the string | |
you yank will not get pushed back in the kill ring by new additions." | |
:global t :init-value nil :lighter " Del" :keymap deleterious-mode-map) | |
(provide 'deleterious) | |
;; Local Variables: | |
;; End: | |
;;; deleterious.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment