Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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