1 ;;; mac-win.el --- support for "Macintosh windows"
3 ;; Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
5 ;; Author: Andrew Choi <akochoi@mac.com>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 ;; ---------------------------------------------------------------------------
29 ;; We want to delay setting frame parameters until the faces are setup
31 ;; Mac can't handle ~ prefix in file names
32 ;(setq auto-save-list-file-prefix ".saves-")
34 (setq frame-creation-function 'x-create-frame-with-faces)
37 ;; (defun mac-handle-scroll-bar-event (event) (interactive "e") (princ event))
39 ;;(global-set-key [vertical-scroll-bar mouse-1] 'mac-handle-scroll-bar-event)
42 [vertical-scroll-bar down-mouse-1]
43 'mac-handle-scroll-bar-event)
45 (global-unset-key [vertical-scroll-bar drag-mouse-1])
46 (global-unset-key [vertical-scroll-bar mouse-1])
50 (defun mac-handle-scroll-bar-event (event)
51 "Handle scroll bar EVENT to emulate Mac Toolbox style scrolling."
53 (let* ((position (event-start event))
54 (window (nth 0 position))
55 (bar-part (nth 4 position)))
56 (select-window window)
59 (goto-char (window-start window))
60 (mac-scroll-down-line))
61 ((eq bar-part 'above-handle)
63 ((eq bar-part 'handle)
64 (scroll-bar-drag event))
65 ((eq bar-part 'below-handle)
68 (goto-char (window-start window))
69 (mac-scroll-up-line)))))
71 (defun mac-scroll-ignore-events ()
72 ;; Ignore confusing non-mouse events
73 (while (not (memq (car-safe (read-event))
74 '(mouse-1 double-mouse-1 triple-mouse-1))) nil))
76 (defun mac-scroll-down ()
78 (mac-scroll-ignore-events)
81 (defun mac-scroll-down-line ()
83 (mac-scroll-ignore-events)
86 (defun mac-scroll-up ()
88 (mac-scroll-ignore-events)
91 (defun mac-scroll-up-line ()
93 (mac-scroll-ignore-events)
96 (defun xw-defined-colors (&optional frame)
97 "Internal function called by `defined-colors', which see."
98 (or frame (setq frame (selected-frame)))
99 (let ((all-colors x-colors)
101 (defined-colors nil))
103 (setq this-color (car all-colors)
104 all-colors (cdr all-colors))
105 (and (color-supported-p this-color frame t)
106 (setq defined-colors (cons this-color defined-colors))))
109 ;; Don't have this yet.
110 (fset 'x-get-resource 'ignore)
112 (unless (eq system-type 'darwin)
113 ;; This variable specifies the Unix program to call (as a process) to
114 ;; deteremine the amount of free space on a file system (defaults to
115 ;; df). If it is not set to nil, ls-lisp will not work correctly
116 ;; unless an external application df is implemented on the Mac.
117 (setq directory-free-space-program nil)
119 ;; Set this so that Emacs calls subprocesses with "sh" as shell to
120 ;; expand filenames Note no subprocess for the shell is actually
121 ;; started (see run_mac_command in sysdep.c).
122 (setq shell-file-name "sh"))
124 ;; X Window emulation in macterm.c is not complete enough to start a
125 ;; frame without a minibuffer properly. Call this to tell ediff
126 ;; library to use a single frame.
127 ; (ediff-toggle-multiframe)
129 ;; Setup to use the Mac clipboard. The functions mac-cut-function and
130 ;; mac-paste-function are defined in mac.c.
131 (set-selection-coding-system 'compound-text-mac)
133 (setq interprogram-cut-function
136 (encode-coding-string str selection-coding-system t) push)))
138 (setq interprogram-paste-function
140 (let ((clipboard (mac-paste-function)))
142 (decode-coding-string clipboard selection-coding-system t)))))
144 (defun mac-drag-n-drop (event)
145 "Edit the files listed in the drag-n-drop event.\n\
146 Switch to a buffer editing the last file dropped."
149 ;; Make sure the drop target has positive co-ords
150 ;; before setting the selected frame - otherwise it
151 ;; won't work. <skx@tardis.ed.ac.uk>
152 (let* ((window (posn-window (event-start event)))
153 (coords (posn-x-y (event-start event)))
156 (if (and (> x 0) (> y 0))
157 (set-frame-selected-window nil window))
161 (decode-coding-string
163 (or file-name-coding-system
164 default-file-name-coding-system))))
165 (car (cdr (cdr event)))))
169 (global-set-key [drag-n-drop] 'mac-drag-n-drop)
171 ;; By checking whether the variable mac-ready-for-drag-n-drop has been
172 ;; defined, the event loop in macterm.c can be informed that it can
173 ;; now receive Finder drag and drop events. Files dropped onto the
174 ;; Emacs application icon can only be processed when the initial frame
175 ;; has been created: this is where the files should be opened.
176 (add-hook 'after-init-hook
178 (defvar mac-ready-for-drag-n-drop t)))
180 ; Define constant values to be set to mac-keyboard-text-encoding
181 (defconst kTextEncodingMacRoman 0)
182 (defconst kTextEncodingISOLatin1 513 "0x201")
183 (defconst kTextEncodingISOLatin2 514 "0x202")
186 (define-ccl-program ccl-encode-mac-roman-font
188 (if (r0 != ,(charset-id 'ascii))
189 (if (r0 == ,(charset-id 'latin-iso8859-1))
190 (translate-character mac-roman-encoder r0 r1)
193 (translate-character mac-roman-encoder r0 r1)))))
194 "CCL program for Mac Roman font")
196 (setq font-ccl-encoder-alist
197 (cons '("mac-roman" . ccl-encode-mac-roman-font)
198 font-ccl-encoder-alist))
200 ;; Create a fontset that uses mac-roman font. With this fontset,
201 ;; characters decoded from mac-roman encoding (ascii, latin-iso8859-1,
202 ;; and mule-unicode-xxxx-yyyy) are displayed by a mac-roman font.
204 (if (fboundp 'new-fontset)
207 (setup-default-fontset)
208 (create-fontset-from-fontset-spec
209 "-etl-fixed-medium-r-normal-*-16-*-*-*-*-*-fontset-mac,
210 ascii:-*-Monaco-*-*-*-*-12-*-*-*-*-*-mac-roman")
211 (let ((monaco-font '("monaco" . "mac-roman")))
215 (or (generic-char-p key)
216 (memq (char-charset val)
217 '(ascii eight-bit-control eight-bit-graphic))
218 (set-fontset-font "fontset-mac" val monaco-font))))
219 (get 'mac-roman-decoder 'translation-table)))))
221 (if (eq system-type 'darwin)
222 ;; On Darwin filenames are encoded in UTF-8
223 (setq file-name-coding-system 'utf-8)
224 ;; To display filenames in Chinese or Japanese, replace mac-roman with
226 (setq file-name-coding-system 'mac-roman))
228 ;; If Emacs is started from the Finder, change the default directory
229 ;; to the user's home directory.
230 (if (string= default-directory "/")
233 ;; Tell Emacs to use pipes instead of pty's for processes because the
234 ;; latter sometimes lose characters. Pty support is compiled in since
235 ;; ange-ftp will not work without it.
236 (setq process-connection-type nil)
238 ;; Assume that fonts are always scalable on the Mac. This sometimes
239 ;; results in characters with jagged edges. However, without it,
240 ;; fonts with both truetype and bitmap representations but no italic
241 ;; or bold bitmap versions will not display these variants correctly.
242 (setq scalable-fonts-allowed t)
244 ;; Make suspend-emacs [C-z] collapse the current frame
245 (substitute-key-definition 'suspend-emacs 'iconify-frame
248 ;; Support mouse-wheel scrolling
251 ;; (prefer-coding-system 'mac-roman)
253 ;; Map certain keypad keys into ASCII characters that people usually expect
254 (define-key function-key-map [return] [?\C-m])
255 (define-key function-key-map [M-return] [?\M-\C-m])
256 (define-key function-key-map [tab] [?\t])
257 (define-key function-key-map [M-tab] [?\M-\t])
258 (define-key function-key-map [backspace] [127])
259 (define-key function-key-map [M-backspace] [?\M-\d])
260 (define-key function-key-map [escape] [?\e])
261 (define-key function-key-map [M-escape] [?\M-\e])
263 ;; Tell read-char how to convert special chars to ASCII
264 (put 'return 'ascii-character 13)
270 (defvar x-colors '("LightGreen"
869 "LightGoldenrodYellow"
870 "light goldenrod yellow"
887 "medium spring green"
1022 "The list of X colors from the `rgb.txt' file.
1023 XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
1025 ;;; arch-tag: 71dfcd14-cde8-4d66-b05c-85ec94fb23a6
1026 ;;; mac-win.el ends here