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.

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