Initial Query

In emacs lisp how do I silence "Process python-process finished"

LLM Generation

Query

In emacs lisp how do I silence "Process python-process finished"

Output

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)
    
*Or, slightly more robustly, you might only silence exit messages:*
 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))
    
Choose `my-silent-process-sentinel` for complete silence from the sentinel, or `my-silent-finish-sentinel` to only silence the exit messages. 2. **Use the Sentinel When Starting the Process:** Modify your call to `start-process` (or similar) to include the `:sentinel` keyword argument.
 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
     )
    
**Method 2: Modify the Sentinel of an Existing Process** If the process named "python-process" is already running (perhaps started by another package or part of your code), you can try to change its sentinel *after* it has started using `set-process-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.")))
**Caveats for Method 2:** * **Timing:** You need to execute this code *before* the process finishes. If it's a short-lived process, this might be difficult. * **Overwriting:** If the code that started the process relies on its own sentinel for cleanup or other actions, replacing it entirely with a do-nothing sentinel might break things. Using `my-silent-finish-sentinel` might be slightly safer in this case, but still potentially problematic. * **Package Interference:** If the process is managed by a package, the package might reset the sentinel later, undoing your change. It's generally better to configure the package itself if it provides options for process handling. **In summary:** The best approach is to specify your custom, silent sentinel using the `:sentinel` keyword when you initially call `start-process` or a related function.

Substring Evaluation

Testing if the previous output contains the string set-process-sentinel: True