Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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