Question

Here is a screenshot of what is going wrong:

Imgur

As you can see, the whitespace characters are getting in the way of auto-complete's pop-up text and making things look really terrible.

When really, I'd like it to look like this:

Imgur

Is there anyone out there who has been able to use whitespace-mode but eliminate it from popping up in the auto-complete stuff?

Was it helpful?

Solution

There is an issue about compatibility between auto-complete and whitespace-mode in the Prelude issue tracker which has the following workaround in its comments (improved a bit from the original):

(defvar my-prev-whitespace-mode nil)
(make-variable-buffer-local 'my-prev-whitespace-mode)

(defadvice popup-draw (before my-turn-off-whitespace activate compile)
  "Turn off whitespace mode before showing autocomplete box"
  (if whitespace-mode
      (progn
        (setq my-prev-whitespace-mode t)
        (prelude-turn-off-whitespace))
    (setq my-prev-whitespace-mode nil)))

(defadvice popup-delete (after my-restore-whitespace activate compile)
  "Restore previous whitespace mode when deleting autocomplete box"
  (if my-prev-whitespace-mode
      (prelude-turn-on-whitespace)))

Essentially this disables whitespace mode for the whole buffer while a popup is shown.

The issue is also reported in the popup.el issue tracker.

OTHER TIPS

Reworked example to make it work (partially).

There are following issues that prevent @lunaryorn's example from working

  • double activating the popup-draw advice would cause my-prev-whitespace-mode to lose stored information
  • activating the popup-delete advice before popup-draw would just switch-off whitespace mode because default value for my-prev-whitespace-mode is nil.

So I evolve the original workaround further to address the two difficulties.

(defun my:force-modes (rule-mode &rest modes)
  "switch on/off several modes depending of state of
    the controlling minor mode
  "
  (let ((rule-state (if rule-mode 1 -1)
       ))
    (mapcar (lambda (k) (funcall k rule-state)) modes)
  )
)

(require 'whitespace)

(defvar my:prev-whitespace-mode nil)
(make-variable-buffer-local 'my:prev-whitespace-mode)
(defvar my:prev-whitespace-pushed nil)
(make-variable-buffer-local 'my:prev-whitespace-pushed)

(defun my:push-whitespace (&rest skip)
  (if my:prev-whitespace-pushed () (progn
    (setq my:prev-whitespace-mode whitespace-mode)
    (setq my:prev-whitespace-pushed t)
    (my:force-modes nil 'whitespace-mode)
  ))
)

(defun my:pop-whitespace (&rest skip)
  (if my:prev-whitespace-pushed (progn
    (setq my:prev-whitespace-pushed nil)
    (my:force-modes my:prev-whitespace-mode 'whitespace-mode)
  ))
)

(require 'popup)

(advice-add 'popup-draw :before #'my:push-whitespace)
(advice-add 'popup-delete :after #'my:pop-whitespace)

This solution still has drawbacks. Whitespace-mode is disabled only when a menu is shown. While there is only single candidate for substitution the whitespace mode continues to disrupt screen.

The issue is most likely with bad choice for functions to dirty hack with advices. There should be more appropriate that are called exactly when disabling whitespace-mode is desirable. But no-one except the developer can name them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top