* Re: master 7fc0292: Allow completion styles to adjust completion metadata [not found] ` <20191026121259.B54E720664@vcs0.savannah.gnu.org> @ 2019-10-26 16:12 ` Stefan Monnier 2019-10-26 16:59 ` João Távora 0 siblings, 1 reply; 2+ messages in thread From: Stefan Monnier @ 2019-10-26 16:12 UTC (permalink / raw To: emacs-devel; +Cc: João Távora > +(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 ^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: master 7fc0292: Allow completion styles to adjust completion metadata 2019-10-26 16:12 ` master 7fc0292: Allow completion styles to adjust completion metadata Stefan Monnier @ 2019-10-26 16:59 ` João Távora 0 siblings, 0 replies; 2+ messages in thread From: João Távora @ 2019-10-26 16:59 UTC (permalink / raw To: Stefan Monnier; +Cc: emacs-devel [-- Attachment #1: Type: text/plain, Size: 1983 bytes --] 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 <monnier@iro.umontreal.ca> 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 > > [-- Attachment #2: Type: text/html, Size: 2616 bytes --] ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-10-26 16:59 UTC | newest] Thread overview: 2+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <20191026121258.26047.33907@vcs0.savannah.gnu.org> [not found] ` <20191026121259.B54E720664@vcs0.savannah.gnu.org> 2019-10-26 16:12 ` master 7fc0292: Allow completion styles to adjust completion metadata Stefan Monnier 2019-10-26 16:59 ` João Távora
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.