25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

emacs.el 66 KiB

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