emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ggtags a2906b7 4/9: Allow `ggtags-global-output` to run


From: Stefan Monnier
Subject: [elpa] externals/ggtags a2906b7 4/9: Allow `ggtags-global-output` to run the process synchronously
Date: Fri, 26 Mar 2021 22:46:20 -0400 (EDT)

branch: externals/ggtags
commit a2906b7a35aa66c3c8e931155b20b8c0afc00887
Author: Nathaniel Nicandro <nathanielnicandro@gmail.com>
Commit: Leo Liu <sdl.web@gmail.com>

    Allow `ggtags-global-output` to run the process synchronously
    
    This will be useful when developing more frontends to ggtags which may need 
to
    receive a list of tag matches synchronously, such as XREF. Alternatively, a
    separate function which calls a process synchronously using something like
    `process-file` could be written, but then the ability to cancel the 
subprocess
    after a certain number of lines have been read would be lost. This is
    important, for example, when asking Global for all references to a tag which
    could have thousands of matches. Packages such as XREF cannot handle such a
    large number of matches efficiently at the moment.
---
 ggtags.el | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/ggtags.el b/ggtags.el
index 7293a26..94dc62c 100644
--- a/ggtags.el
+++ b/ggtags.el
@@ -1971,9 +1971,10 @@ ggtags: history match invalid, jump to first match 
instead")
     (and buffer-file-name ggtags-update-on-save
          (ggtags-update-tags-single buffer-file-name 'nowait))))
 
-(defun ggtags-global-output (buffer cmds callback &optional cutoff)
+(defun ggtags-global-output (buffer cmds callback &optional cutoff sync)
   "Asynchronously pipe the output of running CMDS to BUFFER.
-When finished invoke CALLBACK in BUFFER with process exit status."
+When finished invoke CALLBACK in BUFFER with process exit status.
+If SYNC is non-nil, synchronously run CMDS and call CALLBACK."
   (or buffer (error "Output buffer required"))
   (when (get-buffer-process (get-buffer buffer))
     ;; Notice running multiple processes in the same buffer so that we
@@ -2001,11 +2002,16 @@ When finished invoke CALLBACK in BUFFER with process 
exit status."
                      (when (memq (process-status proc) '(exit signal))
                        (with-current-buffer (process-buffer proc)
                          (set-process-buffer proc nil)
-                         (funcall callback (process-exit-status proc)))))))
+                         (unwind-protect
+                             (funcall callback (process-exit-status proc))
+                           (process-put proc :callback-done t)))))))
     (set-process-query-on-exit-flag proc nil)
     (and cutoff (set-process-filter proc filter))
     (set-process-sentinel proc sentinel)
-    proc))
+    (process-put proc :callback-done nil)
+    (if sync (while (not (process-get proc :callback-done))
+               (accept-process-output proc 1))
+      proc)))
 
 (cl-defun ggtags-fontify-code (code &optional (mode major-mode))
   (cl-check-type mode function)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]