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