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