No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

emacs.el 53 KiB

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