;;; -*- Mode: Emacs-Lisp;  -*-
;;; File: .emacs
;;; Author: Heinz Schmidt (hws@ICSI.Berkeley.EDU)
;;; Copyright (C) International Computer Science Institute, 1991
;;; Changes: Heinz Schmidt (hws@csis.dit.csiro.AU)
;;; Copyright (C) CSIRO Division of Information Technology, 1992
;;;
;;; COPYRIGHT NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY.
;;; It is subject to the terms of the GNU EMACS GENERAL PUBLIC LICENSE
;;; described in a file COPYING in the GNU EMACS distribution or to be obtained
;;; from Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139
;;;*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;;;* FUNCTION: A sample .emacs file to use with Sather tools.
;;;*           Most of the functions are autoloaded.
;;;*
;;;*           SATHER_HOME environment variable is the pathname of 
;;;*           of the sather directory tree.
;;;* 
;;;* RELATED PACKAGES: sather-mode, language-tools, sky-mouse
;;;* 
;;;* HISTORY: 
;;;* Last edited: Mar  8 15:00 1992 (hws)
;;;*  Feb 20 22:05 1992 (hws): In the meantime integrated improved mouse bindings 
;;;*                      to go with multi-click versions of Epoch.
;;;*  May 30 06:42 1991 (hws): envi var is now called SATHER_HOME consistently.
;;;*  May 30 02:12 1991 (hws): adapt to release directory structure.
;;;* Created: Tue Apr 16 17:23:30 1991 (hws)
;;;*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(provide 'sather-customs)		

;;; SATHER_HOME 

(defvar sather-home-directory (or (getenv "SATHER_HOME") "~/no-SATHER_HOME-set"))

;;; Find out whether this is Epoch.
(defvar running-epoch (and (boundp 'epoch::version) epoch::version))
;;; Allow Emacs to find Sather tools

(setq load-path (cons (expand-file-name
		       "emacs/lisp" sather-home-directory)
		      load-path))

;;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;;; TOOLS and other support files
;;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
(defun all-language-mode-setting ()
  (setq fill-column 76)			;among others this affects the length
  (setq fill-prefix "")			;of separator lines 
  )

;;; optionally activate this in various modes

;(defvar sather-mode-hooks nil)
;(push 'all-language-mode-setting sather-mode-hooks)
;(setq lisp-mode-hook 'all-language-mode-setting)
;(setq emacs-lisp-mode-hook 'all-language-mode-setting)

;;;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
;;; language modes and syntax-oriented mouse 

;;; Allow help to find mouse tutorial
(setq *sky-mouse-directory* 
      (expand-file-name "emacs/lisp" sather-home-directory))

(setq *sky-mouse-tutorial*  (expand-file-name "etc/MOUSE-TUTORIAL" 
					      sather-home-directory))

;;; require always now, the two are independent but work well together.

(require 'language-tools "lang-tools")
(require 'sky-mouse)

;;;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
;;; Option setting. Use M-x edit-options for instance to see what 
;;; options are related to languages and/or Sather.

;(setq doc-file-summary			; this defines the file header 
;  (list nil				; lines
;"* FUNCTION:
;*
;* CLASSES:
;* 
;* RELATED PACKAGES:
;*
;"))

;;;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
;;; Abbreviations: you can do mode specific abbreviation to get templates
;;; look at this if you do not have own abbreviations and want them:
;;;
;;; (read-abbrev-file "~/.abbrev_defs")

;;;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
;;; Sather mode 

(autoload 'sather-mode "sather" "Sather mode" t nil)
(if (not (assoc "\\.sa$" auto-mode-alist))
	  (setq auto-mode-alist (append
		       (list (cons "\\.sa$" 'sather-mode))
		       auto-mode-alist)))

;;; Sather C interface code
(if (not (assoc "\\.sac$" auto-mode-alist))
	  (setq auto-mode-alist (append
		       (list (cons "\\.sac$" 'sather-mode))
		       auto-mode-alist)))

;;;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
;;; SAC 


(autoload 'sac-convert-buffer "sac" 
  "Convert the Sather C interface definitions in the current buffer. The
result consists of three parts, Sather code, C code and Sather c_macros. 
These pieces of code are inserted into the buffers named like the current 
buffer but ending in .sa, .c and .macros respectively.
With a prefix argument, the command prompts for the file name."
	  t)				;interactive

;;; SATHER VARIABLES, see C-h v for current value and doc.
;;  (defvar formal-comment-start "-- -")
;;  (defvar sather-separator-list '(":=" "=" "<" ">" "<=" ">=" "/=" "*" "+" "-" "/"))
;;  (defvar sather-leader-list nil)
;;  (defvar sather-trailer-list '(";" ":"))


;;; ADDITIONAL COMMANDS
;;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
;(define-key help-map "a" 'apropos) ;; just an example to recall how we do it

;;; Scroll line wise: c-m-Previous, c-m-Next

(define-key esc-map "\C-n" '(lambda (n) "scroll up in place ARG lines"
				 (interactive "p") (next-line n) (scroll-up n)))

(define-key esc-map "\C-p" '(lambda (n) "scroll down in place ARG lines"
     (interactive "p") (previous-line n) (scroll-down n)))

;;;;; CONTROL-X  -----------

(define-key ctl-x-map "\C-y" 'shrink-window)
(define-key ctl-x-map "\C-^" 'enlarge-window)

;; make sure fill column is always >=40 except user chooses a number
;; explicitly

(define-key ctl-x-map "f" '(lambda (ARG) (interactive "P")
  (cond ((integerp ARG) (set-fill-column ARG))
	((> (current-column) 40) (set-fill-column (current-column)))
	(t (message "fill column is %d" fill-column)))))

;;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;;; Temporary Fixes
;;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
;; fix a bug in current Epoch the does not do M-C-f on 'default: .... '

(modify-syntax-entry ?: "." c-mode-syntax-table) 


;;; from Ken Laprades epoch-local.el

(when (or running-epoch running-x-mouse) ;we are under x
      (put 'suspend-emacs 'disabled
	   "Suspending a program running in an X window is silly
and you would not be able to start it again.  Just switch windows instead.\n")
      (setq suspend-hook 
	    '(lambda () 
	       (error "Suspending an emacs running under X makes no sense")))
      (substitute-key-definition 'suspend-emacs nil global-map)
      (substitute-key-definition 'suspend-emacs nil esc-map)
      (substitute-key-definition 'suspend-emacs nil ctl-x-map)
      )


;;;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
;;; Mouse help
;;;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
(when (or running-epoch running-x-mouse) ;we are under x

;;;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
;;; Mouse customization
;;;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

      (setq thing-multi-click-boundary-alist
	    '((?w thing-symbol thing-get-line thing-sentence thing-paragraph) 
	      (?_ thing-symbol thing-get-line thing-sentence thing-paragraph)
	      (?. thing-symbol thing-get-line thing-sentence thing-paragraph)
	      (?  thing-get-line thing-sentence thing-paragraph)
	      (?\( thing-backward-up thing-backward-up thing-backward-up thing-backward-up 
		   thing-backward-up thing-backward-up thing-backward-up thing-backward-up 
		   thing-backward-up thing-backward-up)
	      (?\) thing-backward-up thing-backward-up thing-backward-up thing-backward-up 
		   thing-backward-up thing-backward-up thing-backward-up thing-backward-up 
		   thing-backward-up thing-backward-up)))

      (defun mouse-end-drag-point-select (arg) 
	"Ends dragging (cf.  mouse-end-drag-point) and selects the thing under the
mouse, if no selection was dragged.  For programming hints cf. mouse-set-point."
	(mouse-end-drag-point arg) 
	(if multi-click-hint (mouse-mark-thing arg)))

      (defmouse :global  "Left" 'mouse-drag-point 'mouse-end-drag-point-select)

      (defmouse :global "C-M-S-Left" 'mouse-set-point 'help-with-mouse-summary)

      (defun help-with-mouse-summary (ignore)
	(with-output-to-temp-buffer "*Mouse Help*"
	  (princ
	   "C-h Z -- Mouse Tutorial
C-h z -- Play Mouse, <Return> to exit (press button and modifiers to see doc)

GLOBAL MOUSE FUNCTIONS:
------+--------------------------------------------------------------+
Mod   |  Left 		     Middle		 Right         Window manager
------+--------------------------------------------------------------+
--    |  Select		     Extend		 Paste	  	  olwm
--    |  Select		     Paste		 Extend		  not olwm
      |                                                              |
S     |  Mark Thing	     Save/Kill/Yank	   --                |  Universal
C     |  Exit minibuffer     Kill to point       Toggle Scroll Mode   > Text/Lang.
M     |  Toggle Focus        Yank to point       Warp to point       |  
C-M   |  Mark Thing          Yank to point       Fill or indent      |
------+--------------------------------------------------------------+
      |                                                              |
      |  Exec kbd macro      Run Point fn        Run Region fn       |  Text
      |                                                              |
M-S   |  Edit /              Describe /          Parents /            > Sather
      |  Visit               Show                Leave, Up           |  SDB
      |                                                              |
      |        -- under epoch multi-click for prefix arg --          |
------+--------------------------------------------------------------+
C-M-S |  This Summary        Mouse Tutorial      Mouse Tutorial      |
------+--------------------------------------------------------------+



MINOR MOUSE SCROLLING MODE, regular invocation by C-Right.
This will vanish when Epoch or Emacs 19 has scrollbars.
------+--------------------------------------------------------------+
Mod   |           Left              Middle             Right         |
------+--------------------------------------------------------------+
  -   |        Line to top        Drag Scroll     Line to bottom     |
  S   |          Page up          Page percent       Page down       |
  M   |          All up              Help            All down        |
      |                                                              |
 M-S  |           Help               Help              Help          |
  C   |       End scrolling     End scrolling     End scrolling      |
------+--------------------------------------------------------------+
")))
      )

(when running-epoch
      (cond ((file-exists-p (expand-file-name "~/.epoch"))
	     (load (expand-file-name "~/.epoch")))
	    (t (load (expand-file-name "etc/.epoch" sather-home-directory)))))

      








