Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

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