Move things around to where more appropriate

This commit is contained in:
Wojciech Kozlowski 2017-08-28 19:21:48 +01:00
parent 494ac9260e
commit 09a339839b
4 changed files with 158 additions and 154 deletions

107
init.el
View File

@ -41,15 +41,6 @@
(menu-bar-mode -1)
(blink-cursor-mode -1)
;; Scrolling ----------------------------------------------------------------
(setq-default scroll-preserve-screen-position 1)
;; Line number --------------------------------------------------------------
(setq-default linum-format "%4d \u2502") ;; Line number format
(add-hook 'prog-mode-hook 'linum-mode) ;; Only in programming modes
;; Modeline -----------------------------------------------------------------
(size-indication-mode 1)
@ -116,8 +107,8 @@
;; *********************************************************************** ;;
;; ;;
;; ;;
;; Any further non-package specific configuration should be set below this ;;
;; point so that it does not get overridden by package configuration. ;;
;; Any configuration that is not in a module or needs to override module ;;
;; settings should be set below this point. ;;
;; ;;
;; ;;
;; ----------------------------------------------------------------------- ;;
@ -132,98 +123,4 @@
;; --------------------------------------------------------------------------
(load custom-file 'noerror)
;; --------------------------------------------------------------------------
;; Programming style.
;; --------------------------------------------------------------------------
(setq-default c-default-style "linux") ;; Default C style
;; --------------------------------------------------------------------------
;; Convenience functions.
;; --------------------------------------------------------------------------
(defun quit-other-window ()
"Quit the next window in cyclic order"
(interactive)
(quit-window t (next-window (selected-window))))
(defun kill-default-buffer ()
"Kill the currently active buffer with no confirmation."
(interactive)
(let (kill-buffer-query-functions) (kill-buffer)))
(defun refresh-non-face-colours ()
"Restart modes that use colours not set with face variables.
This has to be called whenever the active theme changes to
refresh these colours."
(when (and (fboundp 'fci-mode)
(fci-mode))
(fci-mode 1))
(when (and (fboundp 'highlight-parentheses-mode)
(highlight-parentheses-mode))
(highlight-parentheses-mode 1)))
;; --------------------------------------------------------------------------
;; Convenience keyboard shortcuts.
;; --------------------------------------------------------------------------
;; Kill current buffer without prompting.
(global-set-key (kbd "C-x k") 'kill-default-buffer)
;; Kill other window (cyclic order).
(global-set-key (kbd "C-x C-q") 'quit-other-window)
;; Change active window. More convenient than "C-x o".
(global-set-key (kbd "M-o") 'other-window)
;; Scroll up/down.
(global-set-key (kbd "C-<") (lambda() (interactive)
(let ((scroll-preserve-screen-position nil))
(scroll-down 1))))
(global-set-key (kbd "C->") (lambda() (interactive)
(let ((scroll-preserve-screen-position nil))
(scroll-up 1))))
;; Setup key-bindings for switching between themes.
(global-set-key (kbd "C-x t l") '(lambda () (interactive)
(load-theme 'havoc-light t)
(refresh-non-face-colours)))
(global-set-key (kbd "C-x t d") '(lambda () (interactive)
(load-theme 'havoc-dark t)
(refresh-non-face-colours)))
;; --------------------------------------------------------------------------
;; Aliases.
;; --------------------------------------------------------------------------
;; y or n is enough.
(defalias 'yes-or-no-p 'y-or-n-p)
;; Always use ibuffer.
(defalias 'list-buffers 'ibuffer)
;; --------------------------------------------------------------------------
;; Configure garbage collection.
;;
;; Based on advice from:
;; http://bling.github.io/blog/2016/01/18/why-are-you-changing-gc-cons-threshold/
;; --------------------------------------------------------------------------
(defun minibuffer-gc-setup-hook ()
(setq gc-cons-threshold most-positive-fixnum))
(defun minibuffer-gc-exit-hook ()
(setq gc-cons-threshold 800000))
(add-hook 'minibuffer-setup-hook #'minibuffer-gc-setup-hook)
(add-hook 'minibuffer-exit-hook #'minibuffer-gc-exit-hook)
;; --------------------------------------------------------------------------
;; Increase recursion limits.
;; --------------------------------------------------------------------------
(setq-default max-specpdl-size 20000) ;; ~15x original value
(setq-default max-lisp-eval-depth 24000) ;; 30x orignal value
) ;; Reset garbage collection settings.

View File

@ -53,7 +53,9 @@
(use-package fill-column-indicator
:defer t
:init (add-hook 'prog-mode-hook 'fci-mode))
:init
(add-hook 'prog-mode-hook 'fci-mode)
(add-hook 'text-mode-hook 'fci-mode))
;; --------------------------------------------------------------------------
;; Volatile highlights - highlight changes caused by undo, yank, etc.
@ -167,49 +169,6 @@
;; Override the indent-region key-binding
(global-set-key (kbd "C-M-\\") 'indent-region-or-buffer)
;; --------------------------------------------------------------------------
;; Automatically indent yanked text in programming mode.
;; --------------------------------------------------------------------------
(defvar yank-indent-modes
'(LaTeX-mode TeX-mode)
"Modes in which to indent regions that are yanked (or yank-popped).
Only modes that don't derive from `prog-mode' should be
listed here.")
(defvar yank-indent-blacklisted-modes
'(python-mode slim-mode haml-mode)
"Modes for which auto-indenting is suppressed.")
(defvar yank-advised-indent-threshold 10000
"Threshold (# chars) over which indentation does not
automatically occur.")
(defun yank-advised-indent-function (beg end)
"Do indentation, as long as the region isn't too large."
(if (<= (- end beg) yank-advised-indent-threshold)
(indent-region beg end nil)))
(defadvice yank (after yank-indent activate)
"If current mode is one of 'yank-indent-modes,
indent yanked text (with prefix arg don't indent)."
(if (and (not (ad-get-arg 0))
(not (member major-mode yank-indent-blacklisted-modes))
(or (derived-mode-p 'prog-mode)
(member major-mode yank-indent-modes)))
(let ((transient-mark-mode nil))
(yank-advised-indent-function (region-beginning) (region-end)))))
(defadvice yank-pop (after yank-pop-indent activate)
"If current mode is one of `yank-indent-modes',
indent yanked text (with prefix arg don't indent)."
(when (and (not (ad-get-arg 0))
(not (member major-mode yank-indent-blacklisted-modes))
(or (derived-mode-p 'prog-mode)
(member major-mode yank-indent-modes)))
(let ((transient-mark-mode nil))
(yank-advised-indent-function (region-beginning) (region-end)))))
;; --------------------------------------------------------------------------
;; Additional key-bindings.
;; --------------------------------------------------------------------------

View File

@ -1,4 +1,4 @@
;;; emacs.el --- Module file for Emacs management configuration.
;;; emacs.el --- Module file for configuring Emacs itself.
;;
;; Copyright (C) 2017 Wojciech Kozlowski
;;
@ -9,7 +9,7 @@
;;
;;; Commentary:
;;
;; This module sets up packages and configuration for managing Emacs.
;; This module is used for generic Emacs configuration.
;;
;;; License: GPLv3
@ -26,7 +26,99 @@
(defun init-packages/init-emacs ()
;; --------------------------------------------------------------------------
;; Empty config.
;; Keep point in same position on the screen when scrolling.
;; --------------------------------------------------------------------------
(setq-default scroll-preserve-screen-position 1)
;; --------------------------------------------------------------------------
;; Convenience functions.
;; --------------------------------------------------------------------------
(defun quit-other-window ()
"Quit the next window in cyclic order"
(interactive)
(quit-window t (next-window (selected-window))))
(defun kill-default-buffer ()
"Kill the currently active buffer with no confirmation."
(interactive)
(let (kill-buffer-query-functions) (kill-buffer)))
(defun refresh-non-face-colours ()
"Restart modes that use colours not set with face variables.
This has to be called whenever the active theme changes to
refresh these colours."
(when (and (fboundp 'fci-mode)
(fci-mode))
(fci-mode 1))
(when (and (fboundp 'highlight-parentheses-mode)
(highlight-parentheses-mode))
(highlight-parentheses-mode 1)))
;; Key-bindings -------------------------------------------------------------
;; Kill other window (cyclic order).
(global-set-key (kbd "C-x C-q") 'quit-other-window)
;; Kill current buffer without prompting.
(global-set-key (kbd "C-x k") 'kill-default-buffer)
;; --------------------------------------------------------------------------
;; Additional key-bindings.
;; --------------------------------------------------------------------------
;; Change active window. More convenient than "C-x o".
(global-set-key (kbd "M-o") 'other-window)
;; Scroll up/down, but keep point in place.
(global-set-key (kbd "C-<") (lambda() (interactive)
(let ((scroll-preserve-screen-position nil))
(scroll-down 1))))
(global-set-key (kbd "C->") (lambda() (interactive)
(let ((scroll-preserve-screen-position nil))
(scroll-up 1))))
;; Setup key-bindings for switching between themes.
(global-set-key (kbd "C-x t l") '(lambda () (interactive)
(load-theme 'havoc-light t)
(refresh-non-face-colours)))
(global-set-key (kbd "C-x t d") '(lambda () (interactive)
(load-theme 'havoc-dark t)
(refresh-non-face-colours)))
;; --------------------------------------------------------------------------
;; Aliases.
;; --------------------------------------------------------------------------
;; y or n is enough.
(defalias 'yes-or-no-p 'y-or-n-p)
;; Always use ibuffer.
(defalias 'list-buffers 'ibuffer)
;; --------------------------------------------------------------------------
;; Configure garbage collection.
;;
;; Based on advice from:
;; http://bling.github.io/blog/2016/01/18/why-are-you-changing-gc-cons-threshold/
;; --------------------------------------------------------------------------
(defun minibuffer-gc-setup-hook ()
(setq gc-cons-threshold most-positive-fixnum))
(defun minibuffer-gc-exit-hook ()
(setq gc-cons-threshold 800000))
(add-hook 'minibuffer-setup-hook #'minibuffer-gc-setup-hook)
(add-hook 'minibuffer-exit-hook #'minibuffer-gc-exit-hook)
;; --------------------------------------------------------------------------
;; Increase recursion limits.
;; --------------------------------------------------------------------------
(setq-default max-specpdl-size 20000) ;; ~15x original value
(setq-default max-lisp-eval-depth 24000) ;; 30x orignal value
)

View File

@ -3,7 +3,7 @@
;; Copyright (C) 2017 Wojciech Kozlowski
;;
;; Author: Wojciech Kozlowski <wojciech.kozlowski@vivaldi.net>
;; Created: 25 Aug 2017
;; Created: 28 Aug 2017
;;
;; This file is not part of GNU Emacs.
;;
@ -26,6 +26,19 @@
(defun init-packages/init-programming ()
;; --------------------------------------------------------------------------
;; Line numbers.
;; --------------------------------------------------------------------------
(setq-default linum-format "%4d \u2502") ;; Line number format
(add-hook 'prog-mode-hook 'linum-mode) ;; Only in programming modes
;; --------------------------------------------------------------------------
;; Formatting settings.
;; --------------------------------------------------------------------------
(setq-default c-default-style "linux")
;; --------------------------------------------------------------------------
;; Enable yasnippet.
;; --------------------------------------------------------------------------
@ -33,4 +46,47 @@
(use-package yasnippet)
(yas-global-mode 1)
)
;; --------------------------------------------------------------------------
;; Automatically indent yanked text in programming mode.
;; --------------------------------------------------------------------------
(defvar yank-indent-modes
'(LaTeX-mode TeX-mode)
"Modes in which to indent regions that are yanked (or yank-popped).
Only modes that don't derive from `prog-mode' should be
listed here.")
(defvar yank-indent-blacklisted-modes
'(python-mode slim-mode haml-mode)
"Modes for which auto-indenting is suppressed.")
(defvar yank-advised-indent-threshold 10000
"Threshold (# chars) over which indentation does not
automatically occur.")
(defun yank-advised-indent-function (beg end)
"Do indentation, as long as the region isn't too large."
(if (<= (- end beg) yank-advised-indent-threshold)
(indent-region beg end nil)))
(defadvice yank (after yank-indent activate)
"If current mode is one of 'yank-indent-modes,
indent yanked text (with prefix arg don't indent)."
(if (and (not (ad-get-arg 0))
(not (member major-mode yank-indent-blacklisted-modes))
(or (derived-mode-p 'prog-mode)
(member major-mode yank-indent-modes)))
(let ((transient-mark-mode nil))
(yank-advised-indent-function (region-beginning) (region-end)))))
(defadvice yank-pop (after yank-pop-indent activate)
"If current mode is one of `yank-indent-modes',
indent yanked text (with prefix arg don't indent)."
(when (and (not (ad-get-arg 0))
(not (member major-mode yank-indent-blacklisted-modes))
(or (derived-mode-p 'prog-mode)
(member major-mode yank-indent-modes)))
(let ((transient-mark-mode nil))
(yank-advised-indent-function (region-beginning) (region-end)))))
)