25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

emacs.el 82 KiB

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