;;;////////////////////////////////////////////////////////////////
;;;  Speedbar Beta
;;;////////////////////////////////////////////////////////////////

(if  (eq z-emacs-type 'fsf_emacs) ;; Emacs
	 (if (eq z-location 'home)
		  (progn
			 (setq load-path (cons "h:/usr/share/emacs-21.1/site-lisp/speedbar-014beta4" load-path))
			 )))

;;;////////////////////////////////////////////////////////////////
;;;  ELIB
;;;////////////////////////////////////////////////////////////////

(if  (eq z-emacs-type 'fsf_emacs) ;; Emacs
	 (if (eq z-location 'home)
		  (progn
			 (setq load-path (cons "h:/usr/share/emacs-21.1/site-lisp/elib" load-path))
			 )))



;; ---( Autoload )---------------------------------------------------------

;; (load "psgml-init") ;; psgml-auto-setup-1.2.1-5

(load "all")                            ;; xedit all

;; ---(gnuserv: single instance)-----------------------------------------------------

(require 'gnuserv)
(gnuserv-start)


;; ---( Support Functions )---------------------------------------------------------

;; both prolog and perl files are often called .pl;
;; this tries to do the right thing.
(defun prolog-or-perl-mode () (interactive)
  (if
      (or (string-match "/perl\\b" (buffer-string)) ; file with perl header
          (= 1 (point-max)))            ; new file
      (progn	
        (cperl-mode)
        (message "Ambiguous suffix .pl resolved to perl mode."))
    (progn 
      (prolog-mode)
      (message "Ambiguous suffix .pl resolved to prolog mode.")))
  (sit-for 1))

;;; Dave Brennan <brennan@hal.com> has a copy; might as well forward
;;; him any improvements as well!
(defun zzz-insert-braces ()
  "Insert matched braces, leave point inside."
  (interactive "*")
  (let (blink-paren-function) ;nil it temporarily
    (execute-kbd-macro
     (if (and (eq major-mode 'cc-c++-mode) (not (looking-at ";")))
	 "{};" "{}")))
  (backward-sexp 1)
  (if (save-excursion
	(forward-char -1)
	(looking-at "\\$"))
      nil
    (reindent-then-newline-and-indent)
    (c-indent-exp)
    (forward-char 1)
    (newline-and-indent)))

(defun scroll-up-one ( ) 
  "up-one."
  (interactive)
  (scroll-up 1))
(defun scroll-down-one ( )
  "down-one."
  (interactive)
  (scroll-down 1))

(defun self-insert-back-accent ( )
  "inserisce carattere `."
  (interactive)
  (insert-char ?` 1))

(defun self-insert-tilde ( )
  "inserisce carattere ~."
  (interactive)
  (insert-char ?~ 1))

(defun self-insert-open-bracket ( )
  "inserisce carattere {."
  (interactive)
  (insert-char ?{ 1))

(defun self-insert-close-bracket ( )
  "inserisce carattere }."
  (interactive)
  (insert-char ?} 1))

(defvar accent-keys-bound nil
  "accent keys binding state.")

(defun accent-keys-toggle ( )
  "toggle accent keys binding."
  (interactive)
  (if (null accent-keys-bound)
      (accent-keys-bind)
    (accent-keys-unbind)))



(defun accent-keys-tex-bind ( )
  "enable accent keys binding."
  (interactive)
  (if  (eq z-emacs-type 'xemacs) ;; XEmacs
		(progn
		  (keyboard-translate 232 ?` ) ;; e' gr
		  (global-set-key     (quote[249]) '(lambda () (interactive) (recenter 1)) ) ;; u'
		  (global-set-key     (quote[167]) 'recenter ) ;; par
		  (setq accent-keys-bound t)
		  )

	 (progn
		  (keyboard-translate 231 ?{ ) ;; ced
		  (keyboard-translate 176 ?} ) ;; -es
		  (keyboard-translate 167 ?` ) ;; -es
		  (keyboard-translate 163 ?~ ) ;; -es
		  (setq accent-keys-bound t)
		)))

(defun accent-keys-unbind ( )
  "enable accent keys binding."
  (interactive)
  (keyboard-translate 231 231 ) ;; ced
  (keyboard-translate 176 176 ) ;; -es
  (keyboard-translate 242 242 ) ;; o'
  (keyboard-translate 224 224 ) ;; a'
  (keyboard-translate 236 236 ) ;; i'
  (keyboard-translate 233 233 ) ;; e' 
  (keyboard-translate 232 232 ) ;; e' gr
  (global-unset-key (quote[249]) ) ;; u'
  (global-unset-key (quote[167]) ) ;; par
  (setq accent-keys-bound nil))

(if  (eq z-emacs-type 'xemacs) ;; XEmacs
	 (progn
		(accent-keys-full-bind)
		)

  (progn
    (accent-keys-tex-bind)
	 ))

;; cycle through buffers, ignoring uninteresting ones
(defun z-backward-buffer () (interactive)
  "Switch to previously selected buffer."
  (let* ((list (cdr (buffer-list)))
         (buffer (car list)))
    (while (and (cdr list) (string-match "\\*" (buffer-name buffer)))
      (progn
        (setq list (cdr list))
        (setq buffer (car list))))
    (bury-buffer)
    (switch-to-buffer buffer)))


(defun z-forward-buffer () (interactive)
  "Opposite of backward-buffer."
  (let* ((list (reverse (buffer-list)))
         (buffer (car list)))
    (while (and (cdr list) (string-match "\\*" (buffer-name buffer)))
      (progn
        (setq list (cdr list))
        (setq buffer (car list))))
    (switch-to-buffer buffer)))


(defun buffer-tab-find-prev-rec (buffer-list  prev-buffer)
  (when buffer-list 
	 (if (aref (car buffer-list) 3) 
		  prev-buffer
		(buffer-tab-find-prev-rec (cdr buffer-list) (car buffer-list))
	 )
  )
)

(defun buffer-tab-find-prev ()
  (let ((buffer-list  ( buffers-tab-items ))) 
	 (let ((prev-buffer (buffer-tab-find-prev-rec buffer-list nil)))
	 (if prev-buffer 
		  prev-buffer
		(car (last buffer-list))
	 )))
  )

(defun buffer-tab-find-next-rec (buffer-list)
  (when buffer-list 
	 (if (aref (car buffer-list) 3) 
		  (cadr buffer-list)
		(buffer-tab-find-next-rec (cdr buffer-list))
	 )
))

(defun buffer-tab-find-next-z ()
  (let ((buffer-list  ( buffers-tab-items ))) 
	 (let ((next-buffer (buffer-tab-find-next-rec buffer-list)))
	 (if next-buffer 
		  next-buffer
		(last buffer-list))
	 ))
  )

(defun buffer-tab-find-next () ;; buggy
  (let ((buffer-list  (reverse  ( buffers-tab-items )))) 
	 (let ((prev-buffer (buffer-tab-find-prev-rec buffer-list nil)))
	 (if prev-buffer 
		  prev-buffer
		(car (last buffer-list))
	 )))
  )


(defun buffer-tab-advance (&optional direction )
  "Switch to next/prev buffer in Buffer Tab List."
  (interactive)
  (let ((target-buffer 
		 (if direction
			  (buffer-tab-find-prev)
			(buffer-tab-find-next))))
		 (eval (aref  target-buffer 1))))


;; Toggles between line wrapping in the current buffer.
(defun toggle-line-wrapping ()
  "Toggles between line wrapping in the current buffer."
  (interactive)
  (if (eq truncate-lines nil)
      (progn
        (setq truncate-lines t)
        (redraw-display)
        (message "Setting truncate-lines to t"))
    (setq truncate-lines nil)
    (redraw-display)
    (message "Setting truncate-lines to nil"))
  )

;; Untabifies entire buffer.
(defun untabify-buffer ()
  "Untabifies entire buffer."
  (interactive)
  (point-to-register 1)
  (goto-char (point-min))
  (untabify (point-min) (point-max))
  (register-to-point 1)
  )

;; Tabifies entire buffer.
(defun tabify-buffer ()
  "Tabifies entire buffer."
  (interactive)
  (point-to-register 1)
  (goto-char (point-min))
  (tabify (point-min) (point-max))
  (register-to-point 1)
  )

(defun remove-trailing-ctl-M ()
  "Propose to remove trailing ^M from a file."
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (if (and (not (string-match ".gz$" (buffer-file-name)))
             (search-forward-regexp "
$" nil t))
                                        ;: a ^M is found
        (if (or (= (preceding-char) ?\^J)
                (= (following-char) ?\^J) )
            (if (y-or-n-p (format "Remove trailing ^M from %s? " 
                                  (buffer-file-name)))
                (progn (goto-char (point-min))
                       (perform-replace "
" "" nil nil nil)
                       (pop-mark) 
                       (save-buffer))
              (message "No transformation."))))))


(defun toggle-menubar ()
  (interactive)
  (set-specifier
   menubar-visible-p
   (not (specifier-instance menubar-visible-p))))

(defun toggle-modeline ()
  (interactive)
  (set-specifier
   has-modeline-p
   (not (specifier-instance has-modeline-p))))

(defun toggle-toolbar ()
  (interactive)
  (set-specifier
   default-toolbar-visible-p
   (not (specifier-instance default-toolbar-visible-p))))

;; Toggle Gutter Bar
(if  (eq z-emacs-type 'xemacs) ;; XEmacs
	 (defun toggle-gutter-bar ()
		"Tabifies entire buffer."
		(interactive)
		(customize-set-variable 'gutter-buffers-tab-visible-p
										(not gutter-buffers-tab-visible-p))
		)
  )


;; ---( PC Select )-----------------------------------------------------------


(if  (eq z-emacs-type 'xemacs) ;; XEmacs
	 (progn
		(if  (eq system-type 'usg-unix-v) ;; Sun Solaris
			 (progn
				(require 'pc-select)
				(pc-select-mode t)
				)

		  (progn
			 ))
		)
  
  (progn
	 ))


;; ---( Keyboard Mapping )----------------------------------------------------


(global-set-key [backspace] 'backward-delete-char )
(global-set-key [(control backspace)] 'backward-kill-word )
(global-set-key [(meta backspace)] 'undo )


(global-set-key [(meta home)] 'delete-other-windows )
(global-set-key [(meta end)] 'bury-buffer )

(global-set-key [(control prior)] 'other-frame )
(global-set-key [(control next)] 'other-window )

(global-set-key [(meta control prior)] 'outline-previous-visible-heading )
(global-set-key [(meta control next)] 'outline-next-visible-heading )


(global-set-key [(control up)] 'scroll-down-one )
(global-set-key [(control down)] 'scroll-up-one )
(global-set-key [(meta up)] 'backward-block-of-lines )
(global-set-key [(meta down)] 'forward-block-of-lines )


(if  (eq z-system 'winnt) 
	 (progn
		(global-set-key [(control right)] 'forward-word )
		(global-set-key [(control left)] 'backward-word )
		(global-set-key [(control meta right)] 'backward-sexp )
		(global-set-key [(control meta left)] 'forward-sexp )
		)

  (progn ;; reserve control h-arrow for WM
	 ))

;;; WM Desktop !!!
(global-unset-key [(control right)])
(global-unset-key [(control left)])

(global-set-key [(meta right)] 'forward-word )
(global-set-key [(meta left)] 'backward-word )


(global-set-key [clear] '(lambda () (interactive) (recenter 1)))

(define-key global-map [(control clear)]	'recenter)
(define-key global-map [(control kp-space)]	'recenter)

(define-key global-map [kp-home]	'scroll-cursor-to-bottom)
(define-key global-map [kp-end]	'scroll-cursor-to-top)
(define-key global-map [kp-left]	'backward-char-command)
(define-key global-map [kp-right]	'forward-char-command)
(define-key global-map [(control kp-left)]	'scroll-left)
(define-key global-map [(control kp-right)]	'scroll-right)
(define-key global-map [kp-up]		'scroll-down-one)
(define-key global-map [kp-down]	'scroll-up-one)
(define-key global-map [kp-multiply]	'scroll-left)

(define-key global-map [kp-delete]	'bury-buffer)
(define-key global-map [(control kp-delete)]	'kill-this-buffer)
(define-key global-map [(control kp-insert)]	'other-frame)
(define-key global-map [(meta kp-insert)]	'make-frame)
(define-key global-map [(meta kp-delete)]	'delete-frame)


;---(buffers)-----
(require 'bs)
(define-key global-map [kp-insert]	'bs-show)

;;(setq bs-default-configuration "files")

(global-set-key [(control shift tab)]   'bs-cycle-previous)
(global-set-key [(control tab)]  'bs-cycle-next)


;;(global-set-key [(control tab)] 'switch-to-other-buffer )
;;(global-set-key [(control tab)]  '(lambda () 
;;													  (interactive) (buffer-tab-advance t)) ) 
;;(global-set-key [(control meta tab)]  '(lambda () 
;;													  (interactive) (buffer-tab-advance t)) ) 
;;(global-set-key [(control shift tab)]  '(lambda () 
;;													  (interactive) (buffer-tab-advance nil)) ) 

;; better buffer cycling
;; (global-set-key [(control return)] 'forward-buffer)
;; (global-set-key [(shift return)]  'backward-buffer)




(if  (eq z-emacs-type 'xemacs) ;; XEmacs
	 (progn
		(define-key global-map [(control kp-insert)]	'toggle-line-wrapping)
		(setq truncate-lines t)
		)

  (progn
		(define-key global-map [(control kp-insert)]	'toggle-truncate-lines)
;		(toggle-truncate-lines)
	 ))




(define-key global-map [(control kp-prior)]	'shrink-window)
(define-key global-map [(control kp-next)]	
  '(lambda () (interactive) (shrink-window -1)))
(define-key global-map [(meta kp-prior)]	
  '(lambda () (interactive) (set-frame-height (selected-frame) (- (frame-height) 1))))
(define-key global-map [(meta kp-next)]	
  '(lambda () (interactive) (set-frame-height (selected-frame) (+ (frame-height) 1))))
(define-key global-map [(control meta kp-prior)]	
  '(lambda () (interactive) (set-frame-width (selected-frame) (- (frame-width) 1))))
(define-key global-map [(control meta kp-next)]	
  '(lambda () (interactive) (set-frame-width (selected-frame) (+ (frame-width) 1))))


(if  (eq z-emacs-type 'xemacs);; XEmacs
	 (progn
		(define-key global-map [(control meta kp-up)]	
		  '(lambda () (interactive) 
			  (set-frame-position (selected-frame) 
										 (frame-property (selected-frame) 'left) 
										 (- (frame-property (selected-frame) 'top) 5))))
		(define-key global-map [(control meta kp-down)]	
		  '(lambda () (interactive) 
			  (set-frame-position (selected-frame) 
										 (frame-property (selected-frame) 'left) 
										 (+ (frame-property (selected-frame) 'top) 5))))
		(define-key global-map [(control meta kp-left)]	
		  '(lambda () (interactive) 
			  (set-frame-position (selected-frame) 
										 (- (frame-property (selected-frame) 'left) 5) 
										 (frame-property (selected-frame) 'top))))
		(define-key global-map [(control meta kp-right)]	
		  '(lambda () (interactive) 
			  (set-frame-position (selected-frame) 
										 (+ (frame-property (selected-frame) 'left) 5)
										 (frame-property (selected-frame) 'top))))
		)

  (progn
	 (define-key global-map [(control meta kp-up)]	
		'(lambda () (interactive) 
			(set-frame-position (selected-frame) 
									  (frame-parameter (selected-frame) 'left) 
									  (- (frame-parameter (selected-frame) 'top) 5))))
	 (define-key global-map [(control meta kp-down)]	
		'(lambda () (interactive) 
			(set-frame-position (selected-frame) 
									  (frame-parameter (selected-frame) 'left) 
									  (+ (frame-parameter (selected-frame) 'top) 5))))
	 (define-key global-map [(control meta kp-left)]	
		'(lambda () (interactive) 
			(set-frame-position (selected-frame) 
									  (- (frame-parameter (selected-frame) 'left) 5) 
									  (frame-parameter (selected-frame) 'top))))
	 (define-key global-map [(control meta kp-right)]	
		'(lambda () (interactive) 
			(set-frame-position (selected-frame) 
									  (+ (frame-parameter (selected-frame) 'left) 5)
									  (frame-parameter (selected-frame) 'top))))
	 ))







(global-set-key [f11] 'make-frame )
(global-set-key [(control f11)] 'delete-frame )
(global-set-key [f12] 'buffer-menu )
(global-set-key [(control f12)] 'dired )
(global-set-key [(control meta f12)] 'revert-buffer )

(if  (eq z-emacs-type 'xemacs) ;; XEmacs
	 (progn
		(global-set-key [(control f10)]  'toggle-menubar)
		(global-set-key [(meta f10)]  'toggle-gutter-bar)
		(global-set-key [(control meta f10)]  'toggle-modeline)

		(toggle-menubar)
;;		(customize-set-variable 'gutter-buffers-tab-visible-p nil)
		)

  (progn
	 (global-set-key [(control f10)] 'menu-bar-mode )
	 (menu-bar-mode 0)
	 ))


(define-key esc-map "o" 'dired-other-frame )
(define-key esc-map "n" 'goto-line )

(global-set-key [(control f9)] 'gdb )
(global-set-key [f9] 'compile )


(define-key global-map [(control kp-add)] 'kill-rectangle)
(define-key global-map [(control kp-subtract)] 'delete-rectangle)
(define-key global-map [(control kp-enter)] 'yank-rectangle)
(global-set-key [kp-subtract]
  '(lambda () (interactive) 
	  (copy-rectangle-to-register ?r (region-beginning) (region-end) t )))
(global-set-key [kp-add]
  '(lambda () (interactive) 
	  (copy-rectangle-to-register ?r (region-beginning) (region-end))))
(global-unset-key [kp-enter])
(global-set-key [kp-enter]
  '(lambda () (interactive) 
	  (insert-register ?r)
	  (let ((col (current-column)))
		 (forward-line)
		 (move-to-column col t))))
(global-set-key [(meta kp-enter)]
  '(lambda () (interactive) 
	  (insert-register ?r)))

(global-set-key [f4] 'call-last-kbd-macro)
(global-set-key [(control f4)] 'start-kbd-macro )
(global-set-key [(meta f4)] 'end-kbd-macro )
(global-set-key [(shift f4)] 'kbd-macro-query )
(global-set-key [(control meta f4)] 'edit-last-kbd-macro )

;;(global-set-key [(control f4)] 'untabify-buffer)
;;(global-set-key [(meta f4)] 'tabify-buffer)
;;(global-set-key [f5] 'tags-search)
;;(global-set-key [(shift f5)] 'tags-query-replace)
;;(global-set-key [(control f5)] 'list-tags)
;;(global-set-key [(meta f5)] 'tags-apropos)
;;(global-set-key [(control meta f5)] 'visit-tags-table)
;; Hit f9 to force a re-fontify
;;(global-set-key (quote [f9]) (quote font-lock-fontify-buffer))

;;;---(Bookmarks and Session)
(global-set-key [f1] 'bookmark-set )
(global-set-key [f2] ' bookmark-bmenu-list)

(require 'desktop)
(require 'desktop-menu)
(global-set-key [(control f1)] 
					 '(lambda () (interactive) 
						 (and (yes-or-no-p "Save Desktop?")
								(desktop-save "~/"))))
(global-set-key [(control f2)] 'desktop-read)

;; add hook save on exit ?


; ;;;_ + desktop

; (load "desktop")
; (load "desktop-save")

; (defcustom initial-desktop-directory "~/"
;   "*The directory where the main desktop file is stored."
;   :type 'file
;   :group 'desktop)

; (setq escreen-data-file
;       (expand-file-name ".escreen" initial-desktop-directory))

; (add-hook 'desktop-save-hook 'escreen-save-state)
; (add-hook 'desktop-save-hook 'escreen-save-current-screen-configuration)

; (add-hook 'desktop-save-hook 'session-save-session)

; (add-hook 'desktop-save-hook
; 	  (function
; 	   (lambda ()
; 	     (if (fboundp 'eshell-save-some-history)
; 		 (eshell-save-some-history)))))

; (add-hook 'desktop-save-hook
; 	  (function
; 	   (lambda ()
; 	     (if (fboundp 'eshell-save-some-last-dir)
; 		 (eshell-save-some-last-dir)))))

; (defun setup-desktop ()
;   "Setup Emacs by reading from a set of persistent state files."
;   (add-hook
;    'eshell-first-time-mode-hook
;    (function
;     (lambda ()
;       (remove-hook 'kill-emacs-hook 'eshell-save-some-history)
;       (remove-hook 'kill-emacs-hook 'eshell-save-some-last-dir))))

;   (let ((default-directory initial-desktop-directory))
;     (desktop-load-default)
;     (desktop-read))

;   (if (file-readable-p escreen-data-file)
;       (escreen-restore-state escreen-data-file))

;   (add-hook 'kill-emacs-hook
; 	    (function
; 	     (lambda ()
; 	       (let ((buf (get-buffer "*Process List*")))
; 		 (when (and buf (buffer-live-p buf))
; 		   (if (get-buffer-window buf)
; 		       (delete-window (get-buffer-window buf)))
; 		   (kill-buffer buf))))))

;   (add-hook 'kill-emacs-hook 'kill-encrypted-buffers)

;   (run-with-idle-timer (* 60 5)  t 'desktop-kill)
;   (run-with-idle-timer (* 60 30) t 'desktop-kill))

; (if (and (file-exists-p (concat initial-desktop-directory
; 				desktop-basefilename))
; 	 (null noninteractive))
;     (add-hook 'after-init-hook 'setup-desktop))

; ;;;_ + escreen

; (setq escreen-prefix-char [(control backspace)])

; (load "escreen")

; (escreen-install)

; (add-hook 'escreen-goto-screen-hook
; 	  (function
; 	   (lambda ()
; 	     (if (fboundp 'eshell-refresh-windows)
; 		 (eshell-refresh-windows)))))








(global-set-key [(meta control f1)]
  '(lambda () (interactive) 
	  (point-to-register 'p)))
(global-set-key [(meta control f2)]
  '(lambda () (interactive) 
	  (jump-to-register 'p)))

(global-set-key [(control space)]   
  '(lambda () (interactive) 
	  (set-mark-command nil)
	  (zmacs-deactivate-region)
	  ))

(global-set-key [(control return)]   
  '(lambda () (interactive) 
	  (set-mark-command t)
	  ))
(global-set-key [(meta return)] 'ffap-other-frame)  

(global-set-key [(control meta return)] 'pop-global-mark )


(if  (eq z-emacs-type 'xemacs) ;; XEmacs
	 (progn
		(bookmark-load bookmark-default-file)
		)

  (progn
	 ))



(global-set-key [f5] 'isearch-forward-regexp )
(global-set-key [(control f5)] 'make-search-dialog )
(global-set-key [f3] 'isearch-repeat-forward )
(global-set-key [(control f3)] 'isearch-repeat-backward )
(global-set-key [f6] 'query-replace )
(global-set-key [(control f6)] 'query-replace-regexp )

(global-set-key [f7] 'occur )
(global-set-key [(control f7)] 'grep )
(global-set-key [(meta f7)] 'compare-windows )
(global-set-key [(control meta f7)] 'ediff )


(global-set-key [f8] 'speedbar )
;;(define-key speedbar-key-map [button1] 'dframe-click)

;; ---( meta f )--------------------------------------------------------------

(global-unset-key [(meta f)])
(define-prefix-command 'z-meta-f-prefix)
(defvar z-meta-f-map (symbol-function 'z-meta-f-prefix))
(define-key global-map [(meta f)] 'z-meta-f-prefix)

(define-key z-meta-f-map [s] 'save-buffer)
(define-key z-meta-f-map [(meta s)] 'save-buffer)
(define-key z-meta-f-map [v] '(lambda () 
													  (interactive) (save-some-buffers t)) ) 
(define-key z-meta-f-map [(meta v)] '(lambda () 
													  (interactive) (save-some-buffers t)) ) 


(define-key bookmark-map [return] 'bookmark-bmenu-select)


;; ---( Mouse )---------------------------------------------------------------

;; Paste at point NOT at cursor
;(setq mouse-yank-at-point 't)


;; ---( Themes )----------------------------------------------------------------

;;(require 'color-theme)
(require 'color-theme-zcoll)

(global-unset-key [kp-divide])
(global-unset-key [(control kp-divide)])
(global-unset-key [(control /)])

(define-key global-map [kp-divide]	'color-theme-select)
(define-key global-map [(control kp-divide)]	'color-theme-select)
(define-key global-map [(control /)]	'color-theme-select)

;(global-set-key '(control kp-divide) 'color-theme-select )
;(global-set-key '(control divide) 'color-theme-select )

;;(set-face-background 'zmacs-region "DarkGreen")
;;(set-face-foreground 'zmacs-region "white")


;(setq default-frame-alist 
;      '(
;	(top . 10) 
;	(left . 10) 
;	(width . 80) 
;	(height . 45)))

(if  (eq z-emacs-type 'xemacs) ;; XEmacs
	 (progn
		(setq color-theme-is-global t)
		)

  (progn
		(setq color-theme-is-global nil)
	 ))



;; ---( Extra Color )---------------------------------------------------------

(if  (eq z-emacs-type 'xemacs) ;; XEmacs
	 (progn
		(set-face-background 'zmacs-region "Green")
		(set-face-foreground 'zmacs-region "Black")
		)

  (progn
	 ))



;; ---( Custom Fonts )---------------------------------------------------------


(require 'ergo-font)
(ergo-font-default-binding)



;; ----------------------------------------------------------------------------
;; ---( OS Dependent )---------------------------------------------------------
;; ----------------------------------------------------------------------------

(if (eq z-emacs-type 'xemacs) 

	 (cond  ;;--- XEmacs ---------------------------------------------------
	  ((eq system-type 'windows-nt) ;; WinNT
		(cond 
		 (t
		  (progn
			 (custom-set-faces
			  '(default ((t (:size "9pt" :family "Lucida Sans Typewriter"))) t))


		  (setq default-frame-plist 
				  '(
					 (width . 90) 
					 (height . 55)
					 (background-color . "#041e4b")
					 (background-mode . dark)
					 (foreground-color . "cornsilk")
					 (cursor-color . "red")
					 )
			 )
		  (setq initial-frame-plist 
				  '(
					 (top . 30) 
					 (left . 450)
					 (width . 90) 
					 (height . 65)
;					 (background-color . "#041e4b")
;					 (background-mode . dark)
;					 (foreground-color . "cornsilk")
;					 (cursor-color . "red")
					 )
				  )
		  (setq color-theme-is-global t)
;;		  (color-theme-z-ryerson)            ;; default
;;		  (setq color-theme-is-global nil)
		  (color-theme-z-gnome2)          ;; inital
		  )
		  )))
	  ((eq system-type 'gnu/linux);; GNU-Linux
		(cond 
		 ((string= (getenv "DISPLAY") ":0.0")
		  (progn
			 )
		  )
		 (t
		  (progn
			 )
		  )))
	  ((eq system-type 'usg-unix-v);; Sun Solaris
		(cond 
		 ((string= (getenv "DISPLAY") ":0.0")
		  (progn
			 (setq delete-key-deletes-forward t)
			 (setq initial-frame-plist '(top 25 left 400 width 85 height 53))
			 (setq default-frame-plist '(width 80 height 50))
			 (custom-set-faces
			  '(default ((t (:size "15pt" :family "Clean"))) t))
			 (color-theme-z-billw)
			 )
		  )
		 (t
		  (progn
			 (setq delete-key-deletes-forward t)
			 (setq default-frame-plist '(width 90 height 45))
			 (custom-set-faces
			  '(default ((t (:size "13pt" :family "Clean"))) t))
			 (color-theme-z-billw)
			 )
		  )))
	  )

  (cond  ;;--- FSF-Emacs ---------------------------------------------------
	((eq system-type 'windows-nt) ;; WinNT
	 (cond 
	  (t
		(progn
		  (setq default-frame-alist 
				  '(
					 (top . 70) 
;					 (left . 40) 
					 (width . 85) 
					 (height . 40)
					 (background-color . "#303010")
					 (background-mode . dark)
					 (foreground-color . "cornsilk")
					 (border-color . "black")
					 (cursor-color . "white")
					 (mouse-color . "black")			
;;					 (font . "-*-Andale Mono-normal-r-*-*-11-*-*-*-c-*-iso8859-1")
;;					 (font . "-*-Lucida Sans Typewriter-normal-r-*-*-11-*-*-*-c-*-iso8859-1")
					 (font . "-*-Lucida Sans Unicode-normal-r-*-*-12-*-*-*-c-*-iso8859-1")

					 )
			 )

		  (setq color-theme-is-global t)
		  (color-theme-z-gnome3)            ;; default
;;		  (color-theme-z-billw) ;; initial
		  (setq color-theme-is-global nil)
;;		  (color-theme-z-billw) ;; initial
		  (color-theme-z-gnome3-d)            ;; default

		  (setq initial-frame-alist 
				  (append
					'(
					  (top . 30) 
					  (left . 350) 
					  (width . 85) 
					  (height . 29)
;;					  (height . 49)
;;					  (background-color . "#1A4F15" ) 
;;					  (foreground-color . "#CDE7CD" ) 
;;					  (cursor-color . "red")
;;					  (border-color . "blue")
					  (background-color . "#203030")
;;					  (foreground-color . "#00D0D0")
					  (foreground-color . "#CDE7CD" ) 
					  (cursor-color . "red")
					  (border-color . "white")
;;					  (border-color . "#00007F")


;;					  (font . "-*-Raize-normal-r-normal-normal-16-120-96-96-c-90-iso8859-15")
;;					  (font . "-*-SimSun-normal-r-*-*-16-*-*-*-c-*-iso8859-1")
;;					  (font . "-*-r_ansi-normal-r-*-*-16-*-*-*-c-*-iso8859-1")
					  (font . "-*-Need Glasses ?-normal-r-*-*-18-*-*-*-c-*-iso8859-1")
;;					  (font . "-*-r_ansi-normal-r-*-*-14-*-*-*-c-*-iso8859-1")
;;					  (font . "-*-Andale Mono-normal-r-*-*-14-*-*-*-c-*-iso8859-1")
;;					  (font . "-*-Letter Gothic 12 Pitch BT-normal-r-*-*-15-*-*-*-c-*-iso8859-1")

					  )
					initial-frame-alist ))
		  )
		)))
	((eq system-type 'gnu/linux);; GNU-Linux
	 (cond 
	  ((string= (getenv "DISPLAY") ":0.0")
		(progn
		  
		  )
		)
	  (t
		(progn
		  (setq default-frame-alist 
				  '(
;					 (top . 45) 
;					 (left . 40) 
;					 (width . 80) 
;					 (height . 40)
					 (background-color . "#002035")
					 (background-mode . dark)
					 (foreground-color . "cornsilk")
					 (border-color . "black")
					 (cursor-color . "white")
					 (mouse-color . "black")			
					 (font . "-misc-screen-medium-r-normal-*-*-120-*-*-c-*-iso8859-7")
					 )
			 )


		  (setq color-theme-is-global t)
		  (color-theme-z-ryerson)            ;; default

         ;; #ifdef COLOR
         ;; *customization: -color
         ;; #endif
         ;; 
         ;; !!emacs*Foreground: Wheat
         ;; !!emacs*Background: Gray10
         ;; !!emacs*Foreground: Wheat
         ;; !!emacs*Background: DarkSlateGray
         ;; !!emacs*Foreground: Ivory3
         ;; !!emacs*Background: MidnightBlue
         ;; !!emacs*Foreground: DarkSeaGreen3
         ;; !!emacs*Background: Gray13
         ;; !!emacs*Foreground: PowderBlue
         ;; !!emacs*Background: Gray10
         ;; !!emacs*reverseVideo: on
         ;; emacs*pointerColor: Orchid
         ;; emacs*cursorColor: Orchid
         ;; emacs*bitmapIcon: on
         ;; !!emacs*font: -misc-screen-medium-R-normal--14-120-78-78-C-90-ISO8859-7
         ;; !!emacs*font: -greek-smserif-medium-r-semicondensed-*-*-160-*-*-m-*-iso8859-7
         ;; !!emacs*font: 10x20
         ;; !!emacs*font: -Sun-Serif-Medium-R-Normal-Serif-16-160-72-72-M-90-ISO8859-1
         ;; !!emacs*font: -adobe-courier-bold-r-normal--*-140-*-*-m-*-iso8859-1
         ;; emacs*font: -B&H-LucidaTypewriter-Medium-R-Normal-Sans-12-120-75-75-M-70-ISO8859-1
         ;; emacs*menubar.font:-adobe-helvetica-bold-r-normal-*-*-120-*-*-*-*-*-*
         ;; emacs.geometry: 80x25


;		  (setq initial-frame-alist 
;		    	  (append
;		    		'(
;		    		 (width . 90) 
;		    		 (height . 52)
;		    		 ( background-color . "#103045" ) 
;		    		 ( foreground-color . "LightCyan1" ) 
;		    		 ( cursor-color . "Yellow")
;		    		 ( background-mode . dark)
;		    		 (font . "-b&h-lucidatypewriter-medium-r-normal-*-*-120-*-*-m-*-iso8859-9")
;		    		  )
;		    		initial-frame-alist ))
		  
;		  (setq initial-frame-alist 
;		    		'(
;		    		 (width . 90) 
;		    		 (height . 52)
;		    		 ( background-color . "#103045" ) 
;		    		 ( foreground-color . "LightCyan1" ) 
;		    		 ( cursor-color . "Yellow")
;		    		 ( background-mode . dark)
;		    		 (font . "-b&h-lucidatypewriter-medium-r-normal-*-*-120-*-*-m-*-iso8859-9")
;		    		  ))


		  (setq initial-frame-alist 
				  '(
;					 (top . 25) 
;					 (left . 200) 
;					 (width . 80) 
;					 (height . 25)
		    		 ( background-color . "#103045" ) 
		    		 ( foreground-color . "LightCyan1" ) 
		    		 ( cursor-color . "Yellow")
		    		 ( background-mode . dark)
		    		 (font . "-b&h-lucidatypewriter-medium-r-normal-*-*-120-*-*-m-*-iso8859-9")
					 ))	  
		  
		  (setq color-theme-is-global nil)
		  (color-theme-z-jonadabian) ;; initial

		  )
		)))
	((eq system-type 'usg-unix-v);; Sun Solaris
	 (cond 
	  ((string= (getenv "DISPLAY") ":0.0")
		(progn
		  )
		)
	  (t
		(progn
		  )
		)))
	)
  )


;; ---( Backup Files )--------------------------------------------------------


(setq backup-by-copying t)

;(require 'backups)
;(move-backups t)

(setq backup-directory "~/.backups")

(or (directory-files backup-directory)
	  (make-directory backup-directory))
	 
(require 'backup-dir)
(setq bkup-backup-directory-info
		`(
       (t ,(concat backup-directory "/") full-path prepend-name search-upward)
;      (t ,(concat backup-directory "/"))
		  ))




(if (eq z-emacs-type 'xemacs) 

	 (cond  ;;--- XEmacs ---------------------------------------------------
	  ((eq system-type 'windows-nt) ;; WinNT
		(cond 
		 (t
		  (progn
			 (setq backup-by-copying nil)
		  )
		  )))
	  ((eq system-type 'gnu/linux);; GNU-Linux
		(cond 
		 (t
		  (progn
			 (setq backup-by-copying t)
			 )
		  )))
	  ((eq system-type 'usg-unix-v);; Sun Solaris
		(cond 
		 (t
		  (progn
			 (setq backup-by-copying t)
			 )
		  )))
	  )

  (cond  ;;--- FSF-Emacs ---------------------------------------------------
	((eq system-type 'windows-nt) ;; WinNT
	 (cond 
	  (t
		(progn
			 (setq backup-by-copying nil)
		  )
		)))
	((eq system-type 'gnu/linux);; GNU-Linux
	 (cond 
	  (t
		(progn
			 (setq backup-by-copying t)
		  )
		)))
	((eq system-type 'usg-unix-v);; Sun Solaris
	 (cond 
	  (t
		(progn
			 (setq backup-by-copying t)
		  )
		)))
	)
  )




;; ----------------------------------------------------------------------------
;; ---( GenericAddons )---------------------------------------------------------
;; ----------------------------------------------------------------------------

;; ---( AutoRevert )---------------------------------------------------------

(autoload 'auto-revert-mode "autorevert" nil t)
(autoload 'turn-on-auto-revert-mode "autorevert" nil nil)
(autoload 'global-auto-revert-mode "autorevert" nil t)

;; (global-auto-revert-mode 1) ;--- enable autorevert -------------

(add-hook 'java-mode-hook 'turn-on-auto-revert-mode)
(setq auto-revert-interval 5) ;--- check interval: 5 sec. -------------

;; ----------------------------------------------------------------------------
;; ---( Miscellanea )---------------------------------------------------------
;; ----------------------------------------------------------------------------

;; ---( Unclass )---------------------------------------------------------

(setq initial-scratch-message nil)


;;;_ + mule

;;(set-terminal-coding-system 'iso-latin-1)

;; Enable uppercase or lowercase conversions
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)

;; Disable narrowing, whatever the hell it is.
;;(put 'narrow-to-region 'disabled nil)
;; Scrolling
;;(setq scroll-step 1)

;; Tell emacs where my diary file is
(setq diary-file "~/diary/.diary")

;; Replace "yes or no" with y or n
(defun yes-or-no-p (arg)
  "An alias for y-or-n-p, because I hate having to type 'yes' or 'no'."
  (y-or-n-p arg))

;; Tell emacs where central backup directory is, and turn it on
;; (setq backup-directory "~/backups")
;; (require 'backups)
;; (move-backups t)



;; =====================================================================
;; PRINT CONFIGURATION
;; =====================================================================

;; This requires GhostScript which is available at this URL:
;; http://www.cs.wisc.edu/~ghost/aladdin To print, just hit C-cp. This
;; produces a file called printme.ps in the spool directory. Open this
;; in GhostView and print from there. This works even on
;; non-postscript printers.
;;  --- (setq ps-printer-name "~/spool/printme.ps")
;; --- (define-key global-map "\C-cp" 'ps-print-buffer)

;; Printing. For Windows, using w32-print. For Unix, using built-in.
(defun z-print-setup () ;
(if
    ;; Win32
    (eq system-type 'windows-nt)
    (progn
      (add-to-list 'load-path (concat my-site-lisp "/w32-print-1.3"))
      (setq-default
       ;; General
       w32-print-use-faces nil		; disable color, etc
       w32-print-zap-spool-file t	; delete temp file
       w32-print-paper-type 'letter
       w32-print-with-line-numbers t
       w32-print-enable-keymappings nil ; disable keyboard shortcuts
       ;; Postscript
       w32-print-ps-preview nil		; disable print preview
       w32-print-ps-destination (if (eq my-location 'home)
				    "lpt1"
				  "//romsvr1/hplj4050")
       w32-print-ps-text-font-size 14.0
       w32-print-psnup-path (concat my-site-lisp "/w32-print-1.3/bin")
       w32-print-psnup-margin "0in"
       w32-print-psnup-enable t
       ;; Ghostscript
       w32-print-gs-destination (if (eq my-location 'home)
				    "lpt1"
				  "//romsvr1/hplj4050")
       w32-print-gs-device (if (eq my-location 'home) "deskjet" "ljet4")
       w32-print-gs-device-dpi (if (eq my-location 'home) '300 '600)
       w32-print-gs-version "6.01"
       w32-print-gs-path (concat my-gnu-home "/ghostscript/gs6.01/bin")
       w32-print-gs-view-path (concat my-gnu-home "/ghostscript/gsview")
       ;; Plain old printer
       w32-print-lpr-destination (if (eq my-location 'home)
				     "lpt1"
				   "//romsvr1/hplj4050")
       w32-print-lpr-path (concat my-site-lisp "/w32-print-1.2/bin")
       )
      ;; Let's use it
      (load "w32-print")
      )
  ;; Unix system. Nothing to do since I can't print from unix.
  ()
  )
)

;; =====================================================================
;; GREP/DIFF RELATED SETTINGS
;; =====================================================================

;; Ignore case by default:
;;(setq igrep-options "-i")
;;(setq grep-command "egrep -n")

;; To search subdirectories by default:
;;(setq igrep-find t)

;;(setq ediff-ignore-similar-regions t)
;;(setq ediff-use-last-dir t)
;;(setq ediff-diff-options " -b ")


;; =====================================================================
;; CODE RELATED SETTINGS
;; =====================================================================


(if  (eq z-emacs-type 'xemacs) ;; XEmacs
	 (progn
		(require 'paren)
		;; Turn on paren mode - this highlight matching under point
		;; (show-paren-mode 1)
		;;(setq paren-mode nil)
		;;(setq paren-mode 'blink-paren)
		(setq paren-mode 'paren)
		;;(setq paren-mode 'sexp)
		(paren-activate)
		)

  (progn
	 (show-paren-mode)
	 ))


;; Make the % key jump to the matching {}[]() if on another, like VI
;;(global-set-key "%" 'match-paren)
(defun match-paren (arg)
  "Go to the matching parenthesis if on parenthesis otherwise insert %."
  (interactive "p")
  (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
        ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
        (t (self-insert-command (or arg 1)))))

;; =====================================================================
;; =====================================================================
;; Saving Emacs Sessions - Useful when you have a bunch of source
;; files open and you don't want to go and manually open each one,
;; especially when they are in various directories. Page 377 of the
;; GNU Emacs Manual says: "The first time you save the state of the
;; Emacs session, you must do it manually, with the command M-x
;; desktop-save. Once you have dome that, exiting Emacs will save the
;; state again -- not only the present Emacs session, but also
;; subsequent sessions. You can also save the state at any time,
;; without exiting Emacs, by typing M-x desktop-save again.
;; =====================================================================

;;(load "desktop")
;;(desktop-load-default)
;;(desktop-read)

;; =====================================================================
;; =====================================================================
;; USEFUL NOTES AND OTHER STUFF
;; =====================================================================

;; How to record and display a keyboard macro

;; Just open a buffer and type C-x ( Then start typing in your macro.
;; Once you are finished defining your macro type C-x ) Then type M-x
;; name-last-kbd-macro. This will allow you to call your macro
;; whatever you want. Next open up your .emacs file and position your
;; cursor where you want the code for the macro to appear.  Type M-x
;; insert-kbd-macro and type in the name.  The code will automatically
;; be generated.

;; =====================================================================
;; =====================================================================

;; Use shell-command-on-region M-| to send region to external
;; process. If you use a prefix argument , C-u M-| this will replace
;; the region with the output of the external process. Good for
;; sending something to stdin and reading from stdout.

;; =====================================================================
;; =====================================================================

;; To copy to named register: C-x r s a - Where a is the name of the
;; register ( a - z ) to save the text to.

;; To paste from named register: C-x r i a - Where a is the name of
;; the register ( a - z ) to paste the saved text from.

;; To remember current point: C-x r spc a - Where a is the name of the
;; register to save point to.

;; To jump to named point: C-x r j a - Where a is the name of the
;; register holding desired point to jump to

;; =====================================================================
;; SOME GOOD URL's FOR EMACS SOURCES
;; =====================================================================

;; http://www.splode.com/users/friedman/software/emacs-lisp/
;; http://www.anc.ed.ac.uk/~stephen/emacs/ell.html

;; =====================================================================
;; =====================================================================

;;----------------------------------------------------------------------------
;; Set up hooks for often-used major modes 
;;----------------------------------------------------------------------------


;;;////////////////////////////////////////////////////////////////
;;;  IDL (RSI) 
;;;////////////////////////////////////////////////////////////////


;;(setq speedbar-supported-extension-expressions 
;;		(cons ".pro" speedbar-supported-extension-expressions))


(setq auto-mode-alist (cons '("\\.pro\\'" . idlwave-mode) 
			    (cons '("\\.pro\\'" . idlwave-mode) auto-mode-alist)))

(add-hook 'idlwave-mode-hook
          (function
           (lambda ()
             (local-unset-key [(meta backspace)])
             )))

;;;////////////////////////////////////////////////////////////////
;;;  R
;;;////////////////////////////////////////////////////////////////

(if  (eq z-emacs-type 'fsf_emacs) ;; Emacs
	 (if (eq z-location 'home)
		  (progn
			 (setq load-path (cons "h:/usr/share/R/ess/ess-5.1.19/lisp" load-path))
			 (require 'ess-site)
			 )))



;;;////////////////////////////////////////////////////////////////
;;;  AUCTEX
;;;////////////////////////////////////////////////////////////////

(if  (eq z-emacs-type 'fsf_emacs) ;; Emacs
	 (if (eq z-location 'home)
		  (progn
			 (require 'tex-site)
			 ;;(setq-default TeX-master nil) ;-- Query for master file
			 ;;(setq-default TeX-master "Thesis") ;-- Fixed Master File
			 ;;(setq-default TeX-master "Slider") ;-- Fixed Master File
			 ;;(setq-default TeX-master "Abstract") ;-- Fixed Master File
			 (setq Tex-parse-self t) ; Parse on Load
			 (setq Tex-auto-save t) ; Parse on save
			 (setq outline-minor-mode-prefix "\C-o") ; Outline minor Prefix
			 (add-hook 'LaTeX-mode-hook 'outline-minor-mode)
			 )))



;;;////////////////////////////////////////////////////////////////
;;;  PSGML/xslide
;;;////////////////////////////////////////////////////////////////

(if  (eq z-emacs-type 'fsf_emacs) ;; Emacs
	 (if (eq z-location 'home)
		  (progn
			 (setq load-path (cons "h:/usr/share/emacs-21.1/site-lisp/psgml-1.2.5" load-path))
			 (autoload 'sgml-mode "psgml" "Major mode to edit SGML files." t)
			 (autoload 'xml-mode "psgml" "Major mode to edit XML files." t)
			 
			 (setq load-path (cons "h:/usr/share/emacs-21.1/site-lisp/xslide" load-path))
			 (autoload 'xsl-mode "xslide" "Major mode for XSL stylesheets." t)

			 (setq load-path (cons "h:/usr/share/emacs-21.1/site-lisp/xslt-process-2.1/lisp" load-path))
			 (autoload 'xslt-process-mode "xslt-process" "Emacs XSLT processing" t)
			 (autoload 'xslt-process-install-docbook "xslt-process"
				"Register the DocBook package with XSLT-process" t)
			 (add-hook 'sgml-mode-hook 'xslt-process-mode)
			 (add-hook 'xml-mode-hook 'xslt-process-mode)
			 (add-hook 'xsl-mode-hook 'xslt-process-mode)
			 (defadvice xml-mode (after run-xml-mode-hooks act)
				"Invoke `xml-mode-hook' hooks in the XML mode."
				(run-hooks 'xml-mode-hook))

			 (autoload 'css-mode "css-mode")
			 (setq auto-mode-alist       
					 (cons '("\\.css\\'" . css-mode) auto-mode-alist))


			 ;; Turn on font lock when in XSL mode
			 (add-hook 'xsl-mode-hook
						  'turn-on-font-lock)

			 ;; Set up file-extension/mode associations.
			 ;; Note that I use xml-mode for html... that's because i'm writing 
			 ;; XHTML and I want my html to conform to XML.
			 (setq auto-mode-alist 
					 (append '(
								  ("\\.sgml" . sgml-mode)
								  ("\\.idd" . sgml-mode)
								  ("\\.ide" . sgml-mode)
								  ("\\.htm" . sgml-mode)
								  ("\\.html" . sgml-mode)
								  ("\\.xhtml" . xml-mode)
								  ("\\.xml" . xml-mode)
								  ("\\.xsd" . xml-mode)
								  ("\\.xul" . xml-mode)
								  ("\\.rdf" . xml-mode)
								  ;;  ("\\.xsl" . xml-mode)
								  ;;  ("\\.fo" . xml-mode)
								  ("\\.fo" . xsl-mode)
								  ("\\.xsl" . xsl-mode)
								  )
								auto-mode-alist
								)
					 )


			 ;; Set up and enable syntax coloring. 
			 ;; Create faces  to assign markup categories.
			 (make-face 'sgml-doctype-face)
			 (make-face 'sgml-pi-face)
			 (make-face 'sgml-comment-face)
			 (make-face 'sgml-sgml-face)
			 (make-face 'sgml-start-tag-face)
			 (make-face 'sgml-end-tag-face)
			 (make-face 'sgml-entity-face)

			 ;; Assign attributes to faces. Background of white assumed.
			 (set-face-foreground 'sgml-doctype-face "blue1")
			 (set-face-foreground 'sgml-sgml-face "cyan1")
			 (set-face-foreground 'sgml-pi-face "magenta")
			 (set-face-foreground 'sgml-comment-face "purple")
			 (set-face-foreground 'sgml-start-tag-face "Red")
			 (set-face-foreground 'sgml-end-tag-face "Red")
			 (set-face-foreground 'sgml-entity-face "Blue")

			 ;; Assign faces to markup categories.
			 (setq sgml-markup-faces
					 '((doctype	. sgml-doctype-face)
						(pi		. sgml-pi-face)
						(comment	. sgml-comment-face)
						(sgml	. sgml-sgml-face)
						(comment	. sgml-comment-face)
						(start-tag	. sgml-start-tag-face)
						(end-tag	. sgml-end-tag-face)
						(entity	. sgml-entity-face)))

			 ;; PSGML - enable face settings
			 (setq sgml-set-face t)

			 ;; Auto-activate parsing the DTD when a document is loaded.
			 ;; If this isn't enabled, syntax coloring won't take affect until
			 ;; you manually invoke "DTD->Parse DTD"
			 (setq sgml-auto-activate-dtd t)


			 ;; Set up my "DTD CATALOG".
			 ;; defined in "/usr/local/lib/sgml/CATALOG.cat"
			 ;; (add-to-list 'sgml-catalog-files "/usr/local/lib/sgml/HTML4/HTML4.cat")
			 ;; (add-to-list 'sgml-catalog-files "/usr/local/lib/sgml/XHTML1/xhtml1.soc")

			 ;; Set up my "DTD->Insert DTD" menu.

			 (setq sgml-custom-dtd '
					 (
					  ( "DITA concept"
						 "<?xml version=\"1.0\"?>\n<!DOCTYPE concept SYSTEM \"concept.dtd\">" )
					  ( "DITA task"
						 "<?xml version=\"1.0\"?>\n<!DOCTYPE task SYSTEM \"task.dtd\">" )
					  ( "DITA reftopic"
						 "<?xml version=\"1.0\"?>\n<!DOCTYPE reftopic SYSTEM \"reftopic.dtd\">" )
					  ( "DITA APIdesc"
						 "<?xml version=\"1.0\"?>\n<!DOCTYPE APIdesc SYSTEM \"apidesc.dtd\">" )
					  ( "DITA topic"
						 "<?xml version=\"1.0\"?>\n<!DOCTYPE topic SYSTEM \"ditabase.dtd\">" )
					  ( "HOD Script"
						 "<?xml version=\"1.0\"?>\n<!DOCTYPE HASCRIPT SYSTEM \"HAScript.dtd\">" )
					  ( "XHTML 1.0 Strict"
						 "<?xml version=\"1.0\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"xhtml1-strict.dtd\">" )
					  ( "XHTML 1.0 Transitional"
						 "<?xml version=\"1.0\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"xhtml1-transitional.dtd\">" )
					  ( "XHTML 1.0 Frameset"
						 "<?xml version=\"1.0\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"xhtml1-frameset.dtd\">" )
					  ( "HTML 4.01 Transitional"
						 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" )
					  ( "HTML 4.01 Strict"
						 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">" )
					  ( "HTML 4.01 Frameset"
						 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\">" )
					  ( "IBMIDDoc"
						 "<!DOCTYPE ibmiddoc PUBLIC \"+//ISBN 0-933186::IBM//DTD IBMIDDoc//EN\" [\n]>")
					  ( "DOCBOOK XML 4.1.2"
						 "<?xml version=\"1.0\"?>\n<!DOCTYPE book PUBLIC \"-//OASIS//DTD DocBook XML V4.1.2//EN\" \"http://www.oasis-open.org/docbook/xml/4.0/docbookx.dtd\" [\n]>")
					  )
					 )

			 ;; From Lennart Staflin - re-enabling launch of browser (from original HTML mode)
			 (defun my-psgml-hook ()
				(local-set-key "\C-c\C-b" 'browse-url-of-buffer)
				)

			 (add-hook 'sgml-mode-hook 'my-psgml-hook)

			 ;; Set up Validation support
			 ;; First, for sgml-mode, if you always use the same declaration, uncomment
			 ;; the following line and set the path to your declaration. If you use 
			 ;; more than one SGML declaration, leave it unset and use OpenSP as your
			 ;; validator and include DTDDECL entries in your catalog files.
			 ;; (setq sgml-declaration "<path to your SGML declaration>")

			 (setq sgml-validate-command "onsgmls -s %s %s")

			 ;; For xml-mode, override the default validate command by providing a 
			 ;; mode-hook and setting the SGML declaration to the one  
			 ;; provided with either SP or OpenSP.
			 (defun my-psgml-xml-hook ()
				(setq sgml-validate-command "onsgmls -s %s %s")
				;;  (setq sgml-declaration "d:/SP/pubtext/xml.dcl")
				(setq sgml-declaration "d:/OpenSP/pubtext/xml.dcl")
				)
			 (add-hook 'xml-mode-hook 'my-psgml-xml-hook)


			 )))



;;;////////////////////////////////////////////////////////////////
;;;  gnuserv
;;;////////////////////////////////////////////////////////////////

(if  (eq z-emacs-type 'fsf_emacs) ;; Emacs
   (if (eq system-type 'windows-nt)
		 (if (eq z-location 'home)
			  (progn
				 (require 'gnuserv)
				 (gnuserv-start)
				 (setq gnuserv-frame (selected-frame)
				 )))))


;;;////////////////////////////////////////////////////////////////
;;;  COBOL
;;;////////////////////////////////////////////////////////////////

(if
    (eq z-location 'work)
    (progn
		(autoload 'cobol-mode "cobol")

		(setq auto-mode-alist
				(cons '("\\.cbl\\'" . cobol-mode)
						(cons '("\\.cpy\\'" . cobol-mode)
								auto-mode-alist )))
		(add-hook 'cobol-mode-hook 'ffap-bindings)

		))



;;(setq speedbar-supported-extension-expressions 
;;		(append '(".cbl" ".cpy") speedbar-supported-extension-expressions))


;;;////////////////////////////////////////////////////////////////
;;;  DELPHI
;;;////////////////////////////////////////////////////////////////

(autoload 'delphi-mode "delphi")
(setq auto-mode-alist
       (cons '("\\.\\(pas\\|dpr\\|dpk\\)$" . delphi-mode) auto-mode-alist))

;;(setq speedbar-supported-extension-expressions 
;;		(append '(".pas" ".dpr" ".dpk") speedbar-supported-extension-expressions))

(add-hook 'delphi-mode-hook 'turn-on-font-lock)


;;;////////////////////////////////////////////////////////////////
;;;  C/C++
;;;////////////////////////////////////////////////////////////////

;;;_ + cc-mode

(defconst borland-c-style
  '((c-backslash-column		   . 72)
    (c-basic-offset		   . 4)
    (c-block-comment-prefix	   . "")
    (c-hanging-semi&comma-criteria . nil)
    (c-comment-continuation-stars  . "")
    (c-comment-only-line-offset    . 0)
    (c-electric-pound-behavior	   . (alignleft))
    (c-cleanup-list
     . (defun-close-semi list-close-comma scope-operator))
    (c-hanging-colons-alist
     . ((inher-intro)
	(member-init-intro before)
	(case-label after)
	(label after)
	(access-key after)))
    (c-hanging-braces-alist
     . ((brace-list-open before)
	(brace-list-close before)
	(substatement-open before)
	(substatement-case-open before)
	(else-clause before)
	(defun-open before)
	(defun-close before)
	(class-open before)
	(class-close before)
	(block-open after)
	(block-close before)
	(inline-open after)
	(inline-close before)))
    (c-offsets-alist
     . ((string                . c-lineup-dont-change)
	(c		       . c-lineup-C-comments)
	(defun-open	       . 0)
	(defun-close	       . 0)
	(defun-block-intro     . +)
	(class-open	       . 0)
	(class-close	       . 0)
	(inline-open	       . +)
	(inline-close	       . 0)
	(func-decl-cont        . +)
	(knr-argdecl-intro     . +)
	(knr-argdecl	       . 0)
	(topmost-intro	       . 0)
	(topmost-intro-cont    . 0)
	(member-init-intro     . +)
	(member-init-cont      . 0)
	(inher-intro	       . +)
	(inher-cont	       . c-lineup-multi-inher)
	(block-open	       . 0)
	(block-close	       . 0)
	(brace-list-open       . 0)
	(brace-list-close      . 0)
	(brace-list-intro      . +)
	(brace-list-entry      . 0)
	(brace-entry-open      . 0)
	(statement-block-intro . +)
	(statement-case-intro  . +)
	(statement-case-open   . 0)
	(substatement	       . +)
	(case-label	       . 0)
	(access-label	       . -)
	(label		       . 2)
	(do-while-closure      . 0)
	(else-clause	       . 0)
	(catch-clause	       . 0)
	(comment-intro	       . c-lineup-comment)
	(arglist-intro	       . +)
	(arglist-cont	       . 0)
	(arglist-close	       . +)
	(stream-op	       . c-lineup-streamop)
	(inclass	       . +)
	(cpp-macro	       . -1000)
	(cpp-macro-cont        . c-lineup-dont-change)
	(friend	               . 0)
	(objc-method-intro     . -1000)
	(objc-method-args-cont . c-lineup-ObjC-method-args)
	(objc-method-call-cont . c-lineup-ObjC-method-call)
	(extern-lang-open      . 0)
	(extern-lang-close     . 0)
	(inextern-lang	       . +)
	(namespace-open        . 0)
	(namespace-close       . 0)
	(innamespace	       . +)
;	(template-args-cont    . c-lineup-template-args)
;	(inlambda	       . c-lineup-inexpr-block)
;	(lambda-intro-cont     . +)
;	(inexpr-statement      . 0)
;	(inexpr-class	       . +)
	(arglist-cont-nonempty . c-lineup-arglist)
	(substatement-open     . 0)
	(statement	       . c-lineup-runin-statements)
	(statement-cont        . c-lineup-runin-statements))))
  "Borland C programming style")

(defun my-c-mode-common-hook ()
  (c-add-style "borland" borland-c-style t)
  (c-set-style "borland")

  (turn-on-auto-fill)
  (set (make-local-variable 'fill-nobreak-predicate)
       (function
	(lambda nil
	  (not (eq (get-text-property (point) (quote face))
		   (quote font-lock-comment-face))))))

  (setq c-indent-comments-syntactically-p t
	tab-width 8 indent-tabs-mode t)	; allow the use of tabs

  (define-key c-mode-base-map "\C-m" 'newline-and-indent)

  (set (make-local-variable 'comment-start) "// ")
  (set (make-local-variable 'comment-end) ""))

;;(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)