Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do overlays/tooltips work correctly in Emacs for Windows?

Tags:

c#

emacs

I'm using Flymake on C# code, emacs v22.2.1 on Windows.

The Flymake stuff has been working well for me. For those who don't know, you can read an overview of flymake, but the quick story is that flymake repeatedly builds the source file you are currently working on in the background, for the purpose of doing syntax checking. It then highlights the compiler warnings and erros in the current buffer.

Flymake didn't work for C# initially, but I "monkey-patched it" and it works nicely now. If you edit C# in emacs, I highly recommend using flymake.

The only problem I have is with the UI. Flymake highlights the errors and warnings nicely, and then inserts "overlays" with tooltips containing the full error or warning text. If I hover the mouse pointer over the highlighted line in code, the overlay tooltip pops up.

alt text

But as you can see, the overlay tooltip is clipped, and it doesn't display correctly.

Flymake seems to be doing the right thing, it's the overlay part that seems broken., and overlay seems to do the right thing. It's the tooltip that is displayed incorrectly.

Do overlays tooltips work correctly in emacs for Windows?

Where do I look to fix this?


After some research, I found that the effect is demonstrable with (tooltip-show really-long-string)

It has nothing to do with overlays, or flymake.

like image 579
Cheeso Avatar asked Apr 08 '10 15:04

Cheeso


1 Answers

I solved this with a defadvice on tooltip-show.

;; Reforms a single-line string ARG to a multi-line string with a max
;; of LIMIT chars on a line.
;;
;; This is intended to solve a problem with the display of tooltip text
;; in emacs on Win32 - which is that the tooltip is extended to be very very
;; long, and the final line is clipped.
;;
;; The solution is to split the text into multiple lines, and to add a
;; trailing newline to trick the tooltip logic into doing the right thing.
;;
(defun cheeso-reform-string (limit arg)
  (let ((orig arg) (modified "") (curline "") word
        (words (split-string arg " ")))
    (while words
      (progn
        (setq curline "")
        (while (and words (< (length curline) limit))
          (progn
            (setq word (car words))
            (setq words (cdr words))
            (setq curline (concat curline " " word))))
        (setq modified (concat modified curline "\n"))))
    (setq modified (concat modified " \n")))
  )

(defadvice tooltip-show (before
                         flymake-csharp-fixup-tooltip
                         (arg &optional use-echo-area)
                         activate compile)
  (progn
    (if (and (not use-echo-area)
             (eq major-mode 'csharp-mode))
        (let ((orig (ad-get-arg 0)))
          (ad-set-arg 0 (cheeso-reform-string 72 orig))
          ))))

result:

alt text

like image 155
Cheeso Avatar answered Oct 05 '22 17:10

Cheeso