Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

emacs.el 62 KiB

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