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

emacs.el 66 KiB

12 years ago
13 years ago
12 years ago
13 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
12 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
11 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
13 years ago
12 years ago
11 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
13 years ago
13 years ago
12 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
13 years ago
13 years ago
12 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
13 years ago
13 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
13 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
12 years ago
13 years ago
12 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929
  1. ;; (and (file-readable-p "~/.dotfiles/emacs.el")
  2. ;; (load-file "~/.dotfiles/emacs.el"))
  3. ;; make directories
  4. (unless (file-directory-p (expand-file-name user-emacs-directory))
  5. (make-directory (expand-file-name user-emacs-directory)))
  6. (let ((d (expand-file-name (concat user-emacs-directory
  7. "lisp"))))
  8. (unless (file-directory-p d)
  9. (make-directory d))
  10. (add-to-list 'load-path d))
  11. (require 'cl nil t)
  12. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13. ;; download library from web
  14. (defun fetch-library (url &optional byte-compile-p force-download-p)
  15. "If library does not exist, download it from URL and locate it in
  16. \"~/emacs.d/lisp/\". Return nil if library unfound and failed to download,
  17. otherwise the path where the library installed."
  18. (let* ((dir (expand-file-name (concat user-emacs-directory "lisp/")))
  19. (lib (file-name-sans-extension (file-name-nondirectory url)))
  20. (lpath (concat dir lib ".el"))
  21. (locate-p (locate-library lib)))
  22. (if (or force-download-p (not locate-p))
  23. (if (progn (message "Downloading %s..."
  24. url)
  25. (download-file url
  26. lpath
  27. t))
  28. (progn (message "Downloading %s...done"
  29. url)
  30. (when (and byte-compile-p
  31. (require 'bytecomp nil t))
  32. (and (file-exists-p (byte-compile-dest-file lpath))
  33. (delete-file (byte-compile-dest-file lpath)))
  34. (byte-compile-file lpath)))
  35. (progn (and (file-writable-p lpath)
  36. (delete-file lpath))
  37. (message "Downloading %s...failed"
  38. url))))
  39. (locate-library lib)))
  40. (defun download-file (url path &optional ok-if-already-exists)
  41. "Download file from URL and output to PATH."
  42. (or
  43. (let ((curl (executable-find "curl")))
  44. (when curl
  45. (if (and (not ok-if-already-exists)
  46. (file-exists-p path))
  47. nil
  48. (and (eq 0
  49. (call-process curl
  50. nil
  51. nil
  52. nil
  53. "--output"
  54. path
  55. url
  56. ))
  57. path))))
  58. (ignore-errors
  59. (require 'url)
  60. (url-copy-file url
  61. path
  62. ok-if-already-exists)
  63. path)))
  64. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  65. ;; autoload
  66. (defmacro lazy-load-eval (feature &optional functions &rest body)
  67. "Define each FUNCTIONS to autoload from FEATURE.
  68. FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
  69. the function same as FEATURE is defined as autoloaded function. BODY is passed
  70. to `eval-after-load'.
  71. When this macro is evaluated, this returns the path to library if FEATURE
  72. found, otherwise returns nil."
  73. (let* ((libname (symbol-name (eval feature)))
  74. (libpath (locate-library libname)))
  75. (and libpath
  76. `(progn
  77. ,@(mapcar (lambda (f)
  78. (unless (fboundp f)
  79. `(progn
  80. (message "Autoloaded function `%S' defined (%s)"
  81. (quote ,f)
  82. ,libpath)
  83. (autoload (quote ,f)
  84. ,libname
  85. ,(concat "Autoloaded function defined in \""
  86. libpath
  87. "\".")
  88. t))))
  89. (or (eval functions)
  90. `(,(eval feature))))
  91. (eval-after-load ,feature
  92. (quote (progn
  93. ,@body)))
  94. ,libpath))))
  95. (put 'lazy-load-eval 'lisp-indent-function 2)
  96. (when (lazy-load-eval 'tetris nil
  97. (message "Tetris loaded!"))
  98. (message "Tetris found!"))
  99. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  100. ;; start and quit
  101. (setq inhibit-startup-message t)
  102. (setq confirm-kill-emacs 'y-or-n-p)
  103. (setq gc-cons-threshold (* 1024 1024 4))
  104. (when window-system
  105. (add-to-list 'default-frame-alist '(cursor-type . box))
  106. (add-to-list 'default-frame-alist '(background-color . "white"))
  107. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  108. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  109. ;; does not work?
  110. )
  111. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  112. (if window-system (menu-bar-mode 1) (menu-bar-mode 0))
  113. (and (fboundp 'tool-bar-mode)
  114. (tool-bar-mode 0))
  115. (and (fboundp 'set-scroll-bar-mode)
  116. (set-scroll-bar-mode nil))
  117. (add-hook 'kill-emacs-hook
  118. ;; load init file when terminating emacs to ensure file is not broken
  119. 'reload-init-file)
  120. (add-hook 'after-init-hook
  121. (lambda ()
  122. (message "%s was taken to initialize emacs." (emacs-init-time))
  123. (switch-to-buffer "*Messages*")
  124. ))
  125. (cd ".") ; when using windows use / instead of \ in `default-directory'
  126. ;; locale
  127. (set-language-environment "Japanese")
  128. (set-default-coding-systems 'utf-8-unix)
  129. (prefer-coding-system 'utf-8-unix)
  130. (setq system-time-locale "C")
  131. ;; my prefix map
  132. (define-prefix-command 'my-prefix-map)
  133. (define-key ctl-x-map (kbd "C-x") 'my-prefix-map)
  134. (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  135. (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  136. ;; (comint-show-maximum-output)
  137. ;; kill scratch
  138. (add-hook 'after-init-hook
  139. (lambda ()
  140. (kill-buffer "*scratch*")))
  141. ;; modifier keys
  142. ;; (setq mac-option-modifier 'control)
  143. (setq w32-apps-modifier 'meta)
  144. ;; display
  145. (setq redisplay-dont-pause t)
  146. (setq visible-bell t)
  147. (setq ring-bell-function 'ignore)
  148. (mouse-avoidance-mode 'banish)
  149. (and window-system
  150. (fetch-library
  151. "https://raw.github.com/10sr/emacs-lisp/master/save-window-size.el"
  152. t)
  153. (require 'save-window-size nil t))
  154. (defun reload-init-file ()
  155. "Reload emacs init file."
  156. (interactive)
  157. (when (file-readable-p user-init-file)
  158. (load-file user-init-file)))
  159. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  160. ;; global keys
  161. (global-set-key (kbd "<up>") (lambda() (interactive) (scroll-down 1)))
  162. (global-set-key (kbd "<down>") (lambda() (interactive) (scroll-up 1)))
  163. (global-set-key (kbd "<left>") 'scroll-down)
  164. (global-set-key (kbd "<right>") 'scroll-up)
  165. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  166. (global-set-key (kbd "C-\\") help-map)
  167. (define-key ctl-x-map (kbd "DEL") help-map)
  168. (define-key ctl-x-map (kbd "C-h") help-map)
  169. (define-key help-map "a" 'apropos)
  170. ;; disable annoying keys
  171. (global-set-key [prior] 'ignore)
  172. (global-set-key (kbd "<next>") 'ignore)
  173. (global-set-key [menu] 'ignore)
  174. (global-set-key [down-mouse-1] 'ignore)
  175. (global-set-key [down-mouse-2] 'ignore)
  176. (global-set-key [down-mouse-3] 'ignore)
  177. (global-set-key [mouse-1] 'ignore)
  178. (global-set-key [mouse-2] 'ignore)
  179. (global-set-key [mouse-3] 'ignore)
  180. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  181. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  182. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  183. ;; title and mode-line
  184. (when (fetch-library
  185. "https://raw.github.com/10sr/emacs-lisp/master/terminal-title.el"
  186. t)
  187. (require 'terminal-title nil t))
  188. (setq eol-mnemonic-dos "\\r\\n")
  189. (setq eol-mnemonic-mac "\\r")
  190. (setq eol-mnemonic-unix "\\n")
  191. (which-function-mode 0)
  192. (line-number-mode 0)
  193. (column-number-mode 0)
  194. (size-indication-mode 0)
  195. (setq mode-line-position
  196. '(:eval (format "L%%l/%d,C%%c"
  197. (count-lines (point-max)
  198. (point-min)))))
  199. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  200. ;; display date
  201. (add-hook 'after-init-hook
  202. (lambda ()
  203. (when display-time-mode
  204. (display-time-update))
  205. ))
  206. (setq display-time-interval 29)
  207. (setq display-time-day-and-date t)
  208. (setq display-time-format "%a, %d %b %Y %T")
  209. (if window-system
  210. (display-time-mode 0)
  211. (display-time-mode 1))
  212. ;; ;; current directory
  213. ;; (let ((ls (member 'mode-line-buffer-identification
  214. ;; mode-line-format)))
  215. ;; (setcdr ls
  216. ;; (cons '(:eval (concat " ("
  217. ;; (abbreviate-file-name default-directory)
  218. ;; ")"))
  219. ;; (cdr ls))))
  220. ;; ;; display last modified time
  221. ;; (let ((ls (member 'mode-line-buffer-identification
  222. ;; mode-line-format)))
  223. ;; (setcdr ls
  224. ;; (cons '(:eval (concat " "
  225. ;; my-buffer-file-last-modified-time))
  226. ;; (cdr ls))))
  227. (defun buffer-list-not-start-with-space ()
  228. (let ((bl (buffer-list))
  229. b nbl)
  230. (while bl
  231. (setq b (pop bl))
  232. (unless (string-equal " "
  233. (substring (buffer-name b)
  234. 0
  235. 1))
  236. (add-to-list 'nbl b)))
  237. nbl))
  238. ;; http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/
  239. ;; (add-to-list 'minor-mode-alist
  240. ;; '(global-whitespace-mode ""))
  241. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  242. ;; show current info
  243. (defun my-message-current-info ()
  244. ""
  245. (interactive)
  246. (message "%s@%s:%s"
  247. user-login-name
  248. system-name
  249. (abbreviate-file-name default-directory)))
  250. ;; (run-with-idle-timer 3
  251. ;; t
  252. ;; 'my-message-current-info)
  253. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  254. ;; minibuffer
  255. (setq insert-default-directory t)
  256. (setq completion-ignore-case t
  257. read-file-name-completion-ignore-case t
  258. read-buffer-completion-ignore-case t)
  259. (setq resize-mini-windows t)
  260. (temp-buffer-resize-mode 1)
  261. (savehist-mode 1)
  262. (fset 'yes-or-no-p 'y-or-n-p)
  263. ;; complete symbol when `eval'
  264. (define-key read-expression-map (kbd "TAB") 'lisp-complete-symbol)
  265. (define-key minibuffer-local-map (kbd "C-u")
  266. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  267. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  268. ;; letters, font-lock mode and fonts
  269. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  270. (and (or (eq system-type 'Darwin)
  271. (eq system-type 'darwin))
  272. (fboundp 'mac-set-input-method-parameter)
  273. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  274. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  275. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  276. (boundp 'input-method-inactivate-hook))
  277. (add-hook 'input-method-activate-hook
  278. (lambda () (set-cursor-color "red")))
  279. (add-hook 'input-method-inactivate-hook
  280. (lambda () (set-cursor-color "black"))))
  281. (show-paren-mode 1)
  282. (setq show-paren-delay 0.5
  283. show-paren-style 'parenthesis) ; mixed is hard to read
  284. (set-face-background 'show-paren-match
  285. (face-foreground 'default))
  286. (set-face-inverse-video-p 'show-paren-match
  287. t)
  288. (transient-mark-mode 1)
  289. (global-font-lock-mode 1)
  290. (setq font-lock-global-modes
  291. '(not
  292. help-mode
  293. eshell-mode
  294. term-mode
  295. Man-mode))
  296. ;; (standard-display-ascii ?\n "$\n")
  297. (defvar my-eol-face
  298. '(("\n" . (0 font-lock-comment-face t nil)))
  299. )
  300. (defvar my-tab-face
  301. '(("\t" . '(0 highlight t nil))))
  302. (defvar my-jspace-face
  303. '(("\u3000" . '(0 highlight t nil))))
  304. (add-hook 'font-lock-mode-hook
  305. (lambda ()
  306. ;; (font-lock-add-keywords nil my-eol-face)
  307. (font-lock-add-keywords nil my-jspace-face)
  308. ))
  309. (when (require 'whitespace nil t)
  310. (setq whitespace-style '(face
  311. trailing ; trailing blanks
  312. newline ; newlines
  313. newline-mark ; use display table for newline
  314. tab-mark
  315. empty ; empty lines at beg or end of buffer
  316. lines-tail ; lines over 80
  317. ))
  318. ;; (setq whitespace-newline 'font-lock-comment-face)
  319. (add-to-list 'whitespace-display-mappings
  320. `(newline-mark ?\n ,(vconcat "$\n")))
  321. (add-to-list 'whitespace-display-mappings ; not work
  322. `(tab-mark ?\t ,(vconcat "^I\t")))
  323. (global-whitespace-mode t)
  324. (when (eq (display-color-cells)
  325. 256)
  326. (set-face-foreground 'whitespace-newline "brightblack")))
  327. (and nil
  328. (fetch-library
  329. "http://www.emacswiki.org/emacs/download/fill-column-indicator.el"
  330. t)
  331. (require 'fill-column-indicator nil t)
  332. (setq fill-column-indicator))
  333. ;; highlight current line
  334. ;; http://wiki.riywo.com/index.php?Meadow
  335. (defface my-hl-line
  336. '((((min-colors 256)
  337. (background dark))
  338. (:background "color-234"))
  339. (((min-colors 256)
  340. (background light))
  341. (:background "color-234"))
  342. (t
  343. (:underline "black")))
  344. "*Face used by hl-line.")
  345. (setq hl-line-face 'my-hl-line) ;; (setq hl-line-face nil)
  346. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  347. (setq hl-line-global-modes
  348. '(not
  349. term-mode))
  350. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  351. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  352. ;; fonts
  353. (defun my-set-ascii-and-jp-font (list)
  354. "font configuration"
  355. (let ((fspec1 (if (> emacs-major-version 22)
  356. ;; font spec is available in emacs23 and later
  357. (font-spec :family (nth 2 list) :size (nth 3 list))
  358. (cons (nth 2 list) "jisx0208.*")))
  359. (fspec2 (if (> emacs-major-version 22)
  360. (font-spec :family (nth 2 list) :size (nth 3 list))
  361. (cons (nth 2 list) "jisx0201.*"))))
  362. (set-face-attribute 'default nil
  363. :family (nth 0 list)
  364. :height (nth 1 list))
  365. (set-fontset-font "fontset-default"
  366. 'japanese-jisx0208
  367. fspec1)
  368. (set-fontset-font "fontset-default"
  369. 'katakana-jisx0201
  370. fspec2)))
  371. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 90 "takaogothic" 13))
  372. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 100 "takaogothic" 14))
  373. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 100 "ms gothic" 14))
  374. ;; (my-set-ascii-and-jp-font '("monaco" 75 "takaogothic" 11))
  375. ;; (my-set-ascii-and-jp-font '("monaco" 90 "takaogothic" 13))
  376. ;; (my-set-ascii-and-jp-font '("ProggyCleanTTSZ" 120 "takaogothic" 11))
  377. ;; あ a
  378. (and (fetch-library
  379. "https://raw.github.com/10sr/emacs-lisp/master/set-modeline-color.el"
  380. t)
  381. (progn
  382. (require 'set-modeline-color nil t)))
  383. (let ((fg (face-foreground 'default))
  384. (bg (face-background 'default)))
  385. (set-face-background 'mode-line-inactive
  386. (if (face-inverse-video-p 'mode-line) fg bg))
  387. (set-face-foreground 'mode-line-inactive
  388. (if (face-inverse-video-p 'mode-line) bg fg)))
  389. (set-face-underline-p 'mode-line-inactive
  390. t)
  391. (set-face-underline-p 'vertical-border
  392. nil)
  393. (and (fetch-library
  394. "https://raw.github.com/tarao/elisp/master/end-mark.el"
  395. t)
  396. (require 'end-mark nil t)
  397. (global-end-mark-mode))
  398. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  399. ;; file handling
  400. (setq revert-without-query '(".+"))
  401. ;; save cursor position
  402. (setq save-place-file (concat user-emacs-directory
  403. "places"))
  404. (when (require 'saveplace nil t)
  405. (setq-default save-place t))
  406. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  407. (setq make-backup-files t)
  408. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  409. (setq backup-directory-alist
  410. (cons (cons "\\.*$" (expand-file-name "~/.emacs.d/backup"))
  411. backup-directory-alist))
  412. (setq version-control 'never)
  413. (setq delete-old-versions t)
  414. (setq auto-save-list-file-prefix (expand-file-name "~/.emacs.d/auto-save/"))
  415. (setq delete-auto-save-files t)
  416. (add-to-list 'completion-ignored-extensions ".bak")
  417. ;; (setq delete-by-moving-to-trash t
  418. ;; trash-directory "~/.emacs.d/trash")
  419. (add-hook 'after-save-hook
  420. 'executable-make-buffer-file-executable-if-script-p)
  421. (setq bookmark-default-file "~/.emacs.d/bmk")
  422. (add-hook 'recentf-load-hook
  423. (lambda ()
  424. (add-to-list 'recentf-exclude
  425. (regexp-quote bookmark-default-file))))
  426. (and (fetch-library
  427. "https://github.com/10sr/emacs-lisp/raw/master/read-only-only-mode.el"
  428. t)
  429. (lazy-load-eval 'read-only-only-mode))
  430. (and (fetch-library
  431. "https://raw.github.com/10sr/emacs-lisp/master/smart-revert.el"
  432. t)
  433. (require 'smart-revert nil t)
  434. (smart-revert-on))
  435. ;; autosave
  436. (and (fetch-library
  437. "https://raw.github.com/10sr/emacs-lisp/master/autosave.el"
  438. t)
  439. (require 'autosave nil t)
  440. (autosave-set 2))
  441. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  442. ;; editting
  443. (defun my-copy-whole-line ()
  444. ""
  445. (interactive)
  446. (kill-new (concat (buffer-substring (point-at-bol)
  447. (point-at-eol))
  448. "\n")))
  449. (setq require-final-newline t)
  450. (setq kill-whole-line t)
  451. (setq scroll-conservatively 35
  452. scroll-margin 2
  453. scroll-step 0)
  454. (setq default-major-mode 'text-mode)
  455. (setq next-line-add-newlines nil)
  456. (setq kill-read-only-ok t)
  457. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  458. ;; (setq-default line-spacing 0.2)
  459. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  460. (setq-default tab-width 4)
  461. (setq-default indent-tabs-mode nil)
  462. (setq-default indent-line-function nil)
  463. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  464. (delete-selection-mode 1)
  465. (cua-mode 0)
  466. (setq line-move-visual nil)
  467. ;; key bindings
  468. ;; moving around
  469. ;; (global-set-key (kbd "M-j") 'next-line)
  470. ;; (global-set-key (kbd "M-k") 'previous-line)
  471. ;; (global-set-key (kbd "M-h") 'backward-char)
  472. ;; (global-set-key (kbd "M-l") 'forward-char)
  473. ;;(keyboard-translate ?\M-j ?\C-j)
  474. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  475. (define-key esc-map "p" 'backward-paragraph)
  476. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  477. (define-key esc-map "n" 'forward-paragraph)
  478. (global-set-key (kbd "C-<up>") (lambda () (interactive)(scroll-down 1)))
  479. (global-set-key (kbd "C-<down>") (lambda () (interactive)(scroll-up 1)))
  480. (global-set-key (kbd "C-<left>") 'scroll-down)
  481. (global-set-key (kbd "C-<right>") 'scroll-up)
  482. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  483. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  484. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  485. ;; C-h and DEL
  486. (global-set-key (kbd "C-h") (kbd "DEL"))
  487. (global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  488. (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  489. (define-key esc-map "k" 'my-copy-whole-line)
  490. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  491. (define-key esc-map "u" 'undo)
  492. (define-key esc-map "i" (kbd "ESC TAB"))
  493. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  494. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  495. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  496. (define-key my-prefix-map (kbd "C-o") 'occur)
  497. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  498. ;; gmail
  499. (setq mail-interactive t
  500. send-mail-function 'smtpmail-send-it
  501. ;; message-send-mail-function 'smtpmail-send-it
  502. smtpmail-smtp-server "smtp.gmail.com"
  503. smtpmail-smtp-service 587
  504. smtpmail-starttls-credentials '(("smtp.gmail.com" 587
  505. "8.slashes@gmail.com" nil))
  506. smtpmail-auth-credentials '(("smtp.gmail.com" 587
  507. "8.slashes@gmail.com" nil))
  508. user-mail-address "8.slashes@gmail.com")
  509. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  510. ;; buffer killing
  511. (defun my-delete-window-killing-buffer () nil)
  512. (defun my-query-kill-current-buffer ()
  513. ""
  514. (interactive)
  515. (if (y-or-n-p (concat "kill current buffer? :"))
  516. (kill-buffer (current-buffer))))
  517. (substitute-key-definition 'kill-buffer
  518. 'my-query-kill-current-buffer
  519. global-map)
  520. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  521. (defun my-kill-buffers ()
  522. ""
  523. (interactive)
  524. (mapcar (lambda (buf)
  525. (when (buffer-file-name buf)
  526. (kill-buffer buf)))
  527. (buffer-list)))
  528. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  529. ;; share clipboard with x
  530. ;; this page describes this in details, but only these sexps seem to be needed
  531. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  532. (and (not window-system)
  533. (not (eq window-system 'mac))
  534. (getenv "DISPLAY")
  535. (not (equal (getenv "DISPLAY") ""))
  536. (executable-find "xclip")
  537. ;; (< emacs-major-version 24)
  538. (fetch-library "http://www.emacswiki.org/emacs/download/xclip.el" t)
  539. (require 'xclip nil t)
  540. (turn-on-xclip))
  541. (and (eq system-type 'darwin)
  542. (fetch-library
  543. "https://raw.github.com/10sr/emacs-lisp/master/pasteboard.el"
  544. t)
  545. (require 'pasteboard nil t)
  546. (turn-on-pasteboard)
  547. (getenv "TMUX")
  548. (pasteboard-enable-rtun))
  549. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  550. ;; package
  551. (when (require 'package nil t)
  552. (add-to-list 'package-archives
  553. '("melpa" . "http://melpa.milkbox.net/packages/")
  554. t)
  555. (add-to-list 'package-archives
  556. '("marmalade" . "http://marmalade-repo.org/packages/"))
  557. (add-to-list 'package-archives
  558. '("ELPA" . "http://tromey.com/elpa/"))
  559. (package-initialize))
  560. (lazy-load-eval 'sudoku)
  561. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  562. ;; window
  563. (and (fetch-library
  564. "https://raw.github.com/10sr/emacs-lisp/master/window-organizer.el"
  565. t)
  566. (lazy-load-eval 'window-organizer)
  567. (define-key ctl-x-map (kbd "w") 'window-organizer))
  568. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  569. ;; some modes and hooks
  570. ;; todo: reg major mode when set explicitly
  571. ;; Detect file type from shebang and set major-mode.
  572. (add-to-list 'interpreter-mode-alist
  573. '("python3" . python-mode))
  574. (add-to-list 'interpreter-mode-alist
  575. '("python2" . python-mode))
  576. ;; http://fukuyama.co/foreign-regexp
  577. '(and (fetch-library
  578. "https://raw.github.com/k-talo/foreign-regexp.el/master/foreign-regexp.el"
  579. t)
  580. (require 'foreign-regexp nil t)
  581. (progn
  582. (setq foreign-regexp/regexp-type 'perl)
  583. '(setq reb-re-syntax 'foreign-regexp)
  584. ))
  585. (require 'session nil t)
  586. (lazy-load-eval 'sql '(sql-mode)
  587. (require 'sql-indent nil t))
  588. (and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/gtkbm.el"
  589. t)
  590. (lazy-load-eval 'gtkbm)
  591. (global-set-key (kbd "C-x C-d") 'gtkbm))
  592. (and (fetch-library
  593. "https://raw.github.com/10sr/emacs-lisp/master/git-command.el"
  594. t)
  595. (lazy-load-eval 'git-command)
  596. (define-key ctl-x-map "g" 'git-command))
  597. (and (fetch-library
  598. "http://www.emacswiki.org/emacs/download/sl.el"
  599. t)
  600. (lazy-load-eval 'sl))
  601. (defalias 'qcalc 'quick-calc)
  602. (require 'simple nil t)
  603. (add-hook 'makefile-mode-hook
  604. (lambda ()
  605. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  606. ;; this functions is set in write-file-functions, i cannot find any
  607. ;; good way to remove this.
  608. (fset 'makefile-warn-suspicious-lines 'ignore)
  609. ))
  610. (defun make ()
  611. "Run \"make -k\" in current directory."
  612. (interactive)
  613. (compile "make -k"))
  614. (add-hook 'verilog-mode-hook
  615. (lambda ()
  616. (define-key verilog-mode-map ";" 'self-insert-command)))
  617. (setq diff-switches "-u")
  618. (add-hook 'diff-mode-hook
  619. (lambda ()
  620. (view-mode 1)
  621. (set-face-attribute 'diff-header nil
  622. :foreground nil
  623. :background nil
  624. :weight 'bold)
  625. (set-face-attribute 'diff-file-header nil
  626. :foreground nil
  627. :background nil
  628. :weight 'bold)
  629. (set-face-foreground 'diff-index-face "blue")
  630. (set-face-attribute 'diff-hunk-header nil
  631. :foreground "cyan"
  632. :weight 'normal)
  633. (set-face-attribute 'diff-context nil
  634. ;; :foreground "white"
  635. :foreground nil
  636. :weight 'normal)
  637. (set-face-foreground 'diff-removed-face "red")
  638. (set-face-foreground 'diff-added-face "green")
  639. (set-face-attribute 'diff-changed nil
  640. :foreground "magenta"
  641. :weight 'normal)
  642. ))
  643. ;; (ffap-bindings)
  644. (add-hook 'sh-mode-hook
  645. (lambda ()
  646. (define-key sh-mode-map
  647. (kbd "C-x C-e")
  648. 'my-execute-shell-command-current-line)))
  649. (setq sh-here-document-word "__EOC__")
  650. (defun my-execute-shell-command-current-line ()
  651. ""
  652. (interactive)
  653. (shell-command (buffer-substring-no-properties (point-at-bol)
  654. (point))))
  655. (setq auto-mode-alist
  656. `(("autostart\\'" . sh-mode)
  657. ("xinitrc\\'" . sh-mode)
  658. ("xprograms\\'" . sh-mode)
  659. ("PKGBUILD\\'" . sh-mode)
  660. ,@auto-mode-alist))
  661. (and (lazy-load-eval 'pkgbuild-mode)
  662. (setq auto-mode-alist (append '(("PKGBUILD\\'" . pkgbuild-mode))
  663. auto-mode-alist)))
  664. (add-hook 'html-mode-hook
  665. (lambda ()
  666. (define-key html-mode-map (kbd "C-m")
  667. 'reindent-then-newline-and-indent)))
  668. (add-hook 'text-mode-hook
  669. (lambda ()
  670. (define-key text-mode-map (kbd "C-m") 'newline)))
  671. (add-to-list 'Info-default-directory-list
  672. (expand-file-name "~/.info/emacs-ja"))
  673. (add-hook 'apropos-mode-hook
  674. (lambda ()
  675. (define-key apropos-mode-map "n" 'next-line)
  676. (define-key apropos-mode-map "p" 'previous-line)
  677. ))
  678. (add-hook 'isearch-mode-hook
  679. (lambda ()
  680. ;; (define-key isearch-mode-map
  681. ;; (kbd "C-j") 'isearch-other-control-char)
  682. ;; (define-key isearch-mode-map
  683. ;; (kbd "C-k") 'isearch-other-control-char)
  684. ;; (define-key isearch-mode-map
  685. ;; (kbd "C-h") 'isearch-other-control-char)
  686. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  687. (define-key isearch-mode-map (kbd "M-r")
  688. 'isearch-query-replace-regexp)))
  689. (add-hook 'outline-mode-hook
  690. (lambda ()
  691. (if (string-match "\\.md\\'" buffer-file-name)
  692. (set (make-local-variable 'outline-regexp) "#+ "))))
  693. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  694. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  695. (when (fetch-library
  696. "http://jblevins.org/projects/markdown-mode/markdown-mode.el"
  697. t)
  698. (lazy-load-eval 'markdown-mode)
  699. (setq markdown-command (or (executable-find "markdown")
  700. (executable-find "markdown.pl")))
  701. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'markdown-mode))
  702. (add-hook 'markdown-mode-hook
  703. (lambda ()
  704. (outline-minor-mode 1)
  705. (set (make-local-variable 'comment-start) ";"))))
  706. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  707. ;; c-mode
  708. ;; (setq c-default-style "bsd")
  709. (add-hook 'c-mode-common-hook
  710. (lambda ()
  711. (setq c-basic-offset 2
  712. indent-tabs-mode nil)
  713. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  714. (c-toggle-hungry-state -1)
  715. (and (require 'gtags nil t)
  716. (gtags-mode 1))
  717. ))
  718. (when (fetch-library
  719. "https://raw.github.com/mooz/js2-mode/master/js2-mode.el"
  720. t)
  721. (lazy-load-eval 'js2-mode)
  722. (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  723. (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  724. ;; (add-hook 'js2-mode-hook
  725. ;; (lambda ()
  726. (add-hook 'js2-mode-hook
  727. (lambda ()
  728. (define-key js2-mode-map (kbd "C-m") (lambda ()
  729. (interactive)
  730. (js2-enter-key)
  731. (indent-for-tab-command)))
  732. (add-hook (kill-local-variable 'before-save-hook)
  733. 'js2-before-save)
  734. ;; (add-hook 'before-save-hook
  735. ;; 'my-indent-buffer
  736. ;; nil
  737. ;; t)
  738. )))
  739. (when (require 'uniquify nil t)
  740. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  741. (setq uniquify-ignore-buffers-re "*[^*]+*")
  742. (setq uniquify-min-dir-content 1))
  743. (add-hook 'view-mode-hook
  744. (lambda()
  745. (define-key view-mode-map "j"
  746. (lambda() (interactive) (scroll-up 1)))
  747. (define-key view-mode-map "k"
  748. (lambda() (interactive) (scroll-down 1)))
  749. (define-key view-mode-map "v" 'toggle-read-only)
  750. (define-key view-mode-map "q" 'bury-buffer)
  751. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  752. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  753. ;; (define-key view-mode-map
  754. ;; "n" 'nonincremental-repeat-search-forward)
  755. ;; (define-key view-mode-map
  756. ;; "N" 'nonincremental-repeat-search-backward)
  757. (define-key view-mode-map "/" 'isearch-forward-regexp)
  758. (define-key view-mode-map "?" 'isearch-backward-regexp)
  759. (define-key view-mode-map "n" 'isearch-repeat-forward)
  760. (define-key view-mode-map "N" 'isearch-repeat-backward)
  761. ))
  762. (global-set-key "\M-r" 'view-mode)
  763. (setq view-read-only t)
  764. (add-hook 'Man-mode-hook
  765. (lambda ()
  766. (view-mode 1)
  767. (setq truncate-lines nil)))
  768. (setq Man-notify-method (if window-system
  769. 'newframe
  770. 'pushy))
  771. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  772. ;; python
  773. (when (lazy-load-eval 'python '(python-mode))
  774. (setq python-python-command (or (executable-find "python3")
  775. (executable-find "python")))
  776. (defun my-python-run-as-command ()
  777. ""
  778. (interactive)
  779. (shell-command (concat python-python-command " " buffer-file-name)))
  780. (defun my-python-display-python-buffer ()
  781. ""
  782. (interactive)
  783. (set-window-text-height (display-buffer python-buffer
  784. t)
  785. 7))
  786. (add-hook 'python-mode-hook
  787. (lambda ()
  788. (define-key python-mode-map
  789. (kbd "C-c C-e") 'my-python-run-as-command)
  790. (define-key python-mode-map
  791. (kbd "C-c C-b") 'my-python-display-python-buffer)
  792. (define-key python-mode-map (kbd "C-m") 'newline-and-indent)))
  793. (add-hook 'inferior-python-mode-hook
  794. (lambda ()
  795. (my-python-display-python-buffer)
  796. (define-key inferior-python-mode-map
  797. (kbd "<up>") 'comint-previous-input)
  798. (define-key inferior-python-mode-map
  799. (kbd "<down>") 'comint-next-input))))
  800. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  801. ;; GNU GLOBAL(gtags)
  802. ;; http://uguisu.skr.jp/Windows/gtags.html
  803. ;; http://eigyr.dip.jp/gtags.html
  804. ;; http://cha.la.coocan.jp/doc/gnu_global.html
  805. (when (lazy-load-eval 'gtags '(gtags-mode))
  806. (add-hook 'gtags-mode-hook
  807. (lambda ()
  808. (setq gtags-select-buffer-single t)
  809. ;; (local-set-key "\M-t" 'gtags-find-tag)
  810. ;; (local-set-key "\M-r" 'gtags-find-rtag)
  811. ;; (local-set-key "\M-s" 'gtags-find-symbol)
  812. ;; (local-set-key "\C-t" 'gtags-pop-stack)
  813. (define-key gtags-mode-map (kbd "C-x t h") 'gtags-find-tag-from-here)
  814. (define-key gtags-mode-map (kbd "C-x t t") 'gtags-find-tag)
  815. (define-key gtags-mode-map (kbd "C-x t r") 'gtags-find-rtag)
  816. (define-key gtags-mode-map (kbd "C-x t s") 'gtags-find-symbol)
  817. (define-key gtags-mode-map (kbd "C-x t p") 'gtags-find-pattern)
  818. (define-key gtags-mdoe-map (kbd "C-x t f") 'gtags-find-file)
  819. (define-key gtags-mode-map (kbd "C-x t b") 'gtags-pop-stack) ;back
  820. )))
  821. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  822. ;; term mode
  823. ;; (setq multi-term-program shell-file-name)
  824. (and (fetch-library "http://www.emacswiki.org/emacs/download/multi-term.el"
  825. t)
  826. (lazy-load-eval 'multi-term)
  827. (progn
  828. (setq multi-term-switch-after-close nil)
  829. (setq multi-term-dedicated-select-after-open-p t)
  830. (setq multi-term-dedicated-window-height 20)))
  831. (when (lazy-load-eval 'term '(term ansi-term))
  832. (defun my-term-quit-or-send-raw ()
  833. ""
  834. (interactive)
  835. (if (get-buffer-process (current-buffer))
  836. (call-interactively 'term-send-raw)
  837. (kill-buffer)))
  838. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  839. ;; (setq term-ansi-default-program shell-file-name)
  840. (add-hook 'term-setup-hook
  841. (lambda ()
  842. (setq term-display-table (make-display-table))))
  843. (add-hook 'term-mode-hook
  844. (lambda ()
  845. (unless (memq (current-buffer)
  846. (and (featurep 'multi-term)
  847. ;; current buffer is not multi-term buffer
  848. (multi-term-list)))
  849. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  850. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  851. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  852. ;; (define-key term-raw-map "\C-f" 'forward-char)
  853. ;; (define-key term-raw-map "\C-b" 'backward-char)
  854. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  855. (define-key term-raw-map
  856. "\C-x" (lookup-key (current-global-map) "\C-x"))
  857. (define-key term-raw-map
  858. "\C-z" (lookup-key (current-global-map) "\C-z"))
  859. )
  860. ;; (define-key term-raw-map "\C-xl" 'term-line-mode)
  861. ;; (define-key term-mode-map "\C-xc" 'term-char-mode)
  862. (define-key term-raw-map (kbd "<up>")
  863. (lambda () (interactive) (scroll-down 1)))
  864. (define-key term-raw-map (kbd "<down>")
  865. (lambda () (interactive) (scroll-up 1)))
  866. (define-key term-raw-map (kbd "<right>") 'scroll-up)
  867. (define-key term-raw-map (kbd "<left>") 'scroll-down)
  868. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  869. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  870. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  871. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  872. (define-key term-raw-map [delete] 'term-send-raw)
  873. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  874. (define-key term-raw-map "\C-y" 'term-paste)
  875. (define-key term-raw-map
  876. "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  877. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  878. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  879. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  880. ;; (define-key term-raw-map "\C-d" 'delete-char)
  881. (set (make-local-variable 'scroll-margin) 0)
  882. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  883. ;; (cua-mode 0)
  884. ;; (and cua-mode
  885. ;; (local-unset-key (kbd "C-c")))
  886. ;; (define-key cua--prefix-override-keymap
  887. ;;"\C-c" 'term-interrupt-subjob)
  888. (set (make-local-variable 'hl-line-range-function)
  889. (lambda ()
  890. '(0 . 0)))
  891. ))
  892. ;; (add-hook 'term-exec-hook 'forward-char)
  893. )
  894. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  895. ;; buffer switching
  896. (when (lazy-load-eval 'bs '(bs-show)
  897. ;; (add-to-list 'bs-configurations
  898. ;; '("processes" nil get-buffer-process ".*" nil nil))
  899. (add-to-list 'bs-configurations
  900. '("this-frame" nil (lambda (buf)
  901. (memq buf (my-frame-buffer-get)))
  902. ".*" nil nil))
  903. ;; (setq bs-configurations (list
  904. ;; '("processes" nil get-buffer-process ".*" nil nil)
  905. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  906. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  907. )
  908. ;; (global-set-key "\C-x\C-b" 'bs-show)
  909. (defalias 'list-buffers 'bs-show)
  910. (setq bs-default-configuration "files")
  911. (setq bs-default-sort-name "by nothing")
  912. (add-hook 'bs-mode-hook
  913. (lambda ()
  914. (setq bs-default-configuration "files")
  915. ;; (and bs--show-all
  916. ;; (call-interactively 'bs-toggle-show-all))
  917. (set (make-local-variable 'scroll-margin) 0))))
  918. (iswitchb-mode 1)
  919. (defun iswitchb-buffer-display-other-window ()
  920. ""
  921. (interactive)
  922. (let ((iswitchb-default-method 'display))
  923. (call-interactively 'iswitchb-buffer)))
  924. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  925. ;; sdic
  926. (when (lazy-load-eval 'sdic '(sdic-describe-word-at-point))
  927. ;; (define-key my-prefix-map "\C-w" 'sdic-describe-word)
  928. (define-key my-prefix-map "\C-t" 'sdic-describe-word-at-point-echo)
  929. (defun sdic-describe-word-at-point-echo ()
  930. ""
  931. (interactive)
  932. (save-window-excursion
  933. (sdic-describe-word-at-point))
  934. (save-excursion
  935. (set-buffer sdic-buffer-name)
  936. (message (buffer-substring (point-min)
  937. (progn (goto-char (point-min))
  938. (or (and (re-search-forward "^\\w"
  939. nil
  940. t
  941. 4)
  942. (progn (previous-line) t)
  943. (point-at-eol))
  944. (point-max)))))))
  945. (setq sdic-eiwa-dictionary-list '((sdicf-client "/usr/share/dict/gene.sdic")))
  946. (setq sdic-waei-dictionary-list
  947. '((sdicf-client "/usr/share/dict/jedict.sdic" (add-keys-to-headword t))))
  948. (setq sdic-disable-select-window t)
  949. (setq sdic-window-height 7))
  950. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  951. ;; vc
  952. ;; (require 'vc)
  953. (setq vc-handled-backends '())
  954. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  955. ;; gauche-mode
  956. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  957. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  958. (when (and (fetch-library
  959. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  960. t)
  961. (lazy-load-eval 'gauche-mode '(gauche-mode run-scheme)))
  962. (let ((s (executable-find "gosh")))
  963. (setq scheme-program-name s
  964. gauche-program-name s))
  965. (defun run-gauche-other-window ()
  966. "Run gauche on other window"
  967. (interactive)
  968. (switch-to-buffer-other-window
  969. (get-buffer-create "*scheme*"))
  970. (run-gauche))
  971. (defun run-gauche ()
  972. "run gauche"
  973. (run-scheme gauche-program-name)
  974. )
  975. (defun scheme-send-buffer ()
  976. ""
  977. (interactive)
  978. (scheme-send-region (point-min) (point-max))
  979. (my-scheme-display-scheme-buffer)
  980. )
  981. (defun my-scheme-display-scheme-buffer ()
  982. ""
  983. (interactive)
  984. (set-window-text-height (display-buffer scheme-buffer
  985. t)
  986. 7))
  987. (add-hook 'scheme-mode-hook
  988. (lambda ()
  989. nil))
  990. (add-hook 'inferior-scheme-mode-hook
  991. (lambda ()
  992. ;; (my-scheme-display-scheme-buffer)
  993. ))
  994. (setq auto-mode-alist
  995. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  996. (setq auto-mode-alist
  997. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  998. (add-hook 'gauche-mode-hook
  999. (lambda ()
  1000. (define-key gauche-mode-map
  1001. (kbd "C-c C-z") 'run-gauche-other-window)
  1002. (define-key scheme-mode-map
  1003. (kbd "C-c C-c") 'scheme-send-buffer)
  1004. (define-key scheme-mode-map
  1005. (kbd "C-c C-b") 'my-scheme-display-scheme-buffer))))
  1006. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1007. ;; recentf-mode
  1008. (setq recentf-save-file (expand-file-name "~/.emacs.d/recentf")
  1009. recentf-max-menu-items 20
  1010. recentf-max-saved-items 30
  1011. recentf-show-file-shortcuts-flag nil)
  1012. (when (require 'recentf nil t)
  1013. (add-to-list 'recentf-exclude (regexp-quote recentf-save-file))
  1014. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1015. (add-hook 'find-file-hook
  1016. 'recentf-save-list
  1017. t) ; save to file immediately after adding file to recentf list
  1018. (add-hook 'kill-emacs-hook
  1019. 'recentf-load-list)
  1020. (add-hook 'recentf-mode-hook
  1021. 'recentf-save-list)
  1022. ;; (add-hook 'find-file-hook
  1023. ;; (lambda ()
  1024. ;; (recentf-add-file default-directory)))
  1025. (and (fetch-library
  1026. "https://raw.github.com/10sr/emacs-lisp/master/recentf-show.el"
  1027. t)
  1028. (lazy-load-eval 'recentf-show)
  1029. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1030. (add-hook 'recentf-show-before-listing-hook
  1031. 'recentf-load-list))
  1032. (recentf-mode 1)
  1033. (add-hook 'recentf-dialog-mode-hook
  1034. (lambda ()
  1035. ;; (recentf-save-list)
  1036. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1037. ;; 'my-recentf-cd-and-find-file)
  1038. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1039. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1040. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1041. (define-key recentf-dialog-mode-map "n" 'next-line)
  1042. (cd "~/"))))
  1043. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1044. ;; dired
  1045. (when (lazy-load-eval 'dired nil)
  1046. (defun my-dired-echo-file-head (arg)
  1047. ""
  1048. (interactive "P")
  1049. (let ((f (dired-get-filename)))
  1050. (message "%s"
  1051. (with-temp-buffer
  1052. (insert-file-contents f)
  1053. (buffer-substring-no-properties
  1054. (point-min)
  1055. (progn (goto-line (if arg
  1056. (prefix-numeric-value arg)
  1057. 10))
  1058. (point-at-eol)))))))
  1059. (defun my-dired-diff ()
  1060. ""
  1061. (interactive)
  1062. (let ((files (dired-get-marked-files nil nil nil t)))
  1063. (if (eq (car files)
  1064. t)
  1065. (diff (cadr files) (dired-get-filename))
  1066. (message "One files must be marked!"))))
  1067. (defun my-pop-to-buffer-erase-noselect (buffer-or-name)
  1068. "pop up buffer using `display-buffer' and return that buffer."
  1069. (let ((bf (get-buffer-create buffer-or-name)))
  1070. (with-current-buffer bf
  1071. (cd ".")
  1072. (erase-buffer))
  1073. (display-buffer bf)
  1074. bf))
  1075. (defun my-replace-nasi-none ()
  1076. ""
  1077. (save-excursion
  1078. (let ((buffer-read-only nil))
  1079. (goto-char (point-min))
  1080. (while (search-forward "なし" nil t)
  1081. (replace-match "none")))))
  1082. (defun dired-get-file-info ()
  1083. "dired get file info"
  1084. (interactive)
  1085. (let ((f (shell-quote-argument (dired-get-filename t))))
  1086. (if (file-directory-p f)
  1087. (progn
  1088. (message "Calculating disk usage...")
  1089. (shell-command (concat "du -hsD "
  1090. f)))
  1091. (shell-command (concat "file "
  1092. f)))))
  1093. (defun my-dired-scroll-up ()
  1094. ""
  1095. (interactive)
  1096. (my-dired-previous-line (- (window-height) 1)))
  1097. (defun my-dired-scroll-down ()
  1098. ""
  1099. (interactive)
  1100. (my-dired-next-line (- (window-height) 1)))
  1101. ;; (defun my-dired-forward-line (arg)
  1102. ;; ""
  1103. ;; (interactive "p"))
  1104. (defun my-dired-previous-line (arg)
  1105. ""
  1106. (interactive "p")
  1107. (if (> arg 0)
  1108. (progn
  1109. (if (eq (line-number-at-pos)
  1110. 1)
  1111. (goto-char (point-max))
  1112. (forward-line -1))
  1113. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1114. (dired-get-subdir))
  1115. (- arg 1)
  1116. arg)))
  1117. (dired-move-to-filename)))
  1118. (defun my-dired-next-line (arg)
  1119. ""
  1120. (interactive "p")
  1121. (if (> arg 0)
  1122. (progn
  1123. (if (eq (point)
  1124. (point-max))
  1125. (goto-char (point-min))
  1126. (forward-line 1))
  1127. (my-dired-next-line (if (or (dired-get-filename nil t)
  1128. (dired-get-subdir))
  1129. (- arg 1)
  1130. arg)))
  1131. (dired-move-to-filename)))
  1132. (defun my-dired-print-current-dir-and-file ()
  1133. (message "%s %s"
  1134. default-directory
  1135. (buffer-substring-no-properties (point-at-bol)
  1136. (point-at-eol))))
  1137. (defun dired-do-execute-as-command ()
  1138. ""
  1139. (interactive)
  1140. (let ((file (dired-get-filename t)))
  1141. (if (file-executable-p file)
  1142. (start-process file nil file)
  1143. (when (y-or-n-p
  1144. "this file cant be executed. mark as executable and go? : ")
  1145. (set-file-modes file
  1146. (file-modes-symbolic-to-number "u+x" (file-modes file)))
  1147. (start-process file nil file)))))
  1148. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1149. (defun my-dired-x-open ()
  1150. ""
  1151. (interactive)
  1152. (my-x-open (dired-get-filename t t)))
  1153. (if (eq window-system 'mac)
  1154. (setq dired-listing-switches "-lhFG")
  1155. (setq dired-listing-switches "-lhFG --time-style=long-iso")
  1156. )
  1157. (setq dired-listing-switches "-lhFG")
  1158. (put 'dired-find-alternate-file 'disabled nil)
  1159. ;; when using dired-find-alternate-file
  1160. ;; reuse current dired buffer for the file to open
  1161. (setq dired-ls-F-marks-symlinks t)
  1162. (require 'ls-lisp)
  1163. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1164. (setq ls-lisp-dirs-first t)
  1165. (setq ls-lisp-use-localized-time-format t)
  1166. (setq ls-lisp-format-time-list
  1167. '("%Y-%m-%d %H:%M"
  1168. "%Y-%m-%d "))
  1169. (setq dired-dwim-target t)
  1170. ;; (add-hook 'dired-after-readin-hook
  1171. ;; 'my-replace-nasi-none)
  1172. ;; (add-hook 'after-init-hook
  1173. ;; (lambda ()
  1174. ;; (dired ".")))
  1175. (add-hook 'dired-mode-hook
  1176. (lambda ()
  1177. (define-key dired-mode-map "o" 'my-dired-x-open)
  1178. (define-key dired-mode-map "i" 'dired-get-file-info)
  1179. (define-key dired-mode-map "f" 'find-file)
  1180. (define-key dired-mode-map "!" 'shell-command)
  1181. (define-key dired-mode-map "&" 'async-shell-command)
  1182. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1183. (define-key dired-mode-map "=" 'my-dired-diff)
  1184. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1185. (define-key dired-mode-map "b" 'gtkbm)
  1186. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1187. (define-key dired-mode-map "@" (lambda ()
  1188. (interactive) (my-x-open ".")))
  1189. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1190. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1191. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1192. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1193. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1194. (substitute-key-definition 'dired-next-line
  1195. 'my-dired-next-line dired-mode-map)
  1196. (substitute-key-definition 'dired-previous-line
  1197. 'my-dired-previous-line dired-mode-map)
  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. (let ((file "._Icon\015"))
  1203. (when nil (file-readable-p file)
  1204. (delete-file file)))))
  1205. (and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/pack.el"
  1206. t)
  1207. (lazy-load-eval 'pack '(dired-do-pack-or-unpack pack))
  1208. (add-hook 'dired-mode-hook
  1209. (lambda ()
  1210. (define-key dired-mode-map "P" 'dired-do-pack-or-unpack))))
  1211. (and (fetch-library
  1212. "https://raw.github.com/10sr/emacs-lisp/master/dired-list-all-mode.el"
  1213. t)
  1214. (lazy-load-eval 'dired-list-all-mode)
  1215. (setq dired-listing-switches "-lhFG")
  1216. (add-hook 'dired-mode-hook
  1217. (lambda ()
  1218. (define-key dired-mode-map "a" 'dired-list-all-mode)
  1219. )))
  1220. ) ; when dired locate
  1221. ;; http://blog.livedoor.jp/tek_nishi/archives/4693204.html
  1222. (defun my-dired-toggle-mark()
  1223. (let ((cur (cond ((eq (following-char) dired-marker-char) ?\040)
  1224. (t dired-marker-char))))
  1225. (delete-char 1)
  1226. (insert cur)))
  1227. (defun my-dired-mark (arg)
  1228. "toggle mark the current (or next ARG) files.
  1229. If on a subdir headerline, mark all its files except `.' and `..'.
  1230. Use \\[dired-unmark-all-files] to remove all marks
  1231. and \\[dired-unmark] on a subdir to remove the marks in
  1232. this subdir."
  1233. (interactive "P")
  1234. (if (dired-get-subdir)
  1235. (save-excursion (dired-mark-subdir-files))
  1236. (let ((inhibit-read-only t))
  1237. (dired-repeat-over-lines
  1238. (prefix-numeric-value arg)
  1239. 'my-dired-toggle-mark))))
  1240. (defun my-dired-mark-backward (arg)
  1241. "In Dired, move up lines and toggle mark there.
  1242. Optional prefix ARG says how many lines to unflag; default is one line."
  1243. (interactive "p")
  1244. (my-dired-mark (- arg)))
  1245. (add-hook 'dired-mode-hook
  1246. (lambda ()
  1247. (local-set-key (kbd "SPC") 'my-dired-mark)
  1248. (local-set-key (kbd "S-SPC") 'my-dired-mark-backward))
  1249. )
  1250. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1251. ;; eshell
  1252. (lazy-load-eval 'eshell nil
  1253. (defun my-eshell-backward-delete-char ()
  1254. (interactive)
  1255. (when (< (save-excursion
  1256. (eshell-bol)
  1257. (point))
  1258. (point))
  1259. (backward-delete-char 1)))
  1260. (defun my-file-owner-p (file)
  1261. "t if FILE is owned by me."
  1262. (eq (user-uid) (nth 2 (file-attributes file))))
  1263. "http://www.bookshelf.jp/pukiwiki/pukiwiki.php\
  1264. ?Eshell%A4%F2%BB%C8%A4%A4%A4%B3%A4%CA%A4%B9"
  1265. ;; ;; written by Stefan Reichoer <reichoer@web.de>
  1266. ;; (defun eshell/less (&rest args)
  1267. ;; "Invoke `view-file' on the file.
  1268. ;; \"less +42 foo\" also goes to line 42 in the buffer."
  1269. ;; (if args
  1270. ;; (while args
  1271. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1272. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1273. ;; (file (pop args)))
  1274. ;; (view-file file)
  1275. ;; (goto-line line))
  1276. ;; (view-file (pop args))))))
  1277. (defun eshell/o (&optional file)
  1278. (my-x-open (or file ".")))
  1279. ;; (defun eshell/vi (&rest args)
  1280. ;; "Invoke `find-file' on the file.
  1281. ;; \"vi +42 foo\" also goes to line 42 in the buffer."
  1282. ;; (while args
  1283. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1284. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1285. ;; (file (pop args)))
  1286. ;; (find-file file)
  1287. ;; (goto-line line))
  1288. ;; (find-file (pop args)))))
  1289. (defun eshell/clear ()
  1290. "Clear the current buffer, leaving one prompt at the top."
  1291. (let ((inhibit-read-only t))
  1292. (erase-buffer)))
  1293. (defun eshell/d (&optional dirname switches)
  1294. "if first arg is omitted open current directory."
  1295. (dired (or dirname ".") switches))
  1296. (defun eshell/v ()
  1297. (view-mode 1))
  1298. (defun eshell/git (&rest args)
  1299. ""
  1300. (if (member (car args)
  1301. '("di" "diff" "log" "show"))
  1302. (apply 'eshell-exec-visual "git" args)
  1303. (shell-command (mapconcat 'shell-quote-argument
  1304. `("git" ,@args)
  1305. " ")
  1306. t)
  1307. ;; (eshell-external-command "git" args)
  1308. ))
  1309. (defalias 'eshell/: 'ignore)
  1310. (defalias 'eshell/type 'eshell/which)
  1311. ;; (defalias 'eshell/vim 'eshell/vi)
  1312. (defalias 'eshell/ff 'find-file)
  1313. (defalias 'eshell/q 'eshell/exit)
  1314. (defun eshell-goto-prompt ()
  1315. ""
  1316. (interactive)
  1317. (goto-char (point-max)))
  1318. (defun eshell-cd-default-directory (&optional eshell-buffer-or-name)
  1319. "open eshell and change wd
  1320. if arg given, use that eshell buffer, otherwise make new eshell buffer."
  1321. (interactive)
  1322. (let ((dir (expand-file-name default-directory)))
  1323. (switch-to-buffer (or eshell-buffer-or-name
  1324. (eshell t)))
  1325. (unless (equal dir (expand-file-name default-directory))
  1326. ;; (cd dir)
  1327. ;; (eshell-interactive-print (concat "cd " dir "\n"))
  1328. ;; (eshell-emit-prompt)
  1329. (goto-char (point-max))
  1330. (eshell-kill-input)
  1331. (insert "cd " dir)
  1332. (eshell-send-input))))
  1333. (setq eshell-directory-name "~/.emacs.d/eshell/")
  1334. (setq eshell-term-name "eterm-color")
  1335. (setq eshell-scroll-to-bottom-on-input t)
  1336. (setq eshell-cmpl-ignore-case t)
  1337. (setq eshell-cmpl-cycle-completions nil)
  1338. (setq eshell-highlight-prompt nil)
  1339. (setq eshell-ls-initial-args '("-hCFG"
  1340. "--color=auto"
  1341. "--time-style=long-iso")) ; "-hF")
  1342. (setq eshell-prompt-function
  1343. (lambda ()
  1344. (with-temp-buffer
  1345. (let (p1 p2 p3 p4)
  1346. (insert " [")
  1347. (setq p1 (point))
  1348. (insert (abbreviate-file-name default-directory))
  1349. (setq p2 (point))
  1350. (insert "]"
  1351. "\n")
  1352. (setq p3 (point))
  1353. (insert user-login-name
  1354. "@"
  1355. (or (getenv "HOSTNAME")
  1356. (substring (shell-command-to-string
  1357. (or (executable-find "hostname")
  1358. "echo ''"))
  1359. 0
  1360. -1)))
  1361. (setq p4 (point))
  1362. (insert " "
  1363. (format-time-string "%a, %d %b %Y %T %z")
  1364. " eshell\n"
  1365. "last:"
  1366. (number-to-string eshell-last-command-status)
  1367. (if (= (user-uid)
  1368. 0)
  1369. " # "
  1370. " $ "))
  1371. (add-text-properties p1
  1372. p2
  1373. '(face ((foreground-color . "yellow"))))
  1374. (add-text-properties p3
  1375. p4
  1376. '(face ((foreground-color . "cyan"))))
  1377. (buffer-substring (point-min)
  1378. (point-max))))))
  1379. (add-hook 'eshell-mode-hook
  1380. (lambda ()
  1381. ;; (define-key eshell-mode-map (kbd "C-x C-x") (lambda ()
  1382. ;; (interactive)
  1383. ;; (switch-to-buffer (other-buffer))))
  1384. (define-key eshell-mode-map (kbd "C-u") (lambda ()
  1385. (interactive)
  1386. (eshell-goto-prompt)
  1387. (eshell-kill-input)))
  1388. (define-key eshell-mode-map (kbd "C-g") (lambda ()
  1389. (interactive)
  1390. (eshell-goto-prompt)
  1391. (my-keyboard-quit)))
  1392. (define-key eshell-mode-map
  1393. (kbd "DEL") 'my-eshell-backward-delete-char)
  1394. (define-key eshell-mode-map
  1395. (kbd "C-p") 'eshell-previous-matching-input-from-input)
  1396. (define-key eshell-mode-map
  1397. (kbd "C-n") 'eshell-next-matching-input-from-input)
  1398. (apply 'eshell/addpath exec-path)
  1399. (set (make-local-variable 'scroll-margin) 0)
  1400. ;; (eshell/export "GIT_PAGER=")
  1401. ;; (eshell/export "GIT_EDITOR=")
  1402. (eshell/export "LC_MESSAGES=C")
  1403. (switch-to-buffer (current-buffer)) ; move buffer top of list
  1404. (set (make-local-variable 'hl-line-range-function)
  1405. (lambda ()
  1406. '(0 . 0)))
  1407. (add-to-list 'eshell-virtual-targets
  1408. '("/dev/less"
  1409. (lambda (str)
  1410. (if str
  1411. (with-current-buffer nil)))
  1412. nil))
  1413. ))
  1414. (add-hook 'eshell-mode-hook
  1415. (lambda ()
  1416. (add-to-list 'eshell-visual-commands "vim")
  1417. ;; (add-to-list 'eshell-visual-commands "git")
  1418. (add-to-list 'eshell-output-filter-functions
  1419. 'eshell-truncate-buffer)
  1420. (mapcar (lambda (alias)
  1421. (add-to-list 'eshell-command-aliases-list
  1422. alias))
  1423. '(
  1424. ; ("ll" "ls -l $*")
  1425. ; ("la" "ls -a $*")
  1426. ; ("lla" "ls -al $*")
  1427. ("aptin" "apt-get install $*")
  1428. ("eless"
  1429. (concat "cat >>> (with-current-buffer "
  1430. "(get-buffer-create \"*eshell output\") "
  1431. "(erase-buffer) "
  1432. "(setq buffer-read-only nil) "
  1433. "(current-buffer)) "
  1434. "(view-buffer (get-buffer \"*eshell output*\"))")
  1435. ("g" "git $*")
  1436. ))
  1437. )))
  1438. ) ; eval after load eshell
  1439. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1440. ;; frame buffer
  1441. ;; todo: work well when opening files already opened on another window
  1442. (add-hook 'after-make-frame-functions
  1443. (lambda (f)
  1444. (set-window-buffer (frame-selected-window f)
  1445. "*Messages*")))
  1446. (defun make-frame-command-with-name (name)
  1447. "Make frame with name specified."
  1448. (interactive "sName for new frame: ")
  1449. (set-frame-parameter (make-frame-command)
  1450. 'name
  1451. name))
  1452. (defvar my-frame-buffer-plist nil)
  1453. (defun my-frame-buffer-add (&optional buf frame)
  1454. ""
  1455. (setq my-frame-buffer-plist
  1456. (plist-put my-frame-buffer-plist
  1457. (or frame
  1458. (selected-frame))
  1459. (let ((lst (my-frame-buffer-get frame)))
  1460. (if lst
  1461. (add-to-list 'lst
  1462. (or buf
  1463. (current-buffer)))
  1464. (list (or buf
  1465. (current-buffer))))))))
  1466. (defun my-frame-buffer-remove (&optional buf frame)
  1467. ""
  1468. (setq my-frame-buffer-plist
  1469. (plist-put my-frame-buffer-plist
  1470. (or frame
  1471. (selected-frame))
  1472. (delq (or buf
  1473. (current-buffer))
  1474. (my-frame-buffer-get frame)))))
  1475. (defun my-frame-buffer-get (&optional frame)
  1476. ""
  1477. (plist-get my-frame-buffer-plist
  1478. (or frame
  1479. (selected-frame))))
  1480. (defun my-frame-buffer-kill-all-buffer (&optional frame)
  1481. ""
  1482. (mapcar 'kill-buffer
  1483. (my-frame-buffer-get frame)))
  1484. (add-hook 'find-file-hook
  1485. 'my-frame-buffer-add)
  1486. ;; (add-hook 'term-mode-hook
  1487. ;; 'my-frame-buffer-add)
  1488. (add-hook 'eshell-mode-hook
  1489. 'my-frame-buffer-add)
  1490. (add-hook 'Man-mode-hook
  1491. 'my-frame-buffer-add)
  1492. (add-hook 'kill-buffer-hook
  1493. 'my-frame-buffer-remove)
  1494. (add-hook 'delete-frame-functions
  1495. 'my-frame-buffer-kill-all-buffer)
  1496. (defvar my-desktop-terminal "roxterm")
  1497. (defun my-execute-terminal ()
  1498. ""
  1499. (interactive)
  1500. (if (and (or (eq system-type 'windows-nt)
  1501. window-system)
  1502. my-desktop-terminal
  1503. )
  1504. (let ((process-environment (cons "TERM=xterm" process-environment)))
  1505. (start-process "terminal"
  1506. nil
  1507. my-desktop-terminal))
  1508. (my-term)))
  1509. (defvar my-term nil "my terminal buffer")
  1510. (defun my-term ()
  1511. "open terminal buffer and return that buffer."
  1512. (interactive)
  1513. (if (and my-term
  1514. (buffer-name my-term))
  1515. (pop-to-buffer my-term)
  1516. (setq my-term
  1517. (save-window-excursion
  1518. (if (eq system-type 'windows-nt)
  1519. (eshell)
  1520. (if (require 'multi-term nil t)
  1521. (multi-term)
  1522. (ansi-term shell-file-name)))))
  1523. (my-term)))
  1524. (defun my-delete-frame-or-kill-emacs ()
  1525. "delete frame when opening multiple frame, kill emacs when only one."
  1526. (interactive)
  1527. (if (eq 1
  1528. (length (frame-list)))
  1529. (save-buffers-kill-emacs)
  1530. (delete-frame)))
  1531. (define-key my-prefix-map (kbd "C-s") 'my-execute-terminal)
  1532. (define-key my-prefix-map (kbd "C-f") 'make-frame-command-with-name)
  1533. (global-set-key (kbd "C-x C-c") 'my-delete-frame-or-kill-emacs)
  1534. (define-key my-prefix-map (kbd "C-x C-c") 'save-buffers-kill-emacs)
  1535. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1536. ;; x open
  1537. (defvar my-filer nil)
  1538. (setq my-filer (or (executable-find "pcmanfm")
  1539. (executable-find "nautilus")))
  1540. (defun my-x-open (file)
  1541. "open file."
  1542. (interactive "FOpen File: ")
  1543. (setq file (expand-file-name file))
  1544. (message "Opening %s..." file)
  1545. (cond ((eq system-type 'windows-nt)
  1546. (call-process "cmd.exe" nil 0 nil
  1547. "/c" "start" "" (convert-standard-filename file)))
  1548. ((eq system-type 'darwin)
  1549. (call-process "open" nil 0 nil file))
  1550. ((getenv "DISPLAY")
  1551. (call-process (or my-filer "xdg-open") nil 0 nil file))
  1552. (t
  1553. (find-file file))
  1554. )
  1555. ;; (recentf-add-file file)
  1556. (message "Opening %s...done" file))
  1557. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1558. ;; misc funcs
  1559. (defvar sed-in-place-history nil
  1560. "History of `sed-in-place'")
  1561. (defvar sed-in-place-command "sed --in-place=.bak -e")
  1562. (defun sed-in-place (command)
  1563. "sed in place"
  1564. (interactive (list (read-shell-command "sed in place: "
  1565. (concat sed-in-place-command " ")
  1566. 'sed-in-place-history)))
  1567. (shell-command command
  1568. "*sed in place*"))
  1569. (defun dired-do-sed-in-place (&optional arg)
  1570. "sed in place dired"
  1571. (interactive "P")
  1572. (require 'dired-aux)
  1573. (let* ((files (dired-get-marked-files t arg))
  1574. (expr (dired-mark-read-string "Run sed-in-place for %s: "
  1575. nil
  1576. 'sed-in-place
  1577. arg
  1578. files)))
  1579. (if (equal expr
  1580. "")
  1581. (error "No expression specified")
  1582. (shell-command (concat sed-in-place-command
  1583. " '"
  1584. expr
  1585. "' "
  1586. (mapconcat 'shell-quote-argument
  1587. files
  1588. " "))
  1589. "*sed in place*"))))
  1590. (defun dir-show (&optional dir)
  1591. (interactive)
  1592. (let ((bf (get-buffer-create "*dir show*"))
  1593. (list-directory-brief-switches "-C"))
  1594. (with-current-buffer bf
  1595. (list-directory (or nil
  1596. default-directory)
  1597. nil))
  1598. ))
  1599. (defun my-convmv-sjis2utf8-test ()
  1600. "run `convmv -r -f sjis -t utf8 *'
  1601. this is test, does not rename files"
  1602. (interactive)
  1603. (shell-command "convmv -r -f sjis -t utf8 *"))
  1604. (defun my-convmv-sjis2utf8-notest ()
  1605. "run `convmv -r -f sjis -t utf8 * --notest'"
  1606. (interactive)
  1607. (shell-command "convmv -r -f sjis -t utf8 * --notest"))
  1608. (defun kill-ring-save-buffer-file-name ()
  1609. "get current filename"
  1610. (interactive)
  1611. (let ((file buffer-file-name))
  1612. (if file
  1613. (progn (kill-new file)
  1614. (message file))
  1615. (message "not visiting file."))))
  1616. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1617. ;; ;; savage emacs
  1618. ;; ;; when enabled emacs fails to complete
  1619. ;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html
  1620. ;; (defadvice message (before message-for-stupid (arg &rest arg2) activate)
  1621. ;; (setq arg
  1622. ;; (concat arg
  1623. ;; (if (eq nil (string-match "\\. *$" arg)) ".")
  1624. ;; " Stupid!")))
  1625. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1626. ;; japanese input method
  1627. (defun my-load-scim ()
  1628. "use scim-bridge.el as japanese im."
  1629. ;; Load scim-bridge.
  1630. (when (require 'scim-bridge nil t)
  1631. ;; Turn on scim-mode automatically after loading .emacs
  1632. (add-hook 'after-init-hook 'scim-mode-on)
  1633. (setq scim-cursor-color "red")
  1634. (scim-define-preedit-key ?\^h t)
  1635. (scim-define-common-key ?\* nil)
  1636. (scim-define-common-key ?\^/ nil)))
  1637. (defun my-load-anthy ()
  1638. "use anthy.el as japanese im."
  1639. ;; anthy
  1640. (when (require 'anthy nil t)
  1641. (global-set-key
  1642. (kbd "<muhenkan>") (lambda () (interactive) (anthy-mode-off)))
  1643. (global-set-key (kbd "<henkan>") (lambda () (interactive) (anthy-mode-on)))
  1644. (when (>= emacs-major-version 23)
  1645. (setq anthy-accept-timeout 1))))
  1646. ;; quail
  1647. ;; aproposs input-method for some information
  1648. ;; (setq default-input-method "japanese")
  1649. (defun my-load-mozc-el ()
  1650. ""
  1651. (setq mozc-leim-title "[MZ]")
  1652. (when (require 'mozc nil t)
  1653. (setq defauit-input-method "japanese-mozc")
  1654. ))
  1655. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1656. ;; for windows
  1657. (defun start-ckw-bash ()
  1658. ""
  1659. (interactive)
  1660. (start-process
  1661. "ckw_bash"
  1662. nil
  1663. "C:/Documents and Settings/sr/Application Data/dbx/apps/ckw/ckw.exe"))
  1664. ;; command seems to have to be in c drive
  1665. (defun my-w32-add-export-path (&rest args)
  1666. ""
  1667. (mapcar (lambda (path)
  1668. (add-to-list 'exec-path (expand-file-name path)))
  1669. (reverse args))
  1670. (setenv "PATH"
  1671. (mapconcat 'convert-standard-filename
  1672. exec-path
  1673. ";")))
  1674. (when (eq system-type 'windows-nt)
  1675. ;; (setq scheme-program-name "\"c:/Program Files/Gauche/bin/gosh.exe\" -i")
  1676. ;; (setq python-python-command "c:/Python26/python.exe")
  1677. (define-key my-prefix-map (kbd "C-c") 'start-ckw-bash)
  1678. (my-w32-add-export-path "c:/Windows/system"
  1679. "c:/Windows/System32"
  1680. "c:/Program Files/Git/bin"
  1681. "c:/MinGW/bin"
  1682. "c:/MinGW/mingw32/bin"
  1683. (expand-file-name "~/.local/bin")
  1684. (expand-file-name "~/dbx/apps/bin"))
  1685. (when window-system
  1686. (setq w32-enable-synthesized-fonts t))
  1687. (setq file-name-coding-system 'sjis))