Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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