Mercurial > emacs
comparison lisp/term/mac-win.el @ 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 | 1b44d34506e4 |
children | eaa9acd9122c |
comparison
equal
deleted
inserted
replaced
62099:d1245d218964 | 62100:e5deb8b3a701 |
---|---|
1166 | 1166 |
1167 ;;; Make TEXT, a string, the primary X selection. | 1167 ;;; Make TEXT, a string, the primary X selection. |
1168 (defun x-select-text (text &optional push) | 1168 (defun x-select-text (text &optional push) |
1169 (x-set-selection 'PRIMARY text) | 1169 (x-set-selection 'PRIMARY text) |
1170 (setq x-last-selected-text-primary text) | 1170 (setq x-last-selected-text-primary text) |
1171 (when x-select-enable-clipboard | 1171 (if (not x-select-enable-clipboard) |
1172 (setq x-last-selected-text-clipboard nil) | |
1172 (x-set-selection 'CLIPBOARD text) | 1173 (x-set-selection 'CLIPBOARD text) |
1173 (setq x-last-selected-text-clipboard text)) | 1174 (setq x-last-selected-text-clipboard text)) |
1174 ) | 1175 ) |
1175 | 1176 |
1176 (defun x-get-selection (&optional type data-type) | 1177 (defun x-get-selection (&optional type data-type) |
1201 (setq data (decode-coding-string encoded coding)) | 1202 (setq data (decode-coding-string encoded coding)) |
1202 (setq last-coding-system-used coding-save)) | 1203 (setq last-coding-system-used coding-save)) |
1203 (setq data | 1204 (setq data |
1204 (decode-coding-string data 'utf-16))))) | 1205 (decode-coding-string data 'utf-16))))) |
1205 ((eq data-type 'com.apple.traditional-mac-plain-text) | 1206 ((eq data-type 'com.apple.traditional-mac-plain-text) |
1206 (setq data (decode-coding-string data coding)))) | 1207 (setq data (decode-coding-string data coding))) |
1208 ((eq data-type 'public.file-url) | |
1209 (setq data (decode-coding-string data 'utf-8)) | |
1210 ;; Remove a trailing nul character. | |
1211 (let ((len (length data))) | |
1212 (if (and (> len 0) (= (aref data (1- len)) ?\0)) | |
1213 (setq data (substring data 0 (1- len))))))) | |
1207 (put-text-property 0 (length data) 'foreign-selection data-type data)) | 1214 (put-text-property 0 (length data) 'foreign-selection data-type data)) |
1208 data)) | 1215 data)) |
1209 | 1216 |
1210 (defun x-selection-value (type) | 1217 (defun x-selection-value (type) |
1211 (let (text tiff-image) | 1218 (let ((data-types '(public.utf16-plain-text |
1212 (setq text (condition-case nil | 1219 com.apple.traditional-mac-plain-text |
1213 (x-get-selection type 'public.utf16-plain-text) | 1220 public.file-url)) |
1214 (error nil))) | 1221 text tiff-image) |
1215 (if (not text) | 1222 (while (and (null text) data-types) |
1216 (setq text (condition-case nil | 1223 (setq text (condition-case nil |
1217 (x-get-selection type | 1224 (x-get-selection type (car data-types)) |
1218 'com.apple.traditional-mac-plain-text) | 1225 (error nil))) |
1219 (error nil)))) | 1226 (setq data-types (cdr data-types))) |
1220 (if text | 1227 (if text |
1221 (remove-text-properties 0 (length text) '(foreign-selection nil) text)) | 1228 (remove-text-properties 0 (length text) '(foreign-selection nil) text)) |
1222 (setq tiff-image (condition-case nil | 1229 (setq tiff-image (condition-case nil |
1223 (x-get-selection type 'public.tiff) | 1230 (x-get-selection type 'public.tiff) |
1224 (error nil))) | 1231 (error nil))) |
1235 ;;; If this function is called twice and finds the same text, | 1242 ;;; If this function is called twice and finds the same text, |
1236 ;;; it returns nil the second time. This is so that a single | 1243 ;;; it returns nil the second time. This is so that a single |
1237 ;;; selection won't be added to the kill ring over and over. | 1244 ;;; selection won't be added to the kill ring over and over. |
1238 (defun x-get-selection-value () | 1245 (defun x-get-selection-value () |
1239 (let (clip-text primary-text) | 1246 (let (clip-text primary-text) |
1240 (when x-select-enable-clipboard | 1247 (if (not x-select-enable-clipboard) |
1248 (setq x-last-selected-text-clipboard nil) | |
1241 (setq clip-text (x-selection-value 'CLIPBOARD)) | 1249 (setq clip-text (x-selection-value 'CLIPBOARD)) |
1242 (if (string= clip-text "") (setq clip-text nil)) | 1250 (if (string= clip-text "") (setq clip-text nil)) |
1243 | 1251 |
1244 ;; Check the CLIPBOARD selection for 'newness', is it different | 1252 ;; Check the CLIPBOARD selection for 'newness', is it different |
1245 ;; from what we remebered them to be last time we did a | 1253 ;; from what we remebered them to be last time we did a |
1284 ;; non-null one). | 1292 ;; non-null one). |
1285 (or clip-text primary-text) | 1293 (or clip-text primary-text) |
1286 )) | 1294 )) |
1287 | 1295 |
1288 (put 'CLIPBOARD 'mac-scrap-name "com.apple.scrap.clipboard") | 1296 (put 'CLIPBOARD 'mac-scrap-name "com.apple.scrap.clipboard") |
1289 (if (eq system-type 'darwin) | 1297 (when (eq system-type 'darwin) |
1290 (put 'FIND 'mac-scrap-name "com.apple.scrap.find")) | 1298 (put 'FIND 'mac-scrap-name "com.apple.scrap.find") |
1299 (put 'PRIMARY 'mac-scrap-name | |
1300 (format "org.gnu.Emacs.%d.selection.PRIMARY" (emacs-pid)))) | |
1291 (put 'com.apple.traditional-mac-plain-text 'mac-ostype "TEXT") | 1301 (put 'com.apple.traditional-mac-plain-text 'mac-ostype "TEXT") |
1292 (put 'public.utf16-plain-text 'mac-ostype "utxt") | 1302 (put 'public.utf16-plain-text 'mac-ostype "utxt") |
1293 (put 'public.tiff 'mac-ostype "TIFF") | 1303 (put 'public.tiff 'mac-ostype "TIFF") |
1304 (put 'public.file-url 'mac-ostype "furl") | |
1294 | 1305 |
1295 (defun mac-select-convert-to-string (selection type value) | 1306 (defun mac-select-convert-to-string (selection type value) |
1296 (let ((str (cdr (xselect-convert-to-string selection nil value))) | 1307 (let ((str (cdr (xselect-convert-to-string selection nil value))) |
1297 coding) | 1308 coding) |
1298 (setq coding (or next-selection-coding-system selection-coding-system)) | 1309 (setq coding (or next-selection-coding-system selection-coding-system)) |
1324 ))) | 1335 ))) |
1325 | 1336 |
1326 (setq next-selection-coding-system nil) | 1337 (setq next-selection-coding-system nil) |
1327 (cons type str)))) | 1338 (cons type str)))) |
1328 | 1339 |
1340 (defun mac-select-convert-to-file-url (selection type value) | |
1341 (let ((filename (xselect-convert-to-filename selection type value)) | |
1342 (coding (or file-name-coding-system default-file-name-coding-system))) | |
1343 (if (and filename coding) | |
1344 (setq filename (encode-coding-string filename coding))) | |
1345 (and filename | |
1346 (concat "file://localhost" | |
1347 (mapconcat 'url-hexify-string | |
1348 (split-string filename "/") "/"))))) | |
1349 | |
1329 (setq selection-converter-alist | 1350 (setq selection-converter-alist |
1330 (nconc | 1351 (nconc |
1331 '((public.utf16-plain-text . mac-select-convert-to-string) | 1352 '((public.utf16-plain-text . mac-select-convert-to-string) |
1332 (com.apple.traditional-mac-plain-text . mac-select-convert-to-string) | 1353 (com.apple.traditional-mac-plain-text . mac-select-convert-to-string) |
1333 ;; This is not enabled by default because the `Import Image' | 1354 ;; This is not enabled by default because the `Import Image' |
1334 ;; menu makes Emacs crash or hang for unknown reasons. | 1355 ;; menu makes Emacs crash or hang for unknown reasons. |
1335 ;; (public.tiff . nil) | 1356 ;; (public.tiff . nil) |
1357 (public.file-url . mac-select-convert-to-file-url) | |
1336 ) | 1358 ) |
1337 selection-converter-alist)) | 1359 selection-converter-alist)) |
1338 | 1360 |
1339 (defun mac-services-open-file () | 1361 (defun mac-services-open-file () |
1340 (interactive) | 1362 (interactive) |
1700 | 1722 |
1701 ;;; Arrange for the kill and yank functions to set and check the clipboard. | 1723 ;;; Arrange for the kill and yank functions to set and check the clipboard. |
1702 (setq interprogram-cut-function 'x-select-text) | 1724 (setq interprogram-cut-function 'x-select-text) |
1703 (setq interprogram-paste-function 'x-get-selection-value) | 1725 (setq interprogram-paste-function 'x-get-selection-value) |
1704 | 1726 |
1727 (defalias 'x-cut-buffer-or-selection-value 'x-get-selection-value) | |
1705 | 1728 |
1706 ;;; Turn off window-splitting optimization; Mac is usually fast enough | 1729 ;;; Turn off window-splitting optimization; Mac is usually fast enough |
1707 ;;; that this is only annoying. | 1730 ;;; that this is only annoying. |
1708 (setq split-window-keep-point t) | 1731 (setq split-window-keep-point t) |
1709 | 1732 |
1754 ;; has been created: this is where the files should be opened. | 1777 ;; has been created: this is where the files should be opened. |
1755 (add-hook 'after-init-hook | 1778 (add-hook 'after-init-hook |
1756 '(lambda () | 1779 '(lambda () |
1757 (defvar mac-ready-for-drag-n-drop t))) | 1780 (defvar mac-ready-for-drag-n-drop t))) |
1758 | 1781 |
1759 ;;;; Scroll bars | 1782 ;;;; Non-toolkit Scroll bars |
1783 | |
1784 (unless x-toolkit-scroll-bars | |
1760 | 1785 |
1761 ;; for debugging | 1786 ;; for debugging |
1762 ;; (defun mac-handle-scroll-bar-event (event) (interactive "e") (princ event)) | 1787 ;; (defun mac-handle-scroll-bar-event (event) (interactive "e") (princ event)) |
1763 | 1788 |
1764 ;;(global-set-key [vertical-scroll-bar mouse-1] 'mac-handle-scroll-bar-event) | 1789 ;;(global-set-key [vertical-scroll-bar mouse-1] 'mac-handle-scroll-bar-event) |
1814 (defun mac-scroll-up-line () | 1839 (defun mac-scroll-up-line () |
1815 (track-mouse | 1840 (track-mouse |
1816 (mac-scroll-ignore-events) | 1841 (mac-scroll-ignore-events) |
1817 (scroll-up 1))) | 1842 (scroll-up 1))) |
1818 | 1843 |
1844 ) | |
1819 | 1845 |
1820 ;;;; Others | 1846 ;;;; Others |
1821 | 1847 |
1822 (unless (eq system-type 'darwin) | 1848 (unless (eq system-type 'darwin) |
1823 ;; This variable specifies the Unix program to call (as a process) to | 1849 ;; This variable specifies the Unix program to call (as a process) to |