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

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