Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

emacs.el 93 KiB

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