選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

emacs.el 63 KiB

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