117 lines
4.3 KiB
EmacsLisp
117 lines
4.3 KiB
EmacsLisp
;;; init-parens.el --- -*- lexical-binding: t -*-
|
|
;;
|
|
;; Filename: init-parens.el
|
|
;; Description: Initialize Parenthesis
|
|
;; Author: Mingde (Matthew) Zeng
|
|
;; Copyright (C) 2019 Mingde (Matthew) Zeng
|
|
;; Created: Fri Mar 15 10:17:13 2019 (-0400)
|
|
;; Version: 2.0.0
|
|
;; Last-Updated: Tue Dec 24 11:48:49 2019 (-0500)
|
|
;; By: Mingde (Matthew) Zeng
|
|
;; URL: https://github.com/MatthewZMD/.emacs.d
|
|
;; Keywords: M-EMACS .emacs.d parenthesis smartparens delete-block
|
|
;; Compatibility: emacs-version >= 26.1
|
|
;;
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;
|
|
;;; Commentary:
|
|
;;
|
|
;; This initializes parenthesis smartparens delete-block
|
|
;;
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;
|
|
;; This program is free software: you can redistribute it and/or modify
|
|
;; it under the terms of the GNU General Public License as published by
|
|
;; the Free Software Foundation, either version 3 of the License, or (at
|
|
;; your option) any later version.
|
|
;;
|
|
;; This program is distributed in the hope that it will be useful, but
|
|
;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
;; General Public License for more details.
|
|
;;
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
|
;;
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;
|
|
;;; Code:
|
|
|
|
(eval-when-compile
|
|
(require 'init-global-config))
|
|
|
|
;; SmartParensPac
|
|
(use-package smartparens
|
|
:hook (prog-mode . smartparens-mode)
|
|
:diminish smartparens-mode
|
|
:bind
|
|
(:map smartparens-mode-map
|
|
("C-M-f" . sp-forward-sexp)
|
|
("C-M-b" . sp-backward-sexp)
|
|
("C-M-a" . sp-backward-down-sexp)
|
|
("C-M-e" . sp-up-sexp)
|
|
("C-M-w" . sp-copy-sexp)
|
|
("C-M-k" . sp-change-enclosing)
|
|
("M-k" . sp-kill-sexp)
|
|
("C-M-<backspace>" . sp-splice-sexp-killing-backward)
|
|
("C-S-<backspace>" . sp-splice-sexp-killing-around)
|
|
("C-]" . sp-select-next-thing-exchange))
|
|
:custom
|
|
(sp-escape-quotes-after-insert nil)
|
|
:config
|
|
;; Stop pairing single quotes in elisp
|
|
(sp-local-pair 'emacs-lisp-mode "'" nil :actions nil)
|
|
(sp-local-pair 'org-mode "[" nil :actions nil)
|
|
;; Smartparens is broken in `cc-mode' as of Emacs 27. See
|
|
;; https://github.com/Fuco1/smartparens/issues/963
|
|
(unless (version< emacs-version "27")
|
|
(dolist (fun '(c-electric-paren c-electric-brace))
|
|
(add-to-list 'sp--special-self-insert-commands fun))))
|
|
;; -SmartParensPac
|
|
|
|
;; MatchParens
|
|
;; Show matching parenthesis
|
|
(show-paren-mode 1)
|
|
;; we will call `blink-matching-open` ourselves...
|
|
(remove-hook 'post-self-insert-hook
|
|
#'blink-paren-post-self-insert-function)
|
|
|
|
;; this still needs to be set for `blink-matching-open` to work
|
|
(setq blink-matching-paren 'show)
|
|
(let ((ov nil)) ; keep track of the overlay
|
|
(advice-add
|
|
#'show-paren-function
|
|
:after
|
|
(defun show-paren--off-screen+ (&rest _args)
|
|
"Display matching line for off-screen paren."
|
|
(when (overlayp ov)
|
|
(delete-overlay ov))
|
|
;; check if it's appropriate to show match info,
|
|
;; see `blink-paren-post-self-insert-function'
|
|
(when (and (overlay-buffer show-paren--overlay)
|
|
(not (or cursor-in-echo-area
|
|
executing-kbd-macro
|
|
noninteractive
|
|
(minibufferp)
|
|
this-command))
|
|
(and (not (bobp))
|
|
(memq (char-syntax (char-before)) '(?\) ?\$)))
|
|
(= 1 (logand 1 (- (point)
|
|
(save-excursion
|
|
(forward-char -1)
|
|
(skip-syntax-backward "/\\")
|
|
(point))))))
|
|
;; rebind `minibuffer-message' called by
|
|
;; `blink-matching-open' to handle the overlay display
|
|
(cl-letf (((symbol-function #'minibuffer-message)
|
|
(lambda (msg &rest args)
|
|
(let ((msg (apply #'format-message msg args)))
|
|
(setq ov (display-line-overlay+
|
|
(window-start) msg))))))
|
|
(blink-matching-open))))))
|
|
;; -MatchParens
|
|
|
|
(provide 'init-parens)
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;; init-parens.el ends here
|