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

пре 11 година
пре 9 година
пре 13 година
пре 8 година
пре 12 година
пре 12 година
пре 13 година
пре 13 година
пре 9 година
пре 8 година
пре 8 година
пре 8 година
пре 10 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 11 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 11 година
пре 8 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 13 година
пре 13 година
пре 12 година
пре 12 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 13 година
пре 9 година
пре 9 година
пре 9 година
пре 13 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 10 година
пре 12 година
пре 13 година
пре 9 година
пре 13 година
пре 12 година
пре 13 година
пре 10 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 12 година
пре 8 година
пре 8 година
пре 8 година
пре 12 година
пре 12 година
пре 11 година
пре 11 година
пре 8 година
пре 10 година
пре 8 година
пре 9 година
пре 8 година
пре 9 година
пре 11 година
пре 11 година
пре 12 година
пре 8 година
пре 12 година
пре 10 година
пре 10 година
пре 8 година
пре 12 година
пре 12 година
пре 10 година
пре 12 година
пре 11 година
пре 13 година
пре 12 година
пре 13 година
пре 13 година
пре 12 година
пре 8 година
пре 13 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 13 година
пре 13 година
пре 13 година
пре 11 година
пре 12 година
пре 12 година
пре 10 година
пре 13 година
пре 13 година
пре 9 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 13 година
пре 8 година
пре 12 година
пре 8 година
пре 12 година
пре 12 година
пре 8 година
пре 8 година
пре 13 година
пре 8 година
пре 8 година
пре 8 година
пре 13 година
пре 13 година
пре 8 година
пре 12 година
пре 8 година
пре 12 година
пре 11 година
пре 11 година
пре 8 година
пре 11 година
пре 13 година
пре 13 година
пре 9 година
пре 12 година
пре 12 година
пре 12 година
пре 9 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 12 година
пре 8 година
пре 12 година
пре 12 година
пре 10 година
пре 12 година
пре 10 година
пре 11 година
пре 12 година
пре 12 година
пре 12 година
пре 9 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 8 година
пре 11 година
пре 9 година
пре 11 година
пре 9 година
пре 12 година
пре 8 година
пре 12 година
пре 13 година
пре 13 година
пре 8 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 9 година
пре 8 година
пре 9 година
пре 11 година
пре 11 година
пре 13 година
пре 10 година
пре 13 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 9 година
пре 8 година
пре 8 година
пре 9 година
пре 8 година
пре 13 година
пре 13 година
пре 8 година
пре 13 година
пре 9 година
пре 13 година
пре 9 година
пре 8 година
пре 9 година
пре 11 година
пре 13 година
пре 8 година
пре 10 година
пре 13 година
пре 13 година
пре 10 година
пре 13 година
пре 13 година
пре 10 година
пре 10 година
пре 13 година
пре 10 година
пре 12 година
пре 12 година
пре 13 година
пре 13 година
пре 8 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 9 година
пре 12 година
пре 12 година
пре 13 година
пре 9 година
пре 11 година
пре 8 година
пре 12 година
пре 12 година
пре 8 година
пре 12 година
пре 12 година
пре 13 година
пре 13 година
пре 10 година
пре 13 година
пре 10 година
пре 10 година
пре 8 година
пре 8 година
пре 10 година
пре 13 година
пре 8 година
пре 13 година
пре 8 година
пре 13 година
пре 12 година
пре 9 година
пре 9 година
пре 12 година
пре 11 година
пре 13 година
пре 13 година
пре 8 година
пре 12 година
пре 13 година
пре 8 година
пре 8 година
пре 12 година
пре 8 година
пре 12 година
пре 8 година
пре 12 година
пре 8 година
пре 8 година
пре 12 година
пре 12 година
пре 8 година
пре 8 година
пре 10 година
пре 10 година
пре 10 година
пре 12 година
пре 11 година
пре 11 година
пре 11 година
пре 10 година
пре 10 година
пре 12 година
пре 8 година
пре 11 година
пре 10 година
пре 11 година
пре 11 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 11 година
пре 10 година
пре 9 година
пре 10 година
пре 11 година
пре 11 година
пре 10 година
пре 9 година
пре 10 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 9 година
пре 11 година
пре 8 година
пре 8 година
пре 8 година
пре 8 година
пре 11 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918
  1. ;;; emacs.el --- 10sr emacs initialization
  2. ;;; Commentary:
  3. ;;; Code:
  4. ;; SETUP_LOAD: (let ((file "DOTFILES_DIR/emacs.el"))
  5. ;; SETUP_LOAD: (and (file-readable-p file)
  6. ;; SETUP_LOAD: (load-file file)))
  7. (setq debug-on-error t)
  8. ;; make directories
  9. (unless (file-directory-p (expand-file-name user-emacs-directory))
  10. (make-directory (expand-file-name user-emacs-directory)))
  11. (let ((d (expand-file-name (concat user-emacs-directory
  12. "lisp"))))
  13. (unless (file-directory-p d)
  14. (make-directory d))
  15. (add-to-list 'load-path d))
  16. (require 'cl-lib)
  17. (require 'simple)
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19. ;; Some macros for internals
  20. ;; `emacs --load emacs.el` with Emacs 24.3 requires with-eval-after-load to be
  21. ;; defined at the toplevel (means that it should not be defined inside of some
  22. ;; special forms like `when'. I do not now how to do with about this...)
  23. (unless (fboundp 'with-eval-after-load)
  24. ;; polyfill for Emacs < 24.4
  25. (defmacro with-eval-after-load (file &rest body)
  26. "After FILE is loaded execute BODY."
  27. (declare (indent 1) (debug t))
  28. `(eval-after-load ,file (quote (progn ,@body)))))
  29. (defun call-after-init (func)
  30. "If `after-init-hook' has been run, call FUNC immediately.
  31. Otherwize hook it."
  32. (if after-init-time
  33. (funcall func)
  34. (add-hook 'after-init-hook
  35. func)))
  36. (defmacro safe-require-or-eval (feature)
  37. "Require FEATURE if available.
  38. At compile time the feature will be loaded immediately."
  39. `(eval-and-compile
  40. (message "safe-require-or-eval: Trying to require %s" ,feature)
  41. (require ,feature nil t)))
  42. (defmacro autoload-eval-lazily (feature &optional functions &rest body)
  43. "Define autoloading FEATURE that defines FUNCTIONS.
  44. FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
  45. the function same as FEATURE is defined as autoloaded function. BODY is passed
  46. to `eval-after-load'.
  47. After this macro is expanded, this returns the path to library if FEATURE
  48. found, otherwise returns nil."
  49. (declare (indent 2) (debug t))
  50. (let* ((libname (symbol-name (eval feature)))
  51. (libpath (locate-library libname)))
  52. `(progn
  53. (when (locate-library ,libname)
  54. ,@(mapcar (lambda (f)
  55. `(unless (fboundp ',f)
  56. (progn
  57. (message "Autoloaded function `%S' defined (%s)"
  58. (quote ,f)
  59. ,libpath)
  60. (autoload (quote ,f)
  61. ,libname
  62. ,(concat "Autoloaded function defined in \""
  63. libpath
  64. "\".")
  65. t))))
  66. (or (eval functions)
  67. `(,(eval feature)))))
  68. (eval-after-load ,feature
  69. (quote (progn
  70. ,@body)))
  71. (locate-library ,libname))))
  72. (when (autoload-eval-lazily 'tetris nil
  73. (message "Tetris loaded!"))
  74. (message "Tetris found!"))
  75. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  76. ;; download library from web
  77. (defvar fetch-library-enabled-p t
  78. "Set nil to skip downloading with `fetch-library'.")
  79. (defun fetch-library (url &optional byte-compile-p force-download-p)
  80. "Download a library from URL and locate it in \"~/emacs.d/lisp/\".
  81. Return nil if library unfound and failed to download,
  82. otherwise the path where the library installed.
  83. If BYTE-COMPILE-P is t byte compile the file after downloading.
  84. If FORCE-DOWNLOAD-P it t ignore exisiting library and always download.
  85. This function also checks the value of `fetch-library-enabled-p' and do not
  86. fetch libraries if this value is nil. In this case all arguments (including
  87. FORCE-DOWNLOAD-P) will be ignored."
  88. (let* ((dir (expand-file-name (concat user-emacs-directory "lisp/")))
  89. (lib (file-name-sans-extension (file-name-nondirectory url)))
  90. (lpath (concat dir lib ".el"))
  91. (locate-p (locate-library lib)))
  92. (if (and fetch-library-enabled-p
  93. (or force-download-p
  94. (not locate-p)))
  95. (if (progn (message "Downloading %s..."
  96. url)
  97. (download-file url
  98. lpath
  99. t))
  100. (progn (message "Downloading %s...done"
  101. url)
  102. (when (and byte-compile-p
  103. (require 'bytecomp nil t))
  104. (and (file-exists-p (byte-compile-dest-file lpath))
  105. (delete-file (byte-compile-dest-file lpath)))
  106. (message "Byte-compiling %s..."
  107. lpath)
  108. (byte-compile-file lpath)
  109. (message "Byte-compiling %s...done"
  110. lpath)))
  111. (progn (and (file-writable-p lpath)
  112. (delete-file lpath))
  113. (message "Downloading %s...failed"
  114. url))))
  115. (locate-library lib)))
  116. ;; If EMACS_EL_DRY_RUN is set and it is not an empty string, fetch-library
  117. ;; does not actually fetch library.
  118. (let ((dryrun (getenv "EMACS_EL_DRY_RUN")))
  119. (when (and dryrun
  120. (< 0
  121. (length dryrun)))
  122. (setq fetch-library-enabled-p
  123. nil)
  124. (message "EMACS_EL_DRY_RUN is set. Skip fetching libraries.")))
  125. (defun download-file (url path &optional ok-if-already-exists)
  126. "Download file from URL and output to PATH.
  127. IF OK-IF-ALREADY-EXISTS is true force download."
  128. (let ((curl (executable-find "curl"))
  129. (wget (executable-find "wget")))
  130. (cond (wget
  131. (if (and (not ok-if-already-exists)
  132. (file-exists-p path))
  133. nil
  134. (and (eq 0
  135. (call-process wget
  136. nil
  137. nil
  138. nil
  139. "-O"
  140. path
  141. url
  142. ))
  143. path)))
  144. (curl
  145. (if (and (not ok-if-already-exists)
  146. (file-exists-p path))
  147. nil
  148. (and (eq 0
  149. (call-process curl
  150. nil
  151. nil
  152. nil
  153. "--output"
  154. path
  155. "-L"
  156. url
  157. ))
  158. path)))
  159. (t
  160. (ignore-errors
  161. (require 'url)
  162. (url-copy-file url
  163. path
  164. ok-if-already-exists)
  165. path)))))
  166. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  167. ;; package
  168. (set (defvar 10sr-package-list)
  169. '(
  170. markdown-mode
  171. yaml-mode
  172. gnuplot-mode
  173. php-mode
  174. erlang
  175. js2-mode
  176. git-commit
  177. gitignore-mode
  178. adoc-mode
  179. malabar-mode
  180. ;; ack
  181. color-moccur
  182. ggtags
  183. flycheck
  184. auto-highlight-symbol
  185. ;; is flymake installs are required?
  186. ;;flymake-jshint
  187. ;;flymake-python-pyflakes
  188. xclip
  189. foreign-regexp
  190. multi-term
  191. term-run
  192. editorconfig
  193. git-ps1-mode
  194. restart-emacs
  195. fill-column-indicator
  196. pkgbuild-mode
  197. minibuffer-line
  198. scala-mode2
  199. ensime
  200. editorconfig
  201. cyberpunk-theme
  202. grandshell-theme
  203. afternoon-theme
  204. git-command
  205. prompt-text
  206. ;; 10sr repository
  207. ;; 10sr-extras
  208. terminal-title
  209. recentf-show
  210. dired-list-all-mode
  211. pack
  212. set-modeline-color
  213. read-only-only-mode
  214. smart-revert
  215. autosave
  216. ;;window-organizer
  217. remember-major-modes-mode
  218. ilookup
  219. pasteboard
  220. ))
  221. (when (safe-require-or-eval 'package)
  222. (setq package-archives
  223. `(,@package-archives
  224. ("melpa" . "https://melpa.org/packages/")
  225. ("10sr-el" . "https://10sr.github.io/emacs-lisp/p/")))
  226. (package-initialize)
  227. (defun my-auto-install-package ()
  228. "Install packages semi-automatically."
  229. (interactive)
  230. (package-refresh-contents)
  231. (mapc (lambda (pkg)
  232. (or (package-installed-p pkg)
  233. (locate-library (symbol-name pkg))
  234. (package-install pkg)))
  235. 10sr-package-list))
  236. )
  237. ;; (lazy-load-eval 'sudoku)
  238. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  239. ;; my-idle-hook
  240. (defvar my-idle-hook nil
  241. "Hook run when idle for several secs.")
  242. (defvar my-idle-hook-sec 5
  243. "Second to run `my-idle-hook'.")
  244. (run-with-idle-timer my-idle-hook-sec
  245. t
  246. (lambda ()
  247. (run-hooks 'my-idle-hook)))
  248. ;; (add-hook 'my-idle-hook
  249. ;; (lambda ()
  250. ;; (message "idle hook message")))
  251. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  252. ;; start and quit
  253. (setq inhibit-startup-message t)
  254. (setq confirm-kill-emacs 'y-or-n-p)
  255. (setq gc-cons-threshold (* 1024 1024 4))
  256. (when window-system
  257. (add-to-list 'default-frame-alist '(cursor-type . box))
  258. (add-to-list 'default-frame-alist '(background-color . "white"))
  259. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  260. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  261. ;; does not work?
  262. )
  263. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  264. (if window-system (menu-bar-mode 1) (menu-bar-mode 0))
  265. (and (fboundp 'tool-bar-mode)
  266. (tool-bar-mode 0))
  267. (and (fboundp 'set-scroll-bar-mode)
  268. (set-scroll-bar-mode nil))
  269. (add-hook 'kill-emacs-hook
  270. ;; load init file when terminating emacs to ensure file is not broken
  271. 'reload-init-file)
  272. (defun my-force-kill-emacs ()
  273. "My force kill Emacs."
  274. (interactive)
  275. (let ((kill-emacs-hook nil))
  276. (kill-emacs)))
  277. (call-after-init
  278. (lambda ()
  279. (message "%s %s" invocation-name emacs-version)
  280. (message "Invocation directory: %s" default-directory)
  281. (message "%s was taken to initialize emacs." (emacs-init-time))
  282. (switch-to-buffer "*Messages*")))
  283. (cd ".") ; when using windows use / instead of \ in `default-directory'
  284. ;; locale
  285. (set-language-environment "Japanese")
  286. (set-default-coding-systems 'utf-8-unix)
  287. (prefer-coding-system 'utf-8-unix)
  288. (setq system-time-locale "C")
  289. ;; my prefix map
  290. (defvar my-prefix-map nil
  291. "My prefix map.")
  292. (define-prefix-command 'my-prefix-map)
  293. (define-key ctl-x-map (kbd "C-x") 'my-prefix-map)
  294. (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  295. (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  296. ;; (comint-show-maximum-output)
  297. ;; kill scratch
  298. (call-after-init (lambda ()
  299. (let ((buf (get-buffer "*scratch*")))
  300. (when buf
  301. (kill-buffer buf)))))
  302. ;; modifier keys
  303. ;; (setq mac-option-modifier 'control)
  304. ;; display
  305. (setq visible-bell t)
  306. (setq ring-bell-function 'ignore)
  307. (mouse-avoidance-mode 'banish)
  308. (setq echo-keystrokes 0.1)
  309. (defun reload-init-file ()
  310. "Reload Emacs init file."
  311. (interactive)
  312. (when (and user-init-file
  313. (file-readable-p user-init-file))
  314. (load-file user-init-file)))
  315. (safe-require-or-eval 'session)
  316. ;; server
  317. (set-variable 'server-name (concat "server"
  318. (number-to-string (emacs-pid))))
  319. ;; In Cygwin Environment `server-runnning-p' stops when server-use-tcp is nil
  320. ;; In Darwin environment, init fails with message like 'Service name too long'
  321. ;; when server-use-tcp is nil
  322. (when (or (eq system-type
  323. 'cygwin)
  324. (eq system-type
  325. 'darwin))
  326. (set-variable 'server-use-tcp t))
  327. ;; MSYS2 fix
  328. (when (eq system-type
  329. 'windows-nt)
  330. (setq shell-file-name
  331. (executable-find "bash"))
  332. '(setq function-key-map
  333. `(,@function-key-map ([pause] . [?\C-c])
  334. ))
  335. (define-key key-translation-map
  336. (kbd "<pause>")
  337. (kbd "C-c"))
  338. '(keyboard-translate [pause]
  339. (kbd "C-c")p)
  340. ;; TODO: move to other place later
  341. (when (not window-system)
  342. (setq interprogram-paste-function nil)
  343. (setq interprogram-cut-function nil)))
  344. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  345. ;; global keys
  346. (global-set-key (kbd "<up>") 'scroll-down-line)
  347. (global-set-key (kbd "<down>") 'scroll-up-line)
  348. (global-set-key (kbd "<left>") 'scroll-down)
  349. (global-set-key (kbd "<right>") 'scroll-up)
  350. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  351. (global-set-key (kbd "C-\\") help-map)
  352. (define-key ctl-x-map (kbd "DEL") help-map)
  353. (define-key ctl-x-map (kbd "C-h") help-map)
  354. (define-key help-map "a" 'apropos)
  355. ;; disable annoying keys
  356. (global-set-key [prior] 'ignore)
  357. (global-set-key (kbd "<next>") 'ignore)
  358. (global-set-key [menu] 'ignore)
  359. (global-set-key [down-mouse-1] 'ignore)
  360. (global-set-key [down-mouse-2] 'ignore)
  361. (global-set-key [down-mouse-3] 'ignore)
  362. (global-set-key [mouse-1] 'ignore)
  363. (global-set-key [mouse-2] 'ignore)
  364. (global-set-key [mouse-3] 'ignore)
  365. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  366. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  367. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  368. ;; editting
  369. (defun my-copy-whole-line ()
  370. "Copy whole line."
  371. (interactive)
  372. (kill-new (concat (buffer-substring (point-at-bol)
  373. (point-at-eol))
  374. "\n")))
  375. (setq require-final-newline t)
  376. (setq kill-whole-line t)
  377. (setq scroll-conservatively 35
  378. scroll-margin 2
  379. scroll-step 0)
  380. (setq-default major-mode 'text-mode)
  381. (setq next-line-add-newlines nil)
  382. (setq kill-read-only-ok t)
  383. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  384. ;; (setq-default line-spacing 0.2)
  385. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  386. (setq-default tab-width 4)
  387. (setq-default indent-tabs-mode nil)
  388. (setq-default indent-line-function nil)
  389. (setq-default truncate-lines nil)
  390. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  391. (delete-selection-mode 1)
  392. (cua-mode 0)
  393. (setq line-move-visual nil)
  394. ;; key bindings
  395. ;; moving around
  396. ;; (global-set-key (kbd "M-j") 'next-line)
  397. ;; (global-set-key (kbd "M-k") 'previous-line)
  398. ;; (global-set-key (kbd "M-h") 'backward-char)
  399. ;; (global-set-key (kbd "M-l") 'forward-char)
  400. ;;(keyboard-translate ?\M-j ?\C-j)
  401. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  402. (define-key esc-map "p" 'backward-paragraph)
  403. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  404. (define-key esc-map "n" 'forward-paragraph)
  405. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  406. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  407. (global-set-key (kbd "C-<left>") 'scroll-down)
  408. (global-set-key (kbd "C-<right>") 'scroll-up)
  409. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  410. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  411. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  412. ;; C-h and DEL
  413. (global-set-key (kbd "C-h") (kbd "DEL"))
  414. (global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  415. (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  416. (define-key esc-map "k" 'my-copy-whole-line)
  417. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  418. (define-key esc-map "u" 'undo)
  419. (define-key esc-map "i" (kbd "ESC TAB"))
  420. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  421. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  422. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  423. (define-key my-prefix-map (kbd "C-o") 'occur)
  424. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  425. ;; title and mode-line
  426. (when (safe-require-or-eval 'terminal-title)
  427. ;; if TERM is not screen use default value
  428. (if (getenv "TMUX")
  429. ;; if use tmux locally just basename of current dir
  430. (set-variable 'terminal-title-format
  431. '((file-name-nondirectory (directory-file-name
  432. default-directory))))
  433. (if (and (let ((tty-type (frame-parameter nil
  434. 'tty-type)))
  435. (and tty-type
  436. (equal (car (split-string tty-type
  437. "-"))
  438. "screen")))
  439. (not (getenv "SSH_CONNECTION")))
  440. (set-variable 'terminal-title-format
  441. '((file-name-nondirectory (directory-file-name
  442. default-directory))))
  443. ;; seems that TMUX is used locally and ssh to remote host
  444. (set-variable 'terminal-title-format
  445. `("em:"
  446. ,user-login-name
  447. "@"
  448. ,(car (split-string system-name
  449. "\\."))
  450. ":"
  451. default-directory))
  452. )
  453. )
  454. (terminal-title-mode))
  455. (setq eol-mnemonic-dos "\\r\\n")
  456. (setq eol-mnemonic-mac "\\r")
  457. (setq eol-mnemonic-unix "\\n")
  458. (which-function-mode 0)
  459. (line-number-mode 0)
  460. (column-number-mode 0)
  461. (size-indication-mode 0)
  462. (setq mode-line-position
  463. '(:eval (format "L%%l/%d,C%%c"
  464. (count-lines (point-max)
  465. (point-min)))))
  466. (when (safe-require-or-eval 'git-ps1-mode)
  467. (git-ps1-mode))
  468. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  469. ;; display date
  470. (when (safe-require-or-eval 'time)
  471. (setq display-time-interval 29)
  472. (setq display-time-day-and-date t)
  473. (setq display-time-format "%Y/%m/%d %a %H:%M")
  474. ;; (if window-system
  475. ;; (display-time-mode 0)
  476. ;; (display-time-mode 1))
  477. (when display-time-mode
  478. (display-time-update)))
  479. ;; ;; current directory
  480. ;; (let ((ls (member 'mode-line-buffer-identification
  481. ;; mode-line-format)))
  482. ;; (setcdr ls
  483. ;; (cons '(:eval (concat " ("
  484. ;; (abbreviate-file-name default-directory)
  485. ;; ")"))
  486. ;; (cdr ls))))
  487. ;; ;; display last modified time
  488. ;; (let ((ls (member 'mode-line-buffer-identification
  489. ;; mode-line-format)))
  490. ;; (setcdr ls
  491. ;; (cons '(:eval (concat " "
  492. ;; my-buffer-file-last-modified-time))
  493. ;; (cdr ls))))
  494. (defun buffer-list-not-start-with-space ()
  495. "Return a list of buffers that not start with whitespaces."
  496. (let ((bl (buffer-list))
  497. b nbl)
  498. (while bl
  499. (setq b (pop bl))
  500. (unless (string-equal " "
  501. (substring (buffer-name b)
  502. 0
  503. 1))
  504. (add-to-list 'nbl b)))
  505. nbl))
  506. ;; http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/
  507. ;; (add-to-list 'minor-mode-alist
  508. ;; '(global-whitespace-mode ""))
  509. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  510. ;; minibuffer
  511. (setq insert-default-directory t)
  512. (setq completion-ignore-case t
  513. read-file-name-completion-ignore-case t
  514. read-buffer-completion-ignore-case t)
  515. (setq resize-mini-windows t)
  516. (temp-buffer-resize-mode 1)
  517. (savehist-mode 1)
  518. (fset 'yes-or-no-p 'y-or-n-p)
  519. ;; complete symbol when `eval'
  520. (define-key read-expression-map (kbd "TAB") 'completion-at-point)
  521. (define-key minibuffer-local-map (kbd "C-u")
  522. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  523. ;; I dont know these bindings are good
  524. (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
  525. (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
  526. (when (safe-require-or-eval 'minibuffer-line)
  527. (set-face-underline 'minibuffer-line nil)
  528. (set-variable 'minibuffer-line-refresh-interval
  529. 25)
  530. (set-variable 'minibuffer-line-format
  531. `(,(concat user-login-name
  532. "@"
  533. (car (split-string system-name
  534. "\\."))
  535. ":")
  536. (:eval (abbreviate-file-name (or buffer-file-name
  537. default-directory)))
  538. (:eval (and (fboundp 'git-ps1-mode-get-current)
  539. (git-ps1-mode-get-current " [GIT:%s]")))
  540. " "
  541. (:eval (format-time-string display-time-format))))
  542. (minibuffer-line-mode 1)
  543. )
  544. (when (safe-require-or-eval 'prompt-text)
  545. (set-variable 'prompt-text-format
  546. `(,(concat ""
  547. user-login-name
  548. "@"
  549. (car (split-string system-name
  550. "\\."))
  551. ":")
  552. (:eval (abbreviate-file-name (or buffer-file-name
  553. default-directory)))
  554. (:eval (and (fboundp 'git-ps1-mode-get-current)
  555. (git-ps1-mode-get-current " [GIT:%s]")))
  556. " "
  557. (:eval (format-time-string display-time-format))
  558. "\n"
  559. (:eval (symbol-name this-command))
  560. ": "))
  561. (prompt-text-mode 1))
  562. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  563. ;; letters, font-lock mode and fonts
  564. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  565. ;; (set-window-margins (selected-window) 1 1)
  566. (and (or (eq system-type 'Darwin)
  567. (eq system-type 'darwin))
  568. (fboundp 'mac-set-input-method-parameter)
  569. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  570. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  571. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  572. (boundp 'input-method-inactivate-hook))
  573. (add-hook 'input-method-activate-hook
  574. (lambda () (set-cursor-color "red")))
  575. (add-hook 'input-method-inactivate-hook
  576. (lambda () (set-cursor-color "black"))))
  577. (when (safe-require-or-eval 'paren)
  578. (show-paren-mode 1)
  579. (setq show-paren-delay 0.5
  580. show-paren-style 'parenthesis) ; mixed is hard to read
  581. ;; (set-face-background 'show-paren-match
  582. ;; "black")
  583. ;; ;; (face-foreground 'default))
  584. ;; (set-face-foreground 'show-paren-match
  585. ;; "white")
  586. ;; (set-face-inverse-video-p 'show-paren-match
  587. ;; t)
  588. )
  589. (transient-mark-mode 1)
  590. (global-font-lock-mode 1)
  591. (setq font-lock-global-modes
  592. '(not
  593. help-mode
  594. eshell-mode
  595. ;;term-mode
  596. Man-mode))
  597. ;; (standard-display-ascii ?\n "$\n")
  598. ;; (defvar my-eol-face
  599. ;; '(("\n" . (0 font-lock-comment-face t nil)))
  600. ;; )
  601. ;; (defvar my-tab-face
  602. ;; '(("\t" . '(0 highlight t nil))))
  603. (defvar my-jspace-face
  604. '(("\u3000" . '(0 highlight t nil))))
  605. (add-hook 'font-lock-mode-hook
  606. (lambda ()
  607. ;; (font-lock-add-keywords nil my-eol-face)
  608. (font-lock-add-keywords nil my-jspace-face)
  609. ))
  610. (when (safe-require-or-eval 'whitespace)
  611. (add-to-list 'whitespace-display-mappings ; not work
  612. `(tab-mark ?\t ,(vconcat "^I\t")))
  613. ;; (add-to-list 'whitespace-display-mappings
  614. ;; `(newline-mark ?\n ,(vconcat "$\n")))
  615. (setq whitespace-style '(face
  616. trailing ; trailing blanks
  617. newline ; newlines
  618. newline-mark ; use display table for newline
  619. tab-mark
  620. empty ; empty lines at beg or end of buffer
  621. lines-tail ; lines over 80
  622. ))
  623. ;; (setq whitespace-newline 'font-lock-comment-face)
  624. (set-variable 'whitespace-line-column nil)
  625. (global-whitespace-mode t)
  626. (add-hook 'dired-mode-hook
  627. (lambda ()
  628. (setq whitespace-style nil)))
  629. (if (eq (display-color-cells)
  630. 256)
  631. (set-face-foreground 'whitespace-newline "color-109")
  632. ;; (progn
  633. ;; (set-face-bold-p 'whitespace-newline
  634. ;; t))
  635. ))
  636. (and nil
  637. (safe-require-or-eval 'fill-column-indicator)
  638. (setq fill-column-indicator))
  639. ;; highlight current line
  640. ;; http://wiki.riywo.com/index.php?Meadow
  641. (face-spec-set 'hl-line
  642. '((((min-colors 256)
  643. (background dark))
  644. (:background "color-234"))
  645. (((min-colors 256)
  646. (background light))
  647. (:background "color-234"))
  648. (t
  649. (:underline "black"))))
  650. (set-variable 'hl-line-global-modes
  651. '(not
  652. term-mode))
  653. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  654. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  655. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  656. ;;(safe-require-or-eval 'set-modeline-color)
  657. ;; (let ((fg (face-foreground 'default))
  658. ;; (bg (face-background 'default)))
  659. ;; (set-face-background 'mode-line-inactive
  660. ;; (if (face-inverse-video-p 'mode-line) fg bg))
  661. ;; (set-face-foreground 'mode-line-inactive
  662. ;; (if (face-inverse-video-p 'mode-line) bg fg)))
  663. ;; (set-face-underline 'mode-line-inactive
  664. ;; t)
  665. ;; (set-face-underline 'vertical-border
  666. ;; nil)
  667. ;; Not found in MELPA nor any other package repositories
  668. (and (fetch-library
  669. "https://raw.github.com/tarao/elisp/master/end-mark.el"
  670. t)
  671. (safe-require-or-eval 'end-mark)
  672. (global-end-mark-mode))
  673. (when (safe-require-or-eval 'auto-highlight-symbol)
  674. (set-variable 'ahs-idle-interval 0.6)
  675. (global-auto-highlight-symbol-mode 1))
  676. (when (safe-require-or-eval 'cyberpunk-theme)
  677. (load-theme 'cyberpunk t)
  678. (set-face-attribute 'button
  679. nil
  680. :inherit 'highlight))
  681. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  682. ;; file handling
  683. (when (safe-require-or-eval 'editorconfig)
  684. ;; (set-variable 'editorconfig-get-properties-function
  685. ;; 'editorconfig-core-get-properties-hash)
  686. (editorconfig-mode 1))
  687. (setq revert-without-query '(".+"))
  688. ;; save cursor position
  689. (when (safe-require-or-eval 'saveplace)
  690. (setq-default save-place t)
  691. (setq save-place-file (concat user-emacs-directory
  692. "places")))
  693. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  694. (setq make-backup-files t)
  695. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  696. (setq backup-directory-alist
  697. (cons (cons "\\.*$" (expand-file-name (concat user-emacs-directory
  698. "backup")))
  699. backup-directory-alist))
  700. (setq version-control 'never)
  701. (setq delete-old-versions t)
  702. (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
  703. "auto-save/")))
  704. (setq delete-auto-save-files t)
  705. (add-to-list 'completion-ignored-extensions ".bak")
  706. ;; (setq delete-by-moving-to-trash t
  707. ;; trash-directory "~/.emacs.d/trash")
  708. (add-hook 'after-save-hook
  709. 'executable-make-buffer-file-executable-if-script-p)
  710. (set (defvar bookmark-default-file)
  711. (expand-file-name (concat user-emacs-directory
  712. "bmk")))
  713. (with-eval-after-load 'recentf
  714. (defvar recentf-exclude nil)
  715. (add-to-list 'recentf-exclude
  716. (regexp-quote bookmark-default-file)))
  717. (when (safe-require-or-eval 'smart-revert)
  718. (smart-revert-on))
  719. ;; autosave
  720. (when (safe-require-or-eval 'autosave)
  721. (autosave-set 2))
  722. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  723. ;; buffer killing
  724. ;; (defun my-delete-window-killing-buffer () nil)
  725. (defun my-query-kill-current-buffer ()
  726. "Interactively kill current buffer."
  727. (interactive)
  728. (if (y-or-n-p (concat "kill current buffer? :"))
  729. (kill-buffer (current-buffer))))
  730. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  731. (substitute-key-definition 'kill-buffer
  732. 'my-query-kill-current-buffer
  733. global-map)
  734. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  735. ;; share clipboard with x
  736. ;; this page describes this in details, but only these sexps seem to be needed
  737. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  738. (and (not window-system)
  739. (not (eq window-system 'mac))
  740. (getenv "DISPLAY")
  741. (not (equal (getenv "DISPLAY") ""))
  742. (executable-find "xclip")
  743. ;; (< emacs-major-version 24)
  744. (safe-require-or-eval 'xclip)
  745. nil
  746. (turn-on-xclip))
  747. (and (eq system-type 'darwin)
  748. (safe-require-or-eval 'pasteboard)
  749. (turn-on-pasteboard)
  750. (getenv "TMUX")
  751. (pasteboard-enable-rtun))
  752. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  753. ;; some modes and hooks
  754. ;; http://qiita.com/sune2/items/b73037f9e85962f5afb7
  755. (when (safe-require-or-eval 'company)
  756. (global-company-mode)
  757. (set-variable 'company-idle-delay 0.5)
  758. (set-variable 'company-minimum-prefix-length 2)
  759. (set-variable 'company-selection-wrap-around t))
  760. ;; https://github.com/lunaryorn/flycheck
  761. (when (safe-require-or-eval 'flycheck)
  762. (call-after-init 'global-flycheck-mode))
  763. (set-variable 'ac-ignore-case nil)
  764. (when (autoload-eval-lazily 'term-run '(term-run-shell-command term-run))
  765. (define-key ctl-x-map "t" 'term-run-shell-command))
  766. (add-to-list 'safe-local-variable-values
  767. '(encoding utf-8))
  768. (setq enable-local-variables :safe)
  769. (when (safe-require-or-eval 'remember-major-modes-mode)
  770. (remember-major-modes-mode 1))
  771. ;; Detect file type from shebang and set major-mode.
  772. (add-to-list 'interpreter-mode-alist
  773. '("python3" . python-mode))
  774. (add-to-list 'interpreter-mode-alist
  775. '("python2" . python-mode))
  776. ;; http://fukuyama.co/foreign-regexp
  777. '(and (safe-require-or-eval 'foreign-regexp)
  778. (progn
  779. (setq foreign-regexp/regexp-type 'perl)
  780. '(setq reb-re-syntax 'foreign-regexp)
  781. ))
  782. (autoload-eval-lazily 'sql '(sql-mode)
  783. (safe-require-or-eval 'sql-indent))
  784. (when (autoload-eval-lazily 'git-command)
  785. (define-key ctl-x-map "g" 'git-command))
  786. (when (safe-require-or-eval 'git-commit)
  787. (global-git-commit-mode 1))
  788. (when (fetch-library
  789. "http://www.emacswiki.org/emacs/download/sl.el"
  790. t)
  791. (autoload-eval-lazily 'sl))
  792. ;; jdee is too old! use malabar instead
  793. (with-eval-after-load 'jdee
  794. (add-hook 'jdee-mode-hook
  795. (lambda ()
  796. (make-local-variable 'global-mode-string)
  797. (add-to-list 'global-mode-string
  798. mode-line-position))))
  799. ;; Cannot enable error thrown. Why???
  800. ;; https://github.com/m0smith/malabar-mode#Installation
  801. ;; (when (autoload-eval-lazily 'malabar-mode)
  802. ;; (add-to-list 'load-path
  803. ;; (expand-file-name (concat user-emacs-directory "/cedet")))
  804. ;; (safe-require-or-eval 'cedet-devel-load)
  805. ;; (call-after-init 'activate-malabar-mode))
  806. (with-eval-after-load 'make-mode
  807. (defvar makefile-mode-map (make-sparse-keymap))
  808. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  809. ;; this functions is set in write-file-functions, i cannot find any
  810. ;; good way to remove this.
  811. (fset 'makefile-warn-suspicious-lines 'ignore))
  812. (with-eval-after-load 'verilog-mode
  813. (defvar verilog-mode-map (make-sparse-keymap))
  814. (define-key verilog-mode-map ";" 'self-insert-command))
  815. (setq diff-switches "-u")
  816. (with-eval-after-load 'diff-mode
  817. ;; (when (and (eq major-mode
  818. ;; 'diff-mode)
  819. ;; (not buffer-file-name))
  820. ;; ;; do not pass when major-mode is derived mode of diff-mode
  821. ;; (view-mode 1))
  822. (set-face-attribute 'diff-header nil
  823. :foreground nil
  824. :background nil
  825. :weight 'bold)
  826. (set-face-attribute 'diff-file-header nil
  827. :foreground nil
  828. :background nil
  829. :weight 'bold)
  830. (set-face-foreground 'diff-index-face "blue")
  831. (set-face-attribute 'diff-hunk-header nil
  832. :foreground "cyan"
  833. :weight 'normal)
  834. (set-face-attribute 'diff-context nil
  835. ;; :foreground "white"
  836. :foreground nil
  837. :weight 'normal)
  838. (set-face-foreground 'diff-removed-face "red")
  839. (set-face-foreground 'diff-added-face "green")
  840. (set-face-background 'diff-removed-face nil)
  841. (set-face-background 'diff-added-face nil)
  842. (set-face-attribute 'diff-changed nil
  843. :foreground "magenta"
  844. :weight 'normal)
  845. (set-face-attribute 'diff-refine-change nil
  846. :foreground nil
  847. :background nil
  848. :weight 'bold
  849. :inverse-video t)
  850. ;; Annoying !
  851. ;;(diff-auto-refine-mode)
  852. )
  853. ;; (ffap-bindings)
  854. (set-variable 'browse-url-browser-function
  855. 'eww-browse-url)
  856. (set-variable 'sh-here-document-word "__EOC__")
  857. (when (autoload-eval-lazily 'adoc-mode
  858. nil
  859. (defvar adoc-mode-map (make-sparse-keymap))
  860. (define-key adoc-mode-map (kbd "C-m") 'newline))
  861. (setq auto-mode-alist
  862. `(("\\.adoc\\'" . adoc-mode)
  863. ("\\.asciidoc\\'" . adoc-mode)
  864. ,@auto-mode-alist)))
  865. (with-eval-after-load 'markup-faces
  866. ;; Is this too match ?
  867. (set-face-foreground 'markup-meta-face
  868. "color-245")
  869. (set-face-foreground 'markup-meta-hide-face
  870. "color-245")
  871. )
  872. (setq auto-mode-alist
  873. `(("autostart\\'" . sh-mode)
  874. ("xinitrc\\'" . sh-mode)
  875. ("xprograms\\'" . sh-mode)
  876. ("PKGBUILD\\'" . sh-mode)
  877. ,@auto-mode-alist))
  878. ;; TODO: check if this is required
  879. (and (autoload-eval-lazily 'groovy-mode)
  880. (add-to-list 'auto-mode-alist
  881. '("build\\.gradle\\'" . groovy-mode)))
  882. (with-eval-after-load 'yaml-mode
  883. (defvar yaml-mode-map (make-sparse-keymap))
  884. (define-key yaml-mode-map (kbd "C-m") 'newline))
  885. (with-eval-after-load 'html-mode
  886. (defvar html-mode-map (make-sparse-keymap))
  887. (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
  888. (with-eval-after-load 'text-mode
  889. (define-key text-mode-map (kbd "C-m") 'newline))
  890. (add-to-list 'Info-default-directory-list
  891. (expand-file-name "~/.info/emacs-ja"))
  892. (with-eval-after-load 'apropos
  893. (defvar apropos-mode-map (make-sparse-keymap))
  894. (define-key apropos-mode-map "n" 'next-line)
  895. (define-key apropos-mode-map "p" 'previous-line))
  896. (with-eval-after-load 'isearch
  897. ;; (define-key isearch-mode-map
  898. ;; (kbd "C-j") 'isearch-other-control-char)
  899. ;; (define-key isearch-mode-map
  900. ;; (kbd "C-k") 'isearch-other-control-char)
  901. ;; (define-key isearch-mode-map
  902. ;; (kbd "C-h") 'isearch-other-control-char)
  903. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  904. (define-key isearch-mode-map (kbd "M-r")
  905. 'isearch-query-replace-regexp))
  906. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  907. (setq lazy-highlight-cleanup nil)
  908. ;; face for isearch highlighing
  909. (set-face-attribute 'lazy-highlight
  910. nil
  911. :foreground `unspecified
  912. :background `unspecified
  913. :underline t
  914. ;; :weight `bold
  915. )
  916. (add-hook 'outline-mode-hook
  917. (lambda ()
  918. (when (string-match "\\.md\\'" buffer-file-name)
  919. (set (make-local-variable 'outline-regexp) "#+ "))))
  920. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  921. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  922. (when (autoload-eval-lazily 'markdown-mode
  923. '(markdown-mode gfm-mode)
  924. (defvar gfm-mode-map (make-sparse-keymap))
  925. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline))
  926. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  927. (set-variable 'markdown-command (or (executable-find "markdown")
  928. (executable-find "markdown.pl")
  929. ""))
  930. (add-hook 'markdown-mode-hook
  931. (lambda ()
  932. (outline-minor-mode 1)
  933. (flyspell-mode)
  934. (set (make-local-variable 'comment-start) ";")))
  935. )
  936. ;; c-mode
  937. ;; http://www.emacswiki.org/emacs/IndentingC
  938. ;; http://en.wikipedia.org/wiki/Indent_style
  939. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  940. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  941. (with-eval-after-load 'cc-vars
  942. (defvar c-default-style nil)
  943. (add-to-list 'c-default-style
  944. '(c-mode . "k&r"))
  945. (add-to-list 'c-default-style
  946. '(c++-mode . "k&r"))
  947. (add-hook 'c-mode-common-hook
  948. (lambda ()
  949. ;; why c-basic-offset in k&r style defaults to 5 ???
  950. (set-variable 'c-basic-offset 4)
  951. (set-variable 'indent-tabs-mode nil)
  952. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  953. (c-toggle-hungry-state -1)
  954. ;; (and (require 'gtags nil t)
  955. ;; (gtags-mode 1))
  956. )))
  957. (when (autoload-eval-lazily 'php-mode)
  958. (add-hook 'php-mode-hook
  959. (lambda ()
  960. (set-variable 'c-basic-offset 2))))
  961. (autoload-eval-lazily 'js2-mode nil
  962. ;; currently do not use js2-mode
  963. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  964. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  965. (defvar js2-mode-map (make-sparse-keymap))
  966. (define-key js2-mode-map (kbd "C-m") (lambda ()
  967. (interactive)
  968. (js2-enter-key)
  969. (indent-for-tab-command)))
  970. ;; (add-hook (kill-local-variable 'before-save-hook)
  971. ;; 'js2-before-save)
  972. ;; (add-hook 'before-save-hook
  973. ;; 'my-indent-buffer
  974. ;; nil
  975. ;; t)
  976. )
  977. (with-eval-after-load 'js
  978. (set-variable 'js-indent-level 2))
  979. (add-to-list 'interpreter-mode-alist
  980. '("node" . js-mode))
  981. (when (autoload-eval-lazily 'flymake-jslint
  982. '(flymake-jslint-load))
  983. (autoload-eval-lazily 'js nil
  984. (add-hook 'js-mode-hook
  985. 'flymake-jslint-load)))
  986. (safe-require-or-eval 'js-doc)
  987. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  988. (when (safe-require-or-eval 'uniquify)
  989. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  990. (setq uniquify-ignore-buffers-re "*[^*]+*")
  991. (setq uniquify-min-dir-content 1))
  992. (with-eval-after-load 'view
  993. (defvar view-mode-map (make-sparse-keymap))
  994. (define-key view-mode-map "j" 'scroll-up-line)
  995. (define-key view-mode-map "k" 'scroll-down-line)
  996. (define-key view-mode-map "v" 'toggle-read-only)
  997. (define-key view-mode-map "q" 'bury-buffer)
  998. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  999. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  1000. ;; (define-key view-mode-map
  1001. ;; "n" 'nonincremental-repeat-search-forward)
  1002. ;; (define-key view-mode-map
  1003. ;; "N" 'nonincremental-repeat-search-backward)
  1004. (define-key view-mode-map "/" 'isearch-forward-regexp)
  1005. (define-key view-mode-map "?" 'isearch-backward-regexp)
  1006. (define-key view-mode-map "n" 'isearch-repeat-forward)
  1007. (define-key view-mode-map "N" 'isearch-repeat-backward)
  1008. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
  1009. (global-set-key "\M-r" 'view-mode)
  1010. ;; (setq view-read-only t)
  1011. (add-hook 'Man-mode-hook
  1012. (lambda ()
  1013. (view-mode 1)
  1014. (setq truncate-lines nil)))
  1015. (set-variable 'Man-notify-method (if window-system
  1016. 'newframe
  1017. 'aggressive))
  1018. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  1019. "woman_cache.el")))
  1020. (defalias 'man 'woman)
  1021. (add-to-list 'auto-mode-alist
  1022. '("tox\\.ini\\'" . conf-unix-mode))
  1023. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1024. ;; python
  1025. (when (autoload-eval-lazily 'python '(python-mode)
  1026. (defvar python-mode-map (make-sparse-keymap))
  1027. (define-key python-mode-map (kbd "C-c C-e") 'my-python-run-as-command)
  1028. (define-key python-mode-map (kbd "C-c C-b") 'my-python-display-python-buffer)
  1029. (define-key python-mode-map (kbd "C-m") 'newline-and-indent)
  1030. (defvar inferior-python-mode-map (make-sparse-keymap))
  1031. (define-key inferior-python-mode-map (kbd "<up>") 'comint-previous-input)
  1032. (define-key inferior-python-mode-map (kbd "<down>") 'comint-next-input)
  1033. )
  1034. (set-variable 'python-python-command (or (executable-find "python3")
  1035. (executable-find "python")))
  1036. ;; (defun my-python-run-as-command ()
  1037. ;; ""
  1038. ;; (interactive)
  1039. ;; (shell-command (concat python-python-command " " buffer-file-name)))
  1040. (defun my-python-display-python-buffer ()
  1041. ""
  1042. (interactive)
  1043. (defvar python-buffer nil)
  1044. (set-window-text-height (display-buffer python-buffer
  1045. t)
  1046. 7))
  1047. (add-hook 'inferior-python-mode-hook
  1048. (lambda ()
  1049. (my-python-display-python-buffer))))
  1050. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1051. ;; gauche-mode
  1052. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  1053. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  1054. (when (and (fetch-library
  1055. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  1056. t)
  1057. (autoload-eval-lazily 'gauche-mode '(gauche-mode run-scheme)
  1058. (defvar gauche-mode-map (make-sparse-keymap))
  1059. (defvar scheme-mode-map (make-sparse-keymap))
  1060. (define-key gauche-mode-map
  1061. (kbd "C-c C-z") 'run-gauche-other-window)
  1062. (define-key scheme-mode-map
  1063. (kbd "C-c C-c") 'scheme-send-buffer)
  1064. (define-key scheme-mode-map
  1065. (kbd "C-c C-b") 'my-scheme-display-scheme-buffer)))
  1066. (let ((s (executable-find "gosh")))
  1067. (set-variable 'scheme-program-name s)
  1068. (set-variable 'gauche-program-name s))
  1069. (defvar gauche-program-name nil)
  1070. (defvar scheme-buffer nil)
  1071. (defun run-gauche-other-window ()
  1072. "Run gauche on other window"
  1073. (interactive)
  1074. (switch-to-buffer-other-window
  1075. (get-buffer-create "*scheme*"))
  1076. (run-gauche))
  1077. (defun run-gauche ()
  1078. "run gauche"
  1079. (interactive)
  1080. (run-scheme gauche-program-name)
  1081. )
  1082. (defun scheme-send-buffer ()
  1083. ""
  1084. (interactive)
  1085. (scheme-send-region (point-min) (point-max))
  1086. (my-scheme-display-scheme-buffer)
  1087. )
  1088. (defun my-scheme-display-scheme-buffer ()
  1089. ""
  1090. (interactive)
  1091. (set-window-text-height (display-buffer scheme-buffer
  1092. t)
  1093. 7))
  1094. (add-hook 'scheme-mode-hook
  1095. (lambda ()
  1096. nil))
  1097. (add-hook 'inferior-scheme-mode-hook
  1098. (lambda ()
  1099. ;; (my-scheme-display-scheme-buffer)
  1100. ))
  1101. (setq auto-mode-alist
  1102. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  1103. (setq auto-mode-alist
  1104. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  1105. )
  1106. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1107. ;; term mode
  1108. ;; (setq multi-term-program shell-file-name)
  1109. (when (autoload-eval-lazily 'multi-term)
  1110. (set-variable 'multi-term-switch-after-close nil)
  1111. (set-variable 'multi-term-dedicated-select-after-open-p t)
  1112. (set-variable 'multi-term-dedicated-window-height 20))
  1113. (when (autoload-eval-lazily 'term '(term ansi-term)
  1114. (defvar term-raw-map (make-sparse-keymap))
  1115. ;; (define-key term-raw-map "\C-xl" 'term-line-mode)
  1116. ;; (define-key term-mode-map "\C-xc" 'term-char-mode)
  1117. (define-key term-raw-map (kbd "<up>") 'scroll-down-line)
  1118. (define-key term-raw-map (kbd "<down>") 'scroll-up-line)
  1119. (define-key term-raw-map (kbd "<right>") 'scroll-up)
  1120. (define-key term-raw-map (kbd "<left>") 'scroll-down)
  1121. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  1122. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  1123. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  1124. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  1125. (define-key term-raw-map [delete] 'term-send-raw)
  1126. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  1127. (define-key term-raw-map "\C-y" 'term-paste)
  1128. (define-key term-raw-map
  1129. "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  1130. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  1131. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  1132. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  1133. ;; (define-key term-raw-map "\C-d" 'delete-char)
  1134. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  1135. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  1136. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  1137. ;; (define-key term-raw-map "\C-f" 'forward-char)
  1138. ;; (define-key term-raw-map "\C-b" 'backward-char)
  1139. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  1140. )
  1141. (defun my-term-quit-or-send-raw ()
  1142. ""
  1143. (interactive)
  1144. (if (get-buffer-process (current-buffer))
  1145. (call-interactively 'term-send-raw)
  1146. (kill-buffer)))
  1147. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  1148. ;; (setq term-ansi-default-program shell-file-name)
  1149. (add-hook 'term-setup-hook
  1150. (lambda ()
  1151. (set-variable 'term-display-table (make-display-table))))
  1152. (add-hook 'term-mode-hook
  1153. (lambda ()
  1154. (defvar term-raw-map (make-sparse-keymap))
  1155. ;; (unless (memq (current-buffer)
  1156. ;; (and (featurep 'multi-term)
  1157. ;; (defvar multi-term-buffer-list)
  1158. ;; ;; current buffer is not multi-term buffer
  1159. ;; multi-term-buffer-list))
  1160. ;; )
  1161. (set (make-local-variable 'scroll-margin) 0)
  1162. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  1163. ;; (cua-mode 0)
  1164. ;; (and cua-mode
  1165. ;; (local-unset-key (kbd "C-c")))
  1166. ;; (define-key cua--prefix-override-keymap
  1167. ;;"\C-c" 'term-interrupt-subjob)
  1168. (set (make-local-variable (defvar hl-line-range-function))
  1169. (lambda ()
  1170. '(0 . 0)))
  1171. (define-key term-raw-map
  1172. "\C-x" (lookup-key (current-global-map) "\C-x"))
  1173. (define-key term-raw-map
  1174. "\C-z" (lookup-key (current-global-map) "\C-z"))
  1175. ))
  1176. ;; (add-hook 'term-exec-hook 'forward-char)
  1177. )
  1178. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1179. ;; buffer switching
  1180. (defvar bs-configurations)
  1181. (when (autoload-eval-lazily 'bs '(bs-show)
  1182. (add-to-list 'bs-configurations
  1183. '("specials" "^\\*" nil ".*" nil nil))
  1184. (defvar bs-mode-map)
  1185. (defvar bs-current-configuration)
  1186. (define-key bs-mode-map (kbd "t")
  1187. (lambda ()
  1188. (interactive)
  1189. (if (string= "specials"
  1190. bs-current-configuration)
  1191. (bs-set-configuration "files")
  1192. (bs-set-configuration "specials"))
  1193. (bs-refresh)
  1194. (bs-message-without-log "%s"
  1195. (bs--current-config-message))))
  1196. ;; (setq bs-configurations (list
  1197. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1198. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1199. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1200. )
  1201. (defalias 'list-buffers 'bs-show)
  1202. (set-variable 'bs-default-configuration "files")
  1203. (set-variable 'bs-default-sort-name "by nothing")
  1204. (add-hook 'bs-mode-hook
  1205. (lambda ()
  1206. (set (make-local-variable 'scroll-margin) 0))))
  1207. ;;(iswitchb-mode 1)
  1208. (icomplete-mode)
  1209. (defun iswitchb-buffer-display-other-window ()
  1210. "Do iswitchb in other window."
  1211. (interactive)
  1212. (let ((iswitchb-default-method 'display))
  1213. (call-interactively 'iswitchb-buffer)))
  1214. ;;;;;;;;;;;;;;;;;;;;;;;;
  1215. ;; ilookup
  1216. (with-eval-after-load 'ilookup
  1217. (set-variable 'ilookup-dict-alist
  1218. '(
  1219. ("sdcv" . (lambda (word)
  1220. (shell-command-to-string
  1221. (format "sdcv -n '%s'"
  1222. word))))
  1223. ("en" . (lambda (word)
  1224. (shell-command-to-string
  1225. (format "sdcv -n -u dictd_www.dict.org_gcide '%s'"
  1226. word))))
  1227. ("ja" . (lambda (word)
  1228. (shell-command-to-string
  1229. (format "sdcv -n -u EJ-GENE95 -u jmdict-en-ja '%s'"
  1230. word))))
  1231. ("jaj" . (lambda (word)
  1232. (shell-command-to-string
  1233. (format "sdcv -n -u jmdict-en-ja '%s'"
  1234. word))))
  1235. ("jag" .
  1236. (lambda (word)
  1237. (with-temp-buffer
  1238. (insert (shell-command-to-string
  1239. (format "sdcv -n -u 'Genius English-Japanese' '%s'"
  1240. word)))
  1241. (html2text)
  1242. (buffer-substring (point-min)
  1243. (point-max)))))
  1244. ("alc" . (lambda (word)
  1245. (shell-command-to-string
  1246. (format "alc '%s' | head -n 20"
  1247. word))))
  1248. ("app" . (lambda (word)
  1249. (shell-command-to-string
  1250. (format "dict_app '%s'"
  1251. word))))
  1252. ;; letters broken
  1253. ("ms" .
  1254. (lambda (word)
  1255. (let ((url (concat
  1256. "http://api.microsofttranslator.com/V2/Ajax.svc/"
  1257. "Translate?appId=%s&text=%s&to=%s"))
  1258. (apikey "3C9778666C5BA4B406FFCBEE64EF478963039C51")
  1259. (target "ja")
  1260. (eword (url-hexify-string word)))
  1261. (with-current-buffer (url-retrieve-synchronously
  1262. (format url
  1263. apikey
  1264. eword
  1265. target))
  1266. (message "")
  1267. (goto-char (point-min))
  1268. (search-forward-regexp "^$"
  1269. nil
  1270. t)
  1271. (url-unhex-string (buffer-substring-no-properties
  1272. (point)
  1273. (point-max)))))))
  1274. ))
  1275. ;; (funcall (cdr (assoc "ms"
  1276. ;; ilookup-alist))
  1277. ;; "dictionary")
  1278. ;; (switch-to-buffer (url-retrieve-synchronously "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=3C9778666C5BA4B406FFCBEE64EF478963039C51&text=dictionary&to=ja"))
  1279. ;; (switch-to-buffer (url-retrieve-synchronously "http://google.com"))
  1280. (set-variable 'ilookup-default "ja")
  1281. (when (locate-library "google-translate")
  1282. (defvar ilookup-dict-alist nil)
  1283. (add-to-list 'ilookup-dict-alist
  1284. '("gt" .
  1285. (lambda (word)
  1286. (save-excursion
  1287. (google-translate-translate "auto"
  1288. "ja"
  1289. word))
  1290. (with-current-buffer "*Google Translate*"
  1291. (buffer-substring-no-properties (point-min)
  1292. (point-max)))))))
  1293. )
  1294. (when (autoload-eval-lazily 'google-translate '(google-translate-translate
  1295. google-translate-at-point))
  1296. (set-variable 'google-translate-default-source-language "auto")
  1297. (set-variable 'google-translate-default-target-language "ja"))
  1298. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1299. ;; vc
  1300. (set-variable 'vc-handled-backends '())
  1301. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1302. ;; recentf-mode
  1303. (set-variable 'recentf-save-file (expand-file-name (concat user-emacs-directory
  1304. "recentf")))
  1305. (set-variable 'recentf-max-menu-items 20)
  1306. (set-variable 'recentf-max-saved-items 30)
  1307. (set-variable 'recentf-show-file-shortcuts-flag nil)
  1308. (when (safe-require-or-eval 'recentf)
  1309. (add-to-list 'recentf-exclude
  1310. (regexp-quote recentf-save-file))
  1311. (add-to-list 'recentf-exclude
  1312. (regexp-quote (expand-file-name user-emacs-directory)))
  1313. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1314. (remove-hook 'find-file-hook
  1315. 'recentf-track-opened-file)
  1316. (defun my-recentf-load-track-save-list ()
  1317. "Load current recentf list from file, track current visiting file, then save
  1318. the list."
  1319. (recentf-load-list)
  1320. (recentf-track-opened-file)
  1321. (recentf-save-list))
  1322. (add-hook 'find-file-hook
  1323. 'my-recentf-load-track-save-list)
  1324. (add-hook 'kill-emacs-hook
  1325. 'recentf-load-list)
  1326. ;;(run-with-idle-timer 5 t 'recentf-save-list)
  1327. ;; (add-hook 'find-file-hook
  1328. ;; (lambda ()
  1329. ;; (recentf-add-file default-directory)))
  1330. (and (autoload-eval-lazily 'recentf-show)
  1331. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1332. (add-hook 'recentf-show-before-listing-hook
  1333. 'recentf-load-list))
  1334. (recentf-mode 1)
  1335. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1336. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1337. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1338. (define-key recentf-dialog-mode-map "n" 'next-line)
  1339. (add-hook 'recentf-dialog-mode-hook
  1340. (lambda ()
  1341. ;; (recentf-save-list)
  1342. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1343. ;; 'my-recentf-cd-and-find-file)
  1344. (cd "~/"))))
  1345. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1346. ;; dired
  1347. (defun my-dired-echo-file-head (arg)
  1348. ""
  1349. (interactive "P")
  1350. (let ((f (dired-get-filename)))
  1351. (message "%s"
  1352. (with-temp-buffer
  1353. (insert-file-contents f)
  1354. (buffer-substring-no-properties
  1355. (point-min)
  1356. (progn (goto-char (point-min))
  1357. (forward-line (1- (if arg
  1358. (prefix-numeric-value arg)
  1359. 7)))
  1360. (point-at-eol)))))))
  1361. (defun my-dired-diff ()
  1362. ""
  1363. (interactive)
  1364. (let ((files (dired-get-marked-files nil nil nil t)))
  1365. (if (eq (car files)
  1366. t)
  1367. (diff (cadr files) (dired-get-filename))
  1368. (message "One file must be marked!"))))
  1369. (defun dired-get-file-info ()
  1370. "dired get file info"
  1371. (interactive)
  1372. (let ((f (shell-quote-argument (dired-get-filename t))))
  1373. (if (file-directory-p f)
  1374. (progn
  1375. (message "Calculating disk usage...")
  1376. (shell-command (concat "du -hsD "
  1377. f)))
  1378. (shell-command (concat "file "
  1379. f)))))
  1380. (defun my-dired-scroll-up ()
  1381. ""
  1382. (interactive)
  1383. (my-dired-previous-line (- (window-height) 1)))
  1384. (defun my-dired-scroll-down ()
  1385. ""
  1386. (interactive)
  1387. (my-dired-next-line (- (window-height) 1)))
  1388. ;; (defun my-dired-forward-line (arg)
  1389. ;; ""
  1390. ;; (interactive "p"))
  1391. (defun my-dired-previous-line (arg)
  1392. ""
  1393. (interactive "p")
  1394. (if (> arg 0)
  1395. (progn
  1396. (if (eq (line-number-at-pos)
  1397. 1)
  1398. (goto-char (point-max))
  1399. (forward-line -1))
  1400. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1401. (dired-get-subdir))
  1402. (- arg 1)
  1403. arg)))
  1404. (dired-move-to-filename)))
  1405. (defun my-dired-next-line (arg)
  1406. ""
  1407. (interactive "p")
  1408. (if (> arg 0)
  1409. (progn
  1410. (if (eq (point)
  1411. (point-max))
  1412. (goto-char (point-min))
  1413. (forward-line 1))
  1414. (my-dired-next-line (if (or (dired-get-filename nil t)
  1415. (dired-get-subdir))
  1416. (- arg 1)
  1417. arg)))
  1418. (dired-move-to-filename)))
  1419. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1420. (if (eq window-system 'mac)
  1421. (setq dired-listing-switches "-lhF")
  1422. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1423. )
  1424. (setq dired-listing-switches "-lhF")
  1425. (put 'dired-find-alternate-file 'disabled nil)
  1426. ;; when using dired-find-alternate-file
  1427. ;; reuse current dired buffer for the file to open
  1428. (set-variable 'dired-ls-F-marks-symlinks t)
  1429. (when (safe-require-or-eval 'ls-lisp)
  1430. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1431. (setq ls-lisp-dirs-first t)
  1432. (setq ls-lisp-use-localized-time-format t)
  1433. (setq ls-lisp-format-time-list
  1434. '("%Y-%m-%d %H:%M"
  1435. "%Y-%m-%d ")))
  1436. (set-variable 'dired-dwim-target t)
  1437. (set-variable 'dired-isearch-filenames t)
  1438. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  1439. (set-variable 'dired-hide-details-hide-information-lines nil)
  1440. ;; (add-hook 'dired-after-readin-hook
  1441. ;; 'my-replace-nasi-none)
  1442. ;; (add-hook 'after-init-hook
  1443. ;; (lambda ()
  1444. ;; (dired ".")))
  1445. (with-eval-after-load 'dired
  1446. (defvar dired-mode-map (make-sparse-keymap))
  1447. (define-key dired-mode-map "o" 'my-dired-x-open)
  1448. (define-key dired-mode-map "i" 'dired-get-file-info)
  1449. (define-key dired-mode-map "f" 'find-file)
  1450. (define-key dired-mode-map "!" 'shell-command)
  1451. (define-key dired-mode-map "&" 'async-shell-command)
  1452. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1453. (define-key dired-mode-map "=" 'my-dired-diff)
  1454. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1455. (define-key dired-mode-map "b" 'gtkbm)
  1456. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1457. (define-key dired-mode-map "@" (lambda ()
  1458. (interactive) (my-x-open ".")))
  1459. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1460. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1461. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1462. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1463. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1464. (substitute-key-definition 'dired-next-line
  1465. 'my-dired-next-line
  1466. dired-mode-map)
  1467. (substitute-key-definition 'dired-previous-line
  1468. 'my-dired-previous-line
  1469. dired-mode-map)
  1470. ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
  1471. ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
  1472. ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
  1473. ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
  1474. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1475. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1476. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1477. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1478. (add-hook 'dired-mode-hook
  1479. (lambda ()
  1480. (when (fboundp 'dired-hide-details-mode)
  1481. (dired-hide-details-mode t)
  1482. (local-set-key "l" 'dired-hide-details-mode))
  1483. (let ((file "._Icon\015"))
  1484. (when nil
  1485. '(file-readable-p file)
  1486. (delete-file file)))))
  1487. (when (autoload-eval-lazily 'pack '(dired-do-pack-or-unpack pack-pack))
  1488. (with-eval-after-load 'dired
  1489. (define-key dired-mode-map "P" 'dired-do-pack-or-unpack)))
  1490. (when (autoload-eval-lazily 'dired-list-all-mode)
  1491. (setq dired-listing-switches "-lhF")
  1492. (with-eval-after-load 'dired
  1493. (define-key dired-mode-map "a" 'dired-list-all-mode))))
  1494. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1495. ;; my-term
  1496. (defvar my-term nil
  1497. "My terminal buffer.")
  1498. (defvar my-term-function nil
  1499. "Function to create terminal buffer.
  1500. This function accept no argument and return newly created buffer of terminal.")
  1501. (defun my-term (&optional arg)
  1502. "Open terminal buffer and return that buffer.
  1503. If ARG is given or called with prefix argument, create new buffer."
  1504. (interactive "P")
  1505. (if (and (not arg)
  1506. my-term
  1507. (buffer-name my-term))
  1508. (pop-to-buffer my-term)
  1509. (setq my-term
  1510. (save-window-excursion
  1511. (funcall my-term-function)))
  1512. (and my-term
  1513. (my-term))))
  1514. ;; (setq my-term-function
  1515. ;; (lambda ()
  1516. ;; (if (eq system-type 'windows-nt)
  1517. ;; (eshell)
  1518. ;; (if (require 'multi-term nil t)
  1519. ;; (multi-term)
  1520. ;; (ansi-term shell-file-name)))))
  1521. (setq my-term-function (lambda () (eshell t)))
  1522. ;;(define-key my-prefix-map (kbd "C-s") 'my-term)
  1523. (define-key ctl-x-map "i" 'my-term)
  1524. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1525. ;; misc funcs
  1526. (defalias 'qcalc 'quick-calc)
  1527. (defun memo (&optional dir)
  1528. "Open memo.txt in DIR."
  1529. (interactive)
  1530. (pop-to-buffer (find-file-noselect (concat (if dir
  1531. (file-name-as-directory dir)
  1532. "")
  1533. "memo.txt"))))
  1534. (defvar my-rgrep-alist
  1535. `(
  1536. ;; the silver searcher
  1537. ("ag"
  1538. (executable-find "ag")
  1539. "ag --nocolor --nogroup --nopager --filename ")
  1540. ;; ack
  1541. ("ack"
  1542. (executable-find "ack")
  1543. "ack --nocolor --nogroup --nopager --with-filename ")
  1544. ;; gnu global
  1545. ("global"
  1546. (and (require 'gtags nil t)
  1547. (executable-find "global")
  1548. (gtags-get-rootpath))
  1549. "global --result grep ")
  1550. ;; git grep
  1551. ("gitgrep"
  1552. (eq 0
  1553. (shell-command "git rev-parse --git-dir"))
  1554. "git --no-pager -c color.grep=false grep -nH -e ")
  1555. ;; grep
  1556. ("grep"
  1557. t
  1558. ,(concat "find . "
  1559. "-path '*/.git' -prune -o "
  1560. "-path '*/.svn' -prune -o "
  1561. "-type f -print0 | "
  1562. "xargs -0 grep -nH -e "))
  1563. )
  1564. "Alist of rgrep command.
  1565. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  1566. condition to choose COMMAND when evaluated.")
  1567. (defvar my-rgrep-default nil
  1568. "Default command name for my-rgrep.")
  1569. (defun my-rgrep-grep-command (&optional name alist)
  1570. "Return recursive grep command for current directory or nil.
  1571. If NAME is given, use that without testing.
  1572. Commands are searched from ALIST."
  1573. (if alist
  1574. (if name
  1575. ;; if name is given search that from alist and return the command
  1576. (nth 2 (assoc name
  1577. alist))
  1578. ;; if name is not given try test in 1th elem
  1579. (let ((car (car alist))
  1580. (cdr (cdr alist)))
  1581. (if (eval (nth 1 car))
  1582. ;; if the condition is true return the command
  1583. (nth 2 car)
  1584. ;; try next one
  1585. (and cdr
  1586. (my-rgrep-grep-command name cdr)))))
  1587. ;; if alist is not given set default value
  1588. (my-rgrep-grep-command name my-rgrep-alist)))
  1589. (defun my-rgrep (command-args)
  1590. "My recursive grep. Run COMMAND-ARGS."
  1591. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  1592. nil)))
  1593. (if cmd
  1594. (list (read-shell-command "grep command: "
  1595. cmd
  1596. 'grep-find-history))
  1597. (error "My-Rgrep: Command for rgrep not found")
  1598. )))
  1599. (compilation-start command-args
  1600. 'grep-mode))
  1601. ;; (defun my-rgrep-symbol-at-point (command-args)
  1602. ;; "My recursive grep. Run COMMAND-ARGS."
  1603. ;; (interactive (list (read-shell-command "grep command: "
  1604. ;; (concat (my-rgrep-grep-command)
  1605. ;; " "
  1606. ;; (thing-at-point 'symbol))
  1607. ;; 'grep-find-history)))
  1608. ;; (compilation-start command-args
  1609. ;; 'grep-mode))
  1610. (defmacro define-my-rgrep (name)
  1611. "Define rgrep for NAME."
  1612. `(defun ,(intern (concat "my-rgrep-"
  1613. name)) ()
  1614. ,(format "My recursive grep by %s."
  1615. name)
  1616. (interactive)
  1617. (let ((my-rgrep-default ,name))
  1618. (if (called-interactively-p 'any)
  1619. (call-interactively 'my-rgrep)
  1620. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  1621. )
  1622. (define-my-rgrep "ack")
  1623. (define-my-rgrep "ag")
  1624. (define-my-rgrep "gitgrep")
  1625. (define-my-rgrep "grep")
  1626. (define-my-rgrep "global")
  1627. (define-key ctl-x-map "s" 'my-rgrep)
  1628. ;; (defun make ()
  1629. ;; "Run \"make -k\" in current directory."
  1630. ;; (interactive)
  1631. ;; (compile "make -k"))
  1632. (defalias 'make 'compile)
  1633. (define-key ctl-x-map "c" 'compile)
  1634. ;;;;;;;;;;;;;;;;;;;;;;;
  1635. ;; adoc-simple-mode
  1636. (when (safe-require-or-eval 'adoc-mode)
  1637. (defvar adoc-simple-font-lock-keywords
  1638. nil)
  1639. (define-derived-mode adoc-simple-mode adoc-mode
  1640. "Adoc-Simple"
  1641. "Major mode for editing AsciiDoc text files.
  1642. This mode is a simplified version of `adoc-mode'."
  1643. '(set (make-local-variable 'font-lock-defaults)
  1644. '(adoc-simple-font-lock-keywords
  1645. nil nil nil nil
  1646. (font-lock-multiline . t)
  1647. (font-lock-mark-block-function . adoc-font-lock-mark-block-function))))
  1648. (add-to-list 'auto-mode-alist
  1649. '("\\.adoc\\'" . adoc-simple-mode)))
  1650. (when (and (safe-require-or-eval 'google-translate)
  1651. (safe-require-or-eval 'google-translate-smooth-ui))
  1652. (add-to-list 'google-translate-translation-directions-alist
  1653. '("en" . "ja"))
  1654. (defun translate-echo-at-point ()
  1655. "Translate popup at point."
  1656. (interactive)
  1657. (let ((google-translate-output-destination 'echo-area))
  1658. (google-translate-translate "auto" "ja" (current-word t t))))
  1659. (define-minor-mode auto-translate-mode
  1660. "Translate word at point automatically."
  1661. :global nil
  1662. :lighter "ATranslate"))
  1663. ;;; emacs.el ends here