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

12 anni fa
13 anni fa
12 anni fa
13 anni fa
13 anni fa
12 anni fa
12 anni fa
12 anni fa
13 anni fa
13 anni fa
12 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
12 anni fa
12 anni fa
13 anni fa
13 anni fa
13 anni fa
12 anni fa
12 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
12 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
12 anni fa
12 anni fa
12 anni fa
12 anni fa
13 anni fa
12 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
12 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
12 anni fa
13 anni fa
12 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
12 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
12 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
12 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
12 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
12 anni fa
12 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968
  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. (and window-system
  123. (dllib-if-unfound
  124. "https://raw.github.com/10sr/emacs-lisp/master/save-window-size.el"
  125. t)
  126. (require 'save-window-size nil t))
  127. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  128. ;; global keys
  129. (global-set-key (kbd "<up>") (lambda() (interactive) (scroll-down 1)))
  130. (global-set-key (kbd "<down>") (lambda() (interactive) (scroll-up 1)))
  131. (global-set-key (kbd "<left>") 'scroll-down)
  132. (global-set-key (kbd "<right>") 'scroll-up)
  133. (define-key my-prefix-map (kbd "C-o") 'occur)
  134. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  135. (global-set-key (kbd "C-\\") help-map)
  136. (define-key ctl-x-map (kbd "DEL") help-map)
  137. (define-key ctl-x-map (kbd "C-h") help-map)
  138. (define-key help-map "a" 'apropos)
  139. ;; compose window
  140. (global-set-key [?\C--] 'other-window)
  141. (global-set-key [?\C-0] 'delete-window)
  142. (global-set-key [?\C-1] 'delete-other-windows)
  143. (global-set-key [?\C-2] 'split-window-vertically)
  144. (global-set-key [?\C-3] 'split-window-horizontally)
  145. ;; disable annoying keys
  146. (global-set-key [prior] 'ignore)
  147. (global-set-key (kbd "<next>") 'ignore)
  148. (global-set-key [menu] 'ignore)
  149. (global-set-key [down-mouse-1] 'ignore)
  150. (global-set-key [down-mouse-2] 'ignore)
  151. (global-set-key [down-mouse-3] 'ignore)
  152. (global-set-key [mouse-1] 'ignore)
  153. (global-set-key [mouse-2] 'ignore)
  154. (global-set-key [mouse-3] 'ignore)
  155. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  156. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  157. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  158. ;; title and mode-line
  159. (setq eol-mnemonic-dos "crlf")
  160. (setq eol-mnemonic-mac "cr")
  161. (setq eol-mnemonic-unix "lf")
  162. (which-function-mode 0)
  163. (line-number-mode 0)
  164. (column-number-mode 0)
  165. (size-indication-mode 0)
  166. (setq mode-line-position
  167. '(:eval (format "L%%l/%d,C%%c"
  168. (count-lines (point-max)
  169. (point-min)))))
  170. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  171. ;; display date
  172. (add-hook 'after-init-hook
  173. (lambda ()
  174. (when display-time-mode
  175. (display-time-update))
  176. ))
  177. (setq display-time-interval 29)
  178. (setq display-time-day-and-date t)
  179. (setq display-time-format "%a, %d %b %Y %T")
  180. (if window-system
  181. (display-time-mode 0)
  182. (display-time-mode 1))
  183. ;; ;; current directory
  184. ;; (let ((ls (member 'mode-line-buffer-identification
  185. ;; mode-line-format)))
  186. ;; (setcdr ls
  187. ;; (cons '(:eval (concat " ("
  188. ;; (abbreviate-file-name default-directory)
  189. ;; ")"))
  190. ;; (cdr ls))))
  191. ;; ;; display last modified time
  192. ;; (let ((ls (member 'mode-line-buffer-identification
  193. ;; mode-line-format)))
  194. ;; (setcdr ls
  195. ;; (cons '(:eval (concat " "
  196. ;; my-buffer-file-last-modified-time))
  197. ;; (cdr ls))))
  198. '(setq-default header-line-format (list " "
  199. 'display-time-string))
  200. (defvar set-terminal-title-term-regexp ""
  201. "Rexexp for `set-terminal-title'.")
  202. (setq set-terminal-title-term-regexp "^\\(rxvt\\|xterm\\|aterm$\\|screen\\)")
  203. (defun set-terminal-title (&rest args)
  204. ""
  205. (interactive "sString to set as title: ")
  206. (let ((tty (frame-parameter nil
  207. 'tty-type)))
  208. (when (and tty
  209. (string-match set-terminal-title-term-regexp
  210. tty))
  211. (send-string-to-terminal (apply 'concat
  212. "\033]0;"
  213. `(,@args "\007"))))))
  214. (defun my-set-terminal-title ()
  215. ""
  216. (set-terminal-title "["
  217. user-login-name
  218. "@"
  219. system-name
  220. ":"
  221. (abbreviate-file-name (or buffer-file-name
  222. default-directory))
  223. "]["
  224. invocation-name
  225. " "
  226. emacs-version
  227. " "
  228. (symbol-name system-type)
  229. "]["
  230. "FRAME:"
  231. (frame-parameter nil 'name)
  232. ":"
  233. (number-to-string (length
  234. (buffer-list-not-start-with-space)))
  235. "]"
  236. ))
  237. (add-hook 'buffer-file-changed-functions
  238. (lambda (p c)
  239. (my-set-terminal-title)))
  240. (add-hook 'suspend-resume-hook
  241. 'my-set-terminal-title)
  242. (defun buffer-list-not-start-with-space ()
  243. (let ((bl (buffer-list))
  244. b nbl)
  245. (while bl
  246. (setq b (pop bl))
  247. (unless (string-equal " "
  248. (substring (buffer-name b)
  249. 0
  250. 1))
  251. (add-to-list 'nbl b)))
  252. nbl))
  253. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  254. ;; minibuffer
  255. (setq insert-default-directory t)
  256. (setq completion-ignore-case t
  257. read-file-name-completion-ignore-case t
  258. read-buffer-completion-ignore-case t)
  259. (setq resize-mini-window t)
  260. (temp-buffer-resize-mode 1)
  261. (savehist-mode 1)
  262. (fset 'yes-or-no-p 'y-or-n-p)
  263. ;; complete symbol when `eval'
  264. (define-key read-expression-map (kbd "TAB") 'lisp-complete-symbol)
  265. (define-key minibuffer-local-map (kbd "C-u")
  266. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  267. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  268. ;; letters, font-lock mode and fonts
  269. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  270. (and (or (eq system-type 'Darwin)
  271. (eq system-type 'darwin))
  272. (fboundp 'mac-set-input-method-parameter)
  273. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  274. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  275. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  276. (boundp 'input-method-inactivate-hook))
  277. (add-hook 'input-method-activate-hook
  278. (lambda () (set-cursor-color "red")))
  279. (add-hook 'input-method-inactivate-hook
  280. (lambda () (set-cursor-color "black"))))
  281. (show-paren-mode 1)
  282. (setq show-paren-delay 0.5
  283. show-paren-style 'parenthesis) ; mixed is hard to read
  284. (set-face-background 'show-paren-match
  285. (face-foreground 'default))
  286. (set-face-inverse-video-p 'show-paren-match
  287. t)
  288. (transient-mark-mode 1)
  289. (global-font-lock-mode 1)
  290. (setq font-lock-global-modes
  291. '(not
  292. help-mode
  293. eshell-mode
  294. term-mode
  295. Man-mode))
  296. ;; (standard-display-ascii ?\n "$\n")
  297. (defvar my-eol-face
  298. '(("\n" . (0 font-lock-comment-face t nil)))
  299. )
  300. (defvar my-tab-face
  301. '(("\t" . '(0 highlight t nil))))
  302. (defvar my-jspace-face
  303. '(("\u3000" . '(0 highlight t nil))))
  304. (add-hook 'font-lock-mode-hook
  305. (lambda ()
  306. ;; (font-lock-add-keywords nil my-eol-face)
  307. (font-lock-add-keywords nil my-jspace-face)
  308. ))
  309. (when (require 'whitespace nil t)
  310. (setq whitespace-style '(face
  311. trailing ; trailing blanks
  312. newline ; newlines
  313. newline-mark ; use display table for newline
  314. empty ; empty lines at beg or end of buffer
  315. lines-tail ; lines over 80
  316. ))
  317. ;; (setq whitespace-newline 'font-lock-comment-face)
  318. (add-to-list 'whitespace-display-mappings
  319. `(newline-mark ?\n ,(vconcat "$\n"))
  320. )
  321. (global-whitespace-mode t))
  322. (and nil
  323. (dllib-if-unfound
  324. "http://www.emacswiki.org/emacs/download/fill-column-indicator.el"
  325. t)
  326. (require 'fill-column-indicator nil t)
  327. (setq fill-column-indicator))
  328. ;; highlight current line
  329. ;; http://wiki.riywo.com/index.php?Meadow
  330. (defface hlline-face
  331. '((((type x w32)
  332. (class color)
  333. (background dark))
  334. (:background "midnightblue"))
  335. (((type x w32)
  336. (class color)
  337. (background light))
  338. (:background "gainsboro"))
  339. (t
  340. (:underline "black")))
  341. "*Face used by hl-line.")
  342. ;; (defface hlline-ul-face
  343. ;; '((t (:underline "yellow")))
  344. ;; "underline yellow")
  345. (setq hl-line-face 'hlline-face) ;; (setq hl-line-face nil)
  346. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  347. (setq hl-line-global-modes
  348. '(not
  349. term-mode))
  350. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  351. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  352. ;; fonts
  353. (defun my-set-ascii-and-jp-font (list)
  354. ""
  355. (if (> emacs-major-version 22) ;; font spec is available in emacs23 and later
  356. (progn ; 23 or later
  357. (set-face-attribute 'default nil
  358. :family (nth 0 list)
  359. :height (nth 1 list))
  360. (set-fontset-font "fontset-default"
  361. 'japanese-jisx0208
  362. (font-spec :family (nth 2 list) :size (nth 3 list)))
  363. (set-fontset-font "fontset-default"
  364. 'katakana-jisx0201
  365. (font-spec :family (nth 2 list) :size (nth 3 list))))
  366. (progn ; 22
  367. (set-face-attribute 'default nil
  368. :family (nth 0 list)
  369. :height (nth 1 list))
  370. (set-fontset-font "fontset-default"
  371. 'japanese-jisx0208
  372. (cons (nth 2 list) "jisx0208.*"))
  373. (set-fontset-font "fontset-default"
  374. 'katakana-jisx0201
  375. (cons (nth 2 list) "jisx0201.*"))
  376. )))
  377. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 90 "takaogothic" 13))
  378. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 100 "takaogothic" 14))
  379. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 100 "ms gothic" 14))
  380. ;; (my-set-ascii-and-jp-font '("monaco" 75 "takaogothic" 11))
  381. ;; (my-set-ascii-and-jp-font '("monaco" 90 "takaogothic" 13))
  382. ;; (my-set-ascii-and-jp-font '("ProggyCleanTTSZ" 120 "takaogothic" 11))
  383. ;; あ a
  384. (and (dllib-if-unfound
  385. "https://raw.github.com/10sr/emacs-lisp/master/set-modeline-color.el"
  386. t)
  387. (progn
  388. (require 'set-modeline-color nil t)))
  389. (let ((fg (face-foreground 'default))
  390. (bg (face-background 'default)))
  391. (set-face-background 'mode-line-inactive
  392. (if (face-inverse-video-p 'mode-line) fg bg))
  393. (set-face-foreground 'mode-line-inactive
  394. (if (face-inverse-video-p 'mode-line) bg fg)))
  395. (set-face-underline-p 'mode-line-inactive
  396. t)
  397. (set-face-underline-p 'vertical-border
  398. nil)
  399. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  400. ;; file handling
  401. (setq revert-without-query '(".+"))
  402. ;; save cursor position
  403. (setq save-place-file (concat user-emacs-directory
  404. "places"))
  405. (when (require 'saveplace nil t)
  406. (setq-default save-place t))
  407. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  408. (setq make-backup-files t)
  409. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  410. (setq backup-directory-alist
  411. (cons (cons "\\.*$" (expand-file-name "~/.emacs.d/backup"))
  412. backup-directory-alist))
  413. (setq version-control 'never)
  414. (setq delete-old-versions t)
  415. (setq auto-save-list-file-prefix (expand-file-name "~/.emacs.d/autosave/"))
  416. (setq delete-auto-save-files t)
  417. (add-to-list 'completion-ignored-extensions ".bak")
  418. ;; (setq delete-by-moving-to-trash t
  419. ;; trash-directory "~/.emacs.d/trash")
  420. (add-hook 'after-save-hook
  421. 'executable-make-buffer-file-executable-if-script-p)
  422. (setq bookmark-default-file "~/.emacs.d/bmk")
  423. (and (dllib-if-unfound
  424. "https://github.com/10sr/emacs-lisp/raw/master/read-only-only-mode.el"
  425. t)
  426. (require 'read-only-only-mode nil t))
  427. (and (dllib-if-unfound
  428. "https://raw.github.com/10sr/emacs-lisp/master/smart-revert.el"
  429. t)
  430. (require 'smart-revert nil t)
  431. (smart-revert-on)
  432. )
  433. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  434. ;; editting
  435. (setq require-final-newline t)
  436. (setq kill-whole-line t)
  437. (setq scroll-conservatively 35
  438. scroll-margin 2
  439. scroll-step 0)
  440. (setq default-major-mode 'text-mode)
  441. (setq next-line-add-newlines nil)
  442. (setq kill-read-only-ok t)
  443. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  444. ;; (setq-default line-spacing 0.2)
  445. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  446. (setq-default tab-width 4)
  447. (setq-default indent-tabs-mode nil)
  448. (setq-default indent-line-function nil)
  449. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  450. (delete-selection-mode 1)
  451. (cua-mode 0)
  452. (setq line-move-visual nil)
  453. ;; key bindings
  454. ;; moving around
  455. ;; (global-set-key (kbd "M-j") 'next-line)
  456. ;; (global-set-key (kbd "M-k") 'previous-line)
  457. ;; (global-set-key (kbd "M-h") 'backward-char)
  458. ;; (global-set-key (kbd "M-l") 'forward-char)
  459. ;;(keyboard-translate ?\M-j ?\C-j)
  460. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  461. (define-key esc-map "p" 'backward-paragraph)
  462. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  463. (define-key esc-map "n" 'forward-paragraph)
  464. (global-set-key (kbd "C-<up>") (lambda () (interactive)(scroll-down 1)))
  465. (global-set-key (kbd "C-<down>") (lambda () (interactive)(scroll-up 1)))
  466. (global-set-key (kbd "C-<left>") 'scroll-down)
  467. (global-set-key (kbd "C-<right>") 'scroll-up)
  468. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  469. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  470. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  471. ;; C-h and DEL
  472. (global-set-key (kbd "C-h") (kbd "DEL"))
  473. (global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  474. (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  475. (define-key esc-map "k" 'my-copy-whole-line)
  476. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  477. (define-key esc-map "u" 'undo)
  478. (define-key esc-map "i" (kbd "ESC TAB"))
  479. ;(global-set-key (kbd "C-r") 'query-replace-regexp)
  480. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  481. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  482. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  483. ;; gmail
  484. (setq mail-interactive t
  485. send-mail-function 'smtpmail-send-it
  486. ;; message-send-mail-function 'smtpmail-send-it
  487. smtpmail-smtp-server "smtp.gmail.com"
  488. smtpmail-smtp-service 587
  489. smtpmail-starttls-credentials '(("smtp.gmail.com" 587
  490. "8.slashes@gmail.com" nil))
  491. smtpmail-auth-credentials '(("smtp.gmail.com" 587
  492. "8.slashes@gmail.com" nil))
  493. user-mail-address "8.slashes@gmail.com")
  494. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  495. ;; buffer killing
  496. (defun my-delete-window-killing-buffer () nil)
  497. (defun my-query-kill-this-buffer ()
  498. ""
  499. (interactive)
  500. (if (y-or-n-p (concat "kill this buffer? :"))
  501. (kill-buffer (current-buffer))))
  502. (substitute-key-definition 'kill-buffer 'my-query-kill-this-buffer global-map)
  503. ;;(global-set-key "\C-xk" 'my-query-kill-this-buffer)
  504. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  505. ;; share clipboard with x
  506. ;; this page describes this in details, but only these sexps seem to be needed
  507. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  508. (and (not window-system)
  509. (not (eq window-system 'mac))
  510. (getenv "DISPLAY")
  511. (not (equal (getenv "DISPLAY") ""))
  512. (executable-find "xclip")
  513. ;; (< emacs-major-version 24)
  514. (dllib-if-unfound "http://www.emacswiki.org/emacs/download/xclip.el" t)
  515. (require 'xclip nil t)
  516. (turn-on-xclip))
  517. (and (eq system-type 'darwin)
  518. (dllib-if-unfound
  519. "https://raw.github.com/10sr/emacs-lisp/master/pasteboard.el"
  520. t)
  521. (require 'pasteboard nil t)
  522. (turn-on-pasteboard))
  523. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  524. ;; package
  525. (when (require 'package nil t)
  526. (add-to-list 'package-archives
  527. '("melpa" . "http://melpa.milkbox.net/packages/")
  528. t)
  529. (add-to-list 'package-archives
  530. '("marmalade" . "http://marmalade-repo.org/packages/"))
  531. (add-to-list 'package-archives
  532. '("ELPA" . "http://tromey.com/elpa/"))
  533. (package-initialize))
  534. (require 'sudoku nil t)
  535. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  536. ;; some modes and hooks
  537. (require 'simple nil t)
  538. (defun make ()
  539. "Run \"make -k \" in current directory."
  540. (interactive)
  541. (compile "make -k"))
  542. (add-hook 'verilog-mode-hook
  543. (lambda ()
  544. (define-key verilog-mode-map ";" 'self-insert-command)))
  545. (setq diff-switches "-u")
  546. (add-hook 'diff-mode-hook
  547. (lambda ()
  548. (view-mode 1)
  549. (set-face-attribute 'diff-header nil
  550. :foreground nil
  551. :background nil
  552. :weight 'bold)
  553. (set-face-attribute 'diff-file-header nil
  554. :foreground nil
  555. :background nil
  556. :weight 'bold)
  557. (set-face-foreground 'diff-index-face "blue")
  558. (set-face-attribute 'diff-hunk-header nil
  559. :foreground "cyan"
  560. :weight 'normal)
  561. (set-face-attribute 'diff-context nil
  562. ;; :foreground "white"
  563. :foreground nil
  564. :weight 'normal)
  565. (set-face-foreground 'diff-removed-face "red")
  566. (set-face-foreground 'diff-added-face "green")
  567. (set-face-attribute 'diff-changed nil
  568. :foreground "magenta"
  569. :weight 'normal)
  570. ))
  571. ;; (ffap-bindings)
  572. (add-hook 'sh-mode-hook
  573. (lambda ()
  574. (define-key sh-mode-map
  575. (kbd "C-x C-e")
  576. 'my-execute-shell-command-current-line)))
  577. (defun my-execute-shell-command-current-line ()
  578. ""
  579. (interactive)
  580. (shell-command (buffer-substring-no-properties (point-at-bol)
  581. (point))))
  582. (setq auto-mode-alist
  583. `(("autostart\\'" . sh-mode)
  584. ("xinitrc\\'" . sh-mode)
  585. ("xprograms\\'" . sh-mode)
  586. ("PKGBUILD\\'" . sh-mode)
  587. ,@auto-mode-alist))
  588. (when (locate-library "pkgbuild-mode")
  589. (autoload 'pkgbuild-mode "pkgbuild-mode.el" "PKGBUILD mode." t)
  590. (setq auto-mode-alist (append '(("PKGBUILD\\'" . pkgbuild-mode))
  591. auto-mode-alist)))
  592. (add-hook 'text-mode-hook
  593. (lambda ()
  594. (define-key text-mode-map (kbd "C-m") 'newline)))
  595. (add-to-list 'Info-default-directory-list (expand-file-name "~/.info/emacs-ja"))
  596. (add-hook 'apropos-mode-hook
  597. (lambda ()
  598. (define-key apropos-mode-map "n" 'next-line)
  599. (define-key apropos-mode-map "p" 'previous-line)
  600. ))
  601. (add-hook 'isearch-mode-hook
  602. (lambda ()
  603. ;; (define-key isearch-mode-map
  604. ;; (kbd "C-j") 'isearch-other-control-char)
  605. ;; (define-key isearch-mode-map
  606. ;; (kbd "C-k") 'isearch-other-control-char)
  607. ;; (define-key isearch-mode-map
  608. ;; (kbd "C-h") 'isearch-other-control-char)
  609. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  610. (define-key isearch-mode-map (kbd "M-r")
  611. 'isearch-query-replace-regexp)))
  612. (add-hook 'outline-mode-hook
  613. (lambda ()
  614. (if (string-match "\\.md\\'" buffer-file-name)
  615. (set (make-local-variable 'outline-regexp) "#+ "))))
  616. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  617. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  618. (setq markdown-command (or (executable-find "markdown")
  619. (executable-find "markdown.pl")))
  620. (when (dllib-if-unfound
  621. "http://jblevins.org/projects/markdown-mode/markdown-mode.el"
  622. t)
  623. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'markdown-mode))
  624. (autoload 'markdown-mode
  625. "markdown-mode" "Major mode for editing Markdown files." nil)
  626. (add-hook 'markdown-mode-hook
  627. (lambda ()
  628. (outline-minor-mode 1)
  629. (set (make-local-variable 'comment-start) ";"))))
  630. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  631. ;; c-mode
  632. ;; (setq c-default-style "bsd")
  633. (add-hook 'c-mode-common-hook
  634. (lambda ()
  635. (setq c-basic-offset 2
  636. indent-tabs-mode nil)
  637. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  638. (c-toggle-hungry-state -1)
  639. (and (require 'gtags nil t)
  640. (gtags-mode 1))
  641. ))
  642. (when (dllib-if-unfound
  643. "https://raw.github.com/mooz/js2-mode/master/js2-mode.el"
  644. t)
  645. (autoload 'js2-mode "js2-mode" nil t)
  646. (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  647. (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode)))
  648. ;; (add-hook 'js2-mode-hook
  649. ;; (lambda ()
  650. ;; (add-hook 'before-save-hook
  651. ;; 'my-indent-buffer
  652. ;; nil
  653. ;; t)))
  654. (add-hook 'js2-mode-hook
  655. (lambda ()
  656. (define-key js2-mode-map (kbd "C-m") (lambda ()
  657. (interactive)
  658. (js2-enter-key)
  659. (indent-for-tab-command)))
  660. (add-hook (kill-local-variable 'before-save-hook)
  661. 'js2-before-save)))
  662. (and nil
  663. (require 'zone nil t)
  664. (not (eq system-type 'windows-nt))
  665. ;; (zone-when-idle 180)
  666. (run-with-idle-timer 180 t (lambda ()
  667. (unless (memq major-mode
  668. '(term-mode))
  669. (zone)))))
  670. (when (require 'uniquify nil t)
  671. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  672. (setq uniquify-ignore-buffers-re "*[^*]+*")
  673. (setq uniquify-min-dir-content 1))
  674. (add-hook 'view-mode-hook
  675. (lambda()
  676. (define-key view-mode-map "j"
  677. (lambda() (interactive) (scroll-up 1)))
  678. (define-key view-mode-map "k"
  679. (lambda() (interactive) (scroll-down 1)))
  680. (define-key view-mode-map "v" 'toggle-read-only)
  681. (define-key view-mode-map "q" 'bury-buffer)
  682. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  683. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  684. ;; (define-key view-mode-map
  685. ;; "n" 'nonincremental-repeat-search-forward)
  686. ;; (define-key view-mode-map
  687. ;; "N" 'nonincremental-repeat-search-backward)
  688. (define-key view-mode-map "/" 'isearch-forward-regexp)
  689. (define-key view-mode-map "?" 'isearch-backward-regexp)
  690. (define-key view-mode-map "n" 'isearch-repeat-forward)
  691. (define-key view-mode-map "N" 'isearch-repeat-backward)
  692. ))
  693. (global-set-key "\M-r" 'view-mode)
  694. (setq view-read-only t)
  695. (add-hook 'Man-mode-hook
  696. (lambda ()
  697. (view-mode 1)
  698. (setq truncate-lines nil)))
  699. (setq Man-notify-method (if window-system
  700. 'newframe
  701. 'pushy))
  702. (require 'session nil t)
  703. (and (dllib-if-unfound "https://raw.github.com/10sr/emacs-lisp/master/gtkbm.el"
  704. t)
  705. (require 'gtkbm nil t)
  706. (global-set-key (kbd "C-x C-d") 'gtkbm))
  707. (and (dllib-if-unfound
  708. "https://raw.github.com/10sr/emacs-lisp/master/git-command.el"
  709. t)
  710. (require 'git-command nil t)
  711. (define-key ctl-x-map "g" 'git-command))
  712. (and (dllib-if-unfound
  713. "http://www.emacswiki.org/emacs/download/sl.el"
  714. t)
  715. (require 'sl nil t))
  716. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  717. ;; python
  718. (setq python-python-command (or (executable-find "python3")
  719. (executable-find "python")))
  720. (defun my-python-run-as-command ()
  721. ""
  722. (interactive)
  723. (shell-command (concat python-python-command " " buffer-file-name)))
  724. (defun my-python-display-python-buffer ()
  725. ""
  726. (interactive)
  727. (set-window-text-height (display-buffer python-buffer
  728. t)
  729. 7))
  730. (add-hook 'python-mode-hook
  731. (lambda ()
  732. (define-key python-mode-map
  733. (kbd "C-c C-e") 'my-python-run-as-command)
  734. (define-key python-mode-map
  735. (kbd "C-c C-b") 'my-python-display-python-buffer)
  736. (define-key python-mode-map (kbd "C-m") 'newline-and-indent)))
  737. (add-hook 'inferior-python-mode-hook
  738. (lambda ()
  739. (my-python-display-python-buffer)
  740. (define-key inferior-python-mode-map
  741. (kbd "<up>") 'comint-previous-input)
  742. (define-key inferior-python-mode-map
  743. (kbd "<down>") 'comint-next-input)))
  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. ("aptin" "apt-get install $*")
  1357. ("eless"
  1358. (concat "cat >>> (with-current-buffer "
  1359. "(get-buffer-create \"*eshell output\") "
  1360. "(erase-buffer) "
  1361. "(setq buffer-read-only nil) "
  1362. "(current-buffer)) "
  1363. "(view-buffer (get-buffer \"*eshell output*\"))")
  1364. ("g" "git $*")
  1365. ))
  1366. )))
  1367. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1368. ;; get last modified date
  1369. (defvar my-buffer-file-last-modified-time nil "")
  1370. (make-variable-buffer-local 'my-buffer-file-last-modified-time)
  1371. (defun my-get-file-last-modified-time (file)
  1372. ""
  1373. (nth 5
  1374. (file-attributes file)))
  1375. (defun my-set-buffer-file-last-modified-time ()
  1376. ""
  1377. (make-local-variable 'my-buffer-file-last-modified-time)
  1378. (setq my-buffer-file-last-modified-time
  1379. (format-time-string "%Y/%m/%d %H:%M"
  1380. (my-get-file-last-modified-time buffer-file-name))))
  1381. (add-hook 'find-file-hook
  1382. 'my-set-buffer-file-last-modified-time)
  1383. (add-hook 'after-save-hook
  1384. 'my-set-buffer-file-last-modified-time)
  1385. (add-hook 'after-revert-hook
  1386. 'my-set-buffer-file-last-modified-time)
  1387. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1388. ;; frame buffer
  1389. ;; todo:
  1390. ;; work well when opening the file that was already opened on another window
  1391. (add-hook 'after-make-frame-functions
  1392. (lambda (f)
  1393. (set-window-buffer (frame-selected-window f)
  1394. "*Messages*")))
  1395. (defun make-frame-command-with-name (name)
  1396. "Make frame with name specified."
  1397. (interactive "sName for new frame: ")
  1398. (set-frame-parameter (make-frame-command)
  1399. 'name
  1400. name))
  1401. (defvar my-frame-buffer-plist nil)
  1402. (defun my-frame-buffer-add (&optional buf frame)
  1403. ""
  1404. (setq my-frame-buffer-plist
  1405. (plist-put my-frame-buffer-plist
  1406. (or frame
  1407. (selected-frame))
  1408. (let ((lst (my-frame-buffer-get frame)))
  1409. (if lst
  1410. (add-to-list 'lst
  1411. (or buf
  1412. (current-buffer)))
  1413. (list (or buf
  1414. (current-buffer))))))))
  1415. (defun my-frame-buffer-remove (&optional buf frame)
  1416. ""
  1417. (setq my-frame-buffer-plist
  1418. (plist-put my-frame-buffer-plist
  1419. (or frame
  1420. (selected-frame))
  1421. (delq (or buf
  1422. (current-buffer))
  1423. (my-frame-buffer-get frame)))))
  1424. (defun my-frame-buffer-get (&optional frame)
  1425. ""
  1426. (plist-get my-frame-buffer-plist
  1427. (or frame
  1428. (selected-frame))))
  1429. (defun my-frame-buffer-kill-all-buffer (&optional frame)
  1430. ""
  1431. (mapcar 'kill-buffer
  1432. (my-frame-buffer-get frame)))
  1433. (add-hook 'find-file-hook
  1434. 'my-frame-buffer-add)
  1435. (add-hook 'term-mode-hook
  1436. 'my-frame-buffer-add)
  1437. (add-hook 'eshell-mode-hook
  1438. 'my-frame-buffer-add)
  1439. (add-hook 'Man-mode-hook
  1440. 'my-frame-buffer-add)
  1441. (add-hook 'kill-buffer-hook
  1442. 'my-frame-buffer-remove)
  1443. (add-hook 'delete-frame-functions
  1444. 'my-frame-buffer-kill-all-buffer)
  1445. (defvar my-desktop-terminal "roxterm")
  1446. (defun my-execute-terminal ()
  1447. ""
  1448. (interactive)
  1449. (if (and (or (eq system-type 'windows-nt)
  1450. window-system)
  1451. my-desktop-terminal
  1452. )
  1453. (let ((process-environment (cons "TERM=xterm" process-environment)))
  1454. (start-process "terminal"
  1455. nil
  1456. my-desktop-terminal))
  1457. (my-term)))
  1458. (defun my-term ()
  1459. "open terminal buffer and return that buffer."
  1460. (interactive)
  1461. (if (eq system-type 'windows-nt)
  1462. (eshell t)
  1463. (if (featurep 'multi-term)
  1464. (multi-term)
  1465. (ansi-term "/bin/bash"))))
  1466. (defun my-delete-frame-or-kill-emacs ()
  1467. "delete frame when opening multiple frame, kill emacs when only one."
  1468. (interactive)
  1469. (if (eq 1
  1470. (length (frame-list)))
  1471. (save-buffers-kill-emacs)
  1472. (delete-frame)))
  1473. (define-key my-prefix-map (kbd "C-s") 'my-execute-terminal)
  1474. (define-key my-prefix-map (kbd "C-f") 'make-frame-command-with-name)
  1475. (global-set-key (kbd "C-x C-c") 'my-delete-frame-or-kill-emacs)
  1476. (define-key my-prefix-map (kbd "C-x C-c") 'save-buffers-kill-emacs)
  1477. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1478. ;; auto saving
  1479. (defun my-save-current-buffer (silent-p)
  1480. "save current buffer if can without asking"
  1481. (let ((cm (if (current-message)
  1482. (format "%s\n" (current-message))
  1483. ""))
  1484. (fun (symbol-function (if silent-p
  1485. 'ignore
  1486. 'message))))
  1487. (cond ((active-minibuffer-window) nil)
  1488. ((not buffer-file-name)
  1489. (funcall fun
  1490. "%ssaving... this buffer doesn't visit any file." cm)
  1491. nil)
  1492. ((not (file-exists-p buffer-file-name))
  1493. (funcall fun
  1494. "%ssaving... file not exist. save manually first." cm)
  1495. nil)
  1496. (buffer-read-only
  1497. (funcall fun
  1498. "%ssaving... this buffer is read-only." cm)
  1499. nil)
  1500. ((not (buffer-modified-p))
  1501. (funcal fun
  1502. "%ssaving... not modified yet." cm)
  1503. nil)
  1504. ((not (file-writable-p buffer-file-name))
  1505. (funcall fun
  1506. "%ssaving... you cannot change this file." cm)
  1507. nil)
  1508. (t (funcall fun "%ssaving..." cm)
  1509. (save-buffer)
  1510. (funcall fun "%ssaving... done." cm)))))
  1511. ;; (if (and buffer-file-name
  1512. ;; (not buffer-read-only)
  1513. ;; (buffer-modified-p)
  1514. ;; (file-writable-p buffer-file-name))
  1515. ;; (save-buffer))) ; silent one
  1516. (defvar my-auto-save-current-buffer nil "auto save timer object")
  1517. (defun my-auto-save-current-buffer (sec &optional silent-p)
  1518. "auto save current buffer if idle for SEC.
  1519. when SEC is nil, stop auto save if enabled."
  1520. (if sec
  1521. (progn (when my-auto-save-current-buffer
  1522. (cancel-timer my-auto-save-current-buffer)
  1523. (setq my-auto-save-current-buffer nil))
  1524. (setq my-auto-save-current-buffer
  1525. (run-with-idle-timer sec t 'my-save-current-buffer silent-p)))
  1526. (when my-auto-save-current-buffer
  1527. (cancel-timer my-auto-save-current-buffer)
  1528. (setq my-auto-save-current-buffer nil))))
  1529. (my-auto-save-current-buffer 2 t)
  1530. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1531. ;; misc funcs
  1532. (defun dir-show (&optional dir)
  1533. (interactive)
  1534. (let ((bf (get-buffer-create "*dir show*"))
  1535. (list-directory-brief-switches "-C"))
  1536. (with-current-buffer bf
  1537. (list-directory (or nil
  1538. default-directory)
  1539. nil))
  1540. ))
  1541. (defalias 'qcalc 'quick-calc)
  1542. (defun my-kill-buffers ()
  1543. ""
  1544. (interactive)
  1545. (mapcar (lambda (buf)
  1546. (when (buffer-file-name buf)
  1547. (kill-buffer buf)))
  1548. (buffer-list)))
  1549. (defvar my-filer nil)
  1550. (setq my-filer (or (executable-find "pcmanfm")
  1551. (executable-find "nautilus")))
  1552. (defun my-x-open (file)
  1553. "open file."
  1554. (interactive "FOpen File: ")
  1555. (setq file (expand-file-name file))
  1556. (message "Opening %s..." file)
  1557. (cond ((eq system-type 'windows-nt)
  1558. (call-process "cmd.exe" nil 0 nil
  1559. "/c" "start" "" (convert-standard-filename file)))
  1560. ((eq system-type 'darwin)
  1561. (call-process "open" nil 0 nil file))
  1562. ((getenv "DISPLAY")
  1563. (call-process (or my-filer "xdg-open") nil 0 nil file))
  1564. (t
  1565. (find-file file))
  1566. )
  1567. ;; (recentf-add-file file)
  1568. (message "Opening %s...done" file))
  1569. (defun my-keyboard-quit ()
  1570. ""
  1571. (interactive)
  1572. (run-hooks 'before-keyboard-quit-hook)
  1573. ;; (redisplay t)
  1574. (redraw-display)
  1575. ;; (run-hooks 'window-configuration-change-hook)
  1576. (keyboard-quit)
  1577. (insert "insert me")
  1578. (run-hooks 'after-keyboard-quit-hook))
  1579. (substitute-key-definition 'keyboard-quit 'my-keyboard-quit global-map)
  1580. ;; (global-set-key (kbd "C-g") 'my-keyboard-quit)
  1581. (defun my-convmv-sjis2utf8-test ()
  1582. "run `convmv -r -f sjis -t utf8 *'
  1583. this is test, does not rename files"
  1584. (interactive)
  1585. (shell-command "convmv -r -f sjis -t utf8 *"))
  1586. (defun my-convmv-sjis2utf8-notest ()
  1587. "run `convmv -r -f sjis -t utf8 * --notest'"
  1588. (interactive)
  1589. (shell-command "convmv -r -f sjis -t utf8 * --notest"))
  1590. (defun my-copy-whole-line ()
  1591. ""
  1592. (interactive)
  1593. (kill-new (concat (buffer-substring (point-at-bol)
  1594. (point-at-eol))
  1595. "\n")))
  1596. (defun kill-ring-save-buffer-file-name ()
  1597. "get current filename"
  1598. (interactive)
  1599. (let ((file buffer-file-name))
  1600. (if file
  1601. (progn (kill-new file)
  1602. (message file))
  1603. (message "not visiting file."))))
  1604. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1605. ;; forked from http://d.hatena.ne.jp/khiker/20100119/window_resize
  1606. (define-key my-prefix-map (kbd "C-w") 'my-window-organizer)
  1607. (defun my-window-organizer ()
  1608. "Control window size and position."
  1609. (interactive)
  1610. (save-selected-window
  1611. (select-window (window-at 0 0))
  1612. (let ( ;; (window-obj (selected-window))
  1613. ;; (current-width (window-width))
  1614. ;; (current-height (window-height))
  1615. action
  1616. c)
  1617. (catch 'end-flag
  1618. (while t
  1619. (setq action
  1620. (read-key-sequence-vector
  1621. (format "size[%dx%d] 1: maximize; 2, 3: split; 0: \
  1622. delete; o: select other; j, l: enlarge; h, k: shrink; q: quit."
  1623. (window-width)
  1624. (window-height))))
  1625. (setq c (aref action 0))
  1626. (cond ((= c ?l)
  1627. (unless (eq (window-width) (frame-width))
  1628. (enlarge-window-horizontally 1)))
  1629. ((= c ?h)
  1630. (unless (eq (window-width) (frame-width))
  1631. (shrink-window-horizontally 1)))
  1632. ((= c ?j)
  1633. (enlarge-window 1))
  1634. ((= c ?k)
  1635. (shrink-window 1))
  1636. ((= c ?o)
  1637. (other-window 1))
  1638. ((memq c '(?d ?0))
  1639. (unless (eq (selected-window)
  1640. (next-window (selected-window) 0 1))
  1641. (delete-window (selected-window))))
  1642. ((= c ?1)
  1643. (delete-other-windows))
  1644. ((= c ?2)
  1645. (split-window-vertically))
  1646. ((= c ?3)
  1647. (split-window-horizontally))
  1648. ((memq c '(?q ?\C-g))
  1649. (message "Quit")
  1650. (throw 'end-flag t))
  1651. (t
  1652. (beep))))))))
  1653. ;; (aref (read-key-sequence-vector "aa") 0)
  1654. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1655. ;; ;; emacsを殺伐とさせる
  1656. ;; ;; 補完させるとき失敗するからなし
  1657. ;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html
  1658. ;; (defadvice message (before message-for-stupid (arg &rest arg2) activate)
  1659. ;; (setq arg
  1660. ;; (concat arg
  1661. ;; (if (eq nil (string-match "\\. *$" arg)) ".")
  1662. ;; " Stupid!")))
  1663. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1664. ;; japanese input method
  1665. (defun my-load-scim ()
  1666. "use scim-bridge.el as japanese im."
  1667. ;; Load scim-bridge.
  1668. (when (require 'scim-bridge nil t)
  1669. ;; Turn on scim-mode automatically after loading .emacs
  1670. (add-hook 'after-init-hook 'scim-mode-on)
  1671. (setq scim-cursor-color "red")
  1672. (scim-define-preedit-key ?\^h t)
  1673. (scim-define-common-key ?\* nil)
  1674. (scim-define-common-key ?\^/ nil)))
  1675. (defun my-load-anthy ()
  1676. "use anthy.el as japanese im."
  1677. ;; anthy
  1678. (when (require 'anthy nil t)
  1679. (global-set-key
  1680. (kbd "<muhenkan>") (lambda () (interactive) (anthy-mode-off)))
  1681. (global-set-key (kbd "<henkan>") (lambda () (interactive) (anthy-mode-on)))
  1682. (when (>= emacs-major-version 23)
  1683. (setq anthy-accept-timeout 1))))
  1684. ;; quail
  1685. ;; aproposs input-method for some information
  1686. ;; (setq default-input-method "japanese")
  1687. (defun my-load-mozc-el ()
  1688. ""
  1689. (setq mozc-leim-title "[MZ]")
  1690. (when (require 'mozc nil t)
  1691. (setq defauit-input-method "japanese-mozc")
  1692. ))
  1693. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1694. ;; for windows
  1695. ;; (add-to-list 'exec-path "c:/Program Files/Gauche/bin/")
  1696. (defun start-ckw-bash ()
  1697. ""
  1698. (interactive)
  1699. (start-process
  1700. "ckw_bash"
  1701. nil
  1702. "C:/Documents and Settings/sr/Application Data/dbx/apps/ckw/ckw.exe"))
  1703. ;; command seems to have to be in c drive
  1704. (defun my-w32-add-export-path (&rest args)
  1705. ""
  1706. (mapcar (lambda (path)
  1707. (add-to-list 'exec-path (expand-file-name path)))
  1708. (reverse args))
  1709. (setenv "PATH"
  1710. (mapconcat 'convert-standard-filename
  1711. exec-path
  1712. ";")))
  1713. (when (eq system-type 'windows-nt)
  1714. ;; (setq scheme-program-name "\"c:/Program Files/Gauche/bin/gosh.exe\" -i")
  1715. ;; (setq python-python-command "c:/Python26/python.exe")
  1716. (define-key my-prefix-map (kbd "C-c") 'start-ckw-bash)
  1717. (my-w32-add-export-path "c:/Windows/system"
  1718. "c:/Windows/System32"
  1719. "c:/Program Files/Git/bin"
  1720. "c:/MinGW/bin"
  1721. "c:/MinGW/mingw32/bin"
  1722. (expand-file-name "~/.local/bin")
  1723. (expand-file-name "~/dbx/apps/bin"))
  1724. (when window-system
  1725. (setq w32-enable-synthesized-fonts t))
  1726. (setq file-name-coding-system 'sjis))