Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id AB331431FD0 for ; Mon, 16 May 2011 13:48:39 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dXqnXphCwEBM for ; Mon, 16 May 2011 13:48:38 -0700 (PDT) Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com [209.85.161.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 82E33431FB6 for ; Mon, 16 May 2011 13:48:38 -0700 (PDT) Received: by fxm8 with SMTP id 8so3633955fxm.26 for ; Mon, 16 May 2011 13:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:from:to:subject:user-agent:date:message-id :mime-version:content-type; bh=dQUatwj5VDymTesho25Nt0rBXN/S3kVoMSPiQYUfV6s=; b=dkcgNlup1dRvlHnfq0ygszMxFB5vjL3HWgsbuuLScTVDrzP1vMQhQc1P19Atz1EdCU Jlzqytx8dVBT7hKP5DsTKUVaksJIGq7IhL4bTA4BrJDclq+yyHRHM+ibUu2LupeQoc4/ G1EsAPTVCTwx/docNCl4zphTGgq7UR7SpuQw4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:subject:user-agent:date:message-id:mime-version :content-type; b=oSOXpSSK1sizbIkCEnhoGficGtfa259my4yiTCKNY4qwr4htjTMK61rs/0GmJNzFib OvTGSyyveILrNorUx8Eoy+tHj9VUEpJhs4N6m1BjlKPAHw6Ud9EQLqxTvpqVZl2zghKn 4dd0CI3kD+WRqp8lgh56kZ5ccAIGEESfeNZSo= Received: by 10.223.44.86 with SMTP id z22mr6051078fae.3.1305578917016; Mon, 16 May 2011 13:48:37 -0700 (PDT) Received: from localhost (dslb-088-069-136-251.pools.arcor-ip.net [88.69.136.251]) by mx.google.com with ESMTPS id 22sm185741fay.45.2011.05.16.13.48.35 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 16 May 2011 13:48:35 -0700 (PDT) From: Daniel Schoepe To: notmuch@notmuchmail.org Subject: [PATCH] emacs: Add notmuch-before/after-tag-hook User-Agent: Notmuch/0.5-209-gc8b5718 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Mon, 16 May 2011 22:48:24 +0200 Message-ID: <87pqnis76v.fsf@gilead.home.box> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 May 2011 20:48:39 -0000 --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable From=20the commit message: emacs: add notmuch-before- and notmuch-after-tag-hook =20=20=20=20 This patch adds hooks that are run before/after messages are tagged from the emacs interface. In order to implement this and to avoid having hooks parse all the arguments to the notmuch binary again, I created a `notmuch-tag' function that other modules should use instead of running (notmuch-call-notmuch-process "tag" ...) directly. I wasn't sure about adding the notmuch-tag function, but I think it is a bit cleaner than calling notmuch-call-notmuch-process directly in so many places anyway. Of course, any comments or criticism is appreciated. =2D- Daniel --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-emacs-add-notmuch-before-and-notmuch-after-tag-hook.patch Content-Transfer-Encoding: quoted-printable From=201acc99736a84e5294ba44368690dd79001e2e347 Mon Sep 17 00:00:00 2001 From: Daniel Schoepe Date: Sun, 15 May 2011 17:48:58 +0200 Subject: [PATCH] emacs: add notmuch-before- and notmuch-after-tag-hook This patch adds hooks that are run before/after messages are tagged From=20the emacs interface. In order to implement this and to avoid having hooks parse all the arguments to the notmuch binary again, I created a `notmuch-tag' function that other modules should use instead of running (notmuch-call-notmuch-process "tag" ...) directly. =2D-- emacs/notmuch-message.el | 3 +-- emacs/notmuch-show.el | 12 ++++-------- emacs/notmuch.el | 45 +++++++++++++++++++++++++++++++++++++++++-= --- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el index d5c96c2..aefd3fb 100644 =2D-- a/emacs/notmuch-message.el +++ b/emacs/notmuch-message.el @@ -44,8 +44,7 @@ the \"inbox\" and \"todo\", you would set (concat "+" str) str)) notmuch-message-replied-tags))) =2D (apply 'notmuch-call-notmuch-process "tag" =2D (append tags (list (concat "id:" (car (car rep)))) nil)))))) + (apply 'notmuch-tag (concat "id:" (car (car rep))) tags))))) =20 (add-hook 'message-send-hook 'notmuch-message-mark-replied) =20 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 825988c..2b905c8 100644 =2D-- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -1273,10 +1273,8 @@ the result." (new-tags (notmuch-show-add-tags-worker current-tags toadd))) =20 (unless (equal current-tags new-tags) =2D (apply 'notmuch-call-notmuch-process =2D (append (cons "tag" =2D (mapcar (lambda (s) (concat "+" s)) toadd)) =2D (cons (notmuch-show-get-message-id) nil))) + (apply 'notmuch-tag (notmuch-show-get-message-id) + (mapcar (lambda (s) (concat "+" s)) toadd)) (notmuch-show-set-tags new-tags)))) =20 (defun notmuch-show-remove-tag (&rest toremove) @@ -1289,10 +1287,8 @@ the result." (new-tags (notmuch-show-del-tags-worker current-tags toremove))) =20 (unless (equal current-tags new-tags) =2D (apply 'notmuch-call-notmuch-process =2D (append (cons "tag" =2D (mapcar (lambda (s) (concat "-" s)) toremove)) =2D (cons (notmuch-show-get-message-id) nil))) + (apply 'notmuch-tag (notmuch-show-get-message-id) + (mapcar (lambda (s) (concat "-" s)) toremove)) (notmuch-show-set-tags new-tags)))) =20 (defun notmuch-show-toggle-headers () diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 1d683f8..837136d 100644 =2D-- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -465,6 +465,44 @@ and will also appear in a buffer named \"*Notmuch erro= rs*\"." (error (buffer-substring beg end)) )))))) =20 +(defun notmuch-tag (query &rest tags) + "Add/remove tags in TAGS to messages matching QUERY. + +TAGS should be a list of strings of the form \"+TAG\" or \"-TAG\" and +QUERY should be a string containing the search-query. + +Note: Other code should always use this function alter tags of +messages instead of running (notmuch-call-notmuch-process \"tag\" ..) +directly, so that hooks specified in notmuch-before-tag-hook and +notmuch-after-tag-hook will be run." + (run-hooks 'notmuch-before-tag-hook) + (apply 'notmuch-call-notmuch-process + (append (list "tag") tags (list "--" query))) + (run-hooks 'notmuch-after-tag-hook)) + +(defcustom notmuch-before-tag-hook nil + "Hooks that are run before tags of a message are modified. + +'tags' will contain the tags that are about to be added or removed as +a list of strings of the form \"+TAG\" or \"-TAG\". +'query' will be a string containing the search query that determines +the messages that are about to be tagged" + + :type 'hook + :options '(hl-line-mode) + :group 'notmuch) + +(defcustom notmuch-after-tag-hook nil + "Hooks that are run before tags of a message are modified. + +'tags' will contain the tags that were added or removed as +a list of strings of the form \"+TAG\" or \"-TAG\". +'query' will be a string containing the search query that determines +the messages that were tagged" + :type 'hook + :options '(hl-line-mode) + :group 'notmuch) + (defun notmuch-search-set-tags (tags) (save-excursion (end-of-line) @@ -504,7 +542,7 @@ and will also appear in a buffer named \"*Notmuch error= s*\"." =20 (defun notmuch-search-add-tag-region (tag beg end) (let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread= -id-region beg end) " or "))) =2D (notmuch-call-notmuch-process "tag" (concat "+" tag) search-id-strin= g) + (notmuch-tag search-id-string (concat "+" tag)) (save-excursion (let ((last-line (line-number-at-pos end)) (max-line (- (line-number-at-pos (point-max)) 2))) @@ -518,7 +556,7 @@ and will also appear in a buffer named \"*Notmuch error= s*\"." =20 (defun notmuch-search-remove-tag-region (tag beg end) (let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread= -id-region beg end) " or "))) =2D (notmuch-call-notmuch-process "tag" (concat "-" tag) search-id-strin= g) + (notmuch-tag search-id-string (concat "-" tag)) (save-excursion (let ((last-line (line-number-at-pos end)) (max-line (- (line-number-at-pos (point-max)) 2))) @@ -815,8 +853,7 @@ characters as well as `_.+-'. (unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words)) (error "Action must be of the form `+thistag -that_tag'")) (setq words (cdr words)))) =2D (apply 'notmuch-call-notmuch-process "tag" =2D (append action-split (list notmuch-search-query-string) nil)))) + (apply 'notmuch-tag notmuch-search-query-string action-split))) =20 (defun notmuch-search-buffer-title (query) "Returns the title for a buffer with notmuch search results." =2D-=20 1.7.5.1 --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAEBAgAGBQJN0Y2ZAAoJEIaTAtce+Z+JAO8P/32zq9QfBtgD4yaGm5bpttMo W5dwt4J+pUOhW5lRpEh4cAJXhLFpLL5ZO45fGcdhJyVuwsgbxfiCg9op833Noqad 4ATPKbsiyXOOM4ihfjlZlJjPm/23Rmtk7JinAoN76ltGp+J5sZdmVdan8A9uzreX 5wLtFiRCNAL/J60/ZlTNr3aXvNr2vlXfLKyGuVAarpiP0xhhjaCGk3GhTTfT/beb w3sS/ZPM91II0Dm4u+M5nA1RVeesg04G8tS81mqrnnxIrB05Yun8riAUg/6sKMxD lrCtOqf9Bs11P9IpFdHb446ATwS7etBKuErlSG2e+Q+cPHSKkkmGkSAogznMMpEY sk2x7maauUlxw4/hb3vHWgE//uoHEVQgQd0+gmSwCsipM10Wn79kfVXNjxKcFrT1 v8u/iTQ/gsJ52bnbDORJJ/qlmigED+nsHPGTLekx/m9465G6+pw6jrRbgFrawAuU EZImqHp47gIcK9wtQl38aNJYFpekm3zK1SQPjZw4dbTaWSryVvLXk1co9W9W+qvh GWInRH37UE2CjKzCWmDAzrFKTq2Q7o2i2qWmTC+sWfbC349vmu2YxEpswy5sYbeA 24wBy7MUR8pYUIJta2o2pY15VSZh36eWORq31UzUX8ON2b8W8jyNpkGqQXj06bYc VSIo06Kbe9/OgVOERHk+ =Z8Ko -----END PGP SIGNATURE----- --==-=-=--