comparison lisp/term/mac-win.el @ 90070:95879cc1ed20

Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-81 Merge from emacs--cvs-trunk--0 Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-748 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-749 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-750 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-751 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-753 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-754 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-755 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-757 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-78 Merge from emacs--cvs-trunk--0 * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-79 - miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-80 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-81 Merge from emacs--cvs-trunk--0 * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-82 Update from CVS
author Miles Bader <miles@gnu.org>
date Sun, 02 Jan 2005 09:13:19 +0000
parents f2ebccfa87d4 d6563f85d9e5
children 6d92d69fae33
comparison
equal deleted inserted replaced
90069:fa0a5c4db2c8 90070:95879cc1ed20
1 ;;; mac-win.el --- support for "Macintosh windows" 1 ;;; mac-win.el --- parse switches controlling interface with Mac window system
2 2
3 ;; Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc. 3 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
4 4
5 ;; Author: Andrew Choi <akochoi@mac.com> 5 ;; Author: Andrew Choi <akochoi@mac.com>
6 ;; Keywords: terminals
6 7
7 ;; This file is part of GNU Emacs. 8 ;; This file is part of GNU Emacs.
8 9
9 ;; GNU Emacs is free software; you can redistribute it and/or modify 10 ;; 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 ;; it under the terms of the GNU General Public License as published by
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA. 23 ;; Boston, MA 02111-1307, USA.
23 24
24 ;;; Commentary: 25 ;;; Commentary:
25 26
27 ;; Mac-win.el: this file is loaded from ../lisp/startup.el when it recognizes
28 ;; that Mac windows are to be used. Command line switches are parsed and those
29 ;; pertaining to Mac are processed and removed from the command line. The
30 ;; Mac display is opened and hooks are set for popping up the initial window.
31
32 ;; startup.el will then examine startup files, and eventually call the hooks
33 ;; which create the first window(s).
34
26 ;;; Code: 35 ;;; Code:
27 36
28 ;; --------------------------------------------------------------------------- 37 ;; These are the standard X switches from the Xt Initialize.c file of
29 ;; We want to delay setting frame parameters until the faces are setup 38 ;; Release 4.
30 39
31 ;; Mac can't handle ~ prefix in file names 40 ;; Command line Resource Manager string
32 ;(setq auto-save-list-file-prefix ".saves-") 41
33 42 ;; +rv *reverseVideo
34 (setq frame-creation-function 'x-create-frame-with-faces) 43 ;; +synchronous *synchronous
35 44 ;; -background *background
36 ;; for debugging 45 ;; -bd *borderColor
37 ;; (defun mac-handle-scroll-bar-event (event) (interactive "e") (princ event)) 46 ;; -bg *background
38 47 ;; -bordercolor *borderColor
39 ;;(global-set-key [vertical-scroll-bar mouse-1] 'mac-handle-scroll-bar-event) 48 ;; -borderwidth .borderWidth
40 49 ;; -bw .borderWidth
41 (global-set-key 50 ;; -display .display
42 [vertical-scroll-bar down-mouse-1] 51 ;; -fg *foreground
43 'mac-handle-scroll-bar-event) 52 ;; -fn *font
44 53 ;; -font *font
45 (global-unset-key [vertical-scroll-bar drag-mouse-1]) 54 ;; -foreground *foreground
46 (global-unset-key [vertical-scroll-bar mouse-1]) 55 ;; -geometry .geometry
47 56 ;; -i .iconType
57 ;; -itype .iconType
58 ;; -iconic .iconic
59 ;; -name .name
60 ;; -reverse *reverseVideo
61 ;; -rv *reverseVideo
62 ;; -selectionTimeout .selectionTimeout
63 ;; -synchronous *synchronous
64 ;; -xrm
65
66 ;; An alist of X options and the function which handles them. See
67 ;; ../startup.el.
68
69 (if (not (eq window-system 'mac))
70 (error "%s: Loading mac-win.el but not compiled for Mac" (invocation-name)))
71
72 (require 'frame)
73 (require 'mouse)
48 (require 'scroll-bar) 74 (require 'scroll-bar)
49 75 (require 'faces)
50 (defun mac-handle-scroll-bar-event (event) 76 ;;(require 'select)
51 "Handle scroll bar EVENT to emulate Mac Toolbox style scrolling." 77 (require 'menu-bar)
52 (interactive "e") 78 (require 'fontset)
53 (let* ((position (event-start event)) 79 (require 'x-dnd)
54 (window (nth 0 position)) 80
55 (bar-part (nth 4 position))) 81 (defvar x-invocation-args)
56 (select-window window) 82
57 (cond 83 (defvar x-command-line-resources nil)
58 ((eq bar-part 'up) 84
59 (goto-char (window-start window)) 85 ;; Handler for switches of the form "-switch value" or "-switch".
60 (mac-scroll-down-line)) 86 (defun x-handle-switch (switch)
61 ((eq bar-part 'above-handle) 87 (let ((aelt (assoc switch command-line-x-option-alist)))
62 (mac-scroll-down)) 88 (if aelt
63 ((eq bar-part 'handle) 89 (let ((param (nth 3 aelt))
64 (scroll-bar-drag event)) 90 (value (nth 4 aelt)))
65 ((eq bar-part 'below-handle) 91 (if value
66 (mac-scroll-up)) 92 (setq default-frame-alist
67 ((eq bar-part 'down) 93 (cons (cons param value)
68 (goto-char (window-start window)) 94 default-frame-alist))
69 (mac-scroll-up-line))))) 95 (setq default-frame-alist
70 96 (cons (cons param
71 (defun mac-scroll-ignore-events () 97 (car x-invocation-args))
72 ;; Ignore confusing non-mouse events 98 default-frame-alist)
73 (while (not (memq (car-safe (read-event)) 99 x-invocation-args (cdr x-invocation-args)))))))
74 '(mouse-1 double-mouse-1 triple-mouse-1))) nil)) 100
75 101 ;; Handler for switches of the form "-switch n"
76 (defun mac-scroll-down () 102 (defun x-handle-numeric-switch (switch)
77 (track-mouse 103 (let ((aelt (assoc switch command-line-x-option-alist)))
78 (mac-scroll-ignore-events) 104 (if aelt
79 (scroll-down))) 105 (let ((param (nth 3 aelt)))
80 106 (setq default-frame-alist
81 (defun mac-scroll-down-line () 107 (cons (cons param
82 (track-mouse 108 (string-to-int (car x-invocation-args)))
83 (mac-scroll-ignore-events) 109 default-frame-alist)
84 (scroll-down 1))) 110 x-invocation-args
85 111 (cdr x-invocation-args))))))
86 (defun mac-scroll-up () 112
87 (track-mouse 113 ;; Handle options that apply to initial frame only
88 (mac-scroll-ignore-events) 114 (defun x-handle-initial-switch (switch)
89 (scroll-up))) 115 (let ((aelt (assoc switch command-line-x-option-alist)))
90 116 (if aelt
91 (defun mac-scroll-up-line () 117 (let ((param (nth 3 aelt))
92 (track-mouse 118 (value (nth 4 aelt)))
93 (mac-scroll-ignore-events) 119 (if value
94 (scroll-up 1))) 120 (setq initial-frame-alist
95 121 (cons (cons param value)
96 (defun xw-defined-colors (&optional frame) 122 initial-frame-alist))
97 "Internal function called by `defined-colors', which see." 123 (setq initial-frame-alist
98 (or frame (setq frame (selected-frame))) 124 (cons (cons param
99 (let ((all-colors x-colors) 125 (car x-invocation-args))
100 (this-color nil) 126 initial-frame-alist)
101 (defined-colors nil)) 127 x-invocation-args (cdr x-invocation-args)))))))
102 (while all-colors 128
103 (setq this-color (car all-colors) 129 ;; Make -iconic apply only to the initial frame!
104 all-colors (cdr all-colors)) 130 (defun x-handle-iconic (switch)
105 (and (color-supported-p this-color frame t) 131 (setq initial-frame-alist
106 (setq defined-colors (cons this-color defined-colors)))) 132 (cons '(visibility . icon) initial-frame-alist)))
107 defined-colors)) 133
108 134 ;; Handle the -xrm option.
109 ;; Don't have this yet. 135 (defun x-handle-xrm-switch (switch)
110 (fset 'x-get-resource 'ignore) 136 (unless (consp x-invocation-args)
111 137 (error "%s: missing argument to `%s' option" (invocation-name) switch))
112 (unless (eq system-type 'darwin) 138 (setq x-command-line-resources
113 ;; This variable specifies the Unix program to call (as a process) to 139 (if (null x-command-line-resources)
114 ;; deteremine the amount of free space on a file system (defaults to 140 (car x-invocation-args)
115 ;; df). If it is not set to nil, ls-lisp will not work correctly 141 (concat x-command-line-resources "\n" (car x-invocation-args))))
116 ;; unless an external application df is implemented on the Mac. 142 (setq x-invocation-args (cdr x-invocation-args)))
117 (setq directory-free-space-program nil) 143
118 144 ;; Handle the geometry option
119 ;; Set this so that Emacs calls subprocesses with "sh" as shell to 145 (defun x-handle-geometry (switch)
120 ;; expand filenames Note no subprocess for the shell is actually 146 (let* ((geo (x-parse-geometry (car x-invocation-args)))
121 ;; started (see run_mac_command in sysdep.c). 147 (left (assq 'left geo))
122 (setq shell-file-name "sh")) 148 (top (assq 'top geo))
123 149 (height (assq 'height geo))
124 ;; X Window emulation in macterm.c is not complete enough to start a 150 (width (assq 'width geo)))
125 ;; frame without a minibuffer properly. Call this to tell ediff 151 (if (or height width)
126 ;; library to use a single frame. 152 (setq default-frame-alist
127 ; (ediff-toggle-multiframe) 153 (append default-frame-alist
128 154 '((user-size . t))
129 ;; Setup to use the Mac clipboard. The functions mac-cut-function and 155 (if height (list height))
130 ;; mac-paste-function are defined in mac.c. 156 (if width (list width)))
131 (set-selection-coding-system 'compound-text-mac) 157 initial-frame-alist
132 158 (append initial-frame-alist
133 (setq interprogram-cut-function 159 '((user-size . t))
134 '(lambda (str push) 160 (if height (list height))
135 (mac-cut-function 161 (if width (list width)))))
136 (encode-coding-string str selection-coding-system t) push))) 162 (if (or left top)
137 163 (setq initial-frame-alist
138 (setq interprogram-paste-function 164 (append initial-frame-alist
139 '(lambda () 165 '((user-position . t))
140 (let ((clipboard (mac-paste-function))) 166 (if left (list left))
141 (if clipboard 167 (if top (list top)))))
142 (decode-coding-string clipboard selection-coding-system t))))) 168 (setq x-invocation-args (cdr x-invocation-args))))
143 169
144 ;; Don't show the frame name; that's redundant. 170 ;; Handle the -name option. Set the variable x-resource-name
145 (setq-default mode-line-frame-identification " ") 171 ;; to the option's operand; set the name of
146 172 ;; the initial frame, too.
147 (defun mac-drag-n-drop (event) 173 (defun x-handle-name-switch (switch)
148 "Edit the files listed in the drag-n-drop event.\n\ 174 (or (consp x-invocation-args)
149 Switch to a buffer editing the last file dropped." 175 (error "%s: missing argument to `%s' option" (invocation-name) switch))
150 (interactive "e") 176 (setq x-resource-name (car x-invocation-args)
151 (save-excursion 177 x-invocation-args (cdr x-invocation-args))
152 ;; Make sure the drop target has positive co-ords 178 (setq initial-frame-alist (cons (cons 'name x-resource-name)
153 ;; before setting the selected frame - otherwise it 179 initial-frame-alist)))
154 ;; won't work. <skx@tardis.ed.ac.uk> 180
155 (let* ((window (posn-window (event-start event))) 181 (defvar x-display-name nil
156 (coords (posn-x-y (event-start event))) 182 "The display name specifying server and frame.")
157 (x (car coords)) 183
158 (y (cdr coords))) 184 (defun x-handle-display (switch)
159 (if (and (> x 0) (> y 0)) 185 (setq x-display-name (car x-invocation-args)
160 (set-frame-selected-window nil window)) 186 x-invocation-args (cdr x-invocation-args)))
161 (mapcar 187
162 '(lambda (file) 188 (defun x-handle-args (args)
163 (find-file 189 "Process the X-related command line options in ARGS.
164 (decode-coding-string 190 This is done before the user's startup file is loaded. They are copied to
165 file 191 `x-invocation-args', from which the X-related things are extracted, first
166 (or file-name-coding-system 192 the switch (e.g., \"-fg\") in the following code, and possible values
167 default-file-name-coding-system)))) 193 \(e.g., \"black\") in the option handler code (e.g., x-handle-switch).
168 (car (cdr (cdr event))))) 194 This function returns ARGS minus the arguments that have been processed."
169 (raise-frame) 195 ;; We use ARGS to accumulate the args that we don't handle here, to return.
170 (recenter))) 196 (setq x-invocation-args args
171 197 args nil)
172 (global-set-key [drag-n-drop] 'mac-drag-n-drop) 198 (while (and x-invocation-args
173 199 (not (equal (car x-invocation-args) "--")))
174 ;; By checking whether the variable mac-ready-for-drag-n-drop has been 200 (let* ((this-switch (car x-invocation-args))
175 ;; defined, the event loop in macterm.c can be informed that it can 201 (orig-this-switch this-switch)
176 ;; now receive Finder drag and drop events. Files dropped onto the 202 completion argval aelt handler)
177 ;; Emacs application icon can only be processed when the initial frame 203 (setq x-invocation-args (cdr x-invocation-args))
178 ;; has been created: this is where the files should be opened. 204 ;; Check for long options with attached arguments
179 (add-hook 'after-init-hook 205 ;; and separate out the attached option argument into argval.
180 '(lambda () 206 (if (string-match "^--[^=]*=" this-switch)
181 (defvar mac-ready-for-drag-n-drop t))) 207 (setq argval (substring this-switch (match-end 0))
182 208 this-switch (substring this-switch 0 (1- (match-end 0)))))
183 ; Define constant values to be set to mac-keyboard-text-encoding 209 ;; Complete names of long options.
184 (defconst kTextEncodingMacRoman 0) 210 (if (string-match "^--" this-switch)
185 (defconst kTextEncodingISOLatin1 513 "0x201") 211 (progn
186 (defconst kTextEncodingISOLatin2 514 "0x202") 212 (setq completion (try-completion this-switch command-line-x-option-alist))
187 213 (if (eq completion t)
188 214 ;; Exact match for long option.
189 ;; Create a fontset that uses mac-roman font. With this fontset, 215 nil
190 ;; characters decoded from mac-roman encoding (ascii, latin-iso8859-1, 216 (if (stringp completion)
191 ;; and mule-unicode-xxxx-yyyy) are displayed by a mac-roman font. 217 (let ((elt (assoc completion command-line-x-option-alist)))
192 ;; Unnecessary in emacs22 218 ;; Check for abbreviated long option.
193 219 (or elt
194 ;; Carbon uses different fonts than commonly found on X, so 220 (error "Option `%s' is ambiguous" this-switch))
195 ;; we define our own standard fontset here. 221 (setq this-switch completion))))))
196 (defvar mac-standard-fontset-spec 222 (setq aelt (assoc this-switch command-line-x-option-alist))
197 "-apple-Monaco-normal-r-*-*-12-*-*-*-*-*-fontset-mac" 223 (if aelt (setq handler (nth 2 aelt)))
198 "String of fontset spec of the standard fontset. 224 (if handler
199 This defines a fontset consisting of the Monaco variations for 225 (if argval
200 European languages which are distributed with Mac OS X. 226 (let ((x-invocation-args
201 227 (cons argval x-invocation-args)))
202 See the documentation of `create-fontset-from-fontset-spec for the format.") 228 (funcall handler this-switch))
203 229 (funcall handler this-switch))
204 230 (setq args (cons orig-this-switch args)))))
205 (if (fboundp 'new-fontset) 231 (nconc (nreverse args) x-invocation-args))
206 (progn 232
207 (require 'fontset)
208 ;; Setup the default fontset.
209 (setup-default-fontset)
210 ;; Create the standard fontset.
211 (create-fontset-from-fontset-spec mac-standard-fontset-spec t)
212 ))
213
214
215 (if (eq system-type 'darwin)
216 ;; On Darwin filenames are encoded in UTF-8
217 (setq file-name-coding-system 'utf-8)
218 ;; To display filenames in Chinese or Japanese, replace mac-roman with
219 ;; big5 or sjis
220 (setq file-name-coding-system 'mac-roman))
221
222 ;; If Emacs is started from the Finder, change the default directory
223 ;; to the user's home directory.
224 (if (string= default-directory "/")
225 (cd "~"))
226
227 ;; Tell Emacs to use pipes instead of pty's for processes because the
228 ;; latter sometimes lose characters. Pty support is compiled in since
229 ;; ange-ftp will not work without it.
230 (setq process-connection-type nil)
231
232 ;; Assume that fonts are always scalable on the Mac. This sometimes
233 ;; results in characters with jagged edges. However, without it,
234 ;; fonts with both truetype and bitmap representations but no italic
235 ;; or bold bitmap versions will not display these variants correctly.
236 (setq scalable-fonts-allowed t)
237
238 ;; Make suspend-emacs [C-z] collapse the current frame
239 (substitute-key-definition 'suspend-emacs 'iconify-frame
240 global-map)
241
242 ;; Support mouse-wheel scrolling
243 (mouse-wheel-mode 1)
244
245 ;; (prefer-coding-system 'mac-roman)
246
247 ;; Map certain keypad keys into ASCII characters that people usually expect
248 (define-key function-key-map [return] [?\C-m])
249 (define-key function-key-map [M-return] [?\M-\C-m])
250 (define-key function-key-map [tab] [?\t])
251 (define-key function-key-map [M-tab] [?\M-\t])
252 (define-key function-key-map [backspace] [127])
253 (define-key function-key-map [M-backspace] [?\M-\d])
254 (define-key function-key-map [escape] [?\e])
255 (define-key function-key-map [M-escape] [?\M-\e])
256
257 ;; Tell read-char how to convert special chars to ASCII
258 (put 'return 'ascii-character 13)
259 (put 'tab 'ascii-character ?\t)
260 (put 'backspace 'ascii-character 127)
261 (put 'escape 'ascii-character ?\e)
262
263 ;; 233 ;;
264 ;; Available colors 234 ;; Available colors
265 ;; 235 ;;
266 236
267 (defvar x-colors '("LightGreen" 237 (defvar x-colors '("LightGreen"
1014 "WhiteSmoke" 984 "WhiteSmoke"
1015 "white smoke" 985 "white smoke"
1016 "GhostWhite" 986 "GhostWhite"
1017 "ghost white" 987 "ghost white"
1018 "snow") 988 "snow")
1019 "The list of X colors from the `rgb.txt' file. 989 "The list of X colors from the `rgb.txt' file.
1020 XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp") 990 XConsortium: rgb.txt,v 10.41 94/02/20 18:39:36 rws Exp")
991
992 (defun xw-defined-colors (&optional frame)
993 "Internal function called by `defined-colors', which see."
994 (or frame (setq frame (selected-frame)))
995 (let ((all-colors x-colors)
996 (this-color nil)
997 (defined-colors nil))
998 (while all-colors
999 (setq this-color (car all-colors)
1000 all-colors (cdr all-colors))
1001 (and (color-supported-p this-color frame t)
1002 (setq defined-colors (cons this-color defined-colors))))
1003 defined-colors))
1004
1005 ;;;; Function keys
1006
1007 (substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
1008 global-map)
1009
1010 ;; Map certain keypad keys into ASCII characters
1011 ;; that people usually expect.
1012 (define-key function-key-map [return] [?\C-m])
1013 (define-key function-key-map [M-return] [?\M-\C-m])
1014 (define-key function-key-map [tab] [?\t])
1015 (define-key function-key-map [M-tab] [?\M-\t])
1016 (define-key function-key-map [backspace] [127])
1017 (define-key function-key-map [M-backspace] [?\M-\d])
1018 (define-key function-key-map [escape] [?\e])
1019 (define-key function-key-map [M-escape] [?\M-\e])
1020
1021 ;; These tell read-char how to convert
1022 ;; these special chars to ASCII.
1023 (put 'return 'ascii-character 13)
1024 (put 'tab 'ascii-character ?\t)
1025 (put 'backspace 'ascii-character 127)
1026 (put 'escape 'ascii-character ?\e)
1027
1028
1029 ;;;; Keysyms
1030
1031 ;; Define constant values to be set to mac-keyboard-text-encoding
1032 (defconst kTextEncodingMacRoman 0)
1033 (defconst kTextEncodingISOLatin1 513 "0x201")
1034 (defconst kTextEncodingISOLatin2 514 "0x202")
1035
1036
1037 ;;;; Selections and cut buffers
1038
1039 ;; Setup to use the Mac clipboard. The functions mac-cut-function and
1040 ;; mac-paste-function are defined in mac.c.
1041 (set-selection-coding-system 'compound-text-mac)
1042
1043 (setq interprogram-cut-function
1044 '(lambda (str push)
1045 (mac-cut-function
1046 (encode-coding-string str selection-coding-system t) push)))
1047
1048 (setq interprogram-paste-function
1049 '(lambda ()
1050 (let ((clipboard (mac-paste-function)))
1051 (if clipboard
1052 (decode-coding-string clipboard selection-coding-system t)))))
1053
1054
1055 ;;; Do the actual Windows setup here; the above code just defines
1056 ;;; functions and variables that we use now.
1057
1058 (setq command-line-args (x-handle-args command-line-args))
1059
1060 ;;; Make sure we have a valid resource name.
1061 (or (stringp x-resource-name)
1062 (let (i)
1063 (setq x-resource-name (invocation-name))
1064
1065 ;; Change any . or * characters in x-resource-name to hyphens,
1066 ;; so as not to choke when we use it in X resource queries.
1067 (while (setq i (string-match "[.*]" x-resource-name))
1068 (aset x-resource-name i ?-))))
1069
1070 (if (x-display-list)
1071 ;; On Mac OS 8/9, Most coding systems used in code conversion for
1072 ;; font names are not ready at the time when the terminal frame is
1073 ;; created. So we reconstruct font name table for the initial
1074 ;; frame.
1075 (mac-clear-font-name-table)
1076 (x-open-connection "Mac"
1077 x-command-line-resources
1078 ;; Exit Emacs with fatal error if this fails.
1079 t))
1080
1081 (setq frame-creation-function 'x-create-frame-with-faces);; Setup the default fontset.
1082 (setup-default-fontset)
1083
1084 ;; Carbon uses different fonts than commonly found on X, so
1085 ;; we define our own standard fontset here.
1086 (defvar mac-standard-fontset-spec
1087 "-apple-Monaco-normal-r-*-*-12-*-*-*-*-*-fontset-mac"
1088 "String of fontset spec of the standard fontset.
1089 This defines a fontset consisting of the Monaco variations for
1090 European languages which are distributed with Mac OS X.
1091
1092 See the documentation of `create-fontset-from-fontset-spec for the format.")
1093
1094 ;; Create a fontset that uses mac-roman font. With this fontset,
1095 ;; characters decoded from mac-roman encoding (ascii, latin-iso8859-1,
1096 ;; and mule-unicode-xxxx-yyyy) are displayed by a mac-roman font.
1097 (create-fontset-from-fontset-spec mac-standard-fontset-spec t)
1098
1099 ;; Create fontset specified in X resources "Fontset-N" (N is 0, 1, ...).
1100 (create-fontset-from-x-resource)
1101
1102 ;; Try to create a fontset from a font specification which comes
1103 ;; from initial-frame-alist, default-frame-alist, or X resource.
1104 ;; A font specification in command line argument (i.e. -fn XXXX)
1105 ;; should be already in default-frame-alist as a `font'
1106 ;; parameter. However, any font specifications in site-start
1107 ;; library, user's init file (.emacs), and default.el are not
1108 ;; yet handled here.
1109
1110 (let ((font (or (cdr (assq 'font initial-frame-alist))
1111 (cdr (assq 'font default-frame-alist))
1112 (x-get-resource "font" "Font")))
1113 xlfd-fields resolved-name)
1114 (if (and font
1115 (not (query-fontset font))
1116 (setq resolved-name (x-resolve-font-name font))
1117 (setq xlfd-fields (x-decompose-font-name font)))
1118 (if (string= "fontset" (aref xlfd-fields xlfd-regexp-registry-subnum))
1119 (new-fontset font (x-complement-fontset-spec xlfd-fields nil))
1120 ;; Create a fontset from FONT. The fontset name is
1121 ;; generated from FONT.
1122 (create-fontset-from-ascii-font font resolved-name "startup"))))
1123
1124 ;; Apply a geometry resource to the initial frame. Put it at the end
1125 ;; of the alist, so that anything specified on the command line takes
1126 ;; precedence.
1127 (let* ((res-geometry (x-get-resource "geometry" "Geometry"))
1128 parsed)
1129 (if res-geometry
1130 (progn
1131 (setq parsed (x-parse-geometry res-geometry))
1132 ;; If the resource specifies a position,
1133 ;; call the position and size "user-specified".
1134 (if (or (assq 'top parsed) (assq 'left parsed))
1135 (setq parsed (cons '(user-position . t)
1136 (cons '(user-size . t) parsed))))
1137 ;; All geometry parms apply to the initial frame.
1138 (setq initial-frame-alist (append initial-frame-alist parsed))
1139 ;; The size parms apply to all frames.
1140 (if (assq 'height parsed)
1141 (setq default-frame-alist
1142 (cons (cons 'height (cdr (assq 'height parsed)))
1143 default-frame-alist)))
1144 (if (assq 'width parsed)
1145 (setq default-frame-alist
1146 (cons (cons 'width (cdr (assq 'width parsed)))
1147 default-frame-alist))))))
1148
1149 ;; Check the reverseVideo resource.
1150 (let ((case-fold-search t))
1151 (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
1152 (if (and rv
1153 (string-match "^\\(true\\|yes\\|on\\)$" rv))
1154 (setq default-frame-alist
1155 (cons '(reverse . t) default-frame-alist)))))
1156
1157 (defun x-win-suspend-error ()
1158 (error "Suspending an Emacs running under Mac makes no sense"))
1159 (add-hook 'suspend-hook 'x-win-suspend-error)
1160
1161 ;; Don't show the frame name; that's redundant.
1162 (setq-default mode-line-frame-identification " ")
1163
1164 ;; Turn on support for mouse wheels.
1165 (mouse-wheel-mode 1)
1166
1167 (defun mac-drag-n-drop (event)
1168 "Edit the files listed in the drag-n-drop EVENT.
1169 Switch to a buffer editing the last file dropped."
1170 (interactive "e")
1171 ;; Make sure the drop target has positive co-ords
1172 ;; before setting the selected frame - otherwise it
1173 ;; won't work. <skx@tardis.ed.ac.uk>
1174 (let* ((window (posn-window (event-start event)))
1175 (coords (posn-x-y (event-start event)))
1176 (x (car coords))
1177 (y (cdr coords)))
1178 (if (and (> x 0) (> y 0))
1179 (set-frame-selected-window nil window))
1180 (mapcar (lambda (file-name)
1181 (if (listp file-name)
1182 (let ((line (car file-name))
1183 (start (car (cdr file-name)))
1184 (end (car (cdr (cdr file-name)))))
1185 (if (> line 0)
1186 (goto-line line)
1187 (if (and (> start 0) (> end 0))
1188 (progn (set-mark start)
1189 (goto-char end)))))
1190 (x-dnd-handle-one-url window 'private
1191 (concat "file:" file-name))))
1192 (car (cdr (cdr event)))))
1193 (raise-frame))
1194
1195 (global-set-key [drag-n-drop] 'mac-drag-n-drop)
1196
1197 ;; By checking whether the variable mac-ready-for-drag-n-drop has been
1198 ;; defined, the event loop in macterm.c can be informed that it can
1199 ;; now receive Finder drag and drop events. Files dropped onto the
1200 ;; Emacs application icon can only be processed when the initial frame
1201 ;; has been created: this is where the files should be opened.
1202 (add-hook 'after-init-hook
1203 '(lambda ()
1204 (defvar mac-ready-for-drag-n-drop t)))
1205
1206 ;;;; Scroll bars
1207
1208 ;; for debugging
1209 ;; (defun mac-handle-scroll-bar-event (event) (interactive "e") (princ event))
1210
1211 ;;(global-set-key [vertical-scroll-bar mouse-1] 'mac-handle-scroll-bar-event)
1212
1213 (global-set-key
1214 [vertical-scroll-bar down-mouse-1]
1215 'mac-handle-scroll-bar-event)
1216
1217 (global-unset-key [vertical-scroll-bar drag-mouse-1])
1218 (global-unset-key [vertical-scroll-bar mouse-1])
1219
1220 (defun mac-handle-scroll-bar-event (event)
1221 "Handle scroll bar EVENT to emulate Mac Toolbox style scrolling."
1222 (interactive "e")
1223 (let* ((position (event-start event))
1224 (window (nth 0 position))
1225 (bar-part (nth 4 position)))
1226 (select-window window)
1227 (cond
1228 ((eq bar-part 'up)
1229 (goto-char (window-start window))
1230 (mac-scroll-down-line))
1231 ((eq bar-part 'above-handle)
1232 (mac-scroll-down))
1233 ((eq bar-part 'handle)
1234 (scroll-bar-drag event))
1235 ((eq bar-part 'below-handle)
1236 (mac-scroll-up))
1237 ((eq bar-part 'down)
1238 (goto-char (window-start window))
1239 (mac-scroll-up-line)))))
1240
1241 (defun mac-scroll-ignore-events ()
1242 ;; Ignore confusing non-mouse events
1243 (while (not (memq (car-safe (read-event))
1244 '(mouse-1 double-mouse-1 triple-mouse-1))) nil))
1245
1246 (defun mac-scroll-down ()
1247 (track-mouse
1248 (mac-scroll-ignore-events)
1249 (scroll-down)))
1250
1251 (defun mac-scroll-down-line ()
1252 (track-mouse
1253 (mac-scroll-ignore-events)
1254 (scroll-down 1)))
1255
1256 (defun mac-scroll-up ()
1257 (track-mouse
1258 (mac-scroll-ignore-events)
1259 (scroll-up)))
1260
1261 (defun mac-scroll-up-line ()
1262 (track-mouse
1263 (mac-scroll-ignore-events)
1264 (scroll-up 1)))
1265
1266
1267 ;;;; Others
1268
1269 (unless (eq system-type 'darwin)
1270 ;; This variable specifies the Unix program to call (as a process) to
1271 ;; deteremine the amount of free space on a file system (defaults to
1272 ;; df). If it is not set to nil, ls-lisp will not work correctly
1273 ;; unless an external application df is implemented on the Mac.
1274 (setq directory-free-space-program nil)
1275
1276 ;; Set this so that Emacs calls subprocesses with "sh" as shell to
1277 ;; expand filenames Note no subprocess for the shell is actually
1278 ;; started (see run_mac_command in sysdep.c).
1279 (setq shell-file-name "sh"))
1280
1281 ;; X Window emulation in macterm.c is not complete enough to start a
1282 ;; frame without a minibuffer properly. Call this to tell ediff
1283 ;; library to use a single frame.
1284 ; (ediff-toggle-multiframe)
1285
1286 (if (eq system-type 'darwin)
1287 ;; On Darwin filenames are encoded in UTF-8
1288 (setq file-name-coding-system 'utf-8)
1289 ;; To display filenames in Chinese or Japanese, replace mac-roman with
1290 ;; big5 or sjis
1291 (setq file-name-coding-system 'mac-roman))
1292
1293 ;; If Emacs is started from the Finder, change the default directory
1294 ;; to the user's home directory.
1295 (if (string= default-directory "/")
1296 (cd "~"))
1297
1298 ;; Tell Emacs to use pipes instead of pty's for processes because the
1299 ;; latter sometimes lose characters. Pty support is compiled in since
1300 ;; ange-ftp will not work without it.
1301 (setq process-connection-type nil)
1302
1303 ;; Assume that fonts are always scalable on the Mac. This sometimes
1304 ;; results in characters with jagged edges. However, without it,
1305 ;; fonts with both truetype and bitmap representations but no italic
1306 ;; or bold bitmap versions will not display these variants correctly.
1307 (setq scalable-fonts-allowed t)
1308
1309 ;; (prefer-coding-system 'mac-roman)
1021 1310
1022 ;;; arch-tag: 71dfcd14-cde8-4d66-b05c-85ec94fb23a6 1311 ;;; arch-tag: 71dfcd14-cde8-4d66-b05c-85ec94fb23a6
1023 ;;; mac-win.el ends here 1312 ;;; mac-win.el ends here