In emacs lisp how do I silence "Process python-process finished"
In emacs lisp how do I silence "Process python-process finished"
Okay, the message "Process X finished" typically comes from the default **process sentinel** in Emacs. A sentinel is a function that Emacs calls when the state of an asynchronous process changes (e.g., it receives output, exits, gets a signal). To silence this specific message for your "python-process", you need to provide a custom sentinel function when you start the process (or modify the sentinel of an existing process) that *doesn't* display this message upon termination. Here are the common ways to do it: **Method 1: Provide a Custom Sentinel When Starting the Process (Recommended)** This is the cleanest way if you are the one starting the process using functions like `start-process` or `start-process-shell-command`. 1. **Define a Silent Sentinel Function:** This function will be called when the process state changes, but it will simply do nothing when the process finishes.
1 2 3 4 5 6 7 | (defun my-silent-process-sentinel (process event) "A process sentinel that does nothing, silencing default messages." ;; This function intentionally does nothing. ;; The default sentinel would typically print messages based on the 'event'. ;; We ignore the 'process' and 'event' arguments. nil) |
1 2 3 4 5 6 7 8 9 10 | (defun my-silent-finish-sentinel (process event) "Process sentinel that silences 'finished' or 'exited' messages." (unless (or (string-match-p "\\(finished\\|exited\\|killed\\|failed\\)" event)) ;; Optionally, you could add code here to handle *other* events ;; if needed, or even call the default sentinel for non-exit events, ;; though that's more complex. For just silencing the finish ;; message, doing nothing on exit events is sufficient. ;; (message "Process %s event: %s" (process-name process) event) ;; Example debug nil)) |
1 2 3 4 5 6 7 8 9 10 11 12 | ;; Example: Starting a python process silently (start-process "python-process" ; Process name nil ; Buffer or nil (nil means discard output) "python" ; Program "-c" "import time; time.sleep(1); print('Done')" ; Arguments ;; Use your custom sentinel :sentinel #'my-silent-process-sentinel ;; Or use the one that only silences finish messages: ;; :sentinel #'my-silent-finish-sentinel ) |
1 2 3 4 5 6 7 8 9 10 | ;; First, define one of the sentinel functions from Method 1, e.g.: (defun my-silent-process-sentinel (process event) "A process sentinel that does nothing, silencing default messages." nil) ;; Then, find the process and set its sentinel: (let ((proc (get-process "python-process"))) (if proc (set-process-sentinel proc #'my-silent-process-sentinel) (message "Process 'python-process' not found."))) |
Testing if the previous output contains the string set-process-sentinel
: True