Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

emacs.el 106 KiB

6 lat temu
13 lat temu
5 lat temu
3 lat temu
12 lat temu
13 lat temu
13 lat temu
4 lat temu
11 lat temu
3 lat temu
11 lat temu
3 lat temu
11 lat temu
13 lat temu
5 lat temu
13 lat temu
4 lat temu
13 lat temu
12 lat temu
4 lat temu
5 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
4 lat temu
13 lat temu
13 lat temu
12 lat temu
3 lat temu
6 lat temu
Remove my-company-lighter-current-length Debugger entered--Lisp error: (error "`global' non-zero exit: global: GTAGS not found.") signal(error ("`global' non-zero exit: global: GTAGS not found.")) error("`%s' non-zero exit: %s" "global" "global: GTAGS not found.") ggtags-process-string("global" "--ignore-case" "-c" "sys") apply(ggtags-process-string "global" ("--ignore-case" "-c" "sys")) #f(compiled-function (prefix) #<bytecode 0x40751ea1>)("sys") #f(compiled-function (string pred action) #<bytecode 0x40751ec9>)("sys" nil t) all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil) completion-pcm--all-completions("" ("sys" point) #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil) completion-basic-all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3) #f(compiled-function (style) #<bytecode 0x4088a97f>)(basic) completion--some(#f(compiled-function (style) #<bytecode 0x4088a97f>) (basic partial-completion emacs22)) completion--nth-completion(2 "sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3 nil) completion-all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3) company-capf(candidates "sys") apply(company-capf (candidates "sys")) company-call-backend-raw(candidates "sys") apply(company-call-backend-raw (candidates "sys")) company--force-sync(company-call-backend-raw (candidates "sys") company-capf) company-call-backend(candidates "sys") company--fetch-candidates("sys") company-calculate-candidates("sys" nil) company--begin-new() company--perform() company-auto-begin() company-manual-begin() my-company-lighter-current-length() eval((my-company-lighter-current-length)) redisplay_internal\ \(C\ function\)()
5 lat temu
Remove my-company-lighter-current-length Debugger entered--Lisp error: (error "`global' non-zero exit: global: GTAGS not found.") signal(error ("`global' non-zero exit: global: GTAGS not found.")) error("`%s' non-zero exit: %s" "global" "global: GTAGS not found.") ggtags-process-string("global" "--ignore-case" "-c" "sys") apply(ggtags-process-string "global" ("--ignore-case" "-c" "sys")) #f(compiled-function (prefix) #<bytecode 0x40751ea1>)("sys") #f(compiled-function (string pred action) #<bytecode 0x40751ec9>)("sys" nil t) all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil) completion-pcm--all-completions("" ("sys" point) #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil) completion-basic-all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3) #f(compiled-function (style) #<bytecode 0x4088a97f>)(basic) completion--some(#f(compiled-function (style) #<bytecode 0x4088a97f>) (basic partial-completion emacs22)) completion--nth-completion(2 "sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3 nil) completion-all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3) company-capf(candidates "sys") apply(company-capf (candidates "sys")) company-call-backend-raw(candidates "sys") apply(company-call-backend-raw (candidates "sys")) company--force-sync(company-call-backend-raw (candidates "sys") company-capf) company-call-backend(candidates "sys") company--fetch-candidates("sys") company-calculate-candidates("sys" nil) company--begin-new() company--perform() company-auto-begin() company-manual-begin() my-company-lighter-current-length() eval((my-company-lighter-current-length)) redisplay_internal\ \(C\ function\)()
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
3 lat temu
6 lat temu
6 lat temu
5 lat temu
3 lat temu
6 lat temu
4 lat temu
3 lat temu
4 lat temu
3 lat temu
11 lat temu
3 lat temu
5 lat temu
4 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
11 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
11 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
8 lat temu
8 lat temu
5 lat temu
8 lat temu
5 lat temu
8 lat temu
8 lat temu
13 lat temu
6 lat temu
11 lat temu
11 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
4 lat temu
4 lat temu
3 lat temu
4 lat temu
4 lat temu
6 lat temu
12 lat temu
13 lat temu
13 lat temu
6 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
5 lat temu
6 lat temu
4 lat temu
6 lat temu
6 lat temu
6 lat temu
12 lat temu
12 lat temu
6 lat temu
12 lat temu
12 lat temu
12 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
5 lat temu
6 lat temu
6 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
Remove my-company-lighter-current-length Debugger entered--Lisp error: (error "`global' non-zero exit: global: GTAGS not found.") signal(error ("`global' non-zero exit: global: GTAGS not found.")) error("`%s' non-zero exit: %s" "global" "global: GTAGS not found.") ggtags-process-string("global" "--ignore-case" "-c" "sys") apply(ggtags-process-string "global" ("--ignore-case" "-c" "sys")) #f(compiled-function (prefix) #<bytecode 0x40751ea1>)("sys") #f(compiled-function (string pred action) #<bytecode 0x40751ec9>)("sys" nil t) all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil) completion-pcm--all-completions("" ("sys" point) #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil) completion-basic-all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3) #f(compiled-function (style) #<bytecode 0x4088a97f>)(basic) completion--some(#f(compiled-function (style) #<bytecode 0x4088a97f>) (basic partial-completion emacs22)) completion--nth-completion(2 "sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3 nil) completion-all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3) company-capf(candidates "sys") apply(company-capf (candidates "sys")) company-call-backend-raw(candidates "sys") apply(company-call-backend-raw (candidates "sys")) company--force-sync(company-call-backend-raw (candidates "sys") company-capf) company-call-backend(candidates "sys") company--fetch-candidates("sys") company-calculate-candidates("sys" nil) company--begin-new() company--perform() company-auto-begin() company-manual-begin() my-company-lighter-current-length() eval((my-company-lighter-current-length)) redisplay_internal\ \(C\ function\)()
5 lat temu
5 lat temu
5 lat temu
Remove my-company-lighter-current-length Debugger entered--Lisp error: (error "`global' non-zero exit: global: GTAGS not found.") signal(error ("`global' non-zero exit: global: GTAGS not found.")) error("`%s' non-zero exit: %s" "global" "global: GTAGS not found.") ggtags-process-string("global" "--ignore-case" "-c" "sys") apply(ggtags-process-string "global" ("--ignore-case" "-c" "sys")) #f(compiled-function (prefix) #<bytecode 0x40751ea1>)("sys") #f(compiled-function (string pred action) #<bytecode 0x40751ec9>)("sys" nil t) all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil) completion-pcm--all-completions("" ("sys" point) #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil) completion-basic-all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3) #f(compiled-function (style) #<bytecode 0x4088a97f>)(basic) completion--some(#f(compiled-function (style) #<bytecode 0x4088a97f>) (basic partial-completion emacs22)) completion--nth-completion(2 "sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3 nil) completion-all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3) company-capf(candidates "sys") apply(company-capf (candidates "sys")) company-call-backend-raw(candidates "sys") apply(company-call-backend-raw (candidates "sys")) company--force-sync(company-call-backend-raw (candidates "sys") company-capf) company-call-backend(candidates "sys") company--fetch-candidates("sys") company-calculate-candidates("sys" nil) company--begin-new() company--perform() company-auto-begin() company-manual-begin() my-company-lighter-current-length() eval((my-company-lighter-current-length)) redisplay_internal\ \(C\ function\)()
5 lat temu
5 lat temu
5 lat temu
3 lat temu
4 lat temu
6 lat temu
6 lat temu
5 lat temu
5 lat temu
6 lat temu
3 lat temu
6 lat temu
4 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
10 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
13 lat temu
8 lat temu
13 lat temu
4 lat temu
6 lat temu
4 lat temu
5 lat temu
13 lat temu
6 lat temu
13 lat temu
12 lat temu
4 lat temu
13 lat temu
13 lat temu
13 lat temu
6 lat temu
6 lat temu
6 lat temu
13 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
5 lat temu
5 lat temu
5 lat temu
12 lat temu
12 lat temu
12 lat temu
6 lat temu
6 lat temu
12 lat temu
12 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
6 lat temu
12 lat temu
5 lat temu
6 lat temu
11 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
6 lat temu
6 lat temu
11 lat temu
6 lat temu
11 lat temu
6 lat temu
4 lat temu
6 lat temu
6 lat temu
11 lat temu
4 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
3 lat temu
5 lat temu
5 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
5 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
3 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186
  1. ;;; emacs.el --- 10sr emacs initialization
  2. ;;; Code:
  3. ;; SETUP_LOAD: (load "bytecomp") ;; Required for WSL environment
  4. ;; SETUP_LOAD: (let ((file "DOTFILES_DIR/emacs.el"))
  5. ;; SETUP_LOAD: (and (file-readable-p file)
  6. ;; SETUP_LOAD: (byte-recompile-file file nil 0 t)))
  7. ;; TODO: Use custom-set-variables in place of set-variable
  8. (setq debug-on-error t)
  9. (when (getenv "_EMACS_EL_PROFILE")
  10. (eval-and-compile
  11. (require 'profiler))
  12. (profiler-start 'cpu))
  13. ;; https://emacs-jp.github.io/tips/startup-optimization
  14. ;; Temporarily change values to speed up initialization
  15. (defconst my-orig-file-name-handler-alist file-name-handler-alist)
  16. (setq file-name-handler-alist nil)
  17. (defconst my-orig-gc-cons-threshold gc-cons-threshold)
  18. (setq gc-cons-threshold most-positive-fixnum)
  19. ;; make directories
  20. (unless (file-directory-p (expand-file-name user-emacs-directory))
  21. (make-directory (expand-file-name user-emacs-directory)))
  22. ;; Custom file
  23. (setq custom-file (expand-file-name "custom.el" user-emacs-directory))
  24. (when (file-readable-p custom-file)
  25. (load custom-file))
  26. (require 'cl-lib)
  27. (require 'simple)
  28. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  29. ;; Some macros for internals
  30. (defvar after-first-visit-hook nil
  31. "Run only once at the first visit of file.")
  32. (defvar after-first-visit-hook--done nil
  33. "Non-nil when `after-first-visit-hook' has already been called.")
  34. (defun after-first-visit-hook-run ()
  35. "Run `after-first-visit-hook' and clear its config."
  36. (when (not after-first-visit-hook--done)
  37. (run-hooks 'after-first-visit-hook))
  38. (setq after-first-visit-hook--done t)
  39. (remove-hook 'find-file-hook
  40. 'after-first-visit-hook-run))
  41. (add-hook 'find-file-hook
  42. 'after-first-visit-hook-run)
  43. (defmacro eval-after-init (&rest body)
  44. "If `after-init-hook' has been run, run BODY immediately.
  45. Otherwize hook it."
  46. (declare (indent 0) (debug t))
  47. `(if after-init-time
  48. ;; Currently after-init-hook is run just after setting after-init-hook
  49. (progn
  50. ,@body)
  51. (add-hook 'after-init-hook
  52. (lambda ()
  53. ,@body))))
  54. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  55. ;; package
  56. (require 'package)
  57. (set-variable 'package-archives
  58. `(,@package-archives
  59. ("melpa" . "https://melpa.org/packages/")
  60. ;; Somehow fails to download via https
  61. ("10sr-el" . "http://10sr.github.io/emacs-lisp/elpa/")))
  62. (when (< emacs-major-version 27)
  63. (package-initialize))
  64. ;; Use package-install-selected-packages to install these
  65. (let ((my '(
  66. vimrc-mode
  67. markdown-mode
  68. yaml-mode
  69. gnuplot-mode
  70. php-mode
  71. erlang
  72. js2-mode
  73. js-doc
  74. ;; git-commit
  75. gitignore-mode
  76. adoc-mode
  77. go-mode
  78. ;; It seems malabar has been merged into jdee and this package
  79. ;; already removed
  80. ;; malabar-mode
  81. gosh-mode
  82. scala-mode
  83. web-mode
  84. toml-mode
  85. json-mode
  86. color-moccur
  87. ggtags
  88. flycheck
  89. auto-highlight-symbol
  90. hl-todo
  91. ;; Currently not available
  92. ;; pp-c-l
  93. xclip
  94. foreign-regexp
  95. multi-term
  96. term-run
  97. editorconfig
  98. git-ps1-mode
  99. restart-emacs
  100. pkgbuild-mode
  101. minibuffer-line
  102. which-key
  103. ;; I think this works in place of my autosave lib
  104. super-save
  105. pipenv
  106. imenu-list
  107. page-break-lines
  108. ;; aggressive-indent
  109. dired-filter
  110. wgrep
  111. magit
  112. git-gutter
  113. end-mark
  114. sl
  115. ;; TODO: Configure pony-tpl-mode
  116. pony-mode
  117. gited
  118. highlight-indentation
  119. diminish
  120. fic-mode
  121. term-cursor
  122. pydoc
  123. color-identifiers-mode
  124. dired-k
  125. blacken
  126. back-button
  127. with-venv
  128. nyan-mode
  129. diredfl
  130. hardhat
  131. hungry-delete
  132. counsel
  133. ivy-prescient
  134. editorconfig
  135. editorconfig-custom-majormode
  136. git-command
  137. prompt-text
  138. ;; 10sr repository
  139. ;; 10sr-extras
  140. terminal-title
  141. dired-list-all-mode
  142. pack
  143. set-modeline-color
  144. read-only-only-mode
  145. smart-revert
  146. autosave
  147. ;;window-organizer
  148. ilookup
  149. pasteboard
  150. awk-preview
  151. recently
  152. fuzzy-finder
  153. )))
  154. (set-variable 'package-selected-packages
  155. (cl-remove-duplicates (append package-selected-packages
  156. my
  157. ()))))
  158. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  159. ;; my-idle-hook
  160. (defvar my-idle-hook nil
  161. "Hook run when idle for several secs.")
  162. (defvar my-idle-hook-sec 5
  163. "Second to run `my-idle-hook'.")
  164. (run-with-idle-timer my-idle-hook-sec
  165. t
  166. (lambda ()
  167. (run-hooks 'my-idle-hook)))
  168. ;; (add-hook 'my-idle-hook
  169. ;; (lambda ()
  170. ;; (message "idle hook message")))
  171. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  172. ;; start and quit
  173. (setq inhibit-startup-message t)
  174. (setq initial-buffer-choice 'messages-buffer)
  175. (setq confirm-kill-emacs 'y-or-n-p)
  176. ;; (setq gc-cons-threshold (* 1024 1024 16))
  177. (setq garbage-collection-messages nil)
  178. (when window-system
  179. (add-to-list 'default-frame-alist '(cursor-type . box))
  180. (add-to-list 'default-frame-alist '(background-color . "white"))
  181. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  182. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  183. ;; does not work?
  184. )
  185. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  186. (menu-bar-mode 1)
  187. (define-key ctl-x-map "M" 'menu-bar-open)
  188. (defalias 'menu 'menu-bar-open)
  189. (and (fboundp 'tool-bar-mode)
  190. (tool-bar-mode 0))
  191. (and (fboundp 'set-scroll-bar-mode)
  192. (set-scroll-bar-mode nil))
  193. (eval-after-init
  194. (message "%s %s" invocation-name emacs-version)
  195. (message "Invocation directory: %s" default-directory)
  196. (message "%s was taken to initialize emacs." (emacs-init-time))
  197. ;; (view-echo-area-messages)
  198. ;; (view-emacs-news)
  199. )
  200. (with-current-buffer "*Messages*"
  201. (emacs-lock-mode 'kill))
  202. (cd ".") ; when using windows use / instead of \ in `default-directory'
  203. ;; locale
  204. (set-language-environment "Japanese")
  205. (set-default-coding-systems 'utf-8-unix)
  206. (prefer-coding-system 'utf-8-unix)
  207. (setq system-time-locale "C")
  208. ;; my prefix map
  209. (defvar my-prefix-map nil
  210. "My prefix map.")
  211. (define-prefix-command 'my-prefix-map)
  212. (global-set-key (kbd "C-^") 'my-prefix-map)
  213. ;; (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  214. ;; (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  215. ;; (comint-show-maximum-output)
  216. ;; kill scratch
  217. (eval-after-init
  218. (let ((buf (get-buffer "*scratch*")))
  219. (when buf
  220. (kill-buffer buf))))
  221. ;; modifier keys
  222. ;; (setq mac-option-modifier 'control)
  223. ;; display
  224. (setq visible-bell t)
  225. (setq ring-bell-function 'ignore)
  226. (mouse-avoidance-mode 'banish)
  227. (setq echo-keystrokes 0.1)
  228. (defun reload-init-file ()
  229. "Reload Emacs init file."
  230. (interactive)
  231. (when (and user-init-file
  232. (file-readable-p user-init-file))
  233. (load-file user-init-file)))
  234. (require 'session nil t)
  235. ;; server
  236. (set-variable 'server-name (concat "server"
  237. (number-to-string (emacs-pid))))
  238. ;; In Cygwin Environment `server-runnning-p' stops when server-use-tcp is nil
  239. ;; In Darwin environment, init fails with message like 'Service name too long'
  240. ;; when server-use-tcp is nil
  241. (when (or (eq system-type
  242. 'cygwin)
  243. (eq system-type
  244. 'darwin))
  245. (set-variable 'server-use-tcp t))
  246. (add-hook 'server-visit-hook
  247. (lambda ()
  248. (use-local-map (copy-keymap (current-local-map)))
  249. (local-set-key (kbd "C-c C-c") 'server-edit)
  250. ))
  251. ;; MSYS2 fix
  252. (when (eq system-type
  253. 'windows-nt)
  254. (setq shell-file-name
  255. (executable-find "bash"))
  256. '(setq function-key-map
  257. `(,@function-key-map ([pause] . [?\C-c])
  258. ))
  259. (define-key key-translation-map
  260. (kbd "<pause>")
  261. (kbd "C-c"))
  262. '(keyboard-translate [pause]
  263. (kbd "C-c")p)
  264. ;; TODO: move to other place later
  265. (when (not window-system)
  266. (setq interprogram-paste-function nil)
  267. (setq interprogram-cut-function nil)))
  268. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  269. ;; global keys
  270. (global-set-key (kbd "<up>") 'scroll-down-line)
  271. (global-set-key (kbd "<down>") 'scroll-up-line)
  272. (global-set-key (kbd "<left>") 'scroll-down)
  273. (global-set-key (kbd "<right>") 'scroll-up)
  274. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  275. ;; (global-set-key (kbd "C-\\") help-map)
  276. (define-key ctl-x-map (kbd "DEL") help-map)
  277. (define-key ctl-x-map (kbd "C-h") help-map)
  278. ;; This is often fired mistakenly
  279. (define-key ctl-x-map "h" 'ignore) ;; Previously mark-whole-buffer
  280. (define-key help-map "a" 'apropos)
  281. ;; disable annoying keys
  282. (global-set-key [prior] 'ignore)
  283. (global-set-key (kbd "<next>") 'ignore)
  284. (global-set-key [menu] 'ignore)
  285. (global-set-key [down-mouse-1] 'ignore)
  286. (global-set-key [down-mouse-2] 'ignore)
  287. (global-set-key [down-mouse-3] 'ignore)
  288. (global-set-key [mouse-1] 'ignore)
  289. (global-set-key [mouse-2] 'ignore)
  290. (global-set-key [mouse-3] 'ignore)
  291. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  292. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  293. ;; Interactively evaluate Emacs Lisp expressions
  294. (define-key ctl-x-map "i" 'ielm)
  295. (when (fboundp 'which-key-mode)
  296. (set-variable 'which-key-idle-delay 0.3)
  297. (which-key-mode 1))
  298. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  299. ;; editor
  300. ;; Basically it should not set globally (instead use something like file local
  301. ;; variables or editorconfig), but for most cases I just need this...
  302. (defun my-set-require-final-newline ()
  303. "Set `require-final-newline'."
  304. (set (make-local-variable 'require-final-newline)
  305. mode-require-final-newline))
  306. (add-hook 'prog-mode-hook
  307. 'my-set-require-final-newline)
  308. (add-hook 'text-mode-hook
  309. 'my-set-require-final-newline)
  310. (add-hook 'conf-mode-hook
  311. 'my-set-require-final-newline)
  312. ;; Used from term-cursor
  313. ;; hbar is too hard to find...
  314. (defun my-cursor-type-change (&rest args)
  315. "ARGS are discarded."
  316. ;; TODO: Support wdired and wgrep
  317. (if buffer-read-only
  318. (setq cursor-type 'hbar)
  319. (setq cursor-type 'box)))
  320. ;; (add-hook 'switch-buffer-functions
  321. ;; 'my-cursor-type-change)
  322. ;; (add-hook 'read-only-mode-hook
  323. ;; 'my-cursor-type-change)
  324. ;; (when (fboundp 'global-term-cursor-mode)
  325. ;; (global-term-cursor-mode 1))
  326. ;; ;; (term-cursor--eval)
  327. (setq kill-whole-line t)
  328. (setq scroll-conservatively 35
  329. scroll-margin 2)
  330. (setq-default major-mode 'text-mode)
  331. (setq next-line-add-newlines nil)
  332. (setq kill-read-only-ok t)
  333. ;; (setq-default line-spacing 0.2)
  334. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  335. ;; (setq-default tab-width 4)
  336. (setq-default indent-tabs-mode nil)
  337. (setq-default indent-line-function 'indent-to-left-margin)
  338. ;; (setq-default indent-line-function nil)
  339. ;; (setq-default truncate-lines t)
  340. ;; (setq truncate-partial-width-windows nil) ; when splitted horizontally
  341. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  342. (delete-selection-mode 1)
  343. (cua-mode 0)
  344. (setq line-move-visual nil)
  345. (setq create-lockfiles nil)
  346. (setq set-mark-command-repeat-pop t)
  347. (add-hook 'before-save-hook
  348. 'time-stamp)
  349. ;; Add Time-stamp: <> to insert timestamp there
  350. (set-variable 'time-stamp-format
  351. "%:y-%02m-%02d %02H:%02M:%02S %Z 10sr")
  352. ;; key bindings
  353. ;; moving around
  354. ;;(keyboard-translate ?\M-j ?\C-j)
  355. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  356. (define-key esc-map "p" 'backward-paragraph)
  357. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  358. (define-key esc-map "n" 'forward-paragraph)
  359. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  360. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  361. (global-set-key (kbd "C-<left>") 'scroll-down)
  362. (global-set-key (kbd "C-<right>") 'scroll-up)
  363. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  364. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  365. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  366. ;; C-h and DEL
  367. (global-set-key (kbd "C-h") (kbd "DEL"))
  368. ;; (normal-erase-is-backspace-mode 1)
  369. ;; M-SPC fixup-whitespace]
  370. ;; (when (fboundp 'global-hungry-delete-mode)
  371. ;; (set-variable 'hungry-delete-join-reluctantly t)
  372. ;; (add-hook 'after-first-visit-hook
  373. ;; 'global-hungry-delete-mode))
  374. ;;(global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  375. (global-set-key (kbd "C-m") 'newline-and-indent)
  376. ;; (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  377. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  378. (define-key esc-map "u" 'undo)
  379. (define-key esc-map "i" (kbd "ESC TAB"))
  380. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  381. ;; (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  382. ;; (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  383. (if (locate-library "prescient")
  384. (progn
  385. (declare-function prescient-fuzzy-regexp
  386. "prescient")
  387. (autoload 'prescient-fuzzy-regexp
  388. "prescient")
  389. (set-variable 'search-default-mode
  390. (lambda (orig lax)
  391. (prescient-fuzzy-regexp orig))))
  392. (set-variable 'search-default-mode t))
  393. ;; (set-variable 'search-whitespace-regexp ".*?")
  394. ;; (set-variable 'isearch-regexp-lax-whitespace t)
  395. ;; (replace-regexp-in-string "\n" "" (prescient-fuzzy-regexp "abc"))
  396. ;; (string-match-p (prescient-fuzzy-regexp "abc") "aaa\nbc")
  397. ;; (isearch-symbol-regexp "abc def" nil)
  398. ;; (isearch-symbol-regexp "abc def" t)
  399. ;; (word-search-regexp "abc def" nil)
  400. ;; (word-search-regexp "abc def" t)
  401. (when (fboundp 'undo-fu-only-undo)
  402. (global-set-key (kbd "C-_") 'undo-fu-only-undo))
  403. (when (fboundp 'undo-fu-only-redo)
  404. (global-set-key (kbd "C-M-_") 'undo-fu-only-redo))
  405. (require 'page-ext nil t)
  406. (when (fboundp 'global-page-break-lines-mode)
  407. (add-hook 'after-first-visit-hook
  408. 'global-page-break-lines-mode))
  409. (with-eval-after-load 'page-break-lines
  410. (set-face-foreground 'page-break-lines
  411. "cyan")
  412. )
  413. (defun my-insert-page-break ()
  414. "Insert ^L."
  415. (interactive)
  416. (insert "\^L\n"))
  417. (define-key esc-map (kbd "C-m") 'my-insert-page-break)
  418. (when (fboundp 'global-git-gutter-mode)
  419. (add-hook 'after-first-visit-hook
  420. 'global-git-gutter-mode))
  421. (with-eval-after-load 'git-gutter
  422. (declare-function global-git-gutter-mode "git-gutter")
  423. (custom-set-variables
  424. '(git-gutter:lighter " Gttr"))
  425. (custom-set-variables
  426. '(git-gutter:update-interval 2))
  427. (custom-set-variables
  428. '(git-gutter:unchanged-sign " "))
  429. (when (>= (display-color-cells)
  430. 256)
  431. (let ((c "color-233"))
  432. (set-face-background 'git-gutter:modified c)
  433. (set-face-background 'git-gutter:added c)
  434. (set-face-background 'git-gutter:deleted c)
  435. (set-face-background 'git-gutter:unchanged c)))
  436. (set-face-background 'git-gutter:modified "magenta")
  437. (set-face-background 'git-gutter:added "green")
  438. (set-face-background 'git-gutter:deleted "red")
  439. )
  440. ;; (when (fboundp 'fancy-narrow-mode)
  441. ;; (add-hook 'after-first-visit-hook
  442. ;; 'fancy-narrow-mode))
  443. ;; https://solist.work/blog/posts/mark-ring/
  444. (set-variable 'mark-ring-max 32)
  445. (defun my-exchange-point-and-mark ()
  446. "`exchange-point-and-mark' without mark activation."
  447. (interactive)
  448. (exchange-point-and-mark)
  449. (deactivate-mark))
  450. (define-key ctl-x-map (kbd "C-x") 'my-exchange-point-and-mark)
  451. (when (fboundp 'counsel-mark-ring)
  452. (define-key ctl-x-map "m" 'counsel-mark-ring))
  453. (with-eval-after-load 'ivy
  454. (defvar ivy-sort-functions-alist)
  455. (add-to-list 'ivy-sort-functions-alist
  456. '(counsel-mark-ring)))
  457. (run-with-idle-timer 10 t
  458. (lambda ()
  459. (push-mark)
  460. ;; (when (fboundp 'visible-mark-move-overlays)
  461. ;; (visible-mark-move-overlays))
  462. ))
  463. (add-hook 'switch-buffer-functions
  464. (lambda (&rest _)
  465. (unless (or (mark t)
  466. (minibufferp))
  467. (push-mark))))
  468. (add-hook 'switch-buffer-functions
  469. (lambda (&rest _)
  470. (when (minibufferp)
  471. ;; Remove mark in minibuffer
  472. (set-mark nil))))
  473. ;; (when (fboundp 'back-button-mode)
  474. ;; (back-button-mode 1))
  475. ;; (when (fboundp 'back-button-local-forward)
  476. ;; (global-set-key (kbd "<right>") 'back-button-local-forward))
  477. ;; (when (fboundp 'back-button-local-backward)
  478. ;; (global-set-key (kbd "<left>") 'back-button-local-backward))
  479. (when (fboundp 'global-visible-mark-mode)
  480. (set-variable 'visible-mark-max 2)
  481. ;; (set-variable 'visible-mark-faces '(visible-mark-face1 visible-mark-face2))
  482. ;; http://emacs.rubikitch.com/visible-mark/
  483. ;; transient-mark-modeでC-SPC C-SPC、あるいはC-SPC C-gすると消えるバグ修正
  484. (defun visible-mark-move-overlays--avoid-disappear (&rest them)
  485. "Fix.
  486. THEM are function and its args."
  487. (let ((mark-active t)) (apply them)))
  488. (advice-add 'visible-mark-move-overlays
  489. :around
  490. 'visible-mark-move-overlays--avoid-disappear)
  491. ;; (global-visible-mark-mode 1)
  492. )
  493. ;; visible-mark-mode
  494. ;; visible-mark-overlays
  495. ;; mark-ring
  496. ;; (equal mark-ring (cl-copy-list mark-ring))
  497. (when (fboundp 'global-hardhat-mode)
  498. (with-eval-after-load 'hardhat
  499. (defvar hardhat-fullpath-protected-regexps)
  500. (add-to-list 'hardhat-fullpath-protected-regexps
  501. "/\\.venv/")
  502. (defvar hardhat-fullpath-editable-regexps)
  503. (add-to-list 'hardhat-fullpath-editable-regexps
  504. "/\\.git/hooks/.*'")
  505. (add-to-list 'hardhat-fullpath-editable-regexps
  506. "/\\.git/EDIT_INDEX\\.diff\\'")
  507. (defvar hardhat-basename-editable-regexps)
  508. (add-to-list 'hardhat-basename-editable-regexps
  509. "\\`Pipfile.lock\\'")
  510. )
  511. (global-hardhat-mode 1))
  512. (with-eval-after-load 'ignoramus
  513. (defvar ignoramus-file-basename-exact-names)
  514. (set-variable 'ignoramus-file-basename-exact-names
  515. (delete "profile"
  516. ignoramus-file-basename-exact-names))
  517. (set-variable 'ignoramus-file-basename-exact-names
  518. (delete "Profile"
  519. ignoramus-file-basename-exact-names))
  520. )
  521. ;; Fill column
  522. (setq-default fill-column 80)
  523. ;; (add-hook 'text-mode-hook 'turn-on-auto-fill)
  524. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  525. ;; title and mode-line
  526. (when (fboundp 'terminal-title-mode)
  527. ;; if TERM is not screen use default value
  528. (if (getenv "TMUX")
  529. ;; if use tmux locally just basename of current dir
  530. (set-variable 'terminal-title-format
  531. '((file-name-nondirectory (directory-file-name
  532. default-directory))))
  533. (if (and (let ((tty-type (frame-parameter nil
  534. 'tty-type)))
  535. (and tty-type
  536. (equal (car (split-string tty-type
  537. "-"))
  538. "screen")))
  539. (not (getenv "SSH_CONNECTION")))
  540. (set-variable 'terminal-title-format
  541. '((file-name-nondirectory (directory-file-name
  542. default-directory))))
  543. ;; seems that TMUX is used locally and ssh to remote host
  544. (set-variable 'terminal-title-format
  545. `("em:"
  546. ,user-login-name
  547. "@"
  548. ,(car (split-string (system-name)
  549. "\\."))
  550. ":"
  551. default-directory))
  552. )
  553. )
  554. (terminal-title-mode))
  555. (setq eol-mnemonic-dos "\\r\\n")
  556. (setq eol-mnemonic-mac "\\r")
  557. (setq eol-mnemonic-unix "")
  558. (add-hook 'after-first-visit-hook
  559. 'which-function-mode)
  560. (line-number-mode 0)
  561. (column-number-mode 0)
  562. (size-indication-mode 0)
  563. (setq mode-line-position
  564. '(:eval (format ":%%l:%%c /%d%s"
  565. (count-lines (point-max)
  566. (point-min))
  567. (if (buffer-narrowed-p)
  568. "[N]"
  569. "")
  570. )))
  571. (when (fboundp 'diminish)
  572. (eval-after-init
  573. (diminish 'recently-mode)
  574. (diminish 'editorconfig-mode)
  575. (diminish 'which-key-mode)
  576. )
  577. (with-eval-after-load 'whitespace
  578. (diminish 'global-whitespace-mode))
  579. (with-eval-after-load 'page-break-lines
  580. (diminish 'page-break-lines-mode))
  581. (with-eval-after-load 'auto-highlight-symbol
  582. (diminish 'auto-highlight-symbol-mode))
  583. (with-eval-after-load 'color-identifiers-mode
  584. (diminish 'color-identifiers-mode))
  585. (with-eval-after-load 'highlight-indentation
  586. (diminish 'highlight-indentation-mode))
  587. (with-eval-after-load 'back-button
  588. (diminish 'back-button-mode))
  589. (with-eval-after-load 'git-gutter
  590. (diminish 'git-gutter-mode))
  591. (with-eval-after-load 'autorevert
  592. (diminish 'auto-revert-mode))
  593. )
  594. (setq mode-line-front-space "")
  595. ;; (setq mode-line-end-spaces "")
  596. ;; Set current frame name to empty string
  597. (setq-default mode-line-format
  598. (let* ((l mode-line-format)
  599. (l (cl-substitute " " " "
  600. l
  601. :test 'equal))
  602. (l (cl-substitute " " " "
  603. l
  604. :test 'equal))
  605. )
  606. l))
  607. (set-frame-parameter nil 'name "")
  608. ;; See color-name-rgb-alist for available color names
  609. ;; http://www.raebear.net/computers/emacs-colors/
  610. ;; https://www.emacswiki.org/emacs/ListColors
  611. ;; (list-colors-display is not a complete list)
  612. (defconst my-mode-line-background-default
  613. (face-background 'mode-line)
  614. "Default color of mode-line at init.")
  615. (defun my-mode-line-color-update (&rest args)
  616. "ARGS are discarded"
  617. (let ((ro "skyblue")
  618. (rw my-mode-line-background-default))
  619. (if (or (not buffer-read-only)
  620. (and (eq major-mode 'wdired-mode)))
  621. (set-face-background 'mode-line
  622. rw)
  623. (set-face-background 'mode-line
  624. ro))))
  625. (add-hook 'switch-buffer-functions
  626. 'my-mode-line-color-update)
  627. (add-hook 'read-only-mode-hook
  628. 'my-mode-line-color-update)
  629. (add-hook 'wdired-mode-hook
  630. 'my-mode-line-color-update)
  631. (advice-add 'wdired-change-to-dired-mode
  632. :after
  633. 'my-mode-line-color-update)
  634. (advice-add 'wgrep-change-to-wgrep-mode
  635. :after
  636. 'my-mode-line-color-update)
  637. (advice-add 'wgrep-to-original-mode
  638. :after
  639. 'my-mode-line-color-update)
  640. (with-eval-after-load 'hardhat
  641. ;; hardhat-mode-hook does not work as expected...
  642. (advice-add 'hardhat-local-hook
  643. :after
  644. 'my-mode-line-color-update))
  645. (set-face-background 'header-line
  646. my-mode-line-background-default)
  647. ;; sky-color-clock
  648. ;; https://tsuu32.hatenablog.com/entry/2019/11/07/020005
  649. (declare-function sky-color-clock "sky-color-clock")
  650. (declare-function sky-color-clock-initialize "sky-color-clock")
  651. (defun sky-color-clock--form ()
  652. "Gen string for right aligned form."
  653. (let* ((sky-color-clock-str
  654. (propertize (sky-color-clock) 'help-echo (format-time-string "Sky color clock\n%F (%a)")))
  655. (mode-line-right-margin
  656. (propertize " " 'display `(space :align-to (- right-fringe ,(length sky-color-clock-str))))))
  657. (concat mode-line-right-margin sky-color-clock-str)))
  658. (when (require 'sky-color-clock nil t)
  659. (sky-color-clock-initialize 35) ; Tokyo, Japan
  660. (set-variable 'sky-color-clock-format "%H:%M")
  661. (set-variable 'sky-color-clock-enable-emoji-icon nil)
  662. (setq mode-line-end-spaces '(:eval (sky-color-clock--form))))
  663. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  664. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  665. ;; minibuffer
  666. (setq insert-default-directory t)
  667. (setq completion-ignore-case t
  668. read-file-name-completion-ignore-case t
  669. read-buffer-completion-ignore-case t)
  670. (setq resize-mini-windows t)
  671. (temp-buffer-resize-mode 1)
  672. (savehist-mode 1)
  673. (defvar display-time-format "%Y/%m/%d %a %H:%M")
  674. (set-variable 'help-at-pt-display-when-idle t)
  675. (fset 'yes-or-no-p 'y-or-n-p)
  676. ;; complete symbol when `eval'
  677. (define-key read-expression-map (kbd "TAB") 'completion-at-point)
  678. (define-key minibuffer-local-map (kbd "C-u")
  679. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  680. ;; I dont know these bindings are good
  681. (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
  682. (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
  683. (with-eval-after-load 'minibuffer-line
  684. (set-face-underline 'minibuffer-line nil)
  685. )
  686. (when (fboundp 'minibuffer-line-mode)
  687. (set-variable 'minibuffer-line-refresh-interval
  688. 25)
  689. ;; Set idle timer
  690. (defvar my-minibuffer-line--idle-timer nil)
  691. (defvar minibuffer-line-mode)
  692. (add-hook 'minibuffer-line-mode-hook
  693. (lambda ()
  694. (when my-minibuffer-line--idle-timer
  695. (cancel-timer my-minibuffer-line--idle-timer)
  696. (setq my-minibuffer-line--idle-timer nil))
  697. (when minibuffer-line-mode
  698. (setq my-minibuffer-line--idle-timer
  699. (run-with-idle-timer 0.5
  700. t
  701. 'minibuffer-line--update)))))
  702. (set-variable 'minibuffer-line-format
  703. `(,(concat user-login-name
  704. "@"
  705. (car (split-string (system-name)
  706. "\\."))
  707. ":")
  708. (:eval (abbreviate-file-name (or buffer-file-name
  709. default-directory)))
  710. (:eval (and (fboundp 'git-ps1-mode-get-current)
  711. (git-ps1-mode-get-current " [GIT:%s]")))
  712. " "
  713. (:eval (format-time-string display-time-format))))
  714. (when (eval-and-compile (require 'nyan-mode nil t))
  715. (set-variable 'minibuffer-line-format
  716. '((:eval (progn
  717. (list (nyan-create))))))
  718. (defun my-nyan-set-length (&rest _)
  719. "Set `nyan-mode' length to window width."
  720. (set-variable 'nyan-bar-length
  721. (- (frame-parameter nil 'width) 4)))
  722. ;; (my-nyan-set-length)
  723. ;; (add-hook 'after-init-hook
  724. ;; 'my-nyan-set-length)
  725. (add-hook 'window-configuration-change-hook
  726. 'my-nyan-set-length)
  727. (add-hook 'switch-buffer-functions
  728. 'my-nyan-set-length)
  729. )
  730. (minibuffer-line-mode 1)
  731. )
  732. (when (fboundp 'prompt-text-mode)
  733. (set-variable 'prompt-text-format
  734. `(,(concat ""
  735. user-login-name
  736. "@"
  737. (car (split-string (system-name)
  738. "\\."))
  739. ":")
  740. (:eval (abbreviate-file-name (or buffer-file-name
  741. default-directory)))
  742. (:eval (and (fboundp 'git-ps1-mode-get-current)
  743. (git-ps1-mode-get-current " [GIT:%s]")))
  744. " "
  745. (:eval (format-time-string display-time-format))
  746. "\n"
  747. (:eval (symbol-name this-command))
  748. ": "))
  749. (prompt-text-mode 1))
  750. (with-eval-after-load 'helm
  751. (defvar helm-map)
  752. (define-key helm-map (kbd "C-h") (kbd "DEL")))
  753. (defun my-shrink-path-width (path width)
  754. "Shrink PATH to be same or shorter than WIDTH."
  755. (setq path (abbreviate-file-name path))
  756. (if (file-remote-p path)
  757. (let* ((remote (file-remote-p path))
  758. (localname (file-remote-p path 'localname))
  759. (remote-length (length remote))
  760. (width-localname (- width remote-length))
  761. (localname-shrinked (my-shrink-path-width localname width-localname)))
  762. (concat remote localname-shrinked))
  763. (let ((yet (split-string path "/"))
  764. (done nil)
  765. (result path))
  766. (while (and yet
  767. (< width (length result)))
  768. (let ((current (pop yet)))
  769. (unless (string= "" current)
  770. (setq current (substring current 0 1)))
  771. (setq done
  772. (append done (list current))))
  773. (setq result
  774. (concat (mapconcat 'identity
  775. (append done yet)
  776. "/"))))
  777. result)))
  778. ;; (my-shrink-path-width "/Applications/Vivaldi.app/Contents/MacOS/Vivaldi" 20)
  779. ;; (my-shrink-path-width "/scp:sakura:/Applications/Vivaldi.app/Contents/MacOS/Vivaldi" 30)
  780. ;; (my-shrink-path-width "/scp:sakura:/Applications/Vivaldi.app/Contents/MacOS/Vivaldi" 20)
  781. (setq-default header-line-format
  782. '(:eval (let ((f (or (buffer-file-name)
  783. default-directory)))
  784. (when f
  785. (my-shrink-path-width f (window-width))))))
  786. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  787. ;; letters, font-lock mode and fonts
  788. (when (fboundp 'color-identifiers-mode)
  789. (add-hook 'prog-mode-hook
  790. 'color-identifiers-mode))
  791. (setq text-quoting-style 'grave)
  792. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  793. ;; (set-window-margins (selected-window) 1 1)
  794. (unless window-system
  795. (setq frame-background-mode 'dark))
  796. (and (or (eq system-type 'Darwin)
  797. (eq system-type 'darwin))
  798. (fboundp 'mac-set-input-method-parameter)
  799. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  800. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  801. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  802. (boundp 'input-method-inactivate-hook))
  803. (add-hook 'input-method-activate-hook
  804. (lambda () (set-cursor-color "red")))
  805. (add-hook 'input-method-inactivate-hook
  806. (lambda () (set-cursor-color "black"))))
  807. (when (fboundp 'show-paren-mode)
  808. (add-hook 'after-first-visit-hook
  809. 'show-paren-mode))
  810. (set-variable 'show-paren-delay 0.5)
  811. (set-variable 'show-paren-style 'parenthesis) ; mixed is hard to read
  812. ;; (set-face-background 'show-paren-match
  813. ;; "black")
  814. ;; ;; (face-foreground 'default))
  815. ;; (set-face-foreground 'show-paren-match
  816. ;; "white")
  817. ;; (set-face-inverse-video-p 'show-paren-match
  818. ;; t)
  819. (transient-mark-mode 1)
  820. (global-font-lock-mode 1)
  821. (setq font-lock-global-modes
  822. '(not
  823. help-mode
  824. eshell-mode
  825. ;;term-mode
  826. Man-mode
  827. ))
  828. ;; (standard-display-ascii ?\n "$\n")
  829. ;; (defvar my-eol-face
  830. ;; '(("\n" . (0 font-lock-comment-face t nil)))
  831. ;; )
  832. ;; (defvar my-tab-face
  833. ;; '(("\t" . '(0 highlight t nil))))
  834. (defvar my-jspace-face
  835. '(("\u3000" . '(0 highlight t nil))))
  836. (add-hook 'font-lock-mode-hook
  837. (lambda ()
  838. ;; (font-lock-add-keywords nil my-eol-face)
  839. (font-lock-add-keywords nil my-jspace-face)
  840. ))
  841. (set-variable 'font-lock-maximum-decoration
  842. '(
  843. ;; (python-mode . 2)
  844. (t . 2)
  845. ))
  846. (when (fboundp 'global-whitespace-mode)
  847. (add-hook 'after-first-visit-hook
  848. 'global-whitespace-mode))
  849. (add-hook 'dired-mode-hook
  850. ;; Other way to disable in dired buffers?
  851. (lambda () (set-variable 'whitespace-style nil t)))
  852. (with-eval-after-load 'whitespace
  853. (defvar whitespace-display-mappings)
  854. (defvar whitespace-mode)
  855. (add-to-list 'whitespace-display-mappings
  856. ;; We need t since last one takes precedence
  857. `(tab-mark ?\t ,(vconcat "|>\t")) t)
  858. ;; (add-to-list 'whitespace-display-mappings
  859. ;; `(newline-mark ?\n ,(vconcat "$\n")))
  860. (set-variable 'whitespace-style '(face
  861. trailing ; trailing blanks
  862. ;; tabs
  863. ;; spaces
  864. ;; lines
  865. lines-tail ; lines over 80
  866. newline ; newlines
  867. ;; empty ; empty lines at beg or end of buffer
  868. ;; big-indent
  869. ;; space-mark
  870. tab-mark
  871. newline-mark ; use display table for newline
  872. ))
  873. ;; (setq whitespace-newline 'font-lock-comment-face)
  874. ;; (setq whitespace-style (delq 'newline-mark whitespace-style))
  875. (defun my-whitesspace-mode-reload ()
  876. "Reload whitespace-mode config."
  877. (interactive)
  878. (when whitespace-mode
  879. (whitespace-mode 0)
  880. (whitespace-mode 1)))
  881. (set-variable 'whitespace-line-column nil) ; Use value of `fill-column'
  882. (when (>= (display-color-cells)
  883. 256)
  884. (set-face-foreground 'whitespace-newline "color-109")
  885. (set-face-foreground 'whitespace-line
  886. nil)
  887. (set-face-background 'whitespace-line
  888. "gray35")
  889. ;; (progn
  890. ;; (set-face-bold-p 'whitespace-newline
  891. ;; t))
  892. ))
  893. (defun my-gen-hl-line-color-dark ()
  894. "Generate color for current line in black background."
  895. (let* ((candidates (mapcar 'number-to-string (number-sequence 1 6)))
  896. (limit (length candidates))
  897. (r 0) (g 0) (b 0))
  898. (while (and (<= (abs (- r g)) 1)
  899. (<= (abs (- g b)) 1)
  900. (<= (abs (- b r)) 1))
  901. (setq r (random limit))
  902. (setq g (random limit))
  903. (setq b (random limit)))
  904. (format "#%s%s%s"
  905. (nth r candidates)
  906. (nth g candidates)
  907. (nth b candidates)
  908. )))
  909. ;; (my-gen-hl-line-color-dark)
  910. ;; highlight current line
  911. ;; http://wiki.riywo.com/index.php?Meadow
  912. (face-spec-set 'hl-line
  913. `((((min-colors 256)
  914. (background dark))
  915. ;; Rotate midnightblue
  916. (:background ,(my-gen-hl-line-color-dark)))
  917. (((min-colors 256)
  918. (background light))
  919. ;; TODO: What is should be?
  920. (:background "color-234"))
  921. (t
  922. (:underline "black"))))
  923. (set-variable 'hl-line-global-modes
  924. '(not
  925. term-mode))
  926. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  927. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  928. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  929. ;;(require 'set-modeline-color nil t)
  930. ;; (let ((fg (face-foreground 'default))
  931. ;; (bg (face-background 'default)))
  932. ;; (set-face-background 'mode-line-inactive
  933. ;; (if (face-inverse-video-p 'mode-line) fg bg))
  934. ;; (set-face-foreground 'mode-line-inactive
  935. ;; (if (face-inverse-video-p 'mode-line) bg fg)))
  936. ;; (set-face-underline 'mode-line-inactive
  937. ;; t)
  938. ;; (set-face-underline 'vertical-border
  939. ;; nil)
  940. ;; (when (require 'end-mark nil t)
  941. ;; (global-end-mark-mode))
  942. ;; M-x highlight-* to highlight things
  943. (global-hi-lock-mode 1)
  944. (unless (fboundp 'highlight-region-text)
  945. (defun highlight-region-text (beg end)
  946. "Highlight text between BEG and END."
  947. (interactive "r")
  948. (highlight-regexp (regexp-quote (buffer-substring-no-properties beg
  949. end)))
  950. (setq deactivate-mark t)))
  951. (when (fboundp 'auto-highlight-symbol-mode)
  952. (add-hook 'prog-mode-hook
  953. 'auto-highlight-symbol-mode))
  954. ;; Not work in combination with flyspell-mode
  955. ;; (when (fboundp 'global-auto-highlight-symbol-mode)
  956. ;; (add-hook 'after-first-visit-hook
  957. ;; 'global-auto-highlight-symbol-mode))
  958. (set-variable 'ahs-idle-interval 0.6)
  959. (when (fboundp 'highlight-indentation-mode)
  960. (dolist (hook
  961. '(
  962. prog-mode-hook
  963. text-mode-hook
  964. ))
  965. ;; Makes display slow?
  966. ;; (add-hook hook
  967. ;; 'highlight-indentation-mode)
  968. ))
  969. (with-eval-after-load 'highlight-indentation
  970. (set-face-background 'highlight-indentation-face "color-236"))
  971. ;; (set-face-background 'highlight-indentation-current-column-face "#c3b3b3")
  972. (when (fboundp 'fic-mode)
  973. (add-hook 'prog-mode-hook
  974. 'fic-mode))
  975. (when (fboundp 'global-tree-sitter-mode)
  976. (add-hook 'after-first-visit-hook
  977. 'global-tree-sitter-mode)
  978. (add-hook 'tree-sitter-after-on-hook
  979. 'tree-sitter-hl-mode))
  980. (with-eval-after-load 'tree-sitter
  981. (require 'tree-sitter-langs nil t))
  982. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  983. ;; file handling
  984. (auto-insert-mode 1)
  985. ;; fuzzy-finder
  986. (set-variable 'fuzzy-finder-executable "fzf")
  987. (set-variable 'fuzzy-finder-default-arguments
  988. (concat "--ansi "
  989. "--color='bg+:-1' "
  990. "--inline-info "
  991. "--cycle "
  992. "--reverse "
  993. "--multi "
  994. "--print0 "
  995. "--prompt=\"[`pwd`]> \" "))
  996. (set-variable 'fuzzy-finder-default-output-delimiter
  997. "\0")
  998. (set-variable 'fuzzy-finder-default-input-command
  999. (let ((find (or (executable-find "bfs") ;; Breadth-first find https://github.com/tavianator/bfs
  1000. ;; Use gfind if available?
  1001. "find"))
  1002. (fd (or (executable-find "fdfind")
  1003. (executable-find "fd"))))
  1004. (if fd
  1005. (concat "set -eu; set -o pipefail; "
  1006. "echo .; "
  1007. "echo ..; "
  1008. "command " fd " "
  1009. "--follow --hidden --no-ignore "
  1010. "--color always "
  1011. "2>/dev/null")
  1012. (concat "set -eu; set -o pipefail; "
  1013. "echo .; "
  1014. "echo ..; "
  1015. "command " find " -L . "
  1016. "-mindepth 1 "
  1017. "\\( -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune "
  1018. "-o -print "
  1019. "2> /dev/null "
  1020. "| "
  1021. "cut -b3-"))))
  1022. (declare-function fuzzy-finder
  1023. "fuzzy-finder")
  1024. (declare-function fuzzy-finder-find-files-projectile
  1025. "fuzzy-finder")
  1026. (defun my-fuzzy-finder-or-find-file ()
  1027. "Call `fuzzy-finder' if usable or call `find-file'."
  1028. (declare (interactive-only t))
  1029. (interactive)
  1030. (if (and (executable-find "fzf")
  1031. (fboundp 'fuzzy-finder)
  1032. (not (file-remote-p default-directory)))
  1033. (fuzzy-finder-find-files-projectile)
  1034. (call-interactively 'find-file)))
  1035. (define-key ctl-x-map "f" 'my-fuzzy-finder-or-find-file)
  1036. (declare-function fuzzy-finder-action-find-files-goto-line
  1037. "fuzzy-finder")
  1038. (defun my-fuzzy-finder-ripgrep-lines ()
  1039. "Fzf all lines."
  1040. (interactive)
  1041. (unless (executable-find "rg")
  1042. (error "rg not found"))
  1043. (fuzzy-finder :input-command "rg -nH --no-heading --hidden --follow --glob '!.git/*' --color=always ^"
  1044. :action 'fuzzy-finder-action-find-files-goto-line))
  1045. (define-key ctl-x-map "S" 'my-fuzzy-finder-ripgrep-lines)
  1046. (defun my-fuzzy-finder-dired ()
  1047. "Fuzzy finder directory."
  1048. (interactive)
  1049. (fuzzy-finder :input-command "fd --hidden --no-ignore --type directory"
  1050. :directory (expand-file-name "~")))
  1051. (define-key ctl-x-map "d" 'my-fuzzy-finder-dired)
  1052. ;; (set-variable 'fuzzy-finder-default-command "selecta")
  1053. ;; (set-variable 'fuzzy-finder-default-command "peco")
  1054. ;; (set-variable 'fuzzy-finder-default-command "percol")
  1055. ;; (set-variable 'fuzzy-finder-default-command "fzy")
  1056. ;; (set-variable 'fuzzy-finder-default-command "sk --ansi --no-hscroll --reverse")
  1057. ;; (set-variable 'fuzzy-finder-default-command "pick")
  1058. ;; recently
  1059. ;; TODO: Enable after first visit file?
  1060. (with-eval-after-load 'recently
  1061. (defvar recently-excludes)
  1062. (add-to-list 'recently-excludes
  1063. (rx-to-string (list 'and
  1064. 'string-start
  1065. (expand-file-name package-user-dir))
  1066. t)))
  1067. (when (fboundp 'recently-mode)
  1068. (define-key ctl-x-map (kbd "C-r") 'recently-show)
  1069. (set-variable 'recently-max 1000)
  1070. (recently-mode 1))
  1071. (defvar my-cousel-recently-history nil "History of `my-counsel-recently'.")
  1072. (declare-function recently-list "recently" t)
  1073. (when (and (require 'recently nil t)
  1074. (fboundp 'ivy-read))
  1075. (defun my-counsel-recently ()
  1076. "Counsel `recently'."
  1077. (interactive)
  1078. (ivy-read "Recently: " (mapcar 'abbreviate-file-name (recently-list))
  1079. :require-match t
  1080. :history 'my-cousel-recently-history
  1081. :preselect default-directory
  1082. :action (lambda (x) (find-file x))
  1083. :caller 'my-counsel-recently))
  1084. (define-key ctl-x-map (kbd "C-r") 'my-counsel-recently)
  1085. )
  1086. ;; (when (fboundp 'editorconfig-mode)
  1087. ;; (add-hook 'after-first-visit-hook
  1088. ;; 'editorconfig-mode)
  1089. ;; (add-hook 'after-first-visit-hook
  1090. ;; 'editorconfig-mode-apply
  1091. ;; t)) ;; Do after enabling editorconfig-mode
  1092. (when (eval-and-compile (require 'editorconfig nil t))
  1093. (set-variable 'editorconfig--enable-20210221-testing t)
  1094. (editorconfig-mode 1))
  1095. (set-variable 'editorconfig-get-properties-function
  1096. 'editorconfig-core-get-properties-hash)
  1097. (set-variable 'editorconfig-mode-lighter "")
  1098. (when (fboundp 'ws-butler-mode)
  1099. (set-variable 'editorconfig-trim-whitespaces-mode
  1100. 'ws-butler-mode))
  1101. (with-eval-after-load 'org-src
  1102. ;; [*.org\[\*Org Src*\[ c \]*\]]
  1103. (add-hook 'org-src-mode-hook
  1104. 'editorconfig-mode-apply t))
  1105. (when (fboundp 'editorconfig-custom-majormode)
  1106. (add-hook 'editorconfig-after-apply-functions
  1107. 'editorconfig-custom-majormode))
  1108. ;; Add readonly=true to set read-only-mode
  1109. (add-hook 'editorconfig-after-apply-functions
  1110. (lambda (props)
  1111. (let ((r (gethash 'readonly props)))
  1112. (when (and (string= r "true")
  1113. (not buffer-read-only))
  1114. (read-only-mode 1)))))
  1115. (add-hook 'editorconfig-after-apply-functions
  1116. (lambda (props)
  1117. (when (derived-mode-p 'makefile-mode)
  1118. (setq indent-tabs-mode t))
  1119. (when (derived-mode-p 'diff-mode)
  1120. (editorconfig-set-trailing-ws "false")
  1121. (editorconfig-set-trailing-nl "false")
  1122. )
  1123. ))
  1124. (when (fboundp 'editorconfig-auto-apply-enable)
  1125. (add-hook 'editorconfig-conf-mode-hook
  1126. 'editorconfig-auto-apply-enable))
  1127. ;; (when (fboundp 'editorconfig-charset-extras)
  1128. ;; (add-hook 'editorconfig-custom-hooks
  1129. ;; 'editorconfig-charset-extras))
  1130. (setq revert-without-query '(".+"))
  1131. ;; save cursor position
  1132. (when (fboundp 'save-place-mode)
  1133. (autoload 'save-place-find-file-hook "saveplace")
  1134. (add-hook 'after-first-visit-hook
  1135. 'save-place-mode)
  1136. (add-hook 'after-first-visit-hook
  1137. 'save-place-find-file-hook
  1138. t))
  1139. (set-variable 'save-place-file (concat user-emacs-directory
  1140. "places"))
  1141. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  1142. (setq make-backup-files t)
  1143. (setq vc-make-backup-files t)
  1144. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  1145. (setq backup-directory-alist
  1146. (cons (cons "." (expand-file-name (concat user-emacs-directory
  1147. "backup")))
  1148. backup-directory-alist))
  1149. (setq version-control 't)
  1150. (setq delete-old-versions t)
  1151. (setq kept-new-versions 20)
  1152. (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
  1153. "auto-save/")))
  1154. ;; (setq delete-auto-save-files t)
  1155. (setq auto-save-visited-interval 8)
  1156. (auto-save-visited-mode 1)
  1157. ;; (add-to-list 'auto-save-file-name-transforms
  1158. ;; `(".*" ,(concat user-emacs-directory "auto-save-dir") t))
  1159. ;; (setq auto-save-interval 3)
  1160. ;; (auto-save-mode 1)
  1161. (add-to-list 'completion-ignored-extensions ".bak")
  1162. (set-variable 'completion-cycle-threshold nil) ;; NEVER use
  1163. (setq delete-by-moving-to-trash t)
  1164. ;; trash-directory "~/.emacs.d/trash")
  1165. (add-hook 'after-save-hook
  1166. 'executable-make-buffer-file-executable-if-script-p)
  1167. (when (fboundp 'smart-revert-on)
  1168. (smart-revert-on))
  1169. ;; autosave
  1170. ;; auto-save-visited-mode can be used instead?
  1171. ;; (when (require 'autosave nil t)
  1172. ;; (autosave-set 8))
  1173. ;; bookmarks
  1174. (set-variable 'bookmark-default-file
  1175. (expand-file-name (concat user-emacs-directory
  1176. "bmk")))
  1177. (set-variable 'bookmark-sort-flag nil)
  1178. (defun my-bookmark-set ()
  1179. "My `bookmark-set'."
  1180. (interactive)
  1181. (cl-assert (or buffer-file-name
  1182. default-directory))
  1183. (let ((name (file-name-nondirectory (or buffer-file-name
  1184. (directory-file-name default-directory))))
  1185. (linenum (count-lines (point-min)
  1186. (point)))
  1187. (linetext (buffer-substring-no-properties (point-at-bol)
  1188. (point-at-eol))))
  1189. (bookmark-set (format "%s:%d:%s"
  1190. name linenum linetext)
  1191. nil)))
  1192. ;; Done by advice instead
  1193. ;; (set-variable 'bookmark-save-flag
  1194. ;; 1)
  1195. (with-eval-after-load 'recentf
  1196. (defvar recentf-exclude)
  1197. (defvar bookmark-default-file)
  1198. (add-to-list 'recentf-exclude
  1199. (regexp-quote bookmark-default-file)))
  1200. (defvar bookmark-default-file)
  1201. (defun my-bookmark-set--advice (orig-func &rest args)
  1202. "Function for `bookmark-set-internal'.
  1203. ORIG-FUNC is the target function, and ARGS is the argument when it is called."
  1204. (bookmark-load bookmark-default-file)
  1205. (apply orig-func args)
  1206. (bookmark-save))
  1207. (with-eval-after-load 'bookmark
  1208. (advice-add 'bookmark-set-internal
  1209. :around
  1210. 'my-bookmark-set--advice))
  1211. (define-key ctl-x-map "b" 'list-bookmarks)
  1212. (when (fboundp 'counsel-bookmark)
  1213. (define-key ctl-x-map "b" 'counsel-bookmark))
  1214. (define-key ctl-x-map "B" 'my-bookmark-set)
  1215. ;; vc
  1216. (set-variable 'vc-handled-backends '(RCS))
  1217. (set-variable 'vc-rcs-register-switches "-l")
  1218. (set-variable 'vc-rcs-checkin-switches "-l")
  1219. (set-variable 'vc-command-messages t)
  1220. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1221. ;; share clipboard with x
  1222. ;; this page describes this in details, but only these sexps seem to be needed
  1223. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  1224. (and nil
  1225. (not window-system)
  1226. (not (eq window-system 'mac))
  1227. (getenv "DISPLAY")
  1228. (not (equal (getenv "DISPLAY") ""))
  1229. (executable-find "xclip")
  1230. ;; (< emacs-major-version 24)
  1231. '(require 'xclip nil t)
  1232. nil
  1233. (turn-on-xclip))
  1234. (declare-function turn-on-pasteboard "pasteboard")
  1235. (and (eq system-type 'darwin)
  1236. (require 'pasteboard nil t)
  1237. (turn-on-pasteboard))
  1238. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1239. ;; some modes and hooks
  1240. ;; Include some extra modes
  1241. (require 'generic-x)
  1242. ;; Derived from https://github.com/ensime/ensime-emacs/issues/591#issuecomment-291916753
  1243. (defun my-scalafmt ()
  1244. (interactive)
  1245. (cl-assert buffer-file-name)
  1246. (cl-assert (not (buffer-modified-p)))
  1247. (let* ((configdir (locate-dominating-file default-directory ".scalafmt.conf"))
  1248. (configoption (if configdir
  1249. (concat " --config "
  1250. (shell-quote-argument (expand-file-name configdir))
  1251. ".scalafmt.conf"
  1252. )
  1253. ""))
  1254. (str (concat "scalafmt -f "
  1255. (shell-quote-argument buffer-file-name)
  1256. configoption
  1257. " -i --exclude ensime")))
  1258. (message str)
  1259. (shell-command-to-string str))
  1260. (message "scalafmt done")
  1261. (revert-buffer nil t))
  1262. (when (fboundp 'web-mode)
  1263. (add-to-list 'auto-mode-alist
  1264. '("\\.html\\.j2\\'" . web-mode))
  1265. (add-to-list 'auto-mode-alist
  1266. ;; Django Template Language
  1267. '("\\.dtl\\'" . web-mode))
  1268. )
  1269. (when (locate-library "wgrep")
  1270. (set-variable 'wgrep-auto-save-buffer t)
  1271. (with-eval-after-load 'grep
  1272. (defvar grep-mode-map)
  1273. (define-key grep-mode-map
  1274. "e"
  1275. 'wgrep-change-to-wgrep-mode)))
  1276. (when (fboundp 'grep-context-mode)
  1277. (add-hook 'compilation-mode-hook #'grep-context-mode))
  1278. (with-eval-after-load 'remember
  1279. (defvar remember-mode-map)
  1280. (define-key remember-mode-map (kbd "C-x C-s") 'ignore))
  1281. (set-variable 'remember-notes-initial-major-mode
  1282. 'change-log-mode)
  1283. (declare-function global-magit-file-mode "magit-files")
  1284. (with-eval-after-load 'magit-files
  1285. ;; `global-magit-file-mode' is enabled by default and this mode overwrites
  1286. ;; existing keybindings.
  1287. ;; Apparently it is a HARMFUL behavior and it is really awful that I have
  1288. ;; to disable thie mode here, but do anyway.
  1289. ;; See also https://github.com/magit/magit/issues/3517
  1290. (global-magit-file-mode -1))
  1291. (with-eval-after-load 'magit-section
  1292. (set-face-background 'magit-section-highlight
  1293. nil))
  1294. ;; Sane colors
  1295. (with-eval-after-load 'magit-diff
  1296. (set-face-background 'magit-diff-context nil)
  1297. (set-face-background 'magit-diff-context-highlight nil)
  1298. (set-face-foreground 'magit-diff-hunk-heading nil)
  1299. (set-face-background 'magit-diff-hunk-heading nil)
  1300. (set-face-foreground 'magit-diff-hunk-heading-highlight nil)
  1301. (set-face-background 'magit-diff-hunk-heading-highlight nil)
  1302. ;; https://blog.shibayu36.org/entry/2016/03/27/220552
  1303. (set-face-foreground 'magit-diff-added "green")
  1304. (set-face-background 'magit-diff-added nil)
  1305. (set-face-foreground 'magit-diff-added-highlight "green")
  1306. (set-face-background 'magit-diff-added-highlight nil)
  1307. (set-face-foreground 'magit-diff-removed "red")
  1308. (set-face-background 'magit-diff-removed nil)
  1309. (set-face-foreground 'magit-diff-removed-highlight "red")
  1310. (set-face-background 'magit-diff-removed-highlight nil)
  1311. (set-face-background 'magit-diff-lines-boundary "blue")
  1312. )
  1313. (declare-function magit-show-commit "magit")
  1314. (defun my-magit-messenger (file line)
  1315. "Magit messenger."
  1316. (interactive (list buffer-file-name
  1317. (line-number-at-pos)))
  1318. (cl-assert file)
  1319. (cl-assert line)
  1320. (let* ((blame-args '("-w"))
  1321. (id (with-temp-buffer
  1322. (let ((exit (apply 'call-process
  1323. "git" ;; PROGRAM
  1324. nil ;; INFILE
  1325. t ;; DESTINATION
  1326. nil ;; DISPLAY
  1327. "--no-pager" ;; ARGS
  1328. "blame"
  1329. "-L"
  1330. (format "%d,+1" line)
  1331. "--porcelain"
  1332. file
  1333. blame-args
  1334. )))
  1335. (goto-char (point-min))
  1336. (cl-assert (eq exit 0)
  1337. "Failed: %s" (buffer-substring (point)
  1338. (point-at-eol)))
  1339. (save-match-data
  1340. (re-search-forward (rx buffer-start
  1341. (one-or-more hex-digit)))
  1342. (match-string 0))))))
  1343. (magit-show-commit id)))
  1344. (when (boundp 'git-rebase-filename-regexp)
  1345. (add-to-list 'auto-mode-alist
  1346. `(,git-rebase-filename-regexp . text-mode)))
  1347. (when (fboundp 'ggtags-mode)
  1348. (add-hook 'c-mode-common-hook
  1349. 'ggtags-mode)
  1350. (add-hook 'python-mode-hook
  1351. 'ggtags-mode)
  1352. (add-hook 'js-mode-hook
  1353. 'ggtags-mode)
  1354. (add-hook 'scheme-mode-hook
  1355. 'ggtags-mode)
  1356. )
  1357. (when (fboundp 'imenu-list-minor-mode)
  1358. (defvar imenu-list-buffer-name)
  1359. (defun my-imenu-list-toggle ()
  1360. "My 'imenu-list` toggle."
  1361. (interactive)
  1362. (require 'imenu-list)
  1363. (if (eq (window-buffer)
  1364. (get-buffer imenu-list-buffer-name))
  1365. (imenu-list-minor-mode -1)
  1366. (imenu-list-minor-mode 1)))
  1367. ;; (set-variable 'imenu-list-auto-resize t)
  1368. (set-variable 'imenu-list-focus-after-activation t)
  1369. ;; (define-key ctl-x-map (kbd "C-l") 'my-imenu-list-toggle)
  1370. (define-key ctl-x-map (kbd "C-l") 'imenu-list-smart-toggle)
  1371. )
  1372. (add-hook 'emacs-lisp-mode-hook
  1373. (lambda ()
  1374. (setq imenu-generic-expression
  1375. `(("Sections" ";;;\+\n;; \\(.*\\)\n" 1)
  1376. ,@imenu-generic-expression))))
  1377. ;; TODO: Try paraedit http://daregada.blogspot.com/2012/03/paredit.html
  1378. (with-eval-after-load 'compile
  1379. (defvar compilation-filter-start)
  1380. (defvar compilation-error-regexp-alist)
  1381. (eval-and-compile (require 'ansi-color))
  1382. (add-hook 'compilation-filter-hook
  1383. (lambda ()
  1384. (let ((inhibit-read-only t))
  1385. (ansi-color-apply-on-region compilation-filter-start
  1386. (point)))))
  1387. (add-to-list 'compilation-error-regexp-alist
  1388. ;; ansible-lint
  1389. '("^\\([^ \n]+\\):\\([0-9]+\\)$" 1 2))
  1390. (add-to-list 'compilation-error-regexp-alist
  1391. ;; pydocstyle
  1392. '("^\\([^ \n]+\\):\\([0-9]+\\) " 1 2))
  1393. )
  1394. (declare-function company-cancel "company")
  1395. (when (fboundp 'global-company-mode)
  1396. (add-hook 'after-first-visit-hook
  1397. 'global-company-mode))
  1398. ;; http://qiita.com/sune2/items/b73037f9e85962f5afb7
  1399. ;; https://qiita.com/yuze/items/a145b1e3edb6d0c24cbf
  1400. (set-variable 'company-idle-delay nil)
  1401. (set-variable 'company-minimum-prefix-length 2)
  1402. (set-variable 'company-selection-wrap-around t)
  1403. (set-variable 'company-global-modes '(not term-char-mode
  1404. term-line-mode))
  1405. (declare-function company-manual-begin "company")
  1406. (with-eval-after-load 'company
  1407. (defvar company-mode-map)
  1408. (define-key company-mode-map (kbd "C-i") 'company-indent-or-complete-common)
  1409. ;; (with-eval-after-load 'python
  1410. ;; (defvar python-indent-trigger-commands)
  1411. ;; ;; TODO: This disables completion in puthon?
  1412. ;; (add-to-list 'python-indent-trigger-commands
  1413. ;; 'company-indent-or-complete-common))
  1414. (define-key ctl-x-map (kbd "C-i") 'company-complete) ; Originally `indent-rigidly'
  1415. (defvar company-active-map)
  1416. (define-key company-active-map (kbd "C-n") 'company-select-next)
  1417. (define-key company-active-map (kbd "C-p") 'company-select-previous)
  1418. (define-key company-active-map (kbd "C-s") 'company-filter-candidates)
  1419. (define-key company-active-map (kbd "C-i") 'company-complete-selection)
  1420. (define-key company-active-map (kbd "C-f") 'company-complete-selection)
  1421. (defvar company-mode)
  1422. (defvar company-candidates)
  1423. (defvar company-candidates-length)
  1424. ;; (popup-tip "Hello, World!")
  1425. (defun my-company-lighter-current-length ()
  1426. "Get current candidate length."
  1427. (interactive)
  1428. (let ((l nil)
  1429. (inhibit-message t))
  1430. (when (and company-mode
  1431. (not (minibufferp))
  1432. ;; Do nothing when already in company completion
  1433. (not company-candidates))
  1434. ;; FIXME: Somehow it cannto catch errors from ggtags
  1435. (ignore-errors
  1436. ;; (company-auto-begin)
  1437. (company-manual-begin)
  1438. (setq l company-candidates-length)
  1439. (company-cancel)))
  1440. (if l
  1441. (format "[%d]" l)
  1442. "")))
  1443. (defvar company-lighter)
  1444. (set-variable 'company-lighter-base "Cmp")
  1445. ;; (add-to-list 'company-lighter
  1446. ;; '(:eval (my-company-lighter-current-length))
  1447. ;; t)
  1448. ;; This breaks japanese text input
  1449. ;; (set-variable 'my-company-length-popup-tip-timer
  1450. ;; (run-with-idle-timer 0.2 t
  1451. ;; 'my-company-length-popup-tip))
  1452. ;; (current-active-maps)
  1453. ;; (lookup-key)
  1454. '(mapcar (lambda (map)
  1455. (lookup-key map (kbd "C-i")))
  1456. (current-active-maps))
  1457. ;; https://qiita.com/syohex/items/8d21d7422f14e9b53b17
  1458. (set-face-attribute 'company-tooltip nil
  1459. :foreground "black" :background "lightgrey")
  1460. (set-face-attribute 'company-tooltip-common nil
  1461. :foreground "black" :background "lightgrey")
  1462. (set-face-attribute 'company-tooltip-common-selection nil
  1463. :foreground "white" :background "steelblue")
  1464. (set-face-attribute 'company-tooltip-selection nil
  1465. :foreground "black" :background "steelblue")
  1466. (set-face-attribute 'company-preview-common nil
  1467. :background nil :foreground "lightgrey" :underline t)
  1468. (set-face-attribute 'company-scrollbar-fg nil
  1469. :background "orange")
  1470. (set-face-attribute 'company-scrollbar-bg nil
  1471. :background "gray40")
  1472. )
  1473. ;; https://github.com/lunaryorn/flycheck
  1474. ;; TODO: Any way to disable auto check?
  1475. ;; Update flycheck-hooks-alist?
  1476. (when (fboundp 'global-flycheck-mode)
  1477. (add-hook 'after-first-visit-hook
  1478. 'global-flycheck-mode))
  1479. ;; (set-variable 'flycheck-display-errors-delay 2.0)
  1480. ;; (fset 'flycheck-display-error-at-point-soon 'ignore)
  1481. ;; (with-eval-after-load 'flycheck
  1482. ;; (when (fboundp 'flycheck-black-check-setup)
  1483. ;; (flycheck-black-check-setup)))
  1484. ;; (when (fboundp 'ilookup-open-word)
  1485. ;; (define-key ctl-x-map "d" 'ilookup-open-word)
  1486. ;; )
  1487. (set-variable 'ac-ignore-case nil)
  1488. (when (fboundp 'term-run-shell-command)
  1489. (define-key ctl-x-map "t" 'term-run-shell-command))
  1490. (add-to-list 'safe-local-variable-values
  1491. '(encoding utf-8))
  1492. (setq enable-local-variables :safe)
  1493. ;; Detect file type from shebang and set major-mode.
  1494. (add-to-list 'interpreter-mode-alist
  1495. '("python3" . python-mode))
  1496. (add-to-list 'interpreter-mode-alist
  1497. '("python2" . python-mode))
  1498. (with-eval-after-load 'python
  1499. (defvar python-mode-map (make-sparse-keymap))
  1500. (define-key python-mode-map (kbd "C-m") 'newline-and-indent))
  1501. ;; I want to use this, but this breaks normal self-insert-command
  1502. ;; (set-variable 'py-indent-list-style
  1503. ;; 'one-level-to-beginning-of-statement)
  1504. (set-variable 'pydoc-command
  1505. "python3 -m pydoc")
  1506. (declare-function with-venv-advice-add "with-venv")
  1507. (with-eval-after-load 'pydoc
  1508. ;; pydoc depends on python-shell-interpreter but it does not load this
  1509. (require 'python)
  1510. (when (require 'with-venv nil t)
  1511. (with-venv-advice-add 'pydoc)
  1512. ;; Used in interactive function of pydoc
  1513. (with-venv-advice-add 'pydoc-all-modules)))
  1514. (defvar my-cousel-pydoc-history nil "History of `my-counsel-pydoc'.")
  1515. (defun my-counsel-pydoc ()
  1516. "Counsel `pydoc'."
  1517. (interactive)
  1518. (eval-and-compile (require 'pydoc nil t))
  1519. (ivy-read "Recently: " (pydoc-all-modules)
  1520. :require-match t
  1521. :history 'my-cousel-pydoc-history
  1522. :action (lambda (x) (pydoc x))
  1523. :caller 'my-counsel-pydoc))
  1524. (set-variable 'flycheck-python-mypy-config '("mypy.ini" ".mypy.ini" "setup.cfg"))
  1525. (set-variable 'flycheck-flake8rc '("setup.cfg" "tox.ini" ".flake8rc"))
  1526. (set-variable 'flycheck-python-pylint-executable "python3")
  1527. (set-variable 'flycheck-python-pycompile-executable "python3")
  1528. (set-variable 'python-indent-guess-indent-offset nil)
  1529. (with-eval-after-load 'blacken
  1530. (when (require 'with-venv nil t)
  1531. (with-venv-advice-add 'blacken-buffer)))
  1532. (with-eval-after-load 'ansible-doc
  1533. (when (require 'with-venv nil t)
  1534. (with-venv-advice-add 'ansible-doc)))
  1535. ;; `isortify-buffer' breaks buffer when it contains japanese text
  1536. (defun my-isortify ()
  1537. (interactive)
  1538. (cl-assert buffer-file-name)
  1539. (cl-assert (not (buffer-modified-p)))
  1540. (call-process "python" ;; PROGRAM
  1541. nil ;; INFILE
  1542. nil ;; DESTINATION
  1543. nil ;; DISPLAY
  1544. "-m" "isort" buffer-file-name)
  1545. (message "isortify done")
  1546. (revert-buffer nil t))
  1547. (when (fboundp 'with-venv-advice-add)
  1548. ;; TODO: Lazy load with-venv
  1549. (with-venv-advice-add 'my-isortify))
  1550. ;; https://github.com/lunaryorn/old-emacs-configuration/blob/master/lisp/flycheck-virtualenv.el
  1551. (defun my-set-venv-flycheck-executable-find ()
  1552. "Set flycheck executabie find."
  1553. (interactive)
  1554. (when (fboundp 'with-venv)
  1555. (set-variable 'flycheck-executable-find
  1556. '(lambda (e)
  1557. (with-venv
  1558. (executable-find e)))
  1559. t)))
  1560. (defun my-update-flycheck-flake8-error-level-alist ()
  1561. "Update `flycheck-flake8-error-level-alist'."
  1562. (defvar flycheck-flake8-error-level-alist)
  1563. ;; (add-to-list 'flycheck-flake8-error-level-alist
  1564. ;; '("^D.*$" . warning))
  1565. (set-variable 'flycheck-flake8-error-level-alist
  1566. nil)
  1567. )
  1568. (add-hook 'python-mode-hook
  1569. 'my-set-venv-flycheck-executable-find)
  1570. (add-hook 'python-mode-hook
  1571. 'my-update-flycheck-flake8-error-level-alist)
  1572. (when (fboundp 'with-venv-info-mode)
  1573. (add-hook 'python-mode-hook
  1574. 'with-venv-info-mode))
  1575. ;; Run multiple chekcers
  1576. ;; https://github.com/flycheck/flycheck/issues/186
  1577. (add-hook 'python-mode-hook
  1578. (lambda ()
  1579. ;; Currently on python-mode eldoc-mode sometimes print
  1580. ;; wired message on "from" keyword:
  1581. ;;var from = require("./from")
  1582. (eldoc-mode -1)))
  1583. ;; http://fukuyama.co/foreign-regexp
  1584. '(and (require 'foreign-regexp nil t)
  1585. (progn
  1586. (setq foreign-regexp/regexp-type 'perl)
  1587. '(setq reb-re-syntax 'foreign-regexp)
  1588. ))
  1589. (with-eval-after-load 'sql
  1590. (require 'sql-indent nil t))
  1591. (add-to-list 'auto-mode-alist
  1592. '("\\.hql\\'" . sql-mode))
  1593. (when (fboundp 'git-command)
  1594. (define-key ctl-x-map "g" 'git-command))
  1595. (when (fboundp 'gited-list)
  1596. (defalias 'gited 'gited-list))
  1597. (when (and (eval-and-compile (require 'git-commit nil t))
  1598. (fboundp 'global-git-commit-mode))
  1599. ;; git-commit is defined badly and breaks the convention that only loading a
  1600. ;; library should not change the Emacs behavior:
  1601. ;; anyway I enable this manually here.
  1602. (global-git-commit-mode 1))
  1603. (with-eval-after-load 'git-commit
  1604. (add-hook 'git-commit-setup-hook
  1605. 'turn-off-auto-fill t))
  1606. (with-eval-after-load 'rst
  1607. (defvar rst-mode-map)
  1608. (define-key rst-mode-map (kbd "C-m") 'newline-and-indent))
  1609. (with-eval-after-load 'jdee
  1610. (add-hook 'jdee-mode-hook
  1611. (lambda ()
  1612. (make-local-variable 'global-mode-string)
  1613. (add-to-list 'global-mode-string
  1614. mode-line-position))))
  1615. ;; Cannot enable error thrown. Why???
  1616. ;; https://github.com/m0smith/malabar-mode#Installation
  1617. ;; (when (require 'malabar-mode nil t)
  1618. ;; (add-to-list 'load-path
  1619. ;; (expand-file-name (concat user-emacs-directory "/cedet")))
  1620. ;; (require 'cedet-devel-load nil t)
  1621. ;; (eval-after-init (activate-malabar-mode)))
  1622. (with-eval-after-load 'make-mode
  1623. (defvar makefile-mode-map (make-sparse-keymap))
  1624. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  1625. ;; this functions is set in write-file-functions, i cannot find any
  1626. ;; good way to remove this.
  1627. (fset 'makefile-warn-suspicious-lines 'ignore))
  1628. (with-eval-after-load 'verilog-mode
  1629. (defvar verilog-mode-map (make-sparse-keymap))
  1630. (define-key verilog-mode-map ";" 'self-insert-command))
  1631. (setq diff-switches "-u")
  1632. (autoload 'diff-goto-source "diff-mode" nil t)
  1633. (with-eval-after-load 'diff-mode
  1634. ;; (when (and (eq major-mode
  1635. ;; 'diff-mode)
  1636. ;; (not buffer-file-name))
  1637. ;; ;; do not pass when major-mode is derived mode of diff-mode
  1638. ;; (view-mode 1))
  1639. (set-face-attribute 'diff-header nil
  1640. :foreground nil
  1641. :background nil
  1642. :weight 'bold)
  1643. (set-face-attribute 'diff-file-header nil
  1644. :foreground nil
  1645. :background nil
  1646. :weight 'bold)
  1647. (set-face-foreground 'diff-index "blue")
  1648. (set-face-attribute 'diff-hunk-header nil
  1649. :foreground "cyan"
  1650. :weight 'normal)
  1651. (set-face-attribute 'diff-context nil
  1652. ;; :foreground "white"
  1653. :foreground nil
  1654. :weight 'normal)
  1655. (set-face-foreground 'diff-removed "red")
  1656. (set-face-foreground 'diff-added "green")
  1657. (set-face-background 'diff-removed nil)
  1658. (set-face-background 'diff-added nil)
  1659. (set-face-attribute 'diff-changed nil
  1660. :foreground "magenta"
  1661. :weight 'normal)
  1662. (set-face-attribute 'diff-refine-changed nil
  1663. :foreground nil
  1664. :background nil
  1665. :weight 'bold
  1666. :inverse-video t)
  1667. ;; Annoying !
  1668. ;;(diff-auto-refine-mode)
  1669. (set-variable 'diff-refine nil)
  1670. )
  1671. ;; (ffap-bindings)
  1672. (with-eval-after-load 'browse-url
  1673. (set-variable 'browse-url-browser-function
  1674. 'eww-browse-url))
  1675. (set-variable 'sh-here-document-word "__EOC__")
  1676. (with-eval-after-load 'adoc-mode
  1677. (defvar adoc-mode-map)
  1678. (define-key adoc-mode-map (kbd "C-m") 'newline))
  1679. (when (fboundp 'adoc-mode)
  1680. (setq auto-mode-alist
  1681. `(("\\.adoc\\'" . adoc-mode)
  1682. ("\\.asciidoc\\'" . adoc-mode)
  1683. ,@auto-mode-alist)))
  1684. (with-eval-after-load 'markup-faces
  1685. ;; Is this too match ?
  1686. (set-face-foreground 'markup-meta-face
  1687. "color-245")
  1688. (set-face-foreground 'markup-meta-hide-face
  1689. "color-245")
  1690. )
  1691. ;; TODO: check if this is required
  1692. (with-eval-after-load 'groovy-mode
  1693. (defvar groovy-mode-map)
  1694. (define-key groovy-mode-map "(" 'self-insert-command)
  1695. (define-key groovy-mode-map ")" 'self-insert-command)
  1696. (define-key groovy-mode-map (kbd "C-m") 'newline-and-indent)
  1697. )
  1698. (when (fboundp 'groovy-mode)
  1699. (add-to-list 'auto-mode-alist
  1700. '("build\\.gradle\\'" . groovy-mode)))
  1701. (add-to-list 'auto-mode-alist
  1702. '("\\.gawk\\'" . awk-mode))
  1703. (with-eval-after-load 'yaml-mode
  1704. (defvar yaml-mode-map (make-sparse-keymap))
  1705. (define-key yaml-mode-map (kbd "C-m") 'newline))
  1706. (with-eval-after-load 'html-mode
  1707. (defvar html-mode-map (make-sparse-keymap))
  1708. (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
  1709. (with-eval-after-load 'text-mode
  1710. (define-key text-mode-map (kbd "C-m") 'newline))
  1711. (with-eval-after-load 'info
  1712. (defvar Info-additional-directory-list)
  1713. (dolist (dir (directory-files (concat user-emacs-directory
  1714. "info")
  1715. t
  1716. "^[^.].*"))
  1717. (when (file-directory-p dir)
  1718. (add-to-list 'Info-additional-directory-list
  1719. dir)))
  1720. (let ((dir (expand-file-name "~/.brew/share/info")))
  1721. (when (file-directory-p dir)
  1722. (add-to-list 'Info-additional-directory-list
  1723. dir))))
  1724. (with-eval-after-load 'apropos
  1725. (defvar apropos-mode-map (make-sparse-keymap))
  1726. (define-key apropos-mode-map "n" 'next-line)
  1727. (define-key apropos-mode-map "p" 'previous-line))
  1728. ;; `isearch' library does not call `provide' so cannot use with-eval-after-load
  1729. ;; (define-key isearch-mode-map
  1730. ;; (kbd "C-j") 'isearch-other-control-char)
  1731. ;; (define-key isearch-mode-map
  1732. ;; (kbd "C-k") 'isearch-other-control-char)
  1733. ;; (define-key isearch-mode-map
  1734. ;; (kbd "C-h") 'isearch-other-control-char)
  1735. (define-key isearch-mode-map (kbd "C-h") 'isearch-del-char)
  1736. (define-key isearch-mode-map (kbd "M-r")
  1737. 'isearch-query-replace-regexp)
  1738. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  1739. (setq lazy-highlight-cleanup nil)
  1740. ;; face for isearch highlighing
  1741. (set-face-attribute 'lazy-highlight
  1742. nil
  1743. :foreground `unspecified
  1744. :background `unspecified
  1745. :underline t
  1746. ;; :weight `bold
  1747. )
  1748. (add-hook 'outline-mode-hook
  1749. (lambda ()
  1750. (when (string-match "\\.md\\'" buffer-file-name)
  1751. (setq-local outline-regexp "#+ "))))
  1752. (add-hook 'outline-mode-hook
  1753. 'outline-show-all)
  1754. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  1755. (with-eval-after-load 'markdown-mode
  1756. (defvar gfm-mode-map)
  1757. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline)
  1758. (define-key gfm-mode-map "`" nil) ;; markdown-electric-backquote
  1759. )
  1760. (when (fboundp 'gfm-mode)
  1761. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  1762. (add-hook 'markdown-mode-hook
  1763. 'outline-minor-mode)
  1764. (add-hook 'markdown-mode-hook
  1765. (lambda ()
  1766. (setq-local comment-start ";")))
  1767. )
  1768. ;; http://keisanbutsuriya.hateblo.jp/entry/2015/02/10/152543
  1769. ;; M-$ to ispell word
  1770. ;; M-x flyspell-buffer to highlight all suspicious words
  1771. (when (executable-find "aspell")
  1772. (set-variable 'ispell-program-name "aspell")
  1773. (set-variable 'ispell-extra-args '("--lang=en_US")))
  1774. (with-eval-after-load 'ispell
  1775. (add-to-list 'ispell-skip-region-alist '("[^\000-\377]+")))
  1776. (when (fboundp 'flyspell-mode)
  1777. (add-hook 'text-mode-hook
  1778. 'flyspell-mode))
  1779. (when (fboundp 'flyspell-prog-mode)
  1780. (add-hook 'prog-mode-hook
  1781. 'flyspell-prog-mode))
  1782. ;; c-mode
  1783. ;; http://www.emacswiki.org/emacs/IndentingC
  1784. ;; http://en.wikipedia.org/wiki/Indent_style
  1785. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  1786. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  1787. (with-eval-after-load 'cc-vars
  1788. (defvar c-default-style nil)
  1789. (add-to-list 'c-default-style
  1790. '(c-mode . "k&r"))
  1791. (add-to-list 'c-default-style
  1792. '(c++-mode . "k&r")))
  1793. (add-to-list 'auto-mode-alist
  1794. '("\\.gs\\'" . js-mode))
  1795. (with-eval-after-load 'js2-mode
  1796. ;; currently do not use js2-mode
  1797. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  1798. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  1799. ;; (defvar js2-mode-map (make-sparse-keymap))
  1800. ;; (define-key js2-mode-map (kbd "C-m") (lambda ()
  1801. ;; (interactive)
  1802. ;; (js2-enter-key)
  1803. ;; (indent-for-tab-command)))
  1804. ;; (add-hook (kill-local-variable 'before-save-hook)
  1805. ;; 'js2-before-save)
  1806. ;; (add-hook 'before-save-hook
  1807. ;; 'my-indent-buffer
  1808. ;; nil
  1809. ;; t)
  1810. )
  1811. (add-to-list 'interpreter-mode-alist
  1812. '("node" . js-mode))
  1813. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  1814. (with-eval-after-load 'uniquify
  1815. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  1816. (setq uniquify-ignore-buffers-re "*[^*]+*")
  1817. (setq uniquify-min-dir-content 1))
  1818. (with-eval-after-load 'view
  1819. (defvar view-mode-map (make-sparse-keymap))
  1820. (define-key view-mode-map "j" 'scroll-up-line)
  1821. (define-key view-mode-map "k" 'scroll-down-line)
  1822. (define-key view-mode-map "v" 'toggle-read-only)
  1823. (define-key view-mode-map "q" 'bury-buffer)
  1824. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  1825. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  1826. ;; (define-key view-mode-map
  1827. ;; "n" 'nonincremental-repeat-search-forward)
  1828. ;; (define-key view-mode-map
  1829. ;; "N" 'nonincremental-repeat-search-backward)
  1830. ;; N conflicts with git-walktree
  1831. ;; (define-key view-mode-map "/" 'isearch-forward-regexp)
  1832. ;; (define-key view-mode-map "?" 'isearch-backward-regexp)
  1833. ;; (define-key view-mode-map "n" 'isearch-repeat-forward)
  1834. ;; (define-key view-mode-map "N" 'isearch-repeat-backward)
  1835. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
  1836. (global-set-key "\M-r" 'view-mode)
  1837. ;; (setq view-read-only t)
  1838. (with-eval-after-load 'term
  1839. (defvar term-raw-map (make-sparse-keymap))
  1840. (define-key term-raw-map (kbd "C-x")
  1841. (lookup-key (current-global-map)
  1842. (kbd "C-x"))))
  1843. (add-hook 'term-mode-hook
  1844. (lambda ()
  1845. ;; Stop current line highlighting
  1846. (set-variable 'hl-line-range-function (lambda () '(0 . 0)) t)
  1847. (set-variable 'scroll-margin 0 t)
  1848. ))
  1849. (set-variable 'term-buffer-maximum-size 20480)
  1850. (set-variable 'term-suppress-hard-newline t)
  1851. (add-hook 'Man-mode-hook
  1852. (lambda ()
  1853. (view-mode 1)
  1854. (setq truncate-lines nil)))
  1855. (set-variable 'Man-notify-method (if window-system
  1856. 'newframe
  1857. 'aggressive))
  1858. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  1859. "woman_cache.el")))
  1860. ;; not work because man.el will be loaded when man called
  1861. (defalias 'man 'woman)
  1862. (add-to-list 'auto-mode-alist
  1863. '("/tox\\.ini\\'" . conf-unix-mode))
  1864. (add-to-list 'auto-mode-alist
  1865. '("/setup\\.cfg\\'" . conf-unix-mode))
  1866. (when (fboundp 'toml-mode)
  1867. (add-to-list 'auto-mode-alist
  1868. '("/tox\\.ini\\'" . toml-mode))
  1869. (add-to-list 'auto-mode-alist
  1870. '("/setup\\.cfg\\'" . toml-mode))
  1871. (add-to-list 'auto-mode-alist
  1872. '("/Pipfile\\'" . toml-mode))
  1873. (add-to-list 'auto-mode-alist
  1874. '("/poetry\\.lock\\'" . toml-mode))
  1875. )
  1876. (when (fboundp 'json-mode)
  1877. (add-to-list 'auto-mode-alist
  1878. '("/Pipfile\\.lock\\'" . json-mode)))
  1879. (add-hook 'go-mode-hook
  1880. (lambda()
  1881. (defvar go-mode-map)
  1882. (add-hook 'before-save-hook' 'gofmt-before-save nil t)
  1883. (define-key go-mode-map (kbd "M-.") 'godef-jump)))
  1884. (when (fboundp 'k8s-mode)
  1885. (add-to-list 'auto-mode-alist
  1886. '("\\.k8s\\'" . k8s-mode)))
  1887. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1888. ;; buffers
  1889. (defvar bs-configurations)
  1890. (declare-function bs-set-configuration "bs")
  1891. (declare-function bs-refresh "bs")
  1892. (declare-function bs-message-without-log "bs")
  1893. (declare-function bs--current-config-message "bs")
  1894. (with-eval-after-load 'bs
  1895. (add-to-list 'bs-configurations
  1896. '("specials" "^\\*" nil ".*" nil nil))
  1897. (add-to-list 'bs-configurations
  1898. '("files-and-specials" "^\\*" buffer-file-name ".*" nil nil))
  1899. (defvar bs-mode-map)
  1900. (defvar bs-current-configuration)
  1901. (define-key bs-mode-map (kbd "t")
  1902. ;; TODO: fix toggle feature
  1903. (lambda ()
  1904. (interactive)
  1905. (if (string= "specials"
  1906. bs-current-configuration)
  1907. (bs-set-configuration "files")
  1908. (bs-set-configuration "specials"))
  1909. (bs-refresh)
  1910. (bs-message-without-log "%s"
  1911. (bs--current-config-message))))
  1912. ;; (setq bs-configurations (list
  1913. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1914. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1915. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1916. )
  1917. (when (fboundp 'bs-show)
  1918. (defalias 'list-buffers 'bs-show)
  1919. (set-variable 'bs-default-configuration "files-and-specials")
  1920. (set-variable 'bs-default-sort-name "by nothing")
  1921. (add-hook 'bs-mode-hook
  1922. (lambda ()
  1923. (setq-local scroll-margin 0)
  1924. (setq-local header-line-format nil)
  1925. (setq-local mode-line-format nil)
  1926. )))
  1927. ;;(iswitchb-mode 1)
  1928. (icomplete-mode)
  1929. (defun iswitchb-buffer-display-other-window ()
  1930. "Do iswitchb in other window."
  1931. (interactive)
  1932. (let ((iswitchb-default-method 'display))
  1933. (call-interactively 'iswitchb-buffer)))
  1934. ;; buffer killing
  1935. ;; (defun my-delete-window-killing-buffer () nil)
  1936. (defun my-query-kill-current-buffer ()
  1937. "Interactively kill current buffer."
  1938. (interactive)
  1939. (if (y-or-n-p (concat "kill current buffer? :"))
  1940. (kill-buffer (current-buffer))))
  1941. (defun my-force-query-kill-current-buffer ()
  1942. "Interactively kill current buffer."
  1943. (interactive)
  1944. (when (y-or-n-p (concat "kill current buffer? :"))
  1945. (let ((kill-buffer-hook nil)
  1946. (kill-buffer-query-functions nil))
  1947. (kill-buffer (current-buffer)))))
  1948. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  1949. ;; Originally C-x C-k -> kmacro-keymap
  1950. ;; (global-set-key "\C-x\C-k" 'kmacro-keymap)
  1951. (global-set-key (kbd "C-x C-k") 'my-query-kill-current-buffer)
  1952. (substitute-key-definition 'kill-buffer
  1953. 'my-query-kill-current-buffer
  1954. global-map)
  1955. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1956. ;; dired
  1957. (defun my-file-head (filename &optional n)
  1958. "Return list of first N lines of file FILENAME."
  1959. ;; TODO: Fix for janapese text
  1960. ;; TODO: Fix for short text
  1961. (let ((num (or n 10))
  1962. (size 100)
  1963. (beg 0)
  1964. (end 0)
  1965. (result '())
  1966. (read -1))
  1967. (with-temp-buffer
  1968. (erase-buffer)
  1969. (while (or (<= (count-lines (point-min)
  1970. (point-max))
  1971. num)
  1972. (eq read 0))
  1973. (setq end (+ beg size))
  1974. (setq read (nth 1 (insert-file-contents-literally filename
  1975. nil
  1976. beg
  1977. end)))
  1978. (goto-char (point-max))
  1979. (setq beg (+ beg size)))
  1980. (goto-char (point-min))
  1981. (while (< (length result) num)
  1982. (let ((start (point)))
  1983. (forward-line 1)
  1984. (setq result
  1985. `(,@result ,(buffer-substring-no-properties start
  1986. (point))))))
  1987. result
  1988. ;; (buffer-substring-no-properties (point-min)
  1989. ;; (progn
  1990. ;; (forward-line num)
  1991. ;; (point)))
  1992. )))
  1993. ;; (apply 'concat (my-file-head "./shrc" 10)
  1994. (declare-function dired-get-filename "dired" t)
  1995. (defun my-dired-echo-file-head (arg)
  1996. "Echo head of current file.
  1997. ARG is num to show, or defaults to 7."
  1998. (interactive "P")
  1999. (let ((f (dired-get-filename)))
  2000. (message "%s"
  2001. (apply 'concat
  2002. (my-file-head f
  2003. 7)))))
  2004. (declare-function dired-get-marked-files "dired")
  2005. (defun my-dired-diff ()
  2006. "Show diff of marked file and file of current line."
  2007. (interactive)
  2008. (let ((files (dired-get-marked-files nil nil nil t)))
  2009. (if (eq (car files)
  2010. t)
  2011. (diff (cadr files) (dired-get-filename))
  2012. (message "One file must be marked!"))))
  2013. (defun dired-get-file-info ()
  2014. "Print information of current line file."
  2015. (interactive)
  2016. (let* ((file (dired-get-filename t))
  2017. (quoted (shell-quote-argument file)))
  2018. (if (file-directory-p file)
  2019. (progn
  2020. (message "Calculating disk usage...")
  2021. (let ((du (or (executable-find "gdu")
  2022. (executable-find "du")
  2023. (error "du not found"))))
  2024. (shell-command (concat du
  2025. " -hsD "
  2026. quoted))))
  2027. (shell-command (concat "file "
  2028. quoted)))))
  2029. (defun my-dired-scroll-up ()
  2030. "Scroll up."
  2031. (interactive)
  2032. (my-dired-previous-line (- (window-height) 1)))
  2033. (defun my-dired-scroll-down ()
  2034. "Scroll down."
  2035. (interactive)
  2036. (my-dired-next-line (- (window-height) 1)))
  2037. ;; (defun my-dired-forward-line (arg)
  2038. ;; ""
  2039. ;; (interactive "p"))
  2040. (declare-function dired-get-subdir "dired")
  2041. (declare-function dired-move-to-filename "dired")
  2042. (defun my-dired-previous-line (arg)
  2043. "Move ARG lines up."
  2044. (interactive "p")
  2045. (if (> arg 0)
  2046. (progn
  2047. (if (eq (line-number-at-pos)
  2048. 1)
  2049. (goto-char (point-max))
  2050. (forward-line -1))
  2051. (my-dired-previous-line (if (or (dired-get-filename nil t)
  2052. (dired-get-subdir))
  2053. (- arg 1)
  2054. arg)))
  2055. (dired-move-to-filename)))
  2056. (defun my-dired-next-line (arg)
  2057. "Move ARG lines down."
  2058. (interactive "p")
  2059. (if (> arg 0)
  2060. (progn
  2061. (if (eq (point)
  2062. (point-max))
  2063. (goto-char (point-min))
  2064. (forward-line 1))
  2065. (my-dired-next-line (if (or (dired-get-filename nil t)
  2066. (dired-get-subdir))
  2067. (- arg 1)
  2068. arg)))
  2069. (dired-move-to-filename)))
  2070. (defun my-tramp-remote-find-file (f)
  2071. "Open F."
  2072. (interactive (list (read-file-name "My Find File Tramp: "
  2073. "/scp:"
  2074. nil ;; "/scp:"
  2075. (confirm-nonexistent-file-or-buffer))))
  2076. (find-file f))
  2077. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  2078. (if (eq window-system 'mac)
  2079. (setq dired-listing-switches "-lhF")
  2080. (setq dired-listing-switches "-lhF --time-style=long-iso")
  2081. )
  2082. (setq dired-listing-switches "-lhF")
  2083. ;; when using dired-find-alternate-file
  2084. ;; reuse current dired buffer for the file to open
  2085. ;; (put 'dired-find-alternate-file 'disabled nil)
  2086. (set-variable 'dired-ls-F-marks-symlinks t)
  2087. (set-variable 'ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  2088. (set-variable 'ls-lisp-dirs-first t)
  2089. (set-variable 'ls-lisp-use-localized-time-format t)
  2090. (set-variable 'ls-lisp-format-time-list
  2091. '("%Y-%m-%d %H:%M"
  2092. "%Y-%m-%d "))
  2093. (set-variable 'dired-dwim-target t)
  2094. (set-variable 'dired-isearch-filenames t)
  2095. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  2096. (set-variable 'dired-hide-details-hide-information-lines nil)
  2097. (set-variable 'dired-deletion-confirmer 'y-or-n-p)
  2098. (set-variable 'dired-recursive-deletes 'always)
  2099. ;; (add-hook 'dired-after-readin-hook
  2100. ;; 'my-replace-nasi-none)
  2101. (with-eval-after-load 'dired
  2102. (require 'ls-lisp nil t)
  2103. (defvar dired-mode-map (make-sparse-keymap))
  2104. ;; dired-do-chgrp sometimes cause system hung
  2105. (define-key dired-mode-map "G" 'ignore)
  2106. (define-key dired-mode-map "e" 'wdired-change-to-wdired-mode)
  2107. (define-key dired-mode-map "i" 'dired-get-file-info)
  2108. ;; (define-key dired-mode-map "f" 'find-file)
  2109. (define-key dired-mode-map "f" 'my-fuzzy-finder-or-find-file)
  2110. (define-key dired-mode-map "!" 'shell-command)
  2111. (define-key dired-mode-map "&" 'async-shell-command)
  2112. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  2113. (define-key dired-mode-map "=" 'my-dired-diff)
  2114. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  2115. (define-key dired-mode-map "b" 'gtkbm)
  2116. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  2117. (define-key dired-mode-map (kbd "TAB") 'other-window)
  2118. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  2119. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  2120. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  2121. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  2122. (substitute-key-definition 'dired-next-line
  2123. 'my-dired-next-line
  2124. dired-mode-map)
  2125. (substitute-key-definition 'dired-previous-line
  2126. 'my-dired-previous-line
  2127. dired-mode-map)
  2128. ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
  2129. ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
  2130. ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
  2131. ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
  2132. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  2133. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  2134. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  2135. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  2136. (add-hook 'dired-mode-hook
  2137. (lambda ()
  2138. (when (fboundp 'dired-hide-details-mode)
  2139. (dired-hide-details-mode t)
  2140. (local-set-key "l" 'dired-hide-details-mode))
  2141. (let ((file "._Icon\015"))
  2142. (when nil
  2143. '(file-readable-p file)
  2144. (delete-file file)))))
  2145. (when (fboundp 'pack-dired-dwim)
  2146. (with-eval-after-load 'dired
  2147. (define-key dired-mode-map "P" 'pack-dired-dwim)))
  2148. (when (fboundp 'dired-list-all-mode)
  2149. (setq dired-listing-switches "-lhF")
  2150. (with-eval-after-load 'dired
  2151. (define-key dired-mode-map "a" 'dired-list-all-mode))))
  2152. (when (fboundp 'dired-filter-mode)
  2153. (add-hook 'dired-mode-hook
  2154. 'dired-filter-mode))
  2155. (set-variable 'dired-filter-stack nil)
  2156. ;; Currently disabled in favor of dired-from-git-ls-files
  2157. ;; (define-key ctl-x-map "f" 'find-dired)
  2158. (defvar my-dired-git-ls-files-history
  2159. "History for `my-dired-git-ls-files'." nil)
  2160. (defun my-dired-git-ls-files (arg)
  2161. "Dired from git ls-files."
  2162. (interactive (list
  2163. (read-shell-command "git ls-files: "
  2164. "git ls-files -z ")))
  2165. (pop-to-buffer-same-window
  2166. (dired-noselect `(,default-directory
  2167. ,@(split-string (shell-command-to-string arg)
  2168. "\0" t))
  2169. ""))
  2170. )
  2171. (define-key ctl-x-map (kbd "G") 'my-dired-git-ls-files)
  2172. (with-eval-after-load 'dired
  2173. (defvar dired-mode-map (make-sparse-keymap))
  2174. (define-key dired-mode-map "G" 'my-dired-git-ls-files))
  2175. (with-eval-after-load 'pack
  2176. (set-variable 'pack-silence
  2177. t)
  2178. (defvar pack-program-alist)
  2179. (add-to-list 'pack-program-alist
  2180. '("\\.txz\\'" :pack "tar -cJf" :unpack "tar -xf"))
  2181. (when (executable-find "aunpack")
  2182. (add-to-list 'pack-program-alist
  2183. ' ("\\.zip\\'"
  2184. :pack ("zip" "-r" archive sources)
  2185. :pack-append ("zip" "-r" archive sources)
  2186. :unpack ("aunpack" archive))))
  2187. )
  2188. ;; dired-k
  2189. (declare-function dired-k-no-revert "dired-k")
  2190. (when (fboundp 'dired-k)
  2191. (set-variable 'dired-k-style 'git)
  2192. ;; What is the best way of doing this?
  2193. (with-eval-after-load 'dired-k
  2194. (fset 'dired-k--highlight-by-file-attribyte 'ignore))
  2195. ;; (set-variable 'dired-k-size-colors
  2196. ;; `((,most-positive-fixnum)))
  2197. ;; (set-variable 'dired-k-date-colors
  2198. ;; `((,most-positive-fixnum)))
  2199. (add-hook 'dired-after-readin-hook #'dired-k-no-revert)
  2200. )
  2201. ;; (when (eval-and-compile (require 'dired-rainbow nil t))
  2202. ;; (dired-rainbow-define gtags "brightblack" "GTAGS"))
  2203. ;; ?
  2204. ;; (set-variable 'dired-omit-files
  2205. ;; (rx (or (regexp "^\\.?#")
  2206. ;; (regexp "^\\.$")
  2207. ;; (regexp "^\\.\\.$")
  2208. ;; (regexp "^GPATH$")
  2209. ;; (regexp "^GRTAGS$")
  2210. ;; (regexp "^GTAGS$")
  2211. ;; )))
  2212. (with-eval-after-load 'diredfl
  2213. (set-face-foreground 'diredfl-file-name nil)
  2214. )
  2215. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2216. ;; misc funcs
  2217. (define-key ctl-x-map "T" 'git-worktree)
  2218. (define-key ctl-x-map "W" 'git-walktree)
  2219. (when (fboundp 'browse-url-default-macosx-browser)
  2220. (defalias 'browse-osx 'browse-url-default-macosx-browser))
  2221. (defalias 'qcalc 'quick-calc)
  2222. (defun memo (&optional dir)
  2223. "Open memo.txt in DIR."
  2224. (interactive)
  2225. (pop-to-buffer (find-file-noselect (concat (if dir
  2226. (file-name-as-directory dir)
  2227. "")
  2228. "memo.txt"))))
  2229. ;; TODO: remember-projectile
  2230. (set (defvar my-privnotes-path nil
  2231. "My privnotes repository path.")
  2232. (expand-file-name "~/my/privnotes"))
  2233. (defun my-privnotes-readme (dir)
  2234. "Open my privnotes DIR."
  2235. (interactive (list
  2236. (read-file-name "Privnotes: "
  2237. (expand-file-name (format-time-string "%Y%m%d_")
  2238. my-privnotes-path))))
  2239. (let ((path (expand-file-name "README.md" dir)))
  2240. (with-current-buffer (find-file path)
  2241. (unless (file-exists-p path)
  2242. (insert (file-name-base dir)
  2243. "\n"
  2244. "=======\n"
  2245. "\n\n")))))
  2246. (define-key ctl-x-map "p" 'my-privnotes-readme)
  2247. (set (defvar my-rgrep-alist nil
  2248. "Alist of rgrep command.
  2249. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  2250. condition to choose COMMAND when evaluated.")
  2251. `(
  2252. ;; ripgrep
  2253. ("rg"
  2254. (executable-find "rg")
  2255. "rg -nH --no-heading --hidden --no-ignore-parent --glob '!.git/' --smart-case -M 1280 ")
  2256. ;; git grep
  2257. ("gitgrep"
  2258. (eq 0
  2259. (shell-command "git rev-parse --git-dir"))
  2260. "git --no-pager grep -nH -e ")
  2261. ;; sift
  2262. ("sift"
  2263. (executable-find "sift")
  2264. ("sift --binary-skip --filename --line-number --git --smart-case "))
  2265. ;; the silver searcher
  2266. ("ag"
  2267. (executable-find "ag")
  2268. "ag --nogroup --nopager --filename ")
  2269. ;; ack
  2270. ("ack"
  2271. (executable-find "ack")
  2272. "ack --nogroup --nopager --with-filename ")
  2273. ;; gnu global
  2274. ("global"
  2275. (and (require 'ggtags nil t)
  2276. (executable-find "global")
  2277. (ggtags-current-project-root))
  2278. "global --result grep ")
  2279. ;; grep
  2280. ("grep"
  2281. t
  2282. ,(concat "find . "
  2283. "-path '*/.git' -prune -o "
  2284. "-path '*/.svn' -prune -o "
  2285. "-type f -print0 | "
  2286. "xargs -0 grep -nH -e "))
  2287. )
  2288. )
  2289. (defvar my-rgrep-default nil
  2290. "Default command name for my-rgrep.")
  2291. (defun my-rgrep-grep-command (&optional name alist)
  2292. "Return recursive grep command for current directory or nil.
  2293. If NAME is given, use that without testing.
  2294. Commands are searched from ALIST."
  2295. (if alist
  2296. (if name
  2297. ;; if name is given search that from alist and return the command
  2298. (nth 2 (assoc name
  2299. alist))
  2300. ;; if name is not given try test in 1th elem
  2301. (let ((car (car alist))
  2302. (cdr (cdr alist)))
  2303. (if (eval (nth 1 car))
  2304. ;; if the condition is true return the command
  2305. (nth 2 car)
  2306. ;; try next one
  2307. (and cdr
  2308. (my-rgrep-grep-command name cdr)))))
  2309. ;; if alist is not given set default value
  2310. (my-rgrep-grep-command name my-rgrep-alist)))
  2311. (declare-function projectile-project-p "projectile")
  2312. (declare-function projectile-with-default-dir "projectile")
  2313. (declare-function projectile-project-root "projectile")
  2314. (defun my-rgrep (command-args)
  2315. "My recursive grep. Run COMMAND-ARGS.
  2316. If prefix argument is given, use current symbol as default search target
  2317. and search from projectile root (if projectile is available)."
  2318. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  2319. nil)))
  2320. (if cmd
  2321. (list (read-shell-command "grep command: "
  2322. (concat cmd
  2323. (if current-prefix-arg
  2324. (thing-at-point 'symbol t)
  2325. ""))
  2326. 'grep-find-history))
  2327. (error "My-Rgrep: Command for rgrep not found")
  2328. )))
  2329. (if (and current-prefix-arg
  2330. (eval-and-compile (require 'projectile nil t))
  2331. (projectile-project-p))
  2332. (projectile-with-default-dir (projectile-project-root)
  2333. (compilation-start command-args
  2334. 'grep-mode))
  2335. (compilation-start command-args
  2336. 'grep-mode)))
  2337. (defun my-rgrep-thing-at-point-projectile-root ()
  2338. "My recursive grep to find thing at point from project root."
  2339. (interactive)
  2340. (let* ((cmd (my-rgrep-grep-command my-rgrep-default
  2341. nil))
  2342. (command-args
  2343. (if cmd
  2344. (concat cmd
  2345. (or (thing-at-point 'symbol t)
  2346. (error "No symbol at point")))
  2347. (error "My-Rgrep: Command for rgrep not found"))))
  2348. (if (eval-and-compile (require 'projectile nil t))
  2349. (projectile-with-default-dir (or (projectile-project-root)
  2350. default-directory)
  2351. (compilation-start command-args
  2352. 'grep-mode))
  2353. (compilation-start command-args
  2354. 'grep-mode))))
  2355. (defmacro define-my-rgrep (name)
  2356. "Define rgrep for NAME."
  2357. `(defun ,(intern (concat "my-rgrep-"
  2358. name)) ()
  2359. ,(format "My recursive grep by %s."
  2360. name)
  2361. (interactive)
  2362. (let ((my-rgrep-default ,name))
  2363. (if (called-interactively-p 'any)
  2364. (call-interactively 'my-rgrep)
  2365. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2366. )
  2367. (define-my-rgrep "ack")
  2368. (define-my-rgrep "ag")
  2369. (define-my-rgrep "rg")
  2370. (define-my-rgrep "sift")
  2371. (define-my-rgrep "gitgrep")
  2372. (define-my-rgrep "grep")
  2373. (define-my-rgrep "global")
  2374. (define-key ctl-x-map "s" 'my-rgrep)
  2375. (define-key ctl-x-map "." 'my-rgrep-thing-at-point-projectile-root)
  2376. (defun my-occur (regexp &optional region)
  2377. "My occur command to search REGEXP to search REGION."
  2378. (interactive (list (read-string "List lines matching regexp: "
  2379. (thing-at-point 'symbol t))))
  2380. (occur regexp nil region))
  2381. (define-key ctl-x-map (kbd "C-o") 'my-occur)
  2382. (set-variable 'dumb-jump-prefer-searcher 'rg)
  2383. (defalias 'make 'compile)
  2384. (define-key ctl-x-map "c" 'compile)
  2385. (autoload 'pb/push-item "pushbullet")
  2386. (defun my-pushbullet-note (text &optional title)
  2387. "Push TEXT with optional TITLE."
  2388. (interactive "sText to Push: ")
  2389. (pb/push-item '("") text "note" (or title "")))
  2390. ;;;;;;;;;;;;;;;;;;;;;
  2391. ;; git-bug
  2392. (defconst git-bug-ls-regexp
  2393. (eval-when-compile
  2394. (rx bol
  2395. (submatch (one-or-more alphanumeric)) ; id
  2396. ;; (one-or-more any)
  2397. (one-or-more space)
  2398. (submatch (or "open" "close")) ; status
  2399. (one-or-more space)
  2400. (submatch (maximal-match (zero-or-more print))) ; title
  2401. "\t"
  2402. (submatch (one-or-more alphanumeric)) ; user
  2403. (one-or-more space)
  2404. "C:"
  2405. (submatch (one-or-more digit)) ; Comment num
  2406. (one-or-more space)
  2407. "L:"
  2408. (submatch (one-or-more digit)) ; Label num
  2409. eol
  2410. ))
  2411. "Regexp to parse line of output of git-bug ls.
  2412. Used by `git-bug-ls'.")
  2413. (declare-function string-trim "subr-x")
  2414. (defun git-bug-bugs ()
  2415. "Get list of git-bug bugs."
  2416. (with-temp-buffer
  2417. (git-bug--call-process "bug" "ls")
  2418. (goto-char (point-min))
  2419. (let ((bugs nil))
  2420. (while (not (eq (point) (point-max)))
  2421. (save-match-data
  2422. (when (re-search-forward git-bug-ls-regexp (point-at-eol) t)
  2423. (setq bugs `(,@bugs
  2424. ,(list
  2425. :id (match-string 1)
  2426. :status (match-string 2)
  2427. :title (string-trim (match-string 3))
  2428. :user (match-string 4)
  2429. :comment-num (match-string 5)
  2430. :label-num (match-string 6)
  2431. )))))
  2432. (forward-line 1)
  2433. (goto-char (point-at-bol)))
  2434. bugs)))
  2435. (defun git-bug-ls ()
  2436. "Open and select git bug list buffer."
  2437. (interactive)
  2438. (pop-to-buffer (git-bug-ls-noselect)))
  2439. (defun git-bug-ls--set-tabulated-list-mode-variables ()
  2440. "Not implemented.")
  2441. (defun git-bug-ls-mode ()
  2442. "Not implemented.")
  2443. (defun git-bug-ls-noselect (&optional directory)
  2444. "Open git bug list buffer.
  2445. If optional arg DIRECTORY is given change current directory to there before
  2446. initializing."
  2447. (setq directory (expand-file-name (or directory
  2448. default-directory)))
  2449. (cl-assert (file-directory-p directory))
  2450. (let* ((root (git-bug--get-repository-root directory))
  2451. (name (file-name-nondirectory root))
  2452. (bname (format "*GitBug<%s>*" name)))
  2453. (with-current-buffer (get-buffer-create bname)
  2454. (cd root)
  2455. (git-bug-ls--set-tabulated-list-mode-variables)
  2456. (git-bug-ls-mode)
  2457. (current-buffer))))
  2458. (defun git-bug--get-repository-root (dir)
  2459. "Resolve repository root of DIR.
  2460. If DIR is not inside of any git repository, signal an error."
  2461. (cl-assert (file-directory-p dir))
  2462. (with-temp-buffer
  2463. (cd dir)
  2464. (git-bug--call-process "rev-parse" "--show-toplevel")
  2465. (goto-char (point-min))
  2466. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  2467. (defun git-bug--call-process (&rest args)
  2468. "Start git process synchronously with ARGS.
  2469. Raise error when git process ends with non-zero status.
  2470. Any output will be written to current buffer."
  2471. (let ((status (apply 'call-process
  2472. "git"
  2473. nil
  2474. t
  2475. nil
  2476. args)))
  2477. (cl-assert (eq status 0)
  2478. nil
  2479. (buffer-substring-no-properties (point-min) (point-max)))))
  2480. ;;;;;;;;;;;;;;;;;;;
  2481. ;; peek-file-mode
  2482. (defvar peek-file-buffers
  2483. ()
  2484. "Peek buffers.")
  2485. (defun peek-file (file)
  2486. "Peek FILE."
  2487. (interactive "fFile to peek: ")
  2488. (with-current-buffer (find-file file)
  2489. (peek-file-mode)))
  2490. (define-minor-mode peek-file-mode
  2491. "Peek file mode."
  2492. :lighter "PK"
  2493. (view-mode peek-file-mode)
  2494. (add-to-list 'peek-file-buffers
  2495. (current-buffer))
  2496. (add-hook 'switch-buffer-functions
  2497. 'peek-file-remove-buffers))
  2498. (defun peek-file-remove-buffers (&args _)
  2499. "Remove peek file buffers."
  2500. (cl-dolist (buf (cl-copy-list peek-file-buffers))
  2501. (unless (get-buffer-window buf t)
  2502. (setq peek-file-buffers
  2503. (delq buf
  2504. peek-file-buffers))
  2505. (with-current-buffer buf
  2506. (when peek-file-mode
  2507. (kill-buffer))))))
  2508. (declare-function dired-get-file-for-visit "dired")
  2509. (with-eval-after-load 'dired
  2510. (defun dired-peek-file (&rest files)
  2511. "Dired `peak-file' FILES."
  2512. (interactive (list (dired-get-file-for-visit)))
  2513. (message "AAA %S" files)
  2514. (dolist (file files)
  2515. (peek-file file)))
  2516. (defvar dired-mode-map (make-sparse-keymap))
  2517. (define-key dired-mode-map "v" 'dired-peek-file))
  2518. ;;;;;;;;;;;;;;;;;;;;
  2519. ;; remember-projectile
  2520. ;; TODO: Add global-minor-mode
  2521. (defvar remember-data-file)
  2522. (defun my-set-remember-data-file-buffer-local ()
  2523. "Set `remember-data-file'."
  2524. (when (require 'projectile nil t)
  2525. (setq-local remember-data-file
  2526. (expand-file-name ".remember.notes"
  2527. (projectile-project-root)))))
  2528. (add-hook 'after-change-major-mode-hook
  2529. 'my-set-remember-data-file-buffer-local)
  2530. (define-key ctl-x-map "R" 'remember)
  2531. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2532. ;; ivy
  2533. (set-variable 'ivy-format-functions-alist
  2534. '((t . (lambda (cands) (ivy--format-function-generic
  2535. (lambda (str)
  2536. (concat "+> "
  2537. (ivy--add-face str 'ivy-current-match)
  2538. ))
  2539. (lambda (str)
  2540. (concat "| " str))
  2541. cands
  2542. "\n")))))
  2543. (set-variable 'ivy-wrap t)
  2544. (set-variable 'ivy-sort-max-size 500)
  2545. (when (fboundp 'ivy-rich-mode)
  2546. (ivy-rich-mode 1))
  2547. (with-eval-after-load 'ivy
  2548. (defvar ivy-minibuffer-map)
  2549. (define-key ivy-minibuffer-map (kbd "C-u")
  2550. (lambda () (interactive) (delete-region (point-at-bol) (point)))))
  2551. (set-variable 'ivy-on-del-error-function 'ignore)
  2552. (when (fboundp 'counsel-M-x)
  2553. (define-key esc-map "x" 'counsel-M-x)
  2554. )
  2555. (declare-function ivy-thing-at-point "ivy")
  2556. (when (and (fboundp 'ivy-read)
  2557. (locate-library "counsel"))
  2558. (defvar counsel-describe-map)
  2559. (defun my-counsel-describe-symbol ()
  2560. "Forwaord to `describe-symbol'."
  2561. (interactive)
  2562. (cl-assert (eval-and-compile (require 'help-mode nil t))) ;; describe-symbol-backends
  2563. (cl-assert (eval-and-compile (require 'counsel nil t)))
  2564. (ivy-read "Describe symbol: " obarray
  2565. ;; From describe-symbol definition
  2566. :predicate (lambda (vv)
  2567. (cl-some (lambda (x) (funcall (nth 1 x) vv))
  2568. describe-symbol-backends))
  2569. :require-match t
  2570. :history 'counsel-describe-symbol-history
  2571. :keymap counsel-describe-map
  2572. :preselect (ivy-thing-at-point)
  2573. :action (lambda (x)
  2574. (describe-symbol (intern x)))
  2575. :caller 'my-counsel-describe-symbol))
  2576. (define-key help-map "o" 'my-counsel-describe-symbol)
  2577. )
  2578. (declare-function ivy-configure "ivy")
  2579. (with-eval-after-load 'counsel ;; Hook to counsel, not ivy
  2580. ;; (ivy-configure 'my-counsel-describe-symbol
  2581. ;; :sort-fn 'my-ivy-length)
  2582. (ivy-configure 'counsel-M-x
  2583. :initial-input ""
  2584. ;; :sort-fn 'my-ivy-length
  2585. )
  2586. )
  2587. (when (fboundp 'counsel-imenu)
  2588. (define-key ctl-x-map "l" 'counsel-imenu))
  2589. (when (fboundp 'swiper)
  2590. (define-key esc-map (kbd "C-s") 'swiper))
  2591. (with-eval-after-load 'ivy
  2592. ;; ivy-prescient requires counsel already loaded
  2593. (require 'counsel nil t)
  2594. (when (fboundp 'ivy-prescient-mode)
  2595. (set-variable 'prescient-filter-method
  2596. '(literal regexp initialism fuzzy prefix))
  2597. (ivy-prescient-mode 1)))
  2598. ;; ?
  2599. (define-key input-decode-map "\e[1;5C" [C-right])
  2600. (define-key input-decode-map "\e[1;5D" [C-left])
  2601. ;;;;;;;;;;;;;;;;;;;;;;;;
  2602. ;; mozc
  2603. (global-set-key (kbd "C-c m e") 'ignore)
  2604. (global-set-key (kbd "C-c m d") 'ignore)
  2605. ;; mozc
  2606. (when (locate-library "mozc")
  2607. ;; https://tottoto.net/mac-emacs-karabiner-elements-japanese-input-method-config/
  2608. (with-eval-after-load 'mozc
  2609. ;; (define-key mozc-mode-map (kbd "C-h") 'backward-delete-char)
  2610. ;; (define-key mozc-mode-map (kbd "C-p") (kbd "<up>"))
  2611. ;; (define-key mozc-mode-map (kbd "C-n") (kbd "SPC"))
  2612. )
  2613. (setq default-input-method "japanese-mozc")
  2614. (custom-set-variables '(mozc-leim-title "あ"))
  2615. (defun turn-on-input-method ()
  2616. (interactive)
  2617. (activate-input-method default-input-method))
  2618. (defun turn-off-input-method ()
  2619. (interactive)
  2620. (deactivate-input-method))
  2621. ;; (setq mozc-candidate-style 'echo-area)
  2622. (global-set-key (kbd "C-c m e") 'turn-on-input-method)
  2623. (global-set-key (kbd "C-c m d") 'turn-off-input-method)
  2624. (global-set-key (kbd "<f7>") 'turn-off-input-method)
  2625. (global-set-key (kbd "<f8>") 'turn-on-input-method)
  2626. (require 'mozc-popup)
  2627. (set-variable 'mozc-candidate-style 'popup)
  2628. ;; これいる?
  2629. (when (require 'mozc-im nil t)
  2630. (setq default-input-method "japanese-mozc-im")
  2631. ;; (global-set-key (kbd "C-j") 'toggle-input-method)
  2632. )
  2633. )
  2634. ;;;;;;;;;;;;;;
  2635. ;; mmv
  2636. ;; https://www.emacswiki.org/emacs/MakingMarkVisible
  2637. ;;;; Make the mark visible, and the visibility toggleable. ('mmv' means 'make
  2638. ;;;; mark visible'.) By Patrick Gundlach, Teemu Leisti, and Stefan.
  2639. (defgroup mmv nil
  2640. "Make mark visible."
  2641. :group 'tools)
  2642. (defvar mmv-face-foreground
  2643. (face-foreground 'hi-yellow)
  2644. "Foreground color for `mmv-face'.")
  2645. (defvar mmv-face-background
  2646. (face-background 'hi-yellow)
  2647. "Background color for `mmv-face'.")
  2648. (defface mmv-face
  2649. `((t :background ,mmv-face-background :foreground ,mmv-face-foreground))
  2650. "Face used for showing the mark's position."
  2651. :group 'mmv)
  2652. (defvar-local mmv-mark-overlay nil
  2653. "The overlay for showing the mark's position.")
  2654. (defvar-local mmv-is-mark-visible t
  2655. "The overlay is visible only when this variable's value is t.")
  2656. (defun mmv-draw-mark (&rest _)
  2657. "Make the mark's position stand out by means of a one-character-long overlay.
  2658. If the value of variable `mmv-is-mark-visible' is nil, the mark will be
  2659. invisible."
  2660. (unless mmv-mark-overlay
  2661. (setq mmv-mark-overlay (make-overlay 0 0 nil t))
  2662. (overlay-put mmv-mark-overlay 'face 'mmv-face)
  2663. (overlay-put mmv-mark-overlay 'priority 10)) ;; bigger than highlight-indentation-current-column-overlay-priority
  2664. (let ((mark-position (mark t)))
  2665. (cond
  2666. ((null mark-position) (delete-overlay mmv-mark-overlay))
  2667. ((and (< mark-position (point-max))
  2668. (not (eq ?\n (char-after mark-position))))
  2669. (overlay-put mmv-mark-overlay 'after-string nil)
  2670. (move-overlay mmv-mark-overlay mark-position (1+ mark-position)))
  2671. (t
  2672. ;; This branch is called when the mark is at the end of a line or at the
  2673. ;; end of the buffer. We use a bit of trickery to avoid the higlight
  2674. ;; extending from the mark all the way to the right end of the frame.
  2675. (overlay-put mmv-mark-overlay 'after-string
  2676. (propertize " " 'face (overlay-get mmv-mark-overlay 'face)))
  2677. (move-overlay mmv-mark-overlay mark-position mark-position)))))
  2678. ;; ;; Makes display very slow?
  2679. ;; (add-hook 'pre-redisplay-functions #'mmv-draw-mark)
  2680. (defun mmv-toggle-mark-visibility ()
  2681. "Toggles the mark's visiblity and redraws it (whether invisible or visible)."
  2682. (interactive)
  2683. (setq mmv-is-mark-visible (not mmv-is-mark-visible))
  2684. (if mmv-is-mark-visible
  2685. (set-face-attribute 'mmv-face nil :background mmv-face-background :foreground mmv-face-foreground)
  2686. (set-face-attribute 'mmv-face nil :background 'unspecified :foreground 'unspecified))
  2687. (mmv-draw-mark))
  2688. (defun browse-url-macosx-vivaldi-browser (url &rest args)
  2689. "Invoke the macOS Vlvaldi Web browser with URL.
  2690. ARGS are not used."
  2691. (interactive (browse-url-interactive-arg "URL: "))
  2692. (start-process (concat "vivaldi " url)
  2693. nil
  2694. "/Applications/Vivaldi.app/Contents/MacOS/Vivaldi"
  2695. url))
  2696. ;; 前の実行結果を残したまま次のコマンドを実行する方法はあるだろうか
  2697. (defun my-vterm-cmd (command)
  2698. "Start arbitrary command in vterm buffer."
  2699. (interactive "sCommand: ")
  2700. (let ((vterm-shell command)
  2701. (vterm-buffer-name "*vterm-cmd*")
  2702. (vterm-kill-buffer-on-exit nil))
  2703. (when (get-buffer vterm-buffer-name)
  2704. (kill-buffer (get-buffer vterm-buffer-name)))
  2705. (vterm)))
  2706. ;; (setq vterm-shell "bash -l")
  2707. ;; (setq vterm-kill-buffer-on-exit nil)
  2708. ;; ;; (setq vterm-term-environment-variable "screen-256color")
  2709. ;; これいつ動くの?
  2710. ;; 自動で project を switch させる方法はある?
  2711. (add-hook 'projectile-after-switch-project-hook
  2712. (lambda ()
  2713. (message "Projecttile switched to: %s"
  2714. (projectile-project-root))))
  2715. (when (fboundp 'projectile-mode)
  2716. (projectile-mode 1))
  2717. (with-eval-after-load 'eglot
  2718. (when (fboundp 'with-venv-advice-add)
  2719. (with-venv-advice-add 'eglot--executable-find))
  2720. (set-variable 'eldoc-echo-area-use-multiline-p nil)
  2721. (set-variable 'eglot-extend-to-xref t))
  2722. (message "Emacs started at %s"
  2723. (current-time-string))
  2724. (run-with-idle-timer (* 3 60 60) ;; 3 hours
  2725. t
  2726. (lambda ()
  2727. (message "Emacs does nothing for 3 hours: %s"
  2728. (current-time-string))))
  2729. ;; https://emacs-jp.github.io/tips/startup-optimization
  2730. ;; Restore to original value
  2731. (setq gc-cons-threshold my-orig-gc-cons-threshold)
  2732. (setq file-name-handler-alist my-orig-file-name-handler-alist)
  2733. (when (getenv "_EMACS_EL_PROFILE")
  2734. (profiler-report)
  2735. (profiler-stop))
  2736. ;; Local Variables:
  2737. ;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
  2738. ;; flycheck-checker: emacs-lisp
  2739. ;; End:
  2740. ;;; emancs.el ends here