(Fread_file_name): Correct handling of dollars in file
[bpt/emacs.git] / lisp / frame.el
index f2face1..d4947f4 100644 (file)
@@ -32,7 +32,7 @@ function, which should take an alist of parameters as its argument.")
 ;;; The initial value given here for used to ask for a minibuffer.
 ;;; But that's not necessary, because the default is to have one.
 ;;; By not specifying it here, we let an X resource specify it.
-(defvar initial-frame-alist nil
+(defcustom initial-frame-alist nil
   "Alist of frame parameters for creating the initial X window frame.
 You can set this in your `.emacs' file; for example,
  (setq initial-frame-alist '((top . 1) (left . 1) (width . 80) (height . 55)))
@@ -51,7 +51,11 @@ as it appears, you need to use this three-step process:
 * Set `default-frame-alist' to override these options so that they
   don't affect subsequent frames.
 * Set `initial-frame-alist' in a way that matches the X resources,
-  to override what you put in `default-frame-alist'.")
+  to override what you put in `default-frame-alist'."
+  :type '(repeat (cons :format "%v"
+                      (symbol :tag "Parameter")
+                      (sexp :tag "Value")))
+  :group 'frames)
 
 (defvar minibuffer-frame-alist '((width . 80) (height . 2))
   "Alist of frame parameters for initially creating a minibuffer frame.
@@ -169,19 +173,13 @@ These supersede the values given in `default-frame-alist'."
            (progn
              (setq frame-initial-frame-alist
                    (append initial-frame-alist default-frame-alist))
-             ;; Record these with their default values
-             ;; if they don't have any values explicitly.
-             (or (assq 'vertical-scroll-bars frame-initial-frame-alist)
-                 (setq frame-initial-frame-alist
-                       (cons '(vertical-scroll-bars . t)
-                             frame-initial-frame-alist)))
              (or (assq 'horizontal-scroll-bars frame-initial-frame-alist)
                  (setq frame-initial-frame-alist
                        (cons '(horizontal-scroll-bars . t)
                              frame-initial-frame-alist)))
              (setq default-minibuffer-frame
                    (setq frame-initial-frame
-                         (make-frame initial-frame-alist)))
+                         (make-frame frame-initial-frame-alist)))
              ;; Delete any specifications for window geometry parameters
              ;; so that we won't reapply them in frame-notice-user-settings.
              ;; It would be wrong to reapply them then,
@@ -420,6 +418,8 @@ These supersede the values given in `default-frame-alist'."
   "Make a frame on display DISPLAY.
 The optional second argument PARAMETERS specifies additional frame parameters."
   (interactive "sMake frame on display: ")
+  (or (string-match "\\`[^:]*:[0-9]+\\(\\.[0-9]+\\)?\\'" display)
+      (error "Invalid display, not HOST:SERVER or HOST:SERVER.SCREEN"))
   (make-frame (cons (cons 'display display) parameters)))
 
 (defun make-frame-command ()
@@ -503,6 +503,12 @@ the user during startup."
   (cdr param-list))
 
 
+(defcustom focus-follows-mouse t
+  "*Non-nil if window system changes focus when you move the mouse."
+  :type 'boolean
+  :group 'frames
+  :version "20.3")
+
 (defun other-frame (arg)
   "Select the ARG'th different visible frame, and raise it.
 All frames are arranged in a cyclic order.
@@ -522,7 +528,49 @@ A negative ARG moves in the opposite order."
       (setq arg (1+ arg)))
     (raise-frame frame)
     (select-frame frame)
-    (set-mouse-position (selected-frame) (1- (frame-width)) 0)))
+    ;; Ensure, if possible, that frame gets input focus.
+    (if (eq window-system 'w32)
+       (w32-focus-frame frame)
+      (when focus-follows-mouse
+       (set-mouse-position (selected-frame) (1- (frame-width)) 0)))))
+
+(defun make-frame-names-alist ()
+  (let* ((current-frame (selected-frame))
+        (falist
+         (cons
+          (cons (frame-parameter current-frame 'name) current-frame) nil))
+        (frame (next-frame nil t)))
+    (while (not (eq frame current-frame))
+      (progn
+       (setq falist (cons (cons (frame-parameter frame 'name) frame) falist))
+       (setq frame (next-frame frame t))))
+    falist))
+
+(defvar frame-name-history nil)
+(defun select-frame-by-name (name)
+  "Select the frame whose name is NAME and raise it.
+If there is no frame by that name, signal an error."
+  (interactive
+   (let* ((frame-names-alist (make-frame-names-alist))
+          (default (car (car frame-names-alist)))
+          (input (completing-read
+                  (format "Select Frame (default %s): " default)
+                  frame-names-alist nil t nil 'frame-name-history)))
+     (if (= (length input) 0)
+        (list default)
+       (list input))))
+  (let* ((frame-names-alist (make-frame-names-alist))
+        (frame (cdr (assoc name frame-names-alist))))
+    (or frame
+       (error "There is no frame named `%s'" name))
+    (make-frame-visible frame)
+    (raise-frame frame)
+    (select-frame frame)
+    ;; Ensure, if possible, that frame gets input focus.
+    (if (eq window-system 'w32)
+       (w32-focus-frame frame)
+      (when focus-follows-mouse
+       (set-mouse-position (selected-frame) (1- (frame-width)) 0)))))
 \f
 ;;;; Frame configurations
 
@@ -583,7 +631,7 @@ is given and non-nil, the unwanted frames are iconified instead."
 
 (defun frame-parameter (frame parameter)
   "Return FRAME's value for parameter PARAMETER.
-If FRAME is omitted, describe the currently selected frame."
+If FRAME is nil, describe the currently selected frame."
   (cdr (assq parameter (frame-parameters frame))))
 
 (defun frame-height (&optional frame)
@@ -678,6 +726,14 @@ that is beyond the control of Emacs and this command has no effect on it."
                -1 1)))
   (modify-frame-parameters (selected-frame)
                           (list (cons 'auto-lower (> arg 0)))))
+(defun set-frame-name (name)
+  "Set the name of the selected frame to NAME.
+When called interactively, prompt for the name of the frame.
+The frame name is displayed on the modeline if the terminal displays only
+one frame, otherwise the name is displayed on the frame's caption bar."
+  (interactive "sFrame name: ")
+  (modify-frame-parameters (selected-frame)
+                          (list (cons 'name name))))
 \f
 ;;;; Aliases for backward compatibility with Emacs 18.
 (defalias 'screen-height 'frame-height)