* bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer @ 2016-12-29 19:13 Eric Abrahamsen 2016-12-30 4:35 ` npostavs 2017-12-12 1:39 ` Noam Postavsky 0 siblings, 2 replies; 10+ messages in thread From: Eric Abrahamsen @ 2016-12-29 19:13 UTC (permalink / raw) To: 25294 When defining a method using cl-defmethod with the &context and major-mode specializer, 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. These signatures don't work, but should: (cl-defmethod example-method ((&context (major-mode fundamental-mode)))) (cl-defmethod example-method ((&context (major-mode nil))) (cl-defmethod example-method ((&context (major-mode t)))) Right now the only thing that works is: (cl-defmethod example-method ()) In GNU Emacs 26.0.50.9 (x86_64-unknown-linux-gnu, GTK+ Version 3.22.5) of 2016-12-26 built on clem Repository revision: 65b997b95e284e2edc1266663e39791f68d76ad7 Windowing system distributor 'The X.Org Foundation', version 11.0.11804000 Recent messages: Reading active file via nndraft...done Reading active file from MTester via nnmairix...done Checking new news...done Saving the EBDB... done Saving Gnus registry (4516 entries) to ~/Documents/Sync/plusone/gnus.registry.eieio... Saving Gnus registry (size 4516) to ~/Documents/Sync/plusone/gnus.registry.eieio...done Saving /home/eric/.emacs.d/.newsrc.eld... Saving file /home/eric/.emacs.d/.newsrc.eld... Wrote /home/eric/.emacs.d/.newsrc.eld Saving /home/eric/.emacs.d/.newsrc.eld...done Configured features: XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GCONF GSETTINGS NOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 LIBSYSTEMD Important settings: value of $LC_CTYPE: zh_CN.UTF-8 value of $LANG: en_US.UTF-8 value of $XMODIFIERS: @im=fcitx locale-coding-system: utf-8-unix ^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer 2016-12-29 19:13 bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer Eric Abrahamsen @ 2016-12-30 4:35 ` npostavs 2017-12-11 23:57 ` Eric Abrahamsen 2017-12-12 1:39 ` Noam Postavsky 1 sibling, 1 reply; 10+ messages in thread From: npostavs @ 2016-12-30 4:35 UTC (permalink / raw) To: Eric Abrahamsen; +Cc: 25294 Eric Abrahamsen <eric@ericabrahamsen.net> writes: > When defining a method using cl-defmethod with the &context and > major-mode specializer, 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))". > 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? > 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. > (cl-defmethod example-method ((&context (major-mode nil))) > > (cl-defmethod example-method ((&context (major-mode t)))) > > Right now the only thing that works is: > > (cl-defmethod example-method ()) ^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer 2016-12-30 4:35 ` npostavs @ 2017-12-11 23:57 ` Eric Abrahamsen 2017-12-12 0:08 ` Noam Postavsky 0 siblings, 1 reply; 10+ messages in thread From: Eric Abrahamsen @ 2017-12-11 23:57 UTC (permalink / raw) To: npostavs; +Cc: 25294 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. ^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer 2017-12-11 23:57 ` Eric Abrahamsen @ 2017-12-12 0:08 ` Noam Postavsky 0 siblings, 0 replies; 10+ messages in thread From: Noam Postavsky @ 2017-12-12 0:08 UTC (permalink / raw) To: Eric Abrahamsen; +Cc: 25294 Eric Abrahamsen <eric@ericabrahamsen.net> writes: > 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. It's had lots of time to rest then :) >> 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". Still not really convinced by this, what's wrong with the last way you put in your OP: (cl-defmethod example-method ()) ^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer 2016-12-29 19:13 bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer Eric Abrahamsen 2016-12-30 4:35 ` npostavs @ 2017-12-12 1:39 ` Noam Postavsky 2017-12-12 1:43 ` Noam Postavsky 2017-12-12 5:42 ` Eric Abrahamsen 1 sibling, 2 replies; 10+ messages in thread From: Noam Postavsky @ 2017-12-12 1:39 UTC (permalink / raw) To: 25294; +Cc: Eric Abrahamsen [-- Attachment #1: Type: text/plain, Size: 22 bytes --] [forwarding to list] [-- Attachment #2: Type: message/rfc822, Size: 2127 bytes --] From: Eric Abrahamsen <eric@ericabrahamsen.net> To: Noam Postavsky <npostavs@users.sourceforge.net> Subject: Re: bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer Date: Mon, 11 Dec 2017 16:49:14 -0800 Message-ID: <87y3m8rcs5.fsf@ericabrahamsen.net> On 12/11/17 19:08 PM, Noam Postavsky wrote: > Eric Abrahamsen <eric@ericabrahamsen.net> writes: > >> 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. > > It's had lots of time to rest then :) > >>> 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". > > Still not really convinced by this, what's wrong with the last way you > put in your OP: > > (cl-defmethod example-method ()) A year later, older and wiser, I agree that maybe all that's needed is more documentation. I just noticed that, at some point in the interim, the documentation for generic functions has been greatly expanded, which is nice! I'd like to add the following to the docs: 1. The &context thing has to come after the required arguments, but before any &optional or &rest things. 2. You can have an arbitrary number of forms following &context. 3. The &context arguments don't have to match the declared arguments in `cl-defgeneric'. 4. Ergo they can be left off altogether without needing to be specifically declared as nil or what have you, ie, my original bug report isn't really a bug. If this looks okay, I'll have at the docs. Eric ^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer 2017-12-12 1:39 ` Noam Postavsky @ 2017-12-12 1:43 ` Noam Postavsky 2017-12-12 5:42 ` Eric Abrahamsen 1 sibling, 0 replies; 10+ messages in thread From: Noam Postavsky @ 2017-12-12 1:43 UTC (permalink / raw) To: 25294; +Cc: Eric Abrahamsen > From: Eric Abrahamsen <eric@ericabrahamsen.net> > Subject: Re: bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer > To: Noam Postavsky <npostavs@users.sourceforge.net> > Date: Mon, 11 Dec 2017 16:49:14 -0800 (51 minutes, 9 seconds ago) > >> Still not really convinced by this, what's wrong with the last way you >> put in your OP: >> >> (cl-defmethod example-method ()) > > A year later, older and wiser, I agree that maybe all that's needed is > more documentation. I just noticed that, at some point in the interim, > the documentation for generic functions has been greatly expanded, which > is nice! > > I'd like to add the following to the docs: > > 1. The &context thing has to come after the required arguments, but > before any &optional or &rest things. > 2. You can have an arbitrary number of forms following &context. > 3. The &context arguments don't have to match the declared arguments in > `cl-defgeneric'. > 4. Ergo they can be left off altogether without needing to be > specifically declared as nil or what have you, ie, my original bug > report isn't really a bug. > > If this looks okay, I'll have at the docs. Sounds good to me. ^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer 2017-12-12 1:39 ` Noam Postavsky 2017-12-12 1:43 ` Noam Postavsky @ 2017-12-12 5:42 ` Eric Abrahamsen 2017-12-12 23:58 ` Noam Postavsky 1 sibling, 1 reply; 10+ messages in thread From: Eric Abrahamsen @ 2017-12-12 5:42 UTC (permalink / raw) To: Noam Postavsky; +Cc: 25294 [-- Attachment #1: Type: text/plain, Size: 933 bytes --] Noam Postavsky <npostavs@users.sourceforge.net> writes: > [forwarding to list] Whoops, sorry. [...] >> A year later, older and wiser, I agree that maybe all that's needed is >> more documentation. I just noticed that, at some point in the interim, >> the documentation for generic functions has been greatly expanded, which >> is nice! >> >> I'd like to add the following to the docs: >> >> 1. The &context thing has to come after the required arguments, but >> before any &optional or &rest things. >> 2. You can have an arbitrary number of forms following &context. >> 3. The &context arguments don't have to match the declared arguments in >> `cl-defgeneric'. >> 4. Ergo they can be left off altogether without needing to be >> specifically declared as nil or what have you, ie, my original bug >> report isn't really a bug. >> >> If this looks okay, I'll have at the docs. > Sounds good to me. Here's my diff. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: context-spec-docs.diff --] [-- Type: text/x-patch, Size: 1910 bytes --] diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi index 466a12f7a4..6b98a3d639 100644 --- a/doc/lispref/functions.texi +++ b/doc/lispref/functions.texi @@ -1252,15 +1252,21 @@ Generic Functions Extensions for GNU Emacs Lisp}), or of one of its parent classes. @end table -Alternatively, the argument specializer can be of the form -@code{&context (@var{expr} @var{spec})}, in which case the value of -@var{expr} must be compatible with the specializer provided by -@var{spec}; @var{spec} can be any of the forms described above. In -other words, this form of specializer uses the value of @var{expr} -instead of arguments for the decision whether the method is -applicable. For example, @code{&context (overwrite-mode (eql t))} -will make the method compatible only when @code{overwrite-mode} is -turned on. +Generic functions provide a new argument-list keyword, +@code{&context}, which can be used to introduce extra specializers +that test the general environment in which the method is run. This +keyword should appear after the list of required arguments, but before +any @code{&rest} or @code{&optional} keywords. The @code{&context} +specializers look much like regular argument +specializers---(@var{expr} @var{spec})---except that @var{expr} is an +expression to be evaluated in the current context, and the @var{spec} +is a value to compare against. For example, @code{&context +(overwrite-mode (eql t))} will make the method applicable only when +@code{overwrite-mode} is turned on. The @code{&context} keyword can +be followed by any number of context specializers. Because the +context specializers are not part of the generic function's required +argument signature, they may be omitted in methods that don't require +them. The type specializer, @code{(@var{arg} @var{type})}, can specify one of the @dfn{system types} in the following list. When a parent type ^ permalink raw reply related [flat|nested] 10+ messages in thread
* bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer 2017-12-12 5:42 ` Eric Abrahamsen @ 2017-12-12 23:58 ` Noam Postavsky 2017-12-14 0:06 ` Eric Abrahamsen 2017-12-14 21:01 ` Eric Abrahamsen 0 siblings, 2 replies; 10+ messages in thread From: Noam Postavsky @ 2017-12-12 23:58 UTC (permalink / raw) To: Eric Abrahamsen; +Cc: 25294 Eric Abrahamsen <eric@ericabrahamsen.net> writes: > +Generic functions provide a new argument-list keyword, The way you phrased this might lead me to think that the &context keyword should go in the cl-defgeneric form (maybe it's not so bad when seeing in context under cl-defmethod, in patch form it's a bit disconnected). > +@code{&context}, which can be used to introduce extra specializers > +that test the general environment in which the method is run. This > +keyword should appear after the list of required arguments, but before > +any @code{&rest} or @code{&optional} keywords. I wonder if it would be clearer to add this to the @defmac header? @defmac cl-defmethod name [qualifier] arguments [&context (expr spec)@dots{}] &rest [docstring] body Hmm, maybe that ends up being too long. > The @code{&context} > +specializers look much like regular argument > +specializers---(@var{expr} @var{spec})---except that @var{expr} is an > +expression to be evaluated in the current context, and the @var{spec} > +is a value to compare against. For example, @code{&context > +(overwrite-mode (eql t))} will make the method applicable only when > +@code{overwrite-mode} is turned on. The @code{&context} keyword can > +be followed by any number of context specializers. Because the > +context specializers are not part of the generic function's required > +argument signature, they may be omitted in methods that don't require > +them. Otherwise looks fine. ^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer 2017-12-12 23:58 ` Noam Postavsky @ 2017-12-14 0:06 ` Eric Abrahamsen 2017-12-14 21:01 ` Eric Abrahamsen 1 sibling, 0 replies; 10+ messages in thread From: Eric Abrahamsen @ 2017-12-14 0:06 UTC (permalink / raw) To: Noam Postavsky; +Cc: 25294 Noam Postavsky <npostavs@users.sourceforge.net> writes: > Eric Abrahamsen <eric@ericabrahamsen.net> writes: > >> +Generic functions provide a new argument-list keyword, > > The way you phrased this might lead me to think that the &context > keyword should go in the cl-defgeneric form (maybe it's not so bad when > seeing in context under cl-defmethod, in patch form it's a bit > disconnected). Maybe so, yes. I'll look at it in context and see if I can't make that a little clearer. >> +@code{&context}, which can be used to introduce extra specializers >> +that test the general environment in which the method is run. This >> +keyword should appear after the list of required arguments, but before >> +any @code{&rest} or @code{&optional} keywords. > > I wonder if it would be clearer to add this to the @defmac header? > > @defmac cl-defmethod name [qualifier] arguments [&context (expr spec)@dots{}] &rest [docstring] body > > Hmm, maybe that ends up being too long. I never found those things very helpful, and that does look a little long... ^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer 2017-12-12 23:58 ` Noam Postavsky 2017-12-14 0:06 ` Eric Abrahamsen @ 2017-12-14 21:01 ` Eric Abrahamsen 1 sibling, 0 replies; 10+ messages in thread From: Eric Abrahamsen @ 2017-12-14 21:01 UTC (permalink / raw) To: Noam Postavsky; +Cc: 25294 close 25294 quit On 12/12/17 18:58 PM, Noam Postavsky wrote: > Eric Abrahamsen <eric@ericabrahamsen.net> writes: > >> +Generic functions provide a new argument-list keyword, > > The way you phrased this might lead me to think that the &context > keyword should go in the cl-defgeneric form (maybe it's not so bad when > seeing in context under cl-defmethod, in patch form it's a bit > disconnected). > >> +@code{&context}, which can be used to introduce extra specializers >> +that test the general environment in which the method is run. This >> +keyword should appear after the list of required arguments, but before >> +any @code{&rest} or @code{&optional} keywords. > > I wonder if it would be clearer to add this to the @defmac header? > > @defmac cl-defmethod name [qualifier] arguments [&context (expr spec)@dots{}] &rest [docstring] body > > Hmm, maybe that ends up being too long. > >> The @code{&context} >> +specializers look much like regular argument >> +specializers---(@var{expr} @var{spec})---except that @var{expr} is an >> +expression to be evaluated in the current context, and the @var{spec} >> +is a value to compare against. For example, @code{&context >> +(overwrite-mode (eql t))} will make the method applicable only when >> +@code{overwrite-mode} is turned on. The @code{&context} keyword can >> +be followed by any number of context specializers. Because the >> +context specializers are not part of the generic function's required >> +argument signature, they may be omitted in methods that don't require >> +them. > > Otherwise looks fine. > Okay, that's pushed, I ended up adding the bit to the defmac statement after all, it wraps and shouldn't be too big a deal. Thanks, Eric ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2017-12-14 21:01 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-12-29 19:13 bug#25294: 26.0.50; Allow more catch-all values for cl-defmethod's &context plus major-mode specializer Eric Abrahamsen 2016-12-30 4:35 ` npostavs 2017-12-11 23:57 ` Eric Abrahamsen 2017-12-12 0:08 ` Noam Postavsky 2017-12-12 1:39 ` Noam Postavsky 2017-12-12 1:43 ` Noam Postavsky 2017-12-12 5:42 ` Eric Abrahamsen 2017-12-12 23:58 ` Noam Postavsky 2017-12-14 0:06 ` Eric Abrahamsen 2017-12-14 21:01 ` Eric Abrahamsen
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.