Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 regels
2.1 KiB

4 jaren geleden
  1. ;;; swank-clipboard.lisp --- Object clipboard
  2. ;;
  3. ;; Written by Helmut Eller in 2008.
  4. ;; License: Public Domain
  5. (defpackage :swank-clipboard
  6. (:use :cl)
  7. (:import-from :swank :defslimefun :with-buffer-syntax :dcase)
  8. (:export :add :delete-entry :entries :entry-to-ref :ref))
  9. (in-package :swank-clipboard)
  10. (defstruct clipboard entries (counter 0))
  11. (defvar *clipboard* (make-clipboard))
  12. (defslimefun add (datum)
  13. (let ((value (dcase datum
  14. ((:string string package)
  15. (with-buffer-syntax (package)
  16. (eval (read-from-string string))))
  17. ((:inspector part)
  18. (swank:inspector-nth-part part))
  19. ((:sldb frame var)
  20. (swank/backend:frame-var-value frame var)))))
  21. (clipboard-add value)
  22. (format nil "Added: ~a"
  23. (entry-to-string (1- (length (clipboard-entries *clipboard*)))))))
  24. (defslimefun entries ()
  25. (loop for (ref . value) in (clipboard-entries *clipboard*)
  26. collect `(,ref . ,(to-line value))))
  27. (defslimefun delete-entry (entry)
  28. (let ((msg (format nil "Deleted: ~a" (entry-to-string entry))))
  29. (clipboard-delete-entry entry)
  30. msg))
  31. (defslimefun entry-to-ref (entry)
  32. (destructuring-bind (ref . value) (clipboard-entry entry)
  33. (list ref (to-line value 5))))
  34. (defun clipboard-add (value)
  35. (setf (clipboard-entries *clipboard*)
  36. (append (clipboard-entries *clipboard*)
  37. (list (cons (incf (clipboard-counter *clipboard*))
  38. value)))))
  39. (defun clipboard-ref (ref)
  40. (let ((tail (member ref (clipboard-entries *clipboard*) :key #'car)))
  41. (cond (tail (cdr (car tail)))
  42. (t (error "Invalid clipboard ref: ~s" ref)))))
  43. (defun clipboard-entry (entry)
  44. (elt (clipboard-entries *clipboard*) entry))
  45. (defun clipboard-delete-entry (index)
  46. (let* ((list (clipboard-entries *clipboard*))
  47. (tail (nthcdr index list)))
  48. (setf (clipboard-entries *clipboard*)
  49. (append (ldiff list tail) (cdr tail)))))
  50. (defun entry-to-string (entry)
  51. (destructuring-bind (ref . value) (clipboard-entry entry)
  52. (format nil "#@~d(~a)" ref (to-line value))))
  53. (defun to-line (object &optional (width 75))
  54. (with-output-to-string (*standard-output*)
  55. (write object :right-margin width :lines 1)))
  56. (provide :swank-clipboard)