unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* shell-command-sentinel hook?
@ 2024-03-04 18:00 Christopher Howard
  2024-03-04 20:08 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Christopher Howard @ 2024-03-04 18:00 UTC (permalink / raw)
  To: Emacs Devel

Hi, I was just wondering if it would be difficult/problematic to patch simple.el to provide some kind of hook so that, when async shell commands complete, users can run arbitrary elisp? I imagine this would get inserted at the end of shell-command-sentinel...?

I've been getting in the habit lately of moving my activities out of Gnome console and instead running shell commands with async-shell-command. But something I miss is that Gnome console will send a notification at the end of the command which is very visible on the desktop. This can be reproduced in Emacs by adding " && notify-send \"some message\"" onto the end of the command. This works, and could be wrapped in various ways, but it would be nice if the exit code was passed on as well to the callback. I imagine other people would come up with various other creative uses of the hook, especially if we also passed in the command string to the callback.

Am running GNU Emacs 29.1.

-- 
📛 Christopher Howard
🚀 gemini://gem.librehacker.com
🌐 http://gem.librehacker.com

בראשית ברא אלהים את השמים ואת הארץ



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: shell-command-sentinel hook?
  2024-03-04 18:00 shell-command-sentinel hook? Christopher Howard
@ 2024-03-04 20:08 ` Eli Zaretskii
  2024-03-04 20:35   ` Christopher Howard
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2024-03-04 20:08 UTC (permalink / raw)
  To: Christopher Howard; +Cc: emacs-devel

> Date: Mon, 4 Mar 2024 09:00:11 -0900
> From: Christopher Howard <christopher@librehacker.com>
> 
> Hi, I was just wondering if it would be difficult/problematic to patch simple.el to provide some kind of hook so that, when async shell commands complete, users can run arbitrary elisp? I imagine this would get inserted at the end of shell-command-sentinel...?

Why cannot you simply override shell-command-sentinel with your own
function?



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: shell-command-sentinel hook?
  2024-03-04 20:08 ` Eli Zaretskii
@ 2024-03-04 20:35   ` Christopher Howard
  2024-03-06  4:30     ` Suhail Singh
  0 siblings, 1 reply; 5+ messages in thread
From: Christopher Howard @ 2024-03-04 20:35 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

On Mon, Mar 04, 2024 at 10:08:12PM +0200, Eli Zaretskii wrote:
> Why cannot you simply override shell-command-sentinel with your own
> function?

Hi, I think I might end up doing that on my install. But, as an emacs-devel proposal, I thought it would be more useful in-general to have it available in an actual hook. (Hooks are great!) Since I cannot simply wrap shell-command-sentinel (it does not return the message and signal) my overide would need to reproduce the initial part of the function...

``` elisp
  (when (memq (process-status process) '(exit signal))
    (shell-command-set-point-after-cmd (process-buffer process))
    ...etc...
```

That might break in the next emacs release if you guys change any of those functions (memq, shell-command-set-point-after-cmd, etc.) or if you guys replace the sentinel with something else.

-- 
Christopher Howard



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: shell-command-sentinel hook?
  2024-03-04 20:35   ` Christopher Howard
@ 2024-03-06  4:30     ` Suhail Singh
  2024-03-06 16:39       ` Christopher Howard
  0 siblings, 1 reply; 5+ messages in thread
From: Suhail Singh @ 2024-03-06  4:30 UTC (permalink / raw)
  To: Christopher Howard; +Cc: Eli Zaretskii, emacs-devel

Christopher Howard <christopher@librehacker.com> writes:

> my overide would need to reproduce the initial part of the function...

An :after advice would obviate that, unless I'm mistaken.  Not to imply
that a hook may not still be helpful, but IIUC the code duplication
isn't necessary.

-- 
Suhail



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: shell-command-sentinel hook?
  2024-03-06  4:30     ` Suhail Singh
@ 2024-03-06 16:39       ` Christopher Howard
  0 siblings, 0 replies; 5+ messages in thread
From: Christopher Howard @ 2024-03-06 16:39 UTC (permalink / raw)
  To: Suhail Singh; +Cc: Eli Zaretskii, emacs-devel

Okay, thank you. I already implemented the override function, following the previous advice, but that sounds like a good idea as well.

{http://gem.librehacker.com/gemlog/starlog/20240304-0.gmi}

On Tue, Mar 05, 2024 at 11:30:28PM -0500, Suhail Singh wrote:
> An :after advice would obviate that, unless I'm mistaken.  Not to imply
> that a hook may not still be helpful, but IIUC the code duplication
> isn't necessary.

-- 
Christopher Howard



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-06 16:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-04 18:00 shell-command-sentinel hook? Christopher Howard
2024-03-04 20:08 ` Eli Zaretskii
2024-03-04 20:35   ` Christopher Howard
2024-03-06  4:30     ` Suhail Singh
2024-03-06 16:39       ` Christopher Howard

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).