help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: logical not condition in ibuffer config


From: Yuri Khan
Subject: Re: logical not condition in ibuffer config
Date: Mon, 12 Mar 2018 16:12:07 +0700

On Mon, Mar 12, 2018 at 3:17 AM, Hikaru Ichijyo <ichijyo@macross.sdf.jp> wrote:
> I've been setting up ibuffer to group my buffer listing into
> categories.  I've encountered a situation where I may want to make an
> exception to one of the rules.  This is my config:
>
> --8<---------------cut here---------------start------------->8---
>                ("Lisp & Emacs" (or
>                         (mode . emacs-lisp-mode)
>                         (mode . bookmark-bmenu-mode)
>                         (name . "^\\*Packages\\*$")))
> --8<---------------cut here---------------end--------------->8---
>
> I am finding that the "Lisp & Emacs" group catches my bbdb buffer,
> because it is in Emacs-Lisp mode, but I would rather this went to
> Default, since I rarely edit it directly.

The filtering/grouping feature in Ibuffer is written and documented
with interactive use, rather than long-term init-file-based
configuration, in mind. But you can use that to find out how it
represents filter intersection and inversion.

I will use predicates that are easier to test in an uncustomized
emacs, but the results should apply to your case as well.

So, first, I want a few buffers in emacs-lisp-mode, with a secondary
difference that I could intersect and invert.

    $ emacs -Q
    C-x C-f ~/.emacs.d/init.el RET
    M-x find-library RET ibuffer RET
    M-x ibuffer RET

Now, I have two buffers using emacs-lisp-mode. What’s more, one of
them has a file name ending in “.gz”. Let’s see how we can combine
these conditions.

    <f1> m, scroll to Filtering commands

I see a command to combine two filters with “or”, and a command to
invert a filter. I do not see a command to combine with “and”. Let’s
try adding a filter.

    / m emacs-lisp-mode RET

Something happened. I now see only buffers in emacs-lisp-mode. (The
header line shows the currently applied filter as [major mode in use:
emacs-lisp-mode].) So far so good. Now let’s add another filter, with
a condition on file name.

    / f \.gz\' RET

Now I only see the buffer that is in emacs-lisp-mode *and* with file
name ending in “.gz”. (The header line displays this as [filename:
\.gz\'] [major mode in use: emacs-lisp-mode].) Let’s try inverting.

    / !

Now I see the buffer that is in emacs-lisp-mode and with file name
*not* ending “.gz”. (The header line updates to [NOT [filename:
\.gz\']] [major mode in use: emacs-lisp-mode].)

To see how this is represented, I will save this filter:

    / s test1 RET

Emacs says: “Setting ‘ibuffer-saved-filter-groups’ temporarily since
"emacs -q" would overwrite customizations”. I understand it as “your
changes were not saved into your init file and will only be active in
this session”. Okay, let’s see the variable.

    M-: ibuffer-saved-filters RET
    ⇒ (("test1" (not filename . "\\.gz\\'")
                (used-mode . emacs-lisp-mode))
       …more filters…)

And that should answer your questions:

* For an “and”, you just write several filter expressions one after another.
* You can put “not” before the filter predicate.

> So, I want to use a 'not' condition in these rules, to say, "Put
> anything in 'Lisp & Emacs' that's in emacs-lisp-mode,
> bookmark-bmenu-mode, or is named '*Packages*', except for buffers named
> 'bbdb'."

This should be it:

    ("Lisp & Emacs"
      (not name . "^bbdb$")
      (or (mode . emacs-lisp-mode)
          (mode . bookmark-bmenu-mode)
          (name . "^\\*Packages\\*$")))



reply via email to

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