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

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