Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

emacs.el 87 KiB

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