25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

emacs.el 73 KiB

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