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

emacs.el 68 KiB

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