ein-kill-ring.el 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ;;; ein-kill-ring.el --- Kill-ring for cells
  2. ;; Copyright (C) 2012- Takafumi Arakaki
  3. ;; Author: Takafumi Arakaki <aka.tkf at gmail.com>
  4. ;; This file is NOT part of GNU Emacs.
  5. ;; ein-kill-ring.el is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; ein-kill-ring.el is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with ein-kill-ring.el. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; Stolen from simple.el.
  17. ;;; Code:
  18. (defvar ein:kill-ring nil)
  19. (defvar ein:kill-ring-yank-pointer nil)
  20. (defvar ein:kill-ring-max kill-ring-max)
  21. (defun ein:kill-new (obj)
  22. "Make OBJ the latest kill in the kill ring `ein:kill-ring'.
  23. Set `ein:kill-ring-yank-pointer' to point to it."
  24. (push obj ein:kill-ring)
  25. (if (> (length ein:kill-ring) ein:kill-ring-max)
  26. (setcdr (nthcdr (1- ein:kill-ring-max) ein:kill-ring) nil))
  27. (setq ein:kill-ring-yank-pointer ein:kill-ring))
  28. (defun ein:current-kill (n &optional do-not-move)
  29. "Rotate the yanking point by N places, and then return that kill.
  30. If optional arg DO-NOT-MOVE is non-nil, then don't actually
  31. move the yanking point; just return the Nth kill forward."
  32. (unless ein:kill-ring (error "Kill ring is empty"))
  33. (let ((ARGth-kill-element
  34. (nthcdr (mod (- n (length ein:kill-ring-yank-pointer))
  35. (length ein:kill-ring))
  36. ein:kill-ring)))
  37. (unless do-not-move
  38. (setq ein:kill-ring-yank-pointer ARGth-kill-element))
  39. (car ARGth-kill-element)))
  40. (provide 'ein-kill-ring)
  41. ;;; ein-kill-ring.el ends here