PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/emacs/init-10-base.el

https://github.com/Schnouki/dotfiles
Emacs Lisp | 276 lines | 153 code | 51 blank | 72 comment | 3 complexity | 55d4ce919818c5703165080100e45f74 MD5 | raw file
  1. ;;; 10-base --- Basic settings
  2. ;;; Commentary:
  3. ;;; Code:
  4. ;; Tweak the GC threshold.
  5. ;; The default value is 800000, set it to something higher once the startup is
  6. ;; complete. And set it to something even higher in the minibuffer (for ido and
  7. ;; other complex features)
  8. (setq schnouki/gc-threshold 2000000
  9. schnouki/gc-threshold-minibuffer 10000000)
  10. (defun schnouki/set-normal-gc-threshold ()
  11. (setq gc-cons-threshold schnouki/gc-threshold))
  12. (defun schnouki/set-minibuffer-gc-threshold ()
  13. (setq gc-cons-threshold schnouki/gc-threshold-minibuffer))
  14. (add-hook 'after-init-hook #'schnouki/set-normal-gc-threshold)
  15. (add-hook 'minibuffer-setup-hook #'schnouki/set-minibuffer-gc-threshold)
  16. (add-hook 'minibuffer-exit-hook #'schnouki/set-normal-gc-threshold)
  17. (setq gc-cons-threshold most-positive-fixnum)
  18. ;; Paths
  19. (add-to-list 'load-path "~/.config/emacs")
  20. ;; Fix for tramp "recursive load"
  21. ;; (http://lists.gnu.org/archive/html/help-gnu-emacs/2011-05/msg00064.html)
  22. (when (< emacs-major-version 24)
  23. (load "/usr/share/emacs/23.3/lisp/net/tramp.el.gz"))
  24. ;; Custom file
  25. (setq custom-file "~/.config/emacs/init-00-custom.el")
  26. ;; Keep all backup files in a single directory
  27. (setq backup-directory-alist '(("." . "~/.emacs-backup-files/")))
  28. ;; Web browser
  29. (setq browse-url-browser-function 'browse-url-firefox ;chromium
  30. browse-url-firefox-program "firefox"
  31. browse-url-firefox-new-window-is-tab t)
  32. ;; Display date and time
  33. (require 'time)
  34. (display-time)
  35. (setq display-time-24hr-format t)
  36. ;; Display line and colon number
  37. (column-number-mode t)
  38. (line-number-mode t)
  39. ;; No menu bar, tool bar, scroll bar
  40. (menu-bar-mode 0)
  41. (tool-bar-mode 0)
  42. (scroll-bar-mode 0)
  43. ;; No internal border
  44. (add-to-list 'default-frame-alist '(internal-border . 0))
  45. ;; Focus follows mouse
  46. ;(setq mouse-autoselect-window t)
  47. ;; No beep, but flash screen
  48. (setq visible-bell t)
  49. ;; Move point to top/bottom of buffer before signalling a scrolling error
  50. (setq scroll-error-top-bottom t)
  51. ;; Display file name in the window title bar
  52. (setq frame-title-format '(buffer-file-name "%b [%f]" "%b"))
  53. ;; Answer "y" rather than "yes"
  54. (defalias 'yes-or-no-p 'y-or-n-p)
  55. (defmacro with-yes-or-no (answer &rest body)
  56. "Ensure that `yes-or-no-p' and `y-or-n-p' will always return ANSWER while running BODY."
  57. ;; Based on https://www.emacswiki.org/emacs/YesOrNoP#toc2
  58. (declare (indent defun) (debug (body)))
  59. `(cl-letf (((symbol-function 'y-or-n-p) (lambda (&rest args) ,answer))
  60. ((symbol-function 'yes-or-no-p) (lambda (&rest args) ,answer)))
  61. ,@body))
  62. ;; Helper to add things in "default" lists (for buffer-local variables)
  63. (defun add-to-default-list (list-var element)
  64. "Add ELEMENT to the default value of LIST-VAR if it isn't there yet."
  65. (let ((current-list (default-value list-var)))
  66. (if (memq element current-list)
  67. current-list
  68. (setq-default list-var (cons element current-list)))))
  69. ;; Use "initials" completion style
  70. (add-to-list 'completion-styles 'initials t)
  71. ;; Avoid sentences that end with 2 spaces (American style).
  72. ;; TODO: change this automatically according to the current dictionary
  73. (setq sentence-end-double-space nil)
  74. ;; Avoid breaking lines at '(' or ':' characters
  75. (add-hook 'fill-no-break-predicate 'fill-french-nobreak-p)
  76. ;; Justify at 80 columns
  77. (setq-default fill-column 80)
  78. ;; Display matching parenthesis
  79. ;; http://emacs-fu.blogspot.com/2009/01/balancing-your-parentheses.html
  80. (require 'paren)
  81. (show-paren-mode t)
  82. (setq show-paren-style 'expression)
  83. ;; Show the matching parenthseis when it is offscreen
  84. ;; http://www.emacswiki.org/emacs/ShowParenMode#toc1
  85. (defun schnouki/show-matching-paren-offscreen ()
  86. "If the matching paren is offscreen, show the matching line in the echo area.
  87. Has no effect if the character before point is not of the syntax class ')'."
  88. (let* ((cb (char-before (point)))
  89. (matching-text (and cb
  90. (char-equal (char-syntax cb) ?\) )
  91. (blink-matching-open))))
  92. (when matching-text (message matching-text))))
  93. (advice-add 'show-paren-function :after #'schnouki/show-matching-paren-offscreen)
  94. ;; Highlight current line
  95. ;; http://www.emacsblog.org/2007/04/09/highlight-the-current-line/
  96. (global-hl-line-mode 1)
  97. ;; Case-insensitive search
  98. (setq case-fold-search t)
  99. ;; Better selection behaviour
  100. (if (< emacs-major-version 24)
  101. (pc-selection-mode 1)
  102. (progn
  103. (delete-selection-mode 1)
  104. (setq x-select-enable-clipboard t
  105. x-select-enable-primary t)))
  106. ;; Highlight current region
  107. (transient-mark-mode t)
  108. ;; Active region becomes the window selection
  109. (setq select-active-regions t)
  110. ;; Save whatever’s in the current (system) clipboard before
  111. ;; replacing it with the Emacs’ text.
  112. ;; https://github.com/dakrone/eos/blob/master/eos.org
  113. ;; http://pragmaticemacs.com/emacs/add-the-system-clipboard-to-the-emacs-kill-ring/
  114. (setq save-interprogram-paste-before-kill t)
  115. ;; ediff window setup
  116. ;; - don't open a new frame for the control buffer
  117. ;; - split horizontally if the current frame is wide enough
  118. (require 'ediff)
  119. (setq ediff-window-setup-function 'ediff-setup-windows-plain
  120. ediff-split-window-function (lambda (&optional arg)
  121. (if (> (frame-width) 150)
  122. (split-window-horizontally arg)
  123. (split-window-vertically arg))))
  124. ;; - restore window configuration when quitting ediff
  125. (defvar ediff-saved-window-configuration nil)
  126. (add-hook 'ediff-load-hook
  127. (lambda ()
  128. (add-hook 'ediff-before-setup-hook
  129. (lambda ()
  130. (setq ediff-saved-window-configuration (current-window-configuration))))
  131. (let ((restore-window-configuration
  132. (lambda ()
  133. (set-window-configuration ediff-saved-window-configuration))))
  134. (add-hook 'ediff-quit-hook restore-window-configuration 'append)
  135. (add-hook 'ediff-suspend-hook restore-window-configuration 'append))))
  136. ;; Remember the last visited line in a file
  137. (require 'saveplace)
  138. (setq save-place-file "~/.config/emacs/places")
  139. (save-place-mode t)
  140. ;; Save opened files and other stuff
  141. ;; http://www.xsteve.at/prg/emacs/power-user-tips.html
  142. (require 'desktop)
  143. (setq desktop-save t
  144. desktop-load-locked-desktop t
  145. desktop-restore-frames nil
  146. desktop-restore-eager nil
  147. desktop-path '("~/.config/emacs"))
  148. (with-eval-after-load 'dash
  149. (setq desktop-modes-not-to-save (-union desktop-modes-not-to-save
  150. '(prog-mode))))
  151. (defvar schnouki/desktop-was-read nil)
  152. (defun schnouki/desktop-after-read-hook ()
  153. (setq schnouki/desktop-was-read t))
  154. (add-hook 'desktop-after-read-hook #'schnouki/desktop-after-read-hook)
  155. (desktop-save-mode 1)
  156. (setq desktop-globals-to-save
  157. (append '((extended-command-history . 30)
  158. (file-name-history . 100)
  159. (grep-history . 30)
  160. (compile-history . 30)
  161. (minibuffer-history . 50)
  162. (query-replace-history . 60)
  163. (read-expression-history . 60)
  164. (regexp-history . 60)
  165. (regexp-search-ring . 20)
  166. (search-ring . 20)
  167. (shell-command-history . 50)
  168. tags-file-name
  169. register-alist)))
  170. ;; http://www.emacswiki.org/emacs/DeskTop
  171. (add-hook 'auto-save-hook 'desktop-save-in-desktop-dir)
  172. ;; Abort the minibuffer when using the mouse
  173. ;; http://trey-jackson.blogspot.com/2010/04/emacs-tip-36-abort-minibuffer-when.html
  174. (defun stop-using-minibuffer ()
  175. "Kill the minibuffer."
  176. (when (>= (recursion-depth) 1)
  177. (abort-recursive-edit)))
  178. (add-hook 'mouse-leave-buffer-hook 'stop-using-minibuffer)
  179. ;; Don't ask if I want to kill a buffer with a live process attached to it
  180. ;; http://www.masteringemacs.org/articles/2010/11/14/disabling-prompts-emacs/
  181. (setq kill-buffer-query-functions
  182. (remq 'process-kill-buffer-query-function
  183. kill-buffer-query-functions))
  184. ;; Automagically make scripts executable
  185. ;; http://www.masteringemacs.org/articles/2011/01/19/script-files-executable-automatically/
  186. (defvar schnouki/no-script nil)
  187. (defun schnouki/maybe-make-executable-if-script-p ()
  188. "Automagically make scripts executable."
  189. (let ((name (buffer-file-name)))
  190. (unless (cl-some #'(lambda (dir) (string-prefix-p (expand-file-name dir) name))
  191. schnouki/no-script)
  192. (executable-make-buffer-file-executable-if-script-p))))
  193. (add-hook 'after-save-hook 'schnouki/maybe-make-executable-if-script-p)
  194. ;; Wait a very little bit before fontifying buffers
  195. ;; http://tsengf.blogspot.fr/2012/11/slow-scrolling-speed-in-emacs.html
  196. ;(setq jit-lock-defer-time 0.05)
  197. ;; Better naming than main.yml<2>, main.yml<3>, main.yml<4>
  198. (require 'uniquify)
  199. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  200. ;; Move through camelCaseWords and other_long_words
  201. (global-subword-mode 1)
  202. ;; Enable "confusing" commands
  203. (dolist (feat '(downcase-region upcase-region))
  204. (put feat 'disabled nil))
  205. ;; Prefer vertical splits
  206. (defun schnouki/split-window-more-sensibly (&optional window)
  207. (let ((window (or window (selected-window))))
  208. (or (and (window-splittable-p window t)
  209. ;; Split window horizontally.
  210. (with-selected-window window
  211. (split-window-right)))
  212. (and (window-splittable-p window)
  213. ;; Split window vertically.
  214. (with-selected-window window
  215. (split-window-below)))
  216. (split-window-sensibly window))))
  217. (setq split-window-preferred-function 'schnouki/split-window-more-sensibly
  218. split-width-threshold 120
  219. split-height-threshold 100
  220. window-combination-resize t)
  221. ;; (message "Window size: %sx%s" (window-total-width) (window-total-height))
  222. ;; Local Variables:
  223. ;; byte-compile-warnings: (not cl-functions)
  224. ;; End:
  225. ;;; init-10-base.el ends here