FlyMake와 FlySpell에 하나의 키를 사용합니다
문제
Pyflakes와 함께 Flymake를 사용하여 파이썬 코드와 FlySpell을 확인하여 문자열과 댓글을 확인합니다. 다음 오류로 이동하거나 현재 오류가 발생한 경우 오류에 대한 정보를 표시하는 한 가지 기능을 원합니다. 이 기능을 어떻게 작성합니까?
해결책
이 코드는 다음 오류로 이동하는 기능을 제공하며 FlyMake 오류 인 경우 정보가 표시되면 FlySpell 오류 인 경우 수정됩니다. 자동 수정을 원하지 않으면 전화를받는 라인을 제외하고 'my-flyspell-message
호출하기 전에 선을 제거하십시오 'flyspell-auto-correct-word
- 그리고 당신은 철자가 잘못된 단어에 대한 메시지를받을 것입니다.
첫 번째 줄은 이것을 키 바인딩에 바인딩합니다 CC n. 바인딩 키에 대한 자세한 내용은 정보 페이지를 참조하십시오. 주요 바인딩.
(global-set-key (kbd "C-c n") 'my-display-error-or-next-error)
(defun my-display-error-or-next-error ()
"display information for current error, or go to next one"
(interactive)
(when (or (not (my-at-flymake-error))
(not (my-at-flyspell-error)))
;; jump to error if not at one
(my-goto-next-error))
(cond ((my-at-flymake-error)
;; if at flymake error, display menu
(flymake-display-err-menu-for-current-line))
((my-at-flyspell-error)
;; if at flyspell error, fix it
(call-interactively 'flyspell-auto-correct-word)
;; or, uncomment the next line to just get a message
;; (my-flyspell-message)
)))
(defun my-at-flyspell-error ()
"return non-nill if at flyspell error"
(some 'flyspell-overlay-p (overlays-at (point))))
(defun my-at-flymake-error ()
"return non-nil if at flymake error"
(let* ((line-no (flymake-current-line-no))
(line-err-info-list (nth 0 (flymake-find-err-info flymake-err-info line-no))))
line-err-info-list))
(defun my-goto-next-error ()
"jump to next flyspell or flymake error"
(interactive)
(let* ((p (point))
(spell-next-error-function '(lambda ()
(forward-word) (forward-char)
(flyspell-goto-next-error)))
(spell-pos (save-excursion
(funcall spell-next-error-function)
(point)))
(make-pos (save-excursion
(flymake-goto-next-error)
(point))))
(cond ((or (and (< p make-pos) (< p spell-pos))
(and (> p make-pos) (> p spell-pos)))
(funcall (if (< make-pos spell-pos)
'flymake-goto-next-error
spell-next-error-function)))
((< p make-pos)
(flymake-goto-next-error))
((< p spell-pos)
(funcall spell-next-error-function)))))
(defun my-flyspell-message ()
(interactive)
(let ((word (thing-at-point 'word)))
(set-text-properties 0 (length word) nil word)
(message "Missspelled word: %s" word)))
제휴하지 않습니다 StackOverflow