]> git.cworth.org Git - notmuch-wiki/blob - notmuch-emacs.mdwn
724e180a5f4ea62cded5905fc923c847f4c4eed5
[notmuch-wiki] / notmuch-emacs.mdwn
1 [[!img notmuch-logo.png alt="Notmuch logo" class="left"]]
2 # Notmuch Emacs Interface
3
4 One of the more popular Notmuch message reading clients is **notmuch.el**, or
5 `notmuch-mode`, an [Emacs](https://www.gnu.org/software/emacs/) major mode for
6 interacting with Notmuch. It is included in the Notmuch package (`elpa-notmuch`
7 in current Debian or `notmuch-emacs` in Debian 10 or prior). The
8 [[screenshots|screenshots]] give a good overview of the mode.
9
10 This page is a basic guide for setting up and using Notmuch with Emacs. See also
11 the [[tips and tricks page|emacstips]] for more advanced details.
12
13 [[!toc levels=2]]
14
15 ## Prerequisites
16
17 The Notmuch Emacs interface uses the Notmuch [command line
18 interface](https://notmuchmail.org/doc/latest/man1/notmuch.html) to
19 interact with the Notmuch database and your mail store. Please make
20 sure you've [[set up Notmuch|getting-started]] first.
21
22 ## Installation
23
24 Due to the dependency on the command line interface, the Notmuch Emacs interface
25 version must be compatible with the Notmuch version. On Linux, the easiest way
26 to ensure this is to use the package(s) in your distribution's package
27 repository.
28
29 If you've installed Notmuch from a [git
30 checkout](https://git.notmuchmail.org/git/notmuch) or a [source
31 release](https://notmuchmail.org/releases/), Notmuch Emacs is included by
32 default.
33
34 It is **not** recommended to install Notmuch Emacs from the Emacs Lisp Package
35 Archive (ELPA), as the version there is likely not in sync with the command line
36 interface.
37
38 ## Setup
39
40 First, you need to tell Emacs about Notmuch. Add this to your `.emacs` rc file:
41
42         (autoload 'notmuch "notmuch" "notmuch mail" t)
43
44 or if you always want to load Notmuch when you start Emacs:
45
46         (require 'notmuch)
47
48 To start Notmuch Emacs, either run `emacs -f notmuch`, or execute the command
49 `M-x notmuch RET` from within a running Emacs. This will bring you to the
50 Notmuch Hello view.
51
52 ## Customization
53
54 Notmuch Emacs uses the Emacs customization interface extensively for
55 configuration. Execute `M-x customize-group RET notmuch RET` to get to the
56 Notmuch main customization group.
57
58 ### <span id="notmuch_init_file"> Notmuch Emacs configuration file </span>
59
60 After Notmuch is loaded `notmuch-init-file` (typically
61  `~/.emacs.d/notmuch-config.el`) is checked out. If such file exists
62 it is loaded. Most Emacs lisp based configuration not suitable via
63 customization can be put there instead of `~/.emacs`.
64
65 ## Navigating & reading mails
66
67 When first starting Notmuch in Emacs, you will be presented with the
68 Notmuch "hello" page.  If it exits with an error after writing
69 "Welcome to notmuch. You have" you need to do the basic Notmuch setup
70 first (see above).
71 From here you can do searches, see lists of recent
72 searches, saved searches, message tags, help information, etc.
73
74 Executing a search will open a new buffer in `notmuch-search-mode`
75 displaying the search results.  Each line in the search results
76 represents a message thread.  Hitting the '?' key will show help for
77 this mode.
78
79 In general, the 'q' will kill the current Notmuch buffer and return
80 you to the previous buffer (sort of like a 'pop').
81
82 In search mode, navigating to a thread and hitting return will then
83 open a new buffer in `notmuch-show-mode`, which will show the actual
84 message contents of the thread.
85
86 ## Sending mail
87
88 In any Notmuch mode, you can start a new message by hitting the 'm'
89 key.  To reply to a message or thread, just hit the 'r' key.
90
91 When composing new messages, you will be entered in Emacs's
92 `message-mode`, which is a powerful mode for composing and sending
93 messages.  When in message mode, you can type `C-c ?` for help.
94
95 If you would like to use address autocompletion when composing
96 messages, see [address completion](/emacstips#index13h2).
97
98 When you are ready to send a message, type `C-c C-c`. By default
99 message mode will use your sendmail command to send mail, so make sure
100 that works. One annoying standard configuration of message mode is
101 that it will hide the sent mail in your Emacs frame stack, but it will
102 not close it. If you type several mails in an Emacs session they will
103 accumulate and make switching between buffers more annoying. You can
104 avoid that behavior by adding `(setq message-kill-buffer-on-exit t)`
105 in your `.emacs` file
106 (or doing `M-x customize-variable<RET>message-kill-buffer-on-exit<RET>`)
107 which will really close the mail window after sending it.
108
109 ## Attaching files
110
111 Using the `M-x mml-attach-file` command, you can attach any file to be
112 sent with your mail. By default this command is bound to the menu item
113 *Attachments--Attach File* with the key binding `C-c C-a`. The
114 variable `mml-dnd-attach-options` (`M-x
115 customize-variable<RET>mml-dnd-attach-options<RET>`) can be set to
116 allow the prompting for various attachment options (such as
117 inline/attachment) if you want to do that.
118
119 For those who prefer a more graphical interface, you can also simply
120 drag and drop files from a file manager into a mail composition window
121 to have them attached. In Ubuntu this works without any modifications
122 if files are dragged from the file manager.
123
124 And for those who prefer working from command line, the following
125 script opens new Emacs window with empty message and attaches files
126 mentioned as script arguments. (Note: The script expects that you have
127 `(server-start)` in your `.emacs` file.)
128
129         #!/bin/sh
130         attach_cmds=""
131         while [ $# -gt 0 ]; do
132             fullpath=$(readlink --canonicalize "$1")
133             attach_cmds="$attach_cmds (mml-attach-file \"$fullpath\")"
134             shift
135         done
136         emacsclient -a '' -c -e "(progn (compose-mail) $attach_cmds)"
137
138 Also, if you're the kind of person who forgets to add attachments,
139 there's a cure for that disease. See [Never forget
140 attachments](/emacstips#index27h2) for all the details.