This repository has been archived on 2022-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
emacs/modules/em-parentheses.el

126 lines
4.4 KiB
EmacsLisp
Raw Normal View History

2018-07-07 22:34:00 +02:00
;;; em-parentheses.el --- Module file for managing parentheses packages.
2017-08-28 16:33:56 +02:00
;;
;; Copyright (C) 2017 Wojciech Kozlowski
;;
2018-02-04 18:18:18 +01:00
;; Author: Wojciech Kozlowski <wk@wojciechkozlowski.eu>
2017-08-28 16:33:56 +02:00
;; Created: 28 Aug 2017
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;; This module sets up configuration for packages that manage parentheses in
;; code and text.
;;
;;; License: GPLv3
;;; Required packages:
2018-07-07 22:34:00 +02:00
;;; Code:
2017-08-28 16:33:56 +02:00
2018-07-07 22:34:00 +02:00
(defvar emodule/em-parentheses-packages
2017-08-28 16:33:56 +02:00
2018-07-07 22:34:00 +02:00
'(highlight-parentheses
rainbow-delimiters
smartparens)
)
2017-08-28 16:33:56 +02:00
;; Configuration:
2018-07-07 22:34:00 +02:00
(defun emodule/em-parentheses-init ()
"Initialise the `em-parentheses' module."
2017-08-28 16:33:56 +02:00
;; --------------------------------------------------------------------------
2017-09-02 09:16:56 +02:00
;; Highlight parentheses - this package does not use faces for colours,
;; instead it uses the `hl-parens-colors' variable. This can be set in the
;; theme file, but the mode has to be reloaded whenever the theme changes.
2017-08-28 16:33:56 +02:00
;; --------------------------------------------------------------------------
2017-09-02 09:16:56 +02:00
(use-package highlight-parentheses
2018-07-08 01:29:39 +02:00
:hook
(prog-mode . highlight-parentheses-mode))
2017-08-28 16:33:56 +02:00
;; --------------------------------------------------------------------------
2017-09-02 09:16:56 +02:00
;; Rainbow delimiters - colours are set by theme.
2017-08-28 16:33:56 +02:00
;; --------------------------------------------------------------------------
2017-09-02 09:16:56 +02:00
(use-package rainbow-delimiters
2018-07-08 01:29:39 +02:00
:hook
(prog-mode . rainbow-delimiters-mode))
2017-09-02 09:16:56 +02:00
;; --------------------------------------------------------------------------
;; Smartparens highlighting.
;; --------------------------------------------------------------------------
2017-08-28 16:33:56 +02:00
(use-package smartparens
2018-07-08 01:29:39 +02:00
:config
(smartparens-global-mode t)
(show-smartparens-global-mode t)
2018-07-08 01:29:39 +02:00
2017-08-28 16:33:56 +02:00
(require 'smartparens-config)
2018-07-07 22:34:00 +02:00
(declare-function sp-local-pair "smartparens")
(declare-function sp-beginning-of-sexp "smartparens")
2017-08-28 16:33:56 +02:00
;; Key-bindings -----------------------------------------------------------
(define-key smartparens-mode-map (kbd "C-M-f") 'sp-forward-sexp)
(define-key smartparens-mode-map (kbd "C-M-b") 'sp-backward-sexp)
2017-08-28 19:44:38 +02:00
(define-key smartparens-mode-map (kbd "C-M-u") 'sp-backward-up-sexp)
(define-key smartparens-mode-map (kbd "C-M-S-u") 'sp-up-sexp)
2017-08-28 16:33:56 +02:00
(define-key smartparens-mode-map (kbd "C-M-d") 'sp-down-sexp)
2017-08-28 19:44:38 +02:00
(define-key smartparens-mode-map (kbd "C-M-S-d") 'sp-backward-down-sexp)
(define-key smartparens-mode-map (kbd "C-S-a") 'sp-beginning-of-sexp)
(define-key smartparens-mode-map (kbd "C-S-e") 'sp-end-of-sexp)
2017-08-28 16:33:56 +02:00
(define-key smartparens-mode-map (kbd "C-M-t") 'sp-transpose-sexp)
(define-key smartparens-mode-map (kbd "C-M-n") 'sp-next-sexp)
(define-key smartparens-mode-map (kbd "C-M-p") 'sp-previous-sexp)
(define-key smartparens-mode-map (kbd "C-M-k") 'sp-kill-sexp)
(define-key smartparens-mode-map (kbd "C-M-w") 'sp-copy-sexp)
(define-key smartparens-mode-map (kbd "C-<right>") 'sp-forward-slurp-sexp)
(define-key smartparens-mode-map (kbd "C-<left>") 'sp-forward-barf-sexp)
2017-08-28 23:19:38 +02:00
(define-key smartparens-mode-map (kbd "M-D") 'sp-splice-sexp)
2017-08-28 19:44:38 +02:00
(define-key smartparens-mode-map (kbd "C-S-d") 'sp-splice-sexp-killing-forward)
2017-08-28 16:33:56 +02:00
(define-key smartparens-mode-map (kbd "C-M-<backspace>") 'sp-splice-sexp-killing-backward)
(define-key smartparens-mode-map (kbd "C-S-<backspace>") 'sp-splice-sexp-killing-around)
(define-key smartparens-mode-map (kbd "C-]") 'sp-select-next-thing-exchange)
(define-key smartparens-mode-map (kbd "C-M-]") 'sp-select-next-thing)
(define-key smartparens-mode-map (kbd "M-F") 'sp-forward-symbol)
(define-key smartparens-mode-map (kbd "M-B") 'sp-backward-symbol)
(define-key smartparens-mode-map (kbd "C-c f")
(lambda () (interactive) (sp-beginning-of-sexp 2)))
(define-key smartparens-mode-map (kbd "C-c b")
(lambda () (interactive) (sp-beginning-of-sexp -2)))
;; rst-mode
(sp-with-modes 'rst-mode
(sp-local-pair "`" nil :actions nil)
(sp-local-pair "``" "``"))
2017-09-02 09:16:56 +02:00
2017-08-28 16:33:56 +02:00
;; Smartparens custom settings --------------------------------------------
(setq-default
;; Jump to closing parenthesis when closing symbol is typed.
2017-08-28 23:19:38 +02:00
sp-autoskip-closing-pair t
2017-08-28 16:33:56 +02:00
;; Do not automatically reindent anything.
sp-navigate-reindent-after-up nil
sp-navigate-reindent-after-up-in-string nil
;; Do not highlight space between parentheses.
sp-highlight-pair-overlay nil))
)
2018-07-07 22:34:00 +02:00
(provide 'em-parentheses)
;;; em-parentheses.el ends here