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

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