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

emacs.el 102 KiB

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