Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

emacs.el 70 KiB

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