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

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