allout.el 281 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922
  1. ;;; allout.el --- extensive outline mode for use alone and with other modes
  2. ;; Copyright (C) 1992-1994, 2001-2012 Free Software Foundation, Inc.
  3. ;; Author: Ken Manheimer <ken dot manheimer at gmail...>
  4. ;; Maintainer: Ken Manheimer <ken dot manheimer at gmail...>
  5. ;; Created: Dec 1991 -- first release to usenet
  6. ;; Version: 2.3
  7. ;; Keywords: outlines, wp, languages, PGP, GnuPG
  8. ;; Website: http://myriadicity.net/software-and-systems/craft/emacs-allout
  9. ;; This file is part of GNU Emacs.
  10. ;; GNU Emacs is free software: you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation, either version 3 of the License, or
  13. ;; (at your option) any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  20. ;;; Commentary:
  21. ;; Allout outline minor mode provides extensive outline formatting and
  22. ;; and manipulation beyond standard emacs outline mode. Some features:
  23. ;;
  24. ;; - Classic outline-mode topic-oriented navigation and exposure adjustment
  25. ;; - Topic-oriented editing including coherent topic and subtopic
  26. ;; creation, promotion, demotion, cut/paste across depths, etc.
  27. ;; - Incremental search with dynamic exposure and reconcealment of text
  28. ;; - Customizable bullet format -- enables programming-language specific
  29. ;; outlining, for code-folding editing. (Allout code itself is to try it;
  30. ;; formatted as an outline -- do ESC-x eval-buffer in allout.el; but
  31. ;; emacs local file variables need to be enabled when the
  32. ;; file was visited -- see `enable-local-variables'.)
  33. ;; - Configurable per-file initial exposure settings
  34. ;; - Symmetric-key and key-pair topic encryption. Encryption is via the
  35. ;; Emacs 'epg' library. See allout-toggle-current-subtree-encryption
  36. ;; docstring.
  37. ;; - Automatic topic-number maintenance
  38. ;; - "Hot-spot" operation, for single-keystroke maneuvering and
  39. ;; exposure control (see the allout-mode docstring)
  40. ;; - Easy rendering of exposed portions into numbered, latex, indented, etc
  41. ;; outline styles
  42. ;; - Careful attention to whitespace -- enabling blank lines between items
  43. ;; and maintenance of hanging indentation (in paragraph auto-fill and
  44. ;; across topic promotion and demotion) of topic bodies consistent with
  45. ;; indentation of their topic header.
  46. ;;
  47. ;; and more.
  48. ;;
  49. ;; See the `allout-mode' function's docstring for an introduction to the
  50. ;; mode.
  51. ;;
  52. ;; Directions to the latest development version and helpful notes are
  53. ;; available at http://myriadicity.net/Sundry/EmacsAllout .
  54. ;;
  55. ;; The outline menubar additions provide quick reference to many of the
  56. ;; features. See the docstring of the variables `allout-layout' and
  57. ;; `allout-auto-activation' for details on automatic activation of
  58. ;; `allout-mode' as a minor mode. (`allout-init' is deprecated in favor of
  59. ;; a purely customization-based method.)
  60. ;;
  61. ;; Note -- the lines beginning with `;;;_' are outline topic headers.
  62. ;; Customize `allout-auto-activation' to enable, then revisit this
  63. ;; buffer to give it a whirl.
  64. ;; ken manheimer (ken dot manheimer at gmail dot com)
  65. ;;; Code:
  66. ;;;_* Dependency loads
  67. (require 'overlay)
  68. (eval-when-compile
  69. ;; Most of the requires here are for stuff covered by autoloads, which
  70. ;; byte-compiling doesn't trigger.
  71. (require 'epg)
  72. (require 'epa)
  73. (require 'overlay)
  74. ;; `cl' is required for `assert'. `assert' is not covered by a standard
  75. ;; autoload, but it is a macro, so that eval-when-compile is sufficient
  76. ;; to byte-compile it in, or to do the require when the buffer evalled.
  77. (require 'cl)
  78. )
  79. ;;;_* USER CUSTOMIZATION VARIABLES:
  80. ;;;_ > defgroup allout, allout-keybindings
  81. (defgroup allout nil
  82. "Extensive outline minor-mode, for use stand-alone and with other modes.
  83. See Allout Auto Activation for automatic activation."
  84. :prefix "allout-"
  85. :group 'outlines)
  86. (defgroup allout-keybindings nil
  87. "Allout outline mode keyboard bindings configuration."
  88. :group 'allout)
  89. ;;;_ + Layout, Mode, and Topic Header Configuration
  90. (defvar allout-command-prefix) ; defined below
  91. ;;;_ > allout-keybindings incidentals:
  92. ;;;_ : internal key binding stuff - in this section for load-order.
  93. ;;;_ = allout-mode-map
  94. (defvar allout-mode-map 'allout-mode-map
  95. "Keybindings place-holder for (allout) outline minor mode.
  96. Do NOT set the value of this variable. Instead, customize
  97. `allout-command-prefix', `allout-prefixed-keybindings', and
  98. `allout-unprefixed-keybindings'.")
  99. ;;;_ = allout-mode-map-value
  100. (defvar allout-mode-map-value nil
  101. "Keymap for allout outline minor mode.
  102. Do NOT set the value of this variable. Instead, customize
  103. `allout-command-prefix', `allout-prefixed-keybindings', and
  104. `allout-unprefixed-keybindings'.")
  105. ;;;_ = make allout-mode-map-value an alias for allout-mode-map:
  106. ;; this needs to be revised when the value is changed, sigh.
  107. (defalias 'allout-mode-map allout-mode-map-value)
  108. ;;;_ > allout-compose-and-institute-keymap (&optional varname value)
  109. (defun allout-compose-and-institute-keymap (&optional varname value)
  110. "Create the allout keymap according to the keybinding specs, and set it.
  111. Useful standalone or to effect customizations of the
  112. respective allout-mode keybinding variables, `allout-command-prefix',
  113. `allout-prefixed-keybindings', and `allout-unprefixed-keybindings'"
  114. ;; Set the customization variable, if any:
  115. (when varname
  116. (set-default varname value))
  117. (let ((map (make-sparse-keymap)))
  118. (when (boundp 'allout-prefixed-keybindings)
  119. ;; tolerate first definitions of the variables:
  120. (dolist (entry allout-prefixed-keybindings)
  121. (define-key map
  122. ;; XXX vector vs non-vector key descriptions?
  123. (vconcat allout-command-prefix
  124. (car (read-from-string (car entry))))
  125. (cadr entry))))
  126. (when (boundp 'allout-unprefixed-keybindings)
  127. (dolist (entry allout-unprefixed-keybindings)
  128. (define-key map (car (read-from-string (car entry))) (cadr entry))))
  129. (substitute-key-definition 'beginning-of-line 'allout-beginning-of-line
  130. map global-map)
  131. (substitute-key-definition 'move-beginning-of-line 'allout-beginning-of-line
  132. map global-map)
  133. (substitute-key-definition 'end-of-line 'allout-end-of-line
  134. map global-map)
  135. (substitute-key-definition 'move-end-of-line 'allout-end-of-line
  136. map global-map)
  137. (allout-institute-keymap map)))
  138. ;;;_ > allout-institute-keymap (map)
  139. (defun allout-institute-keymap (map)
  140. "Associate allout-mode bindings with allout as a minor mode."
  141. ;; Architecture:
  142. ;; allout-mode-map var is a keymap by virtue of being a defalias for
  143. ;; allout-mode-map-value, which has the actual keymap value.
  144. ;; allout-mode-map's symbol value is just 'allout-mode-map, so it can be
  145. ;; used in minor-mode-map-alist to indirect to the actual
  146. ;; allout-mode-map-var value, which can be adjusted and reassigned.
  147. ;; allout-mode-map-value for keymap reference in various places:
  148. (setq allout-mode-map-value map)
  149. ;; the function value keymap of allout-mode-map is used in
  150. ;; minor-mode-map-alist - update it:
  151. (fset allout-mode-map allout-mode-map-value))
  152. ;;;_ * initialize the mode map:
  153. ;; ensure that allout-mode-map has some setting even if allout-mode hasn't
  154. ;; been invoked:
  155. (allout-compose-and-institute-keymap)
  156. ;;;_ = allout-command-prefix
  157. (defcustom allout-command-prefix "\C-c "
  158. "Key sequence to be used as prefix for outline mode command key bindings.
  159. Default is '\C-c<space>'; just '\C-c' is more short-and-sweet, if you're
  160. willing to let allout use a bunch of \C-c keybindings."
  161. :type 'string
  162. :group 'allout-keybindings
  163. :set 'allout-compose-and-institute-keymap)
  164. ;;;_ = allout-keybindings-binding
  165. (define-widget 'allout-keybindings-binding 'lazy
  166. "Structure of allout keybindings customization items."
  167. :type '(repeat
  168. (list (string :tag "Key" :value "[(meta control shift ?f)]")
  169. (function :tag "Function name"
  170. :value allout-forward-current-level))))
  171. ;;;_ = allout-prefixed-keybindings
  172. (defcustom allout-prefixed-keybindings
  173. '(("[(control ?n)]" allout-next-visible-heading)
  174. ("[(control ?p)]" allout-previous-visible-heading)
  175. ("[(control ?u)]" allout-up-current-level)
  176. ("[(control ?f)]" allout-forward-current-level)
  177. ("[(control ?b)]" allout-backward-current-level)
  178. ("[(control ?a)]" allout-beginning-of-current-entry)
  179. ("[(control ?e)]" allout-end-of-entry)
  180. ("[(control ?i)]" allout-show-children)
  181. ("[(control ?s)]" allout-show-current-subtree)
  182. ("[(control ?t)]" allout-toggle-current-subtree-exposure)
  183. ;; Let user customize if they want to preempt describe-prefix-bindings ^h use.
  184. ;; ("[(control ?h)]" allout-hide-current-subtree)
  185. ("[?h]" allout-hide-current-subtree)
  186. ("[(control ?o)]" allout-show-current-entry)
  187. ("[?!]" allout-show-all)
  188. ("[?x]" allout-toggle-current-subtree-encryption)
  189. ("[? ]" allout-open-sibtopic)
  190. ("[?.]" allout-open-subtopic)
  191. ("[?,]" allout-open-supertopic)
  192. ("[?']" allout-shift-in)
  193. ("[?>]" allout-shift-in)
  194. ("[?<]" allout-shift-out)
  195. ("[(control ?m)]" allout-rebullet-topic)
  196. ("[?*]" allout-rebullet-current-heading)
  197. ("[?#]" allout-number-siblings)
  198. ("[(control ?k)]" allout-kill-topic)
  199. ("[(meta ?k)]" allout-copy-topic-as-kill)
  200. ("[?@]" allout-resolve-xref)
  201. ("[?=?c]" allout-copy-exposed-to-buffer)
  202. ("[?=?i]" allout-indented-exposed-to-buffer)
  203. ("[?=?t]" allout-latexify-exposed)
  204. ("[?=?p]" allout-flatten-exposed-to-buffer)
  205. )
  206. "Allout-mode key bindings that are prefixed with `allout-command-prefix'.
  207. See `allout-unprefixed-keybindings' for the list of keybindings
  208. that are not prefixed.
  209. Use vector format for the keys:
  210. - put literal keys after a '?' question mark, eg: '?a', '?.'
  211. - enclose control, shift, or meta-modified keys as sequences within
  212. parentheses, with the literal key, as above, preceded by the name(s)
  213. of the modifiers, eg: [(control ?a)]
  214. See the existing keys for examples.
  215. Functions can be bound to multiple keys, but binding keys to
  216. multiple functions will not work - the last binding for a key
  217. prevails."
  218. :version "24.1"
  219. :type 'allout-keybindings-binding
  220. :group 'allout-keybindings
  221. :set 'allout-compose-and-institute-keymap
  222. )
  223. ;;;_ = allout-unprefixed-keybindings
  224. (defcustom allout-unprefixed-keybindings
  225. '(("[(control ?k)]" allout-kill-line)
  226. ("[(meta ?k)]" allout-copy-line-as-kill)
  227. ("[(control ?y)]" allout-yank)
  228. ("[(meta ?y)]" allout-yank-pop)
  229. )
  230. "Allout-mode functions bound to keys without any added prefix.
  231. This is in contrast to the majority of allout-mode bindings on
  232. `allout-prefixed-bindings', whose bindings are created with a
  233. preceding command key.
  234. Use vector format for the keys:
  235. - put literal keys after a '?' question mark, eg: '?a', '?.'
  236. - enclose control, shift, or meta-modified keys as sequences within
  237. parentheses, with the literal key, as above, preceded by the name(s)
  238. of the modifiers, eg: [(control ?a)]
  239. See the existing keys for examples."
  240. :version "24.1"
  241. :type 'allout-keybindings-binding
  242. :group 'allout-keybindings
  243. :set 'allout-compose-and-institute-keymap
  244. )
  245. ;;;_ > allout-auto-activation-helper (var value)
  246. ;;;###autoload
  247. (defun allout-auto-activation-helper (var value)
  248. "Institute `allout-auto-activation'.
  249. Intended to be used as the `allout-auto-activation' :set function."
  250. (set-default var value)
  251. (allout-setup))
  252. ;;;_ > allout-setup ()
  253. ;;;###autoload
  254. (defun allout-setup ()
  255. "Do fundamental Emacs session for allout auto-activation.
  256. Establishes allout processing as part of visiting a file if
  257. `allout-auto-activation' is non-nil, or removes it otherwise.
  258. The proper way to use this is through customizing the setting of
  259. `allout-auto-activation'."
  260. (if (not allout-auto-activation)
  261. (remove-hook 'find-file-hook 'allout-find-file-hook)
  262. (add-hook 'find-file-hook 'allout-find-file-hook)))
  263. ;;;_ = allout-auto-activation
  264. ;;;###autoload
  265. (defcustom allout-auto-activation nil
  266. "Configure allout outline mode auto-activation.
  267. Control whether and how allout outline mode is automatically
  268. activated when files are visited with non-nil buffer-specific
  269. file variable `allout-layout'.
  270. When allout-auto-activation is \"On\" (t), allout mode is
  271. activated in buffers with non-nil `allout-layout', and the
  272. specified layout is applied.
  273. With value \"ask\", auto-mode-activation is enabled, and endorsement for
  274. performing auto-layout is asked of the user each time.
  275. With value \"activate\", only auto-mode-activation is enabled.
  276. Auto-layout is not.
  277. With value nil, inhibit any automatic allout-mode activation."
  278. :set 'allout-auto-activation-helper
  279. ;; FIXME: Using strings here is unusual and less efficient than symbols.
  280. :type '(choice (const :tag "On" t)
  281. (const :tag "Ask about layout" "ask")
  282. (const :tag "Mode only" "activate")
  283. (const :tag "Off" nil))
  284. :group 'allout)
  285. (allout-setup)
  286. ;;;_ = allout-default-layout
  287. (defcustom allout-default-layout '(-2 : 0)
  288. "Default allout outline layout specification.
  289. This setting specifies the outline exposure to use when
  290. `allout-layout' has the local value `t'. This docstring describes the
  291. layout specifications.
  292. A list value specifies a default layout for the current buffer,
  293. to be applied upon activation of `allout-mode'. Any non-nil
  294. value will automatically trigger `allout-mode', provided
  295. `allout-auto-activation' has been customized to enable it.
  296. The types of elements in the layout specification are:
  297. INTEGER -- dictate the relative depth to open the corresponding topic(s),
  298. where:
  299. -- negative numbers force the topic to be closed before opening
  300. to the absolute value of the number, so all siblings are open
  301. only to that level.
  302. -- positive numbers open to the relative depth indicated by the
  303. number, but do not force already opened subtopics to be closed.
  304. -- 0 means to close topic -- hide all subitems.
  305. : -- repeat spec -- apply the preceding element to all siblings at
  306. current level, *up to* those siblings that would be covered by specs
  307. following the `:' on the list. Ie, apply to all topics at level but
  308. trailing ones accounted for by trailing specs. (Only the first of
  309. multiple colons at the same level is honored -- later ones are ignored.)
  310. * -- completely exposes the topic, including bodies
  311. + -- exposes all subtopics, but not the bodies
  312. - -- exposes the body of the corresponding topic, but not subtopics
  313. LIST -- a nested layout spec, to be applied intricately to its
  314. corresponding item(s)
  315. Examples:
  316. (-2 : 0)
  317. Collapse the top-level topics to show their children and
  318. grandchildren, but completely collapse the final top-level topic.
  319. (-1 () : 1 0)
  320. Close the first topic so only the immediate subtopics are shown,
  321. leave the subsequent topics exposed as they are until the second
  322. second to last topic, which is exposed at least one level, and
  323. completely close the last topic.
  324. (-2 : -1 *)
  325. Expose children and grandchildren of all topics at current
  326. level except the last two; expose children of the second to
  327. last and completely expose the last one, including its subtopics.
  328. See `allout-expose-topic' for more about the exposure process.
  329. Also, allout's mode-specific provisions will make topic prefixes default
  330. to the comment-start string, if any, of the language of the file. This
  331. is modulo the setting of `allout-use-mode-specific-leader', which see."
  332. :type 'allout-layout-type
  333. :group 'allout)
  334. ;;;_ : allout-layout-type
  335. (define-widget 'allout-layout-type 'lazy
  336. "Allout layout format customization basic building blocks."
  337. :type '(repeat
  338. (choice (integer :tag "integer (<= zero is strict)")
  339. (const :tag ": (repeat prior)" :)
  340. (const :tag "* (completely expose)" *)
  341. (const :tag "+ (expose all offspring, headlines only)" +)
  342. (const :tag "- (expose topic body but not offspring)" -)
  343. (allout-layout-type :tag "<Nested layout>"))))
  344. ;;;_ = allout-inhibit-auto-fill
  345. (defcustom allout-inhibit-auto-fill nil
  346. "If non-nil, auto-fill will be inhibited in the allout buffers.
  347. You can customize this setting to set it for all allout buffers, or set it
  348. in individual buffers if you want to inhibit auto-fill only in particular
  349. buffers. (You could use a function on `allout-mode-hook' to inhibit
  350. auto-fill according, eg, to the major mode.)
  351. If you don't set this and auto-fill-mode is enabled, allout will use the
  352. value that `normal-auto-fill-function', if any, when allout mode starts, or
  353. else allout's special hanging-indent maintaining auto-fill function,
  354. `allout-auto-fill'."
  355. :type 'boolean
  356. :group 'allout)
  357. (make-variable-buffer-local 'allout-inhibit-auto-fill)
  358. ;;;_ = allout-inhibit-auto-fill-on-headline
  359. (defcustom allout-inhibit-auto-fill-on-headline nil
  360. "If non-nil, auto-fill will be inhibited while on topic's header line."
  361. :version "24.1"
  362. :type 'boolean
  363. :group 'allout)
  364. (make-variable-buffer-local 'allout-inhibit-auto-fill-on-headline)
  365. ;;;_ = allout-use-hanging-indents
  366. (defcustom allout-use-hanging-indents t
  367. "If non-nil, topic body text auto-indent defaults to indent of the header.
  368. Ie, it is indented to be just past the header prefix. This is
  369. relevant mostly for use with `indented-text-mode', or other situations
  370. where auto-fill occurs."
  371. :type 'boolean
  372. :group 'allout)
  373. (make-variable-buffer-local 'allout-use-hanging-indents)
  374. ;;;###autoload
  375. (put 'allout-use-hanging-indents 'safe-local-variable
  376. (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil)))))
  377. ;;;_ = allout-reindent-bodies
  378. (defcustom allout-reindent-bodies (if allout-use-hanging-indents
  379. 'text)
  380. "Non-nil enables auto-adjust of topic body hanging indent with depth shifts.
  381. When active, topic body lines that are indented even with or beyond
  382. their topic header are reindented to correspond with depth shifts of
  383. the header.
  384. A value of t enables reindent in non-programming-code buffers, ie
  385. those that do not have the variable `comment-start' set. A value of
  386. `force' enables reindent whether or not `comment-start' is set."
  387. :type '(choice (const nil) (const t) (const text) (const force))
  388. :group 'allout)
  389. (make-variable-buffer-local 'allout-reindent-bodies)
  390. ;;;###autoload
  391. (put 'allout-reindent-bodies 'safe-local-variable
  392. (lambda (x) (memq x '(nil t text force))))
  393. ;;;_ = allout-show-bodies
  394. (defcustom allout-show-bodies nil
  395. "If non-nil, show entire body when exposing a topic, rather than
  396. just the header."
  397. :type 'boolean
  398. :group 'allout)
  399. (make-variable-buffer-local 'allout-show-bodies)
  400. ;;;###autoload
  401. (put 'allout-show-bodies 'safe-local-variable
  402. (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil)))))
  403. ;;;_ = allout-beginning-of-line-cycles
  404. (defcustom allout-beginning-of-line-cycles t
  405. "If non-nil, \\[allout-beginning-of-line] will cycle through smart-placement options.
  406. Cycling only happens on when the command is repeated, not when it
  407. follows a different command.
  408. Smart-placement means that repeated calls to this function will
  409. advance as follows:
  410. - if the cursor is on a non-headline body line and not on the first column:
  411. then it goes to the first column
  412. - if the cursor is on the first column of a non-headline body line:
  413. then it goes to the start of the headline within the item body
  414. - if the cursor is on the headline and not the start of the headline:
  415. then it goes to the start of the headline
  416. - if the cursor is on the start of the headline:
  417. then it goes to the bullet character (for hotspot navigation)
  418. - if the cursor is on the bullet character:
  419. then it goes to the first column of that line (the headline)
  420. - if the cursor is on the first column of the headline:
  421. then it goes to the start of the headline within the item body.
  422. In this fashion, you can use the beginning-of-line command to do
  423. its normal job and then, when repeated, advance through the
  424. entry, cycling back to start.
  425. If this configuration variable is nil, then the cursor is just
  426. advanced to the beginning of the line and remains there on
  427. repeated calls."
  428. :type 'boolean :group 'allout)
  429. ;;;_ = allout-end-of-line-cycles
  430. (defcustom allout-end-of-line-cycles t
  431. "If non-nil, \\[allout-end-of-line] will cycle through smart-placement options.
  432. Cycling only happens on when the command is repeated, not when it
  433. follows a different command.
  434. Smart placement means that repeated calls to this function will
  435. advance as follows:
  436. - if the cursor is not on the end-of-line,
  437. then it goes to the end-of-line
  438. - if the cursor is on the end-of-line but not the end-of-entry,
  439. then it goes to the end-of-entry, exposing it if necessary
  440. - if the cursor is on the end-of-entry,
  441. then it goes to the end of the head line
  442. In this fashion, you can use the end-of-line command to do its
  443. normal job and then, when repeated, advance through the entry,
  444. cycling back to start.
  445. If this configuration variable is nil, then the cursor is just
  446. advanced to the end of the line and remains there on repeated
  447. calls."
  448. :type 'boolean :group 'allout)
  449. ;;;_ = allout-header-prefix
  450. (defcustom allout-header-prefix "."
  451. ;; this string is treated as literal match. it will be `regexp-quote'd, so
  452. ;; one cannot use regular expressions to match varying header prefixes.
  453. "Leading string which helps distinguish topic headers.
  454. Outline topic header lines are identified by a leading topic
  455. header prefix, which mostly have the value of this var at their front.
  456. Level 1 topics are exceptions. They consist of only a single
  457. character, which is typically set to the `allout-primary-bullet'."
  458. :type 'string
  459. :group 'allout)
  460. (make-variable-buffer-local 'allout-header-prefix)
  461. ;;;###autoload
  462. (put 'allout-header-prefix 'safe-local-variable 'stringp)
  463. ;;;_ = allout-primary-bullet
  464. (defcustom allout-primary-bullet "*"
  465. "Bullet used for top-level outline topics.
  466. Outline topic header lines are identified by a leading topic header
  467. prefix, which is concluded by bullets that includes the value of this
  468. var and the respective allout-*-bullets-string vars.
  469. The value of an asterisk (`*') provides for backwards compatibility
  470. with the original Emacs outline mode. See `allout-plain-bullets-string'
  471. and `allout-distinctive-bullets-string' for the range of available
  472. bullets."
  473. :type 'string
  474. :group 'allout)
  475. (make-variable-buffer-local 'allout-primary-bullet)
  476. ;;;###autoload
  477. (put 'allout-primary-bullet 'safe-local-variable 'stringp)
  478. ;;;_ = allout-plain-bullets-string
  479. (defcustom allout-plain-bullets-string ".,"
  480. "The bullets normally used in outline topic prefixes.
  481. See `allout-distinctive-bullets-string' for the other kind of
  482. bullets.
  483. DO NOT include the close-square-bracket, `]', as a bullet.
  484. Outline mode has to be reactivated in order for changes to the value
  485. of this var to take effect."
  486. :type 'string
  487. :group 'allout)
  488. (make-variable-buffer-local 'allout-plain-bullets-string)
  489. ;;;###autoload
  490. (put 'allout-plain-bullets-string 'safe-local-variable 'stringp)
  491. ;;;_ = allout-distinctive-bullets-string
  492. (defcustom allout-distinctive-bullets-string "*+-=>()[{}&!?#%\"X@$~_\\:;^"
  493. "Persistent outline header bullets used to distinguish special topics.
  494. These bullets are distinguish topics with particular character.
  495. They are not used by default in the topic creation routines, but
  496. are offered as options when you modify topic creation with a
  497. universal argument (\\[universal-argument]), or during rebulleting (\\[allout-rebullet-current-heading]).
  498. Distinctive bullets are not cycled when topics are shifted or
  499. otherwise automatically rebulleted, so their marking is
  500. persistent until deliberately changed. Their significance is
  501. purely by convention, however. Some conventions suggest
  502. themselves:
  503. `(' - open paren -- an aside or incidental point
  504. `?' - question mark -- uncertain or outright question
  505. `!' - exclamation point/bang -- emphatic
  506. `[' - open square bracket -- meta-note, about item instead of item's subject
  507. `\"' - double quote -- a quotation or other citation
  508. `=' - equal sign -- an assignment, some kind of definition
  509. `^' - carat -- relates to something above
  510. Some are more elusive, but their rationale may be recognizable:
  511. `+' - plus -- pending consideration, completion
  512. `_' - underscore -- done, completed
  513. `&' - ampersand -- addendum, furthermore
  514. \(Some other non-plain bullets have special meaning to the
  515. software. By default:
  516. `~' marks encryptable topics -- see `allout-topic-encryption-bullet'
  517. `#' marks auto-numbered bullets -- see `allout-numbered-bullet'.)
  518. See `allout-plain-bullets-string' for the standard, alternating
  519. bullets.
  520. You must run `set-allout-regexp' in order for outline mode to
  521. adopt changes of this value.
  522. DO NOT include the close-square-bracket, `]', on either of the bullet
  523. strings."
  524. :type 'string
  525. :group 'allout)
  526. (make-variable-buffer-local 'allout-distinctive-bullets-string)
  527. ;;;###autoload
  528. (put 'allout-distinctive-bullets-string 'safe-local-variable 'stringp)
  529. ;;;_ = allout-use-mode-specific-leader
  530. (defcustom allout-use-mode-specific-leader t
  531. "When non-nil, use mode-specific topic-header prefixes.
  532. Allout outline mode will use the mode-specific `allout-mode-leaders' or
  533. comment-start string, if any, to lead the topic prefix string, so topic
  534. headers look like comments in the programming language. It will also use
  535. the comment-start string, with an '_' appended, for `allout-primary-bullet'.
  536. String values are used as literals, not regular expressions, so
  537. do not escape any regular-expression characters.
  538. Value t means to first check for assoc value in `allout-mode-leaders'
  539. alist, then use comment-start string, if any, then use default (`.').
  540. \(See note about use of comment-start strings, below.)
  541. Set to the symbol for either of `allout-mode-leaders' or
  542. `comment-start' to use only one of them, respectively.
  543. Value nil means to always use the default (`.') and leave
  544. `allout-primary-bullet' unaltered.
  545. comment-start strings that do not end in spaces are tripled in
  546. the header-prefix, and an `_' underscore is tacked on the end, to
  547. distinguish them from regular comment strings. comment-start
  548. strings that do end in spaces are not tripled, but an underscore
  549. is substituted for the space. [This presumes that the space is
  550. for appearance, not comment syntax. You can use
  551. `allout-mode-leaders' to override this behavior, when
  552. undesired.]"
  553. :type '(choice (const t) (const nil) string
  554. (const allout-mode-leaders)
  555. (const comment-start))
  556. :group 'allout)
  557. ;;;###autoload
  558. (put 'allout-use-mode-specific-leader 'safe-local-variable
  559. (lambda (x) (or (memq x '(t nil allout-mode-leaders comment-start))
  560. (stringp x))))
  561. ;;;_ = allout-mode-leaders
  562. (defvar allout-mode-leaders '()
  563. "Specific allout-prefix leading strings per major modes.
  564. Use this if the mode's comment-start string isn't what you
  565. prefer, or if the mode lacks a comment-start string. See
  566. `allout-use-mode-specific-leader' for more details.
  567. If you're constructing a string that will comment-out outline
  568. structuring so it can be included in program code, append an extra
  569. character, like an \"_\" underscore, to distinguish the lead string
  570. from regular comments that start at the beginning-of-line.")
  571. ;;;_ = allout-old-style-prefixes
  572. (defcustom allout-old-style-prefixes nil
  573. "When non-nil, use only old-and-crusty `outline-mode' `*' topic prefixes.
  574. Non-nil restricts the topic creation and modification
  575. functions to asterix-padded prefixes, so they look exactly
  576. like the original Emacs-outline style prefixes.
  577. Whatever the setting of this variable, both old and new style prefixes
  578. are always respected by the topic maneuvering functions."
  579. :type 'boolean
  580. :group 'allout)
  581. (make-variable-buffer-local 'allout-old-style-prefixes)
  582. ;;;###autoload
  583. (put 'allout-old-style-prefixes 'safe-local-variable
  584. (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil)))))
  585. ;;;_ = allout-stylish-prefixes -- alternating bullets
  586. (defcustom allout-stylish-prefixes t
  587. "Do fancy stuff with topic prefix bullets according to level, etc.
  588. Non-nil enables topic creation, modification, and repositioning
  589. functions to vary the topic bullet char (the char that marks the topic
  590. depth) just preceding the start of the topic text) according to level.
  591. Otherwise, only asterisks (`*') and distinctive bullets are used.
  592. This is how an outline can look (but sans indentation) with stylish
  593. prefixes:
  594. * Top level
  595. .* A topic
  596. . + One level 3 subtopic
  597. . . One level 4 subtopic
  598. . . A second 4 subtopic
  599. . + Another level 3 subtopic
  600. . #1 A numbered level 4 subtopic
  601. . #2 Another
  602. . ! Another level 4 subtopic with a different distinctive bullet
  603. . #4 And another numbered level 4 subtopic
  604. This would be an outline with stylish prefixes inhibited (but the
  605. numbered and other distinctive bullets retained):
  606. * Top level
  607. .* A topic
  608. . * One level 3 subtopic
  609. . * One level 4 subtopic
  610. . * A second 4 subtopic
  611. . * Another level 3 subtopic
  612. . #1 A numbered level 4 subtopic
  613. . #2 Another
  614. . ! Another level 4 subtopic with a different distinctive bullet
  615. . #4 And another numbered level 4 subtopic
  616. Stylish and constant prefixes (as well as old-style prefixes) are
  617. always respected by the topic maneuvering functions, regardless of
  618. this variable setting.
  619. The setting of this var is not relevant when `allout-old-style-prefixes'
  620. is non-nil."
  621. :type 'boolean
  622. :group 'allout)
  623. (make-variable-buffer-local 'allout-stylish-prefixes)
  624. ;;;###autoload
  625. (put 'allout-stylish-prefixes 'safe-local-variable
  626. (if (fboundp 'booleanp) 'booleanp (lambda (x) (member x '(t nil)))))
  627. ;;;_ = allout-numbered-bullet
  628. (defcustom allout-numbered-bullet "#"
  629. "String designating bullet of topics that have auto-numbering; nil for none.
  630. Topics having this bullet have automatic maintenance of a sibling
  631. sequence-number tacked on, just after the bullet. Conventionally set
  632. to \"#\", you can set it to a bullet of your choice. A nil value
  633. disables numbering maintenance."
  634. :type '(choice (const nil) string)
  635. :group 'allout)
  636. (make-variable-buffer-local 'allout-numbered-bullet)
  637. ;;;###autoload
  638. (put 'allout-numbered-bullet 'safe-local-variable
  639. (if (fboundp 'string-or-null-p)
  640. 'string-or-null-p
  641. (lambda (x) (or (stringp x) (null x)))))
  642. ;;;_ = allout-file-xref-bullet
  643. (defcustom allout-file-xref-bullet "@"
  644. "Bullet signifying file cross-references, for `allout-resolve-xref'.
  645. Set this var to the bullet you want to use for file cross-references."
  646. :type '(choice (const nil) string)
  647. :group 'allout)
  648. ;;;###autoload
  649. (put 'allout-file-xref-bullet 'safe-local-variable
  650. (if (fboundp 'string-or-null-p)
  651. 'string-or-null-p
  652. (lambda (x) (or (stringp x) (null x)))))
  653. ;;;_ = allout-presentation-padding
  654. (defcustom allout-presentation-padding 2
  655. "Presentation-format white-space padding factor, for greater indent."
  656. :type 'integer
  657. :group 'allout)
  658. (make-variable-buffer-local 'allout-presentation-padding)
  659. ;;;###autoload
  660. (put 'allout-presentation-padding 'safe-local-variable 'integerp)
  661. ;;;_ = allout-flattened-numbering-abbreviation
  662. (define-obsolete-variable-alias 'allout-abbreviate-flattened-numbering
  663. 'allout-flattened-numbering-abbreviation "24.1")
  664. (defcustom allout-flattened-numbering-abbreviation nil
  665. "If non-nil, `allout-flatten-exposed-to-buffer' abbreviates topic
  666. numbers to minimal amount with some context. Otherwise, entire
  667. numbers are always used."
  668. :version "24.1"
  669. :type 'boolean
  670. :group 'allout)
  671. ;;;_ + LaTeX formatting
  672. ;;;_ - allout-number-pages
  673. (defcustom allout-number-pages nil
  674. "Non-nil turns on page numbering for LaTeX formatting of an outline."
  675. :type 'boolean
  676. :group 'allout)
  677. ;;;_ - allout-label-style
  678. (defcustom allout-label-style "\\large\\bf"
  679. "Font and size of labels for LaTeX formatting of an outline."
  680. :type 'string
  681. :group 'allout)
  682. ;;;_ - allout-head-line-style
  683. (defcustom allout-head-line-style "\\large\\sl "
  684. "Font and size of entries for LaTeX formatting of an outline."
  685. :type 'string
  686. :group 'allout)
  687. ;;;_ - allout-body-line-style
  688. (defcustom allout-body-line-style " "
  689. "Font and size of entries for LaTeX formatting of an outline."
  690. :type 'string
  691. :group 'allout)
  692. ;;;_ - allout-title-style
  693. (defcustom allout-title-style "\\Large\\bf"
  694. "Font and size of titles for LaTeX formatting of an outline."
  695. :type 'string
  696. :group 'allout)
  697. ;;;_ - allout-title
  698. (defcustom allout-title '(or buffer-file-name (buffer-name))
  699. "Expression to be evaluated to determine the title for LaTeX
  700. formatted copy."
  701. :type 'sexp
  702. :group 'allout)
  703. ;;;_ - allout-line-skip
  704. (defcustom allout-line-skip ".05cm"
  705. "Space between lines for LaTeX formatting of an outline."
  706. :type 'string
  707. :group 'allout)
  708. ;;;_ - allout-indent
  709. (defcustom allout-indent ".3cm"
  710. "LaTeX formatted depth-indent spacing."
  711. :type 'string
  712. :group 'allout)
  713. ;;;_ + Topic encryption
  714. ;;;_ = allout-encryption group
  715. (defgroup allout-encryption nil
  716. "Settings for topic encryption features of allout outliner."
  717. :group 'allout)
  718. ;;;_ = allout-topic-encryption-bullet
  719. (defcustom allout-topic-encryption-bullet "~"
  720. "Bullet signifying encryption of the entry's body."
  721. :type '(choice (const nil) string)
  722. :version "22.1"
  723. :group 'allout-encryption)
  724. ;;;_ = allout-encrypt-unencrypted-on-saves
  725. (defcustom allout-encrypt-unencrypted-on-saves t
  726. "If non-nil, topics pending encryption are encrypted during buffer saves.
  727. This prevents file-system exposure of un-encrypted contents of
  728. items marked for encryption.
  729. When non-nil, if the topic currently being edited is decrypted,
  730. it will be encrypted for saving but automatically decrypted
  731. before any subsequent user interaction, so it is once again clear
  732. text for editing though the file system copy is encrypted.
  733. \(Auto-saves are handled differently. Buffers with plain-text
  734. exposed encrypted topics are exempted from auto saves until all
  735. such topics are encrypted.)"
  736. :type 'boolean
  737. :version "23.1"
  738. :group 'allout-encryption)
  739. (make-variable-buffer-local 'allout-encrypt-unencrypted-on-saves)
  740. (defvar allout-auto-save-temporarily-disabled nil
  741. "True while topic encryption is pending and auto-saving was active.
  742. The value of `buffer-saved-size' at the time of decryption is used,
  743. for restoring when all encryptions are established.")
  744. (defvar allout-just-did-undo nil
  745. "True just after undo commands, until allout-post-command-business.")
  746. (make-variable-buffer-local 'allout-just-did-undo)
  747. ;;;_ + Developer
  748. ;;;_ = allout-developer group
  749. (defgroup allout-developer nil
  750. "Allout settings developers care about, including topic encryption and more."
  751. :group 'allout)
  752. ;;;_ = allout-run-unit-tests-on-load
  753. (defcustom allout-run-unit-tests-on-load nil
  754. "When non-nil, unit tests will be run at end of loading the allout module.
  755. Generally, allout code developers are the only ones who'll want to set this.
  756. \(If set, this makes it an even better practice to exercise changes by
  757. doing byte-compilation with a repeat count, so the file is loaded after
  758. compilation.)
  759. See `allout-run-unit-tests' to see what's run."
  760. :type 'boolean
  761. :group 'allout-developer)
  762. ;;;_ + Miscellaneous customization
  763. ;;;_ = allout-enable-file-variable-adjustment
  764. (defcustom allout-enable-file-variable-adjustment t
  765. "If non-nil, some allout outline actions edit Emacs local file var text.
  766. This can range from changes to existing entries, addition of new ones,
  767. and creation of a new local variables section when necessary.
  768. Emacs file variables adjustments are also inhibited if `enable-local-variables'
  769. is nil.
  770. Operations potentially causing edits include allout encryption routines.
  771. For details, see `allout-toggle-current-subtree-encryption's docstring."
  772. :type 'boolean
  773. :group 'allout)
  774. (make-variable-buffer-local 'allout-enable-file-variable-adjustment)
  775. ;;;_* CODE -- no user customizations below.
  776. ;;;_ #1 Internal Outline Formatting and Configuration
  777. ;;;_ : Version
  778. ;;;_ = allout-version
  779. (defvar allout-version "2.3"
  780. "Version of currently loaded outline package. (allout.el)")
  781. ;;;_ > allout-version
  782. (defun allout-version (&optional here)
  783. "Return string describing the loaded outline version."
  784. (interactive "P")
  785. (let ((msg (concat "Allout Outline Mode v " allout-version)))
  786. (if here (insert msg))
  787. (message "%s" msg)
  788. msg))
  789. ;;;_ : Mode activation (defined here because it's referenced early)
  790. ;;;_ = allout-mode
  791. (defvar allout-mode nil "Allout outline mode minor-mode flag.")
  792. (make-variable-buffer-local 'allout-mode)
  793. ;;;_ = allout-layout nil
  794. (defvar allout-layout nil ; LEAVE GLOBAL VALUE NIL -- see docstring.
  795. "Buffer-specific setting for allout layout.
  796. In buffers where this is non-nil (and if `allout-auto-activation'
  797. has been customized to enable this behavior), `allout-mode' will be
  798. automatically activated. The layout dictated by the value will be used to
  799. set the initial exposure when `allout-mode' is activated.
  800. \*You should not setq-default this variable non-nil unless you want every
  801. visited file to be treated as an allout file.*
  802. The value would typically be set by a file local variable. For
  803. example, the following lines at the bottom of an Emacs Lisp file:
  804. ;;;Local variables:
  805. ;;;allout-layout: (0 : -1 -1 0)
  806. ;;;End:
  807. dictate activation of `allout-mode' mode when the file is visited
  808. \(presuming proper `allout-auto-activation' customization),
  809. followed by the equivalent of `(allout-expose-topic 0 : -1 -1 0)'.
  810. \(This is the layout used for the allout.el source file.)
  811. `allout-default-layout' describes the specification format.
  812. `allout-layout' can additionally have the value `t', in which
  813. case the value of `allout-default-layout' is used.")
  814. (make-variable-buffer-local 'allout-layout)
  815. ;;;###autoload
  816. (put 'allout-layout 'safe-local-variable
  817. (lambda (x) (or (numberp x) (listp x) (memq x '(: * + -)))))
  818. ;;;_ : Topic header format
  819. ;;;_ = allout-regexp
  820. (defvar allout-regexp ""
  821. "*Regular expression to match the beginning of a heading line.
  822. Any line whose beginning matches this regexp is considered a
  823. heading. This var is set according to the user configuration vars
  824. by `set-allout-regexp'.")
  825. (make-variable-buffer-local 'allout-regexp)
  826. ;;;_ = allout-bullets-string
  827. (defvar allout-bullets-string ""
  828. "A string dictating the valid set of outline topic bullets.
  829. This var should *not* be set by the user -- it is set by `set-allout-regexp',
  830. and is produced from the elements of `allout-plain-bullets-string'
  831. and `allout-distinctive-bullets-string'.")
  832. (make-variable-buffer-local 'allout-bullets-string)
  833. ;;;_ = allout-bullets-string-len
  834. (defvar allout-bullets-string-len 0
  835. "Length of current buffers' `allout-plain-bullets-string'.")
  836. (make-variable-buffer-local 'allout-bullets-string-len)
  837. ;;;_ = allout-depth-specific-regexp
  838. (defvar allout-depth-specific-regexp ""
  839. "*Regular expression to match a heading line prefix for a particular depth.
  840. This expression is used to search for depth-specific topic
  841. headers at depth 2 and greater. Use `allout-depth-one-regexp'
  842. for to seek topics at depth one.
  843. This var is set according to the user configuration vars by
  844. `set-allout-regexp'. It is prepared with format strings for two
  845. decimal numbers, which should each be one less than the depth of the
  846. topic prefix to be matched.")
  847. (make-variable-buffer-local 'allout-depth-specific-regexp)
  848. ;;;_ = allout-depth-one-regexp
  849. (defvar allout-depth-one-regexp ""
  850. "*Regular expression to match a heading line prefix for depth one.
  851. This var is set according to the user configuration vars by
  852. `set-allout-regexp'. It is prepared with format strings for two
  853. decimal numbers, which should each be one less than the depth of the
  854. topic prefix to be matched.")
  855. (make-variable-buffer-local 'allout-depth-one-regexp)
  856. ;;;_ = allout-line-boundary-regexp
  857. (defvar allout-line-boundary-regexp ()
  858. "`allout-regexp' prepended with a newline for the search target.
  859. This is properly set by `set-allout-regexp'.")
  860. (make-variable-buffer-local 'allout-line-boundary-regexp)
  861. ;;;_ = allout-bob-regexp
  862. (defvar allout-bob-regexp ()
  863. "Like `allout-line-boundary-regexp', for headers at beginning of buffer.")
  864. (make-variable-buffer-local 'allout-bob-regexp)
  865. ;;;_ = allout-header-subtraction
  866. (defvar allout-header-subtraction (1- (length allout-header-prefix))
  867. "Allout-header prefix length to subtract when computing topic depth.")
  868. (make-variable-buffer-local 'allout-header-subtraction)
  869. ;;;_ = allout-plain-bullets-string-len
  870. (defvar allout-plain-bullets-string-len (length allout-plain-bullets-string)
  871. "Length of `allout-plain-bullets-string', updated by `set-allout-regexp'.")
  872. (make-variable-buffer-local 'allout-plain-bullets-string-len)
  873. ;;;_ = allout-doublecheck-at-and-shallower
  874. (defconst allout-doublecheck-at-and-shallower 3
  875. "Validate apparent topics of this depth and shallower as being non-aberrant.
  876. Verified with `allout-aberrant-container-p'. The usefulness of
  877. this check is limited to shallow depths, because the
  878. determination of aberrance is according to the mistaken item
  879. being followed by a legitimate item of excessively greater depth.
  880. The classic example of a mistaken item, for a standard allout
  881. outline configuration, is a body line that begins with an '...'
  882. ellipsis. This happens to contain a legitimate depth-2 header
  883. prefix, constituted by two '..' dots at the beginning of the
  884. line. The only thing that can distinguish it *in principle* from
  885. a legitimate one is if the following real header is at a depth
  886. that is discontinuous from the depth of 2 implied by the
  887. ellipsis, ie depth 4 or more. As the depth being tested gets
  888. greater, the likelihood of this kind of disqualification is
  889. lower, and the usefulness of this test is lower.
  890. Extending the depth of the doublecheck increases the amount it is
  891. applied, increasing the cost of the test - on casual estimation,
  892. for outlines with many deep topics, geometrically (O(n)?).
  893. Taken together with decreasing likelihood that the test will be
  894. useful at greater depths, more modest doublecheck limits are more
  895. suitably economical.")
  896. ;;;_ X allout-reset-header-lead (header-lead)
  897. (defun allout-reset-header-lead (header-lead)
  898. "Reset the leading string used to identify topic headers."
  899. (interactive "sNew lead string: ")
  900. (setq allout-header-prefix header-lead)
  901. (setq allout-header-subtraction (1- (length allout-header-prefix)))
  902. (set-allout-regexp))
  903. ;;;_ X allout-lead-with-comment-string (header-lead)
  904. (defun allout-lead-with-comment-string (&optional header-lead)
  905. "Set the topic-header leading string to specified string.
  906. Useful for encapsulating outline structure in programming
  907. language comments. Returns the leading string."
  908. (interactive "P")
  909. (if (not (stringp header-lead))
  910. (setq header-lead (read-string
  911. "String prefix for topic headers: ")))
  912. (setq allout-reindent-bodies nil)
  913. (allout-reset-header-lead header-lead)
  914. header-lead)
  915. ;;;_ > allout-infer-header-lead-and-primary-bullet ()
  916. (defun allout-infer-header-lead-and-primary-bullet ()
  917. "Determine appropriate `allout-header-prefix' and `allout-primary-bullet'.
  918. Works according to settings of:
  919. `comment-start'
  920. `allout-header-prefix' (default)
  921. `allout-use-mode-specific-leader'
  922. and `allout-mode-leaders'.
  923. Apply this via (re)activation of `allout-mode', rather than
  924. invoking it directly."
  925. (let* ((use-leader (and (boundp 'allout-use-mode-specific-leader)
  926. (if (or (stringp allout-use-mode-specific-leader)
  927. (memq allout-use-mode-specific-leader
  928. '(allout-mode-leaders
  929. comment-start
  930. t)))
  931. allout-use-mode-specific-leader
  932. ;; Oops -- garbled value, equate with effect of t:
  933. t)))
  934. (leader
  935. (cond
  936. ((not use-leader) nil)
  937. ;; Use the explicitly designated leader:
  938. ((stringp use-leader) use-leader)
  939. (t (or (and (memq use-leader '(t allout-mode-leaders))
  940. ;; Get it from outline mode leaders?
  941. (cdr (assq major-mode allout-mode-leaders)))
  942. ;; ... didn't get from allout-mode-leaders...
  943. (and (memq use-leader '(t comment-start))
  944. comment-start
  945. ;; Use comment-start, maybe tripled, and with
  946. ;; underscore:
  947. (concat
  948. (if (string= " "
  949. (substring comment-start
  950. (1- (length comment-start))))
  951. ;; Use comment-start, sans trailing space:
  952. (substring comment-start 0 -1)
  953. (concat comment-start comment-start comment-start))
  954. ;; ... and append underscore, whichever:
  955. "_")))))))
  956. (if (not leader)
  957. nil
  958. (setq allout-header-prefix leader)
  959. (if (not allout-old-style-prefixes)
  960. ;; setting allout-primary-bullet makes the top level topics use --
  961. ;; actually, be -- the special prefix:
  962. (setq allout-primary-bullet leader))
  963. allout-header-prefix)))
  964. (defalias 'allout-infer-header-lead
  965. 'allout-infer-header-lead-and-primary-bullet)
  966. ;;;_ > allout-infer-body-reindent ()
  967. (defun allout-infer-body-reindent ()
  968. "Determine proper setting for `allout-reindent-bodies'.
  969. Depends on default setting of `allout-reindent-bodies' (which see)
  970. and presence of setting for `comment-start', to tell whether the
  971. file is programming code."
  972. (if (and allout-reindent-bodies
  973. comment-start
  974. (not (eq 'force allout-reindent-bodies)))
  975. (setq allout-reindent-bodies nil)))
  976. ;;;_ > set-allout-regexp ()
  977. (defun set-allout-regexp ()
  978. "Generate proper topic-header regexp form for outline functions.
  979. Works with respect to `allout-plain-bullets-string' and
  980. `allout-distinctive-bullets-string'.
  981. Also refresh various data structures that hinge on the regexp."
  982. (interactive)
  983. ;; Derive allout-bullets-string from user configured components:
  984. (setq allout-bullets-string "")
  985. (let ((strings (list 'allout-plain-bullets-string
  986. 'allout-distinctive-bullets-string
  987. 'allout-primary-bullet))
  988. cur-string
  989. cur-len
  990. cur-char
  991. index)
  992. (while strings
  993. (setq index 0)
  994. (setq cur-len (length (setq cur-string (symbol-value (car strings)))))
  995. (while (< index cur-len)
  996. (setq cur-char (aref cur-string index))
  997. (setq allout-bullets-string
  998. (concat allout-bullets-string
  999. (cond
  1000. ; Single dash would denote a
  1001. ; sequence, repeated denotes
  1002. ; a dash:
  1003. ((eq cur-char ?-) "--")
  1004. ; literal close-square-bracket
  1005. ; doesn't work right in the
  1006. ; expr, exclude it:
  1007. ((eq cur-char ?\]) "")
  1008. (t (regexp-quote (char-to-string cur-char))))))
  1009. (setq index (1+ index)))
  1010. (setq strings (cdr strings)))
  1011. )
  1012. ;; Derive next for repeated use in allout-pending-bullet:
  1013. (setq allout-plain-bullets-string-len (length allout-plain-bullets-string))
  1014. (setq allout-header-subtraction (1- (length allout-header-prefix)))
  1015. (let (new-part old-part formfeed-part)
  1016. (setq new-part (concat "\\("
  1017. (regexp-quote allout-header-prefix)
  1018. "[ \t]*"
  1019. ;; already regexp-quoted in a custom way:
  1020. "[" allout-bullets-string "]"
  1021. "\\)")
  1022. old-part (concat "\\("
  1023. (regexp-quote allout-primary-bullet)
  1024. "\\|"
  1025. (regexp-quote allout-header-prefix)
  1026. "\\)"
  1027. "+"
  1028. " ?[^" allout-primary-bullet "]")
  1029. formfeed-part "\\(\^L\\)"
  1030. allout-regexp (concat new-part
  1031. "\\|"
  1032. old-part
  1033. "\\|"
  1034. formfeed-part)
  1035. allout-line-boundary-regexp (concat "\n" new-part
  1036. "\\|"
  1037. "\n" old-part
  1038. "\\|"
  1039. "\n" formfeed-part)
  1040. allout-bob-regexp (concat "\\`" new-part
  1041. "\\|"
  1042. "\\`" old-part
  1043. "\\|"
  1044. "\\`" formfeed-part
  1045. ))
  1046. (setq allout-depth-specific-regexp
  1047. (concat "\\(^\\|\\`\\)"
  1048. "\\("
  1049. ;; new-style spacers-then-bullet string:
  1050. "\\("
  1051. (allout-format-quote (regexp-quote allout-header-prefix))
  1052. " \\{%s\\}"
  1053. "[" (allout-format-quote allout-bullets-string) "]"
  1054. "\\)"
  1055. ;; old-style all-bullets string, if primary not multi-char:
  1056. (if (< 0 allout-header-subtraction)
  1057. ""
  1058. (concat "\\|\\("
  1059. (allout-format-quote
  1060. (regexp-quote allout-primary-bullet))
  1061. (allout-format-quote
  1062. (regexp-quote allout-primary-bullet))
  1063. (allout-format-quote
  1064. (regexp-quote allout-primary-bullet))
  1065. "\\{%s\\}"
  1066. ;; disqualify greater depths:
  1067. "[^"
  1068. (allout-format-quote allout-primary-bullet)
  1069. "]\\)"
  1070. ))
  1071. "\\)"
  1072. ))
  1073. (setq allout-depth-one-regexp
  1074. (concat "\\(^\\|\\`\\)"
  1075. "\\("
  1076. "\\("
  1077. (regexp-quote allout-header-prefix)
  1078. ;; disqualify any bullet char following any amount of
  1079. ;; intervening whitespace:
  1080. " *"
  1081. (concat "[^ " allout-bullets-string "]")
  1082. "\\)"
  1083. (if (< 0 allout-header-subtraction)
  1084. ;; Need not support anything like the old
  1085. ;; bullet style if the prefix is multi-char.
  1086. ""
  1087. (concat "\\|"
  1088. (regexp-quote allout-primary-bullet)
  1089. ;; disqualify deeper primary-bullet sequences:
  1090. "[^" allout-primary-bullet "]"))
  1091. "\\)"
  1092. ))))
  1093. ;;;_ : Menu bar
  1094. (defvar allout-mode-exposure-menu)
  1095. (defvar allout-mode-editing-menu)
  1096. (defvar allout-mode-navigation-menu)
  1097. (defvar allout-mode-misc-menu)
  1098. (defun produce-allout-mode-menubar-entries ()
  1099. (require 'easymenu)
  1100. (easy-menu-define allout-mode-exposure-menu
  1101. allout-mode-map-value
  1102. "Allout outline exposure menu."
  1103. '("Exposure"
  1104. ["Show Entry" allout-show-current-entry t]
  1105. ["Show Children" allout-show-children t]
  1106. ["Show Subtree" allout-show-current-subtree t]
  1107. ["Hide Subtree" allout-hide-current-subtree t]
  1108. ["Hide Leaves" allout-hide-current-leaves t]
  1109. "----"
  1110. ["Show All" allout-show-all t]))
  1111. (easy-menu-define allout-mode-editing-menu
  1112. allout-mode-map-value
  1113. "Allout outline editing menu."
  1114. '("Headings"
  1115. ["Open Sibling" allout-open-sibtopic t]
  1116. ["Open Subtopic" allout-open-subtopic t]
  1117. ["Open Supertopic" allout-open-supertopic t]
  1118. "----"
  1119. ["Shift Topic In" allout-shift-in t]
  1120. ["Shift Topic Out" allout-shift-out t]
  1121. ["Rebullet Topic" allout-rebullet-topic t]
  1122. ["Rebullet Heading" allout-rebullet-current-heading t]
  1123. ["Number Siblings" allout-number-siblings t]
  1124. "----"
  1125. ["Toggle Topic Encryption"
  1126. allout-toggle-current-subtree-encryption
  1127. (> (allout-current-depth) 1)]))
  1128. (easy-menu-define allout-mode-navigation-menu
  1129. allout-mode-map-value
  1130. "Allout outline navigation menu."
  1131. '("Navigation"
  1132. ["Next Visible Heading" allout-next-visible-heading t]
  1133. ["Previous Visible Heading"
  1134. allout-previous-visible-heading t]
  1135. "----"
  1136. ["Up Level" allout-up-current-level t]
  1137. ["Forward Current Level" allout-forward-current-level t]
  1138. ["Backward Current Level"
  1139. allout-backward-current-level t]
  1140. "----"
  1141. ["Beginning of Entry"
  1142. allout-beginning-of-current-entry t]
  1143. ["End of Entry" allout-end-of-entry t]
  1144. ["End of Subtree" allout-end-of-current-subtree t]))
  1145. (easy-menu-define allout-mode-misc-menu
  1146. allout-mode-map-value
  1147. "Allout outlines miscellaneous bindings."
  1148. '("Misc"
  1149. ["Version" allout-version t]
  1150. "----"
  1151. ["Duplicate Exposed" allout-copy-exposed-to-buffer t]
  1152. ["Duplicate Exposed, numbered"
  1153. allout-flatten-exposed-to-buffer t]
  1154. ["Duplicate Exposed, indented"
  1155. allout-indented-exposed-to-buffer t]
  1156. "----"
  1157. ["Set Header Lead" allout-reset-header-lead t]
  1158. ["Set New Exposure" allout-expose-topic t])))
  1159. ;;;_ : Allout Modal-Variables Utilities
  1160. ;;;_ = allout-mode-prior-settings
  1161. (defvar allout-mode-prior-settings nil
  1162. "Internal `allout-mode' use; settings to be resumed on mode deactivation.
  1163. See `allout-add-resumptions' and `allout-do-resumptions'.")
  1164. (make-variable-buffer-local 'allout-mode-prior-settings)
  1165. ;;;_ > allout-add-resumptions (&rest pairs)
  1166. (defun allout-add-resumptions (&rest pairs)
  1167. "Set name/value PAIRS.
  1168. Old settings are preserved for later resumption using `allout-do-resumptions'.
  1169. The new values are set as a buffer local. On resumption, the prior buffer
  1170. scope of the variable is restored along with its value. If it was a void
  1171. buffer-local value, then it is left as nil on resumption.
  1172. The pairs are lists whose car is the name of the variable and car of the
  1173. cdr is the new value: '(some-var some-value)'. The pairs can actually be
  1174. triples, where the third element qualifies the disposition of the setting,
  1175. as described further below.
  1176. If the optional third element is the symbol 'extend, then the new value
  1177. created by `cons'ing the second element of the pair onto the front of the
  1178. existing value.
  1179. If the optional third element is the symbol 'append, then the new value is
  1180. extended from the existing one by `append'ing a list containing the second
  1181. element of the pair onto the end of the existing value.
  1182. Extension, and resumptions in general, should not be used for hook
  1183. functions -- use the 'local mode of `add-hook' for that, instead.
  1184. The settings are stored on `allout-mode-prior-settings'."
  1185. (while pairs
  1186. (let* ((pair (pop pairs))
  1187. (name (car pair))
  1188. (value (cadr pair))
  1189. (qualifier (if (> (length pair) 2)
  1190. (caddr pair)))
  1191. prior-value)
  1192. (if (not (symbolp name))
  1193. (error "Pair's name, %S, must be a symbol, not %s"
  1194. name (type-of name)))
  1195. (setq prior-value (condition-case nil
  1196. (symbol-value name)
  1197. (void-variable nil)))
  1198. (when (not (assoc name allout-mode-prior-settings))
  1199. ;; Not already added as a resumption, create the prior setting entry.
  1200. (if (local-variable-p name (current-buffer))
  1201. ;; is already local variable -- preserve the prior value:
  1202. (push (list name prior-value) allout-mode-prior-settings)
  1203. ;; wasn't local variable, indicate so for resumption by killing
  1204. ;; local value, and make it local:
  1205. (push (list name) allout-mode-prior-settings)
  1206. (make-local-variable name)))
  1207. (if qualifier
  1208. (cond ((eq qualifier 'extend)
  1209. (if (not (listp prior-value))
  1210. (error "extension of non-list prior value attempted")
  1211. (set name (cons value prior-value))))
  1212. ((eq qualifier 'append)
  1213. (if (not (listp prior-value))
  1214. (error "appending of non-list prior value attempted")
  1215. (set name (append prior-value (list value)))))
  1216. (t (error "unrecognized setting qualifier `%s' encountered"
  1217. qualifier)))
  1218. (set name value)))))
  1219. ;;;_ > allout-do-resumptions ()
  1220. (defun allout-do-resumptions ()
  1221. "Resume all name/value settings registered by `allout-add-resumptions'.
  1222. This is used when concluding allout-mode, to resume selected variables to
  1223. their settings before allout-mode was started."
  1224. (while allout-mode-prior-settings
  1225. (let* ((pair (pop allout-mode-prior-settings))
  1226. (name (car pair))
  1227. (value-cell (cdr pair)))
  1228. (if (not value-cell)
  1229. ;; Prior value was global:
  1230. (kill-local-variable name)
  1231. ;; Prior value was explicit:
  1232. (set name (car value-cell))))))
  1233. ;;;_ : Mode-specific incidentals
  1234. ;;;_ > allout-unprotected (expr)
  1235. (defmacro allout-unprotected (expr)
  1236. "Enable internal outline operations to alter invisible text."
  1237. `(let ((inhibit-read-only (if (not buffer-read-only) t))
  1238. (inhibit-field-text-motion t))
  1239. ,expr))
  1240. ;;;_ = allout-mode-hook
  1241. (defvar allout-mode-hook nil
  1242. "*Hook that's run when allout mode starts.")
  1243. ;;;_ = allout-mode-deactivate-hook
  1244. (defvar allout-mode-deactivate-hook nil
  1245. "*Hook that's run when allout mode ends.")
  1246. (define-obsolete-variable-alias 'allout-mode-deactivate-hook
  1247. 'allout-mode-off-hook "24.1")
  1248. ;;;_ = allout-exposure-category
  1249. (defvar allout-exposure-category nil
  1250. "Symbol for use as allout invisible-text overlay category.")
  1251. ;;;_ = allout-exposure-change-hook
  1252. (defvar allout-exposure-change-hook nil
  1253. "*Hook that's run after allout outline subtree exposure changes.
  1254. It is run at the conclusion of `allout-flag-region'.
  1255. Functions on the hook must take three arguments:
  1256. - FROM -- integer indicating the point at the start of the change.
  1257. - TO -- integer indicating the point of the end of the change.
  1258. - FLAG -- change mode: nil for exposure, otherwise concealment.
  1259. This hook might be invoked multiple times by a single command.")
  1260. ;;;_ = allout-structure-added-hook
  1261. (defvar allout-structure-added-hook nil
  1262. "*Hook that's run after addition of items to the outline.
  1263. Functions on the hook should take two arguments:
  1264. - NEW-START -- integer indicating position of start of the first new item.
  1265. - NEW-END -- integer indicating position of end of the last new item.
  1266. This hook might be invoked multiple times by a single command.")
  1267. ;;;_ = allout-structure-deleted-hook
  1268. (defvar allout-structure-deleted-hook nil
  1269. "*Hook that's run after disciplined deletion of subtrees from the outline.
  1270. Functions on the hook must take two arguments:
  1271. - DEPTH -- integer indicating the depth of the subtree that was deleted.
  1272. - REMOVED-FROM -- integer indicating the point where the subtree was removed.
  1273. Some edits that remove or invalidate items may be missed by this hook:
  1274. specifically edits that native allout routines do not control.
  1275. This hook might be invoked multiple times by a single command.")
  1276. ;;;_ = allout-structure-shifted-hook
  1277. (defvar allout-structure-shifted-hook nil
  1278. "*Hook that's run after shifting of items in the outline.
  1279. Functions on the hook should take two arguments:
  1280. - DEPTH-CHANGE -- integer indicating depth increase, negative for decrease
  1281. - START -- integer indicating the start point of the shifted parent item.
  1282. Some edits that shift items can be missed by this hook: specifically edits
  1283. that native allout routines do not control.
  1284. This hook might be invoked multiple times by a single command.")
  1285. ;;;_ = allout-after-copy-or-kill-hook
  1286. (defvar allout-after-copy-or-kill-hook nil
  1287. "*Hook that's run after copying outline text.
  1288. Functions on the hook should not require any arguments.")
  1289. ;;;_ = allout-post-undo-hook
  1290. (defvar allout-post-undo-hook nil
  1291. "*Hook that's run after undo activity.
  1292. The item that's current when the hook is run *may* be the one
  1293. that was affected by the undo.
  1294. Functions on the hook should not require any arguments.")
  1295. ;;;_ = allout-outside-normal-auto-fill-function
  1296. (defvar allout-outside-normal-auto-fill-function nil
  1297. "Value of `normal-auto-fill-function' outside of allout mode.
  1298. Used by `allout-auto-fill' to do the mandated `normal-auto-fill-function'
  1299. wrapped within allout's automatic `fill-prefix' setting.")
  1300. (make-variable-buffer-local 'allout-outside-normal-auto-fill-function)
  1301. ;;;_ = prevent redundant activation by desktop mode:
  1302. (add-to-list 'desktop-minor-mode-handlers '(allout-mode . nil))
  1303. ;;;_ = allout-passphrase-verifier-string
  1304. (defvar allout-passphrase-verifier-string nil
  1305. "Setting used to test solicited encryption passphrases against the one
  1306. already associated with a file.
  1307. It consists of an encrypted random string useful only to verify that a
  1308. passphrase entered by the user is effective for decryption. The passphrase
  1309. itself is \*not* recorded in the file anywhere, and the encrypted contents
  1310. are random binary characters to avoid exposing greater susceptibility to
  1311. search attacks.
  1312. The verifier string is retained as an Emacs file variable, as well as in
  1313. the Emacs buffer state, if file variable adjustments are enabled. See
  1314. `allout-enable-file-variable-adjustment' for details about that.")
  1315. (make-variable-buffer-local 'allout-passphrase-verifier-string)
  1316. (make-obsolete 'allout-passphrase-verifier-string
  1317. 'allout-passphrase-verifier-string "23.3")
  1318. ;;;###autoload
  1319. (put 'allout-passphrase-verifier-string 'safe-local-variable 'stringp)
  1320. ;;;_ = allout-passphrase-hint-string
  1321. (defvar allout-passphrase-hint-string ""
  1322. "Variable used to retain reminder string for file's encryption passphrase.
  1323. See the description of `allout-passphrase-hint-handling' for details about how
  1324. the reminder is deployed.
  1325. The hint is retained as an Emacs file variable, as well as in the Emacs buffer
  1326. state, if file variable adjustments are enabled. See
  1327. `allout-enable-file-variable-adjustment' for details about that.")
  1328. (make-variable-buffer-local 'allout-passphrase-hint-string)
  1329. (setq-default allout-passphrase-hint-string "")
  1330. (make-obsolete 'allout-passphrase-hint-string
  1331. 'allout-passphrase-hint-string "23.3")
  1332. ;;;###autoload
  1333. (put 'allout-passphrase-hint-string 'safe-local-variable 'stringp)
  1334. ;;;_ = allout-after-save-decrypt
  1335. (defvar allout-after-save-decrypt nil
  1336. "Internal variable, is nil or has the value of two points:
  1337. - the location of a topic to be decrypted after saving is done
  1338. - where to situate the cursor after the decryption is performed
  1339. This is used to decrypt the topic that was currently being edited, if it
  1340. was encrypted automatically as part of a file write or autosave.")
  1341. (make-variable-buffer-local 'allout-after-save-decrypt)
  1342. ;;;_ = allout-encryption-plaintext-sanitization-regexps
  1343. (defvar allout-encryption-plaintext-sanitization-regexps nil
  1344. "List of regexps whose matches are removed from plaintext before encryption.
  1345. This is for the sake of removing artifacts, like escapes, that are added on
  1346. and not actually part of the original plaintext. The removal is done just
  1347. prior to encryption.
  1348. Entries must be symbols that are bound to the desired values.
  1349. Each value can be a regexp or a list with a regexp followed by a
  1350. substitution string. If it's just a regexp, all its matches are removed
  1351. before the text is encrypted. If it's a regexp and a substitution, the
  1352. substitution is used against the regexp matches, a la `replace-match'.")
  1353. (make-variable-buffer-local 'allout-encryption-text-removal-regexps)
  1354. ;;;_ = allout-encryption-ciphertext-rejection-regexps
  1355. (defvar allout-encryption-ciphertext-rejection-regexps nil
  1356. "Variable for regexps matching plaintext to remove before encryption.
  1357. This is used to detect strings in encryption results that would
  1358. register as allout mode structural elements, for example, as a
  1359. topic prefix.
  1360. Entries must be symbols that are bound to the desired regexp values.
  1361. Encryptions that result in matches will be retried, up to
  1362. `allout-encryption-ciphertext-rejection-limit' times, after which
  1363. an error is raised.")
  1364. (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-regexps)
  1365. ;;;_ = allout-encryption-ciphertext-rejection-ceiling
  1366. (defvar allout-encryption-ciphertext-rejection-ceiling 5
  1367. "Limit on number of times encryption ciphertext is rejected.
  1368. See `allout-encryption-ciphertext-rejection-regexps' for rejection reasons.")
  1369. (make-variable-buffer-local 'allout-encryption-ciphertext-rejection-ceiling)
  1370. ;;;_ > allout-mode-p ()
  1371. ;; Must define this macro above any uses, or byte compilation will lack
  1372. ;; proper def, if file isn't loaded -- eg, during emacs build!
  1373. ;;;###autoload
  1374. (defmacro allout-mode-p ()
  1375. "Return t if `allout-mode' is active in current buffer."
  1376. 'allout-mode)
  1377. ;;;_ > allout-write-contents-hook-handler ()
  1378. (defun allout-write-contents-hook-handler ()
  1379. "Implement `allout-encrypt-unencrypted-on-saves' for file writes
  1380. Return nil if all goes smoothly, or else return an informative
  1381. message if an error is encountered. The message will serve as a
  1382. non-nil return on `write-contents-functions' to prevent saving of
  1383. the buffer while it has decrypted content.
  1384. This behavior depends on Emacs versions that implement the
  1385. `write-contents-functions' hook."
  1386. (if (or (not (allout-mode-p))
  1387. (not (boundp 'allout-encrypt-unencrypted-on-saves))
  1388. (not allout-encrypt-unencrypted-on-saves))
  1389. nil
  1390. (if (save-excursion (goto-char (point-min))
  1391. (allout-next-topic-pending-encryption))
  1392. (progn
  1393. (message "auto-encrypting pending topics")
  1394. (sit-for 0)
  1395. (condition-case failure
  1396. (progn
  1397. (setq allout-after-save-decrypt
  1398. (allout-encrypt-decrypted))
  1399. ;; aok - return nil:
  1400. nil)
  1401. (error
  1402. ;; whoops - probably some still-decrypted items, return non-nil:
  1403. (let ((text (format (concat "%s contents write inhibited due to"
  1404. " encrypted topic encryption error:"
  1405. " %s")
  1406. (buffer-name (current-buffer))
  1407. failure)))
  1408. (message text)(sit-for 2)
  1409. text)))))
  1410. ))
  1411. ;;;_ > allout-after-saves-handler ()
  1412. (defun allout-after-saves-handler ()
  1413. "Decrypt topic encrypted for save, if it's currently being edited.
  1414. Ie, if it was pending encryption and contained the point in its body before
  1415. the save.
  1416. We use values stored in `allout-after-save-decrypt' to locate the topic
  1417. and the place for the cursor after the decryption is done."
  1418. (if (not (and (allout-mode-p)
  1419. (boundp 'allout-after-save-decrypt)
  1420. allout-after-save-decrypt))
  1421. t
  1422. (goto-char (car allout-after-save-decrypt))
  1423. (let ((was-modified (buffer-modified-p)))
  1424. (allout-toggle-subtree-encryption)
  1425. (if (not was-modified)
  1426. (set-buffer-modified-p nil)))
  1427. (goto-char (cadr allout-after-save-decrypt))
  1428. (setq allout-after-save-decrypt nil))
  1429. )
  1430. ;;;_ > allout-called-interactively-p ()
  1431. (defmacro allout-called-interactively-p ()
  1432. "A version of `called-interactively-p' independent of Emacs version."
  1433. ;; ... to ease maintenance of allout without betraying deprecation.
  1434. (if (equal (subr-arity (symbol-function 'called-interactively-p))
  1435. '(0 . 0))
  1436. '(called-interactively-p)
  1437. '(called-interactively-p 'interactive)))
  1438. ;;;_ = allout-inhibit-aberrance-doublecheck nil
  1439. ;; In some exceptional moments, disparate topic depths need to be allowed
  1440. ;; momentarily, eg when one topic is being yanked into another and they're
  1441. ;; about to be reconciled. let-binding allout-inhibit-aberrance-doublecheck
  1442. ;; prevents the aberrance doublecheck to allow, eg, the reconciliation
  1443. ;; processing to happen in the presence of such discrepancies. It should
  1444. ;; almost never be needed, however.
  1445. (defvar allout-inhibit-aberrance-doublecheck nil
  1446. "Internal state, for momentarily inhibits aberrance doublecheck.
  1447. This should only be momentarily let-bound non-nil, not set
  1448. non-nil in a lasting way.")
  1449. ;;;_ #2 Mode environment and activation
  1450. ;;;_ = allout-explicitly-deactivated
  1451. (defvar allout-explicitly-deactivated nil
  1452. "If t, `allout-mode's last deactivation was deliberate.
  1453. So `allout-post-command-business' should not reactivate it...")
  1454. (make-variable-buffer-local 'allout-explicitly-deactivated)
  1455. ;;;_ > allout-init (mode)
  1456. (defun allout-init (mode)
  1457. "DEPRECATED - configure allout activation by customizing
  1458. `allout-auto-activation'. This function remains around, limited
  1459. from what it did before, for backwards compatibility.
  1460. MODE is the activation mode - see `allout-auto-activation' for
  1461. valid values."
  1462. (custom-set-variables (list 'allout-auto-activation (format "%s" mode)))
  1463. (format "%s" mode))
  1464. (make-obsolete 'allout-init
  1465. "customize 'allout-auto-activation' instead." "23.3")
  1466. ;;;_ > allout-setup-menubar ()
  1467. (defun allout-setup-menubar ()
  1468. "Populate the current buffer's menubar with `allout-mode' stuff."
  1469. (let ((menus (list allout-mode-exposure-menu
  1470. allout-mode-editing-menu
  1471. allout-mode-navigation-menu
  1472. allout-mode-misc-menu))
  1473. cur)
  1474. (while menus
  1475. (setq cur (car menus)
  1476. menus (cdr menus))
  1477. (easy-menu-add cur))))
  1478. ;;;_ > allout-overlay-preparations
  1479. (defun allout-overlay-preparations ()
  1480. "Set the properties of the allout invisible-text overlay and others."
  1481. (setplist 'allout-exposure-category nil)
  1482. (put 'allout-exposure-category 'invisible 'allout)
  1483. (put 'allout-exposure-category 'evaporate t)
  1484. ;; ??? We use isearch-open-invisible *and* isearch-mode-end-hook. The
  1485. ;; latter would be sufficient, but it seems that a separate behavior --
  1486. ;; the _transient_ opening of invisible text during isearch -- is keyed to
  1487. ;; presence of the isearch-open-invisible property -- even though this
  1488. ;; property controls the isearch _arrival_ behavior. This is the case at
  1489. ;; least in emacs 21, 22.1, and xemacs 21.4.
  1490. (put 'allout-exposure-category 'isearch-open-invisible
  1491. 'allout-isearch-end-handler)
  1492. (if (featurep 'xemacs)
  1493. (put 'allout-exposure-category 'start-open t)
  1494. (put 'allout-exposure-category 'insert-in-front-hooks
  1495. '(allout-overlay-insert-in-front-handler)))
  1496. (put 'allout-exposure-category 'modification-hooks
  1497. '(allout-overlay-interior-modification-handler)))
  1498. ;;;_ > define-minor-mode allout-mode
  1499. ;;;_ : Defun:
  1500. ;;;###autoload
  1501. (define-minor-mode allout-mode
  1502. ;;;_ . Doc string:
  1503. "Toggle Allout outline mode.
  1504. With a prefix argument ARG, enable Allout outline mode if ARG is
  1505. positive, and disable it otherwise. If called from Lisp, enable
  1506. the mode if ARG is omitted or nil.
  1507. \\<allout-mode-map-value>
  1508. Allout outline mode is a minor mode that provides extensive
  1509. outline oriented formatting and manipulation. It enables
  1510. structural editing of outlines, as well as navigation and
  1511. exposure. It also is specifically aimed at accommodating
  1512. syntax-sensitive text like programming languages. (For example,
  1513. see the allout code itself, which is organized as an allout
  1514. outline.)
  1515. In addition to typical outline navigation and exposure, allout includes:
  1516. - topic-oriented authoring, including keystroke-based topic creation,
  1517. repositioning, promotion/demotion, cut, and paste
  1518. - incremental search with dynamic exposure and reconcealment of hidden text
  1519. - adjustable format, so programming code can be developed in outline-structure
  1520. - easy topic encryption and decryption, symmetric or key-pair
  1521. - \"Hot-spot\" operation, for single-keystroke maneuvering and exposure control
  1522. - integral outline layout, for automatic initial exposure when visiting a file
  1523. - independent extensibility, using comprehensive exposure and authoring hooks
  1524. and many other features.
  1525. Below is a description of the key bindings, and then description
  1526. of special `allout-mode' features and terminology. See also the
  1527. outline menubar additions for quick reference to many of the
  1528. features. Customize `allout-auto-activation' to prepare your
  1529. Emacs session for automatic activation of `allout-mode'.
  1530. The bindings are those listed in `allout-prefixed-keybindings'
  1531. and `allout-unprefixed-keybindings'. We recommend customizing
  1532. `allout-command-prefix' to use just `\\C-c' as the command
  1533. prefix, if the allout bindings don't conflict with any personal
  1534. bindings you have on \\C-c. In any case, outline structure
  1535. navigation and authoring is simplified by positioning the cursor
  1536. on an item's bullet character, the \"hot-spot\" -- then you can
  1537. invoke allout commands with just the un-prefixed,
  1538. un-control-shifted command letters. This is described further in
  1539. the HOT-SPOT Operation section.
  1540. Exposure Control:
  1541. ----------------
  1542. \\[allout-hide-current-subtree] `allout-hide-current-subtree'
  1543. \\[allout-show-children] `allout-show-children'
  1544. \\[allout-show-current-subtree] `allout-show-current-subtree'
  1545. \\[allout-show-current-entry] `allout-show-current-entry'
  1546. \\[allout-show-all] `allout-show-all'
  1547. Navigation:
  1548. ----------
  1549. \\[allout-next-visible-heading] `allout-next-visible-heading'
  1550. \\[allout-previous-visible-heading] `allout-previous-visible-heading'
  1551. \\[allout-up-current-level] `allout-up-current-level'
  1552. \\[allout-forward-current-level] `allout-forward-current-level'
  1553. \\[allout-backward-current-level] `allout-backward-current-level'
  1554. \\[allout-end-of-entry] `allout-end-of-entry'
  1555. \\[allout-beginning-of-current-entry] `allout-beginning-of-current-entry' (alternately, goes to hot-spot)
  1556. \\[allout-beginning-of-line] `allout-beginning-of-line' -- like regular beginning-of-line, but
  1557. if immediately repeated cycles to the beginning of the current item
  1558. and then to the hot-spot (if `allout-beginning-of-line-cycles' is set).
  1559. Topic Header Production:
  1560. -----------------------
  1561. \\[allout-open-sibtopic] `allout-open-sibtopic' Create a new sibling after current topic.
  1562. \\[allout-open-subtopic] `allout-open-subtopic' ... an offspring of current topic.
  1563. \\[allout-open-supertopic] `allout-open-supertopic' ... a sibling of the current topic's parent.
  1564. Topic Level and Prefix Adjustment:
  1565. ---------------------------------
  1566. \\[allout-shift-in] `allout-shift-in' Shift current topic and all offspring deeper
  1567. \\[allout-shift-out] `allout-shift-out' ... less deep
  1568. \\[allout-rebullet-current-heading] `allout-rebullet-current-heading' Prompt for alternate bullet for
  1569. current topic
  1570. \\[allout-rebullet-topic] `allout-rebullet-topic' Reconcile bullets of topic and
  1571. its offspring -- distinctive bullets are not changed, others
  1572. are alternated according to nesting depth.
  1573. \\[allout-number-siblings] `allout-number-siblings' Number bullets of topic and siblings --
  1574. the offspring are not affected.
  1575. With repeat count, revoke numbering.
  1576. Topic-oriented Killing and Yanking:
  1577. ----------------------------------
  1578. \\[allout-kill-topic] `allout-kill-topic' Kill current topic, including offspring.
  1579. \\[allout-copy-topic-as-kill] `allout-copy-topic-as-kill' Copy current topic, including offspring.
  1580. \\[allout-kill-line] `allout-kill-line' Kill line, attending to outline structure.
  1581. \\[allout-copy-line-as-kill] `allout-copy-line-as-kill' Copy line but don't delete it.
  1582. \\[allout-yank] `allout-yank' Yank, adjusting depth of yanked topic to
  1583. depth of heading if yanking into bare topic
  1584. heading (ie, prefix sans text).
  1585. \\[allout-yank-pop] `allout-yank-pop' Is to `allout-yank' as `yank-pop' is to `yank'.
  1586. Topic-oriented Encryption:
  1587. -------------------------
  1588. \\[allout-toggle-current-subtree-encryption] `allout-toggle-current-subtree-encryption'
  1589. Encrypt/Decrypt topic content
  1590. Misc commands:
  1591. -------------
  1592. M-x outlineify-sticky Activate outline mode for current buffer,
  1593. and establish a default file-var setting
  1594. for `allout-layout'.
  1595. \\[allout-mark-topic] `allout-mark-topic'
  1596. \\[allout-copy-exposed-to-buffer] `allout-copy-exposed-to-buffer'
  1597. Duplicate outline, sans concealed text, to
  1598. buffer with name derived from derived from that
  1599. of current buffer -- \"*BUFFERNAME exposed*\".
  1600. \\[allout-flatten-exposed-to-buffer] `allout-flatten-exposed-to-buffer'
  1601. Like above 'copy-exposed', but convert topic
  1602. prefixes to section.subsection... numeric
  1603. format.
  1604. \\[customize-variable] allout-auto-activation
  1605. Prepare Emacs session for allout outline mode
  1606. auto-activation.
  1607. Topic Encryption
  1608. Outline mode supports gpg encryption of topics, with support for
  1609. symmetric and key-pair modes, and auto-encryption of topics
  1610. pending encryption on save.
  1611. Topics pending encryption are, by default, automatically
  1612. encrypted during file saves, including checkpoint saves, to avoid
  1613. exposing the plain text of encrypted topics in the file system.
  1614. If the content of the topic containing the cursor was encrypted
  1615. for a save, it is automatically decrypted for continued editing.
  1616. NOTE: A few GnuPG v2 versions improperly preserve incorrect
  1617. symmetric decryption keys, preventing entry of the correct key on
  1618. subsequent decryption attempts until the cache times-out. That
  1619. can take several minutes. (Decryption of other entries is not
  1620. affected.) Upgrade your EasyPG version, if you can, and you can
  1621. deliberately clear your gpg-agent's cache by sending it a '-HUP'
  1622. signal.
  1623. See `allout-toggle-current-subtree-encryption' function docstring
  1624. and `allout-encrypt-unencrypted-on-saves' customization variable
  1625. for details.
  1626. HOT-SPOT Operation
  1627. Hot-spot operation provides a means for easy, single-keystroke outline
  1628. navigation and exposure control.
  1629. When the text cursor is positioned directly on the bullet character of
  1630. a topic, regular characters (a to z) invoke the commands of the
  1631. corresponding allout-mode keymap control chars. For example, \"f\"
  1632. would invoke the command typically bound to \"C-c<space>C-f\"
  1633. \(\\[allout-forward-current-level] `allout-forward-current-level').
  1634. Thus, by positioning the cursor on a topic bullet, you can
  1635. execute the outline navigation and manipulation commands with a
  1636. single keystroke. Regular navigation keys (eg, \\[forward-char], \\[next-line]) don't get
  1637. this special translation, so you can use them to get out of the
  1638. hot-spot and back to normal editing operation.
  1639. In allout-mode, the normal beginning-of-line command (\\[allout-beginning-of-line]) is
  1640. replaced with one that makes it easy to get to the hot-spot. If you
  1641. repeat it immediately it cycles (if `allout-beginning-of-line-cycles'
  1642. is set) to the beginning of the item and then, if you hit it again
  1643. immediately, to the hot-spot. Similarly, `allout-beginning-of-current-entry'
  1644. \(\\[allout-beginning-of-current-entry]) moves to the hot-spot when the cursor is already located
  1645. at the beginning of the current entry.
  1646. Extending Allout
  1647. Allout exposure and authoring activities all have associated
  1648. hooks, by which independent code can cooperate with allout
  1649. without changes to the allout core. Here are key ones:
  1650. `allout-mode-hook'
  1651. `allout-mode-deactivate-hook' (deprecated)
  1652. `allout-mode-off-hook'
  1653. `allout-exposure-change-hook'
  1654. `allout-structure-added-hook'
  1655. `allout-structure-deleted-hook'
  1656. `allout-structure-shifted-hook'
  1657. `allout-after-copy-or-kill-hook'
  1658. `allout-post-undo-hook'
  1659. Terminology
  1660. Topic hierarchy constituents -- TOPICS and SUBTOPICS:
  1661. ITEM: A unitary outline element, including the HEADER and ENTRY text.
  1662. TOPIC: An ITEM and any ITEMs contained within it, ie having greater DEPTH
  1663. and with no intervening items of lower DEPTH than the container.
  1664. CURRENT ITEM:
  1665. The visible ITEM most immediately containing the cursor.
  1666. DEPTH: The degree of nesting of an ITEM; it increases with containment.
  1667. The DEPTH is determined by the HEADER PREFIX. The DEPTH is also
  1668. called the:
  1669. LEVEL: The same as DEPTH.
  1670. ANCESTORS:
  1671. Those ITEMs whose TOPICs contain an ITEM.
  1672. PARENT: An ITEM's immediate ANCESTOR. It has a DEPTH one less than that
  1673. of the ITEM.
  1674. OFFSPRING:
  1675. The ITEMs contained within an ITEM's TOPIC.
  1676. SUBTOPIC:
  1677. An OFFSPRING of its ANCESTOR TOPICs.
  1678. CHILD:
  1679. An immediate SUBTOPIC of its PARENT.
  1680. SIBLINGS:
  1681. TOPICs having the same PARENT and DEPTH.
  1682. Topic text constituents:
  1683. HEADER: The first line of an ITEM, include the ITEM PREFIX and HEADER
  1684. text.
  1685. ENTRY: The text content of an ITEM, before any OFFSPRING, but including
  1686. the HEADER text and distinct from the ITEM PREFIX.
  1687. BODY: Same as ENTRY.
  1688. PREFIX: The leading text of an ITEM which distinguishes it from normal
  1689. ENTRY text. Allout recognizes the outline structure according
  1690. to the strict PREFIX format. It consists of a PREFIX-LEAD string,
  1691. PREFIX-PADDING, and a BULLET. The BULLET might be followed by a
  1692. number, indicating the ordinal number of the topic among its
  1693. siblings, or an asterisk indicating encryption, plus an optional
  1694. space. After that is the ITEM HEADER text, which is not part of
  1695. the PREFIX.
  1696. The relative length of the PREFIX determines the nesting DEPTH
  1697. of the ITEM.
  1698. PREFIX-LEAD:
  1699. The string at the beginning of a HEADER PREFIX, by default a `.'.
  1700. It can be customized by changing the setting of
  1701. `allout-header-prefix' and then reinitializing `allout-mode'.
  1702. When the PREFIX-LEAD is set to the comment-string of a
  1703. programming language, outline structuring can be embedded in
  1704. program code without interfering with processing of the text
  1705. (by Emacs or the language processor) as program code. This
  1706. setting happens automatically when allout mode is used in
  1707. programming-mode buffers. See `allout-use-mode-specific-leader'
  1708. docstring for more detail.
  1709. PREFIX-PADDING:
  1710. Spaces or asterisks which separate the PREFIX-LEAD and the
  1711. bullet, determining the ITEM's DEPTH.
  1712. BULLET: A character at the end of the ITEM PREFIX, it must be one of
  1713. the characters listed on `allout-plain-bullets-string' or
  1714. `allout-distinctive-bullets-string'. When creating a TOPIC,
  1715. plain BULLETs are by default used, according to the DEPTH of the
  1716. TOPIC. Choice among the distinctive BULLETs is offered when you
  1717. provide a universal argument (\\[universal-argument]) to the
  1718. TOPIC creation command, or when explicitly rebulleting a TOPIC. The
  1719. significance of the various distinctive bullets is purely by
  1720. convention. See the documentation for the above bullet strings for
  1721. more details.
  1722. EXPOSURE:
  1723. The state of a TOPIC which determines the on-screen visibility
  1724. of its OFFSPRING and contained ENTRY text.
  1725. CONCEALED:
  1726. TOPICs and ENTRY text whose EXPOSURE is inhibited. Concealed
  1727. text is represented by \"...\" ellipses.
  1728. CONCEALED TOPICs are effectively collapsed within an ANCESTOR.
  1729. CLOSED: A TOPIC whose immediate OFFSPRING and body-text is CONCEALED.
  1730. OPEN: A TOPIC that is not CLOSED, though its OFFSPRING or BODY may be."
  1731. ;;;_ . Code
  1732. :lighter " Allout"
  1733. :keymap 'allout-mode-map
  1734. (let ((use-layout (if (listp allout-layout)
  1735. allout-layout
  1736. allout-default-layout)))
  1737. (if (not (allout-mode-p))
  1738. (progn
  1739. ;; Deactivation:
  1740. ; Activation not explicitly
  1741. ; requested, and either in
  1742. ; active state or *de*activation
  1743. ; specifically requested:
  1744. (allout-do-resumptions)
  1745. (remove-from-invisibility-spec '(allout . t))
  1746. (remove-hook 'pre-command-hook 'allout-pre-command-business t)
  1747. (remove-hook 'post-command-hook 'allout-post-command-business t)
  1748. (remove-hook 'before-change-functions 'allout-before-change-handler t)
  1749. (remove-hook 'isearch-mode-end-hook 'allout-isearch-end-handler t)
  1750. (remove-hook 'write-contents-functions
  1751. 'allout-write-contents-hook-handler t)
  1752. (remove-overlays (point-min) (point-max)
  1753. 'category 'allout-exposure-category))
  1754. ;; Activating:
  1755. (if allout-old-style-prefixes
  1756. ;; Inhibit all the fancy formatting:
  1757. (allout-add-resumptions '(allout-primary-bullet "*")))
  1758. (allout-overlay-preparations) ; Doesn't hurt to redo this.
  1759. (allout-infer-header-lead-and-primary-bullet)
  1760. (allout-infer-body-reindent)
  1761. (set-allout-regexp)
  1762. (allout-add-resumptions '(allout-encryption-ciphertext-rejection-regexps
  1763. allout-line-boundary-regexp
  1764. extend)
  1765. '(allout-encryption-ciphertext-rejection-regexps
  1766. allout-bob-regexp
  1767. extend))
  1768. (allout-compose-and-institute-keymap)
  1769. (produce-allout-mode-menubar-entries)
  1770. (add-to-invisibility-spec '(allout . t))
  1771. (allout-add-resumptions '(line-move-ignore-invisible t))
  1772. (add-hook 'pre-command-hook 'allout-pre-command-business nil t)
  1773. (add-hook 'post-command-hook 'allout-post-command-business nil t)
  1774. (add-hook 'before-change-functions 'allout-before-change-handler nil t)
  1775. (add-hook 'isearch-mode-end-hook 'allout-isearch-end-handler nil t)
  1776. (add-hook 'write-contents-functions 'allout-write-contents-hook-handler
  1777. nil t)
  1778. ;; Stash auto-fill settings and adjust so custom allout auto-fill
  1779. ;; func will be used if auto-fill is active or activated. (The
  1780. ;; custom func respects topic headline, maintains hanging-indents,
  1781. ;; etc.)
  1782. (allout-add-resumptions (list 'allout-former-auto-filler
  1783. auto-fill-function)
  1784. ;; Register allout-auto-fill to be used if
  1785. ;; filling is active:
  1786. (list 'allout-outside-normal-auto-fill-function
  1787. normal-auto-fill-function)
  1788. '(normal-auto-fill-function allout-auto-fill)
  1789. ;; Paragraphs are broken by topic headlines.
  1790. (list 'paragraph-start
  1791. (concat paragraph-start "\\|^\\("
  1792. allout-regexp "\\)"))
  1793. (list 'paragraph-separate
  1794. (concat paragraph-separate "\\|^\\("
  1795. allout-regexp "\\)")))
  1796. (if (and auto-fill-function (not allout-inhibit-auto-fill))
  1797. ;; allout-auto-fill will use the stashed values and so forth.
  1798. (allout-add-resumptions '(auto-fill-function allout-auto-fill)))
  1799. (allout-setup-menubar)
  1800. ;; Do auto layout if warranted:
  1801. (when (and allout-layout
  1802. allout-auto-activation
  1803. use-layout
  1804. (and (not (string= allout-auto-activation "activate"))
  1805. (if (string= allout-auto-activation "ask")
  1806. (if (y-or-n-p (format "Expose %s with layout '%s'? "
  1807. (buffer-name)
  1808. use-layout))
  1809. t
  1810. (message "Skipped %s layout." (buffer-name))
  1811. nil)
  1812. t)))
  1813. (save-excursion
  1814. (message "Adjusting '%s' exposure..." (buffer-name))
  1815. (goto-char 0)
  1816. (allout-this-or-next-heading)
  1817. (condition-case err
  1818. (progn
  1819. (apply 'allout-expose-topic (list use-layout))
  1820. (message "Adjusting '%s' exposure... done."
  1821. (buffer-name)))
  1822. ;; Problem applying exposure -- notify user, but don't
  1823. ;; interrupt, eg, file visit:
  1824. (error (message "%s" (car (cdr err)))
  1825. (sit-for 1))))
  1826. ) ; when allout-layout
  1827. ) ; if (allout-mode-p)
  1828. ) ; let (())
  1829. ) ; define-minor-mode
  1830. ;;;_ > allout-minor-mode alias
  1831. (defalias 'allout-minor-mode 'allout-mode)
  1832. ;;;_ > allout-unload-function
  1833. (defun allout-unload-function ()
  1834. "Unload the allout outline library."
  1835. (save-current-buffer
  1836. (dolist (buffer (buffer-list))
  1837. (set-buffer buffer)
  1838. (when (allout-mode-p) (allout-mode -1))))
  1839. ;; continue standard unloading
  1840. nil)
  1841. ;;;_ - Position Assessment
  1842. ;;;_ > allout-hidden-p (&optional pos)
  1843. (defsubst allout-hidden-p (&optional pos)
  1844. "Non-nil if the character after point was made invisible by allout."
  1845. (eq (get-char-property (or pos (point)) 'invisible) 'allout))
  1846. ;;;_ > allout-overlay-insert-in-front-handler (ol after beg end
  1847. ;;; &optional prelen)
  1848. (defun allout-overlay-insert-in-front-handler (ol after beg end
  1849. &optional prelen)
  1850. "Shift the overlay so stuff inserted in front of it is excluded."
  1851. (if after
  1852. ;; ??? Shouldn't moving the overlay should be unnecessary, if overlay
  1853. ;; front-advance on the overlay worked as expected?
  1854. (move-overlay ol (1+ beg) (overlay-end ol))))
  1855. ;;;_ > allout-overlay-interior-modification-handler (ol after beg end
  1856. ;;; &optional prelen)
  1857. (defun allout-overlay-interior-modification-handler (ol after beg end
  1858. &optional prelen)
  1859. "Get confirmation before making arbitrary changes to invisible text.
  1860. We expose the invisible text and ask for confirmation. Refusal or
  1861. `keyboard-quit' abandons the changes, with keyboard-quit additionally
  1862. reclosing the opened text.
  1863. No confirmation is necessary when `inhibit-read-only' is set -- eg, allout
  1864. internal functions use this feature cohesively bunch changes."
  1865. (when (and (not inhibit-read-only) (not after))
  1866. (let ((start (point))
  1867. (ol-start (overlay-start ol))
  1868. (ol-end (overlay-end ol))
  1869. first)
  1870. (goto-char beg)
  1871. (while (< (point) end)
  1872. (when (allout-hidden-p)
  1873. (allout-show-to-offshoot)
  1874. (if (allout-hidden-p)
  1875. (save-excursion (forward-char 1)
  1876. (allout-show-to-offshoot)))
  1877. (when (not first)
  1878. (setq first (point))))
  1879. (goto-char (if (featurep 'xemacs)
  1880. (next-property-change (1+ (point)) nil end)
  1881. (next-char-property-change (1+ (point)) end))))
  1882. (when first
  1883. (goto-char first)
  1884. (condition-case nil
  1885. (if (not
  1886. (yes-or-no-p
  1887. (substitute-command-keys
  1888. (concat "Modify concealed text? (\"no\" just aborts,"
  1889. " \\[keyboard-quit] also reconceals) "))))
  1890. (progn (goto-char start)
  1891. (error "Concealed-text change refused")))
  1892. (quit (allout-flag-region ol-start ol-end nil)
  1893. (allout-flag-region ol-start ol-end t)
  1894. (error "Concealed-text change abandoned, text reconcealed"))))
  1895. (goto-char start))))
  1896. ;;;_ > allout-before-change-handler (beg end)
  1897. (defun allout-before-change-handler (beg end)
  1898. "Protect against changes to invisible text.
  1899. See `allout-overlay-interior-modification-handler' for details."
  1900. (when (and (allout-mode-p) undo-in-progress)
  1901. (setq allout-just-did-undo t)
  1902. (if (allout-hidden-p)
  1903. (allout-show-children)))
  1904. ;; allout-overlay-interior-modification-handler on an overlay handles
  1905. ;; this in other emacs, via `allout-exposure-category's 'modification-hooks.
  1906. (when (and (featurep 'xemacs) (allout-mode-p))
  1907. ;; process all of the pending overlays:
  1908. (save-excursion
  1909. (goto-char beg)
  1910. (let ((overlay (allout-get-invisibility-overlay)))
  1911. (if overlay
  1912. (allout-overlay-interior-modification-handler
  1913. overlay nil beg end nil))))))
  1914. ;;;_ > allout-isearch-end-handler (&optional overlay)
  1915. (defun allout-isearch-end-handler (&optional overlay)
  1916. "Reconcile allout outline exposure on arriving in hidden text after isearch.
  1917. Optional OVERLAY parameter is for when this function is used by
  1918. `isearch-open-invisible' overlay property. It is otherwise unused, so this
  1919. function can also be used as an `isearch-mode-end-hook'."
  1920. (if (and (allout-mode-p) (allout-hidden-p))
  1921. (allout-show-to-offshoot)))
  1922. ;;;_ #3 Internal Position State-Tracking -- "allout-recent-*" funcs
  1923. ;; All the basic outline functions that directly do string matches to
  1924. ;; evaluate heading prefix location set the variables
  1925. ;; `allout-recent-prefix-beginning' and `allout-recent-prefix-end'
  1926. ;; when successful. Functions starting with `allout-recent-' all
  1927. ;; use this state, providing the means to avoid redundant searches
  1928. ;; for just-established data. This optimization can provide
  1929. ;; significant speed improvement, but it must be employed carefully.
  1930. ;;;_ = allout-recent-prefix-beginning
  1931. (defvar allout-recent-prefix-beginning 0
  1932. "Buffer point of the start of the last topic prefix encountered.")
  1933. (make-variable-buffer-local 'allout-recent-prefix-beginning)
  1934. ;;;_ = allout-recent-prefix-end
  1935. (defvar allout-recent-prefix-end 0
  1936. "Buffer point of the end of the last topic prefix encountered.")
  1937. (make-variable-buffer-local 'allout-recent-prefix-end)
  1938. ;;;_ = allout-recent-depth
  1939. (defvar allout-recent-depth 0
  1940. "Depth of the last topic prefix encountered.")
  1941. (make-variable-buffer-local 'allout-recent-depth)
  1942. ;;;_ = allout-recent-end-of-subtree
  1943. (defvar allout-recent-end-of-subtree 0
  1944. "Buffer point last returned by `allout-end-of-current-subtree'.")
  1945. (make-variable-buffer-local 'allout-recent-end-of-subtree)
  1946. ;;;_ > allout-prefix-data ()
  1947. (defsubst allout-prefix-data ()
  1948. "Register allout-prefix state data.
  1949. For reference by `allout-recent' funcs. Return
  1950. the new value of `allout-recent-prefix-beginning'."
  1951. (setq allout-recent-prefix-end (or (match-end 1) (match-end 2) (match-end 3))
  1952. allout-recent-prefix-beginning (or (match-beginning 1)
  1953. (match-beginning 2)
  1954. (match-beginning 3))
  1955. allout-recent-depth (max 1 (- allout-recent-prefix-end
  1956. allout-recent-prefix-beginning
  1957. allout-header-subtraction)))
  1958. allout-recent-prefix-beginning)
  1959. ;;;_ > nullify-allout-prefix-data ()
  1960. (defsubst nullify-allout-prefix-data ()
  1961. "Mark allout prefix data as being uninformative."
  1962. (setq allout-recent-prefix-end (point)
  1963. allout-recent-prefix-beginning (point)
  1964. allout-recent-depth 0)
  1965. allout-recent-prefix-beginning)
  1966. ;;;_ > allout-recent-depth ()
  1967. (defsubst allout-recent-depth ()
  1968. "Return depth of last heading encountered by an outline maneuvering function.
  1969. All outline functions which directly do string matches to assess
  1970. headings set the variables `allout-recent-prefix-beginning' and
  1971. `allout-recent-prefix-end' if successful. This function uses those settings
  1972. to return the current depth."
  1973. allout-recent-depth)
  1974. ;;;_ > allout-recent-prefix ()
  1975. (defsubst allout-recent-prefix ()
  1976. "Like `allout-recent-depth', but returns text of last encountered prefix.
  1977. All outline functions which directly do string matches to assess
  1978. headings set the variables `allout-recent-prefix-beginning' and
  1979. `allout-recent-prefix-end' if successful. This function uses those settings
  1980. to return the current prefix."
  1981. (buffer-substring-no-properties allout-recent-prefix-beginning
  1982. allout-recent-prefix-end))
  1983. ;;;_ > allout-recent-bullet ()
  1984. (defmacro allout-recent-bullet ()
  1985. "Like `allout-recent-prefix', but returns bullet of last encountered prefix.
  1986. All outline functions which directly do string matches to assess
  1987. headings set the variables `allout-recent-prefix-beginning' and
  1988. `allout-recent-prefix-end' if successful. This function uses those settings
  1989. to return the current depth of the most recently matched topic."
  1990. '(buffer-substring-no-properties (1- allout-recent-prefix-end)
  1991. allout-recent-prefix-end))
  1992. ;;;_ #4 Navigation
  1993. ;;;_ - Position Assessment
  1994. ;;;_ : Location Predicates
  1995. ;;;_ > allout-do-doublecheck ()
  1996. (defsubst allout-do-doublecheck ()
  1997. "True if current item conditions qualify for checking on topic aberrance."
  1998. (and
  1999. ;; presume integrity of outline and yanked content during yank -- necessary
  2000. ;; to allow for level disparity of yank location and yanked text:
  2001. (not allout-inhibit-aberrance-doublecheck)
  2002. ;; allout-doublecheck-at-and-shallower is ceiling for doublecheck:
  2003. (<= allout-recent-depth allout-doublecheck-at-and-shallower)))
  2004. ;;;_ > allout-aberrant-container-p ()
  2005. (defun allout-aberrant-container-p ()
  2006. "True if topic, or next sibling with children, contains them discontinuously.
  2007. Discontinuous means an immediate offspring that is nested more
  2008. than one level deeper than the topic.
  2009. If topic has no offspring, then the next sibling with offspring will
  2010. determine whether or not this one is determined to be aberrant.
  2011. If true, then the allout-recent-* settings are calibrated on the
  2012. offspring that qualifies it as aberrant, ie with depth that
  2013. exceeds the topic by more than one."
  2014. ;; This is most clearly understood when considering standard-prefix-leader
  2015. ;; low-level topics, which can all too easily match text not intended as
  2016. ;; headers. For example, any line with a leading '.' or '*' and lacking a
  2017. ;; following bullet qualifies without this protection. (A sequence of
  2018. ;; them can occur naturally, eg a typical textual bullet list.) We
  2019. ;; disqualify such low-level sequences when they are followed by a
  2020. ;; discontinuously contained child, inferring that the sequences are not
  2021. ;; actually connected with their prospective context.
  2022. (let ((depth (allout-depth))
  2023. (start-point (point))
  2024. done aberrant)
  2025. (save-match-data
  2026. (save-excursion
  2027. (while (and (not done)
  2028. (re-search-forward allout-line-boundary-regexp nil 0))
  2029. (allout-prefix-data)
  2030. (goto-char allout-recent-prefix-beginning)
  2031. (cond
  2032. ;; sibling -- continue:
  2033. ((eq allout-recent-depth depth))
  2034. ;; first offspring is excessive -- aberrant:
  2035. ((> allout-recent-depth (1+ depth))
  2036. (setq done t aberrant t))
  2037. ;; next non-sibling is lower-depth -- not aberrant:
  2038. (t (setq done t))))))
  2039. (if aberrant
  2040. aberrant
  2041. (goto-char start-point)
  2042. ;; recalibrate allout-recent-*
  2043. (allout-depth)
  2044. nil)))
  2045. ;;;_ > allout-on-current-heading-p ()
  2046. (defun allout-on-current-heading-p ()
  2047. "Return non-nil if point is on current visible topics' header line.
  2048. Actually, returns prefix beginning point."
  2049. (save-excursion
  2050. (allout-beginning-of-current-line)
  2051. (save-match-data
  2052. (and (looking-at allout-regexp)
  2053. (allout-prefix-data)
  2054. (or (not (allout-do-doublecheck))
  2055. (not (allout-aberrant-container-p)))))))
  2056. ;;;_ > allout-on-heading-p ()
  2057. (defalias 'allout-on-heading-p 'allout-on-current-heading-p)
  2058. ;;;_ > allout-e-o-prefix-p ()
  2059. (defun allout-e-o-prefix-p ()
  2060. "True if point is located where current topic prefix ends, heading begins."
  2061. (and (save-match-data
  2062. (save-excursion (let ((inhibit-field-text-motion t))
  2063. (beginning-of-line))
  2064. (looking-at allout-regexp))
  2065. (= (point) (save-excursion (allout-end-of-prefix)(point))))))
  2066. ;;;_ : Location attributes
  2067. ;;;_ > allout-depth ()
  2068. (defun allout-depth ()
  2069. "Return depth of topic most immediately containing point.
  2070. Does not do doublecheck for aberrant topic header.
  2071. Return zero if point is not within any topic.
  2072. Like `allout-current-depth', but respects hidden as well as visible topics."
  2073. (save-excursion
  2074. (let ((start-point (point)))
  2075. (if (and (allout-goto-prefix)
  2076. (not (< start-point (point))))
  2077. allout-recent-depth
  2078. (progn
  2079. ;; Oops, no prefix, nullify it:
  2080. (nullify-allout-prefix-data)
  2081. ;; ... and return 0:
  2082. 0)))))
  2083. ;;;_ > allout-current-depth ()
  2084. (defun allout-current-depth ()
  2085. "Return depth of visible topic most immediately containing point.
  2086. Return zero if point is not within any topic."
  2087. (save-excursion
  2088. (if (allout-back-to-current-heading)
  2089. (max 1
  2090. (- allout-recent-prefix-end
  2091. allout-recent-prefix-beginning
  2092. allout-header-subtraction))
  2093. 0)))
  2094. ;;;_ > allout-get-current-prefix ()
  2095. (defun allout-get-current-prefix ()
  2096. "Topic prefix of the current topic."
  2097. (save-excursion
  2098. (if (allout-goto-prefix)
  2099. (allout-recent-prefix))))
  2100. ;;;_ > allout-get-bullet ()
  2101. (defun allout-get-bullet ()
  2102. "Return bullet of containing topic (visible or not)."
  2103. (save-excursion
  2104. (and (allout-goto-prefix)
  2105. (allout-recent-bullet))))
  2106. ;;;_ > allout-current-bullet ()
  2107. (defun allout-current-bullet ()
  2108. "Return bullet of current (visible) topic heading, or none if none found."
  2109. (condition-case nil
  2110. (save-excursion
  2111. (allout-back-to-current-heading)
  2112. (buffer-substring-no-properties (- allout-recent-prefix-end 1)
  2113. allout-recent-prefix-end))
  2114. ;; Quick and dirty provision, ostensibly for missing bullet:
  2115. (args-out-of-range nil))
  2116. )
  2117. ;;;_ > allout-get-prefix-bullet (prefix)
  2118. (defun allout-get-prefix-bullet (prefix)
  2119. "Return the bullet of the header prefix string PREFIX."
  2120. ;; Doesn't make sense if we're old-style prefixes, but this just
  2121. ;; oughtn't be called then, so forget about it...
  2122. (if (string-match allout-regexp prefix)
  2123. (substring prefix (1- (match-end 2)) (match-end 2))))
  2124. ;;;_ > allout-sibling-index (&optional depth)
  2125. (defun allout-sibling-index (&optional depth)
  2126. "Item number of this prospective topic among its siblings.
  2127. If optional arg DEPTH is greater than current depth, then we're
  2128. opening a new level, and return 0.
  2129. If less than this depth, ascend to that depth and count..."
  2130. (save-excursion
  2131. (cond ((and depth (<= depth 0) 0))
  2132. ((or (null depth) (= depth (allout-depth)))
  2133. (let ((index 1))
  2134. (while (allout-previous-sibling allout-recent-depth nil)
  2135. (setq index (1+ index)))
  2136. index))
  2137. ((< depth allout-recent-depth)
  2138. (allout-ascend-to-depth depth)
  2139. (allout-sibling-index))
  2140. (0))))
  2141. ;;;_ > allout-topic-flat-index ()
  2142. (defun allout-topic-flat-index ()
  2143. "Return a list indicating point's numeric section.subsect.subsubsect...
  2144. Outermost is first."
  2145. (let* ((depth (allout-depth))
  2146. (next-index (allout-sibling-index depth))
  2147. (rev-sibls nil))
  2148. (while (> next-index 0)
  2149. (setq rev-sibls (cons next-index rev-sibls))
  2150. (setq depth (1- depth))
  2151. (setq next-index (allout-sibling-index depth)))
  2152. rev-sibls)
  2153. )
  2154. ;;;_ - Navigation routines
  2155. ;;;_ > allout-beginning-of-current-line ()
  2156. (defun allout-beginning-of-current-line ()
  2157. "Like beginning of line, but to visible text."
  2158. ;; This combination of move-beginning-of-line and beginning-of-line is
  2159. ;; deliberate, but the (beginning-of-line) may now be superfluous.
  2160. (let ((inhibit-field-text-motion t))
  2161. (move-beginning-of-line 1)
  2162. (beginning-of-line)
  2163. (while (and (not (bobp)) (or (not (bolp)) (allout-hidden-p)))
  2164. (beginning-of-line)
  2165. (if (or (allout-hidden-p) (not (bolp)))
  2166. (forward-char -1)))))
  2167. ;;;_ > allout-end-of-current-line ()
  2168. (defun allout-end-of-current-line ()
  2169. "Move to the end of line, past concealed text if any."
  2170. ;; This is for symmetry with `allout-beginning-of-current-line' --
  2171. ;; `move-end-of-line' doesn't suffer the same problem as
  2172. ;; `move-beginning-of-line'.
  2173. (let ((inhibit-field-text-motion t))
  2174. (end-of-line)
  2175. (while (allout-hidden-p)
  2176. (end-of-line)
  2177. (if (allout-hidden-p) (forward-char 1)))))
  2178. ;;;_ > allout-beginning-of-line ()
  2179. (defun allout-beginning-of-line ()
  2180. "Beginning-of-line with `allout-beginning-of-line-cycles' behavior, if set."
  2181. (interactive)
  2182. (if (or (not allout-beginning-of-line-cycles)
  2183. (not (equal last-command this-command)))
  2184. (progn
  2185. (if (and (not (bolp))
  2186. (allout-hidden-p (1- (point))))
  2187. (goto-char (allout-previous-single-char-property-change
  2188. (1- (point)) 'invisible)))
  2189. (move-beginning-of-line 1))
  2190. (allout-depth)
  2191. (let ((beginning-of-body
  2192. (save-excursion
  2193. (while (and (allout-do-doublecheck)
  2194. (allout-aberrant-container-p)
  2195. (allout-previous-visible-heading 1)))
  2196. (allout-beginning-of-current-entry)
  2197. (point))))
  2198. (cond ((= (current-column) 0)
  2199. (goto-char beginning-of-body))
  2200. ((< (point) beginning-of-body)
  2201. (allout-beginning-of-current-line))
  2202. ((= (point) beginning-of-body)
  2203. (goto-char (allout-current-bullet-pos)))
  2204. (t (allout-beginning-of-current-line)
  2205. (if (< (point) beginning-of-body)
  2206. ;; we were on the headline after its start:
  2207. (goto-char beginning-of-body)))))))
  2208. ;;;_ > allout-end-of-line ()
  2209. (defun allout-end-of-line ()
  2210. "End-of-line with `allout-end-of-line-cycles' behavior, if set."
  2211. (interactive)
  2212. (if (or (not allout-end-of-line-cycles)
  2213. (not (equal last-command this-command)))
  2214. (allout-end-of-current-line)
  2215. (let ((end-of-entry (save-excursion
  2216. (allout-end-of-entry)
  2217. (point))))
  2218. (cond ((not (eolp))
  2219. (allout-end-of-current-line))
  2220. ((or (allout-hidden-p) (save-excursion
  2221. (forward-char -1)
  2222. (allout-hidden-p)))
  2223. (allout-back-to-current-heading)
  2224. (allout-show-current-entry)
  2225. (allout-show-children)
  2226. (allout-end-of-entry))
  2227. ((>= (point) end-of-entry)
  2228. (allout-back-to-current-heading)
  2229. (allout-end-of-current-line))
  2230. (t
  2231. (if (not (allout-mark-active-p))
  2232. (push-mark))
  2233. (allout-end-of-entry))))))
  2234. ;;;_ > allout-mark-active-p ()
  2235. (defun allout-mark-active-p ()
  2236. "True if the mark is currently or always active."
  2237. ;; `(cond (boundp...))' (or `(if ...)') invokes special byte-compiler
  2238. ;; provisions, at least in GNU Emacs to prevent warnings about lack of,
  2239. ;; eg, region-active-p.
  2240. (cond ((boundp 'mark-active)
  2241. mark-active)
  2242. ((fboundp 'region-active-p)
  2243. (region-active-p))
  2244. (t)))
  2245. ;;;_ > allout-next-heading ()
  2246. (defsubst allout-next-heading ()
  2247. "Move to the heading for the topic (possibly invisible) after this one.
  2248. Returns the location of the heading, or nil if none found.
  2249. We skip anomalous low-level topics, a la `allout-aberrant-container-p'."
  2250. (save-match-data
  2251. (if (looking-at allout-regexp)
  2252. (forward-char 1))
  2253. (when (re-search-forward allout-line-boundary-regexp nil 0)
  2254. (allout-prefix-data)
  2255. (goto-char allout-recent-prefix-beginning)
  2256. (while (not (bolp))
  2257. (forward-char -1))
  2258. (and (allout-do-doublecheck)
  2259. ;; this will set allout-recent-* on the first non-aberrant topic,
  2260. ;; whether it's the current one or one that disqualifies it:
  2261. (allout-aberrant-container-p))
  2262. ;; this may or may not be the same as above depending on doublecheck:
  2263. (goto-char allout-recent-prefix-beginning))))
  2264. ;;;_ > allout-this-or-next-heading
  2265. (defun allout-this-or-next-heading ()
  2266. "Position cursor on current or next heading."
  2267. ;; A throwaway non-macro that is defined after allout-next-heading
  2268. ;; and usable by allout-mode.
  2269. (if (not (allout-goto-prefix-doublechecked)) (allout-next-heading)))
  2270. ;;;_ > allout-previous-heading ()
  2271. (defun allout-previous-heading ()
  2272. "Move to the prior (possibly invisible) heading line.
  2273. Return the location of the beginning of the heading, or nil if not found.
  2274. We skip anomalous low-level topics, a la `allout-aberrant-container-p'."
  2275. (if (bobp)
  2276. nil
  2277. (let ((start-point (point)))
  2278. ;; allout-goto-prefix-doublechecked calls us, so we can't use it here.
  2279. (allout-goto-prefix)
  2280. (save-match-data
  2281. (when (or (re-search-backward allout-line-boundary-regexp nil 0)
  2282. (looking-at allout-bob-regexp))
  2283. (goto-char (allout-prefix-data))
  2284. (if (and (allout-do-doublecheck)
  2285. (allout-aberrant-container-p))
  2286. (or (allout-previous-heading)
  2287. (and (goto-char start-point)
  2288. ;; recalibrate allout-recent-*:
  2289. (allout-depth)
  2290. nil))
  2291. (point)))))))
  2292. ;;;_ > allout-get-invisibility-overlay ()
  2293. (defun allout-get-invisibility-overlay ()
  2294. "Return the overlay at point that dictates allout invisibility."
  2295. (let ((overlays (overlays-at (point)))
  2296. got)
  2297. (while (and overlays (not got))
  2298. (if (equal (overlay-get (car overlays) 'invisible) 'allout)
  2299. (setq got (car overlays))
  2300. (pop overlays)))
  2301. got))
  2302. ;;;_ > allout-back-to-visible-text ()
  2303. (defun allout-back-to-visible-text ()
  2304. "Move to most recent prior character that is visible, and return point."
  2305. (if (allout-hidden-p)
  2306. (goto-char (overlay-start (allout-get-invisibility-overlay))))
  2307. (point))
  2308. ;;;_ - Subtree Charting
  2309. ;;;_ " These routines either produce or assess charts, which are
  2310. ;;; nested lists of the locations of topics within a subtree.
  2311. ;;;
  2312. ;;; Charts enable efficient subtree navigation by providing a reusable basis
  2313. ;;; for elaborate, compound assessment and adjustment of a subtree.
  2314. ;;;_ > allout-chart-subtree (&optional levels visible orig-depth prev-depth)
  2315. (defun allout-chart-subtree (&optional levels visible orig-depth prev-depth)
  2316. "Produce a location \"chart\" of subtopics of the containing topic.
  2317. Optional argument LEVELS specifies a depth limit (relative to start
  2318. depth) for the chart. Null LEVELS means no limit.
  2319. When optional argument VISIBLE is non-nil, the chart includes
  2320. only the visible subelements of the charted subjects.
  2321. The remaining optional args are for internal use by the function.
  2322. Point is left at the end of the subtree.
  2323. Charts are used to capture outline structure, so that outline-altering
  2324. routines need to assess the structure only once, and then use the chart
  2325. for their elaborate manipulations.
  2326. The chart entries for the topics are in reverse order, so the
  2327. last topic is listed first. The entry for each topic consists of
  2328. an integer indicating the point at the beginning of the topic
  2329. prefix. Charts for offspring consist of a list containing,
  2330. recursively, the charts for the respective subtopics. The chart
  2331. for a topics' offspring precedes the entry for the topic itself.
  2332. The other function parameters are for internal recursion, and should
  2333. not be specified by external callers. ORIG-DEPTH is depth of topic at
  2334. starting point, and PREV-DEPTH is depth of prior topic."
  2335. (let ((original (not orig-depth)) ; `orig-depth' set only in recursion.
  2336. chart curr-depth)
  2337. (if original ; Just starting?
  2338. ; Register initial settings and
  2339. ; position to first offspring:
  2340. (progn (setq orig-depth (allout-depth))
  2341. (or prev-depth (setq prev-depth (1+ orig-depth)))
  2342. (if visible
  2343. (allout-next-visible-heading 1)
  2344. (allout-next-heading))))
  2345. ;; Loop over the current levels' siblings. Besides being more
  2346. ;; efficient than tail-recursing over a level, it avoids exceeding
  2347. ;; the typically quite constrained Emacs max-lisp-eval-depth.
  2348. ;;
  2349. ;; Probably would speed things up to implement loop-based stack
  2350. ;; operation rather than recursing for lower levels. Bah.
  2351. (while (and (not (eobp))
  2352. ; Still within original topic?
  2353. (< orig-depth (setq curr-depth allout-recent-depth))
  2354. (cond ((= prev-depth curr-depth)
  2355. ;; Register this one and move on:
  2356. (setq chart (cons allout-recent-prefix-beginning chart))
  2357. (if (and levels (<= levels 1))
  2358. ;; At depth limit -- skip sublevels:
  2359. (or (allout-next-sibling curr-depth)
  2360. ;; or no more siblings -- proceed to
  2361. ;; next heading at lesser depth:
  2362. (while (and (<= curr-depth
  2363. allout-recent-depth)
  2364. (if visible
  2365. (allout-next-visible-heading 1)
  2366. (allout-next-heading)))))
  2367. (if visible
  2368. (allout-next-visible-heading 1)
  2369. (allout-next-heading))))
  2370. ((and (< prev-depth curr-depth)
  2371. (or (not levels)
  2372. (> levels 0)))
  2373. ;; Recurse on deeper level of curr topic:
  2374. (setq chart
  2375. (cons (allout-chart-subtree (and levels
  2376. (1- levels))
  2377. visible
  2378. orig-depth
  2379. curr-depth)
  2380. chart))
  2381. ;; ... then continue with this one.
  2382. )
  2383. ;; ... else nil if we've ascended back to prev-depth.
  2384. )))
  2385. (if original ; We're at the last sibling on
  2386. ; the original level. Position
  2387. ; to the end of it:
  2388. (progn (and (not (eobp)) (forward-char -1))
  2389. (and (= (preceding-char) ?\n)
  2390. (= (aref (buffer-substring (max 1 (- (point) 3))
  2391. (point))
  2392. 1)
  2393. ?\n)
  2394. (forward-char -1))
  2395. (setq allout-recent-end-of-subtree (point))))
  2396. chart ; (nreverse chart) not necessary,
  2397. ; and maybe not preferable.
  2398. ))
  2399. ;;;_ > allout-chart-siblings (&optional start end)
  2400. (defun allout-chart-siblings (&optional start end)
  2401. "Produce a list of locations of this and succeeding sibling topics.
  2402. Effectively a top-level chart of siblings. See `allout-chart-subtree'
  2403. for an explanation of charts."
  2404. (save-excursion
  2405. (when (allout-goto-prefix-doublechecked)
  2406. (let ((chart (list (point))))
  2407. (while (allout-next-sibling)
  2408. (setq chart (cons (point) chart)))
  2409. (if chart (setq chart (nreverse chart)))))))
  2410. ;;;_ > allout-chart-to-reveal (chart depth)
  2411. (defun allout-chart-to-reveal (chart depth)
  2412. "Return a flat list of hidden points in subtree CHART, up to DEPTH.
  2413. If DEPTH is nil, include hidden points at any depth.
  2414. Note that point can be left at any of the points on chart, or at the
  2415. start point."
  2416. (let (result here)
  2417. (while (and (or (null depth) (> depth 0))
  2418. chart)
  2419. (setq here (car chart))
  2420. (if (listp here)
  2421. (let ((further (allout-chart-to-reveal here (if (null depth)
  2422. depth
  2423. (1- depth)))))
  2424. ;; We're on the start of a subtree -- recurse with it, if there's
  2425. ;; more depth to go:
  2426. (if further (setq result (append further result)))
  2427. (setq chart (cdr chart)))
  2428. (goto-char here)
  2429. (if (allout-hidden-p)
  2430. (setq result (cons here result)))
  2431. (setq chart (cdr chart))))
  2432. result))
  2433. ;;;_ X allout-chart-spec (chart spec &optional exposing)
  2434. ;; (defun allout-chart-spec (chart spec &optional exposing)
  2435. ;; "Not yet (if ever) implemented.
  2436. ;; Produce exposure directives given topic/subtree CHART and an exposure SPEC.
  2437. ;; Exposure spec indicates the locations to be exposed and the prescribed
  2438. ;; exposure status. Optional arg EXPOSING is an integer, with 0
  2439. ;; indicating pending concealment, anything higher indicating depth to
  2440. ;; which subtopic headers should be exposed, and negative numbers
  2441. ;; indicating (negative of) the depth to which subtopic headers and
  2442. ;; bodies should be exposed.
  2443. ;; The produced list can have two types of entries. Bare numbers
  2444. ;; indicate points in the buffer where topic headers that should be
  2445. ;; exposed reside.
  2446. ;; - bare negative numbers indicates that the topic starting at the
  2447. ;; point which is the negative of the number should be opened,
  2448. ;; including their entries.
  2449. ;; - bare positive values indicate that this topic header should be
  2450. ;; opened.
  2451. ;; - Lists signify the beginning and end points of regions that should
  2452. ;; be flagged, and the flag to employ. (For concealment: `(\?r)', and
  2453. ;; exposure:"
  2454. ;; (while spec
  2455. ;; (cond ((listp spec)
  2456. ;; )
  2457. ;; )
  2458. ;; (setq spec (cdr spec)))
  2459. ;; )
  2460. ;;;_ - Within Topic
  2461. ;;;_ > allout-goto-prefix ()
  2462. (defun allout-goto-prefix ()
  2463. "Put point at beginning of immediately containing outline topic.
  2464. Goes to most immediate subsequent topic if none immediately containing.
  2465. Not sensitive to topic visibility.
  2466. Returns the point at the beginning of the prefix, or nil if none."
  2467. (save-match-data
  2468. (let (done)
  2469. (while (and (not done)
  2470. (search-backward "\n" nil 1))
  2471. (forward-char 1)
  2472. (if (looking-at allout-regexp)
  2473. (setq done (allout-prefix-data))
  2474. (forward-char -1)))
  2475. (if (bobp)
  2476. (cond ((looking-at allout-regexp)
  2477. (allout-prefix-data))
  2478. ((allout-next-heading))
  2479. (done))
  2480. done))))
  2481. ;;;_ > allout-goto-prefix-doublechecked ()
  2482. (defun allout-goto-prefix-doublechecked ()
  2483. "Put point at beginning of immediately containing outline topic.
  2484. Like `allout-goto-prefix', but shallow topics (according to
  2485. `allout-doublecheck-at-and-shallower') are checked and
  2486. disqualified for child containment discontinuity, according to
  2487. `allout-aberrant-container-p'."
  2488. (if (allout-goto-prefix)
  2489. (if (and (allout-do-doublecheck)
  2490. (allout-aberrant-container-p))
  2491. (allout-previous-heading)
  2492. (point))))
  2493. ;;;_ > allout-end-of-prefix ()
  2494. (defun allout-end-of-prefix (&optional ignore-decorations)
  2495. "Position cursor at beginning of header text.
  2496. If optional IGNORE-DECORATIONS is non-nil, put just after bullet,
  2497. otherwise skip white space between bullet and ensuing text."
  2498. (if (not (allout-goto-prefix-doublechecked))
  2499. nil
  2500. (goto-char allout-recent-prefix-end)
  2501. (save-match-data
  2502. (if ignore-decorations
  2503. t
  2504. (while (looking-at "[0-9]") (forward-char 1))
  2505. (if (and (not (eolp)) (looking-at "\\s-")) (forward-char 1))))
  2506. ;; Reestablish where we are:
  2507. (allout-current-depth)))
  2508. ;;;_ > allout-current-bullet-pos ()
  2509. (defun allout-current-bullet-pos ()
  2510. "Return position of current (visible) topic's bullet."
  2511. (if (not (allout-current-depth))
  2512. nil
  2513. (1- allout-recent-prefix-end)))
  2514. ;;;_ > allout-back-to-current-heading (&optional interactive)
  2515. (defun allout-back-to-current-heading (&optional interactive)
  2516. "Move to heading line of current topic, or beginning if not in a topic.
  2517. If interactive, we position at the end of the prefix.
  2518. Return value of resulting point, unless we started outside
  2519. of (before any) topics, in which case we return nil."
  2520. (interactive "p")
  2521. (allout-beginning-of-current-line)
  2522. (let ((bol-point (point)))
  2523. (when (allout-goto-prefix-doublechecked)
  2524. (if (<= (point) bol-point)
  2525. (progn
  2526. (setq bol-point (point))
  2527. (allout-beginning-of-current-line)
  2528. (if (not (= bol-point (point)))
  2529. (if (looking-at allout-regexp)
  2530. (allout-prefix-data)))
  2531. (if interactive
  2532. (allout-end-of-prefix)
  2533. (point)))
  2534. (goto-char (point-min))
  2535. nil))))
  2536. ;;;_ > allout-back-to-heading ()
  2537. (defalias 'allout-back-to-heading 'allout-back-to-current-heading)
  2538. ;;;_ > allout-pre-next-prefix ()
  2539. (defun allout-pre-next-prefix ()
  2540. "Skip forward to just before the next heading line.
  2541. Returns that character position."
  2542. (if (allout-next-heading)
  2543. (goto-char (1- allout-recent-prefix-beginning))))
  2544. ;;;_ > allout-end-of-subtree (&optional current include-trailing-blank)
  2545. (defun allout-end-of-subtree (&optional current include-trailing-blank)
  2546. "Put point at the end of the last leaf in the containing topic.
  2547. Optional CURRENT means put point at the end of the containing
  2548. visible topic.
  2549. Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if
  2550. any, as part of the subtree. Otherwise, that trailing blank will be
  2551. excluded as delimiting whitespace between topics.
  2552. Returns the value of point."
  2553. (interactive "P")
  2554. (if current
  2555. (allout-back-to-current-heading)
  2556. (allout-goto-prefix-doublechecked))
  2557. (let ((level allout-recent-depth))
  2558. (allout-next-heading)
  2559. (while (and (not (eobp))
  2560. (> allout-recent-depth level))
  2561. (allout-next-heading))
  2562. (if (eobp)
  2563. (allout-end-of-entry)
  2564. (forward-char -1))
  2565. (if (and (not include-trailing-blank) (= ?\n (preceding-char)))
  2566. (forward-char -1))
  2567. (setq allout-recent-end-of-subtree (point))))
  2568. ;;;_ > allout-end-of-current-subtree (&optional include-trailing-blank)
  2569. (defun allout-end-of-current-subtree (&optional include-trailing-blank)
  2570. "Put point at end of last leaf in currently visible containing topic.
  2571. Optional INCLUDE-TRAILING-BLANK means include a trailing blank line, if
  2572. any, as part of the subtree. Otherwise, that trailing blank will be
  2573. excluded as delimiting whitespace between topics.
  2574. Returns the value of point."
  2575. (interactive)
  2576. (allout-end-of-subtree t include-trailing-blank))
  2577. ;;;_ > allout-beginning-of-current-entry (&optional interactive)
  2578. (defun allout-beginning-of-current-entry (&optional interactive)
  2579. "When not already there, position point at beginning of current topic header.
  2580. If already there, move cursor to bullet for hot-spot operation.
  2581. \(See `allout-mode' doc string for details of hot-spot operation.)"
  2582. (interactive "p")
  2583. (let ((start-point (point)))
  2584. (move-beginning-of-line 1)
  2585. (if (< 0 (allout-current-depth))
  2586. (goto-char allout-recent-prefix-end)
  2587. (goto-char (point-min)))
  2588. (allout-end-of-prefix)
  2589. (if (and interactive
  2590. (= (point) start-point))
  2591. (goto-char (allout-current-bullet-pos)))))
  2592. ;;;_ > allout-end-of-entry (&optional inclusive)
  2593. (defun allout-end-of-entry (&optional inclusive)
  2594. "Position the point at the end of the current topics' entry.
  2595. Optional INCLUSIVE means also include trailing empty line, if any. When
  2596. unset, whitespace between items separates them even when the items are
  2597. collapsed."
  2598. (interactive)
  2599. (allout-pre-next-prefix)
  2600. (if (and (not inclusive) (not (bobp)) (= ?\n (preceding-char)))
  2601. (forward-char -1))
  2602. (point))
  2603. ;;;_ > allout-end-of-current-heading ()
  2604. (defun allout-end-of-current-heading ()
  2605. (interactive)
  2606. (allout-beginning-of-current-entry)
  2607. (search-forward "\n" nil t)
  2608. (forward-char -1))
  2609. (defalias 'allout-end-of-heading 'allout-end-of-current-heading)
  2610. ;;;_ > allout-get-body-text ()
  2611. (defun allout-get-body-text ()
  2612. "Return the unmangled body text of the topic immediately containing point."
  2613. (save-excursion
  2614. (allout-end-of-prefix)
  2615. (if (not (search-forward "\n" nil t))
  2616. nil
  2617. (backward-char 1)
  2618. (let ((pre-body (point)))
  2619. (if (not pre-body)
  2620. nil
  2621. (allout-end-of-entry t)
  2622. (if (not (= pre-body (point)))
  2623. (buffer-substring-no-properties (1+ pre-body) (point))))
  2624. )
  2625. )
  2626. )
  2627. )
  2628. ;;;_ - Depth-wise
  2629. ;;;_ > allout-ascend-to-depth (depth)
  2630. (defun allout-ascend-to-depth (depth)
  2631. "Ascend to depth DEPTH, returning depth if successful, nil if not."
  2632. (if (and (> depth 0)(<= depth (allout-depth)))
  2633. (let (last-ascended)
  2634. (while (and (< depth allout-recent-depth)
  2635. (setq last-ascended (allout-ascend))))
  2636. (goto-char allout-recent-prefix-beginning)
  2637. (if (allout-called-interactively-p) (allout-end-of-prefix))
  2638. (and last-ascended allout-recent-depth))))
  2639. ;;;_ > allout-ascend (&optional dont-move-if-unsuccessful)
  2640. (defun allout-ascend (&optional dont-move-if-unsuccessful)
  2641. "Ascend one level, returning resulting depth if successful, nil if not.
  2642. Point is left at the beginning of the level whether or not
  2643. successful, unless optional DONT-MOVE-IF-UNSUCCESSFUL is set, in
  2644. which case point is returned to its original starting location."
  2645. (if dont-move-if-unsuccessful
  2646. (setq dont-move-if-unsuccessful (point)))
  2647. (prog1
  2648. (if (allout-beginning-of-level)
  2649. (let ((bolevel (point))
  2650. (bolevel-depth allout-recent-depth))
  2651. (allout-previous-heading)
  2652. (cond ((< allout-recent-depth bolevel-depth)
  2653. allout-recent-depth)
  2654. ((= allout-recent-depth bolevel-depth)
  2655. (if dont-move-if-unsuccessful
  2656. (goto-char dont-move-if-unsuccessful))
  2657. (allout-depth)
  2658. nil)
  2659. (t
  2660. ;; some topic after very first is lower depth than first:
  2661. (goto-char bolevel)
  2662. (allout-depth)
  2663. nil))))
  2664. (if (allout-called-interactively-p) (allout-end-of-prefix))))
  2665. ;;;_ > allout-descend-to-depth (depth)
  2666. (defun allout-descend-to-depth (depth)
  2667. "Descend to depth DEPTH within current topic.
  2668. Returning depth if successful, nil if not."
  2669. (let ((start-point (point))
  2670. (start-depth (allout-depth)))
  2671. (while
  2672. (and (> (allout-depth) 0)
  2673. (not (= depth allout-recent-depth)) ; ... not there yet
  2674. (allout-next-heading) ; ... go further
  2675. (< start-depth allout-recent-depth))) ; ... still in topic
  2676. (if (and (> (allout-depth) 0)
  2677. (= allout-recent-depth depth))
  2678. depth
  2679. (goto-char start-point)
  2680. nil))
  2681. )
  2682. ;;;_ > allout-up-current-level (arg)
  2683. (defun allout-up-current-level (arg)
  2684. "Move out ARG levels from current visible topic."
  2685. (interactive "p")
  2686. (let ((start-point (point)))
  2687. (allout-back-to-current-heading)
  2688. (if (not (allout-ascend))
  2689. (progn (goto-char start-point)
  2690. (error "Can't ascend past outermost level"))
  2691. (if (allout-called-interactively-p) (allout-end-of-prefix))
  2692. allout-recent-prefix-beginning)))
  2693. ;;;_ - Linear
  2694. ;;;_ > allout-next-sibling (&optional depth backward)
  2695. (defun allout-next-sibling (&optional depth backward)
  2696. "Like `allout-forward-current-level', but respects invisible topics.
  2697. Traverse at optional DEPTH, or current depth if none specified.
  2698. Go backward if optional arg BACKWARD is non-nil.
  2699. Return the start point of the new topic if successful, nil otherwise."
  2700. (if (if backward (bobp) (eobp))
  2701. nil
  2702. (let ((target-depth (or depth (allout-depth)))
  2703. (start-point (point))
  2704. (start-prefix-beginning allout-recent-prefix-beginning)
  2705. (count 0)
  2706. leaping
  2707. last-depth)
  2708. (while (and
  2709. ;; done too few single steps to resort to the leap routine:
  2710. (not leaping)
  2711. ;; not at limit:
  2712. (not (if backward (bobp) (eobp)))
  2713. ;; still traversable:
  2714. (if backward (allout-previous-heading) (allout-next-heading))
  2715. ;; we're below the target depth
  2716. (> (setq last-depth allout-recent-depth) target-depth))
  2717. (setq count (1+ count))
  2718. (if (> count 7) ; lists are commonly 7 +- 2, right?-)
  2719. (setq leaping t)))
  2720. (cond (leaping
  2721. (or (allout-next-sibling-leap target-depth backward)
  2722. (progn
  2723. (goto-char start-point)
  2724. (if depth (allout-depth) target-depth)
  2725. nil)))
  2726. ((and (not (eobp))
  2727. (and (> (or last-depth (allout-depth)) 0)
  2728. (= allout-recent-depth target-depth))
  2729. (not (= start-prefix-beginning
  2730. allout-recent-prefix-beginning)))
  2731. allout-recent-prefix-beginning)
  2732. (t
  2733. (goto-char start-point)
  2734. (if depth (allout-depth) target-depth)
  2735. nil)))))
  2736. ;;;_ > allout-next-sibling-leap (&optional depth backward)
  2737. (defun allout-next-sibling-leap (&optional depth backward)
  2738. "Like `allout-next-sibling', but by direct search for topic at depth.
  2739. Traverse at optional DEPTH, or current depth if none specified.
  2740. Go backward if optional arg BACKWARD is non-nil.
  2741. Return the start point of the new topic if successful, nil otherwise.
  2742. Costs more than regular `allout-next-sibling' for short traversals:
  2743. - we have to check the prior (next, if traveling backwards)
  2744. item to confirm connectivity with the prior topic, and
  2745. - if confirmed, we have to reestablish the allout-recent-* settings with
  2746. some extra navigation
  2747. - if confirmation fails, we have to do more work to recover
  2748. It is an increasingly big win when there are many intervening
  2749. offspring before the next sibling, however, so
  2750. `allout-next-sibling' resorts to this if it finds itself in that
  2751. situation."
  2752. (if (if backward (bobp) (eobp))
  2753. nil
  2754. (let* ((start-point (point))
  2755. (target-depth (or depth (allout-depth)))
  2756. (search-whitespace-regexp nil)
  2757. (depth-biased (- target-depth 2))
  2758. (expression (if (<= target-depth 1)
  2759. allout-depth-one-regexp
  2760. (format allout-depth-specific-regexp
  2761. depth-biased depth-biased)))
  2762. found
  2763. done)
  2764. (while (not done)
  2765. (setq found (save-match-data
  2766. (if backward
  2767. (re-search-backward expression nil 'to-limit)
  2768. (forward-char 1)
  2769. (re-search-forward expression nil 'to-limit))))
  2770. (if (and found (allout-aberrant-container-p))
  2771. (setq found nil))
  2772. (setq done (or found (if backward (bobp) (eobp)))))
  2773. (if (not found)
  2774. (progn (goto-char start-point)
  2775. nil)
  2776. ;; rationale: if any intervening items were at a lower depth, we
  2777. ;; would now be on the first offspring at the target depth -- ie,
  2778. ;; the preceding item (per the search direction) must be at a
  2779. ;; lesser depth. that's all we need to check.
  2780. (if backward (allout-next-heading) (allout-previous-heading))
  2781. (if (< allout-recent-depth target-depth)
  2782. ;; return to start and reestablish allout-recent-*:
  2783. (progn
  2784. (goto-char start-point)
  2785. (allout-depth)
  2786. nil)
  2787. (goto-char found)
  2788. ;; locate cursor and set allout-recent-*:
  2789. (allout-goto-prefix))))))
  2790. ;;;_ > allout-previous-sibling (&optional depth backward)
  2791. (defun allout-previous-sibling (&optional depth backward)
  2792. "Like `allout-forward-current-level' backwards, respecting invisible topics.
  2793. Optional DEPTH specifies depth to traverse, default current depth.
  2794. Optional BACKWARD reverses direction.
  2795. Return depth if successful, nil otherwise."
  2796. (allout-next-sibling depth (not backward))
  2797. )
  2798. ;;;_ > allout-snug-back ()
  2799. (defun allout-snug-back ()
  2800. "Position cursor at end of previous topic.
  2801. Presumes point is at the start of a topic prefix."
  2802. (if (or (bobp) (eobp))
  2803. nil
  2804. (forward-char -1))
  2805. (if (or (bobp) (not (= ?\n (preceding-char))))
  2806. nil
  2807. (forward-char -1))
  2808. (point))
  2809. ;;;_ > allout-beginning-of-level ()
  2810. (defun allout-beginning-of-level ()
  2811. "Go back to the first sibling at this level, visible or not."
  2812. (allout-end-of-level 'backward))
  2813. ;;;_ > allout-end-of-level (&optional backward)
  2814. (defun allout-end-of-level (&optional backward)
  2815. "Go to the last sibling at this level, visible or not."
  2816. (let ((depth (allout-depth)))
  2817. (while (allout-previous-sibling depth nil))
  2818. (prog1 allout-recent-depth
  2819. (if (allout-called-interactively-p) (allout-end-of-prefix)))))
  2820. ;;;_ > allout-next-visible-heading (arg)
  2821. (defun allout-next-visible-heading (arg)
  2822. "Move to the next ARGth visible heading line, backward if ARG is negative.
  2823. Move to buffer limit in indicated direction if headings are exhausted."
  2824. (interactive "p")
  2825. (let* ((inhibit-field-text-motion t)
  2826. (backward (if (< arg 0) (setq arg (* -1 arg))))
  2827. (step (if backward -1 1))
  2828. (progress (allout-current-bullet-pos))
  2829. prev got)
  2830. (while (> arg 0)
  2831. (while (and
  2832. ;; Boundary condition:
  2833. (not (if backward (bobp)(eobp)))
  2834. ;; Move, skipping over all concealed lines in one fell swoop:
  2835. (prog1 (condition-case nil (or (line-move step) t)
  2836. (error nil))
  2837. (allout-beginning-of-current-line)
  2838. ;; line-move can wind up on the same line if long.
  2839. ;; when moving forward, that would yield no-progress
  2840. (when (and (not backward)
  2841. (<= (point) progress))
  2842. ;; ensure progress by doing line-move from end-of-line:
  2843. (end-of-line)
  2844. (condition-case nil (or (line-move step) t)
  2845. (error nil))
  2846. (allout-beginning-of-current-line)
  2847. (setq progress (point))))
  2848. ;; Deal with apparent header line:
  2849. (save-match-data
  2850. (if (not (looking-at allout-regexp))
  2851. ;; not a header line, keep looking:
  2852. t
  2853. (allout-prefix-data)
  2854. (if (and (allout-do-doublecheck)
  2855. (allout-aberrant-container-p))
  2856. ;; skip this aberrant prospective header line:
  2857. t
  2858. ;; this prospective headerline qualifies -- register:
  2859. (setq got allout-recent-prefix-beginning)
  2860. ;; and break the loop:
  2861. nil)))))
  2862. ;; Register this got, it may be the last:
  2863. (if got (setq prev got))
  2864. (setq arg (1- arg)))
  2865. (cond (got ; Last move was to a prefix:
  2866. (allout-end-of-prefix))
  2867. (prev ; Last move wasn't, but prev was:
  2868. (goto-char prev)
  2869. (allout-end-of-prefix))
  2870. ((not backward) (end-of-line) nil))))
  2871. ;;;_ > allout-previous-visible-heading (arg)
  2872. (defun allout-previous-visible-heading (arg)
  2873. "Move to the previous heading line.
  2874. With argument, repeats or can move forward if negative.
  2875. A heading line is one that starts with a `*' (or that `allout-regexp'
  2876. matches)."
  2877. (interactive "p")
  2878. (prog1 (allout-next-visible-heading (- arg))
  2879. (if (allout-called-interactively-p) (allout-end-of-prefix))))
  2880. ;;;_ > allout-forward-current-level (arg)
  2881. (defun allout-forward-current-level (arg)
  2882. "Position point at the next heading of the same level.
  2883. Takes optional repeat-count, goes backward if count is negative.
  2884. Returns resulting position, else nil if none found."
  2885. (interactive "p")
  2886. (let ((start-depth (allout-current-depth))
  2887. (start-arg arg)
  2888. (backward (> 0 arg)))
  2889. (if (= 0 start-depth)
  2890. (error "No siblings, not in a topic..."))
  2891. (if backward (setq arg (* -1 arg)))
  2892. (allout-back-to-current-heading)
  2893. (while (and (not (zerop arg))
  2894. (if backward
  2895. (allout-previous-sibling)
  2896. (allout-next-sibling)))
  2897. (setq arg (1- arg)))
  2898. (if (not (allout-called-interactively-p))
  2899. nil
  2900. (allout-end-of-prefix)
  2901. (if (not (zerop arg))
  2902. (error "Hit %s level %d topic, traversed %d of %d requested"
  2903. (if backward "first" "last")
  2904. allout-recent-depth
  2905. (- (abs start-arg) arg)
  2906. (abs start-arg))))))
  2907. ;;;_ > allout-backward-current-level (arg)
  2908. (defun allout-backward-current-level (arg)
  2909. "Inverse of `allout-forward-current-level'."
  2910. (interactive "p")
  2911. (if (allout-called-interactively-p)
  2912. (let ((current-prefix-arg (* -1 arg)))
  2913. (call-interactively 'allout-forward-current-level))
  2914. (allout-forward-current-level (* -1 arg))))
  2915. ;;;_ #5 Alteration
  2916. ;;;_ - Fundamental
  2917. ;;;_ = allout-post-goto-bullet
  2918. (defvar allout-post-goto-bullet nil
  2919. "Outline internal var, for `allout-pre-command-business' hot-spot operation.
  2920. When set, tells post-processing to reposition on topic bullet, and
  2921. then unset it. Set by `allout-pre-command-business' when implementing
  2922. hot-spot operation, where literal characters typed over a topic bullet
  2923. are mapped to the command of the corresponding control-key on the
  2924. `allout-mode-map-value'.")
  2925. (make-variable-buffer-local 'allout-post-goto-bullet)
  2926. ;;;_ = allout-command-counter
  2927. (defvar allout-command-counter 0
  2928. "Counter that monotonically increases in allout-mode buffers.
  2929. Set by `allout-pre-command-business', to support allout addons in
  2930. coordinating with allout activity.")
  2931. (make-variable-buffer-local 'allout-command-counter)
  2932. ;;;_ = allout-this-command-hid-text
  2933. (defvar allout-this-command-hid-text nil
  2934. "True if the most recent allout-mode command hid any text.")
  2935. (make-variable-buffer-local 'allout-this-command-hid-text)
  2936. ;;;_ > allout-post-command-business ()
  2937. (defun allout-post-command-business ()
  2938. "Outline `post-command-hook' function.
  2939. - Implement (and clear) `allout-post-goto-bullet', for hot-spot
  2940. outline commands.
  2941. - Move the cursor to the beginning of the entry if it is hidden
  2942. and collapsing activity just happened.
  2943. - If the command we're following was an undo, check for change in
  2944. the status of encrypted items and adjust auto-save inhibitions
  2945. accordingly.
  2946. - Decrypt topic currently being edited if it was encrypted for a save."
  2947. (if (not (allout-mode-p)) ; In allout-mode.
  2948. nil
  2949. (when allout-just-did-undo
  2950. (setq allout-just-did-undo nil)
  2951. (run-hooks 'allout-post-undo-hook)
  2952. (cond ((and (= buffer-saved-size -1)
  2953. allout-auto-save-temporarily-disabled)
  2954. ;; user possibly undid a decryption, disinhibit auto-save:
  2955. (allout-maybe-resume-auto-save-info-after-encryption))
  2956. ((save-excursion
  2957. (save-restriction
  2958. (widen)
  2959. (goto-char (point-min))
  2960. (not (allout-next-topic-pending-encryption))))
  2961. ;; plain-text encrypted items are present, inhibit auto-save:
  2962. (allout-inhibit-auto-save-info-for-decryption (buffer-size)))))
  2963. (if (and (boundp 'allout-after-save-decrypt)
  2964. allout-after-save-decrypt)
  2965. (allout-after-saves-handler))
  2966. ;; Implement allout-post-goto-bullet, if set:
  2967. (if (and allout-post-goto-bullet
  2968. (allout-current-bullet-pos))
  2969. (progn (goto-char (allout-current-bullet-pos))
  2970. (setq allout-post-goto-bullet nil))
  2971. (when (and (allout-hidden-p) allout-this-command-hid-text)
  2972. (allout-beginning-of-current-entry)))))
  2973. ;;;_ > allout-pre-command-business ()
  2974. (defun allout-pre-command-business ()
  2975. "Outline `pre-command-hook' function for outline buffers.
  2976. Among other things, implements special behavior when the cursor is on the
  2977. topic bullet character.
  2978. When the cursor is on the bullet character, self-insert
  2979. characters are reinterpreted as the corresponding
  2980. control-character in the `allout-mode-map-value'. The
  2981. `allout-mode' `post-command-hook' insures that the cursor which
  2982. has moved as a result of such reinterpretation is positioned on
  2983. the bullet character of the destination topic.
  2984. The upshot is that you can get easy, single (ie, unmodified) key
  2985. outline maneuvering operations by positioning the cursor on the bullet
  2986. char. When in this mode you can use regular cursor-positioning
  2987. command/keystrokes to relocate the cursor off of a bullet character to
  2988. return to regular interpretation of self-insert characters."
  2989. (if (not (allout-mode-p))
  2990. nil
  2991. (setq allout-command-counter (1+ allout-command-counter))
  2992. (setq allout-this-command-hid-text nil)
  2993. ;; Do hot-spot navigation.
  2994. (if (and (eq this-command 'self-insert-command)
  2995. (eq (point)(allout-current-bullet-pos)))
  2996. (allout-hotspot-key-handler))))
  2997. ;;;_ > allout-hotspot-key-handler ()
  2998. (defun allout-hotspot-key-handler ()
  2999. "Catchall handling of key bindings in hot-spots.
  3000. Translates unmodified keystrokes to corresponding allout commands, when
  3001. they would qualify if prefixed with the `allout-command-prefix', and sets
  3002. `this-command' accordingly.
  3003. Returns the qualifying command, if any, else nil."
  3004. (interactive)
  3005. (let* ((modified (event-modifiers last-command-event))
  3006. (key-num (cond ((numberp last-command-event) last-command-event)
  3007. ;; for XEmacs character type:
  3008. ((and (fboundp 'characterp)
  3009. (apply 'characterp (list last-command-event)))
  3010. (apply 'char-to-int (list last-command-event)))
  3011. (t 0)))
  3012. mapped-binding)
  3013. (if (zerop key-num)
  3014. nil
  3015. (if (and
  3016. ;; exclude control chars and escape:
  3017. (not modified)
  3018. (<= 33 key-num)
  3019. (setq mapped-binding
  3020. (or
  3021. ;; try control-modified versions of keys:
  3022. (key-binding (vconcat allout-command-prefix
  3023. (vector
  3024. (if (and (<= 97 key-num) ; "a"
  3025. (>= 122 key-num)) ; "z"
  3026. (- key-num 96) key-num)))
  3027. t)
  3028. ;; try non-modified versions of keys:
  3029. (key-binding (vconcat allout-command-prefix
  3030. (vector key-num))
  3031. t))))
  3032. ;; Qualified as an allout command -- do hot-spot operation.
  3033. (setq allout-post-goto-bullet t)
  3034. ;; accept-defaults nil, or else we get allout-item-icon-key-handler.
  3035. (setq mapped-binding (key-binding (vector key-num))))
  3036. (while (keymapp mapped-binding)
  3037. (setq mapped-binding
  3038. (lookup-key mapped-binding (vector (read-char)))))
  3039. (when mapped-binding
  3040. (setq this-command mapped-binding)))))
  3041. ;;;_ > allout-find-file-hook ()
  3042. (defun allout-find-file-hook ()
  3043. "Activate `allout-mode' on non-nil `allout-auto-activation', `allout-layout'.
  3044. See `allout-auto-activation' for setup instructions."
  3045. (if (and allout-auto-activation
  3046. (not (allout-mode-p))
  3047. allout-layout)
  3048. (allout-mode)))
  3049. ;;;_ - Topic Format Assessment
  3050. ;;;_ > allout-solicit-alternate-bullet (depth &optional current-bullet)
  3051. (defun allout-solicit-alternate-bullet (depth &optional current-bullet)
  3052. "Prompt for and return a bullet char as an alternative to the current one.
  3053. Offer one suitable for current depth DEPTH as default."
  3054. (let* ((default-bullet (or (and (stringp current-bullet) current-bullet)
  3055. (allout-bullet-for-depth depth)))
  3056. (sans-escapes (regexp-sans-escapes allout-bullets-string))
  3057. choice)
  3058. (save-excursion
  3059. (goto-char (allout-current-bullet-pos))
  3060. (setq choice (solicit-char-in-string
  3061. (format "Select bullet: %s ('%s' default): "
  3062. sans-escapes
  3063. (allout-substring-no-properties default-bullet))
  3064. sans-escapes
  3065. t)))
  3066. (message "")
  3067. (if (string= choice "") default-bullet choice))
  3068. )
  3069. ;;;_ > allout-distinctive-bullet (bullet)
  3070. (defun allout-distinctive-bullet (bullet)
  3071. "True if BULLET is one of those on `allout-distinctive-bullets-string'."
  3072. (string-match (regexp-quote bullet) allout-distinctive-bullets-string))
  3073. ;;;_ > allout-numbered-type-prefix (&optional prefix)
  3074. (defun allout-numbered-type-prefix (&optional prefix)
  3075. "True if current header prefix bullet is numbered bullet."
  3076. (and allout-numbered-bullet
  3077. (string= allout-numbered-bullet
  3078. (if prefix
  3079. (allout-get-prefix-bullet prefix)
  3080. (allout-get-bullet)))))
  3081. ;;;_ > allout-encrypted-type-prefix (&optional prefix)
  3082. (defun allout-encrypted-type-prefix (&optional prefix)
  3083. "True if current header prefix bullet is for an encrypted entry (body)."
  3084. (and allout-topic-encryption-bullet
  3085. (string= allout-topic-encryption-bullet
  3086. (if prefix
  3087. (allout-get-prefix-bullet prefix)
  3088. (allout-get-bullet)))))
  3089. ;;;_ > allout-bullet-for-depth (&optional depth)
  3090. (defun allout-bullet-for-depth (&optional depth)
  3091. "Return outline topic bullet suited to optional DEPTH, or current depth."
  3092. ;; Find bullet in plain-bullets-string modulo DEPTH.
  3093. (if allout-stylish-prefixes
  3094. (char-to-string (aref allout-plain-bullets-string
  3095. (% (max 0 (- depth 2))
  3096. allout-plain-bullets-string-len)))
  3097. allout-primary-bullet)
  3098. )
  3099. ;;;_ - Topic Production
  3100. ;;;_ > allout-make-topic-prefix (&optional prior-bullet
  3101. (defun allout-make-topic-prefix (&optional prior-bullet
  3102. new
  3103. depth
  3104. instead
  3105. number-control
  3106. index)
  3107. ;; Depth null means use current depth, non-null means we're either
  3108. ;; opening a new topic after current topic, lower or higher, or we're
  3109. ;; changing level of current topic.
  3110. ;; Instead dominates specified bullet-char.
  3111. ;;;_ . Doc string:
  3112. "Generate a topic prefix suitable for optional arg DEPTH, or current depth.
  3113. All the arguments are optional.
  3114. PRIOR-BULLET indicates the bullet of the prefix being changed, or
  3115. nil if none. This bullet may be preserved (other options
  3116. notwithstanding) if it is on the `allout-distinctive-bullets-string',
  3117. for instance.
  3118. Second arg NEW indicates that a new topic is being opened after the
  3119. topic at point, if non-nil. Default bullet for new topics, eg, may
  3120. be set (contingent to other args) to numbered bullets if previous
  3121. sibling is one. The implication otherwise is that the current topic
  3122. is being adjusted -- shifted or rebulleted -- and we don't consider
  3123. bullet or previous sibling.
  3124. Third arg DEPTH forces the topic prefix to that depth, regardless of
  3125. the current topics' depth.
  3126. If INSTEAD is:
  3127. - nil, then the bullet char for the context is used, per distinction or depth
  3128. - a (numeric) character, then character's string representation is used
  3129. - a string, then the user is asked for bullet with the first char as default
  3130. - anything else, the user is solicited with bullet char per context as default
  3131. \(INSTEAD overrides other options, including, eg, a distinctive
  3132. PRIOR-BULLET.)
  3133. Fifth arg, NUMBER-CONTROL, matters only if `allout-numbered-bullet'
  3134. is non-nil *and* no specific INSTEAD was specified. Then
  3135. NUMBER-CONTROL non-nil forces prefix to either numbered or
  3136. unnumbered format, depending on the value of the sixth arg, INDEX.
  3137. \(Note that NUMBER-CONTROL does *not* apply to level 1 topics. Sorry...)
  3138. If NUMBER-CONTROL is non-nil and sixth arg INDEX is non-nil then
  3139. the prefix of the topic is forced to be numbered. Non-nil
  3140. NUMBER-CONTROL and nil INDEX forces non-numbered format on the
  3141. bullet. Non-nil NUMBER-CONTROL and non-nil, non-number INDEX means
  3142. that the index for the numbered prefix will be derived, by counting
  3143. siblings back to start of level. If INDEX is a number, then that
  3144. number is used as the index for the numbered prefix (allowing, eg,
  3145. sequential renumbering to not require this function counting back the
  3146. index for each successive sibling)."
  3147. ;;;_ . Code:
  3148. ;; The options are ordered in likely frequency of use, most common
  3149. ;; highest, least lowest. Ie, more likely to be doing prefix
  3150. ;; adjustments than soliciting, and yet more than numbering.
  3151. ;; Current prefix is least dominant, but most likely to be commonly
  3152. ;; specified...
  3153. (let* (body
  3154. numbering
  3155. denumbering
  3156. (depth (or depth (allout-depth)))
  3157. (header-lead allout-header-prefix)
  3158. (bullet-char
  3159. ;; Getting value for bullet char is practically the whole job:
  3160. (cond
  3161. ; Simplest situation -- level 1:
  3162. ((<= depth 1) (setq header-lead "") allout-primary-bullet)
  3163. ; Simple, too: all asterisks:
  3164. (allout-old-style-prefixes
  3165. ;; Cheat -- make body the whole thing, null out header-lead and
  3166. ;; bullet-char:
  3167. (setq body (make-string depth
  3168. (string-to-char allout-primary-bullet)))
  3169. (setq header-lead "")
  3170. "")
  3171. ;; (Neither level 1 nor old-style, so we're space padding.
  3172. ;; Sneak it in the condition of the next case, whatever it is.)
  3173. ;; Solicitation overrides numbering and other cases:
  3174. ((progn (setq body (make-string (- depth 2) ?\ ))
  3175. ;; The actual condition:
  3176. instead)
  3177. (let ((got (cond ((stringp instead)
  3178. (if (> (length instead) 0)
  3179. (allout-solicit-alternate-bullet
  3180. depth (substring instead 0 1))))
  3181. ((characterp instead) (char-to-string instead))
  3182. (t (allout-solicit-alternate-bullet depth)))))
  3183. ;; Gotta check whether we're numbering and got a numbered bullet:
  3184. (setq numbering (and allout-numbered-bullet
  3185. (not (and number-control (not index)))
  3186. (string= got allout-numbered-bullet)))
  3187. ;; Now return what we got, regardless:
  3188. got))
  3189. ;; Numbering invoked through args:
  3190. ((and allout-numbered-bullet number-control)
  3191. (if (setq numbering (not (setq denumbering (not index))))
  3192. allout-numbered-bullet
  3193. (if (and prior-bullet
  3194. (not (string= allout-numbered-bullet
  3195. prior-bullet)))
  3196. prior-bullet
  3197. (allout-bullet-for-depth depth))))
  3198. ;;; Neither soliciting nor controlled numbering ;;;
  3199. ;;; (may be controlled denumbering, tho) ;;;
  3200. ;; Check wrt previous sibling:
  3201. ((and new ; only check for new prefixes
  3202. (<= depth (allout-depth))
  3203. allout-numbered-bullet ; ... & numbering enabled
  3204. (not denumbering)
  3205. (let ((sibling-bullet
  3206. (save-excursion
  3207. ;; Locate correct sibling:
  3208. (or (>= depth (allout-depth))
  3209. (allout-ascend-to-depth depth))
  3210. (allout-get-bullet))))
  3211. (if (and sibling-bullet
  3212. (string= allout-numbered-bullet sibling-bullet))
  3213. (setq numbering sibling-bullet)))))
  3214. ;; Distinctive prior bullet?
  3215. ((and prior-bullet
  3216. (allout-distinctive-bullet prior-bullet)
  3217. ;; Either non-numbered:
  3218. (or (not (and allout-numbered-bullet
  3219. (string= prior-bullet allout-numbered-bullet)))
  3220. ;; or numbered, and not denumbering:
  3221. (setq numbering (not denumbering)))
  3222. ;; Here 'tis:
  3223. prior-bullet))
  3224. ;; Else, standard bullet per depth:
  3225. ((allout-bullet-for-depth depth)))))
  3226. (concat header-lead
  3227. body
  3228. bullet-char
  3229. (if numbering
  3230. (format "%d" (cond ((and index (numberp index)) index)
  3231. (new (1+ (allout-sibling-index depth)))
  3232. ((allout-sibling-index))))))
  3233. )
  3234. )
  3235. ;;;_ > allout-open-topic (relative-depth &optional before offer-recent-bullet)
  3236. (defun allout-open-topic (relative-depth &optional before offer-recent-bullet)
  3237. "Open a new topic at depth DEPTH.
  3238. New topic is situated after current one, unless optional flag BEFORE
  3239. is non-nil, or unless current line is completely empty -- lacking even
  3240. whitespace -- in which case open is done on the current line.
  3241. When adding an offspring, it will be added immediately after the parent if
  3242. the other offspring are exposed, or after the last child if the offspring
  3243. are hidden. (The intervening offspring will be exposed in the latter
  3244. case.)
  3245. If OFFER-RECENT-BULLET is true, offer to use the bullet of the prior sibling.
  3246. Nuances:
  3247. - Creation of new topics is with respect to the visible topic
  3248. containing the cursor, regardless of intervening concealed ones.
  3249. - New headers are generally created after/before the body of a
  3250. topic. However, they are created right at cursor location if the
  3251. cursor is on a blank line, even if that breaks the current topic
  3252. body. This is intentional, to provide a simple means for
  3253. deliberately dividing topic bodies.
  3254. - Double spacing of topic lists is preserved. Also, the first
  3255. level two topic is created double-spaced (and so would be
  3256. subsequent siblings, if that's left intact). Otherwise,
  3257. single-spacing is used.
  3258. - Creation of sibling or nested topics is with respect to the topic
  3259. you're starting from, even when creating backwards. This way you
  3260. can easily create a sibling in front of the current topic without
  3261. having to go to its preceding sibling, and then open forward
  3262. from there."
  3263. (allout-beginning-of-current-line)
  3264. (save-match-data
  3265. (let* ((inhibit-field-text-motion t)
  3266. (depth (+ (allout-current-depth) relative-depth))
  3267. (opening-on-blank (if (looking-at "^\$")
  3268. (not (setq before nil))))
  3269. ;; bunch o vars set while computing ref-topic
  3270. opening-numbered
  3271. ref-depth
  3272. ref-bullet
  3273. (ref-topic (save-excursion
  3274. (cond ((< relative-depth 0)
  3275. (allout-ascend-to-depth depth))
  3276. ((>= relative-depth 1) nil)
  3277. (t (allout-back-to-current-heading)))
  3278. (setq ref-depth allout-recent-depth)
  3279. (setq ref-bullet
  3280. (if (> allout-recent-prefix-end 1)
  3281. (allout-recent-bullet)
  3282. ""))
  3283. (setq opening-numbered
  3284. (save-excursion
  3285. (and allout-numbered-bullet
  3286. (or (<= relative-depth 0)
  3287. (allout-descend-to-depth depth))
  3288. (if (allout-numbered-type-prefix)
  3289. allout-numbered-bullet))))
  3290. (point)))
  3291. dbl-space
  3292. doing-beginning
  3293. start end)
  3294. (if (not opening-on-blank)
  3295. ; Positioning and vertical
  3296. ; padding -- only if not
  3297. ; opening-on-blank:
  3298. (progn
  3299. (goto-char ref-topic)
  3300. (setq dbl-space ; Determine double space action:
  3301. (or (and (<= relative-depth 0) ; not descending;
  3302. (save-excursion
  3303. ;; at b-o-b or preceded by a blank line?
  3304. (or (> 0 (forward-line -1))
  3305. (looking-at "^\\s-*$")
  3306. (bobp)))
  3307. (save-excursion
  3308. ;; succeeded by a blank line?
  3309. (allout-end-of-current-subtree)
  3310. (looking-at "\n\n")))
  3311. (and (= ref-depth 1)
  3312. (or before
  3313. (= depth 1)
  3314. (save-excursion
  3315. ;; Don't already have following
  3316. ;; vertical padding:
  3317. (not (allout-pre-next-prefix)))))))
  3318. ;; Position to prior heading, if inserting backwards, and not
  3319. ;; going outwards:
  3320. (if (and before (>= relative-depth 0))
  3321. (progn (allout-back-to-current-heading)
  3322. (setq doing-beginning (bobp))
  3323. (if (not (bobp))
  3324. (allout-previous-heading)))
  3325. (if (and before (bobp))
  3326. (open-line 1)))
  3327. (if (<= relative-depth 0)
  3328. ;; Not going inwards, don't snug up:
  3329. (if doing-beginning
  3330. (if (not dbl-space)
  3331. (open-line 1)
  3332. (open-line 2))
  3333. (if before
  3334. (progn (end-of-line)
  3335. (allout-pre-next-prefix)
  3336. (while (and (= ?\n (following-char))
  3337. (save-excursion
  3338. (forward-char 1)
  3339. (allout-hidden-p)))
  3340. (forward-char 1))
  3341. (if (not (looking-at "^$"))
  3342. (open-line 1)))
  3343. (allout-end-of-current-subtree)
  3344. (if (looking-at "\n\n") (forward-char 1))))
  3345. ;; Going inwards -- double-space if first offspring is
  3346. ;; double-spaced, otherwise snug up.
  3347. (allout-end-of-entry)
  3348. (if (eobp)
  3349. (newline 1)
  3350. (line-move 1))
  3351. (allout-beginning-of-current-line)
  3352. (backward-char 1)
  3353. (if (bolp)
  3354. ;; Blank lines between current header body and next
  3355. ;; header -- get to last substantive (non-white-space)
  3356. ;; line in body:
  3357. (progn (setq dbl-space t)
  3358. (re-search-backward "[^ \t\n]" nil t)))
  3359. (if (looking-at "\n\n")
  3360. (setq dbl-space t))
  3361. (if (save-excursion
  3362. (allout-next-heading)
  3363. (when (> allout-recent-depth ref-depth)
  3364. ;; This is an offspring.
  3365. (forward-line -1)
  3366. (looking-at "^\\s-*$")))
  3367. (progn (forward-line 1)
  3368. (open-line 1)
  3369. (forward-line 1)))
  3370. (allout-end-of-current-line))
  3371. ;;(if doing-beginning (goto-char doing-beginning))
  3372. (if (not (bobp))
  3373. ;; We insert a newline char rather than using open-line to
  3374. ;; avoid rear-stickiness inheritance of read-only property.
  3375. (progn (if (and (not (> depth ref-depth))
  3376. (not before))
  3377. (open-line 1)
  3378. (if (and (not dbl-space) (> depth ref-depth))
  3379. (newline 1)
  3380. (if dbl-space
  3381. (open-line 1)
  3382. (if (not before)
  3383. (newline 1)))))
  3384. (if (and dbl-space (not (> relative-depth 0)))
  3385. (newline 1))
  3386. (if (and (not (eobp))
  3387. (or (not (bolp))
  3388. (and (not (bobp))
  3389. ;; bolp doesn't detect concealed
  3390. ;; trailing newlines, compensate:
  3391. (save-excursion
  3392. (forward-char -1)
  3393. (allout-hidden-p)))))
  3394. (forward-char 1))))
  3395. ))
  3396. (setq start (point))
  3397. (insert (concat (allout-make-topic-prefix opening-numbered t depth)
  3398. " "))
  3399. (setq end (1+ (point)))
  3400. (allout-rebullet-heading (and offer-recent-bullet ref-bullet)
  3401. depth nil nil t)
  3402. (if (> relative-depth 0)
  3403. (save-excursion (goto-char ref-topic)
  3404. (allout-show-children)))
  3405. (end-of-line)
  3406. (run-hook-with-args 'allout-structure-added-hook start end)
  3407. )
  3408. )
  3409. )
  3410. ;;;_ > allout-open-subtopic (arg)
  3411. (defun allout-open-subtopic (arg)
  3412. "Open new topic header at deeper level than the current one.
  3413. Negative universal ARG means to open deeper, but place the new topic
  3414. prior to the current one."
  3415. (interactive "p")
  3416. (allout-open-topic 1 (> 0 arg) (< 1 arg)))
  3417. ;;;_ > allout-open-sibtopic (arg)
  3418. (defun allout-open-sibtopic (arg)
  3419. "Open new topic header at same level as the current one.
  3420. Positive universal ARG means to use the bullet of the prior sibling.
  3421. Negative universal ARG means to place the new topic prior to the current
  3422. one."
  3423. (interactive "p")
  3424. (allout-open-topic 0 (> 0 arg) (not (= 1 arg))))
  3425. ;;;_ > allout-open-supertopic (arg)
  3426. (defun allout-open-supertopic (arg)
  3427. "Open new topic header at shallower level than the current one.
  3428. Negative universal ARG means to open shallower, but place the new
  3429. topic prior to the current one."
  3430. (interactive "p")
  3431. (allout-open-topic -1 (> 0 arg) (< 1 arg)))
  3432. ;;;_ - Outline Alteration
  3433. ;;;_ : Topic Modification
  3434. ;;;_ = allout-former-auto-filler
  3435. (defvar allout-former-auto-filler nil
  3436. "Name of modal fill function being wrapped by `allout-auto-fill'.")
  3437. ;;;_ > allout-auto-fill ()
  3438. (defun allout-auto-fill ()
  3439. "`allout-mode' autofill function.
  3440. Maintains outline hanging topic indentation if
  3441. `allout-use-hanging-indents' is set."
  3442. (when (and (not allout-inhibit-auto-fill)
  3443. (or (not allout-inhibit-auto-fill-on-headline)
  3444. (not (allout-on-current-heading-p))))
  3445. (let ((fill-prefix (if allout-use-hanging-indents
  3446. ;; Check for topic header indentation:
  3447. (save-match-data
  3448. (save-excursion
  3449. (beginning-of-line)
  3450. (if (looking-at allout-regexp)
  3451. ;; ... construct indentation to account for
  3452. ;; length of topic prefix:
  3453. (make-string (progn (allout-end-of-prefix)
  3454. (current-column))
  3455. ?\ ))))))
  3456. (use-auto-fill-function
  3457. (if (and (eq allout-outside-normal-auto-fill-function
  3458. 'allout-auto-fill)
  3459. (eq auto-fill-function 'allout-auto-fill))
  3460. 'do-auto-fill
  3461. (or allout-outside-normal-auto-fill-function
  3462. auto-fill-function))))
  3463. (if (or allout-former-auto-filler allout-use-hanging-indents)
  3464. (funcall use-auto-fill-function)))))
  3465. ;;;_ > allout-reindent-body (old-depth new-depth &optional number)
  3466. (defun allout-reindent-body (old-depth new-depth &optional number)
  3467. "Reindent body lines which were indented at OLD-DEPTH to NEW-DEPTH.
  3468. Optional arg NUMBER indicates numbering is being added, and it must
  3469. be accommodated.
  3470. Note that refill of indented paragraphs is not done."
  3471. (save-excursion
  3472. (allout-end-of-prefix)
  3473. (let* ((new-margin (current-column))
  3474. excess old-indent-begin old-indent-end
  3475. ;; We want the column where the header-prefix text started
  3476. ;; *before* the prefix was changed, so we infer it relative
  3477. ;; to the new margin and the shift in depth:
  3478. (old-margin (+ old-depth (- new-margin new-depth))))
  3479. ;; Process lines up to (but excluding) next topic header:
  3480. (allout-unprotected
  3481. (save-match-data
  3482. (while
  3483. (and (re-search-forward "\n\\(\\s-*\\)"
  3484. nil
  3485. t)
  3486. ;; Register the indent data, before we reset the
  3487. ;; match data with a subsequent `looking-at':
  3488. (setq old-indent-begin (match-beginning 1)
  3489. old-indent-end (match-end 1))
  3490. (not (looking-at allout-regexp)))
  3491. (if (> 0 (setq excess (- (- old-indent-end old-indent-begin)
  3492. old-margin)))
  3493. ;; Text starts left of old margin -- don't adjust:
  3494. nil
  3495. ;; Text was hanging at or right of old left margin --
  3496. ;; reindent it, preserving its existing indentation
  3497. ;; beyond the old margin:
  3498. (delete-region old-indent-begin old-indent-end)
  3499. (indent-to (+ new-margin excess (current-column))))))))))
  3500. ;;;_ > allout-rebullet-current-heading (arg)
  3501. (defun allout-rebullet-current-heading (arg)
  3502. "Solicit new bullet for current visible heading."
  3503. (interactive "p")
  3504. (let ((initial-col (current-column))
  3505. (on-bullet (eq (point)(allout-current-bullet-pos)))
  3506. from to
  3507. (backwards (if (< arg 0)
  3508. (setq arg (* arg -1)))))
  3509. (while (> arg 0)
  3510. (save-excursion (allout-back-to-current-heading)
  3511. (allout-end-of-prefix)
  3512. (setq from allout-recent-prefix-beginning
  3513. to allout-recent-prefix-end)
  3514. (allout-rebullet-heading t ;;; instead
  3515. nil ;;; depth
  3516. nil ;;; number-control
  3517. nil ;;; index
  3518. t) ;;; do-successors
  3519. (run-hook-with-args 'allout-exposure-change-hook
  3520. from to t))
  3521. (setq arg (1- arg))
  3522. (if (<= arg 0)
  3523. nil
  3524. (setq initial-col nil) ; Override positioning back to init col
  3525. (if (not backwards)
  3526. (allout-next-visible-heading 1)
  3527. (allout-goto-prefix-doublechecked)
  3528. (allout-next-visible-heading -1))))
  3529. (message "Done.")
  3530. (cond (on-bullet (goto-char (allout-current-bullet-pos)))
  3531. (initial-col (move-to-column initial-col)))))
  3532. ;;;_ > allout-rebullet-heading (&optional instead ...)
  3533. (defun allout-rebullet-heading (&optional instead
  3534. new-depth
  3535. number-control
  3536. index
  3537. do-successors)
  3538. "Adjust bullet of current topic prefix.
  3539. All args are optional.
  3540. If INSTEAD is:
  3541. - nil, then the bullet char for the context is used, per distinction or depth
  3542. - a (numeric) character, then character's string representation is used
  3543. - a string, then the user is asked for bullet with the first char as default
  3544. - anything else, the user is solicited with bullet char per context as default
  3545. Second arg DEPTH forces the topic prefix to that depth, regardless
  3546. of the topic's current depth.
  3547. Third arg NUMBER-CONTROL can force the prefix to or away from
  3548. numbered form. It has effect only if `allout-numbered-bullet' is
  3549. non-nil and soliciting was not explicitly invoked (via first arg).
  3550. Its effect, numbering or denumbering, then depends on the setting
  3551. of the fourth arg, INDEX.
  3552. If NUMBER-CONTROL is non-nil and fourth arg INDEX is nil, then the
  3553. prefix of the topic is forced to be non-numbered. Null index and
  3554. non-nil NUMBER-CONTROL forces denumbering. Non-nil INDEX (and
  3555. non-nil NUMBER-CONTROL) forces a numbered-prefix form. If non-nil
  3556. INDEX is a number, then that number is used for the numbered
  3557. prefix. Non-nil and non-number means that the index for the
  3558. numbered prefix will be derived by allout-make-topic-prefix.
  3559. Fifth arg DO-SUCCESSORS t means re-resolve count on succeeding
  3560. siblings.
  3561. Cf vars `allout-stylish-prefixes', `allout-old-style-prefixes',
  3562. and `allout-numbered-bullet', which all affect the behavior of
  3563. this function."
  3564. (let* ((current-depth (allout-depth))
  3565. (new-depth (or new-depth current-depth))
  3566. (mb allout-recent-prefix-beginning)
  3567. (me allout-recent-prefix-end)
  3568. (current-bullet (buffer-substring-no-properties (- me 1) me))
  3569. (has-annotation (get-text-property mb 'allout-was-hidden))
  3570. (new-prefix (allout-make-topic-prefix current-bullet
  3571. nil
  3572. new-depth
  3573. instead
  3574. number-control
  3575. index)))
  3576. ;; Is new one identical to old?
  3577. (if (and (= current-depth new-depth)
  3578. (string= current-bullet
  3579. (substring new-prefix (1- (length new-prefix)))))
  3580. ;; Nothing to do:
  3581. t
  3582. ;; New prefix probably different from old:
  3583. ; get rid of old one:
  3584. (allout-unprotected (delete-region mb me))
  3585. (goto-char mb)
  3586. ; Dispense with number if
  3587. ; numbered-bullet prefix:
  3588. (save-match-data
  3589. (if (and allout-numbered-bullet
  3590. (string= allout-numbered-bullet current-bullet)
  3591. (looking-at "[0-9]+"))
  3592. (allout-unprotected
  3593. (delete-region (match-beginning 0)(match-end 0)))))
  3594. ;; convey 'allout-was-hidden annotation, if original had it:
  3595. (if has-annotation
  3596. (put-text-property 0 (length new-prefix) 'allout-was-hidden t
  3597. new-prefix))
  3598. ; Put in new prefix:
  3599. (allout-unprotected (insert new-prefix))
  3600. ;; Reindent the body if elected, margin changed, and not encrypted body:
  3601. (if (and allout-reindent-bodies
  3602. (not (= new-depth current-depth))
  3603. (not (allout-encrypted-topic-p)))
  3604. (allout-reindent-body current-depth new-depth))
  3605. (run-hook-with-args 'allout-exposure-change-hook mb me nil)
  3606. ;; Recursively rectify successive siblings of orig topic if
  3607. ;; caller elected for it:
  3608. (if do-successors
  3609. (save-excursion
  3610. (while (allout-next-sibling new-depth nil)
  3611. (setq index
  3612. (cond ((numberp index) (1+ index))
  3613. ((not number-control) (allout-sibling-index))))
  3614. (if (allout-numbered-type-prefix)
  3615. (allout-rebullet-heading nil ;;; instead
  3616. new-depth ;;; new-depth
  3617. number-control;;; number-control
  3618. index ;;; index
  3619. nil))))) ;;;(dont!)do-successors
  3620. ) ; (if (and (= current-depth new-depth)...))
  3621. ) ; let* ((current-depth (allout-depth))...)
  3622. ) ; defun
  3623. ;;;_ > allout-rebullet-topic (arg)
  3624. (defun allout-rebullet-topic (arg &optional sans-offspring)
  3625. "Rebullet the visible topic containing point and all contained subtopics.
  3626. Descends into invisible as well as visible topics, however.
  3627. When optional SANS-OFFSPRING is non-nil, subtopics are not
  3628. shifted. (Shifting a topic outwards without shifting its
  3629. offspring is disallowed, since this would create a \"containment
  3630. discontinuity\", where the depth difference between a topic and
  3631. its immediate offspring is greater than one.)
  3632. With repeat count, shift topic depth by that amount."
  3633. (interactive "P")
  3634. (let ((start-col (current-column)))
  3635. (save-excursion
  3636. ;; Normalize arg:
  3637. (cond ((null arg) (setq arg 0))
  3638. ((listp arg) (setq arg (car arg))))
  3639. ;; Fill the user in, in case we're shifting a big topic:
  3640. (if (not (zerop arg)) (message "Shifting..."))
  3641. (allout-back-to-current-heading)
  3642. (if (<= (+ allout-recent-depth arg) 0)
  3643. (error "Attempt to shift topic below level 1"))
  3644. (allout-rebullet-topic-grunt arg nil nil nil nil sans-offspring)
  3645. (if (not (zerop arg)) (message "Shifting... done.")))
  3646. (move-to-column (max 0 (+ start-col arg)))))
  3647. ;;;_ > allout-rebullet-topic-grunt (&optional relative-depth ...)
  3648. (defun allout-rebullet-topic-grunt (&optional relative-depth
  3649. starting-depth
  3650. starting-point
  3651. index
  3652. do-successors
  3653. sans-offspring)
  3654. "Like `allout-rebullet-topic', but on nearest containing topic
  3655. \(visible or not).
  3656. See `allout-rebullet-heading' for rebulleting behavior.
  3657. All arguments are optional.
  3658. First arg RELATIVE-DEPTH means to shift the depth of the entire
  3659. topic that amount.
  3660. Several subsequent args are for internal recursive use by the function
  3661. itself: STARTING-DEPTH, STARTING-POINT, and INDEX.
  3662. Finally, if optional SANS-OFFSPRING is non-nil then the offspring
  3663. are not shifted. (Shifting a topic outwards without shifting
  3664. its offspring is disallowed, since this would create a
  3665. \"containment discontinuity\", where the depth difference between
  3666. a topic and its immediate offspring is greater than one.)"
  3667. ;; XXX the recursion here is peculiar, and in general the routine may
  3668. ;; need simplification with refactoring.
  3669. (if (and sans-offspring
  3670. relative-depth
  3671. (< relative-depth 0))
  3672. (error (concat "Attempt to shift topic outwards without offspring,"
  3673. " would cause containment discontinuity.")))
  3674. (let* ((relative-depth (or relative-depth 0))
  3675. (new-depth (allout-depth))
  3676. (starting-depth (or starting-depth new-depth))
  3677. (on-starting-call (null starting-point))
  3678. (index (or index
  3679. ;; Leave index null on starting call, so rebullet-heading
  3680. ;; calculates it at what might be new depth:
  3681. (and (or (zerop relative-depth)
  3682. (not on-starting-call))
  3683. (allout-sibling-index))))
  3684. (starting-index index)
  3685. (moving-outwards (< 0 relative-depth))
  3686. (starting-point (or starting-point (point)))
  3687. (local-point (point)))
  3688. ;; Sanity check for excessive promotion done only on starting call:
  3689. (and on-starting-call
  3690. moving-outwards
  3691. (> 0 (+ starting-depth relative-depth))
  3692. (error "Attempt to shift topic out beyond level 1"))
  3693. (cond ((= starting-depth new-depth)
  3694. ;; We're at depth to work on this one.
  3695. ;; When shifting out we work on the children before working on
  3696. ;; the parent to avoid interim `allout-aberrant-container-p'
  3697. ;; aberrancy, and vice-versa when shifting in:
  3698. (if (>= relative-depth 0)
  3699. (allout-rebullet-heading nil
  3700. (+ starting-depth relative-depth)
  3701. nil ;;; number
  3702. index
  3703. nil)) ;;; do-successors
  3704. (when (not sans-offspring)
  3705. ;; ... and work on subsequent ones which are at greater depth:
  3706. (setq index 0)
  3707. (allout-next-heading)
  3708. (while (and (not (eobp))
  3709. (< starting-depth (allout-depth)))
  3710. (setq index (1+ index))
  3711. (allout-rebullet-topic-grunt relative-depth
  3712. (1+ starting-depth)
  3713. starting-point
  3714. index)))
  3715. (when (< relative-depth 0)
  3716. (save-excursion
  3717. (goto-char local-point)
  3718. (allout-rebullet-heading nil ;;; instead
  3719. (+ starting-depth relative-depth)
  3720. nil ;;; number
  3721. starting-index
  3722. nil)))) ;;; do-successors
  3723. ((< starting-depth new-depth)
  3724. ;; Rare case -- subtopic more than one level deeper than parent.
  3725. ;; Treat this one at an even deeper level:
  3726. (allout-rebullet-topic-grunt relative-depth
  3727. new-depth
  3728. starting-point
  3729. index
  3730. sans-offspring)))
  3731. (if on-starting-call
  3732. (progn
  3733. ;; Rectify numbering of former siblings of the adjusted topic,
  3734. ;; if topic has changed depth
  3735. (if (or do-successors
  3736. (and (not (zerop relative-depth))
  3737. (or (= allout-recent-depth starting-depth)
  3738. (= allout-recent-depth (+ starting-depth
  3739. relative-depth)))))
  3740. (allout-rebullet-heading nil nil nil nil t))
  3741. ;; Now rectify numbering of new siblings of the adjusted topic,
  3742. ;; if depth has been changed:
  3743. (progn (goto-char starting-point)
  3744. (if (not (zerop relative-depth))
  3745. (allout-rebullet-heading nil nil nil nil t)))))
  3746. )
  3747. )
  3748. ;;;_ > allout-renumber-to-depth (&optional depth)
  3749. (defun allout-renumber-to-depth (&optional depth)
  3750. "Renumber siblings at current depth.
  3751. Affects superior topics if optional arg DEPTH is less than current depth.
  3752. Returns final depth."
  3753. ;; Proceed by level, processing subsequent siblings on each,
  3754. ;; ascending until we get shallower than the start depth:
  3755. (let ((ascender (allout-depth))
  3756. was-eobp)
  3757. (while (and (not (eobp))
  3758. (allout-depth)
  3759. (>= allout-recent-depth depth)
  3760. (>= ascender depth))
  3761. ; Skip over all topics at
  3762. ; lesser depths, which can not
  3763. ; have been disturbed:
  3764. (while (and (not (setq was-eobp (eobp)))
  3765. (> allout-recent-depth ascender))
  3766. (allout-next-heading))
  3767. ; Prime ascender for ascension:
  3768. (setq ascender (1- allout-recent-depth))
  3769. (if (>= allout-recent-depth depth)
  3770. (allout-rebullet-heading nil ;;; instead
  3771. nil ;;; depth
  3772. nil ;;; number-control
  3773. nil ;;; index
  3774. t)) ;;; do-successors
  3775. (if was-eobp (goto-char (point-max)))))
  3776. allout-recent-depth)
  3777. ;;;_ > allout-number-siblings (&optional denumber)
  3778. (defun allout-number-siblings (&optional denumber)
  3779. "Assign numbered topic prefix to this topic and its siblings.
  3780. With universal argument, denumber -- assign default bullet to this
  3781. topic and its siblings.
  3782. With repeated universal argument (`^U^U'), solicit bullet for each
  3783. rebulleting each topic at this level."
  3784. (interactive "P")
  3785. (save-excursion
  3786. (allout-back-to-current-heading)
  3787. (allout-beginning-of-level)
  3788. (let ((depth allout-recent-depth)
  3789. (index (if (not denumber) 1))
  3790. (use-bullet (equal '(16) denumber))
  3791. (more t))
  3792. (while more
  3793. (allout-rebullet-heading use-bullet ;;; instead
  3794. depth ;;; depth
  3795. t ;;; number-control
  3796. index ;;; index
  3797. nil) ;;; do-successors
  3798. (if index (setq index (1+ index)))
  3799. (setq more (allout-next-sibling depth nil))))))
  3800. ;;;_ > allout-shift-in (arg)
  3801. (defun allout-shift-in (arg)
  3802. "Increase depth of current heading and any items collapsed within it.
  3803. With a negative argument, the item is shifted out using
  3804. `allout-shift-out', instead.
  3805. With an argument greater than one, shift-in the item but not its
  3806. offspring, making the item into a sibling of its former children,
  3807. and a child of sibling that formerly preceded it.
  3808. You are not allowed to shift the first offspring of a topic
  3809. inwards, because that would yield a \"containment
  3810. discontinuity\", where the depth difference between a topic and
  3811. its immediate offspring is greater than one. The first topic in
  3812. the file can be adjusted to any positive depth, however."
  3813. (interactive "p")
  3814. (if (< arg 0)
  3815. (allout-shift-out (* arg -1))
  3816. ;; refuse to create a containment discontinuity:
  3817. (save-excursion
  3818. (allout-back-to-current-heading)
  3819. (if (not (bobp))
  3820. (let* ((current-depth allout-recent-depth)
  3821. (start-point (point))
  3822. (predecessor-depth (progn
  3823. (forward-char -1)
  3824. (allout-goto-prefix-doublechecked)
  3825. (if (< (point) start-point)
  3826. allout-recent-depth
  3827. 0))))
  3828. (if (and (> predecessor-depth 0)
  3829. (> (1+ current-depth)
  3830. (1+ predecessor-depth)))
  3831. (error (concat "Disallowed shift deeper than"
  3832. " containing topic's children."))
  3833. (allout-back-to-current-heading)
  3834. (if (< allout-recent-depth (1+ current-depth))
  3835. (allout-show-children))))))
  3836. (let ((where (point)))
  3837. (allout-rebullet-topic 1 (and (> arg 1) 'sans-offspring))
  3838. (run-hook-with-args 'allout-structure-shifted-hook arg where))))
  3839. ;;;_ > allout-shift-out (arg)
  3840. (defun allout-shift-out (arg)
  3841. "Decrease depth of current heading and any topics collapsed within it.
  3842. This will make the item a sibling of its former container.
  3843. With a negative argument, the item is shifted in using
  3844. `allout-shift-in', instead.
  3845. With an argument greater than one, shift-out the item's offspring
  3846. but not the item itself, making the former children siblings of
  3847. the item.
  3848. With an argument greater than 1, the item's offspring are shifted
  3849. out without shifting the item. This will make the immediate
  3850. subtopics into siblings of the item."
  3851. (interactive "p")
  3852. (if (< arg 0)
  3853. (allout-shift-in (* arg -1))
  3854. ;; Get proper exposure in this area:
  3855. (save-excursion (if (allout-ascend)
  3856. (allout-show-children)))
  3857. ;; Show collapsed children if there's a successor which will become
  3858. ;; their sibling:
  3859. (if (and (allout-current-topic-collapsed-p)
  3860. (save-excursion (allout-next-sibling)))
  3861. (allout-show-children))
  3862. (let ((where (and (allout-depth) allout-recent-prefix-beginning)))
  3863. (save-excursion
  3864. (if (> arg 1)
  3865. ;; Shift the offspring but not the topic:
  3866. (let ((children-chart (allout-chart-subtree 1)))
  3867. (if (listp (car children-chart))
  3868. ;; whoops:
  3869. (setq children-chart (allout-flatten children-chart)))
  3870. (save-excursion
  3871. (dolist (child-point children-chart)
  3872. (goto-char child-point)
  3873. (allout-shift-out 1))))
  3874. (allout-rebullet-topic (* arg -1))))
  3875. (run-hook-with-args 'allout-structure-shifted-hook (* arg -1) where))))
  3876. ;;;_ : Surgery (kill-ring) functions with special provisions for outlines:
  3877. ;;;_ > allout-kill-line (&optional arg)
  3878. (defun allout-kill-line (&optional arg)
  3879. "Kill line, adjusting subsequent lines suitably for outline mode."
  3880. (interactive "*P")
  3881. (if (or (not (allout-mode-p))
  3882. (not (bolp))
  3883. (not (save-match-data (looking-at allout-regexp))))
  3884. ;; Just do a regular kill:
  3885. (kill-line arg)
  3886. ;; Ah, have to watch out for adjustments:
  3887. (let* ((beg (point))
  3888. end
  3889. (beg-hidden (allout-hidden-p))
  3890. (end-hidden (save-excursion (allout-end-of-current-line)
  3891. (setq end (point))
  3892. (allout-hidden-p)))
  3893. (depth (allout-depth)))
  3894. (allout-annotate-hidden beg end)
  3895. (unwind-protect
  3896. (if (and (not beg-hidden) (not end-hidden))
  3897. (allout-unprotected (kill-line arg))
  3898. (kill-line arg))
  3899. (run-hooks 'allout-after-copy-or-kill-hook)
  3900. (allout-deannotate-hidden beg end)
  3901. (if allout-numbered-bullet
  3902. (save-excursion ; Renumber subsequent topics if needed:
  3903. (if (not (save-match-data (looking-at allout-regexp)))
  3904. (allout-next-heading))
  3905. (allout-renumber-to-depth depth)))
  3906. (run-hook-with-args 'allout-structure-deleted-hook depth (point))))))
  3907. ;;;_ > allout-copy-line-as-kill ()
  3908. (defun allout-copy-line-as-kill ()
  3909. "Like `allout-kill-topic', but save to kill ring instead of deleting."
  3910. (interactive)
  3911. (let ((buffer-read-only t))
  3912. (condition-case nil
  3913. (allout-kill-line)
  3914. (buffer-read-only nil))))
  3915. ;;;_ > allout-kill-topic ()
  3916. (defun allout-kill-topic ()
  3917. "Kill topic together with subtopics.
  3918. Trailing whitespace is killed with a topic if that whitespace:
  3919. - would separate the topic from a subsequent sibling
  3920. - would separate the topic from the end of buffer
  3921. - would not be added to whitespace already separating the topic from the
  3922. previous one.
  3923. Topic exposure is marked with text-properties, to be used by
  3924. `allout-yank-processing' for exposure recovery."
  3925. (interactive)
  3926. (let* ((inhibit-field-text-motion t)
  3927. (beg (prog1 (allout-back-to-current-heading) (beginning-of-line)))
  3928. end
  3929. (depth allout-recent-depth))
  3930. (allout-end-of-current-subtree)
  3931. (if (and (/= (current-column) 0) (not (eobp)))
  3932. (forward-char 1))
  3933. (if (not (eobp))
  3934. (if (and (save-match-data (looking-at "\n"))
  3935. (or (save-excursion
  3936. (or (not (allout-next-heading))
  3937. (= depth allout-recent-depth)))
  3938. (and (> (- beg (point-min)) 3)
  3939. (string= (buffer-substring (- beg 2) beg) "\n\n"))))
  3940. (forward-char 1)))
  3941. (allout-annotate-hidden beg (setq end (point)))
  3942. (unwind-protect ; for possible barf-if-buffer-read-only.
  3943. (allout-unprotected (kill-region beg end))
  3944. (allout-deannotate-hidden beg end)
  3945. (run-hooks 'allout-after-copy-or-kill-hook)
  3946. (save-excursion
  3947. (allout-renumber-to-depth depth))
  3948. (run-hook-with-args 'allout-structure-deleted-hook depth (point)))))
  3949. ;;;_ > allout-copy-topic-as-kill ()
  3950. (defun allout-copy-topic-as-kill ()
  3951. "Like `allout-kill-topic', but save to kill ring instead of deleting."
  3952. (interactive)
  3953. (let ((buffer-read-only t))
  3954. (condition-case nil
  3955. (allout-kill-topic)
  3956. (buffer-read-only (message "Topic copied...")))))
  3957. ;;;_ > allout-annotate-hidden (begin end)
  3958. (defun allout-annotate-hidden (begin end)
  3959. "Qualify text with properties to indicate exposure status."
  3960. (let ((was-modified (buffer-modified-p))
  3961. (buffer-read-only nil))
  3962. (allout-deannotate-hidden begin end)
  3963. (save-excursion
  3964. (goto-char begin)
  3965. (let (done next prev overlay)
  3966. (while (not done)
  3967. ;; at or advance to start of next hidden region:
  3968. (if (not (allout-hidden-p))
  3969. (setq next
  3970. (max (1+ (point))
  3971. (allout-next-single-char-property-change (point)
  3972. 'invisible
  3973. nil end))))
  3974. (if (or (not next) (eq prev next))
  3975. ;; still not at start of hidden area -- must not be any left.
  3976. (setq done t)
  3977. (goto-char next)
  3978. (setq prev next)
  3979. (if (not (allout-hidden-p))
  3980. ;; still not at start of hidden area.
  3981. (setq done t)
  3982. (setq overlay (allout-get-invisibility-overlay))
  3983. (setq next (overlay-end overlay)
  3984. prev next)
  3985. ;; advance to end of this hidden area:
  3986. (when next
  3987. (goto-char next)
  3988. (allout-unprotected
  3989. (let ((buffer-undo-list t))
  3990. (put-text-property (overlay-start overlay) next
  3991. 'allout-was-hidden t)))))))))
  3992. (set-buffer-modified-p was-modified)))
  3993. ;;;_ > allout-deannotate-hidden (begin end)
  3994. (defun allout-deannotate-hidden (begin end)
  3995. "Remove allout hidden-text annotation between BEGIN and END."
  3996. (allout-unprotected
  3997. (let ((inhibit-read-only t)
  3998. (buffer-undo-list t))
  3999. (remove-text-properties begin (min end (point-max))
  4000. '(allout-was-hidden t)))))
  4001. ;;;_ > allout-hide-by-annotation (begin end)
  4002. (defun allout-hide-by-annotation (begin end)
  4003. "Translate text properties indicating exposure status into actual exposure."
  4004. (save-excursion
  4005. (goto-char begin)
  4006. (let ((was-modified (buffer-modified-p))
  4007. done next prev)
  4008. (while (not done)
  4009. ;; at or advance to start of next annotation:
  4010. (if (not (get-text-property (point) 'allout-was-hidden))
  4011. (setq next (allout-next-single-char-property-change
  4012. (point) 'allout-was-hidden nil end)))
  4013. (if (or (not next) (eq prev next))
  4014. ;; no more or not advancing -- must not be any left.
  4015. (setq done t)
  4016. (goto-char next)
  4017. (setq prev next)
  4018. (if (not (get-text-property (point) 'allout-was-hidden))
  4019. ;; still not at start of annotation.
  4020. (setq done t)
  4021. ;; advance to just after end of this annotation:
  4022. (setq next (allout-next-single-char-property-change
  4023. (point) 'allout-was-hidden nil end))
  4024. (let ((o (make-overlay prev next nil 'front-advance)))
  4025. (overlay-put o 'category 'allout-exposure-category)
  4026. (overlay-put o 'evaporate t))
  4027. (allout-deannotate-hidden prev next)
  4028. (setq prev next)
  4029. (if next (goto-char next)))))
  4030. (set-buffer-modified-p was-modified))))
  4031. ;;;_ > allout-yank-processing ()
  4032. (defun allout-yank-processing (&optional arg)
  4033. "Incidental allout-specific business to be done just after text yanks.
  4034. Does depth adjustment of yanked topics, when:
  4035. 1 the stuff being yanked starts with a valid outline header prefix, and
  4036. 2 it is being yanked at the end of a line which consists of only a valid
  4037. topic prefix.
  4038. Also, adjusts numbering of subsequent siblings when appropriate.
  4039. Depth adjustment alters the depth of all the topics being yanked
  4040. the amount it takes to make the first topic have the depth of the
  4041. header into which it's being yanked.
  4042. The point is left in front of yanked, adjusted topics, rather than
  4043. at the end (and vice-versa with the mark). Non-adjusted yanks,
  4044. however, are left exactly like normal, non-allout-specific yanks."
  4045. (interactive "*P")
  4046. ; Get to beginning, leaving
  4047. ; region around subject:
  4048. (if (< (allout-mark-marker t) (point))
  4049. (exchange-point-and-mark))
  4050. (save-match-data
  4051. (let* ((subj-beg (point))
  4052. (into-bol (bolp))
  4053. (subj-end (allout-mark-marker t))
  4054. ;; 'resituate' if yanking an entire topic into topic header:
  4055. (resituate (and (let ((allout-inhibit-aberrance-doublecheck t))
  4056. (allout-e-o-prefix-p))
  4057. (looking-at allout-regexp)
  4058. (allout-prefix-data)))
  4059. ;; `rectify-numbering' if resituating (where several topics may
  4060. ;; be resituating) or yanking a topic into a topic slot (bol):
  4061. (rectify-numbering (or resituate
  4062. (and into-bol (looking-at allout-regexp)))))
  4063. (if resituate
  4064. ;; Yanking a topic into the start of a topic -- reconcile to fit:
  4065. (let* ((inhibit-field-text-motion t)
  4066. (prefix-len (if (not (match-end 1))
  4067. 1
  4068. (- (match-end 1) subj-beg)))
  4069. (subj-depth allout-recent-depth)
  4070. (prefix-bullet (allout-recent-bullet))
  4071. (adjust-to-depth
  4072. ;; Nil if adjustment unnecessary, otherwise depth to which
  4073. ;; adjustment should be made:
  4074. (save-excursion
  4075. (and (goto-char subj-end)
  4076. (eolp)
  4077. (goto-char subj-beg)
  4078. (and (looking-at allout-regexp)
  4079. (progn
  4080. (beginning-of-line)
  4081. (not (= (point) subj-beg)))
  4082. (looking-at allout-regexp)
  4083. (allout-prefix-data))
  4084. allout-recent-depth)))
  4085. (more t))
  4086. (setq rectify-numbering allout-numbered-bullet)
  4087. (if adjust-to-depth
  4088. ; Do the adjustment:
  4089. (progn
  4090. (save-restriction
  4091. (narrow-to-region subj-beg subj-end)
  4092. ; Trim off excessive blank
  4093. ; line at end, if any:
  4094. (goto-char (point-max))
  4095. (if (looking-at "^$")
  4096. (allout-unprotected (delete-char -1)))
  4097. ; Work backwards, with each
  4098. ; shallowest level,
  4099. ; successively excluding the
  4100. ; last processed topic from
  4101. ; the narrow region:
  4102. (while more
  4103. (allout-back-to-current-heading)
  4104. ; go as high as we can in each bunch:
  4105. (while (allout-ascend t))
  4106. (save-excursion
  4107. (allout-unprotected
  4108. (allout-rebullet-topic-grunt (- adjust-to-depth
  4109. subj-depth)))
  4110. (allout-depth))
  4111. (if (setq more (not (bobp)))
  4112. (progn (widen)
  4113. (forward-char -1)
  4114. (narrow-to-region subj-beg (point))))))
  4115. ;; Remove new heading prefix:
  4116. (allout-unprotected
  4117. (progn
  4118. (delete-region (point) (+ (point)
  4119. prefix-len
  4120. (- adjust-to-depth
  4121. subj-depth)))
  4122. ; and delete residual subj
  4123. ; prefix digits and space:
  4124. (while (looking-at "[0-9]") (delete-char 1))
  4125. (delete-char -1)
  4126. (if (not (eolp))
  4127. (forward-char))))
  4128. ;; Assert new topic's bullet - minimal effort if unchanged:
  4129. (allout-rebullet-heading (string-to-char prefix-bullet)))
  4130. (exchange-point-and-mark))))
  4131. (if rectify-numbering
  4132. (progn
  4133. (save-excursion
  4134. ; Give some preliminary feedback:
  4135. (message "... reconciling numbers")
  4136. ; ... and renumber, in case necessary:
  4137. (goto-char subj-beg)
  4138. (if (allout-goto-prefix-doublechecked)
  4139. (allout-unprotected
  4140. (allout-rebullet-heading nil ;;; instead
  4141. (allout-depth) ;;; depth
  4142. nil ;;; number-control
  4143. nil ;;; index
  4144. t)))
  4145. (message ""))))
  4146. (if (or into-bol resituate)
  4147. (allout-hide-by-annotation (point) (allout-mark-marker t))
  4148. (allout-deannotate-hidden (allout-mark-marker t) (point)))
  4149. (if (not resituate)
  4150. (exchange-point-and-mark))
  4151. (run-hook-with-args 'allout-structure-added-hook subj-beg subj-end))))
  4152. ;;;_ > allout-yank (&optional arg)
  4153. (defun allout-yank (&optional arg)
  4154. "`allout-mode' yank, with depth and numbering adjustment of yanked topics.
  4155. Non-topic yanks work no differently than normal yanks.
  4156. If a topic is being yanked into a bare topic prefix, the depth of the
  4157. yanked topic is adjusted to the depth of the topic prefix.
  4158. 1 we're yanking in an `allout-mode' buffer
  4159. 2 the stuff being yanked starts with a valid outline header prefix, and
  4160. 3 it is being yanked at the end of a line which consists of only a valid
  4161. topic prefix.
  4162. If these conditions hold then the depth of the yanked topics are all
  4163. adjusted the amount it takes to make the first one at the depth of the
  4164. header into which it's being yanked.
  4165. The point is left in front of yanked, adjusted topics, rather than
  4166. at the end (and vice-versa with the mark). Non-adjusted yanks,
  4167. however, (ones that don't qualify for adjustment) are handled
  4168. exactly like normal yanks.
  4169. Numbering of yanked topics, and the successive siblings at the depth
  4170. into which they're being yanked, is adjusted.
  4171. `allout-yank-pop' works with `allout-yank' just like normal `yank-pop'
  4172. works with normal `yank' in non-outline buffers."
  4173. (interactive "*P")
  4174. (setq this-command 'yank)
  4175. (allout-unprotected
  4176. (yank arg))
  4177. (if (allout-mode-p)
  4178. (allout-yank-processing)))
  4179. ;;;_ > allout-yank-pop (&optional arg)
  4180. (defun allout-yank-pop (&optional arg)
  4181. "Yank-pop like `allout-yank' when popping to bare outline prefixes.
  4182. Adapts level of popped topics to level of fresh prefix.
  4183. Note -- prefix changes to distinctive bullets will stick, if followed
  4184. by pops to non-distinctive yanks. Bug..."
  4185. (interactive "*p")
  4186. (setq this-command 'yank)
  4187. (yank-pop arg)
  4188. (if (allout-mode-p)
  4189. (allout-yank-processing)))
  4190. ;;;_ - Specialty bullet functions
  4191. ;;;_ : File Cross references
  4192. ;;;_ > allout-resolve-xref ()
  4193. (defun allout-resolve-xref ()
  4194. "Pop to file associated with current heading, if it has an xref bullet.
  4195. \(Works according to setting of `allout-file-xref-bullet')."
  4196. (interactive)
  4197. (if (not allout-file-xref-bullet)
  4198. (error
  4199. "Outline cross references disabled -- no `allout-file-xref-bullet'")
  4200. (if (not (string= (allout-current-bullet) allout-file-xref-bullet))
  4201. (error "Current heading lacks cross-reference bullet `%s'"
  4202. allout-file-xref-bullet)
  4203. (let ((inhibit-field-text-motion t)
  4204. file-name)
  4205. (save-match-data
  4206. (save-excursion
  4207. (let* ((text-start allout-recent-prefix-end)
  4208. (heading-end (point-at-eol)))
  4209. (goto-char text-start)
  4210. (setq file-name
  4211. (if (re-search-forward "\\s-\\(\\S-*\\)" heading-end t)
  4212. (buffer-substring (match-beginning 1)
  4213. (match-end 1)))))))
  4214. (setq file-name (expand-file-name file-name))
  4215. (if (or (file-exists-p file-name)
  4216. (if (file-writable-p file-name)
  4217. (y-or-n-p (format "%s not there, create one? "
  4218. file-name))
  4219. (error "%s not found and can't be created" file-name)))
  4220. (condition-case failure
  4221. (find-file-other-window file-name)
  4222. (error failure))
  4223. (error "%s not found" file-name))
  4224. )
  4225. )
  4226. )
  4227. )
  4228. ;;;_ #6 Exposure Control
  4229. ;;;_ - Fundamental
  4230. ;;;_ > allout-flag-region (from to flag)
  4231. (defun allout-flag-region (from to flag)
  4232. "Conceal text between FROM and TO if FLAG is non-nil, else reveal it.
  4233. Exposure-change hook `allout-exposure-change-hook' is run with the same
  4234. arguments as this function, after the exposure changes are made."
  4235. ;; We use outline invisibility spec.
  4236. (remove-overlays from to 'category 'allout-exposure-category)
  4237. (when flag
  4238. (let ((o (make-overlay from to nil 'front-advance)))
  4239. (overlay-put o 'category 'allout-exposure-category)
  4240. (overlay-put o 'evaporate t)
  4241. (when (featurep 'xemacs)
  4242. (let ((props (symbol-plist 'allout-exposure-category)))
  4243. (while props
  4244. (condition-case nil
  4245. ;; as of 2008-02-27, xemacs lacks modification-hooks
  4246. (overlay-put o (pop props) (pop props))
  4247. (error nil))))))
  4248. (setq allout-this-command-hid-text t))
  4249. (run-hook-with-args 'allout-exposure-change-hook from to flag))
  4250. ;;;_ > allout-flag-current-subtree (flag)
  4251. (defun allout-flag-current-subtree (flag)
  4252. "Conceal currently-visible topic's subtree if FLAG non-nil, else reveal it."
  4253. (save-excursion
  4254. (allout-back-to-current-heading)
  4255. (let ((inhibit-field-text-motion t))
  4256. (end-of-line))
  4257. (allout-flag-region (point)
  4258. ;; Exposing must not leave trailing blanks hidden,
  4259. ;; but can leave them exposed when hiding, so we
  4260. ;; can use flag's inverse as the
  4261. ;; include-trailing-blank cue:
  4262. (allout-end-of-current-subtree (not flag))
  4263. flag)))
  4264. ;;;_ - Topic-specific
  4265. ;;;_ > allout-show-entry ()
  4266. (defun allout-show-entry ()
  4267. "Like `allout-show-current-entry', but reveals entries in hidden topics.
  4268. This is a way to give restricted peek at a concealed locality without the
  4269. expense of exposing its context, but can leave the outline with aberrant
  4270. exposure. `allout-show-offshoot' should be used after the peek to rectify
  4271. the exposure."
  4272. (interactive)
  4273. (save-excursion
  4274. (let (beg end)
  4275. (allout-goto-prefix-doublechecked)
  4276. (setq beg (if (allout-hidden-p) (1- (point)) (point)))
  4277. (setq end (allout-pre-next-prefix))
  4278. (allout-flag-region beg end nil)
  4279. (list beg end))))
  4280. ;;;_ > allout-show-children (&optional level strict)
  4281. (defun allout-show-children (&optional level strict)
  4282. "If point is visible, show all direct subheadings of this heading.
  4283. Otherwise, do `allout-show-to-offshoot', and then show subheadings.
  4284. Optional LEVEL specifies how many levels below the current level
  4285. should be shown, or all levels if t. Default is 1.
  4286. Optional STRICT means don't resort to -show-to-offshoot, no matter
  4287. what. This is basically so -show-to-offshoot, which is called by
  4288. this function, can employ the pure offspring-revealing capabilities of
  4289. it.
  4290. Returns point at end of subtree that was opened, if any. (May get a
  4291. point of non-opened subtree?)"
  4292. (interactive "p")
  4293. (let ((start-point (point)))
  4294. (if (and (not strict)
  4295. (allout-hidden-p))
  4296. (progn (allout-show-to-offshoot) ; Point's concealed, open to
  4297. ; expose it.
  4298. ;; Then recurse, but with "strict" set so we don't
  4299. ;; infinite regress:
  4300. (allout-show-children level t))
  4301. (save-excursion
  4302. (allout-beginning-of-current-line)
  4303. (save-restriction
  4304. (let* (depth
  4305. ;; translate the level spec for this routine to the ones
  4306. ;; used by -chart-subtree and -chart-to-reveal:
  4307. (chart-level (cond ((not level) 1)
  4308. ((eq level t) nil)
  4309. (t level)))
  4310. (chart (allout-chart-subtree chart-level))
  4311. (to-reveal (or (allout-chart-to-reveal chart chart-level)
  4312. ;; interactive, show discontinuous children:
  4313. (and chart
  4314. (allout-called-interactively-p)
  4315. (save-excursion
  4316. (allout-back-to-current-heading)
  4317. (setq depth (allout-current-depth))
  4318. (and (allout-next-heading)
  4319. (> allout-recent-depth
  4320. (1+ depth))))
  4321. (message
  4322. "Discontinuous offspring; use `%s %s'%s."
  4323. (substitute-command-keys
  4324. "\\[universal-argument]")
  4325. (substitute-command-keys
  4326. "\\[allout-shift-out]")
  4327. " to elevate them.")
  4328. (allout-chart-to-reveal
  4329. chart (- allout-recent-depth depth))))))
  4330. (goto-char start-point)
  4331. (when (and strict (allout-hidden-p))
  4332. ;; Concealed root would already have been taken care of,
  4333. ;; unless strict was set.
  4334. (allout-flag-region (point) (allout-snug-back) nil)
  4335. (when allout-show-bodies
  4336. (goto-char (car to-reveal))
  4337. (allout-show-current-entry)))
  4338. (while to-reveal
  4339. (goto-char (car to-reveal))
  4340. (allout-flag-region (save-excursion (allout-snug-back) (point))
  4341. (progn (search-forward "\n" nil t)
  4342. (1- (point)))
  4343. nil)
  4344. (when allout-show-bodies
  4345. (goto-char (car to-reveal))
  4346. (allout-show-current-entry))
  4347. (setq to-reveal (cdr to-reveal)))))))
  4348. ;; Compensate for `save-excursion's maintenance of point
  4349. ;; within invisible text:
  4350. (goto-char start-point)))
  4351. ;;;_ > allout-show-to-offshoot ()
  4352. (defun allout-show-to-offshoot ()
  4353. "Like `allout-show-entry', but reveals all concealed ancestors, as well.
  4354. Useful for coherently exposing to a random point in a hidden region."
  4355. (interactive)
  4356. (save-excursion
  4357. (let ((inhibit-field-text-motion t)
  4358. (orig-pt (point))
  4359. (orig-pref (allout-goto-prefix-doublechecked))
  4360. (last-at (point))
  4361. (bag-it 0))
  4362. (while (or (> bag-it 1) (allout-hidden-p))
  4363. (while (allout-hidden-p)
  4364. (move-beginning-of-line 1)
  4365. (if (allout-hidden-p) (forward-char -1)))
  4366. (if (= last-at (setq last-at (point)))
  4367. ;; Oops, we're not making any progress! Show the current topic
  4368. ;; completely, and try one more time here, if we haven't already.
  4369. (progn (beginning-of-line)
  4370. (allout-show-current-subtree)
  4371. (goto-char orig-pt)
  4372. (setq bag-it (1+ bag-it))
  4373. (if (> bag-it 1)
  4374. (error "allout-show-to-offshoot: %s"
  4375. "Stumped by aberrant nesting.")))
  4376. (if (> bag-it 0) (setq bag-it 0))
  4377. (allout-show-children)
  4378. (goto-char orig-pref)))
  4379. (goto-char orig-pt)))
  4380. (if (allout-hidden-p)
  4381. (allout-show-entry)))
  4382. ;;;_ > allout-hide-current-entry ()
  4383. (defun allout-hide-current-entry ()
  4384. "Hide the body directly following this heading."
  4385. (interactive)
  4386. (allout-back-to-current-heading)
  4387. (save-excursion
  4388. (let ((inhibit-field-text-motion t))
  4389. (end-of-line))
  4390. (allout-flag-region (point)
  4391. (progn (allout-end-of-entry) (point))
  4392. t)))
  4393. ;;;_ > allout-show-current-entry (&optional arg)
  4394. (defun allout-show-current-entry (&optional arg)
  4395. "Show body following current heading, or hide entry with universal argument."
  4396. (interactive "P")
  4397. (if arg
  4398. (allout-hide-current-entry)
  4399. (save-excursion (allout-show-to-offshoot))
  4400. (save-excursion
  4401. (allout-flag-region (point)
  4402. (progn (allout-end-of-entry t) (point))
  4403. nil)
  4404. )))
  4405. ;;;_ > allout-show-current-subtree (&optional arg)
  4406. (defun allout-show-current-subtree (&optional arg)
  4407. "Show everything within the current topic.
  4408. With a repeat-count, expose this topic and its siblings."
  4409. (interactive "P")
  4410. (save-excursion
  4411. (if (<= (allout-current-depth) 0)
  4412. ;; Outside any topics -- try to get to the first:
  4413. (if (not (allout-next-heading))
  4414. (error "No topics")
  4415. ;; got to first, outermost topic -- set to expose it and siblings:
  4416. (message "Above outermost topic -- exposing all.")
  4417. (allout-flag-region (point-min)(point-max) nil))
  4418. (allout-beginning-of-current-line)
  4419. (if (not arg)
  4420. (allout-flag-current-subtree nil)
  4421. (allout-beginning-of-level)
  4422. (allout-expose-topic '(* :))))))
  4423. ;;;_ > allout-current-topic-collapsed-p (&optional include-single-liners)
  4424. (defun allout-current-topic-collapsed-p (&optional include-single-liners)
  4425. "True if the currently visible containing topic is already collapsed.
  4426. Single line topics intrinsically can be considered as being both
  4427. collapsed and uncollapsed. If optional INCLUDE-SINGLE-LINERS is
  4428. true, then single-line topics are considered to be collapsed. By
  4429. default, they are treated as being uncollapsed."
  4430. (save-match-data
  4431. (save-excursion
  4432. (and
  4433. ;; Is the topic all on one line (allowing for trailing blank line)?
  4434. (>= (progn (allout-back-to-current-heading)
  4435. (let ((inhibit-field-text-motion t))
  4436. (move-end-of-line 1))
  4437. (point))
  4438. (allout-end-of-current-subtree (not (looking-at "\n\n"))))
  4439. (or include-single-liners
  4440. (progn (backward-char 1) (allout-hidden-p)))))))
  4441. ;;;_ > allout-hide-current-subtree (&optional just-close)
  4442. (defun allout-hide-current-subtree (&optional just-close)
  4443. "Close the current topic, or containing topic if this one is already closed.
  4444. If this topic is closed and it's a top level topic, close this topic
  4445. and its siblings.
  4446. If optional arg JUST-CLOSE is non-nil, do not close the parent or
  4447. siblings, even if the target topic is already closed."
  4448. (interactive)
  4449. (let* ((from (point))
  4450. (sibs-msg "Top-level topic already closed -- closing siblings...")
  4451. (current-exposed (not (allout-current-topic-collapsed-p t))))
  4452. (cond (current-exposed (allout-flag-current-subtree t))
  4453. (just-close nil)
  4454. ((allout-ascend) (allout-hide-current-subtree))
  4455. (t (goto-char 0)
  4456. (message sibs-msg)
  4457. (allout-goto-prefix-doublechecked)
  4458. (allout-expose-topic '(0 :))
  4459. (message (concat sibs-msg " Done."))))
  4460. (goto-char from)))
  4461. ;;;_ > allout-toggle-current-subtree-exposure
  4462. (defun allout-toggle-current-subtree-exposure ()
  4463. "Show or hide the current subtree depending on its current state."
  4464. ;; thanks to tassilo for suggesting this.
  4465. (interactive)
  4466. (save-excursion
  4467. (allout-back-to-heading)
  4468. (if (allout-hidden-p (point-at-eol))
  4469. (allout-show-current-subtree)
  4470. (allout-hide-current-subtree))))
  4471. ;;;_ > allout-show-current-branches ()
  4472. (defun allout-show-current-branches ()
  4473. "Show all subheadings of this heading, but not their bodies."
  4474. (interactive)
  4475. (let ((inhibit-field-text-motion t))
  4476. (beginning-of-line))
  4477. (allout-show-children t))
  4478. ;;;_ > allout-hide-current-leaves ()
  4479. (defun allout-hide-current-leaves ()
  4480. "Hide the bodies of the current topic and all its offspring."
  4481. (interactive)
  4482. (allout-back-to-current-heading)
  4483. (allout-hide-region-body (point) (progn (allout-end-of-current-subtree)
  4484. (point))))
  4485. ;;;_ - Region and beyond
  4486. ;;;_ > allout-show-all ()
  4487. (defun allout-show-all ()
  4488. "Show all of the text in the buffer."
  4489. (interactive)
  4490. (message "Exposing entire buffer...")
  4491. (allout-flag-region (point-min) (point-max) nil)
  4492. (message "Exposing entire buffer... Done."))
  4493. ;;;_ > allout-hide-bodies ()
  4494. (defun allout-hide-bodies ()
  4495. "Hide all of buffer except headings."
  4496. (interactive)
  4497. (allout-hide-region-body (point-min) (point-max)))
  4498. ;;;_ > allout-hide-region-body (start end)
  4499. (defun allout-hide-region-body (start end)
  4500. "Hide all body lines in the region, but not headings."
  4501. (save-match-data
  4502. (save-excursion
  4503. (save-restriction
  4504. (narrow-to-region start end)
  4505. (goto-char (point-min))
  4506. (let ((inhibit-field-text-motion t))
  4507. (while (not (eobp))
  4508. (end-of-line)
  4509. (allout-flag-region (point) (allout-end-of-entry) t)
  4510. (if (not (eobp))
  4511. (forward-char
  4512. (if (looking-at "\n\n")
  4513. 2 1)))))))))
  4514. ;;;_ > allout-expose-topic (spec)
  4515. (defun allout-expose-topic (spec)
  4516. "Apply exposure specs to successive outline topic items.
  4517. Use the more convenient frontend, `allout-new-exposure', if you don't
  4518. need evaluation of the arguments, or even better, the `allout-layout'
  4519. variable-keyed mode-activation/auto-exposure feature of allout outline
  4520. mode. See the respective documentation strings for more details.
  4521. Cursor is left at start position.
  4522. SPEC is either a number or a list.
  4523. Successive specs on a list are applied to successive sibling topics.
  4524. A simple spec (either a number, one of a few symbols, or the null
  4525. list) dictates the exposure for the corresponding topic.
  4526. Non-null lists recursively designate exposure specs for respective
  4527. subtopics of the current topic.
  4528. The `:' repeat spec is used to specify exposure for any number of
  4529. successive siblings, up to the trailing ones for which there are
  4530. explicit specs following the `:'.
  4531. Simple (numeric and null-list) specs are interpreted as follows:
  4532. Numbers indicate the relative depth to open the corresponding topic.
  4533. - negative numbers force the topic to be closed before opening to the
  4534. absolute value of the number, so all siblings are open only to
  4535. that level.
  4536. - positive numbers open to the relative depth indicated by the
  4537. number, but do not force already opened subtopics to be closed.
  4538. - 0 means to close topic -- hide all offspring.
  4539. : - `repeat'
  4540. apply prior element to all siblings at current level, *up to*
  4541. those siblings that would be covered by specs following the `:'
  4542. on the list. Ie, apply to all topics at level but the last
  4543. ones. (Only first of multiple colons at same level is
  4544. respected -- subsequent ones are discarded.)
  4545. * - completely opens the topic, including bodies.
  4546. + - shows all the sub headers, but not the bodies
  4547. - - exposes the body of the corresponding topic.
  4548. Examples:
  4549. \(allout-expose-topic '(-1 : 0))
  4550. Close this and all following topics at current level, exposing
  4551. only their immediate children, but close down the last topic
  4552. at this current level completely.
  4553. \(allout-expose-topic '(-1 () : 1 0))
  4554. Close current topic so only the immediate subtopics are shown;
  4555. show the children in the second to last topic, and completely
  4556. close the last one.
  4557. \(allout-expose-topic '(-2 : -1 *))
  4558. Expose children and grandchildren of all topics at current
  4559. level except the last two; expose children of the second to
  4560. last and completely open the last one."
  4561. (interactive "xExposure spec: ")
  4562. (if (not (listp spec))
  4563. nil
  4564. (let ((depth (allout-depth))
  4565. (max-pos 0)
  4566. prev-elem curr-elem
  4567. stay)
  4568. (while spec
  4569. (setq prev-elem curr-elem
  4570. curr-elem (car spec)
  4571. spec (cdr spec))
  4572. (cond ; Do current element:
  4573. ((null curr-elem) nil)
  4574. ((symbolp curr-elem)
  4575. (cond ((eq curr-elem '*) (allout-show-current-subtree)
  4576. (if (> allout-recent-end-of-subtree max-pos)
  4577. (setq max-pos allout-recent-end-of-subtree)))
  4578. ((eq curr-elem '+)
  4579. (if (not (allout-hidden-p))
  4580. (save-excursion (allout-hide-current-subtree t)))
  4581. (allout-show-current-branches)
  4582. (if (> allout-recent-end-of-subtree max-pos)
  4583. (setq max-pos allout-recent-end-of-subtree)))
  4584. ((eq curr-elem '-) (allout-show-current-entry))
  4585. ((eq curr-elem ':)
  4586. (setq stay t)
  4587. ;; Expand the `repeat' spec to an explicit version,
  4588. ;; w.r.t. remaining siblings:
  4589. (let ((residue ; = # of sibs not covered by remaining spec
  4590. ;; Dang, could be nice to make use of the chart, sigh:
  4591. (- (length (allout-chart-siblings))
  4592. (length spec))))
  4593. (if (< 0 residue)
  4594. ;; Some residue -- cover it with prev-elem:
  4595. (setq spec (append (make-list residue prev-elem)
  4596. spec)))))))
  4597. ((numberp curr-elem)
  4598. (if (and (>= 0 curr-elem) (not (allout-hidden-p)))
  4599. (save-excursion (allout-hide-current-subtree t)
  4600. (if (> 0 curr-elem)
  4601. nil
  4602. (if (> allout-recent-end-of-subtree max-pos)
  4603. (setq max-pos
  4604. allout-recent-end-of-subtree)))))
  4605. (if (> (abs curr-elem) 0)
  4606. (progn (allout-show-children (abs curr-elem))
  4607. (if (> allout-recent-end-of-subtree max-pos)
  4608. (setq max-pos allout-recent-end-of-subtree)))))
  4609. ((listp curr-elem)
  4610. (if (allout-descend-to-depth (1+ depth))
  4611. (let ((got (allout-expose-topic curr-elem)))
  4612. (if (and got (> got max-pos)) (setq max-pos got))))))
  4613. (cond (stay (setq stay nil))
  4614. ((listp (car spec)) nil)
  4615. ((> max-pos (point))
  4616. ;; Capitalize on max-pos state to get us nearer next sibling:
  4617. (progn (goto-char (min (point-max) max-pos))
  4618. (allout-next-heading)))
  4619. ((allout-next-sibling depth))))
  4620. max-pos)))
  4621. ;;;_ > allout-old-expose-topic (spec &rest followers)
  4622. (defun allout-old-expose-topic (spec &rest followers)
  4623. "Deprecated. Use `allout-expose-topic' (with different schema
  4624. format) instead.
  4625. Dictate wholesale exposure scheme for current topic, according to SPEC.
  4626. SPEC is either a number or a list. Optional successive args
  4627. dictate exposure for subsequent siblings of current topic.
  4628. A simple spec (either a number, a special symbol, or the null list)
  4629. dictates the overall exposure for a topic. Non null lists are
  4630. composite specs whose first element dictates the overall exposure for
  4631. a topic, with the subsequent elements in the list interpreted as specs
  4632. that dictate the exposure for the successive offspring of the topic.
  4633. Simple (numeric and null-list) specs are interpreted as follows:
  4634. - Numbers indicate the relative depth to open the corresponding topic:
  4635. - negative numbers force the topic to be close before opening to the
  4636. absolute value of the number.
  4637. - positive numbers just open to the relative depth indicated by the number.
  4638. - 0 just closes
  4639. - `*' completely opens the topic, including bodies.
  4640. - `+' shows all the sub headers, but not the bodies
  4641. - `-' exposes the body and immediate offspring of the corresponding topic.
  4642. If the spec is a list, the first element must be a number, which
  4643. dictates the exposure depth of the topic as a whole. Subsequent
  4644. elements of the list are nested SPECs, dictating the specific exposure
  4645. for the corresponding offspring of the topic.
  4646. Optional FOLLOWERS arguments dictate exposure for succeeding siblings."
  4647. (interactive "xExposure spec: ")
  4648. (let ((inhibit-field-text-motion t)
  4649. (depth (allout-current-depth))
  4650. max-pos)
  4651. (cond ((null spec) nil)
  4652. ((symbolp spec)
  4653. (if (eq spec '*) (allout-show-current-subtree))
  4654. (if (eq spec '+) (allout-show-current-branches))
  4655. (if (eq spec '-) (allout-show-current-entry)))
  4656. ((numberp spec)
  4657. (if (>= 0 spec)
  4658. (save-excursion (allout-hide-current-subtree t)
  4659. (end-of-line)
  4660. (if (or (not max-pos)
  4661. (> (point) max-pos))
  4662. (setq max-pos (point)))
  4663. (if (> 0 spec)
  4664. (setq spec (* -1 spec)))))
  4665. (if (> spec 0)
  4666. (allout-show-children spec)))
  4667. ((listp spec)
  4668. ;(let ((got (allout-old-expose-topic (car spec))))
  4669. ; (if (and got (or (not max-pos) (> got max-pos)))
  4670. ; (setq max-pos got)))
  4671. (let ((new-depth (+ (allout-current-depth) 1))
  4672. got)
  4673. (setq max-pos (allout-old-expose-topic (car spec)))
  4674. (setq spec (cdr spec))
  4675. (if (and spec
  4676. (allout-descend-to-depth new-depth)
  4677. (not (allout-hidden-p)))
  4678. (progn (setq got (apply 'allout-old-expose-topic spec))
  4679. (if (and got (or (not max-pos) (> got max-pos)))
  4680. (setq max-pos got)))))))
  4681. (while (and followers
  4682. (progn (if (and max-pos (< (point) max-pos))
  4683. (progn (goto-char max-pos)
  4684. (setq max-pos nil)))
  4685. (end-of-line)
  4686. (allout-next-sibling depth)))
  4687. (allout-old-expose-topic (car followers))
  4688. (setq followers (cdr followers)))
  4689. max-pos))
  4690. ;;;_ > allout-new-exposure '()
  4691. (defmacro allout-new-exposure (&rest spec)
  4692. "Literal frontend for `allout-expose-topic', doesn't evaluate arguments.
  4693. Some arguments that would need to be quoted in `allout-expose-topic'
  4694. need not be quoted in `allout-new-exposure'.
  4695. Cursor is left at start position.
  4696. Use this instead of obsolete `allout-exposure'.
  4697. Examples:
  4698. \(allout-new-exposure (-1 () () () 1) 0)
  4699. Close current topic at current level so only the immediate
  4700. subtopics are shown, except also show the children of the
  4701. third subtopic; and close the next topic at the current level.
  4702. \(allout-new-exposure : -1 0)
  4703. Close all topics at current level to expose only their
  4704. immediate children, except for the last topic at the current
  4705. level, in which even its immediate children are hidden.
  4706. \(allout-new-exposure -2 : -1 *)
  4707. Expose children and grandchildren of first topic at current
  4708. level, and expose children of subsequent topics at current
  4709. level *except* for the last, which should be opened completely."
  4710. (list 'save-excursion
  4711. '(if (not (or (allout-goto-prefix-doublechecked)
  4712. (allout-next-heading)))
  4713. (error "allout-new-exposure: Can't find any outline topics"))
  4714. (list 'allout-expose-topic (list 'quote spec))))
  4715. ;;;_ #7 Systematic outline presentation -- copying, printing, flattening
  4716. ;;;_ - Mapping and processing of topics
  4717. ;;;_ ( See also Subtree Charting, in Navigation code.)
  4718. ;;;_ > allout-stringify-flat-index (flat-index)
  4719. (defun allout-stringify-flat-index (flat-index &optional context)
  4720. "Convert list representing section/subsection/... to document string.
  4721. Optional arg CONTEXT indicates interior levels to include."
  4722. (let ((delim ".")
  4723. result
  4724. numstr
  4725. (context-depth (or (and context 2) 1)))
  4726. ;; Take care of the explicit context:
  4727. (while (> context-depth 0)
  4728. (setq numstr (int-to-string (car flat-index))
  4729. flat-index (cdr flat-index)
  4730. result (if flat-index
  4731. (cons delim (cons numstr result))
  4732. (cons numstr result))
  4733. context-depth (if flat-index (1- context-depth) 0)))
  4734. (setq delim " ")
  4735. ;; Take care of the indentation:
  4736. (if flat-index
  4737. (progn
  4738. (while flat-index
  4739. (setq result
  4740. (cons delim
  4741. (cons (make-string
  4742. (1+ (truncate (if (zerop (car flat-index))
  4743. 1
  4744. (log10 (car flat-index)))))
  4745. ? )
  4746. result)))
  4747. (setq flat-index (cdr flat-index)))
  4748. ;; Dispose of single extra delim:
  4749. (setq result (cdr result))))
  4750. (apply 'concat result)))
  4751. ;;;_ > allout-stringify-flat-index-plain (flat-index)
  4752. (defun allout-stringify-flat-index-plain (flat-index)
  4753. "Convert list representing section/subsection/... to document string."
  4754. (let ((delim ".")
  4755. result)
  4756. (while flat-index
  4757. (setq result (cons (int-to-string (car flat-index))
  4758. (if result
  4759. (cons delim result))))
  4760. (setq flat-index (cdr flat-index)))
  4761. (apply 'concat result)))
  4762. ;;;_ > allout-stringify-flat-index-indented (flat-index)
  4763. (defun allout-stringify-flat-index-indented (flat-index)
  4764. "Convert list representing section/subsection/... to document string."
  4765. (let ((delim ".")
  4766. result
  4767. numstr)
  4768. ;; Take care of the explicit context:
  4769. (setq numstr (int-to-string (car flat-index))
  4770. flat-index (cdr flat-index)
  4771. result (if flat-index
  4772. (cons delim (cons numstr result))
  4773. (cons numstr result)))
  4774. (setq delim " ")
  4775. ;; Take care of the indentation:
  4776. (if flat-index
  4777. (progn
  4778. (while flat-index
  4779. (setq result
  4780. (cons delim
  4781. (cons (make-string
  4782. (1+ (truncate (if (zerop (car flat-index))
  4783. 1
  4784. (log10 (car flat-index)))))
  4785. ? )
  4786. result)))
  4787. (setq flat-index (cdr flat-index)))
  4788. ;; Dispose of single extra delim:
  4789. (setq result (cdr result))))
  4790. (apply 'concat result)))
  4791. ;;;_ > allout-listify-exposed (&optional start end format)
  4792. (defun allout-listify-exposed (&optional start end format)
  4793. "Produce a list representing exposed topics in current region.
  4794. This list can then be used by `allout-process-exposed' to manipulate
  4795. the subject region.
  4796. Optional START and END indicate bounds of region.
  4797. Optional arg, FORMAT, designates an alternate presentation form for
  4798. the prefix:
  4799. list -- Present prefix as numeric section.subsection..., starting with
  4800. section indicated by the list, innermost nesting first.
  4801. `indent' (symbol) -- Convert header prefixes to all white space,
  4802. except for distinctive bullets.
  4803. The elements of the list produced are lists that represents a topic
  4804. header and body. The elements of that list are:
  4805. - a number representing the depth of the topic,
  4806. - a string representing the header-prefix, including trailing whitespace and
  4807. bullet.
  4808. - a string representing the bullet character,
  4809. - and a series of strings, each containing one line of the exposed
  4810. portion of the topic entry."
  4811. (interactive "r")
  4812. (save-excursion
  4813. (let*
  4814. ((inhibit-field-text-motion t)
  4815. ;; state vars:
  4816. strings prefix result depth new-depth out gone-out bullet beg
  4817. next done)
  4818. (goto-char start)
  4819. (beginning-of-line)
  4820. ;; Goto initial topic, and register preceding stuff, if any:
  4821. (if (> (allout-goto-prefix-doublechecked) start)
  4822. ;; First topic follows beginning point -- register preliminary stuff:
  4823. (setq result
  4824. (list (list 0 "" nil
  4825. (buffer-substring-no-properties start
  4826. (1- (point)))))))
  4827. (while (and (not done)
  4828. (not (eobp)) ; Loop until we've covered the region.
  4829. (not (> (point) end)))
  4830. (setq depth allout-recent-depth ; Current topics depth,
  4831. bullet (allout-recent-bullet) ; ... bullet,
  4832. prefix (allout-recent-prefix)
  4833. beg (progn (allout-end-of-prefix t) (point))) ; and beginning.
  4834. (setq done ; The boundary for the current topic:
  4835. (not (allout-next-visible-heading 1)))
  4836. (setq new-depth allout-recent-depth)
  4837. (setq gone-out out
  4838. out (< new-depth depth))
  4839. (beginning-of-line)
  4840. (setq next (point))
  4841. (goto-char beg)
  4842. (setq strings nil)
  4843. (while (> next (point)) ; Get all the exposed text in
  4844. (setq strings
  4845. (cons (buffer-substring-no-properties
  4846. beg
  4847. ;To hidden text or end of line:
  4848. (progn
  4849. (end-of-line)
  4850. (allout-back-to-visible-text)))
  4851. strings))
  4852. (when (< (point) next) ; Resume from after hid text, if any.
  4853. (line-move 1)
  4854. (beginning-of-line))
  4855. (setq beg (point)))
  4856. ;; Accumulate list for this topic:
  4857. (setq strings (nreverse strings))
  4858. (setq result
  4859. (cons
  4860. (if format
  4861. (let ((special (if (string-match
  4862. (regexp-quote bullet)
  4863. allout-distinctive-bullets-string)
  4864. bullet)))
  4865. (cond ((listp format)
  4866. (list depth
  4867. (if allout-flattened-numbering-abbreviation
  4868. (allout-stringify-flat-index format
  4869. gone-out)
  4870. (allout-stringify-flat-index-plain
  4871. format))
  4872. strings
  4873. special))
  4874. ((eq format 'indent)
  4875. (if special
  4876. (list depth
  4877. (concat (make-string (1+ depth) ? )
  4878. (substring prefix -1))
  4879. strings)
  4880. (list depth
  4881. (make-string depth ? )
  4882. strings)))
  4883. (t (error "allout-listify-exposed: %s %s"
  4884. "invalid format" format))))
  4885. (list depth prefix strings))
  4886. result))
  4887. ;; Reassess format, if any:
  4888. (if (and format (listp format))
  4889. (cond ((= new-depth depth)
  4890. (setq format (cons (1+ (car format))
  4891. (cdr format))))
  4892. ((> new-depth depth) ; descending -- assume by 1:
  4893. (setq format (cons 1 format)))
  4894. (t
  4895. ; Pop the residue:
  4896. (while (< new-depth depth)
  4897. (setq format (cdr format))
  4898. (setq depth (1- depth)))
  4899. ; And increment the current one:
  4900. (setq format
  4901. (cons (1+ (or (car format)
  4902. -1))
  4903. (cdr format)))))))
  4904. ;; Put the list with first at front, to last at back:
  4905. (nreverse result))))
  4906. ;;;_ > allout-region-active-p ()
  4907. (defmacro allout-region-active-p ()
  4908. (cond ((fboundp 'use-region-p) '(use-region-p))
  4909. ((fboundp 'region-active-p) '(region-active-p))
  4910. (t 'mark-active)))
  4911. ;;_ > allout-process-exposed (&optional func from to frombuf
  4912. ;;; tobuf format)
  4913. (defun allout-process-exposed (&optional func from to frombuf tobuf
  4914. format start-num)
  4915. "Map function on exposed parts of current topic; results to another buffer.
  4916. All args are options; default values itemized below.
  4917. Apply FUNCTION to exposed portions FROM position TO position in buffer
  4918. FROMBUF to buffer TOBUF. Sixth optional arg, FORMAT, designates an
  4919. alternate presentation form:
  4920. `flat' -- Present prefix as numeric section.subsection..., starting with
  4921. section indicated by the START-NUM, innermost nesting first.
  4922. X`flat-indented' -- Prefix is like `flat' for first topic at each
  4923. X level, but subsequent topics have only leaf topic
  4924. X number, padded with blanks to line up with first.
  4925. `indent' (symbol) -- Convert header prefixes to all white space,
  4926. except for distinctive bullets.
  4927. Defaults:
  4928. FUNCTION: `allout-insert-listified'
  4929. FROM: region start, if region active, else start of buffer
  4930. TO: region end, if region active, else end of buffer
  4931. FROMBUF: current buffer
  4932. TOBUF: buffer name derived: \"*current-buffer-name exposed*\"
  4933. FORMAT: nil"
  4934. ; Resolve arguments,
  4935. ; defaulting if necessary:
  4936. (if (not func) (setq func 'allout-insert-listified))
  4937. (if (not (and from to))
  4938. (if (allout-region-active-p)
  4939. (setq from (region-beginning) to (region-end))
  4940. (setq from (point-min) to (point-max))))
  4941. (if frombuf
  4942. (if (not (bufferp frombuf))
  4943. ;; Specified but not a buffer -- get it:
  4944. (let ((got (get-buffer frombuf)))
  4945. (if (not got)
  4946. (error (concat "allout-process-exposed: source buffer "
  4947. frombuf
  4948. " not found."))
  4949. (setq frombuf got))))
  4950. ;; not specified -- default it:
  4951. (setq frombuf (current-buffer)))
  4952. (if tobuf
  4953. (if (not (bufferp tobuf))
  4954. (setq tobuf (get-buffer-create tobuf)))
  4955. ;; not specified -- default it:
  4956. (setq tobuf (concat "*" (buffer-name frombuf) " exposed*")))
  4957. (if (listp format)
  4958. (nreverse format))
  4959. (let* ((listified
  4960. (progn (set-buffer frombuf)
  4961. (allout-listify-exposed from to format))))
  4962. (set-buffer tobuf)
  4963. (mapc func listified)
  4964. (pop-to-buffer tobuf)))
  4965. ;;;_ - Copy exposed
  4966. ;;;_ > allout-insert-listified (listified)
  4967. (defun allout-insert-listified (listified)
  4968. "Insert contents of listified outline portion in current buffer.
  4969. LISTIFIED is a list representing each topic header and body:
  4970. \`(depth prefix text)'
  4971. or \`(depth prefix text bullet-plus)'
  4972. If `bullet-plus' is specified, it is inserted just after the entire prefix."
  4973. (setq listified (cdr listified))
  4974. (let ((prefix (prog1
  4975. (car listified)
  4976. (setq listified (cdr listified))))
  4977. (text (prog1
  4978. (car listified)
  4979. (setq listified (cdr listified))))
  4980. (bullet-plus (car listified)))
  4981. (insert prefix)
  4982. (if bullet-plus (insert (concat " " bullet-plus)))
  4983. (while text
  4984. (insert (car text))
  4985. (if (setq text (cdr text))
  4986. (insert "\n")))
  4987. (insert "\n")))
  4988. ;;;_ > allout-copy-exposed-to-buffer (&optional arg tobuf format)
  4989. (defun allout-copy-exposed-to-buffer (&optional arg tobuf format)
  4990. "Duplicate exposed portions of current outline to another buffer.
  4991. Other buffer has current buffers name with \" exposed\" appended to it.
  4992. With repeat count, copy the exposed parts of only the current topic.
  4993. Optional second arg TOBUF is target buffer name.
  4994. Optional third arg FORMAT, if non-nil, symbolically designates an
  4995. alternate presentation format for the outline:
  4996. `flat' - Convert topic header prefixes to numeric
  4997. section.subsection... identifiers.
  4998. `indent' - Convert header prefixes to all white space, except for
  4999. distinctive bullets.
  5000. `indent-flat' - The best of both - only the first of each level has
  5001. the full path, the rest have only the section number
  5002. of the leaf, preceded by the right amount of indentation."
  5003. (interactive "P")
  5004. (if (not tobuf)
  5005. (setq tobuf (get-buffer-create (concat "*" (buffer-name) " exposed*"))))
  5006. (let* ((start-pt (point))
  5007. (beg (if arg (allout-back-to-current-heading) (point-min)))
  5008. (end (if arg (allout-end-of-current-subtree) (point-max)))
  5009. (buf (current-buffer))
  5010. (start-list ()))
  5011. (if (eq format 'flat)
  5012. (setq format (if arg (save-excursion
  5013. (goto-char beg)
  5014. (allout-topic-flat-index))
  5015. '(1))))
  5016. (with-current-buffer tobuf (erase-buffer))
  5017. (allout-process-exposed 'allout-insert-listified
  5018. beg
  5019. end
  5020. (current-buffer)
  5021. tobuf
  5022. format start-list)
  5023. (goto-char (point-min))
  5024. (pop-to-buffer buf)
  5025. (goto-char start-pt)))
  5026. ;;;_ > allout-flatten-exposed-to-buffer (&optional arg tobuf)
  5027. (defun allout-flatten-exposed-to-buffer (&optional arg tobuf)
  5028. "Present numeric outline of outline's exposed portions in another buffer.
  5029. The resulting outline is not compatible with outline mode -- use
  5030. `allout-copy-exposed-to-buffer' if you want that.
  5031. Use `allout-indented-exposed-to-buffer' for indented presentation.
  5032. With repeat count, copy the exposed portions of only current topic.
  5033. Other buffer has current buffer's name with \" exposed\" appended to
  5034. it, unless optional second arg TOBUF is specified, in which case it is
  5035. used verbatim."
  5036. (interactive "P")
  5037. (allout-copy-exposed-to-buffer arg tobuf 'flat))
  5038. ;;;_ > allout-indented-exposed-to-buffer (&optional arg tobuf)
  5039. (defun allout-indented-exposed-to-buffer (&optional arg tobuf)
  5040. "Present indented outline of outline's exposed portions in another buffer.
  5041. The resulting outline is not compatible with outline mode -- use
  5042. `allout-copy-exposed-to-buffer' if you want that.
  5043. Use `allout-flatten-exposed-to-buffer' for numeric sectional presentation.
  5044. With repeat count, copy the exposed portions of only current topic.
  5045. Other buffer has current buffer's name with \" exposed\" appended to
  5046. it, unless optional second arg TOBUF is specified, in which case it is
  5047. used verbatim."
  5048. (interactive "P")
  5049. (allout-copy-exposed-to-buffer arg tobuf 'indent))
  5050. ;;;_ - LaTeX formatting
  5051. ;;;_ > allout-latex-verb-quote (string &optional flow)
  5052. (defun allout-latex-verb-quote (string &optional flow)
  5053. "Return copy of STRING for literal reproduction across LaTeX processing.
  5054. Expresses the original characters (including carriage returns) of the
  5055. string across LaTeX processing."
  5056. (mapconcat (function
  5057. (lambda (char)
  5058. (cond ((memq char '(?\\ ?$ ?% ?# ?& ?{ ?} ?_ ?^ ?- ?*))
  5059. (concat "\\char" (number-to-string char) "{}"))
  5060. ((= char ?\n) "\\\\")
  5061. (t (char-to-string char)))))
  5062. string
  5063. ""))
  5064. ;;;_ > allout-latex-verbatim-quote-curr-line ()
  5065. (defun allout-latex-verbatim-quote-curr-line ()
  5066. "Express line for exact (literal) representation across LaTeX processing.
  5067. Adjust line contents so it is unaltered (from the original line)
  5068. across LaTeX processing, within the context of a `verbatim'
  5069. environment. Leaves point at the end of the line."
  5070. (let ((inhibit-field-text-motion t))
  5071. (beginning-of-line)
  5072. (let ((beg (point))
  5073. (end (point-at-eol)))
  5074. (save-match-data
  5075. (while (re-search-forward "\\\\"
  5076. ;;"\\\\\\|\\{\\|\\}\\|\\_\\|\\$\\|\\\"\\|\\&\\|\\^\\|\\-\\|\\*\\|#"
  5077. end ; bounded by end-of-line
  5078. 1) ; no matches, move to end & return nil
  5079. (goto-char (match-beginning 2))
  5080. (insert "\\")
  5081. (setq end (1+ end))
  5082. (goto-char (1+ (match-end 2))))))))
  5083. ;;;_ > allout-insert-latex-header (buffer)
  5084. (defun allout-insert-latex-header (buffer)
  5085. "Insert initial LaTeX commands at point in BUFFER."
  5086. ;; Much of this is being derived from the stuff in appendix of E in
  5087. ;; the TeXBook, pg 421.
  5088. (set-buffer buffer)
  5089. (let ((doc-style (format "\n\\documentstyle{%s}\n"
  5090. "report"))
  5091. (page-numbering (if allout-number-pages
  5092. "\\pagestyle{empty}\n"
  5093. ""))
  5094. (titlecmd (format "\\newcommand{\\titlecmd}[1]{{%s #1}}\n"
  5095. allout-title-style))
  5096. (labelcmd (format "\\newcommand{\\labelcmd}[1]{{%s #1}}\n"
  5097. allout-label-style))
  5098. (headlinecmd (format "\\newcommand{\\headlinecmd}[1]{{%s #1}}\n"
  5099. allout-head-line-style))
  5100. (bodylinecmd (format "\\newcommand{\\bodylinecmd}[1]{{%s #1}}\n"
  5101. allout-body-line-style))
  5102. (setlength (format "%s%s%s%s"
  5103. "\\newlength{\\stepsize}\n"
  5104. "\\setlength{\\stepsize}{"
  5105. allout-indent
  5106. "}\n"))
  5107. (oneheadline (format "%s%s%s%s%s%s%s"
  5108. "\\newcommand{\\OneHeadLine}[3]{%\n"
  5109. "\\noindent%\n"
  5110. "\\hspace*{#2\\stepsize}%\n"
  5111. "\\labelcmd{#1}\\hspace*{.2cm}"
  5112. "\\headlinecmd{#3}\\\\["
  5113. allout-line-skip
  5114. "]\n}\n"))
  5115. (onebodyline (format "%s%s%s%s%s%s"
  5116. "\\newcommand{\\OneBodyLine}[2]{%\n"
  5117. "\\noindent%\n"
  5118. "\\hspace*{#1\\stepsize}%\n"
  5119. "\\bodylinecmd{#2}\\\\["
  5120. allout-line-skip
  5121. "]\n}\n"))
  5122. (begindoc "\\begin{document}\n\\begin{center}\n")
  5123. (title (format "%s%s%s%s"
  5124. "\\titlecmd{"
  5125. (allout-latex-verb-quote (if allout-title
  5126. (condition-case nil
  5127. (eval allout-title)
  5128. (error "<unnamed buffer>"))
  5129. "Unnamed Outline"))
  5130. "}\n"
  5131. "\\end{center}\n\n"))
  5132. (hsize "\\hsize = 7.5 true in\n")
  5133. (hoffset "\\hoffset = -1.5 true in\n")
  5134. (vspace "\\vspace{.1cm}\n\n"))
  5135. (insert (concat doc-style
  5136. page-numbering
  5137. titlecmd
  5138. labelcmd
  5139. headlinecmd
  5140. bodylinecmd
  5141. setlength
  5142. oneheadline
  5143. onebodyline
  5144. begindoc
  5145. title
  5146. hsize
  5147. hoffset
  5148. vspace)
  5149. )))
  5150. ;;;_ > allout-insert-latex-trailer (buffer)
  5151. (defun allout-insert-latex-trailer (buffer)
  5152. "Insert concluding LaTeX commands at point in BUFFER."
  5153. (set-buffer buffer)
  5154. (insert "\n\\end{document}\n"))
  5155. ;;;_ > allout-latexify-one-item (depth prefix bullet text)
  5156. (defun allout-latexify-one-item (depth prefix bullet text)
  5157. "Insert LaTeX commands for formatting one outline item.
  5158. Args are the topics numeric DEPTH, the header PREFIX lead string, the
  5159. BULLET string, and a list of TEXT strings for the body."
  5160. (let* ((head-line (if text (car text)))
  5161. (body-lines (cdr text))
  5162. (curr-line)
  5163. body-content bop)
  5164. ; Do the head line:
  5165. (insert (concat "\\OneHeadLine{\\verb\1 "
  5166. (allout-latex-verb-quote bullet)
  5167. "\1}{"
  5168. depth
  5169. "}{\\verb\1 "
  5170. (if head-line
  5171. (allout-latex-verb-quote head-line)
  5172. "")
  5173. "\1}\n"))
  5174. (if (not body-lines)
  5175. nil
  5176. ;;(insert "\\beginlines\n")
  5177. (insert "\\begin{verbatim}\n")
  5178. (while body-lines
  5179. (setq curr-line (car body-lines))
  5180. (if (and (not body-content)
  5181. (not (string-match "^\\s-*$" curr-line)))
  5182. (setq body-content t))
  5183. ; Mangle any occurrences of
  5184. ; "\end{verbatim}" in text,
  5185. ; it's special:
  5186. (if (and body-content
  5187. (setq bop (string-match "\\end{verbatim}" curr-line)))
  5188. (setq curr-line (concat (substring curr-line 0 bop)
  5189. ">"
  5190. (substring curr-line bop))))
  5191. ;;(insert "|" (car body-lines) "|")
  5192. (insert curr-line)
  5193. (allout-latex-verbatim-quote-curr-line)
  5194. (insert "\n")
  5195. (setq body-lines (cdr body-lines)))
  5196. (if body-content
  5197. (setq body-content nil)
  5198. (forward-char -1)
  5199. (insert "\\ ")
  5200. (forward-char 1))
  5201. ;;(insert "\\endlines\n")
  5202. (insert "\\end{verbatim}\n")
  5203. )))
  5204. ;;;_ > allout-latexify-exposed (arg &optional tobuf)
  5205. (defun allout-latexify-exposed (arg &optional tobuf)
  5206. "Format current topics exposed portions to TOBUF for LaTeX processing.
  5207. TOBUF defaults to a buffer named the same as the current buffer, but
  5208. with \"*\" prepended and \" latex-formed*\" appended.
  5209. With repeat count, copy the exposed portions of entire buffer."
  5210. (interactive "P")
  5211. (if (not tobuf)
  5212. (setq tobuf
  5213. (get-buffer-create (concat "*" (buffer-name) " latexified*"))))
  5214. (let* ((start-pt (point))
  5215. (beg (if arg (point-min) (allout-back-to-current-heading)))
  5216. (end (if arg (point-max) (allout-end-of-current-subtree)))
  5217. (buf (current-buffer)))
  5218. (set-buffer tobuf)
  5219. (erase-buffer)
  5220. (allout-insert-latex-header tobuf)
  5221. (goto-char (point-max))
  5222. (allout-process-exposed 'allout-latexify-one-item
  5223. beg
  5224. end
  5225. buf
  5226. tobuf)
  5227. (goto-char (point-max))
  5228. (allout-insert-latex-trailer tobuf)
  5229. (goto-char (point-min))
  5230. (pop-to-buffer buf)
  5231. (goto-char start-pt)))
  5232. ;;;_ #8 Encryption
  5233. ;;;_ > allout-toggle-current-subtree-encryption (&optional keymode-cue)
  5234. (defun allout-toggle-current-subtree-encryption (&optional keymode-cue)
  5235. "Encrypt clear or decrypt encoded topic text.
  5236. Allout uses Emacs 'epg' library to perform encryption. Symmetric
  5237. and keypair encryption are supported. All encryption is ascii
  5238. armored.
  5239. Entry encryption defaults to symmetric key mode unless keypair
  5240. recipients are associated with the file (see
  5241. `epa-file-encrypt-to') or the function is invoked with a
  5242. \(KEYMODE-CUE) universal argument greater than 1.
  5243. When encrypting, KEYMODE-CUE universal argument greater than 1
  5244. causes prompting for recipients for public-key keypair
  5245. encryption. Selecting no recipients results in symmetric key
  5246. encryption.
  5247. Further, encrypting with a KEYMODE-CUE universal argument greater
  5248. than 4 - eg, preceded by a doubled Ctrl-U - causes association of
  5249. the specified recipients with the file, replacing those currently
  5250. associated with it. This can be used to dissociate any
  5251. recipients with the file, by selecting no recipients in the
  5252. dialog.
  5253. Encrypted topic's bullets are set to a `~' to signal that the
  5254. contents of the topic (body and subtopics, but not heading) is
  5255. pending encryption or encrypted. `*' asterisk immediately after
  5256. the bullet signals that the body is encrypted, its absence means
  5257. the topic is meant to be encrypted but is not currently. When a
  5258. file with topics pending encryption is saved, topics pending
  5259. encryption are encrypted. See `allout-encrypt-unencrypted-on-saves'
  5260. for auto-encryption specifics.
  5261. \*NOTE WELL* that automatic encryption that happens during saves will
  5262. default to symmetric encryption -- you must deliberately (re)encrypt key-pair
  5263. encrypted topics if you want them to continue to use the key-pair cipher.
  5264. Level-one topics, with prefix consisting solely of an `*' asterisk, cannot be
  5265. encrypted. If you want to encrypt the contents of a top-level topic, use
  5266. \\[allout-shift-in] to increase its depth."
  5267. (interactive "P")
  5268. (save-excursion
  5269. (allout-back-to-current-heading)
  5270. (allout-toggle-subtree-encryption keymode-cue)))
  5271. ;;;_ > allout-toggle-subtree-encryption (&optional keymode-cue)
  5272. (defun allout-toggle-subtree-encryption (&optional keymode-cue)
  5273. "Encrypt clear text or decrypt encoded topic contents (body and subtopics.)
  5274. Entry encryption defaults to symmetric key mode unless keypair
  5275. recipients are associated with the file (see
  5276. `epa-file-encrypt-to') or the function is invoked with a
  5277. \(KEYMODE-CUE) universal argument greater than 1.
  5278. When encrypting, KEYMODE-CUE universal argument greater than 1
  5279. causes prompting for recipients for public-key keypair
  5280. encryption. Selecting no recipients results in symmetric key
  5281. encryption.
  5282. Further, encrypting with a KEYMODE-CUE universal argument greater
  5283. than 4 - eg, preceded by a doubled Ctrl-U - causes association of
  5284. the specified recipients with the file, replacing those currently
  5285. associated with it. This can be used to dissociate any
  5286. recipients with the file, by selecting no recipients in the
  5287. dialog.
  5288. Encryption and decryption uses the Emacs 'epg' library.
  5289. Encrypted text will be ascii-armored.
  5290. See `allout-toggle-current-subtree-encryption' for more details."
  5291. (interactive "P")
  5292. (save-excursion
  5293. (allout-end-of-prefix t)
  5294. (if (= allout-recent-depth 1)
  5295. (error (concat "Cannot encrypt or decrypt level 1 topics -"
  5296. " shift it in to make it encryptable")))
  5297. (let* ((allout-buffer (current-buffer))
  5298. ;; for use with allout-auto-save-temporarily-disabled, if necessary:
  5299. (was-buffer-saved-size buffer-saved-size)
  5300. ;; Assess location:
  5301. (bullet-pos allout-recent-prefix-beginning)
  5302. (after-bullet-pos (point))
  5303. (was-encrypted
  5304. (progn (if (= (point-max) after-bullet-pos)
  5305. (error "no body to encrypt"))
  5306. (allout-encrypted-topic-p)))
  5307. (was-collapsed (if (not (search-forward "\n" nil t))
  5308. nil
  5309. (backward-char 1)
  5310. (allout-hidden-p)))
  5311. (subtree-beg (1+ (point)))
  5312. (subtree-end (allout-end-of-subtree))
  5313. (subject-text (buffer-substring-no-properties subtree-beg
  5314. subtree-end))
  5315. (subtree-end-char (char-after (1- subtree-end)))
  5316. (subtree-trailing-char (char-after subtree-end))
  5317. ;; kluge -- result-text needs to be nil, but we also want to
  5318. ;; check for the error condition
  5319. (result-text (if (or (string= "" subject-text)
  5320. (string= "\n" subject-text))
  5321. (error "No topic contents to %scrypt"
  5322. (if was-encrypted "de" "en"))
  5323. nil))
  5324. ;; Assess key parameters:
  5325. (was-coding-system buffer-file-coding-system))
  5326. (when (not was-encrypted)
  5327. ;; ensure that non-ascii chars pending encryption are noticed before
  5328. ;; they're encrypted, so the coding system is set to accommodate
  5329. ;; them.
  5330. (setq buffer-file-coding-system
  5331. (allout-select-safe-coding-system subtree-beg subtree-end))
  5332. ;; if the coding system for the text being encrypted is different
  5333. ;; than that prevailing, then there a real risk that the coding
  5334. ;; system can't be noticed by emacs when the file is visited. to
  5335. ;; mitigate that, offer to preserve the coding system using a file
  5336. ;; local variable.
  5337. (if (and (not (equal buffer-file-coding-system
  5338. was-coding-system))
  5339. (yes-or-no-p
  5340. (format (concat "Register coding system %s as file local"
  5341. " var? Necessary when only encrypted text"
  5342. " is in that coding system. ")
  5343. buffer-file-coding-system)))
  5344. (allout-adjust-file-variable "buffer-file-coding-system"
  5345. buffer-file-coding-system)))
  5346. (setq result-text
  5347. (allout-encrypt-string subject-text was-encrypted
  5348. (current-buffer) keymode-cue))
  5349. ;; Replace the subtree with the processed product.
  5350. (allout-unprotected
  5351. (progn
  5352. (set-buffer allout-buffer)
  5353. (delete-region subtree-beg subtree-end)
  5354. (insert result-text)
  5355. (if was-collapsed
  5356. (allout-flag-region (1- subtree-beg) (point) t))
  5357. ;; adjust trailing-blank-lines to preserve topic spacing:
  5358. (if (not was-encrypted)
  5359. (if (and (= subtree-end-char ?\n)
  5360. (= subtree-trailing-char ?\n))
  5361. (insert subtree-trailing-char)))
  5362. ;; Ensure that the item has an encrypted-entry bullet:
  5363. (if (not (string= (buffer-substring-no-properties
  5364. (1- after-bullet-pos) after-bullet-pos)
  5365. allout-topic-encryption-bullet))
  5366. (progn (goto-char (1- after-bullet-pos))
  5367. (delete-char 1)
  5368. (insert allout-topic-encryption-bullet)))
  5369. (if was-encrypted
  5370. ;; Remove the is-encrypted bullet qualifier:
  5371. (progn (goto-char after-bullet-pos)
  5372. (delete-char 1))
  5373. ;; Add the is-encrypted bullet qualifier:
  5374. (goto-char after-bullet-pos)
  5375. (insert "*"))))
  5376. ;; adjust buffer's auto-save eligibility:
  5377. (if was-encrypted
  5378. (allout-inhibit-auto-save-info-for-decryption was-buffer-saved-size)
  5379. (allout-maybe-resume-auto-save-info-after-encryption))
  5380. (run-hook-with-args 'allout-structure-added-hook
  5381. bullet-pos subtree-end))))
  5382. ;;;_ > allout-encrypt-string (text decrypt allout-buffer keymode-cue
  5383. ;;; &optional rejected)
  5384. (defun allout-encrypt-string (text decrypt allout-buffer keymode-cue
  5385. &optional rejected)
  5386. "Encrypt or decrypt message TEXT.
  5387. Returns the resulting string, or nil if the transformation fails.
  5388. If DECRYPT is true (default false), then decrypt instead of encrypt.
  5389. ALLOUT-BUFFER identifies the buffer containing the text.
  5390. Entry encryption defaults to symmetric key mode unless keypair
  5391. recipients are associated with the file (see
  5392. `epa-file-encrypt-to') or the function is invoked with a
  5393. \(KEYMODE-CUE) universal argument greater than 1.
  5394. When encrypting, KEYMODE-CUE universal argument greater than 1
  5395. causes prompting for recipients for public-key keypair
  5396. encryption. Selecting no recipients results in symmetric key
  5397. encryption.
  5398. Further, encrypting with a KEYMODE-CUE universal argument greater
  5399. than 4 - eg, preceded by a doubled Ctrl-U - causes association of
  5400. the specified recipients with the file, replacing those currently
  5401. associated with it. This can be used to dissociate any
  5402. recipients with the file, by selecting no recipients in the
  5403. dialog.
  5404. Optional REJECTED is for internal use, to convey the number of
  5405. rejections due to matches against
  5406. `allout-encryption-ciphertext-rejection-regexps', as limited by
  5407. `allout-encryption-ciphertext-rejection-ceiling'.
  5408. NOTE: A few GnuPG v2 versions improperly preserve incorrect
  5409. symmetric decryption keys, preventing entry of the correct key on
  5410. subsequent decryption attempts until the cache times-out. That
  5411. can take several minutes. (Decryption of other entries is not
  5412. affected.) Upgrade your EasyPG version, if you can, and you can
  5413. deliberately clear your gpg-agent's cache by sending it a '-HUP'
  5414. signal."
  5415. (require 'epg)
  5416. (require 'epa)
  5417. (let* ((epg-context (let* ((context (epg-make-context nil t)))
  5418. (epg-context-set-passphrase-callback
  5419. context #'epa-passphrase-callback-function)
  5420. context))
  5421. (encoding (with-current-buffer allout-buffer
  5422. buffer-file-coding-system))
  5423. (multibyte (with-current-buffer allout-buffer
  5424. enable-multibyte-characters))
  5425. ;; "sanitization" avoids encryption results that are outline structure.
  5426. (sani-regexps 'allout-encryption-plaintext-sanitization-regexps)
  5427. (strip-plaintext-regexps (if (not decrypt)
  5428. (allout-get-configvar-values
  5429. sani-regexps)))
  5430. (rejection-regexps 'allout-encryption-ciphertext-rejection-regexps)
  5431. (reject-ciphertext-regexps (if (not decrypt)
  5432. (allout-get-configvar-values
  5433. rejection-regexps)))
  5434. (rejected (or rejected 0))
  5435. (rejections-left (- allout-encryption-ciphertext-rejection-ceiling
  5436. rejected))
  5437. (keypair-mode (cond (decrypt 'decrypting)
  5438. ((<= (prefix-numeric-value keymode-cue) 1)
  5439. 'default)
  5440. ((<= (prefix-numeric-value keymode-cue) 4)
  5441. 'prompt)
  5442. ((> (prefix-numeric-value keymode-cue) 4)
  5443. 'prompt-save)))
  5444. (keypair-message (concat "Select encryption recipients.\n"
  5445. "Symmetric encryption is done if no"
  5446. " recipients are selected. "))
  5447. (encrypt-to (and (boundp 'epa-file-encrypt-to) epa-file-encrypt-to))
  5448. recipients
  5449. massaged-text
  5450. result-text
  5451. )
  5452. ;; Massage the subject text for encoding and filtering.
  5453. (with-temp-buffer
  5454. (insert text)
  5455. ;; convey the text characteristics of the original buffer:
  5456. (set-buffer-multibyte multibyte)
  5457. (when encoding
  5458. (set-buffer-file-coding-system encoding)
  5459. (if (not decrypt)
  5460. (encode-coding-region (point-min) (point-max) encoding)))
  5461. ;; remove sanitization regexps matches before encrypting:
  5462. (when (and strip-plaintext-regexps (not decrypt))
  5463. (dolist (re strip-plaintext-regexps)
  5464. (let ((re (if (listp re) (car re) re))
  5465. (replacement (if (listp re) (cadr re) "")))
  5466. (goto-char (point-min))
  5467. (save-match-data
  5468. (while (re-search-forward re nil t)
  5469. (replace-match replacement nil nil))))))
  5470. (setq massaged-text (buffer-substring-no-properties (point-min)
  5471. (point-max))))
  5472. ;; determine key mode and, if keypair, recipients:
  5473. (setq recipients
  5474. (case keypair-mode
  5475. (decrypting nil)
  5476. (default (if encrypt-to (epg-list-keys epg-context encrypt-to)))
  5477. ((prompt prompt-save)
  5478. (save-window-excursion
  5479. (epa-select-keys epg-context keypair-message)))))
  5480. (setq result-text
  5481. (if decrypt
  5482. (condition-case err
  5483. (epg-decrypt-string epg-context
  5484. (encode-coding-string massaged-text
  5485. (or encoding 'utf-8)))
  5486. (epg-error
  5487. (signal 'egp-error
  5488. (cons (concat (cadr err) " - gpg version problem?")
  5489. (cddr err)))))
  5490. (replace-regexp-in-string "\n$" ""
  5491. (epg-encrypt-string epg-context
  5492. (encode-coding-string massaged-text
  5493. (or encoding 'utf-8))
  5494. recipients))))
  5495. ;; validate result -- non-empty
  5496. (if (not result-text)
  5497. (error "%scryption failed." (if decrypt "De" "En")))
  5498. (when (eq keypair-mode 'prompt-save)
  5499. ;; set epa-file-encrypt-to in the buffer:
  5500. (setq epa-file-encrypt-to (mapcar (lambda (key)
  5501. (epg-user-id-string
  5502. (car (epg-key-user-id-list key))))
  5503. recipients))
  5504. ;; change the file variable:
  5505. (allout-adjust-file-variable "epa-file-encrypt-to" epa-file-encrypt-to))
  5506. (cond
  5507. ;; Retry (within limit) if ciphertext contains rejections:
  5508. ((and (not decrypt)
  5509. ;; Check for disqualification of this ciphertext:
  5510. (let ((regexps reject-ciphertext-regexps)
  5511. reject-it)
  5512. (while (and regexps (not reject-it))
  5513. (setq reject-it (string-match (car regexps) result-text))
  5514. (pop regexps))
  5515. reject-it))
  5516. (setq rejections-left (1- rejections-left))
  5517. (if (<= rejections-left 0)
  5518. (error (concat "Ciphertext rejected too many times"
  5519. " (%s), per `%s'")
  5520. allout-encryption-ciphertext-rejection-ceiling
  5521. 'allout-encryption-ciphertext-rejection-regexps)
  5522. ;; try again (gpg-agent may have the key cached):
  5523. (allout-encrypt-string text decrypt allout-buffer keypair-mode
  5524. (1+ rejected))))
  5525. ;; Barf if encryption yields extraordinary control chars:
  5526. ((and (not decrypt)
  5527. (string-match "[\C-a\C-k\C-o-\C-z\C-@]"
  5528. result-text))
  5529. (error (concat "Encryption produced non-armored text, which"
  5530. "conflicts with allout mode -- reconfigure!")))
  5531. (t result-text))))
  5532. ;;;_ > allout-inhibit-auto-save-info-for-decryption
  5533. (defun allout-inhibit-auto-save-info-for-decryption (was-buffer-saved-size)
  5534. "Temporarily prevent auto-saves in this buffer when an item is decrypted.
  5535. WAS-BUFFER-SAVED-SIZE is the value of `buffer-saved-size' *before*
  5536. the decryption."
  5537. (when (not (or (= buffer-saved-size -1) (= was-buffer-saved-size -1)))
  5538. (setq allout-auto-save-temporarily-disabled was-buffer-saved-size
  5539. buffer-saved-size -1)))
  5540. ;;;_ > allout-maybe-resume-auto-save-info-after-encryption ()
  5541. (defun allout-maybe-resume-auto-save-info-after-encryption ()
  5542. "Restore auto-save info, *if* there are no topics pending encryption."
  5543. (when (and allout-auto-save-temporarily-disabled
  5544. (= buffer-saved-size -1)
  5545. (save-excursion
  5546. (save-restriction
  5547. (widen)
  5548. (goto-char (point-min))
  5549. (not (allout-next-topic-pending-encryption)))))
  5550. (setq buffer-saved-size allout-auto-save-temporarily-disabled
  5551. allout-auto-save-temporarily-disabled nil)))
  5552. ;;;_ > allout-encrypted-topic-p ()
  5553. (defun allout-encrypted-topic-p ()
  5554. "True if the current topic is encryptable and encrypted."
  5555. (save-excursion
  5556. (allout-end-of-prefix t)
  5557. (and (string= (buffer-substring-no-properties (1- (point)) (point))
  5558. allout-topic-encryption-bullet)
  5559. (save-match-data (looking-at "\\*")))
  5560. )
  5561. )
  5562. ;;;_ > allout-next-topic-pending-encryption ()
  5563. (defun allout-next-topic-pending-encryption ()
  5564. "Return the point of the next topic pending encryption, or nil if none.
  5565. Such a topic has the `allout-topic-encryption-bullet' without an
  5566. immediately following '*' that would mark the topic as being encrypted.
  5567. It must also have content."
  5568. (let (done got content-beg)
  5569. (save-match-data
  5570. (while (not done)
  5571. (if (not (re-search-forward
  5572. (format "\\(\\`\\|\n\\)%s *%s[^*]"
  5573. (regexp-quote allout-header-prefix)
  5574. (regexp-quote allout-topic-encryption-bullet))
  5575. nil t))
  5576. (setq got nil
  5577. done t)
  5578. (goto-char (setq got (match-beginning 0)))
  5579. (if (save-match-data (looking-at "\n"))
  5580. (forward-char 1))
  5581. (setq got (point)))
  5582. (cond ((not got)
  5583. (setq done t))
  5584. ((not (search-forward "\n"))
  5585. (setq got nil
  5586. done t))
  5587. ((eobp)
  5588. (setq got nil
  5589. done t))
  5590. (t
  5591. (setq content-beg (point))
  5592. (backward-char 1)
  5593. (allout-end-of-subtree)
  5594. (if (<= (point) content-beg)
  5595. ;; Continue looking
  5596. (setq got nil)
  5597. ;; Got it!
  5598. (setq done t)))
  5599. )
  5600. )
  5601. (if got
  5602. (goto-char got))
  5603. )
  5604. )
  5605. )
  5606. ;;;_ > allout-encrypt-decrypted ()
  5607. (defun allout-encrypt-decrypted ()
  5608. "Encrypt topics pending encryption except those containing exemption point.
  5609. If a topic that is currently being edited was encrypted, we return a list
  5610. containing the location of the topic and the location of the cursor just
  5611. before the topic was encrypted. This can be used, eg, to decrypt the topic
  5612. and exactly resituate the cursor if this is being done as part of a file
  5613. save. See `allout-encrypt-unencrypted-on-saves' for more info."
  5614. (interactive "p")
  5615. (save-match-data
  5616. (save-excursion
  5617. (let* ((current-mark (point-marker))
  5618. (current-mark-position (marker-position current-mark))
  5619. was-modified
  5620. bo-subtree
  5621. editing-topic editing-point)
  5622. (goto-char (point-min))
  5623. (while (allout-next-topic-pending-encryption)
  5624. (setq was-modified (buffer-modified-p))
  5625. (when (save-excursion
  5626. (and (boundp 'allout-encrypt-unencrypted-on-saves)
  5627. allout-encrypt-unencrypted-on-saves
  5628. (setq bo-subtree (re-search-forward "$"))
  5629. (not (allout-hidden-p))
  5630. (>= current-mark (point))
  5631. (allout-end-of-current-subtree)
  5632. (<= current-mark (point))))
  5633. (setq editing-topic (point)
  5634. ;; we had to wait for this 'til now so prior topics are
  5635. ;; encrypted, any relevant text shifts are in place:
  5636. editing-point (- current-mark-position
  5637. (count-trailing-whitespace-region
  5638. bo-subtree current-mark-position))))
  5639. (allout-toggle-subtree-encryption)
  5640. (if (not was-modified)
  5641. (set-buffer-modified-p nil))
  5642. )
  5643. (if (not was-modified)
  5644. (set-buffer-modified-p nil))
  5645. (if editing-topic (list editing-topic editing-point))
  5646. )
  5647. )
  5648. )
  5649. )
  5650. ;;;_ #9 miscellaneous
  5651. ;;;_ : Mode:
  5652. ;;;_ > outlineify-sticky ()
  5653. ;; outlinify-sticky is correct spelling; provide this alias for sticklers:
  5654. ;;;###autoload
  5655. (defalias 'outlinify-sticky 'outlineify-sticky)
  5656. ;;;###autoload
  5657. (defun outlineify-sticky (&optional arg)
  5658. "Activate outline mode and establish file var so it is started subsequently.
  5659. See `allout-layout' and customization of `allout-auto-activation'
  5660. for details on preparing Emacs for automatic allout activation."
  5661. (interactive "P")
  5662. (if (allout-mode-p) (allout-mode)) ; deactivate so we can re-activate...
  5663. (allout-mode)
  5664. (save-excursion
  5665. (goto-char (point-min))
  5666. (if (allout-goto-prefix)
  5667. t
  5668. (allout-open-topic 2)
  5669. (insert (concat "Dummy outline topic header -- see"
  5670. "`allout-mode' docstring: `^Hm'."))
  5671. (allout-adjust-file-variable
  5672. "allout-layout" (or allout-layout '(-1 : 0))))))
  5673. ;;;_ > allout-file-vars-section-data ()
  5674. (defun allout-file-vars-section-data ()
  5675. "Return data identifying the file-vars section, or nil if none.
  5676. Returns a list of the form (BEGINNING-POINT PREFIX-STRING SUFFIX-STRING)."
  5677. ;; minimally gleaned from emacs 21.4 files.el hack-local-variables function.
  5678. (let (beg prefix suffix)
  5679. (save-excursion
  5680. (goto-char (point-max))
  5681. (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
  5682. (if (let ((case-fold-search t))
  5683. (not (search-forward "Local Variables:" nil t)))
  5684. nil
  5685. (setq beg (- (point) 16))
  5686. (setq suffix (buffer-substring-no-properties
  5687. (point)
  5688. (progn (if (search-forward "\n" nil t)
  5689. (forward-char -1))
  5690. (point))))
  5691. (setq prefix (buffer-substring-no-properties
  5692. (progn (if (search-backward "\n" nil t)
  5693. (forward-char 1))
  5694. (point))
  5695. beg))
  5696. (list beg prefix suffix))
  5697. )
  5698. )
  5699. )
  5700. ;;;_ > allout-adjust-file-variable (varname value)
  5701. (defun allout-adjust-file-variable (varname value)
  5702. "Adjust the setting of an Emacs file variable named VARNAME to VALUE.
  5703. This activity is inhibited if either `enable-local-variables' or
  5704. `allout-enable-file-variable-adjustment' are nil.
  5705. When enabled, an entry for the variable is created if not already present,
  5706. or changed if established with a different value. The section for the file
  5707. variables, itself, is created if not already present. When created, the
  5708. section lines (including the section line) exist as second-level topics in
  5709. a top-level topic at the end of the file.
  5710. `enable-local-variables' must be true for any of this to happen."
  5711. (if (not (and enable-local-variables
  5712. allout-enable-file-variable-adjustment))
  5713. nil
  5714. (save-excursion
  5715. (let ((inhibit-field-text-motion t)
  5716. (section-data (allout-file-vars-section-data))
  5717. beg prefix suffix)
  5718. (if section-data
  5719. (setq beg (car section-data)
  5720. prefix (cadr section-data)
  5721. suffix (car (cddr section-data)))
  5722. ;; create the section
  5723. (goto-char (point-max))
  5724. (open-line 1)
  5725. (allout-open-topic 0)
  5726. (end-of-line)
  5727. (insert "Local emacs vars.\n")
  5728. (allout-open-topic 1)
  5729. (setq beg (point)
  5730. suffix ""
  5731. prefix (buffer-substring-no-properties (progn
  5732. (beginning-of-line)
  5733. (point))
  5734. beg))
  5735. (goto-char beg)
  5736. (insert "Local variables:\n")
  5737. (allout-open-topic 0)
  5738. (insert "End:\n")
  5739. )
  5740. ;; look for existing entry or create one, leaving point for insertion
  5741. ;; of new value:
  5742. (goto-char beg)
  5743. (allout-show-to-offshoot)
  5744. (if (search-forward (concat "\n" prefix varname ":") nil t)
  5745. (let* ((value-beg (point))
  5746. (line-end (progn (if (search-forward "\n" nil t)
  5747. (forward-char -1))
  5748. (point)))
  5749. (value-end (- line-end (length suffix))))
  5750. (if (> value-end value-beg)
  5751. (delete-region value-beg value-end)))
  5752. (end-of-line)
  5753. (open-line 1)
  5754. (forward-line 1)
  5755. (insert (concat prefix varname ":")))
  5756. (insert (format " %S%s" value suffix))
  5757. )
  5758. )
  5759. )
  5760. )
  5761. ;;;_ > allout-get-configvar-values (varname)
  5762. (defun allout-get-configvar-values (configvar-name)
  5763. "Return a list of values of the symbols in list bound to CONFIGVAR-NAME.
  5764. The user is prompted for removal of symbols that are unbound, and they
  5765. otherwise are ignored.
  5766. CONFIGVAR-NAME should be the name of the configuration variable,
  5767. not its value."
  5768. (let ((configvar-value (symbol-value configvar-name))
  5769. got)
  5770. (dolist (sym configvar-value)
  5771. (if (not (boundp sym))
  5772. (if (yes-or-no-p (format "%s entry `%s' is unbound -- remove it? "
  5773. configvar-name sym))
  5774. (delq sym (symbol-value configvar-name)))
  5775. (push (symbol-value sym) got)))
  5776. (reverse got)))
  5777. ;;;_ : Topics:
  5778. ;;;_ > allout-mark-topic ()
  5779. (defun allout-mark-topic ()
  5780. "Put the region around topic currently containing point."
  5781. (interactive)
  5782. (let ((inhibit-field-text-motion t))
  5783. (beginning-of-line))
  5784. (allout-goto-prefix-doublechecked)
  5785. (push-mark (point))
  5786. (allout-end-of-current-subtree)
  5787. (exchange-point-and-mark))
  5788. ;;;_ : UI:
  5789. ;;;_ > solicit-char-in-string (prompt string &optional do-defaulting)
  5790. (defun solicit-char-in-string (prompt string &optional do-defaulting)
  5791. "Solicit (with first arg PROMPT) choice of a character from string STRING.
  5792. Optional arg DO-DEFAULTING indicates to accept empty input (CR)."
  5793. (let ((new-prompt prompt)
  5794. got)
  5795. (while (not got)
  5796. (message "%s" new-prompt)
  5797. ;; We do our own reading here, so we can circumvent, eg, special
  5798. ;; treatment for `?' character. (Oughta use minibuffer keymap instead.)
  5799. (setq got
  5800. (char-to-string (let ((cursor-in-echo-area nil)) (read-char))))
  5801. (setq got
  5802. (cond ((string-match (regexp-quote got) string) got)
  5803. ((and do-defaulting (string= got "\r"))
  5804. ;; Return empty string to default:
  5805. "")
  5806. ((string= got "\C-g") (signal 'quit nil))
  5807. (t
  5808. (setq new-prompt (concat prompt
  5809. got
  5810. " ...pick from: "
  5811. string
  5812. ""))
  5813. nil))))
  5814. ;; got something out of loop -- return it:
  5815. got)
  5816. )
  5817. ;;;_ : Strings:
  5818. ;;;_ > regexp-sans-escapes (string)
  5819. (defun regexp-sans-escapes (regexp &optional successive-backslashes)
  5820. "Return a copy of REGEXP with all character escapes stripped out.
  5821. Representations of actual backslashes -- '\\\\\\\\' -- are left as a
  5822. single backslash.
  5823. Optional arg SUCCESSIVE-BACKSLASHES is used internally for recursion."
  5824. (if (string= regexp "")
  5825. ""
  5826. ;; Set successive-backslashes to number if current char is
  5827. ;; backslash, or else to nil:
  5828. (setq successive-backslashes
  5829. (if (= (aref regexp 0) ?\\)
  5830. (if successive-backslashes (1+ successive-backslashes) 1)
  5831. nil))
  5832. (if (or (not successive-backslashes) (= 2 successive-backslashes))
  5833. ;; Include first char:
  5834. (concat (substring regexp 0 1)
  5835. (regexp-sans-escapes (substring regexp 1)))
  5836. ;; Exclude first char, but maintain count:
  5837. (regexp-sans-escapes (substring regexp 1) successive-backslashes))))
  5838. ;;;_ > count-trailing-whitespace-region (beg end)
  5839. (defun count-trailing-whitespace-region (beg end)
  5840. "Return number of trailing whitespace chars between BEG and END.
  5841. If BEG is bigger than END we return 0."
  5842. (if (> beg end)
  5843. 0
  5844. (save-match-data
  5845. (save-excursion
  5846. (goto-char beg)
  5847. (let ((count 0))
  5848. (while (re-search-forward "[ ][ ]*$" end t)
  5849. (goto-char (1+ (match-beginning 2)))
  5850. (setq count (1+ count)))
  5851. count)))))
  5852. ;;;_ > allout-format-quote (string)
  5853. (defun allout-format-quote (string)
  5854. "Return a copy of string with all \"%\" characters doubled."
  5855. (apply 'concat
  5856. (mapcar (lambda (char) (if (= char ?%) "%%" (char-to-string char)))
  5857. string)))
  5858. ;;;_ : lists
  5859. ;;;_ > allout-flatten (list)
  5860. (defun allout-flatten (list)
  5861. "Return a list of all atoms in list."
  5862. ;; classic.
  5863. (cond ((null list) nil)
  5864. ((atom (car list)) (cons (car list) (allout-flatten (cdr list))))
  5865. (t (append (allout-flatten (car list)) (allout-flatten (cdr list))))))
  5866. ;;;_ : Compatibility:
  5867. ;;;_ : xemacs undo-in-progress provision:
  5868. (unless (boundp 'undo-in-progress)
  5869. (defvar undo-in-progress nil
  5870. "Placeholder defvar for XEmacs compatibility from allout.el.")
  5871. (defadvice undo-more (around allout activate)
  5872. ;; This defadvice used only in emacs that lack undo-in-progress, eg xemacs.
  5873. (let ((undo-in-progress t)) ad-do-it)))
  5874. ;;;_ > allout-mark-marker to accommodate divergent emacsen:
  5875. (defun allout-mark-marker (&optional force buffer)
  5876. "Accommodate the different signature for `mark-marker' across Emacsen.
  5877. XEmacs takes two optional args, while Emacs does not,
  5878. so pass them along when appropriate."
  5879. (if (featurep 'xemacs)
  5880. (apply 'mark-marker force buffer)
  5881. (mark-marker)))
  5882. ;;;_ > subst-char-in-string if necessary
  5883. (if (not (fboundp 'subst-char-in-string))
  5884. (defun subst-char-in-string (fromchar tochar string &optional inplace)
  5885. "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
  5886. Unless optional argument INPLACE is non-nil, return a new string."
  5887. (let ((i (length string))
  5888. (newstr (if inplace string (copy-sequence string))))
  5889. (while (> i 0)
  5890. (setq i (1- i))
  5891. (if (eq (aref newstr i) fromchar)
  5892. (aset newstr i tochar)))
  5893. newstr)))
  5894. ;;;_ > wholenump if necessary
  5895. (if (not (fboundp 'wholenump))
  5896. (defalias 'wholenump 'natnump))
  5897. ;;;_ > remove-overlays if necessary
  5898. (if (not (fboundp 'remove-overlays))
  5899. (defun remove-overlays (&optional beg end name val)
  5900. "Clear BEG and END of overlays whose property NAME has value VAL.
  5901. Overlays might be moved and/or split.
  5902. BEG and END default respectively to the beginning and end of buffer."
  5903. (unless beg (setq beg (point-min)))
  5904. (unless end (setq end (point-max)))
  5905. (if (< end beg)
  5906. (setq beg (prog1 end (setq end beg))))
  5907. (save-excursion
  5908. (dolist (o (overlays-in beg end))
  5909. (when (eq (overlay-get o name) val)
  5910. ;; Either push this overlay outside beg...end
  5911. ;; or split it to exclude beg...end
  5912. ;; or delete it entirely (if it is contained in beg...end).
  5913. (if (< (overlay-start o) beg)
  5914. (if (> (overlay-end o) end)
  5915. (progn
  5916. (move-overlay (copy-overlay o)
  5917. (overlay-start o) beg)
  5918. (move-overlay o end (overlay-end o)))
  5919. (move-overlay o (overlay-start o) beg))
  5920. (if (> (overlay-end o) end)
  5921. (move-overlay o end (overlay-end o))
  5922. (delete-overlay o)))))))
  5923. )
  5924. ;;;_ > copy-overlay if necessary -- xemacs ~ 21.4
  5925. (if (not (fboundp 'copy-overlay))
  5926. (defun copy-overlay (o)
  5927. "Return a copy of overlay O."
  5928. (let ((o1 (make-overlay (overlay-start o) (overlay-end o)
  5929. ;; FIXME: there's no easy way to find the
  5930. ;; insertion-type of the two markers.
  5931. (overlay-buffer o)))
  5932. (props (overlay-properties o)))
  5933. (while props
  5934. (overlay-put o1 (pop props) (pop props)))
  5935. o1)))
  5936. ;;;_ > add-to-invisibility-spec if necessary -- xemacs ~ 21.4
  5937. (if (not (fboundp 'add-to-invisibility-spec))
  5938. (defun add-to-invisibility-spec (element)
  5939. "Add ELEMENT to `buffer-invisibility-spec'.
  5940. See documentation for `buffer-invisibility-spec' for the kind of elements
  5941. that can be added."
  5942. (if (eq buffer-invisibility-spec t)
  5943. (setq buffer-invisibility-spec (list t)))
  5944. (setq buffer-invisibility-spec
  5945. (cons element buffer-invisibility-spec))))
  5946. ;;;_ > remove-from-invisibility-spec if necessary -- xemacs ~ 21.4
  5947. (if (not (fboundp 'remove-from-invisibility-spec))
  5948. (defun remove-from-invisibility-spec (element)
  5949. "Remove ELEMENT from `buffer-invisibility-spec'."
  5950. (if (consp buffer-invisibility-spec)
  5951. (setq buffer-invisibility-spec (delete element
  5952. buffer-invisibility-spec)))))
  5953. ;;;_ > move-beginning-of-line if necessary -- older emacs, xemacs
  5954. (if (not (fboundp 'move-beginning-of-line))
  5955. (defun move-beginning-of-line (arg)
  5956. "Move point to beginning of current line as displayed.
  5957. \(This disregards invisible newlines such as those
  5958. which are part of the text that an image rests on.)
  5959. With argument ARG not nil or 1, move forward ARG - 1 lines first.
  5960. If point reaches the beginning or end of buffer, it stops there.
  5961. To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
  5962. (interactive "p")
  5963. (or arg (setq arg 1))
  5964. (if (/= arg 1)
  5965. (condition-case nil (line-move (1- arg)) (error nil)))
  5966. ;; Move to beginning-of-line, ignoring fields and invisible text.
  5967. (skip-chars-backward "^\n")
  5968. (while (and (not (bobp))
  5969. (let ((prop
  5970. (get-char-property (1- (point)) 'invisible)))
  5971. (if (eq buffer-invisibility-spec t)
  5972. prop
  5973. (or (memq prop buffer-invisibility-spec)
  5974. (assq prop buffer-invisibility-spec)))))
  5975. (goto-char (if (featurep 'xemacs)
  5976. (previous-property-change (point))
  5977. (previous-char-property-change (point))))
  5978. (skip-chars-backward "^\n"))
  5979. (vertical-motion 0))
  5980. )
  5981. ;;;_ > move-end-of-line if necessary -- Emacs < 22.1, xemacs
  5982. (if (not (fboundp 'move-end-of-line))
  5983. (defun move-end-of-line (arg)
  5984. "Move point to end of current line as displayed.
  5985. \(This disregards invisible newlines such as those
  5986. which are part of the text that an image rests on.)
  5987. With argument ARG not nil or 1, move forward ARG - 1 lines first.
  5988. If point reaches the beginning or end of buffer, it stops there.
  5989. To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
  5990. (interactive "p")
  5991. (or arg (setq arg 1))
  5992. (let (done)
  5993. (while (not done)
  5994. (let ((newpos
  5995. (save-excursion
  5996. (let ((goal-column 0))
  5997. (and (condition-case nil
  5998. (or (line-move arg) t)
  5999. (error nil))
  6000. (not (bobp))
  6001. (progn
  6002. (while
  6003. (and
  6004. (not (bobp))
  6005. (let ((prop
  6006. (get-char-property (1- (point))
  6007. 'invisible)))
  6008. (if (eq buffer-invisibility-spec t)
  6009. prop
  6010. (or (memq prop
  6011. buffer-invisibility-spec)
  6012. (assq prop
  6013. buffer-invisibility-spec)))))
  6014. (goto-char
  6015. (previous-char-property-change (point))))
  6016. (backward-char 1)))
  6017. (point)))))
  6018. (goto-char newpos)
  6019. (if (and (> (point) newpos)
  6020. (eq (preceding-char) ?\n))
  6021. (backward-char 1)
  6022. (if (and (> (point) newpos) (not (eobp))
  6023. (not (eq (following-char) ?\n)))
  6024. ;; If we skipped something intangible
  6025. ;; and now we're not really at eol,
  6026. ;; keep going.
  6027. (setq arg 1)
  6028. (setq done t)))))))
  6029. )
  6030. ;;;_ > allout-next-single-char-property-change -- alias unless lacking
  6031. (defalias 'allout-next-single-char-property-change
  6032. (if (fboundp 'next-single-char-property-change)
  6033. 'next-single-char-property-change
  6034. 'next-single-property-change)
  6035. ;; No docstring because xemacs defalias doesn't support it.
  6036. )
  6037. ;;;_ > allout-previous-single-char-property-change -- alias unless lacking
  6038. (defalias 'allout-previous-single-char-property-change
  6039. (if (fboundp 'previous-single-char-property-change)
  6040. 'previous-single-char-property-change
  6041. 'previous-single-property-change)
  6042. ;; No docstring because xemacs defalias doesn't support it.
  6043. )
  6044. ;;;_ > allout-select-safe-coding-system
  6045. (defalias 'allout-select-safe-coding-system
  6046. (if (fboundp 'select-safe-coding-system)
  6047. 'select-safe-coding-system
  6048. 'detect-coding-region)
  6049. )
  6050. ;;;_ > allout-substring-no-properties
  6051. ;; define as alias first, so byte compiler is happy.
  6052. (defalias 'allout-substring-no-properties 'substring-no-properties)
  6053. ;; then supplant with definition if underlying alias absent.
  6054. (if (not (fboundp 'substring-no-properties))
  6055. (defun allout-substring-no-properties (string &optional start end)
  6056. (substring string (or start 0) end))
  6057. )
  6058. ;;;_ #10 Unfinished
  6059. ;;;_ > allout-bullet-isearch (&optional bullet)
  6060. (defun allout-bullet-isearch (&optional bullet)
  6061. "Isearch (regexp) for topic with bullet BULLET."
  6062. (interactive)
  6063. (if (not bullet)
  6064. (setq bullet (solicit-char-in-string
  6065. "ISearch for topic with bullet: "
  6066. (regexp-sans-escapes allout-bullets-string))))
  6067. (let ((isearch-regexp t)
  6068. (isearch-string (concat "^"
  6069. allout-header-prefix
  6070. "[ \t]*"
  6071. bullet)))
  6072. (isearch-repeat 'forward)
  6073. (isearch-mode t)))
  6074. ;;;_ #11 Unit tests -- this should be last item before "Provide"
  6075. ;;;_ > allout-run-unit-tests ()
  6076. (defun allout-run-unit-tests ()
  6077. "Run the various allout unit tests."
  6078. (message "Running allout tests...")
  6079. (allout-test-resumptions)
  6080. (message "Running allout tests... Done.")
  6081. (sit-for .5))
  6082. ;;;_ : test resumptions:
  6083. ;;;_ > allout-tests-obliterate-variable (name)
  6084. (defun allout-tests-obliterate-variable (name)
  6085. "Completely unbind variable with NAME."
  6086. (if (local-variable-p name (current-buffer)) (kill-local-variable name))
  6087. (while (boundp name) (makunbound name)))
  6088. ;;;_ > allout-test-resumptions ()
  6089. (defvar allout-tests-globally-unbound nil
  6090. "Fodder for allout resumptions tests -- defvar just for byte compiler.")
  6091. (defvar allout-tests-globally-true nil
  6092. "Fodder for allout resumptions tests -- defvar just for byte compiler.")
  6093. (defvar allout-tests-locally-true nil
  6094. "Fodder for allout resumptions tests -- defvar just for byte compiler.")
  6095. (defun allout-test-resumptions ()
  6096. "Exercise allout resumptions."
  6097. ;; for each resumption case, we also test that the right local/global
  6098. ;; scopes are affected during resumption effects:
  6099. ;; ensure that previously unbound variables return to the unbound state.
  6100. (with-temp-buffer
  6101. (allout-tests-obliterate-variable 'allout-tests-globally-unbound)
  6102. (allout-add-resumptions '(allout-tests-globally-unbound t))
  6103. (assert (not (default-boundp 'allout-tests-globally-unbound)))
  6104. (assert (local-variable-p 'allout-tests-globally-unbound (current-buffer)))
  6105. (assert (boundp 'allout-tests-globally-unbound))
  6106. (assert (equal allout-tests-globally-unbound t))
  6107. (allout-do-resumptions)
  6108. (assert (not (local-variable-p 'allout-tests-globally-unbound
  6109. (current-buffer))))
  6110. (assert (not (boundp 'allout-tests-globally-unbound))))
  6111. ;; ensure that variable with prior global value is resumed
  6112. (with-temp-buffer
  6113. (allout-tests-obliterate-variable 'allout-tests-globally-true)
  6114. (setq allout-tests-globally-true t)
  6115. (allout-add-resumptions '(allout-tests-globally-true nil))
  6116. (assert (equal (default-value 'allout-tests-globally-true) t))
  6117. (assert (local-variable-p 'allout-tests-globally-true (current-buffer)))
  6118. (assert (equal allout-tests-globally-true nil))
  6119. (allout-do-resumptions)
  6120. (assert (not (local-variable-p 'allout-tests-globally-true
  6121. (current-buffer))))
  6122. (assert (boundp 'allout-tests-globally-true))
  6123. (assert (equal allout-tests-globally-true t)))
  6124. ;; ensure that prior local value is resumed
  6125. (with-temp-buffer
  6126. (allout-tests-obliterate-variable 'allout-tests-locally-true)
  6127. (set (make-local-variable 'allout-tests-locally-true) t)
  6128. (assert (not (default-boundp 'allout-tests-locally-true))
  6129. nil (concat "Test setup mistake -- variable supposed to"
  6130. " not have global binding, but it does."))
  6131. (assert (local-variable-p 'allout-tests-locally-true (current-buffer))
  6132. nil (concat "Test setup mistake -- variable supposed to have"
  6133. " local binding, but it lacks one."))
  6134. (allout-add-resumptions '(allout-tests-locally-true nil))
  6135. (assert (not (default-boundp 'allout-tests-locally-true)))
  6136. (assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
  6137. (assert (equal allout-tests-locally-true nil))
  6138. (allout-do-resumptions)
  6139. (assert (boundp 'allout-tests-locally-true))
  6140. (assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
  6141. (assert (equal allout-tests-locally-true t))
  6142. (assert (not (default-boundp 'allout-tests-locally-true))))
  6143. ;; ensure that last of multiple resumptions holds, for various scopes.
  6144. (with-temp-buffer
  6145. (allout-tests-obliterate-variable 'allout-tests-globally-unbound)
  6146. (allout-tests-obliterate-variable 'allout-tests-globally-true)
  6147. (setq allout-tests-globally-true t)
  6148. (allout-tests-obliterate-variable 'allout-tests-locally-true)
  6149. (set (make-local-variable 'allout-tests-locally-true) t)
  6150. (allout-add-resumptions '(allout-tests-globally-unbound t)
  6151. '(allout-tests-globally-true nil)
  6152. '(allout-tests-locally-true nil))
  6153. (allout-add-resumptions '(allout-tests-globally-unbound 2)
  6154. '(allout-tests-globally-true 3)
  6155. '(allout-tests-locally-true 4))
  6156. ;; reestablish many of the basic conditions are maintained after re-add:
  6157. (assert (not (default-boundp 'allout-tests-globally-unbound)))
  6158. (assert (local-variable-p 'allout-tests-globally-unbound (current-buffer)))
  6159. (assert (equal allout-tests-globally-unbound 2))
  6160. (assert (default-boundp 'allout-tests-globally-true))
  6161. (assert (local-variable-p 'allout-tests-globally-true (current-buffer)))
  6162. (assert (equal allout-tests-globally-true 3))
  6163. (assert (not (default-boundp 'allout-tests-locally-true)))
  6164. (assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
  6165. (assert (equal allout-tests-locally-true 4))
  6166. (allout-do-resumptions)
  6167. (assert (not (local-variable-p 'allout-tests-globally-unbound
  6168. (current-buffer))))
  6169. (assert (not (boundp 'allout-tests-globally-unbound)))
  6170. (assert (not (local-variable-p 'allout-tests-globally-true
  6171. (current-buffer))))
  6172. (assert (boundp 'allout-tests-globally-true))
  6173. (assert (equal allout-tests-globally-true t))
  6174. (assert (boundp 'allout-tests-locally-true))
  6175. (assert (local-variable-p 'allout-tests-locally-true (current-buffer)))
  6176. (assert (equal allout-tests-locally-true t))
  6177. (assert (not (default-boundp 'allout-tests-locally-true))))
  6178. ;; ensure that deliberately unbinding registered variables doesn't foul things
  6179. (with-temp-buffer
  6180. (allout-tests-obliterate-variable 'allout-tests-globally-unbound)
  6181. (allout-tests-obliterate-variable 'allout-tests-globally-true)
  6182. (setq allout-tests-globally-true t)
  6183. (allout-tests-obliterate-variable 'allout-tests-locally-true)
  6184. (set (make-local-variable 'allout-tests-locally-true) t)
  6185. (allout-add-resumptions '(allout-tests-globally-unbound t)
  6186. '(allout-tests-globally-true nil)
  6187. '(allout-tests-locally-true nil))
  6188. (allout-tests-obliterate-variable 'allout-tests-globally-unbound)
  6189. (allout-tests-obliterate-variable 'allout-tests-globally-true)
  6190. (allout-tests-obliterate-variable 'allout-tests-locally-true)
  6191. (allout-do-resumptions))
  6192. )
  6193. ;;;_ % Run unit tests if `allout-run-unit-tests-after-load' is true:
  6194. (when allout-run-unit-tests-on-load
  6195. (allout-run-unit-tests))
  6196. ;;;_ #12 Provide
  6197. (provide 'allout)
  6198. ;;;_* Local emacs vars.
  6199. ;; The following `allout-layout' local variable setting:
  6200. ;; - closes all topics from the first topic to just before the third-to-last,
  6201. ;; - shows the children of the third to last (config vars)
  6202. ;; - and the second to last (code section),
  6203. ;; - and closes the last topic (this local-variables section).
  6204. ;;Local variables:
  6205. ;;allout-layout: (0 : -1 -1 0)
  6206. ;;End:
  6207. ;;; allout.el ends here