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

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