Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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