emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Add `org-reverse-string'
@ 2013-01-26 20:44 Daimrod
  2013-01-26 21:02 ` Eric Schulte
  0 siblings, 1 reply; 4+ messages in thread
From: Daimrod @ 2013-01-26 20:44 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 255 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Unify-org-id-reverse-string-and-org-babel-reverse-st.patch --]
[-- Type: text/x-diff, Size: 3734 bytes --]

From e058c4fac767a5faffd8debaabc489c174eef583 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gr=C3=A9goire=20Jadi?= <gregoire.jadi@gmail.com>
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


[-- Attachment #1.3: Type: text/plain, Size: 21 bytes --]


-- 
Daimrod/Greg

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add `org-reverse-string'
  2013-01-26 20:44 [PATCH] Add `org-reverse-string' Daimrod
@ 2013-01-26 21:02 ` Eric Schulte
  2013-01-26 21:35   ` Daimrod
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Schulte @ 2013-01-26 21:02 UTC (permalink / raw)
  To: Daimrod; +Cc: emacs-orgmode

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 <daimrod@gmail.com> 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?= <gregoire.jadi@gmail.com>
> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add `org-reverse-string'
  2013-01-26 21:02 ` Eric Schulte
@ 2013-01-26 21:35   ` Daimrod
  2013-02-13 15:33     ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Daimrod @ 2013-01-26 21:35 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 410 bytes --]

Eric Schulte <schulte.eric@gmail.com> writes:

> 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.

I've added a `declare-function' call to `ob-core.el' but I think I don't
need to add it to `org-id.el' because it already require `org.el'.

Thanks for taking time to review this patch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-Unify-org-id-reverse-string-and-org-babel-reverse-st.patch --]
[-- Type: text/x-diff, Size: 4165 bytes --]

From 91c4d0fde589e23de3bebbc4d8f95f90e85dbc14 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gr=C3=A9goire=20Jadi?= <gregoire.jadi@gmail.com>
Date: Sat, 26 Jan 2013 22:27:51 +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(org-id-new, org-id-decode): Replace
  `org-id-reverse-string' by `org-reverse-string'.
* lisp/ob-core.el(org-babel-trim): Replace `org-babel-reverse-string'
  by `org-reverse-string' and declare it.

TINYCHANGE
---
 lisp/ob-core.el |    9 +++------
 lisp/org-id.el  |    7 ++-----
 lisp/org.el     |    4 ++++
 3 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 9e4c8b1..7453955 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -91,6 +91,7 @@
 (declare-function org-escape-code-in-region "org-src" (beg end))
 (declare-function org-unescape-code-in-string "org-src" (s))
 (declare-function org-table-to-lisp "org-table" (&optional txt))
+(declare-function org-reverse-string "org" (string))
 
 (defgroup org-babel nil
   "Code block evaluation and management in `org-mode' documents."
@@ -2495,10 +2496,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 +2510,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


[-- Attachment #1.3: Type: text/plain, Size: 21 bytes --]


-- 
Daimrod/Greg

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Add `org-reverse-string'
  2013-01-26 21:35   ` Daimrod
@ 2013-02-13 15:33     ` Bastien
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2013-02-13 15:33 UTC (permalink / raw)
  To: Daimrod; +Cc: emacs-orgmode, Eric Schulte

Hi Daimrod,

Daimrod <daimrod@gmail.com> writes:

> Eric Schulte <schulte.eric@gmail.com> writes:
>
>> 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.
>
> I've added a `declare-function' call to `ob-core.el' but I think I don't
> need to add it to `org-id.el' because it already require `org.el'.
>
> Thanks for taking time to review this patch.

I've applied this patch, thanks!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-02-13 15:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-26 20:44 [PATCH] Add `org-reverse-string' Daimrod
2013-01-26 21:02 ` Eric Schulte
2013-01-26 21:35   ` Daimrod
2013-02-13 15:33     ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).