emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Small improvement of maintainability of link escaping
@ 2013-10-05 13:04 Michael Brand
  2013-10-05 13:31 ` Michael Brand
  2013-11-17 12:04 ` Michael Brand
  0 siblings, 2 replies; 5+ messages in thread
From: Michael Brand @ 2013-10-05 13:04 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 232 bytes --]

Hi all

I would like to ask to review and apply the attached patch. It is to
have a timely separatation from a related change that I will suggest
with an ERT in a later patch: Just add "+" to
org-link-escape-chars-browser.

Michael

[-- Attachment #2: 0001-org-table-transpose-table-at-point-Preserve-indentat.patch.txt --]
[-- Type: text/plain, Size: 2090 bytes --]

From 119aad10f2144a1397f2b034bef46dc891dbae5a Mon Sep 17 00:00:00 2001
From: Michael Brand <michael.ch.brand@gmail.com>
Date: Mon, 30 Sep 2013 20:32:29 +0200
Subject: [PATCH] org-table-transpose-table-at-point: Preserve indentation and
 point

* lisp/org-table.el (org-table-transpose-table-at-point): Preserve
indentatinon of first row. Restore point to transposed field in
transposed table.
---
 lisp/org-table.el | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 5bc754c..7be77cc 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -1834,7 +1834,7 @@ blindly applies a recipe that works for simple tables."
 	  (goto-char beg)))))
 
 (defun org-table-transpose-table-at-point ()
-  "Transpose orgmode table at point and eliminate hlines.
+  "Transpose Org table at point and eliminate hlines.
 So a table like
 
 | 1 | 2 | 4 | 5 |
@@ -1849,9 +1849,11 @@ will be transposed as
 | 4 | c | g |
 | 5 | d | h |
 
-Note that horizontal lines disappeared."
+Note that horizontal lines disappear."
   (interactive)
   (let* ((table (delete 'hline (org-table-to-lisp)))
+	 (dline_old (org-table-current-line))
+	 (col_old (org-table-current-column))
 	 (contents (mapcar (lambda (p)
 			     (let ((tp table))
 			       (mapcar
@@ -1861,10 +1863,17 @@ Note that horizontal lines disappeared."
 				    (setq tp (cdr tp))))
 				table)))
 			   (car table))))
-    (delete-region (org-table-begin) (org-table-end))
-    (insert (mapconcat (lambda(x) (concat "| " (mapconcat 'identity x " | " ) "  |\n" ))
-                       contents ""))
-    (org-table-align)))
+    (goto-char (org-table-begin))
+    (re-search-forward "|")
+    (backward-char)
+    (delete-region (point) (org-table-end))
+    (insert (mapconcat
+	     (lambda(x)
+	       (concat "| " (mapconcat 'identity x " | " ) "  |\n" ))
+	     contents ""))
+    (org-table-goto-line col_old)
+    (org-table-goto-column dline_old))
+  (org-table-align))
 
 ;;;###autoload
 (defun org-table-wrap-region (arg)
-- 
1.7.12.4 (Apple Git-37)


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

* Re: [PATCH] Small improvement of maintainability of link escaping
  2013-10-05 13:04 [PATCH] Small improvement of maintainability of link escaping Michael Brand
@ 2013-10-05 13:31 ` Michael Brand
  2013-10-16 13:49   ` Michael Brand
  2013-11-17 12:04 ` Michael Brand
  1 sibling, 1 reply; 5+ messages in thread
From: Michael Brand @ 2013-10-05 13:31 UTC (permalink / raw)
  To: Org Mode

[-- Attachment #1: Type: text/plain, Size: 97 bytes --]

Sorry, I attached the wrong patch (the other one that is waiting in
another thread), here again.

[-- Attachment #2: 0001-Small-improvement-of-maintainability-of-link-escapin.patch.txt --]
[-- Type: text/plain, Size: 5047 bytes --]

From 6d5f603058211ade3b5db118cb3a7d04fbf52a6e Mon Sep 17 00:00:00 2001
From: Michael Brand <michael.ch.brand@gmail.com>
Date: Sat, 5 Oct 2013 15:00:25 +0200
Subject: [PATCH] Small improvement of maintainability of link escaping

* lisp/org.el (org-link-escape-chars): Add comment with escape numbers
alphabetically ordered.
(org-link-escape-chars-browser): Add comment with escape numbers.
(org-link-escape): Use better readable char constant instead of number
constant for percent char.
(org-link-escape-browser): New function to substitute duplicate source
code.
(org-open-at-point): Substitute duplicate source code.
* testing/README: Make comment in source code example clearer.
* testing/lisp/test-org.el (test-org/org-link-escape-chars-browser):
Change URL to real use case and use the new function
`org-link-escape-browser'.
---
 lisp/org.el              | 32 ++++++++++++++------------------
 testing/README           |  4 ++--
 testing/lisp/test-org.el |  8 +++++---
 3 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 5ff9969..9149441 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9732,11 +9732,13 @@ according to FMT (default from `org-email-link-description-format')."
 	  "]"))
 
 (defconst org-link-escape-chars
-  '(?\ ?\[ ?\] ?\; ?\= ?\+)
+  ;;%20 %2B %3B %3D %5B %5D
+  '(?\  ?\+ ?\; ?\= ?\[ ?\])
   "List of characters that should be escaped in link.
 This is the list that is used for internal purposes.")
 
 (defconst org-link-escape-chars-browser
+  ;;%20 %22
   '(?\  ?\")
   "List of escapes for characters that are problematic in links.
 This is the list that is used before handing over to the browser.")
@@ -9758,7 +9760,7 @@ If optional argument MERGE is set, merge TABLE into
   (mapconcat
    (lambda (char)
      (if (or (member char table)
-	     (and (or (< char 32) (= char 37) (> char 126))
+	     (and (or (< char 32) (= char ?\%) (> char 126))
 		  org-url-hexify-p))
 	 (mapconcat (lambda (sequence-element)
 		      (format "%%%.2X" sequence-element))
@@ -9767,6 +9769,13 @@ If optional argument MERGE is set, merge TABLE into
 			       (char-to-string char))) "")
        (char-to-string char))) text ""))
 
+(defun org-link-escape-browser (text)
+  (if (org-string-match-p
+       (concat "[[:nonascii:]" org-link-escape-chars-browser "]")
+       text)
+      (org-link-escape text org-link-escape-chars-browser)
+    text))
+
 (defun org-link-unescape (str)
   "Unhex hexified Unicode strings as returned from the JavaScript function
 encodeURIComponent.  E.g. `%C3%B6' is the german o-Umlaut."
@@ -10467,24 +10476,11 @@ application the system uses for this file type."
 	      (apply cmd (nreverse args1))))
 
 	   ((member type '("http" "https" "ftp" "news"))
-	    (browse-url
-	     (concat type ":"
-		     (if (org-string-match-p
-			  (concat "[[:nonascii:]"
-				  org-link-escape-chars-browser "]")
-			  path)
-			 (org-link-escape path org-link-escape-chars-browser)
-		       path))))
+	    (browse-url (concat type ":" (org-link-escape-browser path))))
 
 	   ((string= type "doi")
-	    (browse-url
-	     (concat org-doi-server-url
-		     (if (org-string-match-p
-			  (concat "[[:nonascii:]"
-				  org-link-escape-chars-browser "]")
-			  path)
-			 (org-link-escape path org-link-escape-chars-browser)
-		       path))))
+	    (browse-url (concat org-doi-server-url
+				(org-link-escape-browser path))))
 
 	   ((member type '("message"))
 	    (browse-url (concat type ":" path)))
diff --git a/testing/README b/testing/README
index 9601ea7..e25a109 100644
--- a/testing/README
+++ b/testing/README
@@ -64,9 +64,9 @@ load and run the test suite with the following commands.
    Use this as a demo example of a failing test
    #+BEGIN_SRC emacs-lisp
      (ert-deftest test-org/org-link-escape-ascii-character-demo-of-fail ()
-       (should (string= "%5B"  ;; expected is right
+       (should (string= "%5B"  ;; expecting %5B is right
                         (org-link-escape "[")))
-       (should (string= "%5C"  ;; expected is wrong, "%5D" would be right
+       (should (string= "%5C"  ;; expecting %5C is wrong, %5D right
                         (org-link-escape "]"))))
    #+END_SRC
    or evaluate the ert-deftest form of the test you want to run.  Then
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index b6c5558..32fa69e 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -524,9 +524,11 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
   "Escape a URL to pass to `browse-url'."
   (should
    (string=
-    "http://some.host.com/search?q=%22Org%20mode%22"
-    (org-link-escape "http://some.host.com/search?q=\"Org mode\""
-		     org-link-escape-chars-browser))))
+    (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
+	    "%22Release%208.2%22&idxname=emacs-orgmode")
+    (org-link-escape-browser
+     (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
+	     "\"Release 8.2\"&idxname=emacs-orgmode")))))
 
 
 \f
-- 
1.7.12.4 (Apple Git-37)


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

* Re: [PATCH] Small improvement of maintainability of link escaping
  2013-10-05 13:31 ` Michael Brand
@ 2013-10-16 13:49   ` Michael Brand
  2013-10-17  5:02     ` Carsten Dominik
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Brand @ 2013-10-16 13:49 UTC (permalink / raw)
  To: Org Mode

Hi all

On Sat, Oct 5, 2013 at 3:31 PM, Michael Brand
<michael.ch.brand@gmail.com> wrote:
> Sorry, I attached the wrong patch (the other one that is waiting in
> another thread), here again.

I would like to remind to review and apply the patch attached on
[2013-10-05 Sat] to this thread
(0001-Small-improvement-of-maintainability-of-link-escapin.patch.txt).

Michael

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

* Re: [PATCH] Small improvement of maintainability of link escaping
  2013-10-16 13:49   ` Michael Brand
@ 2013-10-17  5:02     ` Carsten Dominik
  0 siblings, 0 replies; 5+ messages in thread
From: Carsten Dominik @ 2013-10-17  5:02 UTC (permalink / raw)
  To: Michael Brand; +Cc: Org Mode

[-- Attachment #1: Type: text/plain, Size: 538 bytes --]

Hi Michael,

applied, sorry for the delay, and thanks!

- Carsten

On 16.10.2013, at 15:49, Michael Brand <michael.ch.brand@gmail.com> wrote:

> Hi all
> 
> On Sat, Oct 5, 2013 at 3:31 PM, Michael Brand
> <michael.ch.brand@gmail.com> wrote:
>> Sorry, I attached the wrong patch (the other one that is waiting in
>> another thread), here again.
> 
> I would like to remind to review and apply the patch attached on
> [2013-10-05 Sat] to this thread
> (0001-Small-improvement-of-maintainability-of-link-escapin.patch.txt).
> 
> Michael
> 


[-- Attachment #2: Message signed with OpenPGP using GPGMail --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

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

* Re: [PATCH] Small improvement of maintainability of link escaping
  2013-10-05 13:04 [PATCH] Small improvement of maintainability of link escaping Michael Brand
  2013-10-05 13:31 ` Michael Brand
@ 2013-11-17 12:04 ` Michael Brand
  1 sibling, 0 replies; 5+ messages in thread
From: Michael Brand @ 2013-11-17 12:04 UTC (permalink / raw)
  To: Org Mode

On Sat, Oct 5, 2013 at 3:04 PM, Michael Brand
<michael.ch.brand@gmail.com> wrote:
> [...] related change that I will suggest with an ERT in a later
> patch: Just add "+" to org-link-escape-chars-browser.

For the records: This approach is wrong, for the better one see
http://lists.gnu.org/archive/html/emacs-orgmode/2013-11/msg00686.html

Michael

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

end of thread, other threads:[~2013-11-17 12:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-05 13:04 [PATCH] Small improvement of maintainability of link escaping Michael Brand
2013-10-05 13:31 ` Michael Brand
2013-10-16 13:49   ` Michael Brand
2013-10-17  5:02     ` Carsten Dominik
2013-11-17 12:04 ` Michael Brand

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