Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

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