您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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