From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Patch to implement sorting Org tables by IP address Date: Sat, 20 Dec 2014 12:57:40 +0100 Message-ID: <87vbl6zg7f.fsf@nicolasgoaziou.fr> References: <87r3w4a326.fsf@nicolasgoaziou.fr> <87tx0z8vxw.fsf@nicolasgoaziou.fr> <42DDD6AD-8F6F-4F85-840B-4C3946AD3C55@mac.com> <87oar78ro1.fsf@nicolasgoaziou.fr> <8C2CF3B2-399D-4944-8CE9-D486EA1A0985@mac.com> <87bnn78apu.fsf@nicolasgoaziou.fr> <2217AFF8-7135-4EAC-A189-8152FDDE52F9@mac.com> <87tx0y79st.fsf@nicolasgoaziou.fr> <63EA1170-B4E2-4CB8-95CD-77AF7AA117C3@mac.com> <87ppbm6tgl.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2IeV-0006lY-9z for emacs-orgmode@gnu.org; Sat, 20 Dec 2014 06:57:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y2IeN-0000zJ-Gu for emacs-orgmode@gnu.org; Sat, 20 Dec 2014 06:56:55 -0500 Received: from relay6-d.mail.gandi.net ([2001:4b98:c:538::198]:41237) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y2IeN-0000yI-7h for emacs-orgmode@gnu.org; Sat, 20 Dec 2014 06:56:47 -0500 In-Reply-To: (Jon Snader's message of "Wed, 17 Dec 2014 12:31:55 -0500") 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Jon Snader Cc: emacs-orgmode@gnu.org Jon Snader writes: >> On Dec 14, 2014, at 12:18 PM, Nicolas Goaziou w= rote: > >>> As I said above, you=E2=80=99ve convinced me that ?f ?F is the right so= lution. >>=20 >> Fair enough. Let's settle on that, then. > > Here is the new patch. It extends org-table-sort-lines to allow a user > to specify custom extraction and comparison functions using the ?f ?F > sorting type as in org-sort-list. > > The user can call org-table-sort-lines programmatically specifying > a SORTING-TYPE of ?f or ?F and provide custom extraction and > comparison functions. If the user calls org-table-sort lines > interactively and specifies ?f or ?F, org-do-sort will prompt for > a custom extraction function. The comparison will be either string or > numeric depending on the type of the first extracted key. Thank you. Some comments follow. > -any of (?a ?A ?n ?N ?t ?T) where the capital letter indicate that sorting > -should be done in reverse order." > +any of (?a ?A ?n ?N ?t ?T ?f ?F) where the capital letter indicate > that sorting "indicates" or "capital letters" > + extractfun comparefun tempfun extract-string-p) EXTRACT-STRING-P, and possibly TEMPFUN, are bound too early. See below. > ;; Define the appropriate functions > (cond > ((=3D dcst ?n) > @@ -9075,7 +9081,7 @@ If WITH-CASE is non-nil, the sorting will be case-s= ensitive." > (setq extractfun (if with-case (lambda(x) (org-sort-remove-invisib= le x)) > (lambda(x) (downcase (org-sort-remove-invisible x)))) > comparefun (if (=3D dcst sorting-type) > - 'string< > + #'string< OK, but then there are other occurrences in the function to modify. I suggest to remove this. > + ((=3D dcst ?f) > + (setq tempfun (or getkey-func > + (intern (org-icompleting-read > + "Sort using function: " > + obarray 'fboundp t nil nil)))) > + (setq extract-string-p (stringp (funcall tempfun (caar table)))) > + (setq extractfun (if (and extract-string-p (not with-case)) > + (lambda (x) (downcase (funcall tempfun x))) > + tempfun)) > + (setq comparefun (or compare-func > + (if extract-string-p=20 > + (if (=3D sorting-type ?f) > + #'string< > + (lambda (a b) (and (not (string< a b)) > + (not (string=3D a b))))) > + (if (=3D sorting-type ?f) > + #'< > + #'>))))) I suggest something like (let* ((tempfun (or getkey-func (intern ...))) (extract-string-p (stringp (funcall tempfun (caar table))))) (setq extractfun (if (and extract-string-p (not with-case)) `(lambda (x) (downcase (funcall ',tempfun x))) tempfun)) (setq comparefun (cond (compare-func) (extract-string-p (if (=3D sorting-type ?f) #'string< #'org-= string>)) ((=3D sorting-type ?f) #'<) (t #'>)))) Regards,