You are on page 1of 72

Emacs

1 / 72

Emacs Has No Learning Curve
Emacs and ESS Paul E. Johnson1
1 Department 2 Center

2

of Political Science

for Research Methods and Data Analysis, University of Kansas

2012

Emacs

2 / 72

Outline

1 Why Use Emacs? 2 Emacs Anatomy 3 No Learning Curve 4 ESS 5 Conclusion

Emacs Why Use Emacs?

3 / 72

Outline

1 Why Use Emacs? 2 Emacs Anatomy 3 No Learning Curve 4 ESS 5 Conclusion

) Across Time: Will Always Exist (because eager fanatics maintain it) Free & Open Source . Linux. Unix.... Mac. Atari.Emacs Why Use Emacs? 4 / 72 Why Use Emacs? Multidimensional Availability All Platforms (Windows.

Emacs Why Use Emacs? 5 / 72 Why Use Emacs? Super Tools Emacs has “major modes” for most languages and types of A files (C. insert columns Enormous power to edit very large files At some point in the future.). . Incredibly powerful text management tools “compare” documents or buffers Regular expression search and replace (even across many files) Copy. R. . Stata. paste. L TEX. C++. SAS. Prepare for that time by using Emacs for other projects as well! . you may find that the only editor that is capable for a particular project is Emacs. . Lisp. English.

o b j e c t name c o m p l e t i o n . and s y n t a x − b a s e d h i g h l i g h t i n g o f t h e i n t e r a c t i o n b u f f e r u s i n g Font Lock mode . d e f i n i t e l y . Of c o u r s e .15. a s w e l l a s a v e r y c o n v e n i e n t i n t e r f a c e to the R help system. 2 S h o u l d I r u n R from w i t h i n Emacs ? Yes . i t a l s o i n t e g r a t e s n i c e l y w i t h t h e mechanisms f o r e d i t i n g R s o u r c e u s i n g Emacs. t h i s i s h e l p f u l f o r b o t h d a t a a n a l y s i s and . One can w r i t e code i n one Emacs b u f f e r and send whole or p a r t s of i t f o r e x e c u t i o n to R . I n f e r i o r R mode p r o v i d e s a r e a d l i n e / h i s t o r y mechanism .2012-09-19): 6 . by Kurt Hornik (Version 2.Emacs Why Use Emacs? 6 / 72 Check the R FAQ R FAQ.

i t a l l o w s you t o k e e p a r e c o r d o f y o u r s e s s i o n . a s w e l l a s t o a l l o w f o r t h e r e t r i e v a l of past v e r s i o n s of the code. i n o r d e r t o maintain a l o g of changes i n your programs and data .Emacs Why Use Emacs? 7 / 72 Check the R FAQ . One can a l s o s e a m l e s s l y i n t e g r a t e w i t h a r e v i s i o n c o n t r o l system . I n a d d i t i o n . w h i c h can a l s o be u s e d f o r e r r o r r e c o v e r y through the use of the t r a n s c r i p t mode.. p r o g r a m m i n g . ..

Emacs Emacs Anatomy 8 / 72 Outline 1 Why Use Emacs? 2 Emacs Anatomy 3 No Learning Curve 4 ESS 5 Conclusion .

Status Bar 4. Here’s What I See 1: Pull Down Menus 2. Button Bar 3. Mini-buffer .Emacs Emacs Anatomy 9 / 72 Start Emacs.

You can have 2 “windows” showing same “buffer” Choose File -> New Frame Choose Menu Buffers to select a buffer to display in the currently focused Window . Chose File -> Split Window.Emacs Emacs Anatomy 10 / 72 Terminology Frame: That “whole thing”.” the collection of letters and words that can be shown inside a window. Check for yourself. Window: The content display area inside a frame Buffer: A chunk of “content.

Then type a command and hit return) . A display of R code should differ from Lisp or Java Emacs will guess the mode you want from the file extension (if you open a file) Or you can specify the mode while inside the session Type M-x ( “meta” (usually the Alt key) and the letter x at the same time) and then enter a valid mode. release both keys.Emacs Emacs Anatomy 11 / 72 Emacs ”Major Mode” system We want the editor to customize itself to the language we are working with. (Hit Alt with x.

Emacs Emacs Anatomy 12 / 72 Emacs ”Major Mode” system Test some major modes for yourself. M-x M-x M-x M-x text-mode c-mode tex-mode R-mode .

Emacs No Learning Curve 13 / 72 Outline 1 Why Use Emacs? 2 Emacs Anatomy 3 No Learning Curve 4 ESS 5 Conclusion .

and make Emacs seem difficult to learn Hence the prevalence of “Emacs cheat sheets” floating about on the Internet .Emacs No Learning Curve 14 / 72 Understand the History of Emacs Emacs was created in the days before mice multi-windowed “desktop” environments Windows or Macintosh computers Emacs still has ability to work in a no-picture. and (M) Meta key (usually “Alt” ) These are are featured in the Emacs tutorial. no-mouse “terminal” mode There are many key board combinations using (C) Control. (S) Shift (S).

and I’ll handle most of that for you. more-or-less like other Editors. It is tremendously programmable. Settings that seem unusual can usually be changed. most people can use Emacs comfortably even if they don’t customize it. Emacs will run with pull down menus. or Linux system with X11 display. Mac. Its just a text editor with lots of great features (most of which you will never need).Emacs No Learning Curve 15 / 72 Properly Understood. the Emacs Learning Curve is NOT STEEP Assume the user has the version of Emacs for Windows. .

if you need them. or Type “M->” (Alt. because Emacs now has menus and buttons.. Shift and the greater-than sign) to go to the bottom . You can learn key-stroke combinations later. or Type C-x h (Control-x. Choose select all. (Why “h” for select all?) What’s easier to remember? Hit the “page down” key on the keyboard for a few seconds and watch a file fly by. What’s easier to remember? Click the Edit Menu. release both keys. But you don’t need most of them now..Emacs No Learning Curve 16 / 72 Don’t Listen To People Who Want You To Memorize C-x C-g C-h whatever. then the letter “h” ) I use the first way.

Emacs No Learning Curve 17 / 72 Don’t Listen To People Who Want You To Memorize C-x C-g C-h whatever..000 lines and M-> would have been useful.. .. Yesterday I had R output that was 150.. . I usually just hit “page down” for a moment.

4all2u. C−k delete r e s t of l i n e < Delete > d e l e t e t h e c h a r a c t e r j u s t b e f o r e t h e cursor C−d d e l e t e the next ch arac t er a f t e r the cursor .com/work/emacs.Emacs No Learning Curve 18 / 72 Example of Previous Here is an example from “Experienced Programmers Introduction to Emacs” http://weatherall.htm Now t o a more c o n v e n t i o n a l l e a r n i n g o r d e r C−a move t o b e g i n n i n g o f l i n e C−e move t o end o f l i n e M−< move t o t h e b e g i n n i n g o f t h e f i l e M− > move t o t h e end o f t h e t u t o r i a l .

The HOME and END keys work fine. and the arrow keys in the obvious ways. Note frequent needs.Emacs No Learning Curve 19 / 72 Example of Previous . I’d feel helpless when I had to use some other editor. To do those things. Or arrow keys.. if you remember them. New users should not become preoccupied with memorizing C. in grad school) I don’t deny the keystrokes might be faster. delete key. If I did. I don’t use Control key combinations that are unique to Emacs very often. M and S sequences. then learn those keystrokes. I use the mouse. . and no mouse! (as it was in 1982. I would only need C-a if I had no arrow keys..

.Emacs No Learning Curve 20 / 72 Another Intimidating Example Useful Emacs bits ’n’ bobs http://www. r e g i o n s e l e c t i o n ) C−w: c u t r e g i o n ( s t d emacs ) . s e e abo v e r e . .insectnation.org/howto/emacs-tips Here ' s a few handy k e y c o m b i n a t i o n s I w i s h I ' d been t o l d a b o u t when I s t a r t e d u s i n g emacs : C−g o r ESC ESC ESC : c a n c e l m i n i b r o w s e r s e s s i o n C−s : s e a r c h f o r t e x t C−r : s e a r c h f o r t e x t b a c k w a r d s C−%: r e p l a c e t e x t ( p r e s s s p a c e t o okay e a c h suggested instance C−M−%: r e p l a c e r e g e x ( p r e s s s p a c e t o okay e a c h suggested instance C− [ s p a c e ] : p l a c e mark ( I don ' t u s e t h i s .

Emacs No Learning Curve 21 / 72 Another Intimidating Example . M−w: copy r e g i o n ( s t d emacs ) C−k : c u t l i n e C−y : p a s t e ( yank ) C − l : r e c e n t r e b u f f e r window v e r t i c a l l y a r o u n d active line C−x C−f : open ( f i n d ) f i l e i n b u f f e r C−x C−s : s a v e b u f f e r t o f i l e C−x C−w: s a v e b u f f e r t o new f i l e C−x C−z : s t o p ( p a u s e ) emacs p r o c e s s ( r e − s t a r t with s h e l l fg ) C−x k : k i l l b u f f e r C−x b : c ha ng e a c t i v e b u f f e r C−x 1 : d i s p l a y o n l y c u r r e n t b u f f e r window C−x 2 : s p l i t b u f f e r window C−x 0 : k i l l c u r r e n t b u f f e r pane C−x 4 f : open f i l e i n new window ...

Emacs No Learning Curve 22 / 72 Another Intimidating Example .. C−x C−x C−x C−x C−x C−x C−x M−x 4 b : open b u f f e r i n new window 5 2 : open new f r a m e 5 0 : k i l l c u r r e n t frame 5 f : open f i l e i n new f r a m e 5 b : open b u f f e r i n new f r a m e o : s w i t c h between a c t i v e sub − window D : e n t e r t h e v e r y n i f t y dired − mode glo bal − font − lock − mo de : t o g g l e s y n t a x highlighting M−x perl − mode : a l o t o f co de h i g h l i g h t s f a i r l y w e l l i n P e r l mode M−x g o t o − l i n e : jump t o l i n e F10 : a c c e s s menus i n t e x t mode ( v i a t h e minibuffer ) M−x b y t e − c o m p i l e − f i l e . e m a c s : c o m p i l e . e m a c s o r another e l i s p f i l e for f a s t e r operation ..

Emacs No Learning Curve

23 / 72

Avoid the Emacs Tutorial Until Later
Emacs provides a nearly complete desktop environment that most of us don’t need. The Emacs tutorial emphasizes memorization of keystrokes that are not truly necessary to use Emacs. So don’t. Instead, listen to me! Use my init file. Make Emacs behave in a more familiar way.
scroll up and down with the mouse or arrow keys copy, cut and paste regions with the mouse or the usual keyboard shortcuts

We don’t have to sacrifice on any of the other very powerful features of Emacs Emacs enthusiasts are able to remember hundreds of key combinations, but I can’t.

Emacs No Learning Curve

24 / 72

Avoid the Emacs Tutorial Until Later ...

Some enthusiasts write Lisp code for a living, but I think Lisp stands for “lots of irritating, stupid parentheses.”

Emacs No Learning Curve

25 / 72

Example of Easily Fixed ”Problem”
People are accustomed to cut and paste keys (from MS or Macintosh): keystroke result C-x cut C-c copy C-v paste C-z undo Emacs default keystrokes are keystroke result C-w cut ( “wipe” in Emacs-speak) M-w copy C-y paste ( “yank” in Emacs-speak) Cundo

C-z do what you expect.Emacs No Learning Curve 26 / 72 Example of Easily Fixed ”Problem” . or Make it permanent: Add this in your Emacs startup configuration ( cua − mode t ) Potential problem to keep in mind: Emacs has many keystroke combinations that use C and M and anything we do to “override” them may cause trouble. C-c. Fix. or M-x cua-mode. 3 ways to turn on CUA mode. C-v. Click Options and choose CUA. Turn on “CUA mode” in Emacs. . But most of these bugs have been solved. Will make C-x. In most recent Emacs...

As an example of a bug.. choose Tutorial). The tutorial presumes you can type C-v to go to the next “page” (in the old-fashioned terminal sense of displaying the next “screen sized chunk”). . (Click the Emacs Help menu. try to read the Emacs Tutorial with CUA mode on. that the Emacs tutorial is addressed to a much different user audience than this presentation. Of course.Emacs No Learning Curve 27 / 72 Example of Easily Fixed ”Problem” . the fact that the first thing in the Emacs tutorial is how to see the “next screen” with C-v illustrates my previous point. It is necessary to turn off CUA mode to make any progress inside the Emacs tutorial..

or pasted. Emacs has an elaborate system to select “rectangular” sections. but it is difficult to use Here is the CUA way. Sometimes. especially when revising text that includes tables or columns. That rectangular block can be copied. this can be very handy. Move the cursor “top left” of a rectangle you want to select Hit “C-return” Use arrow keys to expand rectangle. Highlight will display a rectangle. . cut. This is a secret power of CUA mode.Emacs No Learning Curve 28 / 72 CUA mode Rectangular Selection Super-Power There are just a few times when it would be really handy to highlight a rectangular column of text and copy and paste it.

emacs.el On systems I don’t administer.el .d/init.freefaculty. I generally customize the system-wide settings with my personal favorite settings http://pj. I urge my users to install my configuration settings file. or . it reads a series of configuration files Some are “system-wide” Some are user specific On systems I administer. either in .org/Software/Emacs/ 50emacs-ess-ku.Emacs No Learning Curve 29 / 72 Customizations I Recommend When Emacs starts. They they can share in my hard-found victory The user settings can be stored in the user’s home folder.emacs.

. Speaks S t a t i s t i c s ) with R .e s s . if 3. ..... If you try this file . Either you should put this file in your Emacs s i t e .. . f r e e f a c u l t y . I believe you can use Emacs without knowing any Lisp and without even reading the Emacs tutorial . d folder or put it in your home d i r ec t o r y and call it ".. but think it is too d i ff i c u l t to i m p l e m e n t and maintain .. .. without stopping ask the user about a working d i r e c t or y .. .. edu > 2012-08-23 This is my .s t a r t . to I n d e n t a t i o n policy follows P r o g r a m m i n g R E x t e n s i o n s Manual Shift + Enter will send the current line to R . It makes Emacs easy for me to use . . The i n t en t i o n is to make Emacs work more like a " modern " GUI editor .. emacs ". emacs . here are my special features . .. . e m ac s w i k i . .. . emacs startup file .. and it will start R it is not running . 2.. R will start in the current working directory .. d . I ' m just trying to tidy up Paul Johnson < p a u l j o h n @ k u . . If you are using this because you use Emacs to use ESS ( Emacs . . . . . Or re-name it " init .Emacs No Learning Curve 30 / 72 Here’s my Emacs init file (on my laptop 2012-08-23) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 .. 1.. . . . . . .k u . This is a testing version . el " and copy it into a new d i re c t o r y in your Home folder called .. will go up to http : / / pj .. org / Software / Emacs / 50 e m a c s .. . I agree with the idea behind " oneonone Emacs " ( http : / / www .. org / emacs / O n e O n O n e E m a c s ) . el Nothing is new here . . . .

. R runs in its own " frame " . . .. . Don ' t tabify after r e c t a n g le commands ( s e t q cua − keep − region − after − copy t ) . Section I . h ig h l i g h t text s el e c t i o n ( d e l e t e − s e l e c t i o n − m o d e t ) . . . 5. Keyboard and mouse c u s t o m i z a t i o n .Emacs No Learning Curve 31 / 72 Here’s my Emacs init file (on my laptop 2012-08-23) . Windows OS w o r k . C-z . replaces p c . S e l ec t i o n remains after C-c . 4. There ' s a problem with file s el e c t i o n dialogs on Windows .s el e c t ) ( s e t q s h i f t − s e l e c t − m o d e t ) .a r o u n d s ( i f ( eq system − type ' windows − nt ) ( setq use−file−dialog n i l ) ) . . . . . Section II . IIA : make mouse s e l e ct i o n work in the usual Mac / Windows way .s e l e c t ( transient − mark − mode t ) .( require ' p c . is default in Emacs 23+ . C-c . Emacs help pops up in its own frame . cut paste ( s e t q c u a − a u t o − t a b i f y − r e c t a n g l e s n i l ) . windows style binding C-x . . IIB : keyboard c u s t o m i z a t i o n ( cua−mode t ) . C-v . . delete seleted text when typing . 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 .

( setq e s s .o w n . . . turn on syntax h i g h l i g h t i n g ( s e t q text − mode − hook ( q u o t e ( t u r n − o n − a u t o − f i l l text − mode − hook − identify ) ) ) . create a new frame for each help instance . .c o m m a n d " help (\"% s \" .( require ' e s s . ESS Emacs S t a t i s t i c s .f r a m e t ) . always show line numbers .h e l p .h e l p .r . write line numbers on left of window . m i n i b u f f e r tips : will work in future . .. If you want all help buffers to go into one frame do : ( s e t q ess − help − own − frame ' one ) .( setq i n f e r i o r .. . .f r a m e t ) ( s e t q inferior − ess − same − window n i l ) . . . Section III . . html help . h e l p _ t y pe =\" html \") \ n ") .Emacs No Learning Curve 32 / 72 Here’s my Emacs init file (on my laptop 2012-08-23) . ( setq i n f e r i o r .e s s .o w n .e s s . 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 . Section IV . ( g l o b a l . light-up matching parens ( global − font − lock − mode t ) .el d o c ) . P r o g r a m m i n g c o n v e n i e n c e s : ( show − paren − mode t ) .m o d e 1) . . .l i n u m .

w h i t e s p a c e . PJ 2 0 1 2 . . or even . 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 . . .0 3 .2 1 Follow advice in P r o g r a m m i n g R E x t e n s i o n s : Use .p ' ask ) . ..n u k e .. i n d e n t a t i o n in C ++ style ( add − hook ' ess − mode − hook ( lambda ( ) ( e s s − s e t − s t y l e ' C++ ' q u i e t ) ( add − hook ' l o c a l − w r i t e − f i l e − h o o k s ( lambda ( ) ( ess−nuke−trailing−whitespace ) ) ) ) ) .t r a i l i n g .( setq e s s . . start R in current working directory . don ' t ask user ( setq ess−ask−for−ess−directory n i l ) ( s e t q ess − local − process − name ”R ”) . cause " Shift + Enter " to send the current line to ( d e f u n my − ess − eval ( ) ( interactive ) ( i f ( and transient − mark − mode m a r k − a c t i v e ) ( c a l l − i n t e r a c t i v e l y ' ess−eval−region ) ( c a l l − i n t e r a c t i v e l y ' ess − eval − line − and − step ) ) ) ( add − hook ' ess − mode − hook ' ( lambda ( ) ( local−set−key [ ( s h i f t r e t u r n ) ] *R* ' my − ess − eval ) )) . .Emacs No Learning Curve 33 / 72 Here’s my Emacs init file (on my laptop 2012-08-23) .

A : D i s c o u r a g e Emacs from s p l i t t in g " frames " . pop up new frames for new content . d i s c o u r a g e h o r i z o n t a l splits ( s e t q pop − up − windows n i l ) . I try to make this check to see if the feature is . V . . http : / / www . see : .Emacs No Learning Curve 34 / 72 Here’s my Emacs init file (on my laptop 2012-08-23) .u p . . gnu . . i n st a l l e d . . . . C u s t om i z e the use of Frames . e n c o u r a ge it to .. have " framepop ". . appear in wholly new frames on screen . Try to make new content ..W i n d o w . V . . .. Some users don ' t . . . Crazy ! The framepop package can " catch " some special small buffers . org / software / emacs / elisp / h t m l _n o d e / C h o o s i n g . 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 ( s e t q ess−nuke−trailing−whitespace−p t ) . . html ( s e t q pop − up − frames t ) ( s e t q special−display−popup−frame t ) ( s e t q s p l i t − w i n d o w − p r e f e r r e d − f u n c t i o n n i l ) . . .. . Perl ( add − hook ' perl − mode − hook ( lambda ( ) ( s e t q p e r l − i n d e n t − l e v e l 4 ) ) ) . Note that " p o p . Section V . End ESS .f r a m e s " is d if f e r e n t from " framepop ".. B : Use " framepop " to pop up small frame messages . .

t) . ( when ( r e q u i r e ' a d v i c e ) ( when window − system ( when ( r e q u i r e ' f r a m e p o p n i l ( framepop−enable ) ) ) ) I made it pink ! ' noerror ) . it is OK to leave these . . use buffer name ( unsplittable . no menu bar ( minibuffer . Even if you don ' t have framepop . . . so it fits nicely ( b a c k g r o u n d − c o l o r . n i l ) . The framepop packages is in e m a c s . 0 ) . Stops framepop from fiddling with a few specific buffer types . narrower .. 0) ( minibuffer ) ) ) ( s e t q framepop − min − frame − size 2 0 ) ( s e t q framepop − use − advice ( q u o t e a u t o m a t i c ) ) ( s e t q framepop−auto−resize t ) . or m i n u b u f f e r ( l e f t .. ( tool−bar−lines . ( s e t q framepop − frame − parameters ' ( ( name . 71) . −1) . and divert them off to a s p e ci a l l y c o n f i g u r e d frame . nil ) . ”M i s t y R o s e ”) . ( top . always include this ( menu − bar − lines . . ( setq special−display−buffer−names . 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 . away from my main frame ( width . . top left corner of screen ..Emacs No Learning Curve 35 / 72 Here’s my Emacs init file (on my laptop 2012-08-23) . .g o o d i e s on Ubuntu . for October . 30) .

. V . 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 '( ”* H e l p * ” ”* s h e l l * ” ”* C o m p l e t i o n s * ” ”* g r e p * ” ”* t e x − s h e l l * ”) ) . Opening an . .. ' ( m en u ... ex isting file and creating new one in a new frame are the exact . .k e y m e n u . .( d e f i n e .b a r . frames . ( p u r e c o p y ”Read an e x i s t i n g f i l e i n t o an Emacs b u f f e r ”) ) ) . same o p e r a t i o n s . C : Make files opened from the menu bar appear in their own . ”) m e n u − f i n d − e x i s t i n g : e n a b l e ( menu − bar − non − minibuffer − window − p ) : h e l p . .i t e m " Open File . .f i l e ..Emacs No Learning Curve 36 / 72 Here’s my Emacs init file (on my laptop 2012-08-23) . el ( defun menu−find−existing ( ) ”E d i t t h e e x i s t i n g f i l e FILENAME . ( p u r e c o p y ”Open F i l e .m e n u [ o p e n -f i l e ] . ." f i n d . ” ( interactive ) ( l e t * ( ( mustmatch ( n o t ( and ( f b o u n d p ' x − uses − old − gtk − dialog ) ( x − uses − old − gtk − dialog ) ) ) ) ( f i l e n a m e ( c a r ( f i n d − f i l e − r e a d − a r g s ”F i n d f i l e : ” mustmatch ) ) ) ) ( i f mustmatch ( find−file−other−frame filename ) ( find−file filename ) ) ) ) ( d e f i n e − k e y menu − bar − file − menu [ n e w − f i l e ] ' ( menu − item ”Open/ C r e a t e ” f i n d − f i l e − o t h e r − f r a m e : e n a b l e ( menu − bar − non − minibuffer − window − p ) : h e l p ”C r e a t e a new f i l e ”) ) ( d e f i n e − k e y menu − bar − file − menu [ o p e n − f i l e ] ' ( menu − item .f r a m e . This o v e r r i d e s the default menu bar settings . .f i l e . adapted from Emacs menu-bar .o t h e r .

n o n . Section VI : M i s c e l l a n e o u s c o n v e n i e n c e ...w i n d o w . . . . : enable ( m e n u .m i n i b u f f e r . com / ( d e f a d v i c e command − line − normalize − file − name ( before kill−stupid−startup−screen activate ) ( setq inhibit−startup−screen t ) ) ( setq inhibit−splash−screen t ) . http : / / www . Remove Emacs " splash screen " . V . D Open d i re c t o r y list in new frame . ..a r t i c l e s / 549 ( s e t q f r a m e − t i t l e − f o r m a t ”%b − Emacs ”) . com / m a i n . http : / / fuhm . . . o p e r a t e on i t s f i l e s ( D i r e d ) ” : e n a b l e ( n o t ( window − minibuffer − p ( frame − selected − window menu − updating − frame ))))) . 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 . . Show file name in title bar . . ..Emacs No Learning Curve 37 / 72 Here’s my Emacs init file (on my laptop 2012-08-23) . ” d i r e d − o t h e r − f r a m e : h e l p ”Read a d i r e c t o r y .p ) : help " Open Existing File ") ) . l i v e j o u r n a l . t h e t e c h r e p o .b a r . ( d e f i n e − k e y menu − bar − file − menu [ d i r e d ] ' ( menu − item ”Open D i r e c t o r y .

a l i s t ' (( width ..45 http : / / www . 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 . 90) ( height . org / s / emacs / e m a c s. com / q u e s ti o n s / 840279 / passwords-in-emacs-tramp-mode-editing . asks for the log in password without this ( s e t q password−cache−expiry n i l ) . .0 5 . 65) ) ) . Make Emacs scroll smoothly with down arrow key . need scroll bar on right ( like other programs ) ( setq scroll−bar−mode−explicit t ) ( set − scroll − bar − mode ` r i g h t ) .f a q . adjust values . http : / / s t a c k o v e r f l o w .( setq d e f a u l t . testing faq 5. . .2011-10-14 . PJ 2 0 1 1 . . . html # Modifying-pull_002ddown-menus ( s e t q s c r o l l − c o n s e r v a t i v e l y most−positive−fixnum ) .1 5 . . Re member password when c o n n e c t e d to remote sites via Tramp .Emacs No Learning Curve 38 / 72 Here’s my Emacs init file (on my laptop 2012-08-23) . Emacs " tramp " service ( ssh c o n n e c t i o n ) c o n s t a n t l y . . . u n c o m me n t this . gnu . . .f r a m e .. If you want to adjust the size of the frames . I ' m right handed . . .

. .( setq e s s . . Section : Emacs shells work better . . org / w h y _ i _ r u n _ s h e l l s _ i n s i d e _ e m a c s ( s e t q ansi − color − for − comint − mode ' f i l t e r ) ( s e t q comint − prompt − read − only t ) ( s e t q comint − scroll − to − bottom − on − input t ) ( s e t q comint − scroll − to − bottom − on − output t ) ( s e t q comint − move − point − for − output t ) .. .. built into Emacs = = = = = = = = = = = = = = = = = = Ke yboard a c c e l e r a t o r M .. http : / / snarfed .Emacs No Learning Curve 39 / 72 Here’s my Emacs init file (on my laptop 2012-08-23) . ============================================================= From Marc Schwartz Set keys for ' windmove ' .v a r i a b l e s . ...d i r e c t i o n will " scroll " through buffers . . .( c u s t o m . ============================================================= ' meta ) ( windmove−default−keybindings ( g l o b a l − s e t − k e y ( kbd ” M− <up> ”) ' windmove − up ) ( g l o b a l − s e t − k e y ( kbd ” M− <down> ”) ' windmove − down ) . 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 . . Easier to remember than other ways .p d f l a t e x .c o m m a n d s ' (" pdflatex " " make ") ) ..s w v ...s e t . . .

. 266 267 ( g l o b a l − s e t − k e y ( kbd ” M− < r i g h t > ”) ' windmove − right ) ( g l o b a l − s e t − k e y ( kbd ” M− < l e f t > ”) ' w i n d m o v e − l e f t ) .Emacs No Learning Curve 40 / 72 Here’s my Emacs init file (on my laptop 2012-08-23) ..

h i g h l i g h t t e x t selection ( delete−selection−mode t ) . . d e l e t e s e l e t e d t e x t when t y p i n g As far as I can tell. These lines in the startup configuration can (basically) completely solve the problem ( setq shift−select−mode t ) ( transient − mark − mode t ) . so I’m just “making sure” they are still set that way.Emacs No Learning Curve 41 / 72 Another Easily Fixed ”Problem” Selection of text in base Emacs used to be very different from other editors Several settings can be used to make selection work in a way that is more familiar to users (Emacs defaults are migrating in that direction). the first two became defaults in Emacs-23.

. : for a selected region. M-q : re-shapes an ill-formed paragraph M-. will “comment” and “uncomment” all lines. C-g : get out of jail free. this is easier than the menu Edit -> Search (C-r searches in reverse) M-%: Query replace C-M-%: Regular-Expression Query replace (can’t live without them) M-x: execute commands. If you mistakenly start something in the minibuffer. C-g gets out of it. it is easier to find them in a menu or type them by name. But for things that I only do once every 6 months.Emacs No Learning Curve 42 / 72 Shortcuts I do remember There are some keyboard shortcuts I do remember C-s: I search frequently.

Emacs No Learning Curve 43 / 72 Using M-x M-x tells the minibuffer to get ready for a command TAB completion works inside there. this is an easy way to do things. the indentation occurs. Example: indent code in a region Highlight some text and type: M−x indent−region After that. but Emacs minibuffer reminds me I could have used a short cut: You can r u n t h e command ' i n d e n t − r e g i o n ' w i t h C−M−\ Repeat previous using TAB completion feature of minibuffer . so if you remember the first few letters of a command.

A set of legal completions pops up. Highlight some text and type: M−x inden Stop typing. one of which is “indent-region” . Emacs can try to make it writable. “toggle-read-only” or C-x C-q?) .. Which is more memorable. Run M−x toggle−read−only Emacs minibuffer pops up a reminder You can r u n t h e command ” t o g g l e − r e a d − o n l y ” w i t h C−x C−q (thanks very much. Middle-click the one you want to choose it Hit enter Example: accidentally open a read only file. hit the tab key once or twice.Emacs No Learning Curve 44 / 72 Using M-x . Some file saved from R sessions are marked “read only” automatically.. Tedious! I want to edit!.

.” But it is hidden. there is a click-able thing to toggle “read only. (Reminds me of the secret doors in DOOM) . as long as you know its there. Look in the left side of the status bar.. Mouse-1 toggles” It works fine.Emacs No Learning Curve 45 / 72 Using M-x . A reader of the first draft of this presentation pointed out that in the Emacs status bar. for two percent signs %% hover the mouse over the first percent sign. and pops up “buffer is read-only. Maybe the joke’s on me here.

el That may not match my laptop.emacs.el. I wonder. http://pj. My laptop has some features turned on that are commented out in the version on the website. choose Compare.el (the current version of the same config file).Emacs No Learning Curve 46 / 72 Tools -> Compare. 1 2 .freefaculty. Example of a ” power feature”in Emacs What’s the difference between two text files? On my website. 3 In Emacs Tools menu. there is a copy of the Emacs config file I share to people. Perhaps I’ve tried some new settings. open in Emacs. Open ˜/. then 2 buffers.d/init.org/Software/Emacs/ 50emacs-ess-ku. how far out-of-whack is my website with my reality? Download 50emacs-ess-ku.

Example of a ” power feature” in Emacs .Emacs No Learning Curve 47 / 72 Tools -> Compare. . and then it makes you type “yes” in full to escape. or “p” for previous.. Don’t forget to hit “q” to close the compare setup. Type “n” to step to the next difference between the buffers. 2 things happen. The different parts of the 2 buffers are color highlighted A small window pops up in which I can Navigate the differences..

Emacs ESS 48 / 72 Outline 1 Why Use Emacs? 2 Emacs Anatomy 3 No Learning Curve 4 ESS 5 Conclusion .

Emacs ESS 49 / 72 R-mode is provided by the ESS package 1. Send current function to R. . Send selection to R 5. Blue R starter (same as M-x R) 3. Send one line to R 4. ESS menu 2.

which Emacs refers to in the buffer list as *R* If Emacs can’t find R in your system. you need to do some configuration work so that the R/bin folder is added to your system path (I have instructions for that in the crmda computing documentation) . R starts inside a buffer.Emacs ESS 50 / 72 Start an R Session Within Emacs Hit the big blue R button Hopefully.

a terminal in which R is running .Emacs ESS 51 / 72 Some People Prefer ” Splits” with Code and *R* like so The bottom part is the ESS “R inferior mode”.

Emacs ESS 52 / 72 I prefer Separate Frames with R .

On many OS. just type emacs newFile. (In Linux. Open an R file. Make a directory structure. the easiest way to do that is to copy an R file into the desired directory. and run Emacs from within it.R to start). and then open that file with Emacs. Emacs automatically knows to turn on R-mode (ESS Menu & Buttons) .Emacs ESS 53 / 72 Start Emacs within the Desired Working Directory Don’t Start Emacs from an applications menu: It won’t know where to look for files.

I’m just telling you what I like. I want the OS to handle that. . This is an area where reasonable people can disagree. I don’t want Emacs to be my window manager. rather than simply starting new buffers that over-write windows I’m using. Much of my Emacs init file is aimed at forcing Emacs to Start Frames with new content.Emacs ESS 54 / 72 I’m Willing to Fight For Frames I want separate Frames! Spawning more Frames is very un-Emacs-like because it goes against the decades-old tradition of Emacs (during which time one could only have one Frame on one terminal).

. Sometimes I use M-x R. run “getwd()” to make sure the working directory is correct.. hit that button and Emacs sends the whole function to *R*..Emacs ESS 55 / 72 Using ESS button bar Some of the very eager Emacs-ESS users say they remove the button bar and the menus because they are distracting. I can’t imagine. so the M-x R was the only way.) After starting R within Emacs. While revising a function in code. The function evaluator is really handy. I often use the big blue R button to start R. (There was a time when Emacs for Windows had no button bar. just to prove I still can.

You can decide if you like them. Eval versus Eval-and-go.Emacs ESS 56 / 72 ESS Menu The ESS menu teaches you the keyboard shortcuts. Eval-and-go send the instructions and transfer the focus to *R* . Eval commands send instructions to *R*.

and Manuel Eugster) addresses that by creating a “language” for writing documentation inside R code files providing functions to translate the result into documentation files .Emacs ESS 57 / 72 Roxygen Roxygen is a framework for generating R documentation files In the “olden days” (last year). an R package would have separate files for R functions and the help files that went with them. Problem: programmers found it tedious to maintain the separate help files The package roxygen2 (by Hadley Wickham. Peter Danenberg.

. the Roxygen style might be a nice way to prepare your documents.. a ) { x * y * z * a } Click on the first line and from the ESS menu. Even if you aren’t writing a package. Suppose a function is declared like so myFabFunc <− f u n c t i o n ( x .Emacs ESS 58 / 72 Roxygen . y . z . Observe a skeleton is created in which the function can be described . choose Roxygen and “Update/generate template”.

y .... ## ' ## ' ... z . content for \ description {} (no empty lines ) . ## ' @title ## ' @param x ## ' @param y ## ' @param z ## ' @param a ## ' @return ## ' @author pauljohn myFabFunc <− f u n c t i o n ( x . ## ' . content for \ details {} . a ) { x * y * z * a } .Emacs ESS 59 / 72 Roxygen ..

. If we then fill in the sections..Emacs ESS 60 / 72 Roxygen . we will have pretty good documentation for the function and it will be package-ready (more or less)..

such as “lm” Emacs opens a buffer called “username. Edit an existing function object: C-c C-d The mini buffer answers. Instead.Emacs ESS 61 / 72 ESS Magic I Don’t use Menus and Buttons For My shortcut: Shift+Enter sends the current line of code to *R*. I think that’s convenient. you could : Hit the ESS button with one arrow: Or type: C-x C-n. which shows the code for linear models We can edit that file.R” . Object to Edit : type the name of some function. and then re-load it into R with C-c C-l .lm.

run C−c C−d lm and in the beginning insert “browser()”.04-4. I just got an email that indicates it is controversial. To test this. After that.. However. your new version of that function will be used. To me. that is a fun feature.) . when you run functions that access lm. or simply “example(lm)” . the *R* terminal will stop and give you a chance to interact with the inside of that function. (See ESS. The current ESS core team believes that the R code files are the “real” stuff on which we should be working. When the computations come to the line where you put in “browser()” . Then run lm. Section 3..Emacs ESS 62 / 72 ESS Magic I Don’t use Menus and Buttons For .Emacs Speaks Statistics” Version 12.4: Philosophies for using ESS. not fiddling about with functions in memory.

In *R* window. ask for help on lm > ? lm Emacs will open the help file and the menu at the top will have an ESS-help menu In the help file.Emacs ESS 63 / 72 ESS Help Mode While reading a help file in Emacs. it is possible to run the example code Example. . Click the ESS-help menu and choose “Eval Line” or one of the other options. move the cursor to one of the examples at the end of the file.

Then Re-start R (so we have a clean canvas). 3 Step through your R code file line-by-line to be sure everything runs properly 4 Save the output file with the extension *. here is what happens. What if you are working on an R code file. Close R. you have all the records you need for future reference. Some people use the extension *. Record Keeping.Emacs ESS 64 / 72 Transcript Mode. but for me it doesn’t work (don’t know why. Save the R code file. yet) 1 2 As long as you have the R code and the transcript file. In the perfect world.Rt for transcript files.Rout (that means it becomes a “transcript” file). but you type some commands into the *R* buffer interactively? .

Solution strategy. While I’m testing code. I do that all the time. but then it fails! How can that be? It worked before? Obviously. I should save the *R* buffer in a file *. .. Record Keeping.. Emacs recognizes that this is a transcript file .Emacs ESS 65 / 72 Transcript Mode. Open the *. I experiment in the *R* buffer.Rout file in Emacs. something I typed interactively in the *R* buffer did not get copied into the code file properly. I open a new R session I run the R code file that seemed good. then copy commands back to the R code file. The following problem may arise. Let’s suppose I did.Rout.

. I received an email about an ESS feature. or type “C-x h” ) 2 In the ESS-trans menu.03. Since ESS 12. Record Keeping.” The key sequence is C−u C−u C−y. Along the same lines. Viola! That will erase all the output from that file. Emacs won’t let me edit that transcript because it is marked “read only”. choose “Clean” . .. there is an R automatic output “scrub and paste.Emacs ESS 66 / 72 Transcript Mode. so I either have to copy it to a new file or M-x toggle-read-only. and leave behind only the commands that were run. from a reviewer of these slides.. Then 1 Select All of the text (either Menu Edit -> Select All.

It should include commands and output. If you do the ordinary paste. Copy that selection (To copy. . . no output...Emacs ESS 67 / 72 Transcript Mode. But this key sequence will “clean” and paste the resulting R commands. Move the focus to an R code file where you want to paste in only the R commands. not the CUA C-v. Highlight some material in an *R* output window. this requires the traditional C-y ( “yank” ) to paste. use either 1) M-w or 2) C-c from CUA or 3) Edit menu). C−u C−u C−y Note. Record Keeping. with C-y. you get all that messy output.

Emacs Conclusion 68 / 72 Outline 1 Why Use Emacs? 2 Emacs Anatomy 3 No Learning Curve 4 ESS 5 Conclusion .

I looked through the tutorial and I thought “this really is trouble. “ Almost all of the really smart people I know use Emacs. 1947-11-11. . is credited with the quip: “The first five years of Emacs are the worst.Emacs Conclusion 69 / 72 Emacs in Retrospect I think the documentation and publicity that goes with Emacs does it great dis-service.” I’ve told people that “Emacs is like Democracy.” adapting the comment that Winston Churchill made to the House of Commons. except for all those other forms that have been tried from time to time. “Democracy is the worst form of government. Bill Venables. it’s just difficult.” When I first tried Emacs. after that.

Emacs Conclusion 70 / 72 Do I Really Believe There is No Learning Curve? Of course not.” they can use it comfortably and benefit from many powerful features. “Emacs Learning Curve 77% Less Steep Than Previously Believed” I honestly believe that if people are willing to try Emacs “my way. It is not necessary to memorize a raft of key sequences. But I’ll get more hits in Google than with my original title. . even though many Emacs experts do so.

I find the Customization menus still very difficult. If a person is willing to use Emacs with the init file I provide. . enriching. using Emacs can be a very reasonable experience.Emacs Conclusion 71 / 72 Emacs is Extensible I’m not denying the fact that Customizing Emacs is possible. and frustrating (all at the same time) Some parts of Emacs are still difficult for me The help menus are still as confusing to me as ever.

earlham.html .Emacs Conclusion 72 / 72 Useful Websites Introduction to Emacs: http: //cs.edu/~psg/tutorials/vtwm_emacs/part2.