From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: [PATCH] Add `org-reverse-string' Date: Sat, 26 Jan 2013 14:02:26 -0700 Message-ID: <8738xn3bfh.fsf@gmail.com> References: <87zjzv3c92.fsf@casa.home> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:43186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzCtm-0005iZ-1q for emacs-orgmode@gnu.org; Sat, 26 Jan 2013 16:02:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TzCti-00033T-JK for emacs-orgmode@gnu.org; Sat, 26 Jan 2013 16:02:49 -0500 Received: from mail-ia0-x230.google.com ([2607:f8b0:4001:c02::230]:39374) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzCti-00033H-Bg for emacs-orgmode@gnu.org; Sat, 26 Jan 2013 16:02:46 -0500 Received: by mail-ia0-f176.google.com with SMTP id i18so2417475iac.35 for ; Sat, 26 Jan 2013 13:02:45 -0800 (PST) In-Reply-To: <87zjzv3c92.fsf@casa.home> (daimrod@gmail.com's message of "Sat, 26 Jan 2013 21:44:41 +0100") 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: Daimrod Cc: emacs-orgmode@gnu.org This patch looks fine to me, although you'll need to add a `declare-function' call to the top of ob-core.el (and maybe to org-id as well) or the compiler will complain. Daimrod writes: > I needed a `reverse-string' function and I've found two in Org Mode. > `org-babel-reverse-string' and `org-id-reverse-string'. So instead of > rolling my own (I'm playing with `org-contacts.el'), I think it would > be better to unify those functions into one. > > > From e058c4fac767a5faffd8debaabc489c174eef583 Mon Sep 17 00:00:00 2001 > From: =?UTF-8?q?Gr=C3=A9goire=20Jadi?= > Date: Sat, 26 Jan 2013 21:12:54 +0100 > Subject: [PATCH] Unify `org-id-reverse-string' and `org-babel-reverse-string' > into `org-reverse-string' > > * lisp/org.el (org-reverse-string): Add `org-reverse-string' to > reverse a string. > * lisp/org-id.el: Replace `org-id-reverse-string' by > `org-reverse-string'. > * lisp/ob-core.el: Replace `org-babel-reverse-string' by `org-reverse-string' > > TINYCHANGE > --- > lisp/ob-core.el | 8 ++------ > lisp/org-id.el | 7 ++----- > lisp/org.el | 4 ++++ > 3 files changed, 8 insertions(+), 11 deletions(-) > > diff --git a/lisp/ob-core.el b/lisp/ob-core.el > index 9e4c8b1..0a495d0 100644 > --- a/lisp/ob-core.el > +++ b/lisp/ob-core.el > @@ -2495,10 +2495,6 @@ If the table is trivial, then return it as a scalar." > (match-string 1 cell)) > cell) t)) > > -(defun org-babel-reverse-string (string) > - "Return the reverse of STRING." > - (apply 'string (reverse (string-to-list string)))) > - > (defun org-babel-chomp (string &optional regexp) > "Strip trailing spaces and carriage returns from STRING. > Default regexp used is \"[ \f\t\n\r\v]\" but can be > @@ -2513,8 +2509,8 @@ overwritten by specifying a regexp as a second argument." > "Strip leading and trailing spaces and carriage returns from STRING. > Like `org-babel-chomp' only it runs on both the front and back > of the string." > - (org-babel-chomp (org-babel-reverse-string > - (org-babel-chomp (org-babel-reverse-string string) regexp)) > + (org-babel-chomp (org-reverse-string > + (org-babel-chomp (org-reverse-string string) regexp)) > regexp)) > > (defvar org-babel-org-babel-call-process-region-original nil) > diff --git a/lisp/org-id.el b/lisp/org-id.el > index b35ea5e..bb503bd 100644 > --- a/lisp/org-id.el > +++ b/lisp/org-id.el > @@ -343,7 +343,7 @@ So a typical ID could look like \"Org:4nd91V40HI\"." > (unless (org-uuidgen-p unique) > (setq unique (org-id-uuid)))) > ((eq org-id-method 'org) > - (let* ((etime (org-id-reverse-string (org-id-time-to-b36))) > + (let* ((etime (org-reverse-string (org-id-time-to-b36))) > (postfix (if org-id-include-domain > (progn > (require 'message) > @@ -376,9 +376,6 @@ So a typical ID could look like \"Org:4nd91V40HI\"." > (substring rnd 18 20) > (substring rnd 20 32)))) > > -(defun org-id-reverse-string (s) > - (mapconcat 'char-to-string (nreverse (string-to-list s)) "")) > - > (defun org-id-int-to-b36-one-digit (i) > "Turn an integer between 0 and 61 into a single character 0..9, A..Z, a..z." > (cond > @@ -432,7 +429,7 @@ and time is the usual three-integer representation of time." > (if (= 2 (length parts)) > (setq prefix (car parts) time (nth 1 parts)) > (setq prefix nil time (nth 0 parts))) > - (setq time (org-id-reverse-string time)) > + (setq time (org-reverse-string time)) > (setq time (list (org-id-b36-to-int (substring time 0 4)) > (org-id-b36-to-int (substring time 4 8)) > (org-id-b36-to-int (substring time 8 12)))) > diff --git a/lisp/org.el b/lisp/org.el > index 5033cbf..65c8c60 100644 > --- a/lisp/org.el > +++ b/lisp/org.el > @@ -21038,6 +21038,10 @@ for the search purpose." > (error "Unable to create a link to here")))) > (org-occur-in-agenda-files (regexp-quote link)))) > > +(defun org-reverse-string (string) > + "Return the reverse of STRING." > + (apply 'string (reverse (string-to-list string)))) > + > (defun org-uniquify (list) > "Remove duplicate elements from LIST." > (let (res) > -- > 1.7.10.4 -- Eric Schulte http://cs.unm.edu/~eschulte