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

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