.emacs

A multilingual and multiplatform configuration file for Emacs along with some extra goodies packed in the attachment.

;;; .emacs --- multilingual and multiplatform dotemacs

;; Copyright (C) 2002  Free Software Foundation, Inc.

;; Author: Alexander Mikhailian 
;; Keywords: convenience, local

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;;

;;; Code:

(defmacro GNUEmacs (&rest x)
  (list
   'if
   (string-match "GNU Emacs" (prin1-to-string (version)))
   (cons 'progn x)))
(defmacro GNUEmacs20 (&rest x)
  (list
   'if
   (string-match "GNU Emacs 20" (prin1-to-string (version)))
   (cons 'progn x)))
(defmacro GNUEmacs21 (&rest x)
  (list
   'if (string-match "GNU Emacs 21" (prin1-to-string (version)))
   (cons 'progn x)))
(defmacro XEmacs (&rest x)
  (list
   'if (string-match "XEmacs 21" (prin1-to-string (version)))
   (cons 'progn x)))
(defmacro GNULinux (&rest x)
  (list
   'if (string-match "linux" (prin1-to-string system-type))
   (cons 'progn x)))
(defmacro Windows (&rest x)
  (list
   'if (string-match "windows" (prin1-to-string system-type))
   (cons 'progn x)))
(defmacro Solaris (&rest x)
  (list
   'if (string-match "usg-unix-v" (prin1-to-string system-type))
   (cons 'progn x)))
(defmacro XWindow (&rest x)
  (list
   'if (string-match "x" (prin1-to-string window-system))
   (cons 'progn x)))

;;;;;;;;;;;;;;;;; Load Paths                        ;;;;;;;;;;;;;;;;;;;

(GNUEmacs
 (setq
  load-path (cons "~/emacs/misc" load-path))
 (setq
  load-path (cons "~/emacs/Mule\-UCS\-0\.83/lisp" load-path))
 (setq
  load-path (cons "~/emacs/html-helper-mode" load-path))
 (setq
  load-path (cons "~/emacs/ps-print" load-path))
 (setq
  load-path (cons "~/emacs/xslide" load-path)))
;; GNUEmacs

;;;;;;;;;;;;;;;;; Charsets Customization            ;;;;;;;;;;;;;;;;;;;

;; Defining additional coding systems

;; Russian DOS
(defvar cp866-decode-table
  [
        255 240 nil nil 242 nil nil 244 nil nil nil nil nil nil 246 nil
        128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
        144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
        160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
        224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
        252 241 nil nil 243 nil nil 245 nil nil nil nil nil nil 247 nil]
  "Table for converting ISO-8859-5 characters into codepage 866 glyphs.")
(setplist 'cp866-decode-table
          '(charset cyrillic-iso8859-5 language "Cyrillic-ISO" offset 160))

;; Greek DOS
(defvar cp737-decode-table
  [
        255 nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
        248 nil 253 nil nil nil 234 250 235 236 237 nil 238 nil 239 240
        nil 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
        143 144 nil 145 146 147 148 149 150 151 244 245 225 226 227 229
        nil 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
        167 168 170 169 171 172 173 174 175 224 228 232 230 231 232 nil]
        "Table for converting ISO-8859-7 characters into codepage 737 glyphs.")
(setplist 'cp737-decode-table
          '(charset greek-iso8859-7 language "Greek" offset 160))

; setting coding systems
(GNUEmacs
 (codepage-setup 437) ;; ascii
 (codepage-setup 737) ;; Greek old
 (codepage-setup 869) ;; Greek old
 (codepage-setup 851) ;; Greek odd
 (codepage-setup 866) ;; Russian DOS
 (codepage-setup 1251)
 (set-keyboard-coding-system nil)
 (set-terminal-coding-system 'iso-8859-5)
 (prefer-coding-system 'iso-8859-5)
 (setq default-buffer-file-coding-system 'iso-2022-8bit-ss2)
; (set-selection-coding-system 'utf-8)
; (set-clipboard-coding-system 'utf-8)
 (define-coding-system-alias 'windows-1251 'cp1251)
 (define-coding-system-alias 'microsoft-1251 'cp1251)
 (define-coding-system-alias 'microsoft-cp1251 'cp1251)
 (define-coding-system-alias 'windows-cp1251 'cp1251)
 (define-coding-system-alias 'koi8-u 'cyrillic-koi8)
 (define-coding-system-alias 'KOI8-R 'cyrillic-koi8)
 (modify-coding-system-alist 'file "\.*" 'iso-8859-5)
 (modify-coding-system-alist 'file "\\.el$" 'iso-2022-7bit))

;; Do not expand unprintable characters to their octal values
(standard-display-8bit 128 255)

;; PC-like bindings
(GNUEmacs
 (pc-bindings-mode)
 (pc-selection-mode))

(condition-case err
    (require 'belarusian)
  (error
   (message "Cannot load belaruisan input method %s" (cdr err))))

(condition-case err
    (require 'russian)
  (error
   (message "Cannot load russian input method %s" (cdr err))))

(condition-case err
    (require 'php-mode)
  (error
   (message "Cannot load php-mode %s" (cdr err))))

(condition-case err
    (require 'htmlize)
  (error
   (message "Cannot load htmlize %s" (cdr err))))

;; Nice buffer handling when many files are open
(condition-case err
    (require 'msb)
  (error
   (message "Cannot load msb %s" (cdr err))))

;; Nice buffer handling when many files are open
(condition-case err
(require 'dictionary)
  (error
   (message "Cannot load dictionary %s" (cdr err))))

(condition-case err
(require 'blank-mode)
  (error
   (message "Cannot load blank-mode %s" (cdr err))))

(condition-case err
(require 'python-mode)
  (error
   (message "Cannot load python-mode %s" (cdr err))))

(condition-case err
(require 'css-mode)
  (error
   (message "Cannot load css-mode %s" (cdr err))))

(condition-case err
(require 'jde)
  (error
   (message "Cannot load jde-mode %s" (cdr err))))

(condition-case err
    (require 'ansi-color)
  (error
   (message "Cannot load ansi-color %s" (cdr err))))
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)

(condition-case err
    (require 'whitespace)
  (error
   (message "Cannot load whitespace nuke %s" (cdr err))))
(autoload 'nuke-trailing-whitespace "whitespace" nil t)

;;Run shashdot headline fetcher
(condition-case err
    (require 'slashdot)
  (error
   (message "Cannot load slashdot headline fetcher %s" (cdr err))))
;;(setq slashdot-proxy "proxy"
;; slashdot-proxyport 80)

(autoload 'xrdb-mode "xrdb-mode" nil t)
(autoload 'fetchmail-mode "fetchmail-mode" nil t)
(autoload 'dtd-mode "tdtd" "Major mode for SGML and XML DTDs." t)

;; (condition-case err
;;     (and
;;     (require 'ebnf2ps)
;;     (setq
;;      ebnf-syntax 'yacc ;; put as much on one sheet as possible
;;      ps-n-up-printing 2 ;; print on 2 pages
;;      ebnf-horizontal-orientation t))
;;   (error
;;    (message "Cannot load ebnf2ps converter %s" (cdr err))))

;;(condition-case err
;;    (and(require 'table)
;;        (add-hook 'text-mode-hook 'table-recognize))
;;  (error
;;   (message "Cannot load table  %s" (cdr err))))

;;(condition-case err
;;    (and(require 'color-theme)
;;        (color-theme-gnome2))
;;  (error
;;   (message "Cannot load color-teme %s" (cdr err))))

;; TODO ;;
;; Tell emacs to save backups in the global backups directory...
;(defun make-backup-file-name(file)
;  (concat "~/backups/" (file-name-nondirectory file) "~"))


(condition-case err
    (require 'backup-dir)
  (error
   (message "Cannot load backup-dir %s" (cdr err))))

 (setq bkup-backup-directory-info
       '((
          "/home/lowry/.*"
          "~/.backups/"
          ok-create full-path prepend-name)))

;;;;;;;;;;;;;;;;; Font-Lock Settings                ;;;;;;;;;;;;;;;;;;;

(cond
 ((fboundp 'global-font-lock-mode)
  (global-font-lock-mode t)
  (setq
   ;; fontify yet unfontified areas after idle time (secs)
   lazy-lock-stealth-time 2
   ;; don't fontify if buf is greater than this num. of chars
   lazy-lock-minimum-size 20000
   ;; fontify if scrolling into unfontified area
   lazy-lock-defer-on-scrolling t
   ;; perform on-the-fly fontification as you type new chars
   lazy-lock-defer-on-the-fly nil
   ;; perform deferred fontification on modified+subseq. lines
   lazy-lock-defer-contextually t
   lazy-lock-stealth-verbose t
   ;; instead of the default fast-lock-mode
   font-lock-support-mode 'lazy-lock-mode
   font-lock-maximum-decoration t)))

;;  Highlight selection
(GNUEmacs
 (transient-mark-mode t))

;; Highlight matching parentheses
(GNUEmacs
 (show-paren-mode t))

;;Changing .h to use automatic C++ formatting (instead of standard C)
(setq auto-mode-alist
      (append
       '(
         ("\\.h$"             . c++-mode)
         ("\\.dps$"           . pascal-mode)
         ("\\.l$"             . c-mode)
         ("\\.y$"             . c-mode)
         ("\\.py$"            . python-mode)
         ("\\.css$"           . css-mode)
         ("\\.Xdefaults$"     . xrdb-mode)
         ("\\.Xenvironment$"  . xrdb-mode)
         ("\\.Xresources$"    . xrdb-mode)
         ("*.\\.ad$"          . xrdb-mode)
         ("\\.fetchmailrc$"   . fetchmail-mode)
         ("\\.xsl$"           . xml-mode)
         ("\\.tei$"           . xml-mode)
         ("\\.php$"           . php-mode)
         ("\\.dcl$"           . dtd-mode)
         ("\\.dec$"           . dtd-mode)
         ("\\.dtd$"           . dtd-mode)
         ("\\.ele$"           . dtd-mode)
         ("\\.ent$"           . dtd-mode)
         ("\\.mod$"           . dtd-mode)
         ) auto-mode-alist))

;;;;;;;;;;;;;;;;; Interface and Key Bindings        ;;;;;;;;;;;;;;;;;;;

;; Display pictures in GNU Emacs 21
(GNUEmacs21
 (auto-image-file-mode 1)
 (tool-bar-mode nil)
 (toggle-truncate-lines)
 (setq
  tool-bar-button-margin 0
  tool-bar-button-relief 1
  tool-bar-originally-present nil))

;; enable C-x C-l and C-x C-u
(put 'downcase-region 'disabled nil)
(put 'upcase-region   'disabled nil)

;; automatic resizing of the minibuffer
(resize-minibuffer-mode 1)

;; make searches case-INsensitive
(setq-default case-fold-search t)

 ; do not use tabs for indentation
(setq-default indent-tabs-mode nil)

;; Stop ^M's from displaying in system shell window
(add-hook 'comint-output-filter-functions 'shell-strip-ctrl-m nil t)

;; This tells emacs to show the column number in each modeline.
(column-number-mode 1)

;; Wrap lines while typing in text mode
;; (add-hook 'text-mode-hook 'auto-fill-mode t)

;; Don't wrap long lines when viewing
(GNUEmacs
 (hscroll-global-mode t))
;; (hscroll-global-mode nil)

(setq
 ;; exec eval: statements in "Local Variables"
 enable-local-eval t
 ;; remove the startup message
 inhibit-startup-message t
 ;; don't add new lines when scrolling down
 next-line-add-newlines nil
 ;; make sure file ends with NEWLINE
 require-final-newline "yes"
 ;; delete excess backup versions
 delete-old-versions t
 ;; do not make backup files
 ;; make-backup-files nil
 ;; do only one line scrolling
 scroll-step 1
 ;; return to same line on a scroll back
 scroll-preserve-screen-position t
 ;; setting the defualt tabulation
 default-tab-width 2
 ;; dispaly time in the modeline
 display-time-24hr-format t
 display-time-day-and-date t
 ;; customize the calendar
 european-calendar-style t
 calendar-week-start-day 1
 calendar-latitude 51.05
 calendar-longitude -2.39
 calendar-location-name "Ieper"
 ;; enable the debug
 ;; debug-on-error t
 ;; debug-on-quit t
 ;; paste at cursor NOT mouse pointer position
 mouse-yank-at-point t
 ;; auto-save-timeout 1800
 require-final-newline t
 search-highlight t
 ;; put point at the end of the output window
 compilation-scroll-output t
 ;; save all modified buffers without asking
 compilation-ask-about-save nil
 ;; do not ask for the compile command
 compilation-read-command nil
 compilation-window-height 7
 ;; work better but slower
 apropos-do-all t
 ;; autosave every 512 keyboard inputs
 auto-save-interval 512
 ;; limit the number of newest versions
 kept-new-versions 5
 ;; limit the number of oldest versions
 kept-old-versions 5
 auto-save-list-file-prefix "~/.backups/save-"
 tex-dvi-view-command "xdvi *")

;; Shut off message buffer.
;; (setq message-log-max nil)
;; (kill-buffer "*Messages*")

;; Make all "yes or no" prompts show "y or n" instead
(fset 'yes-or-no-p 'y-or-n-p)

;; set autocompletion on
;;(dynamic-completion-mode) ;;!!! slows startup and breaks re-search-forward/re-search-backward

;; We want compression support, entering tgz files etc.. :)
(auto-compression-mode t) ;; !!! slows startup !!!

;; Uncomment if using abbreviations
(abbrev-mode t)

;; This turns off the GUI menus in X.
;; (menu-bar-mode nil))

;; Shut off annoying beep
;; Works only on Windows?
(Windows
 (set-message-beep 'silent))

;;;;;;;;;;;;;;;;; Frame Title Bar Formatting        ;;;;;;;;;;;;;;;;;;;
(setq-default
 frame-title-format
 (list
  '((buffer-file-name
     " %f"
     (dired-directory
      dired-directory
      (revert-buffer-function
       " %b"
       ("%b - Dir:  " default-directory)))))))

(setq-default
 icon-title-format
 (list
  '((buffer-file-name
     " %f"
     (dired-directory
      dired-directory
      (revert-buffer-function
       " %b"
       ("%b - Dir:  " default-directory)))))))

;;;;;;;;;;;;;;;;; W3 Customization                  ;;;;;;;;;;;;;;;;;;;
(custom-set-variables
 '(url-be-asynchronous t)
 '(url-external-retrieval-program "wget")
 '(url-mail-command (quote mail)))
(eval-after-load "mule-sysdp"
  '(and
    (push '("windows-1251" . cp1251) w3-mime-charset-coding-alist)
    (push '("utf-8" . utf-8) w3-mime-charset-coding-alist)))

(setq w3-default-homepage
      "http://bellinux.sourceforge.net")

;;;;;;;;;;;;;;;;; Mail Customization                ;;;;;;;;;;;;;;;;;;;
(setq user-name "mikhailian"
      user-full-name "Alexander Mikhailian"
      user-mail-address "mikhailian @ altern.org"
     ;; mail-default-headers "Content-Type: text/plain; charset=iso-8859-5\n"
     ;; assign a prefix for each quoted line in email replies and forwards
      mail-yank-prefix ">")

; copy all outgoing messages to a file
;;(setq mail-archive-file-name "~/nsmail/Sent")

; specify location of primary mail folder
;;(setq rmail-file-name "~/mail/RMAIL")

; automatically append .signature to end of emails
(setq mail-signature t)

;;;;;;;;;;;;;;;;; Dired Customization               ;;;;;;;;;;;;;;;;;;;
(defadvice dired-advertised-find-file (around dired-subst-directory activate)
  "Replace current buffer if file is a directory."
  (interactive)
  (let ((orig (current-buffer))
        (filename (dired-get-filename)))
    ad-do-it
    (when (and (file-directory-p filename)
               (not (eq (current-buffer) orig)))
      (kill-buffer orig))))


;; Inserts the user name
(defun insert-userid ()
  "Insert the my full name and address"
  (interactive)
        (insert user-full-name " "))


;; Inserts the date in the format
(defun insert-date ()
  "Insert date at point."
  (interactive)
  (insert (format-time-string "%Y.%m.%d %H:%M")))

;;;;;;;;;;;;;;;;; Printing                          ;;;;;;;;;;;;;;;;;;;

;;
(setq ps-n-up-printing 1   ;; print one page on 1 sheet of paper
      ps-print-header nil) ;; remove that ugly header

;;;;;;;;;;;;;;;;; Lisp Customization                ;;;;;;;;;;;;;;;;;;;


;(defun my-lisp()
;  "start up CLISP interactive windows in bottom "
;  (interactive)
;  (Windows
;   (setq inferior-lisp-program "D:/clisp/lisp.exe -M D:/clisp/lispinit.mem"))
;  (GNULinux
;   (setq
;    inferior-lisp-program "/usr/bin/clisp")) ;; lisp binary
;  (split-window-vertically)
;  (other-window 1)
;  (shrink-window 6)
;  (run-lisp "lisp")
;)

;(add-hook 'lisp-mode-hook 'my-lisp)


;;;;;;;;;;;;;;;;; SGML Customization                ;;;;;;;;;;;;;;;;;;;
(defun my-sgml()
  "PSGML Manual in Russian: http://xtalk.kak-sam.to/SGML/em.html"
   (interactive)

   (setq sgml-omittag-transparent t           ; OMITTAG not allowed
         sgml-omittag nil
         sgml-set-face t                      ; face highlighting
         sgml-shorttag nil
         sgml-minimize-attributes nil
         sgml-namecase-general t
         sgml-always-quote-attributes t
         sgml-auto-activate-dtd t
         sgml-indent-step 2
         sgml-indent-data t
                                        ; insert opening and closing tags
         sgml-balanced-tag-edit t
                                        ;do not warn while editing
                                        ;XML files without DTD
         sgml-warn-about-undefined-entities nil
                                        ;do not warn about elements
                                        ;undefined in DTD
         sgml-warn-about-undefined-elements nil
                                        ; insert required
                                        ; child elements
         sgml-auto-insert-required-elements nil)
   ;; (local-set-key [return] 'reindent-then-newline-and-indent)

   ;; SGML markup faces
   (make-face 'sgml-comment-face)
   (make-face 'sgml-doctype-face)
   (make-face 'sgml-end-tag-face)
   (make-face 'sgml-entity-face)
   (make-face 'sgml-ignored-face)
   (make-face 'sgml-ms-end-face)
   (make-face 'sgml-ms-start-face)
   (make-face 'sgml-pi-face)
   (make-face 'sgml-sgml-face)
   (make-face 'sgml-short-ref-face)
   (make-face 'sgml-start-tag-face)

   (set-face-foreground 'sgml-comment-face "gray")
   (set-face-italic-p   'sgml-comment-face t)
   (set-face-foreground 'sgml-doctype-face "white")
   (set-face-background 'sgml-doctype-face "dodger blue")
   (set-face-bold-p   'sgml-doctype-face t)
   (set-face-foreground 'sgml-end-tag-face "dodger blue")
   ;; (set-face-bold-p     'sgml-end-tag-face 'nil)
   (set-face-foreground 'sgml-entity-face "dim gray")
   (set-face-foreground 'sgml-ignored-face "maroon")
   (set-face-background 'sgml-ignored-face "gray90")
   (set-face-foreground 'sgml-ms-end-face "maroon")
   (set-face-foreground 'sgml-ms-start-face "maroon")
   (set-face-foreground 'sgml-pi-face "maroon")
   (set-face-foreground 'sgml-sgml-face "maroon")
   (set-face-foreground 'sgml-short-ref-face "goldenrod")
   (set-face-foreground 'sgml-start-tag-face "dodger blue")
   ;; (set-face-bold-p     'sgml-start-tag-face 'nil)

 (setq-default
  sgml-markup-faces
  '(
    (comment . sgml-comment-face)
    (doctype . sgml-doctype-face)
    (end-tag . sgml-end-tag-face)
    (entity . sgml-entity-face)
    (ignored . sgml-ignored-face)
    (ms-end . sgml-ms-end-face)
    (ms-start . sgml-ms-start-face)
    (pi . sgml-pi-face)
    (sgml . sgml-sgml-face)
    (short-ref . sgml-short-ref-face)
    (start-tag . sgml-start-tag-face)
    ))

 (setq
  ;;  sgml-catalog-files
  ;;  (append sgml-catalog-files
  ;;          (list (concat (getenv "SGML_HOME") "/dtd/catalog")))
  sgml-custom-dtd
  '(("TEIlite XML"
     ""-//TEI//DTD TEI Lite XML ver. 1//EN\"
\"teixlite.dtd\">"
     "teixlite.ced"))))
;; End my-sgml

(add-hook 'sgml-mode-hook 'my-sgml)
; (add-hook 'sgml-mode-hook
;           '(lambda ()
;              (let ((ced-file-name
;                     (concat (file-name-sans-extension (buffer-file-name))
;                             ".ced"))
;                    )
;                (if (file-readable-p ced-file-name)
;                    (sgml-load-dtd ced-file-name)
;                  (sgml-parse-prolog)
;                  (sgml-save-dtd ced-file-name)
;                  ))))
;(setq sgml-validate-command "nsgmls -wxml -s /usr/lib/sgml/declaration/xml.dcl ")

;;;;;;;;;;;;;;;;; XML Customization                 ;;;;;;;;;;;;;;;;;;;
;;(autoload 'xml-mode "psgml-mode" "Major mode to edit XML files." t)

;(autoload 'xsl-mode "xslide" "Major mode for XSL stylesheets." t)

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

;(setq auto-mode-alist
;      (append
;       '(("\\.xsl$"           . xsl-mode))
;       auto-mode-alist))

;;;;;;;;;;;;;;;;; C/C++ Customization               ;;;;;;;;;;;;;;;;;;;
(defun my-c-mode()
  "Customizations for C/C++ mode"
  (interactive)
  (global-set-key [f7] 'compile)
; (local-set-key [return] 'reindent-then-newline-and-indent)
  (setq c-auto-newline t))

(add-hook 'c-mode-hook 'my-c-mode)
(add-hook 'c++-mode-hook 'my-c-mode)

;;;;;;;;;;;;;;;;; Java  Customization               ;;;;;;;;;;;;;;;;;;;
(defun my-java-mode-hook()
  "Hook for running Java file..."
  ;;don't indent braces
  (c-set-offset 'substatement-open 0)
  (c-set-offset 'statement-case-open 0)
  (c-set-offset 'case-label '+)
  (setq tab-width 2
        c-basic-offset 2
        ;; make sure spaces are used instead of tabs
        indent-tabs-mode nil))

(add-hook 'java-mode-hook 'my-java-mode-hook)

;;;;;;;;;;;;;;;;; Autoinsert                        ;;;;;;;;;;;;;;;;;;;
(auto-insert-mode 1)
(add-hook 'find-file-hooks 'auto-insert)

;; Header files
(define-auto-insert
  (cons "\\.\\([Hh]\\)$" "C/C++ Header File Template")
  '(nil
    "/*\n"
    "\n"
    " $Header: $\n"
    " $Log: $\n"
                "\n"
    " \n"
    "\n"
    "*/\n"
    (let* ((noext (substring buffer-file-name 0 (match-beginning 0)))
           (nopath (file-name-nondirectory noext))
           (indent (concat "__" (upcase nopath)
                            "_" (upcase (file-name-extension
buffer-file-name)))))
      (concat "#ifndef " indent "\n"
              "#define " indent "\n\n\n"
              "#endif /* " indent " */"))
    (previous-line 7)
    (end-of-line)))

;;; C/C++ files
(define-auto-insert
  (cons "\\.\\([cC]\\)" "C/C++ Source File Template")
  '(nil
    "/*\n"
    "\n"
    " $Header: $\n"
    " $Log: $\n"
                "\n"
    " \n"
                "\n"
    "*/\n"
    (let* ((nopath (file-name-nondirectory buffer-file-name))
                (noext  (file-name-sans-extension nopath)))
      (concat  "#include \"" noext ".h\"\n\n"))
    (previous-line 5)
    (end-of-line)))

;;; AWK files
(define-auto-insert
  (cons "\\.\\(awk\\)" "AWK File Template")
  '(nil
    "#!/bin/bash\n"
                "#\n"
    "# $Header: $\n"
    "# $Log: $\n"
    "#\n"
    "# \n"
    "#\n"
                "BEGIN{}\n"
                "{\n"
                "\n"
                "}\n"
    (previous-line 6)
    (end-of-line)))

;;; HTML files
(define-auto-insert
  (cons "\\.\\(htm\\)" "HTML File Template")
  '(nil
    ""-//W3C//DTD XHTML 1.0 Strict//EN\">\n"
    "\n"
    "  \n"
    "    \n"
    "\n"
    "    \n"
    "    \n"
    "    \n"
    "    \n"
    "    \n"
    "  \n"
    "  \n"
    "    \n"
    "    

Best viewed with Lynx

\n" " \n" "\n" (previous-line 4) (end-of-line))) ;;;;;;;;;;;;;;;;; Linux Setup ;;;;;;;;;;;;;;;;;;; (GNULinux (define-key global-map [(delete)] "\C-d") (XWindow (create-fontset-from-fontset-spec "-adobe-courier-medium-r-*-*-12-*-*-*-*-*-fontset-adobe, latin-iso8859-1:-rfx-courier-medium-r-*-*-12-*-*-*-*-*-*-1, latin-iso8859-2:-rfx-courier-medium-r-*-*-12-*-*-*-*-*-*-2, cyrillic-iso8859-5:-rfx-courier-medium-r-*-*-12-*-*-*-*-*-*-5") (create-fontset-from-fontset-spec "-adobe-courier-medium-o-*-*-12-*-*-*-*-*-fontset-adobe, latin-iso8859-1:-rfx-courier-medium-o-*-*-12-*-*-*-*-*-*-1, latin-iso8859-2:-rfx-courier-medium-o-*-*-12-*-*-*-*-*-*-2, cyrillic-iso8859-5:-rfx-courier-medium-o-*-*-12-*-*-*-*-*-*-5") (create-fontset-from-fontset-spec "-adobe-courier-bold-o-*-*-12-*-*-*-*-*-fontset-adobe, latin-iso8859-1:-rfx-courier-bold-o-*-*-12-*-*-*-*-*-*-1, latin-iso8859-2:-rfx-courier-bold-o-*-*-12-*-*-*-*-*-*-2, cyrillic-iso8859-5:-rfx-courier-bold-o-*-*-12-*-*-*-*-*-*-5") (create-fontset-from-fontset-spec "-adobe-courier-bold-r-*-*-12-*-*-*-*-*-fontset-adobe, latin-iso8859-1:-rfx-courier-bold-r-*-*-12-*-*-*-*-*-*-1, latin-iso8859-2:-rfx-courier-bold-r-*-*-12-*-*-*-*-*-*-2, cyrillic-iso8859-5:-rfx-courier-bold-r-*-*-12-*-*-*-*-*-*-5") (create-fontset-from-fontset-spec "-*-fixed-medium-r-normal-*-16-*-*-*-c-*-fontset-bdf, japanese-jisx0208:-*-*-medium-r-normal-*-16-*-*-*-c-*-jisx0208.1983-*, katakana-jisx0201:-*-*-medium-r-normal-*-16-*-*-*-c-*-jisx0201*-*, latin-jisx0201:-*-*-medium-r-normal-*-16-*-*-*-c-*-jisx0201*-*, japanese-jisx0208-1978:-*-*-medium-r-normal-*-16-*-*-*-c-*-jisx0208.1978-*, thai-tis620:-misc-fixed-medium-r-normal--16-160-72-72-m-80-tis620.2529-1, lao:-misc-fixed-medium-r-normal--16-160-72-72-m-80-MuleLao-1, tibetan-1-column:-TibMdXA-fixed-medium-r-normal--16-160-72-72-m-80-MuleTibetan-1, ethiopic:-Admas-Ethiomx16f-Medium-R-Normal--16-150-100-100-M-160-Ethiopic-Unicode, tibetan:-TibMdXA-fixed-medium-r-normal--16-160-72-72-m-160-MuleTibetan-0") ;; (set-default-font "fontset-adobe") (setq default-frame-alist '( (top . 15) (left . 35);; for 800x600 screen (width . 80) (height . 33);; for 800x600 screen (cursor-color . "black") (cursor-type . box) (foreground-color . "black") (background-color . "white") (font . "-adobe-courier-medium-r-*-*-12-*-*-*-*-*-fontset-adobe")))) ;;XWindow ;; BDF fonts for printing (load-library "ps-mule");; needed for setting some variables below (setq ps-multibyte-buffer 'bdf-font ps-mule-font-info-database ps-mule-font-info-database-bdf bdf-directory-list '("/usr/X11R6/lib/X11/fonts/misc"))) ;;GNULinux ;;;;;;;;;;;;;;;;; Windows Setup ;;;;;;;;;;;;;;;;;;; ;; WinNT fontset for maximum i18n (Windows (set-w32-system-coding-system 'cp1251) (setq w32-standard-fontset-spec "-*-Courier New-normal-r-*-*-12-*-*-*-c-*-fontset-courier, ascii:-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-1, latin-iso8859-1:-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-1, latin-iso8859-2:-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-2, latin-iso8859-3:-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-3, latin-iso8859-4:-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-4, latin-iso8859-9:-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-9, cyrillic-iso8859-5:-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-5, greek-iso8859-7:-*-Courier New-normal-r-*-*-12-*-*-*-c-*-iso8859-7, hebrew-iso8859-8:-*-Rod-normal-r-*-*-12-*-*-*-c-*-iso8859-8, ipa:-*-Lucida Sans Unicode-normal-r-*-*-12-*-*-*-c-*-muleipa*-*, thai-tis620:-*-Tahoma-normal-r-*-*-12-*-*-*-c-*-tis620-*, latin-jisx0201:-*-MS Gothic-normal-r-*-*-12-*-*-*-c-*-jisx0208-sjis, katakana-jisx0201:-*-MS Gothic-normal-r-*-*-12-*-*-*-c-*-jisx0208-sjis, japanese-jisx0208:-*-MS Gothic-normal-r-*-*-12-*-*-*-c-*-jisx0208-sjis, japanese-jisx0208-1978:-*-MS Gothic-normal-r-*-*-12-*-*-*-c-*-jisx0208-sjis, japanese-jisx0212:-*-MS Gothic-normal-r-*-*-12-*-*-*-c-*-jisx0212-sjis, korean-ksc5601:-*-Gulim-normal-r-*-*-12-*-*-*-c-*-ksc5601-*, chinese-gb2312:-*-MS Song-normal-r-*-*-12-*-*-*-c-*-gb2312-*, chinese-big5-1:-*-MingLiU-normal-r-*-*-12-*-*-*-c-*-big5-*, chinese-big5-2:-*-MingLiU-normal-r-*-*-12-*-*-*-c-*-big5-*") (setq w32-enable-italics t) ;; create-fontset should follow this (create-fontset-from-fontset-spec w32-standard-fontset-spec t) (setq w32-use-w32-font-dialog ; Use a unix-style font dialog w32-fixed-font-alist '("Select Fontset")) ;; setting the default fontset ;; (set-frame-font "fontset-courier") ;; Set up BDF fonts: (setq bdf-directory-list '("l:/lowry/emacs/intlfonts/Asian" "l:/lowry/emacs/intlfonts/Chinese" "l:/lowry/emacs/intlfonts/Chinese.X" "l:/lowry/emacs/intlfonts/Ethiopic" "l:/lowry/emacs/intlfonts/European" "l:/lowry/emacs/intlfonts/Japanese" "l:/lowry/emacs/intlfonts/Japanese.X" "l:/lowry/emacs/intlfonts/Korean.X" "l:/lowry/emacs/intlfonts/Misc/" "l:/lowry/emacs/intlfonts/Japanese.BIG")) ;; Read font names from disk (setq w32-bdf-filename-alist (w32-find-bdf-fonts bdf-directory-list)) ;; Setting the network printer (setq ps-printer-name "//server/printer") ;; BDF fonts for printing (load-library "ps-mule") ;; needed for setting some variables below (setq ps-multibyte-buffer 'bdf-font ps-mule-font-info-database ps-mule-font-info-database-bdf bdf-directory-list '( "l:/intlfonts/Asian" "l:/intlfonts/Chinese" "l:/intlfonts/Chinese.X" "l:/intlfonts/Ethiopic" "l:/intlfonts/European" "l:/intlfonts/Japanese" "l:/intlfonts/Japanese.X" "l:/intlfonts/Korean.X" "l:/intlfonts/Misc" "l:/intlfonts/Japanese.BIG") ) ;; hand-crafted bdf-only fontset (create-fontset-from-fontset-spec "-*-fixed-medium-r-normal-*-16-*-*-*-c-*-fontset-bdf8, japanese-jisx0208:-*-*-medium-r-normal-*-16-*-*-*-c-*-jisx0208.1983-*, katakana-jisx0201:-*-*-medium-r-normal-*-16-*-*-*-c-*-jisx0201*-*, latin-jisx0201:-*-*-medium-r-normal-*-16-*-*-*-c-*-jisx0201*-*, japanese-jisx0208-1978:-*-*-medium-r-normal-*-16-*-*-*-c-*-jisx0208.1978-*, thai-tis620:-misc-fixed-medium-r-normal--16-160-72-72-m-80-tis620.2529-1, lao:-misc-fixed-medium-r-normal--16-160-72-72-m-80-MuleLao-1, tibetan-1-column:-TibMdXA-fixed-medium-r-normal--16-160-72-72-m-80-MuleTibetan-1, ethiopic:-Admas-Ethiomx16f-Medium-R-Normal--16-150-100-100-M-160-Ethiopic-Unicode, tibetan:-TibMdXA-fixed-medium-r-normal--16-160-72-72-m-160-MuleTibetan-0, indian-1-column:-misc-fixed-medium-r-normal--16-160-72-72-c-80-muleindian-1, indian-2-column:-misc-fixed-medium-r-normal--16-160-72-72-c-80-muleindian-2, indian-is13194:-misc-fixed-medium-r-normal--16-160-72-72-c-80-is13194-devanagari") ;; Some fonts have to be mapped explicitly (setq font-encoding-alist (append '(("MuleTibetan-0" (tibetan . 0)) ("GB2312" (chinese-gb2312 . 0)) ("JISX0208" (japanese-jisx0208 . 0)) ("JISX0212" (japanese-jisx0212 . 0)) ("VISCII" (vietnamese-viscii-lower . 0)) ("KSC5601" (korean-ksc5601 . 0)) ("MuleArabic-0" (arabic-digit . 0)) ("MuleArabic-1" (arabic-1-column . 0)) ("MuleArabic-2" (arabic-2-column . 0)) ("MuleIndian-1" (indian-1-column . 0)) ("MuleIndian-2" (indian-2-column . 0)) ("is13194-Devanagari" (indian-is13194 . 0)) ) font-encoding-alist)) (setq default-frame-alist '( ;; (top . 2) (left . 5) ;; (width . 120) (height . 43) (cursor-color . "black") (cursor-type . box) (foreground-color . "black") (background-color . "white") (font . "-*-Courier New-normal-r-*-*-12-*-*-*-c-*-fontset-courier") ) ) ;; Setting bash as the default emacs shell (defun my-shell-setup () "For bash under Emacs 20" (setq comint-scroll-show-maximum-output 'this) (setq comint-completion-addsuffix t) ;; (setq comint-process-echoes t) ;; reported that this is no longer needed (setq comint-eol-on-send t) (setq w32-quote-process-args ?\") (make-variable-buffer-local 'comint-completion-addsuffix)) (setq shell-mode-hook 'my-shell-setup) (setq binary-process-input t) (setq process-coding-system-alist (cons '("bash" . cp1251) process-coding-system-alist))) ;; Match Windows ;;;;;;;;;;;;;;;;; Fontsets Setup ;;;;;;;;;;;;;;;;;;; (custom-set-faces '(xsl-xslt-main-face ((((class color)) (:foreground "black")))) '(xsl-xslt-alternate-face ((((class color)) (:foreground "dodger blue")))) '(xsl-fo-alternate-face ((((class color)) (:foreground "blue" :italic t)))) '(xsl-fo-main-face ((((class color)) (:foreground "Wheat")))) '(xsl-other-element-face ((((class color)) (:foreground "dodger blue" :bold t)))) '(font-lock-comment-face ((((class color)) (:foreground "gray" :italic t)))) '(info-xref ((t (:bold t :foreground "DarkBlue")))) '(font-lock-keyword-face ((((class color)) (:foreground "dodger blue" :bold t)))) '(message-highlighted-header-contents ((t (:foreground "red" :bold t :italic t)))) '(message-headers ((t (:foreground "forestgreen" :size "15" :bold t)))) '(modeline ((t (:inverse-video nil :foreground "black" :background "skyblue")))) '(info-node ((t (:bold t :italic t :foreground "firebrick")))) '(font-lock-function-name-face ((((class color)) (:foreground "DarkSlateBlue" :bold t)))) '(font-lock-type-face ((((class color)) (:foreground "cadet blue" :bold t)))) '(message-header-contents ((t (:foreground "rosybrown" :italic t)))) '(region ((t (:background "white smoke")))) '(font-lock-constant-face ((t (:foreground "olive drab" :bold t)))) '(font-lock-variable-name-face ((t (:foreground "IndianRed" :italic t)))) '(jde-java-font-lock-package-face ((t (:foreground "Pink" :bold t)))) '(font-lock-string-face ((t (:foreground "DeepSkyBlue3")))) '(jde-java-font-lock-number-face ((t (:foreground "blue")))) ) ; jde-bug-breakpoint-cursor ; jde-bug-breakpoint-marker ; jde-java-font-lock-api-face ; jde-java-font-lock-bold-face ; jde-java-font-lock-code-face ; jde-java-font-lock-constant-face ; jde-java-font-lock-doc-tag-face ; jde-java-font-lock-italic-face ; jde-java-font-lock-link-face ; jde-java-font-lock-modifier-face ; jde-java-font-lock-number-face ; jde-java-font-lock-package-face ; jde-java-font-lock-pre-face ; jde-java-font-lock-underline-face ;; This is more correct than the previous statement ; (setq font-lock-face-attributes ; '( ; (font-lock-comment-face "SteelBlue" nil nil 1 nil) ; (font-lock-string-face "cyan" nil nil 1 nil) ; (font-lock-keyword-face "darkorange" nil nil nil nil) ; (font-lock-type-face "yellow" nil nil nil nil) ; (font-lock-function-name-face "DeepSkyBlue" nil nil nil 1) ; (font-lock-variable-name-face "magenta" nil nil nil nil) ; (font-lock-reference-face "blue" nil nil nil nil) ; (font-lock-builtin-face "lightblue" nil nil nil nil) ; (font-lock-constant-face "cornflowerblue" nil nil nil nil) ; (font-lock-warning-face "red" nil nil nil nil))) ;;;;;;;;;;;;;;;;; Unicode Support ;;;;;;;;;;;;;;;;;;; ;; Should happen after create-fontset-from-fontset-spec ;; due to an obscure bug in Mule-UCS (condition-case err (require 'un-define) (error (message "Cannot load Mule-UCS %s" (cdr err)))) (GNUEmacs (modify-coding-system-alist 'file "\\.utf8$" 'utf-8) (modify-coding-system-alist 'file "\\.xml$" 'utf-8) (modify-coding-system-alist 'file "\\.html$" 'utf-8) (modify-coding-system-alist 'file "\\.tei$" 'utf-8) (modify-coding-system-alist 'file "\\.xsl$" 'utf-8) (modify-coding-system-alist 'file "\\.fo$" 'utf-8) (modify-coding-system-alist 'file "\\.php$" 'utf-8) (set-selection-coding-system 'cp1251)) ;;;;;;;;;;;;;;;;; Handle Desktop Sessions ;;;;;;;;;;;;;;;;;;; (require 'desktop) (setq desktop-globals-to-save (append '((read-command-history . 9) (file-name-history . 9) (compile-history . 9) (command-history . 9) (extended-command-history . 9) (shell-command-history . 9) (query-replace-history . 9) (regexp-history . 9) (grep-history . 9) (compile-command . 9) (minibuffer-history . 9)) desktop-globals-to-save)) (desktop-load-default) (desktop-read) ;; Avoid saving too much data (add-hook 'kill-emacs-hook '(lambda () (desktop-truncate search-ring 9) (desktop-truncate regexp-search-ring 9))) ;;;;;;;;;;;;;;;;; Library of Code ;;;;;;;;;;;;;;;;;;; ; (local-set-key [return] 'beautify) ; (local-set-key [?\ ] 'refill-paragraph) ; (defun beautify() ; "Useful only for text modes" ; (interactive) ; (fill-paragraph 1) ; (reindent-then-newline-and-indent)) ; (defun refill-paragraph() ; "uhu" ; (interactive) ; (fill-paragraph 1)) (defun tabify-buffer() "tabifies the current buffer has to always return nil, if added to write-file-hooks" (save-excursion (goto-char (point-min)) (while (re-search-forward "[ \t]+$" nil t) (delete-region (match-beginning 0) (match-end 0))) (goto-char (point-min)) (if (search-forward "\t" nil t) (tabify (1- (point)) (point-max)))) nil) (defun untabify-buffer() (interactive) "untabifies the current buffer has to always return nil, if added to write-file-hooks" (save-excursion (goto-char (point-min)) (while (re-search-forward "[ \t]+$" nil t) (delete-region (match-beginning 0) (match-end 0))) (goto-char (point-min)) (if (search-forward "\t" nil t) (untabify (1- (point)) (point-max)))) nil) (defun downcase-sgml-buffer() (interactive) "downcase all html tags in the current buffer" (save-excursion (goto-char (point-min)) (while (re-search-forward "()]" nil t) (downcase-sgml-tag (match-beginning 2) (match-end 2)))) nil) (defun downcase-sgml-tag(start end) (save-excursion (save-restriction (narrow-to-region start end) (goto-char start) (re-search-forward "^([A-Z]+)" nil t) (downcase-region (match-beginning 1) (match-end 1)))) nil) ;;;;;;;;;;;;;;;;; Misc Hooks ;;;;;;;;;;;;;;;;;;; ;; start the emacs server (server-start) ;; autocompile this file while saving (defun autocompile() "compile itself if ~/.emacs" (interactive) (if (string= (buffer-file-name) (concat default-directory ".emacs")) (byte-compile-file (buffer-file-name)))) (add-hook 'after-save-hook 'autocompile()) (defun do-on-write-file() (untabify-buffer) (setq nuke-trailing-whitespace-p t) (nuke-trailing-whitespace)) (add-hook 'write-file-hooks 'do-on-write-file) (add-hook 'mail-send-hook 'do-on-write-file) ;;; Local Variables: *** ;;; mode:emacs-lisp *** ;;; mode:outline-minor *** ;;; outline-regexp: ";;;;;;;;;;.*;;;;;;;;;" *** ;;; eval:(hide-body) *** ;;; End: *** ;;; .emacs ends here