Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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