2

在文本模式控制台 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

4 回答 4

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))) 
于 2011-04-20T07:54:57.100 回答
2

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

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

我没有独立的存储库,但可以从我在 github 上的 emacs 配置中获得最新版本。

;;; -*- 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)))
于 2011-11-25T05:34:54.550 回答
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))) 
于 2011-06-03T06:51:55.813 回答
1

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

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

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

于 2011-08-02T23:07:43.697 回答