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

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