The very unofficial .emacs home Jean-PhilippeTheberge.emacs
what is this all about ?
customization basics
special topics
local dotfiles
dotfiles on the web
new and updated pages
useful sites and pages
search locally
OS/2 Emacs
Latest Additions
local files:
John J. Glynn
David Jolley

linked files:


The Emacs wiki
ODP search for Emacs
;;; .emacs --- My emacs config file file -*- emacs-lisp -*-

(defconst running-gnu-emacs t)
(defconst running-xemacs nil)
(defconst windozep (equal window-system 'w32))

(require 'cl)

(random t)                              ; Reset the random seed

(if (locate-library "popup-menu")
      (menu-bar-mode -1)
      (if window-system 
            (require 'popup-menu)
            (global-set-key [S-down-mouse-3]  'my-x-popup-menu))))
  (menu-bar-mode (if window-system 1 -1))) ; Disable the menu-bar in console mode
(setq visible-bell t)                   ; Turn off the &*^%$ bell!
(column-number-mode 1)                  ; Turn on the column numbering in the minibuffer
(setq display-time-string-forms '(day "/" month "/" (substring year -2)
                                      " [FR " 24-hours ":" minutes "]"
                                      "[CND " (number-to-string 
                                               (let ((h (- (string-to-number 24-hours) 6)))
                                                 (if (wholenump h)
                                                   (- 12 h))))
                                      ":" minutes "]"
                                      (if mail " Mail" "")))
(display-time)                          ; Show the time in tbe minibuffer
(pc-selection-mode)                     ; Windoze-like selection mode
(fset 'yes-or-no-p 'y-or-n-p)           ; replace y-e-s by y

; Set some nice color (if x)
(if window-system 
      (set-background-color "darkslategray")
      (set-foreground-color "wheat")))

;; Turn on font-lock
(if window-system 
      (setq font-lock-maximum-decoration t)
      ;; Font locking info mode (from
      (defvar info-font-lock-keywords
         '("^\\* [^:]+:+" . font-lock-function-name-face)
         '("\\*[Nn]ote\\b[^:]+:+" . font-lock-reference-face)
         '("  \\(Next\\|Prev\\|Up\\):" . font-lock-reference-face))
        "Additional expressions to highlight in Info mode.")
      (add-hook 'Info-mode-hook
                (lambda ()
                  (make-local-variable 'font-lock-defaults)
                  (setq font-lock-defaults '(info-font-lock-keywords nil t))))
; One day Eli Zaretskii <> said:
; " I think it is generally a bad idea to load font-lock directly from 
; .emacs, especially if you do that before setting default-frame-alist.  It 
; is better to do it from a major-mode-specific hook.  If you want to turn 
; on global-font-lock-mode, do it from a function that is on the 
; after-init-hook list.  Emacs calls after-init-hook after it reads .emacs, 
; so when font-lock is loaded, default-frame-alist is already set."
; Even if I dont use frame-alist (or any frame anyway) I've decide to listen to him!
      (add-hook 'after-init-hook
                (global-font-lock-mode t))))

;; Compression
(auto-compression-mode 1) ; Automatic opening of compressed files.
(if windozep (setq archive-zip-extract '("c:/progra~1/pkzip/pkzip" "-extract")))

;; Set the text for titlebar and icons
(if window-system
    (setq frame-title-format (list "GNU Emacs " emacs-version " running on " (getenv "HOSTNAME"))
          icon-title-format "Emacs"))

;; Set a default font & a function to reset the default font
(if window-system
      (defconst *default-font*
        (if windozep
            "-*-Fixedsys-normal-r-*-*-12-90-96-96-c-*-iso8859-1" ; My Win32 font
   "-adobe-courier-bold-*-*-*-20-*-*-*-*-*-*-*")) ; My Unix fontq
      (defun reset-font-to-default ()
        "Reset the font to the default, as defined in *default-font*"
        (set-default-font *default-font*))

(defun turn-to-unix ()
  (set-buffer-file-coding-system 'iso-8859-1-unix))

;; Keys definitions
(global-set-key [delete] `backward-delete-char)
(global-set-key [home] 'beginning-of-line)
(global-set-key [end] 'end-of-line)
(global-set-key "\C-a" 'select-all)
(global-set-key "\C-c\C-o" 'comment-region)
(global-set-key [f1] 'describe-function)
(global-set-key [M-f1] 'describe-variable)
(global-set-key [f2] 'eval-buffer)
(global-set-key [f3] 'bookmark-jump)
(global-set-key [f4] 'fontify-buffer-with-mode-change)
(global-set-key [f5] 'undo)
(global-set-key [M-f5] 'turn-to-unix)
(global-set-key [f6] 'call-last-kbd-macro)
(global-set-key [f7] 'dired-at-point)
(global-set-key [f8] 'browse-url-at-point)
(global-set-key [f9] 'run-scheme)
(global-set-key [f10] 'insert-time)
(global-set-key [f11] 'gnus)
(global-set-key [f12] 'mail-to-address-at-point)
(global-set-key [C-M-f12] 'zone)
(global-set-key [S-M-f12] 'dissociated-press)
(global-set-key "\C-x\C-c" 'no-way)
(global-set-key "\M-z" 'call-last-kbd-macro)
(global-set-key "\C-xF" 'find-remote-file)

(ignore-errors (load-library "mlsetup"))

;; This is bound to C-x C-c so I dont accidentaly close my emacs
;; to really close emacs, M-x kill-emacs
(defun no-way ()
  (message "NO, I'm sticking here! To kill emacs for real, use \'M-x kill-emacs\'."))

;; A function to destroy the \n
(defun kill-all-newlines-from-buffer ()
  (goto-char (point-min))
  (while (re-search-forward "^[ \t]*$")

;; Thing for scheme mode using siod

(if windozep
    (setq siod-location       "c:/progra~1/siod/siod.exe"
          siod-args           " -ic:/progra~1/siod/r4rs.scm"
          scheme-program-name (concat siod-location siod-args)
          siod-help-file      "c:/progra~1/siod/siod-help.txt"
          scheme-mit-dialect  nil)
  (setq siod-location       "/usr/local/bin/siod"
        siod-args           " -i/usr/local/lib/siod/r4rs.scm"
        scheme-program-name (concat siod-location siod-args)
        siod-help-file      "/usr/share/siod/siod-help.txt"
        scheme-mit-dialect  nil))

(autoload 'siod-help "siod-help" "siod-help" t)
(add-hook 'scheme-mode-hook
          '(lambda ()
             (define-key scheme-mode-map [f1] 'siod-help)))
(add-hook 'scheme-mode-hook
          '(lambda ()
             (define-key scheme-mode-map [f2] 'find-tag)))
(add-hook 'inferior-scheme-mode-hook
          '(lambda ()
             (define-key inferior-scheme-mode-map [f1] 'siod-help)))
(add-hook 'scheme-mode-hook
          '(lambda () (imenu-add-to-menubar "Browser")))

(defun siod-header ()
  (insert "#!/usr/local/bin/siod -v0,-m3 -*- Scheme -*-"))

(setq tags-file-name "/usr/local/lib/siod/TAGS")

;; ange-ftp-shortkut

(defvar remote-servers
  '(("cam" "" "yesod" "/home/yesod")
    ("oeil" "" "yesod" "/home/yesod")
    ("mercere" "" "yesod" "/home/mercere")
    ("trisome" "" "trisome" "/home/trisome")
    ("nextron" "" "jphil" "/data/oda/hdoc")
    ("easysite" "" "jphil" "/opt/home/jphil")
    ("mnex01" "" "jphil" "/opt/home/jphil")))

(defun find-remote-file (name)
  (interactive (list (completing-read "Profile : " remote-servers)))
  (let ((server (assoc name remote-servers)))
    (if server
        (find-file (concat "/" (caddr server) "@" (cadr server) ":" (cadddr server)))
      (message (concat name " not found")))))
(defun select-all ()
  (set-mark (point-min))
  (goto-char (point-max)))

;; The most important defun in this file
(defun dilbert ()
  (load-library "getcomics")
  (if windozep
      (setq comics-viewer "C:/Program Files/Netscape/Communicator/Program/netscape.exe"))
  (get-comic "dilbert"))

;; To put the backup~ files in ~/backup
(if (ignore-errors (require 'backups))
      (move-backups t)
      (setq backup-directory "~/backup")))

(ignore-errors (require 'dired-external))

(defun ascii-table ()
  "Print the ascii table - based on a defun by Alex Schroeder <>"
  (switch-to-buffer "*ASCII*")
  (insert (format "ASCII characters up to number %d.\n" 254))
  (let ((i 0))
    (while (< i 254)
      (setq i (+ i 1))
      (insert (format "%4d %c\n" i i))))

(let ((abbrevf "~/.abbrev"))
  (if (file-exists-p abbrevf)
        (setq-default abbrev-mode t)
        (read-abbrev-file abbrevf)
        (setq save-abbrevs t))))

;; Ange FTP detection. (from Mike West <>)
(defconst remote-file-regexp "^/[^/:]*:"
  "Regexp to match for remote filename.")

(defun is-remote-file (filename)
  "Return t if FILENAME is a valid remote file name for ange-ftp."
  (cond ((and filename
              (string-match remote-file-regexp filename)) t)))

(defun is-ange-ftp ()
  (if (is-remote-file (buffer-file-name))
      (message "File is remote")
    (message "File is local")))

;; A function for f12 to email the address at point

(defconst email-regexp "[-a-zA-Z]+@[-a-zA-Z]+\.[-.a-zA-Z]+"
  "Simple regexp to match email address.")
(defun mail-to-address-at-point ()
;; Based on a defun by Kevin Rodgers <>
  "*Edit a new mail message to the address at point."
  (let ((url-at-point (substring (thing-at-point 'url) 7)))
    (if (string-match email-regexp url-at-point)
        (mail nil url-at-point)
      (message "Bad email address"))))

(defun open-new-line (arg)
; from Juanma Barranquero <>
  (interactive "*p")
    (newline arg)))

; I want to set open-new-line to M-return but I can't find how :(
;(global-set-key [M-RET] 'open-new-line)
; So I use M-' in the meantime...
(global-set-key "\M-'" 'open-new-line)
(defun insert-time ()
  (insert (format-time-string "%d/%m/%Y")))

;; stuff for telneting under windoze
(if windozep
      ;; This telnet.exe thing come from Igor Milavec & Naftali Ramati <>
      ;; is required and is available at
      (setq telnet-program "c:/progra~1/telnet/telnet.exe")
      (require 'telnet)
      (require 'win-telnet)))

(if (locate-library "recentf")
      (require 'recentf)
      (setq recentf-max-menu-items 21)
      (setq recentf-exclude '("^c:/tmp"))))

(autoload 'zone "zone" nil t) 
(autoload 'turn-on-eldoc-mode "eldoc" nil t)
(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
(add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
(autoload 'babel "babel" nil t)

(if windozep
      (require 'gnuserv)
      (setq gnuserv-frame (selected-frame))))

;; To protect my *scratch* buffer from accidental killing
(if (ignore-errors (require 'protbuf))
    (protect-buffer-from-kill-mode 1 "*scratch*"))

(cd (getenv "HOME"))

(setq user-full-name "J-P Theberge"
      user-mail-address "")

(require 'tnt)
(if (not (boundp 'tnt-is-alive))
      (tnt-open "tris00me" "triso21")
      (setq tnt-is-alive t)))

(setq mark-holidays-in-calendar t
      calendar-holiday-marker 'diary-face)

;;; .emacs ends here
All content copyright by the contributors. Website maintained with Emacs , wsmake and html-helper-mode
Emacs community logo by Daniel Lundin Last updated on Sat Jan 22 14:49:24 2005 by Ingo Koch