Newer
Older
sys.etc-skel / .emacs.default
;;;                                         ;;;
; .emacs for GNU Emacs Koeki-u Generic Users  ;
;;;                                         ;;;

;;;
;; Grobal Settings
;;;
;; set 'Do not make back up file'
(setq make-backup-files nil)
(setq-default major-mode 'lisp-interaction-mode)
(setq require-final-newline t)
(setq visible-bell t)
;(setq-default indent-tabs-mode nil)
(setq completion-ignored-extensions
      (cons ".class" completion-ignored-extensions))
(setq debug-on-error t)

(setq my-system-type
      (cond
       ((eq system-type 'ms-dos) (if (boundp 'MULE) 'dos-mule 'demacs))
       ((or (file-exists-p "/386bsd")
	    (file-exists-p "/kernel"))
	(if (boundp 'MULE) 'bsd-mule 'bsd-nemacs))
       (t (if (boundp 'MULE) 'mule 'nemacs))))
(defconst Emacs-18 (string= "18" (substring emacs-version 0 2)))
(defconst Emacs-19 (string= "19" (substring emacs-version 0 2)))
(defconst Emacs-20 (string< "20" (substring emacs-version 0 2)))
(defconst Emacs-21 (string< "21" (substring emacs-version 0 2)))
(defconst Emacs-22 (string< "22" (substring emacs-version 0 2)))
(defconst Emacs-23 (string< "23" (substring emacs-version 0 2)))
(cond
 (Emacs-20
  (set-language-environment "japanese")
  (set-terminal-coding-system 'utf-8)
  (set-buffer-file-coding-system 'utf-8)
  (set-keyboard-coding-system 'utf-8)
  (prefer-coding-system 'utf-8))
 (Emacs-19
  (set-default-process-coding-system *junet* *autoconv*)
  (set-display-coding-system *junet*)))
(setq diff-switches "-uab")

(defvar system-load-path load-path)
(defvar my-load-path "/usr/koeki/share/emacs/lisp")
(or (member my-load-path load-path)
    (setq load-path (cons my-load-path load-path)))

;;;
;; text mode
;;;
(setq text-mode-hook
      '(lambda ()
	 (turn-on-auto-fill)
	 (define-key text-mode-map "\e\C-i" 'lisp-complete-symbol)
	 (or (boundp 'text-mode-hook-running)
	     (let (text-mode-hook-running)
	       (hack-local-variables)))))
(setq-default fill-column 72)

;;;
;; YaTeX version 1.x

;;;
(autoload 'yatex-mode "yatex" "Yet Another LaTeX mode" t)
(setq ;; YaTeX-prefix "\^L"
      ;; YaTeX-fill-prefix "	"
      YaTeX-kanji-code 2
      YaTeX-nervous t
      YaTeX-help-file "~yuuji/src/emacs-lisp/yatex/help/YATEXHLP.jp"
      ;;YaTeX-inhibit-prefix-letter t
      tex-command "platex"
      YaTeX-no-begend-shortcut t
      YaTeX-create-file-prefix-g t
      dviprint-command-format	"dvips %f %t %s.dvi"
      dviprint-from-format	"-p %b"
      dviprint-to-format	"-l %e"
      dvi2-command (concat "xdvi -geo +50+0 -dis " (getenv "DISPLAY")))

;;;
;; yahtml - YaTeX interfaces for html
;;;
(autoload 'yahtml-mode "yahtml" "Yet Another html-mode" t)
(setq yahtml-kanji-code 3
      yahtml-lint-program "htmllint"
      yahtml-www-browser "openurl"
      yahtml-always-/li t
      yahtml-always-/dt t
      yahtml-always-/dd t)

;;;
;; autoload functions for private use
;;;
;(autoload 'insert-header "header" "Set time stamp" t)
(autoload 'status-line-and-col-no-mode "status-line-no" "status" t)
(autoload 'status-line-line-no-mode "status-line-no" "status" t)
(autoload 'status-line-column-no-mode "status-line-no" "status" t)
;--------------- Begins private customization / Functions ----------------
(if (and (boundp 'MULE) (not (fboundp 'line-move)))
    (fset 'line-move 'next-line-internal))

(defun next-line (arg)
  (interactive "p")
  (if (= arg 1)
      (let ((opoint (point)))
	(forward-line 1)
	(if (or (= opoint (point))
		(not (eq (preceding-char) ?\n)))
	    (ding)
	  (goto-char opoint)
	  (line-move arg)))
    (line-move arg))
  nil)

(defun file-complete ()
  (interactive)
  (let*((p (point))
	(s (save-excursion
	     (skip-chars-backward
	      (if (eq system-type 'ms-dos) "^ \t\n;\"\'" "^ \t\n:;\"\'"))
	     (point)))
	(path (buffer-substring s p))
	(dir (or (file-name-directory path) ""))
	(file (file-name-nondirectory path))
	(res (file-name-completion file dir)))
    (cond
     ((eq res t)	(message "Sole completion"))
     ((eq res nil)	(ding) (message "No match!"))
     ((string= file res)
      (message (mapconcat 'princ (file-name-all-completions file dir) " ")))
     (t
      (delete-region p s)
      (insert dir res)))))

;;;
;; Miscellaneous Settings
;;;
;(setq write-file-hooks (cons 'insert-header write-file-hooks))
(setq find-file-hooks (cons 'start-line-col find-file-hooks))
(defun start-line-col ()
  (if (fboundp 'line-number-mode)
      (line-number-mode 1)
    (if (> (buffer-size) 20000)
	(status-line-column-no-mode 1)
      (status-line-and-col-no-mode 1))))
(defvar default-auto-mode-alist auto-mode-alist)
(setq auto-mode-alist
      (append
       (list
	'("\\.[Tt][Ee][Xx]$"	. yatex-mode)
	'("\\.[Ss][Tt][Yy]$"	. yatex-mode)
	'("\\.html?$"		. yahtml-mode)
	'("\\.[chy]$"		. c-mode)
	'("\\.el$"		. emacs-lisp-mode)
	'("_[Ee][Mm][Aa][Cc][Ss]" . emacs-lisp-mode)
	'("\\.emacs\\.*"		. emacs-lisp-mode)
	'("^[Mm]akefile"		. makefile-mode)
	'("\\.tar$"		. tar-mode)
	'("\\.[Dd][Oo][Cc]$"	. text-mode)
	'("\\.[Tt][Ee]?[Xx][Tt]$" . text-mode)
	'("\\.[Zz]$"		. tar-mode)
	'("\\.lsp$"		. lisp-mode)
	'("\\.rb$"		. ruby-mode)
	'("\\.f$"		. fortran-mode)
	'("\\.cob$"		. cobol-mode)
	'("\\.as$"		. actionscript-mode)
	'("\\.pl$"		. cperl-mode)
	'("\\.py$"		. python-mode)
	'("\\.texi[^\\.]*$"	. texinfo-mode)
	'("\\.java"		. java-mode)
	'("\\.js$"		. javascript-mode))
       default-auto-mode-alist))

;;;
;; chmod +x Script
;;;
(if (fboundp 'executable-make-buffer-file-executable-if-script-p)
    (add-hook 'after-save-hook
	      'executable-make-buffer-file-executable-if-script-p))

;;;
;; Windows
;;;
(setq win:frame-title-function
      '(lambda (index)
	 (format "emacs[%d]" index)))
;(setq win:no-raise-at-save t
;      win:new-frame-offset-x 5
;      win:new-frame-offset-y 2
;      win:resumed-frame-offset-x 3
;      win:resumed-frame-offset-y 3
;      win:frame-parameters-to-save-private '(name font))

;;;;
;;; Resume
;;;;
;;(defvar revive:save-variables-global-private nil)

;;;
;; Scroll in place
;;;
(or (featurep 'scroll-in-place) (load "scroll-in-place" t))

;;;
;; font-lock
;;;
(setq frame-background-mode
      (cond
       ((and window-system (x-display-color-p)
	     (if (string-match
		  "on\\|yes\\|true"
		  (or (x-get-resource "reverseVideo" "ReverseVideo") "false"))
		 'dark
	       'light)))
	(t 'mono)))
;(if window-system (require 'hilit19))
(require 'font-lock)
(if (boundp 'global-font-lock-mode)
    (global-font-lock-mode t)
  (font-lock-mode 1))

(custom-set-faces
 '(font-lock-comment-face
   ((((class color) (background dark)) (:foreground "seashell2"))))
 '(font-lock-function-name-face
   ((((class static-color)) (:foreground "blue" :background "yellow"))
    (((type tty)) (:foreground "blue" :background "yellow"))
    (((class color) (background dark))
     (:foreground "yellow" :background "navy"))))
 '(font-lock-variable-name-face
   ((((type tty)) (:foreground "yellow"))
    (((class color) (background dark))
     (:foreground "white" :background "navy"))))
 '(font-lock-string-face
   ((((type tty)) (:foreground "green"))
    (((class color) (background dark)) (:foreground "OliveDrab2"))))
 '(font-lock-doc-string-face
   ((((type tty)) (:foreground "green"))
    (((class color) (background dark)) (:foreground "OliveDrab1")))))

;;;
;; InputMethod
;;;
(defvar my-input-method
  (cond
   ((getenv "INPUT_METHOD")
    (intern (getenv "INPUT_METHOD")))
   ((executable-find "mozc_emacs_helper") 'mozc)
   (t 'canna)))

;;;
;; Canna
;;;
(cond
 ((and (eq my-input-method 'canna)
       window-system)
  (setq canna-use-color t)
  (require 'canna)
  (canna)
  (global-set-key "\C-_" 'canna-undo)
  (if window-system
      (progn
        (define-key global-map [?\C-/] 'canna-undo)
        (define-key global-map [?\C- ] 'canna-set-mark-command)))))
;;;
;; mozc
;;;
(cond
 ((and (eq my-input-method 'mozc)
       (load "mozc" t))
  (setq default-input-method "japanese-mozc"
        ;; mozc-candidate-style 'echo-area        ;; 'overlay is heavy
        mozc-leim-title "((かな))")
  (define-key global-map "\C-o" 'toggle-input-method)
  (define-key global-map (kbd "<zenkaku-hankaku>") 'toggle-input-method)))



;;;
;; X Window System dependent
;;;
;(setq default-frame-alist
;      (cons '(height . 36) default-frame-alist))

;;;
;; mew
;;;
(autoload 'mew "mewsetup" nil t)
(setq mew-init-hook
      '(lambda ()
	 (define-key mew-summary-mode-map "\e\C-m" 'mew-edit-mail-file)
         (define-key mew-draft-mode-map "\C-cy"
           'xcite-yank-cur-msg)))

(setq mew-mail-domain
      (or (getenv "QMAILHOST")
	  (getenv "MAILHOST")
	  (cond
	   ((string-match "^c1\\([0-9][0-9]\\)" user-login-name)
	    (let ((n (substring user-login-name
				(match-beginning 1) (match-end 1))))
	      (concat
	       (cdr (assoc (% (string-to-int n) 4)
			   '((1 . "e") (2 . "f") (3 . "g") (0 . "h"))))
	       ".koeki-u.ac.jp")))
	   ((string-match "^i20\\([0-9][0-9]\\)" user-login-name)
	    "itl.koeki-u.ac.jp"))
	  "e.koeki-u.ac.jp"))

(setq mew-highlight-lines-use nil
      mew-window-use-full t
      mew-replyto-to-list '("From:")
      mew-replyto-to-list '("Reply-to:")
      mew-noreplyto-to-list '("Reply-to:" "From:")
      ;; mew-auto-add-content-type t
      mew-refile-ctrl-multi nil
      mew-mail-domain-list (list mew-mail-domain)
      mew-summary-show-direction 'stop
      mew-mailbox-type (if (string-match "^i20[0-9][0-9]" user-login-name)
			   'mbox
			 'pop)
      mew-theme-file "mew-theme2"
      mew-pop-server "pop.e.koeki-u.ac.jp"
      ;;mew-pop-user (concat user-login-name "@" mew-mail-domain)
      mew-mbox-command "incm"
      ;;mew-fcc nil
      mew-dcc (concat user-login-name "@" mew-mail-domain)
      mew-mbox-command-arg (format "-d %s/maildir" (getenv "HOME")))


(put 'eval-expression 'disabled nil)

(setq xcite:cite-hook
      '(lambda ()
	  (goto-char (point-min))
	   (replace-regexp
	      (concat "^" xcite:current-citation-prefix ">") ">")
	    (goto-char (point-min))
	     (remove-trailing-spaces nil)))

(defun remove-trailing-spaces (squeeze)
  "Remove all trailing spaces of each line after point.
Optional argument SQUEEZE non-nil squeeze the multiple newlines."
  (interactive "P")
  (save-excursion
    (if squeeze
	(while (re-search-forward "\\(\n\n\n+\\)\\|\\(\\s +$\\)" nil t)
	    (if (match-beginning 2)
		      (replace-match "")
	          (forward-char -1)
		      (delete-blank-lines)))
      (replace-regexp "[ \t]+$" ""))))

(defun mew-edit-mail-file ()
  (interactive)
  (save-excursion
    (beginning-of-line)
    (skip-chars-forward " ")
    (let ((n (buffer-substring
	      (point) (progn (skip-chars-forward "0-9") (point))))
	  (folder (substring (buffer-name) 1))
	  (rest (buffer-substring (point) (progn (end-of-line) (point)))))
      (find-file-other-window
       (cond
	((string-match "Guest Book" rest)
	 (save-window-excursion
	   (select-window (next-window))
	   (save-excursion
	     (goto-char (point-min))
	     (re-search-forward "file=\\(.*\\)")
	     (concat "~/http/gb/books/"
		     (buffer-substring (match-beginning 1) (match-end 1))))))))
      )))


;;;
;; gnyognyo
;;;
(setq gnyo:score-file "/usr/koeki/emacs/share/emacs/site-lisp/gnyognyo.score"
      gnyo:mute t)
(autoload 'gnyognyo "gnyognyo" "gnyognyo" t)
(autoload 'gnyo-fight "gnyognyo" "gnyognyo fighting mode" t)

;;;
;; actionscript-mode
;;;
(autoload 'actionscript-mode "actionscript-mode" "actionscript" t nil)

;;;
;; Mercurial
;;;
(defvar hg-mode-map (make-sparse-keymap))
(load "mercurial" t)

;;;
;; javascript mode
;;;
(autoload 'javascript-mode "javascript" "javascript mode" t)
(setq javascript-mode-hook
      '(lambda ()
         (setq javascript-indent-level 2)
         (or (fboundp 'saved-javascript-indent-line)
             (fset 'saved-javascript-indent-line
                   (symbol-function 'javascript-indent-line)))
	 ;; emacs23 can't count column after Kanji characters.
         (defun javascript-indent-line ()
           "Indent the current line as JavaScript source text."
           (save-excursion
             (saved-javascript-indent-line))
	   (skip-chars-forward " \t"))))

;;;
;; global line number and CUA mode
;;;
(cond
 ((fboundp 'display-line-numbers-mode)
  (add-hook 'find-file-hook 'display-line-numbers-mode))
 ((fboundp 'global-linum-mode)
  (global-linum-mode)))
(cond
 ((fboundp 'cua-mode) (cua-mode) (setq cua-enable-cua-keys nil)))

;;;
;; csv-mode (https://elpa.gnu.org/packages/csv-mode.html)
;;;
(load "csv-mode" t)

;;;
;; Ruby mode settings
;;;
(setq ruby-insert-encoding-magic-comment nil)

;;;
;; Global
;;;
(load "term/bobcat")
(if (boundp 'minibuffer-local-filename-completion-map)
    (define-key minibuffer-local-filename-completion-map
      " " 'minibuffer-complete-word))
(if (boundp 'minibuffer-local-must-match-map)
    (define-key minibuffer-local-must-match-map
      " " 'minibuffer-complete-word))
(if (fboundp 'partial-completion-mode) (partial-completion-mode t))
(if (fboundp 'terminal-init-bobcat) (terminal-init-bobcat))

(put 'narrow-to-region 'disabled nil)
(require 'windows)
(win:startup-with-window)
(setq debug-on-error nil)