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

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