;;; gawd-misc.el --- Startup code that does things I can fit nowhere else.

;;; Copyright (C) 1999--2001 Nix <nix@esperi.demon.co.uk>.

;; Author: Nix <nix@esperi.demon.co.uk>
;; Created: 1999-04-18
;; Keywords: local
;; Version: $Revision: 1.15 $

;; This file is not part of XEmacs.

;;; Commentary:

;; This file's sole purpose is to shrink site-start.el, and move the random
;; crap this was introducing out of it.

;; It mainly consists of hordes of setqs, and is dependent upon the
;; requirements list at the top of site-start. Yuck.

;;; Requirements:

(require 'gawd-lists)

;;; Code:

;; General customizations

(setq enable-recursive-minibuffers t            ; Less restrictive
      minibuffer-max-depth nil                  ; As many minibuffers as we want
      backup-by-copying nil                     ; This doesn't break concurrency
      backup-by-copying-when-linked t           ; Don't break links
      backup-by-copying-when-mismatch t         ; Don't change ownership
      backup-by-copying-when-privileged-mismatch 98 ; Don't change the ownership of privileged files
      line-number-mode t                        ; Line numbers are a Good Thing
      column-number-mode t                      ; as are column numbers
      next-line-add-newlines nil                ; What a horrible idea
      bar-cursor 2                              ; Use a 2-pixel-wide bar as a cursor
      paren-mode 'blink-paren                   ; Blink parentheses, like vi.
      find-file-use-truenames nil               ;  Let symlinks work
      find-file-compare-truenames t             ; Compare truenames when deciding file equality
      auto-save-timeout 300                     ; In a 50K buffer, save after this much idleness
      blink-matching-paren-distance 50000       ; We are not a Z80: we can cope with some CPU-load.
      gnus-select-method '(nntp "news.srvr.nix") ; Talk to *us* preferentially
      mail-signature t                          ; Add sigs to email by default
      Info-auto-generate-directory nil          ; Never autogenerate directories
      make-tags-files-invisible t               ; Don't bother people with TAGS buffers
      shifted-motion-keys-select-region nil     ; This is *not* a UI innovation.
      modeline-scrolling-method t               ; Wonderful.
      mail-user-agent 'message-user-agent       ; Give us a decent message compositor
      progress-feedback-use-echo-area t         ; The graphical progress bar is truly horrible-looking
      bell-volume 0                             ; Don't drive everyone beeping mad
      buffers-menu-submenus-for-groups-p 10     ; If more than 10 buffers, group them by mode instead
      x-selection-strict-motif-ownership nil    ; It slows XEmacs down for no gain.
      focus-follows-mouse t                     ; Don't steal the keyboard focus
      uniquify-buffer-name-style 'post-forward-angle-brackets ; Names look like `foo<in/here>'
      uniquify-after-kill-buffer-p t            ; When duplicate buffers go away, fix the original names up again
      uniquify-ignore-buffers-re "^\s-.*$"      ; Don't uniquify temporary buffers
      desktop-missing-file-warning nil          ; Zap a thoroughly irritating warning.
      kill-word-into-kill-ring nil              ; Avoid polluting the kill ring with single words
      tramp-shell-prompt-pattern "^%?[^#$%>\n]*[#$%>] *\\(\\[[0-9;]*[a-zA-Z] *\\)*"
      power-macros-file "~/.emacs.power-macros" ; File in which macro definitions are saved.
      read-quoted-char-radix 16)                ; Who the hell uses octal anymore?

(if (featurep 'xemacs)
    (setq resize-minibuffer-window-max-height 0 ; Don't make the minibuffer larger than the frame
          resize-minibuffer-frame t             ; except if it's the only window, in which case the frame may grow
          complex-buffers-menu-p t              ; Lots of things in the buffer menu
          auto-save-directory (expand-file-name "~/.emacs-autosave/") ; Turn on one-directory autosaving
          auto-save-directory-fallback (expand-file-name "/tmp") ; Set the fallback directory too
          auto-save-offer-delete t              ; Ask about deleting obsolete autosave files
          scroll-in-place t                     ; Scroll-in-place is wonderful; use it.
          delete-key-deletes-forward t)         ; Act the way DEL has always acted
  ;; Emacs
  (setq resize-mini-windows t                   ; Allow minibuffer shrinkage as well as growth
        auto-save-file-name-transforms '((".*" "~/.emacs-autosave/\\&" t)) ; Stick everything in one directory
        line-move-visual nil                    ; Move by real lines, not screen lines
        history-length 100                      ; 100-item-long history lists
        history-delete-duplicates t             ; Delete history duplicates
        apropos-do-all t                        ; Search everything possible
        kill-do-not-save-duplicates t           ; Don't put duplicates into the kill ring
        scroll-preserve-screen-position 'in-place ; Scroll in place.
        scroll-error-top-bottom t               ; Don't throw an error at buffer end
        isearch-allow-scroll t                  ; You can scroll inside isearch
        line-number-display-limit-width 2000    ; A somewhat bigger line-number limit
        kill-read-only-ok t)                    ; Killing read-only text is not an error

(setq-default indent-tabs-mode nil)             ; No tabs in indentation

(if (featurep 'xemacs)
    (progn
      (resize-minibuffer-mode))                 ; Resize the minibuffer window when it gets too small
  ;; Emacs
  (setq-default cursor-type 'bar)               ; Use a bar cursor
  (setq blink-cursor-delay 500)                 ; Only blink after a long period of inactivity
  (blink-cursor-mode 1)                         ; Blink the cursor
  (winner-mode 1))                              ; Window configuration rings

(gnuserv-start)                                 ; Kick off the emacsserver

;; I18N / Unicode stuff

(set-coding-priority-list '(utf-8 iso-8-1 utf-8-bom)) ; Use UTF-8 or ISO-8859-x
(set-language-environment "English")            ; A reasonable default
(set-default-buffer-file-coding-system 'utf-8)  ; Files are in UTF-8 by default
(setq file-name-coding-system 'utf-8            ; Their names are, too. 
      default-file-name-coding-system 'utf-8)

;; Stop some excessively chatty progress gauges from flooding the message log

(add-to-list 'log-message-ignore-labels 'font-lock)

;; Stop the desktop from trying to save nonexistent variables (!)

(mapc #'(lambda (to-zap)
          (setq desktop-globals-to-save (delq to-zap desktop-globals-to-save)))
      '(tags-file-name tags-table-list))

(add-to-list 'desktop-globals-to-save 'tag-table-alist)

;; Save-place customizations

(setq-default save-place t)                     ; Save the position of the cursor
(setq save-place-limit 200)                     ; in at most 200 files

;; Read in the user's abbrevs. This should always occur;
;; why do you need to do something special to make it happen?

(ignore-errors (read-abbrev-file abbrev-file-name t))

;; X customisations

(set-glyph-image modeline-pointer-glyph "leftbutton" nil 'x) ; Use a different glyph when over a modeline
(set-glyph-image gc-pointer-glyph (expand-file-name "trash.xpm" data-directory) nil 'x); Use a trashcan to indicate gc

;; Set up tags tables for system-wide tagged stuff

(setq tag-table-alist '(("^/usr/src/linux[^/]*/.*/*.\.[ch]$" . "/usr/src/linux/")
                        ("^/usr/lib/xemacs/.*\.el$" . "/usr/lib/xemacs/")
                        ("^/usr/lib/xemacs-version-specific/.*\.el$" . "/usr/lib/xemacs/")
                        ("^/usr/lib/xemacs-[0-9.]*/.*\.el$" . "/usr/lib/xemacs/")))

;; The modeline.

;; Cut the %- off the last thing in the modeline, if it is there.
;; Add it an explicit separate item, so it's easy to insert things
;; in front of.

(setcar (last modeline-format)
        (list (replace-in-string (car (last modeline-format))
                                 "%-$" "" t)))

(setq-default modeline-format (append modeline-format (list "%-")))

;; Shuffle the buffer position to just after the global-mode-string.

(setq-default modeline-format (list-shuffle-equal (cons modeline-position-status-extent 'modeline-position-status)
                                                  'global-mode-string modeline-format))

;; Fiddle the buffer position: reduce numbered padding, add some explicit padding.

(setq-default modeline-position-status
              (cons 11 (list
                        " " (cons modeline-line-number-extent
                                  'modeline-line-number)
                        (cons modeline-column-number-extent
                              'modeline-column-number)
                        (cons modeline-percentage-extent
                              'modeline-percentage) " ")))

;; The selective-default-el-suppression list

(defvar inhibit-default-init-portions nil
"A list of parts of `default.el' to skip.
This provides finer-grained control over initialization than
does `inhibit-default-init', allowing portions of `default.el'
to be skipped, as it is doing several things, and the user
might reasonably want to disable some without disabling the
others.

Currently, you can skip

key-bindings                 Key bindings
all-key-bindings             All key bindings, including for specific modes
desktop-load                 Automatic desktop loading
icomplete                    Incremental minibuffer completion
macro-load                   Automatic keyboard macro loading")

(provide 'gawd-misc)