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

emacs.el 65 KiB

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