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