Wednesday, January 09, 2008

Oh, (dot)Emacs, My (dot)Emacs!

After another 38 degree hot & humid Bs As day, it is time to have some fun, and post my Emacs dot file, the core of the editor's customization; like I said before, I'm a big Emacs fan & user.

This one should work on any modern (<21) Emacs around.
I simply hate how the default Emacs setup populates my file systems with all those "backup.txt~" files... That's why I have setup the .emacs file to store all the backups on a given directory, and then use a cronjob to delete the older than X days automatically; for this to work, you have to have a '$HOME/emacs/backups' directory.
Also, there is a snip regarding Timestamp, I use it all the time for writing changelogs.
The 'pc-selection' bit highlights the selection, when you use the keyboard, via Ctrl + Space bar.

The easiest way of making this changes for all users and just one time, is to populate the skel directory of your ditribution, usually on the /etc directory, with whatever you want to be common to all users.


;; ---------------------------------------------------
;; ~/.emacs default file
;; ---------------------------------------------------

;; -----------------------------------------------
;; Safe defaults

(setq inhibit-startup-message t)
(setq default-major-mode 'text-mode)
(menu-bar-mode nil)
(setq bell-volume 100)
(setq visible-bell t)

;; -----------------------------------------------
;; Modeline customization

(display-time)
(setq line-number-mode t)
(setq column-number-mode t)

;; -----------------------------------------------
;; Keyboards shortcuts

(define-key global-map "\C-h" 'backward-delete-char)
(define-key global-map "\M-h" 'backward-kill-word)
(define-key global-map "\C-x\C-u" 'undo)

(global-set-key [f5] 'bury-buffer)

(pc-selection-mode)

;; Esc + the arrow keys as a way to delete words
(define-key esc-map [right] 'kill-word) ;; esc -> kill-word
(define-key esc-map [left] 'backward-kill-word) ;; esc <- backward-kill-word

;; -----------------------------------------------
;; Backups

(defun make-backup-file-name (file-name)
"Create the non-numeric backup file name for `file-name'."
(require 'dired)
(if (file-exists-p "~/emacs/backups")
(concat (expand-file-name "~/emacs/backups/")
(dired-replace-in-string "/" "|" file-name))
(concat file-name "~")))

;; -----------------------------------------------

;; Turn on color syntax
(global-font-lock-mode t)

;; -----------------------------------------------
;; Insert timestamp
(defvar insert-time-format "%T")

(defvar insert-date-format "%d %m %Y"
"*Format for \\[insert-date] (c.f. 'format-time-string' for how to format).")

(defun iTime ()
(interactive "*")
(insert (format-time-string insert-time-format
(current-time))))
(defun iDate ()
(interactive "*")
(insert (format-time-string insert-date-format
(current-time))))
(defun iDate ()
(interactive "*")
(insert (format-time-string insert-date-format
(current-time))))
(defun iDateTotal ()
(interactive "*")
(progn
(iDate)
(insert " ")
(iTime)))

;; -----------------------------------------------

;; EoF ;;


Happy, happy, joy, joy.

Labels: ,

0 Comments:

Post a Comment

<< Home