diff options
| author | Tassilo Horn | 2022-02-08 21:54:56 +0100 |
|---|---|---|
| committer | Tassilo Horn | 2022-02-08 21:54:56 +0100 |
| commit | 2755e6bba0f9dbb4030f51ea3bc258ee23bb41c5 (patch) | |
| tree | 58eadcf6e9080e13f61de579e9488f221644b32c | |
| parent | f7d16d93fded6ccdfef3c537c1841b7322010f12 (diff) | |
| download | emacs-2755e6bba0f9dbb4030f51ea3bc258ee23bb41c5.tar.gz emacs-2755e6bba0f9dbb4030f51ea3bc258ee23bb41c5.zip | |
Allow showing show-paren context in an overlay
* lisp/paren.el (show-paren-context-when-offscreen): Add new
possibility `overlay'.
(show-paren--context-overlay): New defvar.
(show-paren--delete-context-overlay): New function.
(show-paren--show-context-in-overlay): New function.
(show-paren-function): Handle the new `overlay' case.
* lisp/emacs-lisp/eldoc.el (eldoc-display-message-no-interference-p):
There's no interference if `show-paren-context-when-offscreen' is
overlay or child-frame.
| -rw-r--r-- | lisp/emacs-lisp/eldoc.el | 4 | ||||
| -rw-r--r-- | lisp/paren.el | 53 |
2 files changed, 47 insertions, 10 deletions
diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el index 74a20b8a8b7..73713a3dec9 100644 --- a/lisp/emacs-lisp/eldoc.el +++ b/lisp/emacs-lisp/eldoc.el | |||
| @@ -387,6 +387,10 @@ Also store it in `eldoc-last-message' and return that value." | |||
| 387 | ;; conflicts with eldoc. | 387 | ;; conflicts with eldoc. |
| 388 | (and (boundp 'show-paren-context-when-offscreen) | 388 | (and (boundp 'show-paren-context-when-offscreen) |
| 389 | show-paren-context-when-offscreen | 389 | show-paren-context-when-offscreen |
| 390 | ;; There's no conflict with the child-frame and | ||
| 391 | ;; overlay versions. | ||
| 392 | (not (memq show-paren-context-when-offscreen | ||
| 393 | '(child-frame overlay))) | ||
| 390 | (not (pos-visible-in-window-p | 394 | (not (pos-visible-in-window-p |
| 391 | (overlay-end show-paren--overlay))))))) | 395 | (overlay-end show-paren--overlay))))))) |
| 392 | 396 | ||
diff --git a/lisp/paren.el b/lisp/paren.el index 221cad3f05a..8d45987e90c 100644 --- a/lisp/paren.el +++ b/lisp/paren.el | |||
| @@ -96,14 +96,18 @@ context includes the previous nonblank line. | |||
| 96 | 96 | ||
| 97 | By default, the context is shown in the echo area. | 97 | By default, the context is shown in the echo area. |
| 98 | 98 | ||
| 99 | If set to the symbol `overlay', the context is shown in an | ||
| 100 | overlay at the top-left of the window. | ||
| 101 | |||
| 99 | If set to the symbol `child-frame', the context is shown in a | 102 | If set to the symbol `child-frame', the context is shown in a |
| 100 | child frame at the top left of the window. You might want to | 103 | child frame at the top-left of the window. You might want to |
| 101 | customize the `child-frame-border' face (especially the | 104 | customize the `child-frame-border' face (especially the |
| 102 | background color) to give the child frame a distinguished border. | 105 | background color) to give the child frame a distinguished border. |
| 103 | On non-graphical frames, the context is shown in the echo area." | 106 | On non-graphical frames, the context is shown in the echo area." |
| 104 | :type '(choice (const :tag "Off" nil) | 107 | :type '(choice (const :tag "Off" nil) |
| 105 | (const :tag "In echo area" t) | 108 | (const :tag "In echo area" t) |
| 106 | (const :tag "Child frame" child-frame)) | 109 | (const :tag "In overlay" overlay) |
| 110 | (const :tag "In child-frame" child-frame)) | ||
| 107 | :version "29.1") | 111 | :version "29.1") |
| 108 | 112 | ||
| 109 | (defvar show-paren--idle-timer nil) | 113 | (defvar show-paren--idle-timer nil) |
| @@ -368,6 +372,32 @@ It is the default value of `show-paren-data-function'." | |||
| 368 | (add-hook 'post-command-hook | 372 | (add-hook 'post-command-hook |
| 369 | #'show-paren--delete-context-child-frame)))) | 373 | #'show-paren--delete-context-child-frame)))) |
| 370 | 374 | ||
| 375 | (defvar-local show-paren--context-overlay nil) | ||
| 376 | |||
| 377 | (defun show-paren--delete-context-overlay () | ||
| 378 | (when show-paren--context-overlay | ||
| 379 | (delete-overlay show-paren--context-overlay) | ||
| 380 | (setq show-paren--context-overlay nil)) | ||
| 381 | (remove-hook 'post-command-hook #'show-paren--delete-overlays | ||
| 382 | 'local)) | ||
| 383 | |||
| 384 | (defun show-paren--show-context-in-overlay (text) | ||
| 385 | "Show TEXT in an overlay at the top-left of the current window." | ||
| 386 | (setq text (replace-regexp-in-string "\n" " " text)) | ||
| 387 | (show-paren--delete-context-overlay) | ||
| 388 | (let* ((beg (window-start)) | ||
| 389 | (end (save-excursion | ||
| 390 | (goto-char beg) | ||
| 391 | (line-end-position)))) | ||
| 392 | (setq show-paren--context-overlay (make-overlay beg end))) | ||
| 393 | (overlay-put show-paren--context-overlay 'display text) | ||
| 394 | (overlay-put show-paren--context-overlay | ||
| 395 | 'face `(:box | ||
| 396 | ( :line-width (1 . -1) | ||
| 397 | :color ,(face-attribute 'shadow :foreground)))) | ||
| 398 | (add-hook 'post-command-hook #'show-paren--delete-context-overlay | ||
| 399 | nil 'local)) | ||
| 400 | |||
| 371 | (defun show-paren-function () | 401 | (defun show-paren-function () |
| 372 | "Highlight the parentheses until the next input arrives." | 402 | "Highlight the parentheses until the next input arrives." |
| 373 | (let ((data (and show-paren-mode (funcall show-paren-data-function)))) | 403 | (let ((data (and show-paren-mode (funcall show-paren-data-function)))) |
| @@ -435,15 +465,18 @@ It is the default value of `show-paren-data-function'." | |||
| 435 | (if (and show-paren-context-when-offscreen | 465 | (if (and show-paren-context-when-offscreen |
| 436 | (< there-beg here-beg) | 466 | (< there-beg here-beg) |
| 437 | (not (pos-visible-in-window-p openparen))) | 467 | (not (pos-visible-in-window-p openparen))) |
| 438 | (let ((open-paren-line-string | 468 | (let ((context (blink-paren-open-paren-line-string |
| 439 | (blink-paren-open-paren-line-string openparen)) | 469 | openparen)) |
| 440 | (message-log-max nil)) | 470 | (message-log-max nil)) |
| 441 | (if (and (eq show-paren-context-when-offscreen | 471 | (cond |
| 442 | 'child-frame) | 472 | ((and |
| 443 | (display-graphic-p)) | 473 | (eq show-paren-context-when-offscreen 'child-frame) |
| 444 | (show-paren--show-context-in-child-frame | 474 | (display-graphic-p)) |
| 445 | open-paren-line-string) | 475 | (show-paren--show-context-in-child-frame context)) |
| 446 | (minibuffer-message "Matches %s" open-paren-line-string))))) | 476 | ((eq show-paren-context-when-offscreen 'overlay) |
| 477 | (show-paren--show-context-in-overlay context)) | ||
| 478 | (show-paren-context-when-offscreen | ||
| 479 | (minibuffer-message "Matches %s" context)))))) | ||
| 447 | ;; Always set the overlay face, since it varies. | 480 | ;; Always set the overlay face, since it varies. |
| 448 | (overlay-put show-paren--overlay 'priority show-paren-priority) | 481 | (overlay-put show-paren--overlay 'priority show-paren-priority) |
| 449 | (overlay-put show-paren--overlay 'face face)))))) | 482 | (overlay-put show-paren--overlay 'face face)))))) |