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