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