Re: my:erc-predicate

"J.P." <[email protected]>
Newsgroups gmane.emacs.erc.general
Message-ID <[email protected]>
Corwin Brust <[email protected]> writes:

> Answering my own question here (maybe correctly, even!)...
>
> On Fri, Oct 6, 2023 at 10:59 AM Corwin Brust <[email protected]> wrote:
>
>  I'm using a custom command to clear my tracking indicators from modelines.
>
>  Does it seem "normal" to have a custom predicate for finding the right
>  buffer or did I miss core functionality I should use instead?

You can call `erc-get-buffer' with `erc-server-process' as the PROC
argument to find a target buffer belonging to the same network process.
The macro `erc-with-buffer' does exactly that, except it (optionally)
specifies the current `erc-server-process' for you.

  (erc-with-buffer ("#chan") (do-something))

Your `my:erc-predicate' also checks for network process connectivity,
which is something `erc-get-buffer' doesn't do. Basically, anything
built atop `erc-buffer-filter' (usually) works when offline because
`erc-server-process' should still be the same object in all buffers
associated with the (disconnected) server session. But if network
connectivity is important, you could use

  (erc-buffer-filter #'my:erc:predicate erc-server-process)

for the (seq-find ...) part of `erc-connected-p', but you'd obviously
need to tweak `my:erc-predicate' so it defaults to the current buffer
when there's no argument.

> I believe I should be using `erc-default-target' to direct an "it
> worked" message to the correct buffer following an ERC command.
> Gotchas here?

You can also use the symbol `active' as the BUFFER argument to
`erc-display-line' to make it reuse the most recent buffer to have
inserted a message during the session. When disconnected, this is most
often the server buffer.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.