I do 90% of my coding in Emacs. In the old days, I used to run iTerm on a separate desktop and Alt-Tab between them. But the lack of integration bugged me, so I kept trying Emacs term-mode. It took a while, but I finally got a really nice setup, with mouseless-navigation, fish shell integration, and so on.

One thing always niggled. Emacs keeps track of changes to buffers. When you run a potentially destructive command (such as quitting Emacs, installing packages, or running Magit), Emacs warns you about each modified buffer in turn, asking you to decide what you want to do. I appreciate this for regular files, but for buffers containing terminal sessions it is a total PITA.

I’ve been meaning to fix it for months, but finally got around to it today. I have the following in my customization file for multiterm:

(defun ignore-changes-in-term-buffers ()
  (add-hook 'after-change-functions
            (lambda (a b c)
              (set-buffer-modified-p nil))
            nil
            t))

(add-hook 'term-mode-hook
          'ignore-changes-in-term-buffers
          nil
          t)

When term-mode is turned on for a buffer, it triggers the ignore-changes... function. That in turn intercepts every buffer change event, and immediately resets the buffer-modified flag.

It feels like a total hack, so I’d love someone to tell me how silly I am and give me a proper fix.

Please keep it clean, respectful, and relevant. I reserve the right to remove comments I don't feel belong.
  • NickName, E-Mail, and Website are optional. If you supply an e-mail, we'll notify you of activity on this thread.
  • You can use Markdown in your comment (and preview it using the magnifying glass icon in the bottom toolbar).