Emacs personal configuration
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

338 linhas
11KB

  1. (require-package 'unfill)
  2. (when (fboundp 'electric-pair-mode)
  3. (electric-pair-mode))
  4. (when (fboundp 'electric-indent-mode)
  5. (electric-indent-mode))
  6. ;;----------------------------------------------------------------------------
  7. ;; Some basic preferences
  8. ;;----------------------------------------------------------------------------
  9. (setq-default
  10. blink-cursor-delay 0
  11. blink-cursor-interval 0.4
  12. bookmark-default-file (expand-file-name ".bookmarks.el" user-emacs-directory)
  13. buffers-menu-max-size 30
  14. case-fold-search t
  15. column-number-mode t
  16. delete-selection-mode t
  17. ediff-split-window-function 'split-window-horizontally
  18. ediff-window-setup-function 'ediff-setup-windows-plain
  19. indent-tabs-mode nil
  20. make-backup-files nil
  21. mouse-yank-at-point t
  22. save-interprogram-paste-before-kill t
  23. scroll-preserve-screen-position 'always
  24. set-mark-command-repeat-pop t
  25. show-trailing-whitespace t
  26. tooltip-delay 1.5
  27. truncate-lines nil
  28. truncate-partial-width-windows nil
  29. visible-bell t)
  30. (global-auto-revert-mode)
  31. (setq global-auto-revert-non-file-buffers t
  32. auto-revert-verbose nil)
  33. (transient-mark-mode t)
  34. ;;; Whitespace
  35. (defun sanityinc/no-trailing-whitespace ()
  36. "Turn off display of trailing whitespace in this buffer."
  37. (setq show-trailing-whitespace nil))
  38. ;; But don't show trailing whitespace in SQLi, inf-ruby etc.
  39. (dolist (hook '(special-mode-hook
  40. eww-mode-hook
  41. term-mode-hook
  42. comint-mode-hook
  43. compilation-mode-hook
  44. twittering-mode-hook
  45. minibuffer-setup-hook))
  46. (add-hook hook #'sanityinc/no-trailing-whitespace))
  47. (require-package 'whitespace-cleanup-mode)
  48. (global-whitespace-cleanup-mode t)
  49. (when (eval-when-compile (string< "24.3.1" emacs-version))
  50. ;; https://github.com/purcell/emacs.d/issues/138
  51. (after-load 'subword
  52. (diminish 'subword-mode)))
  53. (when (fboundp 'global-prettify-symbols-mode)
  54. (global-prettify-symbols-mode))
  55. (require-package 'undo-tree)
  56. (global-undo-tree-mode)
  57. (diminish 'undo-tree-mode)
  58. (require-package 'highlight-symbol)
  59. (dolist (hook '(prog-mode-hook html-mode-hook css-mode-hook))
  60. (add-hook hook 'highlight-symbol-mode)
  61. (add-hook hook 'highlight-symbol-nav-mode))
  62. (eval-after-load 'highlight-symbol
  63. '(diminish 'highlight-symbol-mode))
  64. ;;----------------------------------------------------------------------------
  65. ;; Zap *up* to char is a handy pair for zap-to-char
  66. ;;----------------------------------------------------------------------------
  67. (autoload 'zap-up-to-char "misc" "Kill up to, but not including ARGth occurrence of CHAR.")
  68. (global-set-key (kbd "M-Z") 'zap-up-to-char)
  69. (require-package 'browse-kill-ring)
  70. ;;----------------------------------------------------------------------------
  71. ;; Don't disable narrowing commands
  72. ;;----------------------------------------------------------------------------
  73. (put 'narrow-to-region 'disabled nil)
  74. (put 'narrow-to-page 'disabled nil)
  75. (put 'narrow-to-defun 'disabled nil)
  76. ;;----------------------------------------------------------------------------
  77. ;; Show matching parens
  78. ;;----------------------------------------------------------------------------
  79. (show-paren-mode 1)
  80. ;;----------------------------------------------------------------------------
  81. ;; Expand region
  82. ;;----------------------------------------------------------------------------
  83. (require-package 'expand-region)
  84. (global-set-key (kbd "C-=") 'er/expand-region)
  85. ;;----------------------------------------------------------------------------
  86. ;; Don't disable case-change functions
  87. ;;----------------------------------------------------------------------------
  88. (put 'upcase-region 'disabled nil)
  89. (put 'downcase-region 'disabled nil)
  90. ;;----------------------------------------------------------------------------
  91. ;; Rectangle selections, and overwrite text when the selection is active
  92. ;;----------------------------------------------------------------------------
  93. (cua-selection-mode t) ; for rectangles, CUA is nice
  94. ;;----------------------------------------------------------------------------
  95. ;; Handy key bindings
  96. ;;----------------------------------------------------------------------------
  97. ;; To be able to M-x without meta
  98. (global-set-key (kbd "C-x C-m") 'execute-extended-command)
  99. ;; Vimmy alternatives to M-^ and C-u M-^
  100. (global-set-key (kbd "C-c j") 'join-line)
  101. (global-set-key (kbd "C-c J") (lambda () (interactive) (join-line 1)))
  102. (global-set-key (kbd "C-.") 'set-mark-command)
  103. (global-set-key (kbd "C-x C-.") 'pop-global-mark)
  104. (require-package 'ace-jump-mode)
  105. (global-set-key (kbd "C-;") 'ace-jump-mode)
  106. (global-set-key (kbd "C-:") 'ace-jump-word-mode)
  107. (require-package 'multiple-cursors)
  108. ;; multiple-cursors
  109. (global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
  110. (global-set-key (kbd "C->") 'mc/mark-next-like-this)
  111. (global-set-key (kbd "C-+") 'mc/mark-next-like-this)
  112. (global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
  113. ;; From active region to multiple cursors:
  114. (global-set-key (kbd "C-c c r") 'set-rectangular-region-anchor)
  115. (global-set-key (kbd "C-c c c") 'mc/edit-lines)
  116. (global-set-key (kbd "C-c c e") 'mc/edit-ends-of-lines)
  117. (global-set-key (kbd "C-c c a") 'mc/edit-beginnings-of-lines)
  118. ;; Train myself to use M-f and M-b instead
  119. (global-unset-key [M-left])
  120. (global-unset-key [M-right])
  121. (defun kill-back-to-indentation ()
  122. "Kill from point back to the first non-whitespace character on the line."
  123. (interactive)
  124. (let ((prev-pos (point)))
  125. (back-to-indentation)
  126. (kill-region (point) prev-pos)))
  127. (global-set-key (kbd "C-M-<backspace>") 'kill-back-to-indentation)
  128. ;;----------------------------------------------------------------------------
  129. ;; Page break lines
  130. ;;----------------------------------------------------------------------------
  131. (require-package 'page-break-lines)
  132. (global-page-break-lines-mode)
  133. (diminish 'page-break-lines-mode)
  134. ;;----------------------------------------------------------------------------
  135. ;; Fill column indicator
  136. ;;----------------------------------------------------------------------------
  137. (when (eval-when-compile (> emacs-major-version 23))
  138. (require-package 'fill-column-indicator)
  139. (defun sanityinc/prog-mode-fci-settings ()
  140. (turn-on-fci-mode)
  141. (when show-trailing-whitespace
  142. (set (make-local-variable 'whitespace-style) '(face trailing))
  143. (whitespace-mode 1)))
  144. ;;(add-hook 'prog-mode-hook 'sanityinc/prog-mode-fci-settings)
  145. (defun sanityinc/fci-enabled-p ()
  146. (and (boundp 'fci-mode) fci-mode))
  147. (defvar sanityinc/fci-mode-suppressed nil)
  148. (defadvice popup-create (before suppress-fci-mode activate)
  149. "Suspend fci-mode while popups are visible"
  150. (let ((fci-enabled (sanityinc/fci-enabled-p)))
  151. (when fci-enabled
  152. (set (make-local-variable 'sanityinc/fci-mode-suppressed) fci-enabled)
  153. (turn-off-fci-mode))))
  154. (defadvice popup-delete (after restore-fci-mode activate)
  155. "Restore fci-mode when all popups have closed"
  156. (when (and sanityinc/fci-mode-suppressed
  157. (null popup-instances))
  158. (setq sanityinc/fci-mode-suppressed nil)
  159. (turn-on-fci-mode)))
  160. ;; Regenerate fci-mode line images after switching themes
  161. (defadvice enable-theme (after recompute-fci-face activate)
  162. (dolist (buffer (buffer-list))
  163. (with-current-buffer buffer
  164. (when (sanityinc/fci-enabled-p)
  165. (turn-on-fci-mode))))))
  166. ;;----------------------------------------------------------------------------
  167. ;; Shift lines up and down with M-up and M-down. When paredit is enabled,
  168. ;; it will use those keybindings. For this reason, you might prefer to
  169. ;; use M-S-up and M-S-down, which will work even in lisp modes.
  170. ;;----------------------------------------------------------------------------
  171. (require-package 'move-dup)
  172. (global-set-key [M-up] 'md/move-lines-up)
  173. (global-set-key [M-down] 'md/move-lines-down)
  174. (global-set-key [M-S-up] 'md/move-lines-up)
  175. (global-set-key [M-S-down] 'md/move-lines-down)
  176. (global-set-key (kbd "C-c p") 'md/duplicate-down)
  177. (global-set-key (kbd "C-c P") 'md/duplicate-up)
  178. ;;----------------------------------------------------------------------------
  179. ;; Fix backward-up-list to understand quotes, see http://bit.ly/h7mdIL
  180. ;;----------------------------------------------------------------------------
  181. (defun backward-up-sexp (arg)
  182. "Jump up to the start of the ARG'th enclosing sexp."
  183. (interactive "p")
  184. (let ((ppss (syntax-ppss)))
  185. (cond ((elt ppss 3)
  186. (goto-char (elt ppss 8))
  187. (backward-up-sexp (1- arg)))
  188. ((backward-up-list arg)))))
  189. (global-set-key [remap backward-up-list] 'backward-up-sexp) ; C-M-u, C-M-up
  190. ;;----------------------------------------------------------------------------
  191. ;; Cut/copy the current line if no region is active
  192. ;;----------------------------------------------------------------------------
  193. (require-package 'whole-line-or-region)
  194. (whole-line-or-region-mode t)
  195. (diminish 'whole-line-or-region-mode)
  196. (make-variable-buffer-local 'whole-line-or-region-mode)
  197. (defun suspend-mode-during-cua-rect-selection (mode-name)
  198. "Add an advice to suspend `MODE-NAME' while selecting a CUA rectangle."
  199. (let ((flagvar (intern (format "%s-was-active-before-cua-rectangle" mode-name)))
  200. (advice-name (intern (format "suspend-%s" mode-name))))
  201. (eval-after-load 'cua-rect
  202. `(progn
  203. (defvar ,flagvar nil)
  204. (make-variable-buffer-local ',flagvar)
  205. (defadvice cua--activate-rectangle (after ,advice-name activate)
  206. (setq ,flagvar (and (boundp ',mode-name) ,mode-name))
  207. (when ,flagvar
  208. (,mode-name 0)))
  209. (defadvice cua--deactivate-rectangle (after ,advice-name activate)
  210. (when ,flagvar
  211. (,mode-name 1)))))))
  212. (suspend-mode-during-cua-rect-selection 'whole-line-or-region-mode)
  213. (defun sanityinc/open-line-with-reindent (n)
  214. "A version of `open-line' which reindents the start and end positions.
  215. If there is a fill prefix and/or a `left-margin', insert them
  216. on the new line if the line would have been blank.
  217. With arg N, insert N newlines."
  218. (interactive "*p")
  219. (let* ((do-fill-prefix (and fill-prefix (bolp)))
  220. (do-left-margin (and (bolp) (> (current-left-margin) 0)))
  221. (loc (point-marker))
  222. ;; Don't expand an abbrev before point.
  223. (abbrev-mode nil))
  224. (delete-horizontal-space t)
  225. (newline n)
  226. (indent-according-to-mode)
  227. (when (eolp)
  228. (delete-horizontal-space t))
  229. (goto-char loc)
  230. (while (> n 0)
  231. (cond ((bolp)
  232. (if do-left-margin (indent-to (current-left-margin)))
  233. (if do-fill-prefix (insert-and-inherit fill-prefix))))
  234. (forward-line 1)
  235. (setq n (1- n)))
  236. (goto-char loc)
  237. (end-of-line)
  238. (indent-according-to-mode)))
  239. (global-set-key (kbd "C-o") 'sanityinc/open-line-with-reindent)
  240. ;;----------------------------------------------------------------------------
  241. ;; Random line sorting
  242. ;;----------------------------------------------------------------------------
  243. (defun sort-lines-random (beg end)
  244. "Sort lines in region randomly."
  245. (interactive "r")
  246. (save-excursion
  247. (save-restriction
  248. (narrow-to-region beg end)
  249. (goto-char (point-min))
  250. (let ;; To make `end-of-line' and etc. to ignore fields.
  251. ((inhibit-field-text-motion t))
  252. (sort-subr nil 'forward-line 'end-of-line nil nil
  253. (lambda (s1 s2) (eq (random 2) 0)))))))
  254. (require-package 'highlight-escape-sequences)
  255. (hes-mode)
  256. (require-package 'guide-key)
  257. (setq guide-key/guide-key-sequence '("C-x r" "C-x 4" "C-x 5" "C-c ;" "C-c ; f" "C-c ' f" "C-x n"))
  258. (guide-key-mode 1)
  259. (diminish 'guide-key-mode)
  260. (provide 'init-editing-utils)