smartparens
smartparens copied to clipboard
I found a way to combine `eldoc-mode' and `show-smartparens-mode' well in minibuffer.
I submit this issue to hope author would not reconstruct the features I use so I could save my time, and to help other people who want to see current match while eldoc-mode override the message.
Feel free to share it anywhere.
;; -*- lexical-binding: t -*-
(let (match-message position-changed)
(advice-add 'sp-show--pair-echo-match :filter-args
(lambda (match-positions)
(setq position-changed
(not (and (equal sp-show-pair-previous-point (point))
(equal sp-show-pair-previous-match-positions
match-positions))))
match-positions))
(advice-add 'sp-show--pair-echo-match :filter-return
(lambda (message)
(when position-changed (setq match-message message))))
(advice-add 'sp-show--pair-delete-overlays :before
(lambda (&rest _rest) (setq match-message nil)))
(advice-add 'eldoc-minibuffer-message :filter-args
(lambda (args)
(if (or (not (stringp match-message))
(string-blank-p match-message)
(minibufferp))
args
(let ((format (car args)) (rest (cdr args)))
(if (string-blank-p (apply 'message format rest))
`(,match-message)
(cons (concat match-message " | " format) rest)))))))
Really cool! Do you think we could maybe integrate this into the package itself? Maybe it could automatically detect you have eldoc active and then enable the advices.
Of course you can. And you can even do better. Firstly you should have better understanding about the situation show-smartparens-mode will show something in minibuffer. Then you can even give user the choose about the content to display when both eldoc-mode and show-smartparens-mode want to occupy the minibuffer. My window-width is long enough so I want to display them all but some people may just want to see one of them.
Notice that eldoc-mode often shows a blank string in minibuffer, so string-blank-p should be used to check if eldoc-mode has some messages to show actually.