comparison lisp/msw-select.el @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children da8ed4261e83
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
36 "Insert the current contents of the mswindows clipboard at point, 36 "Insert the current contents of the mswindows clipboard at point,
37 replacing the active selection if there is one." 37 replacing the active selection if there is one."
38 (interactive "*") 38 (interactive "*")
39 (setq last-command nil) 39 (setq last-command nil)
40 (setq this-command 'yank) ; so that yank-pop works. 40 (setq this-command 'yank) ; so that yank-pop works.
41 (let ((clip (get-clipboard)) (s (mark-marker)) (e (point-marker))) 41 (let ((clip (mswindows-get-clipboard)) (s (mark-marker)) (e (point-marker)))
42 (or clip (error "there is no text on the clipboard")) 42 (or clip (error "there is no text on the clipboard"))
43 (if s 43 (if s
44 (if mouse-track-rectangle-p 44 (if mouse-track-rectangle-p
45 (delete-rectangle s e) 45 (delete-rectangle s e)
46 (delete-region s e))) 46 (delete-region s e)))
47 (push-mark) 47 (push-mark)
48 (if mouse-track-rectangle-p 48 (if mouse-track-rectangle-p
49 (insert-rectangle clip) 49 (insert-rectangle clip)
50 (insert clip)))) 50 (insert clip))))
51 51
52 (defun mswindows-own-clipboard (string)
53 "Paste the given string to the mswindows clipboard."
54 (mswindows-set-clipboard string))
52 55
56 (defvar mswindows-selection-owned-p nil
57 "Whether we have a selection or not.
58 MS-Windows has no concept of ownership; don't use this.")
53 59
60 (defun mswindows-own-selection (data &optional type)
61 "Make an MS-Windows selection of type TYPE and value DATA.
62 The argument TYPE is ignored, and DATA specifies the contents.
63 DATA may be a string,
64 a symbol, an integer (or a cons of two integers or list of two integers).
54 65
66 The selection may also be a cons of two markers pointing to the same buffer,
67 or an overlay. In these cases, the selection is considered to be the text
68 between the markers *at whatever time the selection is examined*.
69 Thus, editing done in the buffer after you specify the selection
70 can alter the effective value of the selection.
71
72 The data may also be a vector of valid non-vector selection values.
73
74 Interactively, the text of the region is used as the selection value."
75 (interactive (if (not current-prefix-arg)
76 (list (read-string "Store text for pasting: "))
77 (list (substring (region-beginning) (region-end)))))
78 (or (valid-simple-selection-p data)
79 (and (vectorp data)
80 (let ((valid t)
81 (i (1- (length data))))
82 (while (>= i 0)
83 (or (valid-simple-selection-p (aref data i))
84 (setq valid nil))
85 (setq i (1- i)))
86 valid))
87 (signal 'error (list "invalid selection" data)))
88 (if data
89 (progn
90 ; (mswindows-set-clipboard data)
91 (setq mswindows-selection-owned-p data))
92 (setq mswindows-selection-owned-p nil))
93 (setq primary-selection-extent
94 (select-make-extent-for-selection
95 data primary-selection-extent))
96 (setq zmacs-region-stays t)
97 data)
98
99 (defun mswindows-disown-selection (&optional secondary-p)
100 "Assuming we own the selection, disown it. With an argument, discard the
101 secondary selection instead of the primary selection."
102 (setq mswindows-selection-owned-p nil)
103 (mswindows-delete-selection))
104
105 (defun mswindows-selection-owner-p (&optional selection)
106 "Return t if current emacs process owns the given Selection.
107 The arg is ignored."
108 (not (eq mswindows-selection-owned-p nil)))
109