[emacs-berlin] Magic magit

Tilmann Singer tils at tils.net
Thu Oct 1 21:34:48 UTC 2015

It was, indeed. Thanks for telling me about completing-read. In case you
or anyone else is interested, below is the code that I use it in now: a
function to quickly clear the notmuch inbox, by archiving the email and
creating an org TODO entry for it. Feedback as usual welcome.

cheers, Til

(defun notmuch-stuff-create ()
  "Quickly move an email from the inbox into org. Creates an org
TODO entry with a link to the current email, and archives the
current email. It prompts for the target org file, prefilled with
best guess as default, based on rules in
  (let* (
         (link (org-store-link nil))
          (completing-read "Org file: " (org-agenda-files) nil t nil
                           'notmuch-stuff-files (notmuch-stuff--guess-org-file))))

    (with-current-buffer (find-file-noselect org-file)
        (org-insert-heading nil nil t)
        (org-todo "TODO")
        (insert link)
        (org-set-tags-to ":mail:")
        ;; NOTE: tags should already be aligned, but they are not. This
        ;; doesn't work either: (org-set-tags nil t)
        (org-set-tags nil t)
        (org-insert-time-stamp (current-time) nil t)
    (notmuch-show-tag-all (list "-inbox"))
    (message (concat "Created TODO entry in " org-file))))

(define-key notmuch-show-mode-map (kbd "C-c t") 'notmuch-stuff-create)

(defun notmuch-stuff-create-from-search ()
  "From a notmuch search buffer, call notmuch-stuff-create for the mail on the current line"

(define-key notmuch-search-mode-map (kbd "C-c t") 'notmuch-stuff-create-from-search)

(defun notmuch-stuff--guess-org-file ()
  "Guess which org file an email belongs to, fall back to projects"
  (let (
        (subject (or (notmuch-show-get-subject) ""))
        (from (or (notmuch-show-get-from) ""))
        (to (or (notmuch-show-get-to) ""))
        (cc (or (notmuch-show-get-cc) "")))

          ;; some conditions snipped

          ((string-match-p "@emacs-berlin\\.org" to) "~/org/emacs.org")
          ((string-match-p "@emacs-berlin\\.org" cc) "~/org/emacs.org")
          ((string-match-p "\\[rubycorns\\]" subject) "~/org/railsgirls.org")
          ((string-match-p "\\[rorganize\\.it\\]" subject) "~/org/railsgirls.org")
          ((string-match-p "@railsgirlsberlin\\.de" to) "~/org/railsgirls.org")
          ((string-match-p "@railsgirlsberlin\\.de" cc) "~/org/railsgirls.org")
          ((string-match-p "@railsgirlsberlin\\.de" from) "~/org/railsgirls.org")
          (t "~/org/projects.org"))))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: <http://mailb.org/pipermail/emacs-berlin/attachments/20151001/f72230a5/attachment.sig>

More information about the emacs-berlin mailing list