Fix case of "GNUstep".
[bpt/emacs.git] / lisp / term / ns-win.el
index cb6e083..51de66e 100644 (file)
@@ -1,6 +1,7 @@
 ;;; ns-win.el --- lisp side of interface with NeXT/Open/GNUstep/MacOS X window system
 
-;; Copyright (C) 1993, 1994, 2005, 2006, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1994, 2005, 2006, 2007, 2008
+;;   Free Software Foundation, Inc.
 
 ;; Authors: Carl Edman, Christian Limpach, Scott Bender,
 ;;          Christophe de Dinechin, Adrian Robert
 
 ;;; Commentary:
 
-;; ns-win.el:  this file is loaded from ../lisp/startup.el when it recognizes
-;; that NS windows are to be used.  Command line switches are parsed and those
-;; pertaining to NS are processed and removed from the command line.  The
-;; NS display is opened and hooks are set for popping up the initial window.
+;; ns-win.el: this file is loaded from ../lisp/startup.el when it
+;; recognizes that Nextstep windows are to be used.  Command line
+;; switches are parsed and those pertaining to Nextstep are processed
+;; and removed from the command line.  The Nextstep display is opened
+;; and hooks are set for popping up the initial window.
 
 ;; startup.el will then examine startup files, and eventually call the hooks
 ;; which create the first window (s).
 
-;; A number of other NS convenience functions are defined in this file,
-;; which works in close coordination with src/nsfns.m.
+;; A number of other Nextstep convenience functions are defined in
+;; this file, which works in close coordination with src/nsfns.m.
 
 ;;; Code:
 
 
-(if (not (featurep 'ns-windowing))
-    (error "%s: Loading ns-win.el but not compiled for *Step/OS X"
+(if (not (featurep 'ns))
+    (error "%s: Loading ns-win.el but not compiled for GNUstep/MacOS"
           (invocation-name)))
 
 (eval-when-compile (require 'cl))
 ;; nsterm.m
 (defvar ns-version-string)
 (defvar ns-expand-space)
-(defvar ns-cursor-blink-rate)
 (defvar ns-alternate-modifier)
 
-(declare-function ns-server-vendor "nsfns.m" (&optional display))
-(declare-function ns-server-version "nsfns.m" (&optional display))
-
 ;;;; Command line argument handling.
 
 (defvar ns-invocation-args nil)
@@ -96,8 +94,8 @@
                                   initial-frame-alist)))
 
 ;; Set (but not used?) in frame.el.
-(defvar ns-display-name nil
-  "The name of the NS display on which Emacs was started.")
+(defvar x-display-name nil
+  "The name of the Nextstep display on which Emacs was started.")
 
 ;; nsterm.m.
 (defvar ns-input-file)
                                      '(ns-open-temp-file))
         ns-input-file (append ns-input-file (list (pop ns-invocation-args)))))
 
-(defun ns-ignore-0-arg (switch))
 (defun ns-ignore-1-arg (switch)
   (setq ns-invocation-args (cdr ns-invocation-args)))
 (defun ns-ignore-2-arg (switch)
   (setq ns-invocation-args (cddr ns-invocation-args)))
 
 (defun ns-handle-args (args)
-  "Process NeXTSTEP-related command line options.
+  "Process Nextstep-related command line options.
 This is run before the user's startup file is loaded.
-The options in ARGS are copied to `ns-invocation-args'.  The
-NeXTSTEP-related settings are then applied using the handlers
+The options in ARGS are copied to `ns-invocation-args'.
+The Nextstep-related settings are then applied using the handlers
 defined in `command-line-ns-option-alist'.
-The return value is ARGS minus the arguments processed."
+The return value is ARGS minus the number of arguments processed."
   ;; We use ARGS to accumulate the args that we don't handle here, to return.
   (setq ns-invocation-args args
         args nil)
@@ -161,29 +158,32 @@ The return value is ARGS minus the arguments processed."
        (setq args (cons orig-this-switch args)))))
   (nreverse args))
 
-(defun x-parse-geometry (geom)
-  "Parse an NS-style geometry string STRING.
+(defun ns-parse-geometry (geom)
+  "Parse a Nextstep-style geometry string GEOM.
 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
 The properties returned may include `top', `left', `height', and `width'."
-  (if (string-match "\\([0-9]+\\)\\( \\([0-9]+\\)\\( \\([0-9]+\\)\\( \\([0-9]+\\) ?\\)?\\)?\\)?"
-                    geom)
-      (apply 'append
-             (list
-              (list (cons 'top (string-to-number (match-string 1 geom))))
-              (if (match-string 3 geom)
-                  (list (cons 'left (string-to-number (match-string 3 geom)))))
-              (if (match-string 5 geom)
-                  (list (cons 'height (string-to-number (match-string 5 geom)))))
-              (if (match-string 7 geom)
-                  (list (cons 'width (string-to-number (match-string 7 geom)))))))
-    '()))
-
-
+  (when (string-match "\\([0-9]+\\)\\( \\([0-9]+\\)\\( \\([0-9]+\\)\
+\\( \\([0-9]+\\) ?\\)?\\)?\\)?"
+                     geom)
+    (apply
+     'append
+     (list
+      (list (cons 'top (string-to-number (match-string 1 geom))))
+      (if (match-string 3 geom)
+         (list (cons 'left (string-to-number (match-string 3 geom)))))
+      (if (match-string 5 geom)
+         (list (cons 'height (string-to-number (match-string 5 geom)))))
+      (if (match-string 7 geom)
+         (list (cons 'width (string-to-number (match-string 7 geom)))))))))
 
 ;;;; Keyboard mapping.
 
-;; These tell read-char how to convert
-;; these special chars to ASCII.
+;; These tell read-char how to convert these special chars to ASCII.
+;;TODO: all terms have these, and at least the return mapping is necessary
+;;      for tramp to recognize the enter key.
+;;      Perhaps they should be moved into common code somewhere
+;;      (when a window system is active).
+;;      Remove if no problems for some time after 2008-08-06.
 (put 'backspace 'ascii-character 127)
 (put 'delete 'ascii-character 127)
 (put 'tab 'ascii-character ?\t)
@@ -193,26 +193,30 @@ The properties returned may include `top', `left', `height', and `width'."
 (put 'return 'ascii-character 13)
 (put 'escape 'ascii-character ?\e)
 
-;; Map certain keypad keys into ASCII characters
-;; that people usually expect.
-(define-key function-key-map [backspace] [127])
-(define-key function-key-map [delete] [127])
-(define-key function-key-map [tab] [?\t])
-(define-key function-key-map [S-tab] [25])
-(define-key function-key-map [linefeed] [?\n])
-(define-key function-key-map [clear] [11])
-(define-key function-key-map [return] [13])
-(define-key function-key-map [escape] [?\e])
-(define-key function-key-map [M-backspace] [?\M-\d])
-(define-key function-key-map [M-delete] [?\M-\d])
-(define-key function-key-map [M-tab] [?\M-\t])
-(define-key function-key-map [M-linefeed] [?\M-\n])
-(define-key function-key-map [M-clear] [?\M-\013])
-(define-key function-key-map [M-return] [?\M-\015])
-(define-key function-key-map [M-escape] [?\M-\e])
-
-
-;; Here are some NeXTSTEP like bindings for command key sequences.
+
+(defvar ns-alternatives-map
+  (let ((map (make-sparse-keymap)))
+    ;; Map certain keypad keys into ASCII characters
+    ;; that people usually expect.
+    (define-key map [backspace] [?\d])
+    (define-key map [delete] [?\d])
+    (define-key map [tab] [?\t])
+    (define-key map [S-tab] [25])
+    (define-key map [linefeed] [?\n])
+    (define-key map [clear] [?\C-l])
+    (define-key map [return] [?\C-m])
+    (define-key map [escape] [?\e])
+    (define-key map [M-backspace] [?\M-\d])
+    (define-key map [M-delete] [?\M-\d])
+    (define-key map [M-tab] [?\M-\t])
+    (define-key map [M-linefeed] [?\M-\n])
+    (define-key map [M-clear] [?\M-\C-l])
+    (define-key map [M-return] [?\M-\C-m])
+    (define-key map [M-escape] [?\M-\e])
+    map)
+  "Keymap of alternative meanings for some keys under NS.")
+
+;; Here are some Nextstep-like bindings for command key sequences.
 (define-key global-map [?\s-,] 'ns-popup-prefs-panel)
 (define-key global-map [?\s-'] 'next-multiframe-window)
 (define-key global-map [?\s-`] 'other-frame)
@@ -265,8 +269,12 @@ The properties returned may include `top', `left', `height', and `width'."
 (define-key global-map [kp-prior] 'scroll-down)
 (define-key global-map [kp-next] 'scroll-up)
 
+;;; Allow shift-clicks to work similarly to under Nextstep
+(define-key global-map [S-mouse-1] 'mouse-save-then-kill)
+(global-unset-key [S-down-mouse-1])
 
-;; Special NeXTSTEP generated events are converted to function keys.  Here
+
+;; 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)))
@@ -281,22 +289,17 @@ The properties returned may include `top', `left', `height', and `width'."
 (define-key global-map [ns-insert-working-text] 'ns-insert-working-text)
 (define-key global-map [ns-delete-working-text] 'ns-delete-working-text)
 (define-key global-map [ns-spi-service-call] 'ns-spi-service-call)
+(define-key global-map [ns-new-frame] 'make-frame)
 
 
 
 ;; Functions to set environment variables by running a subshell.
-;;; Idea based on NS 4.2 distribution, this version of code based on
-;;; mac-read-environment-vars-from-shell () by David Reitter.
+;;; Idea based on Nextstep 4.2 distribution, this version of code
+;;; based on mac-read-environment-vars-from-shell () by David Reitter.
 ;;; Mostly used only under ns-extended-platform-support-mode.
 
 (defun ns-make-command-string (cmdlist)
-  (let ((str "")
-       (cmds cmdlist))
-    (while cmds
-      (if (not (eq str "")) (setq str (format "%s ; " str)))
-      (setq str (format "%s%s" str (car cmds)))
-      (setq cmds (cdr cmds)))
-    str))
+  (mapconcat 'identity cmdlist " ; "))
 
 ;;;###autoload
 (defun ns-grabenv (&optional shell-path startup)
@@ -327,23 +330,17 @@ this defaults to \"printenv\"."
 (defvaralias 'mac-control-modifier 'ns-control-modifier)
 (defvaralias 'mac-option-modifier 'ns-option-modifier)
 (defvaralias 'mac-function-modifier 'ns-function-modifier)
+(defalias 'do-applescript 'ns-do-applescript)
 
-;; alt-up/down scrolling a la Stuart.app
-;; only activated if ns-extended-platform-support is on
-(defun up-one () (interactive) (scroll-up 1))
-(defun down-one () (interactive) (scroll-down 1))
-(defun left-one () (interactive) (scroll-left 1))
-(defun right-one () (interactive) (scroll-right 1))
 
 (defvar menu-bar-ns-file-menu)         ; below
 
-;; Toggle some additional NS-like features that may interfere with users'
-;; expectations coming from emacs on other platforms.
+;; Toggle some additional Nextstep-like features that may interfere
+;; with users' expectations coming from emacs on other platforms.
 (define-minor-mode ns-extended-platform-support-mode
-  "Toggle NS extended platform support features.
+  "Toggle Nextstep extended platform support features.
    When this mode is active (no modeline indicator):
    - File menu is altered slightly in keeping with conventions.
-   - Meta-up, meta-down are bound to scroll window up and down one line.
    - Screen position is preserved in scrolling.
    - Transient mark mode is activated"
   :init-value nil
@@ -351,39 +348,40 @@ this defaults to \"printenv\"."
   :group 'ns
   (if ns-extended-platform-support-mode
       (progn
-        (global-set-key [M-up] 'down-one)
-        (global-set-key [M-down] 'up-one)
-        ;; These conflict w/word-left, word-right.
-        ;;(global-set-key [M-left] 'left-one)
-        ;;(global-set-key [M-right] 'right-one)
-
+       (defun ns-show-manual () "Show Emacs.app manual" (interactive) (info "ns-emacs"))
+       (setq where-is-preferred-modifier 'super)
         (setq scroll-preserve-screen-position t)
         (transient-mark-mode 1)
 
-        ;; Change file menu to simplify and add a couple of NS-specific items
+        ;; Change file menu to simplify and add a couple of
+        ;; Nextstep-specific items
         (easy-menu-remove-item global-map '("menu-bar") 'file)
         (easy-menu-add-item global-map '(menu-bar)
-                            (cons "File" menu-bar-ns-file-menu) 'edit))
+                            (cons "File" menu-bar-ns-file-menu) 'edit)
+       (define-key menu-bar-help-menu [ns-manual]
+         '(menu-item "Emacs.app Manual" ns-show-manual)))
     (progn
       ;; Undo everything above.
-      (global-unset-key [M-up])
-      (global-unset-key [M-down])
+      (fmakunbound 'ns-show-manual)
+      (setq where-is-preferred-modifier 'nil)
       (setq scroll-preserve-screen-position nil)
       (transient-mark-mode 0)
       (easy-menu-remove-item global-map '("menu-bar") 'file)
       (easy-menu-add-item global-map '(menu-bar)
-                          (cons "File" menu-bar-file-menu) 'edit))))
+                          (cons "File" menu-bar-file-menu) 'edit)
+      (easy-menu-remove-item global-map '("menu-bar" "help-menu") 'ns-manual)
+)))
 
 
 (defun x-setup-function-keys (frame)
-  "Set up function Keys for NS for given FRAME."
+  "Set up function Keys for Nextstep for frame FRAME."
   (unless (terminal-parameter frame 'x-setup-function-keys)
     (with-selected-frame frame
-      (setq interprogram-cut-function 'ns-select-text
-           interprogram-paste-function 'ns-pasteboard-value)
-      ;; (let ((map (copy-keymap x-alternatives-map)))
-      ;;   (set-keymap-parent map (keymap-parent local-function-key-map))
-      ;;   (set-keymap-parent local-function-key-map map))
+      (setq interprogram-cut-function 'x-select-text
+           interprogram-paste-function 'x-cut-buffer-or-selection-value)
+      (let ((map (copy-keymap ns-alternatives-map)))
+       (set-keymap-parent map (keymap-parent local-function-key-map))
+       (set-keymap-parent local-function-key-map map))
       (setq system-key-alist
             (list
              (cons (logior (lsh 0 16)   1) 'ns-power-off)
@@ -397,6 +395,7 @@ this defaults to \"printenv\"."
              (cons (logior (lsh 0 16)   9) 'ns-insert-working-text)
              (cons (logior (lsh 0 16)  10) 'ns-delete-working-text)
              (cons (logior (lsh 0 16)  11) 'ns-spi-service-call)
+             (cons (logior (lsh 0 16)  12) 'ns-new-frame)
              (cons (logior (lsh 1 16)  32) 'f1)
              (cons (logior (lsh 1 16)  33) 'f2)
              (cons (logior (lsh 1 16)  34) 'f3)
@@ -477,40 +476,8 @@ this defaults to \"printenv\"."
              (cons (logior (lsh 3 16)  25) 'S-tab)
              (cons (logior (lsh 3 16)  27) 'escape)
              (cons (logior (lsh 3 16) 127) 'delete)
-             ))
-      (set-terminal-parameter frame 'x-setup-function-keys t))))
-
-
-
-;;;; Miscellaneous mouse bindings.
-
-;;; Allow shift-clicks to work just like under NS
-(defun mouse-extend-region (event)
-  "Move point or mark so as to extend region.
-This should be bound to a mouse click event type."
-  (interactive "e")
-  (mouse-minibuffer-check event)
-  (let ((posn (event-end event)))
-    (if (not (windowp (posn-window posn)))
-        (error "Cursor not in text area of window"))
-    (select-window (posn-window posn))
-    (cond
-     ((not (numberp (posn-point posn))))
-     ((or (not mark-active) (> (abs (- (posn-point posn) (point)))
-                               (abs (- (posn-point posn) (mark)))))
-      (let ((point-save (point)))
-        (unwind-protect
-            (progn
-              (goto-char (posn-point posn))
-              (push-mark nil t t)
-              (or transient-mark-mode
-                  (sit-for 1)))
-          (goto-char point-save))))
-     (t
-      (goto-char (posn-point posn))))))
-
-(define-key global-map [S-mouse-1] 'mouse-extend-region)
-(global-unset-key [S-down-mouse-1])
+             )))
+    (set-terminal-parameter frame 'x-setup-function-keys t)))
 
 
 
@@ -582,7 +549,7 @@ This should be bound to a mouse click event type."
 (define-key ns-ps-print-menu-map [ps-print-region-faces]
   '("Region" . ps-print-region-with-faces))
 (define-key ns-ps-print-menu-map [ps-print-buffer-faces]
-  '("Buffer" . ns-ps-print-buffer-with-faces))
+  '("Buffer" . ps-print-buffer-with-faces))
 (define-key menu-bar-ns-file-menu [postscript-print]
   (cons "Postscript Print" ns-ps-print-menu-map))
 
@@ -779,12 +746,12 @@ This should be bound to a mouse click event type."
       (define-key global-map mapping (cons (car path) name))))
     name))
 
-(precompute-menubar-bindings)
-
 ;; nsterm.m
 (defvar ns-input-spi-name)
 (defvar ns-input-spi-arg)
 
+(declare-function dnd-open-file "dnd" (uri action))
+
 (defun ns-spi-service-call ()
   "Respond to a service request."
   (interactive)
@@ -807,10 +774,11 @@ This should be bound to a mouse click event type."
 
 
 
-;;;; Composed key sequence handling for NS system input methods.
-;;;; (On NS systems, input methods are provided for CJK characters,
-;;;;  etc. which require multiple keystrokes, and during entry a
-;;;;  partial ("working") result is typically shown in the editing window.)
+;;;; Composed key sequence handling for Nextstep system input methods.
+;;;; (On Nextstep systems, input methods are provided for CJK
+;;;; characters, etc. which require multiple keystrokes, and during
+;;;; entry a partial ("working") result is typically shown in the
+;;;; editing window.)
 
 (defface ns-working-text-face
   '((t :underline t))
@@ -919,7 +887,7 @@ See ns-insert-working-text."
       (set-file-name-coding-system 'utf-8-nfd)))
 
 ;; PENDING: disable composition-based display for Indic scripts as it
-;;        is not working well under NS for some reason
+;;        is not working well under Nextstep for some reason
 (set-char-table-range composition-function-table
                       '(#x0900 . #x0DFF) nil)
 
@@ -946,7 +914,7 @@ prompting.  If file is a directory perform a find-file on it."
       (push-mark (+ (point) (car (cdr (insert-file-contents f))))))))
 
 (defvar ns-select-overlay nil
-  "Overlay used to highlight areas in files requested by NS apps.")
+  "Overlay used to highlight areas in files requested by Nextstep apps.")
 (make-variable-buffer-local 'ns-select-overlay)
 
 (defvar ns-input-line)                         ; nsterm.m
@@ -986,7 +954,7 @@ Lines are highlighted according to `ns-input-line'."
         (setq ns-select-overlay (delete-overlay ns-select-overlay))))))
 
 (defun ns-unselect-line ()
-  "Removes any NS highlight a buffer may contain."
+  "Removes any Nextstep highlight a buffer may contain."
   (if ns-select-overlay
       (setq ns-select-overlay (delete-overlay ns-select-overlay))))
 
@@ -1026,10 +994,6 @@ Lines are highlighted according to `ns-input-line'."
   (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 "CursorBlinkRate"
-                   (if ns-cursor-blink-rate
-                       (number-to-string ns-cursor-blink-rate)
-                     "NO"))
   (ns-set-resource nil "ExpandSpace"
                    (if ns-expand-space
                        (number-to-string ns-expand-space)
@@ -1064,7 +1028,7 @@ Lines are highlighted according to `ns-input-line'."
                               (t (cdr v)))))
     (if (setq v (assq 'internal-border-width p))
        (ns-set-resource nil "InternalBorderWidth"
-                        (number-to-string v)))
+                        (number-to-string (cdr v))))
     (if (setq v (assq 'vertical-scroll-bars p))
        (ns-set-resource nil "VerticalScrollBars"
                         (case (cdr v)
@@ -1193,7 +1157,7 @@ unless the current buffer is a scratch buffer.")
 
 ;;;; Frame-related functions.
 
-;; Don't show the frame name; that's redundant with NS.
+;; Don't show the frame name; that's redundant with Nextstep.
 (setq-default mode-line-frame-identification '("  "))
 
 ;; You say tomAYto, I say tomAHto..
@@ -1226,7 +1190,6 @@ unless the current buffer is a scratch buffer.")
 
 ;; If no position specified, make new frame offset by 25 from current.
 (defvar parameters)                 ; dynamically bound in make-frame
-
 (add-hook 'before-make-frame-hook
           (lambda ()
             (let ((left (cdr (assq 'left (frame-parameters))))
@@ -1242,13 +1205,11 @@ unless the current buffer is a scratch buffer.")
                                              parameters))))))))
 
 ;; frame will be focused anyway, so select it
+;; (if this is not done, modeline is dimmed until first interaction)
 (add-hook 'after-make-frame-functions 'select-frame)
 
-;; (defun ns-win-suspend-error ()
-;;   (error "Suspending an emacs running under *Step/OS X makes no sense"))
-;; (add-hook 'suspend-hook 'ns-win-suspend-error)
-;; (substitute-key-definition 'suspend-emacs 'iconify-or-deiconify-frame
-;;                        global-map)
+(defvar tool-bar-mode)
+(declare-function tool-bar-mode "tool-bar" (&optional arg))
 
 ;; Based on a function by David Reitter <dreitter@inf.ed.ac.uk> ;
 ;; see http://lists.gnu.org/archive/html/emacs-devel/2005-09/msg00681.html .
@@ -1262,28 +1223,6 @@ unless the current buffer is a scratch buffer.")
                                   0 1)) ))
   (if (not tool-bar-mode) (tool-bar-mode t)))
 
-(defvar ns-cursor-blink-mode)          ; nsterm.m
-
-;; Redefine from frame.el.
-(define-minor-mode blink-cursor-mode
-  "Toggle blinking cursor mode.
-With a numeric argument, turn blinking cursor mode on if ARG is positive,
-otherwise turn it off.  When blinking cursor mode is enabled, the
-cursor of the selected window blinks.
-
-Note that this command is effective only when Emacs
-displays through a window system, because then Emacs does its own
-cursor display.  On a text-only terminal, this is not implemented."
-  :init-value (not (or noninteractive
-                      no-blinking-cursor
-                      (eq ns-cursor-blink-rate nil)))
-  :initialize 'custom-initialize-safe-default
-  :group 'cursor
-  :global t
-  (if blink-cursor-mode
-      (setq ns-cursor-blink-mode t)
-      (setq ns-cursor-blink-mode nil)))
-
 
 
 ;;;; Dialog-related functions.
@@ -1305,16 +1244,9 @@ cursor display.  On a text-only terminal, this is not implemented."
          (error "Cancelled")))
     (print-buffer)))
 
-(defun ns-yes-or-no-p (prompt)
-  "As yes-or-no-p except that NS panel always used for querying."
-  (interactive)
-  (setq last-nonmenu-event nil)
-  (yes-or-no-p prompt))
-
 
 ;;;; Font support.
 
-(defalias 'x-list-fonts 'ns-list-fonts)
 ;; Needed for font listing functions under both backend and normal
 (setq scalable-fonts-allowed t)
 
@@ -1382,27 +1314,27 @@ See the documentation of `create-fontset-from-fontset-spec for the format.")
 (declare-function ns-store-cut-buffer-internal "nsselect.m" (buffer string))
 
 (defun ns-set-pasteboard (string)
-  "Store STRING into the NS server's pasteboard."
+  "Store STRING into the pasteboard of the Nextstep display server."
   ;; Check the data type of STRING.
   (if (not (stringp string)) (error "Nonstring given to pasteboard"))
   (ns-store-cut-buffer-internal 'PRIMARY string))
 
 ;; We keep track of the last text selected here, so we can check the
 ;; current selection against it, and avoid passing back our own text
-;; from ns-pasteboard-value.
+;; from x-cut-buffer-or-selection-value.
 (defvar ns-last-selected-text nil)
 
-(defun ns-select-text (text &optional push)
+(defun x-select-text (text &optional push)
   "Put TEXT, a string, on the pasteboard."
   ;; Don't send the pasteboard too much text.
   ;; It becomes slow, and if really big it causes errors.
   (ns-set-pasteboard text)
   (setq ns-last-selected-text text))
 
-;; Return the value of the current NS selection.  For compatibility
-;; with older NS applications, this checks cut buffer 0 before
-;; retrieving the value of the primary selection.
-(defun ns-pasteboard-value ()
+;; Return the value of the current Nextstep selection.  For
+;; compatibility with older Nextstep applications, this checks cut
+;; buffer 0 before retrieving the value of the primary selection.
+(defun x-cut-buffer-or-selection-value ()
   (let (text)
 
     ;; Consult the selection, then the cut buffer.  Treat empty strings
@@ -1431,14 +1363,9 @@ See the documentation of `create-fontset-from-fontset-spec for the format.")
 
 ;; PENDING: not sure what to do here.. for now interprog- are set in
 ;; init-fn-keys, and unsure whether these x- settings have an effect.
-;;(setq interprogram-cut-function 'ns-select-text
-;;      interprogram-paste-function 'ns-pasteboard-value)
+;;(setq interprogram-cut-function 'x-select-text
+;;      interprogram-paste-function 'x-cut-buffer-or-selection-value)
 ;; These only needed if above not working.
-(defalias 'x-select-text 'ns-select-text)
-(defalias 'x-cut-buffer-or-selection-value 'ns-pasteboard-value)
-(defalias 'x-disown-selection-internal 'ns-disown-selection-internal)
-(defalias 'x-get-selection-internal 'ns-get-selection-internal)
-(defalias 'x-own-selection-internal 'ns-own-selection-internal)
 
 (set-face-background 'region "ns_selection_color")
 
@@ -1450,8 +1377,10 @@ See the documentation of `create-fontset-from-fontset-spec for the format.")
 (global-unset-key [vertical-scroll-bar mouse-1])
 (global-unset-key [vertical-scroll-bar drag-mouse-1])
 
+(declare-function scroll-bar-scale "scroll-bar" (num-denom whole))
+
 (defun ns-scroll-bar-move (event)
-  "Scroll the frame according to an NS scroller event."
+  "Scroll the frame according to a Nextstep scroller event."
   (interactive "e")
   (let* ((pos (event-end event))
          (window (nth 0 pos))
@@ -1471,7 +1400,7 @@ See the documentation of `create-fontset-from-fontset-spec for the format.")
       (vertical-motion (/ (window-height window) 2) window))))
 
 (defun ns-handle-scroll-bar-event (event)
-  "Handle scroll bar EVENT to emulate Mac Toolbox style scrolling."
+  "Handle scroll bar EVENT to emulate Nextstep style scrolling."
   (interactive "e")
   (let* ((position (event-start event))
         (bar-part (nth 4 position))
@@ -1507,13 +1436,11 @@ See the documentation of `create-fontset-from-fontset-spec for the format.")
 
 (defvar x-colors (ns-list-colors)
   "The list of colors defined in non-PANTONE color files.")
-(defvar colors x-colors
-  "The list of colors defined in non-PANTONE color files.")
 
-(defun ns-defined-colors (&optional frame)
+(defun xw-defined-colors (&optional frame)
   "Return a list of colors supported for a particular frame.
 The argument FRAME specifies which frame to try.
-The value may be different for frames on different NS displays."
+The value may be different for frames on different Nextstep displays."
   (or frame (setq frame (selected-frame)))
   (let ((all-colors x-colors)
        (this-color nil)
@@ -1524,8 +1451,6 @@ The value may be different for frames on different NS displays."
       ;; (and (face-color-supported-p frame this-color t)
       (setq defined-colors (cons this-color defined-colors))) ;;)
     defined-colors))
-(defalias 'x-defined-colors 'ns-defined-colors)
-(defalias 'xw-defined-colors 'ns-defined-colors)
 
 (declare-function ns-set-alpha "nsfns.m" (color alpha))
 
@@ -1609,48 +1534,27 @@ Note, tranparency works better on Tiger (10.4) and higher."
      (t
       (set-face-background face ns-input-color frame)))))
 
-
-
-;; Misc aliases.
-(defalias 'x-display-mm-width 'ns-display-mm-width)
-(defalias 'x-display-mm-height 'ns-display-mm-height)
-(defalias 'x-display-backing-store 'ns-display-backing-store)
-(defalias 'x-display-save-under 'ns-display-save-under)
-(defalias 'x-display-visual-class 'ns-display-visual-class)
-(defalias 'x-display-screens 'ns-display-screens)
-(defalias 'x-focus-frame 'ns-focus-frame)
-
-;; Set some options to be as NS-like as possible.
+;; Set some options to be as Nextstep-like as possible.
 (setq frame-title-format t
       icon-title-format t)
 
-;; Set up browser connectivity.
-(defvar browse-url-generic-program)
-
-(setq browse-url-browser-function 'browse-url-generic)
-(setq browse-url-generic-program
-      (cond ((eq system-type 'darwin) "open")
-            ;; Otherwise, GNUstep.
-            (t "gopen")))
-
 
 (defvar ns-initialized nil
-  "Non-nil if NS windowing has been initialized.")
-
-(declare-function ns-open-connection "nsfns.m"
-                 (display &optional resource_string must_succeed))
+  "Non-nil if Nextstep windowing has been initialized.")
 
 (declare-function ns-list-services "nsfns.m" ())
+(declare-function x-open-connection "xfns.c"
+                  (display &optional xrm-string must-succeed))
 
-;; Do the actual NS Windows setup here; the above code just defines
-;; functions and variables that we use now.
+;; Do the actual Nextstep Windows setup here; the above code just
+;; defines functions and variables that we use now.
 (defun ns-initialize-window-system ()
-  "Initialize Emacs for NS (Cocoa / GNUstep) windowing."
+  "Initialize Emacs for Nextstep (Cocoa / GNUstep) windowing."
 
   ;; PENDING: not needed?
   (setq command-line-args (ns-handle-args command-line-args))
 
-  (ns-open-connection (system-name) nil t)
+  (x-open-connection (system-name) nil t)
 
   (dolist (service (ns-list-services))
       (if (eq (car service) 'undefined)