;;; x-win.el --- parse relevant switches and set up for X -*-coding: iso-2022-7bit;-*-
-;; Copyright (C) 1993, 1994, 2001, 2002 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1994, 2001, 2002, 2003, 2004,
+;; 2005 Free Software Foundation, Inc.
;; Author: FSF
;; Keywords: terminals, i18n
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
(require 'select)
(require 'menu-bar)
(require 'fontset)
+(require 'x-dnd)
(defvar x-invocation-args)
+(defvar x-keysym-table)
+(defvar x-selection-timeout)
+(defvar x-session-id)
+(defvar x-session-previous-id)
(defvar x-command-line-resources nil)
(let ((param (nth 3 aelt)))
(setq default-frame-alist
(cons (cons param
- (string-to-int (car x-invocation-args)))
+ (string-to-number (car x-invocation-args)))
default-frame-alist)
x-invocation-args
(cdr x-invocation-args))))))
"The value of the PRIMARY X selection last time we selected or
pasted text.")
(defvar x-last-selected-text-cut nil
- "The value of the X cut buffer last time we selected or pasted text.")
+ "The value of the X cut buffer last time we selected or pasted text.
+The actual text stored in the X cut buffer is what encoded from this value.")
+(defvar x-last-selected-text-cut-encoded nil
+ "The value of the X cut buffer last time we selected or pasted text.
+This is the actual text stored in the X cut buffer.")
;;; It is said that overlarge strings are slow to put into the cut buffer.
;;; Note this value is overridden below.
;; It becomes slow, and if really big it causes errors.
(cond ((>= (length text) x-cut-buffer-max)
(x-set-cut-buffer "" push)
- (setq x-last-selected-text-cut ""))
- ;; Don't store a multibyte string that contains
- ;; eight-bit-control/graphic chars because they can't be
- ;; restored correctly by x-get-cut-buffer.
- ((and (multibyte-string-p text)
- (let ((charsets (find-charset-string text)))
- (or (memq 'eight-bit-control charsets)
- (memq 'eight-bit-graphic charsets))))
- (x-set-cut-buffer "" push)
- (setq x-last-selected-text-cut ""))
+ (setq x-last-selected-text-cut ""
+ x-last-selected-text-cut-encoded ""))
(t
- (x-set-cut-buffer text push)
- (setq x-last-selected-text-cut text)))
+ (setq x-last-selected-text-cut text
+ x-last-selected-text-cut-encoded
+ (encode-coding-string text (or locale-coding-system
+ 'iso-latin-1)))
+ (x-set-cut-buffer x-last-selected-text-cut-encoded push)))
(x-set-selection 'PRIMARY text)
(setq x-last-selected-text-primary text)
(when x-select-enable-clipboard
char)
(if (/= len-utf8 len-ctext)
(if (> len-utf8 len-ctext) utf8 ctext)
- (while (< i len-utf8)
- (setq char (aref ctext i))
- (if (and (< char 128) (/= char (aref utf8 i)))
- (setq selected utf8
- i len-utf8)
- (setq i (1+ i))))
- selected)))
+ (let ((result (compare-strings utf8 0 len-utf8 ctext 0 len-ctext)))
+ (if (or (eq result t)
+ (>= (aref ctext (1- (abs result))) 128))
+ ctext
+ utf8)))))
+
+;; Get a selection value of type TYPE by calling x-get-selection with
+;; an appropiate DATA-TYPE argument decidd by `x-select-request-type'.
+;; The return value is already decoded. If x-get-selection causes an
+;; error, this function return nil.
(defun x-selection-value (type)
(let (text)
(error nil))
utf8-coding last-coding-system-used)
(if utf8
- ;; If it is a locale selection, choose it.
- (or (get-text-property 0 'foreign-selection utf8)
+ ;; If it is a local selection, or it contains only
+ ;; ASCII characers, choose it.
+ (if (or (not (get-text-property 0 'foreign-selection utf8))
+ (= (length utf8) (string-bytes utf8)))
(setq text utf8)))
;; If not yet decided, try COMPOUND_TEXT.
(if (not text)
(if utf8
(setq text (x-select-utf8-or-ctext utf8 ctext))
;; Othewise, choose CTEXT.
- (setq text ctext))))
+ (setq text ctext))
+ (setq text utf8)))
;; If not yet decided, try STRING.
(or text
(setq text (condition-case nil
(if text
(remove-text-properties 0 (length text) '(foreign-selection nil) text))
text))
-
+
;;; Return the value of the current X selection.
;;; Consult the selection, and the cut buffer. Treat empty strings
;;; as if they were unset.
;; from what we remebered them to be last time we did a
;; cut/paste operation.
(setq cut-text
- (cond;; check primary selection
+ (cond;; check cut buffer
((or (not cut-text) (string= cut-text ""))
(setq x-last-selected-text-cut nil))
- ((eq cut-text x-last-selected-text-cut) nil)
- ((string= cut-text x-last-selected-text-cut)
+ ;; This short cut doesn't work because x-get-cut-buffer
+ ;; always returns a newly created string.
+ ;; ((eq cut-text x-last-selected-text-cut) nil)
+ ((string= cut-text x-last-selected-text-cut-encoded)
+ ;; See the comment above. No need of this recording.
;; Record the newer string,
;; so subsequent calls can use the `eq' test.
- (setq x-last-selected-text-cut cut-text)
- nil)
- (t
- (setq x-last-selected-text-cut cut-text))))
+ ;; (setq x-last-selected-text-cut cut-text)
+ nil)
+ (t
+ (setq x-last-selected-text-cut-encoded cut-text
+ x-last-selected-text-cut
+ (decode-coding-string cut-text (or locale-coding-system
+ 'iso-latin-1))))))
;; As we have done one selection, clear this now.
(setq next-selection-coding-system nil)
;; generated from FONT.
(create-fontset-from-ascii-font font resolved-name "startup"))))
-;; Sun expects the menu bar cut and paste commands to use the clipboard.
-;; This has ,? to match both on Sunos and on Solaris.
-(if (string-match "Sun Microsystems,? Inc\\."
- (x-server-vendor))
- (menu-bar-enable-clipboard))
-
;; Apply a geometry resource to the initial frame. Put it at the end
;; of the alist, so that anything specified on the command line takes
;; precedence.
;; Turn on support for mouse wheels.
(mouse-wheel-mode 1)
+
+;; Enable CLIPBOARD copy/paste through menu bar commands.
+(menu-bar-enable-clipboard)
+
+;; Override Paste so it looks at CLIPBOARD first.
+(defun x-clipboard-yank ()
+ "Insert the clipboard contents, or the last stretch of killed text."
+ (interactive)
+ (let ((clipboard-text (x-selection-value 'CLIPBOARD))
+ (x-select-enable-clipboard t))
+ (if (and clipboard-text (> (length clipboard-text) 0))
+ (kill-new clipboard-text))
+ (yank)))
+
+(define-key menu-bar-edit-menu [paste]
+ (cons "Paste" (cons "Paste text from clipboard or kill ring"
+ 'x-clipboard-yank)))
+
+;; Initiate drag and drop
+(add-hook 'after-make-frame-functions 'x-dnd-init-frame)
+(global-set-key [drag-n-drop] 'x-dnd-handle-drag-n-drop-event)
+
;;; arch-tag: f1501302-db8b-4d95-88e3-116697d89f78
;;; x-win.el ends here