Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

.emacs 64 KiB

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