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.

пре 11 година
пре 9 година
пре 6 година
пре 13 година
пре 9 година
пре 12 година
пре 12 година
пре 13 година
пре 13 година
пре 6 година
пре 5 година
пре 5 година
пре 9 година
пре 5 година
пре 9 година
пре 5 година
пре 9 година
пре 8 година
пре 5 година
пре 9 година
пре 11 година
пре 9 година
пре 8 година
пре 9 година
пре 9 година
пре 8 година
пре 9 година
пре 6 година
пре 6 година
пре 6 година
пре 5 година
пре 6 година
пре 9 година
пре 8 година
пре 6 година
пре 9 година
пре 9 година
пре 8 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 9 година
пре 9 година
пре 8 година
пре 9 година
пре 9 година
пре 6 година
пре 9 година
пре 11 година
пре 9 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 13 година
пре 5 година
пре 13 година
пре 6 година
пре 6 година
пре 13 година
пре 12 година
пре 12 година
пре 13 година
пре 12 година
пре 6 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 9 година
пре 5 година
пре 5 година
пре 5 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 11 година
пре 5 година
пре 6 година
пре 13 година
пре 5 година
пре 13 година
пре 12 година
пре 13 година
пре 11 година
пре 9 година
пре 9 година
пре 9 година
пре 6 година
пре 9 година
пре 9 година
пре 12 година
пре 8 година
пре 9 година
пре 6 година
пре 9 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 9 година
пре 9 година
пре 6 година
пре 9 година
пре 7 година
пре 8 година
пре 9 година
пре 6 година
пре 9 година
пре 6 година
пре 6 година
пре 6 година
пре 9 година
пре 5 година
пре 9 година
пре 7 година
пре 8 година
пре 9 година
пре 6 година
пре 6 година
пре 6 година
пре 5 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 13 година
пре 13 година
пре 11 година
пре 11 година
пре 9 година
пре 10 година
пре 9 година
пре 9 година
пре 9 година
пре 8 година
пре 9 година
пре 9 година
пре 12 година
пре 11 година
пре 6 година
пре 13 година
пре 6 година
пре 13 година
пре 5 година
пре 13 година
пре 6 година
пре 13 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 13 година
пре 11 година
пре 5 година
пре 13 година
пре 12 година
пре 13 година
пре 8 година
пре 13 година
пре 6 година
пре 13 година
пре 12 година
пре 9 година
пре 13 година
пре 9 година
пре 6 година
пре 9 година
пре 8 година
пре 9 година
пре 9 година
пре 9 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 5 година
пре 5 година
пре 13 година
пре 13 година
пре 13 година
пре 6 година
пре 11 година
пре 6 година
пре 12 година
пре 12 година
пре 11 година
пре 13 година
пре 13 година
пре 9 година
пре 6 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 13 година
пре 8 година
пре 5 година
пре 8 година
пре 12 година
пре 6 година
пре 12 година
пре 6 година
пре 12 година
пре 12 година
пре 6 година
пре 8 година
пре 8 година
пре 8 година
пре 6 година
пре 13 година
пре 8 година
пре 5 година
пре 8 година
пре 5 година
пре 8 година
пре 9 година
пре 8 година
пре 13 година
пре 13 година
пре 8 година
пре 12 година
пре 8 година
пре 12 година
пре 6 година
пре 11 година
пре 6 година
пре 6 година
пре 11 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 7 година
пре 13 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 6 година
пре 5 година
пре 5 година
пре 6 година
пре 5 година
пре 5 година
пре 6 година
пре 9 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 5 година
пре 12 година
пре 13 година
пре 12 година
пре 9 година
пре 13 година
пре 6 година
пре 13 година
пре 6 година
пре 6 година
пре 13 година
пре 6 година
пре 13 година
пре 6 година
пре 13 година
пре 6 година
пре 13 година
пре 5 година
пре 6 година
пре 6 година
пре 13 година
пре 12 година
пре 6 година
пре 6 година
пре 6 година
пре 12 година
пре 6 година
пре 12 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 12 година
пре 6 година
пре 6 година
пре 12 година
пре 6 година
пре 12 година
пре 12 година
пре 12 година
пре 6 година
пре 12 година
пре 8 година
пре 12 година
пре 8 година
пре 6 година
пре 5 година
пре 6 година
пре 6 година
пре 6 година
пре 5 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 5 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 5 година
пре 5 година
пре 6 година
пре 6 година
пре 6 година
пре 8 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 11 година
пре 5 година
пре 11 година
пре 5 година
пре 6 година
пре 9 година
пре 6 година
пре 5 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 5 година
пре 12 година
пре 9 година
пре 5 година
пре 8 година
пре 6 година
пре 8 година
пре 5 година
пре 12 година
пре 13 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 13 година
пре 8 година
пре 8 година
пре 7 година
пре 8 година
пре 9 година
пре 5 година
пре 6 година
пре 11 година
пре 6 година
пре 13 година
пре 6 година
пре 10 година
пре 13 година
пре 13 година
пре 6 година
пре 12 година
пре 13 година
пре 12 година
пре 10 година
пре 9 година
пре 9 година
пре 10 година
пре 9 година
пре 13 година
пре 13 година
пре 9 година
пре 13 година
пре 10 година
пре 13 година
пре 11 година
пре 13 година
пре 8 година
пре 13 година
пре 5 година
пре 13 година
пре 10 година
пре 13 година
пре 7 година
пре 5 година
пре 7 година
пре 13 година
пре 13 година
пре 10 година
пре 8 година
пре 10 година
пре 13 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 5 година
пре 6 година
пре 5 година
пре 13 година
пре 6 година
пре 13 година
пре 9 година
пре 5 година
пре 11 година
пре 8 година
пре 8 година
пре 8 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 13 година
пре 13 година
пре 11 година
пре 13 година
пре 10 година
пре 6 година
пре 13 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 9 година
пре 6 година
пре 9 година
пре 6 година
пре 9 година
пре 6 година
пре 9 година
пре 9 година
пре 6 година
пре 9 година
пре 6 година
пре 9 година
пре 12 година
пре 9 година
пре 6 година
пре 9 година
пре 12 година
пре 9 година
пре 12 година
пре 9 година
пре 6 година
пре 9 година
пре 6 година
пре 9 година
пре 6 година
пре 6 година
пре 9 година
пре 6 година
пре 9 година
пре 6 година
пре 9 година
пре 6 година
пре 6 година
пре 9 година
пре 8 година
пре 6 година
пре 9 година
пре 5 година
пре 5 година
пре 9 година
пре 12 година
пре 12 година
пре 9 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 9 година
пре 7 година
пре 9 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 5 година
пре 6 година
пре 5 година
пре 6 година
пре 5 година
пре 6 година
пре 5 година
пре 6 година
пре 6 година
пре 6 година
пре 12 година
пре 5 година
пре 6 година
пре 9 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 6 година
пре 11 година
пре 6 година
пре 6 година
пре 5 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 11 година
пре 11 година
пре 6 година
пре 6 година
пре 11 година
пре 6 година
пре 6 година
пре 6 година
пре 6 година
пре 11 година
пре 9 година
пре 11 година
пре 6 година
пре 6 година
пре 6 година
пре 5 година
пре 6 година
пре 11 година
пре 6 година
пре 5 година
пре 9 година
пре 11 година
пре 6 година
пре 6 година
пре 11 година
пре 11 година
пре 11 година
пре 6 година
пре 6 година
пре 11 година
пре 9 година
пре 11 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 5 година
пре 6 година
пре 6 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212
  1. ;;; emacs.el --- 10sr emacs initialization
  2. ;;; Code:
  3. ;; SETUP_LOAD: (let ((file "DOTFILES_DIR/emacs.el"))
  4. ;; SETUP_LOAD: (and (file-readable-p file)
  5. ;; SETUP_LOAD: (byte-recompile-file file nil 0 t)))
  6. (setq debug-on-error t)
  7. ;; make directories
  8. (unless (file-directory-p (expand-file-name user-emacs-directory))
  9. (make-directory (expand-file-name user-emacs-directory)))
  10. (require 'cl-lib)
  11. (require 'simple)
  12. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13. ;; Some macros for internals
  14. ;; TODO: Rename to eval-after-init
  15. (defmacro call-after-init (&rest body)
  16. "If `after-init-hook' has been run, run BODY immediately.
  17. Otherwize hook it."
  18. (declare (indent 0) (debug t))
  19. `(if after-init-time
  20. ;; Currently after-init-hook is run just after setting after-init-hook
  21. (progn
  22. ,@body)
  23. (add-hook 'after-init-hook
  24. (lambda ()
  25. ,@body))))
  26. ;; TODO: Remove: Just checking fboundp should be enough for most cases
  27. (defmacro safe-require-or-eval (feature)
  28. "Require FEATURE if available.
  29. At compile time the feature will be loaded immediately."
  30. `(eval-and-compile
  31. (message "safe-require-or-eval: Trying to require %s" ,feature)
  32. (require ,feature nil t)))
  33. ;; TODO: Remove: Defining autoload is no more needed for most cases
  34. (defmacro autoload-eval-lazily (feature &optional functions &rest body)
  35. "Define autoloading FEATURE that defines FUNCTIONS.
  36. FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
  37. the function same as FEATURE is defined as autoloaded function. BODY is passed
  38. to `eval-after-load'.
  39. After this macro is expanded, this returns the path to library if FEATURE
  40. found, otherwise returns nil."
  41. (declare (indent 2) (debug t))
  42. (let* ((libname (symbol-name (eval feature)))
  43. (libpath (locate-library libname)))
  44. `(progn
  45. (when (locate-library ,libname)
  46. ,@(mapcar (lambda (f)
  47. `(unless (fboundp ',f)
  48. (progn
  49. (message "Autoloaded function `%S' defined (%s)"
  50. (quote ,f)
  51. ,libpath)
  52. (autoload (quote ,f)
  53. ,libname
  54. ,(concat "Autoloaded function defined in \""
  55. libpath
  56. "\".")
  57. t))))
  58. (or (eval functions)
  59. `(,(eval feature)))))
  60. (eval-after-load ,feature
  61. (quote (progn
  62. ,@body)))
  63. (locate-library ,libname))))
  64. (when (autoload-eval-lazily 'tetris nil
  65. (message "Tetris loaded!"))
  66. (message "Tetris found!"))
  67. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  68. ;; package
  69. (set (defvar 10sr-package-list)
  70. '(
  71. vimrc-mode
  72. markdown-mode
  73. yaml-mode
  74. gnuplot-mode
  75. php-mode
  76. erlang
  77. js2-mode
  78. js-doc
  79. git-commit
  80. gitignore-mode
  81. adoc-mode
  82. go-mode
  83. ;; It seems malabar has been merged into jdee and this package
  84. ;; already removed
  85. ;; malabar-mode
  86. gosh-mode
  87. scala-mode
  88. ;;ensime
  89. web-mode
  90. color-moccur
  91. ggtags
  92. flycheck
  93. auto-highlight-symbol
  94. hl-todo
  95. ;; Currently not available
  96. ;; pp-c-l
  97. xclip
  98. foreign-regexp
  99. multi-term
  100. term-run
  101. editorconfig
  102. git-ps1-mode
  103. restart-emacs
  104. fill-column-indicator
  105. pkgbuild-mode
  106. minibuffer-line
  107. which-key
  108. ;; I think this works in place of my autosave lib
  109. super-save
  110. pipenv
  111. imenu-list
  112. page-break-lines
  113. aggressive-indent
  114. dired-filter
  115. wgrep
  116. magit
  117. git-gutter
  118. end-mark
  119. sl
  120. ;; TODO: Configure pony-tpl-mode
  121. pony-mode
  122. gited
  123. highlight-indentation
  124. diminish
  125. fzf
  126. fic-mode
  127. term-cursor
  128. editorconfig
  129. editorconfig-custom-majormode
  130. git-command
  131. prompt-text
  132. ;; 10sr repository
  133. ;; 10sr-extras
  134. terminal-title
  135. dired-list-all-mode
  136. pack
  137. set-modeline-color
  138. read-only-only-mode
  139. smart-revert
  140. autosave
  141. ;;window-organizer
  142. ilookup
  143. pasteboard
  144. awk-preview
  145. recently
  146. ))
  147. (when (safe-require-or-eval 'package)
  148. (setq package-archives
  149. `(,@package-archives
  150. ("melpa" . "https://melpa.org/packages/")
  151. ;; Somehow fails to download via https
  152. ("10sr-el" . "http://10sr.github.io/emacs-lisp/elpa/")))
  153. (package-initialize)
  154. (defun my-auto-install-package ()
  155. "Install packages semi-automatically."
  156. (interactive)
  157. (package-refresh-contents)
  158. (mapc (lambda (pkg)
  159. (or (package-installed-p pkg)
  160. (package-install pkg)))
  161. 10sr-package-list))
  162. )
  163. ;; (lazy-load-eval 'sudoku)
  164. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  165. ;; my-idle-hook
  166. (defvar my-idle-hook nil
  167. "Hook run when idle for several secs.")
  168. (defvar my-idle-hook-sec 5
  169. "Second to run `my-idle-hook'.")
  170. (run-with-idle-timer my-idle-hook-sec
  171. t
  172. (lambda ()
  173. (run-hooks 'my-idle-hook)))
  174. ;; (add-hook 'my-idle-hook
  175. ;; (lambda ()
  176. ;; (message "idle hook message")))
  177. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  178. ;; start and quit
  179. (setq inhibit-startup-message t)
  180. (setq initial-buffer-choice 'messages-buffer)
  181. (setq confirm-kill-emacs 'y-or-n-p)
  182. (setq gc-cons-threshold (* 1024 1024 16))
  183. (setq garbage-collection-messages nil)
  184. (when window-system
  185. (add-to-list 'default-frame-alist '(cursor-type . box))
  186. (add-to-list 'default-frame-alist '(background-color . "white"))
  187. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  188. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  189. ;; does not work?
  190. )
  191. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  192. (menu-bar-mode 1)
  193. (define-key ctl-x-map "m" 'menu-bar-open)
  194. (and (fboundp 'tool-bar-mode)
  195. (tool-bar-mode 0))
  196. (and (fboundp 'set-scroll-bar-mode)
  197. (set-scroll-bar-mode nil))
  198. (call-after-init
  199. (message "%s %s" invocation-name emacs-version)
  200. (message "Invocation directory: %s" default-directory)
  201. (message "%s was taken to initialize emacs." (emacs-init-time))
  202. ;; (view-echo-area-messages)
  203. ;; (view-emacs-news)
  204. )
  205. (with-current-buffer "*Messages*"
  206. (emacs-lock-mode 'kill))
  207. (cd ".") ; when using windows use / instead of \ in `default-directory'
  208. ;; locale
  209. (set-language-environment "Japanese")
  210. (set-default-coding-systems 'utf-8-unix)
  211. (prefer-coding-system 'utf-8-unix)
  212. (setq system-time-locale "C")
  213. ;; my prefix map
  214. (defvar my-prefix-map nil
  215. "My prefix map.")
  216. (define-prefix-command 'my-prefix-map)
  217. (global-set-key (kbd "C-^") 'my-prefix-map)
  218. ;; (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  219. ;; (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  220. ;; (comint-show-maximum-output)
  221. ;; kill scratch
  222. (call-after-init
  223. (let ((buf (get-buffer "*scratch*")))
  224. (when buf
  225. (kill-buffer buf))))
  226. ;; modifier keys
  227. ;; (setq mac-option-modifier 'control)
  228. ;; display
  229. (setq visible-bell t)
  230. (setq ring-bell-function 'ignore)
  231. (mouse-avoidance-mode 'banish)
  232. (setq echo-keystrokes 0.1)
  233. (defun reload-init-file ()
  234. "Reload Emacs init file."
  235. (interactive)
  236. (when (and user-init-file
  237. (file-readable-p user-init-file))
  238. (load-file user-init-file)))
  239. (safe-require-or-eval 'session)
  240. ;; server
  241. (set-variable 'server-name (concat "server"
  242. (number-to-string (emacs-pid))))
  243. ;; In Cygwin Environment `server-runnning-p' stops when server-use-tcp is nil
  244. ;; In Darwin environment, init fails with message like 'Service name too long'
  245. ;; when server-use-tcp is nil
  246. (when (or (eq system-type
  247. 'cygwin)
  248. (eq system-type
  249. 'darwin))
  250. (set-variable 'server-use-tcp t))
  251. ;; MSYS2 fix
  252. (when (eq system-type
  253. 'windows-nt)
  254. (setq shell-file-name
  255. (executable-find "bash"))
  256. '(setq function-key-map
  257. `(,@function-key-map ([pause] . [?\C-c])
  258. ))
  259. (define-key key-translation-map
  260. (kbd "<pause>")
  261. (kbd "C-c"))
  262. '(keyboard-translate [pause]
  263. (kbd "C-c")p)
  264. ;; TODO: move to other place later
  265. (when (not window-system)
  266. (setq interprogram-paste-function nil)
  267. (setq interprogram-cut-function nil)))
  268. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  269. ;; global keys
  270. (global-set-key (kbd "<up>") 'scroll-down-line)
  271. (global-set-key (kbd "<down>") 'scroll-up-line)
  272. (global-set-key (kbd "<left>") 'scroll-down)
  273. (global-set-key (kbd "<right>") 'scroll-up)
  274. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  275. (global-set-key (kbd "C-\\") help-map)
  276. (define-key ctl-x-map (kbd "DEL") help-map)
  277. (define-key ctl-x-map (kbd "C-h") help-map)
  278. (define-key help-map "a" 'apropos)
  279. ;; disable annoying keys
  280. (global-set-key [prior] 'ignore)
  281. (global-set-key (kbd "<next>") 'ignore)
  282. (global-set-key [menu] 'ignore)
  283. (global-set-key [down-mouse-1] 'ignore)
  284. (global-set-key [down-mouse-2] 'ignore)
  285. (global-set-key [down-mouse-3] 'ignore)
  286. (global-set-key [mouse-1] 'ignore)
  287. (global-set-key [mouse-2] 'ignore)
  288. (global-set-key [mouse-3] 'ignore)
  289. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  290. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  291. ;; Interactively evaluate Emacs Lisp expressions
  292. (define-key ctl-x-map "i" 'ielm)
  293. (when (safe-require-or-eval 'which-key)
  294. (which-key-mode))
  295. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  296. ;; editor
  297. ;; Used from term-cursor
  298. ;; hbar is too hard to find...
  299. (defun my-cursor-type-change (&rest args)
  300. "ARGS are discarded."
  301. ;; TODO: Support wdired and wgrep
  302. (if buffer-read-only
  303. (setq cursor-type 'hbar)
  304. (setq cursor-type 'box)))
  305. ;; (add-hook 'switch-buffer-functions
  306. ;; 'my-cursor-type-change)
  307. ;; (add-hook 'read-only-mode-hook
  308. ;; 'my-cursor-type-change)
  309. ;; (when (fboundp 'global-term-cursor-mode)
  310. ;; (global-term-cursor-mode 1))
  311. ;; ;; (term-cursor--eval)
  312. (setq kill-whole-line t)
  313. (setq scroll-conservatively 35
  314. scroll-margin 2)
  315. (setq-default major-mode 'text-mode)
  316. (setq next-line-add-newlines nil)
  317. (setq kill-read-only-ok t)
  318. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  319. ;; (setq-default line-spacing 0.2)
  320. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  321. ;; (setq-default tab-width 4)
  322. (setq-default indent-tabs-mode nil)
  323. (setq-default indent-line-function 'indent-to-left-margin)
  324. ;; (setq-default indent-line-function nil)
  325. (setq-default truncate-lines nil)
  326. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  327. (delete-selection-mode 1)
  328. (cua-mode 0)
  329. (setq line-move-visual nil)
  330. (setq create-lockfiles nil)
  331. (add-hook 'before-save-hook
  332. 'time-stamp)
  333. ;; Add Time-stamp: <> to insert timestamp there
  334. (set-variable 'time-stamp-format
  335. "%:y-%02m-%02d %02H:%02M:%02S %Z 10sr")
  336. ;; key bindings
  337. ;; moving around
  338. ;;(keyboard-translate ?\M-j ?\C-j)
  339. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  340. (define-key esc-map "p" 'backward-paragraph)
  341. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  342. (define-key esc-map "n" 'forward-paragraph)
  343. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  344. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  345. (global-set-key (kbd "C-<left>") 'scroll-down)
  346. (global-set-key (kbd "C-<right>") 'scroll-up)
  347. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  348. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  349. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  350. ;; C-h and DEL
  351. (global-set-key (kbd "C-h") (kbd "DEL"))
  352. ;; (normal-erase-is-backspace-mode 1)
  353. ;;(global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  354. (global-set-key (kbd "C-m") 'newline-and-indent)
  355. ;; (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  356. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  357. (define-key esc-map "u" 'undo)
  358. (define-key esc-map "i" (kbd "ESC TAB"))
  359. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  360. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  361. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  362. (require 'page-ext nil t)
  363. (when (safe-require-or-eval 'page-break-lines)
  364. (global-page-break-lines-mode 1))
  365. (when (safe-require-or-eval 'git-gutter)
  366. (declare-function global-git-gutter-mode "git-gutter")
  367. (custom-set-variables
  368. '(git-gutter:lighter " Gttr"))
  369. (custom-set-variables
  370. '(git-gutter:update-interval 2))
  371. (custom-set-variables
  372. '(git-gutter:unchanged-sign " "))
  373. (when (>= (display-color-cells)
  374. 256)
  375. (let ((c "color-233"))
  376. (set-face-background 'git-gutter:modified c)
  377. (set-face-background 'git-gutter:added c)
  378. (set-face-background 'git-gutter:deleted c)
  379. (set-face-background 'git-gutter:unchanged c)))
  380. (global-git-gutter-mode 1)
  381. )
  382. ;; (when (safe-require-or-eval 'fancy-narrow)
  383. ;; (fancy-narrow-mode 1))
  384. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  385. ;; title and mode-line
  386. (when (safe-require-or-eval 'terminal-title)
  387. ;; if TERM is not screen use default value
  388. (if (getenv "TMUX")
  389. ;; if use tmux locally just basename of current dir
  390. (set-variable 'terminal-title-format
  391. '((file-name-nondirectory (directory-file-name
  392. default-directory))))
  393. (if (and (let ((tty-type (frame-parameter nil
  394. 'tty-type)))
  395. (and tty-type
  396. (equal (car (split-string tty-type
  397. "-"))
  398. "screen")))
  399. (not (getenv "SSH_CONNECTION")))
  400. (set-variable 'terminal-title-format
  401. '((file-name-nondirectory (directory-file-name
  402. default-directory))))
  403. ;; seems that TMUX is used locally and ssh to remote host
  404. (set-variable 'terminal-title-format
  405. `("em:"
  406. ,user-login-name
  407. "@"
  408. ,(car (split-string (system-name)
  409. "\\."))
  410. ":"
  411. default-directory))
  412. )
  413. )
  414. (terminal-title-mode))
  415. (setq eol-mnemonic-dos "\\r\\n")
  416. (setq eol-mnemonic-mac "\\r")
  417. (setq eol-mnemonic-unix "")
  418. (which-function-mode 1)
  419. (line-number-mode 0)
  420. (column-number-mode 0)
  421. (size-indication-mode 0)
  422. (setq mode-line-position
  423. '(:eval (format ":%%l:%%c /%d%s"
  424. (count-lines (point-max)
  425. (point-min))
  426. (if (buffer-narrowed-p)
  427. "[N]"
  428. "")
  429. )))
  430. (when (safe-require-or-eval 'diminish)
  431. ;; FIXME: Eval after enabling mode
  432. (call-after-init
  433. (diminish 'recently-mode)
  434. (diminish 'editorconfig-mode)
  435. (diminish 'auto-highlight-symbol-mode)
  436. (diminish 'global-whitespace-mode)
  437. (diminish 'which-key-mode)
  438. (diminish 'page-break-lines-mode)
  439. (diminish 'highlight-indentation-mode)))
  440. (setq mode-line-front-space "")
  441. ;; (setq mode-line-end-spaces "")
  442. ;; Set current frame name to empty string
  443. (setq-default mode-line-format
  444. (let* ((l mode-line-format)
  445. (l (cl-substitute " " " "
  446. l
  447. :test 'equal))
  448. (l (cl-substitute " " " "
  449. l
  450. :test 'equal))
  451. )
  452. l))
  453. (set-frame-parameter nil 'name "")
  454. ;; See color-name-rgb-alist for available color names
  455. ;; http://www.raebear.net/computers/emacs-colors/
  456. ;; https://www.emacswiki.org/emacs/ListColors
  457. ;; (list-colors-display is not a complete list)
  458. (defconst my-mode-line-background-default
  459. (face-background 'mode-line)
  460. "Default color of mode-line at init.")
  461. (defun my-mode-line-color-update (&rest args)
  462. "ARGS are discarded"
  463. (let ((ro "skyblue")
  464. (rw my-mode-line-background-default))
  465. (if (or (not buffer-read-only)
  466. (and (eq major-mode 'wdired-mode)))
  467. (set-face-background 'mode-line
  468. rw)
  469. (set-face-background 'mode-line
  470. ro))))
  471. (add-hook 'switch-buffer-functions
  472. 'my-mode-line-color-update)
  473. (add-hook 'read-only-mode-hook
  474. 'my-mode-line-color-update)
  475. (add-hook 'wdired-mode-hook
  476. 'my-mode-line-color-update)
  477. (advice-add 'wdired-change-to-dired-mode
  478. :after
  479. 'my-mode-line-color-update)
  480. (advice-add 'wgrep-change-to-wgrep-mode
  481. :after
  482. 'my-mode-line-color-update)
  483. (advice-add 'wgrep-to-original-mode
  484. :after
  485. 'my-mode-line-color-update)
  486. (set-face-background 'header-line
  487. my-mode-line-background-default)
  488. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  489. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  490. ;; minibuffer
  491. (setq insert-default-directory t)
  492. (setq completion-ignore-case t
  493. read-file-name-completion-ignore-case t
  494. read-buffer-completion-ignore-case t)
  495. (setq resize-mini-windows t)
  496. (temp-buffer-resize-mode 1)
  497. (savehist-mode 1)
  498. (defvar display-time-format "%Y/%m/%d %a %H:%M")
  499. (set-variable 'help-at-pt-display-when-idle t)
  500. (fset 'yes-or-no-p 'y-or-n-p)
  501. ;; complete symbol when `eval'
  502. (define-key read-expression-map (kbd "TAB") 'completion-at-point)
  503. (define-key minibuffer-local-map (kbd "C-u")
  504. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  505. ;; I dont know these bindings are good
  506. (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
  507. (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
  508. (when (safe-require-or-eval 'minibuffer-line)
  509. (set-face-underline 'minibuffer-line nil)
  510. (set-variable 'minibuffer-line-refresh-interval
  511. 25)
  512. ;; Set idle timer
  513. (defvar my-minibuffer-line--idle-timer nil)
  514. (defvar minibuffer-line-mode)
  515. (add-hook 'minibuffer-line-mode-hook
  516. (lambda ()
  517. (when my-minibuffer-line--idle-timer
  518. (cancel-timer my-minibuffer-line--idle-timer)
  519. (setq my-minibuffer-line--idle-timer nil))
  520. (when minibuffer-line-mode
  521. (setq my-minibuffer-line--idle-timer
  522. (run-with-idle-timer 0.5
  523. t
  524. 'minibuffer-line--update)))))
  525. (set-variable 'minibuffer-line-format
  526. `(,(concat user-login-name
  527. "@"
  528. (car (split-string (system-name)
  529. "\\."))
  530. ":")
  531. (:eval (abbreviate-file-name (or buffer-file-name
  532. default-directory)))
  533. (:eval (and (fboundp 'git-ps1-mode-get-current)
  534. (git-ps1-mode-get-current " [GIT:%s]")))
  535. " "
  536. (:eval (format-time-string display-time-format))))
  537. (minibuffer-line-mode 1)
  538. )
  539. (when (safe-require-or-eval 'prompt-text)
  540. (set-variable 'prompt-text-format
  541. `(,(concat ""
  542. user-login-name
  543. "@"
  544. (car (split-string (system-name)
  545. "\\."))
  546. ":")
  547. (:eval (abbreviate-file-name (or buffer-file-name
  548. default-directory)))
  549. (:eval (and (fboundp 'git-ps1-mode-get-current)
  550. (git-ps1-mode-get-current " [GIT:%s]")))
  551. " "
  552. (:eval (format-time-string display-time-format))
  553. "\n"
  554. (:eval (symbol-name this-command))
  555. ": "))
  556. (prompt-text-mode 1))
  557. (autoload-eval-lazily 'helm nil
  558. (defvar helm-map)
  559. (define-key helm-map (kbd "C-h") (kbd "DEL")))
  560. (setq-default header-line-format
  561. '(:eval (let ((f (or (buffer-file-name)
  562. default-directory)))
  563. (when f
  564. (abbreviate-file-name f)))))
  565. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  566. ;; letters, font-lock mode and fonts
  567. (setq text-quoting-style 'grave)
  568. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  569. ;; (set-window-margins (selected-window) 1 1)
  570. (unless window-system
  571. (setq frame-background-mode 'dark))
  572. (and (or (eq system-type 'Darwin)
  573. (eq system-type 'darwin))
  574. (fboundp 'mac-set-input-method-parameter)
  575. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  576. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  577. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  578. (boundp 'input-method-inactivate-hook))
  579. (add-hook 'input-method-activate-hook
  580. (lambda () (set-cursor-color "red")))
  581. (add-hook 'input-method-inactivate-hook
  582. (lambda () (set-cursor-color "black"))))
  583. (when (safe-require-or-eval 'paren)
  584. (show-paren-mode 1)
  585. (setq show-paren-delay 0.5
  586. show-paren-style 'parenthesis) ; mixed is hard to read
  587. ;; (set-face-background 'show-paren-match
  588. ;; "black")
  589. ;; ;; (face-foreground 'default))
  590. ;; (set-face-foreground 'show-paren-match
  591. ;; "white")
  592. ;; (set-face-inverse-video-p 'show-paren-match
  593. ;; t)
  594. )
  595. (transient-mark-mode 1)
  596. (global-font-lock-mode 1)
  597. (setq font-lock-global-modes
  598. '(not
  599. help-mode
  600. eshell-mode
  601. ;;term-mode
  602. Man-mode
  603. magit-diff-mode
  604. magit-revision-mode))
  605. ;; (standard-display-ascii ?\n "$\n")
  606. ;; (defvar my-eol-face
  607. ;; '(("\n" . (0 font-lock-comment-face t nil)))
  608. ;; )
  609. ;; (defvar my-tab-face
  610. ;; '(("\t" . '(0 highlight t nil))))
  611. (defvar my-jspace-face
  612. '(("\u3000" . '(0 highlight t nil))))
  613. (add-hook 'font-lock-mode-hook
  614. (lambda ()
  615. ;; (font-lock-add-keywords nil my-eol-face)
  616. (font-lock-add-keywords nil my-jspace-face)
  617. ))
  618. (when (safe-require-or-eval 'whitespace)
  619. (add-to-list 'whitespace-display-mappings
  620. ;; We need t since last one takes precedence
  621. `(tab-mark ?\t ,(vconcat "|>\t")) t)
  622. ;; (add-to-list 'whitespace-display-mappings
  623. ;; `(newline-mark ?\n ,(vconcat "$\n")))
  624. (setq whitespace-style '(face
  625. trailing ; trailing blanks
  626. ;; tabs
  627. ;; spaces
  628. ;; lines
  629. lines-tail ; lines over 80
  630. newline ; newlines
  631. ;; empty ; empty lines at beg or end of buffer
  632. ;; big-indent
  633. ;; space-mark
  634. tab-mark
  635. newline-mark ; use display table for newline
  636. ))
  637. ;; (setq whitespace-newline 'font-lock-comment-face)
  638. ;; (setq whitespace-style (delq 'newline-mark whitespace-style))
  639. (defun my-whitesspace-mode-reload ()
  640. "Reload whitespace-mode config."
  641. (interactive)
  642. (when whitespace-mode
  643. (whitespace-mode 0)
  644. (whitespace-mode 1)))
  645. (set-variable 'whitespace-line-column nil)
  646. (global-whitespace-mode t)
  647. (add-hook 'dired-mode-hook
  648. (lambda ()
  649. (set (make-local-variable 'whitespace-style) nil)))
  650. (if (>= (display-color-cells)
  651. 256)
  652. (set-face-foreground 'whitespace-newline "color-109")
  653. ;; (progn
  654. ;; (set-face-bold-p 'whitespace-newline
  655. ;; t))
  656. ))
  657. (and nil
  658. '(safe-require-or-eval 'fill-column-indicator)
  659. (setq fill-column-indicator))
  660. ;; highlight current line
  661. ;; http://wiki.riywo.com/index.php?Meadow
  662. (face-spec-set 'hl-line
  663. '((((min-colors 256)
  664. (background dark))
  665. (:background "SlateBlue4"))
  666. (((min-colors 256)
  667. (background light))
  668. ;; TODO: What is should be?
  669. (:background "color-234"))
  670. (t
  671. (:underline "black"))))
  672. (set-variable 'hl-line-global-modes
  673. '(not
  674. term-mode))
  675. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  676. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  677. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  678. ;;(safe-require-or-eval 'set-modeline-color)
  679. ;; (let ((fg (face-foreground 'default))
  680. ;; (bg (face-background 'default)))
  681. ;; (set-face-background 'mode-line-inactive
  682. ;; (if (face-inverse-video-p 'mode-line) fg bg))
  683. ;; (set-face-foreground 'mode-line-inactive
  684. ;; (if (face-inverse-video-p 'mode-line) bg fg)))
  685. ;; (set-face-underline 'mode-line-inactive
  686. ;; t)
  687. ;; (set-face-underline 'vertical-border
  688. ;; nil)
  689. ;; (when (safe-require-or-eval 'end-mark)
  690. ;; (global-end-mark-mode))
  691. ;; M-x highlight-* to highlight things
  692. (global-hi-lock-mode 1)
  693. (unless (fboundp 'highlight-region-text)
  694. (defun highlight-region-text (beg end)
  695. "Highlight text between BEG and END."
  696. (interactive "r")
  697. (highlight-regexp (regexp-quote (buffer-substring-no-properties beg
  698. end)))
  699. (setq deactivate-mark t)))
  700. (when (safe-require-or-eval 'auto-highlight-symbol)
  701. (set-variable 'ahs-idle-interval 0.6)
  702. (global-auto-highlight-symbol-mode 1))
  703. (when (safe-require-or-eval 'highlight-indentation)
  704. (set-face-background 'highlight-indentation-face "color-236")
  705. (dolist (hook
  706. '(
  707. prog-mode-hook
  708. text-mode-hook
  709. ))
  710. (add-hook hook
  711. 'highlight-indentation-mode)))
  712. ;; (set-face-background 'highlight-indentation-current-column-face "#c3b3b3")
  713. (when (fboundp 'fic-mode)
  714. (add-hook 'prog-mode-hook
  715. 'fic-mode))
  716. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  717. ;; file handling
  718. (auto-insert-mode 1)
  719. ;; fzf
  720. ;; Too slow in term buffer!
  721. ;; (set-variable 'fzf/executable "sk")
  722. ;; (set-variable 'fzf/args "--color bw --print-query")
  723. ;; Modified from hardcoded default to include:
  724. ;; - directories
  725. ;; - hidden files
  726. ;; - root directory (.)
  727. ;; - parent directory (..)
  728. ;; ripgrep cannot list directories...
  729. ;; (setenv "FZF_DEFAULT_COMMAND" "rg --files --hidden --follow --glob '!.git/*' --no-ignore")
  730. (let* ((find (if (executable-find "bfs")
  731. ;; Breadth-first find https://github.com/tavianator/bfs
  732. "bfs"
  733. ;; Use gfind if available?
  734. "find"))
  735. (findcmd (concat "set -eu; set -o pipefail; "
  736. "echo .; "
  737. "echo ..; "
  738. "command " find " -L . "
  739. "-mindepth 1 "
  740. "\\( -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune "
  741. "-o -print "
  742. "2> /dev/null "
  743. "| "
  744. "cut -b3-"))
  745. (fdcmd (concat "set -eu; set -o pipefail; "
  746. "echo .; "
  747. "echo ..; "
  748. "command fd "
  749. "--follow --hidden --no-ignore "
  750. "--color always "
  751. "2>/dev/null")))
  752. (if (executable-find "fd")
  753. (setenv "FZF_DEFAULT_COMMAND" fdcmd)
  754. (setenv "FZF_DEFAULT_COMMAND" findcmd)))
  755. (set-variable 'fzf/window-height 45)
  756. (set-variable 'fzf/args "--print-query --ansi --color='bg+:-1' --inline-info --cycle")
  757. ;; (set-variable 'fzf/args "--print-query --ansi --inline-info --cycle")
  758. ;; (set-variable 'fzf/args "--print-query --ansi --color=bw --inline-info --cycle")
  759. (defun my-fzf-or-find-file ()
  760. "Call fzf if usable or call find-file."
  761. (declare (interactive-only t))
  762. (interactive)
  763. (if (and (executable-find "fzf")
  764. (fboundp 'fzf)
  765. (not (file-remote-p default-directory)))
  766. (fzf)
  767. (call-interactively 'find-file)))
  768. (define-key ctl-x-map "f" 'my-fzf-or-find-file)
  769. (defun my-fzf-all-lines ()
  770. "Fzf all lines."
  771. (interactive)
  772. (let ((process-environment (cl-copy-list process-environment)))
  773. (setenv "FZF_DEFAULT_COMMAND" "rg -nH --no-heading --hidden --follow --glob '!.git/*' --color=always ^")
  774. (fzf)))
  775. (define-key ctl-x-map "S" 'my-fzf-all-lines)
  776. ;; recently
  777. (when (safe-require-or-eval 'recently)
  778. (define-key ctl-x-map (kbd "C-r") 'recently-show)
  779. (set-variable 'recently-max 1000)
  780. (recently-mode 1))
  781. (when (safe-require-or-eval 'editorconfig)
  782. (set-variable 'editorconfig-get-properties-function
  783. 'editorconfig-core-get-properties-hash)
  784. (editorconfig-mode 1)
  785. (set-variable 'editorconfig-mode-lighter "")
  786. (when (fboundp 'ws-butler-mode)
  787. (set-variable 'editorconfig-trim-whitespaces-mode
  788. 'ws-butler-mode))
  789. (with-eval-after-load 'org-src
  790. ;; [*.org\[\*Org Src*\[ c \]*\]]
  791. (add-hook 'org-src-mode-hook
  792. 'editorconfig-mode-apply t)))
  793. (when (fboundp 'editorconfig-custom-majormode)
  794. (add-hook 'editorconfig-after-apply-functions
  795. 'editorconfig-custom-majormode))
  796. ;; Add readonly=true to set read-only-mode
  797. (add-hook 'editorconfig-after-apply-functions
  798. (lambda (props)
  799. (let ((r (gethash 'readonly props)))
  800. (when (and (string= r "true")
  801. (not buffer-read-only))
  802. (read-only-mode 1)))))
  803. (add-hook 'editorconfig-hack-properties-functions
  804. '(lambda (props)
  805. (when (derived-mode-p 'makefile-mode)
  806. (puthash 'indent_style "tab" props))))
  807. (when (fboundp 'editorconfig-auto-apply-enable)
  808. (add-hook 'editorconfig-conf-mode-hook
  809. 'editorconfig-auto-apply-enable))
  810. ;; (when (fboundp 'editorconfig-charset-extras)
  811. ;; (add-hook 'editorconfig-custom-hooks
  812. ;; 'editorconfig-charset-extras))
  813. (setq revert-without-query '(".+"))
  814. ;; save cursor position
  815. (when (safe-require-or-eval 'saveplace)
  816. (setq-default save-place t)
  817. (setq save-place-file (concat user-emacs-directory
  818. "places")))
  819. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  820. (setq make-backup-files t)
  821. (setq vc-make-backup-files t)
  822. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  823. (setq backup-directory-alist
  824. (cons (cons "." (expand-file-name (concat user-emacs-directory
  825. "backup")))
  826. backup-directory-alist))
  827. (setq version-control 't)
  828. (setq delete-old-versions t)
  829. (setq kept-new-versions 20)
  830. (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
  831. "auto-save/")))
  832. ;; (setq delete-auto-save-files t)
  833. (setq auto-save-visited-interval 8)
  834. (auto-save-visited-mode 1)
  835. ;; (add-to-list 'auto-save-file-name-transforms
  836. ;; `(".*" ,(concat user-emacs-directory "auto-save-dir") t))
  837. ;; (setq auto-save-interval 3)
  838. ;; (auto-save-mode 1)
  839. (add-to-list 'completion-ignored-extensions ".bak")
  840. (set-variable 'completion-cycle-threshold nil) ;; NEVER use
  841. (setq delete-by-moving-to-trash t)
  842. ;; trash-directory "~/.emacs.d/trash")
  843. (add-hook 'after-save-hook
  844. 'executable-make-buffer-file-executable-if-script-p)
  845. (set-variable 'bookmark-default-file
  846. (expand-file-name (concat user-emacs-directory
  847. "bmk")))
  848. (set-variable 'bookmark-save-flag
  849. 1)
  850. (with-eval-after-load 'recentf
  851. (defvar recentf-exclude)
  852. (defvar bookmark-default-file)
  853. (add-to-list 'recentf-exclude
  854. (regexp-quote bookmark-default-file)))
  855. (when (safe-require-or-eval 'smart-revert)
  856. (smart-revert-on))
  857. ;; autosave
  858. ;; auto-save-visited-mode can be used instead?
  859. ;; (when (safe-require-or-eval 'autosave)
  860. ;; (autosave-set 8))
  861. ;; bookmarks
  862. ;; (define-key ctl-x-map "m" 'list-bookmarks)
  863. ;; vc
  864. (set-variable 'vc-handled-backends '(RCS))
  865. (set-variable 'vc-rcs-register-switches "-l")
  866. (set-variable 'vc-rcs-checkin-switches "-l")
  867. (set-variable 'vc-command-messages t)
  868. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  869. ;; share clipboard with x
  870. ;; this page describes this in details, but only these sexps seem to be needed
  871. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  872. (and nil
  873. (not window-system)
  874. (not (eq window-system 'mac))
  875. (getenv "DISPLAY")
  876. (not (equal (getenv "DISPLAY") ""))
  877. (executable-find "xclip")
  878. ;; (< emacs-major-version 24)
  879. '(safe-require-or-eval 'xclip)
  880. nil
  881. (turn-on-xclip))
  882. (and (eq system-type 'darwin)
  883. (safe-require-or-eval 'pasteboard)
  884. (turn-on-pasteboard))
  885. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  886. ;; some modes and hooks
  887. ;; Include some extra modes
  888. (require 'generic-x)
  889. (when (fboundp 'web-mode)
  890. (add-to-list 'auto-mode-alist
  891. '("\\.html\\.j2\\'" . web-mode))
  892. )
  893. (when (autoload-eval-lazily 'wgrep)
  894. (set-variable 'wgrep-auto-save-buffer t)
  895. (with-eval-after-load 'grep
  896. (defvar grep-mode-map)
  897. (define-key grep-mode-map
  898. "e"
  899. 'wgrep-change-to-wgrep-mode)))
  900. (when (fboundp 'grep-context-mode)
  901. (add-hook 'compilation-mode-hook #'grep-context-mode))
  902. (with-eval-after-load 'remember
  903. (defvar remember-mode-map (make-sparse-keymap))
  904. (define-key remember-mode-map (kbd "C-x C-s") 'ignore))
  905. (with-eval-after-load 'magit-files
  906. ;; `global-magit-file-mode' is enabled by default and this mode overwrites
  907. ;; existing keybindings.
  908. ;; Apparently it is a HARMFUL behavior and it is really awful that I have
  909. ;; to disable thie mode here, but do anyway.
  910. ;; See also https://github.com/magit/magit/issues/3517
  911. (global-magit-file-mode -1))
  912. (with-eval-after-load 'magit-section
  913. (set-face-background 'magit-section-highlight
  914. nil))
  915. (with-eval-after-load 'magit-diff
  916. (set-face-background 'magit-diff-added-highlight
  917. nil)
  918. (set-face-background 'magit-diff-removed-highlight
  919. nil)
  920. (set-face-background 'magit-diff-context-highlight
  921. nil)
  922. )
  923. (when (boundp 'git-rebase-filename-regexp)
  924. (add-to-list 'auto-mode-alist
  925. `(,git-rebase-filename-regexp . text-mode)))
  926. (when (safe-require-or-eval 'aggressive-indent)
  927. (defvar aggressive-indent-excluded-modes)
  928. (setq aggressive-indent-excluded-modes
  929. `(diff-mode
  930. toml-mode
  931. conf-mode
  932. dockerfile-mode
  933. groovy-mode
  934. scala-mode
  935. ,@aggressive-indent-excluded-modes))
  936. (global-aggressive-indent-mode 1))
  937. (when (autoload-eval-lazily 'ggtags)
  938. (add-hook 'c-mode-common-hook
  939. (lambda ()
  940. (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
  941. (ggtags-mode 1))))
  942. (add-hook 'python-mode-hook
  943. (lambda ()
  944. (ggtags-mode 1))))
  945. (when (autoload-eval-lazily 'imenu-list)
  946. ;; (set-variable 'imenu-list-auto-resize t)
  947. (set-variable 'imenu-list-focus-after-activation t)
  948. (define-key ctl-x-map "l" 'imenu-list-smart-toggle))
  949. (add-hook 'emacs-lisp-mode-hook
  950. (lambda ()
  951. (setq imenu-generic-expression
  952. `(("Sections" ";;;\+\n;; \\(.*\\)\n" 1)
  953. ,@imenu-generic-expression))))
  954. ;; TODO: Try paraedit http://daregada.blogspot.com/2012/03/paredit.html
  955. (with-eval-after-load 'compile
  956. (defvar compilation-filter-start)
  957. (defvar compilation-error-regexp-alist)
  958. (require 'ansi-color)
  959. (add-hook 'compilation-filter-hook
  960. (lambda ()
  961. (let ((inhibit-read-only t))
  962. (ansi-color-apply-on-region compilation-filter-start
  963. (point)))))
  964. (add-to-list 'compilation-error-regexp-alist
  965. ;; ansible-lint
  966. '("^\\([^ \n]+\\):\\([0-9]+\\)$" 1 2)))
  967. ;; Workaround to avoid ensime error
  968. (defvar ensime-mode-key-prefix nil)
  969. (when (safe-require-or-eval 'company)
  970. ;; http://qiita.com/sune2/items/b73037f9e85962f5afb7
  971. ;; https://qiita.com/yuze/items/a145b1e3edb6d0c24cbf
  972. (global-company-mode)
  973. (set-variable 'company-idle-delay nil)
  974. (set-variable 'company-minimum-prefix-length 2)
  975. (set-variable 'company-selection-wrap-around t)
  976. (defvar company-mode-map)
  977. (define-key company-mode-map (kbd "C-i") 'company-indent-or-complete-common)
  978. (with-eval-after-load 'python
  979. (defvar python-indent-trigger-commands)
  980. ;; TODO: This disables completion in puthon?
  981. (add-to-list 'python-indent-trigger-commands
  982. 'company-indent-or-complete-common))
  983. (define-key ctl-x-map (kbd "C-i") 'company-complete) ; Originally `indent-rigidly'
  984. (defvar company-active-map)
  985. (define-key company-active-map (kbd "C-n") 'company-select-next)
  986. (define-key company-active-map (kbd "C-p") 'company-select-previous)
  987. (define-key company-active-map (kbd "C-s") 'company-filter-candidates)
  988. (define-key company-active-map (kbd "C-i") 'company-complete-selection)
  989. (define-key company-active-map (kbd "C-f") 'company-complete-selection)
  990. (defvar company-mode)
  991. (defvar company-candidates)
  992. (defvar company-candidates-length)
  993. ;; (popup-tip "Hello, World!")
  994. (defun my-company-lighter-current-length ()
  995. "Get current candidate length."
  996. (interactive)
  997. (let ((l nil)
  998. (inhibit-message t))
  999. (when (and company-mode
  1000. (not (minibufferp))
  1001. ;; Do nothing when already in company completion
  1002. (not company-candidates))
  1003. (ignore-errors
  1004. ;; (company-auto-begin)
  1005. (company-manual-begin)
  1006. (setq l company-candidates-length)
  1007. (company-cancel)))
  1008. (if l
  1009. (format "[%d]" l)
  1010. "")))
  1011. (defvar company-lighter)
  1012. (set-variable 'company-lighter-base "Cmp")
  1013. (add-to-list 'company-lighter
  1014. '(:eval (my-company-lighter-current-length))
  1015. t)
  1016. ;; This breaks japanese text input
  1017. ;; (set-variable 'my-company-length-popup-tip-timer
  1018. ;; (run-with-idle-timer 0.2 t
  1019. ;; 'my-company-length-popup-tip))
  1020. ;; (current-active-maps)
  1021. ;; (lookup-key)
  1022. '(mapcar (lambda (map)
  1023. (lookup-key map (kbd "C-i")))
  1024. (current-active-maps))
  1025. ;; https://qiita.com/syohex/items/8d21d7422f14e9b53b17
  1026. (set-face-attribute 'company-tooltip nil
  1027. :foreground "black" :background "lightgrey")
  1028. (set-face-attribute 'company-tooltip-common nil
  1029. :foreground "black" :background "lightgrey")
  1030. (set-face-attribute 'company-tooltip-common-selection nil
  1031. :foreground "white" :background "steelblue")
  1032. (set-face-attribute 'company-tooltip-selection nil
  1033. :foreground "black" :background "steelblue")
  1034. (set-face-attribute 'company-preview-common nil
  1035. :background nil :foreground "lightgrey" :underline t)
  1036. (set-face-attribute 'company-scrollbar-fg nil
  1037. :background "orange")
  1038. (set-face-attribute 'company-scrollbar-bg nil
  1039. :background "gray40")
  1040. )
  1041. ;; https://github.com/lunaryorn/flycheck
  1042. (when (safe-require-or-eval 'flycheck)
  1043. (call-after-init (global-flycheck-mode)))
  1044. (with-eval-after-load 'flycheck
  1045. (when (fboundp 'flycheck-black-check-setup)
  1046. (flycheck-black-check-setup)))
  1047. (set-variable 'flycheck-python-mypy-ini
  1048. ".mypy.ini")
  1049. (when (autoload-eval-lazily 'ilookup)
  1050. (define-key ctl-x-map "d" 'ilookup-open-word))
  1051. (set-variable 'ac-ignore-case nil)
  1052. (when (autoload-eval-lazily 'term-run '(term-run-shell-command term-run))
  1053. (define-key ctl-x-map "t" 'term-run-shell-command))
  1054. (add-to-list 'safe-local-variable-values
  1055. '(encoding utf-8))
  1056. (setq enable-local-variables :safe)
  1057. ;; Detect file type from shebang and set major-mode.
  1058. (add-to-list 'interpreter-mode-alist
  1059. '("python3" . python-mode))
  1060. (add-to-list 'interpreter-mode-alist
  1061. '("python2" . python-mode))
  1062. (with-eval-after-load 'python
  1063. (defvar python-mode-map (make-sparse-keymap))
  1064. (define-key python-mode-map (kbd "C-m") 'newline-and-indent))
  1065. (when (autoload-eval-lazily 'pipenv)
  1066. ;; (declare-function pipenv-projectile-after-switch-default "pipenv")
  1067. ;; (add-hook 'python-mode-hook
  1068. ;; (lambda ()
  1069. ;; (pipenv-mode 1)
  1070. ;; (pipenv-projectile-after-switch-default)))
  1071. )
  1072. (set-variable 'flycheck-python-pycompile-executable "python3")
  1073. (set-variable 'python-indent-guess-indent-offset nil)
  1074. (with-eval-after-load 'blacken
  1075. (when (require 'with-venv nil t)
  1076. (with-venv-advice-add 'blacken-buffer)))
  1077. ;; http://fukuyama.co/foreign-regexp
  1078. '(and (safe-require-or-eval 'foreign-regexp)
  1079. (progn
  1080. (setq foreign-regexp/regexp-type 'perl)
  1081. '(setq reb-re-syntax 'foreign-regexp)
  1082. ))
  1083. (autoload-eval-lazily 'sql '(sql-mode)
  1084. (require 'sql-indent nil t))
  1085. (add-to-list 'auto-mode-alist
  1086. '("\\.hql\\'" . sql-mode))
  1087. (when (autoload-eval-lazily 'git-command)
  1088. (define-key ctl-x-map "g" 'git-command))
  1089. (when (autoload-eval-lazily 'gited)
  1090. (define-key ctl-x-map (kbd "C-g") 'gited-list))
  1091. (when (safe-require-or-eval 'git-commit)
  1092. (global-git-commit-mode 1))
  1093. (with-eval-after-load 'git-commit
  1094. (add-hook 'git-commit-setup-hook
  1095. 'turn-off-auto-fill t))
  1096. (autoload-eval-lazily 'sl)
  1097. (with-eval-after-load 'rst
  1098. (defvar rst-mode-map)
  1099. (define-key rst-mode-map (kbd "C-m") 'newline-and-indent))
  1100. (with-eval-after-load 'jdee
  1101. (add-hook 'jdee-mode-hook
  1102. (lambda ()
  1103. (make-local-variable 'global-mode-string)
  1104. (add-to-list 'global-mode-string
  1105. mode-line-position))))
  1106. ;; Cannot enable error thrown. Why???
  1107. ;; https://github.com/m0smith/malabar-mode#Installation
  1108. ;; (when (autoload-eval-lazily 'malabar-mode)
  1109. ;; (add-to-list 'load-path
  1110. ;; (expand-file-name (concat user-emacs-directory "/cedet")))
  1111. ;; (safe-require-or-eval 'cedet-devel-load)
  1112. ;; (call-after-init (activate-malabar-mode)))
  1113. (with-eval-after-load 'make-mode
  1114. (defvar makefile-mode-map (make-sparse-keymap))
  1115. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  1116. ;; this functions is set in write-file-functions, i cannot find any
  1117. ;; good way to remove this.
  1118. (fset 'makefile-warn-suspicious-lines 'ignore))
  1119. (with-eval-after-load 'verilog-mode
  1120. (defvar verilog-mode-map (make-sparse-keymap))
  1121. (define-key verilog-mode-map ";" 'self-insert-command))
  1122. (setq diff-switches "-u")
  1123. (with-eval-after-load 'diff-mode
  1124. ;; (when (and (eq major-mode
  1125. ;; 'diff-mode)
  1126. ;; (not buffer-file-name))
  1127. ;; ;; do not pass when major-mode is derived mode of diff-mode
  1128. ;; (view-mode 1))
  1129. (set-face-attribute 'diff-header nil
  1130. :foreground nil
  1131. :background nil
  1132. :weight 'bold)
  1133. (set-face-attribute 'diff-file-header nil
  1134. :foreground nil
  1135. :background nil
  1136. :weight 'bold)
  1137. (set-face-foreground 'diff-index "blue")
  1138. (set-face-attribute 'diff-hunk-header nil
  1139. :foreground "cyan"
  1140. :weight 'normal)
  1141. (set-face-attribute 'diff-context nil
  1142. ;; :foreground "white"
  1143. :foreground nil
  1144. :weight 'normal)
  1145. (set-face-foreground 'diff-removed "red")
  1146. (set-face-foreground 'diff-added "green")
  1147. (set-face-background 'diff-removed nil)
  1148. (set-face-background 'diff-added nil)
  1149. (set-face-attribute 'diff-changed nil
  1150. :foreground "magenta"
  1151. :weight 'normal)
  1152. (set-face-attribute 'diff-refine-changed nil
  1153. :foreground nil
  1154. :background nil
  1155. :weight 'bold
  1156. :inverse-video t)
  1157. ;; Annoying !
  1158. ;;(diff-auto-refine-mode)
  1159. )
  1160. ;; (ffap-bindings)
  1161. (set-variable 'browse-url-browser-function
  1162. 'eww-browse-url)
  1163. (set-variable 'sh-here-document-word "__EOC__")
  1164. (when (autoload-eval-lazily 'adoc-mode
  1165. nil
  1166. (defvar adoc-mode-map (make-sparse-keymap))
  1167. (define-key adoc-mode-map (kbd "C-m") 'newline))
  1168. (setq auto-mode-alist
  1169. `(("\\.adoc\\'" . adoc-mode)
  1170. ("\\.asciidoc\\'" . adoc-mode)
  1171. ,@auto-mode-alist)))
  1172. (with-eval-after-load 'markup-faces
  1173. ;; Is this too match ?
  1174. (set-face-foreground 'markup-meta-face
  1175. "color-245")
  1176. (set-face-foreground 'markup-meta-hide-face
  1177. "color-245")
  1178. )
  1179. ;; TODO: check if this is required
  1180. (when (autoload-eval-lazily 'groovy-mode nil
  1181. (defvar groovy-mode-map (make-sparse-keymap))
  1182. (define-key groovy-mode-map "(" 'self-insert-command)
  1183. (define-key groovy-mode-map ")" 'self-insert-command)
  1184. (define-key groovy-mode-map (kbd "C-m") 'newline-and-indent)
  1185. )
  1186. (add-to-list 'auto-mode-alist
  1187. '("build\\.gradle\\'" . groovy-mode)))
  1188. (add-to-list 'auto-mode-alist
  1189. '("\\.gawk\\'" . awk-mode))
  1190. (with-eval-after-load 'yaml-mode
  1191. (defvar yaml-mode-map (make-sparse-keymap))
  1192. (define-key yaml-mode-map (kbd "C-m") 'newline))
  1193. (with-eval-after-load 'html-mode
  1194. (defvar html-mode-map (make-sparse-keymap))
  1195. (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
  1196. (with-eval-after-load 'text-mode
  1197. (define-key text-mode-map (kbd "C-m") 'newline))
  1198. (autoload-eval-lazily 'info nil
  1199. (defvar Info-additional-directory-list)
  1200. (dolist (dir (directory-files (concat user-emacs-directory
  1201. "info")
  1202. t
  1203. "^[^.].*"))
  1204. (when (file-directory-p dir)
  1205. (add-to-list 'Info-additional-directory-list
  1206. dir)))
  1207. (let ((dir (expand-file-name "~/.brew/share/info")))
  1208. (when (file-directory-p dir)
  1209. (add-to-list 'Info-additional-directory-list
  1210. dir))))
  1211. (with-eval-after-load 'apropos
  1212. (defvar apropos-mode-map (make-sparse-keymap))
  1213. (define-key apropos-mode-map "n" 'next-line)
  1214. (define-key apropos-mode-map "p" 'previous-line))
  1215. ;; `isearch' library does not call `provide' so cannot use with-eval-after-load
  1216. ;; (define-key isearch-mode-map
  1217. ;; (kbd "C-j") 'isearch-other-control-char)
  1218. ;; (define-key isearch-mode-map
  1219. ;; (kbd "C-k") 'isearch-other-control-char)
  1220. ;; (define-key isearch-mode-map
  1221. ;; (kbd "C-h") 'isearch-other-control-char)
  1222. (define-key isearch-mode-map (kbd "C-h") 'isearch-del-char)
  1223. (define-key isearch-mode-map (kbd "M-r")
  1224. 'isearch-query-replace-regexp)
  1225. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  1226. (setq lazy-highlight-cleanup nil)
  1227. ;; face for isearch highlighing
  1228. (set-face-attribute 'lazy-highlight
  1229. nil
  1230. :foreground `unspecified
  1231. :background `unspecified
  1232. :underline t
  1233. ;; :weight `bold
  1234. )
  1235. (add-hook 'outline-mode-hook
  1236. (lambda ()
  1237. (when (string-match "\\.md\\'" buffer-file-name)
  1238. (set (make-local-variable 'outline-regexp) "#+ "))))
  1239. (add-hook 'outline-mode-hook
  1240. 'outline-show-all)
  1241. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  1242. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  1243. (when (autoload-eval-lazily 'markdown-mode
  1244. '(markdown-mode gfm-mode)
  1245. (defvar gfm-mode-map (make-sparse-keymap))
  1246. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline))
  1247. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  1248. (set-variable 'markdown-command (or (executable-find "markdown")
  1249. (executable-find "markdown.pl")
  1250. ""))
  1251. (add-hook 'markdown-mode-hook
  1252. (lambda ()
  1253. (outline-minor-mode 1)
  1254. (flyspell-mode)
  1255. (set (make-local-variable 'comment-start) ";")))
  1256. )
  1257. ;; c-mode
  1258. ;; http://www.emacswiki.org/emacs/IndentingC
  1259. ;; http://en.wikipedia.org/wiki/Indent_style
  1260. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  1261. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  1262. (with-eval-after-load 'cc-vars
  1263. (defvar c-default-style nil)
  1264. (add-to-list 'c-default-style
  1265. '(c-mode . "k&r"))
  1266. (add-to-list 'c-default-style
  1267. '(c++-mode . "k&r")))
  1268. (autoload-eval-lazily 'js2-mode nil
  1269. ;; currently do not use js2-mode
  1270. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  1271. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  1272. ;; (defvar js2-mode-map (make-sparse-keymap))
  1273. ;; (define-key js2-mode-map (kbd "C-m") (lambda ()
  1274. ;; (interactive)
  1275. ;; (js2-enter-key)
  1276. ;; (indent-for-tab-command)))
  1277. ;; (add-hook (kill-local-variable 'before-save-hook)
  1278. ;; 'js2-before-save)
  1279. ;; (add-hook 'before-save-hook
  1280. ;; 'my-indent-buffer
  1281. ;; nil
  1282. ;; t)
  1283. )
  1284. (add-to-list 'interpreter-mode-alist
  1285. '("node" . js-mode))
  1286. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  1287. (with-eval-after-load 'uniquify
  1288. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  1289. (setq uniquify-ignore-buffers-re "*[^*]+*")
  1290. (setq uniquify-min-dir-content 1))
  1291. (with-eval-after-load 'view
  1292. (defvar view-mode-map (make-sparse-keymap))
  1293. (define-key view-mode-map "j" 'scroll-up-line)
  1294. (define-key view-mode-map "k" 'scroll-down-line)
  1295. (define-key view-mode-map "v" 'toggle-read-only)
  1296. (define-key view-mode-map "q" 'bury-buffer)
  1297. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  1298. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  1299. ;; (define-key view-mode-map
  1300. ;; "n" 'nonincremental-repeat-search-forward)
  1301. ;; (define-key view-mode-map
  1302. ;; "N" 'nonincremental-repeat-search-backward)
  1303. ;; N conflicts with git-walktree
  1304. ;; (define-key view-mode-map "/" 'isearch-forward-regexp)
  1305. ;; (define-key view-mode-map "?" 'isearch-backward-regexp)
  1306. ;; (define-key view-mode-map "n" 'isearch-repeat-forward)
  1307. ;; (define-key view-mode-map "N" 'isearch-repeat-backward)
  1308. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
  1309. (global-set-key "\M-r" 'view-mode)
  1310. ;; (setq view-read-only t)
  1311. (with-eval-after-load 'term
  1312. (defvar term-raw-map (make-sparse-keymap))
  1313. (define-key term-raw-map (kbd "C-x")
  1314. (lookup-key (current-global-map)
  1315. (kbd "C-x"))))
  1316. (add-hook 'term-mode-hook
  1317. (lambda ()
  1318. ;; Stop current line highlighting
  1319. (set (make-local-variable (defvar hl-line-range-function))
  1320. (lambda () '(0 . 0)))
  1321. (set (make-local-variable 'scroll-margin)
  1322. 0)
  1323. (set-variable 'term-buffer-maximum-size 20480)
  1324. ))
  1325. (add-hook 'Man-mode-hook
  1326. (lambda ()
  1327. (view-mode 1)
  1328. (setq truncate-lines nil)))
  1329. (set-variable 'Man-notify-method (if window-system
  1330. 'newframe
  1331. 'aggressive))
  1332. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  1333. "woman_cache.el")))
  1334. ;; not work because man.el will be loaded when man called
  1335. (defalias 'man 'woman)
  1336. (add-to-list 'auto-mode-alist
  1337. '("tox\\.ini\\'" . conf-unix-mode))
  1338. (when (autoload-eval-lazily 'toml-mode)
  1339. (add-to-list 'auto-mode-alist
  1340. '("/tox\\.ini\\'" . toml-mode))
  1341. (add-to-list 'auto-mode-alist
  1342. '("/Pipfile\\'" . toml-mode))
  1343. (add-to-list 'auto-mode-alist
  1344. '("/poetry\\.lock\\'" . toml-mode))
  1345. )
  1346. (when (autoload-eval-lazily 'json-mode)
  1347. (add-to-list 'auto-mode-alist
  1348. '("/Pipfile\\.lock\\'" . json-mode)))
  1349. (add-hook 'go-mode-hook
  1350. (lambda()
  1351. (defvar go-mode-map)
  1352. (add-hook 'before-save-hook' 'gofmt-before-save nil t)
  1353. (define-key go-mode-map (kbd "M-.") 'godef-jump)))
  1354. (when (autoload-eval-lazily 'k8s-mode)
  1355. (add-to-list 'auto-mode-alist
  1356. '("\\.k8s\\'" . k8s-mode)))
  1357. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1358. ;; buffers
  1359. (defvar bs-configurations)
  1360. (declare-function bs-set-configuration "bs")
  1361. (declare-function bs-refresh "bs")
  1362. (declare-function bs-message-without-log "bs")
  1363. (declare-function bs--current-config-message "bs")
  1364. (when (autoload-eval-lazily 'bs '(bs-show)
  1365. (add-to-list 'bs-configurations
  1366. '("specials" "^\\*" nil ".*" nil nil))
  1367. (add-to-list 'bs-configurations
  1368. '("files-and-specials" "^\\*" buffer-file-name ".*" nil nil))
  1369. (defvar bs-mode-map)
  1370. (defvar bs-current-configuration)
  1371. (define-key bs-mode-map (kbd "t")
  1372. ;; TODO: fix toggle feature
  1373. (lambda ()
  1374. (interactive)
  1375. (if (string= "specials"
  1376. bs-current-configuration)
  1377. (bs-set-configuration "files")
  1378. (bs-set-configuration "specials"))
  1379. (bs-refresh)
  1380. (bs-message-without-log "%s"
  1381. (bs--current-config-message))))
  1382. ;; (setq bs-configurations (list
  1383. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1384. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1385. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1386. )
  1387. (defalias 'list-buffers 'bs-show)
  1388. (set-variable 'bs-default-configuration "files-and-specials")
  1389. (set-variable 'bs-default-sort-name "by nothing")
  1390. (add-hook 'bs-mode-hook
  1391. (lambda ()
  1392. (set (make-local-variable 'scroll-margin) 0))))
  1393. ;;(iswitchb-mode 1)
  1394. (icomplete-mode)
  1395. (defun iswitchb-buffer-display-other-window ()
  1396. "Do iswitchb in other window."
  1397. (interactive)
  1398. (let ((iswitchb-default-method 'display))
  1399. (call-interactively 'iswitchb-buffer)))
  1400. ;; buffer killing
  1401. ;; (defun my-delete-window-killing-buffer () nil)
  1402. (defun my-query-kill-current-buffer ()
  1403. "Interactively kill current buffer."
  1404. (interactive)
  1405. (if (y-or-n-p (concat "kill current buffer? :"))
  1406. (kill-buffer (current-buffer))))
  1407. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  1408. (substitute-key-definition 'kill-buffer
  1409. 'my-query-kill-current-buffer
  1410. global-map)
  1411. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1412. ;; dired
  1413. (defun my-file-head (filename &optional n)
  1414. "Return list of first N lines of file FILENAME."
  1415. ;; TODO: Fix for janapese text
  1416. ;; TODO: Fix for short text
  1417. (let ((num (or n 10))
  1418. (size 100)
  1419. (beg 0)
  1420. (end 0)
  1421. (result '())
  1422. (read -1))
  1423. (with-temp-buffer
  1424. (erase-buffer)
  1425. (while (or (<= (count-lines (point-min)
  1426. (point-max))
  1427. num)
  1428. (eq read 0))
  1429. (setq end (+ beg size))
  1430. (setq read (nth 1 (insert-file-contents-literally filename
  1431. nil
  1432. beg
  1433. end)))
  1434. (goto-char (point-max))
  1435. (setq beg (+ beg size)))
  1436. (goto-char (point-min))
  1437. (while (< (length result) num)
  1438. (let ((start (point)))
  1439. (forward-line 1)
  1440. (setq result
  1441. `(,@result ,(buffer-substring-no-properties start
  1442. (point))))))
  1443. result
  1444. ;; (buffer-substring-no-properties (point-min)
  1445. ;; (progn
  1446. ;; (forward-line num)
  1447. ;; (point)))
  1448. )))
  1449. ;; (apply 'concat (my-file-head "./shrc" 10)
  1450. (defun my-dired-echo-file-head (arg)
  1451. "Echo head of current file.
  1452. ARG is num to show, or defaults to 7."
  1453. (interactive "P")
  1454. (let ((f (dired-get-filename)))
  1455. (message "%s"
  1456. (apply 'concat
  1457. (my-file-head f
  1458. 7)))))
  1459. (defun my-dired-diff ()
  1460. "Show diff of marked file and file of current line."
  1461. (interactive)
  1462. (let ((files (dired-get-marked-files nil nil nil t)))
  1463. (if (eq (car files)
  1464. t)
  1465. (diff (cadr files) (dired-get-filename))
  1466. (message "One file must be marked!"))))
  1467. (defun dired-get-file-info ()
  1468. "Print information of current line file."
  1469. (interactive)
  1470. (let ((f (shell-quote-argument (dired-get-filename t))))
  1471. (if (file-directory-p f)
  1472. (progn
  1473. (message "Calculating disk usage...")
  1474. (shell-command (concat "du -hsD "
  1475. f)))
  1476. (shell-command (concat "file "
  1477. f)))))
  1478. (defun my-dired-scroll-up ()
  1479. "Scroll up."
  1480. (interactive)
  1481. (my-dired-previous-line (- (window-height) 1)))
  1482. (defun my-dired-scroll-down ()
  1483. "Scroll down."
  1484. (interactive)
  1485. (my-dired-next-line (- (window-height) 1)))
  1486. ;; (defun my-dired-forward-line (arg)
  1487. ;; ""
  1488. ;; (interactive "p"))
  1489. (defun my-dired-previous-line (arg)
  1490. "Move ARG lines up."
  1491. (interactive "p")
  1492. (if (> arg 0)
  1493. (progn
  1494. (if (eq (line-number-at-pos)
  1495. 1)
  1496. (goto-char (point-max))
  1497. (forward-line -1))
  1498. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1499. (dired-get-subdir))
  1500. (- arg 1)
  1501. arg)))
  1502. (dired-move-to-filename)))
  1503. (defun my-dired-next-line (arg)
  1504. "Move ARG lines down."
  1505. (interactive "p")
  1506. (if (> arg 0)
  1507. (progn
  1508. (if (eq (point)
  1509. (point-max))
  1510. (goto-char (point-min))
  1511. (forward-line 1))
  1512. (my-dired-next-line (if (or (dired-get-filename nil t)
  1513. (dired-get-subdir))
  1514. (- arg 1)
  1515. arg)))
  1516. (dired-move-to-filename)))
  1517. (defun my-tramp-remote-find-file (f)
  1518. "Open F."
  1519. (interactive (list (read-file-name "My Find File Tramp: "
  1520. "/scp:"
  1521. nil ;; "/scp:"
  1522. (confirm-nonexistent-file-or-buffer))))
  1523. (find-file f))
  1524. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1525. (if (eq window-system 'mac)
  1526. (setq dired-listing-switches "-lhF")
  1527. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1528. )
  1529. (setq dired-listing-switches "-lhF")
  1530. ;; when using dired-find-alternate-file
  1531. ;; reuse current dired buffer for the file to open
  1532. ;; (put 'dired-find-alternate-file 'disabled nil)
  1533. (set-variable 'dired-ls-F-marks-symlinks t)
  1534. (set-variable 'ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1535. (set-variable 'ls-lisp-dirs-first t)
  1536. (set-variable 'ls-lisp-use-localized-time-format t)
  1537. (set-variable 'ls-lisp-format-time-list
  1538. '("%Y-%m-%d %H:%M"
  1539. "%Y-%m-%d "))
  1540. (set-variable 'dired-dwim-target t)
  1541. (set-variable 'dired-isearch-filenames t)
  1542. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  1543. (set-variable 'dired-hide-details-hide-information-lines nil)
  1544. (set-variable 'dired-deletion-confirmer 'y-or-n-p)
  1545. (set-variable 'dired-recursive-deletes 'always)
  1546. ;; (add-hook 'dired-after-readin-hook
  1547. ;; 'my-replace-nasi-none)
  1548. (with-eval-after-load 'dired
  1549. (safe-require-or-eval 'ls-lisp)
  1550. (defvar dired-mode-map (make-sparse-keymap))
  1551. ;; dired-do-chgrp sometimes cause system hung
  1552. (define-key dired-mode-map "G" 'ignore)
  1553. (define-key dired-mode-map "e" 'wdired-change-to-wdired-mode)
  1554. (define-key dired-mode-map "i" 'dired-get-file-info)
  1555. ;; (define-key dired-mode-map "f" 'find-file)
  1556. (define-key dired-mode-map "f" 'my-fzf-or-find-file)
  1557. (define-key dired-mode-map "z" 'fzf)
  1558. (define-key dired-mode-map "!" 'shell-command)
  1559. (define-key dired-mode-map "&" 'async-shell-command)
  1560. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1561. (define-key dired-mode-map "=" 'my-dired-diff)
  1562. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1563. (define-key dired-mode-map "b" 'gtkbm)
  1564. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1565. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1566. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1567. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1568. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1569. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1570. (substitute-key-definition 'dired-next-line
  1571. 'my-dired-next-line
  1572. dired-mode-map)
  1573. (substitute-key-definition 'dired-previous-line
  1574. 'my-dired-previous-line
  1575. dired-mode-map)
  1576. ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
  1577. ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
  1578. ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
  1579. ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
  1580. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1581. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1582. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1583. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1584. (add-hook 'dired-mode-hook
  1585. (lambda ()
  1586. (when (fboundp 'dired-hide-details-mode)
  1587. (dired-hide-details-mode t)
  1588. (local-set-key "l" 'dired-hide-details-mode))
  1589. (let ((file "._Icon\015"))
  1590. (when nil
  1591. '(file-readable-p file)
  1592. (delete-file file)))))
  1593. (when (autoload-eval-lazily 'pack '(dired-do-pack-or-unpack pack-pack)
  1594. (defvar pack-program-alist)
  1595. (add-to-list 'pack-program-alist
  1596. '("\\.txz\\'" :pack "tar -cJf" :unpack "tar -xf")))
  1597. (set-variable 'pack-silence
  1598. t)
  1599. (with-eval-after-load 'dired
  1600. (define-key dired-mode-map "P" 'pack-dired-dwim)))
  1601. (when (autoload-eval-lazily 'dired-list-all-mode)
  1602. (setq dired-listing-switches "-lhF")
  1603. (with-eval-after-load 'dired
  1604. (define-key dired-mode-map "a" 'dired-list-all-mode))))
  1605. (when (autoload-eval-lazily 'dired-filter)
  1606. (add-hook 'dired-mode-hook
  1607. 'dired-filter-mode))
  1608. (set-variable 'dired-filter-stack nil)
  1609. ;; Currently disabled in favor of dired-from-git-ls-files
  1610. ;; (define-key ctl-x-map "f" 'find-dired)
  1611. (defvar my-dired-git-ls-files-history
  1612. "History for `my-dired-git-ls-files'." nil)
  1613. (defun my-dired-git-ls-files (arg)
  1614. "Dired from git ls-files."
  1615. (interactive (list
  1616. (read-shell-command "git ls-files: "
  1617. "git ls-files -z ")))
  1618. (pop-to-buffer-same-window
  1619. (dired-noselect `(,default-directory
  1620. ,@(split-string (shell-command-to-string arg)
  1621. "\0" t))
  1622. ""))
  1623. )
  1624. (define-key ctl-x-map (kbd "G") 'my-dired-git-ls-files)
  1625. (with-eval-after-load 'dired
  1626. (defvar dired-mode-map (make-sparse-keymap))
  1627. (define-key dired-mode-map "G" 'my-dired-git-ls-files))
  1628. ;; (define-minor-mode my-dired-glob-filter)
  1629. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1630. ;; misc funcs
  1631. (define-key ctl-x-map "T" 'git-worktree)
  1632. (define-key ctl-x-map "W" 'git-walktree)
  1633. (when (fboundp 'browse-url-default-macosx-browser)
  1634. (defalias 'browse-osx 'browse-url-default-macosx-browser))
  1635. (defalias 'qcalc 'quick-calc)
  1636. (defun memo (&optional dir)
  1637. "Open memo.txt in DIR."
  1638. (interactive)
  1639. (pop-to-buffer (find-file-noselect (concat (if dir
  1640. (file-name-as-directory dir)
  1641. "")
  1642. "memo.txt"))))
  1643. ;; TODO: remember-projectile
  1644. (set (defvar my-privnotes-path nil
  1645. "My privnotes repository path.")
  1646. (expand-file-name "~/my/privnotes"))
  1647. (defun my-privnotes-readme (dir)
  1648. "Open my privnotes DIR."
  1649. (interactive (list
  1650. (read-file-name "Privnotes: "
  1651. (expand-file-name (format-time-string "%Y%m%d_")
  1652. my-privnotes-path))))
  1653. (let ((path (expand-file-name "README.md" dir)))
  1654. (with-current-buffer (find-file path)
  1655. (unless (file-exists-p path)
  1656. (insert (file-name-base dir)
  1657. "\n"
  1658. "=======\n"
  1659. "\n\n")))))
  1660. (define-key ctl-x-map "p" 'my-privnotes-readme)
  1661. (set (defvar my-rgrep-alist nil
  1662. "Alist of rgrep command.
  1663. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  1664. condition to choose COMMAND when evaluated.")
  1665. `(
  1666. ;; ripgrep
  1667. ("rg"
  1668. (executable-find "rg")
  1669. "rg -nH --no-heading --color=always --hidden --glob '!.git/' --smart-case -M 1280 ")
  1670. ;; git grep
  1671. ("gitgrep"
  1672. (eq 0
  1673. (shell-command "git rev-parse --git-dir"))
  1674. "git --no-pager -c color.grep=always grep -nH -e ")
  1675. ;; sift
  1676. ("sift"
  1677. (executable-find "sift")
  1678. ("sift --binary-skip --filename --line-number --git --smart-case "))
  1679. ;; the silver searcher
  1680. ("ag"
  1681. (executable-find "ag")
  1682. "ag --nogroup --nopager --filename ")
  1683. ;; ack
  1684. ("ack"
  1685. (executable-find "ack")
  1686. "ack --nogroup --nopager --with-filename ")
  1687. ;; gnu global
  1688. ("global"
  1689. (and (require 'ggtags nil t)
  1690. (executable-find "global")
  1691. (ggtags-current-project-root))
  1692. "global --result grep ")
  1693. ;; grep
  1694. ("grep"
  1695. t
  1696. ,(concat "find . "
  1697. "-path '*/.git' -prune -o "
  1698. "-path '*/.svn' -prune -o "
  1699. "-type f -print0 | "
  1700. "xargs -0 grep -nH -e "))
  1701. )
  1702. )
  1703. (defvar my-rgrep-default nil
  1704. "Default command name for my-rgrep.")
  1705. (defun my-rgrep-grep-command (&optional name alist)
  1706. "Return recursive grep command for current directory or nil.
  1707. If NAME is given, use that without testing.
  1708. Commands are searched from ALIST."
  1709. (if alist
  1710. (if name
  1711. ;; if name is given search that from alist and return the command
  1712. (nth 2 (assoc name
  1713. alist))
  1714. ;; if name is not given try test in 1th elem
  1715. (let ((car (car alist))
  1716. (cdr (cdr alist)))
  1717. (if (eval (nth 1 car))
  1718. ;; if the condition is true return the command
  1719. (nth 2 car)
  1720. ;; try next one
  1721. (and cdr
  1722. (my-rgrep-grep-command name cdr)))))
  1723. ;; if alist is not given set default value
  1724. (my-rgrep-grep-command name my-rgrep-alist)))
  1725. (defun my-rgrep (command-args)
  1726. "My recursive grep. Run COMMAND-ARGS.
  1727. If prefix argument is given, use current symbol as default search target
  1728. and search from projectile root (if projectile is available)."
  1729. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  1730. nil)))
  1731. (if cmd
  1732. (list (read-shell-command "grep command: "
  1733. (concat cmd
  1734. (if current-prefix-arg
  1735. (thing-at-point 'symbol t)
  1736. ""))
  1737. 'grep-find-history))
  1738. (error "My-Rgrep: Command for rgrep not found")
  1739. )))
  1740. (if (and current-prefix-arg
  1741. (safe-require-or-eval 'projectile)
  1742. (projectile-project-p))
  1743. (projectile-with-default-dir (projectile-project-root)
  1744. (compilation-start command-args
  1745. 'grep-mode))
  1746. (compilation-start command-args
  1747. 'grep-mode)))
  1748. (defun my-rgrep-thing-at-point-projectile-root ()
  1749. "My recursive grep to find thing at point from project root."
  1750. (interactive)
  1751. (let* ((cmd (my-rgrep-grep-command my-rgrep-default
  1752. nil))
  1753. (command-args
  1754. (if cmd
  1755. (concat cmd
  1756. (or (thing-at-point 'symbol t)
  1757. (error "No symbol at point")))
  1758. (error "My-Rgrep: Command for rgrep not found"))))
  1759. (if (safe-require-or-eval 'projectile)
  1760. (projectile-with-default-dir (or (projectile-project-root)
  1761. default-directory)
  1762. (compilation-start command-args
  1763. 'grep-mode))
  1764. (compilation-start command-args
  1765. 'grep-mode))))
  1766. (defmacro define-my-rgrep (name)
  1767. "Define rgrep for NAME."
  1768. `(defun ,(intern (concat "my-rgrep-"
  1769. name)) ()
  1770. ,(format "My recursive grep by %s."
  1771. name)
  1772. (interactive)
  1773. (let ((my-rgrep-default ,name))
  1774. (if (called-interactively-p 'any)
  1775. (call-interactively 'my-rgrep)
  1776. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  1777. )
  1778. (define-my-rgrep "ack")
  1779. (define-my-rgrep "ag")
  1780. (define-my-rgrep "rg")
  1781. (define-my-rgrep "sift")
  1782. (define-my-rgrep "gitgrep")
  1783. (define-my-rgrep "grep")
  1784. (define-my-rgrep "global")
  1785. (define-key ctl-x-map "s" 'my-rgrep)
  1786. (define-key ctl-x-map "." 'my-rgrep-thing-at-point-projectile-root)
  1787. (defun my-occur (regexp &optional region)
  1788. "My occur command to search REGEXP."
  1789. (interactive (list (read-string "List lines matching regexp: "
  1790. (thing-at-point 'symbol t))))
  1791. (occur regexp nil region))
  1792. (define-key ctl-x-map (kbd "C-o") 'my-occur)
  1793. (set-variable 'dumb-jump-prefer-searcher 'rg)
  1794. (defalias 'make 'compile)
  1795. (define-key ctl-x-map "c" 'compile)
  1796. (defun my-pushbullet-note (text &optional title)
  1797. "Push TEXT."
  1798. (interactive "sText to Push: ")
  1799. (pb/push-item '("") text "note" (or title "")))
  1800. ;;;;;;;;;;;;;;;;;;;;;
  1801. ;; git-bug
  1802. (defconst git-bug-ls-regexp
  1803. (eval-when-compile
  1804. (rx bol
  1805. (submatch (one-or-more alphanumeric)) ; id
  1806. ;; (one-or-more any)
  1807. (one-or-more space)
  1808. (submatch (or "open" "close")) ; status
  1809. (one-or-more space)
  1810. (submatch (maximal-match (zero-or-more print))) ; title
  1811. "\t"
  1812. (submatch (one-or-more alphanumeric)) ; user
  1813. (one-or-more space)
  1814. "C:"
  1815. (submatch (one-or-more digit)) ; Comment num
  1816. (one-or-more space)
  1817. "L:"
  1818. (submatch (one-or-more digit)) ; Label num
  1819. eol
  1820. ))
  1821. "Regexp to parse line of output of git-bug ls.
  1822. Used by `git-bug-ls'.")
  1823. (defun git-bug-bugs ()
  1824. "Get list of git-bug bugs."
  1825. (with-temp-buffer
  1826. (git-bug--call-process "bug" "ls")
  1827. (goto-char (point-min))
  1828. (let ((bugs nil))
  1829. (while (not (eq (point) (point-max)))
  1830. (save-match-data
  1831. (when (re-search-forward git-bug-ls-regexp (point-at-eol) t)
  1832. (setq bugs `(,@bugs
  1833. ,(list
  1834. :id (match-string 1)
  1835. :status (match-string 2)
  1836. :title (string-trim (match-string 3))
  1837. :user (match-string 4)
  1838. :comment-num (match-string 5)
  1839. :label-num (match-string 6)
  1840. )))))
  1841. (forward-line 1)
  1842. (goto-char (point-at-bol)))
  1843. bugs)))
  1844. (defun git-bug-ls-noselect (&optional directory)
  1845. "Open git bug list buffer.
  1846. If optional arg DIRECTORY is given change current directory to there before
  1847. initializing."
  1848. (setq directory (expand-file-name (or directory
  1849. default-directory)))
  1850. (cl-assert (file-directory-p directory))
  1851. (let* ((root (git-bug--get-repository-root directory))
  1852. (name (file-name-nondirectory root))
  1853. (bname (format "*GitBug<%s>*" name)))
  1854. (with-current-buffer (get-buffer-create bname)
  1855. (cd root)
  1856. (git-bug-ls--set-tabulated-list-mode-variables)
  1857. (git-bug-ls-mode)
  1858. (current-buffer))))
  1859. (defun git-bug--get-repository-root (dir)
  1860. "Resolve repository root of DIR.
  1861. If DIR is not inside of any git repository, signal an error."
  1862. (cl-assert (file-directory-p dir))
  1863. (with-temp-buffer
  1864. (cd dir)
  1865. (git-bug--call-process "rev-parse" "--show-toplevel")
  1866. (goto-char (point-min))
  1867. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  1868. (defun git-bug--call-process (&rest args)
  1869. "Start git process synchronously with ARGS.
  1870. Raise error when git process ends with non-zero status.
  1871. Any output will be written to current buffer."
  1872. (let ((status (apply 'call-process
  1873. "git"
  1874. nil
  1875. t
  1876. nil
  1877. args)))
  1878. (cl-assert (eq status 0)
  1879. nil
  1880. (buffer-substring-no-properties (point-min) (point-max)))))
  1881. ;;;;;;;;;;;;;;;;;;;
  1882. ;; peek-file-mode
  1883. (defun peek-file (file)
  1884. "Peek FILE."
  1885. (interactive)
  1886. (message "%s" file))
  1887. ;;;;;;;;;;;;;;;;;;;;
  1888. ;; remember-projectile
  1889. ;; Local Variables:
  1890. ;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
  1891. ;; flycheck-checker: emacs-lisp
  1892. ;; End:
  1893. ;;; emancs.el ends here