elisp-7 288 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593
  1. This is /home/cyd/emacs/doc/lispref/../../info/elisp, produced by
  2. makeinfo version 4.13 from /home/cyd/emacs/doc/lispref/elisp.texi.
  3. This is the `GNU Emacs Lisp Reference Manual' corresponding to Emacs
  4. version 24.2.
  5. Copyright (C) 1990-1996, 1998-2012 Free Software Foundation, Inc.
  6. Permission is granted to copy, distribute and/or modify this
  7. document under the terms of the GNU Free Documentation License,
  8. Version 1.3 or any later version published by the Free Software
  9. Foundation; with the Invariant Sections being "GNU General Public
  10. License," with the Front-Cover texts being "A GNU Manual," and
  11. with the Back-Cover Texts as in (a) below. A copy of the license
  12. is included in the section entitled "GNU Free Documentation
  13. License."
  14. (a) The FSF's Back-Cover Text is: "You have the freedom to copy and
  15. modify this GNU manual. Buying copies from the FSF supports it in
  16. developing GNU and promoting software freedom."
  17. INFO-DIR-SECTION GNU Emacs Lisp
  18. START-INFO-DIR-ENTRY
  19. * Elisp: (elisp). The Emacs Lisp Reference Manual.
  20. END-INFO-DIR-ENTRY
  21. 
  22. File: elisp, Node: Visibility of Frames, Next: Raising and Lowering, Prev: Input Focus, Up: Frames
  23. 29.10 Visibility of Frames
  24. ==========================
  25. A frame on a graphical display may be "visible", "invisible", or
  26. "iconified". If it is visible, its contents are displayed in the usual
  27. manner. If it is iconified, its contents are not displayed, but there
  28. is a little icon somewhere to bring the frame back into view (some
  29. window managers refer to this state as "minimized" rather than
  30. "iconified", but from Emacs' point of view they are the same thing).
  31. If a frame is invisible, it is not displayed at all.
  32. Visibility is meaningless on text terminals, since only the selected
  33. one is actually displayed in any case.
  34. -- Function: frame-visible-p frame
  35. This function returns the visibility status of frame FRAME. The
  36. value is `t' if FRAME is visible, `nil' if it is invisible, and
  37. `icon' if it is iconified.
  38. On a text terminal, all frames are considered visible, whether they
  39. are currently being displayed or not.
  40. -- Command: iconify-frame &optional frame
  41. This function iconifies frame FRAME. If you omit FRAME, it
  42. iconifies the selected frame.
  43. -- Command: make-frame-visible &optional frame
  44. This function makes frame FRAME visible. If you omit FRAME, it
  45. makes the selected frame visible. This does not raise the frame,
  46. but you can do that with `raise-frame' if you wish (*note Raising
  47. and Lowering::).
  48. -- Command: make-frame-invisible &optional frame force
  49. This function makes frame FRAME invisible. If you omit FRAME, it
  50. makes the selected frame invisible.
  51. Unless FORCE is non-`nil', this function refuses to make FRAME
  52. invisible if all other frames are invisible..
  53. The visibility status of a frame is also available as a frame
  54. parameter. You can read or change it as such. *Note Management
  55. Parameters::. The user can also iconify and deiconify frames with the
  56. window manager. This happens below the level at which Emacs can exert
  57. any control, but Emacs does provide events that you can use to keep
  58. track of such changes. *Note Misc Events::.
  59. 
  60. File: elisp, Node: Raising and Lowering, Next: Frame Configurations, Prev: Visibility of Frames, Up: Frames
  61. 29.11 Raising and Lowering Frames
  62. =================================
  63. Most window systems use a desktop metaphor. Part of this metaphor is
  64. the idea that windows are stacked in a notional third dimension
  65. perpendicular to the screen surface, and thus ordered from "highest" to
  66. "lowest". Where two windows overlap, the one higher up covers the one
  67. underneath. Even a window at the bottom of the stack can be seen if no
  68. other window overlaps it.
  69. A window's place in this ordering is not fixed; in fact, users tend
  70. to change the order frequently. "Raising" a window means moving it
  71. "up", to the top of the stack. "Lowering" a window means moving it to
  72. the bottom of the stack. This motion is in the notional third
  73. dimension only, and does not change the position of the window on the
  74. screen.
  75. With Emacs, frames constitute the windows in the metaphor sketched
  76. above. You can raise and lower frames using these functions:
  77. -- Command: raise-frame &optional frame
  78. This function raises frame FRAME (default, the selected frame).
  79. If FRAME is invisible or iconified, this makes it visible.
  80. -- Command: lower-frame &optional frame
  81. This function lowers frame FRAME (default, the selected frame).
  82. -- User Option: minibuffer-auto-raise
  83. If this is non-`nil', activation of the minibuffer raises the frame
  84. that the minibuffer window is in.
  85. You can also enable auto-raise (raising automatically when a frame is
  86. selected) or auto-lower (lowering automatically when it is deselected)
  87. for any frame using frame parameters. *Note Management Parameters::.
  88. 
  89. File: elisp, Node: Frame Configurations, Next: Mouse Tracking, Prev: Raising and Lowering, Up: Frames
  90. 29.12 Frame Configurations
  91. ==========================
  92. A "frame configuration" records the current arrangement of frames, all
  93. their properties, and the window configuration of each one. (*Note
  94. Window Configurations::.)
  95. -- Function: current-frame-configuration
  96. This function returns a frame configuration list that describes
  97. the current arrangement of frames and their contents.
  98. -- Function: set-frame-configuration configuration &optional nodelete
  99. This function restores the state of frames described in
  100. CONFIGURATION. However, this function does not restore deleted
  101. frames.
  102. Ordinarily, this function deletes all existing frames not listed in
  103. CONFIGURATION. But if NODELETE is non-`nil', the unwanted frames
  104. are iconified instead.
  105. 
  106. File: elisp, Node: Mouse Tracking, Next: Mouse Position, Prev: Frame Configurations, Up: Frames
  107. 29.13 Mouse Tracking
  108. ====================
  109. Sometimes it is useful to "track" the mouse, which means to display
  110. something to indicate where the mouse is and move the indicator as the
  111. mouse moves. For efficient mouse tracking, you need a way to wait until
  112. the mouse actually moves.
  113. The convenient way to track the mouse is to ask for events to
  114. represent mouse motion. Then you can wait for motion by waiting for an
  115. event. In addition, you can easily handle any other sorts of events
  116. that may occur. That is useful, because normally you don't want to
  117. track the mouse forever--only until some other event, such as the
  118. release of a button.
  119. -- Special Form: track-mouse body...
  120. This special form executes BODY, with generation of mouse motion
  121. events enabled. Typically, BODY would use `read-event' to read
  122. the motion events and modify the display accordingly. *Note
  123. Motion Events::, for the format of mouse motion events.
  124. The value of `track-mouse' is that of the last form in BODY. You
  125. should design BODY to return when it sees the up-event that
  126. indicates the release of the button, or whatever kind of event
  127. means it is time to stop tracking.
  128. The usual purpose of tracking mouse motion is to indicate on the
  129. screen the consequences of pushing or releasing a button at the current
  130. position.
  131. In many cases, you can avoid the need to track the mouse by using
  132. the `mouse-face' text property (*note Special Properties::). That
  133. works at a much lower level and runs more smoothly than Lisp-level
  134. mouse tracking.
  135. 
  136. File: elisp, Node: Mouse Position, Next: Pop-Up Menus, Prev: Mouse Tracking, Up: Frames
  137. 29.14 Mouse Position
  138. ====================
  139. The functions `mouse-position' and `set-mouse-position' give access to
  140. the current position of the mouse.
  141. -- Function: mouse-position
  142. This function returns a description of the position of the mouse.
  143. The value looks like `(FRAME X . Y)', where X and Y are integers
  144. giving the position in characters relative to the top left corner
  145. of the inside of FRAME.
  146. -- Variable: mouse-position-function
  147. If non-`nil', the value of this variable is a function for
  148. `mouse-position' to call. `mouse-position' calls this function
  149. just before returning, with its normal return value as the sole
  150. argument, and it returns whatever this function returns to it.
  151. This abnormal hook exists for the benefit of packages like
  152. `xt-mouse.el' that need to do mouse handling at the Lisp level.
  153. -- Function: set-mouse-position frame x y
  154. This function "warps the mouse" to position X, Y in frame FRAME.
  155. The arguments X and Y are integers, giving the position in
  156. characters relative to the top left corner of the inside of FRAME.
  157. If FRAME is not visible, this function does nothing. The return
  158. value is not significant.
  159. -- Function: mouse-pixel-position
  160. This function is like `mouse-position' except that it returns
  161. coordinates in units of pixels rather than units of characters.
  162. -- Function: set-mouse-pixel-position frame x y
  163. This function warps the mouse like `set-mouse-position' except that
  164. X and Y are in units of pixels rather than units of characters.
  165. These coordinates are not required to be within the frame.
  166. If FRAME is not visible, this function does nothing. The return
  167. value is not significant.
  168. -- Function: frame-pointer-visible-p &optional frame
  169. This predicate function returns non-`nil' if the mouse pointer
  170. displayed on FRAME is visible; otherwise it returns `nil'. FRAME
  171. omitted or `nil' means the selected frame. This is useful when
  172. `make-pointer-invisible' is set to `t': it allows to know if the
  173. pointer has been hidden. *Note Mouse Avoidance: (emacs)Mouse
  174. Avoidance.
  175. 
  176. File: elisp, Node: Pop-Up Menus, Next: Dialog Boxes, Prev: Mouse Position, Up: Frames
  177. 29.15 Pop-Up Menus
  178. ==================
  179. When using a window system, a Lisp program can pop up a menu so that
  180. the user can choose an alternative with the mouse.
  181. -- Function: x-popup-menu position menu
  182. This function displays a pop-up menu and returns an indication of
  183. what selection the user makes.
  184. The argument POSITION specifies where on the screen to put the top
  185. left corner of the menu. It can be either a mouse button event
  186. (which says to put the menu where the user actuated the button) or
  187. a list of this form:
  188. ((XOFFSET YOFFSET) WINDOW)
  189. where XOFFSET and YOFFSET are coordinates, measured in pixels,
  190. counting from the top left corner of WINDOW. WINDOW may be a
  191. window or a frame.
  192. If POSITION is `t', it means to use the current mouse position.
  193. If POSITION is `nil', it means to precompute the key binding
  194. equivalents for the keymaps specified in MENU, without actually
  195. displaying or popping up the menu.
  196. The argument MENU says what to display in the menu. It can be a
  197. keymap or a list of keymaps (*note Menu Keymaps::). In this case,
  198. the return value is the list of events corresponding to the user's
  199. choice. This list has more than one element if the choice
  200. occurred in a submenu. (Note that `x-popup-menu' does not
  201. actually execute the command bound to that sequence of events.)
  202. On toolkits that support menu titles, the title is taken from the
  203. prompt string of MENU if MENU is a keymap, or from the prompt
  204. string of the first keymap in MENU if it is a list of keymaps
  205. (*note Defining Menus::).
  206. Alternatively, MENU can have the following form:
  207. (TITLE PANE1 PANE2...)
  208. where each pane is a list of form
  209. (TITLE ITEM1 ITEM2...)
  210. Each item should normally be a cons cell `(LINE . VALUE)', where
  211. LINE is a string, and VALUE is the value to return if that LINE is
  212. chosen. An item can also be a string; this makes a non-selectable
  213. line in the menu.
  214. If the user gets rid of the menu without making a valid choice, for
  215. instance by clicking the mouse away from a valid choice or by
  216. typing keyboard input, then this normally results in a quit and
  217. `x-popup-menu' does not return. But if POSITION is a mouse button
  218. event (indicating that the user invoked the menu with the mouse)
  219. then no quit occurs and `x-popup-menu' returns `nil'.
  220. *Usage note:* Don't use `x-popup-menu' to display a menu if you
  221. could do the job with a prefix key defined with a menu keymap. If you
  222. use a menu keymap to implement a menu, `C-h c' and `C-h a' can see the
  223. individual items in that menu and provide help for them. If instead
  224. you implement the menu by defining a command that calls `x-popup-menu',
  225. the help facilities cannot know what happens inside that command, so
  226. they cannot give any help for the menu's items.
  227. The menu bar mechanism, which lets you switch between submenus by
  228. moving the mouse, cannot look within the definition of a command to see
  229. that it calls `x-popup-menu'. Therefore, if you try to implement a
  230. submenu using `x-popup-menu', it cannot work with the menu bar in an
  231. integrated fashion. This is why all menu bar submenus are implemented
  232. with menu keymaps within the parent menu, and never with
  233. `x-popup-menu'. *Note Menu Bar::.
  234. If you want a menu bar submenu to have contents that vary, you should
  235. still use a menu keymap to implement it. To make the contents vary, add
  236. a hook function to `menu-bar-update-hook' to update the contents of the
  237. menu keymap as necessary.
  238. 
  239. File: elisp, Node: Dialog Boxes, Next: Pointer Shape, Prev: Pop-Up Menus, Up: Frames
  240. 29.16 Dialog Boxes
  241. ==================
  242. A dialog box is a variant of a pop-up menu--it looks a little
  243. different, it always appears in the center of a frame, and it has just
  244. one level and one or more buttons. The main use of dialog boxes is for
  245. asking questions that the user can answer with "yes", "no", and a few
  246. other alternatives. With a single button, they can also force the user
  247. to acknowledge important information. The functions `y-or-n-p' and
  248. `yes-or-no-p' use dialog boxes instead of the keyboard, when called
  249. from commands invoked by mouse clicks.
  250. -- Function: x-popup-dialog position contents &optional header
  251. This function displays a pop-up dialog box and returns an
  252. indication of what selection the user makes. The argument
  253. CONTENTS specifies the alternatives to offer; it has this format:
  254. (TITLE (STRING . VALUE)...)
  255. which looks like the list that specifies a single pane for
  256. `x-popup-menu'.
  257. The return value is VALUE from the chosen alternative.
  258. As for `x-popup-menu', an element of the list may be just a string
  259. instead of a cons cell `(STRING . VALUE)'. That makes a box that
  260. cannot be selected.
  261. If `nil' appears in the list, it separates the left-hand items from
  262. the right-hand items; items that precede the `nil' appear on the
  263. left, and items that follow the `nil' appear on the right. If you
  264. don't include a `nil' in the list, then approximately half the
  265. items appear on each side.
  266. Dialog boxes always appear in the center of a frame; the argument
  267. POSITION specifies which frame. The possible values are as in
  268. `x-popup-menu', but the precise coordinates or the individual
  269. window don't matter; only the frame matters.
  270. If HEADER is non-`nil', the frame title for the box is
  271. `Information', otherwise it is `Question'. The former is used for
  272. `message-box' (*note message-box::).
  273. In some configurations, Emacs cannot display a real dialog box; so
  274. instead it displays the same items in a pop-up menu in the center
  275. of the frame.
  276. If the user gets rid of the dialog box without making a valid
  277. choice, for instance using the window manager, then this produces
  278. a quit and `x-popup-dialog' does not return.
  279. 
  280. File: elisp, Node: Pointer Shape, Next: Window System Selections, Prev: Dialog Boxes, Up: Frames
  281. 29.17 Pointer Shape
  282. ===================
  283. You can specify the mouse pointer style for particular text or images
  284. using the `pointer' text property, and for images with the `:pointer'
  285. and `:map' image properties. The values you can use in these
  286. properties are `text' (or `nil'), `arrow', `hand', `vdrag', `hdrag',
  287. `modeline', and `hourglass'. `text' stands for the usual mouse pointer
  288. style used over text.
  289. Over void parts of the window (parts that do not correspond to any
  290. of the buffer contents), the mouse pointer usually uses the `arrow'
  291. style, but you can specify a different style (one of those above) by
  292. setting `void-text-area-pointer'.
  293. -- User Option: void-text-area-pointer
  294. This variable specifies the mouse pointer style for void text
  295. areas. These include the areas after the end of a line or below
  296. the last line in the buffer. The default is to use the `arrow'
  297. (non-text) pointer style.
  298. When using X, you can specify what the `text' pointer style really
  299. looks like by setting the variable `x-pointer-shape'.
  300. -- Variable: x-pointer-shape
  301. This variable specifies the pointer shape to use ordinarily in the
  302. Emacs frame, for the `text' pointer style.
  303. -- Variable: x-sensitive-text-pointer-shape
  304. This variable specifies the pointer shape to use when the mouse is
  305. over mouse-sensitive text.
  306. These variables affect newly created frames. They do not normally
  307. affect existing frames; however, if you set the mouse color of a frame,
  308. that also installs the current value of those two variables. *Note
  309. Font and Color Parameters::.
  310. The values you can use, to specify either of these pointer shapes,
  311. are defined in the file `lisp/term/x-win.el'. Use `M-x apropos <RET>
  312. x-pointer <RET>' to see a list of them.
  313. 
  314. File: elisp, Node: Window System Selections, Next: Drag and Drop, Prev: Pointer Shape, Up: Frames
  315. 29.18 Window System Selections
  316. ==============================
  317. In the X window system, data can be transferred between different
  318. applications by means of "selections". X defines an arbitrary number
  319. of "selection types", each of which can store its own data; however,
  320. only three are commonly used: the "clipboard", "primary selection", and
  321. "secondary selection". *Note Cut and Paste: (emacs)Cut and Paste, for
  322. Emacs commands that make use of these selections. This section
  323. documents the low-level functions for reading and setting X selections.
  324. -- Command: x-set-selection type data
  325. This function sets an X selection. It takes two arguments: a
  326. selection type TYPE, and the value to assign to it, DATA.
  327. TYPE should be a symbol; it is usually one of `PRIMARY',
  328. `SECONDARY' or `CLIPBOARD'. These are symbols with upper-case
  329. names, in accord with X Window System conventions. If TYPE is
  330. `nil', that stands for `PRIMARY'.
  331. If DATA is `nil', it means to clear out the selection. Otherwise,
  332. DATA may be a string, a symbol, an integer (or a cons of two
  333. integers or list of two integers), an overlay, or a cons of two
  334. markers pointing to the same buffer. An overlay or a pair of
  335. markers stands for text in the overlay or between the markers.
  336. The argument DATA may also be a vector of valid non-vector
  337. selection values.
  338. This function returns DATA.
  339. -- Function: x-get-selection &optional type data-type
  340. This function accesses selections set up by Emacs or by other X
  341. clients. It takes two optional arguments, TYPE and DATA-TYPE.
  342. The default for TYPE, the selection type, is `PRIMARY'.
  343. The DATA-TYPE argument specifies the form of data conversion to
  344. use, to convert the raw data obtained from another X client into
  345. Lisp data. Meaningful values include `TEXT', `STRING',
  346. `UTF8_STRING', `TARGETS', `LENGTH', `DELETE', `FILE_NAME',
  347. `CHARACTER_POSITION', `NAME', `LINE_NUMBER', `COLUMN_NUMBER',
  348. `OWNER_OS', `HOST_NAME', `USER', `CLASS', `ATOM', and `INTEGER'.
  349. (These are symbols with upper-case names in accord with X
  350. conventions.) The default for DATA-TYPE is `STRING'.
  351. -- User Option: selection-coding-system
  352. This variable specifies the coding system to use when reading and
  353. writing selections or the clipboard. *Note Coding Systems::. The
  354. default is `compound-text-with-extensions', which converts to the
  355. text representation that X11 normally uses.
  356. When Emacs runs on MS-Windows, it does not implement X selections in
  357. general, but it does support the clipboard. `x-get-selection' and
  358. `x-set-selection' on MS-Windows support the text data type only; if the
  359. clipboard holds other types of data, Emacs treats the clipboard as
  360. empty.
  361. 
  362. File: elisp, Node: Drag and Drop, Next: Color Names, Prev: Window System Selections, Up: Frames
  363. 29.19 Drag and Drop
  364. ===================
  365. When a user drags something from another application over Emacs, that
  366. other application expects Emacs to tell it if Emacs can handle the data
  367. that is dragged. The variable `x-dnd-test-function' is used by Emacs
  368. to determine what to reply. The default value is
  369. `x-dnd-default-test-function' which accepts drops if the type of the
  370. data to be dropped is present in `x-dnd-known-types'. You can
  371. customize `x-dnd-test-function' and/or `x-dnd-known-types' if you want
  372. Emacs to accept or reject drops based on some other criteria.
  373. If you want to change the way Emacs handles drop of different types
  374. or add a new type, customize `x-dnd-types-alist'. This requires
  375. detailed knowledge of what types other applications use for drag and
  376. drop.
  377. When an URL is dropped on Emacs it may be a file, but it may also be
  378. another URL type (ftp, http, etc.). Emacs first checks
  379. `dnd-protocol-alist' to determine what to do with the URL. If there is
  380. no match there and if `browse-url-browser-function' is an alist, Emacs
  381. looks for a match there. If no match is found the text for the URL is
  382. inserted. If you want to alter Emacs behavior, you can customize these
  383. variables.
  384. 
  385. File: elisp, Node: Color Names, Next: Text Terminal Colors, Prev: Drag and Drop, Up: Frames
  386. 29.20 Color Names
  387. =================
  388. A color name is text (usually in a string) that specifies a color.
  389. Symbolic names such as `black', `white', `red', etc., are allowed; use
  390. `M-x list-colors-display' to see a list of defined names. You can also
  391. specify colors numerically in forms such as `#RGB' and `RGB:R/G/B',
  392. where R specifies the red level, G specifies the green level, and B
  393. specifies the blue level. You can use either one, two, three, or four
  394. hex digits for R; then you must use the same number of hex digits for
  395. all G and B as well, making either 3, 6, 9 or 12 hex digits in all.
  396. (See the documentation of the X Window System for more details about
  397. numerical RGB specification of colors.)
  398. These functions provide a way to determine which color names are
  399. valid, and what they look like. In some cases, the value depends on the
  400. "selected frame", as described below; see *note Input Focus::, for the
  401. meaning of the term "selected frame".
  402. To read user input of color names with completion, use `read-color'
  403. (*note read-color: High-Level Completion.).
  404. -- Function: color-defined-p color &optional frame
  405. This function reports whether a color name is meaningful. It
  406. returns `t' if so; otherwise, `nil'. The argument FRAME says
  407. which frame's display to ask about; if FRAME is omitted or `nil',
  408. the selected frame is used.
  409. Note that this does not tell you whether the display you are using
  410. really supports that color. When using X, you can ask for any
  411. defined color on any kind of display, and you will get some
  412. result--typically, the closest it can do. To determine whether a
  413. frame can really display a certain color, use `color-supported-p'
  414. (see below).
  415. This function used to be called `x-color-defined-p', and that name
  416. is still supported as an alias.
  417. -- Function: defined-colors &optional frame
  418. This function returns a list of the color names that are defined
  419. and supported on frame FRAME (default, the selected frame). If
  420. FRAME does not support colors, the value is `nil'.
  421. This function used to be called `x-defined-colors', and that name
  422. is still supported as an alias.
  423. -- Function: color-supported-p color &optional frame background-p
  424. This returns `t' if FRAME can really display the color COLOR (or
  425. at least something close to it). If FRAME is omitted or `nil',
  426. the question applies to the selected frame.
  427. Some terminals support a different set of colors for foreground and
  428. background. If BACKGROUND-P is non-`nil', that means you are
  429. asking whether COLOR can be used as a background; otherwise you
  430. are asking whether it can be used as a foreground.
  431. The argument COLOR must be a valid color name.
  432. -- Function: color-gray-p color &optional frame
  433. This returns `t' if COLOR is a shade of gray, as defined on
  434. FRAME's display. If FRAME is omitted or `nil', the question
  435. applies to the selected frame. If COLOR is not a valid color
  436. name, this function returns `nil'.
  437. -- Function: color-values color &optional frame
  438. This function returns a value that describes what COLOR should
  439. ideally look like on FRAME. If COLOR is defined, the value is a
  440. list of three integers, which give the amount of red, the amount
  441. of green, and the amount of blue. Each integer ranges in
  442. principle from 0 to 65535, but some displays may not use the full
  443. range. This three-element list is called the "rgb values" of the
  444. color.
  445. If COLOR is not defined, the value is `nil'.
  446. (color-values "black")
  447. => (0 0 0)
  448. (color-values "white")
  449. => (65280 65280 65280)
  450. (color-values "red")
  451. => (65280 0 0)
  452. (color-values "pink")
  453. => (65280 49152 51968)
  454. (color-values "hungry")
  455. => nil
  456. The color values are returned for FRAME's display. If FRAME is
  457. omitted or `nil', the information is returned for the selected
  458. frame's display. If the frame cannot display colors, the value is
  459. `nil'.
  460. This function used to be called `x-color-values', and that name is
  461. still supported as an alias.
  462. 
  463. File: elisp, Node: Text Terminal Colors, Next: Resources, Prev: Color Names, Up: Frames
  464. 29.21 Text Terminal Colors
  465. ==========================
  466. Text terminals usually support only a small number of colors, and the
  467. computer uses small integers to select colors on the terminal. This
  468. means that the computer cannot reliably tell what the selected color
  469. looks like; instead, you have to inform your application which small
  470. integers correspond to which colors. However, Emacs does know the
  471. standard set of colors and will try to use them automatically.
  472. The functions described in this section control how terminal colors
  473. are used by Emacs.
  474. Several of these functions use or return "rgb values", described in
  475. *note Color Names::.
  476. These functions accept a display (either a frame or the name of a
  477. terminal) as an optional argument. We hope in the future to make Emacs
  478. support different colors on different text terminals; then this
  479. argument will specify which terminal to operate on (the default being
  480. the selected frame's terminal; *note Input Focus::). At present,
  481. though, the FRAME argument has no effect.
  482. -- Function: tty-color-define name number &optional rgb frame
  483. This function associates the color name NAME with color number
  484. NUMBER on the terminal.
  485. The optional argument RGB, if specified, is an rgb value, a list
  486. of three numbers that specify what the color actually looks like.
  487. If you do not specify RGB, then this color cannot be used by
  488. `tty-color-approximate' to approximate other colors, because Emacs
  489. will not know what it looks like.
  490. -- Function: tty-color-clear &optional frame
  491. This function clears the table of defined colors for a text
  492. terminal.
  493. -- Function: tty-color-alist &optional frame
  494. This function returns an alist recording the known colors
  495. supported by a text terminal.
  496. Each element has the form `(NAME NUMBER . RGB)' or `(NAME
  497. NUMBER)'. Here, NAME is the color name, NUMBER is the number used
  498. to specify it to the terminal. If present, RGB is a list of three
  499. color values (for red, green, and blue) that says what the color
  500. actually looks like.
  501. -- Function: tty-color-approximate rgb &optional frame
  502. This function finds the closest color, among the known colors
  503. supported for DISPLAY, to that described by the rgb value RGB (a
  504. list of color values). The return value is an element of
  505. `tty-color-alist'.
  506. -- Function: tty-color-translate color &optional frame
  507. This function finds the closest color to COLOR among the known
  508. colors supported for DISPLAY and returns its index (an integer).
  509. If the name COLOR is not defined, the value is `nil'.
  510. 
  511. File: elisp, Node: Resources, Next: Display Feature Testing, Prev: Text Terminal Colors, Up: Frames
  512. 29.22 X Resources
  513. =================
  514. This section describes some of the functions and variables for querying
  515. and using X resources, or their equivalent on your operating system.
  516. *Note X Resources: (emacs)X Resources, for more information about X
  517. resources.
  518. -- Function: x-get-resource attribute class &optional component
  519. subclass
  520. The function `x-get-resource' retrieves a resource value from the X
  521. Window defaults database.
  522. Resources are indexed by a combination of a "key" and a "class".
  523. This function searches using a key of the form
  524. `INSTANCE.ATTRIBUTE' (where INSTANCE is the name under which Emacs
  525. was invoked), and using `Emacs.CLASS' as the class.
  526. The optional arguments COMPONENT and SUBCLASS add to the key and
  527. the class, respectively. You must specify both of them or neither.
  528. If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE',
  529. and the class is `Emacs.CLASS.SUBCLASS'.
  530. -- Variable: x-resource-class
  531. This variable specifies the application name that `x-get-resource'
  532. should look up. The default value is `"Emacs"'. You can examine X
  533. resources for application names other than "Emacs" by binding this
  534. variable to some other string, around a call to `x-get-resource'.
  535. -- Variable: x-resource-name
  536. This variable specifies the instance name that `x-get-resource'
  537. should look up. The default value is the name Emacs was invoked
  538. with, or the value specified with the `-name' or `-rn' switches.
  539. To illustrate some of the above, suppose that you have the line:
  540. xterm.vt100.background: yellow
  541. in your X resources file (whose name is usually `~/.Xdefaults' or
  542. `~/.Xresources'). Then:
  543. (let ((x-resource-class "XTerm") (x-resource-name "xterm"))
  544. (x-get-resource "vt100.background" "VT100.Background"))
  545. => "yellow"
  546. (let ((x-resource-class "XTerm") (x-resource-name "xterm"))
  547. (x-get-resource "background" "VT100" "vt100" "Background"))
  548. => "yellow"
  549. -- Variable: inhibit-x-resources
  550. If this variable is non-`nil', Emacs does not look up X resources,
  551. and X resources do not have any effect when creating new frames.
  552. 
  553. File: elisp, Node: Display Feature Testing, Prev: Resources, Up: Frames
  554. 29.23 Display Feature Testing
  555. =============================
  556. The functions in this section describe the basic capabilities of a
  557. particular display. Lisp programs can use them to adapt their behavior
  558. to what the display can do. For example, a program that ordinarily uses
  559. a popup menu could use the minibuffer if popup menus are not supported.
  560. The optional argument DISPLAY in these functions specifies which
  561. display to ask the question about. It can be a display name, a frame
  562. (which designates the display that frame is on), or `nil' (which refers
  563. to the selected frame's display, *note Input Focus::).
  564. *Note Color Names::, *note Text Terminal Colors::, for other
  565. functions to obtain information about displays.
  566. -- Function: display-popup-menus-p &optional display
  567. This function returns `t' if popup menus are supported on DISPLAY,
  568. `nil' if not. Support for popup menus requires that the mouse be
  569. available, since the user cannot choose menu items without a mouse.
  570. -- Function: display-graphic-p &optional display
  571. This function returns `t' if DISPLAY is a graphic display capable
  572. of displaying several frames and several different fonts at once.
  573. This is true for displays that use a window system such as X, and
  574. false for text terminals.
  575. -- Function: display-mouse-p &optional display
  576. This function returns `t' if DISPLAY has a mouse available, `nil'
  577. if not.
  578. -- Function: display-color-p &optional display
  579. This function returns `t' if the screen is a color screen. It
  580. used to be called `x-display-color-p', and that name is still
  581. supported as an alias.
  582. -- Function: display-grayscale-p &optional display
  583. This function returns `t' if the screen can display shades of gray.
  584. (All color displays can do this.)
  585. -- Function: display-supports-face-attributes-p attributes &optional
  586. display
  587. This function returns non-`nil' if all the face attributes in
  588. ATTRIBUTES are supported (*note Face Attributes::).
  589. The definition of `supported' is somewhat heuristic, but basically
  590. means that a face containing all the attributes in ATTRIBUTES,
  591. when merged with the default face for display, can be represented
  592. in a way that's
  593. 1. different in appearance than the default face, and
  594. 2. `close in spirit' to what the attributes specify, if not
  595. exact.
  596. Point (2) implies that a `:weight black' attribute will be
  597. satisfied by any display that can display bold, as will
  598. `:foreground "yellow"' as long as some yellowish color can be
  599. displayed, but `:slant italic' will _not_ be satisfied by the tty
  600. display code's automatic substitution of a `dim' face for italic.
  601. -- Function: display-selections-p &optional display
  602. This function returns `t' if DISPLAY supports selections.
  603. Windowed displays normally support selections, but they may also be
  604. supported in some other cases.
  605. -- Function: display-images-p &optional display
  606. This function returns `t' if DISPLAY can display images. Windowed
  607. displays ought in principle to handle images, but some systems
  608. lack the support for that. On a display that does not support
  609. images, Emacs cannot display a tool bar.
  610. -- Function: display-screens &optional display
  611. This function returns the number of screens associated with the
  612. display.
  613. -- Function: display-pixel-height &optional display
  614. This function returns the height of the screen in pixels. On a
  615. character terminal, it gives the height in characters.
  616. For graphical terminals, note that on "multi-monitor" setups this
  617. refers to the pixel width for all physical monitors associated with
  618. DISPLAY. *Note Multiple Terminals::.
  619. -- Function: display-pixel-width &optional display
  620. This function returns the width of the screen in pixels. On a
  621. character terminal, it gives the width in characters.
  622. For graphical terminals, note that on "multi-monitor" setups this
  623. refers to the pixel width for all physical monitors associated with
  624. DISPLAY. *Note Multiple Terminals::.
  625. -- Function: display-mm-height &optional display
  626. This function returns the height of the screen in millimeters, or
  627. `nil' if Emacs cannot get that information.
  628. -- Function: display-mm-width &optional display
  629. This function returns the width of the screen in millimeters, or
  630. `nil' if Emacs cannot get that information.
  631. -- User Option: display-mm-dimensions-alist
  632. This variable allows the user to specify the dimensions of
  633. graphical displays returned by `display-mm-height' and
  634. `display-mm-width' in case the system provides incorrect values.
  635. -- Function: display-backing-store &optional display
  636. This function returns the backing store capability of the display.
  637. Backing store means recording the pixels of windows (and parts of
  638. windows) that are not exposed, so that when exposed they can be
  639. displayed very quickly.
  640. Values can be the symbols `always', `when-mapped', or
  641. `not-useful'. The function can also return `nil' when the
  642. question is inapplicable to a certain kind of display.
  643. -- Function: display-save-under &optional display
  644. This function returns non-`nil' if the display supports the
  645. SaveUnder feature. That feature is used by pop-up windows to save
  646. the pixels they obscure, so that they can pop down quickly.
  647. -- Function: display-planes &optional display
  648. This function returns the number of planes the display supports.
  649. This is typically the number of bits per pixel. For a tty
  650. display, it is log to base two of the number of colors supported.
  651. -- Function: display-visual-class &optional display
  652. This function returns the visual class for the screen. The value
  653. is one of the symbols `static-gray' (a limited, unchangeable number
  654. of grays), `gray-scale' (a full range of grays), `static-color' (a
  655. limited, unchangeable number of colors), `pseudo-color' (a limited
  656. number of colors), `true-color' (a full range of colors), and
  657. `direct-color' (a full range of colors).
  658. -- Function: display-color-cells &optional display
  659. This function returns the number of color cells the screen
  660. supports.
  661. These functions obtain additional information specifically about X
  662. displays.
  663. -- Function: x-server-version &optional display
  664. This function returns the list of version numbers of the X server
  665. running the display. The value is a list of three integers: the
  666. major and minor version numbers of the X protocol, and the
  667. distributor-specific release number of the X server software
  668. itself.
  669. -- Function: x-server-vendor &optional display
  670. This function returns the "vendor" that provided the X server
  671. software (as a string). Really this means whoever distributes the
  672. X server.
  673. When the developers of X labeled software distributors as
  674. "vendors", they showed their false assumption that no system could
  675. ever be developed and distributed noncommercially.
  676. 
  677. File: elisp, Node: Positions, Next: Markers, Prev: Frames, Up: Top
  678. 30 Positions
  679. ************
  680. A "position" is the index of a character in the text of a buffer. More
  681. precisely, a position identifies the place between two characters (or
  682. before the first character, or after the last character), so we can
  683. speak of the character before or after a given position. However, we
  684. often speak of the character "at" a position, meaning the character
  685. after that position.
  686. Positions are usually represented as integers starting from 1, but
  687. can also be represented as "markers"--special objects that relocate
  688. automatically when text is inserted or deleted so they stay with the
  689. surrounding characters. Functions that expect an argument to be a
  690. position (an integer), but accept a marker as a substitute, normally
  691. ignore which buffer the marker points into; they convert the marker to
  692. an integer, and use that integer, exactly as if you had passed the
  693. integer as the argument, even if the marker points to the "wrong"
  694. buffer. A marker that points nowhere cannot convert to an integer;
  695. using it instead of an integer causes an error. *Note Markers::.
  696. See also the "field" feature (*note Fields::), which provides
  697. functions that are used by many cursor-motion commands.
  698. * Menu:
  699. * Point:: The special position where editing takes place.
  700. * Motion:: Changing point.
  701. * Excursions:: Temporary motion and buffer changes.
  702. * Narrowing:: Restricting editing to a portion of the buffer.
  703. 
  704. File: elisp, Node: Point, Next: Motion, Up: Positions
  705. 30.1 Point
  706. ==========
  707. "Point" is a special buffer position used by many editing commands,
  708. including the self-inserting typed characters and text insertion
  709. functions. Other commands move point through the text to allow editing
  710. and insertion at different places.
  711. Like other positions, point designates a place between two characters
  712. (or before the first character, or after the last character), rather
  713. than a particular character. Usually terminals display the cursor over
  714. the character that immediately follows point; point is actually before
  715. the character on which the cursor sits.
  716. The value of point is a number no less than 1, and no greater than
  717. the buffer size plus 1. If narrowing is in effect (*note Narrowing::),
  718. then point is constrained to fall within the accessible portion of the
  719. buffer (possibly at one end of it).
  720. Each buffer has its own value of point, which is independent of the
  721. value of point in other buffers. Each window also has a value of point,
  722. which is independent of the value of point in other windows on the same
  723. buffer. This is why point can have different values in various windows
  724. that display the same buffer. When a buffer appears in only one window,
  725. the buffer's point and the window's point normally have the same value,
  726. so the distinction is rarely important. *Note Window Point::, for more
  727. details.
  728. -- Function: point
  729. This function returns the value of point in the current buffer, as
  730. an integer.
  731. (point)
  732. => 175
  733. -- Function: point-min
  734. This function returns the minimum accessible value of point in the
  735. current buffer. This is normally 1, but if narrowing is in
  736. effect, it is the position of the start of the region that you
  737. narrowed to. (*Note Narrowing::.)
  738. -- Function: point-max
  739. This function returns the maximum accessible value of point in the
  740. current buffer. This is `(1+ (buffer-size))', unless narrowing is
  741. in effect, in which case it is the position of the end of the
  742. region that you narrowed to. (*Note Narrowing::.)
  743. -- Function: buffer-end flag
  744. This function returns `(point-max)' if FLAG is greater than 0,
  745. `(point-min)' otherwise. The argument FLAG must be a number.
  746. -- Function: buffer-size &optional buffer
  747. This function returns the total number of characters in the current
  748. buffer. In the absence of any narrowing (*note Narrowing::),
  749. `point-max' returns a value one larger than this.
  750. If you specify a buffer, BUFFER, then the value is the size of
  751. BUFFER.
  752. (buffer-size)
  753. => 35
  754. (point-max)
  755. => 36
  756. 
  757. File: elisp, Node: Motion, Next: Excursions, Prev: Point, Up: Positions
  758. 30.2 Motion
  759. ===========
  760. Motion functions change the value of point, either relative to the
  761. current value of point, relative to the beginning or end of the buffer,
  762. or relative to the edges of the selected window. *Note Point::.
  763. * Menu:
  764. * Character Motion:: Moving in terms of characters.
  765. * Word Motion:: Moving in terms of words.
  766. * Buffer End Motion:: Moving to the beginning or end of the buffer.
  767. * Text Lines:: Moving in terms of lines of text.
  768. * Screen Lines:: Moving in terms of lines as displayed.
  769. * List Motion:: Moving by parsing lists and sexps.
  770. * Skipping Characters:: Skipping characters belonging to a certain set.
  771. 
  772. File: elisp, Node: Character Motion, Next: Word Motion, Up: Motion
  773. 30.2.1 Motion by Characters
  774. ---------------------------
  775. These functions move point based on a count of characters. `goto-char'
  776. is the fundamental primitive; the other functions use that.
  777. -- Command: goto-char position
  778. This function sets point in the current buffer to the value
  779. POSITION. If POSITION is less than 1, it moves point to the
  780. beginning of the buffer. If POSITION is greater than the length
  781. of the buffer, it moves point to the end.
  782. If narrowing is in effect, POSITION still counts from the
  783. beginning of the buffer, but point cannot go outside the accessible
  784. portion. If POSITION is out of range, `goto-char' moves point to
  785. the beginning or the end of the accessible portion.
  786. When this function is called interactively, POSITION is the
  787. numeric prefix argument, if provided; otherwise it is read from the
  788. minibuffer.
  789. `goto-char' returns POSITION.
  790. -- Command: forward-char &optional count
  791. This function moves point COUNT characters forward, towards the
  792. end of the buffer (or backward, towards the beginning of the
  793. buffer, if COUNT is negative). If COUNT is `nil', the default is
  794. 1.
  795. If this attempts to move past the beginning or end of the buffer
  796. (or the limits of the accessible portion, when narrowing is in
  797. effect), it signals an error with error symbol
  798. `beginning-of-buffer' or `end-of-buffer'.
  799. In an interactive call, COUNT is the numeric prefix argument.
  800. -- Command: backward-char &optional count
  801. This is just like `forward-char' except that it moves in the
  802. opposite direction.
  803. 
  804. File: elisp, Node: Word Motion, Next: Buffer End Motion, Prev: Character Motion, Up: Motion
  805. 30.2.2 Motion by Words
  806. ----------------------
  807. These functions for parsing words use the syntax table to decide
  808. whether a given character is part of a word. *Note Syntax Tables::.
  809. -- Command: forward-word &optional count
  810. This function moves point forward COUNT words (or backward if
  811. COUNT is negative). If COUNT is `nil', it moves forward one word.
  812. "Moving one word" means moving until point crosses a
  813. word-constituent character and then encounters a word-separator
  814. character. However, this function cannot move point past the
  815. boundary of the accessible portion of the buffer, or across a
  816. field boundary (*note Fields::). The most common case of a field
  817. boundary is the end of the prompt in the minibuffer.
  818. If it is possible to move COUNT words, without being stopped
  819. prematurely by the buffer boundary or a field boundary, the value
  820. is `t'. Otherwise, the return value is `nil' and point stops at
  821. the buffer boundary or field boundary.
  822. If `inhibit-field-text-motion' is non-`nil', this function ignores
  823. field boundaries.
  824. In an interactive call, COUNT is specified by the numeric prefix
  825. argument. If COUNT is omitted or `nil', it defaults to 1.
  826. -- Command: backward-word &optional count
  827. This function is just like `forward-word', except that it moves
  828. backward until encountering the front of a word, rather than
  829. forward.
  830. -- User Option: words-include-escapes
  831. This variable affects the behavior of `forward-word' and everything
  832. that uses it. If it is non-`nil', then characters in the "escape"
  833. and "character quote" syntax classes count as part of words.
  834. Otherwise, they do not.
  835. -- Variable: inhibit-field-text-motion
  836. If this variable is non-`nil', certain motion functions including
  837. `forward-word', `forward-sentence', and `forward-paragraph' ignore
  838. field boundaries.
  839. 
  840. File: elisp, Node: Buffer End Motion, Next: Text Lines, Prev: Word Motion, Up: Motion
  841. 30.2.3 Motion to an End of the Buffer
  842. -------------------------------------
  843. To move point to the beginning of the buffer, write:
  844. (goto-char (point-min))
  845. Likewise, to move to the end of the buffer, use:
  846. (goto-char (point-max))
  847. Here are two commands that users use to do these things. They are
  848. documented here to warn you not to use them in Lisp programs, because
  849. they set the mark and display messages in the echo area.
  850. -- Command: beginning-of-buffer &optional n
  851. This function moves point to the beginning of the buffer (or the
  852. limits of the accessible portion, when narrowing is in effect),
  853. setting the mark at the previous position (except in Transient
  854. Mark mode, if the mark is already active, it does not set the
  855. mark.)
  856. If N is non-`nil', then it puts point N tenths of the way from the
  857. beginning of the accessible portion of the buffer. In an
  858. interactive call, N is the numeric prefix argument, if provided;
  859. otherwise N defaults to `nil'.
  860. *Warning:* Don't use this function in Lisp programs!
  861. -- Command: end-of-buffer &optional n
  862. This function moves point to the end of the buffer (or the limits
  863. of the accessible portion, when narrowing is in effect), setting
  864. the mark at the previous position (except in Transient Mark mode
  865. when the mark is already active). If N is non-`nil', then it puts
  866. point N tenths of the way from the end of the accessible portion of
  867. the buffer.
  868. In an interactive call, N is the numeric prefix argument, if
  869. provided; otherwise N defaults to `nil'.
  870. *Warning:* Don't use this function in Lisp programs!
  871. 
  872. File: elisp, Node: Text Lines, Next: Screen Lines, Prev: Buffer End Motion, Up: Motion
  873. 30.2.4 Motion by Text Lines
  874. ---------------------------
  875. Text lines are portions of the buffer delimited by newline characters,
  876. which are regarded as part of the previous line. The first text line
  877. begins at the beginning of the buffer, and the last text line ends at
  878. the end of the buffer whether or not the last character is a newline.
  879. The division of the buffer into text lines is not affected by the width
  880. of the window, by line continuation in display, or by how tabs and
  881. control characters are displayed.
  882. -- Command: beginning-of-line &optional count
  883. This function moves point to the beginning of the current line.
  884. With an argument COUNT not `nil' or 1, it moves forward COUNT-1
  885. lines and then to the beginning of the line.
  886. This function does not move point across a field boundary (*note
  887. Fields::) unless doing so would move beyond there to a different
  888. line; therefore, if COUNT is `nil' or 1, and point starts at a
  889. field boundary, point does not move. To ignore field boundaries,
  890. either bind `inhibit-field-text-motion' to `t', or use the
  891. `forward-line' function instead. For instance, `(forward-line 0)'
  892. does the same thing as `(beginning-of-line)', except that it
  893. ignores field boundaries.
  894. If this function reaches the end of the buffer (or of the
  895. accessible portion, if narrowing is in effect), it positions point
  896. there. No error is signaled.
  897. -- Function: line-beginning-position &optional count
  898. Return the position that `(beginning-of-line COUNT)' would move to.
  899. -- Command: end-of-line &optional count
  900. This function moves point to the end of the current line. With an
  901. argument COUNT not `nil' or 1, it moves forward COUNT-1 lines and
  902. then to the end of the line.
  903. This function does not move point across a field boundary (*note
  904. Fields::) unless doing so would move beyond there to a different
  905. line; therefore, if COUNT is `nil' or 1, and point starts at a
  906. field boundary, point does not move. To ignore field boundaries,
  907. bind `inhibit-field-text-motion' to `t'.
  908. If this function reaches the end of the buffer (or of the
  909. accessible portion, if narrowing is in effect), it positions point
  910. there. No error is signaled.
  911. -- Function: line-end-position &optional count
  912. Return the position that `(end-of-line COUNT)' would move to.
  913. -- Command: forward-line &optional count
  914. This function moves point forward COUNT lines, to the beginning of
  915. the line. If COUNT is negative, it moves point -COUNT lines
  916. backward, to the beginning of a line. If COUNT is zero, it moves
  917. point to the beginning of the current line. If COUNT is `nil',
  918. that means 1.
  919. If `forward-line' encounters the beginning or end of the buffer (or
  920. of the accessible portion) before finding that many lines, it sets
  921. point there. No error is signaled.
  922. `forward-line' returns the difference between COUNT and the number
  923. of lines actually moved. If you attempt to move down five lines
  924. from the beginning of a buffer that has only three lines, point
  925. stops at the end of the last line, and the value will be 2.
  926. In an interactive call, COUNT is the numeric prefix argument.
  927. -- Function: count-lines start end
  928. This function returns the number of lines between the positions
  929. START and END in the current buffer. If START and END are equal,
  930. then it returns 0. Otherwise it returns at least 1, even if START
  931. and END are on the same line. This is because the text between
  932. them, considered in isolation, must contain at least one line
  933. unless it is empty.
  934. -- Command: count-words start end
  935. This function returns the number of words between the positions
  936. START and END in the current buffer.
  937. This function can also be called interactively. In that case, it
  938. prints a message reporting the number of lines, words, and
  939. characters in the buffer, or in the region if the region is active.
  940. -- Function: line-number-at-pos &optional pos
  941. This function returns the line number in the current buffer
  942. corresponding to the buffer position POS. If POS is `nil' or
  943. omitted, the current buffer position is used.
  944. Also see the functions `bolp' and `eolp' in *note Near Point::.
  945. These functions do not move point, but test whether it is already at the
  946. beginning or end of a line.
  947. 
  948. File: elisp, Node: Screen Lines, Next: List Motion, Prev: Text Lines, Up: Motion
  949. 30.2.5 Motion by Screen Lines
  950. -----------------------------
  951. The line functions in the previous section count text lines, delimited
  952. only by newline characters. By contrast, these functions count screen
  953. lines, which are defined by the way the text appears on the screen. A
  954. text line is a single screen line if it is short enough to fit the width
  955. of the selected window, but otherwise it may occupy several screen
  956. lines.
  957. In some cases, text lines are truncated on the screen rather than
  958. continued onto additional screen lines. In these cases,
  959. `vertical-motion' moves point much like `forward-line'. *Note
  960. Truncation::.
  961. Because the width of a given string depends on the flags that control
  962. the appearance of certain characters, `vertical-motion' behaves
  963. differently, for a given piece of text, depending on the buffer it is
  964. in, and even on the selected window (because the width, the truncation
  965. flag, and display table may vary between windows). *Note Usual
  966. Display::.
  967. These functions scan text to determine where screen lines break, and
  968. thus take time proportional to the distance scanned. If you intend to
  969. use them heavily, Emacs provides caches which may improve the
  970. performance of your code. *Note cache-long-line-scans: Truncation.
  971. -- Function: vertical-motion count &optional window
  972. This function moves point to the start of the screen line COUNT
  973. screen lines down from the screen line containing point. If COUNT
  974. is negative, it moves up instead.
  975. The COUNT argument can be a cons cell, `(COLS . LINES)', instead
  976. of an integer. Then the function moves by LINES screen lines, and
  977. puts point COLS columns from the start of that screen line.
  978. The return value is the number of screen lines over which point was
  979. moved. The value may be less in absolute value than COUNT if the
  980. beginning or end of the buffer was reached.
  981. The window WINDOW is used for obtaining parameters such as the
  982. width, the horizontal scrolling, and the display table. But
  983. `vertical-motion' always operates on the current buffer, even if
  984. WINDOW currently displays some other buffer.
  985. -- Function: count-screen-lines &optional beg end count-final-newline
  986. window
  987. This function returns the number of screen lines in the text from
  988. BEG to END. The number of screen lines may be different from the
  989. number of actual lines, due to line continuation, the display
  990. table, etc. If BEG and END are `nil' or omitted, they default to
  991. the beginning and end of the accessible portion of the buffer.
  992. If the region ends with a newline, that is ignored unless the
  993. optional third argument COUNT-FINAL-NEWLINE is non-`nil'.
  994. The optional fourth argument WINDOW specifies the window for
  995. obtaining parameters such as width, horizontal scrolling, and so
  996. on. The default is to use the selected window's parameters.
  997. Like `vertical-motion', `count-screen-lines' always uses the
  998. current buffer, regardless of which buffer is displayed in WINDOW.
  999. This makes possible to use `count-screen-lines' in any buffer,
  1000. whether or not it is currently displayed in some window.
  1001. -- Command: move-to-window-line count
  1002. This function moves point with respect to the text currently
  1003. displayed in the selected window. It moves point to the beginning
  1004. of the screen line COUNT screen lines from the top of the window.
  1005. If COUNT is negative, that specifies a position -COUNT lines from
  1006. the bottom (or the last line of the buffer, if the buffer ends
  1007. above the specified screen position).
  1008. If COUNT is `nil', then point moves to the beginning of the line
  1009. in the middle of the window. If the absolute value of COUNT is
  1010. greater than the size of the window, then point moves to the place
  1011. that would appear on that screen line if the window were tall
  1012. enough. This will probably cause the next redisplay to scroll to
  1013. bring that location onto the screen.
  1014. In an interactive call, COUNT is the numeric prefix argument.
  1015. The value returned is the window line number point has moved to,
  1016. with the top line in the window numbered 0.
  1017. -- Function: compute-motion from frompos to topos width offsets window
  1018. This function scans the current buffer, calculating screen
  1019. positions. It scans the buffer forward from position FROM,
  1020. assuming that is at screen coordinates FROMPOS, to position TO or
  1021. coordinates TOPOS, whichever comes first. It returns the ending
  1022. buffer position and screen coordinates.
  1023. The coordinate arguments FROMPOS and TOPOS are cons cells of the
  1024. form `(HPOS . VPOS)'.
  1025. The argument WIDTH is the number of columns available to display
  1026. text; this affects handling of continuation lines. `nil' means
  1027. the actual number of usable text columns in the window, which is
  1028. equivalent to the value returned by `(window-width window)'.
  1029. The argument OFFSETS is either `nil' or a cons cell of the form
  1030. `(HSCROLL . TAB-OFFSET)'. Here HSCROLL is the number of columns
  1031. not being displayed at the left margin; most callers get this by
  1032. calling `window-hscroll'. Meanwhile, TAB-OFFSET is the offset
  1033. between column numbers on the screen and column numbers in the
  1034. buffer. This can be nonzero in a continuation line, when the
  1035. previous screen lines' widths do not add up to a multiple of
  1036. `tab-width'. It is always zero in a non-continuation line.
  1037. The window WINDOW serves only to specify which display table to
  1038. use. `compute-motion' always operates on the current buffer,
  1039. regardless of what buffer is displayed in WINDOW.
  1040. The return value is a list of five elements:
  1041. (POS HPOS VPOS PREVHPOS CONTIN)
  1042. Here POS is the buffer position where the scan stopped, VPOS is
  1043. the vertical screen position, and HPOS is the horizontal screen
  1044. position.
  1045. The result PREVHPOS is the horizontal position one character back
  1046. from POS. The result CONTIN is `t' if the last line was continued
  1047. after (or within) the previous character.
  1048. For example, to find the buffer position of column COL of screen
  1049. line LINE of a certain window, pass the window's display start
  1050. location as FROM and the window's upper-left coordinates as
  1051. FROMPOS. Pass the buffer's `(point-max)' as TO, to limit the scan
  1052. to the end of the accessible portion of the buffer, and pass LINE
  1053. and COL as TOPOS. Here's a function that does this:
  1054. (defun coordinates-of-position (col line)
  1055. (car (compute-motion (window-start)
  1056. '(0 . 0)
  1057. (point-max)
  1058. (cons col line)
  1059. (window-width)
  1060. (cons (window-hscroll) 0)
  1061. (selected-window))))
  1062. When you use `compute-motion' for the minibuffer, you need to use
  1063. `minibuffer-prompt-width' to get the horizontal position of the
  1064. beginning of the first screen line. *Note Minibuffer Contents::.
  1065. 
  1066. File: elisp, Node: List Motion, Next: Skipping Characters, Prev: Screen Lines, Up: Motion
  1067. 30.2.6 Moving over Balanced Expressions
  1068. ---------------------------------------
  1069. Here are several functions concerned with balanced-parenthesis
  1070. expressions (also called "sexps" in connection with moving across them
  1071. in Emacs). The syntax table controls how these functions interpret
  1072. various characters; see *note Syntax Tables::. *Note Parsing
  1073. Expressions::, for lower-level primitives for scanning sexps or parts of
  1074. sexps. For user-level commands, see *note Commands for Editing with
  1075. Parentheses: (emacs)Parentheses.
  1076. -- Command: forward-list &optional arg
  1077. This function moves forward across ARG (default 1) balanced groups
  1078. of parentheses. (Other syntactic entities such as words or paired
  1079. string quotes are ignored.)
  1080. -- Command: backward-list &optional arg
  1081. This function moves backward across ARG (default 1) balanced
  1082. groups of parentheses. (Other syntactic entities such as words or
  1083. paired string quotes are ignored.)
  1084. -- Command: up-list &optional arg
  1085. This function moves forward out of ARG (default 1) levels of
  1086. parentheses. A negative argument means move backward but still to
  1087. a less deep spot.
  1088. -- Command: down-list &optional arg
  1089. This function moves forward into ARG (default 1) levels of
  1090. parentheses. A negative argument means move backward but still go
  1091. deeper in parentheses (-ARG levels).
  1092. -- Command: forward-sexp &optional arg
  1093. This function moves forward across ARG (default 1) balanced
  1094. expressions. Balanced expressions include both those delimited by
  1095. parentheses and other kinds, such as words and string constants.
  1096. *Note Parsing Expressions::. For example,
  1097. ---------- Buffer: foo ----------
  1098. (concat-!- "foo " (car x) y z)
  1099. ---------- Buffer: foo ----------
  1100. (forward-sexp 3)
  1101. => nil
  1102. ---------- Buffer: foo ----------
  1103. (concat "foo " (car x) y-!- z)
  1104. ---------- Buffer: foo ----------
  1105. -- Command: backward-sexp &optional arg
  1106. This function moves backward across ARG (default 1) balanced
  1107. expressions.
  1108. -- Command: beginning-of-defun &optional arg
  1109. This function moves back to the ARGth beginning of a defun. If
  1110. ARG is negative, this actually moves forward, but it still moves
  1111. to the beginning of a defun, not to the end of one. ARG defaults
  1112. to 1.
  1113. -- Command: end-of-defun &optional arg
  1114. This function moves forward to the ARGth end of a defun. If ARG
  1115. is negative, this actually moves backward, but it still moves to
  1116. the end of a defun, not to the beginning of one. ARG defaults to
  1117. 1.
  1118. -- User Option: defun-prompt-regexp
  1119. If non-`nil', this buffer-local variable holds a regular
  1120. expression that specifies what text can appear before the
  1121. open-parenthesis that starts a defun. That is to say, a defun
  1122. begins on a line that starts with a match for this regular
  1123. expression, followed by a character with open-parenthesis syntax.
  1124. -- User Option: open-paren-in-column-0-is-defun-start
  1125. If this variable's value is non-`nil', an open parenthesis in
  1126. column 0 is considered to be the start of a defun. If it is
  1127. `nil', an open parenthesis in column 0 has no special meaning.
  1128. The default is `t'.
  1129. -- Variable: beginning-of-defun-function
  1130. If non-`nil', this variable holds a function for finding the
  1131. beginning of a defun. The function `beginning-of-defun' calls
  1132. this function instead of using its normal method, passing it its
  1133. optional argument. If the argument is non-`nil', the function
  1134. should move back by that many functions, like `beginning-of-defun'
  1135. does.
  1136. -- Variable: end-of-defun-function
  1137. If non-`nil', this variable holds a function for finding the end of
  1138. a defun. The function `end-of-defun' calls this function instead
  1139. of using its normal method.
  1140. 
  1141. File: elisp, Node: Skipping Characters, Prev: List Motion, Up: Motion
  1142. 30.2.7 Skipping Characters
  1143. --------------------------
  1144. The following two functions move point over a specified set of
  1145. characters. For example, they are often used to skip whitespace. For
  1146. related functions, see *note Motion and Syntax::.
  1147. These functions convert the set string to multibyte if the buffer is
  1148. multibyte, and they convert it to unibyte if the buffer is unibyte, as
  1149. the search functions do (*note Searching and Matching::).
  1150. -- Function: skip-chars-forward character-set &optional limit
  1151. This function moves point in the current buffer forward, skipping
  1152. over a given set of characters. It examines the character
  1153. following point, then advances point if the character matches
  1154. CHARACTER-SET. This continues until it reaches a character that
  1155. does not match. The function returns the number of characters
  1156. moved over.
  1157. The argument CHARACTER-SET is a string, like the inside of a
  1158. `[...]' in a regular expression except that `]' does not terminate
  1159. it, and `\' quotes `^', `-' or `\'. Thus, `"a-zA-Z"' skips over
  1160. all letters, stopping before the first nonletter, and `"^a-zA-Z"'
  1161. skips nonletters stopping before the first letter. See *Note
  1162. Regular Expressions::. Character classes can also be used, e.g.
  1163. `"[:alnum:]"'. See *note Char Classes::.
  1164. If LIMIT is supplied (it must be a number or a marker), it
  1165. specifies the maximum position in the buffer that point can be
  1166. skipped to. Point will stop at or before LIMIT.
  1167. In the following example, point is initially located directly
  1168. before the `T'. After the form is evaluated, point is located at
  1169. the end of that line (between the `t' of `hat' and the newline).
  1170. The function skips all letters and spaces, but not newlines.
  1171. ---------- Buffer: foo ----------
  1172. I read "-!-The cat in the hat
  1173. comes back" twice.
  1174. ---------- Buffer: foo ----------
  1175. (skip-chars-forward "a-zA-Z ")
  1176. => 18
  1177. ---------- Buffer: foo ----------
  1178. I read "The cat in the hat-!-
  1179. comes back" twice.
  1180. ---------- Buffer: foo ----------
  1181. -- Function: skip-chars-backward character-set &optional limit
  1182. This function moves point backward, skipping characters that match
  1183. CHARACTER-SET, until LIMIT. It is just like `skip-chars-forward'
  1184. except for the direction of motion.
  1185. The return value indicates the distance traveled. It is an
  1186. integer that is zero or less.
  1187. 
  1188. File: elisp, Node: Excursions, Next: Narrowing, Prev: Motion, Up: Positions
  1189. 30.3 Excursions
  1190. ===============
  1191. It is often useful to move point "temporarily" within a localized
  1192. portion of the program. This is called an "excursion", and it is done
  1193. with the `save-excursion' special form. This construct remembers the
  1194. initial identity of the current buffer, and its values of point and the
  1195. mark, and restores them after the excursion completes. It is the
  1196. standard way to move point within one part of a program and avoid
  1197. affecting the rest of the program, and is used thousands of times in
  1198. the Lisp sources of Emacs.
  1199. If you only need to save and restore the identity of the current
  1200. buffer, use `save-current-buffer' or `with-current-buffer' instead
  1201. (*note Current Buffer::). If you need to save or restore window
  1202. configurations, see the forms described in *note Window
  1203. Configurations:: and in *note Frame Configurations::.
  1204. -- Special Form: save-excursion body...
  1205. This special form saves the identity of the current buffer and the
  1206. values of point and the mark in it, evaluates BODY, and finally
  1207. restores the buffer and its saved values of point and the mark.
  1208. All three saved values are restored even in case of an abnormal
  1209. exit via `throw' or error (*note Nonlocal Exits::).
  1210. The value returned by `save-excursion' is the result of the last
  1211. form in BODY, or `nil' if no body forms were given.
  1212. Because `save-excursion' only saves point and mark for the buffer
  1213. that was current at the start of the excursion, any changes made to
  1214. point and/or mark in other buffers, during the excursion, will remain
  1215. in effect afterward. This frequently leads to unintended consequences,
  1216. so the byte compiler warns if you call `set-buffer' during an excursion:
  1217. Warning: Use `with-current-buffer' rather than
  1218. save-excursion+set-buffer
  1219. To avoid such problems, you should call `save-excursion' only after
  1220. setting the desired current buffer, as in the following example:
  1221. (defun append-string-to-buffer (string buffer)
  1222. "Append STRING to the end of BUFFER."
  1223. (with-current-buffer buffer
  1224. (save-excursion
  1225. (goto-char (point-max))
  1226. (insert string))))
  1227. Likewise, `save-excursion' does not restore window-buffer
  1228. correspondences altered by functions such as `switch-to-buffer'. One
  1229. way to restore these correspondences, and the selected window, is to
  1230. use `save-window-excursion' inside `save-excursion' (*note Window
  1231. Configurations::).
  1232. *Warning:* Ordinary insertion of text adjacent to the saved point
  1233. value relocates the saved value, just as it relocates all markers.
  1234. More precisely, the saved value is a marker with insertion type `nil'.
  1235. *Note Marker Insertion Types::. Therefore, when the saved point value
  1236. is restored, it normally comes before the inserted text.
  1237. Although `save-excursion' saves the location of the mark, it does
  1238. not prevent functions which modify the buffer from setting
  1239. `deactivate-mark', and thus causing the deactivation of the mark after
  1240. the command finishes. *Note The Mark::.
  1241. 
  1242. File: elisp, Node: Narrowing, Prev: Excursions, Up: Positions
  1243. 30.4 Narrowing
  1244. ==============
  1245. "Narrowing" means limiting the text addressable by Emacs editing
  1246. commands to a limited range of characters in a buffer. The text that
  1247. remains addressable is called the "accessible portion" of the buffer.
  1248. Narrowing is specified with two buffer positions which become the
  1249. beginning and end of the accessible portion. For most editing commands
  1250. and most Emacs primitives, these positions replace the values of the
  1251. beginning and end of the buffer. While narrowing is in effect, no text
  1252. outside the accessible portion is displayed, and point cannot move
  1253. outside the accessible portion.
  1254. Values such as positions or line numbers, which usually count from
  1255. the beginning of the buffer, do so despite narrowing, but the functions
  1256. which use them refuse to operate on text that is inaccessible.
  1257. The commands for saving buffers are unaffected by narrowing; they
  1258. save the entire buffer regardless of any narrowing.
  1259. If you need to display in a single buffer several very different
  1260. types of text, consider using an alternative facility described in
  1261. *note Swapping Text::.
  1262. -- Command: narrow-to-region start end
  1263. This function sets the accessible portion of the current buffer to
  1264. start at START and end at END. Both arguments should be character
  1265. positions.
  1266. In an interactive call, START and END are set to the bounds of the
  1267. current region (point and the mark, with the smallest first).
  1268. -- Command: narrow-to-page &optional move-count
  1269. This function sets the accessible portion of the current buffer to
  1270. include just the current page. An optional first argument
  1271. MOVE-COUNT non-`nil' means to move forward or backward by
  1272. MOVE-COUNT pages and then narrow to one page. The variable
  1273. `page-delimiter' specifies where pages start and end (*note
  1274. Standard Regexps::).
  1275. In an interactive call, MOVE-COUNT is set to the numeric prefix
  1276. argument.
  1277. -- Command: widen
  1278. This function cancels any narrowing in the current buffer, so that
  1279. the entire contents are accessible. This is called "widening".
  1280. It is equivalent to the following expression:
  1281. (narrow-to-region 1 (1+ (buffer-size)))
  1282. -- Special Form: save-restriction body...
  1283. This special form saves the current bounds of the accessible
  1284. portion, evaluates the BODY forms, and finally restores the saved
  1285. bounds, thus restoring the same state of narrowing (or absence
  1286. thereof) formerly in effect. The state of narrowing is restored
  1287. even in the event of an abnormal exit via `throw' or error (*note
  1288. Nonlocal Exits::). Therefore, this construct is a clean way to
  1289. narrow a buffer temporarily.
  1290. The value returned by `save-restriction' is that returned by the
  1291. last form in BODY, or `nil' if no body forms were given.
  1292. *Caution:* it is easy to make a mistake when using the
  1293. `save-restriction' construct. Read the entire description here
  1294. before you try it.
  1295. If BODY changes the current buffer, `save-restriction' still
  1296. restores the restrictions on the original buffer (the buffer whose
  1297. restrictions it saved from), but it does not restore the identity
  1298. of the current buffer.
  1299. `save-restriction' does _not_ restore point and the mark; use
  1300. `save-excursion' for that. If you use both `save-restriction' and
  1301. `save-excursion' together, `save-excursion' should come first (on
  1302. the outside). Otherwise, the old point value would be restored
  1303. with temporary narrowing still in effect. If the old point value
  1304. were outside the limits of the temporary narrowing, this would
  1305. fail to restore it accurately.
  1306. Here is a simple example of correct use of `save-restriction':
  1307. ---------- Buffer: foo ----------
  1308. This is the contents of foo
  1309. This is the contents of foo
  1310. This is the contents of foo-!-
  1311. ---------- Buffer: foo ----------
  1312. (save-excursion
  1313. (save-restriction
  1314. (goto-char 1)
  1315. (forward-line 2)
  1316. (narrow-to-region 1 (point))
  1317. (goto-char (point-min))
  1318. (replace-string "foo" "bar")))
  1319. ---------- Buffer: foo ----------
  1320. This is the contents of bar
  1321. This is the contents of bar
  1322. This is the contents of foo-!-
  1323. ---------- Buffer: foo ----------
  1324. 
  1325. File: elisp, Node: Markers, Next: Text, Prev: Positions, Up: Top
  1326. 31 Markers
  1327. **********
  1328. A "marker" is a Lisp object used to specify a position in a buffer
  1329. relative to the surrounding text. A marker changes its offset from the
  1330. beginning of the buffer automatically whenever text is inserted or
  1331. deleted, so that it stays with the two characters on either side of it.
  1332. * Menu:
  1333. * Overview of Markers:: The components of a marker, and how it relocates.
  1334. * Predicates on Markers:: Testing whether an object is a marker.
  1335. * Creating Markers:: Making empty markers or markers at certain places.
  1336. * Information from Markers:: Finding the marker's buffer or character position.
  1337. * Marker Insertion Types:: Two ways a marker can relocate when you
  1338. insert where it points.
  1339. * Moving Markers:: Moving the marker to a new buffer or position.
  1340. * The Mark:: How "the mark" is implemented with a marker.
  1341. * The Region:: How to access "the region".
  1342. 
  1343. File: elisp, Node: Overview of Markers, Next: Predicates on Markers, Up: Markers
  1344. 31.1 Overview of Markers
  1345. ========================
  1346. A marker specifies a buffer and a position in that buffer. A marker
  1347. can be used to represent a position in functions that require one, just
  1348. as an integer could be used. In that case, the marker's buffer is
  1349. normally ignored. Of course, a marker used in this way usually points
  1350. to a position in the buffer that the function operates on, but that is
  1351. entirely the programmer's responsibility. *Note Positions::, for a
  1352. complete description of positions.
  1353. A marker has three attributes: the marker position, the marker
  1354. buffer, and the insertion type. The marker position is an integer that
  1355. is equivalent (at a given time) to the marker as a position in that
  1356. buffer. But the marker's position value can change during the life of
  1357. the marker, and often does. Insertion and deletion of text in the
  1358. buffer relocate the marker. The idea is that a marker positioned
  1359. between two characters remains between those two characters despite
  1360. insertion and deletion elsewhere in the buffer. Relocation changes the
  1361. integer equivalent of the marker.
  1362. Deleting text around a marker's position leaves the marker between
  1363. the characters immediately before and after the deleted text. Inserting
  1364. text at the position of a marker normally leaves the marker either in
  1365. front of or after the new text, depending on the marker's "insertion
  1366. type" (*note Marker Insertion Types::)--unless the insertion is done
  1367. with `insert-before-markers' (*note Insertion::).
  1368. Insertion and deletion in a buffer must check all the markers and
  1369. relocate them if necessary. This slows processing in a buffer with a
  1370. large number of markers. For this reason, it is a good idea to make a
  1371. marker point nowhere if you are sure you don't need it any more.
  1372. Markers that can no longer be accessed are eventually removed (*note
  1373. Garbage Collection::).
  1374. Because it is common to perform arithmetic operations on a marker
  1375. position, most of these operations (including `+' and `-') accept
  1376. markers as arguments. In such cases, the marker stands for its current
  1377. position.
  1378. Here are examples of creating markers, setting markers, and moving
  1379. point to markers:
  1380. ;; Make a new marker that initially does not point anywhere:
  1381. (setq m1 (make-marker))
  1382. => #<marker in no buffer>
  1383. ;; Set `m1' to point between the 99th and 100th characters
  1384. ;; in the current buffer:
  1385. (set-marker m1 100)
  1386. => #<marker at 100 in markers.texi>
  1387. ;; Now insert one character at the beginning of the buffer:
  1388. (goto-char (point-min))
  1389. => 1
  1390. (insert "Q")
  1391. => nil
  1392. ;; `m1' is updated appropriately.
  1393. m1
  1394. => #<marker at 101 in markers.texi>
  1395. ;; Two markers that point to the same position
  1396. ;; are not `eq', but they are `equal'.
  1397. (setq m2 (copy-marker m1))
  1398. => #<marker at 101 in markers.texi>
  1399. (eq m1 m2)
  1400. => nil
  1401. (equal m1 m2)
  1402. => t
  1403. ;; When you are finished using a marker, make it point nowhere.
  1404. (set-marker m1 nil)
  1405. => #<marker in no buffer>
  1406. 
  1407. File: elisp, Node: Predicates on Markers, Next: Creating Markers, Prev: Overview of Markers, Up: Markers
  1408. 31.2 Predicates on Markers
  1409. ==========================
  1410. You can test an object to see whether it is a marker, or whether it is
  1411. either an integer or a marker. The latter test is useful in connection
  1412. with the arithmetic functions that work with both markers and integers.
  1413. -- Function: markerp object
  1414. This function returns `t' if OBJECT is a marker, `nil' otherwise.
  1415. Note that integers are not markers, even though many functions
  1416. will accept either a marker or an integer.
  1417. -- Function: integer-or-marker-p object
  1418. This function returns `t' if OBJECT is an integer or a marker,
  1419. `nil' otherwise.
  1420. -- Function: number-or-marker-p object
  1421. This function returns `t' if OBJECT is a number (either integer or
  1422. floating point) or a marker, `nil' otherwise.
  1423. 
  1424. File: elisp, Node: Creating Markers, Next: Information from Markers, Prev: Predicates on Markers, Up: Markers
  1425. 31.3 Functions that Create Markers
  1426. ==================================
  1427. When you create a new marker, you can make it point nowhere, or point
  1428. to the present position of point, or to the beginning or end of the
  1429. accessible portion of the buffer, or to the same place as another given
  1430. marker.
  1431. The next four functions all return markers with insertion type
  1432. `nil'. *Note Marker Insertion Types::.
  1433. -- Function: make-marker
  1434. This function returns a newly created marker that does not point
  1435. anywhere.
  1436. (make-marker)
  1437. => #<marker in no buffer>
  1438. -- Function: point-marker
  1439. This function returns a new marker that points to the present
  1440. position of point in the current buffer. *Note Point::. For an
  1441. example, see `copy-marker', below.
  1442. -- Function: point-min-marker
  1443. This function returns a new marker that points to the beginning of
  1444. the accessible portion of the buffer. This will be the beginning
  1445. of the buffer unless narrowing is in effect. *Note Narrowing::.
  1446. -- Function: point-max-marker
  1447. This function returns a new marker that points to the end of the
  1448. accessible portion of the buffer. This will be the end of the
  1449. buffer unless narrowing is in effect. *Note Narrowing::.
  1450. Here are examples of this function and `point-min-marker', shown in
  1451. a buffer containing a version of the source file for the text of
  1452. this chapter.
  1453. (point-min-marker)
  1454. => #<marker at 1 in markers.texi>
  1455. (point-max-marker)
  1456. => #<marker at 24080 in markers.texi>
  1457. (narrow-to-region 100 200)
  1458. => nil
  1459. (point-min-marker)
  1460. => #<marker at 100 in markers.texi>
  1461. (point-max-marker)
  1462. => #<marker at 200 in markers.texi>
  1463. -- Function: copy-marker &optional marker-or-integer insertion-type
  1464. If passed a marker as its argument, `copy-marker' returns a new
  1465. marker that points to the same place and the same buffer as does
  1466. MARKER-OR-INTEGER. If passed an integer as its argument,
  1467. `copy-marker' returns a new marker that points to position
  1468. MARKER-OR-INTEGER in the current buffer.
  1469. The new marker's insertion type is specified by the argument
  1470. INSERTION-TYPE. *Note Marker Insertion Types::.
  1471. If passed an integer argument less than 1, `copy-marker' returns a
  1472. new marker that points to the beginning of the current buffer. If
  1473. passed an integer argument greater than the length of the buffer,
  1474. `copy-marker' returns a new marker that points to the end of the
  1475. buffer.
  1476. (copy-marker 0)
  1477. => #<marker at 1 in markers.texi>
  1478. (copy-marker 90000)
  1479. => #<marker at 24080 in markers.texi>
  1480. An error is signaled if MARKER is neither a marker nor an integer.
  1481. Two distinct markers are considered `equal' (even though not `eq')
  1482. to each other if they have the same position and buffer, or if they
  1483. both point nowhere.
  1484. (setq p (point-marker))
  1485. => #<marker at 2139 in markers.texi>
  1486. (setq q (copy-marker p))
  1487. => #<marker at 2139 in markers.texi>
  1488. (eq p q)
  1489. => nil
  1490. (equal p q)
  1491. => t
  1492. 
  1493. File: elisp, Node: Information from Markers, Next: Marker Insertion Types, Prev: Creating Markers, Up: Markers
  1494. 31.4 Information from Markers
  1495. =============================
  1496. This section describes the functions for accessing the components of a
  1497. marker object.
  1498. -- Function: marker-position marker
  1499. This function returns the position that MARKER points to, or `nil'
  1500. if it points nowhere.
  1501. -- Function: marker-buffer marker
  1502. This function returns the buffer that MARKER points into, or `nil'
  1503. if it points nowhere.
  1504. (setq m (make-marker))
  1505. => #<marker in no buffer>
  1506. (marker-position m)
  1507. => nil
  1508. (marker-buffer m)
  1509. => nil
  1510. (set-marker m 3770 (current-buffer))
  1511. => #<marker at 3770 in markers.texi>
  1512. (marker-buffer m)
  1513. => #<buffer markers.texi>
  1514. (marker-position m)
  1515. => 3770
  1516. -- Function: buffer-has-markers-at position
  1517. This function returns `t' if one or more markers point at position
  1518. POSITION in the current buffer.
  1519. 
  1520. File: elisp, Node: Marker Insertion Types, Next: Moving Markers, Prev: Information from Markers, Up: Markers
  1521. 31.5 Marker Insertion Types
  1522. ===========================
  1523. When you insert text directly at the place where a marker points, there
  1524. are two possible ways to relocate that marker: it can point before the
  1525. inserted text, or point after it. You can specify which one a given
  1526. marker should do by setting its "insertion type". Note that use of
  1527. `insert-before-markers' ignores markers' insertion types, always
  1528. relocating a marker to point after the inserted text.
  1529. -- Function: set-marker-insertion-type marker type
  1530. This function sets the insertion type of marker MARKER to TYPE.
  1531. If TYPE is `t', MARKER will advance when text is inserted at its
  1532. position. If TYPE is `nil', MARKER does not advance when text is
  1533. inserted there.
  1534. -- Function: marker-insertion-type marker
  1535. This function reports the current insertion type of MARKER.
  1536. Most functions that create markers, without an argument allowing to
  1537. specify the insertion type, create them with insertion type `nil'.
  1538. Also, the mark has, by default, insertion type `nil'.
  1539. 
  1540. File: elisp, Node: Moving Markers, Next: The Mark, Prev: Marker Insertion Types, Up: Markers
  1541. 31.6 Moving Marker Positions
  1542. ============================
  1543. This section describes how to change the position of an existing
  1544. marker. When you do this, be sure you know whether the marker is used
  1545. outside of your program, and, if so, what effects will result from
  1546. moving it--otherwise, confusing things may happen in other parts of
  1547. Emacs.
  1548. -- Function: set-marker marker position &optional buffer
  1549. This function moves MARKER to POSITION in BUFFER. If BUFFER is
  1550. not provided, it defaults to the current buffer.
  1551. If POSITION is less than 1, `set-marker' moves MARKER to the
  1552. beginning of the buffer. If POSITION is greater than the size of
  1553. the buffer, `set-marker' moves marker to the end of the buffer.
  1554. If POSITION is `nil' or a marker that points nowhere, then MARKER
  1555. is set to point nowhere.
  1556. The value returned is MARKER.
  1557. (setq m (point-marker))
  1558. => #<marker at 4714 in markers.texi>
  1559. (set-marker m 55)
  1560. => #<marker at 55 in markers.texi>
  1561. (setq b (get-buffer "foo"))
  1562. => #<buffer foo>
  1563. (set-marker m 0 b)
  1564. => #<marker at 1 in foo>
  1565. -- Function: move-marker marker position &optional buffer
  1566. This is another name for `set-marker'.
  1567. 
  1568. File: elisp, Node: The Mark, Next: The Region, Prev: Moving Markers, Up: Markers
  1569. 31.7 The Mark
  1570. =============
  1571. Each buffer has a special marker, which is designated "the mark". When
  1572. a buffer is newly created, this marker exists but does not point
  1573. anywhere; this means that the mark "doesn't exist" in that buffer yet.
  1574. Subsequent commands can set the mark.
  1575. The mark specifies a position to bound a range of text for many
  1576. commands, such as `kill-region' and `indent-rigidly'. These commands
  1577. typically act on the text between point and the mark, which is called
  1578. the "region". If you are writing a command that operates on the
  1579. region, don't examine the mark directly; instead, use `interactive'
  1580. with the `r' specification. This provides the values of point and the
  1581. mark as arguments to the command in an interactive call, but permits
  1582. other Lisp programs to specify arguments explicitly. *Note Interactive
  1583. Codes::.
  1584. Some commands set the mark as a side-effect. Commands should do
  1585. this only if it has a potential use to the user, and never for their
  1586. own internal purposes. For example, the `replace-regexp' command sets
  1587. the mark to the value of point before doing any replacements, because
  1588. this enables the user to move back there conveniently after the replace
  1589. is finished.
  1590. Once the mark "exists" in a buffer, it normally never ceases to
  1591. exist. However, it may become "inactive", if Transient Mark mode is
  1592. enabled. The buffer-local variable `mark-active', if non-`nil', means
  1593. that the mark is active. A command can call the function
  1594. `deactivate-mark' to deactivate the mark directly, or it can request
  1595. deactivation of the mark upon return to the editor command loop by
  1596. setting the variable `deactivate-mark' to a non-`nil' value.
  1597. If Transient Mark mode is enabled, certain editing commands that
  1598. normally apply to text near point, apply instead to the region when the
  1599. mark is active. This is the main motivation for using Transient Mark
  1600. mode. (Another is that this enables highlighting of the region when
  1601. the mark is active. *Note Display::.)
  1602. In addition to the mark, each buffer has a "mark ring" which is a
  1603. list of markers containing previous values of the mark. When editing
  1604. commands change the mark, they should normally save the old value of the
  1605. mark on the mark ring. The variable `mark-ring-max' specifies the
  1606. maximum number of entries in the mark ring; once the list becomes this
  1607. long, adding a new element deletes the last element.
  1608. There is also a separate global mark ring, but that is used only in a
  1609. few particular user-level commands, and is not relevant to Lisp
  1610. programming. So we do not describe it here.
  1611. -- Function: mark &optional force
  1612. This function returns the current buffer's mark position as an
  1613. integer, or `nil' if no mark has ever been set in this buffer.
  1614. If Transient Mark mode is enabled, and `mark-even-if-inactive' is
  1615. `nil', `mark' signals an error if the mark is inactive. However,
  1616. if FORCE is non-`nil', then `mark' disregards inactivity of the
  1617. mark, and returns the mark position (or `nil') anyway.
  1618. -- Function: mark-marker
  1619. This function returns the marker that represents the current
  1620. buffer's mark. It is not a copy, it is the marker used
  1621. internally. Therefore, changing this marker's position will
  1622. directly affect the buffer's mark. Don't do that unless that is
  1623. the effect you want.
  1624. (setq m (mark-marker))
  1625. => #<marker at 3420 in markers.texi>
  1626. (set-marker m 100)
  1627. => #<marker at 100 in markers.texi>
  1628. (mark-marker)
  1629. => #<marker at 100 in markers.texi>
  1630. Like any marker, this marker can be set to point at any buffer you
  1631. like. If you make it point at any buffer other than the one of
  1632. which it is the mark, it will yield perfectly consistent, but
  1633. rather odd, results. We recommend that you not do it!
  1634. -- Function: set-mark position
  1635. This function sets the mark to POSITION, and activates the mark.
  1636. The old value of the mark is _not_ pushed onto the mark ring.
  1637. *Please note:* Use this function only if you want the user to see
  1638. that the mark has moved, and you want the previous mark position to
  1639. be lost. Normally, when a new mark is set, the old one should go
  1640. on the `mark-ring'. For this reason, most applications should use
  1641. `push-mark' and `pop-mark', not `set-mark'.
  1642. Novice Emacs Lisp programmers often try to use the mark for the
  1643. wrong purposes. The mark saves a location for the user's
  1644. convenience. An editing command should not alter the mark unless
  1645. altering the mark is part of the user-level functionality of the
  1646. command. (And, in that case, this effect should be documented.)
  1647. To remember a location for internal use in the Lisp program, store
  1648. it in a Lisp variable. For example:
  1649. (let ((beg (point)))
  1650. (forward-line 1)
  1651. (delete-region beg (point))).
  1652. -- Function: push-mark &optional position nomsg activate
  1653. This function sets the current buffer's mark to POSITION, and
  1654. pushes a copy of the previous mark onto `mark-ring'. If POSITION
  1655. is `nil', then the value of point is used.
  1656. The function `push-mark' normally _does not_ activate the mark.
  1657. To do that, specify `t' for the argument ACTIVATE.
  1658. A `Mark set' message is displayed unless NOMSG is non-`nil'.
  1659. -- Function: pop-mark
  1660. This function pops off the top element of `mark-ring' and makes
  1661. that mark become the buffer's actual mark. This does not move
  1662. point in the buffer, and it does nothing if `mark-ring' is empty.
  1663. It deactivates the mark.
  1664. -- User Option: transient-mark-mode
  1665. This variable, if non-`nil', enables Transient Mark mode. In
  1666. Transient Mark mode, every buffer-modifying primitive sets
  1667. `deactivate-mark'. As a consequence, most commands that modify
  1668. the buffer also deactivate the mark.
  1669. When Transient Mark mode is enabled and the mark is active, many
  1670. commands that normally apply to the text near point instead apply
  1671. to the region. Such commands should use the function
  1672. `use-region-p' to test whether they should operate on the region.
  1673. *Note The Region::.
  1674. Lisp programs can set `transient-mark-mode' to non-`nil', non-`t'
  1675. values to enable Transient Mark mode temporarily. If the value is
  1676. `lambda', Transient Mark mode is automatically turned off after
  1677. any action, such as buffer modification, that would normally
  1678. deactivate the mark. If the value is `(only . OLDVAL)', then
  1679. `transient-mark-mode' is set to the value OLDVAL after any
  1680. subsequent command that moves point and is not shift-translated
  1681. (*note shift-translation: Key Sequence Input.), or after any other
  1682. action that would normally deactivate the mark.
  1683. -- User Option: mark-even-if-inactive
  1684. If this is non-`nil', Lisp programs and the Emacs user can use the
  1685. mark even when it is inactive. This option affects the behavior of
  1686. Transient Mark mode. When the option is non-`nil', deactivation of
  1687. the mark turns off region highlighting, but commands that use the
  1688. mark behave as if the mark were still active.
  1689. -- Variable: deactivate-mark
  1690. If an editor command sets this variable non-`nil', then the editor
  1691. command loop deactivates the mark after the command returns (if
  1692. Transient Mark mode is enabled). All the primitives that change
  1693. the buffer set `deactivate-mark', to deactivate the mark when the
  1694. command is finished.
  1695. To write Lisp code that modifies the buffer without causing
  1696. deactivation of the mark at the end of the command, bind
  1697. `deactivate-mark' to `nil' around the code that does the
  1698. modification. For example:
  1699. (let (deactivate-mark)
  1700. (insert " "))
  1701. -- Function: deactivate-mark &optional force
  1702. If Transient Mark mode is enabled or FORCE is non-`nil', this
  1703. function deactivates the mark and runs the normal hook
  1704. `deactivate-mark-hook'. Otherwise, it does nothing.
  1705. -- Variable: mark-active
  1706. The mark is active when this variable is non-`nil'. This variable
  1707. is always buffer-local in each buffer. Do _not_ use the value of
  1708. this variable to decide whether a command that normally operates
  1709. on text near point should operate on the region instead. Use the
  1710. function `use-region-p' for that (*note The Region::).
  1711. -- Variable: activate-mark-hook
  1712. -- Variable: deactivate-mark-hook
  1713. These normal hooks are run, respectively, when the mark becomes
  1714. active and when it becomes inactive. The hook
  1715. `activate-mark-hook' is also run at the end of the command loop if
  1716. the mark is active and it is possible that the region may have
  1717. changed.
  1718. -- Function: handle-shift-selection
  1719. This function implements the "shift-selection" behavior of
  1720. point-motion commands. *Note Shift Selection: (emacs)Shift
  1721. Selection. It is called automatically by the Emacs command loop
  1722. whenever a command with a `^' character in its `interactive' spec
  1723. is invoked, before the command itself is executed (*note ^:
  1724. Interactive Codes.).
  1725. If `shift-select-mode' is non-`nil' and the current command was
  1726. invoked via shift translation (*note shift-translation: Key
  1727. Sequence Input.), this function sets the mark and temporarily
  1728. activates the region, unless the region was already temporarily
  1729. activated in this way. Otherwise, if the region has been activated
  1730. temporarily, it deactivates the mark and restores the variable
  1731. `transient-mark-mode' to its earlier value.
  1732. -- Variable: mark-ring
  1733. The value of this buffer-local variable is the list of saved former
  1734. marks of the current buffer, most recent first.
  1735. mark-ring
  1736. => (#<marker at 11050 in markers.texi>
  1737. #<marker at 10832 in markers.texi>
  1738. ...)
  1739. -- User Option: mark-ring-max
  1740. The value of this variable is the maximum size of `mark-ring'. If
  1741. more marks than this are pushed onto the `mark-ring', `push-mark'
  1742. discards an old mark when it adds a new one.
  1743. 
  1744. File: elisp, Node: The Region, Prev: The Mark, Up: Markers
  1745. 31.8 The Region
  1746. ===============
  1747. The text between point and the mark is known as "the region". Various
  1748. functions operate on text delimited by point and the mark, but only
  1749. those functions specifically related to the region itself are described
  1750. here.
  1751. The next two functions signal an error if the mark does not point
  1752. anywhere. If Transient Mark mode is enabled and
  1753. `mark-even-if-inactive' is `nil', they also signal an error if the mark
  1754. is inactive.
  1755. -- Function: region-beginning
  1756. This function returns the position of the beginning of the region
  1757. (as an integer). This is the position of either point or the mark,
  1758. whichever is smaller.
  1759. -- Function: region-end
  1760. This function returns the position of the end of the region (as an
  1761. integer). This is the position of either point or the mark,
  1762. whichever is larger.
  1763. Instead of using `region-beginning' and `region-end', a command
  1764. designed to operate on a region should normally use `interactive' with
  1765. the `r' specification to find the beginning and end of the region.
  1766. This lets other Lisp programs specify the bounds explicitly as
  1767. arguments. *Note Interactive Codes::.
  1768. -- Function: use-region-p
  1769. This function returns `t' if Transient Mark mode is enabled, the
  1770. mark is active, and there is a valid region in the buffer. This
  1771. function is intended to be used by commands that operate on the
  1772. region, instead of on text near point, when the mark is active.
  1773. A region is valid if it has a non-zero size, or if the user option
  1774. `use-empty-active-region' is non-`nil' (by default, it is `nil').
  1775. The function `region-active-p' is similar to `use-region-p', but
  1776. considers all regions as valid. In most cases, you should not use
  1777. `region-active-p', since if the region is empty it is often more
  1778. appropriate to operate on point.
  1779. 
  1780. File: elisp, Node: Text, Next: Non-ASCII Characters, Prev: Markers, Up: Top
  1781. 32 Text
  1782. *******
  1783. This chapter describes the functions that deal with the text in a
  1784. buffer. Most examine, insert, or delete text in the current buffer,
  1785. often operating at point or on text adjacent to point. Many are
  1786. interactive. All the functions that change the text provide for undoing
  1787. the changes (*note Undo::).
  1788. Many text-related functions operate on a region of text defined by
  1789. two buffer positions passed in arguments named START and END. These
  1790. arguments should be either markers (*note Markers::) or numeric
  1791. character positions (*note Positions::). The order of these arguments
  1792. does not matter; it is all right for START to be the end of the region
  1793. and END the beginning. For example, `(delete-region 1 10)' and
  1794. `(delete-region 10 1)' are equivalent. An `args-out-of-range' error is
  1795. signaled if either START or END is outside the accessible portion of
  1796. the buffer. In an interactive call, point and the mark are used for
  1797. these arguments.
  1798. Throughout this chapter, "text" refers to the characters in the
  1799. buffer, together with their properties (when relevant). Keep in mind
  1800. that point is always between two characters, and the cursor appears on
  1801. the character after point.
  1802. * Menu:
  1803. * Near Point:: Examining text in the vicinity of point.
  1804. * Buffer Contents:: Examining text in a general fashion.
  1805. * Comparing Text:: Comparing substrings of buffers.
  1806. * Insertion:: Adding new text to a buffer.
  1807. * Commands for Insertion:: User-level commands to insert text.
  1808. * Deletion:: Removing text from a buffer.
  1809. * User-Level Deletion:: User-level commands to delete text.
  1810. * The Kill Ring:: Where removed text sometimes is saved for later use.
  1811. * Undo:: Undoing changes to the text of a buffer.
  1812. * Maintaining Undo:: How to enable and disable undo information.
  1813. How to control how much information is kept.
  1814. * Filling:: Functions for explicit filling.
  1815. * Margins:: How to specify margins for filling commands.
  1816. * Adaptive Fill:: Adaptive Fill mode chooses a fill prefix from context.
  1817. * Auto Filling:: How auto-fill mode is implemented to break lines.
  1818. * Sorting:: Functions for sorting parts of the buffer.
  1819. * Columns:: Computing horizontal positions, and using them.
  1820. * Indentation:: Functions to insert or adjust indentation.
  1821. * Case Changes:: Case conversion of parts of the buffer.
  1822. * Text Properties:: Assigning Lisp property lists to text characters.
  1823. * Substitution:: Replacing a given character wherever it appears.
  1824. * Transposition:: Swapping two portions of a buffer.
  1825. * Registers:: How registers are implemented. Accessing the text or
  1826. position stored in a register.
  1827. * Base 64:: Conversion to or from base 64 encoding.
  1828. * Checksum/Hash:: Computing cryptographic hashes.
  1829. * Parsing HTML/XML:: Parsing HTML and XML.
  1830. * Atomic Changes:: Installing several buffer changes "atomically".
  1831. * Change Hooks:: Supplying functions to be run when text is changed.
  1832. 
  1833. File: elisp, Node: Near Point, Next: Buffer Contents, Up: Text
  1834. 32.1 Examining Text Near Point
  1835. ==============================
  1836. Many functions are provided to look at the characters around point.
  1837. Several simple functions are described here. See also `looking-at' in
  1838. *note Regexp Search::.
  1839. In the following four functions, "beginning" or "end" of buffer
  1840. refers to the beginning or end of the accessible portion.
  1841. -- Function: char-after &optional position
  1842. This function returns the character in the current buffer at (i.e.,
  1843. immediately after) position POSITION. If POSITION is out of range
  1844. for this purpose, either before the beginning of the buffer, or at
  1845. or beyond the end, then the value is `nil'. The default for
  1846. POSITION is point.
  1847. In the following example, assume that the first character in the
  1848. buffer is `@':
  1849. (string (char-after 1))
  1850. => "@"
  1851. -- Function: char-before &optional position
  1852. This function returns the character in the current buffer
  1853. immediately before position POSITION. If POSITION is out of range
  1854. for this purpose, either at or before the beginning of the buffer,
  1855. or beyond the end, then the value is `nil'. The default for
  1856. POSITION is point.
  1857. -- Function: following-char
  1858. This function returns the character following point in the current
  1859. buffer. This is similar to `(char-after (point))'. However, if
  1860. point is at the end of the buffer, then `following-char' returns 0.
  1861. Remember that point is always between characters, and the cursor
  1862. normally appears over the character following point. Therefore,
  1863. the character returned by `following-char' is the character the
  1864. cursor is over.
  1865. In this example, point is between the `a' and the `c'.
  1866. ---------- Buffer: foo ----------
  1867. Gentlemen may cry ``Pea-!-ce! Peace!,''
  1868. but there is no peace.
  1869. ---------- Buffer: foo ----------
  1870. (string (preceding-char))
  1871. => "a"
  1872. (string (following-char))
  1873. => "c"
  1874. -- Function: preceding-char
  1875. This function returns the character preceding point in the current
  1876. buffer. See above, under `following-char', for an example. If
  1877. point is at the beginning of the buffer, `preceding-char' returns
  1878. 0.
  1879. -- Function: bobp
  1880. This function returns `t' if point is at the beginning of the
  1881. buffer. If narrowing is in effect, this means the beginning of the
  1882. accessible portion of the text. See also `point-min' in *note
  1883. Point::.
  1884. -- Function: eobp
  1885. This function returns `t' if point is at the end of the buffer.
  1886. If narrowing is in effect, this means the end of accessible
  1887. portion of the text. See also `point-max' in *Note Point::.
  1888. -- Function: bolp
  1889. This function returns `t' if point is at the beginning of a line.
  1890. *Note Text Lines::. The beginning of the buffer (or of its
  1891. accessible portion) always counts as the beginning of a line.
  1892. -- Function: eolp
  1893. This function returns `t' if point is at the end of a line. The
  1894. end of the buffer (or of its accessible portion) is always
  1895. considered the end of a line.
  1896. 
  1897. File: elisp, Node: Buffer Contents, Next: Comparing Text, Prev: Near Point, Up: Text
  1898. 32.2 Examining Buffer Contents
  1899. ==============================
  1900. This section describes functions that allow a Lisp program to convert
  1901. any portion of the text in the buffer into a string.
  1902. -- Function: buffer-substring start end
  1903. This function returns a string containing a copy of the text of the
  1904. region defined by positions START and END in the current buffer.
  1905. If the arguments are not positions in the accessible portion of
  1906. the buffer, `buffer-substring' signals an `args-out-of-range'
  1907. error.
  1908. Here's an example which assumes Font-Lock mode is not enabled:
  1909. ---------- Buffer: foo ----------
  1910. This is the contents of buffer foo
  1911. ---------- Buffer: foo ----------
  1912. (buffer-substring 1 10)
  1913. => "This is t"
  1914. (buffer-substring (point-max) 10)
  1915. => "he contents of buffer foo\n"
  1916. If the text being copied has any text properties, these are copied
  1917. into the string along with the characters they belong to. *Note
  1918. Text Properties::. However, overlays (*note Overlays::) in the
  1919. buffer and their properties are ignored, not copied.
  1920. For example, if Font-Lock mode is enabled, you might get results
  1921. like these:
  1922. (buffer-substring 1 10)
  1923. => #("This is t" 0 1 (fontified t) 1 9 (fontified t))
  1924. -- Function: buffer-substring-no-properties start end
  1925. This is like `buffer-substring', except that it does not copy text
  1926. properties, just the characters themselves. *Note Text
  1927. Properties::.
  1928. -- Function: buffer-string
  1929. This function returns the contents of the entire accessible
  1930. portion of the current buffer, as a string.
  1931. -- Function: filter-buffer-substring start end &optional delete
  1932. This function passes the buffer text between START and END through
  1933. the filter functions specified by the wrapper hook
  1934. `filter-buffer-substring-functions', and returns the result. The
  1935. obsolete variable `buffer-substring-filters' is also consulted.
  1936. If both of these variables are `nil', the value is the unaltered
  1937. text from the buffer, i.e. what `buffer-substring' would return.
  1938. If DELETE is non-`nil', this function deletes the text between
  1939. START and END after copying it, like `delete-and-extract-region'.
  1940. Lisp code should use this function instead of `buffer-substring',
  1941. `buffer-substring-no-properties', or `delete-and-extract-region'
  1942. when copying into user-accessible data structures such as the
  1943. kill-ring, X clipboard, and registers. Major and minor modes can
  1944. add functions to `filter-buffer-substring-functions' to alter such
  1945. text as it is copied out of the buffer.
  1946. -- Variable: filter-buffer-substring-functions
  1947. This variable is a wrapper hook (*note Running Hooks::), whose
  1948. members should be functions that accept four arguments: FUN,
  1949. START, END, and DELETE. FUN is a function that takes three
  1950. arguments (START, END, and DELETE), and returns a string. In both
  1951. cases, the START, END, and DELETE arguments are the same as those
  1952. of `filter-buffer-substring'.
  1953. The first hook function is passed a FUN that is equivalent to the
  1954. default operation of `filter-buffer-substring', i.e. it returns
  1955. the buffer-substring between START and END (processed by any
  1956. `buffer-substring-filters') and optionally deletes the original
  1957. text from the buffer. In most cases, the hook function will call
  1958. FUN once, and then do its own processing of the result. The next
  1959. hook function receives a FUN equivalent to this, and so on. The
  1960. actual return value is the result of all the hook functions acting
  1961. in sequence.
  1962. -- Variable: buffer-substring-filters
  1963. This variable is obsoleted by `filter-buffer-substring-functions',
  1964. but is still supported for backward compatibility. Its value
  1965. should should be a list of functions which accept a single string
  1966. argument and return another string. `filter-buffer-substring'
  1967. passes the buffer substring to the first function in this list,
  1968. and the return value of each function is passed to the next
  1969. function. The return value of the last function is passed to
  1970. `filter-buffer-substring-functions'.
  1971. -- Function: current-word &optional strict really-word
  1972. This function returns the symbol (or word) at or near point, as a
  1973. string. The return value includes no text properties.
  1974. If the optional argument REALLY-WORD is non-`nil', it finds a
  1975. word; otherwise, it finds a symbol (which includes both word
  1976. characters and symbol constituent characters).
  1977. If the optional argument STRICT is non-`nil', then point must be
  1978. in or next to the symbol or word--if no symbol or word is there,
  1979. the function returns `nil'. Otherwise, a nearby symbol or word on
  1980. the same line is acceptable.
  1981. -- Function: thing-at-point thing
  1982. Return the THING around or next to point, as a string.
  1983. The argument THING is a symbol which specifies a kind of syntactic
  1984. entity. Possibilities include `symbol', `list', `sexp', `defun',
  1985. `filename', `url', `word', `sentence', `whitespace', `line',
  1986. `page', and others.
  1987. ---------- Buffer: foo ----------
  1988. Gentlemen may cry ``Pea-!-ce! Peace!,''
  1989. but there is no peace.
  1990. ---------- Buffer: foo ----------
  1991. (thing-at-point 'word)
  1992. => "Peace"
  1993. (thing-at-point 'line)
  1994. => "Gentlemen may cry ``Peace! Peace!,''\n"
  1995. (thing-at-point 'whitespace)
  1996. => nil
  1997. 
  1998. File: elisp, Node: Comparing Text, Next: Insertion, Prev: Buffer Contents, Up: Text
  1999. 32.3 Comparing Text
  2000. ===================
  2001. This function lets you compare portions of the text in a buffer, without
  2002. copying them into strings first.
  2003. -- Function: compare-buffer-substrings buffer1 start1 end1 buffer2
  2004. start2 end2
  2005. This function lets you compare two substrings of the same buffer
  2006. or two different buffers. The first three arguments specify one
  2007. substring, giving a buffer (or a buffer name) and two positions
  2008. within the buffer. The last three arguments specify the other
  2009. substring in the same way. You can use `nil' for BUFFER1,
  2010. BUFFER2, or both to stand for the current buffer.
  2011. The value is negative if the first substring is less, positive if
  2012. the first is greater, and zero if they are equal. The absolute
  2013. value of the result is one plus the index of the first differing
  2014. characters within the substrings.
  2015. This function ignores case when comparing characters if
  2016. `case-fold-search' is non-`nil'. It always ignores text
  2017. properties.
  2018. Suppose the current buffer contains the text `foobarbar
  2019. haha!rara!'; then in this example the two substrings are `rbar '
  2020. and `rara!'. The value is 2 because the first substring is greater
  2021. at the second character.
  2022. (compare-buffer-substrings nil 6 11 nil 16 21)
  2023. => 2
  2024. 
  2025. File: elisp, Node: Insertion, Next: Commands for Insertion, Prev: Comparing Text, Up: Text
  2026. 32.4 Inserting Text
  2027. ===================
  2028. "Insertion" means adding new text to a buffer. The inserted text goes
  2029. at point--between the character before point and the character after
  2030. point. Some insertion functions leave point before the inserted text,
  2031. while other functions leave it after. We call the former insertion
  2032. "after point" and the latter insertion "before point".
  2033. Insertion moves markers located at positions after the insertion
  2034. point, so that they stay with the surrounding text (*note Markers::).
  2035. When a marker points at the place of insertion, insertion may or may
  2036. not relocate the marker, depending on the marker's insertion type
  2037. (*note Marker Insertion Types::). Certain special functions such as
  2038. `insert-before-markers' relocate all such markers to point after the
  2039. inserted text, regardless of the markers' insertion type.
  2040. Insertion functions signal an error if the current buffer is
  2041. read-only or if they insert within read-only text.
  2042. These functions copy text characters from strings and buffers along
  2043. with their properties. The inserted characters have exactly the same
  2044. properties as the characters they were copied from. By contrast,
  2045. characters specified as separate arguments, not part of a string or
  2046. buffer, inherit their text properties from the neighboring text.
  2047. The insertion functions convert text from unibyte to multibyte in
  2048. order to insert in a multibyte buffer, and vice versa--if the text
  2049. comes from a string or from a buffer. However, they do not convert
  2050. unibyte character codes 128 through 255 to multibyte characters, not
  2051. even if the current buffer is a multibyte buffer. *Note Converting
  2052. Representations::.
  2053. -- Function: insert &rest args
  2054. This function inserts the strings and/or characters ARGS into the
  2055. current buffer, at point, moving point forward. In other words, it
  2056. inserts the text before point. An error is signaled unless all
  2057. ARGS are either strings or characters. The value is `nil'.
  2058. -- Function: insert-before-markers &rest args
  2059. This function inserts the strings and/or characters ARGS into the
  2060. current buffer, at point, moving point forward. An error is
  2061. signaled unless all ARGS are either strings or characters. The
  2062. value is `nil'.
  2063. This function is unlike the other insertion functions in that it
  2064. relocates markers initially pointing at the insertion point, to
  2065. point after the inserted text. If an overlay begins at the
  2066. insertion point, the inserted text falls outside the overlay; if a
  2067. nonempty overlay ends at the insertion point, the inserted text
  2068. falls inside that overlay.
  2069. -- Function: insert-char character count &optional inherit
  2070. This function inserts COUNT instances of CHARACTER into the
  2071. current buffer before point. The argument COUNT should be an
  2072. integer, and CHARACTER must be a character. The value is `nil'.
  2073. This function does not convert unibyte character codes 128 through
  2074. 255 to multibyte characters, not even if the current buffer is a
  2075. multibyte buffer. *Note Converting Representations::.
  2076. If INHERIT is non-`nil', then the inserted characters inherit
  2077. sticky text properties from the two characters before and after the
  2078. insertion point. *Note Sticky Properties::.
  2079. -- Function: insert-buffer-substring from-buffer-or-name &optional
  2080. start end
  2081. This function inserts a portion of buffer FROM-BUFFER-OR-NAME
  2082. (which must already exist) into the current buffer before point.
  2083. The text inserted is the region between START and END. (These
  2084. arguments default to the beginning and end of the accessible
  2085. portion of that buffer.) This function returns `nil'.
  2086. In this example, the form is executed with buffer `bar' as the
  2087. current buffer. We assume that buffer `bar' is initially empty.
  2088. ---------- Buffer: foo ----------
  2089. We hold these truths to be self-evident, that all
  2090. ---------- Buffer: foo ----------
  2091. (insert-buffer-substring "foo" 1 20)
  2092. => nil
  2093. ---------- Buffer: bar ----------
  2094. We hold these truth-!-
  2095. ---------- Buffer: bar ----------
  2096. -- Function: insert-buffer-substring-no-properties from-buffer-or-name
  2097. &optional start end
  2098. This is like `insert-buffer-substring' except that it does not
  2099. copy any text properties.
  2100. *Note Sticky Properties::, for other insertion functions that inherit
  2101. text properties from the nearby text in addition to inserting it.
  2102. Whitespace inserted by indentation functions also inherits text
  2103. properties.
  2104. 
  2105. File: elisp, Node: Commands for Insertion, Next: Deletion, Prev: Insertion, Up: Text
  2106. 32.5 User-Level Insertion Commands
  2107. ==================================
  2108. This section describes higher-level commands for inserting text,
  2109. commands intended primarily for the user but useful also in Lisp
  2110. programs.
  2111. -- Command: insert-buffer from-buffer-or-name
  2112. This command inserts the entire accessible contents of
  2113. FROM-BUFFER-OR-NAME (which must exist) into the current buffer
  2114. after point. It leaves the mark after the inserted text. The
  2115. value is `nil'.
  2116. -- Command: self-insert-command count
  2117. This command inserts the last character typed; it does so COUNT
  2118. times, before point, and returns `nil'. Most printing characters
  2119. are bound to this command. In routine use, `self-insert-command'
  2120. is the most frequently called function in Emacs, but programs
  2121. rarely use it except to install it on a keymap.
  2122. In an interactive call, COUNT is the numeric prefix argument.
  2123. Self-insertion translates the input character through
  2124. `translation-table-for-input'. *Note Translation of Characters::.
  2125. This command calls `auto-fill-function' whenever that is non-`nil'
  2126. and the character inserted is in the table `auto-fill-chars'
  2127. (*note Auto Filling::).
  2128. This command performs abbrev expansion if Abbrev mode is enabled
  2129. and the inserted character does not have word-constituent syntax.
  2130. (*Note Abbrevs::, and *note Syntax Class Table::.) It is also
  2131. responsible for calling `blink-paren-function' when the inserted
  2132. character has close parenthesis syntax (*note Blinking::).
  2133. The final thing this command does is to run the hook
  2134. `post-self-insert-hook'. You could use this to automatically
  2135. reindent text as it is typed, for example.
  2136. Do not try substituting your own definition of
  2137. `self-insert-command' for the standard one. The editor command
  2138. loop handles this function specially.
  2139. -- Command: newline &optional number-of-newlines
  2140. This command inserts newlines into the current buffer before point.
  2141. If NUMBER-OF-NEWLINES is supplied, that many newline characters
  2142. are inserted.
  2143. This function calls `auto-fill-function' if the current column
  2144. number is greater than the value of `fill-column' and
  2145. NUMBER-OF-NEWLINES is `nil'. Typically what `auto-fill-function'
  2146. does is insert a newline; thus, the overall result in this case is
  2147. to insert two newlines at different places: one at point, and
  2148. another earlier in the line. `newline' does not auto-fill if
  2149. NUMBER-OF-NEWLINES is non-`nil'.
  2150. This command indents to the left margin if that is not zero.
  2151. *Note Margins::.
  2152. The value returned is `nil'. In an interactive call, COUNT is the
  2153. numeric prefix argument.
  2154. -- Variable: overwrite-mode
  2155. This variable controls whether overwrite mode is in effect. The
  2156. value should be `overwrite-mode-textual', `overwrite-mode-binary',
  2157. or `nil'. `overwrite-mode-textual' specifies textual overwrite
  2158. mode (treats newlines and tabs specially), and
  2159. `overwrite-mode-binary' specifies binary overwrite mode (treats
  2160. newlines and tabs like any other characters).
  2161. 
  2162. File: elisp, Node: Deletion, Next: User-Level Deletion, Prev: Commands for Insertion, Up: Text
  2163. 32.6 Deleting Text
  2164. ==================
  2165. Deletion means removing part of the text in a buffer, without saving it
  2166. in the kill ring (*note The Kill Ring::). Deleted text can't be
  2167. yanked, but can be reinserted using the undo mechanism (*note Undo::).
  2168. Some deletion functions do save text in the kill ring in some special
  2169. cases.
  2170. All of the deletion functions operate on the current buffer.
  2171. -- Command: erase-buffer
  2172. This function deletes the entire text of the current buffer (_not_
  2173. just the accessible portion), leaving it empty. If the buffer is
  2174. read-only, it signals a `buffer-read-only' error; if some of the
  2175. text in it is read-only, it signals a `text-read-only' error.
  2176. Otherwise, it deletes the text without asking for any
  2177. confirmation. It returns `nil'.
  2178. Normally, deleting a large amount of text from a buffer inhibits
  2179. further auto-saving of that buffer "because it has shrunk".
  2180. However, `erase-buffer' does not do this, the idea being that the
  2181. future text is not really related to the former text, and its size
  2182. should not be compared with that of the former text.
  2183. -- Command: delete-region start end
  2184. This command deletes the text between positions START and END in
  2185. the current buffer, and returns `nil'. If point was inside the
  2186. deleted region, its value afterward is START. Otherwise, point
  2187. relocates with the surrounding text, as markers do.
  2188. -- Function: delete-and-extract-region start end
  2189. This function deletes the text between positions START and END in
  2190. the current buffer, and returns a string containing the text just
  2191. deleted.
  2192. If point was inside the deleted region, its value afterward is
  2193. START. Otherwise, point relocates with the surrounding text, as
  2194. markers do.
  2195. -- Command: delete-char count &optional killp
  2196. This command deletes COUNT characters directly after point, or
  2197. before point if COUNT is negative. If KILLP is non-`nil', then it
  2198. saves the deleted characters in the kill ring.
  2199. In an interactive call, COUNT is the numeric prefix argument, and
  2200. KILLP is the unprocessed prefix argument. Therefore, if a prefix
  2201. argument is supplied, the text is saved in the kill ring. If no
  2202. prefix argument is supplied, then one character is deleted, but
  2203. not saved in the kill ring.
  2204. The value returned is always `nil'.
  2205. -- Command: delete-backward-char count &optional killp
  2206. This command deletes COUNT characters directly before point, or
  2207. after point if COUNT is negative. If KILLP is non-`nil', then it
  2208. saves the deleted characters in the kill ring.
  2209. In an interactive call, COUNT is the numeric prefix argument, and
  2210. KILLP is the unprocessed prefix argument. Therefore, if a prefix
  2211. argument is supplied, the text is saved in the kill ring. If no
  2212. prefix argument is supplied, then one character is deleted, but
  2213. not saved in the kill ring.
  2214. The value returned is always `nil'.
  2215. -- Command: backward-delete-char-untabify count &optional killp
  2216. This command deletes COUNT characters backward, changing tabs into
  2217. spaces. When the next character to be deleted is a tab, it is
  2218. first replaced with the proper number of spaces to preserve
  2219. alignment and then one of those spaces is deleted instead of the
  2220. tab. If KILLP is non-`nil', then the command saves the deleted
  2221. characters in the kill ring.
  2222. Conversion of tabs to spaces happens only if COUNT is positive.
  2223. If it is negative, exactly -COUNT characters after point are
  2224. deleted.
  2225. In an interactive call, COUNT is the numeric prefix argument, and
  2226. KILLP is the unprocessed prefix argument. Therefore, if a prefix
  2227. argument is supplied, the text is saved in the kill ring. If no
  2228. prefix argument is supplied, then one character is deleted, but
  2229. not saved in the kill ring.
  2230. The value returned is always `nil'.
  2231. -- User Option: backward-delete-char-untabify-method
  2232. This option specifies how `backward-delete-char-untabify' should
  2233. deal with whitespace. Possible values include `untabify', the
  2234. default, meaning convert a tab to many spaces and delete one;
  2235. `hungry', meaning delete all tabs and spaces before point with one
  2236. command; `all' meaning delete all tabs, spaces and newlines before
  2237. point, and `nil', meaning do nothing special for whitespace
  2238. characters.
  2239. 
  2240. File: elisp, Node: User-Level Deletion, Next: The Kill Ring, Prev: Deletion, Up: Text
  2241. 32.7 User-Level Deletion Commands
  2242. =================================
  2243. This section describes higher-level commands for deleting text,
  2244. commands intended primarily for the user but useful also in Lisp
  2245. programs.
  2246. -- Command: delete-horizontal-space &optional backward-only
  2247. This function deletes all spaces and tabs around point. It returns
  2248. `nil'.
  2249. If BACKWARD-ONLY is non-`nil', the function deletes spaces and
  2250. tabs before point, but not after point.
  2251. In the following examples, we call `delete-horizontal-space' four
  2252. times, once on each line, with point between the second and third
  2253. characters on the line each time.
  2254. ---------- Buffer: foo ----------
  2255. I -!-thought
  2256. I -!- thought
  2257. We-!- thought
  2258. Yo-!-u thought
  2259. ---------- Buffer: foo ----------
  2260. (delete-horizontal-space) ; Four times.
  2261. => nil
  2262. ---------- Buffer: foo ----------
  2263. Ithought
  2264. Ithought
  2265. Wethought
  2266. You thought
  2267. ---------- Buffer: foo ----------
  2268. -- Command: delete-indentation &optional join-following-p
  2269. This function joins the line point is on to the previous line,
  2270. deleting any whitespace at the join and in some cases replacing it
  2271. with one space. If JOIN-FOLLOWING-P is non-`nil',
  2272. `delete-indentation' joins this line to the following line
  2273. instead. The function returns `nil'.
  2274. If there is a fill prefix, and the second of the lines being joined
  2275. starts with the prefix, then `delete-indentation' deletes the fill
  2276. prefix before joining the lines. *Note Margins::.
  2277. In the example below, point is located on the line starting
  2278. `events', and it makes no difference if there are trailing spaces
  2279. in the preceding line.
  2280. ---------- Buffer: foo ----------
  2281. When in the course of human
  2282. -!- events, it becomes necessary
  2283. ---------- Buffer: foo ----------
  2284. (delete-indentation)
  2285. => nil
  2286. ---------- Buffer: foo ----------
  2287. When in the course of human-!- events, it becomes necessary
  2288. ---------- Buffer: foo ----------
  2289. After the lines are joined, the function `fixup-whitespace' is
  2290. responsible for deciding whether to leave a space at the junction.
  2291. -- Command: fixup-whitespace
  2292. This function replaces all the horizontal whitespace surrounding
  2293. point with either one space or no space, according to the context.
  2294. It returns `nil'.
  2295. At the beginning or end of a line, the appropriate amount of space
  2296. is none. Before a character with close parenthesis syntax, or
  2297. after a character with open parenthesis or expression-prefix
  2298. syntax, no space is also appropriate. Otherwise, one space is
  2299. appropriate. *Note Syntax Class Table::.
  2300. In the example below, `fixup-whitespace' is called the first time
  2301. with point before the word `spaces' in the first line. For the
  2302. second invocation, point is directly after the `('.
  2303. ---------- Buffer: foo ----------
  2304. This has too many -!-spaces
  2305. This has too many spaces at the start of (-!- this list)
  2306. ---------- Buffer: foo ----------
  2307. (fixup-whitespace)
  2308. => nil
  2309. (fixup-whitespace)
  2310. => nil
  2311. ---------- Buffer: foo ----------
  2312. This has too many spaces
  2313. This has too many spaces at the start of (this list)
  2314. ---------- Buffer: foo ----------
  2315. -- Command: just-one-space &optional n
  2316. This command replaces any spaces and tabs around point with a
  2317. single space, or N spaces if N is specified. It returns `nil'.
  2318. -- Command: delete-blank-lines
  2319. This function deletes blank lines surrounding point. If point is
  2320. on a blank line with one or more blank lines before or after it,
  2321. then all but one of them are deleted. If point is on an isolated
  2322. blank line, then it is deleted. If point is on a nonblank line,
  2323. the command deletes all blank lines immediately following it.
  2324. A blank line is defined as a line containing only tabs and spaces.
  2325. `delete-blank-lines' returns `nil'.
  2326. 
  2327. File: elisp, Node: The Kill Ring, Next: Undo, Prev: User-Level Deletion, Up: Text
  2328. 32.8 The Kill Ring
  2329. ==================
  2330. "Kill functions" delete text like the deletion functions, but save it
  2331. so that the user can reinsert it by "yanking". Most of these functions
  2332. have `kill-' in their name. By contrast, the functions whose names
  2333. start with `delete-' normally do not save text for yanking (though they
  2334. can still be undone); these are "deletion" functions.
  2335. Most of the kill commands are primarily for interactive use, and are
  2336. not described here. What we do describe are the functions provided for
  2337. use in writing such commands. You can use these functions to write
  2338. commands for killing text. When you need to delete text for internal
  2339. purposes within a Lisp function, you should normally use deletion
  2340. functions, so as not to disturb the kill ring contents. *Note
  2341. Deletion::.
  2342. Killed text is saved for later yanking in the "kill ring". This is
  2343. a list that holds a number of recent kills, not just the last text
  2344. kill. We call this a "ring" because yanking treats it as having
  2345. elements in a cyclic order. The list is kept in the variable
  2346. `kill-ring', and can be operated on with the usual functions for lists;
  2347. there are also specialized functions, described in this section, that
  2348. treat it as a ring.
  2349. Some people think this use of the word "kill" is unfortunate, since
  2350. it refers to operations that specifically _do not_ destroy the entities
  2351. "killed". This is in sharp contrast to ordinary life, in which death
  2352. is permanent and "killed" entities do not come back to life.
  2353. Therefore, other metaphors have been proposed. For example, the term
  2354. "cut ring" makes sense to people who, in pre-computer days, used
  2355. scissors and paste to cut up and rearrange manuscripts. However, it
  2356. would be difficult to change the terminology now.
  2357. * Menu:
  2358. * Kill Ring Concepts:: What text looks like in the kill ring.
  2359. * Kill Functions:: Functions that kill text.
  2360. * Yanking:: How yanking is done.
  2361. * Yank Commands:: Commands that access the kill ring.
  2362. * Low-Level Kill Ring:: Functions and variables for kill ring access.
  2363. * Internals of Kill Ring:: Variables that hold kill ring data.
  2364. 
  2365. File: elisp, Node: Kill Ring Concepts, Next: Kill Functions, Up: The Kill Ring
  2366. 32.8.1 Kill Ring Concepts
  2367. -------------------------
  2368. The kill ring records killed text as strings in a list, most recent
  2369. first. A short kill ring, for example, might look like this:
  2370. ("some text" "a different piece of text" "even older text")
  2371. When the list reaches `kill-ring-max' entries in length, adding a new
  2372. entry automatically deletes the last entry.
  2373. When kill commands are interwoven with other commands, each kill
  2374. command makes a new entry in the kill ring. Multiple kill commands in
  2375. succession build up a single kill ring entry, which would be yanked as a
  2376. unit; the second and subsequent consecutive kill commands add text to
  2377. the entry made by the first one.
  2378. For yanking, one entry in the kill ring is designated the "front" of
  2379. the ring. Some yank commands "rotate" the ring by designating a
  2380. different element as the "front". But this virtual rotation doesn't
  2381. change the list itself--the most recent entry always comes first in the
  2382. list.
  2383. 
  2384. File: elisp, Node: Kill Functions, Next: Yanking, Prev: Kill Ring Concepts, Up: The Kill Ring
  2385. 32.8.2 Functions for Killing
  2386. ----------------------------
  2387. `kill-region' is the usual subroutine for killing text. Any command
  2388. that calls this function is a "kill command" (and should probably have
  2389. `kill' in its name). `kill-region' puts the newly killed text in a new
  2390. element at the beginning of the kill ring or adds it to the most recent
  2391. element. It determines automatically (using `last-command') whether
  2392. the previous command was a kill command, and if so appends the killed
  2393. text to the most recent entry.
  2394. -- Command: kill-region start end
  2395. This function kills the text in the region defined by START and
  2396. END. The text is deleted but saved in the kill ring, along with
  2397. its text properties. The value is always `nil'.
  2398. In an interactive call, START and END are point and the mark.
  2399. If the buffer or text is read-only, `kill-region' modifies the kill
  2400. ring just the same, then signals an error without modifying the
  2401. buffer. This is convenient because it lets the user use a series
  2402. of kill commands to copy text from a read-only buffer into the
  2403. kill ring.
  2404. -- User Option: kill-read-only-ok
  2405. If this option is non-`nil', `kill-region' does not signal an
  2406. error if the buffer or text is read-only. Instead, it simply
  2407. returns, updating the kill ring but not changing the buffer.
  2408. -- Command: copy-region-as-kill start end
  2409. This command saves the region defined by START and END on the kill
  2410. ring (including text properties), but does not delete the text
  2411. from the buffer. It returns `nil'.
  2412. The command does not set `this-command' to `kill-region', so a
  2413. subsequent kill command does not append to the same kill ring
  2414. entry.
  2415. In Lisp programs, it is better to use `kill-new' or `kill-append'
  2416. instead of this command. *Note Low-Level Kill Ring::.
  2417. 
  2418. File: elisp, Node: Yanking, Next: Yank Commands, Prev: Kill Functions, Up: The Kill Ring
  2419. 32.8.3 Yanking
  2420. --------------
  2421. Yanking means inserting text from the kill ring, but it does not insert
  2422. the text blindly. Yank commands and some other commands use
  2423. `insert-for-yank' to perform special processing on the text that they
  2424. copy into the buffer.
  2425. -- Function: insert-for-yank string
  2426. This function normally works like `insert' except that it doesn't
  2427. insert the text properties (*note Text Properties::) in the list
  2428. variable `yank-excluded-properties'. However, if any part of
  2429. STRING has a non-`nil' `yank-handler' text property, that property
  2430. can do various special processing on that part of the text being
  2431. inserted.
  2432. -- Function: insert-buffer-substring-as-yank buf &optional start end
  2433. This function resembles `insert-buffer-substring' except that it
  2434. doesn't insert the text properties in the
  2435. `yank-excluded-properties' list.
  2436. You can put a `yank-handler' text property on all or part of the
  2437. text to control how it will be inserted if it is yanked. The
  2438. `insert-for-yank' function looks for that property. The property value
  2439. must be a list of one to four elements, with the following format
  2440. (where elements after the first may be omitted):
  2441. (FUNCTION PARAM NOEXCLUDE UNDO)
  2442. Here is what the elements do:
  2443. FUNCTION
  2444. When FUNCTION is present and non-`nil', it is called instead of
  2445. `insert' to insert the string. FUNCTION takes one argument--the
  2446. string to insert.
  2447. PARAM
  2448. If PARAM is present and non-`nil', it replaces STRING (or the part
  2449. of STRING being processed) as the object passed to FUNCTION (or
  2450. `insert'); for example, if FUNCTION is `yank-rectangle', PARAM
  2451. should be a list of strings to insert as a rectangle.
  2452. NOEXCLUDE
  2453. If NOEXCLUDE is present and non-`nil', the normal removal of the
  2454. yank-excluded-properties is not performed; instead FUNCTION is
  2455. responsible for removing those properties. This may be necessary
  2456. if FUNCTION adjusts point before or after inserting the object.
  2457. UNDO
  2458. If UNDO is present and non-`nil', it is a function that will be
  2459. called by `yank-pop' to undo the insertion of the current object.
  2460. It is called with two arguments, the start and end of the current
  2461. region. FUNCTION can set `yank-undo-function' to override the
  2462. UNDO value.
  2463. -- User Option: yank-excluded-properties
  2464. Yanking discards certain text properties from the yanked text, as
  2465. described above. The value of this variable is the list of
  2466. properties to discard. Its default value contains properties that
  2467. might lead to annoying results, such as causing the text to
  2468. respond to the mouse or specifying key bindings.
  2469. 
  2470. File: elisp, Node: Yank Commands, Next: Low-Level Kill Ring, Prev: Yanking, Up: The Kill Ring
  2471. 32.8.4 Functions for Yanking
  2472. ----------------------------
  2473. This section describes higher-level commands for yanking, which are
  2474. intended primarily for the user but useful also in Lisp programs. Both
  2475. `yank' and `yank-pop' honor the `yank-excluded-properties' variable and
  2476. `yank-handler' text property (*note Yanking::).
  2477. -- Command: yank &optional arg
  2478. This command inserts before point the text at the front of the kill
  2479. ring. It sets the mark at the beginning of that text, using
  2480. `push-mark' (*note The Mark::), and puts point at the end.
  2481. If ARG is a non-`nil' list (which occurs interactively when the
  2482. user types `C-u' with no digits), then `yank' inserts the text as
  2483. described above, but puts point before the yanked text and sets
  2484. the mark after it.
  2485. If ARG is a number, then `yank' inserts the ARGth most recently
  2486. killed text--the ARGth element of the kill ring list, counted
  2487. cyclically from the front, which is considered the first element
  2488. for this purpose.
  2489. `yank' does not alter the contents of the kill ring, unless it
  2490. used text provided by another program, in which case it pushes
  2491. that text onto the kill ring. However if ARG is an integer
  2492. different from one, it rotates the kill ring to place the yanked
  2493. string at the front.
  2494. `yank' returns `nil'.
  2495. -- Command: yank-pop &optional arg
  2496. This command replaces the just-yanked entry from the kill ring
  2497. with a different entry from the kill ring.
  2498. This is allowed only immediately after a `yank' or another
  2499. `yank-pop'. At such a time, the region contains text that was just
  2500. inserted by yanking. `yank-pop' deletes that text and inserts in
  2501. its place a different piece of killed text. It does not add the
  2502. deleted text to the kill ring, since it is already in the kill
  2503. ring somewhere. It does however rotate the kill ring to place the
  2504. newly yanked string at the front.
  2505. If ARG is `nil', then the replacement text is the previous element
  2506. of the kill ring. If ARG is numeric, the replacement is the ARGth
  2507. previous kill. If ARG is negative, a more recent kill is the
  2508. replacement.
  2509. The sequence of kills in the kill ring wraps around, so that after
  2510. the oldest one comes the newest one, and before the newest one
  2511. goes the oldest.
  2512. The return value is always `nil'.
  2513. -- Variable: yank-undo-function
  2514. If this variable is non-`nil', the function `yank-pop' uses its
  2515. value instead of `delete-region' to delete the text inserted by
  2516. the previous `yank' or `yank-pop' command. The value must be a
  2517. function of two arguments, the start and end of the current region.
  2518. The function `insert-for-yank' automatically sets this variable
  2519. according to the UNDO element of the `yank-handler' text property,
  2520. if there is one.
  2521. 
  2522. File: elisp, Node: Low-Level Kill Ring, Next: Internals of Kill Ring, Prev: Yank Commands, Up: The Kill Ring
  2523. 32.8.5 Low-Level Kill Ring
  2524. --------------------------
  2525. These functions and variables provide access to the kill ring at a
  2526. lower level, but are still convenient for use in Lisp programs, because
  2527. they take care of interaction with window system selections (*note
  2528. Window System Selections::).
  2529. -- Function: current-kill n &optional do-not-move
  2530. The function `current-kill' rotates the yanking pointer, which
  2531. designates the "front" of the kill ring, by N places (from newer
  2532. kills to older ones), and returns the text at that place in the
  2533. ring.
  2534. If the optional second argument DO-NOT-MOVE is non-`nil', then
  2535. `current-kill' doesn't alter the yanking pointer; it just returns
  2536. the Nth kill, counting from the current yanking pointer.
  2537. If N is zero, indicating a request for the latest kill,
  2538. `current-kill' calls the value of `interprogram-paste-function'
  2539. (documented below) before consulting the kill ring. If that value
  2540. is a function and calling it returns a string or a list of several
  2541. string, `current-kill' pushes the strings onto the kill ring and
  2542. returns the first string. It also sets the yanking pointer to
  2543. point to the kill-ring entry of the first string returned by
  2544. `interprogram-paste-function', regardless of the value of
  2545. DO-NOT-MOVE. Otherwise, `current-kill' does not treat a zero
  2546. value for N specially: it returns the entry pointed at by the
  2547. yanking pointer and does not move the yanking pointer.
  2548. -- Function: kill-new string &optional replace
  2549. This function pushes the text STRING onto the kill ring and makes
  2550. the yanking pointer point to it. It discards the oldest entry if
  2551. appropriate. It also invokes the value of
  2552. `interprogram-cut-function' (see below).
  2553. If REPLACE is non-`nil', then `kill-new' replaces the first
  2554. element of the kill ring with STRING, rather than pushing STRING
  2555. onto the kill ring.
  2556. -- Function: kill-append string before-p
  2557. This function appends the text STRING to the first entry in the
  2558. kill ring and makes the yanking pointer point to the combined
  2559. entry. Normally STRING goes at the end of the entry, but if
  2560. BEFORE-P is non-`nil', it goes at the beginning. This function
  2561. also invokes the value of `interprogram-cut-function' (see below).
  2562. -- Variable: interprogram-paste-function
  2563. This variable provides a way of transferring killed text from other
  2564. programs, when you are using a window system. Its value should be
  2565. `nil' or a function of no arguments.
  2566. If the value is a function, `current-kill' calls it to get the
  2567. "most recent kill". If the function returns a non-`nil' value,
  2568. then that value is used as the "most recent kill". If it returns
  2569. `nil', then the front of the kill ring is used.
  2570. To facilitate support for window systems that support multiple
  2571. selections, this function may also return a list of strings. In
  2572. that case, the first string is used as the "most recent kill", and
  2573. all the other strings are pushed onto the kill ring, for easy
  2574. access by `yank-pop'.
  2575. The normal use of this function is to get the window system's
  2576. clipboard as the most recent kill, even if the selection belongs to
  2577. another application. *Note Window System Selections::. However,
  2578. if the clipboard contents come from the current Emacs session, this
  2579. function should return `nil'.
  2580. -- Variable: interprogram-cut-function
  2581. This variable provides a way of communicating killed text to other
  2582. programs, when you are using a window system. Its value should be
  2583. `nil' or a function of one required argument.
  2584. If the value is a function, `kill-new' and `kill-append' call it
  2585. with the new first element of the kill ring as the argument.
  2586. The normal use of this function is to put newly killed text in the
  2587. window system's clipboard. *Note Window System Selections::.
  2588. 
  2589. File: elisp, Node: Internals of Kill Ring, Prev: Low-Level Kill Ring, Up: The Kill Ring
  2590. 32.8.6 Internals of the Kill Ring
  2591. ---------------------------------
  2592. The variable `kill-ring' holds the kill ring contents, in the form of a
  2593. list of strings. The most recent kill is always at the front of the
  2594. list.
  2595. The `kill-ring-yank-pointer' variable points to a link in the kill
  2596. ring list, whose CAR is the text to yank next. We say it identifies
  2597. the "front" of the ring. Moving `kill-ring-yank-pointer' to a
  2598. different link is called "rotating the kill ring". We call the kill
  2599. ring a "ring" because the functions that move the yank pointer wrap
  2600. around from the end of the list to the beginning, or vice-versa.
  2601. Rotation of the kill ring is virtual; it does not change the value of
  2602. `kill-ring'.
  2603. Both `kill-ring' and `kill-ring-yank-pointer' are Lisp variables
  2604. whose values are normally lists. The word "pointer" in the name of the
  2605. `kill-ring-yank-pointer' indicates that the variable's purpose is to
  2606. identify one element of the list for use by the next yank command.
  2607. The value of `kill-ring-yank-pointer' is always `eq' to one of the
  2608. links in the kill ring list. The element it identifies is the CAR of
  2609. that link. Kill commands, which change the kill ring, also set this
  2610. variable to the value of `kill-ring'. The effect is to rotate the ring
  2611. so that the newly killed text is at the front.
  2612. Here is a diagram that shows the variable `kill-ring-yank-pointer'
  2613. pointing to the second entry in the kill ring `("some text" "a
  2614. different piece of text" "yet older text")'.
  2615. kill-ring ---- kill-ring-yank-pointer
  2616. | |
  2617. | v
  2618. | --- --- --- --- --- ---
  2619. --> | | |------> | | |--> | | |--> nil
  2620. --- --- --- --- --- ---
  2621. | | |
  2622. | | |
  2623. | | -->"yet older text"
  2624. | |
  2625. | --> "a different piece of text"
  2626. |
  2627. --> "some text"
  2628. This state of affairs might occur after `C-y' (`yank') immediately
  2629. followed by `M-y' (`yank-pop').
  2630. -- Variable: kill-ring
  2631. This variable holds the list of killed text sequences, most
  2632. recently killed first.
  2633. -- Variable: kill-ring-yank-pointer
  2634. This variable's value indicates which element of the kill ring is
  2635. at the "front" of the ring for yanking. More precisely, the value
  2636. is a tail of the value of `kill-ring', and its CAR is the kill
  2637. string that `C-y' should yank.
  2638. -- User Option: kill-ring-max
  2639. The value of this variable is the maximum length to which the kill
  2640. ring can grow, before elements are thrown away at the end. The
  2641. default value for `kill-ring-max' is 60.
  2642. 
  2643. File: elisp, Node: Undo, Next: Maintaining Undo, Prev: The Kill Ring, Up: Text
  2644. 32.9 Undo
  2645. =========
  2646. Most buffers have an "undo list", which records all changes made to the
  2647. buffer's text so that they can be undone. (The buffers that don't have
  2648. one are usually special-purpose buffers for which Emacs assumes that
  2649. undoing is not useful. In particular, any buffer whose name begins
  2650. with a space has its undo recording off by default; see *note Buffer
  2651. Names::.) All the primitives that modify the text in the buffer
  2652. automatically add elements to the front of the undo list, which is in
  2653. the variable `buffer-undo-list'.
  2654. -- Variable: buffer-undo-list
  2655. This buffer-local variable's value is the undo list of the current
  2656. buffer. A value of `t' disables the recording of undo information.
  2657. Here are the kinds of elements an undo list can have:
  2658. `POSITION'
  2659. This kind of element records a previous value of point; undoing
  2660. this element moves point to POSITION. Ordinary cursor motion does
  2661. not make any sort of undo record, but deletion operations use
  2662. these entries to record where point was before the command.
  2663. `(BEG . END)'
  2664. This kind of element indicates how to delete text that was
  2665. inserted. Upon insertion, the text occupied the range BEG-END in
  2666. the buffer.
  2667. `(TEXT . POSITION)'
  2668. This kind of element indicates how to reinsert text that was
  2669. deleted. The deleted text itself is the string TEXT. The place to
  2670. reinsert it is `(abs POSITION)'. If POSITION is positive, point
  2671. was at the beginning of the deleted text, otherwise it was at the
  2672. end.
  2673. `(t HIGH . LOW)'
  2674. This kind of element indicates that an unmodified buffer became
  2675. modified. The elements HIGH and LOW are two integers, each
  2676. recording 16 bits of the visited file's modification time as of
  2677. when it was previously visited or saved. `primitive-undo' uses
  2678. those values to determine whether to mark the buffer as unmodified
  2679. once again; it does so only if the file's modification time
  2680. matches those numbers.
  2681. `(nil PROPERTY VALUE BEG . END)'
  2682. This kind of element records a change in a text property. Here's
  2683. how you might undo the change:
  2684. (put-text-property BEG END PROPERTY VALUE)
  2685. `(MARKER . ADJUSTMENT)'
  2686. This kind of element records the fact that the marker MARKER was
  2687. relocated due to deletion of surrounding text, and that it moved
  2688. ADJUSTMENT character positions. Undoing this element moves MARKER
  2689. - ADJUSTMENT characters.
  2690. `(apply FUNNAME . ARGS)'
  2691. This is an extensible undo item, which is undone by calling
  2692. FUNNAME with arguments ARGS.
  2693. `(apply DELTA BEG END FUNNAME . ARGS)'
  2694. This is an extensible undo item, which records a change limited to
  2695. the range BEG to END, which increased the size of the buffer by
  2696. DELTA. It is undone by calling FUNNAME with arguments ARGS.
  2697. This kind of element enables undo limited to a region to determine
  2698. whether the element pertains to that region.
  2699. `nil'
  2700. This element is a boundary. The elements between two boundaries
  2701. are called a "change group"; normally, each change group
  2702. corresponds to one keyboard command, and undo commands normally
  2703. undo an entire group as a unit.
  2704. -- Function: undo-boundary
  2705. This function places a boundary element in the undo list. The undo
  2706. command stops at such a boundary, and successive undo commands undo
  2707. to earlier and earlier boundaries. This function returns `nil'.
  2708. The editor command loop automatically calls `undo-boundary' just
  2709. before executing each key sequence, so that each undo normally
  2710. undoes the effects of one command. As an exception, the command
  2711. `self-insert-command', which produces self-inserting input
  2712. characters (*note Commands for Insertion::), may remove the
  2713. boundary inserted by the command loop: a boundary is accepted for
  2714. the first such character, the next 19 consecutive self-inserting
  2715. input characters do not have boundaries, and then the 20th does;
  2716. and so on as long as the self-inserting characters continue.
  2717. Hence, sequences of consecutive character insertions can be undone
  2718. as a group.
  2719. All buffer modifications add a boundary whenever the previous
  2720. undoable change was made in some other buffer. This is to ensure
  2721. that each command makes a boundary in each buffer where it makes
  2722. changes.
  2723. Calling this function explicitly is useful for splitting the
  2724. effects of a command into more than one unit. For example,
  2725. `query-replace' calls `undo-boundary' after each replacement, so
  2726. that the user can undo individual replacements one by one.
  2727. -- Variable: undo-in-progress
  2728. This variable is normally `nil', but the undo commands bind it to
  2729. `t'. This is so that various kinds of change hooks can tell when
  2730. they're being called for the sake of undoing.
  2731. -- Function: primitive-undo count list
  2732. This is the basic function for undoing elements of an undo list.
  2733. It undoes the first COUNT elements of LIST, returning the rest of
  2734. LIST.
  2735. `primitive-undo' adds elements to the buffer's undo list when it
  2736. changes the buffer. Undo commands avoid confusion by saving the
  2737. undo list value at the beginning of a sequence of undo operations.
  2738. Then the undo operations use and update the saved value. The new
  2739. elements added by undoing are not part of this saved value, so
  2740. they don't interfere with continuing to undo.
  2741. This function does not bind `undo-in-progress'.
  2742. 
  2743. File: elisp, Node: Maintaining Undo, Next: Filling, Prev: Undo, Up: Text
  2744. 32.10 Maintaining Undo Lists
  2745. ============================
  2746. This section describes how to enable and disable undo information for a
  2747. given buffer. It also explains how the undo list is truncated
  2748. automatically so it doesn't get too big.
  2749. Recording of undo information in a newly created buffer is normally
  2750. enabled to start with; but if the buffer name starts with a space, the
  2751. undo recording is initially disabled. You can explicitly enable or
  2752. disable undo recording with the following two functions, or by setting
  2753. `buffer-undo-list' yourself.
  2754. -- Command: buffer-enable-undo &optional buffer-or-name
  2755. This command enables recording undo information for buffer
  2756. BUFFER-OR-NAME, so that subsequent changes can be undone. If no
  2757. argument is supplied, then the current buffer is used. This
  2758. function does nothing if undo recording is already enabled in the
  2759. buffer. It returns `nil'.
  2760. In an interactive call, BUFFER-OR-NAME is the current buffer. You
  2761. cannot specify any other buffer.
  2762. -- Command: buffer-disable-undo &optional buffer-or-name
  2763. This function discards the undo list of BUFFER-OR-NAME, and
  2764. disables further recording of undo information. As a result, it
  2765. is no longer possible to undo either previous changes or any
  2766. subsequent changes. If the undo list of BUFFER-OR-NAME is already
  2767. disabled, this function has no effect.
  2768. This function returns `nil'.
  2769. As editing continues, undo lists get longer and longer. To prevent
  2770. them from using up all available memory space, garbage collection trims
  2771. them back to size limits you can set. (For this purpose, the "size" of
  2772. an undo list measures the cons cells that make up the list, plus the
  2773. strings of deleted text.) Three variables control the range of
  2774. acceptable sizes: `undo-limit', `undo-strong-limit' and
  2775. `undo-outer-limit'. In these variables, size is counted as the number
  2776. of bytes occupied, which includes both saved text and other data.
  2777. -- User Option: undo-limit
  2778. This is the soft limit for the acceptable size of an undo list.
  2779. The change group at which this size is exceeded is the last one
  2780. kept.
  2781. -- User Option: undo-strong-limit
  2782. This is the upper limit for the acceptable size of an undo list.
  2783. The change group at which this size is exceeded is discarded
  2784. itself (along with all older change groups). There is one
  2785. exception: the very latest change group is only discarded if it
  2786. exceeds `undo-outer-limit'.
  2787. -- User Option: undo-outer-limit
  2788. If at garbage collection time the undo info for the current command
  2789. exceeds this limit, Emacs discards the info and displays a warning.
  2790. This is a last ditch limit to prevent memory overflow.
  2791. -- User Option: undo-ask-before-discard
  2792. If this variable is non-`nil', when the undo info exceeds
  2793. `undo-outer-limit', Emacs asks in the echo area whether to discard
  2794. the info. The default value is `nil', which means to discard it
  2795. automatically.
  2796. This option is mainly intended for debugging. Garbage collection
  2797. is inhibited while the question is asked, which means that Emacs
  2798. might leak memory if the user waits too long before answering the
  2799. question.
  2800. 
  2801. File: elisp, Node: Filling, Next: Margins, Prev: Maintaining Undo, Up: Text
  2802. 32.11 Filling
  2803. =============
  2804. "Filling" means adjusting the lengths of lines (by moving the line
  2805. breaks) so that they are nearly (but no greater than) a specified
  2806. maximum width. Additionally, lines can be "justified", which means
  2807. inserting spaces to make the left and/or right margins line up
  2808. precisely. The width is controlled by the variable `fill-column'. For
  2809. ease of reading, lines should be no longer than 70 or so columns.
  2810. You can use Auto Fill mode (*note Auto Filling::) to fill text
  2811. automatically as you insert it, but changes to existing text may leave
  2812. it improperly filled. Then you must fill the text explicitly.
  2813. Most of the commands in this section return values that are not
  2814. meaningful. All the functions that do filling take note of the current
  2815. left margin, current right margin, and current justification style
  2816. (*note Margins::). If the current justification style is `none', the
  2817. filling functions don't actually do anything.
  2818. Several of the filling functions have an argument JUSTIFY. If it is
  2819. non-`nil', that requests some kind of justification. It can be `left',
  2820. `right', `full', or `center', to request a specific style of
  2821. justification. If it is `t', that means to use the current
  2822. justification style for this part of the text (see
  2823. `current-justification', below). Any other value is treated as `full'.
  2824. When you call the filling functions interactively, using a prefix
  2825. argument implies the value `full' for JUSTIFY.
  2826. -- Command: fill-paragraph &optional justify region
  2827. This command fills the paragraph at or after point. If JUSTIFY is
  2828. non-`nil', each line is justified as well. It uses the ordinary
  2829. paragraph motion commands to find paragraph boundaries. *Note
  2830. Paragraphs: (emacs)Paragraphs.
  2831. When REGION is non-`nil', then if Transient Mark mode is enabled
  2832. and the mark is active, this command calls `fill-region' to fill
  2833. all the paragraphs in the region, instead of filling only the
  2834. current paragraph. When this command is called interactively,
  2835. REGION is `t'.
  2836. -- Command: fill-region start end &optional justify nosqueeze to-eop
  2837. This command fills each of the paragraphs in the region from START
  2838. to END. It justifies as well if JUSTIFY is non-`nil'.
  2839. If NOSQUEEZE is non-`nil', that means to leave whitespace other
  2840. than line breaks untouched. If TO-EOP is non-`nil', that means to
  2841. keep filling to the end of the paragraph--or the next hard
  2842. newline, if `use-hard-newlines' is enabled (see below).
  2843. The variable `paragraph-separate' controls how to distinguish
  2844. paragraphs. *Note Standard Regexps::.
  2845. -- Command: fill-individual-paragraphs start end &optional justify
  2846. citation-regexp
  2847. This command fills each paragraph in the region according to its
  2848. individual fill prefix. Thus, if the lines of a paragraph were
  2849. indented with spaces, the filled paragraph will remain indented in
  2850. the same fashion.
  2851. The first two arguments, START and END, are the beginning and end
  2852. of the region to be filled. The third and fourth arguments,
  2853. JUSTIFY and CITATION-REGEXP, are optional. If JUSTIFY is
  2854. non-`nil', the paragraphs are justified as well as filled. If
  2855. CITATION-REGEXP is non-`nil', it means the function is operating
  2856. on a mail message and therefore should not fill the header lines.
  2857. If CITATION-REGEXP is a string, it is used as a regular
  2858. expression; if it matches the beginning of a line, that line is
  2859. treated as a citation marker.
  2860. Ordinarily, `fill-individual-paragraphs' regards each change in
  2861. indentation as starting a new paragraph. If
  2862. `fill-individual-varying-indent' is non-`nil', then only separator
  2863. lines separate paragraphs. That mode can handle indented
  2864. paragraphs with additional indentation on the first line.
  2865. -- User Option: fill-individual-varying-indent
  2866. This variable alters the action of `fill-individual-paragraphs' as
  2867. described above.
  2868. -- Command: fill-region-as-paragraph start end &optional justify
  2869. nosqueeze squeeze-after
  2870. This command considers a region of text as a single paragraph and
  2871. fills it. If the region was made up of many paragraphs, the blank
  2872. lines between paragraphs are removed. This function justifies as
  2873. well as filling when JUSTIFY is non-`nil'.
  2874. If NOSQUEEZE is non-`nil', that means to leave whitespace other
  2875. than line breaks untouched. If SQUEEZE-AFTER is non-`nil', it
  2876. specifies a position in the region, and means don't canonicalize
  2877. spaces before that position.
  2878. In Adaptive Fill mode, this command calls `fill-context-prefix' to
  2879. choose a fill prefix by default. *Note Adaptive Fill::.
  2880. -- Command: justify-current-line &optional how eop nosqueeze
  2881. This command inserts spaces between the words of the current line
  2882. so that the line ends exactly at `fill-column'. It returns `nil'.
  2883. The argument HOW, if non-`nil' specifies explicitly the style of
  2884. justification. It can be `left', `right', `full', `center', or
  2885. `none'. If it is `t', that means to do follow specified
  2886. justification style (see `current-justification', below). `nil'
  2887. means to do full justification.
  2888. If EOP is non-`nil', that means do only left-justification if
  2889. `current-justification' specifies full justification. This is
  2890. used for the last line of a paragraph; even if the paragraph as a
  2891. whole is fully justified, the last line should not be.
  2892. If NOSQUEEZE is non-`nil', that means do not change interior
  2893. whitespace.
  2894. -- User Option: default-justification
  2895. This variable's value specifies the style of justification to use
  2896. for text that doesn't specify a style with a text property. The
  2897. possible values are `left', `right', `full', `center', or `none'.
  2898. The default value is `left'.
  2899. -- Function: current-justification
  2900. This function returns the proper justification style to use for
  2901. filling the text around point.
  2902. This returns the value of the `justification' text property at
  2903. point, or the variable DEFAULT-JUSTIFICATION if there is no such
  2904. text property. However, it returns `nil' rather than `none' to
  2905. mean "don't justify".
  2906. -- User Option: sentence-end-double-space
  2907. If this variable is non-`nil', a period followed by just one space
  2908. does not count as the end of a sentence, and the filling functions
  2909. avoid breaking the line at such a place.
  2910. -- User Option: sentence-end-without-period
  2911. If this variable is non-`nil', a sentence can end without a
  2912. period. This is used for languages like Thai, where sentences end
  2913. with a double space but without a period.
  2914. -- User Option: sentence-end-without-space
  2915. If this variable is non-`nil', it should be a string of characters
  2916. that can end a sentence without following spaces.
  2917. -- Variable: fill-paragraph-function
  2918. This variable provides a way to override the filling of paragraphs.
  2919. If its value is non-`nil', `fill-paragraph' calls this function to
  2920. do the work. If the function returns a non-`nil' value,
  2921. `fill-paragraph' assumes the job is done, and immediately returns
  2922. that value.
  2923. The usual use of this feature is to fill comments in programming
  2924. language modes. If the function needs to fill a paragraph in the
  2925. usual way, it can do so as follows:
  2926. (let ((fill-paragraph-function nil))
  2927. (fill-paragraph arg))
  2928. -- Variable: fill-forward-paragraph-function
  2929. This variable provides a way to override how the filling functions,
  2930. such as `fill-region' and `fill-paragraph', move forward to the
  2931. next paragraph. Its value should be a function, which is called
  2932. with a single argument N, the number of paragraphs to move, and
  2933. should return the difference between N and the number of
  2934. paragraphs actually moved. The default value of this variable is
  2935. `forward-paragraph'. *Note Paragraphs: (emacs)Paragraphs.
  2936. -- Variable: use-hard-newlines
  2937. If this variable is non-`nil', the filling functions do not delete
  2938. newlines that have the `hard' text property. These "hard
  2939. newlines" act as paragraph separators.
  2940. 
  2941. File: elisp, Node: Margins, Next: Adaptive Fill, Prev: Filling, Up: Text
  2942. 32.12 Margins for Filling
  2943. =========================
  2944. -- User Option: fill-prefix
  2945. This buffer-local variable, if non-`nil', specifies a string of
  2946. text that appears at the beginning of normal text lines and should
  2947. be disregarded when filling them. Any line that fails to start
  2948. with the fill prefix is considered the start of a paragraph; so is
  2949. any line that starts with the fill prefix followed by additional
  2950. whitespace. Lines that start with the fill prefix but no
  2951. additional whitespace are ordinary text lines that can be filled
  2952. together. The resulting filled lines also start with the fill
  2953. prefix.
  2954. The fill prefix follows the left margin whitespace, if any.
  2955. -- User Option: fill-column
  2956. This buffer-local variable specifies the maximum width of filled
  2957. lines. Its value should be an integer, which is a number of
  2958. columns. All the filling, justification, and centering commands
  2959. are affected by this variable, including Auto Fill mode (*note
  2960. Auto Filling::).
  2961. As a practical matter, if you are writing text for other people to
  2962. read, you should set `fill-column' to no more than 70. Otherwise
  2963. the line will be too long for people to read comfortably, and this
  2964. can make the text seem clumsy.
  2965. The default value for `fill-column' is 70.
  2966. -- Command: set-left-margin from to margin
  2967. This sets the `left-margin' property on the text from FROM to TO
  2968. to the value MARGIN. If Auto Fill mode is enabled, this command
  2969. also refills the region to fit the new margin.
  2970. -- Command: set-right-margin from to margin
  2971. This sets the `right-margin' property on the text from FROM to TO
  2972. to the value MARGIN. If Auto Fill mode is enabled, this command
  2973. also refills the region to fit the new margin.
  2974. -- Function: current-left-margin
  2975. This function returns the proper left margin value to use for
  2976. filling the text around point. The value is the sum of the
  2977. `left-margin' property of the character at the start of the
  2978. current line (or zero if none), and the value of the variable
  2979. `left-margin'.
  2980. -- Function: current-fill-column
  2981. This function returns the proper fill column value to use for
  2982. filling the text around point. The value is the value of the
  2983. `fill-column' variable, minus the value of the `right-margin'
  2984. property of the character after point.
  2985. -- Command: move-to-left-margin &optional n force
  2986. This function moves point to the left margin of the current line.
  2987. The column moved to is determined by calling the function
  2988. `current-left-margin'. If the argument N is non-`nil',
  2989. `move-to-left-margin' moves forward N-1 lines first.
  2990. If FORCE is non-`nil', that says to fix the line's indentation if
  2991. that doesn't match the left margin value.
  2992. -- Function: delete-to-left-margin &optional from to
  2993. This function removes left margin indentation from the text between
  2994. FROM and TO. The amount of indentation to delete is determined by
  2995. calling `current-left-margin'. In no case does this function
  2996. delete non-whitespace. If FROM and TO are omitted, they default
  2997. to the whole buffer.
  2998. -- Function: indent-to-left-margin
  2999. This function adjusts the indentation at the beginning of the
  3000. current line to the value specified by the variable `left-margin'.
  3001. (That may involve either inserting or deleting whitespace.) This
  3002. function is value of `indent-line-function' in Paragraph-Indent
  3003. Text mode.
  3004. -- User Option: left-margin
  3005. This variable specifies the base left margin column. In
  3006. Fundamental mode, `C-j' indents to this column. This variable
  3007. automatically becomes buffer-local when set in any fashion.
  3008. -- User Option: fill-nobreak-predicate
  3009. This variable gives major modes a way to specify not to break a
  3010. line at certain places. Its value should be a list of functions.
  3011. Whenever filling considers breaking the line at a certain place in
  3012. the buffer, it calls each of these functions with no arguments and
  3013. with point located at that place. If any of the functions returns
  3014. non-`nil', then the line won't be broken there.
  3015. 
  3016. File: elisp, Node: Adaptive Fill, Next: Auto Filling, Prev: Margins, Up: Text
  3017. 32.13 Adaptive Fill Mode
  3018. ========================
  3019. When "Adaptive Fill Mode" is enabled, Emacs determines the fill prefix
  3020. automatically from the text in each paragraph being filled rather than
  3021. using a predetermined value. During filling, this fill prefix gets
  3022. inserted at the start of the second and subsequent lines of the
  3023. paragraph as described in *note Filling::, and in *note Auto Filling::.
  3024. -- User Option: adaptive-fill-mode
  3025. Adaptive Fill mode is enabled when this variable is non-`nil'. It
  3026. is `t' by default.
  3027. -- Function: fill-context-prefix from to
  3028. This function implements the heart of Adaptive Fill mode; it
  3029. chooses a fill prefix based on the text between FROM and TO,
  3030. typically the start and end of a paragraph. It does this by
  3031. looking at the first two lines of the paragraph, based on the
  3032. variables described below.
  3033. Usually, this function returns the fill prefix, a string. However,
  3034. before doing this, the function makes a final check (not specially
  3035. mentioned in the following) that a line starting with this prefix
  3036. wouldn't look like the start of a paragraph. Should this happen,
  3037. the function signals the anomaly by returning `nil' instead.
  3038. In detail, `fill-context-prefix' does this:
  3039. 1. It takes a candidate for the fill prefix from the first
  3040. line--it tries first the function in `adaptive-fill-function'
  3041. (if any), then the regular expression `adaptive-fill-regexp'
  3042. (see below). The first non-`nil' result of these, or the
  3043. empty string if they're both `nil', becomes the first line's
  3044. candidate.
  3045. 2. If the paragraph has as yet only one line, the function tests
  3046. the validity of the prefix candidate just found. The
  3047. function then returns the candidate if it's valid, or a
  3048. string of spaces otherwise. (see the description of
  3049. `adaptive-fill-first-line-regexp' below).
  3050. 3. When the paragraph already has two lines, the function next
  3051. looks for a prefix candidate on the second line, in just the
  3052. same way it did for the first line. If it doesn't find one,
  3053. it returns `nil'.
  3054. 4. The function now compares the two candidate prefixes
  3055. heuristically: if the non-whitespace characters in the line 2
  3056. candidate occur in the same order in the line 1 candidate,
  3057. the function returns the line 2 candidate. Otherwise, it
  3058. returns the largest initial substring which is common to both
  3059. candidates (which might be the empty string).
  3060. -- User Option: adaptive-fill-regexp
  3061. Adaptive Fill mode matches this regular expression against the text
  3062. starting after the left margin whitespace (if any) on a line; the
  3063. characters it matches are that line's candidate for the fill
  3064. prefix.
  3065. The default value matches whitespace with certain punctuation
  3066. characters intermingled.
  3067. -- User Option: adaptive-fill-first-line-regexp
  3068. Used only in one-line paragraphs, this regular expression acts as
  3069. an additional check of the validity of the one available candidate
  3070. fill prefix: the candidate must match this regular expression, or
  3071. match `comment-start-skip'. If it doesn't, `fill-context-prefix'
  3072. replaces the candidate with a string of spaces "of the same width"
  3073. as it.
  3074. The default value of this variable is `"\\`[ \t]*\\'"', which
  3075. matches only a string of whitespace. The effect of this default
  3076. is to force the fill prefixes found in one-line paragraphs always
  3077. to be pure whitespace.
  3078. -- User Option: adaptive-fill-function
  3079. You can specify more complex ways of choosing a fill prefix
  3080. automatically by setting this variable to a function. The
  3081. function is called with point after the left margin (if any) of a
  3082. line, and it must preserve point. It should return either "that
  3083. line's" fill prefix or `nil', meaning it has failed to determine a
  3084. prefix.
  3085. 
  3086. File: elisp, Node: Auto Filling, Next: Sorting, Prev: Adaptive Fill, Up: Text
  3087. 32.14 Auto Filling
  3088. ==================
  3089. Auto Fill mode is a minor mode that fills lines automatically as text
  3090. is inserted. This section describes the hook used by Auto Fill mode.
  3091. For a description of functions that you can call explicitly to fill and
  3092. justify existing text, see *note Filling::.
  3093. Auto Fill mode also enables the functions that change the margins and
  3094. justification style to refill portions of the text. *Note Margins::.
  3095. -- Variable: auto-fill-function
  3096. The value of this buffer-local variable should be a function (of no
  3097. arguments) to be called after self-inserting a character from the
  3098. table `auto-fill-chars'. It may be `nil', in which case nothing
  3099. special is done in that case.
  3100. The value of `auto-fill-function' is `do-auto-fill' when Auto-Fill
  3101. mode is enabled. That is a function whose sole purpose is to
  3102. implement the usual strategy for breaking a line.
  3103. -- Variable: normal-auto-fill-function
  3104. This variable specifies the function to use for
  3105. `auto-fill-function', if and when Auto Fill is turned on. Major
  3106. modes can set buffer-local values for this variable to alter how
  3107. Auto Fill works.
  3108. -- Variable: auto-fill-chars
  3109. A char table of characters which invoke `auto-fill-function' when
  3110. self-inserted--space and newline in most language environments.
  3111. They have an entry `t' in the table.
  3112. 
  3113. File: elisp, Node: Sorting, Next: Columns, Prev: Auto Filling, Up: Text
  3114. 32.15 Sorting Text
  3115. ==================
  3116. The sorting functions described in this section all rearrange text in a
  3117. buffer. This is in contrast to the function `sort', which rearranges
  3118. the order of the elements of a list (*note Rearrangement::). The
  3119. values returned by these functions are not meaningful.
  3120. -- Function: sort-subr reverse nextrecfun endrecfun &optional
  3121. startkeyfun endkeyfun predicate
  3122. This function is the general text-sorting routine that subdivides a
  3123. buffer into records and then sorts them. Most of the commands in
  3124. this section use this function.
  3125. To understand how `sort-subr' works, consider the whole accessible
  3126. portion of the buffer as being divided into disjoint pieces called
  3127. "sort records". The records may or may not be contiguous, but they
  3128. must not overlap. A portion of each sort record (perhaps all of
  3129. it) is designated as the sort key. Sorting rearranges the records
  3130. in order by their sort keys.
  3131. Usually, the records are rearranged in order of ascending sort key.
  3132. If the first argument to the `sort-subr' function, REVERSE, is
  3133. non-`nil', the sort records are rearranged in order of descending
  3134. sort key.
  3135. The next four arguments to `sort-subr' are functions that are
  3136. called to move point across a sort record. They are called many
  3137. times from within `sort-subr'.
  3138. 1. NEXTRECFUN is called with point at the end of a record. This
  3139. function moves point to the start of the next record. The
  3140. first record is assumed to start at the position of point
  3141. when `sort-subr' is called. Therefore, you should usually
  3142. move point to the beginning of the buffer before calling
  3143. `sort-subr'.
  3144. This function can indicate there are no more sort records by
  3145. leaving point at the end of the buffer.
  3146. 2. ENDRECFUN is called with point within a record. It moves
  3147. point to the end of the record.
  3148. 3. STARTKEYFUN is called to move point from the start of a
  3149. record to the start of the sort key. This argument is
  3150. optional; if it is omitted, the whole record is the sort key.
  3151. If supplied, the function should either return a non-`nil'
  3152. value to be used as the sort key, or return `nil' to indicate
  3153. that the sort key is in the buffer starting at point. In the
  3154. latter case, ENDKEYFUN is called to find the end of the sort
  3155. key.
  3156. 4. ENDKEYFUN is called to move point from the start of the sort
  3157. key to the end of the sort key. This argument is optional.
  3158. If STARTKEYFUN returns `nil' and this argument is omitted (or
  3159. `nil'), then the sort key extends to the end of the record.
  3160. There is no need for ENDKEYFUN if STARTKEYFUN returns a
  3161. non-`nil' value.
  3162. The argument PREDICATE is the function to use to compare keys. If
  3163. keys are numbers, it defaults to `<'; otherwise it defaults to
  3164. `string<'.
  3165. As an example of `sort-subr', here is the complete function
  3166. definition for `sort-lines':
  3167. ;; Note that the first two lines of doc string
  3168. ;; are effectively one line when viewed by a user.
  3169. (defun sort-lines (reverse beg end)
  3170. "Sort lines in region alphabetically;\
  3171. argument means descending order.
  3172. Called from a program, there are three arguments:
  3173. REVERSE (non-nil means reverse order),\
  3174. BEG and END (region to sort).
  3175. The variable `sort-fold-case' determines\
  3176. whether alphabetic case affects
  3177. the sort order."
  3178. (interactive "P\nr")
  3179. (save-excursion
  3180. (save-restriction
  3181. (narrow-to-region beg end)
  3182. (goto-char (point-min))
  3183. (let ((inhibit-field-text-motion t))
  3184. (sort-subr reverse 'forward-line 'end-of-line)))))
  3185. Here `forward-line' moves point to the start of the next record,
  3186. and `end-of-line' moves point to the end of record. We do not pass
  3187. the arguments STARTKEYFUN and ENDKEYFUN, because the entire record
  3188. is used as the sort key.
  3189. The `sort-paragraphs' function is very much the same, except that
  3190. its `sort-subr' call looks like this:
  3191. (sort-subr reverse
  3192. (function
  3193. (lambda ()
  3194. (while (and (not (eobp))
  3195. (looking-at paragraph-separate))
  3196. (forward-line 1))))
  3197. 'forward-paragraph)
  3198. Markers pointing into any sort records are left with no useful
  3199. position after `sort-subr' returns.
  3200. -- User Option: sort-fold-case
  3201. If this variable is non-`nil', `sort-subr' and the other buffer
  3202. sorting functions ignore case when comparing strings.
  3203. -- Command: sort-regexp-fields reverse record-regexp key-regexp start
  3204. end
  3205. This command sorts the region between START and END alphabetically
  3206. as specified by RECORD-REGEXP and KEY-REGEXP. If REVERSE is a
  3207. negative integer, then sorting is in reverse order.
  3208. Alphabetical sorting means that two sort keys are compared by
  3209. comparing the first characters of each, the second characters of
  3210. each, and so on. If a mismatch is found, it means that the sort
  3211. keys are unequal; the sort key whose character is less at the
  3212. point of first mismatch is the lesser sort key. The individual
  3213. characters are compared according to their numerical character
  3214. codes in the Emacs character set.
  3215. The value of the RECORD-REGEXP argument specifies how to divide
  3216. the buffer into sort records. At the end of each record, a search
  3217. is done for this regular expression, and the text that matches it
  3218. is taken as the next record. For example, the regular expression
  3219. `^.+$', which matches lines with at least one character besides a
  3220. newline, would make each such line into a sort record. *Note
  3221. Regular Expressions::, for a description of the syntax and meaning
  3222. of regular expressions.
  3223. The value of the KEY-REGEXP argument specifies what part of each
  3224. record is the sort key. The KEY-REGEXP could match the whole
  3225. record, or only a part. In the latter case, the rest of the
  3226. record has no effect on the sorted order of records, but it is
  3227. carried along when the record moves to its new position.
  3228. The KEY-REGEXP argument can refer to the text matched by a
  3229. subexpression of RECORD-REGEXP, or it can be a regular expression
  3230. on its own.
  3231. If KEY-REGEXP is:
  3232. `\DIGIT'
  3233. then the text matched by the DIGITth `\(...\)' parenthesis
  3234. grouping in RECORD-REGEXP is the sort key.
  3235. `\&'
  3236. then the whole record is the sort key.
  3237. a regular expression
  3238. then `sort-regexp-fields' searches for a match for the regular
  3239. expression within the record. If such a match is found, it
  3240. is the sort key. If there is no match for KEY-REGEXP within
  3241. a record then that record is ignored, which means its
  3242. position in the buffer is not changed. (The other records
  3243. may move around it.)
  3244. For example, if you plan to sort all the lines in the region by the
  3245. first word on each line starting with the letter `f', you should
  3246. set RECORD-REGEXP to `^.*$' and set KEY-REGEXP to `\<f\w*\>'. The
  3247. resulting expression looks like this:
  3248. (sort-regexp-fields nil "^.*$" "\\<f\\w*\\>"
  3249. (region-beginning)
  3250. (region-end))
  3251. If you call `sort-regexp-fields' interactively, it prompts for
  3252. RECORD-REGEXP and KEY-REGEXP in the minibuffer.
  3253. -- Command: sort-lines reverse start end
  3254. This command alphabetically sorts lines in the region between
  3255. START and END. If REVERSE is non-`nil', the sort is in reverse
  3256. order.
  3257. -- Command: sort-paragraphs reverse start end
  3258. This command alphabetically sorts paragraphs in the region between
  3259. START and END. If REVERSE is non-`nil', the sort is in reverse
  3260. order.
  3261. -- Command: sort-pages reverse start end
  3262. This command alphabetically sorts pages in the region between
  3263. START and END. If REVERSE is non-`nil', the sort is in reverse
  3264. order.
  3265. -- Command: sort-fields field start end
  3266. This command sorts lines in the region between START and END,
  3267. comparing them alphabetically by the FIELDth field of each line.
  3268. Fields are separated by whitespace and numbered starting from 1.
  3269. If FIELD is negative, sorting is by the -FIELDth field from the
  3270. end of the line. This command is useful for sorting tables.
  3271. -- Command: sort-numeric-fields field start end
  3272. This command sorts lines in the region between START and END,
  3273. comparing them numerically by the FIELDth field of each line.
  3274. Fields are separated by whitespace and numbered starting from 1.
  3275. The specified field must contain a number in each line of the
  3276. region. Numbers starting with 0 are treated as octal, and numbers
  3277. starting with `0x' are treated as hexadecimal.
  3278. If FIELD is negative, sorting is by the -FIELDth field from the
  3279. end of the line. This command is useful for sorting tables.
  3280. -- User Option: sort-numeric-base
  3281. This variable specifies the default radix for
  3282. `sort-numeric-fields' to parse numbers.
  3283. -- Command: sort-columns reverse &optional beg end
  3284. This command sorts the lines in the region between BEG and END,
  3285. comparing them alphabetically by a certain range of columns. The
  3286. column positions of BEG and END bound the range of columns to sort
  3287. on.
  3288. If REVERSE is non-`nil', the sort is in reverse order.
  3289. One unusual thing about this command is that the entire line
  3290. containing position BEG, and the entire line containing position
  3291. END, are included in the region sorted.
  3292. Note that `sort-columns' rejects text that contains tabs, because
  3293. tabs could be split across the specified columns. Use `M-x
  3294. untabify' to convert tabs to spaces before sorting.
  3295. When possible, this command actually works by calling the `sort'
  3296. utility program.
  3297. 
  3298. File: elisp, Node: Columns, Next: Indentation, Prev: Sorting, Up: Text
  3299. 32.16 Counting Columns
  3300. ======================
  3301. The column functions convert between a character position (counting
  3302. characters from the beginning of the buffer) and a column position
  3303. (counting screen characters from the beginning of a line).
  3304. These functions count each character according to the number of
  3305. columns it occupies on the screen. This means control characters count
  3306. as occupying 2 or 4 columns, depending upon the value of `ctl-arrow',
  3307. and tabs count as occupying a number of columns that depends on the
  3308. value of `tab-width' and on the column where the tab begins. *Note
  3309. Usual Display::.
  3310. Column number computations ignore the width of the window and the
  3311. amount of horizontal scrolling. Consequently, a column value can be
  3312. arbitrarily high. The first (or leftmost) column is numbered 0. They
  3313. also ignore overlays and text properties, aside from invisibility.
  3314. -- Function: current-column
  3315. This function returns the horizontal position of point, measured in
  3316. columns, counting from 0 at the left margin. The column position
  3317. is the sum of the widths of all the displayed representations of
  3318. the characters between the start of the current line and point.
  3319. For an example of using `current-column', see the description of
  3320. `count-lines' in *note Text Lines::.
  3321. -- Command: move-to-column column &optional force
  3322. This function moves point to COLUMN in the current line. The
  3323. calculation of COLUMN takes into account the widths of the
  3324. displayed representations of the characters between the start of
  3325. the line and point.
  3326. When called interactively, COLUMN is the value of prefix numeric
  3327. argument. If COLUMN is not an integer, an error is signaled.
  3328. If column COLUMN is beyond the end of the line, point moves to the
  3329. end of the line. If COLUMN is negative, point moves to the
  3330. beginning of the line.
  3331. If it is impossible to move to column COLUMN because that is in
  3332. the middle of a multicolumn character such as a tab, point moves
  3333. to the end of that character. However, if FORCE is non-`nil', and
  3334. COLUMN is in the middle of a tab, then `move-to-column' converts
  3335. the tab into spaces so that it can move precisely to column
  3336. COLUMN. Other multicolumn characters can cause anomalies despite
  3337. FORCE, since there is no way to split them.
  3338. The argument FORCE also has an effect if the line isn't long
  3339. enough to reach column COLUMN; if it is `t', that means to add
  3340. whitespace at the end of the line to reach that column.
  3341. The return value is the column number actually moved to.
  3342. 
  3343. File: elisp, Node: Indentation, Next: Case Changes, Prev: Columns, Up: Text
  3344. 32.17 Indentation
  3345. =================
  3346. The indentation functions are used to examine, move to, and change
  3347. whitespace that is at the beginning of a line. Some of the functions
  3348. can also change whitespace elsewhere on a line. Columns and indentation
  3349. count from zero at the left margin.
  3350. * Menu:
  3351. * Primitive Indent:: Functions used to count and insert indentation.
  3352. * Mode-Specific Indent:: Customize indentation for different modes.
  3353. * Region Indent:: Indent all the lines in a region.
  3354. * Relative Indent:: Indent the current line based on previous lines.
  3355. * Indent Tabs:: Adjustable, typewriter-like tab stops.
  3356. * Motion by Indent:: Move to first non-blank character.
  3357. 
  3358. File: elisp, Node: Primitive Indent, Next: Mode-Specific Indent, Up: Indentation
  3359. 32.17.1 Indentation Primitives
  3360. ------------------------------
  3361. This section describes the primitive functions used to count and insert
  3362. indentation. The functions in the following sections use these
  3363. primitives. *Note Width::, for related functions.
  3364. -- Function: current-indentation
  3365. This function returns the indentation of the current line, which is
  3366. the horizontal position of the first nonblank character. If the
  3367. contents are entirely blank, then this is the horizontal position
  3368. of the end of the line.
  3369. -- Command: indent-to column &optional minimum
  3370. This function indents from point with tabs and spaces until COLUMN
  3371. is reached. If MINIMUM is specified and non-`nil', then at least
  3372. that many spaces are inserted even if this requires going beyond
  3373. COLUMN. Otherwise the function does nothing if point is already
  3374. beyond COLUMN. The value is the column at which the inserted
  3375. indentation ends.
  3376. The inserted whitespace characters inherit text properties from the
  3377. surrounding text (usually, from the preceding text only). *Note
  3378. Sticky Properties::.
  3379. -- User Option: indent-tabs-mode
  3380. If this variable is non-`nil', indentation functions can insert
  3381. tabs as well as spaces. Otherwise, they insert only spaces.
  3382. Setting this variable automatically makes it buffer-local in the
  3383. current buffer.
  3384. 
  3385. File: elisp, Node: Mode-Specific Indent, Next: Region Indent, Prev: Primitive Indent, Up: Indentation
  3386. 32.17.2 Indentation Controlled by Major Mode
  3387. --------------------------------------------
  3388. An important function of each major mode is to customize the <TAB> key
  3389. to indent properly for the language being edited. This section
  3390. describes the mechanism of the <TAB> key and how to control it. The
  3391. functions in this section return unpredictable values.
  3392. -- Command: indent-for-tab-command &optional rigid
  3393. This is the command bound to <TAB> in most editing modes. Its
  3394. usual action is to indent the current line, but it can
  3395. alternatively insert a tab character or indent a region.
  3396. Here is what it does:
  3397. * First, it checks whether Transient Mark mode is enabled and
  3398. the region is active. If so, it called `indent-region' to
  3399. indent all the text in the region (*note Region Indent::).
  3400. * Otherwise, if the indentation function in
  3401. `indent-line-function' is `indent-to-left-margin' (a trivial
  3402. command that inserts a tab character), or if the variable
  3403. `tab-always-indent' specifies that a tab character ought to
  3404. be inserted (see below), then it inserts a tab character.
  3405. * Otherwise, it indents the current line; this is done by
  3406. calling the function in `indent-line-function'. If the line
  3407. is already indented, and the value of `tab-always-indent' is
  3408. `complete' (see below), it tries completing the text at point.
  3409. If RIGID is non-`nil' (interactively, with a prefix argument),
  3410. then after this command indents a line or inserts a tab, it also
  3411. rigidly indents the entire balanced expression which starts at the
  3412. beginning of the current line, in order to reflect the new
  3413. indentation. This argument is ignored if the command indents the
  3414. region.
  3415. -- Variable: indent-line-function
  3416. This variable's value is the function to be used by
  3417. `indent-for-tab-command', and various other indentation commands,
  3418. to indent the current line. It is usually assigned by the major
  3419. mode; for instance, Lisp mode sets it to `lisp-indent-line', C mode
  3420. sets it to `c-indent-line', and so on. The default value is
  3421. `indent-relative'. *Note Auto-Indentation::.
  3422. -- Command: indent-according-to-mode
  3423. This command calls the function in `indent-line-function' to
  3424. indent the current line in a way appropriate for the current major
  3425. mode.
  3426. -- Command: newline-and-indent
  3427. This function inserts a newline, then indents the new line (the one
  3428. following the newline just inserted) according to the major mode.
  3429. It does indentation by calling `indent-according-to-mode'.
  3430. -- Command: reindent-then-newline-and-indent
  3431. This command reindents the current line, inserts a newline at
  3432. point, and then indents the new line (the one following the
  3433. newline just inserted). It does indentation on both lines by
  3434. calling `indent-according-to-mode'.
  3435. -- User Option: tab-always-indent
  3436. This variable can be used to customize the behavior of the <TAB>
  3437. (`indent-for-tab-command') command. If the value is `t' (the
  3438. default), the command normally just indents the current line. If
  3439. the value is `nil', the command indents the current line only if
  3440. point is at the left margin or in the line's indentation;
  3441. otherwise, it inserts a tab character. If the value is
  3442. `complete', the command first tries to indent the current line,
  3443. and if the line was already indented, it calls
  3444. `completion-at-point' to complete the text at point (*note
  3445. Completion in Buffers::).
  3446. 
  3447. File: elisp, Node: Region Indent, Next: Relative Indent, Prev: Mode-Specific Indent, Up: Indentation
  3448. 32.17.3 Indenting an Entire Region
  3449. ----------------------------------
  3450. This section describes commands that indent all the lines in the
  3451. region. They return unpredictable values.
  3452. -- Command: indent-region start end &optional to-column
  3453. This command indents each nonblank line starting between START
  3454. (inclusive) and END (exclusive). If TO-COLUMN is `nil',
  3455. `indent-region' indents each nonblank line by calling the current
  3456. mode's indentation function, the value of `indent-line-function'.
  3457. If TO-COLUMN is non-`nil', it should be an integer specifying the
  3458. number of columns of indentation; then this function gives each
  3459. line exactly that much indentation, by either adding or deleting
  3460. whitespace.
  3461. If there is a fill prefix, `indent-region' indents each line by
  3462. making it start with the fill prefix.
  3463. -- Variable: indent-region-function
  3464. The value of this variable is a function that can be used by
  3465. `indent-region' as a short cut. It should take two arguments, the
  3466. start and end of the region. You should design the function so
  3467. that it will produce the same results as indenting the lines of the
  3468. region one by one, but presumably faster.
  3469. If the value is `nil', there is no short cut, and `indent-region'
  3470. actually works line by line.
  3471. A short-cut function is useful in modes such as C mode and Lisp
  3472. mode, where the `indent-line-function' must scan from the
  3473. beginning of the function definition: applying it to each line
  3474. would be quadratic in time. The short cut can update the scan
  3475. information as it moves through the lines indenting them; this
  3476. takes linear time. In a mode where indenting a line individually
  3477. is fast, there is no need for a short cut.
  3478. `indent-region' with a non-`nil' argument TO-COLUMN has a
  3479. different meaning and does not use this variable.
  3480. -- Command: indent-rigidly start end count
  3481. This command indents all lines starting between START (inclusive)
  3482. and END (exclusive) sideways by COUNT columns. This "preserves
  3483. the shape" of the affected region, moving it as a rigid unit.
  3484. Consequently, this command is useful not only for indenting
  3485. regions of unindented text, but also for indenting regions of
  3486. formatted code.
  3487. For example, if COUNT is 3, this command adds 3 columns of
  3488. indentation to each of the lines beginning in the region specified.
  3489. In Mail mode, `C-c C-y' (`mail-yank-original') uses
  3490. `indent-rigidly' to indent the text copied from the message being
  3491. replied to.
  3492. -- Command: indent-code-rigidly start end columns &optional
  3493. nochange-regexp
  3494. This is like `indent-rigidly', except that it doesn't alter lines
  3495. that start within strings or comments.
  3496. In addition, it doesn't alter a line if NOCHANGE-REGEXP matches at
  3497. the beginning of the line (if NOCHANGE-REGEXP is non-`nil').
  3498. 
  3499. File: elisp, Node: Relative Indent, Next: Indent Tabs, Prev: Region Indent, Up: Indentation
  3500. 32.17.4 Indentation Relative to Previous Lines
  3501. ----------------------------------------------
  3502. This section describes two commands that indent the current line based
  3503. on the contents of previous lines.
  3504. -- Command: indent-relative &optional unindented-ok
  3505. This command inserts whitespace at point, extending to the same
  3506. column as the next "indent point" of the previous nonblank line.
  3507. An indent point is a non-whitespace character following
  3508. whitespace. The next indent point is the first one at a column
  3509. greater than the current column of point. For example, if point
  3510. is underneath and to the left of the first non-blank character of
  3511. a line of text, it moves to that column by inserting whitespace.
  3512. If the previous nonblank line has no next indent point (i.e., none
  3513. at a great enough column position), `indent-relative' either does
  3514. nothing (if UNINDENTED-OK is non-`nil') or calls
  3515. `tab-to-tab-stop'. Thus, if point is underneath and to the right
  3516. of the last column of a short line of text, this command ordinarily
  3517. moves point to the next tab stop by inserting whitespace.
  3518. The return value of `indent-relative' is unpredictable.
  3519. In the following example, point is at the beginning of the second
  3520. line:
  3521. This line is indented twelve spaces.
  3522. -!-The quick brown fox jumped.
  3523. Evaluation of the expression `(indent-relative nil)' produces the
  3524. following:
  3525. This line is indented twelve spaces.
  3526. -!-The quick brown fox jumped.
  3527. In this next example, point is between the `m' and `p' of `jumped':
  3528. This line is indented twelve spaces.
  3529. The quick brown fox jum-!-ped.
  3530. Evaluation of the expression `(indent-relative nil)' produces the
  3531. following:
  3532. This line is indented twelve spaces.
  3533. The quick brown fox jum -!-ped.
  3534. -- Command: indent-relative-maybe
  3535. This command indents the current line like the previous nonblank
  3536. line, by calling `indent-relative' with `t' as the UNINDENTED-OK
  3537. argument. The return value is unpredictable.
  3538. If the previous nonblank line has no indent points beyond the
  3539. current column, this command does nothing.
  3540. 
  3541. File: elisp, Node: Indent Tabs, Next: Motion by Indent, Prev: Relative Indent, Up: Indentation
  3542. 32.17.5 Adjustable "Tab Stops"
  3543. ------------------------------
  3544. This section explains the mechanism for user-specified "tab stops" and
  3545. the mechanisms that use and set them. The name "tab stops" is used
  3546. because the feature is similar to that of the tab stops on a
  3547. typewriter. The feature works by inserting an appropriate number of
  3548. spaces and tab characters to reach the next tab stop column; it does not
  3549. affect the display of tab characters in the buffer (*note Usual
  3550. Display::). Note that the <TAB> character as input uses this tab stop
  3551. feature only in a few major modes, such as Text mode. *Note Tab Stops:
  3552. (emacs)Tab Stops.
  3553. -- Command: tab-to-tab-stop
  3554. This command inserts spaces or tabs before point, up to the next
  3555. tab stop column defined by `tab-stop-list'. It searches the list
  3556. for an element greater than the current column number, and uses
  3557. that element as the column to indent to. It does nothing if no
  3558. such element is found.
  3559. -- User Option: tab-stop-list
  3560. This variable is the list of tab stop columns used by
  3561. `tab-to-tab-stops'. The elements should be integers in increasing
  3562. order. The tab stop columns need not be evenly spaced.
  3563. Use `M-x edit-tab-stops' to edit the location of tab stops
  3564. interactively.
  3565. 
  3566. File: elisp, Node: Motion by Indent, Prev: Indent Tabs, Up: Indentation
  3567. 32.17.6 Indentation-Based Motion Commands
  3568. -----------------------------------------
  3569. These commands, primarily for interactive use, act based on the
  3570. indentation in the text.
  3571. -- Command: back-to-indentation
  3572. This command moves point to the first non-whitespace character in
  3573. the current line (which is the line in which point is located).
  3574. It returns `nil'.
  3575. -- Command: backward-to-indentation &optional arg
  3576. This command moves point backward ARG lines and then to the first
  3577. nonblank character on that line. It returns `nil'. If ARG is
  3578. omitted or `nil', it defaults to 1.
  3579. -- Command: forward-to-indentation &optional arg
  3580. This command moves point forward ARG lines and then to the first
  3581. nonblank character on that line. It returns `nil'. If ARG is
  3582. omitted or `nil', it defaults to 1.
  3583. 
  3584. File: elisp, Node: Case Changes, Next: Text Properties, Prev: Indentation, Up: Text
  3585. 32.18 Case Changes
  3586. ==================
  3587. The case change commands described here work on text in the current
  3588. buffer. *Note Case Conversion::, for case conversion functions that
  3589. work on strings and characters. *Note Case Tables::, for how to
  3590. customize which characters are upper or lower case and how to convert
  3591. them.
  3592. -- Command: capitalize-region start end
  3593. This function capitalizes all words in the region defined by START
  3594. and END. To capitalize means to convert each word's first
  3595. character to upper case and convert the rest of each word to lower
  3596. case. The function returns `nil'.
  3597. If one end of the region is in the middle of a word, the part of
  3598. the word within the region is treated as an entire word.
  3599. When `capitalize-region' is called interactively, START and END
  3600. are point and the mark, with the smallest first.
  3601. ---------- Buffer: foo ----------
  3602. This is the contents of the 5th foo.
  3603. ---------- Buffer: foo ----------
  3604. (capitalize-region 1 44)
  3605. => nil
  3606. ---------- Buffer: foo ----------
  3607. This Is The Contents Of The 5th Foo.
  3608. ---------- Buffer: foo ----------
  3609. -- Command: downcase-region start end
  3610. This function converts all of the letters in the region defined by
  3611. START and END to lower case. The function returns `nil'.
  3612. When `downcase-region' is called interactively, START and END are
  3613. point and the mark, with the smallest first.
  3614. -- Command: upcase-region start end
  3615. This function converts all of the letters in the region defined by
  3616. START and END to upper case. The function returns `nil'.
  3617. When `upcase-region' is called interactively, START and END are
  3618. point and the mark, with the smallest first.
  3619. -- Command: capitalize-word count
  3620. This function capitalizes COUNT words after point, moving point
  3621. over as it does. To capitalize means to convert each word's first
  3622. character to upper case and convert the rest of each word to lower
  3623. case. If COUNT is negative, the function capitalizes the -COUNT
  3624. previous words but does not move point. The value is `nil'.
  3625. If point is in the middle of a word, the part of the word before
  3626. point is ignored when moving forward. The rest is treated as an
  3627. entire word.
  3628. When `capitalize-word' is called interactively, COUNT is set to
  3629. the numeric prefix argument.
  3630. -- Command: downcase-word count
  3631. This function converts the COUNT words after point to all lower
  3632. case, moving point over as it does. If COUNT is negative, it
  3633. converts the -COUNT previous words but does not move point. The
  3634. value is `nil'.
  3635. When `downcase-word' is called interactively, COUNT is set to the
  3636. numeric prefix argument.
  3637. -- Command: upcase-word count
  3638. This function converts the COUNT words after point to all upper
  3639. case, moving point over as it does. If COUNT is negative, it
  3640. converts the -COUNT previous words but does not move point. The
  3641. value is `nil'.
  3642. When `upcase-word' is called interactively, COUNT is set to the
  3643. numeric prefix argument.
  3644. 
  3645. File: elisp, Node: Text Properties, Next: Substitution, Prev: Case Changes, Up: Text
  3646. 32.19 Text Properties
  3647. =====================
  3648. Each character position in a buffer or a string can have a "text
  3649. property list", much like the property list of a symbol (*note Property
  3650. Lists::). The properties belong to a particular character at a
  3651. particular place, such as, the letter `T' at the beginning of this
  3652. sentence or the first `o' in `foo'--if the same character occurs in two
  3653. different places, the two occurrences in general have different
  3654. properties.
  3655. Each property has a name and a value. Both of these can be any Lisp
  3656. object, but the name is normally a symbol. Typically each property
  3657. name symbol is used for a particular purpose; for instance, the text
  3658. property `face' specifies the faces for displaying the character (*note
  3659. Special Properties::). The usual way to access the property list is to
  3660. specify a name and ask what value corresponds to it.
  3661. If a character has a `category' property, we call it the "property
  3662. category" of the character. It should be a symbol. The properties of
  3663. the symbol serve as defaults for the properties of the character.
  3664. Copying text between strings and buffers preserves the properties
  3665. along with the characters; this includes such diverse functions as
  3666. `substring', `insert', and `buffer-substring'.
  3667. * Menu:
  3668. * Examining Properties:: Looking at the properties of one character.
  3669. * Changing Properties:: Setting the properties of a range of text.
  3670. * Property Search:: Searching for where a property changes value.
  3671. * Special Properties:: Particular properties with special meanings.
  3672. * Format Properties:: Properties for representing formatting of text.
  3673. * Sticky Properties:: How inserted text gets properties from
  3674. neighboring text.
  3675. * Lazy Properties:: Computing text properties in a lazy fashion
  3676. only when text is examined.
  3677. * Clickable Text:: Using text properties to make regions of text
  3678. do something when you click on them.
  3679. * Fields:: The `field' property defines
  3680. fields within the buffer.
  3681. * Not Intervals:: Why text properties do not use
  3682. Lisp-visible text intervals.
  3683. 
  3684. File: elisp, Node: Examining Properties, Next: Changing Properties, Up: Text Properties
  3685. 32.19.1 Examining Text Properties
  3686. ---------------------------------
  3687. The simplest way to examine text properties is to ask for the value of
  3688. a particular property of a particular character. For that, use
  3689. `get-text-property'. Use `text-properties-at' to get the entire
  3690. property list of a character. *Note Property Search::, for functions
  3691. to examine the properties of a number of characters at once.
  3692. These functions handle both strings and buffers. Keep in mind that
  3693. positions in a string start from 0, whereas positions in a buffer start
  3694. from 1.
  3695. -- Function: get-text-property pos prop &optional object
  3696. This function returns the value of the PROP property of the
  3697. character after position POS in OBJECT (a buffer or string). The
  3698. argument OBJECT is optional and defaults to the current buffer.
  3699. If there is no PROP property strictly speaking, but the character
  3700. has a property category that is a symbol, then `get-text-property'
  3701. returns the PROP property of that symbol.
  3702. -- Function: get-char-property position prop &optional object
  3703. This function is like `get-text-property', except that it checks
  3704. overlays first and then text properties. *Note Overlays::.
  3705. The argument OBJECT may be a string, a buffer, or a window. If it
  3706. is a window, then the buffer displayed in that window is used for
  3707. text properties and overlays, but only the overlays active for that
  3708. window are considered. If OBJECT is a buffer, then overlays in
  3709. that buffer are considered first, in order of decreasing priority,
  3710. followed by the text properties. If OBJECT is a string, only text
  3711. properties are considered, since strings never have overlays.
  3712. -- Function: get-char-property-and-overlay position prop &optional
  3713. object
  3714. This is like `get-char-property', but gives extra information
  3715. about the overlay that the property value comes from.
  3716. Its value is a cons cell whose CAR is the property value, the same
  3717. value `get-char-property' would return with the same arguments.
  3718. Its CDR is the overlay in which the property was found, or `nil',
  3719. if it was found as a text property or not found at all.
  3720. If POSITION is at the end of OBJECT, both the CAR and the CDR of
  3721. the value are `nil'.
  3722. -- Variable: char-property-alias-alist
  3723. This variable holds an alist which maps property names to a list of
  3724. alternative property names. If a character does not specify a
  3725. direct value for a property, the alternative property names are
  3726. consulted in order; the first non-`nil' value is used. This
  3727. variable takes precedence over `default-text-properties', and
  3728. `category' properties take precedence over this variable.
  3729. -- Function: text-properties-at position &optional object
  3730. This function returns the entire property list of the character at
  3731. POSITION in the string or buffer OBJECT. If OBJECT is `nil', it
  3732. defaults to the current buffer.
  3733. -- Variable: default-text-properties
  3734. This variable holds a property list giving default values for text
  3735. properties. Whenever a character does not specify a value for a
  3736. property, neither directly, through a category symbol, or through
  3737. `char-property-alias-alist', the value stored in this list is used
  3738. instead. Here is an example:
  3739. (setq default-text-properties '(foo 69)
  3740. char-property-alias-alist nil)
  3741. ;; Make sure character 1 has no properties of its own.
  3742. (set-text-properties 1 2 nil)
  3743. ;; What we get, when we ask, is the default value.
  3744. (get-text-property 1 'foo)
  3745. => 69
  3746. 
  3747. File: elisp, Node: Changing Properties, Next: Property Search, Prev: Examining Properties, Up: Text Properties
  3748. 32.19.2 Changing Text Properties
  3749. --------------------------------
  3750. The primitives for changing properties apply to a specified range of
  3751. text in a buffer or string. The function `set-text-properties' (see
  3752. end of section) sets the entire property list of the text in that
  3753. range; more often, it is useful to add, change, or delete just certain
  3754. properties specified by name.
  3755. Since text properties are considered part of the contents of the
  3756. buffer (or string), and can affect how a buffer looks on the screen,
  3757. any change in buffer text properties marks the buffer as modified.
  3758. Buffer text property changes are undoable also (*note Undo::).
  3759. Positions in a string start from 0, whereas positions in a buffer start
  3760. from 1.
  3761. -- Function: put-text-property start end prop value &optional object
  3762. This function sets the PROP property to VALUE for the text between
  3763. START and END in the string or buffer OBJECT. If OBJECT is `nil',
  3764. it defaults to the current buffer.
  3765. -- Function: add-text-properties start end props &optional object
  3766. This function adds or overrides text properties for the text
  3767. between START and END in the string or buffer OBJECT. If OBJECT
  3768. is `nil', it defaults to the current buffer.
  3769. The argument PROPS specifies which properties to add. It should
  3770. have the form of a property list (*note Property Lists::): a list
  3771. whose elements include the property names followed alternately by
  3772. the corresponding values.
  3773. The return value is `t' if the function actually changed some
  3774. property's value; `nil' otherwise (if PROPS is `nil' or its values
  3775. agree with those in the text).
  3776. For example, here is how to set the `comment' and `face'
  3777. properties of a range of text:
  3778. (add-text-properties START END
  3779. '(comment t face highlight))
  3780. -- Function: remove-text-properties start end props &optional object
  3781. This function deletes specified text properties from the text
  3782. between START and END in the string or buffer OBJECT. If OBJECT
  3783. is `nil', it defaults to the current buffer.
  3784. The argument PROPS specifies which properties to delete. It
  3785. should have the form of a property list (*note Property Lists::):
  3786. a list whose elements are property names alternating with
  3787. corresponding values. But only the names matter--the values that
  3788. accompany them are ignored. For example, here's how to remove the
  3789. `face' property.
  3790. (remove-text-properties START END '(face nil))
  3791. The return value is `t' if the function actually changed some
  3792. property's value; `nil' otherwise (if PROPS is `nil' or if no
  3793. character in the specified text had any of those properties).
  3794. To remove all text properties from certain text, use
  3795. `set-text-properties' and specify `nil' for the new property list.
  3796. -- Function: remove-list-of-text-properties start end
  3797. list-of-properties &optional object
  3798. Like `remove-text-properties' except that LIST-OF-PROPERTIES is a
  3799. list of property names only, not an alternating list of property
  3800. names and values.
  3801. -- Function: set-text-properties start end props &optional object
  3802. This function completely replaces the text property list for the
  3803. text between START and END in the string or buffer OBJECT. If
  3804. OBJECT is `nil', it defaults to the current buffer.
  3805. The argument PROPS is the new property list. It should be a list
  3806. whose elements are property names alternating with corresponding
  3807. values.
  3808. After `set-text-properties' returns, all the characters in the
  3809. specified range have identical properties.
  3810. If PROPS is `nil', the effect is to get rid of all properties from
  3811. the specified range of text. Here's an example:
  3812. (set-text-properties START END nil)
  3813. Do not rely on the return value of this function.
  3814. The easiest way to make a string with text properties is with
  3815. `propertize':
  3816. -- Function: propertize string &rest properties
  3817. This function returns a copy of STRING which has the text
  3818. properties PROPERTIES. These properties apply to all the
  3819. characters in the string that is returned. Here is an example that
  3820. constructs a string with a `face' property and a `mouse-face'
  3821. property:
  3822. (propertize "foo" 'face 'italic
  3823. 'mouse-face 'bold-italic)
  3824. => #("foo" 0 3 (mouse-face bold-italic face italic))
  3825. To put different properties on various parts of a string, you can
  3826. construct each part with `propertize' and then combine them with
  3827. `concat':
  3828. (concat
  3829. (propertize "foo" 'face 'italic
  3830. 'mouse-face 'bold-italic)
  3831. " and "
  3832. (propertize "bar" 'face 'italic
  3833. 'mouse-face 'bold-italic))
  3834. => #("foo and bar"
  3835. 0 3 (face italic mouse-face bold-italic)
  3836. 3 8 nil
  3837. 8 11 (face italic mouse-face bold-italic))
  3838. *Note Buffer Contents::, for the function
  3839. `buffer-substring-no-properties', which copies text from the buffer but
  3840. does not copy its properties.
  3841. 
  3842. File: elisp, Node: Property Search, Next: Special Properties, Prev: Changing Properties, Up: Text Properties
  3843. 32.19.3 Text Property Search Functions
  3844. --------------------------------------
  3845. In typical use of text properties, most of the time several or many
  3846. consecutive characters have the same value for a property. Rather than
  3847. writing your programs to examine characters one by one, it is much
  3848. faster to process chunks of text that have the same property value.
  3849. Here are functions you can use to do this. They use `eq' for
  3850. comparing property values. In all cases, OBJECT defaults to the
  3851. current buffer.
  3852. For good performance, it's very important to use the LIMIT argument
  3853. to these functions, especially the ones that search for a single
  3854. property--otherwise, they may spend a long time scanning to the end of
  3855. the buffer, if the property you are interested in does not change.
  3856. These functions do not move point; instead, they return a position
  3857. (or `nil'). Remember that a position is always between two characters;
  3858. the position returned by these functions is between two characters with
  3859. different properties.
  3860. -- Function: next-property-change pos &optional object limit
  3861. The function scans the text forward from position POS in the
  3862. string or buffer OBJECT until it finds a change in some text
  3863. property, then returns the position of the change. In other
  3864. words, it returns the position of the first character beyond POS
  3865. whose properties are not identical to those of the character just
  3866. after POS.
  3867. If LIMIT is non-`nil', then the scan ends at position LIMIT. If
  3868. there is no property change before that point, this function
  3869. returns LIMIT.
  3870. The value is `nil' if the properties remain unchanged all the way
  3871. to the end of OBJECT and LIMIT is `nil'. If the value is
  3872. non-`nil', it is a position greater than or equal to POS. The
  3873. value equals POS only when LIMIT equals POS.
  3874. Here is an example of how to scan the buffer by chunks of text
  3875. within which all properties are constant:
  3876. (while (not (eobp))
  3877. (let ((plist (text-properties-at (point)))
  3878. (next-change
  3879. (or (next-property-change (point) (current-buffer))
  3880. (point-max))))
  3881. Process text from point to NEXT-CHANGE...
  3882. (goto-char next-change)))
  3883. -- Function: previous-property-change pos &optional object limit
  3884. This is like `next-property-change', but scans back from POS
  3885. instead of forward. If the value is non-`nil', it is a position
  3886. less than or equal to POS; it equals POS only if LIMIT equals POS.
  3887. -- Function: next-single-property-change pos prop &optional object
  3888. limit
  3889. The function scans text for a change in the PROP property, then
  3890. returns the position of the change. The scan goes forward from
  3891. position POS in the string or buffer OBJECT. In other words, this
  3892. function returns the position of the first character beyond POS
  3893. whose PROP property differs from that of the character just after
  3894. POS.
  3895. If LIMIT is non-`nil', then the scan ends at position LIMIT. If
  3896. there is no property change before that point,
  3897. `next-single-property-change' returns LIMIT.
  3898. The value is `nil' if the property remains unchanged all the way to
  3899. the end of OBJECT and LIMIT is `nil'. If the value is non-`nil',
  3900. it is a position greater than or equal to POS; it equals POS only
  3901. if LIMIT equals POS.
  3902. -- Function: previous-single-property-change pos prop &optional object
  3903. limit
  3904. This is like `next-single-property-change', but scans back from
  3905. POS instead of forward. If the value is non-`nil', it is a
  3906. position less than or equal to POS; it equals POS only if LIMIT
  3907. equals POS.
  3908. -- Function: next-char-property-change pos &optional limit
  3909. This is like `next-property-change' except that it considers
  3910. overlay properties as well as text properties, and if no change is
  3911. found before the end of the buffer, it returns the maximum buffer
  3912. position rather than `nil' (in this sense, it resembles the
  3913. corresponding overlay function `next-overlay-change', rather than
  3914. `next-property-change'). There is no OBJECT operand because this
  3915. function operates only on the current buffer. It returns the next
  3916. address at which either kind of property changes.
  3917. -- Function: previous-char-property-change pos &optional limit
  3918. This is like `next-char-property-change', but scans back from POS
  3919. instead of forward, and returns the minimum buffer position if no
  3920. change is found.
  3921. -- Function: next-single-char-property-change pos prop &optional
  3922. object limit
  3923. This is like `next-single-property-change' except that it
  3924. considers overlay properties as well as text properties, and if no
  3925. change is found before the end of the OBJECT, it returns the
  3926. maximum valid position in OBJECT rather than `nil'. Unlike
  3927. `next-char-property-change', this function _does_ have an OBJECT
  3928. operand; if OBJECT is not a buffer, only text-properties are
  3929. considered.
  3930. -- Function: previous-single-char-property-change pos prop &optional
  3931. object limit
  3932. This is like `next-single-char-property-change', but scans back
  3933. from POS instead of forward, and returns the minimum valid
  3934. position in OBJECT if no change is found.
  3935. -- Function: text-property-any start end prop value &optional object
  3936. This function returns non-`nil' if at least one character between
  3937. START and END has a property PROP whose value is VALUE. More
  3938. precisely, it returns the position of the first such character.
  3939. Otherwise, it returns `nil'.
  3940. The optional fifth argument, OBJECT, specifies the string or
  3941. buffer to scan. Positions are relative to OBJECT. The default
  3942. for OBJECT is the current buffer.
  3943. -- Function: text-property-not-all start end prop value &optional
  3944. object
  3945. This function returns non-`nil' if at least one character between
  3946. START and END does not have a property PROP with value VALUE.
  3947. More precisely, it returns the position of the first such
  3948. character. Otherwise, it returns `nil'.
  3949. The optional fifth argument, OBJECT, specifies the string or
  3950. buffer to scan. Positions are relative to OBJECT. The default
  3951. for OBJECT is the current buffer.
  3952. 
  3953. File: elisp, Node: Special Properties, Next: Format Properties, Prev: Property Search, Up: Text Properties
  3954. 32.19.4 Properties with Special Meanings
  3955. ----------------------------------------
  3956. Here is a table of text property names that have special built-in
  3957. meanings. The following sections list a few additional special property
  3958. names that control filling and property inheritance. All other names
  3959. have no standard meaning, and you can use them as you like.
  3960. Note: the properties `composition', `display', `invisible' and
  3961. `intangible' can also cause point to move to an acceptable place, after
  3962. each Emacs command. *Note Adjusting Point::.
  3963. `category'
  3964. If a character has a `category' property, we call it the "property
  3965. category" of the character. It should be a symbol. The
  3966. properties of this symbol serve as defaults for the properties of
  3967. the character.
  3968. `face'
  3969. The `face' property controls the appearance of the character, such
  3970. as its font and color. *Note Faces::. The value of the property
  3971. can be the following:
  3972. * A face name (a symbol or string).
  3973. * A property list of face attributes. This has the form
  3974. (KEYWORD VALUE ...), where each KEYWORD is a face attribute
  3975. name and VALUE is a meaningful value for that attribute.
  3976. With this feature, you do not need to create a face each time
  3977. you want to specify a particular attribute for certain text.
  3978. *Note Face Attributes::.
  3979. * A list, where each element uses one of the two forms listed
  3980. above.
  3981. Font Lock mode (*note Font Lock Mode::) works in most buffers by
  3982. dynamically updating the `face' property of characters based on
  3983. the context.
  3984. `font-lock-face'
  3985. This property specifies a value for the `face' property that Font
  3986. Lock mode should apply to the underlying text. It is one of the
  3987. fontification methods used by Font Lock mode, and is useful for
  3988. special modes that implement their own highlighting. *Note
  3989. Precalculated Fontification::. When Font Lock mode is disabled,
  3990. `font-lock-face' has no effect.
  3991. `mouse-face'
  3992. This property is used instead of `face' when the mouse is on or
  3993. near the character. For this purpose, "near" means that all text
  3994. between the character and where the mouse is have the same
  3995. `mouse-face' property value.
  3996. Emacs ignores all face attributes from the `mouse-face' property
  3997. that alter the text size (e.g. `:height', `:weight', and
  3998. `:slant'). Those attributes are always the same as for the
  3999. unhighlighted text.
  4000. `fontified'
  4001. This property says whether the text is ready for display. If
  4002. `nil', Emacs's redisplay routine calls the functions in
  4003. `fontification-functions' (*note Auto Faces::) to prepare this
  4004. part of the buffer before it is displayed. It is used internally
  4005. by the "just in time" font locking code.
  4006. `display'
  4007. This property activates various features that change the way text
  4008. is displayed. For example, it can make text appear taller or
  4009. shorter, higher or lower, wider or narrow, or replaced with an
  4010. image. *Note Display Property::.
  4011. `help-echo'
  4012. If text has a string as its `help-echo' property, then when you
  4013. move the mouse onto that text, Emacs displays that string in the
  4014. echo area, or in the tooltip window (*note Tooltips:
  4015. (emacs)Tooltips.).
  4016. If the value of the `help-echo' property is a function, that
  4017. function is called with three arguments, WINDOW, OBJECT and POS
  4018. and should return a help string or `nil' for none. The first
  4019. argument, WINDOW is the window in which the help was found. The
  4020. second, OBJECT, is the buffer, overlay or string which had the
  4021. `help-echo' property. The POS argument is as follows:
  4022. * If OBJECT is a buffer, POS is the position in the buffer.
  4023. * If OBJECT is an overlay, that overlay has a `help-echo'
  4024. property, and POS is the position in the overlay's buffer.
  4025. * If OBJECT is a string (an overlay string or a string displayed
  4026. with the `display' property), POS is the position in that
  4027. string.
  4028. If the value of the `help-echo' property is neither a function nor
  4029. a string, it is evaluated to obtain a help string.
  4030. You can alter the way help text is displayed by setting the
  4031. variable `show-help-function' (*note Help display::).
  4032. This feature is used in the mode line and for other active text.
  4033. `keymap'
  4034. The `keymap' property specifies an additional keymap for commands.
  4035. When this keymap applies, it is used for key lookup before the
  4036. minor mode keymaps and before the buffer's local map. *Note
  4037. Active Keymaps::. If the property value is a symbol, the symbol's
  4038. function definition is used as the keymap.
  4039. The property's value for the character before point applies if it
  4040. is non-`nil' and rear-sticky, and the property's value for the
  4041. character after point applies if it is non-`nil' and front-sticky.
  4042. (For mouse clicks, the position of the click is used instead of
  4043. the position of point.)
  4044. `local-map'
  4045. This property works like `keymap' except that it specifies a
  4046. keymap to use _instead of_ the buffer's local map. For most
  4047. purposes (perhaps all purposes), it is better to use the `keymap'
  4048. property.
  4049. `syntax-table'
  4050. The `syntax-table' property overrides what the syntax table says
  4051. about this particular character. *Note Syntax Properties::.
  4052. `read-only'
  4053. If a character has the property `read-only', then modifying that
  4054. character is not allowed. Any command that would do so gets an
  4055. error, `text-read-only'. If the property value is a string, that
  4056. string is used as the error message.
  4057. Insertion next to a read-only character is an error if inserting
  4058. ordinary text there would inherit the `read-only' property due to
  4059. stickiness. Thus, you can control permission to insert next to
  4060. read-only text by controlling the stickiness. *Note Sticky
  4061. Properties::.
  4062. Since changing properties counts as modifying the buffer, it is not
  4063. possible to remove a `read-only' property unless you know the
  4064. special trick: bind `inhibit-read-only' to a non-`nil' value and
  4065. then remove the property. *Note Read Only Buffers::.
  4066. `invisible'
  4067. A non-`nil' `invisible' property can make a character invisible on
  4068. the screen. *Note Invisible Text::, for details.
  4069. `intangible'
  4070. If a group of consecutive characters have equal and non-`nil'
  4071. `intangible' properties, then you cannot place point between them.
  4072. If you try to move point forward into the group, point actually
  4073. moves to the end of the group. If you try to move point backward
  4074. into the group, point actually moves to the start of the group.
  4075. If consecutive characters have unequal non-`nil' `intangible'
  4076. properties, they belong to separate groups; each group is
  4077. separately treated as described above.
  4078. When the variable `inhibit-point-motion-hooks' is non-`nil', the
  4079. `intangible' property is ignored.
  4080. Beware: this property operates at a very low level, and affects a
  4081. lot of code in unexpected ways. So use it with extreme caution.
  4082. A common misuse is to put an intangible property on invisible
  4083. text, which is actually unnecessary since the command loop will
  4084. move point outside of the invisible text at the end of each
  4085. command anyway. *Note Adjusting Point::.
  4086. `field'
  4087. Consecutive characters with the same `field' property constitute a
  4088. "field". Some motion functions including `forward-word' and
  4089. `beginning-of-line' stop moving at a field boundary. *Note
  4090. Fields::.
  4091. `cursor'
  4092. Normally, the cursor is displayed at the beginning or the end of
  4093. any overlay and text property strings present at the current buffer
  4094. position. You can place the cursor on any desired character of
  4095. these strings by giving that character a non-`nil' `cursor' text
  4096. property. In addition, if the value of the `cursor' property is
  4097. an integer number, it specifies the number of buffer's character
  4098. positions, starting with the position where the overlay or the
  4099. `display' property begins, for which the cursor should be
  4100. displayed on that character. Specifically, if the value of the
  4101. `cursor' property of a character is the number N, the cursor will
  4102. be displayed on this character for any buffer position in the
  4103. range `[OVPOS..OVPOS+N)', where OVPOS is the overlay's starting
  4104. position given by `overlay-start' (*note Managing Overlays::), or
  4105. the position where the `display' text property begins in the
  4106. buffer.
  4107. In other words, the string character with the `cursor' property of
  4108. any non-`nil' value is the character where to display the cursor.
  4109. The value of the property says for which buffer positions to
  4110. display the cursor there. If the value is an integer number N,
  4111. the cursor is displayed there when point is anywhere between the
  4112. beginning of the overlay or `display' property and N positions
  4113. after that. If the value is anything else and non-`nil', the
  4114. cursor is displayed there only when point is at the beginning of
  4115. the `display' property or at `overlay-start'.
  4116. When the buffer has many overlay strings (e.g., *note
  4117. before-string: Overlay Properties.) or `display' properties that
  4118. are strings, it is a good idea to use the `cursor' property on
  4119. these strings to cue the Emacs display about the places where to
  4120. put the cursor while traversing these strings. This directly
  4121. communicates to the display engine where the Lisp program wants to
  4122. put the cursor, or where the user would expect the cursor.
  4123. `pointer'
  4124. This specifies a specific pointer shape when the mouse pointer is
  4125. over this text or image. *Note Pointer Shape::, for possible
  4126. pointer shapes.
  4127. `line-spacing'
  4128. A newline can have a `line-spacing' text or overlay property that
  4129. controls the height of the display line ending with that newline.
  4130. The property value overrides the default frame line spacing and
  4131. the buffer local `line-spacing' variable. *Note Line Height::.
  4132. `line-height'
  4133. A newline can have a `line-height' text or overlay property that
  4134. controls the total height of the display line ending in that
  4135. newline. *Note Line Height::.
  4136. `wrap-prefix'
  4137. If text has a `wrap-prefix' property, the prefix it defines will
  4138. be added at display time to the beginning of every continuation
  4139. line due to text wrapping (so if lines are truncated, the
  4140. wrap-prefix is never used). It may be a string or an image (*note
  4141. Other Display Specs::), or a stretch of whitespace such as
  4142. specified by the `:width' or `:align-to' display properties (*note
  4143. Specified Space::).
  4144. A wrap-prefix may also be specified for an entire buffer using the
  4145. `wrap-prefix' buffer-local variable (however, a `wrap-prefix'
  4146. text-property takes precedence over the value of the `wrap-prefix'
  4147. variable). *Note Truncation::.
  4148. `line-prefix'
  4149. If text has a `line-prefix' property, the prefix it defines will
  4150. be added at display time to the beginning of every non-continuation
  4151. line. It may be a string or an image (*note Other Display
  4152. Specs::), or a stretch of whitespace such as specified by the
  4153. `:width' or `:align-to' display properties (*note Specified
  4154. Space::).
  4155. A line-prefix may also be specified for an entire buffer using the
  4156. `line-prefix' buffer-local variable (however, a `line-prefix'
  4157. text-property takes precedence over the value of the `line-prefix'
  4158. variable). *Note Truncation::.
  4159. `modification-hooks'
  4160. If a character has the property `modification-hooks', then its
  4161. value should be a list of functions; modifying that character calls
  4162. all of those functions before the actual modification. Each
  4163. function receives two arguments: the beginning and end of the part
  4164. of the buffer being modified. Note that if a particular
  4165. modification hook function appears on several characters being
  4166. modified by a single primitive, you can't predict how many times
  4167. the function will be called. Furthermore, insertion will not
  4168. modify any existing character, so this hook will only be run when
  4169. removing some characters, replacing them with others, or changing
  4170. their text-properties.
  4171. If these functions modify the buffer, they should bind
  4172. `inhibit-modification-hooks' to `t' around doing so, to avoid
  4173. confusing the internal mechanism that calls these hooks.
  4174. Overlays also support the `modification-hooks' property, but the
  4175. details are somewhat different (*note Overlay Properties::).
  4176. `insert-in-front-hooks'
  4177. `insert-behind-hooks'
  4178. The operation of inserting text in a buffer also calls the
  4179. functions listed in the `insert-in-front-hooks' property of the
  4180. following character and in the `insert-behind-hooks' property of
  4181. the preceding character. These functions receive two arguments,
  4182. the beginning and end of the inserted text. The functions are
  4183. called _after_ the actual insertion takes place.
  4184. See also *note Change Hooks::, for other hooks that are called
  4185. when you change text in a buffer.
  4186. `point-entered'
  4187. `point-left'
  4188. The special properties `point-entered' and `point-left' record
  4189. hook functions that report motion of point. Each time point
  4190. moves, Emacs compares these two property values:
  4191. * the `point-left' property of the character after the old
  4192. location, and
  4193. * the `point-entered' property of the character after the new
  4194. location.
  4195. If these two values differ, each of them is called (if not `nil')
  4196. with two arguments: the old value of point, and the new one.
  4197. The same comparison is made for the characters before the old and
  4198. new locations. The result may be to execute two `point-left'
  4199. functions (which may be the same function) and/or two
  4200. `point-entered' functions (which may be the same function). In
  4201. any case, all the `point-left' functions are called first,
  4202. followed by all the `point-entered' functions.
  4203. It is possible to use `char-after' to examine characters at various
  4204. buffer positions without moving point to those positions. Only an
  4205. actual change in the value of point runs these hook functions.
  4206. The variable `inhibit-point-motion-hooks' can inhibit running the
  4207. `point-left' and `point-entered' hooks, see *note Inhibit point
  4208. motion hooks::.
  4209. `composition'
  4210. This text property is used to display a sequence of characters as a
  4211. single glyph composed from components. But the value of the
  4212. property itself is completely internal to Emacs and should not be
  4213. manipulated directly by, for instance, `put-text-property'.
  4214. -- Variable: inhibit-point-motion-hooks
  4215. When this variable is non-`nil', `point-left' and `point-entered'
  4216. hooks are not run, and the `intangible' property has no effect.
  4217. Do not set this variable globally; bind it with `let'.
  4218. -- Variable: show-help-function
  4219. If this variable is non-`nil', it specifies a function called to
  4220. display help strings. These may be `help-echo' properties, menu
  4221. help strings (*note Simple Menu Items::, *note Extended Menu
  4222. Items::), or tool bar help strings (*note Tool Bar::). The
  4223. specified function is called with one argument, the help string to
  4224. display. Tooltip mode (*note Tooltips: (emacs)Tooltips.) provides
  4225. an example.
  4226. 
  4227. File: elisp, Node: Format Properties, Next: Sticky Properties, Prev: Special Properties, Up: Text Properties
  4228. 32.19.5 Formatted Text Properties
  4229. ---------------------------------
  4230. These text properties affect the behavior of the fill commands. They
  4231. are used for representing formatted text. *Note Filling::, and *note
  4232. Margins::.
  4233. `hard'
  4234. If a newline character has this property, it is a "hard" newline.
  4235. The fill commands do not alter hard newlines and do not move words
  4236. across them. However, this property takes effect only if the
  4237. `use-hard-newlines' minor mode is enabled. *Note Hard and Soft
  4238. Newlines: (emacs)Hard and Soft Newlines.
  4239. `right-margin'
  4240. This property specifies an extra right margin for filling this
  4241. part of the text.
  4242. `left-margin'
  4243. This property specifies an extra left margin for filling this part
  4244. of the text.
  4245. `justification'
  4246. This property specifies the style of justification for filling
  4247. this part of the text.
  4248. 
  4249. File: elisp, Node: Sticky Properties, Next: Lazy Properties, Prev: Format Properties, Up: Text Properties
  4250. 32.19.6 Stickiness of Text Properties
  4251. -------------------------------------
  4252. Self-inserting characters normally take on the same properties as the
  4253. preceding character. This is called "inheritance" of properties.
  4254. A Lisp program can do insertion with inheritance or without,
  4255. depending on the choice of insertion primitive. The ordinary text
  4256. insertion functions, such as `insert', do not inherit any properties.
  4257. They insert text with precisely the properties of the string being
  4258. inserted, and no others. This is correct for programs that copy text
  4259. from one context to another--for example, into or out of the kill ring.
  4260. To insert with inheritance, use the special primitives described in
  4261. this section. Self-inserting characters inherit properties because
  4262. they work using these primitives.
  4263. When you do insertion with inheritance, _which_ properties are
  4264. inherited, and from where, depends on which properties are "sticky".
  4265. Insertion after a character inherits those of its properties that are
  4266. "rear-sticky". Insertion before a character inherits those of its
  4267. properties that are "front-sticky". When both sides offer different
  4268. sticky values for the same property, the previous character's value
  4269. takes precedence.
  4270. By default, a text property is rear-sticky but not front-sticky;
  4271. thus, the default is to inherit all the properties of the preceding
  4272. character, and nothing from the following character.
  4273. You can control the stickiness of various text properties with two
  4274. specific text properties, `front-sticky' and `rear-nonsticky', and with
  4275. the variable `text-property-default-nonsticky'. You can use the
  4276. variable to specify a different default for a given property. You can
  4277. use those two text properties to make any specific properties sticky or
  4278. nonsticky in any particular part of the text.
  4279. If a character's `front-sticky' property is `t', then all its
  4280. properties are front-sticky. If the `front-sticky' property is a list,
  4281. then the sticky properties of the character are those whose names are
  4282. in the list. For example, if a character has a `front-sticky' property
  4283. whose value is `(face read-only)', then insertion before the character
  4284. can inherit its `face' property and its `read-only' property, but no
  4285. others.
  4286. The `rear-nonsticky' property works the opposite way. Most
  4287. properties are rear-sticky by default, so the `rear-nonsticky' property
  4288. says which properties are _not_ rear-sticky. If a character's
  4289. `rear-nonsticky' property is `t', then none of its properties are
  4290. rear-sticky. If the `rear-nonsticky' property is a list, properties
  4291. are rear-sticky _unless_ their names are in the list.
  4292. -- Variable: text-property-default-nonsticky
  4293. This variable holds an alist which defines the default
  4294. rear-stickiness of various text properties. Each element has the
  4295. form `(PROPERTY . NONSTICKINESS)', and it defines the stickiness
  4296. of a particular text property, PROPERTY.
  4297. If NONSTICKINESS is non-`nil', this means that the property
  4298. PROPERTY is rear-nonsticky by default. Since all properties are
  4299. front-nonsticky by default, this makes PROPERTY nonsticky in both
  4300. directions by default.
  4301. The text properties `front-sticky' and `rear-nonsticky', when
  4302. used, take precedence over the default NONSTICKINESS specified in
  4303. `text-property-default-nonsticky'.
  4304. Here are the functions that insert text with inheritance of
  4305. properties:
  4306. -- Function: insert-and-inherit &rest strings
  4307. Insert the strings STRINGS, just like the function `insert', but
  4308. inherit any sticky properties from the adjoining text.
  4309. -- Function: insert-before-markers-and-inherit &rest strings
  4310. Insert the strings STRINGS, just like the function
  4311. `insert-before-markers', but inherit any sticky properties from the
  4312. adjoining text.
  4313. *Note Insertion::, for the ordinary insertion functions which do not
  4314. inherit.
  4315. 
  4316. File: elisp, Node: Lazy Properties, Next: Clickable Text, Prev: Sticky Properties, Up: Text Properties
  4317. 32.19.7 Lazy Computation of Text Properties
  4318. -------------------------------------------
  4319. Instead of computing text properties for all the text in the buffer,
  4320. you can arrange to compute the text properties for parts of the text
  4321. when and if something depends on them.
  4322. The primitive that extracts text from the buffer along with its
  4323. properties is `buffer-substring'. Before examining the properties,
  4324. this function runs the abnormal hook `buffer-access-fontify-functions'.
  4325. -- Variable: buffer-access-fontify-functions
  4326. This variable holds a list of functions for computing text
  4327. properties. Before `buffer-substring' copies the text and text
  4328. properties for a portion of the buffer, it calls all the functions
  4329. in this list. Each of the functions receives two arguments that
  4330. specify the range of the buffer being accessed. (The buffer
  4331. itself is always the current buffer.)
  4332. The function `buffer-substring-no-properties' does not call these
  4333. functions, since it ignores text properties anyway.
  4334. In order to prevent the hook functions from being called more than
  4335. once for the same part of the buffer, you can use the variable
  4336. `buffer-access-fontified-property'.
  4337. -- Variable: buffer-access-fontified-property
  4338. If this variable's value is non-`nil', it is a symbol which is used
  4339. as a text property name. A non-`nil' value for that text property
  4340. means, "the other text properties for this character have already
  4341. been computed".
  4342. If all the characters in the range specified for `buffer-substring'
  4343. have a non-`nil' value for this property, `buffer-substring' does
  4344. not call the `buffer-access-fontify-functions' functions. It
  4345. assumes these characters already have the right text properties,
  4346. and just copies the properties they already have.
  4347. The normal way to use this feature is that the
  4348. `buffer-access-fontify-functions' functions add this property, as
  4349. well as others, to the characters they operate on. That way, they
  4350. avoid being called over and over for the same text.
  4351. 
  4352. File: elisp, Node: Clickable Text, Next: Fields, Prev: Lazy Properties, Up: Text Properties
  4353. 32.19.8 Defining Clickable Text
  4354. -------------------------------
  4355. "Clickable text" is text that can be clicked, with either the mouse or
  4356. via a keyboard command, to produce some result. Many major modes use
  4357. clickable text to implement textual hyper-links, or "links" for short.
  4358. The easiest way to insert and manipulate links is to use the
  4359. `button' package. *Note Buttons::. In this section, we will explain
  4360. how to manually set up clickable text in a buffer, using text
  4361. properties. For simplicity, we will refer to the clickable text as a
  4362. "link".
  4363. Implementing a link involves three separate steps: (1) indicating
  4364. clickability when the mouse moves over the link; (2) making <RET> or
  4365. `Mouse-2' on that link do something; and (3) setting up a `follow-link'
  4366. condition so that the link obeys `mouse-1-click-follows-link'.
  4367. To indicate clickability, add the `mouse-face' text property to the
  4368. text of the link; then Emacs will highlight the link when the mouse
  4369. moves over it. In addition, you should define a tooltip or echo area
  4370. message, using the `help-echo' text property. *Note Special
  4371. Properties::. For instance, here is how Dired indicates that file
  4372. names are clickable:
  4373. (if (dired-move-to-filename)
  4374. (add-text-properties
  4375. (point)
  4376. (save-excursion
  4377. (dired-move-to-end-of-filename)
  4378. (point))
  4379. '(mouse-face highlight
  4380. help-echo "mouse-2: visit this file in other window")))
  4381. To make the link clickable, bind <RET> and `Mouse-2' to commands
  4382. that perform the desired action. Each command should check to see
  4383. whether it was called on a link, and act accordingly. For instance,
  4384. Dired's major mode keymap binds `Mouse-2' to the following command:
  4385. (defun dired-mouse-find-file-other-window (event)
  4386. "In Dired, visit the file or directory name you click on."
  4387. (interactive "e")
  4388. (let ((window (posn-window (event-end event)))
  4389. (pos (posn-point (event-end event)))
  4390. file)
  4391. (if (not (windowp window))
  4392. (error "No file chosen"))
  4393. (with-current-buffer (window-buffer window)
  4394. (goto-char pos)
  4395. (setq file (dired-get-file-for-visit)))
  4396. (if (file-directory-p file)
  4397. (or (and (cdr dired-subdir-alist)
  4398. (dired-goto-subdir file))
  4399. (progn
  4400. (select-window window)
  4401. (dired-other-window file)))
  4402. (select-window window)
  4403. (find-file-other-window (file-name-sans-versions file t)))))
  4404. This command uses the functions `posn-window' and `posn-point' to
  4405. determine where the click occurred, and `dired-get-file-for-visit' to
  4406. determine which file to visit.
  4407. Instead of binding the mouse command in a major mode keymap, you can
  4408. bind it within the link text, using the `keymap' text property (*note
  4409. Special Properties::). For instance:
  4410. (let ((map (make-sparse-keymap)))
  4411. (define-key map [mouse-2] 'operate-this-button)
  4412. (put-text-property link-start link-end 'keymap map))
  4413. With this method, you can easily define different commands for
  4414. different links. Furthermore, the global definition of <RET> and
  4415. `Mouse-2' remain available for the rest of the text in the buffer.
  4416. The basic Emacs command for clicking on links is `Mouse-2'.
  4417. However, for compatibility with other graphical applications, Emacs
  4418. also recognizes `Mouse-1' clicks on links, provided the user clicks on
  4419. the link quickly without moving the mouse. This behavior is controlled
  4420. by the user option `mouse-1-click-follows-link'. *Note Mouse
  4421. References: (emacs)Mouse References.
  4422. To set up the link so that it obeys `mouse-1-click-follows-link',
  4423. you must either (1) apply a `follow-link' text or overlay property to
  4424. the link text, or (2) bind the `follow-link' event to a keymap (which
  4425. can be a major mode keymap or a local keymap specified via the `keymap'
  4426. text property). The value of the `follow-link' property, or the
  4427. binding for the `follow-link' event, acts as a "condition" for the link
  4428. action. This condition tells Emacs two things: the circumstances under
  4429. which a `Mouse-1' click should be regarded as occurring "inside" the
  4430. link, and how to compute an "action code" that says what to translate
  4431. the `Mouse-1' click into. The link action condition can be one of the
  4432. following:
  4433. `mouse-face'
  4434. If the condition is the symbol `mouse-face', a position is inside
  4435. a link if there is a non-`nil' `mouse-face' property at that
  4436. position. The action code is always `t'.
  4437. For example, here is how Info mode handles <Mouse-1>:
  4438. (define-key Info-mode-map [follow-link] 'mouse-face)
  4439. a function
  4440. If the condition is a function, FUNC, then a position POS is
  4441. inside a link if `(FUNC POS)' evaluates to non-`nil'. The value
  4442. returned by FUNC serves as the action code.
  4443. For example, here is how pcvs enables `Mouse-1' to follow links on
  4444. file names only:
  4445. (define-key map [follow-link]
  4446. (lambda (pos)
  4447. (eq (get-char-property pos 'face) 'cvs-filename-face)))
  4448. anything else
  4449. If the condition value is anything else, then the position is
  4450. inside a link and the condition itself is the action code.
  4451. Clearly, you should specify this kind of condition only when
  4452. applying the condition via a text or property overlay on the link
  4453. text (so that it does not apply to the entire buffer).
  4454. The action code tells `Mouse-1' how to follow the link:
  4455. a string or vector
  4456. If the action code is a string or vector, the `Mouse-1' event is
  4457. translated into the first element of the string or vector; i.e.,
  4458. the action of the `Mouse-1' click is the local or global binding of
  4459. that character or symbol. Thus, if the action code is `"foo"',
  4460. `Mouse-1' translates into `f'. If it is `[foo]', `Mouse-1'
  4461. translates into <foo>.
  4462. anything else
  4463. For any other non-`nil' action code, the `Mouse-1' event is
  4464. translated into a `Mouse-2' event at the same position.
  4465. To define `Mouse-1' to activate a button defined with
  4466. `define-button-type', give the button a `follow-link' property. The
  4467. property value should be a link action condition, as described above.
  4468. *Note Buttons::. For example, here is how Help mode handles `Mouse-1':
  4469. (define-button-type 'help-xref
  4470. 'follow-link t
  4471. 'action #'help-button-action)
  4472. To define `Mouse-1' on a widget defined with `define-widget', give
  4473. the widget a `:follow-link' property. The property value should be a
  4474. link action condition, as described above. For example, here is how
  4475. the `link' widget specifies that a <Mouse-1> click shall be translated
  4476. to <RET>:
  4477. (define-widget 'link 'item
  4478. "An embedded link."
  4479. :button-prefix 'widget-link-prefix
  4480. :button-suffix 'widget-link-suffix
  4481. :follow-link "\C-m"
  4482. :help-echo "Follow the link."
  4483. :format "%[%t%]")
  4484. -- Function: mouse-on-link-p pos
  4485. This function returns non-`nil' if position POS in the current
  4486. buffer is on a link. POS can also be a mouse event location, as
  4487. returned by `event-start' (*note Accessing Mouse::).
  4488. 
  4489. File: elisp, Node: Fields, Next: Not Intervals, Prev: Clickable Text, Up: Text Properties
  4490. 32.19.9 Defining and Using Fields
  4491. ---------------------------------
  4492. A field is a range of consecutive characters in the buffer that are
  4493. identified by having the same value (comparing with `eq') of the
  4494. `field' property (either a text-property or an overlay property). This
  4495. section describes special functions that are available for operating on
  4496. fields.
  4497. You specify a field with a buffer position, POS. We think of each
  4498. field as containing a range of buffer positions, so the position you
  4499. specify stands for the field containing that position.
  4500. When the characters before and after POS are part of the same field,
  4501. there is no doubt which field contains POS: the one those characters
  4502. both belong to. When POS is at a boundary between fields, which field
  4503. it belongs to depends on the stickiness of the `field' properties of
  4504. the two surrounding characters (*note Sticky Properties::). The field
  4505. whose property would be inherited by text inserted at POS is the field
  4506. that contains POS.
  4507. There is an anomalous case where newly inserted text at POS would
  4508. not inherit the `field' property from either side. This happens if the
  4509. previous character's `field' property is not rear-sticky, and the
  4510. following character's `field' property is not front-sticky. In this
  4511. case, POS belongs to neither the preceding field nor the following
  4512. field; the field functions treat it as belonging to an empty field
  4513. whose beginning and end are both at POS.
  4514. In all of these functions, if POS is omitted or `nil', the value of
  4515. point is used by default. If narrowing is in effect, then POS should
  4516. fall within the accessible portion. *Note Narrowing::.
  4517. -- Function: field-beginning &optional pos escape-from-edge limit
  4518. This function returns the beginning of the field specified by POS.
  4519. If POS is at the beginning of its field, and ESCAPE-FROM-EDGE is
  4520. non-`nil', then the return value is always the beginning of the
  4521. preceding field that _ends_ at POS, regardless of the stickiness
  4522. of the `field' properties around POS.
  4523. If LIMIT is non-`nil', it is a buffer position; if the beginning
  4524. of the field is before LIMIT, then LIMIT will be returned instead.
  4525. -- Function: field-end &optional pos escape-from-edge limit
  4526. This function returns the end of the field specified by POS.
  4527. If POS is at the end of its field, and ESCAPE-FROM-EDGE is
  4528. non-`nil', then the return value is always the end of the following
  4529. field that _begins_ at POS, regardless of the stickiness of the
  4530. `field' properties around POS.
  4531. If LIMIT is non-`nil', it is a buffer position; if the end of the
  4532. field is after LIMIT, then LIMIT will be returned instead.
  4533. -- Function: field-string &optional pos
  4534. This function returns the contents of the field specified by POS,
  4535. as a string.
  4536. -- Function: field-string-no-properties &optional pos
  4537. This function returns the contents of the field specified by POS,
  4538. as a string, discarding text properties.
  4539. -- Function: delete-field &optional pos
  4540. This function deletes the text of the field specified by POS.
  4541. -- Function: constrain-to-field new-pos old-pos &optional
  4542. escape-from-edge only-in-line inhibit-capture-property
  4543. This function "constrains" NEW-POS to the field that OLD-POS
  4544. belongs to--in other words, it returns the position closest to
  4545. NEW-POS that is in the same field as OLD-POS.
  4546. If NEW-POS is `nil', then `constrain-to-field' uses the value of
  4547. point instead, and moves point to the resulting position in
  4548. addition to returning that position.
  4549. If OLD-POS is at the boundary of two fields, then the acceptable
  4550. final positions depend on the argument ESCAPE-FROM-EDGE. If
  4551. ESCAPE-FROM-EDGE is `nil', then NEW-POS must be in the field whose
  4552. `field' property equals what new characters inserted at OLD-POS
  4553. would inherit. (This depends on the stickiness of the `field'
  4554. property for the characters before and after OLD-POS.) If
  4555. ESCAPE-FROM-EDGE is non-`nil', NEW-POS can be anywhere in the two
  4556. adjacent fields. Additionally, if two fields are separated by
  4557. another field with the special value `boundary', then any point
  4558. within this special field is also considered to be "on the
  4559. boundary".
  4560. Commands like `C-a' with no argument, that normally move backward
  4561. to a specific kind of location and stay there once there, probably
  4562. should specify `nil' for ESCAPE-FROM-EDGE. Other motion commands
  4563. that check fields should probably pass `t'.
  4564. If the optional argument ONLY-IN-LINE is non-`nil', and
  4565. constraining NEW-POS in the usual way would move it to a different
  4566. line, NEW-POS is returned unconstrained. This used in commands
  4567. that move by line, such as `next-line' and `beginning-of-line', so
  4568. that they respect field boundaries only in the case where they can
  4569. still move to the right line.
  4570. If the optional argument INHIBIT-CAPTURE-PROPERTY is non-`nil',
  4571. and OLD-POS has a non-`nil' property of that name, then any field
  4572. boundaries are ignored.
  4573. You can cause `constrain-to-field' to ignore all field boundaries
  4574. (and so never constrain anything) by binding the variable
  4575. `inhibit-field-text-motion' to a non-`nil' value.
  4576. 
  4577. File: elisp, Node: Not Intervals, Prev: Fields, Up: Text Properties
  4578. 32.19.10 Why Text Properties are not Intervals
  4579. ----------------------------------------------
  4580. Some editors that support adding attributes to text in the buffer do so
  4581. by letting the user specify "intervals" within the text, and adding the
  4582. properties to the intervals. Those editors permit the user or the
  4583. programmer to determine where individual intervals start and end. We
  4584. deliberately provided a different sort of interface in Emacs Lisp to
  4585. avoid certain paradoxical behavior associated with text modification.
  4586. If the actual subdivision into intervals is meaningful, that means
  4587. you can distinguish between a buffer that is just one interval with a
  4588. certain property, and a buffer containing the same text subdivided into
  4589. two intervals, both of which have that property.
  4590. Suppose you take the buffer with just one interval and kill part of
  4591. the text. The text remaining in the buffer is one interval, and the
  4592. copy in the kill ring (and the undo list) becomes a separate interval.
  4593. Then if you yank back the killed text, you get two intervals with the
  4594. same properties. Thus, editing does not preserve the distinction
  4595. between one interval and two.
  4596. Suppose we "fix" this problem by coalescing the two intervals when
  4597. the text is inserted. That works fine if the buffer originally was a
  4598. single interval. But suppose instead that we have two adjacent
  4599. intervals with the same properties, and we kill the text of one interval
  4600. and yank it back. The same interval-coalescence feature that rescues
  4601. the other case causes trouble in this one: after yanking, we have just
  4602. one interval. One again, editing does not preserve the distinction
  4603. between one interval and two.
  4604. Insertion of text at the border between intervals also raises
  4605. questions that have no satisfactory answer.
  4606. However, it is easy to arrange for editing to behave consistently for
  4607. questions of the form, "What are the properties of this character?" So
  4608. we have decided these are the only questions that make sense; we have
  4609. not implemented asking questions about where intervals start or end.
  4610. In practice, you can usually use the text property search functions
  4611. in place of explicit interval boundaries. You can think of them as
  4612. finding the boundaries of intervals, assuming that intervals are always
  4613. coalesced whenever possible. *Note Property Search::.
  4614. Emacs also provides explicit intervals as a presentation feature; see
  4615. *note Overlays::.
  4616. 
  4617. File: elisp, Node: Substitution, Next: Transposition, Prev: Text Properties, Up: Text
  4618. 32.20 Substituting for a Character Code
  4619. =======================================
  4620. The following functions replace characters within a specified region
  4621. based on their character codes.
  4622. -- Function: subst-char-in-region start end old-char new-char
  4623. &optional noundo
  4624. This function replaces all occurrences of the character OLD-CHAR
  4625. with the character NEW-CHAR in the region of the current buffer
  4626. defined by START and END.
  4627. If NOUNDO is non-`nil', then `subst-char-in-region' does not
  4628. record the change for undo and does not mark the buffer as
  4629. modified. This was useful for controlling the old selective
  4630. display feature (*note Selective Display::).
  4631. `subst-char-in-region' does not move point and returns `nil'.
  4632. ---------- Buffer: foo ----------
  4633. This is the contents of the buffer before.
  4634. ---------- Buffer: foo ----------
  4635. (subst-char-in-region 1 20 ?i ?X)
  4636. => nil
  4637. ---------- Buffer: foo ----------
  4638. ThXs Xs the contents of the buffer before.
  4639. ---------- Buffer: foo ----------
  4640. -- Command: translate-region start end table
  4641. This function applies a translation table to the characters in the
  4642. buffer between positions START and END.
  4643. The translation table TABLE is a string or a char-table; `(aref
  4644. TABLE OCHAR)' gives the translated character corresponding to
  4645. OCHAR. If TABLE is a string, any characters with codes larger
  4646. than the length of TABLE are not altered by the translation.
  4647. The return value of `translate-region' is the number of characters
  4648. that were actually changed by the translation. This does not
  4649. count characters that were mapped into themselves in the
  4650. translation table.
  4651. 
  4652. File: elisp, Node: Registers, Next: Base 64, Prev: Transposition, Up: Text
  4653. 32.21 Registers
  4654. ===============
  4655. A register is a sort of variable used in Emacs editing that can hold a
  4656. variety of different kinds of values. Each register is named by a
  4657. single character. All ASCII characters and their meta variants (but
  4658. with the exception of `C-g') can be used to name registers. Thus,
  4659. there are 255 possible registers. A register is designated in Emacs
  4660. Lisp by the character that is its name.
  4661. -- Variable: register-alist
  4662. This variable is an alist of elements of the form `(NAME .
  4663. CONTENTS)'. Normally, there is one element for each Emacs
  4664. register that has been used.
  4665. The object NAME is a character (an integer) identifying the
  4666. register.
  4667. The CONTENTS of a register can have several possible types:
  4668. a number
  4669. A number stands for itself. If `insert-register' finds a number
  4670. in the register, it converts the number to decimal.
  4671. a marker
  4672. A marker represents a buffer position to jump to.
  4673. a string
  4674. A string is text saved in the register.
  4675. a rectangle
  4676. A rectangle is represented by a list of strings.
  4677. `(WINDOW-CONFIGURATION POSITION)'
  4678. This represents a window configuration to restore in one frame,
  4679. and a position to jump to in the current buffer.
  4680. `(FRAME-CONFIGURATION POSITION)'
  4681. This represents a frame configuration to restore, and a position
  4682. to jump to in the current buffer.
  4683. (file FILENAME)
  4684. This represents a file to visit; jumping to this value visits file
  4685. FILENAME.
  4686. (file-query FILENAME POSITION)
  4687. This represents a file to visit and a position in it; jumping to
  4688. this value visits file FILENAME and goes to buffer position
  4689. POSITION. Restoring this type of position asks the user for
  4690. confirmation first.
  4691. The functions in this section return unpredictable values unless
  4692. otherwise stated.
  4693. -- Function: get-register reg
  4694. This function returns the contents of the register REG, or `nil'
  4695. if it has no contents.
  4696. -- Function: set-register reg value
  4697. This function sets the contents of register REG to VALUE. A
  4698. register can be set to any value, but the other register functions
  4699. expect only certain data types. The return value is VALUE.
  4700. -- Command: view-register reg
  4701. This command displays what is contained in register REG.
  4702. -- Command: insert-register reg &optional beforep
  4703. This command inserts contents of register REG into the current
  4704. buffer.
  4705. Normally, this command puts point before the inserted text, and the
  4706. mark after it. However, if the optional second argument BEFOREP
  4707. is non-`nil', it puts the mark before and point after. You can
  4708. pass a non-`nil' second argument BEFOREP to this function
  4709. interactively by supplying any prefix argument.
  4710. If the register contains a rectangle, then the rectangle is
  4711. inserted with its upper left corner at point. This means that
  4712. text is inserted in the current line and underneath it on
  4713. successive lines.
  4714. If the register contains something other than saved text (a
  4715. string) or a rectangle (a list), currently useless things happen.
  4716. This may be changed in the future.
  4717. 
  4718. File: elisp, Node: Transposition, Next: Registers, Prev: Substitution, Up: Text
  4719. 32.22 Transposition of Text
  4720. ===========================
  4721. This function can be used to transpose stretches of text:
  4722. -- Function: transpose-regions start1 end1 start2 end2 &optional
  4723. leave-markers
  4724. This function exchanges two nonoverlapping portions of the buffer.
  4725. Arguments START1 and END1 specify the bounds of one portion and
  4726. arguments START2 and END2 specify the bounds of the other portion.
  4727. Normally, `transpose-regions' relocates markers with the transposed
  4728. text; a marker previously positioned within one of the two
  4729. transposed portions moves along with that portion, thus remaining
  4730. between the same two characters in their new position. However,
  4731. if LEAVE-MARKERS is non-`nil', `transpose-regions' does not do
  4732. this--it leaves all markers unrelocated.
  4733. 
  4734. File: elisp, Node: Base 64, Next: Checksum/Hash, Prev: Registers, Up: Text
  4735. 32.23 Base 64 Encoding
  4736. ======================
  4737. Base 64 code is used in email to encode a sequence of 8-bit bytes as a
  4738. longer sequence of ASCII graphic characters. It is defined in Internet
  4739. RFC(1)2045. This section describes the functions for converting to and
  4740. from this code.
  4741. -- Command: base64-encode-region beg end &optional no-line-break
  4742. This function converts the region from BEG to END into base 64
  4743. code. It returns the length of the encoded text. An error is
  4744. signaled if a character in the region is multibyte, i.e. in a
  4745. multibyte buffer the region must contain only characters from the
  4746. charsets `ascii', `eight-bit-control' and `eight-bit-graphic'.
  4747. Normally, this function inserts newline characters into the encoded
  4748. text, to avoid overlong lines. However, if the optional argument
  4749. NO-LINE-BREAK is non-`nil', these newlines are not added, so the
  4750. output is just one long line.
  4751. -- Function: base64-encode-string string &optional no-line-break
  4752. This function converts the string STRING into base 64 code. It
  4753. returns a string containing the encoded text. As for
  4754. `base64-encode-region', an error is signaled if a character in the
  4755. string is multibyte.
  4756. Normally, this function inserts newline characters into the encoded
  4757. text, to avoid overlong lines. However, if the optional argument
  4758. NO-LINE-BREAK is non-`nil', these newlines are not added, so the
  4759. result string is just one long line.
  4760. -- Command: base64-decode-region beg end
  4761. This function converts the region from BEG to END from base 64
  4762. code into the corresponding decoded text. It returns the length of
  4763. the decoded text.
  4764. The decoding functions ignore newline characters in the encoded
  4765. text.
  4766. -- Function: base64-decode-string string
  4767. This function converts the string STRING from base 64 code into
  4768. the corresponding decoded text. It returns a unibyte string
  4769. containing the decoded text.
  4770. The decoding functions ignore newline characters in the encoded
  4771. text.
  4772. ---------- Footnotes ----------
  4773. (1) An RFC, an acronym for "Request for Comments", is a numbered
  4774. Internet informational document describing a standard. RFCs are
  4775. usually written by technical experts acting on their own initiative,
  4776. and are traditionally written in a pragmatic, experience-driven manner.
  4777. 
  4778. File: elisp, Node: Checksum/Hash, Next: Parsing HTML/XML, Prev: Base 64, Up: Text
  4779. 32.24 Checksum/Hash
  4780. ===================
  4781. Emacs has built-in support for computing "cryptographic hashes". A
  4782. cryptographic hash, or "checksum", is a digital "fingerprint" of a
  4783. piece of data (e.g. a block of text) which can be used to check that
  4784. you have an unaltered copy of that data.
  4785. Emacs supports several common cryptographic hash algorithms: MD5,
  4786. SHA-1, SHA-2, SHA-224, SHA-256, SHA-384 and SHA-512. MD5 is the oldest
  4787. of these algorithms, and is commonly used in "message digests" to check
  4788. the integrity of messages transmitted over a network. MD5 is not
  4789. "collision resistant" (i.e. it is possible to deliberately design
  4790. different pieces of data which have the same MD5 hash), so you should
  4791. not used it for anything security-related. A similar theoretical
  4792. weakness also exists in SHA-1. Therefore, for security-related
  4793. applications you should use the other hash types, such as SHA-2.
  4794. -- Function: secure-hash algorithm object &optional start end binary
  4795. This function returns a hash for OBJECT. The argument ALGORITHM
  4796. is a symbol stating which hash to compute: one of `md5', `sha1',
  4797. `sha224', `sha256', `sha384' or `sha512'. The argument OBJECT
  4798. should be a buffer or a string.
  4799. The optional arguments START and END are character positions
  4800. specifying the portion of OBJECT to compute the message digest
  4801. for. If they are `nil' or omitted, the hash is computed for the
  4802. whole of OBJECT.
  4803. If the argument BINARY is omitted or `nil', the function returns
  4804. the "text form" of the hash, as an ordinary Lisp string. If
  4805. BINARY is non-`nil', it returns the hash in "binary form", as a
  4806. sequence of bytes stored in a unibyte string.
  4807. This function does not compute the hash directly from the internal
  4808. representation of OBJECT's text (*note Text Representations::).
  4809. Instead, it encodes the text using a coding system (*note Coding
  4810. Systems::), and computes the hash from that encoded text. If
  4811. OBJECT is a buffer, the coding system used is the one which would
  4812. be chosen by default for writing the text into a file. If OBJECT
  4813. is a string, the user's preferred coding system is used (*note
  4814. Recognize Coding: (emacs)Recognize Coding.).
  4815. -- Function: md5 object &optional start end coding-system noerror
  4816. This function returns an MD5 hash. It is semi-obsolete, since for
  4817. most purposes it is equivalent to calling `secure-hash' with `md5'
  4818. as the ALGORITHM argument. The OBJECT, START and END arguments
  4819. have the same meanings as in `secure-hash'.
  4820. If CODING-SYSTEM is non-`nil', it specifies a coding system to use
  4821. to encode the text; if omitted or `nil', the default coding system
  4822. is used, like in `secure-hash'.
  4823. Normally, `md5' signals an error if the text can't be encoded
  4824. using the specified or chosen coding system. However, if NOERROR
  4825. is non-`nil', it silently uses `raw-text' coding instead.
  4826. 
  4827. File: elisp, Node: Parsing HTML/XML, Next: Atomic Changes, Prev: Checksum/Hash, Up: Text
  4828. 32.25 Parsing HTML and XML
  4829. ==========================
  4830. When Emacs is compiled with libxml2 support, the following functions
  4831. are available to parse HTML or XML text into Lisp object trees.
  4832. -- Function: libxml-parse-html-region start end &optional base-url
  4833. This function parses the text between START and END as HTML, and
  4834. returns a list representing the HTML "parse tree". It attempts to
  4835. handle "real world" HTML by robustly coping with syntax mistakes.
  4836. The optional argument BASE-URL, if non-`nil', should be a string
  4837. specifying the base URL for relative URLs occurring in links.
  4838. In the parse tree, each HTML node is represented by a list in which
  4839. the first element is a symbol representing the node name, the
  4840. second element is an alist of node attributes, and the remaining
  4841. elements are the subnodes.
  4842. The following example demonstrates this. Given this (malformed)
  4843. HTML document:
  4844. <html><head></head><body width=101><div class=thing>Foo<div>Yes
  4845. A call to `libxml-parse-html-region' returns this:
  4846. (html ()
  4847. (head ())
  4848. (body ((width . "101"))
  4849. (div ((class . "thing"))
  4850. "Foo"
  4851. (div ()
  4852. "Yes"))))
  4853. -- Function: libxml-parse-xml-region start end &optional base-url
  4854. This function is the same as `libxml-parse-html-region', except
  4855. that it parses the text as XML rather than HTML (so it is stricter
  4856. about syntax).
  4857. 
  4858. File: elisp, Node: Atomic Changes, Next: Change Hooks, Prev: Parsing HTML/XML, Up: Text
  4859. 32.26 Atomic Change Groups
  4860. ==========================
  4861. In database terminology, an "atomic" change is an indivisible
  4862. change--it can succeed entirely or it can fail entirely, but it cannot
  4863. partly succeed. A Lisp program can make a series of changes to one or
  4864. several buffers as an "atomic change group", meaning that either the
  4865. entire series of changes will be installed in their buffers or, in case
  4866. of an error, none of them will be.
  4867. To do this for one buffer, the one already current, simply write a
  4868. call to `atomic-change-group' around the code that makes the changes,
  4869. like this:
  4870. (atomic-change-group
  4871. (insert foo)
  4872. (delete-region x y))
  4873. If an error (or other nonlocal exit) occurs inside the body of
  4874. `atomic-change-group', it unmakes all the changes in that buffer that
  4875. were during the execution of the body. This kind of change group has
  4876. no effect on any other buffers--any such changes remain.
  4877. If you need something more sophisticated, such as to make changes in
  4878. various buffers constitute one atomic group, you must directly call
  4879. lower-level functions that `atomic-change-group' uses.
  4880. -- Function: prepare-change-group &optional buffer
  4881. This function sets up a change group for buffer BUFFER, which
  4882. defaults to the current buffer. It returns a "handle" that
  4883. represents the change group. You must use this handle to activate
  4884. the change group and subsequently to finish it.
  4885. To use the change group, you must "activate" it. You must do this
  4886. before making any changes in the text of BUFFER.
  4887. -- Function: activate-change-group handle
  4888. This function activates the change group that HANDLE designates.
  4889. After you activate the change group, any changes you make in that
  4890. buffer become part of it. Once you have made all the desired changes
  4891. in the buffer, you must "finish" the change group. There are two ways
  4892. to do this: you can either accept (and finalize) all the changes, or
  4893. cancel them all.
  4894. -- Function: accept-change-group handle
  4895. This function accepts all the changes in the change group
  4896. specified by HANDLE, making them final.
  4897. -- Function: cancel-change-group handle
  4898. This function cancels and undoes all the changes in the change
  4899. group specified by HANDLE.
  4900. Your code should use `unwind-protect' to make sure the group is
  4901. always finished. The call to `activate-change-group' should be inside
  4902. the `unwind-protect', in case the user types `C-g' just after it runs.
  4903. (This is one reason why `prepare-change-group' and
  4904. `activate-change-group' are separate functions, because normally you
  4905. would call `prepare-change-group' before the start of that
  4906. `unwind-protect'.) Once you finish the group, don't use the handle
  4907. again--in particular, don't try to finish the same group twice.
  4908. To make a multibuffer change group, call `prepare-change-group' once
  4909. for each buffer you want to cover, then use `nconc' to combine the
  4910. returned values, like this:
  4911. (nconc (prepare-change-group buffer-1)
  4912. (prepare-change-group buffer-2))
  4913. You can then activate the multibuffer change group with a single call
  4914. to `activate-change-group', and finish it with a single call to
  4915. `accept-change-group' or `cancel-change-group'.
  4916. Nested use of several change groups for the same buffer works as you
  4917. would expect. Non-nested use of change groups for the same buffer will
  4918. get Emacs confused, so don't let it happen; the first change group you
  4919. start for any given buffer should be the last one finished.
  4920. 
  4921. File: elisp, Node: Change Hooks, Prev: Atomic Changes, Up: Text
  4922. 32.27 Change Hooks
  4923. ==================
  4924. These hook variables let you arrange to take notice of all changes in
  4925. all buffers (or in a particular buffer, if you make them buffer-local).
  4926. See also *note Special Properties::, for how to detect changes to
  4927. specific parts of the text.
  4928. The functions you use in these hooks should save and restore the
  4929. match data if they do anything that uses regular expressions;
  4930. otherwise, they will interfere in bizarre ways with the editing
  4931. operations that call them.
  4932. -- Variable: before-change-functions
  4933. This variable holds a list of functions to call before any buffer
  4934. modification. Each function gets two arguments, the beginning and
  4935. end of the region that is about to change, represented as
  4936. integers. The buffer that is about to change is always the
  4937. current buffer.
  4938. -- Variable: after-change-functions
  4939. This variable holds a list of functions to call after any buffer
  4940. modification. Each function receives three arguments: the
  4941. beginning and end of the region just changed, and the length of
  4942. the text that existed before the change. All three arguments are
  4943. integers. The buffer has been changed is always the current
  4944. buffer.
  4945. The length of the old text is the difference between the buffer
  4946. positions before and after that text as it was before the change.
  4947. As for the changed text, its length is simply the difference
  4948. between the first two arguments.
  4949. Output of messages into the `*Messages*' buffer does not call these
  4950. functions.
  4951. -- Macro: combine-after-change-calls body...
  4952. The macro executes BODY normally, but arranges to call the
  4953. after-change functions just once for a series of several
  4954. changes--if that seems safe.
  4955. If a program makes several text changes in the same area of the
  4956. buffer, using the macro `combine-after-change-calls' around that
  4957. part of the program can make it run considerably faster when
  4958. after-change hooks are in use. When the after-change hooks are
  4959. ultimately called, the arguments specify a portion of the buffer
  4960. including all of the changes made within the
  4961. `combine-after-change-calls' body.
  4962. *Warning:* You must not alter the values of
  4963. `after-change-functions' within the body of a
  4964. `combine-after-change-calls' form.
  4965. *Warning:* if the changes you combine occur in widely scattered
  4966. parts of the buffer, this will still work, but it is not advisable,
  4967. because it may lead to inefficient behavior for some change hook
  4968. functions.
  4969. -- Variable: first-change-hook
  4970. This variable is a normal hook that is run whenever a buffer is
  4971. changed that was previously in the unmodified state.
  4972. -- Variable: inhibit-modification-hooks
  4973. If this variable is non-`nil', all of the change hooks are
  4974. disabled; none of them run. This affects all the hook variables
  4975. described above in this section, as well as the hooks attached to
  4976. certain special text properties (*note Special Properties::) and
  4977. overlay properties (*note Overlay Properties::).
  4978. Also, this variable is bound to non-`nil' while running those same
  4979. hook variables, so that by default modifying the buffer from a
  4980. modification hook does not cause other modification hooks to be
  4981. run. If you do want modification hooks to be run in a particular
  4982. piece of code that is itself run from a modification hook, then
  4983. rebind locally `inhibit-modification-hooks' to `nil'.
  4984. 
  4985. File: elisp, Node: Non-ASCII Characters, Next: Searching and Matching, Prev: Text, Up: Top
  4986. 33 Non-ASCII Characters
  4987. ***********************
  4988. This chapter covers the special issues relating to characters and how
  4989. they are stored in strings and buffers.
  4990. * Menu:
  4991. * Text Representations:: How Emacs represents text.
  4992. * Converting Representations:: Converting unibyte to multibyte and vice versa.
  4993. * Selecting a Representation:: Treating a byte sequence as unibyte or multi.
  4994. * Character Codes:: How unibyte and multibyte relate to
  4995. codes of individual characters.
  4996. * Character Properties:: Character attributes that define their
  4997. behavior and handling.
  4998. * Character Sets:: The space of possible character codes
  4999. is divided into various character sets.
  5000. * Scanning Charsets:: Which character sets are used in a buffer?
  5001. * Translation of Characters:: Translation tables are used for conversion.
  5002. * Coding Systems:: Coding systems are conversions for saving files.
  5003. * Input Methods:: Input methods allow users to enter various
  5004. non-ASCII characters without special keyboards.
  5005. * Locales:: Interacting with the POSIX locale.
  5006. 
  5007. File: elisp, Node: Text Representations, Next: Converting Representations, Up: Non-ASCII Characters
  5008. 33.1 Text Representations
  5009. =========================
  5010. Emacs buffers and strings support a large repertoire of characters from
  5011. many different scripts, allowing users to type and display text in
  5012. almost any known written language.
  5013. To support this multitude of characters and scripts, Emacs closely
  5014. follows the "Unicode Standard". The Unicode Standard assigns a unique
  5015. number, called a "codepoint", to each and every character. The range
  5016. of codepoints defined by Unicode, or the Unicode "codespace", is
  5017. `0..#x10FFFF' (in hexadecimal notation), inclusive. Emacs extends this
  5018. range with codepoints in the range `#x110000..#x3FFFFF', which it uses
  5019. for representing characters that are not unified with Unicode and "raw
  5020. 8-bit bytes" that cannot be interpreted as characters. Thus, a
  5021. character codepoint in Emacs is a 22-bit integer number.
  5022. To conserve memory, Emacs does not hold fixed-length 22-bit numbers
  5023. that are codepoints of text characters within buffers and strings.
  5024. Rather, Emacs uses a variable-length internal representation of
  5025. characters, that stores each character as a sequence of 1 to 5 8-bit
  5026. bytes, depending on the magnitude of its codepoint(1). For example,
  5027. any ASCII character takes up only 1 byte, a Latin-1 character takes up
  5028. 2 bytes, etc. We call this representation of text "multibyte".
  5029. Outside Emacs, characters can be represented in many different
  5030. encodings, such as ISO-8859-1, GB-2312, Big-5, etc. Emacs converts
  5031. between these external encodings and its internal representation, as
  5032. appropriate, when it reads text into a buffer or a string, or when it
  5033. writes text to a disk file or passes it to some other process.
  5034. Occasionally, Emacs needs to hold and manipulate encoded text or
  5035. binary non-text data in its buffers or strings. For example, when
  5036. Emacs visits a file, it first reads the file's text verbatim into a
  5037. buffer, and only then converts it to the internal representation.
  5038. Before the conversion, the buffer holds encoded text.
  5039. Encoded text is not really text, as far as Emacs is concerned, but
  5040. rather a sequence of raw 8-bit bytes. We call buffers and strings that
  5041. hold encoded text "unibyte" buffers and strings, because Emacs treats
  5042. them as a sequence of individual bytes. Usually, Emacs displays
  5043. unibyte buffers and strings as octal codes such as `\237'. We
  5044. recommend that you never use unibyte buffers and strings except for
  5045. manipulating encoded text or binary non-text data.
  5046. In a buffer, the buffer-local value of the variable
  5047. `enable-multibyte-characters' specifies the representation used. The
  5048. representation for a string is determined and recorded in the string
  5049. when the string is constructed.
  5050. -- Variable: enable-multibyte-characters
  5051. This variable specifies the current buffer's text representation.
  5052. If it is non-`nil', the buffer contains multibyte text; otherwise,
  5053. it contains unibyte encoded text or binary non-text data.
  5054. You cannot set this variable directly; instead, use the function
  5055. `set-buffer-multibyte' to change a buffer's representation.
  5056. -- Function: position-bytes position
  5057. Buffer positions are measured in character units. This function
  5058. returns the byte-position corresponding to buffer position
  5059. POSITION in the current buffer. This is 1 at the start of the
  5060. buffer, and counts upward in bytes. If POSITION is out of range,
  5061. the value is `nil'.
  5062. -- Function: byte-to-position byte-position
  5063. Return the buffer position, in character units, corresponding to
  5064. given BYTE-POSITION in the current buffer. If BYTE-POSITION is
  5065. out of range, the value is `nil'. In a multibyte buffer, an
  5066. arbitrary value of BYTE-POSITION can be not at character boundary,
  5067. but inside a multibyte sequence representing a single character;
  5068. in this case, this function returns the buffer position of the
  5069. character whose multibyte sequence includes BYTE-POSITION. In
  5070. other words, the value does not change for all byte positions that
  5071. belong to the same character.
  5072. -- Function: multibyte-string-p string
  5073. Return `t' if STRING is a multibyte string, `nil' otherwise.
  5074. -- Function: string-bytes string
  5075. This function returns the number of bytes in STRING. If STRING is
  5076. a multibyte string, this can be greater than `(length STRING)'.
  5077. -- Function: unibyte-string &rest bytes
  5078. This function concatenates all its argument BYTES and makes the
  5079. result a unibyte string.
  5080. ---------- Footnotes ----------
  5081. (1) This internal representation is based on one of the encodings
  5082. defined by the Unicode Standard, called "UTF-8", for representing any
  5083. Unicode codepoint, but Emacs extends UTF-8 to represent the additional
  5084. codepoints it uses for raw 8-bit bytes and characters not unified with
  5085. Unicode.
  5086. 
  5087. File: elisp, Node: Converting Representations, Next: Selecting a Representation, Prev: Text Representations, Up: Non-ASCII Characters
  5088. 33.2 Converting Text Representations
  5089. ====================================
  5090. Emacs can convert unibyte text to multibyte; it can also convert
  5091. multibyte text to unibyte, provided that the multibyte text contains
  5092. only ASCII and 8-bit raw bytes. In general, these conversions happen
  5093. when inserting text into a buffer, or when putting text from several
  5094. strings together in one string. You can also explicitly convert a
  5095. string's contents to either representation.
  5096. Emacs chooses the representation for a string based on the text from
  5097. which it is constructed. The general rule is to convert unibyte text
  5098. to multibyte text when combining it with other multibyte text, because
  5099. the multibyte representation is more general and can hold whatever
  5100. characters the unibyte text has.
  5101. When inserting text into a buffer, Emacs converts the text to the
  5102. buffer's representation, as specified by `enable-multibyte-characters'
  5103. in that buffer. In particular, when you insert multibyte text into a
  5104. unibyte buffer, Emacs converts the text to unibyte, even though this
  5105. conversion cannot in general preserve all the characters that might be
  5106. in the multibyte text. The other natural alternative, to convert the
  5107. buffer contents to multibyte, is not acceptable because the buffer's
  5108. representation is a choice made by the user that cannot be overridden
  5109. automatically.
  5110. Converting unibyte text to multibyte text leaves ASCII characters
  5111. unchanged, and converts bytes with codes 128 through 255 to the
  5112. multibyte representation of raw eight-bit bytes.
  5113. Converting multibyte text to unibyte converts all ASCII and
  5114. eight-bit characters to their single-byte form, but loses information
  5115. for non-ASCII characters by discarding all but the low 8 bits of each
  5116. character's codepoint. Converting unibyte text to multibyte and back
  5117. to unibyte reproduces the original unibyte text.
  5118. The next two functions either return the argument STRING, or a newly
  5119. created string with no text properties.
  5120. -- Function: string-to-multibyte string
  5121. This function returns a multibyte string containing the same
  5122. sequence of characters as STRING. If STRING is a multibyte string,
  5123. it is returned unchanged. The function assumes that STRING
  5124. includes only ASCII characters and raw 8-bit bytes; the latter are
  5125. converted to their multibyte representation corresponding to the
  5126. codepoints `#x3FFF80' through `#x3FFFFF', inclusive (*note
  5127. codepoints: Text Representations.).
  5128. -- Function: string-to-unibyte string
  5129. This function returns a unibyte string containing the same
  5130. sequence of characters as STRING. It signals an error if STRING
  5131. contains a non-ASCII character. If STRING is a unibyte string, it
  5132. is returned unchanged. Use this function for STRING arguments
  5133. that contain only ASCII and eight-bit characters.
  5134. -- Function: byte-to-string byte
  5135. This function returns a unibyte string containing a single byte of
  5136. character data, CHARACTER. It signals an error if CHARACTER is
  5137. not an integer between 0 and 255.
  5138. -- Function: multibyte-char-to-unibyte char
  5139. This converts the multibyte character CHAR to a unibyte character,
  5140. and returns that character. If CHAR is neither ASCII nor
  5141. eight-bit, the function returns -1.
  5142. -- Function: unibyte-char-to-multibyte char
  5143. This convert the unibyte character CHAR to a multibyte character,
  5144. assuming CHAR is either ASCII or raw 8-bit byte.
  5145. 
  5146. File: elisp, Node: Selecting a Representation, Next: Character Codes, Prev: Converting Representations, Up: Non-ASCII Characters
  5147. 33.3 Selecting a Representation
  5148. ===============================
  5149. Sometimes it is useful to examine an existing buffer or string as
  5150. multibyte when it was unibyte, or vice versa.
  5151. -- Function: set-buffer-multibyte multibyte
  5152. Set the representation type of the current buffer. If MULTIBYTE
  5153. is non-`nil', the buffer becomes multibyte. If MULTIBYTE is
  5154. `nil', the buffer becomes unibyte.
  5155. This function leaves the buffer contents unchanged when viewed as a
  5156. sequence of bytes. As a consequence, it can change the contents
  5157. viewed as characters; for instance, a sequence of three bytes
  5158. which is treated as one character in multibyte representation will
  5159. count as three characters in unibyte representation. Eight-bit
  5160. characters representing raw bytes are an exception. They are
  5161. represented by one byte in a unibyte buffer, but when the buffer
  5162. is set to multibyte, they are converted to two-byte sequences, and
  5163. vice versa.
  5164. This function sets `enable-multibyte-characters' to record which
  5165. representation is in use. It also adjusts various data in the
  5166. buffer (including overlays, text properties and markers) so that
  5167. they cover the same text as they did before.
  5168. You cannot use `set-buffer-multibyte' on an indirect buffer,
  5169. because indirect buffers always inherit the representation of the
  5170. base buffer.
  5171. -- Function: string-as-unibyte string
  5172. If STRING is already a unibyte string, this function returns
  5173. STRING itself. Otherwise, it returns a new string with the same
  5174. bytes as STRING, but treating each byte as a separate character
  5175. (so that the value may have more characters than STRING); as an
  5176. exception, each eight-bit character representing a raw byte is
  5177. converted into a single byte. The newly-created string contains no
  5178. text properties.
  5179. -- Function: string-as-multibyte string
  5180. If STRING is a multibyte string, this function returns STRING
  5181. itself. Otherwise, it returns a new string with the same bytes as
  5182. STRING, but treating each multibyte sequence as one character.
  5183. This means that the value may have fewer characters than STRING
  5184. has. If a byte sequence in STRING is invalid as a multibyte
  5185. representation of a single character, each byte in the sequence is
  5186. treated as a raw 8-bit byte. The newly-created string contains no
  5187. text properties.
  5188. 
  5189. File: elisp, Node: Character Codes, Next: Character Properties, Prev: Selecting a Representation, Up: Non-ASCII Characters
  5190. 33.4 Character Codes
  5191. ====================
  5192. The unibyte and multibyte text representations use different character
  5193. codes. The valid character codes for unibyte representation range from
  5194. 0 to `#xFF' (255)--the values that can fit in one byte. The valid
  5195. character codes for multibyte representation range from 0 to
  5196. `#x3FFFFF'. In this code space, values 0 through `#x7F' (127) are for
  5197. ASCII characters, and values `#x80' (128) through `#x3FFF7F' (4194175)
  5198. are for non-ASCII characters.
  5199. Emacs character codes are a superset of the Unicode standard.
  5200. Values 0 through `#x10FFFF' (1114111) correspond to Unicode characters
  5201. of the same codepoint; values `#x110000' (1114112) through `#x3FFF7F'
  5202. (4194175) represent characters that are not unified with Unicode; and
  5203. values `#x3FFF80' (4194176) through `#x3FFFFF' (4194303) represent
  5204. eight-bit raw bytes.
  5205. -- Function: characterp charcode
  5206. This returns `t' if CHARCODE is a valid character, and `nil'
  5207. otherwise.
  5208. (characterp 65)
  5209. => t
  5210. (characterp 4194303)
  5211. => t
  5212. (characterp 4194304)
  5213. => nil
  5214. -- Function: max-char
  5215. This function returns the largest value that a valid character
  5216. codepoint can have.
  5217. (characterp (max-char))
  5218. => t
  5219. (characterp (1+ (max-char)))
  5220. => nil
  5221. -- Function: get-byte &optional pos string
  5222. This function returns the byte at character position POS in the
  5223. current buffer. If the current buffer is unibyte, this is
  5224. literally the byte at that position. If the buffer is multibyte,
  5225. byte values of ASCII characters are the same as character
  5226. codepoints, whereas eight-bit raw bytes are converted to their
  5227. 8-bit codes. The function signals an error if the character at
  5228. POS is non-ASCII.
  5229. The optional argument STRING means to get a byte value from that
  5230. string instead of the current buffer.
  5231. 
  5232. Local Variables:
  5233. coding: iso-8859-1
  5234. End: