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

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

bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &cont


From: Eric Abrahamsen
Subject: bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer
Date: Mon, 11 Dec 2017 15:57:15 -0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Ahem, I only just noticed (a year later) that there was a response to
this when I searched for bug reports I'd opened -- sorry about that.

> Is this about the undocumented specializer mentioned in cl-generic.el?
>
>     ;;; Dispatch on major mode.
>
>     ;; Two parts:
>     ;; - first define a specializer (derived-mode <mode>) to match symbols
>     ;;   representing major modes, while obeying the major mode hierarchy.
>     ;; - then define a context-rewriter so you can write
>     ;;   "&context (major-mode c-mode)" rather than
>     ;;   "&context (major-mode (derived-mode c-mode))".

Yes, that's it.

>> there should be more acceptable options for
>> catch-all or fall-through methods. Ie, we want to create a method that
>> fires regardless of the major mode.
>
> If you want to ignore the major mode, why do you want to use the
> major-mode specializer?

It's the equivalent of the "t" branch in a `cond' statement. You write
methods to handle specific major modes, and write another method to
handle the catch-all case of "all other modes".

>> These signatures don't work, but
>> should:
>>
>> (cl-defmethod example-method ((&context (major-mode fundamental-mode))))
>>
>
> Should that be
>
>     (cl-defmethod example-method (&context (major-mode fundamental-mode)))
>
> The reason this doesn't work is because fundamental isn't actually the
> parent mode of text-mode or prog-mode, i.e., (get 'text-mode
> 'derived-mode-parent) => nil.

Right -- I still think either t or nil should do it.





reply via email to

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