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

emacs.el 65 KiB

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