25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

emacs.el 72 KiB

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