Skip to content

Instantly share code, notes, and snippets.

@zkytony
Created July 30, 2023 20:08
Show Gist options
  • Save zkytony/b0af383bbc3f7b6d6b0bff5aa7f8f470 to your computer and use it in GitHub Desktop.
Save zkytony/b0af383bbc3f7b6d6b0bff5aa7f8f470 to your computer and use it in GitHub Desktop.
custom mode for navigating mypy output
;;; mypy-mode.el --- Navigate Mypy Output in Emacs
;; Copyright (C) 2023 Kaiyu Zheng
;; Author: Your Name <kaiyutony@gmail.com>
;; Keywords: convenience
;; Version: 0.0.1
;; Package-Requires: ((emacs "24.3"))
;;; Commentary:
;; This package provides a major mode for navigating mypy output in Emacs.
;; It is similar to `compilation-mode`, but the 'g' keybinding is changed to
;; reload the current buffer from disk (using `revert-buffer`) rather than
;; rerunning the compilation command.
;;; Code:
(defun mypy-revert-buffer ()
"Reload the current buffer from disk."
(interactive)
(revert-buffer t t))
(define-derived-mode mypy-report-mode compilation-mode "Mypy"
"Major mode for navigating Mypy output.")
(define-key mypy-report-mode-map (kbd "g") 'mypy-revert-buffer)
(provide 'mypy-report-mode)
;;; mypy-report-mode.el ends here
@zkytony
Copy link
Author

zkytony commented Jul 30, 2023

Configuration

Load the mode

(load "mypy-report-mode.el" nil t t)

Make screen splits the screen into top and bottom sections by default

(add-hook 'mypy-report-mode-hook
          (lambda ()
            (setq split-width-threshold nil)))

Load the mode by default when opening mypy_report (where mypy output is dumped)
(add-to-list 'auto-mode-alist '("mypy_report" . mypy-report-mode))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment