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/parentheses.el

120 lines
4.2 KiB
EmacsLisp
Raw Normal View History

2017-08-28 16:33:56 +02:00
;;; parentheses.el --- Module file for managing parentheses packages.
;;
;; Copyright (C) 2017 Wojciech Kozlowski
;;
;; Author: Wojciech Kozlowski <wojciech.kozlowski@vivaldi.net>
;; 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:
2017-09-02 14:45:42 +02:00
(setq emodule/parentheses-packages
2017-08-28 16:33:56 +02:00
2017-09-02 09:16:56 +02:00
'(highlight-parentheses
rainbow-delimiters
2017-08-28 16:33:56 +02:00
smartparens)
)
;; Configuration:
2017-09-02 14:45:42 +02:00
(defun emodule/parentheses-init ()
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
2017-08-28 16:33:56 +02:00
:defer t
:init
2017-09-02 09:16:56 +02:00
(add-hook 'prog-mode-hook '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
2017-08-28 16:33:56 +02:00
:defer t
:init
2017-09-02 09:16:56 +02:00
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode))
;; --------------------------------------------------------------------------
;; Smartparens highlighting.
;; --------------------------------------------------------------------------
2017-08-28 16:33:56 +02:00
(use-package smartparens
:init
(smartparens-global-mode t)
(show-smartparens-global-mode t)
2017-08-28 16:33:56 +02:00
:config
(require 'smartparens-config)
;; 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))
)