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 70 KiB

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