unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: david@tethera.net
To: notmuch@notmuchmail.org
Cc: David Bremner <bremner@debian.org>,
	Simon Campese <notmuchmail_org@campese.de>
Subject: [PATCH] emacs: introduce notmuch-command-to-string, replace use of shell-command-to-string
Date: Fri,  8 Mar 2013 09:04:38 -0400	[thread overview]
Message-ID: <1362747878-3571-1-git-send-email-david@tethera.net> (raw)
In-Reply-To: <874nguxbvq.fsf@tu-dortmund.de>

From: David Bremner <bremner@debian.org>

This has two benefits: unified error handling, and avoiding tramp's
hooking into shell-command-string.

This seems to be a fix for id:874nguxbvq.fsf@tu-dortmund.de
---

Simon: can you check if this fixes your bug?

 emacs/notmuch-lib.el | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 270e3dc..556b1a4 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -112,13 +112,25 @@ For example, if you wanted to remove an \"inbox\" tag and add an
 		  (select-window (posn-window (event-start last-input-event)))
 		  (button-activate button)))
 
+(defun notmuch-command-to-string (&rest args)
+  "Synchronously invoke \"notmuch\" with the given list of arguments.
+
+If notmuch exits with a non-zero status, output from the process
+will appear in a buffer named \"*Notmuch errors*\" and an error
+will be signaled.
+
+Otherwise the output will be returned"
+  (with-temp-buffer
+    (let* ((status (apply #'call-process notmuch-command nil t nil args))
+	   (output (buffer-string)))
+      (notmuch-check-exit-status status (cons notmuch-command args) output)
+      output)))
+
 (defun notmuch-version ()
   "Return a string with the notmuch version number."
   (let ((long-string
 	 ;; Trim off the trailing newline.
-	 (substring (shell-command-to-string
-		     (concat notmuch-command " --version"))
-		    0 -1)))
+	 (substring (notmuch-command-to-string "--version") 0 -1))
     (if (string-match "^notmuch\\( version\\)? \\(.*\\)$"
 		      long-string)
 	(match-string 2 long-string)
@@ -127,9 +139,7 @@ For example, if you wanted to remove an \"inbox\" tag and add an
 (defun notmuch-config-get (item)
   "Return a value from the notmuch configuration."
   ;; Trim off the trailing newline
-  (substring (shell-command-to-string
-	      (concat notmuch-command " config get " item))
-	      0 -1))
+  (substring (notmuch-command-to-string "config" "get" item) 0 -1))
 
 (defun notmuch-database-path ()
   "Return the database.path value from the notmuch configuration."
-- 
1.8.2.rc1

  parent reply	other threads:[~2013-03-08 13:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-02 11:46 [BUG] inconsistent user context handling w/ tramp Simon Campese
2013-03-02 18:50 ` David Bremner
2013-03-08 13:04 ` david [this message]
2013-03-29 15:14   ` [PATCH] emacs: introduce notmuch-command-to-string, replace use of shell-command-to-string David Bremner
2013-03-29 15:54     ` Tomi Ollila
2013-04-01 13:33   ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1362747878-3571-1-git-send-email-david@tethera.net \
    --to=david@tethera.net \
    --cc=bremner@debian.org \
    --cc=notmuch@notmuchmail.org \
    --cc=notmuchmail_org@campese.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).