您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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