Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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