Fix eldoc frame shrinking on some setups
There appears to be an Emacs bug where in some environments, calling set-frame-size to another size and then to the original size will result in the second call not taking effect. This means that the workaround for #68 causes the frame to shrink if moving between doc items with the same doc size (or within the same doc item). Instead, we just temporarily shrink the Markdown separators to make the window size calculations work, then restore them afterwards. * eldoc-box.el (eldoc-box--update-childframe-geometry): Adjust markdown separator width instead of setting the frame to a tiny size.
This commit is contained in:
		
							parent
							
								
									b5aa481432
								
							
						
					
					
						commit
						05895fdbb9
					
				
							
								
								
									
										36
									
								
								eldoc-box.el
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								eldoc-box.el
									
									
									
									
									
								
							| @ -411,14 +411,15 @@ FRAME is the childframe, WINDOW is the primary window." | |||||||
|   ;; property of (space :width text) -- which is what we apply onto |   ;; property of (space :width text) -- which is what we apply onto | ||||||
|   ;; markdown separators -- ‘window-text-pixel-size’ wouldn’t return |   ;; markdown separators -- ‘window-text-pixel-size’ wouldn’t return | ||||||
|   ;; the correct value. Instead, it returns the current window width. |   ;; the correct value. Instead, it returns the current window width. | ||||||
|   ;; So now the childram only grows in size and never shrinks. For |   ;; So now the childram only grows in size and never shrinks. (My | ||||||
|   ;; whatever reason, if we set the frame size very small before |   ;; guess is that the function takes (space :width text) at face | ||||||
|   ;; calculating window’s text size, it can return the right value. |  | ||||||
|   ;; (My guess is that the function takes (space :width text) at face |  | ||||||
|   ;; value, but that can’t be the whole picture because it works fine |   ;; value, but that can’t be the whole picture because it works fine | ||||||
|   ;; when I manually evaluate the function in the childframe...) |   ;; when I manually evaluate the function in the childframe...) | ||||||
|   (set-frame-size frame 1 1 t) |   ;; Setting the frame size to something small causes redisplay issues | ||||||
|   (let* ((size |   ;; under some setups such as pgtk with Wayland. So instead we just | ||||||
|  |   ;; temporarily shrink the separators. | ||||||
|  |   (let* ((separators (eldoc-box--remove-display-width-text window)) | ||||||
|  |          (size | ||||||
|           (window-text-pixel-size |           (window-text-pixel-size | ||||||
|            window nil nil |            window nil nil | ||||||
|            (if (functionp eldoc-box-max-pixel-width) (funcall eldoc-box-max-pixel-width) eldoc-box-max-pixel-width) |            (if (functionp eldoc-box-max-pixel-width) (funcall eldoc-box-max-pixel-width) eldoc-box-max-pixel-width) | ||||||
| @ -431,7 +432,28 @@ FRAME is the childframe, WINDOW is the primary window." | |||||||
|          (pos (funcall eldoc-box-position-function width height))) |          (pos (funcall eldoc-box-position-function width height))) | ||||||
|     (set-frame-size frame width height t) |     (set-frame-size frame width height t) | ||||||
|     ;; move position |     ;; move position | ||||||
|     (set-frame-position frame (car pos) (cdr pos)))) |     (set-frame-position frame (car pos) (cdr pos)) | ||||||
|  |     (eldoc-box--restore-display-width-text window separators))) | ||||||
|  | 
 | ||||||
|  | (defun eldoc-box--remove-display-width-text (window) | ||||||
|  |   "Remove `(display (space :width text))' properties in WINDOW. | ||||||
|  | Returns the list of `prop-match' objects found so they can be restored." | ||||||
|  |   (with-selected-window window | ||||||
|  |     (save-excursion | ||||||
|  |       (goto-char (point-min)) | ||||||
|  |       (let ((matches nil)) | ||||||
|  |         (while-let ((prop (text-property-search-forward 'display '(space :width text) t))) | ||||||
|  |           (push prop matches) | ||||||
|  |           (remove-text-properties (prop-match-beginning prop) (prop-match-end prop) '(display))) | ||||||
|  |         matches)))) | ||||||
|  | 
 | ||||||
|  | (defun eldoc-box--restore-display-width-text (window matches) | ||||||
|  |   "Undoes the effects of `eldoc-box--remove-display-width-text' in WINDOW." | ||||||
|  |   (with-selected-window window | ||||||
|  |     (mapcar (lambda (match) (add-text-properties (prop-match-beginning match) | ||||||
|  |                                                  (prop-match-end match) | ||||||
|  |                                                  `(display ,(prop-match-value match)))) | ||||||
|  |             matches))) | ||||||
| 
 | 
 | ||||||
| (defun eldoc-box--inhibit-childframe-for (sec) | (defun eldoc-box--inhibit-childframe-for (sec) | ||||||
|   "Inhibit display of childframe for SEC seconds after Emacs is idle again." |   "Inhibit display of childframe for SEC seconds after Emacs is idle again." | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Ash
						Ash