Flymake抱怨X即使配置为不使用X也不可用

时间:2011-04-20 07:33:16

标签: emacs terminal syntax-checking flymake

在文本模式控制台Emacs会话中运行Flymake模式,如何告诉Flymake 在文本控制台中显示其消息而不是尝试与X通信?

Emacs 23在各种环境中运行,包括Debian和Ubuntu。

我将flymake-gui-warnings-enabled设置为nil,但当我flymake-display-err-menu-for-current-line抱怨时:

X windows are not in use or not initialized

是的,我知道; Emacs在没有X的情况下运行SSH连接。这就是我禁用Flymake使用GUI的原因。我怎么能告诉Flymake 尝试使用GUI,而是说出它在Emacs窗口中的说法

4 个答案:

答案 0 :(得分:5)

我发现“工具提示”错误消息无论如何都很烦人,所以我在我的.emacs中显示了这个消息,在迷你缓冲区中显示flymake错误消息。这是我从某个地方下网的事情。它被称为flymake-cursor.el。信用属于第一个写它的人。您不需要特定于我用作flymake帮助器的Python工具的pyflake位。主要功能是show-fly-err-at-point,它允许您使用常规光标悬停在消息的突出显示行上。

;; 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))) 

答案 1 :(得分:2)

这基本上是Noufal Ibrahim的答案,但pyflakes部分已被删除。更具体地说,我直接使用flymake-ler-text来提取错误的文本部分。我只试过epylint。像魅力一样。

;; 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))) 

答案 2 :(得分:2)

早期解决方案的改进。使错误消息更像eldoc消息。消息不会在消息缓冲区中结束,消息不会闪烁,并且消息不会阻止其他输出。使用词法范围的变量而不是全局变量。

需要emacs 24.我相信词法绑定注释必须位于文件的顶部。

我没有这方面的独立存储库,但最新版本可以从my emacs config on github获得。

;;; -*- lexical-binding: t -*-
;; Make flymake show eldoc style error messages.
(require 'eldoc)
(defun c5-flymake-ler-at-point ()
  (caar (flymake-find-err-info flymake-err-info (line-number-at-pos))))

(defun c5-flymake-show-ler (ler)
  (when ler
    ;; Don't log message.
    (let ((message-log-max nil)) 
      (message (flymake-ler-text ler)))))

(let ((timer nil)
      (ler nil))
 (defalias 'c5-flymake-post-command-action (lambda ()
    (when timer
      (cancel-timer timer)
      (setq timer nil))
    (setq ler (c5-flymake-ler-at-point))
    (when ler
      (setq timer (run-at-time "0.9 sec" nil
                               (lambda ()
                                 (when (let ((eldoc-mode t))
                                         (eldoc-display-message-p))
                                   (c5-flymake-show-ler ler))))))))

 (defalias 'c5-flymake-pre-command-action (lambda ()
    (when (let ((eldoc-mode t)) (eldoc-display-message-no-interference-p))
      (c5-flymake-show-ler ler)))))

(defadvice flymake-mode (before c5-flymake-post-command activate compile)
  (add-hook 'post-command-hook 'c5-flymake-post-command-action nil t)
  (add-hook 'pre-command-hook 'c5-flymake-pre-command-action nil t))

(defadvice flymake-goto-next-error (after display-message activate compile)
  (c5-flymake-show-ler (c5-flymake-ler-at-point)))

(defadvice flymake-goto-prev-error (after display-message activate compile)
  (c5-flymake-show-ler (c5-flymake-ler-at-point)))

答案 3 :(得分:1)

您可以在以下网址下载更完整版本的flymake-cursor.el

http://www.emacswiki.org/emacs/flymake-cursor.el

它有一些优化功能可确保您在高速光标时不会向迷你缓冲区发送垃圾邮件。