No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

emacs.el 67 KiB

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