Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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