diff options
author | Vincent Ambo <mail@tazj.in> | 2020-06-16T00·06+0100 |
---|---|---|
committer | Vincent Ambo <mail@tazj.in> | 2020-06-16T00·06+0100 |
commit | 4fe4e3d9a297ff9c8aa77e1a196a96b65ecd99ae (patch) | |
tree | 54455b0cd36e58fd745ce0b6d38101b7a902ce4b /users/glittershark/emacs.d/show-matching-paren.el | |
parent | 2edb963b97867b27f68efac8d05bf966077b0b01 (diff) | |
parent | 69ee53bffaf145eb86dd39a6cdc0ae4d9d3de45c (diff) |
Add 'users/glittershark/emacs.d/' from commit '69ee53bffaf145eb86dd39a6cdc0ae4d9d3de45c' r/979
git-subtree-dir: users/glittershark/emacs.d git-subtree-mainline: 2edb963b97867b27f68efac8d05bf966077b0b01 git-subtree-split: 69ee53bffaf145eb86dd39a6cdc0ae4d9d3de45c
Diffstat (limited to 'users/glittershark/emacs.d/show-matching-paren.el')
-rw-r--r-- | users/glittershark/emacs.d/show-matching-paren.el | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/users/glittershark/emacs.d/show-matching-paren.el b/users/glittershark/emacs.d/show-matching-paren.el new file mode 100644 index 000000000000..d10751a63f94 --- /dev/null +++ b/users/glittershark/emacs.d/show-matching-paren.el @@ -0,0 +1,61 @@ +;;; ~/.doom.d/show-matching-paren.el -*- lexical-binding: t; -*- + +;;; https://with-emacs.com/posts/ui-hacks/show-matching-lines-when-parentheses-go-off-screen/ + +;; 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)))))) + +(defun display-line-overlay+ (pos str &optional face) + "Display line at POS as STR with FACE. + +FACE defaults to inheriting from default and highlight." + (let ((ol (save-excursion + (goto-char pos) + (make-overlay (line-beginning-position) + (line-end-position))))) + (overlay-put ol 'display str) + (overlay-put ol 'face + (or face '(:inherit default :inherit highlight))) + ol)) + +(setq show-paren-style 'paren + show-paren-delay 0.03 + show-paren-highlight-openparen t + show-paren-when-point-inside-paren nil + show-paren-when-point-in-periphery t) +(show-paren-mode 1) |