;; file: $ISIP_IFC/login/editor_emacs_modes.el
;; version: $Id: editor_emacs_modes.el 9614 2004-07-03 18:24:30Z picone $
;;
;;
;; this file sets various variables and modes
;;

;;---------------------------------------------------------------------------;;
;;									     ;;
;; html related settings					     	     ;;
;;									     ;;
;;---------------------------------------------------------------------------;;
(autoload 'html-helper-mode "html-helper-mode" "HTML major mode." t)
(defvar html-helper-address-string (concat "www@" (getenv "ISIP_DOMAIN"))
  "*The default author string of each file.")

;;---------------------------------------------------------------------------;;
;;									     ;;
;; assist in moderation of mailing lists
;;									     ;;
;;---------------------------------------------------------------------------;;

(setq moderator-password-file 
      (substitute-in-file-name "$HOME/login/moderator_password.text"))

(defun mail-approve-message ()
  "insert the approved password for the given message"
  (interactive)
  (save-excursion
    (beginning-of-buffer)
    (if (search-forward "--text follows this line--" (point-max) t)
	
	;; then
	(progn
	(next-line 1)
	(beginning-of-line)
	(insert-file moderator-password-file)))))

;;---------------------------------------------------------------------------;;
;;									     ;;
;; backup/journal/auto-save related settings				     ;;
;;									     ;;
;;---------------------------------------------------------------------------;;

;; turn off backup/copy modes
;;
(setq make-backup-files nil)
;;(setq backup-by-copying nil)
;;(setq backup-by-copying-when-linked t)
;;(setq backup-by-copying-when-mismatch t)

;; turn off auto-save modes
;;
(setq auto-save-interval 0)
(setq auto-save-default nil)

;; turn on auto-save/backups if requested
;;
(if (and
     (getenv "ISIP_EDITOR_BACKUP_INTERVAL")
     (> (string-to-int (getenv "ISIP_EDITOR_BACKUP_INTERVAL")) 0))
    (progn
      (setq make-backup-files t)
      (setq backup-by-copying nil)
      (setq auto-save-default t)
      (setq auto-save-interval
	    (string-to-int (getenv "ISIP_EDITOR_BACKUP_INTERVAL")))
      (setq delete-auto-save-files t)))

;;---------------------------------------------------------------------------;;
;;									     ;;
;; misc. tools requiring setup						     ;;
;;									     ;;
;;---------------------------------------------------------------------------;;

;; calculator
;;
(autoload 'calc "calc" "calculator mode" t nil)
(autoload 'calc-extensions "calc-ext" nil nil nil)
(autoload 'quick-calc "calc" "quick calculator" t nil)
(autoload 'calc-grab-region "calc-ext" nil t nil)
(autoload 'defmath "calc-ext" nil t t)

(require 'iswitchb)
(iswitchb-default-keybindings)

;;---------------------------------------------------------------------------;;
;;									     ;;
;; misc. modes and interactive settings					     ;;
;;									     ;;
;;---------------------------------------------------------------------------;;

;; turn off the annoying suggest key bindings mode
;;
(setq suggest-key-bindings nil)

;; set default mode for new buffers
;;
(setq default-major-mode 'fundamental-mode)

;; turn off message logging
;;
(setq message-log-max 0)

;; activate linenumber mode
;;
(setq line-number-mode t)

;; prompt for terminating files with linefeed
;;
(setq require-final-newline 'ask)

;; set the default printer command
;;
(setq lpr-command "lp")
(setq lpr-switches '("-o nobanner" "-m"))

;; case:
;;  these statements make the downcase/upcase commands less intelligent
;;  by forcing them to ignore case. this is a compromise between the needs
;;  of programmers and text processors.
;;
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)

;;---------------------------------------------------------------------------;;
;;									     ;;
;; c++ mode customization    					             ;;
;;									     ;;
;;---------------------------------------------------------------------------;;
(add-hook 'c++-mode-hook
	  '(lambda () (local-set-key "\r" 'newline-and-indent)))
(add-hook 'c++-mode-hook
	  '(lambda () (local-set-key [C-tab] 'tab-to-tab-stop)))
(add-hook 'c++-mode-hook
	  '(lambda () (local-set-key "\C-x!" 'isip-c++-insert-error-handler)))

;; add the extra types to c++ mode for font-lock
;;
(setq c++-font-lock-extra-types 
      '("boolean" "llong" "byte" "unichar" "ubyte" "ushort" "ulong" "ullong"
	"slong" "sllong" "sint" "wchar_t"
	"complexfloat" "complexdouble" "complexlong" "size_t"
	"byte8" "uint16" "uint32" "uint64" "int16" "int32" "int64" 
	"float32" "float64"))

;; define our c++ syntactic guidelines for font-lock
;;
(font-lock-add-keywords 
 'c++-mode
 '(
   ;; mark anything with all lower-case letters and ending with _a or _d
   ;; as a variable (class data or arguments)
   ;;
   ("\\<\\([a-z0-9_]+_[ad]\\)\\>" 1 font-lock-variable-name-face)

   ;; define our general function name rule -- the name should start
   ;; with a lower-case character, have mixed-case characters in the
   ;; name, and contain no underscores
   ;;
   ("\\<\\([a-z][a-z]+[A-Z][a-zA-Z]+\\)\\>" 1 font-lock-function-name-face)

   ;; define some common single-word function names that won't be
   ;; picked up by our general capitalization rule
   ;;
   ("\\<\\(name\\|diagnose\\|debug\\|assign\\|read\\|write\\|eq\\|load\\|handle\\|open\\|close\\|get\\|clear\\|find\\|put\\|length\\|concat\\|insert\\|lt\\|gt\\|le\\|ge\\|ne\\|rand\\|hash\\|init\\|reset\\)\\>" 1 font-lock-function-name-face)
   
   ;; define our general type name/class name rule -- the name should
   ;; start with a capital letter but have some lower-case characters
   ;; in it
   ;;
   ("\\<\\([A-Z]+[a-z]+[a-zA-Z]+\\)\\>" 1 font-lock-type-face)

   ;; define our general constant rule -- all upper case characters
   ;; and allow underscores and numbers after the first upper case
   ;; character. it also allows the name to start with an arbitrary
   ;; number of underscores as long as there are no lower-case
   ;; characters
   ;;
   ("\\<\\(_*[A-Z][A-Z0-9_]+\\)\\>" 1 font-lock-constant-face)))

;;---------------------------------------------------------------------------;;
;;									     ;;
;; other code development related settings				     ;;
;;									     ;;
;;---------------------------------------------------------------------------;;

;; setup the jde java tools for compiling and debugging java files
;;
(add-hook 'java-mode-hook 
	  '(lambda () (require 'jde)))

;; make .html files automatically use html-helper mode
;;
(setq auto-mode-alist
      (cons (cons "\\.html$" 'html-helper-mode) auto-mode-alist))

;; make .h files automatically use c++ mode
;;
(setq auto-mode-alist
      (cons (cons "\\.h$" 'c++-mode) auto-mode-alist))
(setq c++-untame-characters nil)

;; make .sh files automatically use the shell mode
;;
(setq auto-mode-alist
      (cons (cons "\\.sh$" 'sh-mode) auto-mode-alist))

;; make .pl files automatically use the perl mode
;;
(setq auto-mode-alist
      (cons (cons "\\.pl$" 'perl-mode) auto-mode-alist))

;; set the default executable line for scripting languages
;;
;; We specifically quote the regular expresions for the file names
;; (rather than extracting it from the auto-mode-alist) because you
;; want the magic string added to only the .pl files, not the .pm
;; files (which are also opened in perl mode), etc.
;;
(add-hook 'perl-mode-hook 
	  (function 
	   (lambda ()
	     (if (string-match "\\.[Pp][Ll]\\'" (or (buffer-file-name) ""))
		 (executable-set-magic "/usr/local/bin/perl" "" t t)))))

;; disable this -- it breaks running wish easily
;;
;;(add-hook 'tcl-mode-hook 
;;	  (function 
;;	   (lambda ()
;;	     (if (string-match "\\.[Tt][Cc][Ll]\\'" (or (buffer-file-name) ""))
;;		 (executable-set-magic "/usr/local/bin/wish" "-f" t t)))))

;; disable this - it breaks bash files
;;
;;(add-hook 'sh-mode-hook 
;;	  (function 
;;	   (lambda ()
;;	     (if (string-match "\\.[Ss][Hh]\\'" (or (buffer-file-name) ""))
;;		 (executable-set-magic "/bin/sh" "" t t)))))

;; set the default compile command
;;
(setq compile-command "$ISIP_MAKE")

;; allow error messages to not be left justified
;;
(add-hook 'c++-mode-hook
	  '(lambda () 
	     (setq compilation-error-regexp-alist
		   (cons (list "\\ *\\([a-zA-Z][-a-zA-Z_0-9]+.cc: ?\\)?\\([a-zA-Z]?:?[^:( 	\n]*[^:( 	\n0-9][^:( 	\n]*\\)[:(][ 	]*\\([0-9]+\\)\\([) 	]\\|:\\(\\([0-9]+:\\)\\|[0-9]*[^:0-9]\\)\\)" 2 3 6) nil))))

;;---------------------------------------------------------------------------;;
;;									     ;;
;; special foreign language modes			     		     ;;
;;									     ;;
;;---------------------------------------------------------------------------;;
(if (boundp 'MULE) (setq jserver-list (list (getenv "ISIP_HOST"))))
(if (boundp 'MULE) (set-default-file-coding-system *euc-japan*))
(if (boundp 'MULE) (load-file "/common/mule/lisp/quail/latin.el"))

;;
;; end of file
