You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

emacs.el 102 KiB

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