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 53 KiB

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