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 68 KiB

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