;;
;; $Id: q-gnu-19-init.el,v 1.70 1997/07/31 20:28:33 ejb Exp $
;; $Source: /home/ejb/elisp/q/RCS/q-gnu-19-init.el,v $
;; $Author: ejb $
;;
;; This file performs version-specific initialization
;;

(provide 'q-gnu-19-init)

(defvar pre-19-29 nil)
(defvar pre-19-30 nil)
(defvar line-mode-fmt "")

(defun q-gnu-19-init ()
  ;; Nothing in here is different among different versions that predate
  ;; emacs-minor-version.  This statement is here so we can blindly
  ;; assume it is defined.
  (if (not (boundp 'emacs-minor-version))
      (setq emacs-minor-version 0))

  (setq pre-19-29 (< emacs-minor-version 29))
  (setq pre-19-30 (< emacs-minor-version 30))
  (setq pre-19-31 (< emacs-minor-version 31))

  (if pre-19-29
      (progn
	(if window-system
	    (progn
	      (require 'scroll-bar)
	      (require 'menu-bar)

	      ;; Turn off all scroll bars and menu bars
	      (scroll-bar-mode -1)
	      
	      ;; There was a menu-bar-mode bug in emacs 19.23...
	      (if (string-match "^19\\.23" emacs-version)
		  (let ((lines (frame-height)))
		    (menu-bar-mode -1)
		    (set-frame-height nil lines))
		(menu-bar-mode -1))

	      (signal-proper-size)
	    )
	)
      )
  )

  ;; yes-or-no-p uses a dialog if the last event wasn't from the keyboard.
  ;; This is wrong.  It should use a dialog if the last event WAS from a
  ;; menu.  If a subprocess like gdb or emacsserver does a find file,
  ;; the result is a dialog.  Some special case fixes may be in emacs,
  ;; but unless the general case is fixed, forget dialog boxes in yes-or-no-p.
  ;; To get around this, force last-nonmenu-event to be true whenever
  ;; yes-or-no-p is called.
  ;; Note: this may be fixed in 19.26, but I'm not taking any chances.
  ;; 19.26 is at least a little smarter about setting last-nonmenu-event.
  (if (not (fboundp 'real-yes-or-no-p))
      (fset 'real-yes-or-no-p (symbol-function 'yes-or-no-p)))
  (fset 'yes-or-no-p (symbol-function 'no-dialog-yes-or-no-p))

  (if (not (fboundp 'local-variable-p))
      (fset 'local-variable-p (symbol-function 'return-false)))

  ;; emacs-19-specific variables
  (setq
   default-major-mode 'indented-text-mode
   initial-major-mode 'indented-text-mode
  )

  (require 'cc-mode)
  (setq c-style-alist
	(append (list q-cc-style) c-style-alist)
  )

  ;; q-indent-mode is no longer needed in Emacs 20 since the fill
  ;; commands have gotten smarter.
  (autoload 'q-indent-mode "q-indent-mode"
    "Minor mode for indentation features" t)
  (autoload 'q-indent-set-indent-vars "q-indent-mode"
    "Set paragraph and indent variables")
  (add-hook 'TeX-mode-hook 'turn-on-q-indent)
  (add-hook 'tex-mode-hook 'turn-on-q-indent)
  (add-hook 'mail-mode-hook 'turn-on-q-indent)
  (add-hook 'text-mode-hook 'q-indent-set-indent-vars)


  ;; add-hook adds to the beginning of the hooks list
  (require 'crnl-mode)
  (add-hook 'find-file-hooks 'crnl-mode-maybe t) ; t appends to hooks

  (if pre-19-29
      (progn
	(set-variable 'load-path
		      (append (list
			       (expand-file-name "~/elisp/pre-19.29")
			      )
			      load-path))

	(autoload 'dabbrev-expand "new-dabbrev" "Expand dynamic abbreviation" t)
	(autoload 'dabbrev-completion "new-dabbrev"
	  "Complete dynamic abbreviation" t)

	(global-set-key "\M-:" 'eval-expression)
      )
  )

  ;; From 19.30, cc-mode is the default
  (if pre-19-30
      (progn
	(set-variable 'load-path
		      (append (list
			       (expand-file-name "~/elisp/pre-19.30")
			      )
			      load-path))

	;; Allow overloading of c-mode and c++-mode
	(fmakunbound 'c-mode)
	(makunbound 'c-mode-map)
	(makunbound 'c-style-alist)
	(fmakunbound 'c++-mode)
	(makunbound 'c++-mode-map)
	
	(autoload 'c++-mode "cc-mode" "C++ Editing Mode" t)
	(autoload 'c-mode   "cc-mode" "C Editing Mode" t)
      )
  )
	
  (if pre-19-31
      (progn
	(set-variable 'load-path
		      (append (list
			       (expand-file-name "~/elisp/pre-19.31")
			      )
			      load-path))
      )
  )
)

(defun signal-proper-size ()
  ;; Tell gwm that we have established our desired geometry.  This uses
  ;; special case gwm code in ejb's gwm configuration.  We know that
  ;; name is already set in default-frame-alist because fix-frame-name
  ;; has already been called.
  (let ((name (cdr (assq 'name default-frame-alist))))
    (set-frame-name "set-origdims")
    (sit-for .1)
    (set-frame-name name)))

(defun no-dialog-yes-or-no-p (prompt)
  (let ((last-nonmenu-event t))
    (real-yes-or-no-p prompt)))

(defun return-false (&rest args)
  (interactive)
  nil
)

(defun turn-on-q-indent ()
  (q-indent-mode t)
)
