company-box icon indicating copy to clipboard operation
company-box copied to clipboard

company-box clips off to the edge of the screen

Open SreenivasVRao opened this issue 3 years ago • 7 comments

https://i.imgur.com/cF1DBCD.png

As you can see - the doc string shows up in a childframe which doesn't wrap at the edge of the screen. On dual monitors, the problem is that the doc string shows up in a childframe spanning multiple monitors:

https://media.discordapp.net/attachments/406554085794381833/825157364344029274/Screen_Shot_2021-03-26_at_7.55.13_PM.png?width=2160&height=375

Any advice on how to overcome this? I'm using doom emacs.

SreenivasVRao avatar May 01 '21 23:05 SreenivasVRao

I have the same issue. I'm very new to emacs and don't know elisp so a 'proper' solution that could form a pull request is beyond me, however you can manually set the documentation frame size here. I've changed mine to ((width . height) (window-text-pixel-size window nil nil 800 10000)), for instance. The quickest way to implement this is to modify this file under ~/.emacs.d/elpa/ and then M-x emacs-lisp-byte-compile-and-load.

Edit: I just looked at this again and wrote a better solution:

((width . height) (window-text-pixel-size window nil nil (- (frame-outer-width) (+ 20 (+ box-width (nth 0 box-position)))) (- (frame-outer-height) 20)))

This will ensure that the documentation box can at most expand to the right and bottom edges of the frame but not beyond it and will rescale with the frame. For a pull request this should perhaps take into account the total area of the current monitor such that the doc box can expand beyond the edges of the emacs frame (e.g. using display-pixel-width); I'll consider which might be more desirable behaviour and submit a pull request accordingly (edit2: although come to think of it I'm not sure that this box can ever expand outside of the emacs frame anyway, unless it's OS-dependent).

HawkinsT avatar Sep 20 '21 18:09 HawkinsT

I also have this problem on a single-monitor laptop: image

NightMachinery avatar Sep 21 '21 16:09 NightMachinery

Patching the mentioned line, the problem is that the frame is not soft-wrapping at all: image

NightMachinery avatar Sep 21 '21 16:09 NightMachinery

To fix this, I needed to add (toggle-truncate-lines -1) to the end of the function company-box-doc--make-buffer.

(defun company-box-doc--make-buffer (object)
  (let* ((buffer-list-update-hook nil)
         (inhibit-modification-hooks t)
         (string (cond ((stringp object) object)
                       ((bufferp object) (with-current-buffer object (buffer-string))))))
    (when (and string (> (length (string-trim string)) 0))
      (with-current-buffer (company-box--get-buffer "doc")
        (erase-buffer)
        (insert string)
        (setq mode-line-format nil
              display-line-numbers nil
              header-line-format nil
              show-trailing-whitespace nil
              cursor-in-non-selected-windows nil)

        (toggle-truncate-lines -1) ;; PATCHED HERE

        (current-buffer)))))

BTW, you do not need to edit the original files. You can copy the functions to your own personal config and edit them there; The new definitions would override the old ones (if you load company-box before them).

I hope these two patches are merged into the master, as the current behavior is only suitable if you have a huge monitor.

image

NightMachinery avatar Sep 21 '21 16:09 NightMachinery

Thanks, I've just proposed a commit that makes the above the default behaviour. I've also added the company-box-doc-no-wrap option in case anyone wishes to keep the existing behaviour.

HawkinsT avatar Sep 21 '21 18:09 HawkinsT

I haven't had a chance to investigate - but thanks @HawkinsT for your efforts! This bug has been bothering me a lot over the past few months.

SreenivasVRao avatar Sep 22 '21 01:09 SreenivasVRao

@sebastiencs any chance you can review this soon? :)

SreenivasVRao avatar Dec 01 '21 17:12 SreenivasVRao