;; Paul Johnson ;; 2011-01-09 ;; This updates my previous startup option file that was called ;; 50emacs-ess-ku.el. Either you should put this file in your ;; Emacs site-start.d folder or put it in your home directory ;; and call it .emacs. ;; If you are using this because you use Emacs to work with R, the ;; main special features are: ;; 1. Shift+Enter will send the current line to R, and it will start ;; R if it is not running. ;; 2. R will start in the current working directory, without stopping ;; to ask the user about a working directory. ;; 2. R runs in its own "frame" ;; 3. Emacs help information pops up in its own frame. ;; This is my .emacs file, it is a collection of special tricks I've ;; learned by complaining to Emacs users. It makes Emacs easy for me ;; to use. If you try this file, I believe you can use Emacs without ;; knowing any Lisp and without even reading the Emacs tutorial. The ;; intention is to make Emacs work more like a "modern" GUI editor. I ;; don't want it to try to supply a window manager or re-design the ;; keyboard and mouse. I respect the long heritage of Emacs and its ;; extensibility, but I don't need those legacy features that were ;; written before modern computers were invented. I agree with the ;; idea behind "oneonone Emacs" ;; (http://www.emacswiki.org/emacs/OneOnOneEmacs), but think it is too ;; difficult to implement and maintain. ;; I've never liked the complicated system of "mark" and "point" for ;; text selection and I don't generally use any of the multi-click ;; keyboard commands. Any "shortcut" that requires me to type several ;; keys is not really a shortcut. It is not easier to type C-x C-f ;; that it is to click "File" with the mouse. I do use some single ;; key-combination shortcuts, like M-q to "reformat region". ;; I started on this because I was constantly aggravated that files on ;; which I was working would get covered over by new material from ;; Emacs. I completely hate that. I want new content to pop new ;; panels and/or windows wherever possible. When I do M-x to open the ;; command mini-buffer, and then I type a letter or two and hit TAB, I ;; want to leave my document undisturbed on the screen. I want the ;; options resulting from the TAB to appear in their own window, which ;; automatically disappears after I make my choice. ;; The only exception below is caused by a bug in Emacs for ;; Windows. The file selection GUI is broken, so the file dialog is ;; turned off. ;; I've added comments for the commands below, you can read them if ;; you are curious what they do. (if (eq system-type 'windows-nt) (setq use-file-dialog nil)) ; necessary on windows b/c dialog bug ; make mouse selection work in the usual Mac/Windows way (require 'pc-select) (transient-mark-mode t) ; highlight text selection (delete-selection-mode t) ; delete seleted text when typing (cua-mode t) ; windows style keybind C-x, C-v, cut paste (setq cua-auto-tabify-rectangles nil) ;; Don't tabify after rectangle commands (setq cua-keep-region-after-copy t) ;; Selection remains after C-c ;; Stop Emacs from splitting "frames", encourage it to pop up new ; frames for new content. ; see: http://www.gnu.org/software/emacs/elisp/html_node/Choosing-Window.html (setq pop-up-frames t) (setq special-display-popup-frame t) (setq split-window-preferred-function nil) ;discourage horizontal splits (setq pop-up-windows nil) ;; Wow. "pop-up-frames" is different from "framepop". Crazy! ;; The framepop package can "catch" some special small buffers and ;; divert them off to a specially configured frame. I made it pink! ;; The framepop packages is in emacs-goodies on Ubuntu, I hope ;; it is installed in whatever system I use. If it is installed ;; the following causes useful changes in the way special frames are ;; delivered. It doesn't get all special frames, such as "grep". ;; But it does grab tab completions. That's a big plus. (require 'advice) (when window-system (require 'framepop) (framepop-enable)) (setq framepop-frame-parameters '((name . nil) ; use buffer name (unsplittable . t) ; always include this (menu-bar-lines . 0) ; no menu bar (minibuffer . nil) ; or minubuffer (left . -1) ; top left corner of screen, (top . 30) ; away from my main frame (width . 71) ; narrower, so it fits nicely (background-color . "MistyRose") ; for October. (tool-bar-lines . 0) (minibuffer))) (setq framepop-min-frame-size 20) (setq framepop-use-advice (quote automatic)) (setq framepop-auto-resize t) ;; Framepop does not catch all of the frames you want. It will ;; pop up full sized frames for little lists. . ;; I see no benefit in it. (setq special-display-buffer-names '("*Help*" "*shell*" "*Completions*" "*grep*" "*tex-shell*")) ;; I wish I could make all new files & buffers appear in separate frames. ;; But I can't find a way. But I can make files opened from the menu bar ;; appear in their own frames. This overrides the default menu bar settings. ;; Opening an existing file and creating new one in a new frame are the exact ;; same operations. ;; adapted from Emacs menu-bar.el (defun menu-find-existing () "Edit the existing file FILENAME." (interactive) (let* ((mustmatch (not (and (fboundp 'x-uses-old-gtk-dialog) (x-uses-old-gtk-dialog)))) (filename (car (find-file-read-args "Find file: " mustmatch)))) (if mustmatch (find-file-other-frame filename) (find-file filename)))) (define-key menu-bar-file-menu [new-file] '(menu-item "New..." find-file-other-frame :enable (menu-bar-non-minibuffer-window-p) :help "Create a new file")) (define-key menu-bar-file-menu [open-file] `(menu-item ,(purecopy "Open File...") menu-find-existing :enable (menu-bar-non-minibuffer-window-p) :help ,(purecopy "Read an existing file into an Emacs buffer"))) ;(define-key menu-bar-file-menu [open-file] ; '(menu-item "Open File..." find-file-other-frame ; :enable (menu-bar-non-minibuffer-window-p) ; :help "Open Existing File")) ;;Open directory list in new frame. (define-key menu-bar-file-menu [dired] '(menu-item "Open Directory..." dired-other-frame :help "Read a directory; operate on its files (Dired)" :enable (not (window-minibuffer-p (frame-selected-window menu-updating-frame))))) ;; Remove "splash screen" ;; http://fuhm.livejournal.com/ (defadvice command-line-normalize-file-name (before kill-stupid-startup-screen activate) (setq inhibit-startup-screen t)) (setq inhibit-splash-screen t) ;; Default Emacs does not scroll pages smoothly with down arrow key. ; It tries to jump a page-worth. ; See this for advice on preventing that ; http://stackoverflow.com/questions/3631220/fix-to-get-smooth-scrolling-in-emacs (setq redisplay-dont-pause t) (setq scroll-conservatively 20) (setq scroll-margin 2) (setq scroll-preserve-screen-position 1) ;; programming conveniences: (show-paren-mode t) ; light-up matching parens (global-font-lock-mode t) ; turn on syntax highlight (setq text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify))) ;; ;;(setq default-frame-alist '((width . 90) (height . 65))) ;; ESS for R customization begins here: (setq inferior-ess-own-frame t) (setq inferior-ess-same-window nil) ;;; ;;;;;create a new frame for each help instance ;;; ;;(setq ess-help-own-frame t) ;;;;;If you want all help ;;;;; buffers to go into one frame do: ;;; (setq ess-help-own-frame 'one) ;; minibuffer tips ;;(require 'ess-eldoc) ;; html help ; (setq inferior-ess-r-help-command "help(\"%s\", help_type=\"html\")\n") ;;start R in current working directory (setq ess-ask-for-ess-directory nil) (setq ess-local-process-name "R") ;; cause "Shift+Enter" to send the current line to *R* (defun my-ess-eval () (interactive) (if (and transient-mark-mode mark-active) (call-interactively 'ess-eval-region) (call-interactively 'ess-eval-line-and-step))) (add-hook 'ess-mode-hook '(lambda() (local-set-key [(shift return)] 'my-ess-eval))) ;;http://stackoverflow.com/questions/840279/passwords-in-emacs-tramp-mode-editing ;; Emacs "tramp" service (ssh connection) constantly ;; asks for the log in password without this (setq password-cache-expiry nil) ;; I'm right handed, need scroll bar on right (like other programs) (setq scroll-bar-mode-explicit t) (set-scroll-bar-mode `right) (setq ansi-color-for-comint-mode 'filter) (setq comint-prompt-read-only t) (setq comint-scroll-to-bottom-on-input t) (setq comint-scroll-to-bottom-on-output t) (setq comint-move-point-for-output t)