unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: David Bremner <david@tethera.net>,
	Tomi Ollila <tomi.ollila@iki.fi>,
	Matt Armstrong <marmstrong@google.com>,
	notmuch@notmuchmail.org
Subject: [PATCH 3/9] emacs: wrap process-lines
Date: Sun, 29 Aug 2021 12:23:29 -0700	[thread overview]
Message-ID: <20210829192335.4192305-4-david@tethera.net> (raw)
In-Reply-To: <20210829192335.4192305-1-david@tethera.net>

Initially just set the working directory, to avoid (the implicit)
call-process crashing when the default-directory points to a
non-existent location.

Use of a macro here is over-engineering for this change, but the same
change needs to be applied to several other process creation
primitives.
---
 emacs/notmuch-address.el | 2 +-
 emacs/notmuch-draft.el   | 2 +-
 emacs/notmuch-hello.el   | 6 +++---
 emacs/notmuch-lib.el     | 9 +++++++++
 emacs/notmuch-tree.el    | 2 +-
 emacs/notmuch.el         | 2 +-
 6 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 9fc13bc5..1a4cdda2 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -217,7 +217,7 @@ requiring external commands."
       ;; harvest if necessary.
       (notmuch-address-harvest-trigger)))
    (t
-    (process-lines notmuch-address-command original))))
+    (notmuch--process-lines notmuch-address-command original))))
 
 (defun notmuch-address-expand-name ()
   (cond
diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index a68b7d8d..1f156746 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -239,7 +239,7 @@ applied to newly inserted messages)."
 (defun notmuch-draft-resume (id)
   "Resume editing of message with id ID."
   ;; Used by command `notmuch-show-resume-message'.
-  (let* ((tags (process-lines notmuch-command "search" "--output=tags"
+  (let* ((tags (notmuch--process-lines notmuch-command "search" "--output=tags"
 			      "--exclude=false" id))
 	 (draft (equal tags (notmuch-update-tags tags notmuch-draft-tags))))
     (when (or draft
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 1e66555b..450cfcfb 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -494,7 +494,7 @@ diagonal."
 		    (widget-get widget :notmuch-search-oldest-first)))))
 
 (defun notmuch-saved-search-count (search)
-  (car (process-lines notmuch-command "count" search)))
+  (car (notmuch--process-lines notmuch-command "count" search)))
 
 (defun notmuch-hello-tags-per-line (widest)
   "Determine how many tags to show per line and how wide they
@@ -746,7 +746,7 @@ Complete list of currently available key bindings:
 		    (list (cons tag
 				(concat "tag:"
 					(notmuch-escape-boolean-term tag))))))
-	     (process-lines notmuch-command "search" "--output=tags" "*")))
+	     (notmuch--process-lines notmuch-command "search" "--output=tags" "*")))
 
 (defun notmuch-hello-insert-header ()
   "Insert the default notmuch-hello header."
@@ -784,7 +784,7 @@ Complete list of currently available key bindings:
 		   :help-echo "Refresh"
 		   (notmuch-hello-nice-number
 		    (string-to-number
-		     (car (process-lines notmuch-command "count")))))
+		     (car (notmuch--process-lines notmuch-command "count")))))
     (widget-insert " messages.\n")))
 
 (defun notmuch-hello-insert-saved-searches ()
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index c7bb2091..928286c3 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -860,6 +860,15 @@ You may need to restart Emacs or upgrade your notmuch package."))
       ;; `notmuch-logged-error' does not return.
       ))))
 
+(defmacro notmuch--apply-with-env (func &rest args)
+  `(let ((default-directory "~"))
+     (apply ,func ,@args)))
+
+(defun notmuch--process-lines (program &rest args)
+  "Wrap process-lines, binding DEFAULT-DIRECTORY to a safe
+default"
+  (notmuch--apply-with-env #'process-lines program args))
+
 (defun notmuch-call-notmuch--helper (destination args)
   "Helper for synchronous notmuch invocation commands.
 
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 2f508128..49192e95 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -1098,7 +1098,7 @@ the same as for the function notmuch-tree."
 				   (concat " and (" query-context ")"))))
 	 (sort-arg (if oldest-first "--sort=oldest-first" "--sort=newest-first"))
 	 (message-arg (if unthreaded "--unthreaded" "--entire-thread")))
-    (when (equal (car (process-lines notmuch-command "count" search-args)) "0")
+    (when (equal (car (notmuch--process-lines notmuch-command "count" search-args)) "0")
       (setq search-args basic-query))
     (notmuch-tag-clear-cache)
     (let ((proc (notmuch-start-notmuch
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 739cb93b..c81155e6 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -935,7 +935,7 @@ See `notmuch-tag' for information on the format of TAG-CHANGES."
 PROMPT is the string to prompt with."
   (let* ((all-tags
 	  (mapcar (lambda (tag) (notmuch-escape-boolean-term tag))
-		  (process-lines notmuch-command "search" "--output=tags" "*")))
+		  (notmuch--process-lines notmuch-command "search" "--output=tags" "*")))
 	 (completions
 	  (append (list "folder:" "path:" "thread:" "id:" "date:" "from:" "to:"
 			"subject:" "attachment:")
-- 
2.33.0

  parent reply	other threads:[~2021-08-29 19:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-17 21:03 [Joerg Jaspert] Bug#922536: notmuch-emacs: notmuch breaks on directory removal David Bremner
2019-02-18 22:18 ` Tomi Ollila
2019-02-20 18:12   ` Matt Armstrong
2019-02-21 17:18     ` Tomi Ollila
2019-02-26 12:34       ` David Bremner
2021-08-29 19:23         ` Wrap process creating primitives with safe CWD David Bremner
2021-08-29 19:23           ` [PATCH 1/9] test/emacs: provide macro test-log-error David Bremner
2021-08-29 19:23           ` [PATCH 2/9] test/emacs: run notmuch-hello with a nonexisting default dir David Bremner
2021-08-29 19:23           ` David Bremner [this message]
2021-08-29 19:23           ` [PATCH 4/9] emacs: wrap call-process-region David Bremner
2021-08-29 19:23           ` [PATCH 5/9] test/emacs: test for notmuch-search with nonexistent CWD David Bremner
2021-08-29 19:23           ` [PATCH 6/9] emacs: wrap make-process David Bremner
2021-08-29 19:23           ` [PATCH 7/9] test/emacs: test for notmuch-show with nonexistent CWD David Bremner
2021-08-29 19:23           ` [PATCH 8/9] emacs: wrap call-process David Bremner
2021-08-29 19:23           ` [PATCH 9/9] test/emacs: tests for notmuch-{tree,unthreaded} with bad CWD David Bremner
2021-09-11 14:35           ` Wrap process creating primitives with safe CWD David Bremner
2021-09-11 14:49 ` [Joerg Jaspert] Bug#922536: notmuch-emacs: notmuch breaks on directory removal 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=20210829192335.4192305-4-david@tethera.net \
    --to=david@tethera.net \
    --cc=marmstrong@google.com \
    --cc=notmuch@notmuchmail.org \
    --cc=tomi.ollila@iki.fi \
    /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).