;; Special Nextstep-generated events are converted to function keys. Here
;; are the bindings for them.
-(define-key global-map [ns-power-off]
- (lambda () (interactive) (save-buffers-kill-emacs t)))
+(define-key global-map [ns-power-off] 'save-buffers-kill-emacs)
(define-key global-map [ns-open-file] 'ns-find-file)
(define-key global-map [ns-open-temp-file] [ns-open-file])
(define-key global-map [ns-drag-file] 'ns-insert-file)
(define-key global-map [ns-spi-service-call] 'ns-spi-service-call)
(define-key global-map [ns-new-frame] 'make-frame)
(define-key global-map [ns-toggle-toolbar] 'ns-toggle-toolbar)
-(define-key global-map [ns-info-prefs] 'ns-show-preferences-help)
+(define-key global-map [ns-show-prefs] 'customize)
;; Functions to set environment variables by running a subshell.
(cons (logior (lsh 0 16) 11) 'ns-spi-service-call)
(cons (logior (lsh 0 16) 12) 'ns-new-frame)
(cons (logior (lsh 0 16) 13) 'ns-toggle-toolbar)
- (cons (logior (lsh 0 16) 14) 'ns-info-prefs)
+ (cons (logior (lsh 0 16) 14) 'ns-show-prefs)
(cons (logior (lsh 1 16) 32) 'f1)
(cons (logior (lsh 1 16) 33) 'f2)
(cons (logior (lsh 1 16) 34) 'f3)
;; Must come after keybindings.
-(fmakunbound 'clipboard-yank)
-(fmakunbound 'clipboard-kill-ring-save)
-(fmakunbound 'clipboard-kill-region)
-(fmakunbound 'menu-bar-enable-clipboard)
+;; (fmakunbound 'clipboard-yank)
+;; (fmakunbound 'clipboard-kill-ring-save)
+;; (fmakunbound 'clipboard-kill-region)
+;; (fmakunbound 'menu-bar-enable-clipboard)
;; Add a couple of menus and rearrange some others; easiest just to redo toplvl
;; Note keymap defns must be given last-to-first
(t (read res)))))
;; nsterm.m
-(defvar ns-command-modifier)
-(defvar ns-control-modifier)
-(defvar ns-function-modifier)
-(defvar ns-antialias-text)
-(defvar ns-use-qd-smoothing)
-(defvar ns-use-system-highlight-color)
-(defvar ns-confirm-quit)
-
-(declare-function ns-set-resource "nsfns.m" (owner name value))
-(declare-function ns-font-name "nsfns.m" (name))
+
(declare-function ns-read-file-name "nsfns.m"
(prompt &optional dir isLoad init))
-(defun ns-save-preferences ()
- "Set all the defaults."
- (interactive)
- ;; Global preferences
- (ns-set-resource nil "AlternateModifier" (symbol-name ns-alternate-modifier))
- (ns-set-resource nil "CommandModifier" (symbol-name ns-command-modifier))
- (ns-set-resource nil "ControlModifier" (symbol-name ns-control-modifier))
- (ns-set-resource nil "FunctionModifier" (symbol-name ns-function-modifier))
- (ns-set-resource nil "ExpandSpace"
- (if ns-expand-space
- (number-to-string ns-expand-space)
- "NO"))
- (ns-set-resource nil "GSFontAntiAlias" (if ns-antialias-text "YES" "NO"))
- (ns-set-resource nil "UseQuickdrawSmoothing"
- (if ns-use-qd-smoothing "YES" "NO"))
- (ns-set-resource nil "UseSystemHighlightColor"
- (if ns-use-system-highlight-color "YES" "NO"))
- (ns-set-resource nil "ConfirmQuit"
- (if ns-confirm-quit "YES" "NO"))
- ;; Default frame parameters
- (let ((p (frame-parameters))
- v)
- (if (setq v (assq 'font p))
- (ns-set-resource nil "Font" (ns-font-name (cdr v))))
- (if (setq v (assq 'fontsize p))
- (ns-set-resource nil "FontSize" (number-to-string (cdr v))))
- (if (setq v (assq 'foreground-color p))
- (ns-set-resource nil "Foreground" (cdr v)))
- (if (setq v (assq 'background-color p))
- (ns-set-resource nil "Background" (cdr v)))
- (if (setq v (assq 'cursor-color p))
- (ns-set-resource nil "CursorColor" (cdr v)))
- (if (setq v (assq 'cursor-type p))
- (ns-set-resource nil "CursorType" (if (symbolp (cdr v))
- (symbol-name (cdr v))
- (cdr v))))
- (if (setq v (assq 'underline p))
- (ns-set-resource nil "Underline"
- (case (cdr v)
- ((t) "YES")
- ((nil) "NO")
- (t (cdr v)))))
- (if (setq v (assq 'internal-border-width p))
- (ns-set-resource nil "InternalBorderWidth"
- (number-to-string (cdr v))))
- (if (setq v (assq 'vertical-scroll-bars p))
- (ns-set-resource nil "VerticalScrollBars"
- (case (cdr v)
- ((t) "YES")
- ((nil) "NO")
- ((left) "left")
- ((right) "right")
- (t nil))))
- (if (setq v (assq 'height p))
- (ns-set-resource nil "Height" (number-to-string (cdr v))))
- (if (setq v (assq 'width p))
- (ns-set-resource nil "Width" (number-to-string (cdr v))))
- (if (setq v (assq 'top p))
- (ns-set-resource nil "Top" (number-to-string (cdr v))))
- (if (setq v (assq 'left p))
- (ns-set-resource nil "Left" (number-to-string (cdr v))))
- ;; These not fully supported
- (if (setq v (assq 'auto-raise p))
- (ns-set-resource nil "AutoRaise" (if (cdr v) "YES" "NO")))
- (if (setq v (assq 'auto-lower p))
- (ns-set-resource nil "AutoLower" (if (cdr v) "YES" "NO")))
- (if (setq v (assq 'menu-bar-lines p))
- (ns-set-resource nil "Menus" (if (cdr v) "YES" "NO")))
- )
- (let ((fl (face-list)))
- (while (consp fl)
- (or (eq 'default (car fl))
- ;; dont save Default* since it causes all created faces to
- ;; inherit its values. The properties of the default face
- ;; have already been saved from the frame-parameters anyway.
- (let* ((name (symbol-name (car fl)))
- (font (face-font (car fl)))
- ;; (fontsize (face-fontsize (car fl)))
- (foreground (face-foreground (car fl)))
- (background (face-background (car fl)))
- (underline (face-underline-p (car fl)))
- (italic (face-italic-p (car fl)))
- (bold (face-bold-p (car fl)))
- (stipple (face-stipple (car fl))))
- ;; (ns-set-resource nil (concat name ".attributeFont")
- ;; (if font font nil))
- ;; (ns-set-resource nil (concat name ".attributeFontSize")
- ;; (if fontsize (number-to-string fontsize) nil))
- (ns-set-resource nil (concat name ".attributeForeground")
- (if foreground foreground nil))
- (ns-set-resource nil (concat name ".attributeBackground")
- (if background background nil))
- (ns-set-resource nil (concat name ".attributeUnderline")
- (if underline "YES" nil))
- (ns-set-resource nil (concat name ".attributeItalic")
- (if italic "YES" nil))
- (ns-set-resource nil (concat name ".attributeBold")
- (if bold "YES" nil))
- (and stipple
- (or (stringp stipple)
- (setq stipple (prin1-to-string stipple))))
- (ns-set-resource nil (concat name ".attributeStipple")
- (if stipple stipple nil))))
- (setq fl (cdr fl)))))
-
-(declare-function menu-bar-options-save-orig "ns-win" () t)
-
-;; call ns-save-preferences when menu-bar-options-save is called
-(fset 'menu-bar-options-save-orig (symbol-function 'menu-bar-options-save))
-(defun ns-save-options ()
- (interactive)
- (menu-bar-options-save-orig)
- (ns-save-preferences))
-(fset 'menu-bar-options-save (symbol-function 'ns-save-options))
-
-
;;;; File handling.
(defun ns-open-file-using-panel ()
;;;; Dialog-related functions.
-(defun ns-show-preferences-help ()
- "Show NS Preferences panel section in the Emacs manual"
- (interactive)
- (info "(emacs)Mac / GNUstep Customization"))
-
;; Ask user for confirm before printing. Due to Kevin Rodgers.
(defun ns-print-buffer ()
"Interactive front-end to `print-buffer': asks for user confirmation first."
extern Lisp_Object Qcursor_color, Qcursor_type, Qns;
-EmacsPrefsController *prefsController;
-
-/* Preferences equivalent to those set by X resources under X are managed
- through the OpenStep defaults system. These pertain to behavior of the
- graphical interface components. The one difference from X is that the
- values below are SET when the user chooses save-options. This makes
- things easier for users, but sometimes violates expectations when some
- user-set options appear when running under -q/Q. Therefore we depart
- from X behavior and refuse to read defaults when started under these
+/* Some preferences equivalent to those set by X resources under X are
+ managed through the OpenStep defaults system. We depart from X
+ behavior and refuse to read defaults when started under these
options. */
/* Set in emacs.c. */
the Function modifer (laptops). May be any of the modifier lisp symbols. */
Lisp_Object ns_function_modifier;
-/* A floating point value specifying vertical stretch (positive) or shrink
- (negative) of text line spacing. Zero means default spacing.
- YES indicates 0.5, NO indicates 0.0. */
-Lisp_Object ns_expand_space;
-
/* Control via default 'GSFontAntiAlias' on OS X and GNUstep. */
Lisp_Object ns_antialias_text;
static struct timeval select_timeout;
static int select_nfds;
static NSAutoreleasePool *outerpool;
-static BOOL ns_shutdown_properly = NO;
static struct input_event *emacs_event = NULL;
static struct input_event *q_event_ptr = NULL;
static int n_emacs_events_pending = 0;
ns_command_modifier = Qsuper;
ns_control_modifier = Qcontrol;
ns_function_modifier = Qnone;
- ns_expand_space = make_float (0.0);
ns_antialias_text = Qt;
ns_antialias_threshold = 10.0; /* not exposed to lisp side */
ns_use_qd_smoothing = Qnil;
ns_set_default_prefs ();
if (!ns_no_defaults)
{
- ns_default ("AlternateModifier", &ns_alternate_modifier,
- Qnil, Qnil, NO, YES);
- if (NILP (ns_alternate_modifier))
- ns_alternate_modifier = Qmeta;
- ns_default ("CommandModifier", &ns_command_modifier,
- Qnil, Qnil, NO, YES);
- if (NILP (ns_command_modifier))
- ns_command_modifier = Qsuper;
- ns_default ("ControlModifier", &ns_control_modifier,
- Qnil, Qnil, NO, YES);
- if (NILP (ns_control_modifier))
- ns_control_modifier = Qcontrol;
- ns_default ("FunctionModifier", &ns_function_modifier,
- Qnil, Qnil, NO, YES);
- if (NILP (ns_function_modifier))
- ns_function_modifier = Qnone;
- ns_default ("ExpandSpace", &ns_expand_space,
- make_float (0.5), make_float (0.0), YES, NO);
ns_default ("GSFontAntiAlias", &ns_antialias_text,
Qt, Qnil, NO, NO);
tmp = Qnil;
+ /* this is a standard variable */
ns_default ("AppleAntiAliasingThreshold", &tmp,
make_float (10.0), make_float (6.0), YES, NO);
ns_antialias_threshold = NILP (tmp) ? 10.0 : XFLOATINT (tmp);
- ns_default ("UseQuickdrawSmoothing", &ns_use_qd_smoothing,
- Qt, Qnil, NO, NO);
- ns_default ("UseSystemHighlightColor", &ns_use_system_highlight_color,
- Qt, Qnil, NO, NO);
- ns_default ("ConfirmQuit", &ns_confirm_quit,
- Qt, Qnil, NO, NO);
}
- if (EQ (ns_use_system_highlight_color, Qt))
- {
- ns_selection_color = [[NSUserDefaults standardUserDefaults]
- stringForKey: @"AppleHighlightColor"];
- if (ns_selection_color == nil)
- ns_selection_color = NS_SELECTION_COLOR_DEFAULT;
- }
- else
+ ns_selection_color = [[NSUserDefaults standardUserDefaults]
+ stringForKey: @"AppleHighlightColor"];
+ if (ns_selection_color == nil)
ns_selection_color = NS_SELECTION_COLOR_DEFAULT;
-
+
{
NSColorList *cl = [NSColorList colorListNamed: @"Emacs"];
if (sig == 0 || sig == SIGTERM)
{
- ns_shutdown_properly = YES;
[NSApp terminate: NSApp];
}
else // force a stack trace to happen
- (void)showPreferencesWindow: (id)sender
{
- if (prefsController == nil)
- prefsController = [[EmacsPrefsController alloc] init];
- [prefsController showForFrame: SELECTED_FRAME ()];
+ struct frame *emacsframe = SELECTED_FRAME ();
+ NSEvent *theEvent = [NSApp currentEvent];
+
+ if (!emacs_event)
+ return;
+ emacs_event->kind = NS_NONKEY_EVENT;
+ emacs_event->code = KEY_NS_SHOW_PREFS;
+ emacs_event->modifiers = 0;
+ EV_TRAILER (theEvent);
}
}
-/* Termination sequences (ns_shutdown_properly):
+/* Termination sequences:
C-x C-c:
Cmd-Q:
MenuBar | File | Exit:
- ns_term_shutdown: 0
- -terminate: 1
- -appShouldTerminate: 1
-
Select Quit from App menubar:
- received -terminate: 0
- ns_term_shutdown: 0
- -terminate: 1
- -appShouldTerminate: 1
+ -terminate
+ KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
+ ns_term_shutdown()
Select Quit from Dock menu:
Logout attempt:
- -appShouldTerminate: 0
+ -appShouldTerminate
Cancel -> Nothing else
Accept ->
- -terminate: 0
- ns_term_shutdown: 0
- -terminate: 1
- -appShouldTerminate: 1
+
+ -terminate
+ KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
+ ns_term_shutdown()
+
*/
- (void) terminate: (id)sender
{
- if (ns_shutdown_properly)
- [super terminate: sender];
- else
- {
- struct frame *emacsframe = SELECTED_FRAME ();
-
- if (!emacs_event)
- return;
-
- ns_shutdown_properly = YES;
- emacs_event->kind = NON_ASCII_KEYSTROKE_EVENT;
- emacs_event->code = KEY_NS_POWER_OFF;
- EV_TRAILER ((id)nil);
- }
+ struct frame *emacsframe = SELECTED_FRAME ();
+
+ if (!emacs_event)
+ return;
+
+ emacs_event->kind = NS_NONKEY_EVENT;
+ emacs_event->code = KEY_NS_POWER_OFF;
+ emacs_event->arg = Qt; /* mark as non-key event */
+ EV_TRAILER ((id)nil);
}
{
int ret;
- if (ns_shutdown_properly || NILP (ns_confirm_quit))
+ if (NILP (ns_confirm_quit)) // || ns_shutdown_properly --> TO DO
return NSTerminateNow;
ret = NSRunAlertPanel([[NSProcessInfo processInfo] processName],
-/* ==========================================================================
-
- EmacsPrefsController implementation
-
- ========================================================================== */
-
-
-@implementation EmacsPrefsController
-
-/* in Tiger+, can just do [popup selectItemWithTag: tag]; */
-static void selectItemWithTag (NSPopUpButton *popup, int tag)
-{
- NSEnumerator *items = [[popup itemArray] objectEnumerator];
- NSMenuItem *item;
- while (item = [items nextObject])
- {
- if ([item tag] == tag)
- {
- [popup selectItem: item];
- return;
- }
- }
-}
-
-- init
-{
- [NSBundle loadNibNamed: @"preferences" owner: self];
- return self;
-}
-
-
-- (void) showForFrame: (struct frame *)f
-{
- frame = f;
- [self setPanelFromValues];
- [prefsWindow makeKeyAndOrderFront: self];
- [prefsWindow display];
-}
-
-
-/* If you change this, change setPanelFromDefaultValues too. */
-- (void) setPanelFromValues
-{
- int cursorType
- = ns_lisp_to_cursor_type (get_frame_param (frame, Qcursor_type));
- prevExpandSpace = XFLOATINT (ns_expand_space);
-
-#ifdef NS_IMPL_COCOA
- prevUseHighlightColor = ns_use_system_highlight_color;
-#endif
-
- [expandSpaceSlider setFloatValue: prevExpandSpace];
- [cursorTypeMatrix selectCellWithTag: (cursorType == FILLED_BOX_CURSOR ? 1 :
- (cursorType == BAR_CURSOR ? 2 :
- (cursorType == HBAR_CURSOR ? 3 : 4)))];
- selectItemWithTag (alternateModMenu,
- parse_solitary_modifier (ns_alternate_modifier));
- selectItemWithTag (commandModMenu,
- parse_solitary_modifier (ns_command_modifier));
-#ifdef NS_IMPL_COCOA
- selectItemWithTag (controlModMenu,
- parse_solitary_modifier (ns_control_modifier));
- selectItemWithTag (functionModMenu,
- parse_solitary_modifier (ns_function_modifier));
- [smoothFontsCheck setState: (NILP (ns_antialias_text) ? NO : YES)];
- [useQuickdrawCheck setState: (NILP (ns_use_qd_smoothing) ? NO : YES)];
- [useSysHiliteCheck setState: (NILP (prevUseHighlightColor) ? NO : YES)];
- [confirmQuitCheck setState: (NILP (ns_confirm_quit) ? NO : YES)];
-#endif
-}
-
-
-/* This and ns_set_default_prefs should be changed together. */
-- (void) setPanelFromDefaultValues
-{
- [expandSpaceSlider setFloatValue: 0.0];
- [cursorTypeMatrix selectCellWithTag: 1]; /* filled box */
- selectItemWithTag (alternateModMenu, meta_modifier);
- selectItemWithTag (commandModMenu, super_modifier);
-#ifdef NS_IMPL_COCOA
- selectItemWithTag (controlModMenu, ctrl_modifier);
- selectItemWithTag (functionModMenu, 0); /* none */
- [smoothFontsCheck setState: YES];
- [useQuickdrawCheck setState: NO];
- [useSysHiliteCheck setState: YES];
-#endif
-}
-
-
-- (void) setValuesFromPanel
-{
- int altTag = [[alternateModMenu selectedItem] tag];
- int cmdTag = [[commandModMenu selectedItem] tag];
-#ifdef NS_IMPL_COCOA
- int ctrlTag = [[controlModMenu selectedItem] tag];
- int fnTag = [[functionModMenu selectedItem] tag];
-#endif
- float expandSpace = [expandSpaceSlider floatValue];
- int cursorTag = [[cursorTypeMatrix selectedCell] tag];
- Lisp_Object cursor_type = ns_cursor_type_to_lisp
- ( cursorTag == 1 ? FILLED_BOX_CURSOR
- : cursorTag == 2 ? BAR_CURSOR
- : cursorTag == 3 ? HBAR_CURSOR : HOLLOW_BOX_CURSOR);
-
- if (expandSpace != prevExpandSpace)
- {
- ns_expand_space = make_float (expandSpace);
- /* TODO: more needed: store needed metrics in nsfont_info, update
- frame default font max_bounds and fontp, recompute faces */
-/* FRAME_LINE_HEIGHT (frame) *= (expandSpace / prevExpandSpace);
- x_set_window_size (frame, 0, frame->text_cols, frame->text_lines); */
- prevExpandSpace = expandSpace;
- }
-
- store_frame_param (frame, Qcursor_type, cursor_type);
- x_set_cursor_type (frame, cursor_type, Qnil); /* FIXME: do only if changed */
-
- ns_alternate_modifier = ns_mod_to_lisp (altTag);
- ns_command_modifier = ns_mod_to_lisp (cmdTag);
-#ifdef NS_IMPL_COCOA
- ns_control_modifier = ns_mod_to_lisp (ctrlTag);
- ns_function_modifier = ns_mod_to_lisp (fnTag);
- ns_antialias_text = [smoothFontsCheck state] ? Qt : Qnil;
- ns_use_qd_smoothing = [useQuickdrawCheck state] ? Qt : Qnil;
- ns_use_system_highlight_color = [useSysHiliteCheck state] ? Qt : Qnil;
- ns_confirm_quit = [confirmQuitCheck state] ? Qt : Qnil;
- if (! EQ (ns_use_system_highlight_color, prevUseHighlightColor))
- {
- prevUseHighlightColor = ns_use_system_highlight_color;
- if (EQ (ns_use_system_highlight_color, Qt))
- {
- ns_selection_color = [[NSUserDefaults standardUserDefaults]
- stringForKey: @"AppleHighlightColor"];
- if (ns_selection_color == nil)
- ns_selection_color = NS_SELECTION_COLOR_DEFAULT;
- }
- else
- ns_selection_color = NS_SELECTION_COLOR_DEFAULT;
- }
-#endif /* NS_IMPL_COCOA */
- Fcall_interactively (intern ("ns-save-preferences"), Qnil, Qnil);
-}
-
-
-/* buttons */
-- (IBAction)cancel: (id)sender
-{
- [prefsWindow close];
-}
-
-
-- (IBAction)ok: (id)sender
-{
- [self setValuesFromPanel];
- [prefsWindow close];
-}
-
-
-- (IBAction)resetToDefaults: (id)sender
-{
- [self setPanelFromDefaultValues];
-}
-
-
-- (IBAction)runHelp: (id)sender
-{
- struct frame *emacsframe = frame;
- if (!emacs_event)
- return;
- ns_raise_frame(frame);
- emacs_event->kind = NS_NONKEY_EVENT;
- emacs_event->code = KEY_NS_INFO_PREFS;
- EV_TRAILER ((id)nil);
-}
-
-
-- (IBAction)setColors: (id)sender
-{
- Lisp_Object lispFrame;
- XSETFRAME (lispFrame, frame);
- ns_raise_frame(frame);
- Fns_popup_color_panel (lispFrame);
-}
-
-
-- (IBAction)setDefaultFont: (id)sender
-{
- Lisp_Object lispFrame;
- XSETFRAME (lispFrame, frame);
- ns_raise_frame(frame);
- Fns_popup_font_panel (lispFrame);
-}
-
-@end /* EmacsPrefsController */
-
-
-
/* ==========================================================================
Set to none means that the function key is not interpreted by Emacs at all,\n\
allowing it to be used at a lower level for accented character entry.");
- DEFVAR_LISP ("ns-expand-space", &ns_expand_space,
- "Amount by which spacing between lines is expanded (positive)\n\
-or shrunk (negative). Zero (the default) means standard line height.\n\
-(This variable should only be read, never set.)");
-
DEFVAR_LISP ("ns-antialias-text", &ns_antialias_text,
"Non-nil (the default) means to render text antialiased. Only has an effect on OS X Panther and above.");