]> git.notmuchmail.org Git - notmuch/blob - emacs/notmuch-compat.el
c4e07780506d84855c46f0169b22368b88319a0d
[notmuch] / emacs / notmuch-compat.el
1 ;;; notmuch-compat.el --- compatibility functions for earlier versions of emacs
2 ;;
3 ;; The functions in this file are copied from more modern versions of
4 ;; emacs and are Copyright (C) 1985-1986, 1992, 1994-1995, 1999-2017
5 ;; Free Software Foundation, Inc.
6 ;;
7 ;; This file is part of Notmuch.
8 ;;
9 ;; Notmuch is free software: you can redistribute it and/or modify it
10 ;; under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
13 ;;
14 ;; Notmuch is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 ;; General Public License for more details.
18 ;;
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with Notmuch.  If not, see <https://www.gnu.org/licenses/>.
21
22 ;;; Code:
23
24 ;; Before Emacs 26.1 lines that are longer than 998 octets were not.
25 ;; folded. Commit 77bbca8c82f6e553c42abbfafca28f55fc995d00 fixed
26 ;; that. Until we drop support for Emacs 25 we have to backport that
27 ;; fix. To avoid interfering with Gnus we only run the hook when
28 ;; called from notmuch-message-mode.
29
30 (declare-function mail-header-fold-field "mail-parse" nil)
31
32 (defun notmuch-message--fold-long-headers ()
33   (when (eq major-mode 'notmuch-message-mode)
34     (goto-char (point-min))
35     (while (not (eobp))
36       (when (and (looking-at "[^:]+:")
37                  (> (- (line-end-position) (point)) 998))
38         (mail-header-fold-field))
39       (forward-line 1))))
40
41 (unless (fboundp 'message--fold-long-headers)
42   (add-hook 'message-header-hook 'notmuch-message--fold-long-headers))
43
44 (provide 'notmuch-compat)
45
46 ;;; notmuch-compat.el ends here