Use forward-line rather than goto-line.
[bpt/emacs.git] / lisp / startup.el
index 2d7995a..3d177f9 100644 (file)
@@ -1,7 +1,7 @@
 ;;; startup.el --- process Emacs shell arguments
 
 ;; Copyright (C) 1985, 1986, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-;;   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+;;   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
 ;;   Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
@@ -47,7 +47,7 @@ directory using `find-file'.  If t, open the `*scratch*' buffer."
   :type '(choice
          (const     :tag "Startup screen" nil)
          (directory :tag "Directory" :value "~/")
-         (file      :tag "File" :value "~/file.txt")
+         (file      :tag "File" :value "~/.emacs")
          (const     :tag "Lisp scratch buffer" t))
   :version "23.1"
   :group 'initialization)
@@ -55,8 +55,8 @@ directory using `find-file'.  If t, open the `*scratch*' buffer."
 (defcustom inhibit-startup-screen nil
   "Non-nil inhibits the startup screen.
 
-This is for use in your personal init file (but NOT site-start.el), once
-you are familiar with the contents of the startup screen."
+This is for use in your personal init file (but NOT site-start.el),
+once you are familiar with the contents of the startup screen."
   :type 'boolean
   :group 'initialization)
 
@@ -134,6 +134,7 @@ This is normally copied from `default-directory' when Emacs starts.")
     ("-fs" 0 x-handle-initial-switch fullscreen fullboth)
     ("-fw" 0 x-handle-initial-switch fullscreen fullwidth)
     ("-fh" 0 x-handle-initial-switch fullscreen fullheight)
+    ("-mm" 0 x-handle-initial-switch fullscreen maximized)
     ("-ib" 1 x-handle-numeric-switch internal-border-width)
     ("-g" 1 x-handle-geometry)
     ("-lsp" 1 x-handle-numeric-switch line-spacing)
@@ -159,6 +160,7 @@ This is normally copied from `default-directory' when Emacs starts.")
     ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth)
     ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth)
     ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight)
+    ("--maximized" 0 x-handle-initial-switch fullscreen maximized)
     ("--internal-border" 1 x-handle-numeric-switch internal-border-width)
     ("--geometry" 1 x-handle-geometry)
     ("--foreground-color" 1 x-handle-switch foreground-color)
@@ -220,8 +222,8 @@ and VALUE is the value which is given to that frame parameter
     ("-cr" 1 ns-handle-switch cursor-color)
     ("-vb" 0 ns-handle-switch vertical-scroll-bars t)
     ("-hb" 0 ns-handle-switch horizontal-scroll-bars t)
-    ("-bd" 1 ns-handle-switch) 
-    ;; ("--border-width" 1 ns-handle-numeric-switch border-width) 
+    ("-bd" 1 ns-handle-switch)
+    ;; ("--border-width" 1 ns-handle-numeric-switch border-width)
     ;; ("--display" 1 ns-handle-display)
     ("--name" 1 ns-handle-name-switch)
     ("--title" 1 ns-handle-switch title)
@@ -342,7 +344,7 @@ this variable usefully is to set it while building and dumping Emacs."
                               "")
   "Full mailing address of this user.
 This is initialized with environment variable `EMAIL' or, as a
-fallback, using `mail-host-address'. This is done after your
+fallback, using `mail-host-address'.  This is done after your
 init file is read, in case it sets `mail-host-address'."
   :type 'string
   :group 'mail)
@@ -499,7 +501,8 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
                     (delete (concat "PWD=" pwd)
                             process-environment)))))
     (setq default-directory (abbreviate-file-name default-directory))
-    (let ((menubar-bindings-done nil))
+    (let ((menubar-bindings-done nil)
+         (old-face-font-rescale-alist face-font-rescale-alist))
       (unwind-protect
          (command-line)
        ;; Do this again, in case .emacs defined more abbreviations.
@@ -540,6 +543,19 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
                  (not (and initial-window-system
                            (not noninteractive)
                            (not (eq initial-window-system 'pc)))))
+
+         ;; FIXME: The user's init file may change
+         ;; face-font-rescale-alist.  However, the default face
+         ;; already has an assigned font object, which does not take
+         ;; face-font-rescale-alist into account.  For such
+         ;; situations, we ought to have a way to find all font
+         ;; objects and regenerate them; currently we do not.  As a
+         ;; workaround, we specifically reset te default face's :font
+         ;; attribute here.  See bug#1785.
+         (unless (eq face-font-rescale-alist
+                     old-face-font-rescale-alist)
+           (set-face-attribute 'default nil :font (font-spec)))
+
          ;; Modify the initial frame based on what .emacs puts into
          ;; ...-frame-alist.
          (if (fboundp 'frame-notice-user-settings)
@@ -603,7 +619,7 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
     ("--color"           . "-color")))
 
 (defconst tool-bar-images-pixel-height 24
-  "Height in pixels of images in the tool bar.")
+  "Height in pixels of images in the tool-bar.")
 
 (defvar tool-bar-originally-present nil
   "Non-nil if tool-bars are present before user and site init files are read.")
@@ -694,6 +710,7 @@ opening the first frame (e.g. open a connection to an X server).")
 (declare-function tool-bar-setup "tool-bar")
 
 (defvar server-name)
+(defvar server-process)
 
 (defun command-line ()
   (setq before-init-time (current-time)
@@ -827,10 +844,10 @@ opening the first frame (e.g. open a connection to an X server).")
              (orig-argi argi)
              argval)
        ;; Handle --OPTION=VALUE format.
-       (when (string-match "^\\(--[^=]*\\)=" argi)
+       (when (string-match "\\`\\(--[^=]*\\)=" argi)
          (setq argval (substring argi (match-end 0))
                 argi (match-string 1 argi)))
-       (unless (equal argi "--")
+       (when (string-match "\\`--." orig-argi)
          (let ((completion (try-completion argi longopts)))
            (if (eq completion t)
                (setq argi (substring argi 1))
@@ -977,13 +994,15 @@ opening the first frame (e.g. open a connection to an X server).")
                                   init-file-user)
                           :error)
        (if (file-directory-p (expand-file-name
-                              ;; We don't support ~USER on MS-Windows except
-                              ;; for the current user, and always load .emacs
-                              ;; from the current user's home directory (see
-                              ;; below).  So always check "~", even if invoked
-                              ;; with "-u USER", or if $USER or $LOGNAME are
-                              ;; set to something different.
-                              (if (eq system-type 'windows-nt)
+                              ;; We don't support ~USER on MS-Windows
+                              ;; and MS-DOS except for the current
+                              ;; user, and always load .emacs from
+                              ;; the current user's home directory
+                              ;; (see below).  So always check "~",
+                              ;; even if invoked with "-u USER", or
+                              ;; if $USER or $LOGNAME are set to
+                              ;; something different.
+                              (if (memq system-type '(windows-nt ms-dos))
                                   "~"
                                 (concat "~" init-file-user))))
            nil
@@ -1218,7 +1237,14 @@ the `--debug-init' option to view a complete error backtrace."
     (when dn
       (when (stringp dn) (setq server-name dn))
       (server-start)
-      (daemon-initialized)))
+      (if server-process
+         (daemon-initialized)
+       (if (stringp dn)
+           (message
+            "Unable to start daemon: Emacs server named %S already running"
+            server-name)
+         (message "Unable to start the daemon.\nAnother instance of Emacs is running the server, either as daemon or interactively.\nYou can use emacsclient to connect to that Emacs process."))
+       (kill-emacs 1))))
 
   ;; Run emacs-session-restore (session management) if started by
   ;; the session manager and we have a session manager connection.
@@ -1260,6 +1286,7 @@ If this is nil, no message will be displayed."
         '("GNU" (lambda (button) (describe-gnu-project))
           "Display info on the GNU project")))
      " operating system.\n\n"
+     :face variable-pitch
      :link ("Emacs Tutorial" (lambda (button) (help-with-tutorial)))
      "\tLearn basic keystroke commands"
      (lambda ()
@@ -1279,7 +1306,6 @@ If this is nil, no message will be displayed."
             ""
           (concat " (" title ")"))))
      "\n"
-     :face variable-pitch
      :link ("Emacs Guided Tour"
            (lambda (button) (browse-url "http://www.gnu.org/software/emacs/tour/"))
            "Browse http://www.gnu.org/software/emacs/tour/")
@@ -1800,64 +1826,68 @@ To quit a partially entered command, type Control-g.\n")
 
   ;; If keys have their default meanings,
   ;; use precomputed string to save lots of time.
-  (if (and (eq (key-binding "\C-h") 'help-command)
-          (eq (key-binding "\C-xu") 'advertised-undo)
-          (eq (key-binding "\C-x\C-c") 'save-buffers-kill-terminal)
-          (eq (key-binding "\C-ht") 'help-with-tutorial)
-          (eq (key-binding "\C-hi") 'info)
-          (eq (key-binding "\C-hr") 'info-emacs-manual)
-          (eq (key-binding "\C-h\C-n") 'view-emacs-news))
-      (progn
-       (insert "
-Get help\t   C-h  (Hold down CTRL and press h)
+  (let ((c-h-accessible
+         ;; If normal-erase-is-backspace is used on a tty, there's
+         ;; no way to invoke C-h and you have to use F1 instead.
+         (or (not (char-table-p keyboard-translate-table))
+             (eq (aref keyboard-translate-table ?\C-h) ?\C-h))))
+    (if (and (eq (key-binding "\C-h") 'help-command)
+             (eq (key-binding "\C-xu") 'advertised-undo)
+             (eq (key-binding "\C-x\C-c") 'save-buffers-kill-terminal)
+             (eq (key-binding "\C-ht") 'help-with-tutorial)
+             (eq (key-binding "\C-hi") 'info)
+             (eq (key-binding "\C-hr") 'info-emacs-manual)
+             (eq (key-binding "\C-h\C-n") 'view-emacs-news))
+        (let ((help (if c-h-accessible "C-h" "<f1>")))
+          (insert "
+Get help\t   " help "  (Hold down CTRL and press h)
 ")
-       (insert-button "Emacs manual"
-                      'action (lambda (button) (info-emacs-manual))
-                      'follow-link t)
-       (insert "          C-h r\t")
-       (insert-button "Browse manuals"
-                      'action (lambda (button) (Info-directory))
-                      'follow-link t)
-       (insert "\t   C-h i
+          (insert-button "Emacs manual"
+                         'action (lambda (button) (info-emacs-manual))
+                         'follow-link t)
+          (insert "       " help " r\t")
+          (insert-button "Browse manuals"
+                         'action (lambda (button) (Info-directory))
+                         'follow-link t)
+          (insert "\t   " help " i
 ")
-       (insert-button "Emacs tutorial"
-                      'action (lambda (button) (help-with-tutorial))
-                      'follow-link t)
-       (insert "          C-h t\tUndo changes\t   C-x u
+          (insert-button "Emacs tutorial"
+                         'action (lambda (button) (help-with-tutorial))
+                         'follow-link t)
+          (insert "       " help " t\tUndo changes\t   C-x u
 ")
-       (insert-button "Buy manuals"
-                      'action (lambda (button) (view-order-manuals))
-                      'follow-link t)
-       (insert "\t   C-h C-m\tExit Emacs\t   C-x C-c"))
+          (insert-button "Buy manuals"
+                         'action (lambda (button) (view-order-manuals))
+                         'follow-link t)
+          (insert "\t   " help " C-m\tExit Emacs\t   C-x C-c"))
 
-    (insert (format "
+      (insert (format "
 Get help\t   %s
 "
-                   (let ((where (where-is-internal
-                                 'help-command nil t)))
-                     (if where
-                         (key-description where)
-                       "M-x help"))))
-    (insert-button "Emacs manual"
-                  'action (lambda (button) (info-emacs-manual))
-                  'follow-link t)
-    (insert (substitute-command-keys"\t   \\[info-emacs-manual]\t"))
-    (insert-button "Browse manuals"
-                  'action (lambda (button) (Info-directory))
-                  'follow-link t)
-    (insert (substitute-command-keys "\t   \\[info]
+                      (let ((where (where-is-internal 'help-command nil t)))
+                        (if where
+                            (key-description where)
+                          "M-x help"))))
+      (insert-button "Emacs manual"
+                     'action (lambda (button) (info-emacs-manual))
+                     'follow-link t)
+      (insert (substitute-command-keys"\t   \\[info-emacs-manual]\t"))
+      (insert-button "Browse manuals"
+                     'action (lambda (button) (Info-directory))
+                     'follow-link t)
+      (insert (substitute-command-keys "\t   \\[info]
 "))
-    (insert-button "Emacs tutorial"
-                  'action (lambda (button) (help-with-tutorial))
-                  'follow-link t)
-    (insert (substitute-command-keys
-            "\t   \\[help-with-tutorial]\tUndo changes\t   \\[advertised-undo]
+      (insert-button "Emacs tutorial"
+                     'action (lambda (button) (help-with-tutorial))
+                     'follow-link t)
+      (insert (substitute-command-keys
+               "\t   \\[help-with-tutorial]\tUndo changes\t   \\[advertised-undo]
 "))
-    (insert-button "Buy manuals"
-                  'action (lambda (button) (view-order-manuals))
-                  'follow-link t)
-    (insert (substitute-command-keys
-            "\t   \\[view-order-manuals]\tExit Emacs\t   \\[save-buffers-kill-terminal]")))
+      (insert-button "Buy manuals"
+                     'action (lambda (button) (view-order-manuals))
+                     'follow-link t)
+      (insert (substitute-command-keys
+              "\t   \\[view-order-manuals]\tExit Emacs\t   \\[save-buffers-kill-terminal]"))))
 
   ;; Say how to use the menu bar with the keyboard.
   (insert "\n")
@@ -1985,12 +2015,14 @@ Type \\[describe-distribution] for information on "))
   (insert "\tBuying printed manuals from the FSF\n"))
 
 (defun startup-echo-area-message ()
-  (if (eq (key-binding "\C-h\C-a") 'about-emacs)
-      "For information about GNU Emacs and the GNU system, type C-h C-a."
-    (substitute-command-keys
-     "For information about GNU Emacs and the GNU system, type \
-\\[about-emacs].")))
-
+  (cond ((daemonp)
+        "Starting Emacs daemon.")
+       ((eq (key-binding "\C-h\C-a") 'about-emacs)
+        "For information about GNU Emacs and the GNU system, type C-h C-a.")
+       (t
+        (substitute-command-keys
+         "For information about GNU Emacs and the GNU system, type \
+\\[about-emacs]."))))
 
 (defun display-startup-echo-area-message ()
   (let ((resize-mini-windows t))
@@ -2113,21 +2145,20 @@ A fancy display is used on graphic displays, normal otherwise."
                (setq argi "")
              ;; Convert long options to ordinary options
              ;; and separate out an attached option argument into argval.
-             (when (string-match "^\\(--[^=]*\\)=" argi)
+             (when (string-match "\\`\\(--[^=]*\\)=" argi)
                (setq argval (substring argi (match-end 0))
                      argi (match-string 1 argi)))
-             (if (equal argi "--")
-                 (setq completion nil)
-               (setq completion (try-completion argi longopts)))
-             (if (eq completion t)
-                 (setq argi (substring argi 1))
-               (if (stringp completion)
-                   (let ((elt (assoc completion longopts)))
-                     (or elt
-                         (error "Option `%s' is ambiguous" argi))
-                     (setq argi (substring (car elt) 1)))
-                 (setq argval nil
-                       argi orig-argi))))
+             (when (string-match "\\`--." orig-argi)
+               (setq completion (try-completion argi longopts))
+               (if (eq completion t)
+                   (setq argi (substring argi 1))
+                 (if (stringp completion)
+                     (let ((elt (assoc completion longopts)))
+                       (or elt
+                           (error "Option `%s' is ambiguous" argi))
+                       (setq argi (substring (car elt) 1)))
+                   (setq argval nil
+                         argi orig-argi)))))
 
            ;; Execute the option.
            (cond ((setq tem (assoc argi command-switch-alist))
@@ -2227,8 +2258,9 @@ A fancy display is used on graphic displays, normal otherwise."
                     (if (= file-count 1)
                         (setq first-file-buffer (find-file file))
                       (find-file-other-window file)))
-                  (or (zerop line)
-                      (goto-line line))
+                  (unless (zerop line)
+                    (goto-char (point-min))
+                    (forward-line (1- line)))
                   (setq line 0)
                   (unless (< column 1)
                     (move-to-column (1- column)))
@@ -2261,8 +2293,9 @@ A fancy display is used on graphic displays, normal otherwise."
                                   (inhibit-startup-screen
                                    (find-file-other-window file))
                                   (t (find-file file))))
-                          (or (zerop line)
-                              (goto-line line))
+                          (unless (zerop line)
+                            (goto-char (point-min))
+                            (forward-line (1- line)))
                           (setq line 0)
                           (unless (< column 1)
                             (move-to-column (1- column)))