emacs-devel
[Top][All Lists]
Advanced

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

Re: Smarter M-x that filters on major-mode


From: Lars Ingebrigtsen
Subject: Re: Smarter M-x that filters on major-mode
Date: Sun, 14 Feb 2021 14:30:33 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

I've now separated all the related changes into a series of hopefully
sensible patches, and pushed to the trunk.

To summarise:

(defun foo ()
  (interactive "p" foo-mode))

is now valid, and works for both major and minor modes.  Using this is,
of course, backwards incompatible, and moreover, produces bytecode
that's not backwards compatible either.  (If it's not used, the .elc
file will still be backwards compatible.)

The general form is:

(defun foo ()
  (declare (completion PREDICATE))
  (interactive "p"))

Where PREDICATE is a function, and can be pretty much anything.  It's
called with the symbol and the current buffer as predicates.  So that
can be used for mode filtering, too, but it's kinda cumbersome, so a
short version is also provided:

(defun foo ()
  (declare (modes foo-mode))
  (interactive "p"))

This expands to the first version, and if you're writing code that
should still work in older Emacs versions, these latter two forms has to
be used.

I've tagged up eww and gnus/gnus*.el, so to look at the effect, try

emacs -Q -l eww
M-x eww TAB

in a version before and after this patch set.

The new variable 'read-extended-command-predicate' controls what's
included, and the default value is to filter out commands that's not
applicable to the current buffer.

Now go fortheth and marketh uppeth.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




reply via email to

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