help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

code: deleterious mode [Was: yank-pop problem]


From: Ian Zimmerman
Subject: code: deleterious mode [Was: yank-pop problem]
Date: Fri, 7 Aug 2015 11:49:36 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

This thread gave me an idea :-)

Constructive criticism most welcome!

;;; 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)

(defmacro deleterious-def (thing)
  (let ((sthing (symbol-name thing)))
  `(defun ,(intern (concat "deleterious-delete-" sthing)) (n)
     ,(concat
       "Delete a " sthing
       " without adding to the kill ring.
Numeric prefix arg means delete that many " sthing "s.
Negative arg means delete backward.")
     (interactive "p")
     (let ((bound
            (save-excursion
              (forward-thing (quote ,thing) n)
              (point))))
       (if (< (point) bound) (delete-region (point) bound)
         (delete-region bound (point)))))))

(deleterious-def line)
(deleterious-def sentence)
(deleterious-def sexp)
(deleterious-def word)

(defconst deleterious-mode-map
  (let ((k (make-sparse-keymap)))
    (define-key k [remap kill-region] 'delete-region)
    (define-key k [remap kill-line] 'deleterious-delete-line)
    (define-key k [remap kill-sentence] 'deleterious-delete-sentence)
    (define-key k [remap kill-sexp] 'deleterious-delete-sexp)
    (define-key k [remap kill-word] 'deleterious-delete-word)
    k)
  "Keymap to use in Deleterious minor mode.")

;;;###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

-- 
Please *no* private copies of mailing list or newsgroup messages.
Rule 420: All persons more than eight miles high to leave the court.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]