You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 11 години
преди 9 години
преди 13 години
преди 12 години
преди 12 години
преди 13 години
преди 11 години
преди 13 години
преди 10 години
преди 10 години
преди 9 години
преди 9 години
преди 9 години
преди 9 години
преди 9 години
преди 9 години
преди 12 години
преди 10 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 10 години
преди 10 години
преди 10 години
преди 12 години
преди 11 години
преди 9 години
преди 9 години
преди 9 години
преди 9 години
преди 10 години
преди 11 години
преди 11 години
преди 11 години
преди 10 години
преди 10 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 13 години
преди 13 години
преди 12 години
преди 12 години
преди 13 години
преди 12 години
преди 13 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 13 години
преди 9 години
преди 9 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 12 години
преди 10 години
преди 12 години
преди 13 години
преди 9 години
преди 9 години
преди 13 години
преди 12 години
преди 13 години
преди 12 години
преди 12 години
преди 10 години
преди 12 години
преди 12 години
преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 11 години
преди 9 години
преди 11 години
преди 10 години
преди 12 години
преди 12 години
преди 12 години
преди 11 години
преди 11 години
преди 9 години
преди 10 години
преди 9 години
преди 9 години
преди 9 години
преди 9 години
преди 11 години
преди 11 години
преди 12 години
преди 9 години
преди 9 години
преди 10 години
преди 10 години
преди 12 години
преди 12 години
преди 10 години
преди 12 години
преди 11 години
преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 11 години
преди 11 години
преди 11 години
преди 13 години
преди 12 години
преди 13 години
преди 13 години
преди 12 години
преди 13 години
преди 13 години
преди 13 години
преди 11 години
преди 12 години
преди 12 години
преди 10 години
преди 13 години
преди 13 години
преди 13 години
преди 12 години
преди 13 години
преди 13 години
преди 12 години
преди 12 години
преди 12 години
преди 13 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 13 години
преди 12 години
преди 13 години
преди 12 години
преди 12 години
преди 13 години
преди 12 години
преди 13 години
преди 9 години
преди 13 години
преди 9 години
преди 9 години
преди 13 години
преди 13 години
преди 12 години
преди 9 години
преди 12 години
преди 10 години
преди 12 години
преди 12 години
преди 13 години
преди 13 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 10 години
преди 12 години
преди 11 години
преди 11 години
преди 13 години
преди 13 години
преди 12 години
преди 12 години
преди 12 години
преди 9 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 12 години
преди 12 години
преди 9 години
преди 12 години
преди 12 години
преди 11 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 10 години
преди 12 години
преди 12 години
преди 10 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 10 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 11 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 11 години
преди 10 години
преди 11 години
преди 9 години
преди 11 години
преди 9 години
преди 9 години
преди 11 години
преди 10 години
преди 11 години
преди 11 години
преди 9 години
преди 11 години
преди 10 години
преди 9 години
преди 11 години
преди 12 години
преди 10 години
преди 12 години
преди 12 години
преди 10 години
преди 12 години
преди 11 години
преди 12 години
преди 12 години
преди 10 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 9 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 11 години
преди 11 години
преди 9 години
преди 11 години
преди 12 години
преди 9 години
преди 12 години
преди 13 години
преди 12 години
преди 13 години
преди 10 години
преди 10 години
преди 11 години
преди 11 години
преди 12 години
преди 9 години
преди 12 години
преди 9 години
преди 11 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 12 години
преди 13 години
преди 12 години
преди 9 години
преди 11 години
преди 12 години
преди 13 години
преди 9 години
преди 13 години
преди 13 години
преди 12 години
преди 13 години
преди 12 години
преди 13 години
преди 12 години
преди 11 години
преди 12 години
преди 10 години
преди 13 години
преди 13 години
преди 13 години
преди 9 години
преди 9 години
преди 12 години
преди 13 години
преди 13 години
преди 13 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 9 години
преди 11 години
преди 9 години
преди 11 години
преди 12 години
преди 9 години
преди 12 години
преди 11 години
преди 13 години
преди 13 години
преди 9 години
преди 12 години
преди 13 години
преди 13 години
преди 12 години
преди 13 години
преди 12 години
преди 10 години
преди 13 години
преди 13 години
преди 12 години
преди 13 години
преди 12 години
преди 13 години
преди 12 години
преди 9 години
преди 12 години
преди 13 години
преди 13 години
преди 13 години
преди 13 години
преди 10 години
преди 9 години
преди 10 години
преди 9 години
преди 10 години
преди 10 години
преди 10 години
преди 9 години
преди 10 години
преди 13 години
преди 9 години
преди 11 години
преди 12 години
преди 11 години
преди 12 години
преди 13 години
преди 9 години
преди 10 години
преди 10 години
преди 13 години
преди 13 години
преди 9 години
преди 10 години
преди 13 години
преди 12 години
преди 12 години
преди 12 години
преди 10 години
преди 12 години
преди 13 години
преди 10 години
преди 13 години
преди 10 години
преди 13 години
преди 13 години
преди 9 години
преди 10 години
преди 9 години
преди 9 години
преди 10 години
преди 13 години
преди 9 години
преди 10 години
преди 12 години
преди 9 години
преди 12 години
преди 9 години
преди 12 години
преди 9 години
преди 12 години
преди 11 години
преди 12 години
преди 10 години
преди 12 години
преди 10 години
преди 12 години
преди 10 години
преди 12 години
преди 10 години
преди 12 години
преди 13 години
преди 13 години
преди 13 години
преди 12 години
преди 9 години
преди 12 години
преди 9 години
преди 12 години
преди 9 години
преди 12 години
преди 9 години
преди 12 години
преди 10 години
преди 12 години
преди 12 години
преди 12 години
преди 9 години
преди 12 години
преди 13 години
преди 9 години
преди 12 години
преди 11 години
преди 10 години
преди 12 години
преди 12 години
преди 9 години
преди 12 години
преди 11 години
преди 12 години
преди 12 години
преди 13 години
преди 13 години
преди 10 години
преди 13 години
преди 10 години
преди 13 години
преди 13 години
преди 12 години
преди 13 години
преди 10 години
преди 10 години
преди 10 години
преди 13 години
преди 9 години
преди 13 години
преди 9 години
преди 13 години
преди 12 години
преди 12 години
преди 13 години
преди 12 години
преди 12 години
преди 12 години
преди 13 години
преди 13 години
преди 12 години
преди 12 години
преди 13 години
преди 13 години
преди 12 години
преди 9 години
преди 9 години
преди 12 години
преди 11 години
преди 13 години
преди 13 години
преди 12 години
преди 12 години
преди 12 години
преди 13 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 9 години
преди 12 години
преди 11 години
преди 12 години
преди 11 години
преди 12 години
преди 9 години
преди 12 години
преди 10 години
преди 12 години
преди 9 години
преди 9 години
преди 9 години
преди 12 години
преди 12 години
преди 12 години
преди 9 години
преди 12 години
преди 9 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 11 години
преди 12 години
преди 12 години
преди 13 години
преди 9 години
преди 13 години
преди 10 години
преди 13 години
преди 12 години
преди 13 години
преди 12 години
преди 9 години
преди 9 години
преди 12 години
преди 13 години
преди 12 години
преди 13 години
преди 12 години
преди 13 години
преди 12 години
преди 12 години
преди 12 години
преди 10 години
преди 12 години
преди 10 години
преди 10 години
преди 10 години
преди 12 години
преди 10 години
преди 10 години
преди 12 години
преди 10 години
преди 12 години
преди 13 години
преди 12 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 9 години
преди 9 години
преди 9 години
преди 9 години
преди 9 години
преди 9 години
преди 10 години
преди 9 години
преди 12 години
преди 10 години
преди 9 години
преди 9 години
преди 10 години
преди 9 години
преди 9 години
преди 10 години
преди 12 години
преди 9 години
преди 12 години
преди 9 години
преди 12 години
преди 9 години
преди 12 години
преди 12 години
преди 12 години
преди 13 години
преди 10 години
преди 10 години
преди 10 години
преди 12 години
преди 11 години
преди 11 години
преди 11 години
преди 10 години
преди 10 години
преди 10 години
преди 12 години
преди 12 години
преди 13 години
преди 9 години
преди 13 години
преди 12 години
преди 13 години
преди 13 години
преди 13 години
преди 12 години
преди 11 години
преди 10 години
преди 11 години
преди 11 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 11 години
преди 10 години
преди 9 години
преди 10 години
преди 11 години
преди 11 години
преди 10 години
преди 9 години
преди 10 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 12 години
преди 10 години
преди 12 години
преди 12 години
преди 12 години
преди 10 години
преди 12 години
преди 12 години
преди 12 години
преди 12 години
преди 10 години
преди 12 години
преди 12 години
преди 12 години
преди 10 години
преди 12 години
преди 13 години
преди 11 години
преди 13 години
преди 11 години
преди 13 години
преди 11 години
преди 13 години
преди 11 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 10 години
преди 11 години
преди 13 години
преди 12 години
преди 13 години
преди 13 години
преди 11 години
преди 12 години
преди 11 години
преди 9 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 11 години
преди 10 години
преди 11 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697
  1. ;;; emacs.el --- 10sr emacs initialization
  2. ;;; Commentary:
  3. ;;; Code:
  4. ;; SETUP_LOAD: (let ((file "DOTFILES_DIR/emacs.el"))
  5. ;; SETUP_LOAD: (and (file-readable-p file)
  6. ;; SETUP_LOAD: (load-file file)))
  7. ;; make directories
  8. (unless (file-directory-p (expand-file-name user-emacs-directory))
  9. (make-directory (expand-file-name user-emacs-directory)))
  10. (let ((d (expand-file-name (concat user-emacs-directory
  11. "lisp"))))
  12. (unless (file-directory-p d)
  13. (make-directory d))
  14. (add-to-list 'load-path d))
  15. (eval-when-compile
  16. (require 'cl nil t))
  17. ;; (add-hook 'after-change-major-mode-hook
  18. ;; (lambda ()
  19. ;; (message "cmm: %S %s"
  20. ;; major-mode
  21. ;; buffer-file-name)))
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23. ;; Some macros for internals
  24. (defun call-after-init (func)
  25. "If `after-init-hook' has been run, call FUNC immediately.
  26. Otherwize hook it."
  27. (if after-init-time
  28. (funcall func)
  29. (add-hook 'after-init-hook
  30. func)))
  31. (defmacro defvar-set (symbol value &optional docstring)
  32. "Define SYMBOL as a variable and set to VALUE.
  33. Variable will be defined with DOCSTRING if given, otherwise do not set even
  34. VALUE when defining SYMBOL."
  35. `(set (if ,docstring
  36. (defvar ,symbol
  37. nil
  38. ,docstring)
  39. (defvar ,symbol))
  40. ,value))
  41. (defmacro safe-require-or-eval (feature)
  42. "Require FEATURE if available.
  43. At compile time the feature will be loaded immediately."
  44. `(eval-and-compile
  45. (require ,feature nil t)))
  46. (defmacro autoload-eval-lazily (feature &optional functions &rest body)
  47. "Define autoloading FEATURE that defines FUNCTIONS.
  48. FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
  49. the function same as FEATURE is defined as autoloaded function. BODY is passed
  50. to `eval-after-load'.
  51. After this macro is expanded, this returns the path to library if FEATURE
  52. found, otherwise returns nil."
  53. (let* ((libname (symbol-name (eval feature)))
  54. (libpath (locate-library libname)))
  55. (and libpath
  56. `(progn
  57. ,@(mapcar (lambda (f)
  58. (unless (fboundp f)
  59. `(progn
  60. (message "Autoloaded function `%S' defined (%s)"
  61. (quote ,f)
  62. ,libpath)
  63. (autoload (quote ,f)
  64. ,libname
  65. ,(concat "Autoloaded function defined in \""
  66. libpath
  67. "\".")
  68. t))))
  69. (or (eval functions)
  70. `(,(eval feature))))
  71. (eval-after-load ,feature
  72. (quote (progn
  73. ,@body)))
  74. (locate-library ,libname)))))
  75. (put 'autoload-eval-lazily 'lisp-indent-function 2)
  76. (when (autoload-eval-lazily 'tetris nil
  77. (message "Tetris loaded!"))
  78. (message "Tetris found!"))
  79. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  80. ;; download library from web
  81. (defvar fetch-library-enabled-p t
  82. "Set nil to skip downloading with `fetch-library'.")
  83. (defun fetch-library (url &optional byte-compile-p force-download-p)
  84. "Download a library from URL and locate it in \"~/emacs.d/lisp/\".
  85. Return nil if library unfound and failed to download,
  86. otherwise the path where the library installed.
  87. If BYTE-COMPILE-P is t byte compile the file after downloading.
  88. If FORCE-DOWNLOAD-P it t ignore exisiting library and always download.
  89. This function also checks the value of `fetch-library-enabled-p' and do not
  90. fetch libraries if this value is nil. In this case all arguments (including
  91. FORCE-DOWNLOAD-P) will be ignored."
  92. (let* ((dir (expand-file-name (concat user-emacs-directory "lisp/")))
  93. (lib (file-name-sans-extension (file-name-nondirectory url)))
  94. (lpath (concat dir lib ".el"))
  95. (locate-p (locate-library lib)))
  96. (if (and fetch-library-enabled-p
  97. (or force-download-p
  98. (not locate-p)))
  99. (if (progn (message "Downloading %s..."
  100. url)
  101. (download-file url
  102. lpath
  103. t))
  104. (progn (message "Downloading %s...done"
  105. url)
  106. (when (and byte-compile-p
  107. (require 'bytecomp nil t))
  108. (and (file-exists-p (byte-compile-dest-file lpath))
  109. (delete-file (byte-compile-dest-file lpath)))
  110. (message "Byte-compiling %s..."
  111. lpath)
  112. (byte-compile-file lpath)
  113. (message "Byte-compiling %s...done"
  114. lpath)))
  115. (progn (and (file-writable-p lpath)
  116. (delete-file lpath))
  117. (message "Downloading %s...failed"
  118. url))))
  119. (locate-library lib)))
  120. ;; If EMACS_EL_DRY_RUN is set and it is not an empty string, fetch-library
  121. ;; does not actually fetch library.
  122. (let ((dryrun (getenv "EMACS_EL_DRY_RUN")))
  123. (when (and dryrun
  124. (< 0
  125. (length dryrun)))
  126. (setq fetch-library-enabled-p
  127. nil)
  128. (message "EMACS_EL_DRY_RUN is set. Skip fetching libraries.")))
  129. (defun download-file (url path &optional ok-if-already-exists)
  130. "Download file from URL and output to PATH.
  131. IF OK-IF-ALREADY-EXISTS is true force download."
  132. (let ((curl (executable-find "curl"))
  133. (wget (executable-find "wget")))
  134. (cond (wget
  135. (if (and (not ok-if-already-exists)
  136. (file-exists-p path))
  137. nil
  138. (and (eq 0
  139. (call-process wget
  140. nil
  141. nil
  142. nil
  143. "-O"
  144. path
  145. url
  146. ))
  147. path)))
  148. (curl
  149. (if (and (not ok-if-already-exists)
  150. (file-exists-p path))
  151. nil
  152. (and (eq 0
  153. (call-process curl
  154. nil
  155. nil
  156. nil
  157. "--output"
  158. path
  159. "-L"
  160. url
  161. ))
  162. path)))
  163. (t
  164. (ignore-errors
  165. (require 'url)
  166. (url-copy-file url
  167. path
  168. ok-if-already-exists)
  169. path)))))
  170. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  171. ;; package
  172. (defvar-set my-package-list
  173. '(
  174. markdown-mode
  175. yaml-mode
  176. gnuplot-mode
  177. erlang
  178. js2-mode
  179. git-commit-mode
  180. gitignore-mode
  181. ;; ack
  182. color-moccur
  183. gtags
  184. flycheck
  185. ;; is flymake installs are required?
  186. ;;flymake-jshint
  187. ;;flymake-python-pyflakes
  188. xclip
  189. foreign-regexp
  190. multi-term
  191. dirtree
  192. term-run
  193. editorconfig
  194. )
  195. "Package list just for me.")
  196. (when (safe-require-or-eval 'package)
  197. ;; (add-to-list 'package-archives
  198. ;; '("ELPA" . "http://tromey.com/elpa/"))
  199. (add-to-list 'package-archives
  200. '("melpa" . "http://melpa.milkbox.net/packages/")
  201. t)
  202. (add-to-list 'package-archives
  203. '("marmalade" . "http://marmalade-repo.org/packages/"))
  204. (package-initialize)
  205. (defun my-auto-install-package ()
  206. "Install packages semi-automatically."
  207. (interactive)
  208. (package-refresh-contents)
  209. (mapc (lambda (pkg)
  210. (or (package-installed-p pkg)
  211. (locate-library (symbol-name pkg))
  212. (package-install pkg)))
  213. my-package-list))
  214. )
  215. ;; (lazy-load-eval 'sudoku)
  216. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  217. ;; my-idle-hook
  218. (defvar my-idle-hook nil
  219. "Hook run when idle for several secs.")
  220. (defvar my-idle-hook-sec 5
  221. "Second to run `my-idle-hook'.")
  222. (run-with-idle-timer my-idle-hook-sec
  223. t
  224. (lambda ()
  225. (run-hooks 'my-idle-hook)))
  226. ;; (add-hook 'my-idle-hook
  227. ;; (lambda ()
  228. ;; (message "idle hook message")))
  229. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  230. ;; start and quit
  231. (setq inhibit-startup-message t)
  232. (setq confirm-kill-emacs 'y-or-n-p)
  233. (setq gc-cons-threshold (* 1024 1024 4))
  234. (when window-system
  235. (add-to-list 'default-frame-alist '(cursor-type . box))
  236. (add-to-list 'default-frame-alist '(background-color . "white"))
  237. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  238. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  239. ;; does not work?
  240. )
  241. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  242. (if window-system (menu-bar-mode 1) (menu-bar-mode 0))
  243. (and (fboundp 'tool-bar-mode)
  244. (tool-bar-mode 0))
  245. (and (fboundp 'set-scroll-bar-mode)
  246. (set-scroll-bar-mode nil))
  247. (add-hook 'kill-emacs-hook
  248. ;; load init file when terminating emacs to ensure file is not broken
  249. 'reload-init-file)
  250. (defun my-force-kill-emacs ()
  251. "My force kill Emacs."
  252. (interactive)
  253. (let ((kill-emacs-hook nil))
  254. (kill-emacs)))
  255. (call-after-init
  256. (lambda ()
  257. (message "%s %s" invocation-name emacs-version)
  258. (message "%s was taken to initialize emacs." (emacs-init-time))
  259. (switch-to-buffer "*Messages*")))
  260. (cd ".") ; when using windows use / instead of \ in `default-directory'
  261. ;; locale
  262. (set-language-environment "Japanese")
  263. (set-default-coding-systems 'utf-8-unix)
  264. (prefer-coding-system 'utf-8-unix)
  265. (setq system-time-locale "C")
  266. ;; my prefix map
  267. (defvar my-prefix-map nil
  268. "My prefix map.")
  269. (define-prefix-command 'my-prefix-map)
  270. (define-key ctl-x-map (kbd "C-x") 'my-prefix-map)
  271. (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  272. (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  273. ;; (comint-show-maximum-output)
  274. ;; kill scratch
  275. (call-after-init (lambda ()
  276. (let ((buf (get-buffer "*scratch*")))
  277. (when buf
  278. (kill-buffer buf)))))
  279. ;; modifier keys
  280. ;; (setq mac-option-modifier 'control)
  281. ;; display
  282. (setq redisplay-dont-pause t)
  283. (setq visible-bell t)
  284. (setq ring-bell-function 'ignore)
  285. (mouse-avoidance-mode 'banish)
  286. (and window-system
  287. (fetch-library
  288. "https://raw.github.com/10sr/emacs-lisp/master/save-window-size.el"
  289. t)
  290. (safe-require-or-eval 'save-window-size))
  291. (defun reload-init-file ()
  292. "Reload Emacs init file."
  293. (interactive)
  294. (when (and user-init-file
  295. (file-readable-p user-init-file))
  296. (load-file user-init-file)))
  297. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  298. ;; for windows
  299. (defun start-ckw-bash ()
  300. "Start ckw in windows."
  301. (interactive)
  302. (start-process
  303. "ckw_bash"
  304. nil
  305. "C:/Documents and Settings/sr/Application Data/dbx/apps/ckw/ckw.exe"))
  306. ;; command seems to have to be in c drive
  307. (defun my-w32-add-export-path (&rest args)
  308. "Add pathes ARGS for windows."
  309. (mapc (lambda (path)
  310. (add-to-list 'exec-path (expand-file-name path)))
  311. (reverse args))
  312. (setenv "PATH"
  313. (mapconcat 'convert-standard-filename
  314. exec-path
  315. ";")))
  316. (when (eq system-type 'windows-nt)
  317. ;; (setq scheme-program-name "\"c:/Program Files/Gauche/bin/gosh.exe\" -i")
  318. ;; (setq python-python-command "c:/Python26/python.exe")
  319. ;; (define-key my-prefix-map (kbd "C-c") 'start-ckw-bash)
  320. (my-w32-add-export-path "c:/Windows/system"
  321. "c:/Windows/System32"
  322. "c:/Program Files/Git/bin"
  323. "c:/MinGW/bin"
  324. "c:/MinGW/mingw32/bin"
  325. (expand-file-name "~/.local/bin")
  326. (expand-file-name "~/dbx/apps/bin"))
  327. (when window-system
  328. (defvar-set w32-enable-synthesized-fonts t))
  329. (defvar-set w32-apps-modifier 'meta)
  330. (setq file-name-coding-system 'sjis))
  331. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  332. ;; global keys
  333. (global-set-key (kbd "<up>") 'scroll-down-line)
  334. (global-set-key (kbd "<down>") 'scroll-up-line)
  335. (global-set-key (kbd "<left>") 'scroll-down)
  336. (global-set-key (kbd "<right>") 'scroll-up)
  337. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  338. (global-set-key (kbd "C-\\") help-map)
  339. (define-key ctl-x-map (kbd "DEL") help-map)
  340. (define-key ctl-x-map (kbd "C-h") help-map)
  341. (define-key help-map "a" 'apropos)
  342. ;; disable annoying keys
  343. (global-set-key [prior] 'ignore)
  344. (global-set-key (kbd "<next>") 'ignore)
  345. (global-set-key [menu] 'ignore)
  346. (global-set-key [down-mouse-1] 'ignore)
  347. (global-set-key [down-mouse-2] 'ignore)
  348. (global-set-key [down-mouse-3] 'ignore)
  349. (global-set-key [mouse-1] 'ignore)
  350. (global-set-key [mouse-2] 'ignore)
  351. (global-set-key [mouse-3] 'ignore)
  352. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  353. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  354. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  355. ;; title and mode-line
  356. (when (and (fetch-library
  357. "https://raw.github.com/10sr/emacs-lisp/master/terminal-title.el"
  358. t)
  359. (safe-require-or-eval 'terminal-title))
  360. ;; if TERM is not screen use default value
  361. (if (getenv "TMUX")
  362. ;; if use tmux locally just basename of current dir
  363. (defvar-set terminal-title-format
  364. '((file-name-nondirectory (directory-file-name
  365. default-directory))))
  366. (if (and (let ((tty-type (frame-parameter nil
  367. 'tty-type)))
  368. (and tty-type
  369. (equal (car (split-string tty-type
  370. "-"))
  371. "screen")))
  372. (not (getenv "SSH_CONNECTION")))
  373. (defvar-set terminal-title-format
  374. '((file-name-nondirectory (directory-file-name
  375. default-directory))))
  376. ;; seems that TMUX is used locally and ssh to remote host
  377. (defvar-set terminal-title-format
  378. `("em:"
  379. ,user-login-name
  380. "@"
  381. ,(car (split-string system-name
  382. "\\."))
  383. ":"
  384. default-directory))
  385. )
  386. )
  387. (terminal-title-mode))
  388. (setq eol-mnemonic-dos "\\r\\n")
  389. (setq eol-mnemonic-mac "\\r")
  390. (setq eol-mnemonic-unix "\\n")
  391. (which-function-mode 0)
  392. (line-number-mode 0)
  393. (column-number-mode 0)
  394. (size-indication-mode 0)
  395. (setq mode-line-position
  396. '(:eval (format "L%%l/%d,C%%c"
  397. (count-lines (point-max)
  398. (point-min)))))
  399. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  400. ;; display date
  401. (call-after-init (lambda ()
  402. (when display-time-mode
  403. (display-time-update))))
  404. (when (safe-require-or-eval 'time)
  405. (setq display-time-interval 29)
  406. (setq display-time-day-and-date t)
  407. (setq display-time-format "%a, %d %b %Y %T")
  408. (if window-system
  409. (display-time-mode 0)
  410. (display-time-mode 1)))
  411. ;; ;; current directory
  412. ;; (let ((ls (member 'mode-line-buffer-identification
  413. ;; mode-line-format)))
  414. ;; (setcdr ls
  415. ;; (cons '(:eval (concat " ("
  416. ;; (abbreviate-file-name default-directory)
  417. ;; ")"))
  418. ;; (cdr ls))))
  419. ;; ;; display last modified time
  420. ;; (let ((ls (member 'mode-line-buffer-identification
  421. ;; mode-line-format)))
  422. ;; (setcdr ls
  423. ;; (cons '(:eval (concat " "
  424. ;; my-buffer-file-last-modified-time))
  425. ;; (cdr ls))))
  426. (defun buffer-list-not-start-with-space ()
  427. "Return a list of buffers that not start with whitespaces."
  428. (let ((bl (buffer-list))
  429. b nbl)
  430. (while bl
  431. (setq b (pop bl))
  432. (unless (string-equal " "
  433. (substring (buffer-name b)
  434. 0
  435. 1))
  436. (add-to-list 'nbl b)))
  437. nbl))
  438. ;; http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/
  439. ;; (add-to-list 'minor-mode-alist
  440. ;; '(global-whitespace-mode ""))
  441. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  442. ;; system info
  443. (defun my-message-current-info ()
  444. "Echo current login name, hostname and directory."
  445. (interactive)
  446. (message "%s@%s:%s"
  447. user-login-name
  448. system-name
  449. (abbreviate-file-name default-directory)))
  450. ;; (run-with-idle-timer 3
  451. ;; t
  452. ;; 'my-message-current-info)
  453. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  454. ;; minibuffer
  455. (setq insert-default-directory t)
  456. (setq completion-ignore-case t
  457. read-file-name-completion-ignore-case t
  458. read-buffer-completion-ignore-case t)
  459. (setq resize-mini-windows t)
  460. (temp-buffer-resize-mode 1)
  461. (savehist-mode 1)
  462. (fset 'yes-or-no-p 'y-or-n-p)
  463. ;; complete symbol when `eval'
  464. (define-key read-expression-map (kbd "TAB") 'lisp-complete-symbol)
  465. (define-key minibuffer-local-map (kbd "C-u")
  466. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  467. ;; I dont know these bindings are good
  468. (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
  469. (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
  470. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  471. ;; letters, font-lock mode and fonts
  472. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  473. ;; (set-window-margins (selected-window) 1 1)
  474. (and (or (eq system-type 'Darwin)
  475. (eq system-type 'darwin))
  476. (fboundp 'mac-set-input-method-parameter)
  477. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  478. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  479. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  480. (boundp 'input-method-inactivate-hook))
  481. (add-hook 'input-method-activate-hook
  482. (lambda () (set-cursor-color "red")))
  483. (add-hook 'input-method-inactivate-hook
  484. (lambda () (set-cursor-color "black"))))
  485. (when (safe-require-or-eval 'paren)
  486. (show-paren-mode 1)
  487. (setq show-paren-delay 0.5
  488. show-paren-style 'parenthesis) ; mixed is hard to read
  489. ;; (set-face-background 'show-paren-match
  490. ;; "black")
  491. ;; ;; (face-foreground 'default))
  492. ;; (set-face-foreground 'show-paren-match
  493. ;; "white")
  494. ;; (set-face-inverse-video-p 'show-paren-match
  495. ;; t)
  496. )
  497. (transient-mark-mode 1)
  498. (global-font-lock-mode 1)
  499. (setq font-lock-global-modes
  500. '(not
  501. help-mode
  502. eshell-mode
  503. term-mode
  504. Man-mode))
  505. ;; (standard-display-ascii ?\n "$\n")
  506. (defvar my-eol-face
  507. '(("\n" . (0 font-lock-comment-face t nil)))
  508. )
  509. (defvar my-tab-face
  510. '(("\t" . '(0 highlight t nil))))
  511. (defvar my-jspace-face
  512. '(("\u3000" . '(0 highlight t nil))))
  513. (add-hook 'font-lock-mode-hook
  514. (lambda ()
  515. ;; (font-lock-add-keywords nil my-eol-face)
  516. (font-lock-add-keywords nil my-jspace-face)
  517. ))
  518. (when (safe-require-or-eval 'whitespace)
  519. (add-to-list 'whitespace-display-mappings ; not work
  520. `(tab-mark ?\t ,(vconcat "^I\t")))
  521. (add-to-list 'whitespace-display-mappings
  522. `(newline-mark ?\n ,(vconcat "$\n")))
  523. (setq whitespace-style '(face
  524. trailing ; trailing blanks
  525. newline ; newlines
  526. newline-mark ; use display table for newline
  527. ;; tab-mark
  528. empty ; empty lines at beg or end of buffer
  529. lines-tail ; lines over 80
  530. ))
  531. ;; (setq whitespace-newline 'font-lock-comment-face)
  532. (global-whitespace-mode t)
  533. (if (eq (display-color-cells)
  534. 256)
  535. (set-face-foreground 'whitespace-newline "brightblack")
  536. ;; (progn
  537. ;; (set-face-bold-p 'whitespace-newline
  538. ;; t))
  539. ))
  540. (and nil
  541. (fetch-library
  542. "http://www.emacswiki.org/emacs/download/fill-column-indicator.el"
  543. t)
  544. (safe-require-or-eval 'fill-column-indicator)
  545. (setq fill-column-indicator))
  546. ;; highlight current line
  547. ;; http://wiki.riywo.com/index.php?Meadow
  548. (defface my-hl-line
  549. '((((min-colors 256)
  550. (background dark))
  551. (:background "color-234"))
  552. (((min-colors 256)
  553. (background light))
  554. (:background "color-234"))
  555. (t
  556. (:underline "black")))
  557. "*Face used by hl-line.")
  558. (defvar-set hl-line-face 'my-hl-line) ;; (setq hl-line-face nil)
  559. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  560. (defvar-set hl-line-global-modes
  561. '(not
  562. term-mode))
  563. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  564. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  565. ;; fonts
  566. (defun my-set-ascii-and-jp-font (list)
  567. "Set font configuration to LIST."
  568. (let ((fspec1 (if (> emacs-major-version 22)
  569. ;; font spec is available in emacs23 and later
  570. (font-spec :family (nth 2 list) :size (nth 3 list))
  571. (cons (nth 2 list) "jisx0208.*")))
  572. (fspec2 (if (> emacs-major-version 22)
  573. (font-spec :family (nth 2 list) :size (nth 3 list))
  574. (cons (nth 2 list) "jisx0201.*"))))
  575. (set-face-attribute 'default nil
  576. :family (nth 0 list)
  577. :height (nth 1 list))
  578. (set-fontset-font "fontset-default"
  579. 'japanese-jisx0208
  580. fspec1)
  581. (set-fontset-font "fontset-default"
  582. 'katakana-jisx0201
  583. fspec2)))
  584. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 90 "takaogothic" 13))
  585. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 100 "takaogothic" 14))
  586. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 100 "ms gothic" 14))
  587. ;; (my-set-ascii-and-jp-font '("monaco" 75 "takaogothic" 11))
  588. ;; (my-set-ascii-and-jp-font '("monaco" 90 "takaogothic" 13))
  589. ;; (my-set-ascii-and-jp-font '("ProggyCleanTTSZ" 120 "takaogothic" 11))
  590. ;; あ a
  591. (and (fetch-library
  592. "https://raw.github.com/10sr/emacs-lisp/master/set-modeline-color.el"
  593. t)
  594. (progn
  595. (safe-require-or-eval 'set-modeline-color)))
  596. (let ((fg (face-foreground 'default))
  597. (bg (face-background 'default)))
  598. (set-face-background 'mode-line-inactive
  599. (if (face-inverse-video-p 'mode-line) fg bg))
  600. (set-face-foreground 'mode-line-inactive
  601. (if (face-inverse-video-p 'mode-line) bg fg)))
  602. (set-face-underline 'mode-line-inactive
  603. t)
  604. (set-face-underline 'vertical-border
  605. nil)
  606. (and (fetch-library
  607. "https://raw.github.com/tarao/elisp/master/end-mark.el"
  608. t)
  609. (safe-require-or-eval 'end-mark)
  610. (global-end-mark-mode))
  611. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  612. ;; file handling
  613. (setq revert-without-query '(".+"))
  614. ;; save cursor position
  615. (when (safe-require-or-eval 'saveplace)
  616. (setq-default save-place t)
  617. (setq save-place-file (concat user-emacs-directory
  618. "places")))
  619. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  620. (setq make-backup-files t)
  621. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  622. (setq backup-directory-alist
  623. (cons (cons "\\.*$" (expand-file-name (concat user-emacs-directory
  624. "backup")))
  625. backup-directory-alist))
  626. (setq version-control 'never)
  627. (setq delete-old-versions t)
  628. (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
  629. "auto-save/")))
  630. (setq delete-auto-save-files t)
  631. (add-to-list 'completion-ignored-extensions ".bak")
  632. ;; (setq delete-by-moving-to-trash t
  633. ;; trash-directory "~/.emacs.d/trash")
  634. (add-hook 'after-save-hook
  635. 'executable-make-buffer-file-executable-if-script-p)
  636. (defvar-set bookmark-default-file (concat user-emacs-directory
  637. "bmk"))
  638. (add-hook 'recentf-load-hook
  639. (lambda ()
  640. (defvar recentf-exclude)
  641. (add-to-list 'recentf-exclude
  642. (regexp-quote bookmark-default-file))))
  643. (and (fetch-library
  644. "https://raw.github.com/10sr/emacs-lisp/master/read-only-only-mode.el"
  645. t)
  646. (autoload-eval-lazily 'read-only-only-mode))
  647. (and (fetch-library
  648. "https://raw.github.com/10sr/emacs-lisp/master/smart-revert.el"
  649. t)
  650. (safe-require-or-eval 'smart-revert)
  651. (smart-revert-on))
  652. ;; autosave
  653. (and (fetch-library
  654. "https://raw.github.com/10sr/emacs-lisp/master/autosave.el"
  655. t)
  656. (safe-require-or-eval 'autosave)
  657. (autosave-set 2))
  658. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  659. ;; editting
  660. (defun my-copy-whole-line ()
  661. "Copy whole line."
  662. (interactive)
  663. (kill-new (concat (buffer-substring (point-at-bol)
  664. (point-at-eol))
  665. "\n")))
  666. (setq require-final-newline t)
  667. (setq kill-whole-line t)
  668. (setq scroll-conservatively 35
  669. scroll-margin 2
  670. scroll-step 0)
  671. (setq-default major-mode 'text-mode)
  672. (setq next-line-add-newlines nil)
  673. (setq kill-read-only-ok t)
  674. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  675. ;; (setq-default line-spacing 0.2)
  676. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  677. (setq-default tab-width 4)
  678. (setq-default indent-tabs-mode nil)
  679. (setq-default indent-line-function nil)
  680. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  681. (delete-selection-mode 1)
  682. (cua-mode 0)
  683. (setq line-move-visual nil)
  684. ;; key bindings
  685. ;; moving around
  686. ;; (global-set-key (kbd "M-j") 'next-line)
  687. ;; (global-set-key (kbd "M-k") 'previous-line)
  688. ;; (global-set-key (kbd "M-h") 'backward-char)
  689. ;; (global-set-key (kbd "M-l") 'forward-char)
  690. ;;(keyboard-translate ?\M-j ?\C-j)
  691. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  692. (define-key esc-map "p" 'backward-paragraph)
  693. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  694. (define-key esc-map "n" 'forward-paragraph)
  695. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  696. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  697. (global-set-key (kbd "C-<left>") 'scroll-down)
  698. (global-set-key (kbd "C-<right>") 'scroll-up)
  699. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  700. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  701. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  702. ;; C-h and DEL
  703. (global-set-key (kbd "C-h") (kbd "DEL"))
  704. (global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  705. (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  706. (define-key esc-map "k" 'my-copy-whole-line)
  707. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  708. (define-key esc-map "u" 'undo)
  709. (define-key esc-map "i" (kbd "ESC TAB"))
  710. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  711. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  712. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  713. (define-key my-prefix-map (kbd "C-o") 'occur)
  714. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  715. ;; japanese input method
  716. (defun my-load-scim ()
  717. "Use scim-bridge.el as japanese im."
  718. ;; Load scim-bridge.
  719. (when (safe-require-or-eval 'scim-bridge)
  720. ;; Turn on scim-mode automatically after loading .emacs
  721. (call-after-init 'scim-mode-on)
  722. (defvar-set scim-cursor-color "red")
  723. (scim-define-preedit-key ?\^h t)
  724. (scim-define-common-key ?\* nil)
  725. (scim-define-common-key ?\^/ nil)))
  726. (defun my-load-anthy ()
  727. "Use anthy.el as japanese im."
  728. ;; anthy
  729. (when (safe-require-or-eval 'anthy)
  730. (global-set-key
  731. (kbd "<muhenkan>") (lambda () (interactive) (anthy-mode-off)))
  732. (global-set-key (kbd "<henkan>") (lambda () (interactive) (anthy-mode-on)))
  733. (when (>= emacs-major-version 23)
  734. (defvar-set anthy-accept-timeout 1))))
  735. ;; quail
  736. ;; aproposs input-method for some information
  737. ;; (setq default-input-method "japanese")
  738. (defun my-load-mozc-el ()
  739. "Use mozc.el as japanese im."
  740. (when (safe-require-or-eval 'mozc)
  741. (defvar-set defauit-input-method "japanese-mozc")
  742. (defvar-set mozc-leim-title "[MZ]")
  743. ))
  744. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  745. ;; gmail
  746. (setq mail-interactive t
  747. send-mail-function 'smtpmail-send-it
  748. ;; message-send-mail-function 'smtpmail-send-it
  749. smtpmail-smtp-server "smtp.gmail.com"
  750. smtpmail-smtp-service 587
  751. smtpmail-starttls-credentials '(("smtp.gmail.com" 587
  752. "8.slashes@gmail.com" nil))
  753. smtpmail-auth-credentials '(("smtp.gmail.com" 587
  754. "8.slashes@gmail.com" nil))
  755. user-mail-address "8.slashes@gmail.com")
  756. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  757. ;; buffer killing
  758. ;; (defun my-delete-window-killing-buffer () nil)
  759. (defun my-query-kill-current-buffer ()
  760. "Interactively kill current buffer."
  761. (interactive)
  762. (if (y-or-n-p (concat "kill current buffer? :"))
  763. (kill-buffer (current-buffer))))
  764. (substitute-key-definition 'kill-buffer
  765. 'my-query-kill-current-buffer
  766. global-map)
  767. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  768. (defun my-kill-buffers ()
  769. "Kill buffers that visit files."
  770. (interactive)
  771. (mapcar (lambda (buf)
  772. (when (buffer-file-name buf)
  773. (kill-buffer buf)))
  774. (buffer-list)))
  775. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  776. ;; share clipboard with x
  777. ;; this page describes this in details, but only these sexps seem to be needed
  778. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  779. (and (not window-system)
  780. (not (eq window-system 'mac))
  781. (getenv "DISPLAY")
  782. (not (equal (getenv "DISPLAY") ""))
  783. (executable-find "xclip")
  784. ;; (< emacs-major-version 24)
  785. (safe-require-or-eval 'xclip)
  786. nil
  787. (turn-on-xclip))
  788. (and (eq system-type 'darwin)
  789. (fetch-library
  790. "https://raw.github.com/10sr/emacs-lisp/master/pasteboard.el"
  791. t)
  792. (safe-require-or-eval 'pasteboard)
  793. (turn-on-pasteboard)
  794. (getenv "TMUX")
  795. (pasteboard-enable-rtun))
  796. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  797. ;; https://github.com/lunaryorn/flycheck
  798. (when (safe-require-or-eval 'flycheck)
  799. (call-after-init 'global-flycheck-mode))
  800. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  801. ;; window
  802. '(and (fetch-library
  803. "https://raw.github.com/10sr/emacs-lisp/master/window-organizer.el"
  804. t)
  805. (autoload-eval-lazily 'window-organizer)
  806. (define-key ctl-x-map (kbd "w") 'window-organizer))
  807. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  808. ;; server
  809. (when (safe-require-or-eval 'server)
  810. (setq server-name (concat "server"
  811. (number-to-string (emacs-pid))))
  812. ;; In Cygwin Environment `server-runnning-p' stops when server-use-tcp is nil
  813. ;; In Darwin environment, init fails with message like 'Service name too long'
  814. ;; when server-use-tcp is nil
  815. (when (or (eq system-type
  816. 'cygwin)
  817. (eq system-type
  818. 'darwin))
  819. (setq server-use-tcp t))
  820. (defun my-construct-emacsclient-editor-command ()
  821. "Construct and return command in a string to connect to current Emacs server."
  822. (if server-use-tcp
  823. (format "%s -f \"%s/%s\""
  824. "emacsclient"
  825. (expand-file-name server-auth-dir)
  826. server-name)
  827. (format "%s -s \"%s/%s\""
  828. "emacsclient"
  829. server-socket-dir
  830. server-name)))
  831. (setq process-environment
  832. `(,(concat "EDITOR="
  833. (my-construct-emacsclient-editor-command))
  834. ,(concat "GIT_EDITOR="
  835. (my-construct-emacsclient-editor-command))
  836. ,@process-environment))
  837. (server-start))
  838. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  839. ;; some modes and hooks
  840. (add-to-list 'safe-local-variable-values
  841. '(encoding utf-8))
  842. (setq enable-local-variables :safe)
  843. (when (autoload-eval-lazily 'dirtree nil
  844. (defun my-dirtree-current-line-directory-p ()
  845. "Return nil if element on current line is not a directory."
  846. (file-directory-p (widget-get (tree-mode-button-current-line)
  847. :file)))
  848. ;; This fix is actually a little strange. Strictly speaking
  849. ;; judging tree should be done by whether the widget is a tree one.
  850. (defun my-dirtree-next-node (arg)
  851. "Fix the problem that `tree-mode-next-node' moves cursor 2 lines."
  852. (interactive "p")
  853. (if (my-dirtree-current-line-directory-p)
  854. (widget-forward (* arg 2))
  855. (widget-forward arg)))
  856. (defun my-dirtree-previous-node (arg)
  857. "Fix the problem that `tree-mode-previous-node' moves cursor 2 lines."
  858. (interactive "p")
  859. (my-dirtree-next-node (- arg)))
  860. (define-key dirtree-mode-map "n" 'my-dirtree-next-node)
  861. (define-key dirtree-mode-map "p" 'my-dirtree-previous-node))
  862. (define-key ctl-x-map "d" 'dirtree))
  863. (and (fetch-library
  864. "https://raw.github.com/10sr/emacs-lisp/master/remember-major-modes-mode.el"
  865. t)
  866. (safe-require-or-eval 'remember-major-modes-mode)
  867. (remember-major-modes-mode 1)
  868. )
  869. ;; Detect file type from shebang and set major-mode.
  870. (add-to-list 'interpreter-mode-alist
  871. '("python3" . python-mode))
  872. (add-to-list 'interpreter-mode-alist
  873. '("python2" . python-mode))
  874. ;; http://fukuyama.co/foreign-regexp
  875. '(and (safe-require-or-eval 'foreign-regexp)
  876. (progn
  877. (setq foreign-regexp/regexp-type 'perl)
  878. '(setq reb-re-syntax 'foreign-regexp)
  879. ))
  880. (safe-require-or-eval 'session)
  881. (autoload-eval-lazily 'sql '(sql-mode)
  882. (safe-require-or-eval 'sql-indent))
  883. '(and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/gtkbm.el"
  884. t)
  885. (autoload-eval-lazily 'gtkbm)
  886. (global-set-key (kbd "C-x C-d") 'gtkbm))
  887. (and (fetch-library
  888. "https://raw.github.com/10sr/git-command-el/master/git-command.el"
  889. t)
  890. (autoload-eval-lazily 'git-command
  891. nil
  892. ;; for git-command old version
  893. (when (boundp 'git-command-major-mode-alist)
  894. (message "You are using old git-command ! Update it !!!")
  895. (add-to-list 'git-command-major-mode-alist
  896. '("di" . diff-mode))
  897. (add-to-list 'git-command-major-mode-alist
  898. '("graph" . fundamental-mode))
  899. (add-to-list 'git-command-major-mode-alist
  900. '("log" . fundamental-mode)))
  901. ;; for git-command new version
  902. (when (boundp 'git-command-view-command-list)
  903. (add-to-list 'git-command-view-command-list
  904. "graph")
  905. (add-to-list 'git-command-view-command-list
  906. "blame")
  907. (add-to-list 'git-command-view-command-list
  908. "help"))
  909. (when (boundp 'git-command-aliases-alist)
  910. ;; (message "new version of git-command!")
  911. (add-to-list 'git-command-aliases-alist
  912. '("di" . (lambda (options cmd args new-buffer-p)
  913. (git-command-exec options
  914. "diff"
  915. args
  916. new-buffer-p))))
  917. (add-to-list 'git-command-aliases-alist
  918. '("grep" . (lambda (options cmd args new-buffer-p)
  919. (my-rgrep
  920. (concat
  921. "git "
  922. (git-command-construct-commandline
  923. `(,@options "--no-pager"
  924. "-c" "color.grep=false")
  925. cmd
  926. `("-nHe" ,@args))))))))
  927. (setq git-command-use-emacsclient t)
  928. (or git-command-prompt-file
  929. (setq git-command-prompt-file
  930. (git-command-find-git-ps1
  931. "/usr/share/git-core/contrib/completion/git-prompt.sh"))))
  932. ;; (setq git-command-default-options "-c color.ui=always")
  933. (define-key ctl-x-map "g" 'git-command))
  934. (and (fetch-library
  935. "http://www.emacswiki.org/emacs/download/sl.el"
  936. t)
  937. (autoload-eval-lazily 'sl))
  938. (defalias 'qcalc 'quick-calc)
  939. (safe-require-or-eval 'simple)
  940. (add-hook 'makefile-mode-hook
  941. (lambda ()
  942. (local-set-key (kbd "C-m") 'newline-and-indent)
  943. ;; this functions is set in write-file-functions, i cannot find any
  944. ;; good way to remove this.
  945. (fset 'makefile-warn-suspicious-lines 'ignore)
  946. ))
  947. (add-hook 'verilog-mode-hook
  948. (lambda ()
  949. (local-set-key ";" 'self-insert-command)))
  950. (setq diff-switches "-u")
  951. (add-hook 'diff-mode-hook
  952. (lambda ()
  953. ;; (when (and (eq major-mode
  954. ;; 'diff-mode)
  955. ;; (not buffer-file-name))
  956. ;; ;; do not pass when major-mode is derived mode of diff-mode
  957. ;; (view-mode 1))
  958. (set-face-attribute 'diff-header nil
  959. :foreground nil
  960. :background nil
  961. :weight 'bold)
  962. (set-face-attribute 'diff-file-header nil
  963. :foreground nil
  964. :background nil
  965. :weight 'bold)
  966. (set-face-foreground 'diff-index-face "blue")
  967. (set-face-attribute 'diff-hunk-header nil
  968. :foreground "cyan"
  969. :weight 'normal)
  970. (set-face-attribute 'diff-context nil
  971. ;; :foreground "white"
  972. :foreground nil
  973. :weight 'normal)
  974. (set-face-foreground 'diff-removed-face "red")
  975. (set-face-foreground 'diff-added-face "green")
  976. (set-face-background 'diff-removed-face nil)
  977. (set-face-background 'diff-added-face nil)
  978. (set-face-attribute 'diff-changed nil
  979. :foreground "magenta"
  980. :weight 'normal)
  981. (set-face-attribute 'diff-refine-change nil
  982. :foreground nil
  983. :background nil
  984. :weight 'bold
  985. :inverse-video t)
  986. ;; Annoying !
  987. ;;(diff-auto-refine-mode)
  988. ))
  989. ;; (ffap-bindings)
  990. (add-hook 'sh-mode-hook
  991. (lambda ()
  992. (local-set-key
  993. (kbd "C-x C-e")
  994. 'my-execute-shell-command-current-line)))
  995. (defvar-set sh-here-document-word "__EOC__")
  996. (defun my-execute-shell-command-current-line ()
  997. "Run current line as shell command."
  998. (interactive)
  999. (shell-command (buffer-substring-no-properties (point-at-bol)
  1000. (point))))
  1001. (setq auto-mode-alist
  1002. `(("autostart\\'" . sh-mode)
  1003. ("xinitrc\\'" . sh-mode)
  1004. ("xprograms\\'" . sh-mode)
  1005. ("PKGBUILD\\'" . sh-mode)
  1006. ,@auto-mode-alist))
  1007. (and (autoload-eval-lazily 'pkgbuild-mode)
  1008. (setq auto-mode-alist (append '(("PKGBUILD\\'" . pkgbuild-mode))
  1009. auto-mode-alist)))
  1010. (add-hook 'yaml-mode-hook
  1011. (lambda ()
  1012. (local-set-key(kbd "C-m") 'newline)))
  1013. (add-hook 'html-mode-hook
  1014. (lambda ()
  1015. (local-set-key(kbd "C-m") 'reindent-then-newline-and-indent)))
  1016. (add-hook 'text-mode-hook
  1017. (lambda ()
  1018. (local-set-key (kbd "C-m") 'newline)))
  1019. (add-to-list 'Info-default-directory-list
  1020. (expand-file-name "~/.info/emacs-ja"))
  1021. (add-hook 'apropos-mode-hook
  1022. (lambda ()
  1023. (local-set-key "n" 'next-line)
  1024. (local-set-key "p" 'previous-line)
  1025. ))
  1026. (add-hook 'isearch-mode-hook
  1027. (lambda ()
  1028. ;; (define-key isearch-mode-map
  1029. ;; (kbd "C-j") 'isearch-other-control-char)
  1030. ;; (define-key isearch-mode-map
  1031. ;; (kbd "C-k") 'isearch-other-control-char)
  1032. ;; (define-key isearch-mode-map
  1033. ;; (kbd "C-h") 'isearch-other-control-char)
  1034. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  1035. (define-key isearch-mode-map (kbd "M-r")
  1036. 'isearch-query-replace-regexp)))
  1037. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  1038. (setq lazy-highlight-cleanup nil)
  1039. ;; face for isearch highlighing
  1040. (set-face-attribute 'lazy-highlight
  1041. nil
  1042. :foreground `unspecified
  1043. :background `unspecified
  1044. :underline t
  1045. ;; :weight `bold
  1046. )
  1047. (add-hook 'outline-mode-hook
  1048. (lambda ()
  1049. (if (string-match "\\.md\\'" buffer-file-name)
  1050. (set (make-local-variable 'outline-regexp) "#+ "))))
  1051. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  1052. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  1053. (when (autoload-eval-lazily 'markdown-mode
  1054. '(markdown-mode gfm-mode))
  1055. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  1056. (setq markdown-command (or (executable-find "markdown")
  1057. (executable-find "markdown.pl")))
  1058. (add-hook 'markdown-mode-hook
  1059. (lambda ()
  1060. (outline-minor-mode 1)
  1061. (flyspell-mode)
  1062. (set (make-local-variable 'comment-start) ";"))))
  1063. ;; c-mode
  1064. ;; http://www.emacswiki.org/emacs/IndentingC
  1065. ;; http://en.wikipedia.org/wiki/Indent_style
  1066. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  1067. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  1068. (when (autoload-eval-lazily 'cc-vars
  1069. nil
  1070. (defvar c-default-style)
  1071. (add-to-list 'c-default-style
  1072. '(c-mode . "k&r"))
  1073. (add-to-list 'c-default-style
  1074. '(c++-mode . "k&r"))
  1075. (add-hook 'c-mode-common-hook
  1076. (lambda ()
  1077. ;; why c-basic-offset in k&r style defaults to 5 ???
  1078. (defvar-set c-basic-offset 4)
  1079. (defvar-set indent-tabs-mode nil)
  1080. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  1081. (c-toggle-hungry-state -1)
  1082. ;; (and (require 'gtags nil t)
  1083. ;; (gtags-mode 1))
  1084. ))))
  1085. (when (autoload-eval-lazily 'php-mode)
  1086. (add-hook 'php-mode-hook
  1087. (lambda ()
  1088. (setq c-basic-offset 2))))
  1089. (when (autoload-eval-lazily 'js2-mode)
  1090. ;; currently do not use js2-mode
  1091. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  1092. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  1093. (add-hook 'js2-mode-hook
  1094. (lambda ()
  1095. (define-key js2-mode-map (kbd "C-m") (lambda ()
  1096. (interactive)
  1097. (js2-enter-key)
  1098. (indent-for-tab-command)))
  1099. ;; (add-hook (kill-local-variable 'before-save-hook)
  1100. ;; 'js2-before-save)
  1101. ;; (add-hook 'before-save-hook
  1102. ;; 'my-indent-buffer
  1103. ;; nil
  1104. ;; t)
  1105. )))
  1106. (eval-after-load "js"
  1107. (defvar-set js-indent-level 2))
  1108. (add-to-list 'interpreter-mode-alist
  1109. '("node" . js-mode))
  1110. (when (autoload-eval-lazily 'flymake-jslint
  1111. '(flymake-jslint-load))
  1112. (autoload-eval-lazily 'js nil
  1113. (add-hook 'js-mode-hook
  1114. 'flymake-jslint-load)))
  1115. (safe-require-or-eval 'js-doc)
  1116. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  1117. (when (safe-require-or-eval 'uniquify)
  1118. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  1119. (setq uniquify-ignore-buffers-re "*[^*]+*")
  1120. (setq uniquify-min-dir-content 1))
  1121. (add-hook 'view-mode-hook
  1122. (lambda()
  1123. (defvar view-mode-map)
  1124. (define-key view-mode-map "j" 'scroll-up-line)
  1125. (define-key view-mode-map "k" 'scroll-down-line)
  1126. (define-key view-mode-map "v" 'toggle-read-only)
  1127. (define-key view-mode-map "q" 'bury-buffer)
  1128. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  1129. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  1130. ;; (define-key view-mode-map
  1131. ;; "n" 'nonincremental-repeat-search-forward)
  1132. ;; (define-key view-mode-map
  1133. ;; "N" 'nonincremental-repeat-search-backward)
  1134. (define-key view-mode-map "/" 'isearch-forward-regexp)
  1135. (define-key view-mode-map "?" 'isearch-backward-regexp)
  1136. (define-key view-mode-map "n" 'isearch-repeat-forward)
  1137. (define-key view-mode-map "N" 'isearch-repeat-backward)
  1138. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point)
  1139. ))
  1140. (global-set-key "\M-r" 'view-mode)
  1141. ;; (setq view-read-only t)
  1142. ;; (defun my-view-mode-search-word (word)
  1143. ;; "Search for word current directory and subdirectories.
  1144. ;; If called intearctively, find word at point."
  1145. ;; (interactive (list (thing-at-point 'symbol)))
  1146. ;; (if word
  1147. ;; (if (and (require 'gtags nil t)
  1148. ;; (gtags-get-rootpath))
  1149. ;; (gtags-goto-tag word "s")
  1150. ;; (my-rgrep word))
  1151. ;; (message "No word at point.")
  1152. ;; nil))
  1153. (add-hook 'Man-mode-hook
  1154. (lambda ()
  1155. (view-mode 1)
  1156. (setq truncate-lines nil)))
  1157. (defvar-set Man-notify-method (if window-system
  1158. 'newframe
  1159. 'aggressive))
  1160. (defvar-set woman-cache-filename (expand-file-name (concat user-emacs-directory
  1161. "woman_cache.el")))
  1162. (defalias 'man 'woman)
  1163. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1164. ;; python
  1165. (when (autoload-eval-lazily 'python '(python-mode))
  1166. (defvar-set python-python-command (or (executable-find "python3")
  1167. (executable-find "python")))
  1168. ;; (defun my-python-run-as-command ()
  1169. ;; ""
  1170. ;; (interactive)
  1171. ;; (shell-command (concat python-python-command " " buffer-file-name)))
  1172. (defun my-python-display-python-buffer ()
  1173. ""
  1174. (interactive)
  1175. (defvar python-buffer)
  1176. (set-window-text-height (display-buffer python-buffer
  1177. t)
  1178. 7))
  1179. (add-hook 'python-mode-hook
  1180. (lambda ()
  1181. (local-set-key (kbd "C-c C-e") 'my-python-run-as-command)
  1182. (local-set-key (kbd "C-c C-b") 'my-python-display-python-buffer)
  1183. (local-set-key (kbd "C-m") 'newline-and-indent)))
  1184. (add-hook 'inferior-python-mode-hook
  1185. (lambda ()
  1186. (my-python-display-python-buffer)
  1187. (local-set-key (kbd "<up>") 'comint-previous-input)
  1188. (local-set-key (kbd "<down>") 'comint-next-input))))
  1189. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1190. ;; GNU GLOBAL(gtags)
  1191. ;; http://uguisu.skr.jp/Windows/gtags.html
  1192. ;; http://eigyr.dip.jp/gtags.html
  1193. ;; http://cha.la.coocan.jp/doc/gnu_global.html
  1194. (let ((d "/opt/local/share/gtags/"))
  1195. (and (file-directory-p d)
  1196. (add-to-list 'load-path
  1197. d)))
  1198. (when (autoload-eval-lazily 'gtags '(gtags-mode))
  1199. (add-hook 'gtags-mode-hook
  1200. (lambda ()
  1201. (view-mode gtags-mode)
  1202. (setq gtags-select-buffer-single t)
  1203. ;; (local-set-key "\M-t" 'gtags-find-tag)
  1204. ;; (local-set-key "\M-r" 'gtags-find-rtag)
  1205. ;; (local-set-key "\M-s" 'gtags-find-symbol)
  1206. ;; (local-set-key "\C-t" 'gtags-pop-stack)
  1207. (define-key gtags-mode-map (kbd "C-x t h")
  1208. 'gtags-find-tag-from-here)
  1209. (define-key gtags-mode-map (kbd "C-x t t") 'gtags-find-tag)
  1210. (define-key gtags-mode-map (kbd "C-x t r") 'gtags-find-rtag)
  1211. (define-key gtags-mode-map (kbd "C-x t s") 'gtags-find-symbol)
  1212. (define-key gtags-mode-map (kbd "C-x t p") 'gtags-find-pattern)
  1213. (define-key gtags-mode-map (kbd "C-x t f") 'gtags-find-file)
  1214. (define-key gtags-mode-map (kbd "C-x t b") 'gtags-pop-stack) ;back
  1215. ))
  1216. (add-hook 'gtags-select-mode-hook
  1217. (lambda ()
  1218. (define-key gtags-select-mode-map (kbd "C-m") 'gtags-select-tag)
  1219. ))
  1220. )
  1221. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1222. ;; term mode
  1223. ;; (setq multi-term-program shell-file-name)
  1224. (when (autoload-eval-lazily 'multi-term)
  1225. (setq multi-term-switch-after-close nil)
  1226. (setq multi-term-dedicated-select-after-open-p t)
  1227. (setq multi-term-dedicated-window-height 20))
  1228. (when (autoload-eval-lazily 'term '(term ansi-term))
  1229. (defun my-term-quit-or-send-raw ()
  1230. ""
  1231. (interactive)
  1232. (if (get-buffer-process (current-buffer))
  1233. (call-interactively 'term-send-raw)
  1234. (kill-buffer)))
  1235. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  1236. ;; (setq term-ansi-default-program shell-file-name)
  1237. (add-hook 'term-setup-hook
  1238. (lambda ()
  1239. (defvar-set term-display-table (make-display-table))))
  1240. (add-hook 'term-mode-hook
  1241. (lambda ()
  1242. (defvar term-raw-map)
  1243. (unless (memq (current-buffer)
  1244. (and (featurep 'multi-term)
  1245. (defvar multi-term-buffer-list)
  1246. ;; current buffer is not multi-term buffer
  1247. multi-term-buffer-list))
  1248. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  1249. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  1250. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  1251. ;; (define-key term-raw-map "\C-f" 'forward-char)
  1252. ;; (define-key term-raw-map "\C-b" 'backward-char)
  1253. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  1254. (define-key term-raw-map
  1255. "\C-x" (lookup-key (current-global-map) "\C-x"))
  1256. (define-key term-raw-map
  1257. "\C-z" (lookup-key (current-global-map) "\C-z"))
  1258. )
  1259. ;; (define-key term-raw-map "\C-xl" 'term-line-mode)
  1260. ;; (define-key term-mode-map "\C-xc" 'term-char-mode)
  1261. (define-key term-raw-map (kbd "<up>") 'scroll-down-line)
  1262. (define-key term-raw-map (kbd "<down>") 'scroll-up-line)
  1263. (define-key term-raw-map (kbd "<right>") 'scroll-up)
  1264. (define-key term-raw-map (kbd "<left>") 'scroll-down)
  1265. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  1266. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  1267. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  1268. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  1269. (define-key term-raw-map [delete] 'term-send-raw)
  1270. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  1271. (define-key term-raw-map "\C-y" 'term-paste)
  1272. (define-key term-raw-map
  1273. "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  1274. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  1275. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  1276. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  1277. ;; (define-key term-raw-map "\C-d" 'delete-char)
  1278. (set (make-local-variable 'scroll-margin) 0)
  1279. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  1280. ;; (cua-mode 0)
  1281. ;; (and cua-mode
  1282. ;; (local-unset-key (kbd "C-c")))
  1283. ;; (define-key cua--prefix-override-keymap
  1284. ;;"\C-c" 'term-interrupt-subjob)
  1285. (set (make-local-variable (defvar hl-line-range-function))
  1286. (lambda ()
  1287. '(0 . 0)))
  1288. ))
  1289. ;; (add-hook 'term-exec-hook 'forward-char)
  1290. )
  1291. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1292. ;; buffer switching
  1293. (defvar bs-configurations)
  1294. (when (autoload-eval-lazily 'bs '(bs-show)
  1295. ;; (add-to-list 'bs-configurations
  1296. ;; '("processes" nil get-buffer-process ".*" nil nil))
  1297. (add-to-list 'bs-configurations
  1298. '("files-and-terminals" nil nil nil
  1299. (lambda (buf)
  1300. (and (bs-visits-non-file buf)
  1301. (save-excursion
  1302. (set-buffer buf)
  1303. (not (memq major-mode
  1304. '(term-mode
  1305. eshell-mode))))))))
  1306. ;; (setq bs-configurations (list
  1307. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1308. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1309. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1310. )
  1311. ;; (global-set-key "\C-x\C-b" 'bs-show)
  1312. (defalias 'list-buffers 'bs-show)
  1313. (defvar-set bs-default-configuration "files-and-terminals")
  1314. (defvar-set bs-default-sort-name "by nothing")
  1315. (add-hook 'bs-mode-hook
  1316. (lambda ()
  1317. ;; (setq bs-default-configuration "files")
  1318. ;; (and bs--show-all
  1319. ;; (call-interactively 'bs-toggle-show-all))
  1320. (set (make-local-variable 'scroll-margin) 0))))
  1321. ;;(iswitchb-mode 1)
  1322. (icomplete-mode)
  1323. (defun iswitchb-buffer-display-other-window ()
  1324. "Do iswitchb in other window."
  1325. (interactive)
  1326. (let ((iswitchb-default-method 'display))
  1327. (call-interactively 'iswitchb-buffer)))
  1328. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1329. ;; sdic
  1330. (when (autoload-eval-lazily 'sdic '(sdic-describe-word-at-point))
  1331. ;; (define-key my-prefix-map "\C-w" 'sdic-describe-word)
  1332. (define-key my-prefix-map "\C-t" 'sdic-describe-word-at-point-echo)
  1333. (defun sdic-describe-word-at-point-echo ()
  1334. ""
  1335. (interactive)
  1336. (save-window-excursion
  1337. (sdic-describe-word-at-point))
  1338. (save-excursion
  1339. (set-buffer sdic-buffer-name)
  1340. (message (buffer-substring (point-min)
  1341. (progn (goto-char (point-min))
  1342. (or (and (re-search-forward "^\\w"
  1343. nil
  1344. t
  1345. 4)
  1346. (progn (previous-line) t)
  1347. (point-at-eol))
  1348. (point-max)))))))
  1349. (setq sdic-eiwa-dictionary-list '((sdicf-client "/usr/share/dict/gene.sdic")))
  1350. (setq sdic-waei-dictionary-list
  1351. '((sdicf-client "/usr/share/dict/jedict.sdic" (add-keys-to-headword t))))
  1352. (setq sdic-disable-select-window t)
  1353. (setq sdic-window-height 7))
  1354. ;;;;;;;;;;;;;;;;;;;;;;;;
  1355. ;; ilookup
  1356. (when (fetch-library
  1357. "https://raw.github.com/10sr/emacs-lisp/master/ilookup.el"
  1358. t)
  1359. (autoload-eval-lazily 'ilookup
  1360. '(ilookup-open)
  1361. (setq ilookup-dict-alist
  1362. '(
  1363. ("en" . (lambda (word)
  1364. (shell-command-to-string
  1365. (format "sdcv -n -u dictd_www.dict.org_gcide '%s'"
  1366. word))))
  1367. ("ja" . (lambda (word)
  1368. (shell-command-to-string
  1369. (format "sdcv -n -u EJ-GENE95 -u jmdict-en-ja '%s'"
  1370. word))))
  1371. ("jaj" . (lambda (word)
  1372. (shell-command-to-string
  1373. (format "sdcv -n -u jmdict-en-ja '%s'"
  1374. word))))
  1375. ("jag" .
  1376. (lambda (word)
  1377. (with-temp-buffer
  1378. (insert (shell-command-to-string
  1379. (format "sdcv -n -u 'Genius English-Japanese' '%s'"
  1380. word)))
  1381. (html2text)
  1382. (buffer-substring (point-min)
  1383. (point-max)))))
  1384. ("alc" . (lambda (word)
  1385. (shell-command-to-string
  1386. (format "alc '%s' | head -n 20"
  1387. word))))
  1388. ("app" . (lambda (word)
  1389. (shell-command-to-string
  1390. (format "dict_app '%s'"
  1391. word))))
  1392. ;; letters broken
  1393. ("ms" .
  1394. (lambda (word)
  1395. (let ((url (concat
  1396. "http://api.microsofttranslator.com/V2/Ajax.svc/"
  1397. "Translate?appId=%s&text=%s&to=%s"))
  1398. (apikey "3C9778666C5BA4B406FFCBEE64EF478963039C51")
  1399. (target "ja")
  1400. (eword (url-hexify-string word)))
  1401. (with-current-buffer (url-retrieve-synchronously
  1402. (format url
  1403. apikey
  1404. eword
  1405. target))
  1406. (message "")
  1407. (goto-char (point-min))
  1408. (search-forward-regexp "^$"
  1409. nil
  1410. t)
  1411. (url-unhex-string (buffer-substring-no-properties
  1412. (point)
  1413. (point-max)))))))
  1414. ))
  1415. ;; (funcall (cdr (assoc "ms"
  1416. ;; ilookup-alist))
  1417. ;; "dictionary")
  1418. ;; (switch-to-buffer (url-retrieve-synchronously "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=3C9778666C5BA4B406FFCBEE64EF478963039C51&text=dictionary&to=ja"))
  1419. ;; (switch-to-buffer (url-retrieve-synchronously "http://google.com"))
  1420. (setq ilookup-default "ja")
  1421. (when (locate-library "google-translate")
  1422. (add-to-list 'ilookup-dict-alist
  1423. '("gt" .
  1424. (lambda (word)
  1425. (save-excursion
  1426. (google-translate-translate "auto"
  1427. "ja"
  1428. word))
  1429. (with-current-buffer "*Google Translate*"
  1430. (buffer-substring-no-properties (point-min)
  1431. (point-max)))))))
  1432. ))
  1433. (when (autoload-eval-lazily 'google-translate '(google-translate-translate
  1434. google-translate-at-point))
  1435. (setq google-translate-default-source-language "auto")
  1436. (setq google-translate-default-target-language "ja"))
  1437. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1438. ;; vc
  1439. (require 'vc)
  1440. ;;(setq vc-handled-backends '())
  1441. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1442. ;; gauche-mode
  1443. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  1444. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  1445. (when (and (fetch-library
  1446. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  1447. t)
  1448. (autoload-eval-lazily 'gauche-mode '(gauche-mode run-scheme)))
  1449. (let ((s (executable-find "gosh")))
  1450. (setq scheme-program-name s
  1451. gauche-program-name s))
  1452. (defun run-gauche-other-window ()
  1453. "Run gauche on other window"
  1454. (interactive)
  1455. (switch-to-buffer-other-window
  1456. (get-buffer-create "*scheme*"))
  1457. (run-gauche))
  1458. (defun run-gauche ()
  1459. "run gauche"
  1460. (run-scheme gauche-program-name)
  1461. )
  1462. (defun scheme-send-buffer ()
  1463. ""
  1464. (interactive)
  1465. (scheme-send-region (point-min) (point-max))
  1466. (my-scheme-display-scheme-buffer)
  1467. )
  1468. (defun my-scheme-display-scheme-buffer ()
  1469. ""
  1470. (interactive)
  1471. (set-window-text-height (display-buffer scheme-buffer
  1472. t)
  1473. 7))
  1474. (add-hook 'scheme-mode-hook
  1475. (lambda ()
  1476. nil))
  1477. (add-hook 'inferior-scheme-mode-hook
  1478. (lambda ()
  1479. ;; (my-scheme-display-scheme-buffer)
  1480. ))
  1481. (setq auto-mode-alist
  1482. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  1483. (setq auto-mode-alist
  1484. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  1485. (add-hook 'gauche-mode-hook
  1486. (lambda ()
  1487. (define-key gauche-mode-map
  1488. (kbd "C-c C-z") 'run-gauche-other-window)
  1489. (define-key scheme-mode-map
  1490. (kbd "C-c C-c") 'scheme-send-buffer)
  1491. (define-key scheme-mode-map
  1492. (kbd "C-c C-b") 'my-scheme-display-scheme-buffer))))
  1493. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1494. ;; recentf-mode
  1495. (setq recentf-save-file (expand-file-name (concat user-emacs-directory
  1496. "recentf"))
  1497. recentf-max-menu-items 20
  1498. recentf-max-saved-items 30
  1499. recentf-show-file-shortcuts-flag nil)
  1500. (when (safe-require-or-eval 'recentf)
  1501. (add-to-list 'recentf-exclude
  1502. (regexp-quote recentf-save-file))
  1503. (add-to-list 'recentf-exclude
  1504. (regexp-quote (expand-file-name user-emacs-directory)))
  1505. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1506. (remove-hook 'find-file-hook
  1507. 'recentf-track-opened-file)
  1508. (defun my-recentf-load-track-save-list ()
  1509. "Load current recentf list from file, track current visiting file, then save
  1510. the list."
  1511. (recentf-load-list)
  1512. (recentf-track-opened-file)
  1513. (recentf-save-list))
  1514. (add-hook 'find-file-hook
  1515. 'my-recentf-load-track-save-list)
  1516. (add-hook 'kill-emacs-hook
  1517. 'recentf-load-list)
  1518. ;;(run-with-idle-timer 5 t 'recentf-save-list)
  1519. ;; (add-hook 'find-file-hook
  1520. ;; (lambda ()
  1521. ;; (recentf-add-file default-directory)))
  1522. (and (fetch-library
  1523. "https://raw.github.com/10sr/emacs-lisp/master/recentf-show.el"
  1524. t)
  1525. (autoload-eval-lazily 'recentf-show)
  1526. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1527. (add-hook 'recentf-show-before-listing-hook
  1528. 'recentf-load-list))
  1529. (recentf-mode 1)
  1530. (add-hook 'recentf-dialog-mode-hook
  1531. (lambda ()
  1532. ;; (recentf-save-list)
  1533. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1534. ;; 'my-recentf-cd-and-find-file)
  1535. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1536. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1537. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1538. (define-key recentf-dialog-mode-map "n" 'next-line)
  1539. (cd "~/"))))
  1540. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1541. ;; dired
  1542. (when (autoload-eval-lazily 'dired nil)
  1543. (defun my-dired-echo-file-head (arg)
  1544. ""
  1545. (interactive "P")
  1546. (let ((f (dired-get-filename)))
  1547. (message "%s"
  1548. (with-temp-buffer
  1549. (insert-file-contents f)
  1550. (buffer-substring-no-properties
  1551. (point-min)
  1552. (progn (goto-line (if arg
  1553. (prefix-numeric-value arg)
  1554. 7))
  1555. (point-at-eol)))))))
  1556. (defun my-dired-diff ()
  1557. ""
  1558. (interactive)
  1559. (let ((files (dired-get-marked-files nil nil nil t)))
  1560. (if (eq (car files)
  1561. t)
  1562. (diff (cadr files) (dired-get-filename))
  1563. (message "One files must be marked!"))))
  1564. (defun my-pop-to-buffer-erase-noselect (buffer-or-name)
  1565. "pop up buffer using `display-buffer' and return that buffer."
  1566. (let ((bf (get-buffer-create buffer-or-name)))
  1567. (with-current-buffer bf
  1568. (cd ".")
  1569. (erase-buffer))
  1570. (display-buffer bf)
  1571. bf))
  1572. (defun my-replace-nasi-none ()
  1573. ""
  1574. (save-excursion
  1575. (let ((buffer-read-only nil))
  1576. (goto-char (point-min))
  1577. (while (search-forward "なし" nil t)
  1578. (replace-match "none")))))
  1579. (defun dired-get-file-info ()
  1580. "dired get file info"
  1581. (interactive)
  1582. (let ((f (shell-quote-argument (dired-get-filename t))))
  1583. (if (file-directory-p f)
  1584. (progn
  1585. (message "Calculating disk usage...")
  1586. (shell-command (concat "du -hsD "
  1587. f)))
  1588. (shell-command (concat "file "
  1589. f)))))
  1590. (defun my-dired-scroll-up ()
  1591. ""
  1592. (interactive)
  1593. (my-dired-previous-line (- (window-height) 1)))
  1594. (defun my-dired-scroll-down ()
  1595. ""
  1596. (interactive)
  1597. (my-dired-next-line (- (window-height) 1)))
  1598. ;; (defun my-dired-forward-line (arg)
  1599. ;; ""
  1600. ;; (interactive "p"))
  1601. (defun my-dired-previous-line (arg)
  1602. ""
  1603. (interactive "p")
  1604. (if (> arg 0)
  1605. (progn
  1606. (if (eq (line-number-at-pos)
  1607. 1)
  1608. (goto-char (point-max))
  1609. (forward-line -1))
  1610. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1611. (dired-get-subdir))
  1612. (- arg 1)
  1613. arg)))
  1614. (dired-move-to-filename)))
  1615. (defun my-dired-next-line (arg)
  1616. ""
  1617. (interactive "p")
  1618. (if (> arg 0)
  1619. (progn
  1620. (if (eq (point)
  1621. (point-max))
  1622. (goto-char (point-min))
  1623. (forward-line 1))
  1624. (my-dired-next-line (if (or (dired-get-filename nil t)
  1625. (dired-get-subdir))
  1626. (- arg 1)
  1627. arg)))
  1628. (dired-move-to-filename)))
  1629. (defun my-dired-print-current-dir-and-file ()
  1630. (message "%s %s"
  1631. default-directory
  1632. (buffer-substring-no-properties (point-at-bol)
  1633. (point-at-eol))))
  1634. (defun dired-do-execute-as-command ()
  1635. ""
  1636. (interactive)
  1637. (let ((file (dired-get-filename t)))
  1638. (if (file-executable-p file)
  1639. (start-process file nil file)
  1640. (when (y-or-n-p
  1641. "This file cant be executed. Mark as executable and go? ")
  1642. (set-file-modes file
  1643. (file-modes-symbolic-to-number "u+x" (file-modes file)))
  1644. (start-process file nil file)))))
  1645. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1646. (defun my-dired-x-open ()
  1647. ""
  1648. (interactive)
  1649. (my-x-open (dired-get-filename t t)))
  1650. (if (eq window-system 'mac)
  1651. (setq dired-listing-switches "-lhF")
  1652. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1653. )
  1654. (setq dired-listing-switches "-lhF")
  1655. (put 'dired-find-alternate-file 'disabled nil)
  1656. ;; when using dired-find-alternate-file
  1657. ;; reuse current dired buffer for the file to open
  1658. (defvar-set dired-ls-F-marks-symlinks t)
  1659. (when (safe-require-or-eval 'ls-lisp)
  1660. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1661. (setq ls-lisp-dirs-first t)
  1662. (setq ls-lisp-use-localized-time-format t)
  1663. (setq ls-lisp-format-time-list
  1664. '("%Y-%m-%d %H:%M"
  1665. "%Y-%m-%d ")))
  1666. (defvar-set dired-dwim-target t)
  1667. (defvar-set dired-isearch-filenames t)
  1668. (defvar-set dired-hide-details-hide-symlink-targets nil)
  1669. (defvar-set dired-hide-details-hide-information-lines nil)
  1670. ;; (add-hook 'dired-after-readin-hook
  1671. ;; 'my-replace-nasi-none)
  1672. ;; (add-hook 'after-init-hook
  1673. ;; (lambda ()
  1674. ;; (dired ".")))
  1675. (add-hook 'dired-mode-hook
  1676. (lambda ()
  1677. (local-set-key "o" 'my-dired-x-open)
  1678. (local-set-key "i" 'dired-get-file-info)
  1679. (local-set-key "f" 'find-file)
  1680. (local-set-key "!" 'shell-command)
  1681. (local-set-key "&" 'async-shell-command)
  1682. (local-set-key "X" 'dired-do-async-shell-command)
  1683. (local-set-key "=" 'my-dired-diff)
  1684. (local-set-key "B" 'gtkbm-add-current-dir)
  1685. (local-set-key "b" 'gtkbm)
  1686. (local-set-key "h" 'my-dired-echo-file-head)
  1687. (local-set-key "@" (lambda ()
  1688. (interactive) (my-x-open ".")))
  1689. (local-set-key (kbd "TAB") 'other-window)
  1690. ;; (local-set-key "P" 'my-dired-do-pack-or-unpack)
  1691. (local-set-key "/" 'dired-isearch-filenames)
  1692. (local-set-key (kbd "DEL") 'dired-up-directory)
  1693. (local-set-key (kbd "C-h") 'dired-up-directory)
  1694. (substitute-key-definition 'dired-next-line
  1695. 'my-dired-next-line
  1696. (current-local-map))
  1697. (substitute-key-definition 'dired-previous-line
  1698. 'my-dired-previous-line
  1699. (current-local-map))
  1700. ;; (local-set-key (kbd "C-p") 'my-dired-previous-line)
  1701. ;; (local-set-key (kbd "p") 'my-dired-previous-line)
  1702. ;; (local-set-key (kbd "C-n") 'my-dired-next-line)
  1703. ;; (local-set-key (kbd "n") 'my-dired-next-line)
  1704. (local-set-key (kbd "<left>") 'my-dired-scroll-up)
  1705. (local-set-key (kbd "<right>") 'my-dired-scroll-down)
  1706. (local-set-key (kbd "ESC p") 'my-dired-scroll-up)
  1707. (local-set-key (kbd "ESC n") 'my-dired-scroll-down)
  1708. (when (fboundp 'dired-hide-details-mode)
  1709. (dired-hide-details-mode t)
  1710. (local-set-key "l" 'dired-hide-details-mode))
  1711. (let ((file "._Icon\015"))
  1712. (when nil (file-readable-p file)
  1713. (delete-file file)))))
  1714. (and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/pack.el"
  1715. t)
  1716. (autoload-eval-lazily 'pack '(dired-do-pack-or-unpack pack))
  1717. (add-hook 'dired-mode-hook
  1718. (lambda ()
  1719. (local-set-key "P" 'dired-do-pack-or-unpack))))
  1720. (and (fetch-library
  1721. "https://raw.github.com/10sr/emacs-lisp/master/dired-list-all-mode.el"
  1722. t)
  1723. (autoload-eval-lazily 'dired-list-all-mode)
  1724. (setq dired-listing-switches "-lhF")
  1725. (add-hook 'dired-mode-hook
  1726. (lambda ()
  1727. (local-set-key "a" 'dired-list-all-mode)
  1728. )))
  1729. ) ; when dired locate
  1730. ;; http://blog.livedoor.jp/tek_nishi/archives/4693204.html
  1731. (defvar dired-marker-char)
  1732. (defun my-dired-toggle-mark()
  1733. (let ((cur (cond ((eq (following-char) dired-marker-char) ?\040)
  1734. (t dired-marker-char))))
  1735. (delete-char 1)
  1736. (insert cur)))
  1737. (defun my-dired-mark (arg)
  1738. "Toggle mark the current (or next ARG) files.
  1739. If on a subdir headerline, mark all its files except `.' and `..'.
  1740. Use \\[dired-unmark-all-files] to remove all marks
  1741. and \\[dired-unmark] on a subdir to remove the marks in
  1742. this subdir."
  1743. (interactive "P")
  1744. (if (dired-get-subdir)
  1745. (save-excursion (dired-mark-subdir-files))
  1746. (let ((inhibit-read-only t))
  1747. (dired-repeat-over-lines
  1748. (prefix-numeric-value arg)
  1749. 'my-dired-toggle-mark))))
  1750. (defun my-dired-mark-backward (arg)
  1751. "In Dired, move up lines and toggle mark there.
  1752. Optional prefix ARG says how many lines to unflag; default is one line."
  1753. (interactive "p")
  1754. (my-dired-mark (- arg)))
  1755. (add-hook 'dired-mode-hook
  1756. (lambda ()
  1757. (local-set-key (kbd "SPC") 'my-dired-mark)
  1758. (local-set-key (kbd "S-SPC") 'my-dired-mark-backward))
  1759. )
  1760. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1761. ;; eshell
  1762. (autoload-eval-lazily 'eshell nil
  1763. (defvar-set eshell-banner-message (format "Welcome to the Emacs shell
  1764. %s
  1765. C-x t to toggling emacs-text-mode
  1766. "
  1767. (shell-command-to-string "uname -a")
  1768. ))
  1769. (defvar eshell-text-mode-map
  1770. (let ((map (make-sparse-keymap)))
  1771. (define-key map (kbd "C-x t") 'eshell-text-mode-toggle)
  1772. map))
  1773. (define-derived-mode eshell-text-mode text-mode
  1774. "Eshell-Text"
  1775. "Text-mode for Eshell."
  1776. nil)
  1777. (defun eshell-text-mode-toggle ()
  1778. "Toggle eshell-text-mode and eshell-mode."
  1779. (interactive)
  1780. (cond ((eq major-mode
  1781. 'eshell-text-mode)
  1782. (goto-char (point-max))
  1783. (message "Eshell text mode disabled")
  1784. (eshell-mode))
  1785. ((eq major-mode
  1786. 'eshell-mode)
  1787. (message "Eshell text mode enabled")
  1788. (eshell-write-history)
  1789. (eshell-text-mode))
  1790. (t
  1791. (message "Not in eshell buffer")
  1792. nil)))
  1793. (defun my-eshell-backward-delete-char ()
  1794. (interactive)
  1795. (when (< (save-excursion
  1796. (eshell-bol)
  1797. (point))
  1798. (point))
  1799. (backward-delete-char 1)))
  1800. (defun my-file-owner-p (file)
  1801. "t if FILE is owned by me."
  1802. (eq (user-uid) (nth 2 (file-attributes file))))
  1803. "http://www.bookshelf.jp/pukiwiki/pukiwiki.php\
  1804. ?Eshell%A4%F2%BB%C8%A4%A4%A4%B3%A4%CA%A4%B9"
  1805. ;; ;; written by Stefan Reichoer <reichoer@web.de>
  1806. ;; (defun eshell/less (&rest args)
  1807. ;; "Invoke `view-file' on the file.
  1808. ;; \"less +42 foo\" also goes to line 42 in the buffer."
  1809. ;; (if args
  1810. ;; (while args
  1811. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1812. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1813. ;; (file (pop args)))
  1814. ;; (view-file file)
  1815. ;; (goto-line line))
  1816. ;; (view-file (pop args))))))
  1817. (defun eshell/o (&optional file)
  1818. (my-x-open (or file ".")))
  1819. ;; (defun eshell/vi (&rest args)
  1820. ;; "Invoke `find-file' on the file.
  1821. ;; \"vi +42 foo\" also goes to line 42 in the buffer."
  1822. ;; (while args
  1823. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1824. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1825. ;; (file (pop args)))
  1826. ;; (find-file file)
  1827. ;; (goto-line line))
  1828. ;; (find-file (pop args)))))
  1829. (defun eshell/clear ()
  1830. "Clear the current buffer, leaving one prompt at the top."
  1831. (interactive)
  1832. (let ((inhibit-read-only t))
  1833. (erase-buffer)))
  1834. (defun eshell-clear ()
  1835. (interactive)
  1836. (let ((inhibit-read-only t))
  1837. (erase-buffer)
  1838. (insert (funcall eshell-prompt-function))))
  1839. (defun eshell/d (&optional dirname switches)
  1840. "if first arg is omitted open current directory."
  1841. (dired (or dirname ".") switches))
  1842. (defun eshell/v ()
  1843. (view-mode 1))
  1844. ;; (defun eshell/aaa (&rest args)
  1845. ;; (message "%S"
  1846. ;; args))
  1847. (defalias 'eshell/: 'ignore)
  1848. (defalias 'eshell/type 'eshell/which)
  1849. ;; (defalias 'eshell/vim 'eshell/vi)
  1850. (defalias 'eshell/ff 'find-file)
  1851. (defalias 'eshell/q 'eshell/exit)
  1852. (defun eshell-goto-prompt ()
  1853. ""
  1854. (interactive)
  1855. (goto-char (point-max)))
  1856. (defun eshell-delete-char-or-logout (n)
  1857. (interactive "p")
  1858. (if (equal (eshell-get-old-input)
  1859. "")
  1860. (progn
  1861. (insert "exit")
  1862. (eshell-send-input))
  1863. (delete-char n)))
  1864. (defun eshell-kill-input ()
  1865. (interactive)
  1866. (delete-region (point)
  1867. (progn (eshell-bol)
  1868. (point))))
  1869. (defalias 'eshell/logout 'eshell/exit)
  1870. (defun eshell-cd-default-directory (&optional eshell-buffer-or-name)
  1871. "open eshell and change wd
  1872. if arg given, use that eshell buffer, otherwise make new eshell buffer."
  1873. (interactive)
  1874. (let ((dir (expand-file-name default-directory)))
  1875. (switch-to-buffer (or eshell-buffer-or-name
  1876. (eshell t)))
  1877. (unless (equal dir (expand-file-name default-directory))
  1878. ;; (cd dir)
  1879. ;; (eshell-interactive-print (concat "cd " dir "\n"))
  1880. ;; (eshell-emit-prompt)
  1881. (goto-char (point-max))
  1882. (eshell-kill-input)
  1883. (insert "cd " dir)
  1884. (eshell-send-input))))
  1885. (defadvice eshell-next-matching-input-from-input
  1886. ;; do not cycle history
  1887. (around eshell-history-do-not-cycle activate)
  1888. (if (= 0
  1889. (or eshell-history-index
  1890. 0))
  1891. (progn
  1892. (delete-region eshell-last-output-end (point))
  1893. (insert-and-inherit eshell-matching-input-from-input-string)
  1894. (setq eshell-history-index nil))
  1895. ad-do-it))
  1896. (defvar-set eshell-directory-name (concat user-emacs-directory
  1897. "eshell/"))
  1898. (defvar-set eshell-term-name "eterm-color")
  1899. (defvar-set eshell-scroll-to-bottom-on-input t)
  1900. (defvar-set eshell-cmpl-ignore-case t)
  1901. (defvar-set eshell-cmpl-cycle-completions nil)
  1902. (defvar-set eshell-highlight-prompt nil)
  1903. (defvar-set eshell-ls-initial-args '("-hCFG"
  1904. "--color=auto"
  1905. "--time-style=long-iso")) ; "-hF")
  1906. (defvar-set eshell-prompt-function
  1907. 'my-eshell-prompt-function)
  1908. (defvar eshell-last-command-status)
  1909. (defun my-eshell-prompt-function()
  1910. "Prompt function.
  1911. It looks like:
  1912. :: [10sr@darwin:~/][ESHELL]
  1913. :: $
  1914. "
  1915. (concat ":: ["
  1916. (let ((str (concat user-login-name
  1917. "@"
  1918. (car (split-string system-name
  1919. "\\."))
  1920. )))
  1921. (put-text-property 0
  1922. (length str)
  1923. 'face
  1924. 'underline
  1925. str)
  1926. str)
  1927. ":"
  1928. (let ((str (abbreviate-file-name default-directory)))
  1929. (put-text-property 0
  1930. (length str)
  1931. 'face
  1932. 'underline
  1933. str)
  1934. str)
  1935. "][ESHELL]\n:: "
  1936. (if (eq 0
  1937. eshell-last-command-status)
  1938. ""
  1939. (format "[STATUS:%d] "
  1940. eshell-last-command-status))
  1941. (if (= (user-uid)
  1942. 0)
  1943. "# "
  1944. "$ ")
  1945. ))
  1946. (add-hook 'eshell-mode-hook
  1947. (lambda ()
  1948. ;; (define-key eshell-mode-map (kbd "C-x C-x") (lambda ()
  1949. ;; (interactive)
  1950. ;; (switch-to-buffer (other-buffer))))
  1951. ;; (define-key eshell-mode-map (kbd "C-g") (lambda ()
  1952. ;; (interactive)
  1953. ;; (eshell-goto-prompt)
  1954. ;; (keyboard-quit)))
  1955. (local-set-key (kbd "C-x t") 'eshell-text-mode-toggle)
  1956. (local-set-key (kbd "C-u") 'eshell-kill-input)
  1957. (local-set-key (kbd "C-d") 'eshell-delete-char-or-logout)
  1958. ;; (define-key eshell-mode-map (kbd "C-l")
  1959. ;; 'eshell-clear)
  1960. (local-set-key (kbd "DEL") 'my-eshell-backward-delete-char)
  1961. (local-set-key (kbd "<up>") 'scroll-down-line)
  1962. (local-set-key (kbd "<down>") 'scroll-up-line)
  1963. ;; (define-key eshell-mode-map
  1964. ;; (kbd "C-p") 'eshell-previous-matching-input-from-input)
  1965. ;; (define-key eshell-mode-map
  1966. ;; (kbd "C-n") 'eshell-next-matching-input-from-input)
  1967. (apply 'eshell/addpath exec-path)
  1968. (set (make-local-variable 'scroll-margin) 0)
  1969. ;; (eshell/export "GIT_PAGER=")
  1970. ;; (eshell/export "GIT_EDITOR=")
  1971. (eshell/export "LC_MESSAGES=C")
  1972. (switch-to-buffer (current-buffer)) ; move buffer top of list
  1973. (set (make-local-variable (defvar hl-line-range-function))
  1974. (lambda ()
  1975. '(0 . 0)))
  1976. (defvar eshell-virtual-targets)
  1977. (add-to-list 'eshell-virtual-targets
  1978. '("/dev/less"
  1979. (lambda (str)
  1980. (if str
  1981. (with-current-buffer nil)))
  1982. nil))
  1983. ))
  1984. (add-hook 'eshell-mode-hook
  1985. (lambda ()
  1986. (defvar eshell-visual-commands)
  1987. (defvar eshell-output-filter-functions)
  1988. (defvar eshell-command-aliases-list)
  1989. (add-to-list 'eshell-visual-commands "vim")
  1990. ;; (add-to-list 'eshell-visual-commands "git")
  1991. (add-to-list 'eshell-output-filter-functions
  1992. 'eshell-truncate-buffer)
  1993. (mapcar (lambda (alias)
  1994. (add-to-list 'eshell-command-aliases-list
  1995. alias))
  1996. '(
  1997. ;; ("ll" "ls -l $*")
  1998. ;; ("la" "ls -a $*")
  1999. ;; ("lla" "ls -al $*")
  2000. ("git" "git -c color.ui=always $*")
  2001. ("g" "git $*")
  2002. ("eless"
  2003. (concat "cat >>> (with-current-buffer "
  2004. "(get-buffer-create \"*eshell output\") "
  2005. "(erase-buffer) "
  2006. "(setq buffer-read-only nil) "
  2007. "(current-buffer)) "
  2008. "(view-buffer (get-buffer \"*eshell output*\"))"))
  2009. )
  2010. )))
  2011. ) ; eval after load eshell
  2012. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2013. ;; my-term
  2014. (defvar my-term nil
  2015. "My terminal buffer.")
  2016. (defvar my-term-function nil
  2017. "Function to create terminal buffer.
  2018. This function accept no argument and return newly created buffer of terminal.")
  2019. (defun my-term (&optional arg)
  2020. "Open terminal buffer and return that buffer.
  2021. If ARG is given or called with prefix argument, create new buffer."
  2022. (interactive "P")
  2023. (if (and (not arg)
  2024. my-term
  2025. (buffer-name my-term))
  2026. (pop-to-buffer my-term)
  2027. (setq my-term
  2028. (save-window-excursion
  2029. (funcall my-term-function)))
  2030. (and my-term
  2031. (my-term))))
  2032. ;; (setq my-term-function
  2033. ;; (lambda ()
  2034. ;; (if (eq system-type 'windows-nt)
  2035. ;; (eshell)
  2036. ;; (if (require 'multi-term nil t)
  2037. ;; (multi-term)
  2038. ;; (ansi-term shell-file-name)))))
  2039. (setq my-term-function (lambda () (eshell t)))
  2040. ;;(define-key my-prefix-map (kbd "C-s") 'my-term)
  2041. (define-key ctl-x-map "i" 'my-term)
  2042. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2043. ;; x open
  2044. (defvar my-filer nil)
  2045. (setq my-filer (or (executable-find "pcmanfm")
  2046. (executable-find "nautilus")))
  2047. (defun my-x-open (file)
  2048. "Open FILE."
  2049. (interactive "FOpen File: ")
  2050. (setq file (expand-file-name file))
  2051. (message "Opening %s..." file)
  2052. (cond ((eq system-type 'windows-nt)
  2053. (call-process "cmd.exe" nil 0 nil
  2054. "/c" "start" "" (convert-standard-filename file)))
  2055. ((eq system-type 'darwin)
  2056. (call-process "open" nil 0 nil file))
  2057. ((getenv "DISPLAY")
  2058. (call-process (or my-filer "xdg-open") nil 0 nil file))
  2059. (t
  2060. (find-file file))
  2061. )
  2062. ;; (recentf-add-file file)
  2063. (message "Opening %s...done" file))
  2064. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2065. ;; misc funcs
  2066. (defun my-git-apply-index-from-buffer (&optional buf)
  2067. "Git apply buffer. BUF is buffer to apply. nil to use current buffer."
  2068. (interactive)
  2069. (let ((buf (or buf
  2070. (current-buffer)))
  2071. (file (make-temp-file "git-apply-diff.emacs")))
  2072. (with-current-buffer buf
  2073. (write-region (point-min)
  2074. (point-max)
  2075. file)
  2076. (call-process "git"
  2077. nil
  2078. nil
  2079. nil
  2080. "apply"
  2081. "--cached"
  2082. file))))
  2083. (defun memo (&optional dir)
  2084. "Open memo.txt in DIR."
  2085. (interactive)
  2086. (pop-to-buffer (find-file-noselect (concat (if dir
  2087. (file-name-as-directory dir)
  2088. "")
  2089. "memo.txt"))))
  2090. (defvar my-rgrep-alist
  2091. `(
  2092. ;; the silver searcher
  2093. ("ag"
  2094. (executable-find "ag")
  2095. "ag --nocolor --nogroup --nopager ")
  2096. ;; ack
  2097. ("ack"
  2098. (executable-find "ack")
  2099. "ack --nocolor --nogroup --nopager --with-filename ")
  2100. ;; gnu global
  2101. ("global"
  2102. (and (require 'gtags nil t)
  2103. (executable-find "global")
  2104. (gtags-get-rootpath))
  2105. "global --result grep ")
  2106. ;; git grep
  2107. ("gitgrep"
  2108. (eq 0
  2109. (shell-command "git rev-parse --git-dir"))
  2110. "git --no-pager -c color.grep=false grep -nH -e ")
  2111. ;; grep
  2112. ("grep"
  2113. t
  2114. ,(concat "find . "
  2115. "-path '*/.git' -prune -o "
  2116. "-path '*/.svn' -prune -o "
  2117. "-type f -print0 | "
  2118. "xargs -0 grep -nH -e "))
  2119. )
  2120. "Alist of rgrep command.
  2121. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  2122. condition to choose COMMAND when evaluated.")
  2123. (defvar my-rgrep-default nil
  2124. "Default command name for my-rgrep.")
  2125. (defun my-rgrep-grep-command (&optional name alist)
  2126. "Return recursive grep command for current directory or nil.
  2127. If NAME is given, use that without testing.
  2128. Commands are searched from ALIST."
  2129. (if alist
  2130. (if name
  2131. ;; if name is given search that from alist and return the command
  2132. (nth 2 (assoc name
  2133. alist))
  2134. ;; if name is not given try test in 1th elem
  2135. (let ((car (car alist))
  2136. (cdr (cdr alist)))
  2137. (if (eval (nth 1 car))
  2138. ;; if the condition is true return the command
  2139. (nth 2 car)
  2140. ;; try next one
  2141. (and cdr
  2142. (my-rgrep-grep-command name cdr)))))
  2143. ;; if alist is not given set default value
  2144. (my-rgrep-grep-command name my-rgrep-alist)))
  2145. (defun my-rgrep (command-args)
  2146. "My recursive grep. Run COMMAND-ARGS."
  2147. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  2148. nil)))
  2149. (if cmd
  2150. (list (read-shell-command "grep command: "
  2151. cmd
  2152. 'grep-find-history))
  2153. (error "My-Rgrep: Command for rgrep not found")
  2154. )))
  2155. (compilation-start command-args
  2156. 'grep-mode))
  2157. ;; (defun my-rgrep-symbol-at-point (command-args)
  2158. ;; "My recursive grep. Run COMMAND-ARGS."
  2159. ;; (interactive (list (read-shell-command "grep command: "
  2160. ;; (concat (my-rgrep-grep-command)
  2161. ;; " "
  2162. ;; (thing-at-point 'symbol))
  2163. ;; 'grep-find-history)))
  2164. ;; (compilation-start command-args
  2165. ;; 'grep-mode))
  2166. (defmacro define-my-rgrep (name)
  2167. "Define rgrep for NAME."
  2168. `(defun ,(intern (concat "my-rgrep-"
  2169. name)) ()
  2170. ,(format "My recursive grep by %s."
  2171. name)
  2172. (interactive)
  2173. (let ((my-rgrep-default ,name))
  2174. (if (called-interactively-p 'any)
  2175. (call-interactively 'my-rgrep)
  2176. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2177. )
  2178. (define-my-rgrep "ack")
  2179. (define-my-rgrep "ag")
  2180. (define-my-rgrep "gitgrep")
  2181. (define-my-rgrep "grep")
  2182. (define-my-rgrep "global")
  2183. (define-key ctl-x-map "s" 'my-rgrep)
  2184. ;; (defun make ()
  2185. ;; "Run \"make -k\" in current directory."
  2186. ;; (interactive)
  2187. ;; (compile "make -k"))
  2188. (defalias 'make 'compile)
  2189. (defvar sed-in-place-history nil
  2190. "History of `sed-in-place'.")
  2191. (defvar sed-in-place-command "sed --in-place=.bak -e")
  2192. (defun sed-in-place (command)
  2193. "Issue sed in place COMMAND."
  2194. (interactive (list (read-shell-command "sed in place: "
  2195. (concat sed-in-place-command " ")
  2196. 'sed-in-place-history)))
  2197. (shell-command command
  2198. "*sed in place*"))
  2199. (defun dired-do-sed-in-place (&optional arg)
  2200. "Issue sed in place dired. If ARG is given, use the next ARG files."
  2201. (interactive "p")
  2202. (require 'dired-aux)
  2203. (let* ((files (dired-get-marked-files t arg))
  2204. (expr (dired-mark-read-string "Run sed-in-place for %s: "
  2205. nil
  2206. 'sed-in-place
  2207. arg
  2208. files)))
  2209. (if (equal expr
  2210. "")
  2211. (error "No expression specified")
  2212. (shell-command (concat sed-in-place-command
  2213. " '"
  2214. expr
  2215. "' "
  2216. (mapconcat 'shell-quote-argument
  2217. files
  2218. " "))
  2219. "*sed in place*"))))
  2220. (defun dir-show (&optional dir)
  2221. "Show DIR list."
  2222. (interactive)
  2223. (let ((bf (get-buffer-create "*dir show*"))
  2224. (list-directory-brief-switches "-C"))
  2225. (with-current-buffer bf
  2226. (list-directory (or nil
  2227. default-directory)
  2228. nil))
  2229. ))
  2230. (defun my-convmv-sjis2utf8-test ()
  2231. "Run `convmv -r -f sjis -t utf8 *'.
  2232. this is test, does not rename files."
  2233. (interactive)
  2234. (shell-command "convmv -r -f sjis -t utf8 *"))
  2235. (defun my-convmv-sjis2utf8-notest ()
  2236. "Run `convmv -r -f sjis -t utf8 * --notest'."
  2237. (interactive)
  2238. (shell-command "convmv -r -f sjis -t utf8 * --notest"))
  2239. (defun kill-ring-save-buffer-file-name ()
  2240. "Get current filename."
  2241. (interactive)
  2242. (let ((file buffer-file-name))
  2243. (if file
  2244. (progn (kill-new file)
  2245. (message file))
  2246. (message "not visiting file."))))
  2247. (defvar kill-ring-buffer-name "*kill-ring*"
  2248. "Buffer name for `kill-ring-buffer'.")
  2249. (defun open-kill-ring-buffer ()
  2250. "Open kill- ring buffer."
  2251. (interactive)
  2252. (pop-to-buffer
  2253. (with-current-buffer (get-buffer-create kill-ring-buffer-name)
  2254. (erase-buffer)
  2255. (yank)
  2256. (text-mode)
  2257. (current-local-map)
  2258. (goto-char (point-min))
  2259. (yank)
  2260. (current-buffer))))
  2261. (defun set-terminal-header (string)
  2262. "Set terminal header STRING."
  2263. (let ((savepos "\033[s")
  2264. (restorepos "\033[u")
  2265. (movecursor "\033[0;%dH")
  2266. (inverse "\033[7m")
  2267. (restorecolor "\033[0m")
  2268. (cols (frame-parameter nil 'width))
  2269. (length (length string)))
  2270. ;; (redraw-frame (selected-frame))
  2271. (send-string-to-terminal (concat savepos
  2272. (format movecursor
  2273. (1+ (- cols length)))
  2274. inverse
  2275. string
  2276. restorecolor
  2277. restorepos))
  2278. ))
  2279. (defun my-set-terminal-header ()
  2280. "Set terminal header."
  2281. (set-terminal-header (concat " "
  2282. user-login-name
  2283. "@"
  2284. (car (split-string system-name
  2285. "\\."))
  2286. " "
  2287. (format-time-string "%Y/%m/%d %T %z")
  2288. " ")))
  2289. ;; (run-with-timer
  2290. ;; 0.1
  2291. ;; 1
  2292. ;; 'my-set-terminal-header)
  2293. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2294. ;; ;; savage emacs
  2295. ;; ;; when enabled emacs fails to complete
  2296. ;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html
  2297. ;; (defadvice message (before message-for-stupid (arg &rest arg2) activate)
  2298. ;; (setq arg
  2299. ;; (concat arg
  2300. ;; (if (eq nil
  2301. ;; (string-match "\\. *$"
  2302. ;; arg))
  2303. ;; ".")
  2304. ;; " Stupid!")))
  2305. ;; TODO: make these a library
  2306. (defvar info-in-prompt
  2307. nil
  2308. "System info in the form of \"[user@host] \".")
  2309. (setq info-in-prompt
  2310. (concat "["
  2311. user-login-name
  2312. "@"
  2313. (car (split-string system-name
  2314. "\\."))
  2315. "]"))
  2316. (defun my-real-function-subr-p (function)
  2317. "Return t if FUNCTION is a built-in function even if it is advised."
  2318. (let* ((advised (and (symbolp function)
  2319. (featurep 'advice)
  2320. (ad-get-advice-info function)))
  2321. (real-function
  2322. (or (and advised (let ((origname (cdr (assq 'origname advised))))
  2323. (and (fboundp origname)
  2324. origname)))
  2325. function))
  2326. (def (if (symbolp real-function)
  2327. (symbol-function real-function)
  2328. function)))
  2329. (subrp def)))
  2330. ;; (my-real-function-subr-p 'my-real-function-subr-p)
  2331. ;; (defadvice read-from-minibuffer (before info-in-prompt activate)
  2332. ;; "Show system info when use `read-from-minibuffer'."
  2333. ;; (ad-set-arg 0
  2334. ;; (concat my-system-info
  2335. ;; (ad-get-arg 0))))
  2336. ;; (defadvice read-string (before info-in-prompt activate)
  2337. ;; "Show system info when use `read-string'."
  2338. ;; (ad-set-arg 0
  2339. ;; (concat my-system-info
  2340. ;; (ad-get-arg 0))))
  2341. ;; (when (< emacs-major-version 24)
  2342. ;; (defadvice completing-read (before info-in-prompt activate)
  2343. ;; "Show system info when use `completing-read'."
  2344. ;; (ad-set-arg 0
  2345. ;; (concat my-system-info
  2346. ;; (ad-get-arg 0)))))
  2347. (defmacro info-in-prompt-set (&rest functions)
  2348. "Set info-in-prompt advices for FUNCTIONS."
  2349. `(progn
  2350. ,@(mapcar (lambda (f)
  2351. `(defadvice ,f (before info-in-prompt activate)
  2352. "Show info in prompt."
  2353. (let ((orig (ad-get-arg 0)))
  2354. (unless (string-match-p (regexp-quote info-in-prompt)
  2355. orig)
  2356. (ad-set-arg 0
  2357. (concat info-in-prompt
  2358. " "
  2359. orig))))))
  2360. functions)))
  2361. (info-in-prompt-set read-from-minibuffer
  2362. read-string
  2363. completing-read)
  2364. ;;; emacs.el ends here