Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

emacs.el 88 KiB

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