* macos.texi (Preferences Panel): Update description of font setting to reflect that...
[bpt/emacs.git] / doc / emacs / macos.texi
1 @c This is part of the Emacs manual.
2 @c Copyright (C) 2000, 2001, 2002, 2003, 2004,
3 @c 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 @c See file emacs.texi for copying conditions.
5 @node Mac OS / GNUstep, Microsoft Windows, Antinews, Top
6 @appendix Emacs and Mac OS / GNUstep
7 @cindex Mac OS X
8 @cindex Macintosh
9 @cindex GNUstep
10
11 This section briefly describes the peculiarities of using Emacs built with
12 the GNUstep libraries on GNU/Linux or other operating systems, or on Mac OS X
13 with native window system support. For Mac OS X, Emacs can be built either
14 without window system support, with X11, or with the Cocoa interface. This
15 section only applies to the Cocoa build. Emacs 23 does not support Mac OS
16 Classic.
17
18 Emacs, when built on Mac OS X, uses the Cocoa application interface. For
19 various historical and technical reasons, Emacs uses the term @samp{Nextstep}
20 internally, instead of ``Cocoa'' or ``Mac OS X''; for instance, most of the
21 commands and variables described in the following sections begin with
22 @samp{ns-}, which is short for @samp{Nextstep}. NeXTstep was an application
23 interface released by NeXT Inc during the 1980s, of which Cocoa is a direct
24 descendent. Apart from Cocoa, there is another NeXTstep-style system:
25 GNUstep, which is free software. As of this writing, the GNUstep support is
26 alpha status (see @pxref{GNUstep Support}), but we hope to improve it in the
27 future.
28
29 @menu
30 * Mac / GNUstep Basics:: Basic Emacs usage under GNUstep or Mac OS.
31 * Mac / GNUstep Customization:: Customizations under GNUstep or Mac OS.
32 * Mac / GNUstep Events:: How window system events are handled.
33 * GNUstep Support:: Details on status of GNUstep support
34 *
35 @end menu
36
37 @node Mac / GNUstep Basics, Mac / GNUstep Customization, , Mac OS / GNUstep
38 @section Basic Emacs usage under Mac OS and GNUstep
39
40 By default, the @key{alt} and @key{option} keys are the same as
41 @key{Meta} when running under Mac OS. The Mac @key{Cmd} key is the
42 same as @key{Super}, and Emacs provides a set of keybindings using
43 this modifier key that mimic other Mac / GNUstep applications (@pxref{Mac /
44 GNUstep Events}). You can change these bindings in the usual way (@pxref{Key
45 Bindings}), or by using the Preferences panel (@pxref{Mac / GNUstep
46 Customization}).
47
48 The standard Mac / GNUstep font and color panels are accessible via the
49 @samp{Windows} menu, or via the standard @key{Cmd-t} and @key{Cmd-C}
50 keybindings. To use the color panel, drag from it to an Emacs frame
51 to change the foreground color of the face at that position (if the
52 @key{shift} key is held down, it changes the background color
53 instead). To finalize the settings for either color or font, choose
54 @samp{Save Options} in the @samp{Options} menu. To discard the
55 settings, create a new frame and close the altered one.
56
57 @key{S-Mouse-1} (i.e., clicking the left mouse button
58 while holding down the @key{Shift} key) adjusts the region to the
59 click position, just like @key{Mouse-3} (@code{mouse-save-then-kill});
60 it does not pop up a menu for changing the default face, as
61 @key{S-Mouse-1} normally does (@pxref{Temporary Face Changes}). This
62 change makes Emacs behave more like other Mac / GNUstep applications.
63
64 When you open or save files using the menus, or using the standard
65 @key{Cmd-o} and @key{Cmd-S} bindings, Emacs uses graphical file
66 dialogs to read file names. However, if you use the regular Emacs key
67 sequences, such as @key{C-x C-f}, Emacs uses the minibuffer to read
68 file names.
69
70 On GNUstep, in an X-windows environment you need to use @key{Cmd-c}
71 instead of one of the @key{C-w} or @key{M-w} commands to transfer text
72 to the X primary selection; otherwise, Emacs will use the
73 ``clipboard'' selection. Likewise, @key{Cmd-y} (instead of @key{C-y})
74 yanks from the X primary selection instead of the kill-ring or
75 clipboard.
76
77
78 @subsection Grabbing environment variables
79
80 Many programs which may run under Emacs like latex or man depend on the
81 settings of environment variables. If Emacs is launched from the shell, it
82 will automatically inherit these environment variables and its subprocesses
83 will inherit them from it. But if Emacs is launched from the Finder it
84 is not a descendant of any shell, so its environment variables haven't been
85 set which often causes the subprocesses it launches to behave differently than
86 they would when launched from the shell.
87
88 To solve this problem for Emacs, there are two solutions. First is to
89 run, from the command line:
90
91 @example
92 .../Emacs.app/Contents/MacOS/bin/mac-fix-env
93 @end example
94
95 This will pick up your environment settings and save them into a special file
96 @file{~/.MacOSX/environment.plist}, which the desktop environment will use to
97 set the environment for all launched applications. The drawback of this
98 method is it needs to be run again whenever something changes.
99
100 The other approach is to use the @code{ns-grabenv} command inside Emacs. This
101 function will run a subshell and copy its environment variables into Emacs.
102
103 Adding this line to your @file{~/.emacs} will grab the csh environment
104 whenever emacs runs under a window system.
105
106 @lisp
107 (if window-system (ns-grabenv))
108 @end lisp
109
110 If you have a different shell you will have to give @code{ns-grabenv} some
111 arguments. For zsh you would do this.
112
113 @lisp
114 (if window-system (ns-grabenv "/usr/bin/zsh"
115 "source /etc/zshenv"
116 "source ~/.zshenv"))
117 @end lisp
118
119 The reason that @code{ns-grabenv} is not done by default is that it adds up
120 to a second or two to the Emacs startup time.
121
122
123 @node Mac / GNUstep Customization, Mac / GNUstep Events, Mac / GNUstep Basics, Mac OS / GNUstep
124 @section Mac / GNUstep Customization
125
126 Emacs can be customized in several ways in addition to the standard
127 customization buffers and the Options menu.
128
129
130 @subsection Preferences Panel
131
132 The Preferences panel, much like the Options menu, is designed to allow quick
133 and convenient setting of commonly used options.
134
135 The Preferences panel is available for setting commonly used GUI-related
136 options for Emacs. Access it under the Emacs menu (Mac) or Info menu
137 (GNUstep), or using @kbd{Cmd-,}.
138
139 Settings made here are saved when @samp{OK} is hit, or @samp{Save Options} is
140 selected from the Options menu. These settings are stored into the NeXTstep
141 ``defaults'' system under keys described below.
142
143 @itemize @bullet
144 @item
145 To set the default font used by Emacs click the @samp{Default Font...} button
146 to being up the Font Panel, then click on a frame. The font of this frame
147 will then be changed when you make a selection in the Font Panel, and this
148 will be used as the default for future frames. If you do not select a frame
149 first, the frame selected when you activated Preferences will be changed.
150
151 @item
152 The Color panel, brought up by the @samp{Colors...} button, allows setting of
153 foreground or background of any face. Drag from the color bar to over the
154 emacs face you want to change. This will change the foreground of that face,
155 or holding shift when dragging will change the background.
156
157 @item
158 @samp{Smooth Fonts} and @samp{Use Quickdraw} control text antialiasing.
159 Quickdraw is an older Mac technology still supported under OS X.
160
161 @item
162 The @samp{Expand Line Spacing} slider controls vertical spacing of text. The
163 0.0 setting corresponds to the same height as other applications. Settings
164 less than 0 compress the spacing, and greater than 0 expand it. Emacs must be
165 restarted for the new setting to take effect.
166
167 @item
168 The @samp{Cursor Type} radio buttons select the cursor shape:
169 cursor:
170
171 @itemize
172 @item
173 Filled Box - the cursor is displayed as a box (default)
174 @item
175 Vertical Bar - the cursor is displayed as a vertical line
176 @item
177 Underscore - the cursor is displayed as a horizontal line
178 @item
179 Hollow - the cursor is displayed as a box with an outline but no fill
180 @end itemize
181
182 @item
183 The @samp{Cursor Blink Rate} slider to sets the frequency at which the cursor
184 blinks (CURRENTLY INOPERATIVE -- use @samp{customize group cursor} instead.)
185
186 @item
187 The @samp{Use System Highlight Color} option controls whether selected text is
188 highlighted with the system default or the local emacs setting.
189
190 @end itemize
191
192 The behavior of Modifier keys inside emacs can be controlled by the drop-down
193 menus in the @samp{Modifiers} section. By default the Alt or Opt key is bound
194 to the Emacs 'Meta' key, and the Command key is bound to 'super' which allows
195 the Command key to function in a way similar to other NeXTstep/OS X
196 applications.
197
198
199 @subsection Font and Color Panels
200
201 The Font Panel may be accessed from the Windows menu or by @kbd{Cmd-t}. It
202 will set the default font in the frame most recently used or clicked on. To
203 make the setting permanent, use @samp{Save Options} in the Options menu, or
204 run @code{ns-save-preferences}.
205
206 You can bring up a color panel (with @key{Cmd-C} or from the Windows menu) and
207 drag the color you want over the emacs face you want to change. Normal
208 dragging will alter the foreground color. Shift dragging will alter the
209 background color. To make the changes permanent select the "Save Options"
210 item in the "Options" menu, or run @code{ns-save-preferences}. Useful in this
211 context is the listing of all faces obtained by @key{M-x}
212 @code{list-faces-display}.
213
214
215 @subsection Defaults
216
217 Under X, resources are used to customize the behavior of Emacs to the
218 needs of the user. Nextstep defaults fulfill a similar function. From
219 the command line, the command @samp{defaults read org.gnu.Emacs} shows
220 these resources as of the last Emacs exited, and individual resources
221 can be read or written by commands like @samp{defaults read Emacs Foo}
222 and @samp{defaults write Emacs Foo barvalue}.
223
224 Calling the function @code{ns-save-preferences} in lisp, or
225 selecting the @samp{Option / Save Options} menu item, automatically
226 writes out the defaults corresponding to the selected window.
227
228 In addition, you can set many of the following customizations by
229 setting @code{default-frame-alist} in your initialization file.
230
231 Many of the preferences relating specifically to the Nextstep windowing
232 system (such as font rendering and the cursor type) can be set using the
233 Preferences panel. It is important to note that when you hit @samp{OK} on
234 this panel, @emph{all} Nextstep settings are saved (including font and
235 colors).
236
237 This is a listing of some of the more useful defaults (and their
238 default values). Several of these defaults accept the names of colors
239 as values. For a list of all available colors pull up the color panel
240 and look at the color list called @samp{Emacs}. Emacs also accepts
241 color specifications of the form @samp{ARGBaarrggbb} where @var{aa},
242 @var{rr}, @var{gg}, and @var{bb} are two hexadecimal digits describing
243 the alpha, red, green, and blue content of the color respectively.
244 @samp{HSBhhssbb}, @samp{CMYKccmmyykk} and @samp{GRAYgg} are the
245 equivalents in @samp{HSB}, @samp{CMYK} and gray scales. (For HSB,
246 @samp{AHSBaahhssbb} is also accepted.)
247
248 @table @samp
249 @item InternalBorderWidth
250 Width in pixels of the internal border of the Nextstep frame. This
251 acts to separate the text area of the window from the fringes,
252 scrollbars, and/or edges.
253
254 @example
255 defaults write Emacs InternalBorderWidth 2
256 @end example
257
258 @item VerticalScrollBars
259 @samp{YES} or @samp{NO} to enable or disable scroll bars, @samp{left} or
260 @samp{right} to explicitly set the side.
261
262 @example
263 defaults write Emacs VerticalScrollBars YES
264 @end example
265
266 @item Font
267 Name of the default font to be used for new frames (which can be
268 overridden by various faces). If this font is not set, Emacs will use
269 the system wide fixed pitch font. For most users the system fixed
270 pitch font will be @samp{Monaco} which doesn't have any bold or italic
271 versions. (Italic will be synthesized.)
272
273 @item FontSize
274 Size of the font to be used for new frames. If not set, Emacs will
275 use the default size of the system wide fixed pitch font.
276
277 @item Foreground
278 The default foreground (text) color for new frames.
279
280 @example
281 defaults write Emacs Foreground "Black"
282 @end example
283
284 @item Background
285 The default background color for new frames.
286
287 @example
288 defaults write Emacs Background "White"
289 @end example
290
291 @item Height
292 Height in rows of the default window.
293
294 @example
295 defaults write Emacs Height 48
296 @end example
297
298 @item Width
299 Width in columns of the default window.
300
301 @example
302 defaults write Emacs Width 80
303 @end example
304
305 @item CursorType
306 Name of the default cursor type for Emacs. Allowed values are
307 @samp{box}, @samp{hollow}, @samp{underscore}, @samp{bar}, @samp{line} and @samp{no}.
308
309 @example
310 defaults write Emacs CursorType box
311 @end example
312
313 @item CursorColor
314 Name of the default cursor color for Emacs. Of a particular use for
315 this setting is the @samp{Highlight} color. When it is the cursor
316 color, Emacs will draw the cursor using the standard Nextstep
317 highlighting operator.
318
319 @example
320 defaults write Emacs CursorColor blue
321 @end example
322
323 @item Top
324 Distance in pixels from the top of the screen of the upper left corner
325 of the default window.
326
327 @example
328 defaults write Emacs Top 100
329 @end example
330
331 @item Left
332 Distance in pixels from the left edge of the screen to the upper left
333 corner of the default window.
334
335 @example
336 defaults write Emacs Left 100
337 @end example
338
339 @item HideOnAutoLaunch
340 @samp{YES} or @samp{NO} to determine whether Emacs will hide itself when
341 autolaunched from the dock.
342
343 @example
344 defaults write Emacs HideOnAutoLaunch NO
345 @end example
346
347 @item ExpandSpace
348 This lets you expand or shrink the line height used for displaying
349 text. When this is set to 0.0, display should look like other
350 Nextstep applications. If you set it higher than 0, Emacs will spread
351 the text lines apart, less than 0, compress them together. (With
352 settings below zero parts of characters may be chopped off in certain
353 fonts.) When using the Preferences panel, this is controlled by a
354 slider. You must OK the panel and then restart Emacs for this default
355 to take effect.
356
357 When setting this using @code{"defaults write"}, you can either set a floating
358 point value, or @samp{YES}, which is equivalent 0.5, or @samp{NO}, which is
359 equivalent to 0.0.
360
361 @example
362 defaults write Emacs ExpandSpace -0.125
363 @end example
364
365 @item GSFontAntiAlias
366 This turns antialiasing on and off on. Note that, on OS X, even if
367 antialiasing is on, Emacs will not antialias text of a size below the system
368 preference setting.
369
370 @example
371 defaults write Emacs GSFontAntiAlias NO
372 @end example
373
374 @item UseQuickdrawSmoothing
375 On OS X 10.3 and higher, this will render fonts using Quickdraw antialiasing,
376 which is less heavy than the Quartz antialiasing used by default. Whether
377 this is on or off, the system font size threshold for antialiasing (see above)
378 is respected.
379
380 @example
381 defaults write Emacs UseQuickdrawSmoothing YES
382 @end example
383
384 @item AlternateModifier
385 This allows you to set the effect of the Alt or Opt key. The default is
386 @samp{meta}, meaning to use as the Emacs 'meta' key. You can also set this to
387 @samp{command}, @samp{hyper}, @samp{alt}, or @samp{none}. The last is useful
388 for Continental users who normally use this key to enter accented and other
389 special characters.
390
391 @example
392 defaults write Emacs AlternateModifier "none"
393 @end example
394
395 @item CommandModifier
396 This allows you to set the effect of the Command key. The default is
397 @samp{super}, which is used in a set of keybindings such as @code{s-o} for
398 ``open file'' and @code{s-z} for ``undo'' that are similar to other NeXTstep
399 applications. On the other hand, some people who use the Alt/Opt key for
400 accent entry like to set this to @samp{meta} so they still have easy access to
401 Emacs functionality bound to meta keys. You can also set this, like Alt/Opt,
402 to @samp{hyper} or @samp{alt}, though there are no bindings to combinations
403 using these keys by default. The @samp{none} option is not available for the
404 Command key.
405
406 @example
407 defaults write Emacs CommandModifier "meta"
408 @end example
409
410 @item fooFrame
411 Position and size to use for the frame named @var{foo} when it is
412 created. The position and size have to be specified as a space
413 separated list: @samp{top}, @samp{left}, @samp{height} and
414 @samp{width}. @samp{top} and @samp{left} are expressed in pixels,
415 @samp{height} is given in rows and @samp{width} is given in columns.
416 Named frames can be created by e.g. @code{(make-frame '((name
417 . "FOO")))}.
418
419 @example
420 defaults write Emacs TestFrame "100 200 30 70"
421 @end example
422
423 Another default previouly used by many Emacs users is this.
424
425 @example
426 defaults write Workspace DefaultOpenApp Emacs
427 @end example
428
429 It caused the NeXTstep Workspace to open files without a registered extension
430 in Emacs instead of as usual Edit. For this default to work, Emacs needed to
431 be in the application search path of the Workspace (which usually includes
432 @file{~/Applications} and @file{~/Applications}). If anyone knows the current
433 way to do this under OS X please contact the authors.
434
435 @end table
436
437 @subsection Open files by dragging to an Emacs window
438
439 The default behaviour when a user drags files from another application
440 into an Emacs frame is to insert the contents of all the dragged files
441 into the current buffer. To remap the @code{ns-drag-file} event to
442 open the dragged files in the current frame use the following line:
443
444 @lisp
445 (define-key global-map [ns-drag-file] 'ns-find-file)
446 @end lisp
447
448
449 @node Mac / GNUstep Events, GNUstep Support, Mac / GNUstep Customization, Mac OS / GNUstep
450 @section Windowing System Events under Mac OS / GNUstep
451
452 Nextstep applications receive a number of special events which have
453 no X equivalent. These are sent as specially defined ``keys'', which
454 do not correspond to any sequence of keystrokes. Under Emacs, these
455 ``key'' events can be bound to functions just like ordinary
456 keystrokes. Here is a list of these events.
457
458 @table @key
459 @item ns-open-file
460 @vindex ns-pop-up-frames
461 This event occurs when another Nextstep application requests that
462 Emacs open a file. A typical reason for this would be a user
463 double-clicking a file in the Finder application. By default, Emacs
464 responds to this event by opening a new frame and visiting the file in
465 that frame (@code{ns-find-file}), As an exception, if the selected
466 buffer is the @samp{*scratch*} buffer, Emacs visits the file in the
467 the selected frame.
468
469 You can change how Emacs responds to @key{ns-open-file} by changing
470 the variable @code{ns-pop-up-frames}. Its default value,
471 @code{'fresh}, is what we have just described. A value of @code{t}
472 means to always visit the file in a new frame. A value of @code{nil}
473 means to always visit the file in an existing frame.
474
475 @item ns-open-temp-file
476 This event occurs when another application requests that Emacs open a
477 temporary file. By default, this is handled by just generating a
478 @code{ns-open-file} event, the results of which are described above.
479
480 You can bind @key{ns-pop-up-frames} and @key{ns-open-temp-file} to
481 other Lisp functions. When the event is registered, the name of the
482 file to open is stored in the variable @code{ns-input-file}.
483
484 @item ns-open-file-line
485 Some applications, such as ProjectBuilder and gdb, request not only a
486 particular file, but also a particular line or sequence of lines in
487 the file. Emacs handles this by visiting that file and highlighting
488 the requested line (@code{ns-open-file-select-line}).
489
490 @item ns-drag-file
491 This event occurs when a user drags files from another application
492 into an Emacs frame. The default behavior is to insert the contents
493 of all the dragged files into the current buffer
494 (@code{ns-insert-files}). The list of dragged files is stored in the
495 variable @code{ns-input-file}.
496
497 @item ns-drag-color
498 This event occurs when a user drags a color from the color well (or
499 some other source) into an Emacs frame. The default behavior is to
500 alter the foreground color of the area the color was dragged onto
501 (@code{ns-set-foreground-at-mouse}). If this event is issued with a
502 @key{Shift} modifier, Emacs changes the background color instead
503 (@code{ns-set-background-at-mouse}). The name of the dragged color is
504 stored in the variable @code{ns-input-color}.
505
506 @item ns-change-font
507 This event occurs when the user selects a font in a Nextstep font
508 panel (which can be opened with @kbd{Cmd-t}). The default behavior is
509 to adjust the font of the selected frame
510 (@code{ns-respond-to-changefont}). The name and size of the selected
511 font are stored in the variables @code{ns-input-font} and
512 @code{ns-input-fontsize} respectively.
513
514 @item ns-power-off
515 This event occurs when the user logs out and Emacs is still running.
516 The default behavior is to save all file-visiting buffers without
517 confirmation, and exit.
518 @end table
519
520 Emacs also allows users to make use of Nextstep services, via a set
521 of commands whose names begin with @samp{ns-service-} and end with the
522 name of the service. Type @kbd{M-x ns-service-@key{TAB}@key{TAB}} to
523 see a list of these commands. These functions either operate on
524 marked text (replacing it with the result) or take a string argument
525 and return the result as a string. You can also use the Lisp function
526 @code{ns-perform-service} to pass arbitrary strings to arbitrary
527 services and receive the results back. Note that you may need to
528 restart Emacs to access newly-available services.
529
530
531 @node GNUstep Support, , Mac / GNUstep Events, Mac OS / GNUstep
532 @section GNUstep Support
533
534 Emacs can be built and run under GNUstep however building is difficult and
535 there are some limitations to functionality. In particular, it may be
536 necessary to run @samp{make bootstrap} with a plain X configuration, then
537 @samp{make clean} and @samp{./configure --with-ns} followed by @samp{make
538 install}.
539
540 Currently CANNOT_DUMP is automatically enabled in GNUstep configurations,
541 because the unex file(s) for GNUstep, mainly @samp{unexelf.c}, have not been
542 updated yet with the ``zone'' code in and related to @samp{unexmacosx.c}.
543
544 @ignore
545 arch-tag: a822c2ab-4273-4997-927e-c153bb71dcf6
546 @end ignore