;;; ns-win.el --- lisp side of interface with NeXT/Open/GNUstep/MacOS X window system
-;; Copyright (C) 1993, 1994, 2005, 2006, 2007, 2008, 2009
+;; Copyright (C) 1993, 1994, 2005, 2006, 2007, 2008, 2009, 2010
;; Free Software Foundation, Inc.
;; Authors: Carl Edman
;; Set (but not used?) in frame.el.
(defvar x-display-name nil
- "The name of the Nextstep display on which Emacs was started.")
+ "The name of the window display on which Emacs was started.
+On X, the display name of individual X frames is recorded in the
+`display' frame parameter.")
;; nsterm.m.
(defvar ns-input-file)
;;;; Keyboard mapping.
;; 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)
(put 'S-tab 'ascii-character (logior 16 ?\t))
-(put 'linefeed 'ascii-character ?\n)
-(put 'clear 'ascii-character 12)
-(put 'return 'ascii-character 13)
-(put 'escape 'ascii-character ?\e)
-
(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])
(defalias 'do-applescript 'ns-do-applescript)
(defun x-setup-function-keys (frame)
- "Set up function Keys for Nextstep for frame FRAME."
+ "Set up `function-key-map' on the graphical frame FRAME."
(unless (terminal-parameter frame 'x-setup-function-keys)
(with-selected-frame frame
(setq interprogram-cut-function 'x-select-text
(set-terminal-parameter frame 'x-setup-function-keys t)))
-
-;; Must come after keybindings.
-
-;; (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
(define-key global-map [menu-bar] (make-sparse-keymap "menu-bar"))
(if ns-select-overlay
(setq ns-select-overlay (delete-overlay ns-select-overlay)))
(deactivate-mark)
- (goto-line (if (consp ns-input-line)
- (min (car ns-input-line) (cdr ns-input-line))
- ns-input-line)))
+ (goto-char (point-min))
+ (forward-line (1- (if (consp ns-input-line)
+ (min (car ns-input-line) (cdr ns-input-line))
+ ns-input-line))))
(ns-input-line
(if (not ns-select-overlay)
- (overlay-put (setq ns-select-overlay (make-overlay (point-min) (point-min)))
+ (overlay-put (setq ns-select-overlay (make-overlay (point-min)
+ (point-min)))
'face 'highlight))
(let ((beg (save-excursion
- (goto-line (if (consp ns-input-line)
- (min (car ns-input-line) (cdr ns-input-line))
- ns-input-line))
- (point)))
+ (goto-char (point-min))
+ (line-beginning-position
+ (if (consp ns-input-line)
+ (min (car ns-input-line) (cdr ns-input-line))
+ ns-input-line))))
(end (save-excursion
- (goto-line (+ 1 (if (consp ns-input-line)
- (max (car ns-input-line) (cdr ns-input-line))
- ns-input-line)))
- (point))))
+ (goto-char (point-min))
+ (line-beginning-position
+ (1+ (if (consp ns-input-line)
+ (max (car ns-input-line) (cdr ns-input-line))
+ ns-input-line))))))
(move-overlay ns-select-overlay beg end)
(deactivate-mark)
(goto-char beg)))
(defun ns-print-buffer ()
"Interactive front-end to `print-buffer': asks for user confirmation first."
(interactive)
- (if (and (interactive-p)
+ (if (and (called-interactively-p 'interactive)
(or (listp last-nonmenu-event)
(and (char-or-string-p (event-basic-type last-command-event))
(memq 'super (event-modifiers last-command-event)))))
(format "Creation of the standard fontset failed: %s" err)
:error)))))
+(defvar ns-reg-to-script) ; nsfont.m
+
+;; This maps font registries (not exposed by NS APIs for font selection) to
+;; unicode scripts (which can be mapped to unicode character ranges which are).
+;; See ../international/fontset.el
+(setq ns-reg-to-script
+ '(("iso8859-1" . latin)
+ ("iso8859-2" . latin)
+ ("iso8859-3" . latin)
+ ("iso8859-4" . latin)
+ ("iso8859-5" . cyrillic)
+ ("microsoft-cp1251" . cyrillic)
+ ("koi8-r" . cyrillic)
+ ("iso8859-6" . arabic)
+ ("iso8859-7" . greek)
+ ("iso8859-8" . hebrew)
+ ("iso8859-9" . latin)
+ ("iso8859-10" . latin)
+ ("iso8859-11" . thai)
+ ("tis620" . thai)
+ ("iso8859-13" . latin)
+ ("iso8859-14" . latin)
+ ("iso8859-15" . latin)
+ ("iso8859-16" . latin)
+ ("viscii1.1-1" . latin)
+ ("jisx0201" . kana)
+ ("jisx0208" . han)
+ ("jisx0212" . han)
+ ("jisx0213" . han)
+ ("gb2312.1980" . han)
+ ("gb18030" . han)
+ ("gbk-0" . han)
+ ("big5" . han)
+ ("cns11643" . han)
+ ("sisheng_cwnn" . bopomofo)
+ ("ksc5601.1987" . hangul)
+ ("ethiopic-unicode" . ethiopic)
+ ("is13194-devanagari" . indian-is13194)
+ ("iso10646.indian-1" . devanagari)))
+
;;;; Pasteboard support.
(defvar ns-last-selected-text nil)
(defun x-select-text (text &optional push)
- "Put TEXT, a string, on the pasteboard."
+ "Select TEXT, a string, according to the window system.
+
+On X, put TEXT in the primary X selection. For backward
+compatibility with older X applications, set the value of X cut
+buffer 0 as well, and if the optional argument PUSH is non-nil,
+rotate the cut buffers. If `x-select-enable-clipboard' is
+non-nil, copy the text to the X clipboard as well.
+
+On Windows, make TEXT the current selection. If
+`x-select-enable-clipboard' is non-nil, copy the text to the
+clipboard as well. The argument PUSH is ignored.
+
+On Nextstep, put TEXT in the pasteboard; PUSH is ignored."
;; Don't send the pasteboard too much text.
;; It becomes slow, and if really big it causes errors.
(ns-set-pasteboard text)
(interactive)
(insert (ns-get-cut-buffer-internal 'SECONDARY)))
-;; 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 'x-select-text
-;; interprogram-paste-function 'x-cut-buffer-or-selection-value)
-;; These only needed if above not working.
-
-(set-face-background 'region "ns_selection_color")
-
;;;; Scrollbar handling.
(let* ((pos (event-end event))
(window (nth 0 pos))
(scale (nth 2 pos)))
- (save-excursion
- (set-buffer (window-buffer window))
+ (with-current-buffer (window-buffer window)
(cond
((eq (car scale) (cdr scale))
(goto-char (point-max)))
(declare-function ns-list-colors "nsfns.m" (&optional frame))
(defvar x-colors (ns-list-colors)
- "The list of colors defined in non-PANTONE color files.")
+ "List of basic colors available on color displays.
+For X, the list comes from the `rgb.txt' file,v 10.41 94/02/20.
+For Nextstep, this is a list of non-PANTONE colors returned by
+the operating system.")
(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 Nextstep displays."
+ "Internal function called by `defined-colors'."
(or frame (setq frame (selected-frame)))
(let ((all-colors x-colors)
(this-color nil)
(setq defined-colors (cons this-color defined-colors))) ;;)
defined-colors))
-(declare-function ns-set-alpha "nsfns.m" (color alpha))
-
-;; Convenience and work-around for fact that set color fns now require named.
-(defun ns-set-background-alpha (alpha)
- "Sets ALPHA (opacity) of background.
-Set from 0.0 (fully transparent) to 1.0 (fully opaque; default).
-Note, tranparency works better on Tiger (10.4) and higher."
- (interactive "nSet background alpha to: ")
- (let ((bgcolor (cdr (assq 'background-color (frame-parameters)))))
- (set-frame-parameter (selected-frame)
- 'background-color (ns-set-alpha bgcolor alpha))))
-
;; Functions for color panel + drag
(defun ns-face-at-pos (pos)
(let* ((frame (car pos))
((eq window-pos 'vertical-line)
'default)
((consp window-pos)
- (save-excursion
- (set-buffer buffer)
+ (with-current-buffer buffer
(let ((p (car (compute-motion (window-start window)
(cons (nth 0 edges) (nth 1 edges))
(window-end window)
;; FIXME: This will surely lead to "MODIFIED OUTSIDE CUSTOM" warnings.
(menu-bar-mode (if (get-lisp-resource nil "Menus") 1 -1))
- (mouse-wheel-mode 1)
(setq ns-initialized t))