jwiegley / emacs-async

Simple library for asynchronous processing in Emacs
GNU General Public License v3.0
828 stars 68 forks source link

Allow overriding of connection type? #102

Open alphapapa opened 6 years ago

alphapapa commented 6 years ago

Hi John,

I'm having a problem using rg with async-start-process: https://github.com/BurntSushi/ripgrep/issues/951

I tried to bind process-connection-type around async-start-process, but it has no effect because async-start-process rebinds it to nil before calling start-process. However, when I do this, it works:

(defun argh-start-process (name program finish-func &rest program-args)
  "Start the executable PROGRAM asynchronously.  See `async-start'.
PROGRAM is passed PROGRAM-ARGS, calling FINISH-FUNC with the
process object when done.  If FINISH-FUNC is nil, the future
object will return the process object when the program is
finished.  Set DEFAULT-DIRECTORY to change PROGRAM's current
working directory."
  (let* ((buf (generate-new-buffer (concat "*" name "*")))
         ;; NOTE: Removed let-binding of process-connection-type.
         (proc (apply #'start-process name buf program program-args)))
    (with-current-buffer buf
      (set (make-local-variable 'async-callback) finish-func)
      (set-process-sentinel proc #'async-when-done)
      (unless (string= name "emacs")
        (set (make-local-variable 'async-callback-for-process) t))
      proc)))

(let ((default-directory directory)
      (process-connection-type 'pty))
  (argh-start-process "rg-scan-async" "nice"
                      (apply-partially #'magit-todos--rg-scan-async-callback magit-status-buffer)
                      "-n5"
                      "rg" "--column" magit-todos-ag-search-regexp))

Is there a reason it doesn't allow the connection type to be changed? If not, could it?

Thanks.

thierryvolpiatto commented 6 years ago

alphapapa notifications@github.com writes:

Hi John,

I'm having a problem using rg with async-start-process: BurntSushi/ripgrep#951

Ripgrep in helm works perfecly called in an async process, see in helm-grep.el how it is called.

I don't understand what you want to do here, don't know also why you want to use async-start-process???

async-start-process should call "emacs" only and then inside the new emacs process, compute your code. So it is nonsense to start an emacs async to run an async-process in it, use instead directly start-process from your main emacs.

I tried to bind process-connection-type around async-start-process, but it has no effect because async-start-process rebinds it to nil before calling start-process. However, when I do this, it works:

(defun argh-start-process (name program finish-func &rest program-args) "Start the executable PROGRAM asynchronously. See `async-start'. PROGRAM is passed PROGRAM-ARGS, calling FINISH-FUNC with the process object when done. If FINISH-FUNC is nil, the future object will return the process object when the program is finished. Set DEFAULT-DIRECTORY to change PROGRAM's current working directory." (let ((buf (generate-new-buffer (concat "" name "*"))) ;; NOTE: Removed let-binding of process-connection-type. (proc (apply #'start-process name buf program program-args))) (with-current-buffer buf (set (make-local-variable 'async-callback) finish-func) (set-process-sentinel proc #'async-when-done) (unless (string= name "emacs") (set (make-local-variable 'async-callback-for-process) t)) proc)))

(let ((default-directory directory) (process-connection-type 'pty)) (argh-start-process "rg-scan-async" "nice" (apply-partially #'magit-todos--rg-scan-async-callback magit-status-buffer) "-n5" "rg" "--column" magit-todos-ag-search-regexp))

Is there a reason it doesn't allow the connection type to be changed? If not, could it?

Really hard to understand what you want to achieve here...

-- Thierry