您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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