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

emacs.el 90 KiB

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