]> code.delx.au - gnu-emacs/blob - man/macos.texi
(mouse-avoidance-point-position): Use posn-at-point instead of compute-motion.
[gnu-emacs] / man / macos.texi
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 2000, 2001, 2002, 2003, 2004,
3 @c 2005, 2006 Free Software Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5 @node Mac OS, Emacs and Microsoft Windows, Antinews, Top
6 @appendix Emacs and Mac OS
7 @cindex Mac OS
8 @cindex Macintosh
9
10 This section briefly describes the peculiarities of using Emacs
11 under Mac OS with native window system support. For Mac OS X, Emacs
12 can be built either without window system support, with X11, or with
13 Carbon API. This section only applies to the Carbon build. For Mac
14 OS Classic, Emacs can be built with or without Carbon API, and this
15 section applies to either of them because they run on the native
16 window system.
17
18 Emacs built on Mac OS X supports most of its major features except
19 display support of PostScript images. The following features of Emacs
20 are not supported on Mac OS Classic: unexec (@code{dump-emacs}),
21 asynchronous subprocesses (@code{start-process}), and networking
22 (@code{open-network-stream}). As a result, packages such as Gnus,
23 GUD, and Comint do not work. Synchronous subprocesses
24 (@code{call-process}) are supported on non-Carbon build, but
25 specially-crafted external programs are needed. Since external
26 programs to handle commands such as @code{print-buffer} and
27 @code{diff} are not available on Mac OS Classic, they are not
28 supported. Non-Carbon build on Mac OS Classic does not support some
29 features such as file dialogs, drag-and-drop, and Unicode menus.
30
31 @menu
32 * Input: Mac Input. Keyboard and mouse input on Mac.
33 * Intl: Mac International. International character sets on Mac.
34 * Env: Mac Environment Variables. Setting environment variables for Emacs.
35 * Directories: Mac Directories. Volumes and directories on Mac.
36 * Font: Mac Font Specs. Specifying fonts on Mac.
37 * Functions: Mac Functions. Mac-specific Lisp functions.
38 @end menu
39
40 @node Mac Input
41 @section Keyboard and Mouse Input on Mac
42 @cindex Meta (Mac OS)
43 @cindex keyboard coding (Mac OS)
44
45 @vindex mac-control-modifier
46 @vindex mac-command-modifier
47 @vindex mac-option-modifier
48 On Mac, Emacs can use @key{control}, @key{command}, and @key{option}
49 keys as any of Emacs modifier keys except @key{SHIFT} (i.e.,
50 @key{ALT}, @key{CTRL}, @key{HYPER}, @key{META}, and @key{SUPER}). The
51 assignment is controlled by the variables @code{mac-control-modifier},
52 @code{mac-command-modifier}, and @code{mac-option-modifier}. The
53 value for each of these variables can be one of the following symbols:
54 @code{alt}, @code{control}, @code{hyper}, @code{meta}, @code{super},
55 and @code{nil} (no particular assignment). By default, the
56 @key{control} key works as @key{CTRL}, and the @key{command} key as
57 @key{META}.
58
59 For the @key{option} key, if @code{mac-option-modifier} is set to
60 @code{nil}, which is the default, the key works as the normal
61 @key{option} key, i.e., dead-key processing will work. This is useful
62 for entering non-@acronym{ASCII} Latin characters directly from the
63 Mac keyboard, for example.
64
65 Emacs recognizes the setting in the Keyboard control panel (Mac OS
66 Classic) or the International system preference pane (Mac OS X) and
67 supports international and alternative keyboard layouts (e.g., Dvorak)
68 if its script is either Roman, Japanese, Traditional Chinese, Korean,
69 Cyrillic, Simplified Chinese, or Central European. Keyboard layouts
70 based on Unicode may not work properly. Selecting one of the layouts
71 from the keyboard layout pull-down menu will affect how the keys typed
72 on the keyboard are interpreted.
73
74 @vindex mac-pass-command-to-system
75 @vindex mac-pass-control-to-system
76 Mac OS intercepts and handles certain key combinations (e.g.,
77 @key{command}-@key{SPC} for switching input languages). These will not
78 be passed to Emacs. One can disable this interception by setting
79 @code{mac-pass-command-to-system} or @code{mac-pass-control-to-system}
80 to @code{nil}.
81
82 @vindex mac-emulate-three-button-mouse
83 Especially for one-button mice, the multiple button feature can be
84 emulated by setting @code{mac-emulate-three-button-mouse} to @code{t}
85 or @code{reverse}. If set to @code{t} (@code{reverse}, respectively),
86 pressing the mouse button with the @key{option} key is recognized as
87 the second (third) button, and that with the @key{command} key is
88 recognized as the third (second) button.
89
90 @vindex mac-wheel-button-is-mouse-2
91 For multi-button mice, the wheel button and the secondary button are
92 recognized as the second and the third button, respectively. If
93 @code{mac-wheel-button-is-mouse-2} is set to @code{nil}, their roles
94 are exchanged.
95
96 @node Mac International
97 @section International Character Set Support on Mac
98 @cindex Mac Roman coding system
99 @cindex clipboard support (Mac OS)
100
101 Mac uses non-standard encodings for the upper 128 single-byte
102 characters. They also deviate from the ISO 2022 standard by using
103 character codes in the range 128-159. The coding systems
104 @code{mac-roman}, @code{mac-centraleurroman}, and @code{mac-cyrillic}
105 are used to represent these Mac encodings.
106
107 You can use input methods provided either by LEIM (@pxref{Input
108 Methods}) or Mac OS to enter international characters. To use the
109 former, see the International Character Set Support section of the
110 manual (@pxref{International}).
111
112 Emacs on Mac OS automatically changes the value of
113 @code{keyboard-coding-system} according to the current keyboard
114 layout. So users don't need to set it manually, and even if set, it
115 will be changed when the keyboard layout change is detected next time.
116
117 The Mac clipboard and the Emacs kill ring (@pxref{Killing}) are
118 synchronized by default: you can yank a piece of text and paste it
119 into another Mac application, or cut or copy one in another Mac
120 application and yank it into a Emacs buffer. This feature can be
121 disabled by setting @code{x-select-enable-clipboard} to @code{nil}.
122 One can still do copy and paste with another application from the Edit
123 menu.
124
125 On Mac, the role of the coding system for selection that is set by
126 @code{set-selection-coding-system} (@pxref{Communication Coding}) is
127 two-fold. First, it is used as a preferred coding system for the
128 traditional text flavor that does not specify any particular encodings
129 and is mainly used by applications on Mac OS Classic. Second, it
130 specifies the intermediate encoding for the UTF-16 text flavor that is
131 mainly used by applications on Mac OS X.
132
133 When pasting UTF-16 text data from the clipboard, it is first
134 converted to the encoding specified by the selection coding system
135 using the converter in the Mac OS system, and then decoded into the
136 Emacs internal encoding using the converter in Emacs. If the first
137 conversion failed, then the UTF-16 data is directly converted to Emacs
138 internal encoding using the converter in Emacs. Copying UTF-16 text
139 to the clipboard goes through the inverse path. The reason for this
140 two-pass decoding is to avoid subtle differences in Unicode mappings
141 between the Mac OS system and Emacs such as various kinds of hyphens,
142 and to minimize users' customization. For example, users that mainly
143 use Latin characters would prefer Greek characters to be decoded into
144 the @code{mule-unicode-0100-24ff} charset, but Japanese users would
145 prefer them to be decoded into the @code{japanese-jisx0208} charset.
146 Since the coding system for selection is automatically set according
147 to the system locale setting, users usually don't have to set it
148 manually.
149
150 The default language environment (@pxref{Language Environments}) is
151 set according to the locale setting at the startup time. On Mac OS,
152 the locale setting is consulted in the following order:
153
154 @enumerate
155 @item
156 Environment variables @env{LC_ALL}, @env{LC_CTYPE} and @env{LANG} as
157 in other systems.
158
159 @item
160 Preference @code{AppleLocale} that is set by default on Mac OS X 10.3
161 and later.
162
163 @item
164 Preference @code{AppleLanguages} that is set by default on Mac OS X
165 10.1 and later.
166
167 @item
168 Variable @code{mac-system-locale} that is derived from the system
169 language and region codes. This variable is available on all
170 supported Mac OS versions including Mac OS Classic.
171 @end enumerate
172
173 The default values of almost all variables about coding systems are
174 also set according to the language environment. So usually you don't
175 have to customize these variables manually.
176
177 @node Mac Environment Variables
178 @section Environment Variables and Command Line Arguments.
179 @cindex environment variables (Mac OS)
180
181 On Mac OS X, when Emacs is run in a terminal, it inherits the values
182 of environment variables from the shell from which it is invoked.
183 However, when it is run from the Finder as a GUI application, it only
184 inherits environment variable values defined in the file
185 @file{~/.MacOSX/environment.plist} that affects all the applications
186 invoked from the Finder or the @command{open} command.
187
188 Command line arguments are specified like
189
190 @example
191 /Applications/Emacs.app/Contents/MacOS/Emacs -g 80x25 &
192 @end example
193
194 @noindent
195 if Emacs is installed at @file{/Applications/Emacs.app}. If Emacs is
196 invoked like this, then it also inherits the values of environment
197 variables from the shell from which it is invoked.
198
199 On Mac OS Classic, environment variables and command line arguments
200 for Emacs can be set by modifying the @samp{STR#} resources 128 and
201 129, respectively. A common environment variable that one may want to
202 set is @samp{HOME}.
203
204 The way to set an environment variable is by adding a string of the
205 form
206
207 @example
208 ENV_VAR=VALUE
209 @end example
210
211 @noindent
212 to resource @samp{STR#} number 128 using @code{ResEdit}. To set up the
213 program to use unibyte characters exclusively, for example, add the
214 string
215
216 @example
217 EMACS_UNIBYTE=1
218 @end example
219
220 @cindex Mac Preferences
221 Although Emacs on Mac does not support X resources (@pxref{X
222 Resources}) directly, one can use the Preferences system in place of X
223 resources. For example, adding the line
224
225 @example
226 Emacs.cursorType: bar
227 @end example
228
229 @noindent
230 to @file{~/.Xresources} in X11 corresponds to the execution of
231
232 @example
233 defaults write org.gnu.Emacs Emacs.cursorType bar
234 @end example
235
236 @noindent
237 on Mac OS X. One can use boolean or numeric values as well as string
238 values as follows:
239
240 @example
241 defaults write org.gnu.Emacs Emacs.toolBar -bool false
242 defaults write org.gnu.Emacs Emacs.lineSpacing -int 3
243 @end example
244
245 @noindent
246 Try @kbd{M-x man RET defaults RET} for the usage of the
247 @command{defaults} command. Alternatively, if you have Developer
248 Tools installed on Mac OS X, you can use Property List Editor to edit
249 the file @file{~/Library/Preferences/org.gnu.Emacs.plist}.
250
251
252 @node Mac Directories
253 @section Volumes and Directories on Mac
254 @cindex file names (Mac OS)
255
256 This node applies to Mac OS Classic only.
257
258 The directory structure in Mac OS Classic is seen by Emacs as
259
260 @example
261 /@var{volumename}/@var{filename}
262 @end example
263
264 So when Emacs requests a file name, doing file name completion on
265 @file{/} will display all volumes on the system. You can use @file{..}
266 to go up a directory level.
267
268 On Mac OS Classic, to access files and folders on the desktop, look
269 in the folder @file{Desktop Folder} in your boot volume (this folder
270 is usually invisible in the Mac @code{Finder}).
271
272 On Mac OS Classic, Emacs creates the Mac folder
273 @file{:Preferences:Emacs:} in the @file{System Folder} and uses it as
274 the temporary directory. Emacs maps the directory name @file{/tmp/}
275 to that. Therefore it is best to avoid naming a volume @file{tmp}.
276 If everything works correctly, the program should leave no files in it
277 when it exits. You should be able to set the environment variable
278 @code{TMPDIR} to use another directory but this folder will still be
279 created.
280
281
282 @node Mac Font Specs
283 @section Specifying Fonts on Mac
284 @cindex font names (Mac OS)
285
286 It is rare that you need to specify a font name in Emacs; usually
287 you specify face attributes instead. For example, you can use 14pt
288 Courier by customizing the default face attributes for all frames:
289
290 @lisp
291 (set-face-attribute 'default nil
292 :family "courier" :height 140)
293 @end lisp
294
295 @noindent
296 Alternatively, an interactive one is also available
297 (@pxref{Face Customization}).
298
299 But when you do need to specify a font name in Emacs on Mac, use a
300 standard X font name:
301
302 @smallexample
303 -@var{maker}-@var{family}-@var{weight}-@var{slant}-@var{widthtype}-@var{style}@dots{}
304 @dots{}-@var{pixels}-@var{height}-@var{horiz}-@var{vert}-@var{spacing}-@var{width}-@var{charset}
305 @end smallexample
306
307 @noindent
308 @xref{Font X}. Wildcards are supported as they are on X.
309
310 Emacs on Mac OS Classic uses QuickDraw Text routines for drawing texts
311 by default. Emacs on Mac OS X uses @acronym{ATSUI, Apple Type Services
312 for Unicode Imaging} as well as QuickDraw Text, and most of the
313 characters other than Chinese, Japanese, and Korean ones are drawn using
314 the former by default.
315
316 @acronym{ATSUI}-compatible fonts have maker name @code{apple} and
317 charset @code{iso10646-1}. For example 12-point Monaco can be specified
318 by the name
319 @samp{-apple-monaco-medium-r-normal--12-*-*-*-*-*-iso10646-1}. Note
320 that it must be specified in a format containing 14 @samp{-}s (i.e., not
321 by @samp{-apple-monaco-medium-r-normal-12-*-iso10646-1}) because every
322 @acronym{ATSUI}-compatible font is a scalable one.
323
324 QuickDraw Text fonts have maker name @code{apple} and various charset
325 names other than @code{iso10646-1}. Native Apple fonts in Mac Roman
326 encoding has charset @code{mac-roman}. You can specify a
327 @code{mac-roman} font for @acronym{ASCII} characters like
328
329 @smalllisp
330 (add-to-list
331 'default-frame-alist
332 '(font . "-apple-monaco-medium-r-normal--13-*-*-*-*-*-mac-roman"))
333 @end smalllisp
334
335 @noindent
336 but that does not extend to ISO-8859-1: specifying a @code{mac-roman}
337 font for Latin-1 characters introduces wrong glyphs.
338
339 Native Apple Traditional Chinese, Simplified Chinese, Japanese,
340 Korean, Central European, Cyrillic, Symbol, and Dingbats fonts have
341 charsets @samp{big5-0}, @samp{gb2312.1980-0},
342 @samp{jisx0208.1983-sjis} and @samp{jisx0201.1976-0},
343 @samp{ksc5601.1989-0}, @samp{mac-centraleurroman},
344 @samp{mac-cyrillic}, @samp{mac-symbol}, and @samp{mac-dingbats},
345 respectively.
346
347 The use of @code{create-fontset-from-fontset-spec} (@pxref{Defining
348 Fontsets}) for defining fontsets often results in wrong ones especially
349 when using only OS-bundled QuickDraw Text fonts. The recommended way to
350 use them is to create a fontset using
351 @code{create-fontset-from-mac-roman-font}:
352
353 @lisp
354 (create-fontset-from-mac-roman-font
355 "-apple-courier-medium-r-normal--13-*-*-*-*-*-mac-roman"
356 nil "foo")
357 @end lisp
358
359 @noindent
360 and then optionally specifying Chinese, Japanese, or Korean font
361 families using @code{set-fontset-font}:
362
363 @lisp
364 (set-fontset-font "fontset-foo"
365 'chinese-gb2312 '("song" . "gb2312.1980-0"))
366 @end lisp
367
368 Single-byte fonts converted from GNU fonts in BDF format, which are not
369 in the Mac Roman encoding, have foundry, family, and character sets
370 encoded in the names of their font suitcases. E.g., the font suitcase
371 @samp{ETL-Fixed-ISO8859-1} contains fonts which can be referred to by
372 the name @samp{-ETL-fixed-*-iso8859-1}.
373
374 @vindex mac-allow-anti-aliasing
375 Mac OS X 10.2 or later can use two types of text renderings: Quartz 2D
376 (aka Core Graphics) and QuickDraw. By default, Emacs uses the former on
377 such versions. It can be changed by setting
378 @code{mac-allow-anti-aliasing} to @code{t} (Quartz 2D) or @code{nil}
379 (QuickDraw). Both @acronym{ATSUI} and QuickDraw Text drawings are
380 affected by the value of this variable.
381
382
383 @node Mac Functions
384 @section Mac-Specific Lisp Functions
385 @cindex Lisp functions specific to Mac OS
386
387 @findex do-applescript
388 The function @code{do-applescript} takes a string argument,
389 executes it as an AppleScript command, and returns the result as a
390 string.
391
392 @findex mac-file-name-to-posix
393 @findex posix-file-name-to-mac
394 The function @code{mac-file-name-to-posix} takes a Mac file name and
395 returns the GNU or Unix equivalent. The function
396 @code{posix-file-name-to-mac} performs the opposite conversion. They
397 are useful for constructing AppleScript commands to be passed to
398 @code{do-applescript}.
399
400 @findex mac-set-file-creator
401 @findex mac-get-file-creator
402 @findex mac-set-file-type
403 @findex mac-get-file-type
404 The functions @code{mac-set-file-creator},
405 @code{mac-get-file-creator}, @code{mac-set-file-type}, and
406 @code{mac-get-file-type} can be used to set and get creator and file
407 codes.
408
409 @findex mac-get-preference
410 The function @code{mac-get-preference} returns the preferences value
411 converted to a Lisp object for a specified key and application.
412
413 @ignore
414 arch-tag: a822c2ab-4273-4997-927e-c153bb71dcf6
415 @end ignore