Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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