emacs-erc
[Top][All Lists]
Advanced

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

declarative syntax to ERC show/hide messages by "type"


From: Corwin Brust
Subject: declarative syntax to ERC show/hide messages by "type"
Date: Thu, 10 Dec 2020 20:09:22 -0600

Hello.   This is a question for now, rather than any specific
completed solution.  I do have some things working or semi-working
which have "driven me" to reach out in hope of consultation in
approaching design.  Please let me know, on or off list as you think
best, if you want to see more sources than I show initially here.

Focusing on ERC, my goal facets, which probably are given here in
roughly descending importance:

1. I'd like to be able to interactively toggle individual messages for
type (e.g. QUIT, JOIN, AWAY, etc.) using text properties, or similar,
so I can reveal or hide them temporarily in a given buffer.

2. I'd like to be able to "declare" my settings such as persona,
network, channel, maybe pal, etc, at various of the levels where these
terms/concepts intersect.  (E.g. we can remember we want to hide only
NICK lines in the buffer for #freenode on chat.freenode.net and when
the current nick is "DrBigBuffer".)   The logic here needs to take the
most specific applicable setting I've expressed as it's default when
e.g. creating a buffer or prompting me though an interactive change.

3. I should be able to make these declarations interactively, via
customize, and in elisp and pay as little or as much attention to how
Emacs persists my changes as I'd like.  Notwithstanding elapsed time
before anything that could come from this may be enabled by ERC
defaults, the goal is a path toward sticky settings backed by
declarative and/or literate forms which can be written by customize or
"by hand".

In the on other lists there been a little discussion of the problem
space I'm meaning to get at with this last one, but for those who may
not have followed that (list/topic), there's a contention between
elisp init forms and customize, especially it can be difficult to keep
track of matters such as order of initialization or confusing if
different features are partially customized, and partially setup via
init.el or whathaveyou.

This is particularly a challenge for the use-pacakge/leaf integration
project which exposes "keywords", (i.e.directives, functionality)
directly interfacing with customize but that effectively forces users
to manually disassemble customize statements to continue using it at
all once implementing e.g. use-package).

My hope in proposing this last point is to provide within ERC,
something of a living experiment toward a more general solution
declarative "grammars" that, perhaps somewhat automatically, provides
a "fuller", "stickier" customize and or coding experience.   Since
this seems to some degree like "the hard part", I'll add also here a
couple of ideas that I thought might help, which isn't to say that
they are particularly novel: first, using lexical binding of
custom-file, probably setting the var from an alist, perhaps someday
someday allowing custom-file itself to hold an alist, for keyed on
custom group; and second: we could at least start out assuming lots of
tiny files.   Granting, things could potentially get hairy fast, I
think ERC might make a util and fertile ground to play around with
this stuff.

In any case, in my own experimentation, I was able to get pretty much
the desired feature (e.g. hiding and showing messages based on
membership in a list of types), using buffer-invisibility-spec.  This
required "taking over" from erc-stamp custody of the 'invisible' text
property, which otherwise conflicted when timestamps were enabled.

I was able to achieve this with a small hack into erc.el (attached
with an extra) plus an additional bit in my init scripts, as such:

#+BEGIN_SRC emacs-lisp
;; init stuff to hide instead of ignore various codes
(defun my:erc-add-invisibility ()
  "Use `buffer-invisibility-spec' to hide messages by type.

Requires our hack to create an erc-type text property within
`erc-display-message'."
  (let* ((inhibit-read-only t)
(new (get-text-property (- (point-max) 2) 'erc-type))
(old (get-text-property (+ (point-min) 2) 'invisible))
(inv (if old (if (listp old)
  (append old (list new))
(list old new))
new)))
    (add-text-properties (point-min) (point-max)
(list 'invisible inv))))

(add-hook 'erc-insert-post-hook #'my:erc-add-invisibility)
#+END_SRC

I also have a semi working interactive command that may, if it
cooperates, provide a per buffer customization that is then retained
for reuse if I Custom-save.  Once it does cooperate it should be easy
enough to make it also DTRT when called from e.g. erc-join-hook.

Finally, for those who may find it useful, here's a defvar that should
maybe be a defconst? that I have in my init scripts as part of playing
around with this.

#+BEGIN_SRC emacs-lisp
(defvar my:erc-types
  '((sQUIT :string "QUIT" :documentation "Quit message to channel")
    (sMODE :string "MODE" :documentation "Mode for channel")
    (sJOIN :string "JOIN" :documentation "Join channel")
    (sPART :string "PART" :documentation "Part channel")
    (sKICK :string "KICK" :documentation "Kick from channel")
    (sNICK :string "NICK" :documentation "Nick chat")
    (s301  :string "301"  :documentation "Away notice")
    (s305  :string "305"  :documentation "Return from awayness")
    (s306  :string "306"  :documentation "Set awayness")
    (s324  :string "324"  :documentation "Channel modes on join ")
    (s329  :string "329"  :documentation "Channel creation date")
    (s332  :string "332"  :documentation "Topic notice")
    (s333  :string "333"  :documentation "Who set the topic")
    (s353  :string "353"  :documentation "Names notice"))
  "List of ERC message types for visibility toggle.")

(defvar my:erc-channel-hide-types
  '((t :equal (sPART sJOIN sQUIT s301 sNICK)))
  "Alist mapping channels to messages to hide when joining.

Keys are strings naming channels or the the special entry t,
which provides a default or starting list of message types, as
symbols.  Possible keys include :equal which supplies a list and
causes defaults to be ignored, :and which supplements the
default list, and :not which filters the list so far.")
#+END_SRC

As an aside, in case it is unclear: this RFC would be different
behavior from erc-hide-list (or erc-track-exclude-types) which aiu
discard messages of the undesired types.

Please let me know your thoughts, questions, and ideas.  And thanks to
Amin and the many various IRC and points etc. for encouragement and
wisdom.  As always, these fine people likely wrote the great bits of
any particularly handy code I shared, except the many typos which
obviously I have carefully added all by myself. :)

Regards,
-- 
Corwin
corwin@bru.st

Attachment: erc-type_and_erc-yank_01.patch
Description: Binary data


reply via email to

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