From 7cbaa82c48741e20a96106904e4cccc676723f47 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 7 Jul 2022 23:09:06 -0500 Subject: Add goto-matching-paren --- lisp/+emacs.el | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/lisp/+emacs.el b/lisp/+emacs.el index d6071a3..322e8a9 100644 --- a/lisp/+emacs.el +++ b/lisp/+emacs.el @@ -119,7 +119,7 @@ Do this only if the buffer is not visiting a file." sentence-end-double-space t set-mark-command-repeat-pop t show-paren-delay 0 - show-paren-style 'mixed + show-paren-style 'parenthesis show-paren-when-point-in-periphery t show-paren-when-point-inside-paren t ;;show-trailing-whitespace t @@ -286,7 +286,7 @@ ARG is passed to `backward-kill-word'." (interactive "P") (+backward-kill-word-wrapper #'backward-kill-word arg)) -;; ... and advice +;;; ... and advice ;; Indent the region after a yank. (defun +yank@indent (&rest _) @@ -302,23 +302,34 @@ ARG is passed to `backward-kill-word'." "Predicate for `save-some-buffers-default-predicate'. It returns nil with remote files." (not (file-remote-p (buffer-file-name)))) + +;; https://www.wwwtech.de/articles/2013/may/emacs:-jump-to-matching-paren-beginning-of-block +(defun +goto-matching-paren (&optional arg) + "Go to the matching paren, similar to vi's %." + (interactive "p") + (or arg (setq arg 1)) + (cond + ;; Check for "outside of bracket" positions + ((looking-at "[\[\(\{]") (forward-sexp arg)) + ((looking-back "[\]\)\}]" 1) (backward-sexp arg)) + ;; Otherwise, move from inside the bracket + ((looking-at "[\]\)\}]") (forward-char) (backward-sexp arg)) + ((looking-back "[\[\(\{]" 1) (backward-char) (forward-sexp arg)) + (t (up-list arg t t)))) + ;;; Bindings -;; I need to place these bindings under `+key-mode-map' so that they aren't -;; shadowed by other maps. There might be a better way to do this. -(require '+key) - -(dolist (binding '(("C-x C-c" . +save-buffers-quit) - ("M-SPC" . +cycle-spacing) - ("M-/" . hippie-expand) - ("M-=" . count-words) - ("C-x C-b" . ibuffer) - ("C-s" . isearch-forward-regexp) - ("C-r" . isearch-backward-regexp) - ("C-M-s" . isearch-forward) - ("C-M-r" . isearch-backward))) - (define-key (current-global-map) (kbd (car binding)) (cdr binding))) +(define-key (current-global-map) (kbd "C-x C-c") #'+save-buffers-quit) +(define-key (current-global-map) (kbd "M-SPC") #'+cycle-spacing) +(define-key (current-global-map) (kbd "M-/") #'hippie-expand) +(define-key (current-global-map) (kbd "M-=") #'count-words) +(define-key (current-global-map) (kbd "C-x C-b") #'ibuffer) +(define-key (current-global-map) (kbd "C-s") #'isearch-forward-regexp) +(define-key (current-global-map) (kbd "C-r") #'isearch-backward-regexp) +(define-key (current-global-map) (kbd "C-M-s") #'isearch-forward) +(define-key (current-global-map) (kbd "C-M-r") #'isearch-backward) +(define-key (current-global-map) (kbd "C-M--") #'+goto-matching-paren) ;;; Required libraries -- cgit 1.4.1-21-gabe81