2017-08-25 22:37:01 +01:00
|
|
|
;;; editing.el --- Module file for editing configuration.
|
|
|
|
;;
|
|
|
|
;; Copyright (C) 2017 Wojciech Kozlowski
|
|
|
|
;;
|
2018-02-04 17:18:18 +00:00
|
|
|
;; Author: Wojciech Kozlowski <wk@wojciechkozlowski.eu>
|
2017-08-25 22:37:01 +01:00
|
|
|
;; Created: 25 Aug 2017
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
|
|
|
;; This module sets up packages and configuration for editing text and code.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
|
|
|
;;; Required packages:
|
|
|
|
|
2017-09-02 13:45:42 +01:00
|
|
|
(setq emodule/editing-packages
|
2017-08-27 11:52:04 +01:00
|
|
|
|
2017-08-28 22:48:11 +01:00
|
|
|
'(duplicate-thing
|
2017-08-27 23:09:18 +01:00
|
|
|
expand-region
|
2017-08-28 18:44:56 +01:00
|
|
|
fill-column-indicator
|
2017-08-28 22:19:38 +01:00
|
|
|
undo-tree
|
2017-08-28 22:48:11 +01:00
|
|
|
volatile-highlights
|
|
|
|
whole-line-or-region
|
2017-08-28 22:19:38 +01:00
|
|
|
ws-butler)
|
2017-08-27 11:52:04 +01:00
|
|
|
|
|
|
|
)
|
2017-08-25 22:37:01 +01:00
|
|
|
|
|
|
|
;; Configuration:
|
|
|
|
|
2017-09-02 13:45:42 +01:00
|
|
|
(defun emodule/editing-init ()
|
2017-08-27 11:52:04 +01:00
|
|
|
|
2017-08-27 17:22:00 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Duplicate things.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(use-package duplicate-thing
|
|
|
|
:defer t
|
2017-08-27 22:14:10 +01:00
|
|
|
:bind (("M-C" . duplicate-thing)))
|
|
|
|
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Expand region - intelligent select.
|
|
|
|
;; --------------------------------------------------------------------------
|
2017-08-28 15:33:56 +01:00
|
|
|
|
2017-08-27 22:14:10 +01:00
|
|
|
(use-package expand-region
|
|
|
|
:defer t
|
|
|
|
:bind (("C-'" . er/expand-region)))
|
2017-08-27 17:22:00 +01:00
|
|
|
|
2017-08-27 23:09:18 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Column indicator.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(use-package fill-column-indicator
|
|
|
|
:defer t
|
2017-09-02 08:02:53 +01:00
|
|
|
:bind
|
|
|
|
(("C-x t f" . fci-mode))
|
2017-08-28 19:21:48 +01:00
|
|
|
:init
|
2017-09-02 08:16:56 +01:00
|
|
|
;; (defun fci-mode-unless-large-file ()
|
|
|
|
;; "Enable fci-mode unless the file is too large."
|
|
|
|
;; (interactive)
|
|
|
|
;; (unless (> (count-lines (point-min) (point-max)) 9999)
|
|
|
|
;; (fci-mode)))
|
|
|
|
|
2017-09-02 08:02:53 +01:00
|
|
|
;; (add-hook 'prog-mode-hook 'fci-mode-unless-large-file)
|
|
|
|
;; (add-hook 'text-mode-hook 'fci-mode-unless-large-file)
|
|
|
|
)
|
2017-08-27 23:09:18 +01:00
|
|
|
|
2017-08-28 22:48:11 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Undo tree. To undo "C-\", to redo "C-_", undo tree "C-x u".
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(use-package undo-tree
|
|
|
|
:init
|
|
|
|
(global-undo-tree-mode))
|
|
|
|
|
2017-08-27 17:22:00 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Volatile highlights - highlight changes caused by undo, yank, etc.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
2017-08-28 22:17:11 +01:00
|
|
|
(use-package volatile-highlights
|
|
|
|
:init
|
|
|
|
(volatile-highlights-mode t))
|
2017-08-27 17:22:00 +01:00
|
|
|
|
2017-08-28 18:44:56 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
2017-08-28 22:48:11 +01:00
|
|
|
;; Kill line when calling kill-region without a selected region.
|
2017-08-28 18:44:56 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
2017-08-28 22:48:11 +01:00
|
|
|
(use-package whole-line-or-region
|
2017-08-28 22:17:11 +01:00
|
|
|
:init
|
2017-08-28 22:48:11 +01:00
|
|
|
(whole-line-or-region-global-mode t))
|
2017-08-28 18:44:56 +01:00
|
|
|
|
2017-08-27 11:52:04 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
2017-08-28 22:48:11 +01:00
|
|
|
;; `ws-butler' will cleanup whitespace on all modified files on save.
|
2017-08-27 11:52:04 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
2017-08-28 22:48:11 +01:00
|
|
|
|
|
|
|
(use-package ws-butler
|
|
|
|
:init
|
|
|
|
(ws-butler-global-mode))
|
2017-08-27 11:52:04 +01:00
|
|
|
|
|
|
|
;; --------------------------------------------------------------------------
|
2017-08-28 22:48:11 +01:00
|
|
|
;; Non-package related editing settings.
|
2017-08-27 11:52:04 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; Kill whole line when point at beginning of line.
|
2017-08-28 15:33:56 +01:00
|
|
|
(setq-default kill-whole-line t)
|
2017-08-27 11:52:04 +01:00
|
|
|
|
|
|
|
;; Replace selected rather than inserting text at point.
|
|
|
|
(delete-selection-mode)
|
|
|
|
|
2017-08-28 22:48:11 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Use UTF-8.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
(set-terminal-coding-system 'utf-8)
|
|
|
|
(set-keyboard-coding-system 'utf-8)
|
|
|
|
(set-language-environment "UTF-8")
|
|
|
|
(prefer-coding-system 'utf-8)
|
2017-08-28 22:19:38 +01:00
|
|
|
|
2017-08-27 11:52:04 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Formatting
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
2017-08-28 18:44:56 +01:00
|
|
|
(setq-default
|
|
|
|
;; Indentation size - applies even when indent-tabs-mode is nil.
|
|
|
|
tab-width 8
|
|
|
|
;; Do not use tab characters for indentation.
|
|
|
|
indent-tabs-mode nil
|
|
|
|
;; Standard fill-column width - last character is for end of line glyph.
|
|
|
|
fill-column 79
|
|
|
|
;; Highlight lines that are too long in whitespace mode.
|
|
|
|
whitespace-line-column fill-column)
|
2017-08-27 11:52:04 +01:00
|
|
|
|
2017-08-28 22:19:38 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Completion help.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; hippie-expand is a better version of dabbrev-expand.
|
|
|
|
(global-set-key (kbd "M-/") 'hippie-expand)
|
|
|
|
|
|
|
|
(setq-default
|
|
|
|
hippie-expand-try-functions-list
|
|
|
|
'(try-expand-dabbrev ;; Search current buffer.
|
|
|
|
try-expand-dabbrev-all-buffers ;; Search all other buffers.
|
|
|
|
try-expand-dabbrev-from-kill ;; Search the kill ring.
|
|
|
|
try-complete-file-name-partially ;; Complete text partially as file name.
|
|
|
|
try-complete-file-name ;; Complete text as file name.
|
|
|
|
try-expand-all-abbrevs ;; Expand according to all abbrev tables.
|
|
|
|
try-expand-list ;; Complete the current list to a list in the buffer.
|
|
|
|
try-expand-line ;; Complete the current line to a line in the buffer.
|
|
|
|
try-complete-lisp-symbol-partially ;; Complete partially as Elisp symbol.
|
|
|
|
try-complete-lisp-symbol) ;; Complete as Elisp symbol.
|
|
|
|
)
|
|
|
|
|
2017-08-30 01:13:52 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Check spelling.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(use-package flyspell
|
|
|
|
:init
|
|
|
|
(add-hook 'text-mode-hook 'flyspell-mode)
|
|
|
|
(add-hook 'org-mode-hook 'flyspell-mode)
|
|
|
|
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
|
|
|
|
:config
|
|
|
|
(if (executable-find "aspell")
|
|
|
|
(progn
|
|
|
|
(setq-default ispell-program-name "aspell")
|
|
|
|
(setq-default ispell-extra-args '("--sug-mode=ultra")))
|
|
|
|
(setq-default ispell-program-name "ispell")))
|
|
|
|
|
2017-08-27 11:52:04 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Commands.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(defun toggle-indent-tabs-mode ()
|
|
|
|
"Toggle a indent-tabs-mode between a defined and undefined state."
|
|
|
|
(interactive)
|
|
|
|
(setq indent-tabs-mode (not indent-tabs-mode))
|
|
|
|
(setq-default indent-tabs-mode indent-tabs-mode))
|
|
|
|
|
|
|
|
(defun x-move-beginning-of-line (arg)
|
|
|
|
"Move point back to indentation of beginning of line.
|
|
|
|
|
|
|
|
Move point to the first non-whitespace character on this
|
|
|
|
line. If point is already there, move to the beginning of
|
|
|
|
the line. Effectively toggle between the first
|
|
|
|
non-whitespace character and the beginning of the line.
|
|
|
|
|
|
|
|
If ARG is not nil or 1, move forward ARG - 1 lines first. If
|
|
|
|
point reaches the beginning or end of the buffer, stop
|
|
|
|
there."
|
|
|
|
|
|
|
|
(interactive "^p")
|
|
|
|
(setq arg (or arg 1))
|
|
|
|
|
|
|
|
;; Move lines first
|
|
|
|
(when (/= arg 1)
|
|
|
|
(let ((line-move-visual nil))
|
|
|
|
(forward-line (1- arg))))
|
|
|
|
|
|
|
|
(let ((orig-point (point)))
|
|
|
|
(back-to-indentation)
|
|
|
|
(when (= orig-point (point))
|
|
|
|
(move-beginning-of-line 1))))
|
|
|
|
|
|
|
|
(defun indent-buffer ()
|
|
|
|
"Indent the currently visited buffer."
|
|
|
|
(interactive)
|
|
|
|
(indent-region (point-min) (point-max)))
|
|
|
|
|
|
|
|
(defcustom indent-sensitive-modes
|
|
|
|
'(coffee-mode python-mode slim-mode haml-mode yaml-mode)
|
|
|
|
"Modes for which auto-indenting is suppressed."
|
|
|
|
:type 'list)
|
|
|
|
|
|
|
|
(defun indent-region-or-buffer ()
|
|
|
|
"Indent a region if selected, otherwise the whole buffer."
|
|
|
|
(interactive)
|
|
|
|
(unless (member major-mode indent-sensitive-modes)
|
|
|
|
(save-excursion
|
|
|
|
(if (region-active-p)
|
|
|
|
(indent-region (region-beginning) (region-end))
|
|
|
|
(indent-buffer)
|
|
|
|
(whitespace-cleanup)))))
|
|
|
|
|
|
|
|
;; Key-bindings -------------------------------------------------------------
|
|
|
|
|
|
|
|
;; Override the beginning of line key-binding.
|
|
|
|
(global-set-key (kbd "C-a") 'x-move-beginning-of-line)
|
|
|
|
|
|
|
|
;; Override the indent-region key-binding
|
|
|
|
(global-set-key (kbd "C-M-\\") 'indent-region-or-buffer)
|
|
|
|
|
2017-08-27 17:22:00 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
2017-08-28 18:44:56 +01:00
|
|
|
;; Additional key-bindings.
|
2017-08-27 17:22:00 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
;; Toggle whitespace mode.
|
|
|
|
(global-set-key (kbd "C-c w") 'whitespace-mode)
|
|
|
|
|
2017-08-27 20:39:11 +01:00
|
|
|
;; Occur. More convenient than "M-s o"
|
|
|
|
(global-set-key (kbd "M-s M-o") 'occur)
|
|
|
|
|
2017-08-27 11:52:04 +01:00
|
|
|
)
|