Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

emacs.el 102 KiB

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