Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

emacs.el 103 KiB

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