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

emacs.el 68 KiB

12 years ago
13 years ago
12 years ago
13 years ago
13 years ago
12 years ago
12 years ago
12 years ago
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
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
11 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
11 years ago
13 years ago
12 years ago
13 years ago
13 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
12 years ago
11 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
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
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
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989
  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 4
  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. (define-key view-mode-map (kbd "C-m") 'my-view-mode-search-word)
  763. ))
  764. (global-set-key "\M-r" 'view-mode)
  765. (setq view-read-only t)
  766. (defun my-view-mode-search-word (word)
  767. "Search for word current directory and subdirectories.
  768. If called intearctively, find word at point."
  769. (interactive (list (thing-at-point 'symbol)))
  770. (if word
  771. (if (and (require 'gtags nil t)
  772. (gtags-get-rootpath))
  773. (gtags-goto-tag word "s")
  774. (if (eq 0
  775. (shell-command "git rev-parse --git-dir"))
  776. (compilation-start (format "git --no-pager grep -nH -e '%s'"
  777. word)
  778. 'grep-mode)
  779. ;; TODO: handle ack
  780. (grep (format "%s '%s' -r ."
  781. grep-command
  782. word))))
  783. (message "No word at point.")
  784. nil))
  785. (add-hook 'Man-mode-hook
  786. (lambda ()
  787. (view-mode 1)
  788. (setq truncate-lines nil)))
  789. (setq Man-notify-method (if window-system
  790. 'newframe
  791. 'pushy))
  792. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  793. ;; python
  794. (when (lazy-load-eval 'python '(python-mode))
  795. (setq python-python-command (or (executable-find "python3")
  796. (executable-find "python")))
  797. (defun my-python-run-as-command ()
  798. ""
  799. (interactive)
  800. (shell-command (concat python-python-command " " buffer-file-name)))
  801. (defun my-python-display-python-buffer ()
  802. ""
  803. (interactive)
  804. (set-window-text-height (display-buffer python-buffer
  805. t)
  806. 7))
  807. (add-hook 'python-mode-hook
  808. (lambda ()
  809. (define-key python-mode-map
  810. (kbd "C-c C-e") 'my-python-run-as-command)
  811. (define-key python-mode-map
  812. (kbd "C-c C-b") 'my-python-display-python-buffer)
  813. (define-key python-mode-map (kbd "C-m") 'newline-and-indent)))
  814. (add-hook 'inferior-python-mode-hook
  815. (lambda ()
  816. (my-python-display-python-buffer)
  817. (define-key inferior-python-mode-map
  818. (kbd "<up>") 'comint-previous-input)
  819. (define-key inferior-python-mode-map
  820. (kbd "<down>") 'comint-next-input))))
  821. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  822. ;; GNU GLOBAL(gtags)
  823. ;; http://uguisu.skr.jp/Windows/gtags.html
  824. ;; http://eigyr.dip.jp/gtags.html
  825. ;; http://cha.la.coocan.jp/doc/gnu_global.html
  826. (when (lazy-load-eval 'gtags '(gtags-mode))
  827. (add-hook 'gtags-mode-hook
  828. (lambda ()
  829. (setq gtags-select-buffer-single t)
  830. ;; (local-set-key "\M-t" 'gtags-find-tag)
  831. ;; (local-set-key "\M-r" 'gtags-find-rtag)
  832. ;; (local-set-key "\M-s" 'gtags-find-symbol)
  833. ;; (local-set-key "\C-t" 'gtags-pop-stack)
  834. (define-key gtags-mode-map (kbd "C-x t h") 'gtags-find-tag-from-here)
  835. (define-key gtags-mode-map (kbd "C-x t t") 'gtags-find-tag)
  836. (define-key gtags-mode-map (kbd "C-x t r") 'gtags-find-rtag)
  837. (define-key gtags-mode-map (kbd "C-x t s") 'gtags-find-symbol)
  838. (define-key gtags-mode-map (kbd "C-x t p") 'gtags-find-pattern)
  839. (define-key gtags-mdoe-map (kbd "C-x t f") 'gtags-find-file)
  840. (define-key gtags-mode-map (kbd "C-x t b") 'gtags-pop-stack) ;back
  841. )))
  842. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  843. ;; term mode
  844. ;; (setq multi-term-program shell-file-name)
  845. (and (fetch-library "http://www.emacswiki.org/emacs/download/multi-term.el"
  846. t)
  847. (lazy-load-eval 'multi-term)
  848. (progn
  849. (setq multi-term-switch-after-close nil)
  850. (setq multi-term-dedicated-select-after-open-p t)
  851. (setq multi-term-dedicated-window-height 20)))
  852. (when (lazy-load-eval 'term '(term ansi-term))
  853. (defun my-term-quit-or-send-raw ()
  854. ""
  855. (interactive)
  856. (if (get-buffer-process (current-buffer))
  857. (call-interactively 'term-send-raw)
  858. (kill-buffer)))
  859. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  860. ;; (setq term-ansi-default-program shell-file-name)
  861. (add-hook 'term-setup-hook
  862. (lambda ()
  863. (setq term-display-table (make-display-table))))
  864. (add-hook 'term-mode-hook
  865. (lambda ()
  866. (unless (memq (current-buffer)
  867. (and (featurep 'multi-term)
  868. ;; current buffer is not multi-term buffer
  869. (multi-term-list)))
  870. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  871. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  872. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  873. ;; (define-key term-raw-map "\C-f" 'forward-char)
  874. ;; (define-key term-raw-map "\C-b" 'backward-char)
  875. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  876. (define-key term-raw-map
  877. "\C-x" (lookup-key (current-global-map) "\C-x"))
  878. (define-key term-raw-map
  879. "\C-z" (lookup-key (current-global-map) "\C-z"))
  880. )
  881. ;; (define-key term-raw-map "\C-xl" 'term-line-mode)
  882. ;; (define-key term-mode-map "\C-xc" 'term-char-mode)
  883. (define-key term-raw-map (kbd "<up>")
  884. (lambda () (interactive) (scroll-down 1)))
  885. (define-key term-raw-map (kbd "<down>")
  886. (lambda () (interactive) (scroll-up 1)))
  887. (define-key term-raw-map (kbd "<right>") 'scroll-up)
  888. (define-key term-raw-map (kbd "<left>") 'scroll-down)
  889. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  890. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  891. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  892. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  893. (define-key term-raw-map [delete] 'term-send-raw)
  894. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  895. (define-key term-raw-map "\C-y" 'term-paste)
  896. (define-key term-raw-map
  897. "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  898. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  899. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  900. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  901. ;; (define-key term-raw-map "\C-d" 'delete-char)
  902. (set (make-local-variable 'scroll-margin) 0)
  903. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  904. ;; (cua-mode 0)
  905. ;; (and cua-mode
  906. ;; (local-unset-key (kbd "C-c")))
  907. ;; (define-key cua--prefix-override-keymap
  908. ;;"\C-c" 'term-interrupt-subjob)
  909. (set (make-local-variable 'hl-line-range-function)
  910. (lambda ()
  911. '(0 . 0)))
  912. ))
  913. ;; (add-hook 'term-exec-hook 'forward-char)
  914. )
  915. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  916. ;; buffer switching
  917. (when (lazy-load-eval 'bs '(bs-show)
  918. ;; (add-to-list 'bs-configurations
  919. ;; '("processes" nil get-buffer-process ".*" nil nil))
  920. (add-to-list 'bs-configurations
  921. '("this-frame" nil (lambda (buf)
  922. (memq buf (my-frame-buffer-get)))
  923. ".*" nil nil))
  924. ;; (setq bs-configurations (list
  925. ;; '("processes" nil get-buffer-process ".*" nil nil)
  926. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  927. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  928. )
  929. ;; (global-set-key "\C-x\C-b" 'bs-show)
  930. (defalias 'list-buffers 'bs-show)
  931. (setq bs-default-configuration "files")
  932. (setq bs-default-sort-name "by nothing")
  933. (add-hook 'bs-mode-hook
  934. (lambda ()
  935. (setq bs-default-configuration "files")
  936. ;; (and bs--show-all
  937. ;; (call-interactively 'bs-toggle-show-all))
  938. (set (make-local-variable 'scroll-margin) 0))))
  939. (iswitchb-mode 1)
  940. (defun iswitchb-buffer-display-other-window ()
  941. ""
  942. (interactive)
  943. (let ((iswitchb-default-method 'display))
  944. (call-interactively 'iswitchb-buffer)))
  945. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  946. ;; sdic
  947. (when (lazy-load-eval 'sdic '(sdic-describe-word-at-point))
  948. ;; (define-key my-prefix-map "\C-w" 'sdic-describe-word)
  949. (define-key my-prefix-map "\C-t" 'sdic-describe-word-at-point-echo)
  950. (defun sdic-describe-word-at-point-echo ()
  951. ""
  952. (interactive)
  953. (save-window-excursion
  954. (sdic-describe-word-at-point))
  955. (save-excursion
  956. (set-buffer sdic-buffer-name)
  957. (message (buffer-substring (point-min)
  958. (progn (goto-char (point-min))
  959. (or (and (re-search-forward "^\\w"
  960. nil
  961. t
  962. 4)
  963. (progn (previous-line) t)
  964. (point-at-eol))
  965. (point-max)))))))
  966. (setq sdic-eiwa-dictionary-list '((sdicf-client "/usr/share/dict/gene.sdic")))
  967. (setq sdic-waei-dictionary-list
  968. '((sdicf-client "/usr/share/dict/jedict.sdic" (add-keys-to-headword t))))
  969. (setq sdic-disable-select-window t)
  970. (setq sdic-window-height 7))
  971. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  972. ;; vc
  973. ;; (require 'vc)
  974. (setq vc-handled-backends '())
  975. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  976. ;; gauche-mode
  977. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  978. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  979. (when (and (fetch-library
  980. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  981. t)
  982. (lazy-load-eval 'gauche-mode '(gauche-mode run-scheme)))
  983. (let ((s (executable-find "gosh")))
  984. (setq scheme-program-name s
  985. gauche-program-name s))
  986. (defun run-gauche-other-window ()
  987. "Run gauche on other window"
  988. (interactive)
  989. (switch-to-buffer-other-window
  990. (get-buffer-create "*scheme*"))
  991. (run-gauche))
  992. (defun run-gauche ()
  993. "run gauche"
  994. (run-scheme gauche-program-name)
  995. )
  996. (defun scheme-send-buffer ()
  997. ""
  998. (interactive)
  999. (scheme-send-region (point-min) (point-max))
  1000. (my-scheme-display-scheme-buffer)
  1001. )
  1002. (defun my-scheme-display-scheme-buffer ()
  1003. ""
  1004. (interactive)
  1005. (set-window-text-height (display-buffer scheme-buffer
  1006. t)
  1007. 7))
  1008. (add-hook 'scheme-mode-hook
  1009. (lambda ()
  1010. nil))
  1011. (add-hook 'inferior-scheme-mode-hook
  1012. (lambda ()
  1013. ;; (my-scheme-display-scheme-buffer)
  1014. ))
  1015. (setq auto-mode-alist
  1016. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  1017. (setq auto-mode-alist
  1018. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  1019. (add-hook 'gauche-mode-hook
  1020. (lambda ()
  1021. (define-key gauche-mode-map
  1022. (kbd "C-c C-z") 'run-gauche-other-window)
  1023. (define-key scheme-mode-map
  1024. (kbd "C-c C-c") 'scheme-send-buffer)
  1025. (define-key scheme-mode-map
  1026. (kbd "C-c C-b") 'my-scheme-display-scheme-buffer))))
  1027. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1028. ;; recentf-mode
  1029. (setq recentf-save-file (expand-file-name "~/.emacs.d/recentf")
  1030. recentf-max-menu-items 20
  1031. recentf-max-saved-items 30
  1032. recentf-show-file-shortcuts-flag nil)
  1033. (when (require 'recentf nil t)
  1034. (add-to-list 'recentf-exclude (regexp-quote recentf-save-file))
  1035. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1036. (add-hook 'find-file-hook
  1037. 'recentf-save-list
  1038. t) ; save to file immediately after adding file to recentf list
  1039. (add-hook 'kill-emacs-hook
  1040. 'recentf-load-list)
  1041. (add-hook 'recentf-mode-hook
  1042. 'recentf-save-list)
  1043. ;; (add-hook 'find-file-hook
  1044. ;; (lambda ()
  1045. ;; (recentf-add-file default-directory)))
  1046. (and (fetch-library
  1047. "https://raw.github.com/10sr/emacs-lisp/master/recentf-show.el"
  1048. t)
  1049. (lazy-load-eval 'recentf-show)
  1050. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1051. (add-hook 'recentf-show-before-listing-hook
  1052. 'recentf-load-list))
  1053. (recentf-mode 1)
  1054. (add-hook 'recentf-dialog-mode-hook
  1055. (lambda ()
  1056. ;; (recentf-save-list)
  1057. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1058. ;; 'my-recentf-cd-and-find-file)
  1059. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1060. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1061. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1062. (define-key recentf-dialog-mode-map "n" 'next-line)
  1063. (cd "~/"))))
  1064. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1065. ;; dired
  1066. (when (lazy-load-eval 'dired nil)
  1067. (defun my-dired-echo-file-head (arg)
  1068. ""
  1069. (interactive "P")
  1070. (let ((f (dired-get-filename)))
  1071. (message "%s"
  1072. (with-temp-buffer
  1073. (insert-file-contents f)
  1074. (buffer-substring-no-properties
  1075. (point-min)
  1076. (progn (goto-line (if arg
  1077. (prefix-numeric-value arg)
  1078. 10))
  1079. (point-at-eol)))))))
  1080. (defun my-dired-diff ()
  1081. ""
  1082. (interactive)
  1083. (let ((files (dired-get-marked-files nil nil nil t)))
  1084. (if (eq (car files)
  1085. t)
  1086. (diff (cadr files) (dired-get-filename))
  1087. (message "One files must be marked!"))))
  1088. (defun my-pop-to-buffer-erase-noselect (buffer-or-name)
  1089. "pop up buffer using `display-buffer' and return that buffer."
  1090. (let ((bf (get-buffer-create buffer-or-name)))
  1091. (with-current-buffer bf
  1092. (cd ".")
  1093. (erase-buffer))
  1094. (display-buffer bf)
  1095. bf))
  1096. (defun my-replace-nasi-none ()
  1097. ""
  1098. (save-excursion
  1099. (let ((buffer-read-only nil))
  1100. (goto-char (point-min))
  1101. (while (search-forward "なし" nil t)
  1102. (replace-match "none")))))
  1103. (defun dired-get-file-info ()
  1104. "dired get file info"
  1105. (interactive)
  1106. (let ((f (shell-quote-argument (dired-get-filename t))))
  1107. (if (file-directory-p f)
  1108. (progn
  1109. (message "Calculating disk usage...")
  1110. (shell-command (concat "du -hsD "
  1111. f)))
  1112. (shell-command (concat "file "
  1113. f)))))
  1114. (defun my-dired-scroll-up ()
  1115. ""
  1116. (interactive)
  1117. (my-dired-previous-line (- (window-height) 1)))
  1118. (defun my-dired-scroll-down ()
  1119. ""
  1120. (interactive)
  1121. (my-dired-next-line (- (window-height) 1)))
  1122. ;; (defun my-dired-forward-line (arg)
  1123. ;; ""
  1124. ;; (interactive "p"))
  1125. (defun my-dired-previous-line (arg)
  1126. ""
  1127. (interactive "p")
  1128. (if (> arg 0)
  1129. (progn
  1130. (if (eq (line-number-at-pos)
  1131. 1)
  1132. (goto-char (point-max))
  1133. (forward-line -1))
  1134. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1135. (dired-get-subdir))
  1136. (- arg 1)
  1137. arg)))
  1138. (dired-move-to-filename)))
  1139. (defun my-dired-next-line (arg)
  1140. ""
  1141. (interactive "p")
  1142. (if (> arg 0)
  1143. (progn
  1144. (if (eq (point)
  1145. (point-max))
  1146. (goto-char (point-min))
  1147. (forward-line 1))
  1148. (my-dired-next-line (if (or (dired-get-filename nil t)
  1149. (dired-get-subdir))
  1150. (- arg 1)
  1151. arg)))
  1152. (dired-move-to-filename)))
  1153. (defun my-dired-print-current-dir-and-file ()
  1154. (message "%s %s"
  1155. default-directory
  1156. (buffer-substring-no-properties (point-at-bol)
  1157. (point-at-eol))))
  1158. (defun dired-do-execute-as-command ()
  1159. ""
  1160. (interactive)
  1161. (let ((file (dired-get-filename t)))
  1162. (if (file-executable-p file)
  1163. (start-process file nil file)
  1164. (when (y-or-n-p
  1165. "this file cant be executed. mark as executable and go? : ")
  1166. (set-file-modes file
  1167. (file-modes-symbolic-to-number "u+x" (file-modes file)))
  1168. (start-process file nil file)))))
  1169. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1170. (defun my-dired-x-open ()
  1171. ""
  1172. (interactive)
  1173. (my-x-open (dired-get-filename t t)))
  1174. (if (eq window-system 'mac)
  1175. (setq dired-listing-switches "-lhFG")
  1176. (setq dired-listing-switches "-lhFG --time-style=long-iso")
  1177. )
  1178. (setq dired-listing-switches "-lhFG")
  1179. (put 'dired-find-alternate-file 'disabled nil)
  1180. ;; when using dired-find-alternate-file
  1181. ;; reuse current dired buffer for the file to open
  1182. (setq dired-ls-F-marks-symlinks t)
  1183. (require 'ls-lisp)
  1184. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1185. (setq ls-lisp-dirs-first t)
  1186. (setq ls-lisp-use-localized-time-format t)
  1187. (setq ls-lisp-format-time-list
  1188. '("%Y-%m-%d %H:%M"
  1189. "%Y-%m-%d "))
  1190. (setq dired-dwim-target t)
  1191. ;; (add-hook 'dired-after-readin-hook
  1192. ;; 'my-replace-nasi-none)
  1193. ;; (add-hook 'after-init-hook
  1194. ;; (lambda ()
  1195. ;; (dired ".")))
  1196. (add-hook 'dired-mode-hook
  1197. (lambda ()
  1198. (define-key dired-mode-map "o" 'my-dired-x-open)
  1199. (define-key dired-mode-map "i" 'dired-get-file-info)
  1200. (define-key dired-mode-map "f" 'find-file)
  1201. (define-key dired-mode-map "!" 'shell-command)
  1202. (define-key dired-mode-map "&" 'async-shell-command)
  1203. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1204. (define-key dired-mode-map "=" 'my-dired-diff)
  1205. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1206. (define-key dired-mode-map "b" 'gtkbm)
  1207. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1208. (define-key dired-mode-map "@" (lambda ()
  1209. (interactive) (my-x-open ".")))
  1210. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1211. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1212. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1213. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1214. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1215. (substitute-key-definition 'dired-next-line
  1216. 'my-dired-next-line dired-mode-map)
  1217. (substitute-key-definition 'dired-previous-line
  1218. 'my-dired-previous-line dired-mode-map)
  1219. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1220. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1221. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1222. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1223. (let ((file "._Icon\015"))
  1224. (when nil (file-readable-p file)
  1225. (delete-file file)))))
  1226. (and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/pack.el"
  1227. t)
  1228. (lazy-load-eval 'pack '(dired-do-pack-or-unpack pack))
  1229. (add-hook 'dired-mode-hook
  1230. (lambda ()
  1231. (define-key dired-mode-map "P" 'dired-do-pack-or-unpack))))
  1232. (and (fetch-library
  1233. "https://raw.github.com/10sr/emacs-lisp/master/dired-list-all-mode.el"
  1234. t)
  1235. (lazy-load-eval 'dired-list-all-mode)
  1236. (setq dired-listing-switches "-lhFG")
  1237. (add-hook 'dired-mode-hook
  1238. (lambda ()
  1239. (define-key dired-mode-map "a" 'dired-list-all-mode)
  1240. )))
  1241. ) ; when dired locate
  1242. ;; http://blog.livedoor.jp/tek_nishi/archives/4693204.html
  1243. (defun my-dired-toggle-mark()
  1244. (let ((cur (cond ((eq (following-char) dired-marker-char) ?\040)
  1245. (t dired-marker-char))))
  1246. (delete-char 1)
  1247. (insert cur)))
  1248. (defun my-dired-mark (arg)
  1249. "toggle mark the current (or next ARG) files.
  1250. If on a subdir headerline, mark all its files except `.' and `..'.
  1251. Use \\[dired-unmark-all-files] to remove all marks
  1252. and \\[dired-unmark] on a subdir to remove the marks in
  1253. this subdir."
  1254. (interactive "P")
  1255. (if (dired-get-subdir)
  1256. (save-excursion (dired-mark-subdir-files))
  1257. (let ((inhibit-read-only t))
  1258. (dired-repeat-over-lines
  1259. (prefix-numeric-value arg)
  1260. 'my-dired-toggle-mark))))
  1261. (defun my-dired-mark-backward (arg)
  1262. "In Dired, move up lines and toggle mark there.
  1263. Optional prefix ARG says how many lines to unflag; default is one line."
  1264. (interactive "p")
  1265. (my-dired-mark (- arg)))
  1266. (add-hook 'dired-mode-hook
  1267. (lambda ()
  1268. (local-set-key (kbd "SPC") 'my-dired-mark)
  1269. (local-set-key (kbd "S-SPC") 'my-dired-mark-backward))
  1270. )
  1271. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1272. ;; eshell
  1273. (lazy-load-eval 'eshell nil
  1274. (defun my-eshell-backward-delete-char ()
  1275. (interactive)
  1276. (when (< (save-excursion
  1277. (eshell-bol)
  1278. (point))
  1279. (point))
  1280. (backward-delete-char 1)))
  1281. (defun my-file-owner-p (file)
  1282. "t if FILE is owned by me."
  1283. (eq (user-uid) (nth 2 (file-attributes file))))
  1284. "http://www.bookshelf.jp/pukiwiki/pukiwiki.php\
  1285. ?Eshell%A4%F2%BB%C8%A4%A4%A4%B3%A4%CA%A4%B9"
  1286. ;; ;; written by Stefan Reichoer <reichoer@web.de>
  1287. ;; (defun eshell/less (&rest args)
  1288. ;; "Invoke `view-file' on the file.
  1289. ;; \"less +42 foo\" also goes to line 42 in the buffer."
  1290. ;; (if args
  1291. ;; (while args
  1292. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1293. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1294. ;; (file (pop args)))
  1295. ;; (view-file file)
  1296. ;; (goto-line line))
  1297. ;; (view-file (pop args))))))
  1298. (defun eshell/o (&optional file)
  1299. (my-x-open (or file ".")))
  1300. ;; (defun eshell/vi (&rest args)
  1301. ;; "Invoke `find-file' on the file.
  1302. ;; \"vi +42 foo\" also goes to line 42 in the buffer."
  1303. ;; (while args
  1304. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1305. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1306. ;; (file (pop args)))
  1307. ;; (find-file file)
  1308. ;; (goto-line line))
  1309. ;; (find-file (pop args)))))
  1310. (defun eshell/clear ()
  1311. "Clear the current buffer, leaving one prompt at the top."
  1312. (let ((inhibit-read-only t))
  1313. (erase-buffer)))
  1314. (defun eshell/d (&optional dirname switches)
  1315. "if first arg is omitted open current directory."
  1316. (dired (or dirname ".") switches))
  1317. (defun eshell/v ()
  1318. (view-mode 1))
  1319. (defun eshell/git (&rest args)
  1320. ""
  1321. (if (member (car args)
  1322. '("di" "diff" "log" "show"))
  1323. (apply 'eshell-exec-visual "git" args)
  1324. (shell-command (mapconcat 'shell-quote-argument
  1325. `("git" ,@args)
  1326. " ")
  1327. t)
  1328. ;; (eshell-external-command "git" args)
  1329. ))
  1330. (defalias 'eshell/: 'ignore)
  1331. (defalias 'eshell/type 'eshell/which)
  1332. ;; (defalias 'eshell/vim 'eshell/vi)
  1333. (defalias 'eshell/ff 'find-file)
  1334. (defalias 'eshell/q 'eshell/exit)
  1335. (defun eshell-goto-prompt ()
  1336. ""
  1337. (interactive)
  1338. (goto-char (point-max)))
  1339. (defun eshell-cd-default-directory (&optional eshell-buffer-or-name)
  1340. "open eshell and change wd
  1341. if arg given, use that eshell buffer, otherwise make new eshell buffer."
  1342. (interactive)
  1343. (let ((dir (expand-file-name default-directory)))
  1344. (switch-to-buffer (or eshell-buffer-or-name
  1345. (eshell t)))
  1346. (unless (equal dir (expand-file-name default-directory))
  1347. ;; (cd dir)
  1348. ;; (eshell-interactive-print (concat "cd " dir "\n"))
  1349. ;; (eshell-emit-prompt)
  1350. (goto-char (point-max))
  1351. (eshell-kill-input)
  1352. (insert "cd " dir)
  1353. (eshell-send-input))))
  1354. (setq eshell-directory-name "~/.emacs.d/eshell/")
  1355. (setq eshell-term-name "eterm-color")
  1356. (setq eshell-scroll-to-bottom-on-input t)
  1357. (setq eshell-cmpl-ignore-case t)
  1358. (setq eshell-cmpl-cycle-completions nil)
  1359. (setq eshell-highlight-prompt nil)
  1360. (setq eshell-ls-initial-args '("-hCFG"
  1361. "--color=auto"
  1362. "--time-style=long-iso")) ; "-hF")
  1363. (setq eshell-prompt-function
  1364. (lambda ()
  1365. (with-temp-buffer
  1366. (let (p1 p2 p3 p4)
  1367. (insert " [")
  1368. (setq p1 (point))
  1369. (insert (abbreviate-file-name default-directory))
  1370. (setq p2 (point))
  1371. (insert "]"
  1372. "\n")
  1373. (setq p3 (point))
  1374. (insert user-login-name
  1375. "@"
  1376. (or (getenv "HOSTNAME")
  1377. (substring (shell-command-to-string
  1378. (or (executable-find "hostname")
  1379. "echo ''"))
  1380. 0
  1381. -1)))
  1382. (setq p4 (point))
  1383. (insert " "
  1384. (format-time-string "%a, %d %b %Y %T %z")
  1385. " eshell\n"
  1386. "last:"
  1387. (number-to-string eshell-last-command-status)
  1388. (if (= (user-uid)
  1389. 0)
  1390. " # "
  1391. " $ "))
  1392. (add-text-properties p1
  1393. p2
  1394. '(face ((foreground-color . "yellow"))))
  1395. (add-text-properties p3
  1396. p4
  1397. '(face ((foreground-color . "cyan"))))
  1398. (buffer-substring (point-min)
  1399. (point-max))))))
  1400. (add-hook 'eshell-mode-hook
  1401. (lambda ()
  1402. ;; (define-key eshell-mode-map (kbd "C-x C-x") (lambda ()
  1403. ;; (interactive)
  1404. ;; (switch-to-buffer (other-buffer))))
  1405. (define-key eshell-mode-map (kbd "C-u") (lambda ()
  1406. (interactive)
  1407. (eshell-goto-prompt)
  1408. (eshell-kill-input)))
  1409. (define-key eshell-mode-map (kbd "C-g") (lambda ()
  1410. (interactive)
  1411. (eshell-goto-prompt)
  1412. (my-keyboard-quit)))
  1413. (define-key eshell-mode-map
  1414. (kbd "DEL") 'my-eshell-backward-delete-char)
  1415. (define-key eshell-mode-map
  1416. (kbd "C-p") 'eshell-previous-matching-input-from-input)
  1417. (define-key eshell-mode-map
  1418. (kbd "C-n") 'eshell-next-matching-input-from-input)
  1419. (apply 'eshell/addpath exec-path)
  1420. (set (make-local-variable 'scroll-margin) 0)
  1421. ;; (eshell/export "GIT_PAGER=")
  1422. ;; (eshell/export "GIT_EDITOR=")
  1423. (eshell/export "LC_MESSAGES=C")
  1424. (switch-to-buffer (current-buffer)) ; move buffer top of list
  1425. (set (make-local-variable 'hl-line-range-function)
  1426. (lambda ()
  1427. '(0 . 0)))
  1428. (add-to-list 'eshell-virtual-targets
  1429. '("/dev/less"
  1430. (lambda (str)
  1431. (if str
  1432. (with-current-buffer nil)))
  1433. nil))
  1434. ))
  1435. (add-hook 'eshell-mode-hook
  1436. (lambda ()
  1437. (add-to-list 'eshell-visual-commands "vim")
  1438. ;; (add-to-list 'eshell-visual-commands "git")
  1439. (add-to-list 'eshell-output-filter-functions
  1440. 'eshell-truncate-buffer)
  1441. (mapcar (lambda (alias)
  1442. (add-to-list 'eshell-command-aliases-list
  1443. alias))
  1444. '(
  1445. ; ("ll" "ls -l $*")
  1446. ; ("la" "ls -a $*")
  1447. ; ("lla" "ls -al $*")
  1448. ("aptin" "apt-get install $*")
  1449. ("eless"
  1450. (concat "cat >>> (with-current-buffer "
  1451. "(get-buffer-create \"*eshell output\") "
  1452. "(erase-buffer) "
  1453. "(setq buffer-read-only nil) "
  1454. "(current-buffer)) "
  1455. "(view-buffer (get-buffer \"*eshell output*\"))")
  1456. ("g" "git $*")
  1457. ))
  1458. )))
  1459. ) ; eval after load eshell
  1460. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1461. ;; frame buffer
  1462. ;; todo: work well when opening files already opened on another window
  1463. (add-hook 'after-make-frame-functions
  1464. (lambda (f)
  1465. (set-window-buffer (frame-selected-window f)
  1466. "*Messages*")))
  1467. (defun make-frame-command-with-name (name)
  1468. "Make frame with name specified."
  1469. (interactive "sName for new frame: ")
  1470. (set-frame-parameter (make-frame-command)
  1471. 'name
  1472. name))
  1473. (defvar my-frame-buffer-plist nil)
  1474. (defun my-frame-buffer-add (&optional buf frame)
  1475. ""
  1476. (setq my-frame-buffer-plist
  1477. (plist-put my-frame-buffer-plist
  1478. (or frame
  1479. (selected-frame))
  1480. (let ((lst (my-frame-buffer-get frame)))
  1481. (if lst
  1482. (add-to-list 'lst
  1483. (or buf
  1484. (current-buffer)))
  1485. (list (or buf
  1486. (current-buffer))))))))
  1487. (defun my-frame-buffer-remove (&optional buf frame)
  1488. ""
  1489. (setq my-frame-buffer-plist
  1490. (plist-put my-frame-buffer-plist
  1491. (or frame
  1492. (selected-frame))
  1493. (delq (or buf
  1494. (current-buffer))
  1495. (my-frame-buffer-get frame)))))
  1496. (defun my-frame-buffer-get (&optional frame)
  1497. ""
  1498. (plist-get my-frame-buffer-plist
  1499. (or frame
  1500. (selected-frame))))
  1501. (defun my-frame-buffer-kill-all-buffer (&optional frame)
  1502. ""
  1503. (mapcar 'kill-buffer
  1504. (my-frame-buffer-get frame)))
  1505. (add-hook 'find-file-hook
  1506. 'my-frame-buffer-add)
  1507. ;; (add-hook 'term-mode-hook
  1508. ;; 'my-frame-buffer-add)
  1509. (add-hook 'eshell-mode-hook
  1510. 'my-frame-buffer-add)
  1511. (add-hook 'Man-mode-hook
  1512. 'my-frame-buffer-add)
  1513. (add-hook 'kill-buffer-hook
  1514. 'my-frame-buffer-remove)
  1515. (add-hook 'delete-frame-functions
  1516. 'my-frame-buffer-kill-all-buffer)
  1517. (defvar my-desktop-terminal "roxterm")
  1518. (defun my-execute-terminal ()
  1519. ""
  1520. (interactive)
  1521. (if (and (or (eq system-type 'windows-nt)
  1522. window-system)
  1523. my-desktop-terminal
  1524. )
  1525. (let ((process-environment (cons "TERM=xterm" process-environment)))
  1526. (start-process "terminal"
  1527. nil
  1528. my-desktop-terminal))
  1529. (my-term)))
  1530. (defvar my-term nil "my terminal buffer")
  1531. (defun my-term ()
  1532. "open terminal buffer and return that buffer."
  1533. (interactive)
  1534. (if (and my-term
  1535. (buffer-name my-term))
  1536. (pop-to-buffer my-term)
  1537. (setq my-term
  1538. (save-window-excursion
  1539. (funcall my-term-function)
  1540. ))
  1541. (and my-term
  1542. (my-term))))
  1543. (defvar my-term-function nil
  1544. "Function to create terminal buffer.")
  1545. ;; (setq my-term-function
  1546. ;; (lambda ()
  1547. ;; (if (eq system-type 'windows-nt)
  1548. ;; (eshell)
  1549. ;; (if (require 'multi-term nil t)
  1550. ;; (multi-term)
  1551. ;; (ansi-term shell-file-name)))))
  1552. (setq my-term-function 'eshell)
  1553. (defun my-delete-frame-or-kill-emacs ()
  1554. "delete frame when opening multiple frame, kill emacs when only one."
  1555. (interactive)
  1556. (if (eq 1
  1557. (length (frame-list)))
  1558. (save-buffers-kill-emacs)
  1559. (delete-frame)))
  1560. (define-key my-prefix-map (kbd "C-s") 'my-execute-terminal)
  1561. (define-key my-prefix-map (kbd "C-f") 'make-frame-command-with-name)
  1562. (global-set-key (kbd "C-x C-c") 'my-delete-frame-or-kill-emacs)
  1563. (define-key my-prefix-map (kbd "C-x C-c") 'save-buffers-kill-emacs)
  1564. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1565. ;; x open
  1566. (defvar my-filer nil)
  1567. (setq my-filer (or (executable-find "pcmanfm")
  1568. (executable-find "nautilus")))
  1569. (defun my-x-open (file)
  1570. "open file."
  1571. (interactive "FOpen File: ")
  1572. (setq file (expand-file-name file))
  1573. (message "Opening %s..." file)
  1574. (cond ((eq system-type 'windows-nt)
  1575. (call-process "cmd.exe" nil 0 nil
  1576. "/c" "start" "" (convert-standard-filename file)))
  1577. ((eq system-type 'darwin)
  1578. (call-process "open" nil 0 nil file))
  1579. ((getenv "DISPLAY")
  1580. (call-process (or my-filer "xdg-open") nil 0 nil file))
  1581. (t
  1582. (find-file file))
  1583. )
  1584. ;; (recentf-add-file file)
  1585. (message "Opening %s...done" file))
  1586. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1587. ;; misc funcs
  1588. (defun my-grep ()
  1589. "Use git-grep if avaliable. Only called interactively."
  1590. (interactive)
  1591. (require 'grep)
  1592. (let ((--grep-command-bak grep-command)
  1593. (--grep-use-null-device-bak grep-use-null-device))
  1594. (if (called-interactively-p 'any)
  1595. (progn
  1596. (when (eq 0
  1597. (shell-command "git rev-parse --git-dir"))
  1598. (grep-apply-setting 'grep-command
  1599. "git --no-pager grep -nH -e ")
  1600. (grep-apply-setting 'grep-use-null-device
  1601. nil))
  1602. (call-interactively 'grep)
  1603. (grep-apply-setting 'grep-command
  1604. --grep-command-bak)
  1605. (grep-apply-setting 'grep-use-null-device
  1606. --grep-use-null-device-bak))
  1607. (message "my-grep only allow interactive call."))))
  1608. (defun make ()
  1609. "Run \"make -k\" in current directory."
  1610. (interactive)
  1611. (compile "make -k"))
  1612. (defvar sed-in-place-history nil
  1613. "History of `sed-in-place'")
  1614. (defvar sed-in-place-command "sed --in-place=.bak -e")
  1615. (defun sed-in-place (command)
  1616. "sed in place"
  1617. (interactive (list (read-shell-command "sed in place: "
  1618. (concat sed-in-place-command " ")
  1619. 'sed-in-place-history)))
  1620. (shell-command command
  1621. "*sed in place*"))
  1622. (defun dired-do-sed-in-place (&optional arg)
  1623. "sed in place dired"
  1624. (interactive "P")
  1625. (require 'dired-aux)
  1626. (let* ((files (dired-get-marked-files t arg))
  1627. (expr (dired-mark-read-string "Run sed-in-place for %s: "
  1628. nil
  1629. 'sed-in-place
  1630. arg
  1631. files)))
  1632. (if (equal expr
  1633. "")
  1634. (error "No expression specified")
  1635. (shell-command (concat sed-in-place-command
  1636. " '"
  1637. expr
  1638. "' "
  1639. (mapconcat 'shell-quote-argument
  1640. files
  1641. " "))
  1642. "*sed in place*"))))
  1643. (defun dir-show (&optional dir)
  1644. (interactive)
  1645. (let ((bf (get-buffer-create "*dir show*"))
  1646. (list-directory-brief-switches "-C"))
  1647. (with-current-buffer bf
  1648. (list-directory (or nil
  1649. default-directory)
  1650. nil))
  1651. ))
  1652. (defun my-convmv-sjis2utf8-test ()
  1653. "run `convmv -r -f sjis -t utf8 *'
  1654. this is test, does not rename files"
  1655. (interactive)
  1656. (shell-command "convmv -r -f sjis -t utf8 *"))
  1657. (defun my-convmv-sjis2utf8-notest ()
  1658. "run `convmv -r -f sjis -t utf8 * --notest'"
  1659. (interactive)
  1660. (shell-command "convmv -r -f sjis -t utf8 * --notest"))
  1661. (defun kill-ring-save-buffer-file-name ()
  1662. "get current filename"
  1663. (interactive)
  1664. (let ((file buffer-file-name))
  1665. (if file
  1666. (progn (kill-new file)
  1667. (message file))
  1668. (message "not visiting file."))))
  1669. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1670. ;; ;; savage emacs
  1671. ;; ;; when enabled emacs fails to complete
  1672. ;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html
  1673. ;; (defadvice message (before message-for-stupid (arg &rest arg2) activate)
  1674. ;; (setq arg
  1675. ;; (concat arg
  1676. ;; (if (eq nil (string-match "\\. *$" arg)) ".")
  1677. ;; " Stupid!")))
  1678. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1679. ;; japanese input method
  1680. (defun my-load-scim ()
  1681. "use scim-bridge.el as japanese im."
  1682. ;; Load scim-bridge.
  1683. (when (require 'scim-bridge nil t)
  1684. ;; Turn on scim-mode automatically after loading .emacs
  1685. (add-hook 'after-init-hook 'scim-mode-on)
  1686. (setq scim-cursor-color "red")
  1687. (scim-define-preedit-key ?\^h t)
  1688. (scim-define-common-key ?\* nil)
  1689. (scim-define-common-key ?\^/ nil)))
  1690. (defun my-load-anthy ()
  1691. "use anthy.el as japanese im."
  1692. ;; anthy
  1693. (when (require 'anthy nil t)
  1694. (global-set-key
  1695. (kbd "<muhenkan>") (lambda () (interactive) (anthy-mode-off)))
  1696. (global-set-key (kbd "<henkan>") (lambda () (interactive) (anthy-mode-on)))
  1697. (when (>= emacs-major-version 23)
  1698. (setq anthy-accept-timeout 1))))
  1699. ;; quail
  1700. ;; aproposs input-method for some information
  1701. ;; (setq default-input-method "japanese")
  1702. (defun my-load-mozc-el ()
  1703. ""
  1704. (setq mozc-leim-title "[MZ]")
  1705. (when (require 'mozc nil t)
  1706. (setq defauit-input-method "japanese-mozc")
  1707. ))
  1708. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1709. ;; for windows
  1710. (defun start-ckw-bash ()
  1711. ""
  1712. (interactive)
  1713. (start-process
  1714. "ckw_bash"
  1715. nil
  1716. "C:/Documents and Settings/sr/Application Data/dbx/apps/ckw/ckw.exe"))
  1717. ;; command seems to have to be in c drive
  1718. (defun my-w32-add-export-path (&rest args)
  1719. ""
  1720. (mapcar (lambda (path)
  1721. (add-to-list 'exec-path (expand-file-name path)))
  1722. (reverse args))
  1723. (setenv "PATH"
  1724. (mapconcat 'convert-standard-filename
  1725. exec-path
  1726. ";")))
  1727. (when (eq system-type 'windows-nt)
  1728. ;; (setq scheme-program-name "\"c:/Program Files/Gauche/bin/gosh.exe\" -i")
  1729. ;; (setq python-python-command "c:/Python26/python.exe")
  1730. (define-key my-prefix-map (kbd "C-c") 'start-ckw-bash)
  1731. (my-w32-add-export-path "c:/Windows/system"
  1732. "c:/Windows/System32"
  1733. "c:/Program Files/Git/bin"
  1734. "c:/MinGW/bin"
  1735. "c:/MinGW/mingw32/bin"
  1736. (expand-file-name "~/.local/bin")
  1737. (expand-file-name "~/dbx/apps/bin"))
  1738. (when window-system
  1739. (setq w32-enable-synthesized-fonts t))
  1740. (setq file-name-coding-system 'sjis))