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