Dot Emacs

;; John Bear, July 13, 2009
;; ~/Library/Preferences/Aquamacs Emacs/customizations.el
;; is where font initializations are stored.

;;; m-x describe-key is useful for finding out which function is bound to a key sequence.
;;; c-] pops up the lisp stack

;; To use this file, put a copy into your home directory,
;; and name it .emacs  The first character is a dot, and it's
;; very important.  Unfortunately, most Unix systems are set
;; to hide files whose names begin with dot, so if you're trying to
;; see it, you might need to get a shell window and type ls -la 
;; To get a shell window, type M-x shell 

;; From here on down there is stuff which you MIGHT find useful.
;; To try any part, copy it, then type M-x evaluate-expression
;; and then paste (with C-y) the expression into the minibuffer.

;; Contents start here.

(display-time) ; Displays the current time in the bar at the bottom of the buffer.

; (setq mac-option-modifier 'meta) ;; want option key to be meta

;; Here is the elisp command for switching to the nth buffer
;; C-M-l switches to the previous buffer
;; M-*n* C-M-l switches to the *n*th previous buffer
;; For instance, M-1 C-M-l is equiv. to C-M-l
(defun switch-to-previous-buffer (&optional arg)
 (interactive "P")
 (if arg
     (switch-to-buffer (nth arg (buffer-list)))
   (switch-to-buffer (other-buffer))))

(global-set-key "\C-[\C-l" 'switch-to-previous-buffer)          ;;C-M-l

(defun switch-to-third-buffer ()
  (interactive)
  (switch-to-buffer (other-buffer (other-buffer))))

(global-set-key "\C-x\C-\M-l" 'switch-to-third-buffer)

;; This function
;; copies the whole buffer into the kill ring
;; in one fell swoop.  So I do "C-x a" to copy
;; the msg and then in some other window I do Apple-v
;; or Command-v to paste it.
;;
(defun kill-ring-save-whole-buffer (n)
 (interactive "P")
 (let (beg end)
  (beginning-of-buffer)
  (setq beg (point))
  (end-of-buffer)
  (setq end (point))
;  (mark-whole-buffer beg end)
  (kill-ring-save beg end)
 ))

(global-set-key "\C-xa" 'kill-ring-save-whole-buffer)

(setq x-select-enable-clipboard t) ; allow copying between apps
;; in R do dev.off() to close the file after doing plot or curve.

(add-hook
 'inferior-ess-mode-hook
 '(lambda ()
    (define-key inferior-ess-mode-map "\C-\M-l" 'switch-to-previous-buffer) ;C-M-L
  ))

(defun sweave-template ()
  (interactive)
  (insert
"% -*- mode: noweb; noweb-default-code-mode: R-mode; -*-
\\documentclass[11pt]{article}

\\usepackage{geometry}

% See geometry.pdf to learn the layout options. There are lots.

\\geometry{letterpaper}                   % ... or a4paper or a5paper or ...

%\\geometry{landscape}                % Activate for for rotated page geometry
%\\usepackage[parfill]{parskip}    % Activate to begin paragraphs with an empty line rather than an indent
\\usepackage{graphicx}
\\usepackage{amssymb}
\\usepackage{epstopdf}
\\usepackage{verbatim}
\\usepackage{float}
% verbatim package is required for \\begin{comment} and \\end{comment}
% verbatim package is required for \\begin{comment} and \\end{comment}
\\let\\remark=\\comment % This makes it so \\begin{remark} makes text not show up
\\let\\endremark=\\endcomment
%\\renewenvironment{remark}{}{}  % This resets remarks to show up again.
\\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}

%\\SweaveOpts{height=4.0}
\\title{Title}
\\author{John Bear <jb@johnbear.net>}
% \\author{Dean Billheimer <dean.billheimer@arizona.edu>}
%\\date{}                                     % Activate to display a given date or no date

\\begin{document}
\\maketitle

<<>>=
print('Hello')
@
\\end{document}
")
;; The next few lines put the cursor into the R code region so that
;; Aquamacs will know that you might want to start R, and it should
;; put a Start-R icon in the top menu bar.
(search-backward "<<>>=")
(end-of-line)
(forward-char)
(Rnw-mode)
;(initialize-colors)
)