From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kyle Meyer Subject: Re: About org-sort -> org-sort-list with custom sort function Date: Sat, 06 May 2017 22:55:15 -0400 Message-ID: <87vapd5qb0.fsf@kyleam.com> References: <87inlhhgvf.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34140) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d7CM2-0000jE-8z for emacs-orgmode@gnu.org; Sat, 06 May 2017 22:55:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d7CLz-0002Cs-2s for emacs-orgmode@gnu.org; Sat, 06 May 2017 22:55:26 -0400 Received: from pb-smtp1.pobox.com ([64.147.108.70]:65141 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d7CLy-0002CW-QP for emacs-orgmode@gnu.org; Sat, 06 May 2017 22:55:22 -0400 In-Reply-To: <87inlhhgvf.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Zhitao Gong , emacs-orgmode@gnu.org Zhitao Gong writes: > I think there is a bug in org-sort or org-sort-list function. > > If you call org-sort (C-c ^) on list items, this function will call > org-sort-list. However, org-sort calls org-sort-list with only one > argument, i.e., the with-case (see the code below) > > #+BEGIN_SRC emacs-lisp > ((org-at-item-p) (org-call-with-arg 'org-sort-list with-case)) > #+END_SRC emacs-lisp org-sort actually isn't calling org-sort-list with one argument; it's calling it interactively, while let-binding current-prefix-arg: (defsubst org-call-with-arg (command arg) "Call COMMAND interactively, but pretend prefix arg was ARG." (let ((current-prefix-arg arg)) (call-interactively command))) I'm a bit confused about why org-call-with-arg is necessary because I think call-interactively already propagates the current prefix argument, but perhaps I'm missing some subtlety here. Either way ... > The problem is that if you choose ?f (sorting with custom key function), > then org-sort-list expects another argument, the compare-func, which is > not passed to it. > > IMHO, there are two ways to solve this > > 1. Ask for the compare-func in org-sort-list, as it does for the > getkey-func. A default value could be provided for compare-func, > e.g., string<, <, etc. Or > 2. Restrict the return type to a string (or integer) so that we could > fix the compare-func I see it as a documentation issue. org-sort-list's docstring doesn't make it clear which part of the description applies to an interactive caller versus a Lisp caller. An interactive caller can choose the ?f sorting type, but they can't specify the compare-func. Entries are compared using sort-subr's default comparison behavior (see its docstring), and getkey-func has to return a value that's compatible with this behavior. And I think it's OK to not expose compare-func to the interactive caller. In cases where sort-subr's default behavior won't do and a user wants to supply a value for compare-func, they can create their own command that wraps a non-interactive org-sort-list call. What do you think? -- Kyle