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

emacs.el 68 KiB

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