您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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