You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

emacs.el 66 KiB

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