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 101 KiB

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