(bury-buffer)
(kill-buffer)))
-(defun notmuch-documentation-first-line (symbol)
- "Return the first line of the documentation string for SYMBOL."
- (let ((doc (documentation symbol)))
- (if doc
- (with-temp-buffer
- (insert (documentation symbol t))
- (goto-char (point-min))
- (let ((beg (point)))
- (end-of-line)
- (buffer-substring beg (point))))
- "")))
-
(defun notmuch-prefix-key-description (key)
"Given a prefix key code, return a human-readable string representation.
(or (and (symbolp binding)
(get binding 'notmuch-doc))
(and (functionp binding)
- (notmuch-documentation-first-line binding))))
+ (let ((doc (documentation binding)))
+ (and doc
+ (string-match "\\`.+" doc)
+ (match-string 0 doc))))))
tail)))
tail)
(insert desc)))
(pop-to-buffer (help-buffer)))))
-(defvar notmuch-buffer-refresh-function nil
+(defvar-local notmuch-buffer-refresh-function nil
"Function to call to refresh the current buffer.")
-(make-variable-buffer-local 'notmuch-buffer-refresh-function)
(defun notmuch-refresh-this-buffer ()
"Refresh the current buffer."
;;
-(defun notmuch-remove-if-not (predicate list)
- "Return a copy of LIST with all items not satisfying PREDICATE removed."
- (let (out)
- (while list
- (when (funcall predicate (car list))
- (push (car list) out))
- (setq list (cdr list)))
- (nreverse out)))
-
(defun notmuch-plist-delete (plist property)
(let* ((xplist (cons nil plist))
(pred xplist))
(setq pred (cddr pred)))
(cdr xplist)))
-(defun notmuch-split-content-type (content-type)
- "Split content/type into 'content' and 'type'."
- (split-string content-type "/"))
-
(defun notmuch-match-content-type (t1 t2)
"Return t if t1 and t2 are matching content types, taking wildcards into account."
- (let ((st1 (notmuch-split-content-type t1))
- (st2 (notmuch-split-content-type t2)))
+ (let ((st1 (split-string t1 "/"))
+ (st2 (split-string t2 "/")))
(if (or (string= (cadr st1) "*")
(string= (cadr st2) "*"))
;; Comparison of content types should be case insensitive.
invoke `set-process-sentinel' directly on the returned process,
as that will interfere with the handling of stderr and the exit
status."
- (let (err-file err-buffer proc err-proc
- ;; Find notmuch using Emacs' `exec-path'
- (command (or (executable-find notmuch-command)
- (error "Command not found: %s" notmuch-command))))
- (if (fboundp 'make-process)
- (progn
- (setq err-buffer (generate-new-buffer " *notmuch-stderr*"))
- ;; Emacs 25 and newer has `make-process', which allows
- ;; redirecting stderr independently from stdout to a
- ;; separate buffer. As this allows us to avoid using a
- ;; temporary file and shell invocation, use it when
- ;; available.
- (setq proc (make-process
- :name name
- :buffer buffer
- :command (cons command args)
- :connection-type 'pipe
- :stderr err-buffer))
- (setq err-proc (get-buffer-process err-buffer))
- (process-put proc 'err-buffer err-buffer)
-
- (process-put err-proc 'err-file err-file)
- (process-put err-proc 'err-buffer err-buffer)
- (set-process-sentinel err-proc #'notmuch-start-notmuch-error-sentinel))
- ;; On Emacs versions before 25, there is no way to capture
- ;; stdout and stderr separately for asynchronous processes, or
- ;; even to redirect stderr to a file, so we use a trivial shell
- ;; wrapper to send stderr to a temporary file and clean things
- ;; up in the sentinel.
- (setq err-file (make-temp-file "nmerr"))
- (let ((process-connection-type nil)) ;; Use a pipe
- (setq proc (apply #'start-process name buffer
- "/bin/sh" "-c"
- "exec 2>\"$1\"; shift; exec \"$0\" \"$@\""
- command err-file args)))
- (process-put proc 'err-file err-file))
+ (let* ((command (or (executable-find notmuch-command)
+ (error "Command not found: %s" notmuch-command)))
+ (err-buffer (generate-new-buffer " *notmuch-stderr*"))
+ (proc (make-process
+ :name name
+ :buffer buffer
+ :command (cons command args)
+ :connection-type 'pipe
+ :stderr err-buffer))
+ (err-proc (get-buffer-process err-buffer)))
+ (process-put proc 'err-buffer err-buffer)
(process-put proc 'sub-sentinel sentinel)
(process-put proc 'real-command (cons notmuch-command args))
(set-process-sentinel proc #'notmuch-start-notmuch-sentinel)
+ (set-process-sentinel err-proc #'notmuch-start-notmuch-error-sentinel)
proc))
(defun notmuch-start-notmuch-sentinel (proc event)
"Process sentinel function used by `notmuch-start-notmuch'."
- (let* ((err-file (process-get proc 'err-file))
- (err-buffer (or (process-get proc 'err-buffer)
- (find-file-noselect err-file)))
- (err (and (not (zerop (buffer-size err-buffer)))
+ (let* ((err-buffer (process-get proc 'err-buffer))
+ (err (and (buffer-live-p err-buffer)
+ (not (zerop (buffer-size err-buffer)))
(with-current-buffer err-buffer (buffer-string))))
(sub-sentinel (process-get proc 'sub-sentinel))
(real-command (process-get proc 'real-command)))
(error
;; Emacs behaves strangely if an error escapes from a sentinel,
;; so turn errors into messages.
- (message "%s" (error-message-string err))))
- (when err-file (ignore-errors (delete-file err-file)))))
+ (message "%s" (error-message-string err))))))
(defun notmuch-start-notmuch-error-sentinel (proc event)
- (let* ((err-file (process-get proc 'err-file))
- ;; When `make-process' is available, use the error buffer
- ;; associated with the process, otherwise the error file.
- (err-buffer (or (process-get proc 'err-buffer)
- (find-file-noselect err-file))))
- (when err-buffer (kill-buffer err-buffer))))
-
-;; This variable is used only buffer local, but it needs to be
-;; declared globally first to avoid compiler warnings.
-(defvar notmuch-show-process-crypto nil)
-(make-variable-buffer-local 'notmuch-show-process-crypto)
+ (let ((buffer (process-buffer proc)))
+ (when (buffer-live-p buffer)
+ (kill-buffer buffer))))
+
+(defvar-local notmuch-show-process-crypto nil)
(defun notmuch-interactive-region ()
"Return the bounds of the current interactive region.