Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 13 Jahren
vor 12 Jahren
vor 13 Jahren
vor 13 Jahren
vor 11 Jahren
vor 8 Jahren
vor 11 Jahren
vor 11 Jahren
vor 11 Jahren
vor 11 Jahren
vor 13 Jahren
vor 13 Jahren
vor 12 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 12 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 9 Jahren
vor 9 Jahren
vor 12 Jahren
vor 9 Jahren
vor 9 Jahren
vor 9 Jahren
vor 9 Jahren
vor 13 Jahren
vor 13 Jahren
vor 11 Jahren
vor 12 Jahren
vor 13 Jahren
vor 13 Jahren
vor 11 Jahren
vor 13 Jahren
vor 12 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 11 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 12 Jahren
vor 13 Jahren
vor 12 Jahren
vor 13 Jahren
vor 12 Jahren
vor 6 Jahren
vor 8 Jahren
vor 8 Jahren
vor 13 Jahren
vor 11 Jahren
vor 11 Jahren
vor 6 Jahren
vor 6 Jahren
vor 12 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 6 Jahren
vor 12 Jahren
vor 12 Jahren
vor 6 Jahren
vor 12 Jahren
vor 12 Jahren
vor 6 Jahren
vor 12 Jahren
vor 6 Jahren
vor 6 Jahren
vor 6 Jahren
vor 6 Jahren
vor 6 Jahren
vor 11 Jahren
vor 11 Jahren
vor 6 Jahren
vor 6 Jahren
vor 12 Jahren
vor 6 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 10 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 8 Jahren
vor 10 Jahren
vor 13 Jahren
vor 13 Jahren
vor 12 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 13 Jahren
vor 12 Jahren
vor 13 Jahren
vor 12 Jahren
vor 12 Jahren
vor 12 Jahren
vor 6 Jahren
vor 6 Jahren
vor 12 Jahren
vor 12 Jahren
vor 12 Jahren
vor 9 Jahren
vor 11 Jahren
vor 6 Jahren
vor 11 Jahren
vor 6 Jahren
vor 6 Jahren
vor 11 Jahren
vor 11 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617
  1. ;;; emacs.el --- 10sr emacs initialization
  2. ;;; Code:
  3. ;; SETUP_LOAD: (let ((file "DOTFILES_DIR/emacs.el"))
  4. ;; SETUP_LOAD: (and (file-readable-p file)
  5. ;; SETUP_LOAD: (load-file file)))
  6. (setq debug-on-error t)
  7. ;; make directories
  8. (unless (file-directory-p (expand-file-name user-emacs-directory))
  9. (make-directory (expand-file-name user-emacs-directory)))
  10. (require 'cl-lib)
  11. (require 'simple)
  12. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13. ;; Some macros for internals
  14. (defun call-after-init (func)
  15. "If `after-init-hook' has been run, call FUNC immediately.
  16. Otherwize hook it."
  17. (if after-init-time
  18. (funcall func)
  19. (add-hook 'after-init-hook
  20. func)))
  21. (defmacro safe-require-or-eval (feature)
  22. "Require FEATURE if available.
  23. At compile time the feature will be loaded immediately."
  24. `(eval-and-compile
  25. (message "safe-require-or-eval: Trying to require %s" ,feature)
  26. (require ,feature nil t)))
  27. (defmacro autoload-eval-lazily (feature &optional functions &rest body)
  28. "Define autoloading FEATURE that defines FUNCTIONS.
  29. FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
  30. the function same as FEATURE is defined as autoloaded function. BODY is passed
  31. to `eval-after-load'.
  32. After this macro is expanded, this returns the path to library if FEATURE
  33. found, otherwise returns nil."
  34. (declare (indent 2) (debug t))
  35. (let* ((libname (symbol-name (eval feature)))
  36. (libpath (locate-library libname)))
  37. `(progn
  38. (when (locate-library ,libname)
  39. ,@(mapcar (lambda (f)
  40. `(unless (fboundp ',f)
  41. (progn
  42. (message "Autoloaded function `%S' defined (%s)"
  43. (quote ,f)
  44. ,libpath)
  45. (autoload (quote ,f)
  46. ,libname
  47. ,(concat "Autoloaded function defined in \""
  48. libpath
  49. "\".")
  50. t))))
  51. (or (eval functions)
  52. `(,(eval feature)))))
  53. (eval-after-load ,feature
  54. (quote (progn
  55. ,@body)))
  56. (locate-library ,libname))))
  57. (when (autoload-eval-lazily 'tetris nil
  58. (message "Tetris loaded!"))
  59. (message "Tetris found!"))
  60. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  61. ;; package
  62. (set (defvar 10sr-package-list)
  63. '(
  64. vimrc-mode
  65. markdown-mode
  66. yaml-mode
  67. gnuplot-mode
  68. php-mode
  69. erlang
  70. js2-mode
  71. js-doc
  72. git-commit
  73. gitignore-mode
  74. adoc-mode
  75. go-mode
  76. ;; It seems malabar has been merged into jdee and this package
  77. ;; already removed
  78. ;; malabar-mode
  79. ;; ack
  80. color-moccur
  81. ggtags
  82. flycheck
  83. auto-highlight-symbol
  84. hl-todo
  85. ;; Currently not available
  86. ;; pp-c-l
  87. ;; is flymake installs are required?
  88. ;;flymake-jshint
  89. ;;flymake-python-pyflakes
  90. xclip
  91. foreign-regexp
  92. multi-term
  93. term-run
  94. editorconfig
  95. git-ps1-mode
  96. restart-emacs
  97. fill-column-indicator
  98. pkgbuild-mode
  99. minibuffer-line
  100. which-key
  101. ;; I think this works in place of my autosave lib
  102. super-save
  103. pipenv
  104. imenu-list
  105. scala-mode
  106. ;;ensime
  107. editorconfig
  108. editorconfig-custom-majormode
  109. git-command
  110. prompt-text
  111. ;; 10sr repository
  112. ;; 10sr-extras
  113. terminal-title
  114. recentf-show
  115. dired-list-all-mode
  116. pack
  117. set-modeline-color
  118. read-only-only-mode
  119. smart-revert
  120. autosave
  121. ;;window-organizer
  122. remember-major-modes-mode
  123. ilookup
  124. pasteboard
  125. end-mark
  126. sl
  127. gosh-mode
  128. ))
  129. (when (safe-require-or-eval 'package)
  130. (setq package-archives
  131. `(,@package-archives
  132. ("melpa" . "https://melpa.org/packages/")
  133. ;; Somehow fails to download via https
  134. ("10sr-el" . "http://10sr.github.io/emacs-lisp/elpa/")))
  135. (package-initialize)
  136. (defun my-auto-install-package ()
  137. "Install packages semi-automatically."
  138. (interactive)
  139. (package-refresh-contents)
  140. (mapc (lambda (pkg)
  141. (or (package-installed-p pkg)
  142. (package-install pkg)))
  143. 10sr-package-list))
  144. )
  145. ;; (lazy-load-eval 'sudoku)
  146. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  147. ;; my-idle-hook
  148. (defvar my-idle-hook nil
  149. "Hook run when idle for several secs.")
  150. (defvar my-idle-hook-sec 5
  151. "Second to run `my-idle-hook'.")
  152. (run-with-idle-timer my-idle-hook-sec
  153. t
  154. (lambda ()
  155. (run-hooks 'my-idle-hook)))
  156. ;; (add-hook 'my-idle-hook
  157. ;; (lambda ()
  158. ;; (message "idle hook message")))
  159. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  160. ;; start and quit
  161. (setq inhibit-startup-message t)
  162. (setq confirm-kill-emacs 'y-or-n-p)
  163. (setq gc-cons-threshold (* 1024 1024 4))
  164. (when window-system
  165. (add-to-list 'default-frame-alist '(cursor-type . box))
  166. (add-to-list 'default-frame-alist '(background-color . "white"))
  167. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  168. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  169. ;; does not work?
  170. )
  171. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  172. (if window-system (menu-bar-mode 1) (menu-bar-mode 0))
  173. (and (fboundp 'tool-bar-mode)
  174. (tool-bar-mode 0))
  175. (and (fboundp 'set-scroll-bar-mode)
  176. (set-scroll-bar-mode nil))
  177. (call-after-init
  178. (lambda ()
  179. (message "%s %s" invocation-name emacs-version)
  180. (message "Invocation directory: %s" default-directory)
  181. (message "%s was taken to initialize emacs." (emacs-init-time))
  182. (switch-to-buffer "*Messages*")))
  183. (cd ".") ; when using windows use / instead of \ in `default-directory'
  184. ;; locale
  185. (set-language-environment "Japanese")
  186. (set-default-coding-systems 'utf-8-unix)
  187. (prefer-coding-system 'utf-8-unix)
  188. (setq system-time-locale "C")
  189. ;; my prefix map
  190. (defvar my-prefix-map nil
  191. "My prefix map.")
  192. (define-prefix-command 'my-prefix-map)
  193. (define-key ctl-x-map (kbd "C-x") 'my-prefix-map)
  194. (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  195. (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  196. ;; (comint-show-maximum-output)
  197. ;; kill scratch
  198. (call-after-init (lambda ()
  199. (let ((buf (get-buffer "*scratch*")))
  200. (when buf
  201. (kill-buffer buf)))))
  202. ;; modifier keys
  203. ;; (setq mac-option-modifier 'control)
  204. ;; display
  205. (setq visible-bell t)
  206. (setq ring-bell-function 'ignore)
  207. (mouse-avoidance-mode 'banish)
  208. (setq echo-keystrokes 0.1)
  209. (defun reload-init-file ()
  210. "Reload Emacs init file."
  211. (interactive)
  212. (when (and user-init-file
  213. (file-readable-p user-init-file))
  214. (load-file user-init-file)))
  215. (safe-require-or-eval 'session)
  216. ;; server
  217. (set-variable 'server-name (concat "server"
  218. (number-to-string (emacs-pid))))
  219. ;; In Cygwin Environment `server-runnning-p' stops when server-use-tcp is nil
  220. ;; In Darwin environment, init fails with message like 'Service name too long'
  221. ;; when server-use-tcp is nil
  222. (when (or (eq system-type
  223. 'cygwin)
  224. (eq system-type
  225. 'darwin))
  226. (set-variable 'server-use-tcp t))
  227. ;; MSYS2 fix
  228. (when (eq system-type
  229. 'windows-nt)
  230. (setq shell-file-name
  231. (executable-find "bash"))
  232. '(setq function-key-map
  233. `(,@function-key-map ([pause] . [?\C-c])
  234. ))
  235. (define-key key-translation-map
  236. (kbd "<pause>")
  237. (kbd "C-c"))
  238. '(keyboard-translate [pause]
  239. (kbd "C-c")p)
  240. ;; TODO: move to other place later
  241. (when (not window-system)
  242. (setq interprogram-paste-function nil)
  243. (setq interprogram-cut-function nil)))
  244. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  245. ;; global keys
  246. (global-set-key (kbd "<up>") 'scroll-down-line)
  247. (global-set-key (kbd "<down>") 'scroll-up-line)
  248. (global-set-key (kbd "<left>") 'scroll-down)
  249. (global-set-key (kbd "<right>") 'scroll-up)
  250. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  251. (global-set-key (kbd "C-\\") help-map)
  252. (define-key ctl-x-map (kbd "DEL") help-map)
  253. (define-key ctl-x-map (kbd "C-h") help-map)
  254. (define-key help-map "a" 'apropos)
  255. ;; disable annoying keys
  256. (global-set-key [prior] 'ignore)
  257. (global-set-key (kbd "<next>") 'ignore)
  258. (global-set-key [menu] 'ignore)
  259. (global-set-key [down-mouse-1] 'ignore)
  260. (global-set-key [down-mouse-2] 'ignore)
  261. (global-set-key [down-mouse-3] 'ignore)
  262. (global-set-key [mouse-1] 'ignore)
  263. (global-set-key [mouse-2] 'ignore)
  264. (global-set-key [mouse-3] 'ignore)
  265. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  266. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  267. (when (safe-require-or-eval 'which-key)
  268. (which-key-mode))
  269. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  270. ;; editting
  271. (setq kill-whole-line t)
  272. (setq scroll-conservatively 35
  273. scroll-margin 2
  274. scroll-step 0)
  275. (setq-default major-mode 'text-mode)
  276. (setq next-line-add-newlines nil)
  277. (setq kill-read-only-ok t)
  278. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  279. ;; (setq-default line-spacing 0.2)
  280. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  281. ;; (setq-default tab-width 4)
  282. (setq-default indent-tabs-mode nil)
  283. (setq-default indent-line-function 'indent-to-left-margin)
  284. ;; (setq-default indent-line-function nil)
  285. (setq-default truncate-lines nil)
  286. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  287. (delete-selection-mode 1)
  288. (cua-mode 0)
  289. (setq line-move-visual nil)
  290. ;; key bindings
  291. ;; moving around
  292. ;;(keyboard-translate ?\M-j ?\C-j)
  293. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  294. (define-key esc-map "p" 'backward-paragraph)
  295. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  296. (define-key esc-map "n" 'forward-paragraph)
  297. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  298. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  299. (global-set-key (kbd "C-<left>") 'scroll-down)
  300. (global-set-key (kbd "C-<right>") 'scroll-up)
  301. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  302. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  303. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  304. ;; C-h and DEL
  305. (global-set-key (kbd "C-h") (kbd "DEL"))
  306. ;;(global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  307. (global-set-key (kbd "C-m") 'newline-and-indent)
  308. ;; (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  309. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  310. (define-key esc-map "u" 'undo)
  311. (define-key esc-map "i" (kbd "ESC TAB"))
  312. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  313. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  314. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  315. (define-key my-prefix-map (kbd "C-o") 'occur)
  316. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  317. ;; title and mode-line
  318. (when (safe-require-or-eval 'terminal-title)
  319. ;; if TERM is not screen use default value
  320. (if (getenv "TMUX")
  321. ;; if use tmux locally just basename of current dir
  322. (set-variable 'terminal-title-format
  323. '((file-name-nondirectory (directory-file-name
  324. default-directory))))
  325. (if (and (let ((tty-type (frame-parameter nil
  326. 'tty-type)))
  327. (and tty-type
  328. (equal (car (split-string tty-type
  329. "-"))
  330. "screen")))
  331. (not (getenv "SSH_CONNECTION")))
  332. (set-variable 'terminal-title-format
  333. '((file-name-nondirectory (directory-file-name
  334. default-directory))))
  335. ;; seems that TMUX is used locally and ssh to remote host
  336. (set-variable 'terminal-title-format
  337. `("em:"
  338. ,user-login-name
  339. "@"
  340. ,(car (split-string (system-name)
  341. "\\."))
  342. ":"
  343. default-directory))
  344. )
  345. )
  346. (terminal-title-mode))
  347. (setq eol-mnemonic-dos "\\r\\n")
  348. (setq eol-mnemonic-mac "\\r")
  349. (setq eol-mnemonic-unix "")
  350. (which-function-mode 0)
  351. (line-number-mode 0)
  352. (column-number-mode 0)
  353. (size-indication-mode 0)
  354. (setq mode-line-position
  355. '(:eval (format "L%%l/%d:C%%c"
  356. (count-lines (point-max)
  357. (point-min)))))
  358. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  359. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  360. ;; minibuffer
  361. (setq insert-default-directory t)
  362. (setq completion-ignore-case t
  363. read-file-name-completion-ignore-case t
  364. read-buffer-completion-ignore-case t)
  365. (setq resize-mini-windows t)
  366. (temp-buffer-resize-mode 1)
  367. (savehist-mode 1)
  368. (defvar display-time-format "%Y/%m/%d %a %H:%M")
  369. (fset 'yes-or-no-p 'y-or-n-p)
  370. ;; complete symbol when `eval'
  371. (define-key read-expression-map (kbd "TAB") 'completion-at-point)
  372. (define-key minibuffer-local-map (kbd "C-u")
  373. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  374. ;; I dont know these bindings are good
  375. (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
  376. (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
  377. (when (safe-require-or-eval 'minibuffer-line)
  378. (set-face-underline 'minibuffer-line nil)
  379. (set-variable 'minibuffer-line-refresh-interval
  380. 25)
  381. ;; Set idle timer
  382. (defvar my-minibuffer-line--idle-timer nil)
  383. (defvar minibuffer-line-mode)
  384. (add-hook 'minibuffer-line-mode-hook
  385. (lambda ()
  386. (when my-minibuffer-line--idle-timer
  387. (cancel-timer my-minibuffer-line--idle-timer)
  388. (setq my-minibuffer-line--idle-timer nil))
  389. (when minibuffer-line-mode
  390. (setq my-minibuffer-line--idle-timer
  391. (run-with-idle-timer 0.5
  392. t
  393. 'minibuffer-line--update)))))
  394. (set-variable 'minibuffer-line-format
  395. `(,(concat user-login-name
  396. "@"
  397. (car (split-string (system-name)
  398. "\\."))
  399. ":")
  400. (:eval (abbreviate-file-name (or buffer-file-name
  401. default-directory)))
  402. (:eval (and (fboundp 'git-ps1-mode-get-current)
  403. (git-ps1-mode-get-current " [GIT:%s]")))
  404. " "
  405. (:eval (format-time-string display-time-format))))
  406. (minibuffer-line-mode 1)
  407. )
  408. (when (safe-require-or-eval 'prompt-text)
  409. (set-variable 'prompt-text-format
  410. `(,(concat ""
  411. user-login-name
  412. "@"
  413. (car (split-string (system-name)
  414. "\\."))
  415. ":")
  416. (:eval (abbreviate-file-name (or buffer-file-name
  417. default-directory)))
  418. (:eval (and (fboundp 'git-ps1-mode-get-current)
  419. (git-ps1-mode-get-current " [GIT:%s]")))
  420. " "
  421. (:eval (format-time-string display-time-format))
  422. "\n"
  423. (:eval (symbol-name this-command))
  424. ": "))
  425. (prompt-text-mode 1))
  426. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  427. ;; letters, font-lock mode and fonts
  428. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  429. ;; (set-window-margins (selected-window) 1 1)
  430. (and (or (eq system-type 'Darwin)
  431. (eq system-type 'darwin))
  432. (fboundp 'mac-set-input-method-parameter)
  433. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  434. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  435. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  436. (boundp 'input-method-inactivate-hook))
  437. (add-hook 'input-method-activate-hook
  438. (lambda () (set-cursor-color "red")))
  439. (add-hook 'input-method-inactivate-hook
  440. (lambda () (set-cursor-color "black"))))
  441. (when (safe-require-or-eval 'paren)
  442. (show-paren-mode 1)
  443. (setq show-paren-delay 0.5
  444. show-paren-style 'parenthesis) ; mixed is hard to read
  445. ;; (set-face-background 'show-paren-match
  446. ;; "black")
  447. ;; ;; (face-foreground 'default))
  448. ;; (set-face-foreground 'show-paren-match
  449. ;; "white")
  450. ;; (set-face-inverse-video-p 'show-paren-match
  451. ;; t)
  452. )
  453. (transient-mark-mode 1)
  454. (global-font-lock-mode 1)
  455. (setq font-lock-global-modes
  456. '(not
  457. help-mode
  458. eshell-mode
  459. ;;term-mode
  460. Man-mode))
  461. ;; (standard-display-ascii ?\n "$\n")
  462. ;; (defvar my-eol-face
  463. ;; '(("\n" . (0 font-lock-comment-face t nil)))
  464. ;; )
  465. ;; (defvar my-tab-face
  466. ;; '(("\t" . '(0 highlight t nil))))
  467. (defvar my-jspace-face
  468. '(("\u3000" . '(0 highlight t nil))))
  469. (add-hook 'font-lock-mode-hook
  470. (lambda ()
  471. ;; (font-lock-add-keywords nil my-eol-face)
  472. (font-lock-add-keywords nil my-jspace-face)
  473. ))
  474. (when (safe-require-or-eval 'whitespace)
  475. (add-to-list 'whitespace-display-mappings
  476. ;; We need t since last one takes precedence
  477. `(tab-mark ?\t ,(vconcat "^I\t")) t)
  478. ;; (add-to-list 'whitespace-display-mappings
  479. ;; `(newline-mark ?\n ,(vconcat "$\n")))
  480. (setq whitespace-style '(face
  481. trailing ; trailing blanks
  482. newline ; newlines
  483. newline-mark ; use display table for newline
  484. tab-mark
  485. empty ; empty lines at beg or end of buffer
  486. lines-tail ; lines over 80
  487. ))
  488. ;; (setq whitespace-newline 'font-lock-comment-face)
  489. (set-variable 'whitespace-line-column nil)
  490. (global-whitespace-mode t)
  491. (add-hook 'dired-mode-hook
  492. (lambda ()
  493. (set (make-local-variable 'whitespace-style) nil)))
  494. (if (eq (display-color-cells)
  495. 256)
  496. (set-face-foreground 'whitespace-newline "color-109")
  497. ;; (progn
  498. ;; (set-face-bold-p 'whitespace-newline
  499. ;; t))
  500. ))
  501. (and nil
  502. '(safe-require-or-eval 'fill-column-indicator)
  503. (setq fill-column-indicator))
  504. ;; highlight current line
  505. ;; http://wiki.riywo.com/index.php?Meadow
  506. (face-spec-set 'hl-line
  507. '((((min-colors 256)
  508. (background dark))
  509. (:background "color-234"))
  510. (((min-colors 256)
  511. (background light))
  512. (:background "color-234"))
  513. (t
  514. (:underline "black"))))
  515. (set-variable 'hl-line-global-modes
  516. '(not
  517. term-mode))
  518. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  519. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  520. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  521. ;;(safe-require-or-eval 'set-modeline-color)
  522. ;; (let ((fg (face-foreground 'default))
  523. ;; (bg (face-background 'default)))
  524. ;; (set-face-background 'mode-line-inactive
  525. ;; (if (face-inverse-video-p 'mode-line) fg bg))
  526. ;; (set-face-foreground 'mode-line-inactive
  527. ;; (if (face-inverse-video-p 'mode-line) bg fg)))
  528. ;; (set-face-underline 'mode-line-inactive
  529. ;; t)
  530. ;; (set-face-underline 'vertical-border
  531. ;; nil)
  532. (when (safe-require-or-eval 'end-mark)
  533. (global-end-mark-mode))
  534. (when (safe-require-or-eval 'auto-highlight-symbol)
  535. (set-variable 'ahs-idle-interval 0.6)
  536. (global-auto-highlight-symbol-mode 1))
  537. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  538. ;; file handling
  539. (when (safe-require-or-eval 'editorconfig)
  540. ;; (set-variable 'editorconfig-get-properties-function
  541. ;; 'editorconfig-core-get-properties-hash)
  542. (editorconfig-mode 1)
  543. (set-variable 'editorconfig-mode-lighter " EC")
  544. (with-eval-after-load 'org-src
  545. ;; [*.org\[\*Org Src*\[ c \]*\]]
  546. (add-hook 'org-src-mode-hook
  547. 'editorconfig-mode-apply t)))
  548. (when (fboundp 'editorconfig-custom-majormode)
  549. (add-hook 'editorconfig-custom-hooks
  550. 'editorconfig-custom-majormode))
  551. ;; Add readonly=true to set read-only-mode
  552. (add-hook 'editorconfig-custom-hooks
  553. (lambda (props)
  554. (let ((r (gethash 'readonly props)))
  555. (when (and (string= r "true")
  556. (not buffer-read-only))
  557. (read-only-mode 1)))))
  558. ;; (when (fboundp 'editorconfig-charset-extras)
  559. ;; (add-hook 'editorconfig-custom-hooks
  560. ;; 'editorconfig-charset-extras))
  561. (setq revert-without-query '(".+"))
  562. ;; save cursor position
  563. (when (safe-require-or-eval 'saveplace)
  564. (setq-default save-place t)
  565. (setq save-place-file (concat user-emacs-directory
  566. "places")))
  567. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  568. (setq make-backup-files t)
  569. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  570. (setq backup-directory-alist
  571. (cons (cons "\\.*$" (expand-file-name (concat user-emacs-directory
  572. "backup")))
  573. backup-directory-alist))
  574. (setq version-control 'never)
  575. (setq delete-old-versions t)
  576. (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
  577. "auto-save/")))
  578. (setq delete-auto-save-files t)
  579. (add-to-list 'completion-ignored-extensions ".bak")
  580. (setq delete-by-moving-to-trash t)
  581. ;; trash-directory "~/.emacs.d/trash")
  582. (add-hook 'after-save-hook
  583. 'executable-make-buffer-file-executable-if-script-p)
  584. (set (defvar bookmark-default-file)
  585. (expand-file-name (concat user-emacs-directory
  586. "bmk")))
  587. (with-eval-after-load 'recentf
  588. (defvar recentf-exclude nil)
  589. (add-to-list 'recentf-exclude
  590. (regexp-quote bookmark-default-file)))
  591. (when (safe-require-or-eval 'smart-revert)
  592. (smart-revert-on))
  593. ;; autosave
  594. (when (safe-require-or-eval 'autosave)
  595. (autosave-set 8))
  596. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  597. ;; buffer killing
  598. ;; (defun my-delete-window-killing-buffer () nil)
  599. (defun my-query-kill-current-buffer ()
  600. "Interactively kill current buffer."
  601. (interactive)
  602. (if (y-or-n-p (concat "kill current buffer? :"))
  603. (kill-buffer (current-buffer))))
  604. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  605. (substitute-key-definition 'kill-buffer
  606. 'my-query-kill-current-buffer
  607. global-map)
  608. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  609. ;; share clipboard with x
  610. ;; this page describes this in details, but only these sexps seem to be needed
  611. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  612. (and nil
  613. (not window-system)
  614. (not (eq window-system 'mac))
  615. (getenv "DISPLAY")
  616. (not (equal (getenv "DISPLAY") ""))
  617. (executable-find "xclip")
  618. ;; (< emacs-major-version 24)
  619. '(safe-require-or-eval 'xclip)
  620. nil
  621. (turn-on-xclip))
  622. (and (eq system-type 'darwin)
  623. (safe-require-or-eval 'pasteboard)
  624. (turn-on-pasteboard))
  625. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  626. ;; some modes and hooks
  627. ;; Include some extra modes
  628. (require 'generic-x)
  629. (when (autoload-eval-lazily 'ggtags)
  630. (add-hook 'c-mode-common-hook
  631. (lambda ()
  632. (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
  633. (ggtags-mode 1))))
  634. (add-hook 'python-mode-hook
  635. (lambda ()
  636. (ggtags-mode 1))))
  637. (when (autoload-eval-lazily 'imenu-list)
  638. (set-variable 'imenu-list-auto-resize t)
  639. (set-variable 'imenu-list-focus-after-activation t)
  640. (define-key ctl-x-map "l" 'imenu-list-smart-toggle))
  641. (with-eval-after-load 'compile
  642. (defvar compilation-filter-start)
  643. (defvar compilation-error-regexp-alist)
  644. (require 'ansi-color)
  645. (add-hook 'compilation-filter-hook
  646. (lambda ()
  647. (let ((inhibit-read-only t))
  648. (ansi-color-apply-on-region compilation-filter-start
  649. (point)))))
  650. (add-to-list 'compilation-error-regexp-alist
  651. ;; ansible-lint
  652. '("^\\([^ \n]+\\):\\([0-9]+\\)$" 1 2)))
  653. ;; Workaround to avoid ensime error
  654. (defvar ensime-mode-key-prefix nil)
  655. ;; http://qiita.com/sune2/items/b73037f9e85962f5afb7
  656. (when (safe-require-or-eval 'company)
  657. (global-company-mode)
  658. (set-variable 'company-idle-delay 0.5)
  659. (set-variable 'company-minimum-prefix-length 2)
  660. (set-variable 'company-selection-wrap-around t))
  661. ;; https://github.com/lunaryorn/flycheck
  662. (when (safe-require-or-eval 'flycheck)
  663. (call-after-init 'global-flycheck-mode))
  664. (when (autoload-eval-lazily 'ilookup)
  665. (define-key ctl-x-map "d" 'ilookup-open-word))
  666. (set-variable 'ac-ignore-case nil)
  667. (when (autoload-eval-lazily 'term-run '(term-run-shell-command term-run))
  668. (define-key ctl-x-map "t" 'term-run-shell-command))
  669. (add-to-list 'safe-local-variable-values
  670. '(encoding utf-8))
  671. (setq enable-local-variables :safe)
  672. ;; (when (safe-require-or-eval 'remember-major-modes-mode)
  673. ;; (remember-major-modes-mode 1))
  674. ;; Detect file type from shebang and set major-mode.
  675. (add-to-list 'interpreter-mode-alist
  676. '("python3" . python-mode))
  677. (add-to-list 'interpreter-mode-alist
  678. '("python2" . python-mode))
  679. (with-eval-after-load 'python
  680. (defvar python-mode-map (make-sparse-keymap))
  681. (define-key python-mode-map (kbd "C-m") 'newline-and-indent))
  682. ;; http://fukuyama.co/foreign-regexp
  683. '(and (safe-require-or-eval 'foreign-regexp)
  684. (progn
  685. (setq foreign-regexp/regexp-type 'perl)
  686. '(setq reb-re-syntax 'foreign-regexp)
  687. ))
  688. (autoload-eval-lazily 'sql '(sql-mode)
  689. (require 'sql-indent nil t))
  690. (when (autoload-eval-lazily 'git-command)
  691. (define-key ctl-x-map "g" 'git-command))
  692. (when (safe-require-or-eval 'git-commit)
  693. (global-git-commit-mode 1))
  694. (with-eval-after-load 'git-commit
  695. (add-hook 'git-commit-setup-hook
  696. 'turn-off-auto-fill t))
  697. (autoload-eval-lazily 'sl)
  698. (with-eval-after-load 'rst
  699. (defvar rst-mode-map)
  700. (define-key rst-mode-map (kbd "C-m") 'newline-and-indent))
  701. (with-eval-after-load 'jdee
  702. (add-hook 'jdee-mode-hook
  703. (lambda ()
  704. (make-local-variable 'global-mode-string)
  705. (add-to-list 'global-mode-string
  706. mode-line-position))))
  707. ;; Cannot enable error thrown. Why???
  708. ;; https://github.com/m0smith/malabar-mode#Installation
  709. ;; (when (autoload-eval-lazily 'malabar-mode)
  710. ;; (add-to-list 'load-path
  711. ;; (expand-file-name (concat user-emacs-directory "/cedet")))
  712. ;; (safe-require-or-eval 'cedet-devel-load)
  713. ;; (call-after-init 'activate-malabar-mode))
  714. (with-eval-after-load 'make-mode
  715. (defvar makefile-mode-map (make-sparse-keymap))
  716. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  717. ;; this functions is set in write-file-functions, i cannot find any
  718. ;; good way to remove this.
  719. (fset 'makefile-warn-suspicious-lines 'ignore))
  720. (with-eval-after-load 'verilog-mode
  721. (defvar verilog-mode-map (make-sparse-keymap))
  722. (define-key verilog-mode-map ";" 'self-insert-command))
  723. (setq diff-switches "-u")
  724. (with-eval-after-load 'diff-mode
  725. ;; (when (and (eq major-mode
  726. ;; 'diff-mode)
  727. ;; (not buffer-file-name))
  728. ;; ;; do not pass when major-mode is derived mode of diff-mode
  729. ;; (view-mode 1))
  730. (set-face-attribute 'diff-header nil
  731. :foreground nil
  732. :background nil
  733. :weight 'bold)
  734. (set-face-attribute 'diff-file-header nil
  735. :foreground nil
  736. :background nil
  737. :weight 'bold)
  738. (set-face-foreground 'diff-index "blue")
  739. (set-face-attribute 'diff-hunk-header nil
  740. :foreground "cyan"
  741. :weight 'normal)
  742. (set-face-attribute 'diff-context nil
  743. ;; :foreground "white"
  744. :foreground nil
  745. :weight 'normal)
  746. (set-face-foreground 'diff-removed "red")
  747. (set-face-foreground 'diff-added "green")
  748. (set-face-background 'diff-removed nil)
  749. (set-face-background 'diff-added nil)
  750. (set-face-attribute 'diff-changed nil
  751. :foreground "magenta"
  752. :weight 'normal)
  753. (set-face-attribute 'diff-refine-changed nil
  754. :foreground nil
  755. :background nil
  756. :weight 'bold
  757. :inverse-video t)
  758. ;; Annoying !
  759. ;;(diff-auto-refine-mode)
  760. )
  761. ;; (ffap-bindings)
  762. (set-variable 'browse-url-browser-function
  763. 'eww-browse-url)
  764. (set-variable 'sh-here-document-word "__EOC__")
  765. (when (autoload-eval-lazily 'adoc-mode
  766. nil
  767. (defvar adoc-mode-map (make-sparse-keymap))
  768. (define-key adoc-mode-map (kbd "C-m") 'newline))
  769. (setq auto-mode-alist
  770. `(("\\.adoc\\'" . adoc-mode)
  771. ("\\.asciidoc\\'" . adoc-mode)
  772. ,@auto-mode-alist)))
  773. (with-eval-after-load 'markup-faces
  774. ;; Is this too match ?
  775. (set-face-foreground 'markup-meta-face
  776. "color-245")
  777. (set-face-foreground 'markup-meta-hide-face
  778. "color-245")
  779. )
  780. ;; TODO: check if this is required
  781. (when (autoload-eval-lazily 'groovy-mode nil
  782. (defvar groovy-mode-map (make-sparse-keymap))
  783. (define-key groovy-mode-map "(" 'self-insert-command)
  784. (define-key groovy-mode-map ")" 'self-insert-command)
  785. (define-key groovy-mode-map (kbd "C-m") 'newline-and-indent)
  786. )
  787. (add-to-list 'auto-mode-alist
  788. '("build\\.gradle\\'" . groovy-mode)))
  789. (with-eval-after-load 'yaml-mode
  790. (defvar yaml-mode-map (make-sparse-keymap))
  791. (define-key yaml-mode-map (kbd "C-m") 'newline))
  792. (with-eval-after-load 'html-mode
  793. (defvar html-mode-map (make-sparse-keymap))
  794. (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
  795. (with-eval-after-load 'text-mode
  796. (define-key text-mode-map (kbd "C-m") 'newline))
  797. (with-eval-after-load 'info
  798. (defvar Info-directory-list nil)
  799. (add-to-list 'Info-directory-list
  800. (expand-file-name "~/.brew/share/info")))
  801. (with-eval-after-load 'apropos
  802. (defvar apropos-mode-map (make-sparse-keymap))
  803. (define-key apropos-mode-map "n" 'next-line)
  804. (define-key apropos-mode-map "p" 'previous-line))
  805. ;; `isearch' library does not call `provide' so cannot use with-eval-after-load
  806. ;; (define-key isearch-mode-map
  807. ;; (kbd "C-j") 'isearch-other-control-char)
  808. ;; (define-key isearch-mode-map
  809. ;; (kbd "C-k") 'isearch-other-control-char)
  810. ;; (define-key isearch-mode-map
  811. ;; (kbd "C-h") 'isearch-other-control-char)
  812. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  813. (define-key isearch-mode-map (kbd "M-r")
  814. 'isearch-query-replace-regexp)
  815. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  816. (setq lazy-highlight-cleanup nil)
  817. ;; face for isearch highlighing
  818. (set-face-attribute 'lazy-highlight
  819. nil
  820. :foreground `unspecified
  821. :background `unspecified
  822. :underline t
  823. ;; :weight `bold
  824. )
  825. (add-hook 'outline-mode-hook
  826. (lambda ()
  827. (when (string-match "\\.md\\'" buffer-file-name)
  828. (set (make-local-variable 'outline-regexp) "#+ "))))
  829. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  830. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  831. (when (autoload-eval-lazily 'markdown-mode
  832. '(markdown-mode gfm-mode)
  833. (defvar gfm-mode-map (make-sparse-keymap))
  834. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline))
  835. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  836. (set-variable 'markdown-command (or (executable-find "markdown")
  837. (executable-find "markdown.pl")
  838. ""))
  839. (add-hook 'markdown-mode-hook
  840. (lambda ()
  841. (outline-minor-mode 1)
  842. (flyspell-mode)
  843. (set (make-local-variable 'comment-start) ";")))
  844. )
  845. ;; c-mode
  846. ;; http://www.emacswiki.org/emacs/IndentingC
  847. ;; http://en.wikipedia.org/wiki/Indent_style
  848. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  849. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  850. (with-eval-after-load 'cc-vars
  851. (defvar c-default-style nil)
  852. (add-to-list 'c-default-style
  853. '(c-mode . "k&r"))
  854. (add-to-list 'c-default-style
  855. '(c++-mode . "k&r")))
  856. (autoload-eval-lazily 'js2-mode nil
  857. ;; currently do not use js2-mode
  858. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  859. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  860. ;; (defvar js2-mode-map (make-sparse-keymap))
  861. ;; (define-key js2-mode-map (kbd "C-m") (lambda ()
  862. ;; (interactive)
  863. ;; (js2-enter-key)
  864. ;; (indent-for-tab-command)))
  865. ;; (add-hook (kill-local-variable 'before-save-hook)
  866. ;; 'js2-before-save)
  867. ;; (add-hook 'before-save-hook
  868. ;; 'my-indent-buffer
  869. ;; nil
  870. ;; t)
  871. )
  872. (add-to-list 'interpreter-mode-alist
  873. '("node" . js-mode))
  874. (when (autoload-eval-lazily 'flymake-jslint
  875. '(flymake-jslint-load))
  876. (autoload-eval-lazily 'js nil
  877. (add-hook 'js-mode-hook
  878. 'flymake-jslint-load)))
  879. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  880. (with-eval-after-load 'uniquify
  881. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  882. (setq uniquify-ignore-buffers-re "*[^*]+*")
  883. (setq uniquify-min-dir-content 1))
  884. (with-eval-after-load 'view
  885. (defvar view-mode-map (make-sparse-keymap))
  886. (define-key view-mode-map "j" 'scroll-up-line)
  887. (define-key view-mode-map "k" 'scroll-down-line)
  888. (define-key view-mode-map "v" 'toggle-read-only)
  889. (define-key view-mode-map "q" 'bury-buffer)
  890. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  891. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  892. ;; (define-key view-mode-map
  893. ;; "n" 'nonincremental-repeat-search-forward)
  894. ;; (define-key view-mode-map
  895. ;; "N" 'nonincremental-repeat-search-backward)
  896. (define-key view-mode-map "/" 'isearch-forward-regexp)
  897. (define-key view-mode-map "?" 'isearch-backward-regexp)
  898. (define-key view-mode-map "n" 'isearch-repeat-forward)
  899. (define-key view-mode-map "N" 'isearch-repeat-backward)
  900. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
  901. (global-set-key "\M-r" 'view-mode)
  902. ;; (setq view-read-only t)
  903. (with-eval-after-load 'term
  904. (defvar term-raw-map (make-sparse-keymap))
  905. (define-key term-raw-map (kbd "C-x")
  906. (lookup-key (current-global-map)
  907. (kbd "C-x"))))
  908. (add-hook 'term-mode-hook
  909. (lambda ()
  910. ;; Stop current line highlighting
  911. (set (make-local-variable (defvar hl-line-range-function))
  912. (lambda () '(0 . 0)))
  913. (set (make-local-variable 'scroll-margin)
  914. 0)))
  915. (add-hook 'Man-mode-hook
  916. (lambda ()
  917. (view-mode 1)
  918. (setq truncate-lines nil)))
  919. (set-variable 'Man-notify-method (if window-system
  920. 'newframe
  921. 'aggressive))
  922. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  923. "woman_cache.el")))
  924. ;; not work because man.el will be loaded when man called
  925. (defalias 'man 'woman)
  926. (add-to-list 'auto-mode-alist
  927. '("tox\\.ini\\'" . conf-unix-mode))
  928. (when (autoload-eval-lazily 'toml-mode)
  929. (add-to-list 'auto-mode-alist
  930. '("/Pipfile\\'" . toml-mode)))
  931. (when (autoload-eval-lazily 'json-mode)
  932. (add-to-list 'auto-mode-alist
  933. '("/Pipfile\\.lock\\'" . json-mode)))
  934. (add-hook 'go-mode-hook
  935. (lambda()
  936. (defvar go-mode-map)
  937. (add-hook 'before-save-hook' 'gofmt-before-save)
  938. (define-key go-mode-map (kbd "M-.") 'godef-jump)))
  939. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  940. ;; buffer switching
  941. (defvar bs-configurations)
  942. (when (autoload-eval-lazily 'bs '(bs-show)
  943. (add-to-list 'bs-configurations
  944. '("specials" "^\\*" nil ".*" nil nil))
  945. (add-to-list 'bs-configurations
  946. '("files-and-specials" "^\\*" buffer-file-name ".*" nil nil))
  947. (defvar bs-mode-map)
  948. (defvar bs-current-configuration)
  949. (define-key bs-mode-map (kbd "t")
  950. ;; TODO: fix toggle feature
  951. (lambda ()
  952. (interactive)
  953. (if (string= "specials"
  954. bs-current-configuration)
  955. (bs-set-configuration "files")
  956. (bs-set-configuration "specials"))
  957. (bs-refresh)
  958. (bs-message-without-log "%s"
  959. (bs--current-config-message))))
  960. ;; (setq bs-configurations (list
  961. ;; '("processes" nil get-buffer-process ".*" nil nil)
  962. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  963. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  964. )
  965. (defalias 'list-buffers 'bs-show)
  966. (set-variable 'bs-default-configuration "files-and-specials")
  967. (set-variable 'bs-default-sort-name "by nothing")
  968. (add-hook 'bs-mode-hook
  969. (lambda ()
  970. (set (make-local-variable 'scroll-margin) 0))))
  971. ;;(iswitchb-mode 1)
  972. (icomplete-mode)
  973. (defun iswitchb-buffer-display-other-window ()
  974. "Do iswitchb in other window."
  975. (interactive)
  976. (let ((iswitchb-default-method 'display))
  977. (call-interactively 'iswitchb-buffer)))
  978. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  979. ;; vc
  980. (set-variable 'vc-handled-backends '())
  981. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  982. ;; recentf-mode
  983. (set-variable 'recentf-save-file (expand-file-name (concat user-emacs-directory
  984. "recentf")))
  985. (set-variable 'recentf-max-menu-items 20)
  986. (set-variable 'recentf-max-saved-items 30)
  987. (set-variable 'recentf-show-file-shortcuts-flag nil)
  988. (when (safe-require-or-eval 'recentf)
  989. (add-to-list 'recentf-exclude
  990. (regexp-quote recentf-save-file))
  991. (add-to-list 'recentf-exclude
  992. (regexp-quote (expand-file-name user-emacs-directory)))
  993. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  994. (remove-hook 'find-file-hook
  995. 'recentf-track-opened-file)
  996. (defun my-recentf-load-track-save-list ()
  997. "Load current recentf list from file, track current visiting file, then save
  998. the list."
  999. (recentf-load-list)
  1000. (recentf-track-opened-file)
  1001. (recentf-save-list))
  1002. (add-hook 'find-file-hook
  1003. 'my-recentf-load-track-save-list)
  1004. (add-hook 'kill-emacs-hook
  1005. 'recentf-load-list)
  1006. ;;(run-with-idle-timer 5 t 'recentf-save-list)
  1007. ;; (add-hook 'find-file-hook
  1008. ;; (lambda ()
  1009. ;; (recentf-add-file default-directory)))
  1010. (and (autoload-eval-lazily 'recentf-show)
  1011. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1012. (add-hook 'recentf-show-before-listing-hook
  1013. 'recentf-load-list))
  1014. (recentf-mode 1)
  1015. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1016. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1017. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1018. (define-key recentf-dialog-mode-map "n" 'next-line)
  1019. (add-hook 'recentf-dialog-mode-hook
  1020. (lambda ()
  1021. ;; (recentf-save-list)
  1022. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1023. ;; 'my-recentf-cd-and-find-file)
  1024. (cd "~/"))))
  1025. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1026. ;; dired
  1027. (defun my-dired-echo-file-head (arg)
  1028. "Echo head of current file.
  1029. ARG is num to show, or defaults to 7."
  1030. (interactive "P")
  1031. (let ((f (dired-get-filename)))
  1032. (message "%s"
  1033. (with-temp-buffer
  1034. (insert-file-contents f)
  1035. (buffer-substring-no-properties
  1036. (point-min)
  1037. (progn (goto-char (point-min))
  1038. (forward-line (1- (if arg
  1039. (prefix-numeric-value arg)
  1040. 7)))
  1041. (point-at-eol)))))))
  1042. (defun my-dired-diff ()
  1043. "Show diff of marked file and file of current line."
  1044. (interactive)
  1045. (let ((files (dired-get-marked-files nil nil nil t)))
  1046. (if (eq (car files)
  1047. t)
  1048. (diff (cadr files) (dired-get-filename))
  1049. (message "One file must be marked!"))))
  1050. (defun dired-get-file-info ()
  1051. "Print information of current line file."
  1052. (interactive)
  1053. (let ((f (shell-quote-argument (dired-get-filename t))))
  1054. (if (file-directory-p f)
  1055. (progn
  1056. (message "Calculating disk usage...")
  1057. (shell-command (concat "du -hsD "
  1058. f)))
  1059. (shell-command (concat "file "
  1060. f)))))
  1061. (defun my-dired-scroll-up ()
  1062. "Scroll up."
  1063. (interactive)
  1064. (my-dired-previous-line (- (window-height) 1)))
  1065. (defun my-dired-scroll-down ()
  1066. "Scroll down."
  1067. (interactive)
  1068. (my-dired-next-line (- (window-height) 1)))
  1069. ;; (defun my-dired-forward-line (arg)
  1070. ;; ""
  1071. ;; (interactive "p"))
  1072. (defun my-dired-previous-line (arg)
  1073. "Move ARG lines up."
  1074. (interactive "p")
  1075. (if (> arg 0)
  1076. (progn
  1077. (if (eq (line-number-at-pos)
  1078. 1)
  1079. (goto-char (point-max))
  1080. (forward-line -1))
  1081. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1082. (dired-get-subdir))
  1083. (- arg 1)
  1084. arg)))
  1085. (dired-move-to-filename)))
  1086. (defun my-dired-next-line (arg)
  1087. "Move ARG lines down."
  1088. (interactive "p")
  1089. (if (> arg 0)
  1090. (progn
  1091. (if (eq (point)
  1092. (point-max))
  1093. (goto-char (point-min))
  1094. (forward-line 1))
  1095. (my-dired-next-line (if (or (dired-get-filename nil t)
  1096. (dired-get-subdir))
  1097. (- arg 1)
  1098. arg)))
  1099. (dired-move-to-filename)))
  1100. (defun my-dired-tramp-open (host)
  1101. "Open HOST home directory."
  1102. (interactive "sHostname: ")
  1103. (find-file (format "/scp:%s:" host)))
  1104. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1105. (if (eq window-system 'mac)
  1106. (setq dired-listing-switches "-lhF")
  1107. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1108. )
  1109. (setq dired-listing-switches "-lhF")
  1110. (put 'dired-find-alternate-file 'disabled nil)
  1111. ;; when using dired-find-alternate-file
  1112. ;; reuse current dired buffer for the file to open
  1113. (set-variable 'dired-ls-F-marks-symlinks t)
  1114. (set-variable 'ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1115. (set-variable 'ls-lisp-dirs-first t)
  1116. (set-variable 'ls-lisp-use-localized-time-format t)
  1117. (set-variable 'ls-lisp-format-time-list
  1118. '("%Y-%m-%d %H:%M"
  1119. "%Y-%m-%d "))
  1120. (set-variable 'dired-dwim-target t)
  1121. (set-variable 'dired-isearch-filenames t)
  1122. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  1123. (set-variable 'dired-hide-details-hide-information-lines nil)
  1124. (set-variable 'dired-deletion-confirmer 'y-or-n-p)
  1125. (set-variable 'dired-recursive-deletes 'always)
  1126. ;; (add-hook 'dired-after-readin-hook
  1127. ;; 'my-replace-nasi-none)
  1128. (with-eval-after-load 'dired
  1129. (safe-require-or-eval 'ls-lisp)
  1130. (defvar dired-mode-map (make-sparse-keymap))
  1131. (define-key dired-mode-map "i" 'dired-get-file-info)
  1132. (define-key dired-mode-map "f" 'find-file)
  1133. (define-key dired-mode-map "!" 'shell-command)
  1134. (define-key dired-mode-map "&" 'async-shell-command)
  1135. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1136. (define-key dired-mode-map "=" 'my-dired-diff)
  1137. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1138. (define-key dired-mode-map "b" 'gtkbm)
  1139. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1140. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1141. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1142. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1143. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1144. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1145. (substitute-key-definition 'dired-next-line
  1146. 'my-dired-next-line
  1147. dired-mode-map)
  1148. (substitute-key-definition 'dired-previous-line
  1149. 'my-dired-previous-line
  1150. dired-mode-map)
  1151. ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
  1152. ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
  1153. ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
  1154. ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
  1155. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1156. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1157. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1158. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1159. (add-hook 'dired-mode-hook
  1160. (lambda ()
  1161. (when (fboundp 'dired-hide-details-mode)
  1162. (dired-hide-details-mode t)
  1163. (local-set-key "l" 'dired-hide-details-mode))
  1164. (let ((file "._Icon\015"))
  1165. (when nil
  1166. '(file-readable-p file)
  1167. (delete-file file)))))
  1168. (when (autoload-eval-lazily 'pack '(dired-do-pack-or-unpack pack-pack))
  1169. (with-eval-after-load 'dired
  1170. (define-key dired-mode-map "P" 'pack-dired-dwim)))
  1171. (when (autoload-eval-lazily 'dired-list-all-mode)
  1172. (setq dired-listing-switches "-lhF")
  1173. (with-eval-after-load 'dired
  1174. (define-key dired-mode-map "a" 'dired-list-all-mode))))
  1175. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1176. ;; misc funcs
  1177. (defalias 'qcalc 'quick-calc)
  1178. (defun memo (&optional dir)
  1179. "Open memo.txt in DIR."
  1180. (interactive)
  1181. (pop-to-buffer (find-file-noselect (concat (if dir
  1182. (file-name-as-directory dir)
  1183. "")
  1184. "memo.txt"))))
  1185. (defvar my-rgrep-alist
  1186. `(
  1187. ;; git grep
  1188. ("gitgrep"
  1189. (eq 0
  1190. (shell-command "git rev-parse --git-dir"))
  1191. "git --no-pager -c color.grep=false grep -nH -e ")
  1192. ;; ripgrep
  1193. ("rg"
  1194. (executable-find "rg")
  1195. "rg --no-heading --color=never --smart-case ")
  1196. ;; sift
  1197. ("sift"
  1198. (executable-find "sift")
  1199. ("sift --no-color --binary-skip --filename --line-number --git --smart-case "))
  1200. ;; the silver searcher
  1201. ("ag"
  1202. (executable-find "ag")
  1203. "ag --nocolor --nogroup --nopager --filename ")
  1204. ;; ack
  1205. ("ack"
  1206. (executable-find "ack")
  1207. "ack --nocolor --nogroup --nopager --with-filename ")
  1208. ;; gnu global
  1209. ("global"
  1210. (and (require 'gtags nil t)
  1211. (executable-find "global")
  1212. (gtags-get-rootpath))
  1213. "global --result grep ")
  1214. ;; grep
  1215. ("grep"
  1216. t
  1217. ,(concat "find . "
  1218. "-path '*/.git' -prune -o "
  1219. "-path '*/.svn' -prune -o "
  1220. "-type f -print0 | "
  1221. "xargs -0 grep -nH -e "))
  1222. )
  1223. "Alist of rgrep command.
  1224. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  1225. condition to choose COMMAND when evaluated.")
  1226. (defvar my-rgrep-default nil
  1227. "Default command name for my-rgrep.")
  1228. (defun my-rgrep-grep-command (&optional name alist)
  1229. "Return recursive grep command for current directory or nil.
  1230. If NAME is given, use that without testing.
  1231. Commands are searched from ALIST."
  1232. (if alist
  1233. (if name
  1234. ;; if name is given search that from alist and return the command
  1235. (nth 2 (assoc name
  1236. alist))
  1237. ;; if name is not given try test in 1th elem
  1238. (let ((car (car alist))
  1239. (cdr (cdr alist)))
  1240. (if (eval (nth 1 car))
  1241. ;; if the condition is true return the command
  1242. (nth 2 car)
  1243. ;; try next one
  1244. (and cdr
  1245. (my-rgrep-grep-command name cdr)))))
  1246. ;; if alist is not given set default value
  1247. (my-rgrep-grep-command name my-rgrep-alist)))
  1248. (defun my-rgrep (command-args)
  1249. "My recursive grep. Run COMMAND-ARGS.
  1250. If prefix argument is given, use current symbol as default search target
  1251. and search from projectile root (if projectile is available)."
  1252. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  1253. nil)))
  1254. (if cmd
  1255. (list (read-shell-command "grep command: "
  1256. (concat cmd
  1257. (if current-prefix-arg
  1258. (thing-at-point 'symbol t)
  1259. ""))
  1260. 'grep-find-history))
  1261. (error "My-Rgrep: Command for rgrep not found")
  1262. )))
  1263. (if (and current-prefix-arg
  1264. (safe-require-or-eval 'projectile))
  1265. (projectile-with-default-dir (projectile-project-root)
  1266. (compilation-start command-args
  1267. 'grep-mode))
  1268. (compilation-start command-args
  1269. 'grep-mode)))
  1270. (defmacro define-my-rgrep (name)
  1271. "Define rgrep for NAME."
  1272. `(defun ,(intern (concat "my-rgrep-"
  1273. name)) ()
  1274. ,(format "My recursive grep by %s."
  1275. name)
  1276. (interactive)
  1277. (let ((my-rgrep-default ,name))
  1278. (if (called-interactively-p 'any)
  1279. (call-interactively 'my-rgrep)
  1280. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  1281. )
  1282. (define-my-rgrep "ack")
  1283. (define-my-rgrep "ag")
  1284. (define-my-rgrep "rg")
  1285. (define-my-rgrep "sift")
  1286. (define-my-rgrep "gitgrep")
  1287. (define-my-rgrep "grep")
  1288. (define-my-rgrep "global")
  1289. (define-key ctl-x-map "s" 'my-rgrep)
  1290. (defalias 'make 'compile)
  1291. (define-key ctl-x-map "c" 'compile)
  1292. ;;;;;;;;;;;;;;;;;;;;;;;
  1293. ;; adoc-simple-mode
  1294. (when (safe-require-or-eval 'adoc-mode)
  1295. (defvar adoc-simple-font-lock-keywords
  1296. nil)
  1297. (define-derived-mode adoc-simple-mode adoc-mode
  1298. "Adoc-Simple"
  1299. "Major mode for editing AsciiDoc text files.
  1300. This mode is a simplified version of `adoc-mode'."
  1301. '(set (make-local-variable 'font-lock-defaults)
  1302. '(adoc-simple-font-lock-keywords
  1303. nil nil nil nil
  1304. (font-lock-multiline . t)
  1305. (font-lock-mark-block-function . adoc-font-lock-mark-block-function))))
  1306. (add-to-list 'auto-mode-alist
  1307. '("\\.adoc\\'" . adoc-simple-mode)))
  1308. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1309. ;; awk-preview
  1310. (defgroup awk-preview nil
  1311. "Awk previewer."
  1312. :tag "Awk Preview"
  1313. :prefix "awk-preview-"
  1314. :group 'tools)
  1315. (defcustom awk-preview-program
  1316. (or (executable-find "gawk")
  1317. (executable-find "awk")
  1318. "awk")
  1319. "Awk program to execute."
  1320. :type 'string
  1321. :group 'awk-preview)
  1322. (defcustom awk-preview-switches
  1323. '("--sandbox" "--" "{print}")
  1324. "String of awk options appended when running awk preview."
  1325. :type '(repeat string)
  1326. :group 'awk-preview)
  1327. (defun awk-preview--invoke (start end output)
  1328. "Execute awk process and get result."
  1329. (let ((proc (apply 'start-process
  1330. "awk-preview"
  1331. output
  1332. awk-preview-program
  1333. awk-preview-switches)))
  1334. (message "%S" proc)
  1335. (process-send-region proc start end)
  1336. (process-send-eof proc)
  1337. (accept-process-output proc)
  1338. )
  1339. output)
  1340. (defun awk-preview (start end)
  1341. "Run awk and preview result."
  1342. (interactive "r")
  1343. (let ((output (with-current-buffer (get-buffer-create "*awk-preview output*")
  1344. (erase-buffer)
  1345. (current-buffer))))
  1346. (awk-preview--invoke start end output)
  1347. (message "awk-preview: %s" (with-current-buffer output
  1348. (buffer-substring-no-properties (point-min) (point-max))))
  1349. ))
  1350. (defun my-file-head (filename &optional n)
  1351. "Return list of first N lines of file FILENAME."
  1352. (let ((num (or n 10))
  1353. (size 100)
  1354. (beg 0)
  1355. (end 0)
  1356. (result '()))
  1357. (with-temp-buffer
  1358. (while (<= (count-lines (point-min)
  1359. (point-max))
  1360. num)
  1361. (setq end (+ beg size))
  1362. (insert-file-contents filename
  1363. nil
  1364. beg
  1365. end)
  1366. (setq beg end))
  1367. (goto-char (point-min))
  1368. (while (< (length result) num)
  1369. (let ((start (point)))
  1370. (forward-line 1)
  1371. (setq result
  1372. `(,@result ,(buffer-substring-no-properties start
  1373. (point))))))
  1374. result)))
  1375. ;; (apply 'concat (car (my-file-head "./emacs.el"))
  1376. (set-variable 'dumb-jump-prefer-searcher 'rg)
  1377. ;; Local Variables:
  1378. ;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
  1379. ;; flycheck-checker: emacs-lisp
  1380. ;; End:
  1381. ;;; emancs.el ends here