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

emacs.el 72 KiB

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