Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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