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

emacs.el 54 KiB

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