+(setq command-line-args (x-handle-args command-line-args))
+
+;;; Make sure we have a valid resource name.
+(or (stringp x-resource-name)
+ (let (i)
+ (setq x-resource-name (invocation-name))
+
+ ;; Change any . or * characters in x-resource-name to hyphens,
+ ;; so as not to choke when we use it in X resource queries.
+ (while (setq i (string-match "[.*]" x-resource-name))
+ (aset x-resource-name i ?-))))
+
+;; For the benefit of older Emacses (19.27 and earlier) that are sharing
+;; the same lisp directory, don't pass the third argument unless we seem
+;; to have the multi-display support.
+(if (fboundp 'x-close-connection)
+ (x-open-connection (or x-display-name
+ (setq x-display-name (getenv "DISPLAY")))
+ x-command-line-resources
+ ;; Exit Emacs with fatal error if this fails.
+ t)
+ (x-open-connection (or x-display-name
+ (setq x-display-name (getenv "DISPLAY")))
+ x-command-line-resources))
+
+(setq frame-creation-function 'x-create-frame-with-faces)
+
+(setq x-cut-buffer-max (min (- (/ (x-server-max-request-size) 2) 100)
+ x-cut-buffer-max))
+
+(if (fboundp 'new-fontset)
+ (progn
+ ;; Create a default fontset.
+ (create-fontset-from-fontset-spec default-fontset-spec)
+
+ ;; Create fontset specified in X resources.
+ (create-fontset-from-x-resource)
+
+ ;; Try to create a fontset from font specification which comes from
+ ;; initial-frame-alist, default-frame-alist, or X resource if the font
+ ;; name conforms to XLFD and the registry part is `fontset'. A font
+ ;; specification in command line argument (-fn XXXX) should be in
+ ;; default-frame-alist already. However, any font specification in
+ ;; site-start library, user's init file (.emacs), and default.el are
+ ;; not yet handled here.
+
+ (let ((font (or (cdr (assq 'font initial-frame-alist))
+ (cdr (assq 'font default-frame-alist))
+ (x-get-resource "font" "Font")
+ (x-get-resource "fontset" "Fontset")))
+ xlfd-fields fontlist)
+ (if (and font
+ (not (query-fontset font))
+ (setq xlfd-fields (x-decompose-font-name font)))
+ (progn
+ (if (not (string= "fontset"
+ (aref xlfd-fields xlfd-regexp-registry-subnum)))
+ (progn
+ ;; Create a fontset of the name FONT.
+ (setq fontlist (list (cons 'ascii font)))
+ (aset xlfd-fields xlfd-regexp-foundry-subnum nil)
+ (aset xlfd-fields xlfd-regexp-family-subnum nil)
+ (aset xlfd-fields xlfd-regexp-adstyle-subnum nil)
+ (aset xlfd-fields xlfd-regexp-avgwidth-subnum nil)))
+ (new-fontset font (x-complement-fontset-spec xlfd-fields fontlist)))))))
+
+;; Sun expects the menu bar cut and paste commands to use the clipboard.
+;; This has ,? to match both on Sunos and on Solaris.
+(if (string-match "Sun Microsystems,? Inc\\."
+ (x-server-vendor))
+ (menu-bar-enable-clipboard))
+
+;; Apply a geometry resource to the initial frame. Put it at the end
+;; of the alist, so that anything specified on the command line takes
+;; precedence.
+(let* ((res-geometry (x-get-resource "geometry" "Geometry"))
+ parsed)
+ (if res-geometry
+ (progn
+ (setq parsed (x-parse-geometry res-geometry))
+ ;; If the resource specifies a position,
+ ;; call the position and size "user-specified".
+ (if (or (assq 'top parsed) (assq 'left parsed))
+ (setq parsed (cons '(user-position . t)
+ (cons '(user-size . t) parsed))))
+ ;; All geometry parms apply to the initial frame.
+ (setq initial-frame-alist (append initial-frame-alist parsed))
+ ;; The size parms apply to all frames.
+ (if (assq 'height parsed)
+ (setq default-frame-alist
+ (cons (cons 'height (cdr (assq 'height parsed)))
+ default-frame-alist)))
+ (if (assq 'width parsed)
+ (setq default-frame-alist
+ (cons (cons 'width (cdr (assq 'width parsed)))
+ default-frame-alist))))))
+
+;; Check the reverseVideo resource.
+(let ((case-fold-search t))
+ (let ((rv (x-get-resource "reverseVideo" "ReverseVideo")))
+ (if (and rv
+ (string-match "^\\(true\\|yes\\|on\\)$" rv))
+ (setq default-frame-alist
+ (cons '(reverse . t) default-frame-alist)))))
+
+;; Set x-selection-timeout, measured in milliseconds.
+(let ((res-selection-timeout
+ (x-get-resource "selectionTimeout" "SelectionTimeout")))
+ (setq x-selection-timeout 20000)
+ (if res-selection-timeout
+ (setq x-selection-timeout (string-to-number res-selection-timeout))))
+
+(defun x-win-suspend-error ()
+ (error "Suspending an emacs running under X makes no sense"))
+(add-hook 'suspend-hook 'x-win-suspend-error)
+
+;;; Arrange for the kill and yank functions to set and check the clipboard.
+(setq interprogram-cut-function 'x-select-text)
+(setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
+
+;;; Turn off window-splitting optimization; X is usually fast enough
+;;; that this is only annoying.
+(setq split-window-keep-point t)
+
+;; Don't show the frame name; that's redundant with X.
+(setq-default mode-line-buffer-identification '("Emacs: %12b"))
+
+;;; Motif direct handling of f10 wasn't working right,
+;;; So temporarily we've turned it off in lwlib-Xm.c
+;;; and turned the Emacs f10 back on.
+;;; ;; Motif normally handles f10 itself, so don't try to handle it a second time.
+;;; (if (featurep 'motif)
+;;; (global-set-key [f10] 'ignore))
+
+;;; x-win.el ends here