[notmuch] tach.el: An interface for handling attachments in message-mode

2010-02-20 Thread Jesse Rosenthal
Dear all,

Sending email in emacs message-mode is great, but the handling of
(outgoing) attachments leaves a lot to be desired. MML's markup can be
confusing, and can easily be edited by mistake.

Thus: tach.el. Tach is a minor mode that adds mutt-like attachment
handling to message mode. It's not notmuch specific, but I wrote it to
use with notmuch, and I thought it might be of use to some on the
list. 

You can get tach by typing:

git clone http://jkr.acm.jhu.edu/git/tach.git

Also, because the server has been a bit spotty recently, I've put the
current version of the file at the end of this message.

To use tach, put tach.el in your load-path, and add the following to
your .emacs:

(require 'tach)
(add-hook 'message-mode-hook 'tach-minor-mode)

Now when you type "C-c C-a" in message-mode, you should get a new window
with an attachment list. In that window, you can add and delete
attachments using `+' and `-', and scroll through them using the arrow
keys or the emacs direction commands.

tach.el will convert the attachments into MML markup as a last
step before sending. Hopefully you should never have to deal with it by
hand.

Some details: tach actually makes a numerical list at the bottom of the
message itself, separated by a custom separator. The message is narrowed
to above this separator, and the attachment window is an indirect buffer
narrowed to the region below the separator. The separator is erased when
the messages are translated to mml markup at the end.

This is still a work in its earliest stages, and the usual disclaimers
apply. It certainly needs more a lot more commenting and
documentation. But I thought it might be useful, or at least fun to play
around with, and I'd love to hear any feedback. As I said, it's not
notmuch-specific, so I'm not sending it as a patch, but if people like
it, we might also consider making it part of the notmuch emacs bundle,
at some point in its future development.

Best,
Jesse

---FILE--BELOW--
;; tach.el -- Interface for handling attachments in message-mode

;; Filename: tach.el
;; Copyright (C) 2010 Jesse Rosenthal
;; Author: Jesse Rosenthal 
;; Maintainer: Jesse Rosenthal 
;; Created: 18 Feb 2010
;; Description: Handles attachments for message mode
;; Version 0.01alpha

;; This file is not part of GNU Emacs.

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation; either version 2, or (at your
;; option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;; To use: add the following to your .emacs: 
;;   (require 'tach)
;;   (add-hook 'message-mode-hook 'tach-minor-mode)
;;
;; Pressing `C-cC-a' in message mode will open up an attachment
;; window. The first time you open it, it will prompt for a file name.
;;
;; In the attachment window, you can press `+' to add a file, or `-'
;; to remove one.
;;
;; Note that the attachment window is actually a different view of the
;; message buffer, so that if there is some failure, the attachment
;; list will be saved at the bottom of the message, as a numerical
;; list under a customizable separator.
;;
;; The files will be added to the outgoing message by mml before it is
;; sent.


(require 'message)
(require 'mml)

(defconst tach-sep  "--attachments follow this line--")

(defconst tach-line-regexp "^\\([0-9]+.\\) +\\(.+?\\) +\\(\\[.+, 
[0-9\.]+[KM]\\]\\)$")

(defvar tach-send-confirmation nil)

(defvar tach-buffer-name)
(make-variable-buffer-local 'tach-buffer-name)

(defvar tach-mode-hooks 'nil)
(make-variable-buffer-local 'tach-mode-hooks)

(defvar tach-mode-map
  (let ((map (make-sparse-keymap)))
(define-key map "+" 'tach-add-file)
(define-key map "-" 'tach-delete-file)
(define-key map "\C-c\C-c" 'tach-send-from-attach-buffer)
(define-key map [up] 'tach-prev-entry)
(define-key map [down] 'tach-next-entry)
(define-key map "n" 'tach-next-entry)
(define-key map "p" 'tach-prev-entry)
(define-key map "\C-n" 'tach-next-entry)
(define-key map "\C-p" 'tach-prev-entry)
map)
  "Keymap for attachment mode")
(fset 'tach-mode-map tach-mode-map)

(defvar tach-minor-mode-map
  (let ((map (make-sparse-keymap)))
(define-key map "\C-c\C-a"  'tach-goto)
map)
  "Keymap for attachment minor mode")
(fset 'tach-minor-mode-map tach-minor-mode-map)

(defun tach-mode ()
  (interactive)
  (kill-all-local-variables)
  (use-local-map 'tach-mode-map)
  (hl-line-mode 1)
  (setq major-mode 

[notmuch] tach.el: An interface for handling attachments in message-mode

2010-02-20 Thread Jesse Rosenthal
Dear all,

Sending email in emacs message-mode is great, but the handling of
(outgoing) attachments leaves a lot to be desired. MML's markup can be
confusing, and can easily be edited by mistake.

Thus: tach.el. Tach is a minor mode that adds mutt-like attachment
handling to message mode. It's not notmuch specific, but I wrote it to
use with notmuch, and I thought it might be of use to some on the
list. 

You can get tach by typing:

git clone http://jkr.acm.jhu.edu/git/tach.git

Also, because the server has been a bit spotty recently, I've put the
current version of the file at the end of this message.

To use tach, put tach.el in your load-path, and add the following to
your .emacs:

(require 'tach)
(add-hook 'message-mode-hook 'tach-minor-mode)

Now when you type C-c C-a in message-mode, you should get a new window
with an attachment list. In that window, you can add and delete
attachments using `+' and `-', and scroll through them using the arrow
keys or the emacs direction commands.

tach.el will convert the attachments into MML markup as a last
step before sending. Hopefully you should never have to deal with it by
hand.

Some details: tach actually makes a numerical list at the bottom of the
message itself, separated by a custom separator. The message is narrowed
to above this separator, and the attachment window is an indirect buffer
narrowed to the region below the separator. The separator is erased when
the messages are translated to mml markup at the end.

This is still a work in its earliest stages, and the usual disclaimers
apply. It certainly needs more a lot more commenting and
documentation. But I thought it might be useful, or at least fun to play
around with, and I'd love to hear any feedback. As I said, it's not
notmuch-specific, so I'm not sending it as a patch, but if people like
it, we might also consider making it part of the notmuch emacs bundle,
at some point in its future development.

Best,
Jesse

---FILE--BELOW--
;; tach.el -- Interface for handling attachments in message-mode

;; Filename: tach.el
;; Copyright (C) 2010 Jesse Rosenthal
;; Author: Jesse Rosenthal jrosent...@jhu.edu
;; Maintainer: Jesse Rosenthal jrosent...@jhu.edu
;; Created: 18 Feb 2010
;; Description: Handles attachments for message mode
;; Version 0.01alpha

;; This file is not part of GNU Emacs.

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation; either version 2, or (at your
;; option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:

;; To use: add the following to your .emacs: 
;;   (require 'tach)
;;   (add-hook 'message-mode-hook 'tach-minor-mode)
;;
;; Pressing `C-cC-a' in message mode will open up an attachment
;; window. The first time you open it, it will prompt for a file name.
;;
;; In the attachment window, you can press `+' to add a file, or `-'
;; to remove one.
;;
;; Note that the attachment window is actually a different view of the
;; message buffer, so that if there is some failure, the attachment
;; list will be saved at the bottom of the message, as a numerical
;; list under a customizable separator.
;;
;; The files will be added to the outgoing message by mml before it is
;; sent.


(require 'message)
(require 'mml)

(defconst tach-sep  --attachments follow this line--)

(defconst tach-line-regexp ^\\([0-9]+.\\) +\\(.+?\\) +\\(\\[.+, 
[0-9\.]+[KM]\\]\\)$)

(defvar tach-send-confirmation nil)

(defvar tach-buffer-name)
(make-variable-buffer-local 'tach-buffer-name)

(defvar tach-mode-hooks 'nil)
(make-variable-buffer-local 'tach-mode-hooks)

(defvar tach-mode-map
  (let ((map (make-sparse-keymap)))
(define-key map + 'tach-add-file)
(define-key map - 'tach-delete-file)
(define-key map \C-c\C-c 'tach-send-from-attach-buffer)
(define-key map [up] 'tach-prev-entry)
(define-key map [down] 'tach-next-entry)
(define-key map n 'tach-next-entry)
(define-key map p 'tach-prev-entry)
(define-key map \C-n 'tach-next-entry)
(define-key map \C-p 'tach-prev-entry)
map)
  Keymap for attachment mode)
(fset 'tach-mode-map tach-mode-map)

(defvar tach-minor-mode-map
  (let ((map (make-sparse-keymap)))
(define-key map \C-c\C-a  'tach-goto)
map)
  Keymap for attachment minor mode)
(fset 'tach-minor-mode-map tach-minor-mode-map)

(defun tach-mode ()
  (interactive)
  (kill-all-local-variables)
  (use-local-map 'tach-mode-map)
  (hl-line-mode 1)
  (setq