unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH 0/2] browse-url.el: cleanup & elinks support
@ 2007-08-22  1:14 Johannes Weiner
  2007-08-22  1:16 ` [PATCH 1/2] browse-url.el: cleanup Johannes Weiner
  2007-08-22  1:19 ` [PATCH 2/2] browse-url.el: elinks support Johannes Weiner
  0 siblings, 2 replies; 9+ messages in thread
From: Johannes Weiner @ 2007-08-22  1:14 UTC (permalink / raw)
  To: Emacs development discussions

Hi,

here is a patch that adds Elinks support for browse-url.el.  Also included, a
cleanup patch that moves the common pattern of encoding URLs into a dedicated
function.

The patches are incremental.

	Hannes

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

* [PATCH 1/2] browse-url.el: cleanup
  2007-08-22  1:14 [PATCH 0/2] browse-url.el: cleanup & elinks support Johannes Weiner
@ 2007-08-22  1:16 ` Johannes Weiner
  2007-08-22  1:35   ` Magnus Henoch
  2007-08-22 21:27   ` Richard Stallman
  2007-08-22  1:19 ` [PATCH 2/2] browse-url.el: elinks support Johannes Weiner
  1 sibling, 2 replies; 9+ messages in thread
From: Johannes Weiner @ 2007-08-22  1:16 UTC (permalink / raw)
  To: Emacs development discussions

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

Hi,

this patch moves the common pattern of encoding URLs to a dedicated function.

	Hannes

[-- Attachment #2: emacs-browse-url-cleanup.patch --]
[-- Type: text/x-diff, Size: 4749 bytes --]

diff -Naur emacs.orig/lisp/net/browse-url.el emacs/lisp/net/browse-url.el
--- emacs.orig/lisp/net/browse-url.el	2007-08-22 02:38:28.000000000 +0200
+++ emacs/lisp/net/browse-url.el	2007-08-22 02:38:53.000000000 +0200
@@ -612,6 +612,21 @@
   :group 'browse-url)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; URL encoding
+
+(defun browse-url-encode-url (url)
+  "Encode all `confusing' characters in URL."
+  (let ((encoded-url (copy-seq url)))
+    (while (string-match "%" encoded-url)
+      (setq encoded-url (replace-match "%25" t t encoded-url)))
+    (while (string-match "[*\"()',=;? ]" encoded-url)
+      (setq encoded-url
+	    (replace-match (format "%%%x"
+				   (string-to-char (match-string 0 encoded-url)))
+			   t t encoded-url)))
+    encoded-url))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; URL input
 
 ;;;###autoload
@@ -684,14 +699,7 @@
 		     (or file-name-coding-system
 			 default-file-name-coding-system))))
     (if coding (setq file (encode-coding-string file coding))))
-  ;; URL-encode special chars, do % first
-  (let ((s 0))
-    (while (setq s (string-match "%" file s))
-      (setq file (replace-match "%25" t t file)
-	    s (1+ s))))
-  (while (string-match "[*\"()',=;? ]" file)
-    (let ((enc (format "%%%x" (aref file (match-beginning 0)))))
-      (setq file (replace-match enc t t file))))
+  (setq file (browse-url-encode-url file))
   (dolist (map browse-url-filename-alist)
     (when (and map (string-match (car map) file))
       (setq file (replace-match (cdr map) t nil file))))
@@ -897,11 +905,7 @@
 When called non-interactively, optional second argument NEW-WINDOW is
 used instead of `browse-url-new-window-flag'."
   (interactive (browse-url-interactive-arg "URL: "))
-  ;; URL encode any `confusing' characters in the URL.  This needs to
-  ;; include at least commas; presumably also close parens and dollars.
-  (while (string-match "[,)$]" url)
-    (setq url (replace-match
-	       (format "%%%x" (string-to-char (match-string 0 url))) t t url)))
+  (setq url (browse-url-encode-url url))
   (let* ((process-environment (browse-url-process-environment))
 	 (process
 	  (apply 'start-process
@@ -971,11 +975,7 @@
 When called non-interactively, optional second argument NEW-WINDOW is
 used instead of `browse-url-new-window-flag'."
   (interactive (browse-url-interactive-arg "URL: "))
-  ;; URL encode any `confusing' characters in the URL.  This needs to
-  ;; include at least commas; presumably also close parens and dollars.
-  (while (string-match "[,)$]" url)
-    (setq url (replace-match
-	       (format "%%%x" (string-to-char (match-string 0 url))) t t url)))
+  (setq url (browse-url-encode-url url))
   (let* ((process-environment (browse-url-process-environment))
          (process
 	  (apply 'start-process
@@ -1033,11 +1033,7 @@
 are ignored as well.  Firefox on Windows will always open the requested
 URL in a new window."
   (interactive (browse-url-interactive-arg "URL: "))
-  ;; URL encode any `confusing' characters in the URL.  This needs to
-  ;; include at least commas; presumably also close parens.
-  (while (string-match "[,)]" url)
-    (setq url (replace-match
-	       (format "%%%x" (string-to-char (match-string 0 url))) t t url)))
+  (setq url (browse-url-encode-url url))
   (let* ((process-environment (browse-url-process-environment))
 	 (process
 	  (apply 'start-process
@@ -1089,11 +1085,7 @@
 When called non-interactively, optional second argument NEW-WINDOW is
 used instead of `browse-url-new-window-flag'."
   (interactive (browse-url-interactive-arg "URL: "))
-  ;; URL encode any `confusing' characters in the URL.  This needs to
-  ;; include at least commas; presumably also close parens and dollars.
-  (while (string-match "[,)$]" url)
-    (setq url (replace-match
-	       (format "%%%x" (string-to-char (match-string 0 url))) t t url)))
+  (setq url (browse-url-encode-url))
   (let* ((process-environment (browse-url-process-environment))
          (process (apply 'start-process
 			 (concat "galeon " url)
@@ -1138,11 +1130,7 @@
 When called non-interactively, optional second argument NEW-WINDOW is
 used instead of `browse-url-new-window-flag'."
   (interactive (browse-url-interactive-arg "URL: "))
-  ;; URL encode any `confusing' characters in the URL.  This needs to
-  ;; include at least commas; presumably also close parens and dollars.
-  (while (string-match "[,)$]" url)
-    (setq url (replace-match
-	       (format "%%%x" (string-to-char (match-string 0 url))) t t url)))
+  (setq url (browse-url-encode-url url))
   (let* ((process-environment (browse-url-process-environment))
          (process (apply 'start-process
 			 (concat "epiphany " url)

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

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

* [PATCH 2/2] browse-url.el: elinks support
  2007-08-22  1:14 [PATCH 0/2] browse-url.el: cleanup & elinks support Johannes Weiner
  2007-08-22  1:16 ` [PATCH 1/2] browse-url.el: cleanup Johannes Weiner
@ 2007-08-22  1:19 ` Johannes Weiner
  2007-08-22 21:27   ` Richard Stallman
  1 sibling, 1 reply; 9+ messages in thread
From: Johannes Weiner @ 2007-08-22  1:19 UTC (permalink / raw)
  To: Emacs development discussions

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

Hi,

this patch adds `browse-url-elinks'.

	Hannes

[-- Attachment #2: emacs-browse-url-elinks.patch --]
[-- Type: text/x-diff, Size: 3167 bytes --]

diff -Naur emacs.orig/lisp/net/browse-url.el emacs/lisp/net/browse-url.el
--- emacs.orig/lisp/net/browse-url.el	2007-08-22 02:40:40.000000000 +0200
+++ emacs/lisp/net/browse-url.el	2007-08-22 02:57:32.000000000 +0200
@@ -55,6 +55,7 @@
 ;; browse-url-default-macosx-browser  Mac OS X browser
 ;; browse-url-gnome-moz               GNOME interface to Mozilla
 ;; browse-url-kde                     KDE konqueror (kfm)
+;; browse-url-elinks                  Elinks      Don't know (tried with 0.12.GIT)
 
 ;; [A version of the Netscape browser is now free software
 ;; <URL:http://www.mozilla.org/>, albeit not GPLed, so it is
@@ -263,6 +264,7 @@
 	  (function-item :tag "Grail" :value  browse-url-grail)
 	  (function-item :tag "MMM" :value  browse-url-mmm)
 	  (function-item :tag "KDE" :value browse-url-kde)
+	  (function-item :tag "Elinks" :value browse-url-elinks)
 	  (function-item :tag "Specified by `Browse Url Generic Program'"
 			 :value browse-url-generic)
 	  (function-item :tag "Default Windows browser"
@@ -611,6 +613,11 @@
   :type '(repeat (string :tag "Argument"))
   :group 'browse-url)
 
+(defcustom browse-url-elinks-wrapper '("xterm" "-e")
+  "*Wrapper command prepended to the Elinks command-line."
+  :type '(repeat (string :tag "Wrapper"))
+  :group 'browse-url)
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; URL encoding
 
@@ -1493,6 +1500,46 @@
   (apply #'start-process (concat "KDE " url) nil browse-url-kde-program
 	                 (append browse-url-kde-args (list url))))
 
+;;;###autoload
+(defun browse-url-elinks (url)
+  "Ask the Elinks WWW browser to load URL.
+Default to the URL around the point.
+
+The document is loaded in a new tab of a running Elinks or, if
+none yet running, a newly started instance.
+
+The Elinks command will be prepended by the program+arguments
+from `elinks-browse-url-wrapper'."
+  (interactive (browse-url-interactive-arg "URL: "))
+  (setq url (browse-url-encode-url url))
+  (let ((process-environment (browse-url-process-environment))
+	(elinks-ping-process (start-process "elinks-ping" nil
+					     "elinks" "-remote" "ping()")))
+    (set-process-sentinel elinks-ping-process
+			  `(lambda (process change)
+			     (browse-url-elinks-sentinel process ,url)))))
+
+(defun browse-url-elinks-sentinel (process url)
+  "Determines if Elinks is running or a new one has to be started."
+  (let ((exit-status (process-exit-status process))
+	(process-environment (browse-url-process-environment)))
+    ;; Try to determine if an instance is running or if we have to
+    ;; create a new one.
+    (case exit-status
+      (5
+       ;; No instance, start a new one.
+       (apply #'start-process
+	      (append (list (concat "elinks:" url) nil)
+		      browse-url-elinks-wrapper
+		      (list "elinks" url))))
+      (0
+       ;; Found an instance, open URL in new tab.
+       (start-process (concat "elinks:" url) nil
+		      "elinks" "-remote"
+		      (concat "openURL(\"" url "\",new-tab)")))
+      (otherwise
+       (error "Undefined exit-code of process `elinks'.")))))
+
 (provide 'browse-url)
 
 ;;; arch-tag: d2079573-5c06-4097-9598-f550fba19430

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

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

* Re: [PATCH 1/2] browse-url.el: cleanup
  2007-08-22  1:16 ` [PATCH 1/2] browse-url.el: cleanup Johannes Weiner
@ 2007-08-22  1:35   ` Magnus Henoch
  2007-08-22  1:52     ` Johannes Weiner
  2007-08-22 21:27   ` Richard Stallman
  1 sibling, 1 reply; 9+ messages in thread
From: Magnus Henoch @ 2007-08-22  1:35 UTC (permalink / raw)
  To: emacs-devel

Johannes Weiner <hannes@saeurebad.de> writes:

> this patch moves the common pattern of encoding URLs to a dedicated function.

You could also use the function `url-hexify-string' for this.

Magnus

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

* Re: [PATCH 1/2] browse-url.el: cleanup
  2007-08-22  1:35   ` Magnus Henoch
@ 2007-08-22  1:52     ` Johannes Weiner
  0 siblings, 0 replies; 9+ messages in thread
From: Johannes Weiner @ 2007-08-22  1:52 UTC (permalink / raw)
  To: Magnus Henoch; +Cc: Emacs development discussions

Hi Magnus,

On Wed, Aug 22, 2007 at 03:35:21AM +0200, Magnus Henoch wrote:
> > this patch moves the common pattern of encoding URLs to a dedicated function.
> 
> You could also use the function `url-hexify-string' for this.

`url-hexify-string' replaces too much. Even the '://' part gets hexified,
which makes the url unreadable for the browsers' user-input interfaces.

> Magnus

	Hannes

-- 
Are you looking for that "friends" stuff from C++ (if I have that
right, unless it was Java <g>). This is Lisp, we just shoot from the
hip and do not worry about that stuff.
	-- Ken Tilton

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

* Re: [PATCH 2/2] browse-url.el: elinks support
  2007-08-22  1:19 ` [PATCH 2/2] browse-url.el: elinks support Johannes Weiner
@ 2007-08-22 21:27   ` Richard Stallman
  2007-09-07  4:40     ` Glenn Morris
  0 siblings, 1 reply; 9+ messages in thread
From: Richard Stallman @ 2007-08-22 21:27 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: emacs-devel

We can add this once your copyright assignment arrives.

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

* Re: [PATCH 1/2] browse-url.el: cleanup
  2007-08-22  1:16 ` [PATCH 1/2] browse-url.el: cleanup Johannes Weiner
  2007-08-22  1:35   ` Magnus Henoch
@ 2007-08-22 21:27   ` Richard Stallman
  2007-09-07  4:41     ` Glenn Morris
  1 sibling, 1 reply; 9+ messages in thread
From: Richard Stallman @ 2007-08-22 21:27 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: emacs-devel

This patch seems good.  We can install it when your legal papers arrive.

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

* Re: [PATCH 2/2] browse-url.el: elinks support
  2007-08-22 21:27   ` Richard Stallman
@ 2007-09-07  4:40     ` Glenn Morris
  0 siblings, 0 replies; 9+ messages in thread
From: Glenn Morris @ 2007-09-07  4:40 UTC (permalink / raw)
  To: rms; +Cc: Johannes Weiner, emacs-devel

Richard Stallman wrote:

> We can add this once your copyright assignment arrives.

They arrived, I installed it.

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

* Re: [PATCH 1/2] browse-url.el: cleanup
  2007-08-22 21:27   ` Richard Stallman
@ 2007-09-07  4:41     ` Glenn Morris
  0 siblings, 0 replies; 9+ messages in thread
From: Glenn Morris @ 2007-09-07  4:41 UTC (permalink / raw)
  To: rms; +Cc: Johannes Weiner, emacs-devel

Richard Stallman wrote:

> This patch seems good.  We can install it when your legal papers arrive.

They arrived, I installed it.

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

end of thread, other threads:[~2007-09-07  4:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-22  1:14 [PATCH 0/2] browse-url.el: cleanup & elinks support Johannes Weiner
2007-08-22  1:16 ` [PATCH 1/2] browse-url.el: cleanup Johannes Weiner
2007-08-22  1:35   ` Magnus Henoch
2007-08-22  1:52     ` Johannes Weiner
2007-08-22 21:27   ` Richard Stallman
2007-09-07  4:41     ` Glenn Morris
2007-08-22  1:19 ` [PATCH 2/2] browse-url.el: elinks support Johannes Weiner
2007-08-22 21:27   ` Richard Stallman
2007-09-07  4:40     ` Glenn Morris

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

	https://git.savannah.gnu.org/cgit/emacs.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).