Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flymake complains X is not available even when configured not to use X

Running the Flymake mode in a text-mode console Emacs session, how can I tell Flymake to display its messages in the text console instead of trying to communicate with X?

Emacs 23 running on various environments, including Debian and Ubuntu.

I have flymake-gui-warnings-enabled set to nil, but when I flymake-display-err-menu-for-current-line it complains:

X windows are not in use or not initialized

Yes, I know that; Emacs is running across an SSH connection without X. That's why I disabled GUI use by Flymake. How can I tell Flymake not to try using the GUI, and instead to say what it has to say in the Emacs windows?

like image 681
bignose Avatar asked Jan 21 '26 17:01

bignose


2 Answers

I've found the "tooltip" error messages plain annoying anyway so I have this in my .emacs that displays flymake error messages in the minibuffer. This is something which I got off the net somewhere. It was called flymake-cursor.el. Credit belongs to the chap who wrote it first. You don't need the pyflake bits which are specific to the Python tool I use as a flymake helper. The main function is show-fly-err-at-point which allows you to use your regular cursor to hover on a highlighted line for the message.

;; License: Gnu Public License
;;
;; Additional functionality that makes flymake error messages appear
;; in the minibuffer when point is on a line containing a flymake
;; error. This saves having to mouse over the error, which is a
;    ; keyboard user's annoyance

;;flymake-ler(file line type text &optional full-file)
(defun show-fly-err-at-point ()
  "If the cursor is sitting on a flymake error, display the
message in the minibuffer"
  (interactive)
  (let ((line-no (line-number-at-pos)))
    (dolist (elem flymake-err-info)
      (if (eq (car elem) line-no)
      (let ((err (car (second elem))))
        (message "%s" (fly-pyflake-determine-message err)))))))

(defun fly-pyflake-determine-message (err)
  "pyflake is flakey if it has compile problems, this adjusts the
message to display, so there is one ;)"
  (cond ((not (or (eq major-mode 'Python) (eq major-mode 'python-mode) t)))
    ((null (flymake-ler-file err))
     ;; normal message do your thing
     (flymake-ler-text err))
    (t ;; could not compile err
     (format "compile error, problem on line %s" (flymake-ler-line err)))))

(defadvice flymake-goto-next-error (after display-message activate compile)
  "Display the error in the mini-buffer rather than having to mouse over it"
  (show-fly-err-at-point))

(defadvice flymake-goto-prev-error (after display-message activate compile)
  "Display the error in the mini-buffer rather than having to mouse over it"
  (show-fly-err-at-point))

(defadvice flymake-mode (before post-command-stuff activate compile)
  "Add functionality to the post command hook so that if the
cursor is sitting on a flymake error the error information is
displayed in the minibuffer (rather than having to mouse over
it)"
  (set (make-local-variable 'post-command-hook)
       (cons 'show-fly-err-at-point post-command-hook))) 
like image 129
Noufal Ibrahim Avatar answered Jan 23 '26 21:01

Noufal Ibrahim


Here's basically the answer of Noufal Ibrahim but the pyflakes part has been removed. More specifically I'm using flymake-ler-text directly to extract the text part of the error. I've only tried with epylint. Works like a charm.

;; show error in the mini buffer instead of in the menu.
;; flymake-ler(file line type text &optional full-file)
(defun show-fly-err-at-point ()
  "If the cursor is sitting on a flymake error, display the message in the minibuffer"
  (interactive)
  (let ((line-no (line-number-at-pos)))
    (dolist (elem flymake-err-info)
      (if (eq (car elem) line-no)
          (let ((err (car (second elem))))
            (message "%s" (flymake-ler-text err)))))))

(defadvice flymake-goto-next-error (after display-message activate compile)
  "Display the error in the mini-buffer rather than having to mouse over it"
  (show-fly-err-at-point))

(defadvice flymake-goto-prev-error (after display-message activate compile)
  "Display the error in the mini-buffer rather than having to mouse over it"
  (show-fly-err-at-point))

(defadvice flymake-mode (before post-command-stuff activate compile)
  "Add functionality to the post command hook so that if the
cursor is sitting on a flymake error the error information is
displayed in the minibuffer (rather than having to mouse over
it)"
  (set (make-local-variable 'post-command-hook)
       (cons 'show-fly-err-at-point post-command-hook))) 
like image 43
Nil Geisweiller Avatar answered Jan 23 '26 20:01

Nil Geisweiller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!