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