25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

emacs.el 66 KiB

12 년 전
13 년 전
12 년 전
13 년 전
13 년 전
12 년 전
12 년 전
12 년 전
12 년 전
12 년 전
13 년 전
13 년 전
12 년 전
13 년 전
13 년 전
13 년 전
13 년 전
12 년 전
12 년 전
13 년 전
13 년 전
13 년 전
12 년 전
12 년 전
13 년 전
13 년 전
13 년 전
13 년 전
13 년 전
13 년 전
13 년 전
13 년 전
13 년 전
13 년 전
13 년 전
12 년 전
12 년 전
12 년 전
12 년 전
12 년 전
13 년 전
13 년 전
12 년 전
13 년 전
12 년 전
13 년 전
13 년 전
13 년 전
12 년 전
12 년 전
12 년 전
12 년 전
12 년 전
12 년 전
12 년 전
13 년 전
12 년 전
12 년 전
12 년 전
13 년 전
13 년 전
12 년 전
13 년 전
13 년 전
13 년 전
13 년 전
13 년 전
13 년 전
13 년 전
12 년 전
13 년 전
13 년 전
12 년 전
13 년 전
13 년 전
13 년 전
13 년 전
12 년 전
12 년 전
12 년 전
12 년 전
13 년 전
12 년 전
12 년 전
13 년 전
12 년 전
13 년 전
12 년 전
13 년 전
12 년 전
13 년 전
12 년 전
13 년 전
12 년 전
13 년 전
12 년 전
13 년 전
13 년 전
12 년 전
13 년 전
12 년 전
12 년 전
12 년 전
12 년 전
12 년 전
13 년 전
13 년 전
12 년 전
13 년 전
12 년 전
13 년 전
12 년 전
13 년 전
12 년 전
12 년 전
13 년 전
12 년 전
12 년 전
13 년 전
12 년 전
12 년 전
12 년 전
12 년 전
13 년 전
13 년 전
13 년 전
13 년 전
12 년 전
12 년 전
12 년 전
13 년 전
12 년 전
13 년 전
13 년 전
13 년 전
13 년 전
13 년 전
12 년 전
12 년 전
13 년 전
13 년 전
13 년 전
13 년 전
13 년 전
13 년 전
13 년 전
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915
  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 "\\r\\n")
  188. (setq eol-mnemonic-mac "\\r")
  189. (setq eol-mnemonic-unix "\\n")
  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. ;; this functions is set in write-file-functions, i cannot find any
  600. ;; good way to remove this.
  601. (fset 'makefile-warn-suspicious-lines 'ignore)
  602. ))
  603. (defun make ()
  604. "Run \"make -k\" in current directory."
  605. (interactive)
  606. (compile "make -k"))
  607. (add-hook 'verilog-mode-hook
  608. (lambda ()
  609. (define-key verilog-mode-map ";" 'self-insert-command)))
  610. (setq diff-switches "-u")
  611. (add-hook 'diff-mode-hook
  612. (lambda ()
  613. (view-mode 1)
  614. (set-face-attribute 'diff-header nil
  615. :foreground nil
  616. :background nil
  617. :weight 'bold)
  618. (set-face-attribute 'diff-file-header nil
  619. :foreground nil
  620. :background nil
  621. :weight 'bold)
  622. (set-face-foreground 'diff-index-face "blue")
  623. (set-face-attribute 'diff-hunk-header nil
  624. :foreground "cyan"
  625. :weight 'normal)
  626. (set-face-attribute 'diff-context nil
  627. ;; :foreground "white"
  628. :foreground nil
  629. :weight 'normal)
  630. (set-face-foreground 'diff-removed-face "red")
  631. (set-face-foreground 'diff-added-face "green")
  632. (set-face-attribute 'diff-changed nil
  633. :foreground "magenta"
  634. :weight 'normal)
  635. ))
  636. ;; (ffap-bindings)
  637. (add-hook 'sh-mode-hook
  638. (lambda ()
  639. (define-key sh-mode-map
  640. (kbd "C-x C-e")
  641. 'my-execute-shell-command-current-line)))
  642. (setq sh-here-document-word "__EOC__")
  643. (defun my-execute-shell-command-current-line ()
  644. ""
  645. (interactive)
  646. (shell-command (buffer-substring-no-properties (point-at-bol)
  647. (point))))
  648. (setq auto-mode-alist
  649. `(("autostart\\'" . sh-mode)
  650. ("xinitrc\\'" . sh-mode)
  651. ("xprograms\\'" . sh-mode)
  652. ("PKGBUILD\\'" . sh-mode)
  653. ,@auto-mode-alist))
  654. (and (lazy-load-eval 'pkgbuild-mode)
  655. (setq auto-mode-alist (append '(("PKGBUILD\\'" . pkgbuild-mode))
  656. auto-mode-alist)))
  657. (add-hook 'text-mode-hook
  658. (lambda ()
  659. (define-key text-mode-map (kbd "C-m") 'newline)))
  660. (add-to-list 'Info-default-directory-list
  661. (expand-file-name "~/.info/emacs-ja"))
  662. (add-hook 'apropos-mode-hook
  663. (lambda ()
  664. (define-key apropos-mode-map "n" 'next-line)
  665. (define-key apropos-mode-map "p" 'previous-line)
  666. ))
  667. (add-hook 'isearch-mode-hook
  668. (lambda ()
  669. ;; (define-key isearch-mode-map
  670. ;; (kbd "C-j") 'isearch-other-control-char)
  671. ;; (define-key isearch-mode-map
  672. ;; (kbd "C-k") 'isearch-other-control-char)
  673. ;; (define-key isearch-mode-map
  674. ;; (kbd "C-h") 'isearch-other-control-char)
  675. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  676. (define-key isearch-mode-map (kbd "M-r")
  677. 'isearch-query-replace-regexp)))
  678. (add-hook 'outline-mode-hook
  679. (lambda ()
  680. (if (string-match "\\.md\\'" buffer-file-name)
  681. (set (make-local-variable 'outline-regexp) "#+ "))))
  682. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  683. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  684. (when (fetch-library
  685. "http://jblevins.org/projects/markdown-mode/markdown-mode.el"
  686. t)
  687. (lazy-load-eval 'markdown-mode)
  688. (setq markdown-command (or (executable-find "markdown")
  689. (executable-find "markdown.pl")))
  690. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'markdown-mode))
  691. (add-hook 'markdown-mode-hook
  692. (lambda ()
  693. (outline-minor-mode 1)
  694. (set (make-local-variable 'comment-start) ";"))))
  695. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  696. ;; c-mode
  697. ;; (setq c-default-style "bsd")
  698. (add-hook 'c-mode-common-hook
  699. (lambda ()
  700. (setq c-basic-offset 2
  701. indent-tabs-mode nil)
  702. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  703. (c-toggle-hungry-state -1)
  704. (and (require 'gtags nil t)
  705. (gtags-mode 1))
  706. ))
  707. (when (fetch-library
  708. "https://raw.github.com/mooz/js2-mode/master/js2-mode.el"
  709. t)
  710. (lazy-load-eval 'js2-mode)
  711. (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  712. (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  713. ;; (add-hook 'js2-mode-hook
  714. ;; (lambda ()
  715. (add-hook 'js2-mode-hook
  716. (lambda ()
  717. (define-key js2-mode-map (kbd "C-m") (lambda ()
  718. (interactive)
  719. (js2-enter-key)
  720. (indent-for-tab-command)))
  721. (add-hook (kill-local-variable 'before-save-hook)
  722. 'js2-before-save)
  723. ;; (add-hook 'before-save-hook
  724. ;; 'my-indent-buffer
  725. ;; nil
  726. ;; t)
  727. )))
  728. (when (require 'uniquify nil t)
  729. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  730. (setq uniquify-ignore-buffers-re "*[^*]+*")
  731. (setq uniquify-min-dir-content 1))
  732. (add-hook 'view-mode-hook
  733. (lambda()
  734. (define-key view-mode-map "j"
  735. (lambda() (interactive) (scroll-up 1)))
  736. (define-key view-mode-map "k"
  737. (lambda() (interactive) (scroll-down 1)))
  738. (define-key view-mode-map "v" 'toggle-read-only)
  739. (define-key view-mode-map "q" 'bury-buffer)
  740. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  741. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  742. ;; (define-key view-mode-map
  743. ;; "n" 'nonincremental-repeat-search-forward)
  744. ;; (define-key view-mode-map
  745. ;; "N" 'nonincremental-repeat-search-backward)
  746. (define-key view-mode-map "/" 'isearch-forward-regexp)
  747. (define-key view-mode-map "?" 'isearch-backward-regexp)
  748. (define-key view-mode-map "n" 'isearch-repeat-forward)
  749. (define-key view-mode-map "N" 'isearch-repeat-backward)
  750. ))
  751. (global-set-key "\M-r" 'view-mode)
  752. (setq view-read-only t)
  753. (add-hook 'Man-mode-hook
  754. (lambda ()
  755. (view-mode 1)
  756. (setq truncate-lines nil)))
  757. (setq Man-notify-method (if window-system
  758. 'newframe
  759. 'pushy))
  760. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  761. ;; python
  762. (when (lazy-load-eval 'python '(python-mode))
  763. (setq python-python-command (or (executable-find "python3")
  764. (executable-find "python")))
  765. (defun my-python-run-as-command ()
  766. ""
  767. (interactive)
  768. (shell-command (concat python-python-command " " buffer-file-name)))
  769. (defun my-python-display-python-buffer ()
  770. ""
  771. (interactive)
  772. (set-window-text-height (display-buffer python-buffer
  773. t)
  774. 7))
  775. (add-hook 'python-mode-hook
  776. (lambda ()
  777. (define-key python-mode-map
  778. (kbd "C-c C-e") 'my-python-run-as-command)
  779. (define-key python-mode-map
  780. (kbd "C-c C-b") 'my-python-display-python-buffer)
  781. (define-key python-mode-map (kbd "C-m") 'newline-and-indent)))
  782. (add-hook 'inferior-python-mode-hook
  783. (lambda ()
  784. (my-python-display-python-buffer)
  785. (define-key inferior-python-mode-map
  786. (kbd "<up>") 'comint-previous-input)
  787. (define-key inferior-python-mode-map
  788. (kbd "<down>") 'comint-next-input))))
  789. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  790. ;; GNU GLOBAL(gtags)
  791. ;; http://uguisu.skr.jp/Windows/gtags.html
  792. ;; http://eigyr.dip.jp/gtags.html
  793. ;; http://cha.la.coocan.jp/doc/gnu_global.html
  794. (when (lazy-load-eval 'gtags '(gtags-mode))
  795. (add-hook 'gtags-mode-hook
  796. (lambda ()
  797. (setq gtags-select-buffer-single t)
  798. ;; (local-set-key "\M-t" 'gtags-find-tag)
  799. ;; (local-set-key "\M-r" 'gtags-find-rtag)
  800. ;; (local-set-key "\M-s" 'gtags-find-symbol)
  801. ;; (local-set-key "\C-t" 'gtags-pop-stack)
  802. (define-key gtags-mode-map (kbd "C-x t h") 'gtags-find-tag-from-here)
  803. (define-key gtags-mode-map (kbd "C-x t t") 'gtags-find-tag)
  804. (define-key gtags-mode-map (kbd "C-x t r") 'gtags-find-rtag)
  805. (define-key gtags-mode-map (kbd "C-x t s") 'gtags-find-symbol)
  806. (define-key gtags-mode-map (kbd "C-x t p") 'gtags-find-pattern)
  807. (define-key gtags-mdoe-map (kbd "C-x t f") 'gtags-find-file)
  808. (define-key gtags-mode-map (kbd "C-x t b") 'gtags-pop-stack) ;back
  809. )))
  810. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  811. ;; term mode
  812. ;; (setq multi-term-program shell-file-name)
  813. (and (fetch-library "http://www.emacswiki.org/emacs/download/multi-term.el"
  814. t)
  815. (lazy-load-eval 'multi-term)
  816. (progn
  817. (setq multi-term-switch-after-close nil)
  818. (setq multi-term-dedicated-select-after-open-p t)
  819. (setq multi-term-dedicated-window-height 20)))
  820. (when (lazy-load-eval 'term '(term ansi-term))
  821. (defun my-term-quit-or-send-raw ()
  822. ""
  823. (interactive)
  824. (if (get-buffer-process (current-buffer))
  825. (call-interactively 'term-send-raw)
  826. (kill-buffer)))
  827. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  828. ;; (setq term-ansi-default-program shell-file-name)
  829. (add-hook 'term-setup-hook
  830. (lambda ()
  831. (setq term-display-table (make-display-table))))
  832. (add-hook 'term-mode-hook
  833. (lambda ()
  834. (unless (memq (current-buffer)
  835. (and (featurep 'multi-term)
  836. ;; current buffer is not multi-term buffer
  837. (multi-term-list)))
  838. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  839. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  840. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  841. ;; (define-key term-raw-map "\C-f" 'forward-char)
  842. ;; (define-key term-raw-map "\C-b" 'backward-char)
  843. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  844. (define-key term-raw-map
  845. "\C-x" (lookup-key (current-global-map) "\C-x"))
  846. (define-key term-raw-map
  847. "\C-z" (lookup-key (current-global-map) "\C-z"))
  848. )
  849. ;; (define-key term-raw-map "\C-xl" 'term-line-mode)
  850. ;; (define-key term-mode-map "\C-xc" 'term-char-mode)
  851. (define-key term-raw-map (kbd "<up>")
  852. (lambda () (interactive) (scroll-down 1)))
  853. (define-key term-raw-map (kbd "<down>")
  854. (lambda () (interactive) (scroll-up 1)))
  855. (define-key term-raw-map (kbd "<right>") 'scroll-up)
  856. (define-key term-raw-map (kbd "<left>") 'scroll-down)
  857. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  858. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  859. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  860. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  861. (define-key term-raw-map [delete] 'term-send-raw)
  862. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  863. (define-key term-raw-map "\C-y" 'term-paste)
  864. (define-key term-raw-map
  865. "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  866. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  867. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  868. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  869. ;; (define-key term-raw-map "\C-d" 'delete-char)
  870. (set (make-local-variable 'scroll-margin) 0)
  871. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  872. ;; (cua-mode 0)
  873. ;; (and cua-mode
  874. ;; (local-unset-key (kbd "C-c")))
  875. ;; (define-key cua--prefix-override-keymap
  876. ;;"\C-c" 'term-interrupt-subjob)
  877. (set (make-local-variable 'hl-line-range-function)
  878. (lambda ()
  879. '(0 . 0)))
  880. ))
  881. ;; (add-hook 'term-exec-hook 'forward-char)
  882. )
  883. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  884. ;; buffer switching
  885. (when (lazy-load-eval 'bs '(bs-show)
  886. ;; (add-to-list 'bs-configurations
  887. ;; '("processes" nil get-buffer-process ".*" nil nil))
  888. (add-to-list 'bs-configurations
  889. '("this-frame" nil (lambda (buf)
  890. (memq buf (my-frame-buffer-get)))
  891. ".*" nil nil))
  892. ;; (setq bs-configurations (list
  893. ;; '("processes" nil get-buffer-process ".*" nil nil)
  894. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  895. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  896. )
  897. ;; (global-set-key "\C-x\C-b" 'bs-show)
  898. (defalias 'list-buffers 'bs-show)
  899. (setq bs-default-configuration "files")
  900. (setq bs-default-sort-name "by nothing")
  901. (add-hook 'bs-mode-hook
  902. (lambda ()
  903. (setq bs-default-configuration "files")
  904. ;; (and bs--show-all
  905. ;; (call-interactively 'bs-toggle-show-all))
  906. (set (make-local-variable 'scroll-margin) 0))))
  907. (iswitchb-mode 1)
  908. (defun iswitchb-buffer-display-other-window ()
  909. ""
  910. (interactive)
  911. (let ((iswitchb-default-method 'display))
  912. (call-interactively 'iswitchb-buffer)))
  913. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  914. ;; sdic
  915. (when (lazy-load-eval 'sdic '(sdic-describe-word-at-point))
  916. ;; (define-key my-prefix-map "\C-w" 'sdic-describe-word)
  917. (define-key my-prefix-map "\C-t" 'sdic-describe-word-at-point-echo)
  918. (defun sdic-describe-word-at-point-echo ()
  919. ""
  920. (interactive)
  921. (save-window-excursion
  922. (sdic-describe-word-at-point))
  923. (save-excursion
  924. (set-buffer sdic-buffer-name)
  925. (message (buffer-substring (point-min)
  926. (progn (goto-char (point-min))
  927. (or (and (re-search-forward "^\\w"
  928. nil
  929. t
  930. 4)
  931. (progn (previous-line) t)
  932. (point-at-eol))
  933. (point-max)))))))
  934. (setq sdic-eiwa-dictionary-list '((sdicf-client "/usr/share/dict/gene.sdic")))
  935. (setq sdic-waei-dictionary-list
  936. '((sdicf-client "/usr/share/dict/jedict.sdic" (add-keys-to-headword t))))
  937. (setq sdic-disable-select-window t)
  938. (setq sdic-window-height 7))
  939. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  940. ;; vc
  941. ;; (require 'vc)
  942. (setq vc-handled-backends '())
  943. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  944. ;; gauche-mode
  945. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  946. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  947. (when (and (fetch-library
  948. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  949. t)
  950. (lazy-load-eval 'gauche-mode '(gauche-mode run-scheme)))
  951. (let ((s (executable-find "gosh")))
  952. (setq scheme-program-name s
  953. gauche-program-name s))
  954. (defun run-gauche-other-window ()
  955. "Run gauche on other window"
  956. (interactive)
  957. (switch-to-buffer-other-window
  958. (get-buffer-create "*scheme*"))
  959. (run-gauche))
  960. (defun run-gauche ()
  961. "run gauche"
  962. (run-scheme gauche-program-name)
  963. )
  964. (defun scheme-send-buffer ()
  965. ""
  966. (interactive)
  967. (scheme-send-region (point-min) (point-max))
  968. (my-scheme-display-scheme-buffer)
  969. )
  970. (defun my-scheme-display-scheme-buffer ()
  971. ""
  972. (interactive)
  973. (set-window-text-height (display-buffer scheme-buffer
  974. t)
  975. 7))
  976. (add-hook 'scheme-mode-hook
  977. (lambda ()
  978. nil))
  979. (add-hook 'inferior-scheme-mode-hook
  980. (lambda ()
  981. ;; (my-scheme-display-scheme-buffer)
  982. ))
  983. (setq auto-mode-alist
  984. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  985. (setq auto-mode-alist
  986. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  987. (add-hook 'gauche-mode-hook
  988. (lambda ()
  989. (define-key gauche-mode-map
  990. (kbd "C-c C-z") 'run-gauche-other-window)
  991. (define-key scheme-mode-map
  992. (kbd "C-c C-c") 'scheme-send-buffer)
  993. (define-key scheme-mode-map
  994. (kbd "C-c C-b") 'my-scheme-display-scheme-buffer))))
  995. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  996. ;; recentf-mode
  997. (setq recentf-save-file (expand-file-name "~/.emacs.d/recentf")
  998. recentf-max-menu-items 20
  999. recentf-max-saved-items 30
  1000. recentf-show-file-shortcuts-flag nil)
  1001. (when (require 'recentf nil t)
  1002. (add-to-list 'recentf-exclude (regexp-quote recentf-save-file))
  1003. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1004. (add-hook 'find-file-hook
  1005. 'recentf-save-list
  1006. t) ; save to file immediately after adding file to recentf list
  1007. (add-hook 'kill-emacs-hook
  1008. 'recentf-load-list)
  1009. (add-hook 'recentf-mode-hook
  1010. 'recentf-save-list)
  1011. ;; (add-hook 'find-file-hook
  1012. ;; (lambda ()
  1013. ;; (recentf-add-file default-directory)))
  1014. (and (fetch-library
  1015. "https://raw.github.com/10sr/emacs-lisp/master/recentf-show.el"
  1016. t)
  1017. (lazy-load-eval 'recentf-show)
  1018. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1019. (add-hook 'recentf-show-before-listing-hook
  1020. 'recentf-load-list))
  1021. (recentf-mode 1)
  1022. (add-hook 'recentf-dialog-mode-hook
  1023. (lambda ()
  1024. ;; (recentf-save-list)
  1025. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1026. ;; 'my-recentf-cd-and-find-file)
  1027. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1028. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1029. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1030. (define-key recentf-dialog-mode-map "n" 'next-line)
  1031. (cd "~/"))))
  1032. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1033. ;; dired
  1034. (when (lazy-load-eval 'dired nil)
  1035. (defun my-dired-echo-file-head (arg)
  1036. ""
  1037. (interactive "P")
  1038. (let ((f (dired-get-filename)))
  1039. (message "%s"
  1040. (with-temp-buffer
  1041. (insert-file-contents f)
  1042. (buffer-substring-no-properties
  1043. (point-min)
  1044. (progn (goto-line (if arg
  1045. (prefix-numeric-value arg)
  1046. 10))
  1047. (point-at-eol)))))))
  1048. (defun my-dired-diff ()
  1049. ""
  1050. (interactive)
  1051. (let ((files (dired-get-marked-files nil nil nil t)))
  1052. (if (eq (car files)
  1053. t)
  1054. (diff (cadr files) (dired-get-filename))
  1055. (message "One files must be marked!"))))
  1056. (defun my-pop-to-buffer-erase-noselect (buffer-or-name)
  1057. "pop up buffer using `display-buffer' and return that buffer."
  1058. (let ((bf (get-buffer-create buffer-or-name)))
  1059. (with-current-buffer bf
  1060. (cd ".")
  1061. (erase-buffer))
  1062. (display-buffer bf)
  1063. bf))
  1064. (defun my-replace-nasi-none ()
  1065. ""
  1066. (save-excursion
  1067. (let ((buffer-read-only nil))
  1068. (goto-char (point-min))
  1069. (while (search-forward "なし" nil t)
  1070. (replace-match "none")))))
  1071. (defun dired-get-file-info ()
  1072. "dired get file info"
  1073. (interactive)
  1074. (let ((f (shell-quote-argument (dired-get-filename t))))
  1075. (if (file-directory-p f)
  1076. (progn
  1077. (message "Calculating disk usage...")
  1078. (shell-command (concat "du -hsD "
  1079. f)))
  1080. (shell-command (concat "file "
  1081. f)))))
  1082. (defun my-dired-scroll-up ()
  1083. ""
  1084. (interactive)
  1085. (my-dired-previous-line (- (window-height) 1)))
  1086. (defun my-dired-scroll-down ()
  1087. ""
  1088. (interactive)
  1089. (my-dired-next-line (- (window-height) 1)))
  1090. ;; (defun my-dired-forward-line (arg)
  1091. ;; ""
  1092. ;; (interactive "p"))
  1093. (defun my-dired-previous-line (arg)
  1094. ""
  1095. (interactive "p")
  1096. (if (> arg 0)
  1097. (progn
  1098. (if (eq (line-number-at-pos)
  1099. 1)
  1100. (goto-char (point-max))
  1101. (forward-line -1))
  1102. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1103. (dired-get-subdir))
  1104. (- arg 1)
  1105. arg)))
  1106. (dired-move-to-filename)))
  1107. (defun my-dired-next-line (arg)
  1108. ""
  1109. (interactive "p")
  1110. (if (> arg 0)
  1111. (progn
  1112. (if (eq (point)
  1113. (point-max))
  1114. (goto-char (point-min))
  1115. (forward-line 1))
  1116. (my-dired-next-line (if (or (dired-get-filename nil t)
  1117. (dired-get-subdir))
  1118. (- arg 1)
  1119. arg)))
  1120. (dired-move-to-filename)))
  1121. (defun my-dired-print-current-dir-and-file ()
  1122. (message "%s %s"
  1123. default-directory
  1124. (buffer-substring-no-properties (point-at-bol)
  1125. (point-at-eol))))
  1126. (defun dired-do-execute-as-command ()
  1127. ""
  1128. (interactive)
  1129. (let ((file (dired-get-filename t)))
  1130. (if (file-executable-p file)
  1131. (start-process file nil file)
  1132. (when (y-or-n-p
  1133. "this file cant be executed. mark as executable and go? : ")
  1134. (set-file-modes file
  1135. (file-modes-symbolic-to-number "u+x" (file-modes file)))
  1136. (start-process file nil file)))))
  1137. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1138. (defun my-dired-x-open ()
  1139. ""
  1140. (interactive)
  1141. (my-x-open (dired-get-filename t t)))
  1142. (if (eq window-system 'mac)
  1143. (setq dired-listing-switches "-lhFG")
  1144. (setq dired-listing-switches "-lhFG --time-style=long-iso")
  1145. )
  1146. (setq dired-listing-switches "-lhFG")
  1147. (put 'dired-find-alternate-file 'disabled nil)
  1148. ;; when using dired-find-alternate-file
  1149. ;; reuse current dired buffer for the file to open
  1150. (setq dired-ls-F-marks-symlinks t)
  1151. (require 'ls-lisp)
  1152. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1153. (setq ls-lisp-dirs-first t)
  1154. (setq ls-lisp-use-localized-time-format t)
  1155. (setq ls-lisp-format-time-list
  1156. '("%Y-%m-%d %H:%M"
  1157. "%Y-%m-%d "))
  1158. (setq dired-dwim-target t)
  1159. ;; (add-hook 'dired-after-readin-hook
  1160. ;; 'my-replace-nasi-none)
  1161. ;; (add-hook 'after-init-hook
  1162. ;; (lambda ()
  1163. ;; (dired ".")))
  1164. (add-hook 'dired-mode-hook
  1165. (lambda ()
  1166. (define-key dired-mode-map "o" 'my-dired-x-open)
  1167. (define-key dired-mode-map "i" 'dired-get-file-info)
  1168. (define-key dired-mode-map "f" 'find-file)
  1169. (define-key dired-mode-map "!" 'shell-command)
  1170. (define-key dired-mode-map "&" 'async-shell-command)
  1171. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1172. (define-key dired-mode-map "=" 'my-dired-diff)
  1173. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1174. (define-key dired-mode-map "b" 'gtkbm)
  1175. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1176. (define-key dired-mode-map "@" (lambda ()
  1177. (interactive) (my-x-open ".")))
  1178. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1179. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1180. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1181. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1182. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1183. (substitute-key-definition 'dired-next-line
  1184. 'my-dired-next-line dired-mode-map)
  1185. (substitute-key-definition 'dired-previous-line
  1186. 'my-dired-previous-line dired-mode-map)
  1187. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1188. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1189. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1190. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1191. (let ((file "._Icon\015"))
  1192. (when nil (file-readable-p file)
  1193. (delete-file file)))))
  1194. (and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/pack.el"
  1195. t)
  1196. (lazy-load-eval 'pack '(dired-do-pack-or-unpack pack))
  1197. (add-hook 'dired-mode-hook
  1198. (lambda ()
  1199. (define-key dired-mode-map "P" 'dired-do-pack-or-unpack))))
  1200. (and (fetch-library
  1201. "https://raw.github.com/10sr/emacs-lisp/master/dired-list-all-mode.el"
  1202. t)
  1203. (lazy-load-eval 'dired-list-all-mode)
  1204. (setq dired-listing-switches "-lhFG")
  1205. (add-hook 'dired-mode-hook
  1206. (lambda ()
  1207. (define-key dired-mode-map "a" 'dired-list-all-mode)
  1208. )))
  1209. ) ; when dired locate
  1210. ;; http://blog.livedoor.jp/tek_nishi/archives/4693204.html
  1211. (defun my-dired-toggle-mark()
  1212. (let ((cur (cond ((eq (following-char) dired-marker-char) ?\040)
  1213. (t dired-marker-char))))
  1214. (delete-char 1)
  1215. (insert cur)))
  1216. (defun my-dired-mark (arg)
  1217. "toggle mark the current (or next ARG) files.
  1218. If on a subdir headerline, mark all its files except `.' and `..'.
  1219. Use \\[dired-unmark-all-files] to remove all marks
  1220. and \\[dired-unmark] on a subdir to remove the marks in
  1221. this subdir."
  1222. (interactive "P")
  1223. (if (dired-get-subdir)
  1224. (save-excursion (dired-mark-subdir-files))
  1225. (let ((inhibit-read-only t))
  1226. (dired-repeat-over-lines
  1227. (prefix-numeric-value arg)
  1228. 'my-dired-toggle-mark))))
  1229. (defun my-dired-mark-backward (arg)
  1230. "In Dired, move up lines and toggle mark there.
  1231. Optional prefix ARG says how many lines to unflag; default is one line."
  1232. (interactive "p")
  1233. (my-dired-mark (- arg)))
  1234. (add-hook 'dired-mode-hook
  1235. (lambda ()
  1236. (local-set-key (kbd "SPC") 'my-dired-mark)
  1237. (local-set-key (kbd "S-SPC") 'my-dired-mark-backward))
  1238. )
  1239. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1240. ;; eshell
  1241. (lazy-load-eval 'eshell nil
  1242. (defun my-eshell-backward-delete-char ()
  1243. (interactive)
  1244. (when (< (save-excursion
  1245. (eshell-bol)
  1246. (point))
  1247. (point))
  1248. (backward-delete-char 1)))
  1249. (defun my-file-owner-p (file)
  1250. "t if FILE is owned by me."
  1251. (eq (user-uid) (nth 2 (file-attributes file))))
  1252. "http://www.bookshelf.jp/pukiwiki/pukiwiki.php\
  1253. ?Eshell%A4%F2%BB%C8%A4%A4%A4%B3%A4%CA%A4%B9"
  1254. ;; ;; written by Stefan Reichoer <reichoer@web.de>
  1255. ;; (defun eshell/less (&rest args)
  1256. ;; "Invoke `view-file' on the file.
  1257. ;; \"less +42 foo\" also goes to line 42 in the buffer."
  1258. ;; (if args
  1259. ;; (while args
  1260. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1261. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1262. ;; (file (pop args)))
  1263. ;; (view-file file)
  1264. ;; (goto-line line))
  1265. ;; (view-file (pop args))))))
  1266. (defun eshell/o (&optional file)
  1267. (my-x-open (or file ".")))
  1268. ;; (defun eshell/vi (&rest args)
  1269. ;; "Invoke `find-file' on the file.
  1270. ;; \"vi +42 foo\" also goes to line 42 in the buffer."
  1271. ;; (while args
  1272. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1273. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1274. ;; (file (pop args)))
  1275. ;; (find-file file)
  1276. ;; (goto-line line))
  1277. ;; (find-file (pop args)))))
  1278. (defun eshell/clear ()
  1279. "Clear the current buffer, leaving one prompt at the top."
  1280. (let ((inhibit-read-only t))
  1281. (erase-buffer)))
  1282. (defun eshell/d (&optional dirname switches)
  1283. "if first arg is omitted open current directory."
  1284. (dired (or dirname ".") switches))
  1285. (defun eshell/v ()
  1286. (view-mode 1))
  1287. (defun eshell/git (&rest args)
  1288. ""
  1289. (if (member (car args)
  1290. '("di" "diff" "log" "show"))
  1291. (apply 'eshell-exec-visual "git" args)
  1292. (shell-command (mapconcat 'shell-quote-argument
  1293. `("git" ,@args)
  1294. " ")
  1295. t)
  1296. ;; (eshell-external-command "git" args)
  1297. ))
  1298. (defalias 'eshell/: 'ignore)
  1299. (defalias 'eshell/type 'eshell/which)
  1300. ;; (defalias 'eshell/vim 'eshell/vi)
  1301. (defalias 'eshell/ff 'find-file)
  1302. (defalias 'eshell/q 'eshell/exit)
  1303. (defun eshell-goto-prompt ()
  1304. ""
  1305. (interactive)
  1306. (goto-char (point-max)))
  1307. (defun eshell-cd-default-directory (&optional eshell-buffer-or-name)
  1308. "open eshell and change wd
  1309. if arg given, use that eshell buffer, otherwise make new eshell buffer."
  1310. (interactive)
  1311. (let ((dir (expand-file-name default-directory)))
  1312. (switch-to-buffer (or eshell-buffer-or-name
  1313. (eshell t)))
  1314. (unless (equal dir (expand-file-name default-directory))
  1315. ;; (cd dir)
  1316. ;; (eshell-interactive-print (concat "cd " dir "\n"))
  1317. ;; (eshell-emit-prompt)
  1318. (goto-char (point-max))
  1319. (eshell-kill-input)
  1320. (insert "cd " dir)
  1321. (eshell-send-input))))
  1322. (setq eshell-directory-name "~/.emacs.d/eshell/")
  1323. (setq eshell-term-name "eterm-color")
  1324. (setq eshell-scroll-to-bottom-on-input t)
  1325. (setq eshell-cmpl-ignore-case t)
  1326. (setq eshell-cmpl-cycle-completions nil)
  1327. (setq eshell-highlight-prompt nil)
  1328. (setq eshell-ls-initial-args '("-hCFG"
  1329. "--color=auto"
  1330. "--time-style=long-iso")) ; "-hF")
  1331. (setq eshell-prompt-function
  1332. (lambda ()
  1333. (with-temp-buffer
  1334. (let (p1 p2 p3 p4)
  1335. (insert " [")
  1336. (setq p1 (point))
  1337. (insert (abbreviate-file-name default-directory))
  1338. (setq p2 (point))
  1339. (insert "]"
  1340. "\n")
  1341. (setq p3 (point))
  1342. (insert user-login-name
  1343. "@"
  1344. (or (getenv "HOSTNAME")
  1345. (substring (shell-command-to-string
  1346. (or (executable-find "hostname")
  1347. "echo ''"))
  1348. 0
  1349. -1)))
  1350. (setq p4 (point))
  1351. (insert " "
  1352. (format-time-string "%a, %d %b %Y %T %z")
  1353. " eshell\n"
  1354. "last:"
  1355. (number-to-string eshell-last-command-status)
  1356. (if (= (user-uid)
  1357. 0)
  1358. " # "
  1359. " $ "))
  1360. (add-text-properties p1
  1361. p2
  1362. '(face ((foreground-color . "yellow"))))
  1363. (add-text-properties p3
  1364. p4
  1365. '(face ((foreground-color . "cyan"))))
  1366. (buffer-substring (point-min)
  1367. (point-max))))))
  1368. (add-hook 'eshell-mode-hook
  1369. (lambda ()
  1370. ;; (define-key eshell-mode-map (kbd "C-x C-x") (lambda ()
  1371. ;; (interactive)
  1372. ;; (switch-to-buffer (other-buffer))))
  1373. (define-key eshell-mode-map (kbd "C-u") (lambda ()
  1374. (interactive)
  1375. (eshell-goto-prompt)
  1376. (eshell-kill-input)))
  1377. (define-key eshell-mode-map (kbd "C-g") (lambda ()
  1378. (interactive)
  1379. (eshell-goto-prompt)
  1380. (my-keyboard-quit)))
  1381. (define-key eshell-mode-map
  1382. (kbd "DEL") 'my-eshell-backward-delete-char)
  1383. (define-key eshell-mode-map
  1384. (kbd "C-p") 'eshell-previous-matching-input-from-input)
  1385. (define-key eshell-mode-map
  1386. (kbd "C-n") 'eshell-next-matching-input-from-input)
  1387. (apply 'eshell/addpath exec-path)
  1388. (set (make-local-variable 'scroll-margin) 0)
  1389. ;; (eshell/export "GIT_PAGER=")
  1390. ;; (eshell/export "GIT_EDITOR=")
  1391. (eshell/export "LC_MESSAGES=C")
  1392. (switch-to-buffer (current-buffer)) ; move buffer top of list
  1393. (set (make-local-variable 'hl-line-range-function)
  1394. (lambda ()
  1395. '(0 . 0)))
  1396. (add-to-list 'eshell-virtual-targets
  1397. '("/dev/less"
  1398. (lambda (str)
  1399. (if str
  1400. (with-current-buffer nil)))
  1401. nil))
  1402. ))
  1403. (add-hook 'eshell-mode-hook
  1404. (lambda ()
  1405. (add-to-list 'eshell-visual-commands "vim")
  1406. ;; (add-to-list 'eshell-visual-commands "git")
  1407. (add-to-list 'eshell-output-filter-functions
  1408. 'eshell-truncate-buffer)
  1409. (mapcar (lambda (alias)
  1410. (add-to-list 'eshell-command-aliases-list
  1411. alias))
  1412. '(
  1413. ; ("ll" "ls -l $*")
  1414. ; ("la" "ls -a $*")
  1415. ; ("lla" "ls -al $*")
  1416. ("aptin" "apt-get install $*")
  1417. ("eless"
  1418. (concat "cat >>> (with-current-buffer "
  1419. "(get-buffer-create \"*eshell output\") "
  1420. "(erase-buffer) "
  1421. "(setq buffer-read-only nil) "
  1422. "(current-buffer)) "
  1423. "(view-buffer (get-buffer \"*eshell output*\"))")
  1424. ("g" "git $*")
  1425. ))
  1426. )))
  1427. ) ; eval after load eshell
  1428. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1429. ;; frame buffer
  1430. ;; todo: work well when opening files already opened on another window
  1431. (add-hook 'after-make-frame-functions
  1432. (lambda (f)
  1433. (set-window-buffer (frame-selected-window f)
  1434. "*Messages*")))
  1435. (defun make-frame-command-with-name (name)
  1436. "Make frame with name specified."
  1437. (interactive "sName for new frame: ")
  1438. (set-frame-parameter (make-frame-command)
  1439. 'name
  1440. name))
  1441. (defvar my-frame-buffer-plist nil)
  1442. (defun my-frame-buffer-add (&optional buf frame)
  1443. ""
  1444. (setq my-frame-buffer-plist
  1445. (plist-put my-frame-buffer-plist
  1446. (or frame
  1447. (selected-frame))
  1448. (let ((lst (my-frame-buffer-get frame)))
  1449. (if lst
  1450. (add-to-list 'lst
  1451. (or buf
  1452. (current-buffer)))
  1453. (list (or buf
  1454. (current-buffer))))))))
  1455. (defun my-frame-buffer-remove (&optional buf frame)
  1456. ""
  1457. (setq my-frame-buffer-plist
  1458. (plist-put my-frame-buffer-plist
  1459. (or frame
  1460. (selected-frame))
  1461. (delq (or buf
  1462. (current-buffer))
  1463. (my-frame-buffer-get frame)))))
  1464. (defun my-frame-buffer-get (&optional frame)
  1465. ""
  1466. (plist-get my-frame-buffer-plist
  1467. (or frame
  1468. (selected-frame))))
  1469. (defun my-frame-buffer-kill-all-buffer (&optional frame)
  1470. ""
  1471. (mapcar 'kill-buffer
  1472. (my-frame-buffer-get frame)))
  1473. (add-hook 'find-file-hook
  1474. 'my-frame-buffer-add)
  1475. ;; (add-hook 'term-mode-hook
  1476. ;; 'my-frame-buffer-add)
  1477. (add-hook 'eshell-mode-hook
  1478. 'my-frame-buffer-add)
  1479. (add-hook 'Man-mode-hook
  1480. 'my-frame-buffer-add)
  1481. (add-hook 'kill-buffer-hook
  1482. 'my-frame-buffer-remove)
  1483. (add-hook 'delete-frame-functions
  1484. 'my-frame-buffer-kill-all-buffer)
  1485. (defvar my-desktop-terminal "roxterm")
  1486. (defun my-execute-terminal ()
  1487. ""
  1488. (interactive)
  1489. (if (and (or (eq system-type 'windows-nt)
  1490. window-system)
  1491. my-desktop-terminal
  1492. )
  1493. (let ((process-environment (cons "TERM=xterm" process-environment)))
  1494. (start-process "terminal"
  1495. nil
  1496. my-desktop-terminal))
  1497. (my-term)))
  1498. (defvar my-term nil "my terminal buffer")
  1499. (defun my-term ()
  1500. "open terminal buffer and return that buffer."
  1501. (interactive)
  1502. (if (and my-term
  1503. (buffer-name my-term))
  1504. (pop-to-buffer my-term)
  1505. (setq my-term
  1506. (save-window-excursion
  1507. (if (eq system-type 'windows-nt)
  1508. (eshell)
  1509. (if (require 'multi-term nil t)
  1510. (multi-term)
  1511. (ansi-term shell-file-name)))))
  1512. (my-term)))
  1513. (defun my-delete-frame-or-kill-emacs ()
  1514. "delete frame when opening multiple frame, kill emacs when only one."
  1515. (interactive)
  1516. (if (eq 1
  1517. (length (frame-list)))
  1518. (save-buffers-kill-emacs)
  1519. (delete-frame)))
  1520. (define-key my-prefix-map (kbd "C-s") 'my-execute-terminal)
  1521. (define-key my-prefix-map (kbd "C-f") 'make-frame-command-with-name)
  1522. (global-set-key (kbd "C-x C-c") 'my-delete-frame-or-kill-emacs)
  1523. (define-key my-prefix-map (kbd "C-x C-c") 'save-buffers-kill-emacs)
  1524. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1525. ;; x open
  1526. (defvar my-filer nil)
  1527. (setq my-filer (or (executable-find "pcmanfm")
  1528. (executable-find "nautilus")))
  1529. (defun my-x-open (file)
  1530. "open file."
  1531. (interactive "FOpen File: ")
  1532. (setq file (expand-file-name file))
  1533. (message "Opening %s..." file)
  1534. (cond ((eq system-type 'windows-nt)
  1535. (call-process "cmd.exe" nil 0 nil
  1536. "/c" "start" "" (convert-standard-filename file)))
  1537. ((eq system-type 'darwin)
  1538. (call-process "open" nil 0 nil file))
  1539. ((getenv "DISPLAY")
  1540. (call-process (or my-filer "xdg-open") nil 0 nil file))
  1541. (t
  1542. (find-file file))
  1543. )
  1544. ;; (recentf-add-file file)
  1545. (message "Opening %s...done" file))
  1546. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1547. ;; misc funcs
  1548. (defvar sed-in-place-history nil
  1549. "History of `sed-in-place'")
  1550. (defvar sed-in-place-command "sed --in-place=.bak -e")
  1551. (defun sed-in-place (command)
  1552. "sed in place"
  1553. (interactive (list (read-shell-command "sed in place: "
  1554. (concat sed-in-place-command " ")
  1555. 'sed-in-place-history)))
  1556. (shell-command command
  1557. "*sed in place*"))
  1558. (defun dired-do-sed-in-place (&optional arg)
  1559. "sed in place dired"
  1560. (interactive "P")
  1561. (require 'dired-aux)
  1562. (let* ((files (dired-get-marked-files t arg))
  1563. (expr (dired-mark-read-string "Run sed-in-place for %s: "
  1564. nil
  1565. 'sed-in-place
  1566. arg
  1567. files)))
  1568. (if (equal expr
  1569. "")
  1570. (error "No expression specified")
  1571. (shell-command (concat sed-in-place-command
  1572. " '"
  1573. expr
  1574. "' "
  1575. (mapconcat 'shell-quote-argument
  1576. files
  1577. " "))
  1578. "*sed in place*"))))
  1579. (defun dir-show (&optional dir)
  1580. (interactive)
  1581. (let ((bf (get-buffer-create "*dir show*"))
  1582. (list-directory-brief-switches "-C"))
  1583. (with-current-buffer bf
  1584. (list-directory (or nil
  1585. default-directory)
  1586. nil))
  1587. ))
  1588. (defun my-convmv-sjis2utf8-test ()
  1589. "run `convmv -r -f sjis -t utf8 *'
  1590. this is test, does not rename files"
  1591. (interactive)
  1592. (shell-command "convmv -r -f sjis -t utf8 *"))
  1593. (defun my-convmv-sjis2utf8-notest ()
  1594. "run `convmv -r -f sjis -t utf8 * --notest'"
  1595. (interactive)
  1596. (shell-command "convmv -r -f sjis -t utf8 * --notest"))
  1597. (defun kill-ring-save-buffer-file-name ()
  1598. "get current filename"
  1599. (interactive)
  1600. (let ((file buffer-file-name))
  1601. (if file
  1602. (progn (kill-new file)
  1603. (message file))
  1604. (message "not visiting file."))))
  1605. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1606. ;; ;; savage emacs
  1607. ;; ;; when enabled emacs fails to complete
  1608. ;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html
  1609. ;; (defadvice message (before message-for-stupid (arg &rest arg2) activate)
  1610. ;; (setq arg
  1611. ;; (concat arg
  1612. ;; (if (eq nil (string-match "\\. *$" arg)) ".")
  1613. ;; " Stupid!")))
  1614. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1615. ;; japanese input method
  1616. (defun my-load-scim ()
  1617. "use scim-bridge.el as japanese im."
  1618. ;; Load scim-bridge.
  1619. (when (require 'scim-bridge nil t)
  1620. ;; Turn on scim-mode automatically after loading .emacs
  1621. (add-hook 'after-init-hook 'scim-mode-on)
  1622. (setq scim-cursor-color "red")
  1623. (scim-define-preedit-key ?\^h t)
  1624. (scim-define-common-key ?\* nil)
  1625. (scim-define-common-key ?\^/ nil)))
  1626. (defun my-load-anthy ()
  1627. "use anthy.el as japanese im."
  1628. ;; anthy
  1629. (when (require 'anthy nil t)
  1630. (global-set-key
  1631. (kbd "<muhenkan>") (lambda () (interactive) (anthy-mode-off)))
  1632. (global-set-key (kbd "<henkan>") (lambda () (interactive) (anthy-mode-on)))
  1633. (when (>= emacs-major-version 23)
  1634. (setq anthy-accept-timeout 1))))
  1635. ;; quail
  1636. ;; aproposs input-method for some information
  1637. ;; (setq default-input-method "japanese")
  1638. (defun my-load-mozc-el ()
  1639. ""
  1640. (setq mozc-leim-title "[MZ]")
  1641. (when (require 'mozc nil t)
  1642. (setq defauit-input-method "japanese-mozc")
  1643. ))
  1644. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1645. ;; for windows
  1646. (defun start-ckw-bash ()
  1647. ""
  1648. (interactive)
  1649. (start-process
  1650. "ckw_bash"
  1651. nil
  1652. "C:/Documents and Settings/sr/Application Data/dbx/apps/ckw/ckw.exe"))
  1653. ;; command seems to have to be in c drive
  1654. (defun my-w32-add-export-path (&rest args)
  1655. ""
  1656. (mapcar (lambda (path)
  1657. (add-to-list 'exec-path (expand-file-name path)))
  1658. (reverse args))
  1659. (setenv "PATH"
  1660. (mapconcat 'convert-standard-filename
  1661. exec-path
  1662. ";")))
  1663. (when (eq system-type 'windows-nt)
  1664. ;; (setq scheme-program-name "\"c:/Program Files/Gauche/bin/gosh.exe\" -i")
  1665. ;; (setq python-python-command "c:/Python26/python.exe")
  1666. (define-key my-prefix-map (kbd "C-c") 'start-ckw-bash)
  1667. (my-w32-add-export-path "c:/Windows/system"
  1668. "c:/Windows/System32"
  1669. "c:/Program Files/Git/bin"
  1670. "c:/MinGW/bin"
  1671. "c:/MinGW/mingw32/bin"
  1672. (expand-file-name "~/.local/bin")
  1673. (expand-file-name "~/dbx/apps/bin"))
  1674. (when window-system
  1675. (setq w32-enable-synthesized-fonts t))
  1676. (setq file-name-coding-system 'sjis))