;; Sean B. Palmer's init.el File ;; http://purl.org/net/sbp/ ;; ;; Because I'm picky, and I like this set-up. (defvar running-xemacs (string-match "XEmacs\\|Lucid" emacs-version)) ;; Make the title bar show the name of current buffer (setq frame-title-format '("xemacs@localhost %*%+ %b")) ;; Options (setq default-major-mode 'text-mode) (setq line-number-mode t) ;; Put line/column # at the bottom of the page (setq column-number-mode t) (setq require-final-newline t) ;; Always end a file with a newline (setq scroll-step 1) ;; Scroll one line at a time (setq visible-bell t) ;; Turn off the bell (setq inhibit-startup-message t) ;; No splash (setq font-lock-mode-maximum-decoration t) ;; Turn hilighting on (setq backup-directory-alist (quote ((".*" . "~/.backups")))) (defconst use-backup-dir t) ;use backup directory (fset 'yes-or-no-p 'y-or-n-p) ;; Use y or n instead of yes or no (cond (running-xemacs (setq options-save-faces t) ;; Enable saving of customization )) (set-face-font 'default "-*-Courier New-medium-r-*-*-*-110-*-*-*-*-iso8859-1") (defvar backup-directory "~/.xemacs/backups/") (defun make-backup-file-name (file) (if (file-exists-p (expand-file-name backup-directory)) (concat (expand-file-name backup-directory) (file-name-nondirectory file) "~") (concat file "~") )) ;; Functions (defun my-toggle-toolbar () (interactive) (set-specifier default-toolbar-visible-p (not (specifier-instance default-toolbar-visible-p)))) (defun my-match-paren (arg) "Go to the matching parenthesis if on parenthesis otherwise insert %." (interactive "p") (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1)) ((looking-at "\\s\)") (forward-char 1) (backward-list 1)) (t (self-insert-command (or arg 1))))) (defun my-wc-on-region (start end) (interactive "r") (let ((words 0) (lines 0) (chars 0)) (save-excursion (goto-char start) (while (< (point) end) (forward-word 1) (setq words (1+ words)))) (setq lines (count-lines start end) chars (- end start)) (message "Region has %d lines, %d words, %d characters." lines words chars))) ;; Keybindings (global-set-key "\C-xd" 'delete-region) (global-set-key "\C-z" 'undo) (global-set-key "\C-n" 'bs-cycle-next) (define-key global-map '(f10) 'delete-window) (global-set-key "\C-xt" 'my-toggle-toolbar) (global-set-key "\C-5" 'my-match-paren) (global-set-key "\C-xw" 'my-wc-on-region) ;; Prevent accidentally killing emacs. (global-set-key [(control x) (control c)] '(lambda () (interactive) (if (y-or-n-p-with-timeout "Do you really want to exit Emacs ? " 4 nil) (save-buffers-kill-emacs)))) ;; @@ kill buffer is C-x k, but it asks for a RET too... ;; Python-mode stuff ;; "Useful" (add-hook 'python-mode-hook (lambda () (set (make-variable-buffer-local 'beginning-of-defun-function) 'py-beginning-of-def-or-class) (setq outline-regexp "def\\|class "))) ;; The missing key shortcuts for Uncomment Region (add-hook 'python-mode-hook (lambda () (define-key py-mode-map "\C-c3" (lambda (beg end) (interactive "r") (py-comment-region beg end '(4)))))) (defun cs-python-mode-hook () (turn-on-font-lock) (setq auto-fill-function 'do-auto-fill indent-tabs-mode nil py-python-command "python" py-indent-offset 3 py-continuation-offset 3 py-smart-indentation t py-block-comment-prefix "#")) (add-hook 'python-mode-hook 'cs-python-mode-hook) ;; Show leading and trailing whitespace ;(add-hook 'python-mode-hook ;'(lambda() ; (setq font-lock-keywords ; (append font-lock-keywords ; '( ; ("[\t ]+$" (0 'secondary-selection t)) ; ))))) ;; More information with the info file (Control-h i) ;; test other stuff ; ;; Able to VIEW COMPRESSED (.gz and .z) FILES directly ; (auto-compression-mode) ; - http://www.dtek.chalmers.se/~d1temp/emacs.html (defun sidle-up (numlines start-point) "Move this line or region upward by numlines (defaults to one)." (interactive "*_p\nd") (cond ((<= numlines 0) (error "Prefix arg must be positive")) ;; if there is an active region, move it rather than just current line ((region-active-p) (let ((orig-top (region-beginning)) (orig-bottom (region-end)) (start-mark (mark))) (move-marker (point-marker t) orig-top) (beginning-of-line) ;; only take action if the region is not at top (cond ((> (point) 1) (let ((top (point))) (forward-line (* -1 numlines)) (let ((chars-up (- top (point)))) (kill-region top (point)) (move-marker (point-marker t) (- orig-bottom chars-up)) ;; If the end-of-region is not at beginning-of-line, ;; move insertion point to after end-of-line. (cond ((not (zerop (current-column))) (message "current-column: %d" (current-column)) (beginning-of-line) (forward-line 1) ;; If at end-of-buffer and the last line does not ;; have an appended newline, insert a newline. (if (not (zerop (current-column))) (newline)))) (yank) (move-marker (point-marker t) (- start-point chars-up)) (move-marker (mark-marker t) (- start-mark chars-up)) (activate-region)))) ;; already at beginning-of-buffer -- beep and abort (t (move-marker (point-marker t) start-point) (error "Beginning of buffer"))))) ;; no active region -- move just the current line (t (beginning-of-line) ;; beep and abort if at beginning-of-buffer (cond ((eq (point) (point-min)) (move-marker (point-marker t) start-point) (error "Beginning of buffer"))) (let* ((top (point)) (chars-out (- start-point top))) (forward-line 1) ;; if at end-of-buffer on a line with no appended newline, add one (if (not (zerop (current-column))) (newline)) (kill-region top (point)) (forward-line (* -1 numlines)) (yank) (forward-line -1) (beginning-of-line) (forward-char chars-out) (if (eq (symbol-value 'major-mode) 'c++-mode) (if (sit-for 0.25) (c-indent-command))))))) (defun sidle-down (numlines start-point) "Move this line or region downward by numlines (defaults to one)." (interactive "*_p\nd") (cond ((<= numlines 0) (error "Prefix arg must be positive")) ;; if there is an active region, move it rather than just current line ((region-active-p) (let ((orig-top (region-beginning)) (orig-bottom (region-end)) (start-mark (mark))) (move-marker (point-marker t) orig-bottom) ;; If the end-of-region is not at beginning-of-line, ;; move extraction point to after end-of-line. (cond ((not (zerop (current-column))) (beginning-of-line) (forward-line 1))) ;; only take action if the region is not at bottom (cond ((not (eq (point) (point-max))) (let ((bottom (point))) (forward-line numlines) ;; if at end-of-buffer on a line with no appended newline, ;; add one. (if (not (zerop (current-column))) (newline)) (let ((chars-down (- (point) bottom))) (kill-region bottom (point)) (move-marker (point-marker t) orig-top) (beginning-of-line) (yank) (move-marker (point-marker t) (+ start-point chars-down)) (move-marker (mark-marker t) (+ start-mark chars-down)) (activate-region)))) ;; already at end-of-buffer -- beep and abort (t (move-marker (point-marker t) start-point) (error "End of buffer"))))) ;; no active region -- move just the current line (t (beginning-of-line) (let* ((top (point)) (chars-out (- start-point top))) (forward-line 1) ;; beep and abort if at end-of-buffer (cond ((or (not (zerop (current-column))) (eq (point) (point-max))) (move-marker (point-marker t) start-point) (error "End of buffer"))) (kill-region top (point)) (forward-line numlines) ;; if at end-of-buffer on a line with no appended newline, add one (if (not (zerop (current-column))) (newline)) (yank) (forward-line -1) (beginning-of-line) (forward-char chars-out))))) ;; Bind Ctrl-UpArrow to move either the selected region or (if none) the ;; current line upward (maximum of 1 and the prefix-arg) lines. (global-set-key '(control up) 'sidle-up) ;; Bind Ctrl-DownArrow to move either the selected region or (if none) the ;; current line downward (maximum of 1 and the prefix-arg) lines. (global-set-key '(control down) 'sidle-down) ;; http://list-archive.xemacs.org/xemacs/199904/msg00039.html