You're right, this version didn't work for many reasons. Once we get cl-defgeneric to work, we can fix it to work by return value, as you suggest... João On Sat, Oct 26, 2019, 17:12 Stefan Monnier wrote: > > +(cl-defgeneric completion-adjust-metadata-for-style (style metadata) > > + "Adjust METADATA of current completion according to STYLE." > > + (:method (_style _metadata) nil) ; nop by default > > Hmm... if "nop" is to return nil, it means it works by side-effect, but > if the metadata is `nil` to start with, there's no side-effect that can > turn it into a non-nil value, right? > > So I think it should work by returning a new metadata and hence "nop" > should be to return `metadata` unmodified. > > > + (let ((alist (cdr metadata))) > > + (setf (alist-get 'display-sort-function alist) > > + (compose-flex-sort-fn (alist-get 'display-sort-function > alist))) > > + (setf (alist-get 'cycle-sort-function alist) > > + (compose-flex-sort-fn (alist-get 'cycle-sort-function > alist))) > > This works by side-effecting the alist, but those entries may (and > usually) come from immediate constants in the code, so this is > like "self-modifying code" :-( > > > + metadata)))) > > I see here you do return the metadata, good. > > > + (result-and-style > > + (completion--some > > + (lambda (style) > > + (let ((probe (funcall (nth n (assq style > > + completion-styles-alist)) > > + string table pred point))) > > + (and probe (cons probe style)))) > > + (completion--styles metadata)))) > > + (completion-adjust-metadata-for-style (cdr result-and-style) > metadata) > > (if requote > > But here it appears you're not using the return value, unless I'm > missing something. > > > Stefan > >