Вы находитесь на странице: 1из 72

Emacs

1 / 72

Emacs Has No Learning Curve


Emacs and ESS Paul E. Johnson1
1 Department 2 Center

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

Emacs Why Use Emacs?

4 / 72

Why Use Emacs? Multidimensional Availability

All Platforms (Windows, Mac, Linux, Unix, Atari,...) Across Time: Will Always Exist (because eager fanatics maintain it) Free & Open Source

Emacs Why Use Emacs?

5 / 72

Why Use Emacs? Super Tools

Emacs has major modes for most languages and types of A les (C, C++, Lisp, R, SAS, Stata, L TEX, English, . . .). Incredibly powerful text management tools
compare documents or buers Regular expression search and replace (even across many les) Copy, paste, insert columns

Enormous power to edit very large les At some point in the future, you may nd that the only editor that is capable for a particular project is Emacs. Prepare for that time by using Emacs for other projects as well!

Emacs Why Use Emacs?

6 / 72

Check the R FAQ


R FAQ, by Kurt Hornik (Version 2.15.2012-09-19):
6 . 2 S h o u l d I r u n R from w i t h i n Emacs ? Yes , d e f i n i t e l y . 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 , 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 , 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. Of c o u r s e , 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. 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 ; 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

Emacs Why Use Emacs?

7 / 72

Check the R FAQ ...

p r o g r a m m i n g . 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 o r d e r t o maintain a l o g of changes i n your programs and data , 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 a d d i t i o n , 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 , 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.

Emacs Emacs Anatomy

8 / 72

Outline

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

Emacs Emacs Anatomy

9 / 72

Start Emacs. Heres What I See

1: Pull Down Menus 2. Button Bar 3. Status Bar 4. Mini-buer

Emacs Emacs Anatomy

10 / 72

Terminology

Frame: That whole thing. Window: The content display area inside a frame Buer: A chunk of content, the collection of letters and words that can be shown inside a window. Check for yourself.
Chose File -> Split Window. You can have 2 windows showing same buer Choose File -> New Frame Choose Menu Buers to select a buer to display in the currently focused Window

Emacs Emacs Anatomy

11 / 72

Emacs Major Mode system

We want the editor to customize itself to the language we are working with. A display of R code should dier from Lisp or Java Emacs will guess the mode you want from the le extension (if you open a le) 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. (Hit Alt with x, release both keys. Then type a command and hit return)

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

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, no-mouse terminal mode


There are many key board combinations using (C) Control, (S) Shift (S), and (M) Meta key (usually Alt ) These are are featured in the Emacs tutorial, and make Emacs seem dicult to learn Hence the prevalence of Emacs cheat sheets oating about on the Internet

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, Mac, or Linux system with X11 display. Emacs will run with pull down menus, more-or-less like other Editors. Its just a text editor with lots of great features (most of which you will never need). It is tremendously programmable, most people can use Emacs comfortably even if they dont customize it. Settings that seem unusual can usually be changed, and Ill handle most of that for you.

Emacs No Learning Curve

16 / 72

Dont Listen To People Who Want You To Memorize C-x C-g C-h whatever...
You can learn key-stroke combinations later, if you need them. But you dont need most of them now, because Emacs now has menus and buttons. Whats easier to remember?
Click the Edit Menu, Choose select all, or Type C-x h (Control-x, release both keys, then the letter h ) I use the rst way. (Why h for select all?)

Whats easier to remember?


Hit the page down key on the keyboard for a few seconds and watch a le y by, or Type M-> (Alt, Shift and the greater-than sign) to go to the bottom

Emacs No Learning Curve

17 / 72

Dont Listen To People Who Want You To Memorize C-x C-g C-h whatever... ...

I usually just hit page down for a moment. Yesterday I had R output that was 150,000 lines and M-> would have been useful.

Emacs No Learning Curve

18 / 72

Example of Previous
Here is an example from Experienced Programmers Introduction to Emacs http://weatherall.4all2u.com/work/emacs.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 Ca move t o b e g i n n i n g o f l i n e Ce 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 . Ck 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 Cd d e l e t e the next ch arac t er a f t e r the cursor

Emacs No Learning Curve

19 / 72

Example of Previous ...


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

Emacs No Learning Curve

20 / 72

Another Intimidating Example


Useful Emacs bits n bobs http://www.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 : Cg 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 Cs : s e a r c h f o r t e x t Cr : 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 CM%: 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 . . . s e e abo v e r e . r e g i o n s e l e c t i o n ) Cw: c u t r e g i o n ( s t d emacs )

Emacs No Learning Curve

21 / 72

Another Intimidating Example ...


Mw: copy r e g i o n ( s t d emacs ) Ck : c u t l i n e Cy : 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 Cx Cf : open ( f i n d ) f i l e i n b u f f e r Cx Cs : s a v e b u f f e r t o f i l e Cx Cw: s a v e b u f f e r t o new f i l e Cx Cz : 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 ) Cx k : k i l l b u f f e r Cx b : c ha ng e a c t i v e b u f f e r Cx 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 Cx 2 : s p l i t b u f f e r window Cx 0 : k i l l c u r r e n t b u f f e r pane Cx 4 f : open f i l e i n new window

Emacs No Learning Curve

22 / 72

Another Intimidating Example ...


Cx Cx Cx Cx Cx Cx Cx Mx 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 Mx 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 Mx 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 ) Mx 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 dont need. The Emacs tutorial emphasizes memorization of keystrokes that are not truly necessary to use Emacs. So dont. Instead, listen to me! Use my init le. 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 dont have to sacrice on any of the other very powerful features of Emacs Emacs enthusiasts are able to remember hundreds of key combinations, but I cant.

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

Emacs No Learning Curve

26 / 72

Example of Easily Fixed Problem ...


Fix. Turn on CUA mode in Emacs. Will make C-x, C-v, C-c, C-z do what you expect. 3 ways to turn on CUA mode.
In most recent Emacs, Click Options and choose CUA, or M-x cua-mode, or Make it permanent: Add this in your Emacs startup conguration ( 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. But most of these bugs have been solved.

Emacs No Learning Curve

27 / 72

Example of Easily Fixed Problem ...


As an example of a bug, try to read the Emacs Tutorial with CUA mode on. (Click the Emacs Help menu, 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). It is necessary to turn o CUA mode to make any progress inside the Emacs tutorial. Of course, the fact that the rst thing in the Emacs tutorial is how to see the next screen with C-v illustrates my previous point, that the Emacs tutorial is addressed to a much dierent user audience than this presentation.

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. This is a secret power of CUA mode. Emacs has an elaborate system to select rectangular sections, but it is dicult to use Here is the CUA way.
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.

That rectangular block can be copied, cut, or pasted. Sometimes, this can be very handy, especially when revising text that includes tables or columns.

Emacs No Learning Curve

29 / 72

Customizations I Recommend
When Emacs starts, it reads a series of conguration les
Some are system-wide Some are user specic

On systems I administer, I generally customize the system-wide settings with my personal favorite settings http://pj.freefaculty.org/Software/Emacs/ 50emacs-ess-ku.el On systems I dont administer, I urge my users to install my conguration settings le. They they can share in my hard-found victory The user settings can be stored in the users home folder, either in
.emacs, or .emacs.d/init.el

Emacs No Learning Curve

30 / 72

Heres my Emacs init le (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 ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; ;; This is a testing version , will go up to http : / / pj . f r e e f a c u l t y . org / Software / Emacs / 50 e m a c s - e s s - k u . el Nothing is new here , I ' m just trying to tidy up Paul Johnson < p a u l j o h n @ k u . edu > 2012-08-23 This is my . emacs startup file . 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 i n t en t i o n is to make Emacs work more like a " modern " GUI editor . I agree with the idea behind " oneonone Emacs " ( http : / / www . e m ac s w i k i . org / emacs / O n e O n O n e E m a c s ) , 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 . Either you should put this file in your Emacs s i t e - s t a r t . d folder or put it in your home d i r ec t o r y and call it ". emacs ". Or re-name it " init . el " and copy it into a new d i re c t o r y in your Home folder called . emacs . d .

; ; If you are using this because you use Emacs to use ESS ( Emacs ; ; Speaks S t a t i s t i c s ) with R , here are my special features . ;; ;; ;; ;; ;; 1. 2. if 3. 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 , and it will start R it is not running . R will start in the current working directory , without stopping ask the user about a working d i r e c t or y .

Emacs No Learning Curve

31 / 72

Heres my Emacs init le (on my laptop 2012-08-23) ...


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 ; ; 4. R runs in its own " frame " ; ; 5. Emacs help pops up in its own frame .

; ; Section I . Windows OS w o r k - a r o u n d s ( i f ( eq system type ' windows nt ) ( setq usefiledialog n i l ) ) ; ; There ' s a problem with file s el e c t i o n dialogs on Windows

; ; Section II . Keyboard and mouse c u s t o m i z a t i o n ; ; IIA : make mouse s e l e ct i o n work in the usual Mac / Windows way ; ;( require ' p c - 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 ) ; is default in Emacs 23+ , replaces p c - s e l e c t ( transient mark mode t ) ; 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 ) ; delete seleted text when typing ; ; IIB : keyboard c u s t o m i z a t i o n ( cuamode t ) ; windows style binding C-x , C-v , C-c , C-z , 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 ) ; ; Don ' t tabify after r e c t a n g le commands ( s e t q cua keep region after copy t ) ; ; S e l ec t i o n remains after C-c

Emacs No Learning Curve

32 / 72

Heres my Emacs init le (on my laptop 2012-08-23) ...


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 ; ; write line numbers on left of window ; ; ( g l o b a l - l i n u m - m o d e 1) ; always show line numbers

; ; Section III . 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 ) ; light-up matching parens ( global font lock mode t ) ; 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 ) ) )

; ; Section IV . ESS Emacs S t a t i s t i c s ; ;( setq i n f e r i o r - e s s - o w n - f r a m e t ) ( s e t q inferior ess same window n i l ) ; ; create a new frame for each help instance ; ; ( setq e s s - h e l p - o w n - f r a m e t ) ; ; If you want all help buffers to go into one frame do : ( s e t q ess help own frame ' one ) ; ; m i n i b u f f e r tips : will work in future ; ;( require ' e s s - el d o c ) ; ; html help ; ( setq i n f e r i o r - e s s - r - h e l p - c o m m a n d " help (\"% s \" , h e l p _ t y pe =\" html \") \ n ")

Emacs No Learning Curve

33 / 72

Heres my Emacs init le (on my laptop 2012-08-23) ...


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 ; ; start R in current working directory , don ' t ask user ( setq essaskforessdirectory 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 ' essevalregion ) ( 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 ( ) ( localsetkey [ ( s h i f t r e t u r n ) ]
*R*

' my ess eval )

))

; ; PJ 2 0 1 2 - 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 ; ; 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 ( ) ( essnuketrailingwhitespace ) ) ) ) ) ; ;( setq e s s - n u k e - t r a i l i n g - w h i t e s p a c e - p ' ask ) ; ; or even

Emacs No Learning Curve

34 / 72

Heres my Emacs init le (on my laptop 2012-08-23) ...


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 essnuketrailingwhitespacep t ) ; ;; 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 ) ) ) ; ;; End ESS

; ; Section V . C u s t om i z e the use of Frames . Try to make new content ; ; appear in wholly new frames on screen . ;; ; ; V . A : D i s c o u r a g e Emacs from s p l i t t in g " frames " , e n c o u r a ge it to ; ; pop up new frames for new content . see : ; ; http : / / www . gnu . org / software / emacs / elisp / h t m l _n o d e / C h o o s i n g - W i n d o w . html ( s e t q pop up frames t ) ( s e t q specialdisplaypopupframe 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 ) ; 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 ) ; ; V . B : Use " framepop " to pop up small frame messages . Some users don ' t ; ; have " framepop ". I try to make this check to see if the feature is ; ; i n st a l l e d . ; ; Note that " p o p - u p - f r a m e s " is d if f e r e n t from " framepop ". ; ; Crazy ! The framepop package can " catch " some special small buffers

Emacs No Learning Curve

35 / 72

Heres my Emacs init le (on my laptop 2012-08-23) ...


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 ; ; 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 . ; ; The framepop packages is in e m a c s - g o o d i e s on Ubuntu . ( 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 ( framepopenable ) ) ) ) I made it pink !

'

noerror )

; ; Even if you don ' t have framepop , it is OK to leave these . ;; ( s e t q framepop frame parameters ' ( ( name . n i l ) ; use buffer name ( unsplittable . t) ; always include this ( menu bar lines . 0 ) ; no menu bar ( minibuffer . nil ) ; or m i n u b u f f e r ( l e f t . 1) ; top left corner of screen , ( top . 30) ; away from my main frame ( width . 71) ; narrower , so it fits nicely ( b a c k g r o u n d c o l o r . M i s t y R o s e ) ; for October . ( toolbarlines . 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 framepopautoresize t ) ; ; Stops framepop from fiddling with a few specific buffer types . ( setq specialdisplaybuffernames

Emacs No Learning Curve

36 / 72

Heres my Emacs init le (on my laptop 2012-08-23) ...


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 * ) )

; ; V . C : Make files opened from the menu bar appear in their own ; ; frames . This o v e r r i d e s the default menu bar settings . Opening an ; ; ex isting file and creating new one in a new frame are the exact ; ; same o p e r a t i o n s . adapted from Emacs menu-bar . el ( defun menufindexisting ( ) E d i t t h e e x i s t i n g f i l e FILENAME . ( 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 ( findfileotherframe filename ) ( findfile 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 , ( p u r e c o p y Open F i l e . . . ) 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 , ( 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 ) ) ) ; ;( d e f i n e - k e y m e n u - b a r - f i l e - m e n u [ o p e n -f i l e ] ; ; ' ( m en u - i t e m " Open File ..." f i n d - f i l e - o t h e r - f r a m e

Emacs No Learning Curve

37 / 72

Heres my Emacs init le (on my laptop 2012-08-23) ...


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 ;; ;; : enable ( m e n u - b a r - n o n - m i n i b u f f e r - w i n d o w - p ) : help " Open Existing File ") )

; ; V . D Open d i re c t o r y list in new frame . ( 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 . . . 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 ; 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 )))))

; ; 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 ; ; Remove Emacs " splash screen " ; ; http : / / fuhm . l i v e j o u r n a l . com / ( d e f a d v i c e command line normalize file name ( before killstupidstartupscreen activate ) ( setq inhibitstartupscreen t ) ) ( setq inhibitsplashscreen t )

; ; Show file name in title bar ; ; http : / / www . t h e t e c h r e p o . com / m a i n - 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 )

Emacs No Learning Curve

38 / 72

Heres my Emacs init le (on my laptop 2012-08-23) ...


215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 ; ; I ' m right handed , need scroll bar on right ( like other programs ) ( setq scrollbarmodeexplicit t ) ( set scroll bar mode ` r i g h t )

; ; Make Emacs scroll smoothly with down arrow key . ; ;2011-10-14 ; ; testing faq 5.45 http : / / www . gnu . org / s / emacs / e m a c s- f a q . 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 mostpositivefixnum )

; ; If you want to adjust the size of the frames , u n c o m me n t this , adjust values ; ;( setq d e f a u l t - f r a m e - a l i s t ' (( width . 90) ( height . 65) ) )

; ; Re member password when c o n n e c t e d to remote sites via Tramp ; ; http : / / s t a c k o v e r f l o w . com / q u e s ti o n s / 840279 / passwords-in-emacs-tramp-mode-editing ; ; Emacs " tramp " service ( ssh c o n n e c t i o n ) c o n s t a n t l y ; ; asks for the log in password without this ( s e t q passwordcacheexpiry n i l )

; ; PJ 2 0 1 1 - 0 5 - 1 5

Emacs No Learning Curve

39 / 72

Heres my Emacs init le (on my laptop 2012-08-23) ...


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 ; ;( setq e s s - s w v - p d f l a t e x - c o m m a n d s ' (" pdflatex " " make ") ) ; ;( c u s t o m - s e t - v a r i a b l e s

; ; Section : Emacs shells work better ; ; http : / / snarfed . 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 )

;; ;; ;; ;; ;; ;; ;; ============================================================= From Marc Schwartz Set keys for ' windmove ' , built into Emacs = = = = = = = = = = = = = = = = = = Ke yboard a c c e l e r a t o r M - d i r e c t i o n will " scroll " through buffers . Easier to remember than other ways . =============================================================
' meta )

( windmovedefaultkeybindings

( 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 )

Emacs No Learning Curve

40 / 72

Heres my Emacs init le (on my laptop 2012-08-23) ...

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

41 / 72

Another Easily Fixed Problem


Selection of text in base Emacs used to be very dierent 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). These lines in the startup conguration can (basically) completely solve the problem
( setq shiftselectmode t ) ( transient mark mode t ) ; h i g h l i g h t t e x t selection ( deleteselectionmode 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, the rst two became defaults in Emacs-23, so Im just making sure they are still set that way.

Emacs No Learning Curve

42 / 72

Shortcuts I do remember
There are some keyboard shortcuts I do remember
C-s: I search frequently, this is easier than the menu Edit -> Search (C-r searches in reverse) M-%: Query replace C-M-%: Regular-Expression Query replace (cant live without them) M-x: execute commands. C-g : get out of jail free. If you mistakenly start something in the minibuer, C-g gets out of it. M-q : re-shapes an ill-formed paragraph M-; : for a selected region, will comment and uncomment all lines.

But for things that I only do once every 6 months, it is easier to nd them in a menu or type them by name.

Emacs No Learning Curve

43 / 72

Using M-x
M-x tells the minibuer to get ready for a command TAB completion works inside there, so if you remember the rst few letters of a command, this is an easy way to do things. Example: indent code in a region
Highlight some text and type: Mx indentregion After that, the indentation occurs, but Emacs minibuer 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 CM\

Repeat previous using TAB completion feature of minibuer

Emacs No Learning Curve

44 / 72

Using M-x ...


Highlight some text and type: Mx inden Stop typing, hit the tab key once or twice. A set of legal completions pops up, one of which is indent-region . Middle-click the one you want to choose it Hit enter

Example: accidentally open a read only le. Some le saved from R sessions are marked read only automatically. Tedious! I want to edit!. Emacs can try to make it writable.
Run Mx togglereadonly Emacs minibuer 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 Cx Cq
(thanks very much. Which is more memorable. toggle-read-only or C-x C-q?)

Emacs No Learning Curve

45 / 72

Using M-x ...

Maybe the jokes on me here.


A reader of the rst draft of this presentation pointed out that in the Emacs status bar, there is a click-able thing to toggle read only. But it is hidden. Look in the left side of the status bar, for two percent signs %% hover the mouse over the rst percent sign, and pops up buer is read-only. Mouse-1 toggles It works ne, as long as you know its there. (Reminds me of the secret doors in DOOM)

Emacs No Learning Curve

46 / 72

Tools -> Compare. Example of a power featurein Emacs


Whats the dierence between two text les? On my website, there is a copy of the Emacs cong le I share to people. http://pj.freefaculty.org/Software/Emacs/ 50emacs-ess-ku.el That may not match my laptop. Perhaps Ive tried some new settings. My laptop has some features turned on that are commented out in the version on the website. I wonder, how far out-of-whack is my website with my reality?
Download 50emacs-ess-ku.el, open in Emacs. Open /.emacs.d/init.el (the current version of the same cong le). 3 In Emacs Tools menu, choose Compare, then 2 buers.
1 2

Emacs No Learning Curve

47 / 72

Tools -> Compare. Example of a power feature in Emacs ...

2 things happen.
The dierent parts of the 2 buers are color highlighted A small window pops up in which I can Navigate the dierences.
Type n to step to the next dierence between the buers, or p for previous.

Dont forget to hit q to close the compare setup, and then it makes you type yes in full to escape.

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. ESS menu 2. Blue R starter (same as M-x R) 3. Send one line to R 4. Send selection to R 5. Send current function to R.

Emacs ESS

50 / 72

Start an R Session Within Emacs

Hit the big blue R button Hopefully, R starts inside a buer, which Emacs refers to in the buer list as *R* If Emacs cant nd R in your system, you need to do some conguration work so that the R/bin folder is added to your system path (I have instructions for that in the crmda computing documentation)

Emacs ESS

51 / 72

Some People Prefer Splits with Code and *R* like so

The bottom part is the ESS R inferior mode, a terminal in which R is running

Emacs ESS

52 / 72

I prefer Separate Frames with R

Emacs ESS

53 / 72

Start Emacs within the Desired Working Directory

Dont Start Emacs from an applications menu: It wont know where to look for les. Make a directory structure, and run Emacs from within it. (In Linux, just type emacs newFile.R to start). On many OS, the easiest way to do that is to copy an R le into the desired directory, and then open that le with Emacs. Open an R le, Emacs automatically knows to turn on R-mode (ESS Menu & Buttons)

Emacs ESS

54 / 72

Im 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). Much of my Emacs init le is aimed at forcing Emacs to Start Frames with new content, rather than simply starting new buers that over-write windows Im using. This is an area where reasonable people can disagree, Im just telling you what I like. I dont want Emacs to be my window manager, I want the OS to handle that.

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 cant imagine... I often use the big blue R button to start R.

Sometimes I use M-x R, just to prove I still can. (There was a time when Emacs for Windows had no button bar, so the M-x R was the only way.)

After starting R within Emacs, run getwd() to make sure the working directory is correct. The function evaluator is really handy. While revising a function in code, hit that button and Emacs sends the whole function to *R*.

Emacs ESS

56 / 72

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

Emacs ESS

57 / 72

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

Emacs ESS

58 / 72

Roxygen ...
Even if you arent writing a package, the Roxygen style might be a nice way to prepare your documents. Suppose a function is declared like so
myFabFunc < f u n c t i o n ( x , y , z , a ) { x * y * z * a }

Click on the rst line and from the ESS menu, choose Roxygen and Update/generate template. Observe a skeleton is created in which the function can be described

Emacs ESS

59 / 72

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

Emacs ESS

60 / 72

Roxygen ...

If we then ll in the sections, we will have pretty good documentation for the function and it will be package-ready (more or less).

Emacs ESS

61 / 72

ESS Magic I Dont use Menus and Buttons For


My shortcut: Shift+Enter sends the current line of code to *R*. I think thats convenient.
Instead, you could :
Hit the ESS button with one arrow: Or type: C-x C-n.

Edit an existing function object:


C-c C-d The mini buer answers, Object to Edit : type the name of some function, such as lm Emacs opens a buer called username.lm.R , which shows the code for linear models We can edit that le, and then re-load it into R with C-c C-l

Emacs ESS

62 / 72

ESS Magic I Dont use Menus and Buttons For ...


After that, when you run functions that access lm, your new version of that function will be used. To test this, run Cc Cd lm and in the beginning insert browser(). Then run lm, or simply example(lm) . When the computations come to the line where you put in browser() , the *R* terminal will stop and give you a chance to interact with the inside of that function. To me, that is a fun feature. However, I just got an email that indicates it is controversial. (See ESS- Emacs Speaks Statistics Version 12.04-4, Section 3.4: Philosophies for using ESS. The current ESS core team believes that the R code les are the real stu on which we should be working, not ddling about with functions in memory.)

Emacs ESS

63 / 72

ESS Help Mode


While reading a help le in Emacs, it is possible to run the example code Example. In *R* window, ask for help on lm
> ? lm

Emacs will open the help le and the menu at the top will have an ESS-help menu In the help le, move the cursor to one of the examples at the end of the le. Click the ESS-help menu and choose Eval Line or one of the other options.

Emacs ESS

64 / 72

Transcript Mode. Record Keeping.


In the perfect world, here is what happens.
Save the R code le. Close R. Then Re-start R (so we have a clean canvas). 3 Step through your R code le line-by-line to be sure everything runs properly 4 Save the output le with the extension *.Rout (that means it becomes a transcript le). Some people use the extension *.Rt for transcript les, but for me it doesnt work (dont know why, yet)
1 2

As long as you have the R code and the transcript le, you have all the records you need for future reference. What if you are working on an R code le, but you type some commands into the *R* buer interactively?

Emacs ESS

65 / 72

Transcript Mode. Record Keeping. ...


I do that all the time. While Im testing code, I experiment in the *R* buer, then copy commands back to the R code le. I should save the *R* buer in a le *.Rout. Lets suppose I did. The following problem may arise.
I open a new R session I run the R code le that seemed good, but then it fails! How can that be? It worked before?

Obviously, something I typed interactively in the *R* buer did not get copied into the code le properly. Solution strategy.
Open the *.Rout le in Emacs. Emacs recognizes that this is a transcript le

Emacs ESS

66 / 72

Transcript Mode. Record Keeping. ...


Emacs wont let me edit that transcript because it is marked read only, so I either have to copy it to a new le or M-x toggle-read-only. Then
1 Select All of the text (either Menu Edit -> Select All, or type

C-x h )
2 In the ESS-trans menu, choose Clean .

Viola! That will erase all the output from that le, and leave behind only the commands that were run.

Along the same lines, from a reviewer of these slides, I received an email about an ESS feature. Since ESS 12.03, there is an R automatic output scrub and paste. The key sequence is Cu Cu Cy.

Emacs ESS

67 / 72

Transcript Mode. Record Keeping. ...


Highlight some material in an *R* output window. It should include commands and output. Copy that selection (To copy, use either 1) M-w or 2) C-c from CUA or 3) Edit menu). Move the focus to an R code le where you want to paste in only the R commands, no output.
If you do the ordinary paste, with C-y, you get all that messy output. But this key sequence will clean and paste the resulting R commands.

Cu Cu Cy
Note, this requires the traditional C-y ( yank ) to paste, not the CUA C-v.

Emacs Conclusion

68 / 72

Outline

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

Emacs Conclusion

69 / 72

Emacs in Retrospect
I think the documentation and publicity that goes with Emacs does it great dis-service.
Bill Venables, is credited with the quip: The rst ve years of Emacs are the worst; after that, its just dicult.

When I rst tried Emacs, I looked through the tutorial and I thought this really is trouble. Ive told people that Emacs is like Democracy, adapting the comment that Winston Churchill made to the House of Commons, 1947-11-11, Democracy is the worst form of government, except for all those other forms that have been tried from time to time. Almost all of the really smart people I know use Emacs.

Emacs Conclusion

70 / 72

Do I Really Believe There is No Learning Curve?

Of course not. But Ill get more hits in Google than with my original title, Emacs Learning Curve 77% Less Steep Than Previously Believed I honestly believe that if people are willing to try Emacs my way, they can use it comfortably and benet from many powerful features. It is not necessary to memorize a raft of key sequences, even though many Emacs experts do so.

Emacs Conclusion

71 / 72

Emacs is Extensible

Im not denying the fact that


Customizing Emacs is possible, enriching, and frustrating (all at the same time)

Some parts of Emacs are still dicult for me


The help menus are still as confusing to me as ever. I nd the Customization menus still very dicult.

If a person is willing to use Emacs with the init le I provide, using Emacs can be a very reasonable experience.

Emacs Conclusion

72 / 72

Useful Websites

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

Вам также может понравиться