cus-edit.el 168 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899
  1. ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages
  2. ;;
  3. ;; Copyright (C) 1996-1997, 1999-2012 Free Software Foundation, Inc.
  4. ;;
  5. ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
  6. ;; Maintainer: FSF
  7. ;; Keywords: help, faces
  8. ;; Package: emacs
  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. ;;
  22. ;; This file implements the code to create and edit customize buffers.
  23. ;;
  24. ;; See `custom.el'.
  25. ;; No commands should have names starting with `custom-' because
  26. ;; that interferes with completion. Use `customize-' for commands
  27. ;; that the user will run with M-x, and `Custom-' for interactive commands.
  28. ;; The identity of a customize option is represented by a Lisp symbol.
  29. ;; The following values are associated with an option.
  30. ;; 0. The current value.
  31. ;; This is the value of the option as seen by "the rest of Emacs".
  32. ;; Usually extracted by 'default-value', but can be extracted with
  33. ;; different means if the option symbol has the 'custom-get'
  34. ;; property. Similarly, set-default (or the 'custom-set' property)
  35. ;; can set it.
  36. ;; 1. The widget value.
  37. ;; This is the value shown in the widget in a customize buffer.
  38. ;; 2. The customized value.
  39. ;; This is the last value given to the option through customize.
  40. ;; It is stored in the 'customized-value' property of the option, in a
  41. ;; cons-cell whose car evaluates to the customized value.
  42. ;; 3. The saved value.
  43. ;; This is last value saved from customize.
  44. ;; It is stored in the 'saved-value' property of the option, in a
  45. ;; cons-cell whose car evaluates to the saved value.
  46. ;; 4. The standard value.
  47. ;; This is the value given in the 'defcustom' declaration.
  48. ;; It is stored in the 'standard-value' property of the option, in a
  49. ;; cons-cell whose car evaluates to the standard value.
  50. ;; 5. The "think" value.
  51. ;; This is what customize thinks the current value should be.
  52. ;; This is the customized value, if any such value exists, otherwise
  53. ;; the saved value, if that exists, and as a last resort the standard
  54. ;; value.
  55. ;; The reason for storing values unevaluated: This is so you can have
  56. ;; values that depend on the environment. For example, you can have a
  57. ;; variable that has one value when Emacs is running under a window
  58. ;; system, and another value on a tty. Since the evaluation is only done
  59. ;; when the variable is first initialized, this is only relevant for the
  60. ;; saved (and standard) values, but affect others values for
  61. ;; compatibility.
  62. ;; You can see (and modify and save) this unevaluated value by selecting
  63. ;; "Show Saved Lisp Expression" from the Lisp interface. This will
  64. ;; give you the unevaluated saved value, if any, otherwise the
  65. ;; unevaluated standard value.
  66. ;; The possible states for a customize widget are:
  67. ;; 0. unknown
  68. ;; The state has not been determined yet.
  69. ;; 1. modified
  70. ;; The widget value is different from the current value.
  71. ;; 2. changed
  72. ;; The current value is different from the "think" value.
  73. ;; 3. set
  74. ;; The "think" value is the customized value.
  75. ;; 4. saved
  76. ;; The "think" value is the saved value.
  77. ;; 5. standard
  78. ;; The "think" value is the standard value.
  79. ;; 6. rogue
  80. ;; There is no standard value. This means that the variable was
  81. ;; not defined with defcustom, nor handled in cus-start.el. Most
  82. ;; standard interactive Custom commands do not let you create a
  83. ;; Custom buffer containing such variables. However, such Custom
  84. ;; buffers can be created, for instance, by calling
  85. ;; `customize-apropos' with a prefix arg or by calling
  86. ;; `customize-option' non-interactively.
  87. ;; 7. hidden
  88. ;; There is no widget value.
  89. ;; 8. mismatch
  90. ;; The widget value is not valid member of the :type specified for the
  91. ;; option.
  92. ;;; Code:
  93. (require 'cus-face)
  94. (require 'wid-edit)
  95. (defvar custom-versions-load-alist) ; from cus-load
  96. (defvar recentf-exclude) ; from recentf.el
  97. (condition-case nil
  98. (require 'cus-load)
  99. (error nil))
  100. (condition-case nil
  101. (require 'cus-start)
  102. (error nil))
  103. (put 'custom-define-hook 'custom-type 'hook)
  104. (put 'custom-define-hook 'standard-value '(nil))
  105. (custom-add-to-group 'customize 'custom-define-hook 'custom-variable)
  106. ;;; Customization Groups.
  107. (defgroup emacs nil
  108. "Customization of the One True Editor."
  109. :link '(custom-manual "(emacs)Top"))
  110. ;; Most of these groups are stolen from `finder.el',
  111. (defgroup editing nil
  112. "Basic text editing facilities."
  113. :group 'emacs)
  114. (defgroup convenience nil
  115. "Convenience features for faster editing."
  116. :group 'emacs)
  117. (defgroup files nil
  118. "Support for editing files."
  119. :group 'emacs)
  120. (defgroup wp nil
  121. "Support for editing text files."
  122. :tag "Text"
  123. :group 'emacs)
  124. (defgroup data nil
  125. "Support for editing binary data files."
  126. :group 'emacs)
  127. (defgroup abbrev nil
  128. "Abbreviation handling, typing shortcuts, macros."
  129. :tag "Abbreviations"
  130. :group 'convenience)
  131. (defgroup matching nil
  132. "Various sorts of searching and matching."
  133. :group 'editing)
  134. (defgroup emulations nil
  135. "Emulations of other editors."
  136. :link '(custom-manual "(emacs)Emulation")
  137. :group 'editing)
  138. (defgroup mouse nil
  139. "Mouse support."
  140. :group 'editing)
  141. (defgroup outlines nil
  142. "Support for hierarchical outlining."
  143. :group 'wp)
  144. (defgroup external nil
  145. "Interfacing to external utilities."
  146. :group 'emacs)
  147. (defgroup comm nil
  148. "Communications, networking, and remote access to files."
  149. :tag "Communication"
  150. :group 'emacs)
  151. (defgroup processes nil
  152. "Process, subshell, compilation, and job control support."
  153. :group 'external)
  154. (defgroup programming nil
  155. "Support for programming in other languages."
  156. :group 'emacs)
  157. (defgroup languages nil
  158. "Specialized modes for editing programming languages."
  159. :group 'programming)
  160. (defgroup lisp nil
  161. "Lisp support, including Emacs Lisp."
  162. :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
  163. :group 'languages
  164. :group 'development)
  165. (defgroup c nil
  166. "Support for the C language and related languages."
  167. :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
  168. :link '(custom-manual "(ccmode)")
  169. :group 'languages)
  170. (defgroup tools nil
  171. "Programming tools."
  172. :group 'programming)
  173. (defgroup applications nil
  174. "Applications written in Emacs."
  175. :group 'emacs)
  176. (defgroup calendar nil
  177. "Calendar and time management support."
  178. :group 'applications)
  179. (defgroup mail nil
  180. "Modes for electronic-mail handling."
  181. :group 'applications)
  182. (defgroup news nil
  183. "Support for netnews reading and posting."
  184. :link '(custom-manual "(gnus)")
  185. :group 'applications)
  186. (defgroup games nil
  187. "Games, jokes and amusements."
  188. :group 'applications)
  189. (defgroup development nil
  190. "Support for further development of Emacs."
  191. :group 'emacs)
  192. (defgroup docs nil
  193. "Support for Emacs documentation."
  194. :group 'development)
  195. (defgroup extensions nil
  196. "Emacs Lisp language extensions."
  197. :group 'development)
  198. (defgroup internal nil
  199. "Code for Emacs internals, build process, defaults."
  200. :group 'development)
  201. (defgroup maint nil
  202. "Maintenance aids for the Emacs development group."
  203. :tag "Maintenance"
  204. :group 'development)
  205. (defgroup environment nil
  206. "Fitting Emacs with its environment."
  207. :group 'emacs)
  208. (defgroup hardware nil
  209. "Support for interfacing with miscellaneous hardware."
  210. :group 'environment)
  211. (defgroup terminals nil
  212. "Support for terminal types."
  213. :group 'environment)
  214. (defgroup unix nil
  215. "Front-ends/assistants for, or emulators of, UNIX features."
  216. :group 'environment)
  217. (defgroup i18n nil
  218. "Internationalization and alternate character-set support."
  219. :link '(custom-manual "(emacs)International")
  220. :group 'environment
  221. :group 'editing)
  222. (defgroup x nil
  223. "The X Window system."
  224. :group 'environment)
  225. (defgroup frames nil
  226. "Support for Emacs frames and window systems."
  227. :group 'environment)
  228. (defgroup tex nil
  229. "Code related to the TeX formatter."
  230. :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
  231. :group 'wp)
  232. (defgroup faces nil
  233. "Support for multiple fonts."
  234. :group 'emacs)
  235. (defgroup help nil
  236. "Support for on-line help systems."
  237. :group 'emacs)
  238. (defgroup multimedia nil
  239. "Non-textual support, specifically images and sound."
  240. :group 'emacs)
  241. (defgroup local nil
  242. "Code local to your site."
  243. :group 'emacs)
  244. (defgroup customize '((widgets custom-group))
  245. "Customization of the Customization support."
  246. :prefix "custom-"
  247. :group 'help)
  248. (defgroup custom-faces nil
  249. "Faces used by customize."
  250. :group 'customize
  251. :group 'faces)
  252. (defgroup custom-browse nil
  253. "Control customize browser."
  254. :prefix "custom-"
  255. :group 'customize)
  256. (defgroup custom-buffer nil
  257. "Control customize buffers."
  258. :prefix "custom-"
  259. :group 'customize)
  260. (defgroup custom-menu nil
  261. "Control customize menus."
  262. :prefix "custom-"
  263. :group 'customize)
  264. (defgroup alloc nil
  265. "Storage allocation and gc for GNU Emacs Lisp interpreter."
  266. :tag "Storage Allocation"
  267. :group 'internal)
  268. (defgroup undo nil
  269. "Undoing changes in buffers."
  270. :link '(custom-manual "(emacs)Undo")
  271. :group 'editing)
  272. (defgroup mode-line nil
  273. "Content of the modeline."
  274. :group 'environment)
  275. (defgroup editing-basics nil
  276. "Most basic editing facilities."
  277. :group 'editing)
  278. (defgroup display nil
  279. "How characters are displayed in buffers."
  280. :group 'environment)
  281. (defgroup execute nil
  282. "Executing external commands."
  283. :group 'processes)
  284. (defgroup installation nil
  285. "The Emacs installation."
  286. :group 'environment)
  287. (defgroup dired nil
  288. "Directory editing."
  289. :group 'environment)
  290. (defgroup limits nil
  291. "Internal Emacs limits."
  292. :group 'internal)
  293. (defgroup debug nil
  294. "Debugging Emacs itself."
  295. :group 'development)
  296. (defgroup keyboard nil
  297. "Input from the keyboard."
  298. :group 'environment)
  299. (defgroup mouse nil
  300. "Input from the mouse."
  301. :group 'environment)
  302. (defgroup menu nil
  303. "Input from the menus."
  304. :group 'environment)
  305. (defgroup dnd nil
  306. "Handling data from drag and drop."
  307. :group 'environment)
  308. (defgroup auto-save nil
  309. "Preventing accidental loss of data."
  310. :group 'files)
  311. (defgroup processes-basics nil
  312. "Basic stuff dealing with processes."
  313. :group 'processes)
  314. (defgroup mule nil
  315. "MULE Emacs internationalization."
  316. :group 'i18n)
  317. (defgroup windows nil
  318. "Windows within a frame."
  319. :link '(custom-manual "(emacs)Windows")
  320. :group 'environment)
  321. ;;; Custom mode keymaps
  322. (defvar custom-mode-map
  323. (let ((map (make-keymap)))
  324. (set-keymap-parent map widget-keymap)
  325. (define-key map [remap self-insert-command] 'Custom-no-edit)
  326. (define-key map "\^m" 'Custom-newline)
  327. (define-key map " " 'scroll-up-command)
  328. (define-key map "\177" 'scroll-down-command)
  329. (define-key map "\C-c\C-c" 'Custom-set)
  330. (define-key map "\C-x\C-s" 'Custom-save)
  331. (define-key map "q" 'Custom-buffer-done)
  332. (define-key map "u" 'Custom-goto-parent)
  333. (define-key map "n" 'widget-forward)
  334. (define-key map "p" 'widget-backward)
  335. map)
  336. "Keymap for `Custom-mode'.")
  337. (defvar custom-mode-link-map
  338. (let ((map (make-keymap)))
  339. (set-keymap-parent map custom-mode-map)
  340. (define-key map [down-mouse-2] nil)
  341. (define-key map [down-mouse-1] 'mouse-drag-region)
  342. (define-key map [mouse-2] 'widget-move-and-invoke)
  343. map)
  344. "Local keymap for links in `Custom-mode'.")
  345. (defvar custom-field-keymap
  346. (let ((map (copy-keymap widget-field-keymap)))
  347. (define-key map "\C-c\C-c" 'Custom-set)
  348. (define-key map "\C-x\C-s" 'Custom-save)
  349. map)
  350. "Keymap used inside editable fields in customization buffers.")
  351. (widget-put (get 'editable-field 'widget-type) :keymap custom-field-keymap)
  352. ;;; Utilities.
  353. (defun custom-split-regexp-maybe (regexp)
  354. "If REGEXP is a string, split it to a list at `\\|'.
  355. You can get the original back from the result with:
  356. (mapconcat 'identity result \"\\|\")
  357. IF REGEXP is not a string, return it unchanged."
  358. (if (stringp regexp)
  359. (split-string regexp "\\\\|")
  360. regexp))
  361. (defun custom-variable-prompt ()
  362. "Prompt for a custom variable, defaulting to the variable at point.
  363. Return a list suitable for use in `interactive'."
  364. (let* ((v (variable-at-point))
  365. (default (and (symbolp v) (custom-variable-p v) (symbol-name v)))
  366. (enable-recursive-minibuffers t)
  367. val)
  368. (setq val (completing-read
  369. (if default (format "Customize variable (default %s): " default)
  370. "Customize variable: ")
  371. obarray 'custom-variable-p t nil nil default))
  372. (list (if (equal val "")
  373. (if (symbolp v) v nil)
  374. (intern val)))))
  375. (defun custom-menu-filter (menu widget)
  376. "Convert MENU to the form used by `widget-choose'.
  377. MENU should be in the same format as `custom-variable-menu'.
  378. WIDGET is the widget to apply the filter entries of MENU on."
  379. (let ((result nil)
  380. current name action filter)
  381. (while menu
  382. (setq current (car menu)
  383. name (nth 0 current)
  384. action (nth 1 current)
  385. filter (nth 2 current)
  386. menu (cdr menu))
  387. (if (or (null filter) (funcall filter widget))
  388. (push (cons name action) result)
  389. (push name result)))
  390. (nreverse result)))
  391. ;;; Unlispify.
  392. (defvar custom-prefix-list nil
  393. "List of prefixes that should be ignored by `custom-unlispify'.")
  394. (defcustom custom-unlispify-menu-entries t
  395. "Display menu entries as words instead of symbols if non-nil."
  396. :group 'custom-menu
  397. :type 'boolean)
  398. (defcustom custom-unlispify-remove-prefixes nil
  399. "Non-nil means remove group prefixes from option names in buffer."
  400. :group 'custom-menu
  401. :group 'custom-buffer
  402. :type 'boolean)
  403. (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
  404. "Convert SYMBOL into a menu entry."
  405. (cond ((not custom-unlispify-menu-entries)
  406. (symbol-name symbol))
  407. ((get symbol 'custom-tag)
  408. (if no-suffix
  409. (get symbol 'custom-tag)
  410. (concat (get symbol 'custom-tag) "...")))
  411. (t
  412. (with-current-buffer (get-buffer-create " *Custom-Work*")
  413. (erase-buffer)
  414. (princ symbol (current-buffer))
  415. (goto-char (point-min))
  416. ;; FIXME: Boolean variables are not predicates, so they shouldn't
  417. ;; end with `-p'. -stef
  418. ;; (when (and (eq (get symbol 'custom-type) 'boolean)
  419. ;; (re-search-forward "-p\\'" nil t))
  420. ;; (replace-match "" t t)
  421. ;; (goto-char (point-min)))
  422. (if custom-unlispify-remove-prefixes
  423. (let ((prefixes custom-prefix-list)
  424. prefix)
  425. (while prefixes
  426. (setq prefix (car prefixes))
  427. (if (search-forward prefix (+ (point) (length prefix)) t)
  428. (progn
  429. (setq prefixes nil)
  430. (delete-region (point-min) (point)))
  431. (setq prefixes (cdr prefixes))))))
  432. (subst-char-in-region (point-min) (point-max) ?- ?\ t)
  433. (capitalize-region (point-min) (point-max))
  434. (unless no-suffix
  435. (goto-char (point-max))
  436. (insert "..."))
  437. (buffer-string)))))
  438. (defcustom custom-unlispify-tag-names t
  439. "Display tag names as words instead of symbols if non-nil."
  440. :group 'custom-buffer
  441. :type 'boolean)
  442. (defun custom-unlispify-tag-name (symbol)
  443. "Convert SYMBOL into a menu entry."
  444. (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
  445. (custom-unlispify-menu-entry symbol t)))
  446. (defun custom-prefix-add (symbol prefixes)
  447. "Add SYMBOL to list of ignored PREFIXES."
  448. (cons (or (get symbol 'custom-prefix)
  449. (concat (symbol-name symbol) "-"))
  450. prefixes))
  451. ;;; Guess.
  452. (defcustom custom-guess-name-alist
  453. '(("-p\\'" boolean)
  454. ("-flag\\'" boolean)
  455. ("-hook\\'" hook)
  456. ("-face\\'" face)
  457. ("-file\\'" file)
  458. ("-function\\'" function)
  459. ("-functions\\'" (repeat function))
  460. ("-list\\'" (repeat sexp))
  461. ("-alist\\'" (alist :key-type sexp :value-type sexp)))
  462. "Alist of (MATCH TYPE).
  463. MATCH should be a regexp matching the name of a symbol, and TYPE should
  464. be a widget suitable for editing the value of that symbol. The TYPE
  465. of the first entry where MATCH matches the name of the symbol will be
  466. used.
  467. This is used for guessing the type of variables not declared with
  468. customize."
  469. :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
  470. :group 'custom-buffer)
  471. (defcustom custom-guess-doc-alist
  472. '(("\\`\\*?Non-nil " boolean))
  473. "Alist of (MATCH TYPE).
  474. MATCH should be a regexp matching a documentation string, and TYPE
  475. should be a widget suitable for editing the value of a variable with
  476. that documentation string. The TYPE of the first entry where MATCH
  477. matches the name of the symbol will be used.
  478. This is used for guessing the type of variables not declared with
  479. customize."
  480. :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type")))
  481. :group 'custom-buffer)
  482. (defun custom-guess-type (symbol)
  483. "Guess a widget suitable for editing the value of SYMBOL.
  484. This is done by matching SYMBOL with `custom-guess-name-alist' and
  485. if that fails, the doc string with `custom-guess-doc-alist'."
  486. (let ((name (symbol-name symbol))
  487. (names custom-guess-name-alist)
  488. current found)
  489. (while names
  490. (setq current (car names)
  491. names (cdr names))
  492. (when (string-match (nth 0 current) name)
  493. (setq found (nth 1 current)
  494. names nil)))
  495. (unless found
  496. (let ((doc (documentation-property symbol 'variable-documentation))
  497. (docs custom-guess-doc-alist))
  498. (when doc
  499. (while docs
  500. (setq current (car docs)
  501. docs (cdr docs))
  502. (when (string-match (nth 0 current) doc)
  503. (setq found (nth 1 current)
  504. docs nil))))))
  505. found))
  506. ;;; Sorting.
  507. ;;;###autoload
  508. (defcustom custom-browse-sort-alphabetically nil
  509. "If non-nil, sort customization group alphabetically in `custom-browse'."
  510. :type 'boolean
  511. :group 'custom-browse)
  512. (defcustom custom-browse-order-groups nil
  513. "If non-nil, order group members within each customization group.
  514. If `first', order groups before non-groups.
  515. If `last', order groups after non-groups."
  516. :type '(choice (const first)
  517. (const last)
  518. (const :tag "none" nil))
  519. :group 'custom-browse)
  520. (defcustom custom-browse-only-groups nil
  521. "If non-nil, show group members only within each customization group."
  522. :type 'boolean
  523. :group 'custom-browse)
  524. ;;;###autoload
  525. (defcustom custom-buffer-sort-alphabetically t
  526. "Whether to sort customization groups alphabetically in Custom buffer."
  527. :type 'boolean
  528. :group 'custom-buffer
  529. :version "24.1")
  530. (defcustom custom-buffer-order-groups 'last
  531. "If non-nil, order group members within each customization group.
  532. If `first', order groups before non-groups.
  533. If `last', order groups after non-groups."
  534. :type '(choice (const first)
  535. (const last)
  536. (const :tag "none" nil))
  537. :group 'custom-buffer)
  538. ;;;###autoload
  539. (defcustom custom-menu-sort-alphabetically nil
  540. "If non-nil, sort each customization group alphabetically in menus."
  541. :type 'boolean
  542. :group 'custom-menu)
  543. (defcustom custom-menu-order-groups 'first
  544. "If non-nil, order group members within each customization group.
  545. If `first', order groups before non-groups.
  546. If `last', order groups after non-groups."
  547. :type '(choice (const first)
  548. (const last)
  549. (const :tag "none" nil))
  550. :group 'custom-menu)
  551. (defun custom-sort-items (items sort-alphabetically order-groups)
  552. "Return a sorted copy of ITEMS.
  553. ITEMS should be a `custom-group' property.
  554. If SORT-ALPHABETICALLY non-nil, sort alphabetically.
  555. If ORDER-GROUPS is `first' order groups before non-groups, if `last' order
  556. groups after non-groups, if nil do not order groups at all."
  557. (sort (copy-sequence items)
  558. (lambda (a b)
  559. (let ((typea (nth 1 a)) (typeb (nth 1 b))
  560. (namea (nth 0 a)) (nameb (nth 0 b)))
  561. (cond ((not order-groups)
  562. ;; Since we don't care about A and B order, maybe sort.
  563. (when sort-alphabetically
  564. (string-lessp namea nameb)))
  565. ((eq typea 'custom-group)
  566. ;; If B is also a group, maybe sort. Otherwise, order A and B.
  567. (if (eq typeb 'custom-group)
  568. (when sort-alphabetically
  569. (string-lessp namea nameb))
  570. (eq order-groups 'first)))
  571. ((eq typeb 'custom-group)
  572. ;; Since A cannot be a group, order A and B.
  573. (eq order-groups 'last))
  574. (sort-alphabetically
  575. ;; Since A and B cannot be groups, sort.
  576. (string-lessp namea nameb)))))))
  577. ;;; Custom Mode Commands.
  578. ;; This variable is used by `custom-tool-bar-map', or directly by
  579. ;; `custom-buffer-create-internal' if `custom-buffer-verbose-help' is non-nil.
  580. (defvar custom-commands
  581. '((" Set for current session " Custom-set t
  582. "Apply all settings in this buffer to the current session"
  583. "index"
  584. "Apply")
  585. (" Save for future sessions " Custom-save
  586. (or custom-file user-init-file)
  587. "Apply all settings in this buffer and save them for future Emacs sessions."
  588. "save"
  589. "Save")
  590. (" Undo edits " Custom-reset-current t
  591. "Restore all settings in this buffer to reflect their current values."
  592. "refresh"
  593. "Undo")
  594. (" Reset to saved " Custom-reset-saved t
  595. "Restore all settings in this buffer to their saved values (if any)."
  596. "undo"
  597. "Reset")
  598. (" Erase customizations " Custom-reset-standard
  599. (or custom-file user-init-file)
  600. "Un-customize all settings in this buffer and save them with standard values."
  601. "delete"
  602. "Uncustomize")
  603. (" Help for Customize " Custom-help t
  604. "Get help for using Customize."
  605. "help"
  606. "Help")
  607. (" Exit " Custom-buffer-done t "Exit Customize." "exit" "Exit")))
  608. (defun Custom-help ()
  609. "Read the node on Easy Customization in the Emacs manual."
  610. (interactive)
  611. (info "(emacs)Easy Customization"))
  612. (defvar custom-reset-menu
  613. '(("Undo Edits" . Custom-reset-current)
  614. ("Reset to Saved" . Custom-reset-saved)
  615. ("Erase Customizations (use standard values)" . Custom-reset-standard))
  616. "Alist of actions for the `Reset' button.
  617. The key is a string containing the name of the action, the value is a
  618. Lisp function taking the widget as an element which will be called
  619. when the action is chosen.")
  620. (defvar custom-options nil
  621. "Customization widgets in the current buffer.")
  622. (defun custom-command-apply (fun query &optional strong-query)
  623. "Call function FUN on all widgets in `custom-options'.
  624. If there is more than one widget, ask user for confirmation using
  625. the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil,
  626. and `yes-or-no-p' otherwise."
  627. (if (or (and (= 1 (length custom-options))
  628. (memq (widget-type (car custom-options))
  629. '(custom-variable custom-face)))
  630. (funcall (if strong-query 'yes-or-no-p 'y-or-n-p) query))
  631. (progn (mapc fun custom-options) t)
  632. (message "Aborted")
  633. nil))
  634. (defun Custom-set (&rest _ignore)
  635. "Set the current value of all edited settings in the buffer."
  636. (interactive)
  637. (custom-command-apply
  638. (lambda (child)
  639. (when (eq (widget-get child :custom-state) 'modified)
  640. (widget-apply child :custom-set)))
  641. "Set all values according to this buffer? "))
  642. (defun Custom-save (&rest _ignore)
  643. "Set all edited settings, then save all settings that have been set.
  644. If a setting was edited and set before, this saves it. If a
  645. setting was merely edited before, this sets it then saves it."
  646. (interactive)
  647. (when (custom-command-apply
  648. (lambda (child)
  649. (when (memq (widget-get child :custom-state)
  650. '(modified set changed rogue))
  651. (widget-apply child :custom-mark-to-save)))
  652. "Save all settings in this buffer? " t)
  653. ;; Save changes to buffer and redraw.
  654. (custom-save-all)
  655. (dolist (child custom-options)
  656. (widget-apply child :custom-state-set-and-redraw))))
  657. (defun custom-reset (_widget &optional event)
  658. "Select item from reset menu."
  659. (let* ((completion-ignore-case t)
  660. (answer (widget-choose "Reset settings"
  661. custom-reset-menu
  662. event)))
  663. (if answer
  664. (funcall answer))))
  665. (defun Custom-reset-current (&rest _ignore)
  666. "Reset all edited settings in the buffer to show their current values."
  667. (interactive)
  668. (custom-command-apply
  669. (lambda (widget)
  670. (if (memq (widget-get widget :custom-state) '(modified changed))
  671. (widget-apply widget :custom-reset-current)))
  672. "Reset all settings' buffer text to show current values? "))
  673. (defun Custom-reset-saved (&rest _ignore)
  674. "Reset all edited or set settings in the buffer to their saved value.
  675. This also shows the saved values in the buffer."
  676. (interactive)
  677. (custom-command-apply
  678. (lambda (widget)
  679. (if (memq (widget-get widget :custom-state) '(modified set changed rogue))
  680. (widget-apply widget :custom-reset-saved)))
  681. "Reset all settings (current values and buffer text) to saved values? "))
  682. ;; The next two variables are bound to '(t) by `Custom-reset-standard'
  683. ;; and `custom-group-reset-standard'. If these variables are nil, both
  684. ;; `custom-variable-reset-standard' and `custom-face-reset-standard'
  685. ;; save, reset and redraw the handled widget immediately. Otherwise,
  686. ;; they add the widget to the corresponding list and leave it to
  687. ;; `custom-reset-standard-save-and-update' to save, reset and redraw it.
  688. (defvar custom-reset-standard-variables-list nil)
  689. (defvar custom-reset-standard-faces-list nil)
  690. ;; The next function was excerpted from `custom-variable-reset-standard'
  691. ;; and `custom-face-reset-standard' and is used to avoid calling
  692. ;; `custom-save-all' repeatedly (and thus saving settings to file one by
  693. ;; one) when erasing all customizations.
  694. (defun custom-reset-standard-save-and-update ()
  695. "Save settings and redraw after erasing customizations."
  696. (when (or (and custom-reset-standard-variables-list
  697. (not (eq custom-reset-standard-variables-list '(t))))
  698. (and custom-reset-standard-faces-list
  699. (not (eq custom-reset-standard-faces-list '(t)))))
  700. ;; Save settings to file.
  701. (custom-save-all)
  702. ;; Set state of and redraw variables.
  703. (dolist (widget custom-reset-standard-variables-list)
  704. (unless (eq widget t)
  705. (widget-put widget :custom-state 'unknown)
  706. (custom-redraw widget)))
  707. ;; Set state of and redraw faces.
  708. (dolist (widget custom-reset-standard-faces-list)
  709. (unless (eq widget t)
  710. (let* ((symbol (widget-value widget))
  711. (child (car (widget-get widget :children)))
  712. (comment-widget (widget-get widget :comment-widget)))
  713. (put symbol 'face-comment nil)
  714. (widget-value-set child
  715. (custom-pre-filter-face-spec
  716. (list (list t (custom-face-attributes-get
  717. symbol nil)))))
  718. ;; This call manages the comment visibility
  719. (widget-value-set comment-widget "")
  720. (custom-face-state-set widget)
  721. (custom-redraw-magic widget))))))
  722. (defun Custom-reset-standard (&rest _ignore)
  723. "Erase all customizations (either current or saved) in current buffer.
  724. The immediate result is to restore them to their standard values.
  725. This operation eliminates any saved values for the group members,
  726. making them as if they had never been customized at all."
  727. (interactive)
  728. ;; Bind these temporarily.
  729. (let ((custom-reset-standard-variables-list '(t))
  730. (custom-reset-standard-faces-list '(t)))
  731. (custom-command-apply
  732. (lambda (widget)
  733. (and (or (null (widget-get widget :custom-standard-value))
  734. (widget-apply widget :custom-standard-value))
  735. (memq (widget-get widget :custom-state)
  736. '(modified set changed saved rogue))
  737. (widget-apply widget :custom-mark-to-reset-standard)))
  738. "Erase all customizations for settings in this buffer? " t)
  739. (custom-reset-standard-save-and-update)))
  740. ;;; The Customize Commands
  741. (defun custom-prompt-variable (prompt-var prompt-val &optional comment)
  742. "Prompt for a variable and a value and return them as a list.
  743. PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the
  744. prompt for the value. The %s escape in PROMPT-VAL is replaced with
  745. the name of the variable.
  746. If the variable has a `variable-interactive' property, that is used as if
  747. it were the arg to `interactive' (which see) to interactively read the value.
  748. If the variable has a `custom-type' property, it must be a widget and the
  749. `:prompt-value' property of that widget will be used for reading the value.
  750. If the variable also has a `custom-get' property, that is used for finding
  751. the current value of the variable, otherwise `symbol-value' is used.
  752. If optional COMMENT argument is non-nil, also prompt for a comment and return
  753. it as the third element in the list."
  754. (let* ((var (read-variable prompt-var))
  755. (minibuffer-help-form '(describe-variable var))
  756. (val
  757. (let ((prop (get var 'variable-interactive))
  758. (type (get var 'custom-type))
  759. (prompt (format prompt-val var)))
  760. (unless (listp type)
  761. (setq type (list type)))
  762. (cond (prop
  763. ;; Use VAR's `variable-interactive' property
  764. ;; as an interactive spec for prompting.
  765. (call-interactively `(lambda (arg)
  766. (interactive ,prop)
  767. arg)))
  768. (type
  769. (widget-prompt-value type
  770. prompt
  771. (if (boundp var)
  772. (funcall
  773. (or (get var 'custom-get) 'symbol-value)
  774. var))
  775. (not (boundp var))))
  776. (t
  777. (eval-minibuffer prompt))))))
  778. (if comment
  779. (list var val
  780. (read-string "Comment: " (get var 'variable-comment)))
  781. (list var val))))
  782. ;;;###autoload
  783. (defun customize-set-value (variable value &optional comment)
  784. "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object.
  785. If VARIABLE has a `variable-interactive' property, that is used as if
  786. it were the arg to `interactive' (which see) to interactively read the value.
  787. If VARIABLE has a `custom-type' property, it must be a widget and the
  788. `:prompt-value' property of that widget will be used for reading the value.
  789. If given a prefix (or a COMMENT argument), also prompt for a comment."
  790. (interactive (custom-prompt-variable "Set variable: "
  791. "Set %s to value: "
  792. current-prefix-arg))
  793. (cond ((string= comment "")
  794. (put variable 'variable-comment nil))
  795. (comment
  796. (put variable 'variable-comment comment)))
  797. (set variable value))
  798. ;;;###autoload
  799. (defun customize-set-variable (variable value &optional comment)
  800. "Set the default for VARIABLE to VALUE, and return VALUE.
  801. VALUE is a Lisp object.
  802. If VARIABLE has a `custom-set' property, that is used for setting
  803. VARIABLE, otherwise `set-default' is used.
  804. If VARIABLE has a `variable-interactive' property, that is used as if
  805. it were the arg to `interactive' (which see) to interactively read the value.
  806. If VARIABLE has a `custom-type' property, it must be a widget and the
  807. `:prompt-value' property of that widget will be used for reading the value.
  808. If given a prefix (or a COMMENT argument), also prompt for a comment."
  809. (interactive (custom-prompt-variable "Set variable: "
  810. "Set customized value for %s to: "
  811. current-prefix-arg))
  812. (custom-load-symbol variable)
  813. (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
  814. (funcall (or (get variable 'custom-set) 'set-default) variable value)
  815. (put variable 'customized-value (list (custom-quote value)))
  816. (cond ((string= comment "")
  817. (put variable 'variable-comment nil)
  818. (put variable 'customized-variable-comment nil))
  819. (comment
  820. (put variable 'variable-comment comment)
  821. (put variable 'customized-variable-comment comment)))
  822. value)
  823. ;;;###autoload
  824. (defun customize-save-variable (variable value &optional comment)
  825. "Set the default for VARIABLE to VALUE, and save it for future sessions.
  826. Return VALUE.
  827. If VARIABLE has a `custom-set' property, that is used for setting
  828. VARIABLE, otherwise `set-default' is used.
  829. If VARIABLE has a `variable-interactive' property, that is used as if
  830. it were the arg to `interactive' (which see) to interactively read the value.
  831. If VARIABLE has a `custom-type' property, it must be a widget and the
  832. `:prompt-value' property of that widget will be used for reading the value.
  833. If given a prefix (or a COMMENT argument), also prompt for a comment."
  834. (interactive (custom-prompt-variable "Set and save variable: "
  835. "Set and save value for %s as: "
  836. current-prefix-arg))
  837. (funcall (or (get variable 'custom-set) 'set-default) variable value)
  838. (put variable 'saved-value (list (custom-quote value)))
  839. (custom-push-theme 'theme-value variable 'user 'set (custom-quote value))
  840. (cond ((string= comment "")
  841. (put variable 'variable-comment nil)
  842. (put variable 'saved-variable-comment nil))
  843. (comment
  844. (put variable 'variable-comment comment)
  845. (put variable 'saved-variable-comment comment)))
  846. (put variable 'customized-value nil)
  847. (put variable 'customized-variable-comment nil)
  848. (if (custom-file t)
  849. (custom-save-all)
  850. (message "Setting `%s' temporarily since \"emacs -q\" would overwrite customizations"
  851. variable)
  852. (set variable value))
  853. value)
  854. ;; Some parts of Emacs might prompt the user to save customizations,
  855. ;; during startup before customizations are loaded. This function
  856. ;; handles this corner case by avoiding calling `custom-save-variable'
  857. ;; too early, which could wipe out existing customizations.
  858. ;;;###autoload
  859. (defun customize-push-and-save (list-var elts)
  860. "Add ELTS to LIST-VAR and save for future sessions, safely.
  861. ELTS should be a list. This function adds each entry to the
  862. value of LIST-VAR using `add-to-list'.
  863. If Emacs is initialized, call `customize-save-variable' to save
  864. the resulting list value now. Otherwise, add an entry to
  865. `after-init-hook' to save it after initialization."
  866. (dolist (entry elts)
  867. (add-to-list list-var entry))
  868. (if after-init-time
  869. (let ((coding-system-for-read nil))
  870. (customize-save-variable list-var (eval list-var)))
  871. (add-hook 'after-init-hook
  872. `(lambda ()
  873. (customize-push-and-save ',list-var ',elts)))))
  874. ;;;###autoload
  875. (defun customize ()
  876. "Select a customization buffer which you can use to set user options.
  877. User options are structured into \"groups\".
  878. Initially the top-level group `Emacs' and its immediate subgroups
  879. are shown; the contents of those subgroups are initially hidden."
  880. (interactive)
  881. (customize-group 'emacs))
  882. ;;;###autoload
  883. (defun customize-mode (mode)
  884. "Customize options related to the current major mode.
  885. If a prefix \\[universal-argument] was given (or if the current major mode has no known group),
  886. then prompt for the MODE to customize."
  887. (interactive
  888. (list
  889. (let ((completion-regexp-list '("-mode\\'"))
  890. (group (custom-group-of-mode major-mode)))
  891. (if (and group (not current-prefix-arg))
  892. major-mode
  893. (intern
  894. (completing-read (if group
  895. (format "Major mode (default %s): " major-mode)
  896. "Major mode: ")
  897. obarray
  898. 'custom-group-of-mode
  899. t nil nil (if group (symbol-name major-mode))))))))
  900. (customize-group (custom-group-of-mode mode)))
  901. (defun customize-read-group ()
  902. (let ((completion-ignore-case t))
  903. (completing-read "Customize group (default emacs): "
  904. obarray
  905. (lambda (symbol)
  906. (or (and (get symbol 'custom-loads)
  907. (not (get symbol 'custom-autoload)))
  908. (get symbol 'custom-group)))
  909. t)))
  910. ;;;###autoload
  911. (defun customize-group (&optional group other-window)
  912. "Customize GROUP, which must be a customization group.
  913. If OTHER-WINDOW is non-nil, display in another window."
  914. (interactive (list (customize-read-group)))
  915. (when (stringp group)
  916. (if (string-equal "" group)
  917. (setq group 'emacs)
  918. (setq group (intern group))))
  919. (let ((name (format "*Customize Group: %s*"
  920. (custom-unlispify-tag-name group))))
  921. (cond
  922. ((null (get-buffer name))
  923. (funcall (if other-window
  924. 'custom-buffer-create-other-window
  925. 'custom-buffer-create)
  926. (list (list group 'custom-group))
  927. name
  928. (concat " for group "
  929. (custom-unlispify-tag-name group))))
  930. (other-window
  931. (switch-to-buffer-other-window name))
  932. (t
  933. (pop-to-buffer-same-window name)))))
  934. ;;;###autoload
  935. (defun customize-group-other-window (&optional group)
  936. "Customize GROUP, which must be a customization group, in another window."
  937. (interactive (list (customize-read-group)))
  938. (customize-group group t))
  939. ;;;###autoload
  940. (defalias 'customize-variable 'customize-option)
  941. ;;;###autoload
  942. (defun customize-option (symbol)
  943. "Customize SYMBOL, which must be a user option variable."
  944. (interactive (custom-variable-prompt))
  945. (unless symbol
  946. (error "No variable specified"))
  947. (let ((basevar (indirect-variable symbol)))
  948. (custom-buffer-create (list (list basevar 'custom-variable))
  949. (format "*Customize Option: %s*"
  950. (custom-unlispify-tag-name basevar)))
  951. (unless (eq symbol basevar)
  952. (message "`%s' is an alias for `%s'" symbol basevar))))
  953. ;;;###autoload
  954. (defalias 'customize-variable-other-window 'customize-option-other-window)
  955. ;;;###autoload
  956. (defun customize-option-other-window (symbol)
  957. "Customize SYMBOL, which must be a user option variable.
  958. Show the buffer in another window, but don't select it."
  959. (interactive (custom-variable-prompt))
  960. (unless symbol
  961. (error "No variable specified"))
  962. (let ((basevar (indirect-variable symbol)))
  963. (custom-buffer-create-other-window
  964. (list (list basevar 'custom-variable))
  965. (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar)))
  966. (unless (eq symbol basevar)
  967. (message "`%s' is an alias for `%s'" symbol basevar))))
  968. (defvar customize-changed-options-previous-release "23.4"
  969. "Version for `customize-changed-options' to refer back to by default.")
  970. ;; Packages will update this variable, so make it available.
  971. ;;;###autoload
  972. (defvar customize-package-emacs-version-alist nil
  973. "Alist mapping versions of a package to Emacs versions.
  974. We use this for packages that have their own names, but are released
  975. as part of Emacs itself.
  976. Each elements looks like this:
  977. (PACKAGE (PVERSION . EVERSION)...)
  978. Here PACKAGE is the name of a package, as a symbol. After
  979. PACKAGE come one or more elements, each associating a
  980. package version PVERSION with the first Emacs version
  981. EVERSION in which it (or a subsequent version of PACKAGE)
  982. was first released. Both PVERSION and EVERSION are strings.
  983. PVERSION should be a string that this package used in
  984. the :package-version keyword for `defcustom', `defgroup',
  985. and `defface'.
  986. For example, the MH-E package updates this alist as follows:
  987. (add-to-list 'customize-package-emacs-version-alist
  988. '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\")
  989. (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\")
  990. (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\")
  991. (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\")))
  992. The value of PACKAGE needs to be unique and it needs to match the
  993. PACKAGE value appearing in the :package-version keyword. Since
  994. the user might see the value in a error message, a good choice is
  995. the official name of the package, such as MH-E or Gnus.")
  996. ;;;###autoload
  997. (defalias 'customize-changed 'customize-changed-options)
  998. ;;;###autoload
  999. (defun customize-changed-options (&optional since-version)
  1000. "Customize all settings whose meanings have changed in Emacs itself.
  1001. This includes new user option variables and faces, and new
  1002. customization groups, as well as older options and faces whose meanings
  1003. or default values have changed since the previous major Emacs release.
  1004. With argument SINCE-VERSION (a string), customize all settings
  1005. that were added or redefined since that version."
  1006. (interactive
  1007. (list
  1008. (read-from-minibuffer
  1009. (format "Customize options changed, since version (default %s): "
  1010. customize-changed-options-previous-release))))
  1011. (if (equal since-version "")
  1012. (setq since-version nil)
  1013. (unless (condition-case nil
  1014. (numberp (read since-version))
  1015. (error nil))
  1016. (signal 'wrong-type-argument (list 'numberp since-version))))
  1017. (unless since-version
  1018. (setq since-version customize-changed-options-previous-release))
  1019. ;; Load the information for versions since since-version. We use
  1020. ;; custom-load-symbol for this.
  1021. (put 'custom-versions-load-alist 'custom-loads nil)
  1022. (dolist (elt custom-versions-load-alist)
  1023. (if (customize-version-lessp since-version (car elt))
  1024. (dolist (load (cdr elt))
  1025. (custom-add-load 'custom-versions-load-alist load))))
  1026. (custom-load-symbol 'custom-versions-load-alist)
  1027. (put 'custom-versions-load-alist 'custom-loads nil)
  1028. (let (found)
  1029. (mapatoms
  1030. (lambda (symbol)
  1031. (let* ((package-version (get symbol 'custom-package-version))
  1032. (version
  1033. (or (and package-version
  1034. (customize-package-emacs-version symbol
  1035. package-version))
  1036. (get symbol 'custom-version))))
  1037. (if version
  1038. (when (customize-version-lessp since-version version)
  1039. (if (or (get symbol 'custom-group)
  1040. (get symbol 'group-documentation))
  1041. (push (list symbol 'custom-group) found))
  1042. (if (custom-variable-p symbol)
  1043. (push (list symbol 'custom-variable) found))
  1044. (if (custom-facep symbol)
  1045. (push (list symbol 'custom-face) found)))))))
  1046. (if found
  1047. (custom-buffer-create (custom-sort-items found t 'first)
  1048. "*Customize Changed Options*")
  1049. (error "No user option defaults have been changed since Emacs %s"
  1050. since-version))))
  1051. (defun customize-package-emacs-version (symbol package-version)
  1052. "Return the Emacs version in which SYMBOL's meaning last changed.
  1053. PACKAGE-VERSION has the form (PACKAGE . VERSION). We use
  1054. `customize-package-emacs-version-alist' to find the version of
  1055. Emacs that is associated with version VERSION of PACKAGE."
  1056. (let (package-versions emacs-version)
  1057. ;; Use message instead of error since we want user to be able to
  1058. ;; see the rest of the symbols even if a package author has
  1059. ;; botched things up.
  1060. (cond ((not (listp package-version))
  1061. (message "Invalid package-version value for %s" symbol))
  1062. ((setq package-versions (assq (car package-version)
  1063. customize-package-emacs-version-alist))
  1064. (setq emacs-version
  1065. (cdr (assoc (cdr package-version) package-versions)))
  1066. (unless emacs-version
  1067. (message "%s version %s not found in %s" symbol
  1068. (cdr package-version)
  1069. "customize-package-emacs-version-alist")))
  1070. (t
  1071. (message "Package %s version %s lists no corresponding Emacs version"
  1072. (car package-version)
  1073. (cdr package-version))))
  1074. emacs-version))
  1075. (defun customize-version-lessp (version1 version2)
  1076. ;; Why are the versions strings, and given that they are, why aren't
  1077. ;; they converted to numbers and compared as such here? -- fx
  1078. ;; In case someone made a mistake and left out the quotes
  1079. ;; in the :version value.
  1080. (if (numberp version2)
  1081. (setq version2 (prin1-to-string version2)))
  1082. (let (major1 major2 minor1 minor2)
  1083. (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1)
  1084. (setq major1 (read (or (match-string 1 version1)
  1085. "0")))
  1086. (setq minor1 (read (or (match-string 3 version1)
  1087. "0")))
  1088. (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2)
  1089. (setq major2 (read (or (match-string 1 version2)
  1090. "0")))
  1091. (setq minor2 (read (or (match-string 3 version2)
  1092. "0")))
  1093. (or (< major1 major2)
  1094. (and (= major1 major2)
  1095. (< minor1 minor2)))))
  1096. ;;;###autoload
  1097. (defun customize-face (&optional face other-window)
  1098. "Customize FACE, which should be a face name or nil.
  1099. If FACE is nil, customize all faces. If FACE is actually a
  1100. face-alias, customize the face it is aliased to.
  1101. If OTHER-WINDOW is non-nil, display in another window.
  1102. Interactively, when point is on text which has a face specified,
  1103. suggest to customize that face, if it's customizable."
  1104. (interactive (list (read-face-name "Customize face" "all faces" t)))
  1105. (if (member face '(nil ""))
  1106. (setq face (face-list)))
  1107. (if (and (listp face) (null (cdr face)))
  1108. (setq face (car face)))
  1109. (let ((display-fun (if other-window
  1110. 'custom-buffer-create-other-window
  1111. 'custom-buffer-create)))
  1112. (if (listp face)
  1113. (funcall display-fun
  1114. (custom-sort-items
  1115. (mapcar (lambda (s) (list s 'custom-face)) face)
  1116. t nil)
  1117. "*Customize Faces*")
  1118. ;; If FACE is actually an alias, customize the face it is aliased to.
  1119. (if (get face 'face-alias)
  1120. (setq face (get face 'face-alias)))
  1121. (unless (facep face)
  1122. (error "Invalid face %S" face))
  1123. (funcall display-fun
  1124. (list (list face 'custom-face))
  1125. (format "*Customize Face: %s*"
  1126. (custom-unlispify-tag-name face))))))
  1127. ;;;###autoload
  1128. (defun customize-face-other-window (&optional face)
  1129. "Show customization buffer for face FACE in other window.
  1130. If FACE is actually a face-alias, customize the face it is aliased to.
  1131. Interactively, when point is on text which has a face specified,
  1132. suggest to customize that face, if it's customizable."
  1133. (interactive (list (read-face-name "Customize face" "all faces" t)))
  1134. (customize-face face t))
  1135. (defalias 'customize-customized 'customize-unsaved)
  1136. ;;;###autoload
  1137. (defun customize-unsaved ()
  1138. "Customize all options and faces set in this session but not saved."
  1139. (interactive)
  1140. (let ((found nil))
  1141. (mapatoms (lambda (symbol)
  1142. (and (or (get symbol 'customized-face)
  1143. (get symbol 'customized-face-comment))
  1144. (custom-facep symbol)
  1145. (push (list symbol 'custom-face) found))
  1146. (and (or (get symbol 'customized-value)
  1147. (get symbol 'customized-variable-comment))
  1148. (boundp symbol)
  1149. (push (list symbol 'custom-variable) found))))
  1150. (if (not found)
  1151. (error "No user options are set but unsaved")
  1152. (custom-buffer-create (custom-sort-items found t nil)
  1153. "*Customize Unsaved*"))))
  1154. ;;;###autoload
  1155. (defun customize-rogue ()
  1156. "Customize all user variables modified outside customize."
  1157. (interactive)
  1158. (let ((found nil))
  1159. (mapatoms (lambda (symbol)
  1160. (let ((cval (or (get symbol 'customized-value)
  1161. (get symbol 'saved-value)
  1162. (get symbol 'standard-value))))
  1163. (when (and cval ;Declared with defcustom.
  1164. (default-boundp symbol) ;Has a value.
  1165. (not (equal (eval (car cval))
  1166. ;; Which does not match customize.
  1167. (default-value symbol))))
  1168. (push (list symbol 'custom-variable) found)))))
  1169. (if (not found)
  1170. (error "No rogue user options")
  1171. (custom-buffer-create (custom-sort-items found t nil)
  1172. "*Customize Rogue*"))))
  1173. ;;;###autoload
  1174. (defun customize-saved ()
  1175. "Customize all saved options and faces."
  1176. (interactive)
  1177. (let ((found nil))
  1178. (mapatoms (lambda (symbol)
  1179. (and (or (get symbol 'saved-face)
  1180. (get symbol 'saved-face-comment))
  1181. (custom-facep symbol)
  1182. (push (list symbol 'custom-face) found))
  1183. (and (or (get symbol 'saved-value)
  1184. (get symbol 'saved-variable-comment))
  1185. (boundp symbol)
  1186. (push (list symbol 'custom-variable) found))))
  1187. (if (not found )
  1188. (error "No saved user options")
  1189. (custom-buffer-create (custom-sort-items found t nil)
  1190. "*Customize Saved*"))))
  1191. (declare-function apropos-parse-pattern "apropos" (pattern))
  1192. ;;;###autoload
  1193. (defun customize-apropos (pattern &optional type)
  1194. "Customize all loaded options, faces and groups matching PATTERN.
  1195. PATTERN can be a word, a list of words (separated by spaces),
  1196. or a regexp (using some regexp special characters). If it is a word,
  1197. search for matches for that word as a substring. If it is a list of words,
  1198. search for matches for any two (or more) of those words.
  1199. If TYPE is `options', include only options.
  1200. If TYPE is `faces', include only faces.
  1201. If TYPE is `groups', include only groups.
  1202. If TYPE is t (interactively, with prefix arg), include variables
  1203. that are not customizable options, as well as faces and groups
  1204. \(but we recommend using `apropos-variable' instead)."
  1205. (interactive (list (apropos-read-pattern "symbol") current-prefix-arg))
  1206. (require 'apropos)
  1207. (apropos-parse-pattern pattern)
  1208. (let (found)
  1209. (mapatoms
  1210. `(lambda (symbol)
  1211. (when (string-match apropos-regexp (symbol-name symbol))
  1212. ,(if (not (memq type '(faces options)))
  1213. '(if (get symbol 'custom-group)
  1214. (push (list symbol 'custom-group) found)))
  1215. ,(if (not (memq type '(options groups)))
  1216. '(if (custom-facep symbol)
  1217. (push (list symbol 'custom-face) found)))
  1218. ,(if (not (memq type '(groups faces)))
  1219. `(if (and (boundp symbol)
  1220. (eq (indirect-variable symbol) symbol)
  1221. (or (get symbol 'saved-value)
  1222. (custom-variable-p symbol)
  1223. ,(if (not (memq type '(nil options)))
  1224. '(get symbol 'variable-documentation))))
  1225. (push (list symbol 'custom-variable) found))))))
  1226. (if (not found)
  1227. (error "No %s matching %s"
  1228. (if (eq type t)
  1229. "items"
  1230. (format "customizable %s"
  1231. (if (memq type '(options faces groups))
  1232. (symbol-name type)
  1233. "items")))
  1234. pattern)
  1235. (custom-buffer-create
  1236. (custom-sort-items found t custom-buffer-order-groups)
  1237. "*Customize Apropos*"))))
  1238. ;;;###autoload
  1239. (defun customize-apropos-options (regexp &optional arg)
  1240. "Customize all loaded customizable options matching REGEXP.
  1241. With prefix ARG, include variables that are not customizable options
  1242. \(but it is better to use `apropos-variable' if you want to find those)."
  1243. (interactive "sCustomize options (regexp): \nP")
  1244. (customize-apropos regexp (or arg 'options)))
  1245. ;;;###autoload
  1246. (defun customize-apropos-faces (regexp)
  1247. "Customize all loaded faces matching REGEXP."
  1248. (interactive "sCustomize faces (regexp): \n")
  1249. (customize-apropos regexp 'faces))
  1250. ;;;###autoload
  1251. (defun customize-apropos-groups (regexp)
  1252. "Customize all loaded groups matching REGEXP."
  1253. (interactive "sCustomize groups (regexp): \n")
  1254. (customize-apropos regexp 'groups))
  1255. ;;; Buffer.
  1256. (defcustom custom-buffer-style 'links
  1257. "Control the presentation style for customization buffers.
  1258. The value should be a symbol, one of:
  1259. brackets: groups nest within each other with big horizontal brackets.
  1260. links: groups have links to subgroups."
  1261. :type '(radio (const brackets)
  1262. (const links))
  1263. :group 'custom-buffer)
  1264. (defcustom custom-buffer-done-kill nil
  1265. "Non-nil means exiting a Custom buffer should kill it."
  1266. :type 'boolean
  1267. :version "22.1"
  1268. :group 'custom-buffer)
  1269. (defcustom custom-buffer-indent 3
  1270. "Number of spaces to indent nested groups."
  1271. :type 'integer
  1272. :group 'custom-buffer)
  1273. (defun custom-get-fresh-buffer (name)
  1274. "Get a fresh new buffer with name NAME.
  1275. If the buffer already exist, clean it up to be like new.
  1276. Beware: it's not quite like new. Good enough for custom, but maybe
  1277. not for everybody."
  1278. ;; To be more complete, we should also kill all permanent-local variables,
  1279. ;; but it's not needed for custom.
  1280. (let ((buf (get-buffer name)))
  1281. (when (and buf (buffer-local-value 'buffer-file-name buf))
  1282. ;; This will check if the file is not saved.
  1283. (kill-buffer buf)
  1284. (setq buf nil))
  1285. (if (null buf)
  1286. (get-buffer-create name)
  1287. (with-current-buffer buf
  1288. (kill-all-local-variables)
  1289. (run-hooks 'kill-buffer-hook)
  1290. ;; Delete overlays before erasing the buffer so the overlay hooks
  1291. ;; don't get run spuriously when we erase the buffer.
  1292. (let ((ols (overlay-lists)))
  1293. (dolist (ol (nconc (car ols) (cdr ols)))
  1294. (delete-overlay ol)))
  1295. (erase-buffer)
  1296. buf))))
  1297. ;;;###autoload
  1298. (defun custom-buffer-create (options &optional name description)
  1299. "Create a buffer containing OPTIONS.
  1300. Optional NAME is the name of the buffer.
  1301. OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
  1302. SYMBOL is a customization option, and WIDGET is a widget for editing
  1303. that option."
  1304. (pop-to-buffer-same-window (custom-get-fresh-buffer (or name "*Customization*")))
  1305. (custom-buffer-create-internal options description))
  1306. ;;;###autoload
  1307. (defun custom-buffer-create-other-window (options &optional name description)
  1308. "Create a buffer containing OPTIONS, and display it in another window.
  1309. The result includes selecting that window.
  1310. Optional NAME is the name of the buffer.
  1311. OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where
  1312. SYMBOL is a customization option, and WIDGET is a widget for editing
  1313. that option."
  1314. (unless name (setq name "*Customization*"))
  1315. (switch-to-buffer-other-window (custom-get-fresh-buffer name))
  1316. (custom-buffer-create-internal options description))
  1317. (defcustom custom-reset-button-menu nil
  1318. "If non-nil, only show a single reset button in customize buffers.
  1319. This button will have a menu with all three reset operations."
  1320. :type 'boolean
  1321. :group 'custom-buffer)
  1322. (defcustom custom-buffer-verbose-help t
  1323. "If non-nil, include explanatory text in the customization buffer."
  1324. :type 'boolean
  1325. :group 'custom-buffer)
  1326. (defun Custom-buffer-done (&rest _ignore)
  1327. "Exit current Custom buffer according to `custom-buffer-done-kill'."
  1328. (interactive)
  1329. (quit-window custom-buffer-done-kill))
  1330. (defvar custom-button nil
  1331. "Face used for buttons in customization buffers.")
  1332. (defvar custom-button-mouse nil
  1333. "Mouse face used for buttons in customization buffers.")
  1334. (defvar custom-button-pressed nil
  1335. "Face used for pressed buttons in customization buffers.")
  1336. (defcustom custom-search-field t
  1337. "If non-nil, show a search field in Custom buffers."
  1338. :type 'boolean
  1339. :version "24.1"
  1340. :group 'custom-buffer)
  1341. (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box)
  1342. '(("unspecified" . unspecified))))
  1343. "If non-nil, indicate active buttons in a `raised-button' style.
  1344. Otherwise use brackets."
  1345. :type 'boolean
  1346. :version "21.1"
  1347. :group 'custom-buffer
  1348. :set (lambda (variable value)
  1349. (custom-set-default variable value)
  1350. (setq custom-button
  1351. (if value 'custom-button 'custom-button-unraised))
  1352. (setq custom-button-mouse
  1353. (if value 'custom-button-mouse 'highlight))
  1354. (setq custom-button-pressed
  1355. (if value
  1356. 'custom-button-pressed
  1357. 'custom-button-pressed-unraised))))
  1358. (defun custom-buffer-create-internal (options &optional _description)
  1359. (Custom-mode)
  1360. (let ((init-file (or custom-file user-init-file)))
  1361. ;; Insert verbose help at the top of the custom buffer.
  1362. (when custom-buffer-verbose-help
  1363. (widget-insert (if init-file
  1364. "To apply changes, use the Save or Set buttons."
  1365. "Custom settings cannot be saved; maybe you started Emacs with `-q'.")
  1366. "\nFor details, see ")
  1367. (widget-create 'custom-manual
  1368. :tag "Saving Customizations"
  1369. "(emacs)Saving Customizations")
  1370. (widget-insert " in the ")
  1371. (widget-create 'custom-manual
  1372. :tag "Emacs manual"
  1373. :help-echo "Read the Emacs manual."
  1374. "(emacs)Top")
  1375. (widget-insert "."))
  1376. (widget-insert "\n")
  1377. ;; Insert the search field.
  1378. (when custom-search-field
  1379. (widget-insert "\n")
  1380. (let* ((echo "Search for custom items.
  1381. You can enter one or more words separated by spaces,
  1382. or a regular expression.")
  1383. (search-widget
  1384. (widget-create
  1385. 'editable-field
  1386. :size 40 :help-echo echo
  1387. :action `(lambda (widget &optional event)
  1388. (customize-apropos (split-string (widget-value widget)))))))
  1389. (widget-insert " ")
  1390. (widget-create-child-and-convert
  1391. search-widget 'push-button
  1392. :tag " Search "
  1393. :help-echo echo :action
  1394. (lambda (widget &optional _event)
  1395. (customize-apropos (split-string (widget-value (widget-get widget :parent))))))
  1396. (widget-insert "\n")))
  1397. ;; The custom command buttons are also in the toolbar, so for a
  1398. ;; time they were not inserted in the buffer if the toolbar was in use.
  1399. ;; But it can be a little confusing for the buffer layout to
  1400. ;; change according to whether or nor the toolbar is on, not to
  1401. ;; mention that a custom buffer can in theory be created in a
  1402. ;; frame with a toolbar, then later viewed in one without.
  1403. ;; So now the buttons are always inserted in the buffer. (Bug#1326)
  1404. (if custom-buffer-verbose-help
  1405. (widget-insert "
  1406. Operate on all settings in this buffer:\n"))
  1407. (let ((button (lambda (tag action active help _icon _label)
  1408. (widget-insert " ")
  1409. (if (eval active)
  1410. (widget-create 'push-button :tag tag
  1411. :help-echo help :action action))))
  1412. (commands custom-commands))
  1413. (apply button (pop commands)) ; Set for current session
  1414. (apply button (pop commands)) ; Save for future sessions
  1415. (if custom-reset-button-menu
  1416. (progn
  1417. (widget-insert " ")
  1418. (widget-create 'push-button
  1419. :tag "Reset buffer"
  1420. :help-echo "Show a menu with reset operations."
  1421. :mouse-down-action 'ignore
  1422. :action 'custom-reset))
  1423. (widget-insert "\n")
  1424. (apply button (pop commands)) ; Undo edits
  1425. (apply button (pop commands)) ; Reset to saved
  1426. (apply button (pop commands)) ; Erase customization
  1427. (widget-insert " ")
  1428. (pop commands) ; Help (omitted)
  1429. (apply button (pop commands)))) ; Exit
  1430. (widget-insert "\n\n"))
  1431. ;; Now populate the custom buffer.
  1432. (message "Creating customization items...")
  1433. (buffer-disable-undo)
  1434. (setq custom-options
  1435. (if (= (length options) 1)
  1436. (mapcar (lambda (entry)
  1437. (widget-create (nth 1 entry)
  1438. :documentation-shown t
  1439. :custom-state 'unknown
  1440. :tag (custom-unlispify-tag-name
  1441. (nth 0 entry))
  1442. :value (nth 0 entry)))
  1443. options)
  1444. (let ((count 0)
  1445. (length (length options)))
  1446. (mapcar (lambda (entry)
  1447. (prog2
  1448. (message "Creating customization items ...%2d%%"
  1449. (/ (* 100.0 count) length))
  1450. (widget-create (nth 1 entry)
  1451. :tag (custom-unlispify-tag-name
  1452. (nth 0 entry))
  1453. :value (nth 0 entry))
  1454. (setq count (1+ count))
  1455. (unless (eq (preceding-char) ?\n)
  1456. (widget-insert "\n"))
  1457. (widget-insert "\n")))
  1458. options))))
  1459. (unless (eq (preceding-char) ?\n)
  1460. (widget-insert "\n"))
  1461. (message "Creating customization items ...done")
  1462. (message "Resetting customization items...")
  1463. (unless (eq custom-buffer-style 'tree)
  1464. (mapc 'custom-magic-reset custom-options))
  1465. (message "Resetting customization items...done")
  1466. (message "Creating customization setup...")
  1467. (widget-setup)
  1468. (buffer-enable-undo)
  1469. (goto-char (point-min))
  1470. (message "Creating customization setup...done"))
  1471. ;;; The Tree Browser.
  1472. ;;;###autoload
  1473. (defun customize-browse (&optional group)
  1474. "Create a tree browser for the customize hierarchy."
  1475. (interactive)
  1476. (unless group
  1477. (setq group 'emacs))
  1478. (let ((name "*Customize Browser*"))
  1479. (pop-to-buffer-same-window (custom-get-fresh-buffer name)))
  1480. (Custom-mode)
  1481. (widget-insert (format "\
  1482. %s buttons; type RET or click mouse-1
  1483. on a button to invoke its action.
  1484. Invoke [+] to expand a group, and [-] to collapse an expanded group.\n"
  1485. (if custom-raised-buttons
  1486. "`Raised' text indicates"
  1487. "Square brackets indicate")))
  1488. (if custom-browse-only-groups
  1489. (widget-insert "\
  1490. Invoke the [Group] button below to edit that item in another window.\n\n")
  1491. (widget-insert "Invoke the ")
  1492. (widget-create 'item
  1493. :format "%t"
  1494. :tag "[Group]"
  1495. :tag-glyph "folder")
  1496. (widget-insert ", ")
  1497. (widget-create 'item
  1498. :format "%t"
  1499. :tag "[Face]"
  1500. :tag-glyph "face")
  1501. (widget-insert ", and ")
  1502. (widget-create 'item
  1503. :format "%t"
  1504. :tag "[Option]"
  1505. :tag-glyph "option")
  1506. (widget-insert " buttons below to edit that
  1507. item in another window.\n\n"))
  1508. (let ((custom-buffer-style 'tree))
  1509. (widget-create 'custom-group
  1510. :custom-last t
  1511. :custom-state 'unknown
  1512. :tag (custom-unlispify-tag-name group)
  1513. :value group))
  1514. (widget-setup)
  1515. (goto-char (point-min)))
  1516. (define-widget 'custom-browse-visibility 'item
  1517. "Control visibility of items in the customize tree browser."
  1518. :format "%[[%t]%]"
  1519. :action 'custom-browse-visibility-action)
  1520. (defun custom-browse-visibility-action (widget &rest _ignore)
  1521. (let ((custom-buffer-style 'tree))
  1522. (custom-toggle-parent widget)))
  1523. (define-widget 'custom-browse-group-tag 'custom-group-link
  1524. "Show parent in other window when activated."
  1525. :tag "Group"
  1526. :tag-glyph "folder"
  1527. :action 'custom-browse-group-tag-action)
  1528. (defun custom-browse-group-tag-action (widget &rest _ignore)
  1529. (let ((parent (widget-get widget :parent)))
  1530. (customize-group-other-window (widget-value parent))))
  1531. (define-widget 'custom-browse-variable-tag 'custom-group-link
  1532. "Show parent in other window when activated."
  1533. :tag "Option"
  1534. :tag-glyph "option"
  1535. :action 'custom-browse-variable-tag-action)
  1536. (defun custom-browse-variable-tag-action (widget &rest _ignore)
  1537. (let ((parent (widget-get widget :parent)))
  1538. (customize-variable-other-window (widget-value parent))))
  1539. (define-widget 'custom-browse-face-tag 'custom-group-link
  1540. "Show parent in other window when activated."
  1541. :tag "Face"
  1542. :tag-glyph "face"
  1543. :action 'custom-browse-face-tag-action)
  1544. (defun custom-browse-face-tag-action (widget &rest _ignore)
  1545. (let ((parent (widget-get widget :parent)))
  1546. (customize-face-other-window (widget-value parent))))
  1547. (defconst custom-browse-alist '((" " "space")
  1548. (" | " "vertical")
  1549. ("-\\ " "top")
  1550. (" |-" "middle")
  1551. (" `-" "bottom")))
  1552. (defun custom-browse-insert-prefix (prefix)
  1553. "Insert PREFIX. On XEmacs convert it to line graphics."
  1554. ;; Fixme: do graphics.
  1555. (if nil ; (featurep 'xemacs)
  1556. (progn
  1557. (insert "*")
  1558. (while (not (string-equal prefix ""))
  1559. (let ((entry (substring prefix 0 3)))
  1560. (setq prefix (substring prefix 3))
  1561. (let ((overlay (make-overlay (1- (point)) (point) nil t nil))
  1562. (name (nth 1 (assoc entry custom-browse-alist))))
  1563. (overlay-put overlay 'end-glyph (widget-glyph-find name entry))
  1564. (overlay-put overlay 'start-open t)
  1565. (overlay-put overlay 'end-open t)))))
  1566. (insert prefix)))
  1567. ;;; Modification of Basic Widgets.
  1568. ;;
  1569. ;; We add extra properties to the basic widgets needed here. This is
  1570. ;; fine, as long as we are careful to stay within our own namespace.
  1571. ;;
  1572. ;; We want simple widgets to be displayed by default, but complex
  1573. ;; widgets to be hidden.
  1574. ;; This widget type is obsolete as of Emacs 24.1.
  1575. (widget-put (get 'item 'widget-type) :custom-show t)
  1576. (widget-put (get 'editable-field 'widget-type)
  1577. :custom-show (lambda (_widget value)
  1578. (let ((pp (pp-to-string value)))
  1579. (cond ((string-match "\n" pp)
  1580. nil)
  1581. ((> (length pp) 40)
  1582. nil)
  1583. (t t)))))
  1584. (widget-put (get 'menu-choice 'widget-type) :custom-show t)
  1585. ;;; The `custom-manual' Widget.
  1586. (define-widget 'custom-manual 'info-link
  1587. "Link to the manual entry for this customization option."
  1588. :help-echo "Read the manual entry for this option."
  1589. :keymap custom-mode-link-map
  1590. :follow-link 'mouse-face
  1591. :button-face 'custom-link
  1592. :mouse-face 'highlight
  1593. :pressed-face 'highlight
  1594. :tag "Manual")
  1595. ;;; The `custom-magic' Widget.
  1596. (defgroup custom-magic-faces nil
  1597. "Faces used by the magic button."
  1598. :group 'custom-faces
  1599. :group 'custom-buffer)
  1600. (defface custom-invalid '((((class color))
  1601. (:foreground "yellow1" :background "red1"))
  1602. (t
  1603. (:weight bold :slant italic :underline t)))
  1604. "Face used when the customize item is invalid."
  1605. :group 'custom-magic-faces)
  1606. (define-obsolete-face-alias 'custom-invalid-face 'custom-invalid "22.1")
  1607. (defface custom-rogue '((((class color))
  1608. (:foreground "pink" :background "black"))
  1609. (t
  1610. (:underline t)))
  1611. "Face used when the customize item is not defined for customization."
  1612. :group 'custom-magic-faces)
  1613. (define-obsolete-face-alias 'custom-rogue-face 'custom-rogue "22.1")
  1614. (defface custom-modified '((((min-colors 88) (class color))
  1615. (:foreground "white" :background "blue1"))
  1616. (((class color))
  1617. (:foreground "white" :background "blue"))
  1618. (t
  1619. (:slant italic :bold)))
  1620. "Face used when the customize item has been modified."
  1621. :group 'custom-magic-faces)
  1622. (define-obsolete-face-alias 'custom-modified-face 'custom-modified "22.1")
  1623. (defface custom-set '((((min-colors 88) (class color))
  1624. (:foreground "blue1" :background "white"))
  1625. (((class color))
  1626. (:foreground "blue" :background "white"))
  1627. (t
  1628. (:slant italic)))
  1629. "Face used when the customize item has been set."
  1630. :group 'custom-magic-faces)
  1631. (define-obsolete-face-alias 'custom-set-face 'custom-set "22.1")
  1632. (defface custom-changed '((((min-colors 88) (class color))
  1633. (:foreground "white" :background "blue1"))
  1634. (((class color))
  1635. (:foreground "white" :background "blue"))
  1636. (t
  1637. (:slant italic)))
  1638. "Face used when the customize item has been changed."
  1639. :group 'custom-magic-faces)
  1640. (define-obsolete-face-alias 'custom-changed-face 'custom-changed "22.1")
  1641. (defface custom-themed '((((min-colors 88) (class color))
  1642. (:foreground "white" :background "blue1"))
  1643. (((class color))
  1644. (:foreground "white" :background "blue"))
  1645. (t
  1646. (:slant italic)))
  1647. "Face used when the customize item has been set by a theme."
  1648. :group 'custom-magic-faces)
  1649. (defface custom-saved '((t (:underline t)))
  1650. "Face used when the customize item has been saved."
  1651. :group 'custom-magic-faces)
  1652. (define-obsolete-face-alias 'custom-saved-face 'custom-saved "22.1")
  1653. (defconst custom-magic-alist
  1654. '((nil "#" underline "\
  1655. UNINITIALIZED, you should not see this.")
  1656. (unknown "?" italic "\
  1657. UNKNOWN, you should not see this.")
  1658. (hidden "-" default "\
  1659. HIDDEN, invoke \"Show\" in the previous line to show." "\
  1660. group now hidden, invoke \"Show\", above, to show contents.")
  1661. (invalid "x" custom-invalid "\
  1662. INVALID, the displayed value cannot be set.")
  1663. (modified "*" custom-modified "\
  1664. EDITED, shown value does not take effect until you set or save it." "\
  1665. something in this group has been edited but not set.")
  1666. (set "+" custom-set "\
  1667. SET for current session only." "\
  1668. something in this group has been set but not saved.")
  1669. (changed ":" custom-changed "\
  1670. CHANGED outside Customize." "\
  1671. something in this group has been changed outside customize.")
  1672. (saved "!" custom-saved "\
  1673. SAVED and set." "\
  1674. something in this group has been set and saved.")
  1675. (themed "o" custom-themed "\
  1676. THEMED." "\
  1677. visible group members are all at standard values.")
  1678. (rogue "@" custom-rogue "\
  1679. NO CUSTOMIZATION DATA; not intended to be customized." "\
  1680. something in this group is not prepared for customization.")
  1681. (standard " " nil "\
  1682. STANDARD." "\
  1683. visible group members are all at standard values."))
  1684. "Alist of customize option states.
  1685. Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where
  1686. STATE is one of the following symbols:
  1687. `nil'
  1688. For internal use, should never occur.
  1689. `unknown'
  1690. For internal use, should never occur.
  1691. `hidden'
  1692. This item is not being displayed.
  1693. `invalid'
  1694. This item is modified, but has an invalid form.
  1695. `modified'
  1696. This item is modified, and has a valid form.
  1697. `set'
  1698. This item has been set but not saved.
  1699. `changed'
  1700. The current value of this item has been changed outside Customize.
  1701. `saved'
  1702. This item is marked for saving.
  1703. `rogue'
  1704. This item has no customization information.
  1705. `standard'
  1706. This item is unchanged from the standard setting.
  1707. MAGIC is a string used to present that state.
  1708. FACE is a face used to present the state.
  1709. ITEM-DESC is a string describing the state for options.
  1710. GROUP-DESC is a string describing the state for groups. If this is
  1711. left out, ITEM-DESC will be used.
  1712. The string %c in either description will be replaced with the
  1713. category of the item. These are `group'. `option', and `face'.
  1714. The list should be sorted most significant first.")
  1715. (defcustom custom-magic-show 'long
  1716. "If non-nil, show textual description of the state.
  1717. If `long', show a full-line description, not just one word."
  1718. :type '(choice (const :tag "no" nil)
  1719. (const long)
  1720. (other :tag "short" short))
  1721. :group 'custom-buffer)
  1722. (defcustom custom-magic-show-hidden '(option face)
  1723. "Control whether the State button is shown for hidden items.
  1724. The value should be a list with the custom categories where the State
  1725. button should be visible. Possible categories are `group', `option',
  1726. and `face'."
  1727. :type '(set (const group) (const option) (const face))
  1728. :group 'custom-buffer)
  1729. (defcustom custom-magic-show-button nil
  1730. "Show a \"magic\" button indicating the state of each customization option."
  1731. :type 'boolean
  1732. :group 'custom-buffer)
  1733. (define-widget 'custom-magic 'default
  1734. "Show and manipulate state for a customization option."
  1735. :format "%v"
  1736. :action 'widget-parent-action
  1737. :notify 'ignore
  1738. :value-get 'ignore
  1739. :value-create 'custom-magic-value-create
  1740. :value-delete 'widget-children-value-delete)
  1741. (defun widget-magic-mouse-down-action (widget &optional _event)
  1742. ;; Non-nil unless hidden.
  1743. (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
  1744. :custom-state)
  1745. 'hidden)))
  1746. (defun custom-magic-value-create (widget)
  1747. "Create compact status report for WIDGET."
  1748. (let* ((parent (widget-get widget :parent))
  1749. (state (widget-get parent :custom-state))
  1750. (hidden (eq state 'hidden))
  1751. (entry (assq state custom-magic-alist))
  1752. (magic (nth 1 entry))
  1753. (face (nth 2 entry))
  1754. (category (widget-get parent :custom-category))
  1755. (text (or (and (eq category 'group)
  1756. (nth 4 entry))
  1757. (nth 3 entry)))
  1758. (form (widget-get parent :custom-form))
  1759. children)
  1760. (unless (eq state 'hidden)
  1761. (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text)
  1762. (setq text (concat (match-string 1 text)
  1763. (symbol-name category)
  1764. (match-string 2 text))))
  1765. (when (and custom-magic-show
  1766. (or (not hidden)
  1767. (memq category custom-magic-show-hidden)))
  1768. (insert " ")
  1769. (when (and (eq category 'group)
  1770. (not (and (eq custom-buffer-style 'links)
  1771. (> (widget-get parent :custom-level) 1))))
  1772. (insert-char ?\ (* custom-buffer-indent
  1773. (widget-get parent :custom-level))))
  1774. (push (widget-create-child-and-convert
  1775. widget 'choice-item
  1776. :help-echo "Change the state of this item."
  1777. :format (if hidden "%t" "%[%t%]")
  1778. :button-prefix 'widget-push-button-prefix
  1779. :button-suffix 'widget-push-button-suffix
  1780. :mouse-down-action 'widget-magic-mouse-down-action
  1781. :tag " State ")
  1782. children)
  1783. (insert ": ")
  1784. (let ((start (point)))
  1785. (if (eq custom-magic-show 'long)
  1786. (insert text)
  1787. (insert (symbol-name state)))
  1788. (cond ((eq form 'lisp)
  1789. (insert " (lisp)"))
  1790. ((eq form 'mismatch)
  1791. (insert " (mismatch)")))
  1792. (put-text-property start (point) 'face 'custom-state))
  1793. (insert "\n"))
  1794. (when (and (eq category 'group)
  1795. (not (and (eq custom-buffer-style 'links)
  1796. (> (widget-get parent :custom-level) 1))))
  1797. (insert-char ?\ (* custom-buffer-indent
  1798. (widget-get parent :custom-level))))
  1799. (when custom-magic-show-button
  1800. (when custom-magic-show
  1801. (let ((indent (widget-get parent :indent)))
  1802. (when indent
  1803. (insert-char ? indent))))
  1804. (push (widget-create-child-and-convert
  1805. widget 'choice-item
  1806. :mouse-down-action 'widget-magic-mouse-down-action
  1807. :button-face face
  1808. :button-prefix ""
  1809. :button-suffix ""
  1810. :help-echo "Change the state."
  1811. :format (if hidden "%t" "%[%t%]")
  1812. :tag (if (memq form '(lisp mismatch))
  1813. (concat "(" magic ")")
  1814. (concat "[" magic "]")))
  1815. children)
  1816. (insert " "))
  1817. (widget-put widget :children children))))
  1818. (defun custom-magic-reset (widget)
  1819. "Redraw the :custom-magic property of WIDGET."
  1820. (let ((magic (widget-get widget :custom-magic)))
  1821. (when magic
  1822. (widget-value-set magic (widget-value magic)))))
  1823. ;;; The `custom' Widget.
  1824. (defface custom-button
  1825. '((((type x w32 ns) (class color)) ; Like default modeline
  1826. (:box (:line-width 2 :style released-button)
  1827. :background "lightgrey" :foreground "black"))
  1828. (t
  1829. nil))
  1830. "Face for custom buffer buttons if `custom-raised-buttons' is non-nil."
  1831. :version "21.1"
  1832. :group 'custom-faces)
  1833. (define-obsolete-face-alias 'custom-button-face 'custom-button "22.1")
  1834. (defface custom-button-mouse
  1835. '((((type x w32 ns) (class color))
  1836. (:box (:line-width 2 :style released-button)
  1837. :background "grey90" :foreground "black"))
  1838. (t
  1839. ;; This is for text terminals that support mouse, like GPM mouse
  1840. ;; or the MS-DOS terminal: inverse-video makes the button stand
  1841. ;; out on mouse-over.
  1842. (:inverse-video t)))
  1843. "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil."
  1844. :version "22.1"
  1845. :group 'custom-faces)
  1846. (defface custom-button-unraised
  1847. '((t :inherit underline))
  1848. "Face for custom buffer buttons if `custom-raised-buttons' is nil."
  1849. :version "22.1"
  1850. :group 'custom-faces)
  1851. (setq custom-button
  1852. (if custom-raised-buttons 'custom-button 'custom-button-unraised))
  1853. (setq custom-button-mouse
  1854. (if custom-raised-buttons 'custom-button-mouse 'highlight))
  1855. (defface custom-button-pressed
  1856. '((((type x w32 ns) (class color))
  1857. (:box (:line-width 2 :style pressed-button)
  1858. :background "lightgrey" :foreground "black"))
  1859. (t
  1860. (:inverse-video t)))
  1861. "Face for pressed custom buttons if `custom-raised-buttons' is non-nil."
  1862. :version "21.1"
  1863. :group 'custom-faces)
  1864. (define-obsolete-face-alias 'custom-button-pressed-face
  1865. 'custom-button-pressed "22.1")
  1866. (defface custom-button-pressed-unraised
  1867. '((default :inherit custom-button-unraised)
  1868. (((class color) (background light)) :foreground "magenta4")
  1869. (((class color) (background dark)) :foreground "violet"))
  1870. "Face for pressed custom buttons if `custom-raised-buttons' is nil."
  1871. :version "22.1"
  1872. :group 'custom-faces)
  1873. (setq custom-button-pressed
  1874. (if custom-raised-buttons
  1875. 'custom-button-pressed
  1876. 'custom-button-pressed-unraised))
  1877. (defface custom-documentation '((t nil))
  1878. "Face used for documentation strings in customization buffers."
  1879. :group 'custom-faces)
  1880. (define-obsolete-face-alias 'custom-documentation-face
  1881. 'custom-documentation "22.1")
  1882. (defface custom-state '((((class color)
  1883. (background dark))
  1884. (:foreground "lime green"))
  1885. (((class color)
  1886. (background light))
  1887. (:foreground "dark green"))
  1888. (t nil))
  1889. "Face used for State descriptions in the customize buffer."
  1890. :group 'custom-faces)
  1891. (define-obsolete-face-alias 'custom-state-face 'custom-state "22.1")
  1892. (defface custom-link
  1893. '((t :inherit link))
  1894. "Face for links in customization buffers."
  1895. :version "22.1"
  1896. :group 'custom-faces)
  1897. (define-widget 'custom 'default
  1898. "Customize a user option."
  1899. :format "%v"
  1900. :convert-widget 'custom-convert-widget
  1901. :notify 'custom-notify
  1902. :custom-prefix ""
  1903. :custom-level 1
  1904. :custom-state 'hidden
  1905. :documentation-property 'widget-subclass-responsibility
  1906. :value-create 'widget-subclass-responsibility
  1907. :value-delete 'widget-children-value-delete
  1908. :value-get 'widget-value-value-get
  1909. :validate 'widget-children-validate
  1910. :match (lambda (_widget value) (symbolp value)))
  1911. (defun custom-convert-widget (widget)
  1912. "Initialize :value and :tag from :args in WIDGET."
  1913. (let ((args (widget-get widget :args)))
  1914. (when args
  1915. (widget-put widget :value (widget-apply widget
  1916. :value-to-internal (car args)))
  1917. (widget-put widget :tag (custom-unlispify-tag-name (car args)))
  1918. (widget-put widget :args nil)))
  1919. widget)
  1920. (defun custom-notify (widget &rest args)
  1921. "Keep track of changes."
  1922. (let ((state (widget-get widget :custom-state)))
  1923. (unless (eq state 'modified)
  1924. (unless (memq state '(nil unknown hidden))
  1925. (widget-put widget :custom-state 'modified))
  1926. (custom-magic-reset widget)
  1927. (apply 'widget-default-notify widget args))))
  1928. (defun custom-redraw (widget)
  1929. "Redraw WIDGET with current settings."
  1930. (let ((line (count-lines (point-min) (point)))
  1931. (column (current-column))
  1932. (pos (point))
  1933. (from (marker-position (widget-get widget :from)))
  1934. (to (marker-position (widget-get widget :to))))
  1935. (save-excursion
  1936. (widget-value-set widget (widget-value widget))
  1937. (custom-redraw-magic widget))
  1938. (when (and (>= pos from) (<= pos to))
  1939. (condition-case nil
  1940. (progn
  1941. (goto-char (point-min))
  1942. (forward-line (if (> column 0)
  1943. (1- line)
  1944. line))
  1945. (move-to-column column))
  1946. (error nil)))))
  1947. (defun custom-redraw-magic (widget)
  1948. "Redraw WIDGET state with current settings."
  1949. (while widget
  1950. (let ((magic (widget-get widget :custom-magic)))
  1951. (cond (magic
  1952. (widget-value-set magic (widget-value magic))
  1953. (when (setq widget (widget-get widget :group))
  1954. (custom-group-state-update widget)))
  1955. (t
  1956. (setq widget nil)))))
  1957. (widget-setup))
  1958. (make-obsolete 'custom-show "this widget type is no longer supported." "24.1")
  1959. (defun custom-show (widget value)
  1960. "Non-nil if WIDGET should be shown with VALUE by default."
  1961. (let ((show (widget-get widget :custom-show)))
  1962. (if (functionp show)
  1963. (funcall show widget value)
  1964. show)))
  1965. (defun custom-load-widget (widget)
  1966. "Load all dependencies for WIDGET."
  1967. (custom-load-symbol (widget-value widget)))
  1968. (defun custom-unloaded-symbol-p (symbol)
  1969. "Return non-nil if the dependencies of SYMBOL have not yet been loaded."
  1970. (let ((found nil)
  1971. (loads (get symbol 'custom-loads))
  1972. load)
  1973. (while loads
  1974. (setq load (car loads)
  1975. loads (cdr loads))
  1976. (cond ((symbolp load)
  1977. (unless (featurep load)
  1978. (setq found t)))
  1979. ((assoc load load-history))
  1980. ((assoc (locate-library load) load-history)
  1981. (message nil))
  1982. (t
  1983. (setq found t))))
  1984. found))
  1985. (defun custom-unloaded-widget-p (widget)
  1986. "Return non-nil if the dependencies of WIDGET have not yet been loaded."
  1987. (custom-unloaded-symbol-p (widget-value widget)))
  1988. (defun custom-toggle-hide (widget)
  1989. "Toggle visibility of WIDGET."
  1990. (custom-load-widget widget)
  1991. (let ((state (widget-get widget :custom-state)))
  1992. (cond ((memq state '(invalid modified set))
  1993. (error "There are unsaved changes"))
  1994. ((eq state 'hidden)
  1995. (widget-put widget :custom-state 'unknown))
  1996. (t
  1997. (widget-put widget :documentation-shown nil)
  1998. (widget-put widget :custom-state 'hidden)))
  1999. (custom-redraw widget)
  2000. (widget-setup)))
  2001. (defun custom-toggle-parent (widget &rest _ignore)
  2002. "Toggle visibility of parent of WIDGET."
  2003. (custom-toggle-hide (widget-get widget :parent)))
  2004. (defun custom-add-see-also (widget &optional prefix)
  2005. "Add `See also ...' to WIDGET if there are any links.
  2006. Insert PREFIX first if non-nil."
  2007. (let* ((symbol (widget-get widget :value))
  2008. (links (get symbol 'custom-links))
  2009. (many (> (length links) 2))
  2010. (buttons (widget-get widget :buttons))
  2011. (indent (widget-get widget :indent)))
  2012. (when links
  2013. (when indent
  2014. (insert-char ?\ indent))
  2015. (when prefix
  2016. (insert prefix))
  2017. (insert "See also ")
  2018. (while links
  2019. (push (widget-create-child-and-convert
  2020. widget (car links)
  2021. :button-face 'custom-link
  2022. :mouse-face 'highlight
  2023. :pressed-face 'highlight)
  2024. buttons)
  2025. (setq links (cdr links))
  2026. (cond ((null links)
  2027. (insert ".\n"))
  2028. ((null (cdr links))
  2029. (if many
  2030. (insert ", and ")
  2031. (insert " and ")))
  2032. (t
  2033. (insert ", "))))
  2034. (widget-put widget :buttons buttons))))
  2035. (defun custom-add-parent-links (widget &optional initial-string _doc-initial-string)
  2036. "Add \"Parent groups: ...\" to WIDGET if the group has parents.
  2037. The value is non-nil if any parents were found.
  2038. If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"."
  2039. (let ((name (widget-value widget))
  2040. (type (widget-type widget))
  2041. (buttons (widget-get widget :buttons))
  2042. (start (point))
  2043. (parents nil))
  2044. (insert (or initial-string "Groups:"))
  2045. (mapatoms (lambda (symbol)
  2046. (when (member (list name type) (get symbol 'custom-group))
  2047. (insert " ")
  2048. (push (widget-create-child-and-convert
  2049. widget 'custom-group-link
  2050. :tag (custom-unlispify-tag-name symbol)
  2051. symbol)
  2052. buttons)
  2053. (setq parents (cons symbol parents)))))
  2054. (if parents
  2055. (insert "\n")
  2056. (delete-region start (point)))
  2057. (widget-put widget :buttons buttons)
  2058. parents))
  2059. ;;; The `custom-comment' Widget.
  2060. ;; like the editable field
  2061. (defface custom-comment '((((type tty))
  2062. :background "yellow3"
  2063. :foreground "black")
  2064. (((class grayscale color)
  2065. (background light))
  2066. :background "gray85")
  2067. (((class grayscale color)
  2068. (background dark))
  2069. :background "dim gray")
  2070. (t
  2071. :slant italic))
  2072. "Face used for comments on variables or faces."
  2073. :version "21.1"
  2074. :group 'custom-faces)
  2075. (define-obsolete-face-alias 'custom-comment-face 'custom-comment "22.1")
  2076. ;; like font-lock-comment-face
  2077. (defface custom-comment-tag
  2078. '((((class color) (background dark)) (:foreground "gray80"))
  2079. (((class color) (background light)) (:foreground "blue4"))
  2080. (((class grayscale) (background light))
  2081. (:foreground "DimGray" :weight bold :slant italic))
  2082. (((class grayscale) (background dark))
  2083. (:foreground "LightGray" :weight bold :slant italic))
  2084. (t (:weight bold)))
  2085. "Face used for the comment tag on variables or faces."
  2086. :group 'custom-faces)
  2087. (define-obsolete-face-alias 'custom-comment-tag-face 'custom-comment-tag "22.1")
  2088. (define-widget 'custom-comment 'string
  2089. "User comment."
  2090. :tag "Comment"
  2091. :help-echo "Edit a comment here."
  2092. :sample-face 'custom-comment-tag
  2093. :value-face 'custom-comment
  2094. :shown nil
  2095. :create 'custom-comment-create)
  2096. (defun custom-comment-create (widget)
  2097. (let* ((null-comment (equal "" (widget-value widget))))
  2098. (if (or (widget-get (widget-get widget :parent) :comment-shown)
  2099. (not null-comment))
  2100. (widget-default-create widget)
  2101. ;; `widget-default-delete' expects markers in these slots --
  2102. ;; maybe it shouldn't.
  2103. (widget-put widget :from (point-marker))
  2104. (widget-put widget :to (point-marker)))))
  2105. (defun custom-comment-hide (widget)
  2106. (widget-put (widget-get widget :parent) :comment-shown nil))
  2107. ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
  2108. ;; the global custom one
  2109. (defun custom-comment-show (widget)
  2110. (widget-put widget :comment-shown t)
  2111. (custom-redraw widget)
  2112. (widget-setup))
  2113. (defun custom-comment-invisible-p (widget)
  2114. (let ((val (widget-value (widget-get widget :comment-widget))))
  2115. (and (equal "" val)
  2116. (not (widget-get widget :comment-shown)))))
  2117. ;;; The `custom-variable' Widget.
  2118. (defface custom-variable-tag
  2119. `((((class color)
  2120. (background dark))
  2121. (:foreground "light blue" :weight bold))
  2122. (((min-colors 88) (class color)
  2123. (background light))
  2124. (:foreground "blue1" :weight bold))
  2125. (((class color)
  2126. (background light))
  2127. (:foreground "blue" :weight bold))
  2128. (t (:weight bold)))
  2129. "Face used for unpushable variable tags."
  2130. :group 'custom-faces)
  2131. (define-obsolete-face-alias 'custom-variable-tag-face
  2132. 'custom-variable-tag "22.1")
  2133. (defface custom-variable-button '((t (:underline t :weight bold)))
  2134. "Face used for pushable variable tags."
  2135. :group 'custom-faces)
  2136. (define-obsolete-face-alias 'custom-variable-button-face
  2137. 'custom-variable-button "22.1")
  2138. (defcustom custom-variable-default-form 'edit
  2139. "Default form of displaying variable values."
  2140. :type '(choice (const edit)
  2141. (const lisp))
  2142. :group 'custom-buffer
  2143. :version "20.3")
  2144. (defun custom-variable-documentation (variable)
  2145. "Return documentation of VARIABLE for use in Custom buffer.
  2146. Normally just return the docstring. But if VARIABLE automatically
  2147. becomes buffer local when set, append a message to that effect."
  2148. (if (and (local-variable-if-set-p variable)
  2149. (or (not (local-variable-p variable))
  2150. (with-temp-buffer
  2151. (local-variable-if-set-p variable))))
  2152. (concat (documentation-property variable 'variable-documentation)
  2153. "\n
  2154. This variable automatically becomes buffer-local when set outside Custom.
  2155. However, setting it through Custom sets the default value.")
  2156. (documentation-property variable 'variable-documentation)))
  2157. (define-widget 'custom-variable 'custom
  2158. "A widget for displaying a Custom variable.
  2159. The following properties have special meanings for this widget:
  2160. :hidden-states should be a list of widget states for which the
  2161. widget's initial contents are to be hidden.
  2162. :custom-form should be a symbol describing how to display and
  2163. edit the variable---either `edit' (using edit widgets),
  2164. `lisp' (as a Lisp sexp), or `mismatch' (should not happen);
  2165. if nil, use the return value of `custom-variable-default-form'.
  2166. :shown-value, if non-nil, should be a list whose `car' is the
  2167. variable value to display in place of the current value.
  2168. :custom-style describes the widget interface style; nil is the
  2169. default style, while `simple' means a simpler interface that
  2170. inhibits the magic custom-state widget."
  2171. :format "%v"
  2172. :help-echo "Set or reset this variable."
  2173. :documentation-property #'custom-variable-documentation
  2174. :custom-category 'option
  2175. :custom-state nil
  2176. :custom-menu 'custom-variable-menu-create
  2177. :custom-form nil
  2178. :value-create 'custom-variable-value-create
  2179. :action 'custom-variable-action
  2180. :hidden-states '(standard)
  2181. :custom-set 'custom-variable-set
  2182. :custom-mark-to-save 'custom-variable-mark-to-save
  2183. :custom-reset-current 'custom-redraw
  2184. :custom-reset-saved 'custom-variable-reset-saved
  2185. :custom-reset-standard 'custom-variable-reset-standard
  2186. :custom-mark-to-reset-standard 'custom-variable-mark-to-reset-standard
  2187. :custom-standard-value 'custom-variable-standard-value
  2188. :custom-state-set-and-redraw 'custom-variable-state-set-and-redraw)
  2189. (defun custom-variable-type (symbol)
  2190. "Return a widget suitable for editing the value of SYMBOL.
  2191. If SYMBOL has a `custom-type' property, use that.
  2192. Otherwise, try matching SYMBOL against `custom-guess-name-alist' and
  2193. try matching its doc string against `custom-guess-doc-alist'."
  2194. (let* ((type (or (get symbol 'custom-type)
  2195. (and (not (get symbol 'standard-value))
  2196. (custom-guess-type symbol))
  2197. 'sexp))
  2198. (options (get symbol 'custom-options))
  2199. (tmp (if (listp type)
  2200. (copy-sequence type)
  2201. (list type))))
  2202. (when options
  2203. (widget-put tmp :options options))
  2204. tmp))
  2205. (defun custom-variable-value-create (widget)
  2206. "Here is where you edit the variable's value."
  2207. (custom-load-widget widget)
  2208. (unless (widget-get widget :custom-form)
  2209. (widget-put widget :custom-form custom-variable-default-form))
  2210. (let* ((buttons (widget-get widget :buttons))
  2211. (children (widget-get widget :children))
  2212. (form (widget-get widget :custom-form))
  2213. (symbol (widget-get widget :value))
  2214. (tag (widget-get widget :tag))
  2215. (type (custom-variable-type symbol))
  2216. (conv (widget-convert type))
  2217. (get (or (get symbol 'custom-get) 'default-value))
  2218. (prefix (widget-get widget :custom-prefix))
  2219. (last (widget-get widget :custom-last))
  2220. (style (widget-get widget :custom-style))
  2221. (value (let ((shown-value (widget-get widget :shown-value)))
  2222. (cond (shown-value
  2223. (car shown-value))
  2224. ((default-boundp symbol)
  2225. (funcall get symbol))
  2226. (t (widget-get conv :value)))))
  2227. (state (or (widget-get widget :custom-state)
  2228. (if (memq (custom-variable-state symbol value)
  2229. (widget-get widget :hidden-states))
  2230. 'hidden))))
  2231. ;; If we don't know the state, see if we need to edit it in lisp form.
  2232. (unless state
  2233. (setq state (if (custom-show type value) 'unknown 'hidden)))
  2234. (when (eq state 'unknown)
  2235. (unless (widget-apply conv :match value)
  2236. (setq form 'mismatch)))
  2237. ;; Now we can create the child widget.
  2238. (cond ((eq custom-buffer-style 'tree)
  2239. (insert prefix (if last " `--- " " |--- "))
  2240. (push (widget-create-child-and-convert
  2241. widget 'custom-browse-variable-tag)
  2242. buttons)
  2243. (insert " " tag "\n")
  2244. (widget-put widget :buttons buttons))
  2245. ((eq state 'hidden)
  2246. ;; Indicate hidden value.
  2247. (push (widget-create-child-and-convert
  2248. widget 'custom-visibility
  2249. :help-echo "Show the value of this option."
  2250. :on-glyph "down"
  2251. :on "Hide"
  2252. :off-glyph "right"
  2253. :off "Show Value"
  2254. :action 'custom-toggle-hide-variable
  2255. nil)
  2256. buttons)
  2257. (insert " ")
  2258. (push (widget-create-child-and-convert
  2259. widget 'item
  2260. :format "%{%t%} "
  2261. :sample-face 'custom-variable-tag
  2262. :tag tag
  2263. :parent widget)
  2264. buttons))
  2265. ((memq form '(lisp mismatch))
  2266. (push (widget-create-child-and-convert
  2267. widget 'custom-visibility
  2268. :help-echo "Hide the value of this option."
  2269. :on "Hide"
  2270. :off "Show"
  2271. :on-glyph "down"
  2272. :off-glyph "right"
  2273. :action 'custom-toggle-hide-variable
  2274. t)
  2275. buttons)
  2276. (insert " ")
  2277. ;; This used to try presenting the saved value or the
  2278. ;; standard value, but it seems more intuitive to present
  2279. ;; the current value (Bug#7600).
  2280. (let* ((value (cond ((default-boundp symbol)
  2281. (custom-quote (funcall get symbol)))
  2282. (t
  2283. (custom-quote (widget-get conv :value))))))
  2284. (insert (symbol-name symbol) ": ")
  2285. (push (widget-create-child-and-convert
  2286. widget 'sexp
  2287. :button-face 'custom-variable-button-face
  2288. :format "%v"
  2289. :tag (symbol-name symbol)
  2290. :parent widget
  2291. :value value)
  2292. children)))
  2293. (t
  2294. ;; Edit mode.
  2295. (push (widget-create-child-and-convert
  2296. widget 'custom-visibility
  2297. :help-echo "Hide or show this option."
  2298. :on "Hide"
  2299. :off "Show"
  2300. :on-glyph "down"
  2301. :off-glyph "right"
  2302. :action 'custom-toggle-hide-variable
  2303. t)
  2304. buttons)
  2305. (insert " ")
  2306. (let* ((format (widget-get type :format))
  2307. tag-format value-format)
  2308. (unless (string-match ":" format)
  2309. (error "Bad format"))
  2310. (setq tag-format (substring format 0 (match-end 0)))
  2311. (setq value-format (substring format (match-end 0)))
  2312. (push (widget-create-child-and-convert
  2313. widget 'item
  2314. :format tag-format
  2315. :action 'custom-tag-action
  2316. :help-echo "Change value of this option."
  2317. :mouse-down-action 'custom-tag-mouse-down-action
  2318. :button-face 'custom-variable-button
  2319. :sample-face 'custom-variable-tag
  2320. tag)
  2321. buttons)
  2322. (push (widget-create-child-and-convert
  2323. widget type
  2324. :format value-format
  2325. :value value)
  2326. children))))
  2327. (unless (eq custom-buffer-style 'tree)
  2328. (unless (eq (preceding-char) ?\n)
  2329. (widget-insert "\n"))
  2330. ;; Create the magic button.
  2331. (unless (eq style 'simple)
  2332. (let ((magic (widget-create-child-and-convert
  2333. widget 'custom-magic nil)))
  2334. (widget-put widget :custom-magic magic)
  2335. (push magic buttons)))
  2336. (widget-put widget :buttons buttons)
  2337. ;; Insert documentation.
  2338. (widget-put widget :documentation-indent 3)
  2339. (unless (and (eq style 'simple)
  2340. (eq state 'hidden))
  2341. (widget-add-documentation-string-button
  2342. widget :visibility-widget 'custom-visibility))
  2343. ;; The comment field
  2344. (unless (eq state 'hidden)
  2345. (let* ((comment (get symbol 'variable-comment))
  2346. (comment-widget
  2347. (widget-create-child-and-convert
  2348. widget 'custom-comment
  2349. :parent widget
  2350. :value (or comment ""))))
  2351. (widget-put widget :comment-widget comment-widget)
  2352. ;; Don't push it !!! Custom assumes that the first child is the
  2353. ;; value one.
  2354. (setq children (append children (list comment-widget)))))
  2355. ;; Update the rest of the properties.
  2356. (widget-put widget :custom-form form)
  2357. (widget-put widget :children children)
  2358. ;; Now update the state.
  2359. (if (eq state 'hidden)
  2360. (widget-put widget :custom-state state)
  2361. (custom-variable-state-set widget))
  2362. ;; See also.
  2363. (unless (eq state 'hidden)
  2364. (when (eq (widget-get widget :custom-level) 1)
  2365. (custom-add-parent-links widget))
  2366. (custom-add-see-also widget)))))
  2367. (defun custom-toggle-hide-variable (visibility-widget &rest _ignore)
  2368. "Toggle the visibility of a `custom-variable' parent widget.
  2369. By default, this signals an error if the parent has unsaved
  2370. changes. If the parent has a `simple' :custom-style property,
  2371. the present value is saved to its :shown-value property instead."
  2372. (let ((widget (widget-get visibility-widget :parent)))
  2373. (unless (eq (widget-type widget) 'custom-variable)
  2374. (error "Invalid widget type"))
  2375. (custom-load-widget widget)
  2376. (let ((state (widget-get widget :custom-state)))
  2377. (if (eq state 'hidden)
  2378. (widget-put widget :custom-state 'unknown)
  2379. ;; In normal interface, widget can't be hidden if modified.
  2380. (when (memq state '(invalid modified set))
  2381. (if (eq (widget-get widget :custom-style) 'simple)
  2382. (widget-put widget :shown-value
  2383. (list (widget-value
  2384. (car-safe
  2385. (widget-get widget :children)))))
  2386. (error "There are unsaved changes")))
  2387. (widget-put widget :documentation-shown nil)
  2388. (widget-put widget :custom-state 'hidden))
  2389. (custom-redraw widget)
  2390. (widget-setup))))
  2391. (defun custom-tag-action (widget &rest args)
  2392. "Pass :action to first child of WIDGET's parent."
  2393. (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
  2394. :action args))
  2395. (defun custom-tag-mouse-down-action (widget &rest args)
  2396. "Pass :mouse-down-action to first child of WIDGET's parent."
  2397. (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
  2398. :mouse-down-action args))
  2399. (defun custom-variable-state (symbol val)
  2400. "Return the state of SYMBOL if its value is VAL.
  2401. If SYMBOL has a non-nil `custom-get' property, it overrides VAL.
  2402. Possible return values are `standard', `saved', `set', `themed',
  2403. `changed', and `rogue'."
  2404. (let* ((get (or (get symbol 'custom-get) 'default-value))
  2405. (value (if (default-boundp symbol)
  2406. (funcall get symbol)
  2407. val))
  2408. (comment (get symbol 'variable-comment))
  2409. tmp
  2410. temp)
  2411. (cond ((progn (setq tmp (get symbol 'customized-value))
  2412. (setq temp
  2413. (get symbol 'customized-variable-comment))
  2414. (or tmp temp))
  2415. (if (condition-case nil
  2416. (and (equal value (eval (car tmp)))
  2417. (equal comment temp))
  2418. (error nil))
  2419. 'set
  2420. 'changed))
  2421. ((progn (setq tmp (get symbol 'theme-value))
  2422. (setq temp (get symbol 'saved-variable-comment))
  2423. (or tmp temp))
  2424. (if (condition-case nil
  2425. (and (equal comment temp)
  2426. (equal value
  2427. (eval
  2428. (car (custom-variable-theme-value
  2429. symbol)))))
  2430. (error nil))
  2431. (cond
  2432. ((eq (caar tmp) 'user) 'saved)
  2433. ((eq (caar tmp) 'changed)
  2434. (if (condition-case nil
  2435. (and (null comment)
  2436. (equal value
  2437. (eval
  2438. (car (get symbol 'standard-value)))))
  2439. (error nil))
  2440. ;; The value was originally set outside
  2441. ;; custom, but it was set to the standard
  2442. ;; value (probably an autoloaded defcustom).
  2443. 'standard
  2444. 'changed))
  2445. (t 'themed))
  2446. 'changed))
  2447. ((setq tmp (get symbol 'standard-value))
  2448. (if (condition-case nil
  2449. (and (equal value (eval (car tmp)))
  2450. (equal comment nil))
  2451. (error nil))
  2452. 'standard
  2453. 'changed))
  2454. (t 'rogue))))
  2455. (defun custom-variable-state-set (widget &optional state)
  2456. "Set the state of WIDGET to STATE.
  2457. If STATE is nil, the value is computed by `custom-variable-state'."
  2458. (widget-put widget :custom-state
  2459. (or state (custom-variable-state (widget-value widget)
  2460. (widget-get widget :value)))))
  2461. (defun custom-variable-standard-value (widget)
  2462. (get (widget-value widget) 'standard-value))
  2463. (defvar custom-variable-menu
  2464. `(("Set for Current Session" custom-variable-set
  2465. (lambda (widget)
  2466. (eq (widget-get widget :custom-state) 'modified)))
  2467. ;; Note that in all the backquoted code in this file, we test
  2468. ;; init-file-user rather than user-init-file. This is in case
  2469. ;; cus-edit is loaded by something in site-start.el, because
  2470. ;; user-init-file is not set at that stage.
  2471. ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html
  2472. ,@(when (or custom-file init-file-user)
  2473. '(("Save for Future Sessions" custom-variable-save
  2474. (lambda (widget)
  2475. (memq (widget-get widget :custom-state)
  2476. '(modified set changed rogue))))))
  2477. ("Undo Edits" custom-redraw
  2478. (lambda (widget)
  2479. (and (default-boundp (widget-value widget))
  2480. (memq (widget-get widget :custom-state) '(modified changed)))))
  2481. ("Reset to Saved" custom-variable-reset-saved
  2482. (lambda (widget)
  2483. (and (or (get (widget-value widget) 'saved-value)
  2484. (get (widget-value widget) 'saved-variable-comment))
  2485. (memq (widget-get widget :custom-state)
  2486. '(modified set changed rogue)))))
  2487. ,@(when (or custom-file init-file-user)
  2488. '(("Erase Customization" custom-variable-reset-standard
  2489. (lambda (widget)
  2490. (and (get (widget-value widget) 'standard-value)
  2491. (memq (widget-get widget :custom-state)
  2492. '(modified set changed saved rogue)))))))
  2493. ("Set to Backup Value" custom-variable-reset-backup
  2494. (lambda (widget)
  2495. (get (widget-value widget) 'backup-value)))
  2496. ("---" ignore ignore)
  2497. ("Add Comment" custom-comment-show custom-comment-invisible-p)
  2498. ("---" ignore ignore)
  2499. ("Show Current Value" custom-variable-edit
  2500. (lambda (widget)
  2501. (eq (widget-get widget :custom-form) 'lisp)))
  2502. ("Show Saved Lisp Expression" custom-variable-edit-lisp
  2503. (lambda (widget)
  2504. (eq (widget-get widget :custom-form) 'edit))))
  2505. "Alist of actions for the `custom-variable' widget.
  2506. Each entry has the form (NAME ACTION FILTER) where NAME is the name of
  2507. the menu entry, ACTION is the function to call on the widget when the
  2508. menu is selected, and FILTER is a predicate which takes a `custom-variable'
  2509. widget as an argument, and returns non-nil if ACTION is valid on that
  2510. widget. If FILTER is nil, ACTION is always valid.")
  2511. (defun custom-variable-action (widget &optional event)
  2512. "Show the menu for `custom-variable' WIDGET.
  2513. Optional EVENT is the location for the menu."
  2514. (if (eq (widget-get widget :custom-state) 'hidden)
  2515. (custom-toggle-hide widget)
  2516. (unless (eq (widget-get widget :custom-state) 'modified)
  2517. (custom-variable-state-set widget))
  2518. (custom-redraw-magic widget)
  2519. (let* ((completion-ignore-case t)
  2520. (answer (widget-choose (concat "Operation on "
  2521. (custom-unlispify-tag-name
  2522. (widget-get widget :value)))
  2523. (custom-menu-filter custom-variable-menu
  2524. widget)
  2525. event)))
  2526. (if answer
  2527. (funcall answer widget)))))
  2528. (defun custom-variable-edit (widget)
  2529. "Edit value of WIDGET."
  2530. (widget-put widget :custom-state 'unknown)
  2531. (widget-put widget :custom-form 'edit)
  2532. (custom-redraw widget))
  2533. (defun custom-variable-edit-lisp (widget)
  2534. "Edit the Lisp representation of the value of WIDGET."
  2535. (widget-put widget :custom-state 'unknown)
  2536. (widget-put widget :custom-form 'lisp)
  2537. (custom-redraw widget))
  2538. (defun custom-variable-set (widget)
  2539. "Set the current value for the variable being edited by WIDGET."
  2540. (let* ((form (widget-get widget :custom-form))
  2541. (state (widget-get widget :custom-state))
  2542. (child (car (widget-get widget :children)))
  2543. (symbol (widget-value widget))
  2544. (set (or (get symbol 'custom-set) 'set-default))
  2545. (comment-widget (widget-get widget :comment-widget))
  2546. (comment (widget-value comment-widget))
  2547. val)
  2548. (cond ((eq state 'hidden)
  2549. (error "Cannot set hidden variable"))
  2550. ((setq val (widget-apply child :validate))
  2551. (goto-char (widget-get val :from))
  2552. (error "%s" (widget-get val :error)))
  2553. ((memq form '(lisp mismatch))
  2554. (when (equal comment "")
  2555. (setq comment nil)
  2556. ;; Make the comment invisible by hand if it's empty
  2557. (custom-comment-hide comment-widget))
  2558. (custom-variable-backup-value widget)
  2559. (custom-push-theme 'theme-value symbol 'user
  2560. 'set (custom-quote (widget-value child)))
  2561. (funcall set symbol (eval (setq val (widget-value child))))
  2562. (put symbol 'customized-value (list val))
  2563. (put symbol 'variable-comment comment)
  2564. (put symbol 'customized-variable-comment comment))
  2565. (t
  2566. (when (equal comment "")
  2567. (setq comment nil)
  2568. ;; Make the comment invisible by hand if it's empty
  2569. (custom-comment-hide comment-widget))
  2570. (custom-variable-backup-value widget)
  2571. (custom-push-theme 'theme-value symbol 'user
  2572. 'set (custom-quote (widget-value child)))
  2573. (funcall set symbol (setq val (widget-value child)))
  2574. (put symbol 'customized-value (list (custom-quote val)))
  2575. (put symbol 'variable-comment comment)
  2576. (put symbol 'customized-variable-comment comment)))
  2577. (custom-variable-state-set widget)
  2578. (custom-redraw-magic widget)))
  2579. (defun custom-variable-mark-to-save (widget)
  2580. "Set value and mark for saving the variable edited by WIDGET."
  2581. (let* ((form (widget-get widget :custom-form))
  2582. (state (widget-get widget :custom-state))
  2583. (child (car (widget-get widget :children)))
  2584. (symbol (widget-value widget))
  2585. (set (or (get symbol 'custom-set) 'set-default))
  2586. (comment-widget (widget-get widget :comment-widget))
  2587. (comment (widget-value comment-widget))
  2588. val)
  2589. (cond ((eq state 'hidden)
  2590. (error "Cannot set hidden variable"))
  2591. ((setq val (widget-apply child :validate))
  2592. (goto-char (widget-get val :from))
  2593. (error "Saving %s: %s" symbol (widget-get val :error)))
  2594. ((memq form '(lisp mismatch))
  2595. (when (equal comment "")
  2596. (setq comment nil)
  2597. ;; Make the comment invisible by hand if it's empty
  2598. (custom-comment-hide comment-widget))
  2599. (put symbol 'saved-value (list (widget-value child)))
  2600. (custom-push-theme 'theme-value symbol 'user
  2601. 'set (custom-quote (widget-value child)))
  2602. (funcall set symbol (eval (widget-value child)))
  2603. (put symbol 'variable-comment comment)
  2604. (put symbol 'saved-variable-comment comment))
  2605. (t
  2606. (when (equal comment "")
  2607. (setq comment nil)
  2608. ;; Make the comment invisible by hand if it's empty
  2609. (custom-comment-hide comment-widget))
  2610. (put symbol 'saved-value
  2611. (list (custom-quote (widget-value child))))
  2612. (custom-push-theme 'theme-value symbol 'user
  2613. 'set (custom-quote (widget-value child)))
  2614. (funcall set symbol (widget-value child))
  2615. (put symbol 'variable-comment comment)
  2616. (put symbol 'saved-variable-comment comment)))
  2617. (put symbol 'customized-value nil)
  2618. (put symbol 'customized-variable-comment nil)))
  2619. (defsubst custom-variable-state-set-and-redraw (widget)
  2620. "Set state of variable widget WIDGET and redraw with current settings."
  2621. (custom-variable-state-set widget)
  2622. (custom-redraw-magic widget))
  2623. (defun custom-variable-save (widget)
  2624. "Save value of variable edited by widget WIDGET."
  2625. (custom-variable-mark-to-save widget)
  2626. (custom-save-all)
  2627. (custom-variable-state-set-and-redraw widget))
  2628. (defun custom-variable-reset-saved (widget)
  2629. "Restore the saved value for the variable being edited by WIDGET.
  2630. This also updates the buffer to show that value.
  2631. The value that was current before this operation
  2632. becomes the backup value, so you can get it again."
  2633. (let* ((symbol (widget-value widget))
  2634. (set (or (get symbol 'custom-set) 'set-default))
  2635. (value (get symbol 'saved-value))
  2636. (comment (get symbol 'saved-variable-comment)))
  2637. (cond ((or value comment)
  2638. (put symbol 'variable-comment comment)
  2639. (custom-variable-backup-value widget)
  2640. (custom-push-theme 'theme-value symbol 'user 'set (car-safe value))
  2641. (condition-case nil
  2642. (funcall set symbol (eval (car value)))
  2643. (error nil)))
  2644. (t
  2645. (error "No saved value for %s" symbol)))
  2646. (put symbol 'customized-value nil)
  2647. (put symbol 'customized-variable-comment nil)
  2648. (widget-put widget :custom-state 'unknown)
  2649. ;; This call will possibly make the comment invisible
  2650. (custom-redraw widget)))
  2651. (defun custom-variable-mark-to-reset-standard (widget)
  2652. "Mark to restore standard setting for the variable edited by widget WIDGET.
  2653. If `custom-reset-standard-variables-list' is nil, save, reset and
  2654. redraw the widget immediately."
  2655. (let* ((symbol (widget-value widget)))
  2656. (if (get symbol 'standard-value)
  2657. (custom-variable-backup-value widget)
  2658. (error "No standard setting known for %S" symbol))
  2659. (put symbol 'variable-comment nil)
  2660. (put symbol 'customized-value nil)
  2661. (put symbol 'customized-variable-comment nil)
  2662. (custom-push-theme 'theme-value symbol 'user 'reset)
  2663. (custom-theme-recalc-variable symbol)
  2664. (if (and custom-reset-standard-variables-list
  2665. (or (get symbol 'saved-value) (get symbol 'saved-variable-comment)))
  2666. (progn
  2667. (put symbol 'saved-value nil)
  2668. (put symbol 'saved-variable-comment nil)
  2669. ;; Append this to `custom-reset-standard-variables-list' to
  2670. ;; have `custom-reset-standard-save-and-update' save setting
  2671. ;; to the file, update the widget's state, and redraw it.
  2672. (setq custom-reset-standard-variables-list
  2673. (cons widget custom-reset-standard-variables-list)))
  2674. (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
  2675. (put symbol 'saved-value nil)
  2676. (put symbol 'saved-variable-comment nil)
  2677. (custom-save-all))
  2678. (widget-put widget :custom-state 'unknown)
  2679. ;; This call will possibly make the comment invisible
  2680. (custom-redraw widget))))
  2681. (defun custom-variable-reset-standard (widget)
  2682. "Restore standard setting for the variable edited by WIDGET.
  2683. This operation eliminates any saved setting for the variable,
  2684. restoring it to the state of a variable that has never been customized.
  2685. The value that was current before this operation
  2686. becomes the backup value, so you can get it again."
  2687. (let (custom-reset-standard-variables-list)
  2688. (custom-variable-mark-to-reset-standard widget)))
  2689. (defun custom-variable-backup-value (widget)
  2690. "Back up the current value for WIDGET's variable.
  2691. The backup value is kept in the car of the `backup-value' property."
  2692. (let* ((symbol (widget-value widget))
  2693. (get (or (get symbol 'custom-get) 'default-value))
  2694. (type (custom-variable-type symbol))
  2695. (conv (widget-convert type))
  2696. (value (if (default-boundp symbol)
  2697. (funcall get symbol)
  2698. (widget-get conv :value))))
  2699. (put symbol 'backup-value (list value))))
  2700. (defun custom-variable-reset-backup (widget)
  2701. "Restore the backup value for the variable being edited by WIDGET.
  2702. The value that was current before this operation
  2703. becomes the backup value, so you can use this operation repeatedly
  2704. to switch between two values."
  2705. (let* ((symbol (widget-value widget))
  2706. (set (or (get symbol 'custom-set) 'set-default))
  2707. (value (get symbol 'backup-value))
  2708. (comment-widget (widget-get widget :comment-widget))
  2709. (comment (widget-value comment-widget)))
  2710. (if value
  2711. (progn
  2712. (custom-variable-backup-value widget)
  2713. (custom-push-theme 'theme-value symbol 'user 'set value)
  2714. (condition-case nil
  2715. (funcall set symbol (car value))
  2716. (error nil)))
  2717. (error "No backup value for %s" symbol))
  2718. (put symbol 'customized-value (list (custom-quote (car value))))
  2719. (put symbol 'variable-comment comment)
  2720. (put symbol 'customized-variable-comment comment)
  2721. (custom-variable-state-set widget)
  2722. ;; This call will possibly make the comment invisible
  2723. (custom-redraw widget)))
  2724. ;;; The `custom-visibility' Widget
  2725. (define-widget 'custom-visibility 'visibility
  2726. "Show or hide a documentation string."
  2727. :button-face 'custom-visibility
  2728. :pressed-face 'custom-visibility
  2729. :mouse-face 'highlight
  2730. :pressed-face 'highlight
  2731. :on-glyph nil
  2732. :off-glyph nil)
  2733. (defface custom-visibility
  2734. '((t :height 0.8 :inherit link))
  2735. "Face for the `custom-visibility' widget."
  2736. :version "23.1"
  2737. :group 'custom-faces)
  2738. ;;; The `custom-face-edit' Widget.
  2739. (define-widget 'custom-face-edit 'checklist
  2740. "Widget for editing face attributes.
  2741. The following properties have special meanings for this widget:
  2742. :value is a plist of face attributes.
  2743. :default-face-attributes, if non-nil, is a plist of defaults for
  2744. face attributes (as specified by a `default' defface entry)."
  2745. :format "%v"
  2746. :extra-offset 3
  2747. :button-args '(:help-echo "Control whether this attribute has any effect.")
  2748. :value-to-internal 'custom-face-edit-fix-value
  2749. :match (lambda (widget value)
  2750. (widget-checklist-match widget
  2751. (custom-face-edit-fix-value widget value)))
  2752. :value-create 'custom-face-edit-value-create
  2753. :convert-widget 'custom-face-edit-convert-widget
  2754. :args (mapcar (lambda (att)
  2755. (list 'group :inline t
  2756. :sibling-args (widget-get (nth 1 att) :sibling-args)
  2757. (list 'const :format "" :value (nth 0 att))
  2758. (nth 1 att)))
  2759. custom-face-attributes))
  2760. (defun custom-face-edit-value-create (widget)
  2761. (let* ((alist (widget-checklist-match-find
  2762. widget (widget-get widget :value)))
  2763. (args (widget-get widget :args))
  2764. (show-all (widget-get widget :show-all-attributes))
  2765. (buttons (widget-get widget :buttons))
  2766. (defaults (widget-checklist-match-find
  2767. widget
  2768. (widget-get widget :default-face-attributes)))
  2769. entry)
  2770. (unless (looking-back "^ *")
  2771. (insert ?\n))
  2772. (insert-char ?\s (widget-get widget :extra-offset))
  2773. (if (or alist defaults show-all)
  2774. (dolist (prop args)
  2775. (setq entry (or (assq prop alist)
  2776. (assq prop defaults)))
  2777. (if (or entry show-all)
  2778. (widget-checklist-add-item widget prop entry)))
  2779. (insert (propertize "-- Empty face --" 'face 'shadow) ?\n))
  2780. (let ((indent (widget-get widget :indent)))
  2781. (if indent (insert-char ?\s (widget-get widget :indent))))
  2782. (push (widget-create-child-and-convert
  2783. widget 'visibility
  2784. :help-echo "Show or hide all face attributes."
  2785. :button-face 'custom-visibility
  2786. :pressed-face 'custom-visibility
  2787. :mouse-face 'highlight
  2788. :on "Hide Unused Attributes" :off "Show All Attributes"
  2789. :on-glyph nil :off-glyph nil
  2790. :always-active t
  2791. :action 'custom-face-edit-value-visibility-action
  2792. show-all)
  2793. buttons)
  2794. (insert ?\n)
  2795. (widget-put widget :buttons buttons)
  2796. (widget-put widget :children (nreverse (widget-get widget :children)))))
  2797. (defun custom-face-edit-value-visibility-action (widget &rest _ignore)
  2798. ;; Toggle hiding of face attributes.
  2799. (let ((parent (widget-get widget :parent)))
  2800. (widget-put parent :show-all-attributes
  2801. (not (widget-get parent :show-all-attributes)))
  2802. (custom-redraw parent)))
  2803. (defun custom-face-edit-fix-value (_widget value)
  2804. "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
  2805. Also change :reverse-video to :inverse-video."
  2806. (custom-fix-face-spec value))
  2807. (defun custom-face-edit-convert-widget (widget)
  2808. "Convert :args as widget types in WIDGET."
  2809. (widget-put
  2810. widget
  2811. :args (mapcar (lambda (arg)
  2812. (widget-convert arg
  2813. :deactivate 'custom-face-edit-deactivate
  2814. :activate 'custom-face-edit-activate
  2815. :delete 'custom-face-edit-delete))
  2816. (widget-get widget :args)))
  2817. widget)
  2818. (defconst custom-face-edit (widget-convert 'custom-face-edit)
  2819. "Converted version of the `custom-face-edit' widget.")
  2820. (defun custom-face-edit-deactivate (widget)
  2821. "Make face widget WIDGET inactive for user modifications."
  2822. (unless (widget-get widget :inactive)
  2823. (let ((tag (custom-face-edit-attribute-tag widget))
  2824. (from (copy-marker (widget-get widget :from)))
  2825. (value (widget-value widget))
  2826. (inhibit-read-only t)
  2827. (inhibit-modification-hooks t))
  2828. (save-excursion
  2829. (goto-char from)
  2830. (widget-default-delete widget)
  2831. (insert tag ": " (propertize "--" 'face 'shadow) "\n")
  2832. (widget-put widget :inactive
  2833. (cons value (cons from (- (point) from))))))))
  2834. (defun custom-face-edit-activate (widget)
  2835. "Make face widget WIDGET active for user modifications."
  2836. (let ((inactive (widget-get widget :inactive))
  2837. (inhibit-read-only t)
  2838. (inhibit-modification-hooks t))
  2839. (when (consp inactive)
  2840. (save-excursion
  2841. (goto-char (car (cdr inactive)))
  2842. (delete-region (point) (+ (point) (cdr (cdr inactive))))
  2843. (widget-put widget :inactive nil)
  2844. (widget-apply widget :create)
  2845. (widget-value-set widget (car inactive))
  2846. (widget-setup)))))
  2847. (defun custom-face-edit-delete (widget)
  2848. "Remove WIDGET from the buffer."
  2849. (let ((inactive (widget-get widget :inactive))
  2850. (inhibit-read-only t)
  2851. (inhibit-modification-hooks t))
  2852. (if (not inactive)
  2853. ;; Widget is alive, we don't have to do anything special
  2854. (widget-default-delete widget)
  2855. ;; WIDGET is already deleted because we did so to deactivate it;
  2856. ;; now just get rid of the label we put in its place.
  2857. (delete-region (car (cdr inactive))
  2858. (+ (car (cdr inactive)) (cdr (cdr inactive))))
  2859. (widget-put widget :inactive nil))))
  2860. (defun custom-face-edit-attribute-tag (widget)
  2861. "Return the first :tag property in WIDGET or one of its children."
  2862. (let ((tag (widget-get widget :tag)))
  2863. (or (and (not (equal tag "")) tag)
  2864. (let ((children (widget-get widget :children)))
  2865. (while (and (null tag) children)
  2866. (setq tag (custom-face-edit-attribute-tag (pop children))))
  2867. tag))))
  2868. ;;; The `custom-display' Widget.
  2869. (define-widget 'custom-display 'menu-choice
  2870. "Select a display type."
  2871. :tag "Display"
  2872. :value t
  2873. :help-echo "Specify frames where the face attributes should be used."
  2874. :args '((const :tag "all" t)
  2875. (const :tag "defaults" default)
  2876. (checklist
  2877. :tag "specific display"
  2878. :offset 0
  2879. :extra-offset 9
  2880. :args ((group :sibling-args (:help-echo "\
  2881. Only match the specified window systems.")
  2882. (const :format "Type: "
  2883. type)
  2884. (checklist :inline t
  2885. :offset 0
  2886. (const :format "X "
  2887. :sibling-args (:help-echo "\
  2888. The X11 Window System.")
  2889. x)
  2890. (const :format "PM "
  2891. :sibling-args (:help-echo "\
  2892. OS/2 Presentation Manager.")
  2893. pm)
  2894. (const :format "W32 "
  2895. :sibling-args (:help-echo "\
  2896. Windows NT/9X.")
  2897. w32)
  2898. (const :format "NS "
  2899. :sibling-args (:help-echo "\
  2900. GNUstep or Macintosh OS Cocoa interface.")
  2901. ns)
  2902. (const :format "DOS "
  2903. :sibling-args (:help-echo "\
  2904. Plain MS-DOS.")
  2905. pc)
  2906. (const :format "TTY%n"
  2907. :sibling-args (:help-echo "\
  2908. Plain text terminals.")
  2909. tty)))
  2910. (group :sibling-args (:help-echo "\
  2911. Only match the frames with the specified color support.")
  2912. (const :format "Class: "
  2913. class)
  2914. (checklist :inline t
  2915. :offset 0
  2916. (const :format "Color "
  2917. :sibling-args (:help-echo "\
  2918. Match color frames.")
  2919. color)
  2920. (const :format "Grayscale "
  2921. :sibling-args (:help-echo "\
  2922. Match grayscale frames.")
  2923. grayscale)
  2924. (const :format "Monochrome%n"
  2925. :sibling-args (:help-echo "\
  2926. Match frames with no color support.")
  2927. mono)))
  2928. (group :sibling-args (:help-echo "\
  2929. The minimum number of colors the frame should support.")
  2930. (const :format "" min-colors)
  2931. (integer :tag "Minimum number of colors" ))
  2932. (group :sibling-args (:help-echo "\
  2933. Only match frames with the specified intensity.")
  2934. (const :format "\
  2935. Background brightness: "
  2936. background)
  2937. (checklist :inline t
  2938. :offset 0
  2939. (const :format "Light "
  2940. :sibling-args (:help-echo "\
  2941. Match frames with light backgrounds.")
  2942. light)
  2943. (const :format "Dark\n"
  2944. :sibling-args (:help-echo "\
  2945. Match frames with dark backgrounds.")
  2946. dark)))
  2947. (group :sibling-args (:help-echo "\
  2948. Only match frames that support the specified face attributes.")
  2949. (const :format "Supports attributes:" supports)
  2950. (custom-face-edit :inline t :format "%n%v"))))))
  2951. ;;; The `custom-face' Widget.
  2952. (defface custom-face-tag
  2953. `((t :inherit custom-variable-tag))
  2954. "Face used for face tags."
  2955. :group 'custom-faces)
  2956. (define-obsolete-face-alias 'custom-face-tag-face 'custom-face-tag "22.1")
  2957. (defcustom custom-face-default-form 'selected
  2958. "Default form of displaying face definition."
  2959. :type '(choice (const all)
  2960. (const selected)
  2961. (const lisp))
  2962. :group 'custom-buffer
  2963. :version "20.3")
  2964. (define-widget 'custom-face 'custom
  2965. "Widget for customizing a face.
  2966. The following properties have special meanings for this widget:
  2967. :value is the face name (a symbol).
  2968. :custom-form should be a symbol describing how to display and
  2969. edit the face attributes---either `selected' (attributes for
  2970. selected display only), `all' (all attributes), `lisp' (as a
  2971. Lisp sexp), or `mismatch' (should not happen); if nil, use
  2972. the return value of `custom-face-default-form'.
  2973. :custom-style describes the widget interface style; nil is the
  2974. default style, while `simple' means a simpler interface that
  2975. inhibits the magic custom-state widget.
  2976. :sample-indent, if non-nil, is the number of columns to which to
  2977. indent the face sample (an integer).
  2978. :shown-value, if non-nil, is the face spec to display as the value
  2979. of the widget, instead of the current face spec."
  2980. :sample-face 'custom-face-tag
  2981. :help-echo "Set or reset this face."
  2982. :documentation-property #'face-doc-string
  2983. :value-create 'custom-face-value-create
  2984. :action 'custom-face-action
  2985. :custom-category 'face
  2986. :custom-form nil
  2987. :custom-set 'custom-face-set
  2988. :custom-mark-to-save 'custom-face-mark-to-save
  2989. :custom-reset-current 'custom-redraw
  2990. :custom-reset-saved 'custom-face-reset-saved
  2991. :custom-reset-standard 'custom-face-reset-standard
  2992. :custom-mark-to-reset-standard 'custom-face-mark-to-reset-standard
  2993. :custom-standard-value 'custom-face-standard-value
  2994. :custom-state-set-and-redraw 'custom-face-state-set-and-redraw
  2995. :custom-menu 'custom-face-menu-create)
  2996. (define-widget 'custom-face-all 'editable-list
  2997. "An editable list of display specifications and attributes."
  2998. :entry-format "%i %d %v"
  2999. :insert-button-args '(:help-echo "Insert new display specification here.")
  3000. :append-button-args '(:help-echo "Append new display specification here.")
  3001. :delete-button-args '(:help-echo "Delete this display specification.")
  3002. :args '((group :format "%v" custom-display custom-face-edit)))
  3003. (defconst custom-face-all (widget-convert 'custom-face-all)
  3004. "Converted version of the `custom-face-all' widget.")
  3005. (defun custom-filter-face-spec (spec filter-index &optional default-filter)
  3006. "Return a canonicalized version of SPEC using.
  3007. FILTER-INDEX is the index in the entry for each attribute in
  3008. `custom-face-attributes' at which the appropriate filter function can be
  3009. found, and DEFAULT-FILTER is the filter to apply for attributes that
  3010. don't specify one."
  3011. (mapcar (lambda (entry)
  3012. ;; Filter a single face-spec entry
  3013. (let ((tests (car entry))
  3014. (unfiltered-attrs
  3015. ;; Handle both old- and new-style attribute syntax
  3016. (if (listp (car (cdr entry)))
  3017. (car (cdr entry))
  3018. (cdr entry)))
  3019. (filtered-attrs nil))
  3020. ;; Filter each face attribute
  3021. (while unfiltered-attrs
  3022. (let* ((attr (pop unfiltered-attrs))
  3023. (pre-filtered-value (pop unfiltered-attrs))
  3024. (filter
  3025. (or (nth filter-index (assq attr custom-face-attributes))
  3026. default-filter))
  3027. (filtered-value
  3028. (if filter
  3029. (funcall filter pre-filtered-value)
  3030. pre-filtered-value)))
  3031. (push filtered-value filtered-attrs)
  3032. (push attr filtered-attrs)))
  3033. ;;
  3034. (list tests filtered-attrs)))
  3035. spec))
  3036. (defun custom-pre-filter-face-spec (spec)
  3037. "Return SPEC changed as necessary for editing by the face customization widget.
  3038. SPEC must be a full face spec."
  3039. (custom-filter-face-spec spec 2))
  3040. (defun custom-post-filter-face-spec (spec)
  3041. "Return the customized SPEC in a form suitable for setting the face."
  3042. (custom-filter-face-spec spec 3))
  3043. (defun custom-face-widget-to-spec (widget)
  3044. "Return a face spec corresponding to WIDGET.
  3045. WIDGET should be a `custom-face' widget."
  3046. (unless (eq (widget-type widget) 'custom-face)
  3047. (error "Invalid widget"))
  3048. (let ((child (car (widget-get widget :children))))
  3049. (custom-post-filter-face-spec
  3050. (if (eq (widget-type child) 'custom-face-edit)
  3051. `((t ,(widget-value child)))
  3052. (widget-value child)))))
  3053. (defun custom-face-get-current-spec (face)
  3054. (let ((spec (or (get face 'customized-face)
  3055. (get face 'saved-face)
  3056. (get face 'face-defface-spec)
  3057. ;; Attempt to construct it.
  3058. `((t ,(custom-face-attributes-get
  3059. face (selected-frame)))))))
  3060. ;; If the user has changed this face in some other way,
  3061. ;; edit it as the user has specified it.
  3062. (if (not (face-spec-match-p face spec (selected-frame)))
  3063. (setq spec `((t ,(face-attr-construct face (selected-frame))))))
  3064. (custom-pre-filter-face-spec spec)))
  3065. (defun custom-toggle-hide-face (visibility-widget &rest _ignore)
  3066. "Toggle the visibility of a `custom-face' parent widget.
  3067. By default, this signals an error if the parent has unsaved
  3068. changes. If the parent has a `simple' :custom-style property,
  3069. the present value is saved to its :shown-value property instead."
  3070. (let ((widget (widget-get visibility-widget :parent)))
  3071. (unless (eq (widget-type widget) 'custom-face)
  3072. (error "Invalid widget type"))
  3073. (custom-load-widget widget)
  3074. (let ((state (widget-get widget :custom-state)))
  3075. (if (eq state 'hidden)
  3076. (widget-put widget :custom-state 'unknown)
  3077. ;; In normal interface, widget can't be hidden if modified.
  3078. (when (memq state '(invalid modified set))
  3079. (if (eq (widget-get widget :custom-style) 'simple)
  3080. (widget-put widget :shown-value
  3081. (custom-face-widget-to-spec widget))
  3082. (error "There are unsaved changes")))
  3083. (widget-put widget :documentation-shown nil)
  3084. (widget-put widget :custom-state 'hidden))
  3085. (custom-redraw widget)
  3086. (widget-setup))))
  3087. (defun custom-face-value-create (widget)
  3088. "Create a list of the display specifications for WIDGET."
  3089. (let* ((buttons (widget-get widget :buttons))
  3090. (symbol (widget-get widget :value))
  3091. (tag (or (widget-get widget :tag)
  3092. (prin1-to-string symbol)))
  3093. (hiddenp (eq (widget-get widget :custom-state) 'hidden))
  3094. (style (widget-get widget :custom-style))
  3095. children)
  3096. (if (eq custom-buffer-style 'tree)
  3097. ;; Draw a tree-style `custom-face' widget
  3098. (progn
  3099. (insert (widget-get widget :custom-prefix)
  3100. (if (widget-get widget :custom-last) " `--- " " |--- "))
  3101. (push (widget-create-child-and-convert
  3102. widget 'custom-browse-face-tag)
  3103. buttons)
  3104. (insert " " tag "\n")
  3105. (widget-put widget :buttons buttons))
  3106. ;; Draw an ordinary `custom-face' widget
  3107. (let ((opoint (point)))
  3108. ;; Visibility indicator.
  3109. (push (widget-create-child-and-convert
  3110. widget 'custom-visibility
  3111. :help-echo "Hide or show this face."
  3112. :on "Hide" :off "Show"
  3113. :on-glyph "down" :off-glyph "right"
  3114. :action 'custom-toggle-hide-face
  3115. (not hiddenp))
  3116. buttons)
  3117. ;; Face name (tag).
  3118. (insert " " tag)
  3119. (widget-specify-sample widget opoint (point)))
  3120. (insert
  3121. (cond ((eq custom-buffer-style 'face) " ")
  3122. ((string-match "face\\'" tag) ":")
  3123. (t " face: ")))
  3124. ;; Face sample.
  3125. (let ((sample-indent (widget-get widget :sample-indent))
  3126. (indent-tabs-mode nil))
  3127. (and sample-indent
  3128. (<= (current-column) sample-indent)
  3129. (indent-to-column sample-indent)))
  3130. (push (widget-create-child-and-convert
  3131. widget 'item
  3132. :format "[%{%t%}]"
  3133. :sample-face (let ((spec (widget-get widget :shown-value)))
  3134. (if spec (face-spec-choose spec) symbol))
  3135. :tag "sample")
  3136. buttons)
  3137. (insert "\n")
  3138. ;; Magic.
  3139. (unless (eq (widget-get widget :custom-style) 'simple)
  3140. (let ((magic (widget-create-child-and-convert
  3141. widget 'custom-magic nil)))
  3142. (widget-put widget :custom-magic magic)
  3143. (push magic buttons)))
  3144. ;; Update buttons.
  3145. (widget-put widget :buttons buttons)
  3146. ;; Insert documentation.
  3147. (unless (and hiddenp (eq style 'simple))
  3148. (widget-put widget :documentation-indent 3)
  3149. (widget-add-documentation-string-button
  3150. widget :visibility-widget 'custom-visibility)
  3151. ;; The comment field
  3152. (unless hiddenp
  3153. (let* ((comment (get symbol 'face-comment))
  3154. (comment-widget
  3155. (widget-create-child-and-convert
  3156. widget 'custom-comment
  3157. :parent widget
  3158. :value (or comment ""))))
  3159. (widget-put widget :comment-widget comment-widget)
  3160. (push comment-widget children))))
  3161. ;; Editor.
  3162. (unless (eq (preceding-char) ?\n)
  3163. (insert "\n"))
  3164. (unless hiddenp
  3165. (custom-load-widget widget)
  3166. (unless (widget-get widget :custom-form)
  3167. (widget-put widget :custom-form custom-face-default-form))
  3168. (let* ((spec (or (widget-get widget :shown-value)
  3169. (custom-face-get-current-spec symbol)))
  3170. (form (widget-get widget :custom-form))
  3171. (indent (widget-get widget :indent))
  3172. face-alist face-entry spec-default spec-match editor)
  3173. ;; Find a display in SPEC matching the selected display.
  3174. ;; This will use the usual face customization interface.
  3175. (setq face-alist spec)
  3176. (when (eq (car-safe (car-safe face-alist)) 'default)
  3177. (setq spec-default (pop face-alist)))
  3178. (while (and face-alist (listp face-alist) (null spec-match))
  3179. (setq face-entry (car face-alist))
  3180. (and (listp face-entry)
  3181. (face-spec-set-match-display (car face-entry)
  3182. (selected-frame))
  3183. (widget-apply custom-face-edit :match (cadr face-entry))
  3184. (setq spec-match face-entry))
  3185. (setq face-alist (cdr face-alist)))
  3186. ;; Insert the appropriate editing widget.
  3187. (setq editor
  3188. (cond
  3189. ((and (eq form 'selected)
  3190. (or spec-match spec-default))
  3191. (when indent (insert-char ?\s indent))
  3192. (widget-create-child-and-convert
  3193. widget 'custom-face-edit
  3194. :value (cadr spec-match)
  3195. :default-face-attributes (cadr spec-default)))
  3196. ((and (not (eq form 'lisp))
  3197. (widget-apply custom-face-all :match spec))
  3198. (widget-create-child-and-convert
  3199. widget 'custom-face-all :value spec))
  3200. (t
  3201. (when indent
  3202. (insert-char ?\s indent))
  3203. (widget-create-child-and-convert
  3204. widget 'sexp :value spec))))
  3205. (custom-face-state-set widget)
  3206. (push editor children)
  3207. (widget-put widget :children children))))))
  3208. (defvar custom-face-menu
  3209. `(("Set for Current Session" custom-face-set)
  3210. ,@(when (or custom-file init-file-user)
  3211. '(("Save for Future Sessions" custom-face-save)))
  3212. ("Undo Edits" custom-redraw
  3213. (lambda (widget)
  3214. (memq (widget-get widget :custom-state) '(modified changed))))
  3215. ("Reset to Saved" custom-face-reset-saved
  3216. (lambda (widget)
  3217. (or (get (widget-value widget) 'saved-face)
  3218. (get (widget-value widget) 'saved-face-comment))))
  3219. ,@(when (or custom-file init-file-user)
  3220. '(("Erase Customization" custom-face-reset-standard
  3221. (lambda (widget)
  3222. (get (widget-value widget) 'face-defface-spec)))))
  3223. ("---" ignore ignore)
  3224. ("Add Comment" custom-comment-show custom-comment-invisible-p)
  3225. ("---" ignore ignore)
  3226. ("For Current Display" custom-face-edit-selected
  3227. (lambda (widget)
  3228. (not (eq (widget-get widget :custom-form) 'selected))))
  3229. ("For All Kinds of Displays" custom-face-edit-all
  3230. (lambda (widget)
  3231. (not (eq (widget-get widget :custom-form) 'all))))
  3232. ("Show Lisp Expression" custom-face-edit-lisp
  3233. (lambda (widget)
  3234. (not (eq (widget-get widget :custom-form) 'lisp)))))
  3235. "Alist of actions for the `custom-face' widget.
  3236. Each entry has the form (NAME ACTION FILTER) where NAME is the name of
  3237. the menu entry, ACTION is the function to call on the widget when the
  3238. menu is selected, and FILTER is a predicate which takes a `custom-face'
  3239. widget as an argument, and returns non-nil if ACTION is valid on that
  3240. widget. If FILTER is nil, ACTION is always valid.")
  3241. (defun custom-face-edit-selected (widget)
  3242. "Edit selected attributes of the value of WIDGET."
  3243. (widget-put widget :custom-state 'unknown)
  3244. (widget-put widget :custom-form 'selected)
  3245. (custom-redraw widget))
  3246. (defun custom-face-edit-all (widget)
  3247. "Edit all attributes of the value of WIDGET."
  3248. (widget-put widget :custom-state 'unknown)
  3249. (widget-put widget :custom-form 'all)
  3250. (custom-redraw widget))
  3251. (defun custom-face-edit-lisp (widget)
  3252. "Edit the Lisp representation of the value of WIDGET."
  3253. (widget-put widget :custom-state 'unknown)
  3254. (widget-put widget :custom-form 'lisp)
  3255. (custom-redraw widget))
  3256. (defun custom-face-state (face)
  3257. "Return the current state of the face FACE.
  3258. This is one of `set', `saved', `changed', `themed', or `rogue'."
  3259. (let* ((comment (get face 'face-comment))
  3260. (state
  3261. (cond
  3262. ((or (get face 'customized-face)
  3263. (get face 'customized-face-comment))
  3264. (if (equal (get face 'customized-face-comment) comment)
  3265. 'set
  3266. 'changed))
  3267. ((or (get face 'saved-face)
  3268. (get face 'saved-face-comment))
  3269. (if (equal (get face 'saved-face-comment) comment)
  3270. (cond
  3271. ((eq 'user (caar (get face 'theme-face)))
  3272. 'saved)
  3273. ((eq 'changed (caar (get face 'theme-face)))
  3274. 'changed)
  3275. (t 'themed))
  3276. 'changed))
  3277. ((get face 'face-defface-spec)
  3278. (if (equal comment nil)
  3279. 'standard
  3280. 'changed))
  3281. (t 'rogue))))
  3282. ;; If the user called set-face-attribute to change the default for
  3283. ;; new frames, this face is "set outside of Customize".
  3284. (if (and (not (eq state 'rogue))
  3285. (get face 'face-modified))
  3286. 'changed
  3287. state)))
  3288. (defun custom-face-state-set (widget)
  3289. "Set the state of WIDGET."
  3290. (widget-put widget :custom-state
  3291. (custom-face-state (widget-value widget))))
  3292. (defun custom-face-action (widget &optional event)
  3293. "Show the menu for `custom-face' WIDGET.
  3294. Optional EVENT is the location for the menu."
  3295. (if (eq (widget-get widget :custom-state) 'hidden)
  3296. (custom-toggle-hide widget)
  3297. (let* ((completion-ignore-case t)
  3298. (symbol (widget-get widget :value))
  3299. (answer (widget-choose (concat "Operation on "
  3300. (custom-unlispify-tag-name symbol))
  3301. (custom-menu-filter custom-face-menu
  3302. widget)
  3303. event)))
  3304. (if answer
  3305. (funcall answer widget)))))
  3306. (defun custom-face-set (widget)
  3307. "Make the face attributes in WIDGET take effect."
  3308. (let* ((symbol (widget-value widget))
  3309. (value (custom-face-widget-to-spec widget))
  3310. (comment-widget (widget-get widget :comment-widget))
  3311. (comment (widget-value comment-widget)))
  3312. (when (equal comment "")
  3313. (setq comment nil)
  3314. ;; Make the comment invisible by hand if it's empty
  3315. (custom-comment-hide comment-widget))
  3316. (put symbol 'customized-face value)
  3317. (custom-push-theme 'theme-face symbol 'user 'set value)
  3318. (if (face-spec-choose value)
  3319. (face-spec-set symbol value t)
  3320. ;; face-set-spec ignores empty attribute lists, so just give it
  3321. ;; something harmless instead.
  3322. (face-spec-set symbol '((t :foreground unspecified)) t))
  3323. (put symbol 'customized-face-comment comment)
  3324. (put symbol 'face-comment comment)
  3325. (custom-face-state-set widget)
  3326. (custom-redraw-magic widget)))
  3327. (defun custom-face-mark-to-save (widget)
  3328. "Mark for saving the face edited by WIDGET."
  3329. (let* ((symbol (widget-value widget))
  3330. (value (custom-face-widget-to-spec widget))
  3331. (comment-widget (widget-get widget :comment-widget))
  3332. (comment (widget-value comment-widget)))
  3333. (when (equal comment "")
  3334. (setq comment nil)
  3335. ;; Make the comment invisible by hand if it's empty
  3336. (custom-comment-hide comment-widget))
  3337. (custom-push-theme 'theme-face symbol 'user 'set value)
  3338. (if (face-spec-choose value)
  3339. (face-spec-set symbol value t)
  3340. ;; face-set-spec ignores empty attribute lists, so just give it
  3341. ;; something harmless instead.
  3342. (face-spec-set symbol '((t :foreground unspecified)) t))
  3343. (unless (eq (widget-get widget :custom-state) 'standard)
  3344. (put symbol 'saved-face value))
  3345. (put symbol 'customized-face nil)
  3346. (put symbol 'face-comment comment)
  3347. (put symbol 'customized-face-comment nil)
  3348. (put symbol 'saved-face-comment comment)))
  3349. (defsubst custom-face-state-set-and-redraw (widget)
  3350. "Set state of face widget WIDGET and redraw with current settings."
  3351. (custom-face-state-set widget)
  3352. (custom-redraw-magic widget))
  3353. (defun custom-face-save (widget)
  3354. "Save the face edited by WIDGET."
  3355. (custom-face-mark-to-save widget)
  3356. (custom-save-all)
  3357. (custom-face-state-set-and-redraw widget))
  3358. ;; For backward compatibility.
  3359. (define-obsolete-function-alias 'custom-face-save-command 'custom-face-save
  3360. "22.1")
  3361. (defun custom-face-reset-saved (widget)
  3362. "Restore WIDGET to the face's default attributes."
  3363. (let* ((symbol (widget-value widget))
  3364. (child (car (widget-get widget :children)))
  3365. (value (get symbol 'saved-face))
  3366. (comment (get symbol 'saved-face-comment))
  3367. (comment-widget (widget-get widget :comment-widget)))
  3368. (unless (or value comment)
  3369. (error "No saved value for this face"))
  3370. (put symbol 'customized-face nil)
  3371. (put symbol 'customized-face-comment nil)
  3372. (custom-push-theme 'theme-face symbol 'user 'set value)
  3373. (face-spec-set symbol value t)
  3374. (put symbol 'face-comment comment)
  3375. (widget-value-set child value)
  3376. ;; This call manages the comment visibility
  3377. (widget-value-set comment-widget (or comment ""))
  3378. (custom-face-state-set widget)
  3379. (custom-redraw-magic widget)))
  3380. (defun custom-face-standard-value (widget)
  3381. (get (widget-value widget) 'face-defface-spec))
  3382. (defun custom-face-mark-to-reset-standard (widget)
  3383. "Restore widget WIDGET to the face's standard attribute values.
  3384. If `custom-reset-standard-faces-list' is nil, save, reset and
  3385. redraw the widget immediately."
  3386. (let* ((symbol (widget-value widget))
  3387. (child (car (widget-get widget :children)))
  3388. (value (get symbol 'face-defface-spec))
  3389. (comment-widget (widget-get widget :comment-widget)))
  3390. (unless value
  3391. (error "No standard setting for this face"))
  3392. (put symbol 'customized-face nil)
  3393. (put symbol 'customized-face-comment nil)
  3394. (custom-push-theme 'theme-face symbol 'user 'reset)
  3395. (face-spec-set symbol value t)
  3396. (custom-theme-recalc-face symbol)
  3397. (if (and custom-reset-standard-faces-list
  3398. (or (get symbol 'saved-face) (get symbol 'saved-face-comment)))
  3399. ;; Do this later.
  3400. (progn
  3401. (put symbol 'saved-face nil)
  3402. (put symbol 'saved-face-comment nil)
  3403. ;; Append this to `custom-reset-standard-faces-list' and have
  3404. ;; `custom-reset-standard-save-and-update' save setting to the
  3405. ;; file, update the widget's state, and redraw it.
  3406. (setq custom-reset-standard-faces-list
  3407. (cons widget custom-reset-standard-faces-list)))
  3408. (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
  3409. (put symbol 'saved-face nil)
  3410. (put symbol 'saved-face-comment nil)
  3411. (custom-save-all))
  3412. (put symbol 'face-comment nil)
  3413. (widget-value-set child
  3414. (custom-pre-filter-face-spec
  3415. (list (list t (custom-face-attributes-get
  3416. symbol nil)))))
  3417. ;; This call manages the comment visibility
  3418. (widget-value-set comment-widget "")
  3419. (custom-face-state-set widget)
  3420. (custom-redraw-magic widget))))
  3421. (defun custom-face-reset-standard (widget)
  3422. "Restore WIDGET to the face's standard attribute values.
  3423. This operation eliminates any saved attributes for the face,
  3424. restoring it to the state of a face that has never been customized."
  3425. (let (custom-reset-standard-faces-list)
  3426. (custom-face-mark-to-reset-standard widget)))
  3427. ;;; The `face' Widget.
  3428. (defvar widget-face-prompt-value-history nil
  3429. "History of input to `widget-face-prompt-value'.")
  3430. (define-widget 'face 'symbol
  3431. "A Lisp face name (with sample)."
  3432. :format "%{%t%}: (%{sample%}) %v"
  3433. :tag "Face"
  3434. :value 'default
  3435. :sample-face-get 'widget-face-sample-face-get
  3436. :notify 'widget-face-notify
  3437. :match (lambda (_widget value) (facep value))
  3438. :completions (apply-partially #'completion-table-with-predicate
  3439. obarray #'facep 'strict)
  3440. :prompt-match 'facep
  3441. :prompt-history 'widget-face-prompt-value-history
  3442. :validate (lambda (widget)
  3443. (unless (facep (widget-value widget))
  3444. (widget-put widget
  3445. :error (format "Invalid face: %S"
  3446. (widget-value widget)))
  3447. widget)))
  3448. (defun widget-face-sample-face-get (widget)
  3449. (let ((value (widget-value widget)))
  3450. (if (facep value)
  3451. value
  3452. 'default)))
  3453. (defun widget-face-notify (widget child &optional event)
  3454. "Update the sample, and notify the parent."
  3455. (overlay-put (widget-get widget :sample-overlay)
  3456. 'face (widget-apply widget :sample-face-get))
  3457. (widget-default-notify widget child event))
  3458. ;;; The `hook' Widget.
  3459. (define-widget 'hook 'list
  3460. "An Emacs Lisp hook."
  3461. :value-to-internal (lambda (_widget value)
  3462. (if (and value (symbolp value))
  3463. (list value)
  3464. value))
  3465. :match (lambda (widget value)
  3466. (or (symbolp value)
  3467. (widget-group-match widget value)))
  3468. ;; Avoid adding undefined functions to the hook, especially for
  3469. ;; things like `find-file-hook' or even more basic ones, to avoid
  3470. ;; chaos.
  3471. :set (lambda (symbol value)
  3472. (dolist (elt value)
  3473. (if (fboundp elt)
  3474. (add-hook symbol elt))))
  3475. :convert-widget 'custom-hook-convert-widget
  3476. :tag "Hook")
  3477. (defun custom-hook-convert-widget (widget)
  3478. ;; Handle `:options'.
  3479. (let* ((options (widget-get widget :options))
  3480. (other `(editable-list :inline t
  3481. :entry-format "%i %d%v"
  3482. (function :format " %v")))
  3483. (args (if options
  3484. (list `(checklist :inline t
  3485. ,@(mapcar (lambda (entry)
  3486. `(function-item ,entry))
  3487. options))
  3488. other)
  3489. (list other))))
  3490. (widget-put widget :args args)
  3491. widget))
  3492. ;;; The `custom-group-link' Widget.
  3493. (define-widget 'custom-group-link 'link
  3494. "Show parent in other window when activated."
  3495. :button-face 'custom-link
  3496. :mouse-face 'highlight
  3497. :pressed-face 'highlight
  3498. :help-echo "Create customization buffer for this group."
  3499. :keymap custom-mode-link-map
  3500. :follow-link 'mouse-face
  3501. :action 'custom-group-link-action)
  3502. (defun custom-group-link-action (widget &rest _ignore)
  3503. (customize-group (widget-value widget)))
  3504. ;;; The `custom-group' Widget.
  3505. (defcustom custom-group-tag-faces nil
  3506. ;; In XEmacs, this ought to play games with font size.
  3507. ;; Fixme: make it do so in Emacs.
  3508. "Face used for group tags.
  3509. The first member is used for level 1 groups, the second for level 2,
  3510. and so forth. The remaining group tags are shown with `custom-group-tag'."
  3511. :type '(repeat face)
  3512. :group 'custom-faces)
  3513. (defface custom-group-tag-1
  3514. `((((class color)
  3515. (background dark))
  3516. (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch))
  3517. (((min-colors 88) (class color)
  3518. (background light))
  3519. (:foreground "red1" :weight bold :height 1.2 :inherit variable-pitch))
  3520. (((class color)
  3521. (background light))
  3522. (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch))
  3523. (t (:weight bold)))
  3524. "Face used for group tags."
  3525. :group 'custom-faces)
  3526. (define-obsolete-face-alias 'custom-group-tag-face-1 'custom-group-tag-1 "22.1")
  3527. (defface custom-group-tag
  3528. `((((class color)
  3529. (background dark))
  3530. (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch))
  3531. (((min-colors 88) (class color)
  3532. (background light))
  3533. (:foreground "blue1" :weight bold :height 1.2 :inherit variable-pitch))
  3534. (((class color)
  3535. (background light))
  3536. (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch))
  3537. (t (:weight bold)))
  3538. "Face used for low level group tags."
  3539. :group 'custom-faces)
  3540. (define-obsolete-face-alias 'custom-group-tag-face 'custom-group-tag "22.1")
  3541. (define-widget 'custom-group 'custom
  3542. "Customize group."
  3543. :format "%v"
  3544. :sample-face-get 'custom-group-sample-face-get
  3545. :documentation-property 'group-documentation
  3546. :help-echo "Set or reset all members of this group."
  3547. :value-create 'custom-group-value-create
  3548. :action 'custom-group-action
  3549. :custom-category 'group
  3550. :custom-set 'custom-group-set
  3551. :custom-mark-to-save 'custom-group-mark-to-save
  3552. :custom-reset-current 'custom-group-reset-current
  3553. :custom-reset-saved 'custom-group-reset-saved
  3554. :custom-reset-standard 'custom-group-reset-standard
  3555. :custom-mark-to-reset-standard 'custom-group-mark-to-reset-standard
  3556. :custom-state-set-and-redraw 'custom-group-state-set-and-redraw
  3557. :custom-menu 'custom-group-menu-create)
  3558. (defun custom-group-sample-face-get (widget)
  3559. ;; Use :sample-face.
  3560. (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces)
  3561. 'custom-group-tag))
  3562. (define-widget 'custom-group-visibility 'visibility
  3563. "An indicator and manipulator for hidden group contents."
  3564. :create 'custom-group-visibility-create)
  3565. (defun custom-group-visibility-create (widget)
  3566. (let ((visible (widget-value widget)))
  3567. (if visible
  3568. (insert "--------")))
  3569. (widget-default-create widget))
  3570. (defun custom-group-members (symbol groups-only)
  3571. "Return SYMBOL's custom group members.
  3572. If GROUPS-ONLY non-nil, return only those members that are groups."
  3573. (if (not groups-only)
  3574. (get symbol 'custom-group)
  3575. (let (members)
  3576. (dolist (entry (get symbol 'custom-group))
  3577. (when (eq (nth 1 entry) 'custom-group)
  3578. (push entry members)))
  3579. (nreverse members))))
  3580. (defun custom-group-value-create (widget)
  3581. "Insert a customize group for WIDGET in the current buffer."
  3582. (unless (eq (widget-get widget :custom-state) 'hidden)
  3583. (custom-load-widget widget))
  3584. (let* ((state (widget-get widget :custom-state))
  3585. (level (widget-get widget :custom-level))
  3586. ;; (indent (widget-get widget :indent))
  3587. (prefix (widget-get widget :custom-prefix))
  3588. (buttons (widget-get widget :buttons))
  3589. (tag (widget-get widget :tag))
  3590. (symbol (widget-value widget))
  3591. (members (custom-group-members symbol
  3592. (and (eq custom-buffer-style 'tree)
  3593. custom-browse-only-groups)))
  3594. (doc (widget-docstring widget)))
  3595. (cond ((and (eq custom-buffer-style 'tree)
  3596. (eq state 'hidden)
  3597. (or members (custom-unloaded-widget-p widget)))
  3598. (custom-browse-insert-prefix prefix)
  3599. (push (widget-create-child-and-convert
  3600. widget 'custom-browse-visibility
  3601. ;; :tag-glyph "plus"
  3602. :tag "+")
  3603. buttons)
  3604. (insert "-- ")
  3605. ;; (widget-glyph-insert nil "-- " "horizontal")
  3606. (push (widget-create-child-and-convert
  3607. widget 'custom-browse-group-tag)
  3608. buttons)
  3609. (insert " " tag "\n")
  3610. (widget-put widget :buttons buttons))
  3611. ((and (eq custom-buffer-style 'tree)
  3612. (zerop (length members)))
  3613. (custom-browse-insert-prefix prefix)
  3614. (insert "[ ]-- ")
  3615. ;; (widget-glyph-insert nil "[ ]" "empty")
  3616. ;; (widget-glyph-insert nil "-- " "horizontal")
  3617. (push (widget-create-child-and-convert
  3618. widget 'custom-browse-group-tag)
  3619. buttons)
  3620. (insert " " tag "\n")
  3621. (widget-put widget :buttons buttons))
  3622. ((eq custom-buffer-style 'tree)
  3623. (custom-browse-insert-prefix prefix)
  3624. (if (zerop (length members))
  3625. (progn
  3626. (custom-browse-insert-prefix prefix)
  3627. (insert "[ ]-- ")
  3628. ;; (widget-glyph-insert nil "[ ]" "empty")
  3629. ;; (widget-glyph-insert nil "-- " "horizontal")
  3630. (push (widget-create-child-and-convert
  3631. widget 'custom-browse-group-tag)
  3632. buttons)
  3633. (insert " " tag "\n")
  3634. (widget-put widget :buttons buttons))
  3635. (push (widget-create-child-and-convert
  3636. widget 'custom-browse-visibility
  3637. ;; :tag-glyph "minus"
  3638. :tag "-")
  3639. buttons)
  3640. (insert "-\\ ")
  3641. ;; (widget-glyph-insert nil "-\\ " "top")
  3642. (push (widget-create-child-and-convert
  3643. widget 'custom-browse-group-tag)
  3644. buttons)
  3645. (insert " " tag "\n")
  3646. (widget-put widget :buttons buttons)
  3647. (message "Creating group...")
  3648. (let* ((members (custom-sort-items
  3649. members
  3650. ;; Never sort the top-level custom group.
  3651. (unless (eq symbol 'emacs)
  3652. custom-browse-sort-alphabetically)
  3653. custom-browse-order-groups))
  3654. (prefixes (widget-get widget :custom-prefixes))
  3655. (custom-prefix-list (custom-prefix-add symbol prefixes))
  3656. (extra-prefix (if (widget-get widget :custom-last)
  3657. " "
  3658. " | "))
  3659. (prefix (concat prefix extra-prefix))
  3660. children entry)
  3661. (while members
  3662. (setq entry (car members)
  3663. members (cdr members))
  3664. (push (widget-create-child-and-convert
  3665. widget (nth 1 entry)
  3666. :group widget
  3667. :tag (custom-unlispify-tag-name (nth 0 entry))
  3668. :custom-prefixes custom-prefix-list
  3669. :custom-level (1+ level)
  3670. :custom-last (null members)
  3671. :value (nth 0 entry)
  3672. :custom-prefix prefix)
  3673. children))
  3674. (widget-put widget :children (reverse children)))
  3675. (message "Creating group...done")))
  3676. ;; Nested style.
  3677. ((eq state 'hidden)
  3678. ;; Create level indicator.
  3679. ;; Create tag.
  3680. (if (eq custom-buffer-style 'links)
  3681. (push (widget-create-child-and-convert
  3682. widget 'custom-group-link
  3683. :tag tag
  3684. symbol)
  3685. buttons)
  3686. (insert-char ?\ (* custom-buffer-indent (1- level)))
  3687. (insert "-- ")
  3688. (push (widget-create-child-and-convert
  3689. widget 'custom-group-visibility
  3690. :help-echo "Show members of this group."
  3691. :action 'custom-toggle-parent
  3692. (not (eq state 'hidden)))
  3693. buttons))
  3694. (insert " : ")
  3695. ;; Create magic button.
  3696. (let ((magic (widget-create-child-and-convert
  3697. widget 'custom-magic nil)))
  3698. (widget-put widget :custom-magic magic)
  3699. (push magic buttons))
  3700. ;; Update buttons.
  3701. (widget-put widget :buttons buttons)
  3702. ;; Insert documentation.
  3703. (if (and (eq custom-buffer-style 'links) (> level 1))
  3704. (widget-put widget :documentation-indent 0))
  3705. (widget-add-documentation-string-button
  3706. widget :visibility-widget 'custom-visibility))
  3707. ;; Nested style.
  3708. (t ;Visible.
  3709. ;; Draw a horizontal line (this works for both graphical
  3710. ;; and text displays):
  3711. (let ((p (point)))
  3712. (insert "\n")
  3713. (put-text-property p (1+ p) 'face '(:underline t))
  3714. (overlay-put (make-overlay p (1+ p))
  3715. 'before-string
  3716. (propertize "\n" 'face '(:underline t)
  3717. 'display '(space :align-to 999))))
  3718. ;; Add parent groups references above the group.
  3719. (when (eq level 1)
  3720. (if (custom-add-parent-links widget "Parent groups:")
  3721. (insert "\n")))
  3722. (insert-char ?\ (* custom-buffer-indent (1- level)))
  3723. ;; Create tag.
  3724. (let ((start (point)))
  3725. (insert tag " group: ")
  3726. (widget-specify-sample widget start (point)))
  3727. (cond
  3728. ((not doc)
  3729. (insert " Group definition missing. "))
  3730. ((< (length doc) 50)
  3731. (insert doc)))
  3732. ;; Create visibility indicator.
  3733. (unless (eq custom-buffer-style 'links)
  3734. (insert "--------")
  3735. (push (widget-create-child-and-convert
  3736. widget 'visibility
  3737. :help-echo "Hide members of this group."
  3738. :action 'custom-toggle-parent
  3739. (not (eq state 'hidden)))
  3740. buttons)
  3741. (insert " "))
  3742. (insert "\n")
  3743. ;; Create magic button.
  3744. (let ((magic (widget-create-child-and-convert
  3745. widget 'custom-magic
  3746. :indent 0
  3747. nil)))
  3748. (widget-put widget :custom-magic magic)
  3749. (push magic buttons))
  3750. ;; Update buttons.
  3751. (widget-put widget :buttons buttons)
  3752. ;; Insert documentation.
  3753. (when (and doc (>= (length doc) 50))
  3754. (widget-add-documentation-string-button
  3755. widget :visibility-widget 'custom-visibility))
  3756. ;; Parent groups.
  3757. (if nil ;;; This should test that the buffer
  3758. ;;; was not made to display a group.
  3759. (when (eq level 1)
  3760. (insert-char ?\ custom-buffer-indent)
  3761. (custom-add-parent-links widget)))
  3762. (custom-add-see-also widget
  3763. (make-string (* custom-buffer-indent level)
  3764. ?\ ))
  3765. ;; Members.
  3766. (message "Creating group...")
  3767. (let* ((members (custom-sort-items
  3768. members
  3769. ;; Never sort the top-level custom group.
  3770. (unless (eq symbol 'emacs)
  3771. custom-buffer-sort-alphabetically)
  3772. custom-buffer-order-groups))
  3773. (prefixes (widget-get widget :custom-prefixes))
  3774. (custom-prefix-list (custom-prefix-add symbol prefixes))
  3775. (len (length members))
  3776. (count 0)
  3777. (reporter (make-progress-reporter
  3778. "Creating group entries..." 0 len))
  3779. children)
  3780. (setq children
  3781. (mapcar
  3782. (lambda (entry)
  3783. (widget-insert "\n")
  3784. (progress-reporter-update reporter (setq count (1+ count)))
  3785. (let ((sym (nth 0 entry))
  3786. (type (nth 1 entry)))
  3787. (prog1
  3788. (widget-create-child-and-convert
  3789. widget type
  3790. :group widget
  3791. :tag (custom-unlispify-tag-name sym)
  3792. :custom-prefixes custom-prefix-list
  3793. :custom-level (1+ level)
  3794. :value sym)
  3795. (unless (eq (preceding-char) ?\n)
  3796. (widget-insert "\n")))))
  3797. members))
  3798. (mapc 'custom-magic-reset children)
  3799. (widget-put widget :children children)
  3800. (custom-group-state-update widget)
  3801. (progress-reporter-done reporter))
  3802. ;; End line
  3803. (let ((p (1+ (point))))
  3804. (insert "\n\n")
  3805. (put-text-property p (1+ p) 'face '(:underline t))
  3806. (overlay-put (make-overlay p (1+ p))
  3807. 'before-string
  3808. (propertize "\n" 'face '(:underline t)
  3809. 'display '(space :align-to 999))))))))
  3810. (defvar custom-group-menu
  3811. `(("Set for Current Session" custom-group-set
  3812. (lambda (widget)
  3813. (eq (widget-get widget :custom-state) 'modified)))
  3814. ,@(when (or custom-file init-file-user)
  3815. '(("Save for Future Sessions" custom-group-save
  3816. (lambda (widget)
  3817. (memq (widget-get widget :custom-state) '(modified set))))))
  3818. ("Undo Edits" custom-group-reset-current
  3819. (lambda (widget)
  3820. (memq (widget-get widget :custom-state) '(modified))))
  3821. ("Reset to Saved" custom-group-reset-saved
  3822. (lambda (widget)
  3823. (memq (widget-get widget :custom-state) '(modified set))))
  3824. ,@(when (or custom-file init-file-user)
  3825. '(("Erase Customization" custom-group-reset-standard
  3826. (lambda (widget)
  3827. (memq (widget-get widget :custom-state) '(modified set saved)))))))
  3828. "Alist of actions for the `custom-group' widget.
  3829. Each entry has the form (NAME ACTION FILTER) where NAME is the name of
  3830. the menu entry, ACTION is the function to call on the widget when the
  3831. menu is selected, and FILTER is a predicate which takes a `custom-group'
  3832. widget as an argument, and returns non-nil if ACTION is valid on that
  3833. widget. If FILTER is nil, ACTION is always valid.")
  3834. (defun custom-group-action (widget &optional event)
  3835. "Show the menu for `custom-group' WIDGET.
  3836. Optional EVENT is the location for the menu."
  3837. (if (eq (widget-get widget :custom-state) 'hidden)
  3838. (custom-toggle-hide widget)
  3839. (let* ((completion-ignore-case t)
  3840. (answer (widget-choose (concat "Operation on "
  3841. (custom-unlispify-tag-name
  3842. (widget-get widget :value)))
  3843. (custom-menu-filter custom-group-menu
  3844. widget)
  3845. event)))
  3846. (if answer
  3847. (funcall answer widget)))))
  3848. (defun custom-group-set (widget)
  3849. "Set changes in all modified group members."
  3850. (dolist (child (widget-get widget :children))
  3851. (when (eq (widget-get child :custom-state) 'modified)
  3852. (widget-apply child :custom-set))))
  3853. (defun custom-group-mark-to-save (widget)
  3854. "Mark all modified group members for saving."
  3855. (dolist (child (widget-get widget :children))
  3856. (when (memq (widget-get child :custom-state) '(modified set))
  3857. (widget-apply child :custom-mark-to-save))))
  3858. (defsubst custom-group-state-set-and-redraw (widget)
  3859. "Set state of group widget WIDGET and redraw with current settings."
  3860. (dolist (child (widget-get widget :children))
  3861. (when (memq (widget-get child :custom-state) '(modified set))
  3862. (widget-apply child :custom-state-set-and-redraw))))
  3863. (defun custom-group-save (widget)
  3864. "Save all modified group members."
  3865. (custom-group-mark-to-save widget)
  3866. (custom-save-all)
  3867. (custom-group-state-set-and-redraw widget))
  3868. (defun custom-group-reset-current (widget)
  3869. "Reset all modified group members."
  3870. (dolist (child (widget-get widget :children))
  3871. (when (eq (widget-get child :custom-state) 'modified)
  3872. (widget-apply child :custom-reset-current))))
  3873. (defun custom-group-reset-saved (widget)
  3874. "Reset all modified or set group members."
  3875. (dolist (child (widget-get widget :children))
  3876. (when (memq (widget-get child :custom-state) '(modified set))
  3877. (widget-apply child :custom-reset-saved))))
  3878. (defun custom-group-reset-standard (widget)
  3879. "Reset all modified, set, or saved group members."
  3880. (let ((custom-reset-standard-variables-list '(t))
  3881. (custom-reset-standard-faces-list '(t)))
  3882. (custom-group-mark-to-reset-standard widget)
  3883. (custom-reset-standard-save-and-update)))
  3884. (defun custom-group-mark-to-reset-standard (widget)
  3885. "Mark to reset all modified, set, or saved group members."
  3886. (dolist (child (widget-get widget :children))
  3887. (when (memq (widget-get child :custom-state)
  3888. '(modified set saved))
  3889. (widget-apply child :custom-mark-to-reset-standard))))
  3890. (defun custom-group-state-update (widget)
  3891. "Update magic."
  3892. (unless (eq (widget-get widget :custom-state) 'hidden)
  3893. (let* ((children (widget-get widget :children))
  3894. (states (mapcar (lambda (child)
  3895. (widget-get child :custom-state))
  3896. children))
  3897. (magics custom-magic-alist)
  3898. (found 'standard))
  3899. (while magics
  3900. (let ((magic (car (car magics))))
  3901. (if (and (not (eq magic 'hidden))
  3902. (memq magic states))
  3903. (setq found magic
  3904. magics nil)
  3905. (setq magics (cdr magics)))))
  3906. (widget-put widget :custom-state found)))
  3907. (custom-magic-reset widget))
  3908. ;;; Reading and writing the custom file.
  3909. ;;;###autoload
  3910. (defcustom custom-file nil
  3911. "File used for storing customization information.
  3912. The default is nil, which means to use your init file
  3913. as specified by `user-init-file'. If the value is not nil,
  3914. it should be an absolute file name.
  3915. You can set this option through Custom, if you carefully read the
  3916. last paragraph below. However, usually it is simpler to write
  3917. something like the following in your init file:
  3918. \(setq custom-file \"~/.emacs-custom.el\")
  3919. \(load custom-file)
  3920. Note that both lines are necessary: the first line tells Custom to
  3921. save all customizations in this file, but does not load it.
  3922. When you change this variable outside Custom, look in the
  3923. previous custom file \(usually your init file) for the
  3924. forms `(custom-set-variables ...)' and `(custom-set-faces ...)',
  3925. and copy them (whichever ones you find) to the new custom file.
  3926. This will preserve your existing customizations.
  3927. If you save this option using Custom, Custom will write all
  3928. currently saved customizations, including the new one for this
  3929. option itself, into the file you specify, overwriting any
  3930. `custom-set-variables' and `custom-set-faces' forms already
  3931. present in that file. It will not delete any customizations from
  3932. the old custom file. You should do that manually if that is what you
  3933. want. You also have to put something like `\(load \"CUSTOM-FILE\")
  3934. in your init file, where CUSTOM-FILE is the actual name of the
  3935. file. Otherwise, Emacs will not load the file when it starts up,
  3936. and hence will not set `custom-file' to that file either."
  3937. :type '(choice (const :tag "Your Emacs init file" nil)
  3938. (file :format "%t:%v%d"
  3939. :doc
  3940. "Please read entire docstring below before setting \
  3941. this through Custom.
  3942. Click on \"More\" \(or position point there and press RETURN)
  3943. if only the first line of the docstring is shown."))
  3944. :group 'customize)
  3945. (defun custom-file (&optional no-error)
  3946. "Return the file name for saving customizations."
  3947. (if (null user-init-file)
  3948. ;; Started with -q, i.e. the file containing Custom settings
  3949. ;; hasn't been read. Saving settings there won't make much
  3950. ;; sense.
  3951. (if no-error
  3952. nil
  3953. (error "Saving settings from \"emacs -q\" would overwrite existing customizations"))
  3954. (file-chase-links (or custom-file user-init-file))))
  3955. ;; If recentf-mode is non-nil, this is defined.
  3956. (declare-function recentf-expand-file-name "recentf" (name))
  3957. ;;;###autoload
  3958. (defun custom-save-all ()
  3959. "Save all customizations in `custom-file'."
  3960. (when (and (null custom-file) init-file-had-error)
  3961. (error "Cannot save customizations; init file was not fully loaded"))
  3962. (let* ((filename (custom-file))
  3963. (recentf-exclude
  3964. (if recentf-mode
  3965. (cons (concat "\\`"
  3966. (regexp-quote
  3967. (recentf-expand-file-name (custom-file)))
  3968. "\\'")
  3969. recentf-exclude)))
  3970. (old-buffer (find-buffer-visiting filename))
  3971. old-buffer-name)
  3972. (with-current-buffer (let ((find-file-visit-truename t))
  3973. (or old-buffer (find-file-noselect filename)))
  3974. ;; We'll save using file-precious-flag, so avoid destroying
  3975. ;; symlinks. (If we're not already visiting the buffer, this is
  3976. ;; handled by find-file-visit-truename, above.)
  3977. (when old-buffer
  3978. (setq old-buffer-name (buffer-file-name))
  3979. (set-visited-file-name (file-chase-links filename)))
  3980. (unless (eq major-mode 'emacs-lisp-mode)
  3981. (emacs-lisp-mode))
  3982. (let ((inhibit-read-only t)
  3983. (print-length nil)
  3984. (print-level nil))
  3985. (custom-save-variables)
  3986. (custom-save-faces))
  3987. (let ((file-precious-flag t))
  3988. (save-buffer))
  3989. (if old-buffer
  3990. (progn
  3991. (set-visited-file-name old-buffer-name)
  3992. (set-buffer-modified-p nil))
  3993. (kill-buffer (current-buffer))))))
  3994. ;;;###autoload
  3995. (defun customize-save-customized ()
  3996. "Save all user options which have been set in this session."
  3997. (interactive)
  3998. (mapatoms (lambda (symbol)
  3999. (let ((face (get symbol 'customized-face))
  4000. (value (get symbol 'customized-value))
  4001. (face-comment (get symbol 'customized-face-comment))
  4002. (variable-comment
  4003. (get symbol 'customized-variable-comment)))
  4004. (when face
  4005. (put symbol 'saved-face face)
  4006. (custom-push-theme 'theme-face symbol 'user 'set value)
  4007. (put symbol 'customized-face nil))
  4008. (when value
  4009. (put symbol 'saved-value value)
  4010. (custom-push-theme 'theme-value symbol 'user 'set value)
  4011. (put symbol 'customized-value nil))
  4012. (when variable-comment
  4013. (put symbol 'saved-variable-comment variable-comment)
  4014. (put symbol 'customized-variable-comment nil))
  4015. (when face-comment
  4016. (put symbol 'saved-face-comment face-comment)
  4017. (put symbol 'customized-face-comment nil)))))
  4018. ;; We really should update all custom buffers here.
  4019. (custom-save-all))
  4020. ;; Editing the custom file contents in a buffer.
  4021. (defun custom-save-delete (symbol)
  4022. "Delete all calls to SYMBOL from the contents of the current buffer.
  4023. Leave point at the old location of the first such call,
  4024. or (if there were none) at the end of the buffer.
  4025. This function does not save the buffer."
  4026. (goto-char (point-min))
  4027. ;; Skip all whitespace and comments.
  4028. (while (forward-comment 1))
  4029. (or (eobp)
  4030. (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors.
  4031. (let (first)
  4032. (catch 'found
  4033. (while t ;; We exit this loop only via throw.
  4034. ;; Skip all whitespace and comments.
  4035. (while (forward-comment 1))
  4036. (let ((start (point))
  4037. (sexp (condition-case nil
  4038. (read (current-buffer))
  4039. (end-of-file (throw 'found nil)))))
  4040. (when (and (listp sexp)
  4041. (eq (car sexp) symbol))
  4042. (delete-region start (point))
  4043. (unless first
  4044. (setq first (point)))))))
  4045. (if first
  4046. (goto-char first)
  4047. ;; Move in front of local variables, otherwise long Custom
  4048. ;; entries would make them ineffective.
  4049. (let ((pos (point-max))
  4050. (case-fold-search t))
  4051. (save-excursion
  4052. (goto-char (point-max))
  4053. (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
  4054. 'move)
  4055. (when (search-forward "Local Variables:" nil t)
  4056. (setq pos (line-beginning-position))))
  4057. (goto-char pos)))))
  4058. (defvar sort-fold-case) ; defined in sort.el
  4059. (defun custom-save-variables ()
  4060. "Save all customized variables in `custom-file'."
  4061. (save-excursion
  4062. (custom-save-delete 'custom-set-variables)
  4063. (let ((standard-output (current-buffer))
  4064. (saved-list (make-list 1 0))
  4065. sort-fold-case)
  4066. ;; First create a sorted list of saved variables.
  4067. (mapatoms
  4068. (lambda (symbol)
  4069. (if (and (get symbol 'saved-value)
  4070. ;; ignore theme values
  4071. (or (null (get symbol 'theme-value))
  4072. (eq 'user (caar (get symbol 'theme-value)))))
  4073. (nconc saved-list (list symbol)))))
  4074. (setq saved-list (sort (cdr saved-list) 'string<))
  4075. (unless (bolp)
  4076. (princ "\n"))
  4077. (princ "(custom-set-variables
  4078. ;; custom-set-variables was added by Custom.
  4079. ;; If you edit it by hand, you could mess it up, so be careful.
  4080. ;; Your init file should contain only one such instance.
  4081. ;; If there is more than one, they won't work right.\n")
  4082. (dolist (symbol saved-list)
  4083. (let ((spec (car-safe (get symbol 'theme-value)))
  4084. (value (get symbol 'saved-value))
  4085. (requests (get symbol 'custom-requests))
  4086. (now (and (not (custom-variable-p symbol))
  4087. (or (boundp symbol)
  4088. (eq (get symbol 'force-value)
  4089. 'rogue))))
  4090. (comment (get symbol 'saved-variable-comment)))
  4091. ;; Check REQUESTS for validity.
  4092. (dolist (request requests)
  4093. (when (and (symbolp request) (not (featurep request)))
  4094. (message "Unknown requested feature: %s" request)
  4095. (setq requests (delq request requests))))
  4096. ;; Is there anything customized about this variable?
  4097. (when (or (and spec (eq (car spec) 'user))
  4098. comment
  4099. (and (null spec) (get symbol 'saved-value)))
  4100. ;; Output an element for this variable.
  4101. ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT).
  4102. ;; SYMBOL is the variable name.
  4103. ;; VALUE-FORM is an expression to return the customized value.
  4104. ;; NOW if non-nil means always set the variable immediately
  4105. ;; when the customizations are reloaded. This is used
  4106. ;; for rogue variables
  4107. ;; REQUESTS is a list of packages to load before setting the
  4108. ;; variable. Each element of it will be passed to `require'.
  4109. ;; COMMENT is whatever comment the user has specified
  4110. ;; with the customize facility.
  4111. (unless (bolp)
  4112. (princ "\n"))
  4113. (princ " '(")
  4114. (prin1 symbol)
  4115. (princ " ")
  4116. (prin1 (car value))
  4117. (when (or now requests comment)
  4118. (princ " ")
  4119. (prin1 now)
  4120. (when (or requests comment)
  4121. (princ " ")
  4122. (prin1 requests)
  4123. (when comment
  4124. (princ " ")
  4125. (prin1 comment))))
  4126. (princ ")"))))
  4127. (if (bolp)
  4128. (princ " "))
  4129. (princ ")")
  4130. (unless (looking-at "\n")
  4131. (princ "\n")))))
  4132. (defun custom-save-faces ()
  4133. "Save all customized faces in `custom-file'."
  4134. (save-excursion
  4135. (custom-save-delete 'custom-reset-faces)
  4136. (custom-save-delete 'custom-set-faces)
  4137. (let ((standard-output (current-buffer))
  4138. (saved-list (make-list 1 0))
  4139. sort-fold-case)
  4140. ;; First create a sorted list of saved faces.
  4141. (mapatoms
  4142. (lambda (symbol)
  4143. (if (and (get symbol 'saved-face)
  4144. (eq 'user (car (car-safe (get symbol 'theme-face)))))
  4145. (nconc saved-list (list symbol)))))
  4146. (setq saved-list (sort (cdr saved-list) 'string<))
  4147. ;; The default face must be first, since it affects the others.
  4148. (if (memq 'default saved-list)
  4149. (setq saved-list (cons 'default (delq 'default saved-list))))
  4150. (unless (bolp)
  4151. (princ "\n"))
  4152. (princ "(custom-set-faces
  4153. ;; custom-set-faces was added by Custom.
  4154. ;; If you edit it by hand, you could mess it up, so be careful.
  4155. ;; Your init file should contain only one such instance.
  4156. ;; If there is more than one, they won't work right.\n")
  4157. (dolist (symbol saved-list)
  4158. (let ((spec (car-safe (get symbol 'theme-face)))
  4159. (value (get symbol 'saved-face))
  4160. (now (not (or (get symbol 'face-defface-spec)
  4161. (and (not (custom-facep symbol))
  4162. (not (get symbol 'force-face))))))
  4163. (comment (get symbol 'saved-face-comment)))
  4164. (when (or (and spec (eq (nth 0 spec) 'user))
  4165. comment
  4166. (and (null spec) (get symbol 'saved-face)))
  4167. ;; Don't print default face here.
  4168. (unless (bolp)
  4169. (princ "\n"))
  4170. (princ " '(")
  4171. (prin1 symbol)
  4172. (princ " ")
  4173. (prin1 value)
  4174. (when (or now comment)
  4175. (princ " ")
  4176. (prin1 now)
  4177. (when comment
  4178. (princ " ")
  4179. (prin1 comment)))
  4180. (princ ")"))))
  4181. (if (bolp)
  4182. (princ " "))
  4183. (princ ")")
  4184. (unless (looking-at "\n")
  4185. (princ "\n")))))
  4186. ;;; The Customize Menu.
  4187. ;;; Menu support
  4188. (defcustom custom-menu-nesting 2
  4189. "Maximum nesting in custom menus."
  4190. :type 'integer
  4191. :group 'custom-menu)
  4192. (defun custom-face-menu-create (_widget symbol)
  4193. "Ignoring WIDGET, create a menu entry for customization face SYMBOL."
  4194. (vector (custom-unlispify-menu-entry symbol)
  4195. `(customize-face ',symbol)
  4196. t))
  4197. (defun custom-variable-menu-create (_widget symbol)
  4198. "Ignoring WIDGET, create a menu entry for customization variable SYMBOL."
  4199. (let ((type (get symbol 'custom-type)))
  4200. (unless (listp type)
  4201. (setq type (list type)))
  4202. (if (and type (widget-get type :custom-menu))
  4203. (widget-apply type :custom-menu symbol)
  4204. (vector (custom-unlispify-menu-entry symbol)
  4205. `(customize-variable ',symbol)
  4206. t))))
  4207. ;; Add checkboxes to boolean variable entries.
  4208. (widget-put (get 'boolean 'widget-type)
  4209. :custom-menu (lambda (_widget symbol)
  4210. (vector (custom-unlispify-menu-entry symbol)
  4211. `(customize-variable ',symbol)
  4212. ':style 'toggle
  4213. ':selected symbol)))
  4214. (defun custom-group-menu-create (_widget symbol)
  4215. "Ignoring WIDGET, create a menu entry for customization group SYMBOL."
  4216. `( ,(custom-unlispify-menu-entry symbol t)
  4217. :filter (lambda (&rest junk)
  4218. (let* ((menu (custom-menu-create ',symbol)))
  4219. (if (consp menu) (cdr menu) menu)))))
  4220. ;;;###autoload
  4221. (defun custom-menu-create (symbol)
  4222. "Create menu for customization group SYMBOL.
  4223. The menu is in a format applicable to `easy-menu-define'."
  4224. (let* ((deactivate-mark nil)
  4225. (item (vector (custom-unlispify-menu-entry symbol)
  4226. `(customize-group ',symbol)
  4227. t)))
  4228. (if (and (or (not (boundp 'custom-menu-nesting))
  4229. (>= custom-menu-nesting 0))
  4230. (progn
  4231. (custom-load-symbol symbol)
  4232. (< (length (get symbol 'custom-group)) widget-menu-max-size)))
  4233. (let ((custom-prefix-list (custom-prefix-add symbol
  4234. custom-prefix-list))
  4235. (members (custom-sort-items (get symbol 'custom-group)
  4236. custom-menu-sort-alphabetically
  4237. custom-menu-order-groups)))
  4238. `(,(custom-unlispify-menu-entry symbol t)
  4239. ,item
  4240. "--"
  4241. ,@(mapcar (lambda (entry)
  4242. (widget-apply (if (listp (nth 1 entry))
  4243. (nth 1 entry)
  4244. (list (nth 1 entry)))
  4245. :custom-menu (nth 0 entry)))
  4246. members)))
  4247. item)))
  4248. ;;;###autoload
  4249. (defun customize-menu-create (symbol &optional name)
  4250. "Return a customize menu for customization group SYMBOL.
  4251. If optional NAME is given, use that as the name of the menu.
  4252. Otherwise the menu will be named `Customize'.
  4253. The format is suitable for use with `easy-menu-define'."
  4254. (unless name
  4255. (setq name "Customize"))
  4256. `(,name
  4257. :filter (lambda (&rest junk)
  4258. (let ((menu (custom-menu-create ',symbol)))
  4259. (if (consp menu) (cdr menu) menu)))))
  4260. ;;; Toolbar and menubar support
  4261. (easy-menu-define
  4262. Custom-mode-menu (list custom-mode-map custom-field-keymap)
  4263. "Menu used in customization buffers."
  4264. (nconc (list "Custom"
  4265. (customize-menu-create 'customize))
  4266. (mapcar (lambda (arg)
  4267. (let ((tag (nth 0 arg))
  4268. (command (nth 1 arg))
  4269. (active (nth 2 arg))
  4270. (help (nth 3 arg)))
  4271. (vector tag command :active (eval active) :help help)))
  4272. custom-commands)))
  4273. (defvar tool-bar-map)
  4274. ;;; `custom-tool-bar-map' used to be set up here. This will fail to
  4275. ;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
  4276. ;;; we set this up lazily in `Custom-mode'.
  4277. (defvar custom-tool-bar-map nil
  4278. "Keymap for toolbar in Custom mode.")
  4279. ;;; The Custom Mode.
  4280. (defun Custom-no-edit (_pos &optional _event)
  4281. "Invoke button at POS, or refuse to allow editing of Custom buffer."
  4282. (interactive "@d")
  4283. (error "You can't edit this part of the Custom buffer"))
  4284. (defun Custom-newline (pos &optional event)
  4285. "Invoke button at POS, or refuse to allow editing of Custom buffer."
  4286. (interactive "@d")
  4287. (let ((button (get-char-property pos 'button)))
  4288. ;; If there is no button at point, then use the one at the start
  4289. ;; of the line, if it is a custom-group-link (bug#2298).
  4290. (or button
  4291. (if (setq button (get-char-property (line-beginning-position) 'button))
  4292. (or (eq (widget-type button) 'custom-group-link)
  4293. (setq button nil))))
  4294. (if button
  4295. (widget-apply-action button event)
  4296. (error "You can't edit this part of the Custom buffer"))))
  4297. (defun Custom-goto-parent ()
  4298. "Go to the parent group listed at the top of this buffer.
  4299. If several parents are listed, go to the first of them."
  4300. (interactive)
  4301. (save-excursion
  4302. (goto-char (point-min))
  4303. (if (search-forward "\nParent groups: " nil t)
  4304. (let* ((button (get-char-property (point) 'button))
  4305. (parent (downcase (widget-get button :tag))))
  4306. (customize-group parent)))))
  4307. (defcustom Custom-mode-hook nil
  4308. "Hook called when entering Custom mode."
  4309. :type 'hook
  4310. :group 'custom-buffer)
  4311. (defun custom-state-buffer-message (widget)
  4312. (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified)
  4313. (message "To install your edits, invoke [State] and choose the Set operation")))
  4314. (defun custom--initialize-widget-variables ()
  4315. (set (make-local-variable 'widget-documentation-face) 'custom-documentation)
  4316. (set (make-local-variable 'widget-button-face) custom-button)
  4317. (set (make-local-variable 'widget-button-pressed-face) custom-button-pressed)
  4318. (set (make-local-variable 'widget-mouse-face) custom-button-mouse)
  4319. ;; We need this because of the "More" button on docstrings.
  4320. ;; Otherwise clicking on "More" can push point offscreen, which
  4321. ;; causes the window to recenter on point, which pushes the
  4322. ;; newly-revealed docstring offscreen; which is annoying. -- cyd.
  4323. (set (make-local-variable 'widget-button-click-moves-point) t)
  4324. ;; When possible, use relief for buttons, not bracketing. This test
  4325. ;; may not be optimal.
  4326. (when custom-raised-buttons
  4327. (set (make-local-variable 'widget-push-button-prefix) "")
  4328. (set (make-local-variable 'widget-push-button-suffix) "")
  4329. (set (make-local-variable 'widget-link-prefix) "")
  4330. (set (make-local-variable 'widget-link-suffix) ""))
  4331. (setq show-trailing-whitespace nil))
  4332. (define-derived-mode Custom-mode nil "Custom"
  4333. "Major mode for editing customization buffers.
  4334. The following commands are available:
  4335. \\<widget-keymap>\
  4336. Move to next button, link or editable field. \\[widget-forward]
  4337. Move to previous button, link or editable field. \\[widget-backward]
  4338. \\<custom-field-keymap>\
  4339. Complete content of editable text field. \\[widget-complete]
  4340. \\<custom-mode-map>\
  4341. Invoke button under the mouse pointer. \\[widget-button-click]
  4342. Invoke button under point. \\[widget-button-press]
  4343. Set all options from current text. \\[Custom-set]
  4344. Make values in current text permanent. \\[Custom-save]
  4345. Make text match actual option values. \\[Custom-reset-current]
  4346. Reset options to permanent settings. \\[Custom-reset-saved]
  4347. Erase customizations; set options
  4348. and buffer text to the standard values. \\[Custom-reset-standard]
  4349. Entry to this mode calls the value of `Custom-mode-hook'
  4350. if that value is non-nil."
  4351. (use-local-map custom-mode-map)
  4352. (easy-menu-add Custom-mode-menu)
  4353. (set (make-local-variable 'tool-bar-map)
  4354. (or custom-tool-bar-map
  4355. ;; Set up `custom-tool-bar-map'.
  4356. (let ((map (make-sparse-keymap)))
  4357. (mapc
  4358. (lambda (arg)
  4359. (tool-bar-local-item-from-menu
  4360. (nth 1 arg) (nth 4 arg) map custom-mode-map
  4361. :label (nth 5 arg)))
  4362. custom-commands)
  4363. (setq custom-tool-bar-map map))))
  4364. (make-local-variable 'custom-options)
  4365. (make-local-variable 'custom-local-buffer)
  4366. (custom--initialize-widget-variables)
  4367. (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t))
  4368. (put 'Custom-mode 'mode-class 'special)
  4369. ;; backward-compatibility
  4370. (defun custom-mode ()
  4371. "Non-interactive variant of `Custom-mode'."
  4372. (Custom-mode))
  4373. (make-obsolete 'custom-mode 'Custom-mode "23.1")
  4374. (put 'custom-mode 'mode-class 'special)
  4375. (define-obsolete-variable-alias 'custom-mode-hook 'Custom-mode-hook "23.1")
  4376. (dolist (regexp
  4377. '("^No user option defaults have been changed since Emacs "
  4378. "^Invalid face:? "
  4379. "^No \\(?:customized\\|rogue\\|saved\\) user options"
  4380. "^No customizable items matching "
  4381. "^There are unset changes"
  4382. "^Cannot set hidden variable"
  4383. "^No \\(?:saved\\|backup\\) value for "
  4384. "^No standard setting known for "
  4385. "^No standard setting for this face"
  4386. "^Saving settings from \"emacs -q\" would overwrite existing customizations"))
  4387. (add-to-list 'debug-ignored-errors regexp))
  4388. ;;; The End.
  4389. (provide 'cus-edit)
  4390. ;;; cus-edit.el ends here