#emacs #terminal #syntax-checking #flymake
#emacs #терминал #проверка синтаксиса #flymake
Вопрос:
Запуск режима Flymake в сеансе Emacs консоли текстового режима, как я могу сказать 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 работает через SSH-соединение без X. Вот почему я отключил использование графического интерфейса Flymake. Как я могу сказать Flymake, чтобы он не пытался использовать графический интерфейс, а вместо этого сказал, что он должен сказать в окнах Emacs?
Ответ №1:
Я все равно обнаружил, что сообщения об ошибках «всплывающей подсказки» просто раздражают, поэтому у меня есть это в моем, .emacs
которое отображает flymake
сообщения об ошибках в минибуфере. Это то, что я где-то нашел в сети. Это было вызвано flymake-cursor.el
. Заслуга принадлежит парню, который написал это первым. Вам не нужны биты pyflake, которые специфичны для инструмента Python, который я использую в качестве помощника flymake. Основная функция — это 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 amp;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)))
Ответ №2:
Вот в основном ответ Нуфаля Ибрагима, но часть pyflakes была удалена. Более конкретно, я использую flymake-ler-text напрямую для извлечения текстовой части ошибки. Я пробовал только с epylint. Работает как шарм.
;; show error in the mini buffer instead of in the menu.
;; flymake-ler(file line type text amp;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)))
Ответ №3:
Усовершенствование предыдущих решений. Заставляет сообщения об ошибках вести себя больше как сообщения eldoc. Сообщения не попадают в буфер сообщений, сообщения не мерцают и сообщения не блокируют другой вывод. Использует переменные с лексической областью вместо глобальных переменных.
Требуется emacs 24. Я считаю, что комментарий к лексической привязке должен располагаться вверху вашего файла.
У меня нет независимого репозитория для этого, но самую последнюю версию можно получить из моей конфигурации emacs на 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)))
Ответ №4:
Вы можете загрузить более полную версию flymake-cursor.el
по адресу:
http://www.emacswiki.org/emacs/flymake-cursor.el
В нем есть некоторые оптимизации, которые гарантируют, что он не спамит ваш мини-буфер, когда вы перемещаете курсор на высокой скорости.