Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

11 лет назад
9 лет назад
13 лет назад
8 лет назад
12 лет назад
12 лет назад
13 лет назад
13 лет назад
9 лет назад
8 лет назад
8 лет назад
11 лет назад
8 лет назад
8 лет назад
8 лет назад
8 лет назад
8 лет назад
8 лет назад
6 лет назад
8 лет назад
8 лет назад
6 лет назад
8 лет назад
8 лет назад
6 лет назад
8 лет назад
8 лет назад
8 лет назад
8 лет назад
8 лет назад
8 лет назад
8 лет назад
11 лет назад
8 лет назад
11 лет назад
11 лет назад
11 лет назад
13 лет назад
13 лет назад
12 лет назад
12 лет назад
13 лет назад
12 лет назад
13 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
9 лет назад
9 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
12 лет назад
10 лет назад
12 лет назад
13 лет назад
9 лет назад
13 лет назад
12 лет назад
13 лет назад
10 лет назад
8 лет назад
8 лет назад
8 лет назад
8 лет назад
12 лет назад
8 лет назад
8 лет назад
6 лет назад
8 лет назад
7 лет назад
8 лет назад
8 лет назад
7 лет назад
8 лет назад
8 лет назад
12 лет назад
12 лет назад
11 лет назад
11 лет назад
8 лет назад
10 лет назад
8 лет назад
8 лет назад
7 лет назад
8 лет назад
11 лет назад
11 лет назад
6 лет назад
12 лет назад
12 лет назад
11 лет назад
13 лет назад
12 лет назад
13 лет назад
7 лет назад
13 лет назад
12 лет назад
8 лет назад
13 лет назад
7 лет назад
7 лет назад
13 лет назад
13 лет назад
13 лет назад
11 лет назад
12 лет назад
12 лет назад
10 лет назад
13 лет назад
13 лет назад
9 лет назад
13 лет назад
12 лет назад
13 лет назад
12 лет назад
12 лет назад
12 лет назад
13 лет назад
8 лет назад
8 лет назад
12 лет назад
12 лет назад
12 лет назад
8 лет назад
8 лет назад
6 лет назад
13 лет назад
8 лет назад
8 лет назад
8 лет назад
13 лет назад
13 лет назад
8 лет назад
12 лет назад
8 лет назад
12 лет назад
11 лет назад
11 лет назад
7 лет назад
13 лет назад
6 лет назад
9 лет назад
6 лет назад
12 лет назад
12 лет назад
12 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
6 лет назад
13 лет назад
12 лет назад
8 лет назад
12 лет назад
12 лет назад
10 лет назад
12 лет назад
10 лет назад
12 лет назад
6 лет назад
12 лет назад
12 лет назад
12 лет назад
6 лет назад
12 лет назад
7 лет назад
12 лет назад
8 лет назад
6 лет назад
6 лет назад
6 лет назад
6 лет назад
6 лет назад
6 лет назад
6 лет назад
8 лет назад
11 лет назад
9 лет назад
11 лет назад
6 лет назад
9 лет назад
6 лет назад
6 лет назад
12 лет назад
8 лет назад
8 лет назад
6 лет назад
8 лет назад
12 лет назад
13 лет назад
6 лет назад
6 лет назад
6 лет назад
6 лет назад
13 лет назад
8 лет назад
8 лет назад
7 лет назад
8 лет назад
9 лет назад
6 лет назад
13 лет назад
10 лет назад
13 лет назад
13 лет назад
12 лет назад
13 лет назад
12 лет назад
9 лет назад
8 лет назад
8 лет назад
9 лет назад
8 лет назад
13 лет назад
13 лет назад
8 лет назад
13 лет назад
9 лет назад
13 лет назад
11 лет назад
13 лет назад
8 лет назад
13 лет назад
13 лет назад
13 лет назад
7 лет назад
13 лет назад
13 лет назад
10 лет назад
8 лет назад
10 лет назад
13 лет назад
6 лет назад
13 лет назад
9 лет назад
8 лет назад
8 лет назад
8 лет назад
12 лет назад
12 лет назад
12 лет назад
13 лет назад
13 лет назад
10 лет назад
13 лет назад
13 лет назад
8 лет назад
13 лет назад
8 лет назад
13 лет назад
9 лет назад
9 лет назад
12 лет назад
11 лет назад
13 лет назад
13 лет назад
8 лет назад
12 лет назад
13 лет назад
8 лет назад
6 лет назад
8 лет назад
6 лет назад
8 лет назад
8 лет назад
6 лет назад
8 лет назад
6 лет назад
8 лет назад
12 лет назад
8 лет назад
6 лет назад
8 лет назад
12 лет назад
8 лет назад
12 лет назад
8 лет назад
6 лет назад
8 лет назад
6 лет назад
8 лет назад
6 лет назад
8 лет назад
6 лет назад
8 лет назад
8 лет назад
8 лет назад
8 лет назад
12 лет назад
12 лет назад
8 лет назад
8 лет назад
7 лет назад
8 лет назад
12 лет назад
8 лет назад
10 лет назад
11 лет назад
10 лет назад
6 лет назад
6 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
11 лет назад
6 лет назад
10 лет назад
6 лет назад
6 лет назад
10 лет назад
9 лет назад
10 лет назад
11 лет назад
11 лет назад
9 лет назад
10 лет назад
6 лет назад
6 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
11 лет назад
6 лет назад
6 лет назад
6 лет назад
6 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  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: (load-file file)))
  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. ;; It seems malabar has been merged into jdee and this package
  76. ;; already removed
  77. ;; malabar-mode
  78. ;; ack
  79. color-moccur
  80. ggtags
  81. flycheck
  82. auto-highlight-symbol
  83. hl-todo
  84. ;; Currently not available
  85. ;; pp-c-l
  86. ;; is flymake installs are required?
  87. ;;flymake-jshint
  88. ;;flymake-python-pyflakes
  89. xclip
  90. foreign-regexp
  91. multi-term
  92. term-run
  93. editorconfig
  94. git-ps1-mode
  95. restart-emacs
  96. fill-column-indicator
  97. pkgbuild-mode
  98. minibuffer-line
  99. which-key
  100. ;; I think this works in place of my autosave lib
  101. super-save
  102. pipenv
  103. imenu-list
  104. scala-mode
  105. ;;ensime
  106. editorconfig
  107. editorconfig-custom-majormode
  108. git-command
  109. prompt-text
  110. ;; 10sr repository
  111. ;; 10sr-extras
  112. terminal-title
  113. recentf-show
  114. dired-list-all-mode
  115. pack
  116. set-modeline-color
  117. read-only-only-mode
  118. smart-revert
  119. autosave
  120. ;;window-organizer
  121. remember-major-modes-mode
  122. ilookup
  123. pasteboard
  124. end-mark
  125. sl
  126. gosh-mode
  127. ))
  128. (when (safe-require-or-eval 'package)
  129. (setq package-archives
  130. `(,@package-archives
  131. ("melpa" . "https://melpa.org/packages/")
  132. ;; Somehow fails to download via https
  133. ("10sr-el" . "http://10sr.github.io/emacs-lisp/elpa/")))
  134. (package-initialize)
  135. (defun my-auto-install-package ()
  136. "Install packages semi-automatically."
  137. (interactive)
  138. (package-refresh-contents)
  139. (mapc (lambda (pkg)
  140. (or (package-installed-p pkg)
  141. (package-install pkg)))
  142. 10sr-package-list))
  143. )
  144. ;; (lazy-load-eval 'sudoku)
  145. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  146. ;; my-idle-hook
  147. (defvar my-idle-hook nil
  148. "Hook run when idle for several secs.")
  149. (defvar my-idle-hook-sec 5
  150. "Second to run `my-idle-hook'.")
  151. (run-with-idle-timer my-idle-hook-sec
  152. t
  153. (lambda ()
  154. (run-hooks 'my-idle-hook)))
  155. ;; (add-hook 'my-idle-hook
  156. ;; (lambda ()
  157. ;; (message "idle hook message")))
  158. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  159. ;; start and quit
  160. (setq inhibit-startup-message t)
  161. (setq confirm-kill-emacs 'y-or-n-p)
  162. (setq gc-cons-threshold (* 1024 1024 4))
  163. (when window-system
  164. (add-to-list 'default-frame-alist '(cursor-type . box))
  165. (add-to-list 'default-frame-alist '(background-color . "white"))
  166. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  167. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  168. ;; does not work?
  169. )
  170. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  171. (if window-system (menu-bar-mode 1) (menu-bar-mode 0))
  172. (and (fboundp 'tool-bar-mode)
  173. (tool-bar-mode 0))
  174. (and (fboundp 'set-scroll-bar-mode)
  175. (set-scroll-bar-mode nil))
  176. (call-after-init
  177. (lambda ()
  178. (message "%s %s" invocation-name emacs-version)
  179. (message "Invocation directory: %s" default-directory)
  180. (message "%s was taken to initialize emacs." (emacs-init-time))
  181. (switch-to-buffer "*Messages*")))
  182. (cd ".") ; when using windows use / instead of \ in `default-directory'
  183. ;; locale
  184. (set-language-environment "Japanese")
  185. (set-default-coding-systems 'utf-8-unix)
  186. (prefer-coding-system 'utf-8-unix)
  187. (setq system-time-locale "C")
  188. ;; my prefix map
  189. (defvar my-prefix-map nil
  190. "My prefix map.")
  191. (define-prefix-command 'my-prefix-map)
  192. (define-key ctl-x-map (kbd "C-x") 'my-prefix-map)
  193. (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  194. (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  195. ;; (comint-show-maximum-output)
  196. ;; kill scratch
  197. (call-after-init (lambda ()
  198. (let ((buf (get-buffer "*scratch*")))
  199. (when buf
  200. (kill-buffer buf)))))
  201. ;; modifier keys
  202. ;; (setq mac-option-modifier 'control)
  203. ;; display
  204. (setq visible-bell t)
  205. (setq ring-bell-function 'ignore)
  206. (mouse-avoidance-mode 'banish)
  207. (setq echo-keystrokes 0.1)
  208. (defun reload-init-file ()
  209. "Reload Emacs init file."
  210. (interactive)
  211. (when (and user-init-file
  212. (file-readable-p user-init-file))
  213. (load-file user-init-file)))
  214. (safe-require-or-eval 'session)
  215. ;; server
  216. (set-variable 'server-name (concat "server"
  217. (number-to-string (emacs-pid))))
  218. ;; In Cygwin Environment `server-runnning-p' stops when server-use-tcp is nil
  219. ;; In Darwin environment, init fails with message like 'Service name too long'
  220. ;; when server-use-tcp is nil
  221. (when (or (eq system-type
  222. 'cygwin)
  223. (eq system-type
  224. 'darwin))
  225. (set-variable 'server-use-tcp t))
  226. ;; MSYS2 fix
  227. (when (eq system-type
  228. 'windows-nt)
  229. (setq shell-file-name
  230. (executable-find "bash"))
  231. '(setq function-key-map
  232. `(,@function-key-map ([pause] . [?\C-c])
  233. ))
  234. (define-key key-translation-map
  235. (kbd "<pause>")
  236. (kbd "C-c"))
  237. '(keyboard-translate [pause]
  238. (kbd "C-c")p)
  239. ;; TODO: move to other place later
  240. (when (not window-system)
  241. (setq interprogram-paste-function nil)
  242. (setq interprogram-cut-function nil)))
  243. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  244. ;; global keys
  245. (global-set-key (kbd "<up>") 'scroll-down-line)
  246. (global-set-key (kbd "<down>") 'scroll-up-line)
  247. (global-set-key (kbd "<left>") 'scroll-down)
  248. (global-set-key (kbd "<right>") 'scroll-up)
  249. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  250. (global-set-key (kbd "C-\\") help-map)
  251. (define-key ctl-x-map (kbd "DEL") help-map)
  252. (define-key ctl-x-map (kbd "C-h") help-map)
  253. (define-key help-map "a" 'apropos)
  254. ;; disable annoying keys
  255. (global-set-key [prior] 'ignore)
  256. (global-set-key (kbd "<next>") 'ignore)
  257. (global-set-key [menu] 'ignore)
  258. (global-set-key [down-mouse-1] 'ignore)
  259. (global-set-key [down-mouse-2] 'ignore)
  260. (global-set-key [down-mouse-3] 'ignore)
  261. (global-set-key [mouse-1] 'ignore)
  262. (global-set-key [mouse-2] 'ignore)
  263. (global-set-key [mouse-3] 'ignore)
  264. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  265. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  266. (when (safe-require-or-eval 'which-key)
  267. (which-key-mode))
  268. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  269. ;; editting
  270. (setq kill-whole-line t)
  271. (setq scroll-conservatively 35
  272. scroll-margin 2
  273. scroll-step 0)
  274. (setq-default major-mode 'text-mode)
  275. (setq next-line-add-newlines nil)
  276. (setq kill-read-only-ok t)
  277. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  278. ;; (setq-default line-spacing 0.2)
  279. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  280. ;; (setq-default tab-width 4)
  281. (setq-default indent-tabs-mode nil)
  282. (setq-default indent-line-function 'indent-to-left-margin)
  283. ;; (setq-default indent-line-function nil)
  284. (setq-default truncate-lines nil)
  285. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  286. (delete-selection-mode 1)
  287. (cua-mode 0)
  288. (setq line-move-visual nil)
  289. ;; key bindings
  290. ;; moving around
  291. ;;(keyboard-translate ?\M-j ?\C-j)
  292. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  293. (define-key esc-map "p" 'backward-paragraph)
  294. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  295. (define-key esc-map "n" 'forward-paragraph)
  296. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  297. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  298. (global-set-key (kbd "C-<left>") 'scroll-down)
  299. (global-set-key (kbd "C-<right>") 'scroll-up)
  300. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  301. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  302. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  303. ;; C-h and DEL
  304. (global-set-key (kbd "C-h") (kbd "DEL"))
  305. ;;(global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  306. (global-set-key (kbd "C-m") 'newline-and-indent)
  307. ;; (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  308. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  309. (define-key esc-map "u" 'undo)
  310. (define-key esc-map "i" (kbd "ESC TAB"))
  311. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  312. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  313. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  314. (define-key my-prefix-map (kbd "C-o") 'occur)
  315. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  316. ;; title and mode-line
  317. (when (safe-require-or-eval 'terminal-title)
  318. ;; if TERM is not screen use default value
  319. (if (getenv "TMUX")
  320. ;; if use tmux locally just basename of current dir
  321. (set-variable 'terminal-title-format
  322. '((file-name-nondirectory (directory-file-name
  323. default-directory))))
  324. (if (and (let ((tty-type (frame-parameter nil
  325. 'tty-type)))
  326. (and tty-type
  327. (equal (car (split-string tty-type
  328. "-"))
  329. "screen")))
  330. (not (getenv "SSH_CONNECTION")))
  331. (set-variable 'terminal-title-format
  332. '((file-name-nondirectory (directory-file-name
  333. default-directory))))
  334. ;; seems that TMUX is used locally and ssh to remote host
  335. (set-variable 'terminal-title-format
  336. `("em:"
  337. ,user-login-name
  338. "@"
  339. ,(car (split-string (system-name)
  340. "\\."))
  341. ":"
  342. default-directory))
  343. )
  344. )
  345. (terminal-title-mode))
  346. (setq eol-mnemonic-dos "\\r\\n")
  347. (setq eol-mnemonic-mac "\\r")
  348. (setq eol-mnemonic-unix "")
  349. (which-function-mode 0)
  350. (line-number-mode 0)
  351. (column-number-mode 0)
  352. (size-indication-mode 0)
  353. (setq mode-line-position
  354. '(:eval (format "L%%l/%d:C%%c"
  355. (count-lines (point-max)
  356. (point-min)))))
  357. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  358. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  359. ;; minibuffer
  360. (setq insert-default-directory t)
  361. (setq completion-ignore-case t
  362. read-file-name-completion-ignore-case t
  363. read-buffer-completion-ignore-case t)
  364. (setq resize-mini-windows t)
  365. (temp-buffer-resize-mode 1)
  366. (savehist-mode 1)
  367. (defvar display-time-format "%Y/%m/%d %a %H:%M")
  368. (fset 'yes-or-no-p 'y-or-n-p)
  369. ;; complete symbol when `eval'
  370. (define-key read-expression-map (kbd "TAB") 'completion-at-point)
  371. (define-key minibuffer-local-map (kbd "C-u")
  372. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  373. ;; I dont know these bindings are good
  374. (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
  375. (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
  376. (when (safe-require-or-eval 'minibuffer-line)
  377. (set-face-underline 'minibuffer-line nil)
  378. (set-variable 'minibuffer-line-refresh-interval
  379. 25)
  380. ;; Set idle timer
  381. (defvar my-minibuffer-line--idle-timer nil)
  382. (defvar minibuffer-line-mode)
  383. (add-hook 'minibuffer-line-mode-hook
  384. (lambda ()
  385. (when my-minibuffer-line--idle-timer
  386. (cancel-timer my-minibuffer-line--idle-timer)
  387. (setq my-minibuffer-line--idle-timer nil))
  388. (when minibuffer-line-mode
  389. (setq my-minibuffer-line--idle-timer
  390. (run-with-idle-timer 0.5
  391. t
  392. 'minibuffer-line--update)))))
  393. (set-variable 'minibuffer-line-format
  394. `(,(concat user-login-name
  395. "@"
  396. (car (split-string (system-name)
  397. "\\."))
  398. ":")
  399. (:eval (abbreviate-file-name (or buffer-file-name
  400. default-directory)))
  401. (:eval (and (fboundp 'git-ps1-mode-get-current)
  402. (git-ps1-mode-get-current " [GIT:%s]")))
  403. " "
  404. (:eval (format-time-string display-time-format))))
  405. (minibuffer-line-mode 1)
  406. )
  407. (when (safe-require-or-eval 'prompt-text)
  408. (set-variable 'prompt-text-format
  409. `(,(concat ""
  410. user-login-name
  411. "@"
  412. (car (split-string (system-name)
  413. "\\."))
  414. ":")
  415. (:eval (abbreviate-file-name (or buffer-file-name
  416. default-directory)))
  417. (:eval (and (fboundp 'git-ps1-mode-get-current)
  418. (git-ps1-mode-get-current " [GIT:%s]")))
  419. " "
  420. (:eval (format-time-string display-time-format))
  421. "\n"
  422. (:eval (symbol-name this-command))
  423. ": "))
  424. (prompt-text-mode 1))
  425. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  426. ;; letters, font-lock mode and fonts
  427. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  428. ;; (set-window-margins (selected-window) 1 1)
  429. (and (or (eq system-type 'Darwin)
  430. (eq system-type 'darwin))
  431. (fboundp 'mac-set-input-method-parameter)
  432. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  433. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  434. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  435. (boundp 'input-method-inactivate-hook))
  436. (add-hook 'input-method-activate-hook
  437. (lambda () (set-cursor-color "red")))
  438. (add-hook 'input-method-inactivate-hook
  439. (lambda () (set-cursor-color "black"))))
  440. (when (safe-require-or-eval 'paren)
  441. (show-paren-mode 1)
  442. (setq show-paren-delay 0.5
  443. show-paren-style 'parenthesis) ; mixed is hard to read
  444. ;; (set-face-background 'show-paren-match
  445. ;; "black")
  446. ;; ;; (face-foreground 'default))
  447. ;; (set-face-foreground 'show-paren-match
  448. ;; "white")
  449. ;; (set-face-inverse-video-p 'show-paren-match
  450. ;; t)
  451. )
  452. (transient-mark-mode 1)
  453. (global-font-lock-mode 1)
  454. (setq font-lock-global-modes
  455. '(not
  456. help-mode
  457. eshell-mode
  458. ;;term-mode
  459. Man-mode))
  460. ;; (standard-display-ascii ?\n "$\n")
  461. ;; (defvar my-eol-face
  462. ;; '(("\n" . (0 font-lock-comment-face t nil)))
  463. ;; )
  464. ;; (defvar my-tab-face
  465. ;; '(("\t" . '(0 highlight t nil))))
  466. (defvar my-jspace-face
  467. '(("\u3000" . '(0 highlight t nil))))
  468. (add-hook 'font-lock-mode-hook
  469. (lambda ()
  470. ;; (font-lock-add-keywords nil my-eol-face)
  471. (font-lock-add-keywords nil my-jspace-face)
  472. ))
  473. (when (safe-require-or-eval 'whitespace)
  474. (add-to-list 'whitespace-display-mappings
  475. ;; We need t since last one takes precedence
  476. `(tab-mark ?\t ,(vconcat "^I\t")) t)
  477. ;; (add-to-list 'whitespace-display-mappings
  478. ;; `(newline-mark ?\n ,(vconcat "$\n")))
  479. (setq whitespace-style '(face
  480. trailing ; trailing blanks
  481. newline ; newlines
  482. newline-mark ; use display table for newline
  483. tab-mark
  484. empty ; empty lines at beg or end of buffer
  485. lines-tail ; lines over 80
  486. ))
  487. ;; (setq whitespace-newline 'font-lock-comment-face)
  488. (set-variable 'whitespace-line-column nil)
  489. (global-whitespace-mode t)
  490. (add-hook 'dired-mode-hook
  491. (lambda ()
  492. (set (make-local-variable 'whitespace-style) nil)))
  493. (if (eq (display-color-cells)
  494. 256)
  495. (set-face-foreground 'whitespace-newline "color-109")
  496. ;; (progn
  497. ;; (set-face-bold-p 'whitespace-newline
  498. ;; t))
  499. ))
  500. (and nil
  501. '(safe-require-or-eval 'fill-column-indicator)
  502. (setq fill-column-indicator))
  503. ;; highlight current line
  504. ;; http://wiki.riywo.com/index.php?Meadow
  505. (face-spec-set 'hl-line
  506. '((((min-colors 256)
  507. (background dark))
  508. (:background "color-234"))
  509. (((min-colors 256)
  510. (background light))
  511. (:background "color-234"))
  512. (t
  513. (:underline "black"))))
  514. (set-variable 'hl-line-global-modes
  515. '(not
  516. term-mode))
  517. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  518. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  519. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  520. ;;(safe-require-or-eval 'set-modeline-color)
  521. ;; (let ((fg (face-foreground 'default))
  522. ;; (bg (face-background 'default)))
  523. ;; (set-face-background 'mode-line-inactive
  524. ;; (if (face-inverse-video-p 'mode-line) fg bg))
  525. ;; (set-face-foreground 'mode-line-inactive
  526. ;; (if (face-inverse-video-p 'mode-line) bg fg)))
  527. ;; (set-face-underline 'mode-line-inactive
  528. ;; t)
  529. ;; (set-face-underline 'vertical-border
  530. ;; nil)
  531. (when (safe-require-or-eval 'end-mark)
  532. (global-end-mark-mode))
  533. (when (safe-require-or-eval 'auto-highlight-symbol)
  534. (set-variable 'ahs-idle-interval 0.6)
  535. (global-auto-highlight-symbol-mode 1))
  536. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  537. ;; file handling
  538. (when (safe-require-or-eval 'editorconfig)
  539. ;; (set-variable 'editorconfig-get-properties-function
  540. ;; 'editorconfig-core-get-properties-hash)
  541. (editorconfig-mode 1)
  542. (set-variable 'editorconfig-mode-lighter " EC")
  543. (with-eval-after-load 'org-src
  544. ;; [*.org\[\*Org Src*\[ c \]*\]]
  545. (add-hook 'org-src-mode-hook
  546. 'editorconfig-mode-apply t)))
  547. (when (fboundp 'editorconfig-custom-majormode)
  548. (add-hook 'editorconfig-custom-hooks
  549. 'editorconfig-custom-majormode))
  550. ;; Add readonly=true to set read-only-mode
  551. (add-hook 'editorconfig-custom-hooks
  552. (lambda (props)
  553. (let ((r (gethash 'readonly props)))
  554. (when (and (string= r "true")
  555. (not buffer-read-only))
  556. (read-only-mode 1)))))
  557. ;; (when (fboundp 'editorconfig-charset-extras)
  558. ;; (add-hook 'editorconfig-custom-hooks
  559. ;; 'editorconfig-charset-extras))
  560. (setq revert-without-query '(".+"))
  561. ;; save cursor position
  562. (when (safe-require-or-eval 'saveplace)
  563. (setq-default save-place t)
  564. (setq save-place-file (concat user-emacs-directory
  565. "places")))
  566. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  567. (setq make-backup-files t)
  568. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  569. (setq backup-directory-alist
  570. (cons (cons "\\.*$" (expand-file-name (concat user-emacs-directory
  571. "backup")))
  572. backup-directory-alist))
  573. (setq version-control 'never)
  574. (setq delete-old-versions t)
  575. (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
  576. "auto-save/")))
  577. (setq delete-auto-save-files t)
  578. (add-to-list 'completion-ignored-extensions ".bak")
  579. (setq delete-by-moving-to-trash t)
  580. ;; trash-directory "~/.emacs.d/trash")
  581. (add-hook 'after-save-hook
  582. 'executable-make-buffer-file-executable-if-script-p)
  583. (set (defvar bookmark-default-file)
  584. (expand-file-name (concat user-emacs-directory
  585. "bmk")))
  586. (with-eval-after-load 'recentf
  587. (defvar recentf-exclude nil)
  588. (add-to-list 'recentf-exclude
  589. (regexp-quote bookmark-default-file)))
  590. (when (safe-require-or-eval 'smart-revert)
  591. (smart-revert-on))
  592. ;; autosave
  593. (when (safe-require-or-eval 'autosave)
  594. (autosave-set 8))
  595. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  596. ;; buffer killing
  597. ;; (defun my-delete-window-killing-buffer () nil)
  598. (defun my-query-kill-current-buffer ()
  599. "Interactively kill current buffer."
  600. (interactive)
  601. (if (y-or-n-p (concat "kill current buffer? :"))
  602. (kill-buffer (current-buffer))))
  603. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  604. (substitute-key-definition 'kill-buffer
  605. 'my-query-kill-current-buffer
  606. global-map)
  607. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  608. ;; share clipboard with x
  609. ;; this page describes this in details, but only these sexps seem to be needed
  610. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  611. (and nil
  612. (not window-system)
  613. (not (eq window-system 'mac))
  614. (getenv "DISPLAY")
  615. (not (equal (getenv "DISPLAY") ""))
  616. (executable-find "xclip")
  617. ;; (< emacs-major-version 24)
  618. '(safe-require-or-eval 'xclip)
  619. nil
  620. (turn-on-xclip))
  621. (and (eq system-type 'darwin)
  622. (safe-require-or-eval 'pasteboard)
  623. (turn-on-pasteboard))
  624. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  625. ;; some modes and hooks
  626. ;; Include some extra modes
  627. (require 'generic-x)
  628. (when (autoload-eval-lazily 'ggtags)
  629. (add-hook 'c-mode-common-hook
  630. (lambda ()
  631. (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
  632. (ggtags-mode 1))))
  633. (add-hook 'python-mode-hook
  634. (lambda ()
  635. (ggtags-mode 1))))
  636. (when (autoload-eval-lazily 'imenu-list)
  637. (set-variable 'imenu-list-auto-resize t)
  638. (set-variable 'imenu-list-focus-after-activation t)
  639. (define-key ctl-x-map "l" 'imenu-list-smart-toggle))
  640. (with-eval-after-load 'compile
  641. (defvar compilation-filter-start)
  642. (defvar compilation-error-regexp-alist)
  643. (require 'ansi-color)
  644. (add-hook 'compilation-filter-hook
  645. (lambda ()
  646. (let ((inhibit-read-only t))
  647. (ansi-color-apply-on-region compilation-filter-start
  648. (point)))))
  649. (add-to-list 'compilation-error-regexp-alist
  650. ;; ansible-lint
  651. '("^\\([^ \n]+\\):\\([0-9]+\\)$" 1 2)))
  652. ;; Workaround to avoid ensime error
  653. (defvar ensime-mode-key-prefix nil)
  654. ;; http://qiita.com/sune2/items/b73037f9e85962f5afb7
  655. (when (safe-require-or-eval 'company)
  656. (global-company-mode)
  657. (set-variable 'company-idle-delay 0.5)
  658. (set-variable 'company-minimum-prefix-length 2)
  659. (set-variable 'company-selection-wrap-around t))
  660. ;; https://github.com/lunaryorn/flycheck
  661. (when (safe-require-or-eval 'flycheck)
  662. (call-after-init 'global-flycheck-mode))
  663. (when (autoload-eval-lazily 'ilookup)
  664. (define-key ctl-x-map "d" 'ilookup-open-word))
  665. (set-variable 'ac-ignore-case nil)
  666. (when (autoload-eval-lazily 'term-run '(term-run-shell-command term-run))
  667. (define-key ctl-x-map "t" 'term-run-shell-command))
  668. (add-to-list 'safe-local-variable-values
  669. '(encoding utf-8))
  670. (setq enable-local-variables :safe)
  671. ;; (when (safe-require-or-eval 'remember-major-modes-mode)
  672. ;; (remember-major-modes-mode 1))
  673. ;; Detect file type from shebang and set major-mode.
  674. (add-to-list 'interpreter-mode-alist
  675. '("python3" . python-mode))
  676. (add-to-list 'interpreter-mode-alist
  677. '("python2" . python-mode))
  678. (with-eval-after-load 'python
  679. (defvar python-mode-map (make-sparse-keymap))
  680. (define-key python-mode-map (kbd "C-m") 'newline-and-indent))
  681. ;; http://fukuyama.co/foreign-regexp
  682. '(and (safe-require-or-eval 'foreign-regexp)
  683. (progn
  684. (setq foreign-regexp/regexp-type 'perl)
  685. '(setq reb-re-syntax 'foreign-regexp)
  686. ))
  687. (autoload-eval-lazily 'sql '(sql-mode)
  688. (require 'sql-indent nil t))
  689. (when (autoload-eval-lazily 'git-command)
  690. (define-key ctl-x-map "g" 'git-command))
  691. (when (safe-require-or-eval 'git-commit)
  692. (global-git-commit-mode 1))
  693. (with-eval-after-load 'git-commit
  694. (add-hook 'git-commit-setup-hook
  695. 'turn-off-auto-fill t))
  696. (autoload-eval-lazily 'sl)
  697. (with-eval-after-load 'rst
  698. (defvar rst-mode-map)
  699. (define-key rst-mode-map (kbd "C-m") 'newline-and-indent))
  700. (with-eval-after-load 'jdee
  701. (add-hook 'jdee-mode-hook
  702. (lambda ()
  703. (make-local-variable 'global-mode-string)
  704. (add-to-list 'global-mode-string
  705. mode-line-position))))
  706. ;; Cannot enable error thrown. Why???
  707. ;; https://github.com/m0smith/malabar-mode#Installation
  708. ;; (when (autoload-eval-lazily 'malabar-mode)
  709. ;; (add-to-list 'load-path
  710. ;; (expand-file-name (concat user-emacs-directory "/cedet")))
  711. ;; (safe-require-or-eval 'cedet-devel-load)
  712. ;; (call-after-init 'activate-malabar-mode))
  713. (with-eval-after-load 'make-mode
  714. (defvar makefile-mode-map (make-sparse-keymap))
  715. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  716. ;; this functions is set in write-file-functions, i cannot find any
  717. ;; good way to remove this.
  718. (fset 'makefile-warn-suspicious-lines 'ignore))
  719. (with-eval-after-load 'verilog-mode
  720. (defvar verilog-mode-map (make-sparse-keymap))
  721. (define-key verilog-mode-map ";" 'self-insert-command))
  722. (setq diff-switches "-u")
  723. (with-eval-after-load 'diff-mode
  724. ;; (when (and (eq major-mode
  725. ;; 'diff-mode)
  726. ;; (not buffer-file-name))
  727. ;; ;; do not pass when major-mode is derived mode of diff-mode
  728. ;; (view-mode 1))
  729. (set-face-attribute 'diff-header nil
  730. :foreground nil
  731. :background nil
  732. :weight 'bold)
  733. (set-face-attribute 'diff-file-header nil
  734. :foreground nil
  735. :background nil
  736. :weight 'bold)
  737. (set-face-foreground 'diff-index "blue")
  738. (set-face-attribute 'diff-hunk-header nil
  739. :foreground "cyan"
  740. :weight 'normal)
  741. (set-face-attribute 'diff-context nil
  742. ;; :foreground "white"
  743. :foreground nil
  744. :weight 'normal)
  745. (set-face-foreground 'diff-removed "red")
  746. (set-face-foreground 'diff-added "green")
  747. (set-face-background 'diff-removed nil)
  748. (set-face-background 'diff-added nil)
  749. (set-face-attribute 'diff-changed nil
  750. :foreground "magenta"
  751. :weight 'normal)
  752. (set-face-attribute 'diff-refine-changed nil
  753. :foreground nil
  754. :background nil
  755. :weight 'bold
  756. :inverse-video t)
  757. ;; Annoying !
  758. ;;(diff-auto-refine-mode)
  759. )
  760. ;; (ffap-bindings)
  761. (set-variable 'browse-url-browser-function
  762. 'eww-browse-url)
  763. (set-variable 'sh-here-document-word "__EOC__")
  764. (when (autoload-eval-lazily 'adoc-mode
  765. nil
  766. (defvar adoc-mode-map (make-sparse-keymap))
  767. (define-key adoc-mode-map (kbd "C-m") 'newline))
  768. (setq auto-mode-alist
  769. `(("\\.adoc\\'" . adoc-mode)
  770. ("\\.asciidoc\\'" . adoc-mode)
  771. ,@auto-mode-alist)))
  772. (with-eval-after-load 'markup-faces
  773. ;; Is this too match ?
  774. (set-face-foreground 'markup-meta-face
  775. "color-245")
  776. (set-face-foreground 'markup-meta-hide-face
  777. "color-245")
  778. )
  779. ;; TODO: check if this is required
  780. (when (autoload-eval-lazily 'groovy-mode nil
  781. (defvar groovy-mode-map (make-sparse-keymap))
  782. (define-key groovy-mode-map "(" 'self-insert-command)
  783. (define-key groovy-mode-map ")" 'self-insert-command)
  784. (define-key groovy-mode-map (kbd "C-m") 'newline-and-indent)
  785. )
  786. (add-to-list 'auto-mode-alist
  787. '("build\\.gradle\\'" . groovy-mode)))
  788. (with-eval-after-load 'yaml-mode
  789. (defvar yaml-mode-map (make-sparse-keymap))
  790. (define-key yaml-mode-map (kbd "C-m") 'newline))
  791. (with-eval-after-load 'html-mode
  792. (defvar html-mode-map (make-sparse-keymap))
  793. (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
  794. (with-eval-after-load 'text-mode
  795. (define-key text-mode-map (kbd "C-m") 'newline))
  796. (with-eval-after-load 'info
  797. (defvar Info-directory-list nil)
  798. (add-to-list 'Info-directory-list
  799. (expand-file-name "~/.brew/share/info")))
  800. (with-eval-after-load 'apropos
  801. (defvar apropos-mode-map (make-sparse-keymap))
  802. (define-key apropos-mode-map "n" 'next-line)
  803. (define-key apropos-mode-map "p" 'previous-line))
  804. ;; `isearch' library does not call `provide' so cannot use with-eval-after-load
  805. ;; (define-key isearch-mode-map
  806. ;; (kbd "C-j") 'isearch-other-control-char)
  807. ;; (define-key isearch-mode-map
  808. ;; (kbd "C-k") 'isearch-other-control-char)
  809. ;; (define-key isearch-mode-map
  810. ;; (kbd "C-h") 'isearch-other-control-char)
  811. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  812. (define-key isearch-mode-map (kbd "M-r")
  813. 'isearch-query-replace-regexp)
  814. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  815. (setq lazy-highlight-cleanup nil)
  816. ;; face for isearch highlighing
  817. (set-face-attribute 'lazy-highlight
  818. nil
  819. :foreground `unspecified
  820. :background `unspecified
  821. :underline t
  822. ;; :weight `bold
  823. )
  824. (add-hook 'outline-mode-hook
  825. (lambda ()
  826. (when (string-match "\\.md\\'" buffer-file-name)
  827. (set (make-local-variable 'outline-regexp) "#+ "))))
  828. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  829. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  830. (when (autoload-eval-lazily 'markdown-mode
  831. '(markdown-mode gfm-mode)
  832. (defvar gfm-mode-map (make-sparse-keymap))
  833. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline))
  834. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  835. (set-variable 'markdown-command (or (executable-find "markdown")
  836. (executable-find "markdown.pl")
  837. ""))
  838. (add-hook 'markdown-mode-hook
  839. (lambda ()
  840. (outline-minor-mode 1)
  841. (flyspell-mode)
  842. (set (make-local-variable 'comment-start) ";")))
  843. )
  844. ;; c-mode
  845. ;; http://www.emacswiki.org/emacs/IndentingC
  846. ;; http://en.wikipedia.org/wiki/Indent_style
  847. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  848. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  849. (with-eval-after-load 'cc-vars
  850. (defvar c-default-style nil)
  851. (add-to-list 'c-default-style
  852. '(c-mode . "k&r"))
  853. (add-to-list 'c-default-style
  854. '(c++-mode . "k&r")))
  855. (autoload-eval-lazily 'js2-mode nil
  856. ;; currently do not use js2-mode
  857. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  858. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  859. ;; (defvar js2-mode-map (make-sparse-keymap))
  860. ;; (define-key js2-mode-map (kbd "C-m") (lambda ()
  861. ;; (interactive)
  862. ;; (js2-enter-key)
  863. ;; (indent-for-tab-command)))
  864. ;; (add-hook (kill-local-variable 'before-save-hook)
  865. ;; 'js2-before-save)
  866. ;; (add-hook 'before-save-hook
  867. ;; 'my-indent-buffer
  868. ;; nil
  869. ;; t)
  870. )
  871. (add-to-list 'interpreter-mode-alist
  872. '("node" . js-mode))
  873. (when (autoload-eval-lazily 'flymake-jslint
  874. '(flymake-jslint-load))
  875. (autoload-eval-lazily 'js nil
  876. (add-hook 'js-mode-hook
  877. 'flymake-jslint-load)))
  878. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  879. (with-eval-after-load 'uniquify
  880. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  881. (setq uniquify-ignore-buffers-re "*[^*]+*")
  882. (setq uniquify-min-dir-content 1))
  883. (with-eval-after-load 'view
  884. (defvar view-mode-map (make-sparse-keymap))
  885. (define-key view-mode-map "j" 'scroll-up-line)
  886. (define-key view-mode-map "k" 'scroll-down-line)
  887. (define-key view-mode-map "v" 'toggle-read-only)
  888. (define-key view-mode-map "q" 'bury-buffer)
  889. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  890. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  891. ;; (define-key view-mode-map
  892. ;; "n" 'nonincremental-repeat-search-forward)
  893. ;; (define-key view-mode-map
  894. ;; "N" 'nonincremental-repeat-search-backward)
  895. (define-key view-mode-map "/" 'isearch-forward-regexp)
  896. (define-key view-mode-map "?" 'isearch-backward-regexp)
  897. (define-key view-mode-map "n" 'isearch-repeat-forward)
  898. (define-key view-mode-map "N" 'isearch-repeat-backward)
  899. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
  900. (global-set-key "\M-r" 'view-mode)
  901. ;; (setq view-read-only t)
  902. (with-eval-after-load 'term
  903. (defvar term-raw-map (make-sparse-keymap))
  904. (define-key term-raw-map (kbd "C-x")
  905. (lookup-key (current-global-map)
  906. (kbd "C-x"))))
  907. (add-hook 'term-mode-hook
  908. (lambda ()
  909. ;; Stop current line highlighting
  910. (set (make-local-variable (defvar hl-line-range-function))
  911. (lambda () '(0 . 0)))
  912. (set (make-local-variable 'scroll-margin)
  913. 0)))
  914. (add-hook 'Man-mode-hook
  915. (lambda ()
  916. (view-mode 1)
  917. (setq truncate-lines nil)))
  918. (set-variable 'Man-notify-method (if window-system
  919. 'newframe
  920. 'aggressive))
  921. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  922. "woman_cache.el")))
  923. ;; not work because man.el will be loaded when man called
  924. (defalias 'man 'woman)
  925. (add-to-list 'auto-mode-alist
  926. '("tox\\.ini\\'" . conf-unix-mode))
  927. (when (autoload-eval-lazily 'toml-mode)
  928. (add-to-list 'auto-mode-alist
  929. '("/Pipfile\\'" . toml-mode)))
  930. (when (autoload-eval-lazily 'json-mode)
  931. (add-to-list 'auto-mode-alist
  932. '("/Pipfile\\.lock\\'" . json-mode)))
  933. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  934. ;; buffer switching
  935. (defvar bs-configurations)
  936. (when (autoload-eval-lazily 'bs '(bs-show)
  937. (add-to-list 'bs-configurations
  938. '("specials" "^\\*" nil ".*" nil nil))
  939. (add-to-list 'bs-configurations
  940. '("files-and-specials" "^\\*" buffer-file-name ".*" nil nil))
  941. (defvar bs-mode-map)
  942. (defvar bs-current-configuration)
  943. (define-key bs-mode-map (kbd "t")
  944. ;; TODO: fix toggle feature
  945. (lambda ()
  946. (interactive)
  947. (if (string= "specials"
  948. bs-current-configuration)
  949. (bs-set-configuration "files")
  950. (bs-set-configuration "specials"))
  951. (bs-refresh)
  952. (bs-message-without-log "%s"
  953. (bs--current-config-message))))
  954. ;; (setq bs-configurations (list
  955. ;; '("processes" nil get-buffer-process ".*" nil nil)
  956. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  957. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  958. )
  959. (defalias 'list-buffers 'bs-show)
  960. (set-variable 'bs-default-configuration "files-and-specials")
  961. (set-variable 'bs-default-sort-name "by nothing")
  962. (add-hook 'bs-mode-hook
  963. (lambda ()
  964. (set (make-local-variable 'scroll-margin) 0))))
  965. ;;(iswitchb-mode 1)
  966. (icomplete-mode)
  967. (defun iswitchb-buffer-display-other-window ()
  968. "Do iswitchb in other window."
  969. (interactive)
  970. (let ((iswitchb-default-method 'display))
  971. (call-interactively 'iswitchb-buffer)))
  972. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  973. ;; vc
  974. (set-variable 'vc-handled-backends '())
  975. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  976. ;; recentf-mode
  977. (set-variable 'recentf-save-file (expand-file-name (concat user-emacs-directory
  978. "recentf")))
  979. (set-variable 'recentf-max-menu-items 20)
  980. (set-variable 'recentf-max-saved-items 30)
  981. (set-variable 'recentf-show-file-shortcuts-flag nil)
  982. (when (safe-require-or-eval 'recentf)
  983. (add-to-list 'recentf-exclude
  984. (regexp-quote recentf-save-file))
  985. (add-to-list 'recentf-exclude
  986. (regexp-quote (expand-file-name user-emacs-directory)))
  987. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  988. (remove-hook 'find-file-hook
  989. 'recentf-track-opened-file)
  990. (defun my-recentf-load-track-save-list ()
  991. "Load current recentf list from file, track current visiting file, then save
  992. the list."
  993. (recentf-load-list)
  994. (recentf-track-opened-file)
  995. (recentf-save-list))
  996. (add-hook 'find-file-hook
  997. 'my-recentf-load-track-save-list)
  998. (add-hook 'kill-emacs-hook
  999. 'recentf-load-list)
  1000. ;;(run-with-idle-timer 5 t 'recentf-save-list)
  1001. ;; (add-hook 'find-file-hook
  1002. ;; (lambda ()
  1003. ;; (recentf-add-file default-directory)))
  1004. (and (autoload-eval-lazily 'recentf-show)
  1005. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1006. (add-hook 'recentf-show-before-listing-hook
  1007. 'recentf-load-list))
  1008. (recentf-mode 1)
  1009. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1010. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1011. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1012. (define-key recentf-dialog-mode-map "n" 'next-line)
  1013. (add-hook 'recentf-dialog-mode-hook
  1014. (lambda ()
  1015. ;; (recentf-save-list)
  1016. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1017. ;; 'my-recentf-cd-and-find-file)
  1018. (cd "~/"))))
  1019. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1020. ;; dired
  1021. (defun my-dired-echo-file-head (arg)
  1022. "Echo head of current file.
  1023. ARG is num to show, or defaults to 7."
  1024. (interactive "P")
  1025. (let ((f (dired-get-filename)))
  1026. (message "%s"
  1027. (with-temp-buffer
  1028. (insert-file-contents f)
  1029. (buffer-substring-no-properties
  1030. (point-min)
  1031. (progn (goto-char (point-min))
  1032. (forward-line (1- (if arg
  1033. (prefix-numeric-value arg)
  1034. 7)))
  1035. (point-at-eol)))))))
  1036. (defun my-dired-diff ()
  1037. "Show diff of marked file and file of current line."
  1038. (interactive)
  1039. (let ((files (dired-get-marked-files nil nil nil t)))
  1040. (if (eq (car files)
  1041. t)
  1042. (diff (cadr files) (dired-get-filename))
  1043. (message "One file must be marked!"))))
  1044. (defun dired-get-file-info ()
  1045. "Print information of current line file."
  1046. (interactive)
  1047. (let ((f (shell-quote-argument (dired-get-filename t))))
  1048. (if (file-directory-p f)
  1049. (progn
  1050. (message "Calculating disk usage...")
  1051. (shell-command (concat "du -hsD "
  1052. f)))
  1053. (shell-command (concat "file "
  1054. f)))))
  1055. (defun my-dired-scroll-up ()
  1056. "Scroll up."
  1057. (interactive)
  1058. (my-dired-previous-line (- (window-height) 1)))
  1059. (defun my-dired-scroll-down ()
  1060. "Scroll down."
  1061. (interactive)
  1062. (my-dired-next-line (- (window-height) 1)))
  1063. ;; (defun my-dired-forward-line (arg)
  1064. ;; ""
  1065. ;; (interactive "p"))
  1066. (defun my-dired-previous-line (arg)
  1067. "Move ARG lines up."
  1068. (interactive "p")
  1069. (if (> arg 0)
  1070. (progn
  1071. (if (eq (line-number-at-pos)
  1072. 1)
  1073. (goto-char (point-max))
  1074. (forward-line -1))
  1075. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1076. (dired-get-subdir))
  1077. (- arg 1)
  1078. arg)))
  1079. (dired-move-to-filename)))
  1080. (defun my-dired-next-line (arg)
  1081. "Move ARG lines down."
  1082. (interactive "p")
  1083. (if (> arg 0)
  1084. (progn
  1085. (if (eq (point)
  1086. (point-max))
  1087. (goto-char (point-min))
  1088. (forward-line 1))
  1089. (my-dired-next-line (if (or (dired-get-filename nil t)
  1090. (dired-get-subdir))
  1091. (- arg 1)
  1092. arg)))
  1093. (dired-move-to-filename)))
  1094. (defun my-dired-tramp-open (host)
  1095. "Open HOST home directory."
  1096. (interactive "sHostname: ")
  1097. (find-file (format "/scp:%s:" host)))
  1098. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1099. (if (eq window-system 'mac)
  1100. (setq dired-listing-switches "-lhF")
  1101. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1102. )
  1103. (setq dired-listing-switches "-lhF")
  1104. (put 'dired-find-alternate-file 'disabled nil)
  1105. ;; when using dired-find-alternate-file
  1106. ;; reuse current dired buffer for the file to open
  1107. (set-variable 'dired-ls-F-marks-symlinks t)
  1108. (set-variable 'ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1109. (set-variable 'ls-lisp-dirs-first t)
  1110. (set-variable 'ls-lisp-use-localized-time-format t)
  1111. (set-variable 'ls-lisp-format-time-list
  1112. '("%Y-%m-%d %H:%M"
  1113. "%Y-%m-%d "))
  1114. (set-variable 'dired-dwim-target t)
  1115. (set-variable 'dired-isearch-filenames t)
  1116. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  1117. (set-variable 'dired-hide-details-hide-information-lines nil)
  1118. (set-variable 'dired-deletion-confirmer 'y-or-n-p)
  1119. (set-variable 'dired-recursive-deletes 'always)
  1120. ;; (add-hook 'dired-after-readin-hook
  1121. ;; 'my-replace-nasi-none)
  1122. (with-eval-after-load 'dired
  1123. (safe-require-or-eval 'ls-lisp)
  1124. (defvar dired-mode-map (make-sparse-keymap))
  1125. (define-key dired-mode-map "i" 'dired-get-file-info)
  1126. (define-key dired-mode-map "f" 'find-file)
  1127. (define-key dired-mode-map "!" 'shell-command)
  1128. (define-key dired-mode-map "&" 'async-shell-command)
  1129. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1130. (define-key dired-mode-map "=" 'my-dired-diff)
  1131. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1132. (define-key dired-mode-map "b" 'gtkbm)
  1133. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1134. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1135. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1136. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1137. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1138. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1139. (substitute-key-definition 'dired-next-line
  1140. 'my-dired-next-line
  1141. dired-mode-map)
  1142. (substitute-key-definition 'dired-previous-line
  1143. 'my-dired-previous-line
  1144. dired-mode-map)
  1145. ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
  1146. ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
  1147. ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
  1148. ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
  1149. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1150. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1151. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1152. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1153. (add-hook 'dired-mode-hook
  1154. (lambda ()
  1155. (when (fboundp 'dired-hide-details-mode)
  1156. (dired-hide-details-mode t)
  1157. (local-set-key "l" 'dired-hide-details-mode))
  1158. (let ((file "._Icon\015"))
  1159. (when nil
  1160. '(file-readable-p file)
  1161. (delete-file file)))))
  1162. (when (autoload-eval-lazily 'pack '(dired-do-pack-or-unpack pack-pack))
  1163. (with-eval-after-load 'dired
  1164. (define-key dired-mode-map "P" 'pack-dired-dwim)))
  1165. (when (autoload-eval-lazily 'dired-list-all-mode)
  1166. (setq dired-listing-switches "-lhF")
  1167. (with-eval-after-load 'dired
  1168. (define-key dired-mode-map "a" 'dired-list-all-mode))))
  1169. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1170. ;; misc funcs
  1171. (defalias 'qcalc 'quick-calc)
  1172. (defun memo (&optional dir)
  1173. "Open memo.txt in DIR."
  1174. (interactive)
  1175. (pop-to-buffer (find-file-noselect (concat (if dir
  1176. (file-name-as-directory dir)
  1177. "")
  1178. "memo.txt"))))
  1179. (defvar my-rgrep-alist
  1180. `(
  1181. ;; git grep
  1182. ("gitgrep"
  1183. (eq 0
  1184. (shell-command "git rev-parse --git-dir"))
  1185. "git --no-pager -c color.grep=false grep -nH -e ")
  1186. ;; ripgrep
  1187. ("rg"
  1188. (executable-find "rg")
  1189. "rg --no-heading --color=never --smart-case ")
  1190. ;; sift
  1191. ("sift"
  1192. (executable-find "sift")
  1193. ("sift --no-color --binary-skip --filename --line-number --git --smart-case "))
  1194. ;; the silver searcher
  1195. ("ag"
  1196. (executable-find "ag")
  1197. "ag --nocolor --nogroup --nopager --filename ")
  1198. ;; ack
  1199. ("ack"
  1200. (executable-find "ack")
  1201. "ack --nocolor --nogroup --nopager --with-filename ")
  1202. ;; gnu global
  1203. ("global"
  1204. (and (require 'gtags nil t)
  1205. (executable-find "global")
  1206. (gtags-get-rootpath))
  1207. "global --result grep ")
  1208. ;; grep
  1209. ("grep"
  1210. t
  1211. ,(concat "find . "
  1212. "-path '*/.git' -prune -o "
  1213. "-path '*/.svn' -prune -o "
  1214. "-type f -print0 | "
  1215. "xargs -0 grep -nH -e "))
  1216. )
  1217. "Alist of rgrep command.
  1218. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  1219. condition to choose COMMAND when evaluated.")
  1220. (defvar my-rgrep-default nil
  1221. "Default command name for my-rgrep.")
  1222. (defun my-rgrep-grep-command (&optional name alist)
  1223. "Return recursive grep command for current directory or nil.
  1224. If NAME is given, use that without testing.
  1225. Commands are searched from ALIST."
  1226. (if alist
  1227. (if name
  1228. ;; if name is given search that from alist and return the command
  1229. (nth 2 (assoc name
  1230. alist))
  1231. ;; if name is not given try test in 1th elem
  1232. (let ((car (car alist))
  1233. (cdr (cdr alist)))
  1234. (if (eval (nth 1 car))
  1235. ;; if the condition is true return the command
  1236. (nth 2 car)
  1237. ;; try next one
  1238. (and cdr
  1239. (my-rgrep-grep-command name cdr)))))
  1240. ;; if alist is not given set default value
  1241. (my-rgrep-grep-command name my-rgrep-alist)))
  1242. (defun my-rgrep (command-args)
  1243. "My recursive grep. Run COMMAND-ARGS.
  1244. If prefix argument is given use current symbol as default search target."
  1245. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  1246. nil)))
  1247. (if cmd
  1248. (list (read-shell-command "grep command: "
  1249. (concat cmd
  1250. (if current-prefix-arg
  1251. (thing-at-point 'symbol t)
  1252. ""))
  1253. 'grep-find-history))
  1254. (error "My-Rgrep: Command for rgrep not found")
  1255. )))
  1256. (compilation-start command-args
  1257. 'grep-mode))
  1258. (defmacro define-my-rgrep (name)
  1259. "Define rgrep for NAME."
  1260. `(defun ,(intern (concat "my-rgrep-"
  1261. name)) ()
  1262. ,(format "My recursive grep by %s."
  1263. name)
  1264. (interactive)
  1265. (let ((my-rgrep-default ,name))
  1266. (if (called-interactively-p 'any)
  1267. (call-interactively 'my-rgrep)
  1268. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  1269. )
  1270. (define-my-rgrep "ack")
  1271. (define-my-rgrep "ag")
  1272. (define-my-rgrep "rg")
  1273. (define-my-rgrep "sift")
  1274. (define-my-rgrep "gitgrep")
  1275. (define-my-rgrep "grep")
  1276. (define-my-rgrep "global")
  1277. (define-key ctl-x-map "s" 'my-rgrep)
  1278. (defalias 'make 'compile)
  1279. (define-key ctl-x-map "c" 'compile)
  1280. ;;;;;;;;;;;;;;;;;;;;;;;
  1281. ;; adoc-simple-mode
  1282. (when (safe-require-or-eval 'adoc-mode)
  1283. (defvar adoc-simple-font-lock-keywords
  1284. nil)
  1285. (define-derived-mode adoc-simple-mode adoc-mode
  1286. "Adoc-Simple"
  1287. "Major mode for editing AsciiDoc text files.
  1288. This mode is a simplified version of `adoc-mode'."
  1289. '(set (make-local-variable 'font-lock-defaults)
  1290. '(adoc-simple-font-lock-keywords
  1291. nil nil nil nil
  1292. (font-lock-multiline . t)
  1293. (font-lock-mark-block-function . adoc-font-lock-mark-block-function))))
  1294. (add-to-list 'auto-mode-alist
  1295. '("\\.adoc\\'" . adoc-simple-mode)))
  1296. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1297. ;; awk-preview
  1298. (defgroup awk-preview nil
  1299. "Awk previewer."
  1300. :tag "Awk Preview"
  1301. :prefix "awk-preview-"
  1302. :group 'tools)
  1303. (defcustom awk-preview-program
  1304. (or (executable-find "gawk")
  1305. (executable-find "awk")
  1306. "awk")
  1307. "Awk program to execute."
  1308. :type 'string
  1309. :group 'awk-preview)
  1310. (defcustom awk-preview-switches
  1311. '("--sandbox" "--" "{print}")
  1312. "String of awk options appended when running awk preview."
  1313. :type '(repeat string)
  1314. :group 'awk-preview)
  1315. (defun awk-preview--invoke (start end output)
  1316. "Execute awk process and get result."
  1317. (let ((proc (apply 'start-process
  1318. "awk-preview"
  1319. output
  1320. awk-preview-program
  1321. awk-preview-switches)))
  1322. (message "%S" proc)
  1323. (process-send-region proc start end)
  1324. (process-send-eof proc)
  1325. (accept-process-output proc)
  1326. )
  1327. output)
  1328. (defun awk-preview (start end)
  1329. "Run awk and preview result."
  1330. (interactive "r")
  1331. (let ((output (with-current-buffer (get-buffer-create "*awk-preview output*")
  1332. (erase-buffer)
  1333. (current-buffer))))
  1334. (awk-preview--invoke start end output)
  1335. (message "awk-preview: %s" (with-current-buffer output
  1336. (buffer-substring-no-properties (point-min) (point-max))))
  1337. ))
  1338. (defun my-file-head (filename &optional n)
  1339. "Return list of first N lines of file FILENAME."
  1340. (let ((num (or n 10))
  1341. (size 100)
  1342. (beg 0)
  1343. (end 0)
  1344. (result '()))
  1345. (with-temp-buffer
  1346. (while (<= (count-lines (point-min)
  1347. (point-max))
  1348. num)
  1349. (setq end (+ beg size))
  1350. (insert-file-contents filename
  1351. nil
  1352. beg
  1353. end)
  1354. (setq beg end))
  1355. (goto-char (point-min))
  1356. (while (< (length result) num)
  1357. (let ((start (point)))
  1358. (forward-line 1)
  1359. (setq result
  1360. `(,@result ,(buffer-substring-no-properties start
  1361. (point))))))
  1362. result)))
  1363. ;; (apply 'concat (car (my-file-head "./emacs.el"))
  1364. ;; Local Variables:
  1365. ;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
  1366. ;; flycheck-checker: emacs-lisp
  1367. ;; End:
  1368. ;;; emancs.el ends here