A SHORT Primer for EMACS for Busy Scientists_by_FC_Michel_Rice_Univ

  • Upload
    srescia

  • View
    217

  • Download
    0

Embed Size (px)

Citation preview

  • 7/29/2019 A SHORT Primer for EMACS for Busy Scientists_by_FC_Michel_Rice_Univ

    1/4

    ORT Primer for EMACS for Busy Scientists http://psr.rice.edu/em

    10/25/2006 1

    A SHORT Primer for EMACS for Busy Scientists

    Curt Michel

    Emacs i s an word processi ng pr ogr am( pl us l ots more) t hat has t he advant aget hat i t can be r un over a dumb t ermi nal ( i . e. , a PC or MacI nt osh wi t h anel ement ary t ermi nal pr ogr am) . Thus you can edi t your f i l es away f r om t he of f i ce( or you can t r y t o use ' vi ' i f you ever get t he ' t ermcap' t o wor k r i ght ) . Emacsal so has some very ni ce f eat ur es such as keepi ng several f i l es i n buf f ers sot hat you can vi ew one whi l e edi t i ng anot her, etc. I t al so has edi t i ng modes f or

    l atex, t ex, C, etc. wi t h f eat ur es both f or el i mi nati ng common er r ors and f orcompi l i ng t he fi l e i n one wi ndow whi l e edi t i ng ( cor r ect i ng) i t i n anot her .

    A down si de of emacs i s t hat i t i s di f f i cul t t o fi nd out qui ckl y how t o do al lt he STANDARD st uf f t hat even the most el ement ary word pr ocessi ng pr ogr amwi l l doi n a t r i vi al way. Thus t he mi nut e you t r y to use emacs you suddenl y cannot do al ot of t hi ngs you are used t o bei ng abl e to do. Thi s PRI MER i s i nt ended t opr ovi de t hat knowl edge. Ot her wi se you waste a l ot of t i me doi ng t r i vi al t askswi t h pr i mi t i ve t ool s, i nst ead of f i ndi ng out what great t hi ngs you can do wi t hemacs. Another down si de of emacs i s i t s obvi ous comput er- nerdi ness, whi ch i sr eveal ed i n t he excessi ve and poi nt l ess rel i ance on havi ng t o hi t speci alcont r ol keys numerous t i mes. There i s no cur e of f ered here.

    Emacs has a si mpl e tut ori al whi ch i s adver t i zed when ' emacs' i s ent ered at t hepr ompt and RET( ur n) i s hi t . I wi l l assume t hat t he r eader has t aken t het ut ori al , but I wi l l be r edundant i n t hat I al so want t o remi nd t he r eader what

    t he st andard act i ons ar e.

    ENTERI NG TEXT: i s at t he cur sor posi t i on - hi t t i ng a key ent ers at t he posi t i onof t he cur sor . I f t he cur sor i s si t t i ng on a char act er , t he char act er i s movedt o t he r i ght t o make r oom.

    DELETI NG TEXT: wi t h t he DEL key r etai ns the char act er wher e the cursor i s andr emoves char act er s successi vel y t o the l ef t , i ncl udi ng newl i nes, so an ent i r edocument coul d be r emoved by st ar t i ng at t he end and hol di ng down DEL, whi ch i swhat I mean by doi ng t r i vi al t hi ngs wi t h pr i mi t i ve t ool s. I f i t ' s too mucht r oubl e to move t he cur sor, C- d ( cont r ol d) del etes what i s at t he cur sor.Usef ul f or del et i ng the newl i ne at t he end of ever y sent ence.

    I DI DN' T MEAN TO DO I T: ' C- x u' undoes t he l ast command, and may be envokedr epeat edl y t o undo successi vel y ear l i er commands.

    Ni nety per cent of edi t i ng can be done wi t h these pr i mi t i ves, but t he remai ni ngt en percent can become ni nety percent i f t hat ' s al l you have.

    FI NDI NG TEXT: t ypi cal l y one i s proof i ng t ext and want s t o go t o a speci f i c poi nti n t he document , most easi l y by sear chi ng f or a near by di st i nct i ve word. To dot hi s, ent er C- s (cont r ol s) and ' I - search: ' appear s i n t he bot t om l i ne( "mi ni buf f er" ) . As you t ype i n t he word or words t o be searched, emacs searchesDOWN t hrough the f i l e, so you may get t o t he word wi t hout t ypi ng i t compl et el y.I f you ar e st ar t i ng t oo l ow, you get t he "hel pf ul " message ' Fai l i ng I - sear ch: 'but don' t gi ve up, j ust hi t C- s agai n and i t wi l l st art agai n f r om t he top oft he f i l e, wi t h t he message ' Wr apped I - sear ch: ' . I f you pi ck a common word,r epeat ed C- s commands wi l l st ep down t hr ough t he f i l e. I f you seem t o be st ucki n ' search' j ust cl i ck i n t he f i l e wi ndow.

    DELETI NG/ PASTI NG TEXT: now t hat you f ound i t , you probabl y want t o del et esomethi ng. Emacs has al l sort s of goof y ' del ete' opt i ons not wort h ment i oni ng.

    Al most al ways you want t o si mpl y del et e everyt hi ng bet ween HERE and THERE. Youmark t he begi ni ng wi t h the cur sor ( i ncl udi ng t he f i r st symbol t o be del eted) andt ype C- SPC ( cont r ol spacebar) and t hen move the cur sor t o the l ast charact er t obe del eted and t ype C- w. The t ext vani shes and i s st or ed. I f your i nt ent i on i st o move the text somewher e el se, you now si mpl y move the cur sor t o t he new poi ntand t ype C- y. I f your i nt ent i on i s t o COPY t he t ext , you mark i t and t ype C- wC- y ( whi ch br i ef l y del etes i t ) and then move t o where you want t o PASTE i t .

    REPETI TI VE OPERATI ONS: of t en you need t o do a l ot of t he same thi ng.

    One r epet i t i ve oper at i on i s t o change exi st i ng t ext t o somet hi ng el se. I f Iwant t o change ' Truman' t o ' Cl i nt on' I can t ype ' M- x repl ace- st r i ng' where M- xi s ' meta- charact er x' ( yes, t hey want you t o use TWO cont r ol keys) . On t he Sunworkst at i ons i t i s t he bl ack di amond key on ei t her si de of t he spacebar( i f no such key, t ry Esc, and i f t hat f ai l s, t ry C- [ ) ; you

  • 7/29/2019 A SHORT Primer for EMACS for Busy Scientists_by_FC_Michel_Rice_Univ

    2/4

    ORT Primer for EMACS for Busy Scientists http://psr.rice.edu/em

    10/25/2006 1

    hol d down the bl ack di amond and hi t x, but now you must l i t eral l y t ype i n' r epl ace- st r i ng' . Si nce t hi s i s so br ai n- dead, emacs' s creat or s have made t hespacebar an "accel erat or" so t hat you can t ype i n j ust par t of a command and hi tspacebar and t he rest of t he word wi l l be compl eted. But i f you t ype i n ' M- x r'and hi t spacebar, emacs wi l l di spl ay al l known such commands t hat st art out t hi sway whenever t here are more t han one. You wi l l need t o t ype at l east ' M- x r epl 'and t he spacebar wi l l gi ve you ' M- x repl ace- ' so you st i l l need t o type ' s' andt hen spacebar gi ves you FI NALLY ' M- x repl ace- st r i ng' . You now need t o do onemore br ai n- dead thi ng, namel y hi t RET t o have di spl ayed: ' Repl ace st r i ng: ' andNOW you can type i n ' Truman' , hi t RET, and you now have ' M- x Repl ace st r i ngTr uman wi t h: ' and t he r est i s f i nal l y obvi ous. BUT t he r epl acement i s f r om t hecur sor t o the end of f i l e ( i t makes no sense, I know) , so you have to go to t he

    begi nni ng of t he f i l e wi t h ' Shi f t M-

  • 7/29/2019 A SHORT Primer for EMACS for Busy Scientists_by_FC_Michel_Rice_Univ

    3/4

    ORT Primer for EMACS for Busy Scientists http://psr.rice.edu/em

    10/25/2006 1

    case L) and spacebar wi l l compl ete i t t o ' M- x goto- l i ne' and you now need RET t oact ual l y get t he command ' Goto l i ne: ' whi ch we can now can t ype i n.

    WI NDOW MANAGEMENT: ' C- x 2' opens t wo wi ndows contai ni ng t he same f i l e, so youcan r ead what you sai d one pl ace whi l e wr i t i ng another, ' C- x 1' r emoves t hewi ndow you ar e not worki ng i n. ' C- x C- f ' put s what you ar e worki ng on i n abuf f er and l oads t he f i l e you ar e quer i ed f or i n t he mi ni buf f er . I f you want t ol oad t he f i l e as a separat e wi ndow whi l e keepi ng t he f i l e you are worki ng on,t ype ' C- x 4 C- f ' ( don' t ask, I don' t know) . I f you f or get and l oad a f i l e t hati s al r eady i n a buf f er, emacs wi l l use the one i n t he buf f er and not t he( pr obabl y unedi t ed) one i n your di r ect or y. ' C- x C- s' t hen makes t he t wo t hesame ( i . e. , saves t o di sk). The easy way t hen t o get a f i l e f r om buf f er i nt o a

    second wi ndow i s spl i t t he wi ndow ( C- x 2) and then pr etend you are aski ng f ort he ver si on on di sk (C- x C- f ) .

    SPELL CHECKI NG: f or every usef ul f unct i on, emacs has a dozen goof bal l var i ant s,so you can check the spel l i ng of a word, r egi on, etc. To check the spel l i ng ofa si ngl e word, move t he cursor t o t he space at t he end of t he word and t ype' M- $' ( "mi dl e" pr oduces a sel f - expl ani t or y l i st of acti ons i n Engl i sh, pl us t hechoi ces "0 i dl e", "1 mi l e", and "2 mi ddl e"; t ype ' 2' and t he mi sspel l i ng i scor r ect ed) . To spel l t he whol e document ( t he usual use), t ype ' M- x spel l - b'spacebar t o get ' M- x spel l - buf f er ' and i t wi l l go through t he wor ds i t doesn' tl i ke ( whi ch of t en seem per f ect l y good: t he spel l checker di dn' t l i ke "REGul ar "as used i n t hi s document ( of cour se) , but compl ai ned i nst ead about "r egul ar" ) .Unf ort unatel y, onl y i f you edi t t he word wi l l emacs go t o t he pl ace i n t hedocument where i t i s used, whi ch makes i t di f f i cul t t o puzzl e out what you meantsometi mes. And you have t o hi t ' y' f or t he edi t t o t ake ef f ect once t he word i sl ocat ed, RET j ust ski ps on. Use ' Texspel l ' f or LaTeX document s unl ess you want

    t hi ngs l i ke ' \ f rac' l i sted. To do t hi s, t ype ' M- x shel l ' whi ch wi l l pop up t heUni x command l i ne, and af t er r unni ng Texspel l you hi t ' C- x b' and RET t o getback t o t he f i l e.

    ADVANCED FEATURES: t he above seemt o be t he more- or - l ess st andar d t hi ngs onewoul d l i ke t o do wi t h f i l es. Emacs l ets you pop out t o the command l i ne andcompi l e t he appr opr i ate f i l es. For exampl e, i f you are edi t i ng a LaTeX documentwi t h a ' . t ex' ext ensi on, emacs wi l l assume you are i n TEX mode, so you need t ot ype ' M- x l at ex- mode' t o manual l y cor r ect i t ( or use the extensi on ' . l t x'i nst ead) . The mode i s l i st ed i n t he r ever se- vi deo l i ne at t he bott om, whi chusual l y says ' Fundament al ' . Now you can t ype ' C- c C- b' and a second wi ndow wi l lpop up i n whi ch t he compi l ati on wi l l be shown. To get r i d of i t , t ype ' C- x 1' ,maki ng sur e t he cur sor has marked somet hi ng i n t he wi ndow you want t okeep. Act ual l y ' C- c C- f ' al so works and you wi l l occasi onal l y envoke i t whenf umbl i ng t o type ' C- x C- f ' whi ch asks f or a new f i l e name to edi t .

    To pop up another f i l e, t ype ' C- x C- b' t o see what ' s avai l abl e, t hen ' C- x b' t oent er t he name of t he desi r ed buf f er or C- x C- f t o add anot her f i l e to t heemacs.

    I f you are edi t i ng Tabl es, l ook up "* r ect angl es" i n t he manual ( i f you haven' texi t ed emacs, t he manual wi l l be stored i n a buf f er cal l ed *i nf o*) - you can movear ound col umns of t ext ( ' r ect angl es' ) j ust l i ke ent i r e l i nes of t ext. You mar kt he upper l ef t wi t h C- SPC and move t he cur sor t o t he l ower r i ght . Not usef ulf or t ext , but I copi ed t he t hi r d paragraph above wi t h C- w C- y, and then choppedout t he cent er by marki ng t he col on and the peri od at t he end to pr oduce ( ' M- xcl ear- rect angl e' ) :

    ADVANCED FEATURES t hi ngs onewoul d l i ke t o do nd l i ne andcompi l e t he appro LaTeX documentwi t h a ' . t ex' ext o you need t o

    t ype ' M- x l at ex- m n ' . l t x'i nst ead) . The mo t t om, whi chusual l y says ' Fun ond wi ndow wi l lpop up i n whi ch t t ype ' C- x 1' ,maki ng sure t he c t t okeep. Act ual l y ' C oke i t whenf umbl i ng t o t ype .

    COMMAND SUMMARY: ( not al l di scussed above) r ar e mnemoni c not edC- h i get t he manualC- d ( d) el et e char act er at cur sorC- spacebar mark t ext f r ompresent cur sor posi t i on t o next posi t i onC- w CUT mar ked t extC- y PASTE i n CUT t extC- x u ( u) ndo

  • 7/29/2019 A SHORT Primer for EMACS for Busy Scientists_by_FC_Michel_Rice_Univ

    4/4

    ORT Primer for EMACS for Busy Scientists http://psr.rice.edu/em

    10/25/2006 1

    C- g escape command modeC- x C- f l oad new f i l eC- x C- w copy exi st i ng f i l e t o a new name and edi t t hatC- x 4 C- f l oad new f i l e i nt o second wi ndowC- x C- s ( s)ave f i l eC- x C- c l eave emacsC- u 47 C- x f set l i ne l engt h t o 47 ( not hi ng wi l l happen t o exi st i ng t ext)M- q now changes l i ne l ength t o 47 i n paragr aph cont ai ni ng cursorC- s ( s) ear chC- x C- b l i st buf f er s ( ot her f i l es t hat have been l oaded) ( spl i t s screen)C- x b l oad buf f er by i t s f i l e nameC- x x r st or e maked t ext i n r egi st er "r "

    C- x g r ( g) et t ext st ored i n r egi st er "r "C- x / r store cursor posi t i on i n f i l e i n regi ster "r "C- x j r ( j ) ump cursor t o posi t i on st ored i n r egi st er "r "

    cannot st ore BOTH t ext and posi t i on i n same regi st er nameC- x 2 spl i t s wi ndow i n ( 2)C- x 1 r eturns t o ( 1) wi ndow, del eti ng i nact i ve oneC- c C- b compi l e i n second wi ndowC- c C- f " " "C- x TAB i ndent s marked l i nes of t ext one spaceM- x repl ace- st ri ng r epl ace st r i ngM- x r epl ace- r egexp r epl ace r egul ar expr essi onM- x l at ex- mode changes mode t o l at ex ( f or exampl e)M- x aut o- f i l l - mode wr aps l i nes t o keep f r om r unni ng of f screenM- x goto- l i ne f i nd l i ne by numberM- x spel l - buf f er spel l check f i l eM- x shel l escape t o command l i ne ( C- x b RET r et urns t o wher e you were)

    SHI FT M- $ spel l check word j ust wr i t t enSHI FT M- % r epl ace st r i ng ( asks permi ssi on each i nst ance)Shi f t M- < go t o t op of f i l eShi f t M- > go t o bot t om of f i l e