changeset 62100:e5deb8b3a701

Don't define or bind scroll bar functions if x-toolkit-scroll-bars is t. (x-select-text, x-get-selection-value): Clear x-last-selected-text-clipboard if x-select-enable-clipboard is nil. (PRIMARY): Put mac-scrap-name property. (mac-select-convert-to-file-url): New function. (public.file-url): New selection target type. Add to selection-converter-alist. (x-get-selection, x-selection-value): Handle it. (x-cut-buffer-or-selection-value): New alias.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Fri, 06 May 2005 08:01:13 +0000
parents d1245d218964
children ad0379779256
files lisp/term/mac-win.el
diffstat 1 files changed, 41 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/term/mac-win.el	Fri May 06 00:27:50 2005 +0000
+++ b/lisp/term/mac-win.el	Fri May 06 08:01:13 2005 +0000
@@ -1168,7 +1168,8 @@
 (defun x-select-text (text &optional push)
   (x-set-selection 'PRIMARY text)
   (setq x-last-selected-text-primary text)
-  (when x-select-enable-clipboard
+  (if (not x-select-enable-clipboard)
+      (setq x-last-selected-text-clipboard nil)
     (x-set-selection 'CLIPBOARD text)
     (setq x-last-selected-text-clipboard text))
   )
@@ -1203,20 +1204,26 @@
 		 (setq data
 		       (decode-coding-string data 'utf-16)))))
 	    ((eq data-type 'com.apple.traditional-mac-plain-text)
-	     (setq data (decode-coding-string data coding))))
+	     (setq data (decode-coding-string data coding)))
+	    ((eq data-type 'public.file-url)
+	     (setq data (decode-coding-string data 'utf-8))
+	     ;; Remove a trailing nul character.
+	     (let ((len (length data)))
+	       (if (and (> len 0) (= (aref data (1- len)) ?\0))
+		   (setq data (substring data 0 (1- len)))))))
       (put-text-property 0 (length data) 'foreign-selection data-type data))
     data))
 
 (defun x-selection-value (type)
-  (let (text tiff-image)
-    (setq text (condition-case nil
-		   (x-get-selection type 'public.utf16-plain-text)
-		 (error nil)))
-    (if (not text)
-	(setq text (condition-case nil
-		       (x-get-selection type
-					'com.apple.traditional-mac-plain-text)
-		     (error nil))))
+  (let ((data-types '(public.utf16-plain-text
+		      com.apple.traditional-mac-plain-text
+		      public.file-url))
+	text tiff-image)
+    (while (and (null text) data-types)
+      (setq text (condition-case nil
+		     (x-get-selection type (car data-types))
+		   (error nil)))
+      (setq data-types (cdr data-types)))
     (if text
 	(remove-text-properties 0 (length text) '(foreign-selection nil) text))
     (setq tiff-image (condition-case nil
@@ -1237,7 +1244,8 @@
 ;;; selection won't be added to the kill ring over and over.
 (defun x-get-selection-value ()
   (let (clip-text primary-text)
-    (when x-select-enable-clipboard
+    (if (not x-select-enable-clipboard)
+	(setq x-last-selected-text-clipboard nil)
       (setq clip-text (x-selection-value 'CLIPBOARD))
       (if (string= clip-text "") (setq clip-text nil))
 
@@ -1286,11 +1294,14 @@
     ))
 
 (put 'CLIPBOARD 'mac-scrap-name "com.apple.scrap.clipboard")
-(if (eq system-type 'darwin)
-    (put 'FIND 'mac-scrap-name "com.apple.scrap.find"))
+(when (eq system-type 'darwin)
+  (put 'FIND 'mac-scrap-name "com.apple.scrap.find")
+  (put 'PRIMARY 'mac-scrap-name
+       (format "org.gnu.Emacs.%d.selection.PRIMARY" (emacs-pid))))
 (put 'com.apple.traditional-mac-plain-text 'mac-ostype "TEXT")
 (put 'public.utf16-plain-text 'mac-ostype "utxt")
 (put 'public.tiff 'mac-ostype "TIFF")
+(put 'public.file-url 'mac-ostype "furl")
 
 (defun mac-select-convert-to-string (selection type value)
   (let ((str (cdr (xselect-convert-to-string selection nil value)))
@@ -1326,6 +1337,16 @@
       (setq next-selection-coding-system nil)
       (cons type str))))
 
+(defun mac-select-convert-to-file-url (selection type value)
+  (let ((filename (xselect-convert-to-filename selection type value))
+	(coding (or file-name-coding-system default-file-name-coding-system)))
+    (if (and filename coding)
+	(setq filename (encode-coding-string filename coding)))
+    (and filename
+	 (concat "file://localhost"
+		 (mapconcat 'url-hexify-string
+			    (split-string filename "/") "/")))))
+
 (setq selection-converter-alist
       (nconc
        '((public.utf16-plain-text . mac-select-convert-to-string)
@@ -1333,6 +1354,7 @@
 	 ;; This is not enabled by default because the `Import Image'
 	 ;; menu makes Emacs crash or hang for unknown reasons.
 	 ;; (public.tiff . nil)
+	 (public.file-url . mac-select-convert-to-file-url)
 	 )
        selection-converter-alist))
 
@@ -1702,6 +1724,7 @@
 (setq interprogram-cut-function 'x-select-text)
 (setq interprogram-paste-function 'x-get-selection-value)
 
+(defalias 'x-cut-buffer-or-selection-value 'x-get-selection-value)
 
 ;;; Turn off window-splitting optimization; Mac is usually fast enough
 ;;; that this is only annoying.
@@ -1756,7 +1779,9 @@
 	  '(lambda ()
 	     (defvar mac-ready-for-drag-n-drop t)))
 
-;;;; Scroll bars
+;;;; Non-toolkit Scroll bars
+
+(unless x-toolkit-scroll-bars
 
 ;; for debugging
 ;; (defun mac-handle-scroll-bar-event (event) (interactive "e") (princ event))
@@ -1816,6 +1841,7 @@
     (mac-scroll-ignore-events)
     (scroll-up 1)))
 
+)
 
 ;;;; Others