emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rename `eww' to `web'


From: Stefan Monnier
Subject: Re: Rename `eww' to `web'
Date: Fri, 05 Jul 2013 07:02:18 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

> So I think it makes sense to go straight to `eww' for that case: opening
> a URL with `C-x C-f'.  Like I said, it's DWIMmery.  There will be a
> small percentage of users unhappy with it, who will want to just view
> the file, and we should make that easy (I guessed `find-file-literally'
> incorrectly but it can be something simple to set in `url-handler-mode'
> defcustoms).  The key thing is that there are no command names to
> discover--opening a URL Just Works.

I currently use C-x C-f with url-handler-mode on a regular basis to open
PDF, tarballs, and Elisp files.  Sometime it gets it wrong because it
only uses the URL name rather than the content-type metadata to choose
the major mode, but want to make sure this keeps working.

But I don't see any reason why this should collide with using eww in
other cases: eww can't do anything particularly useful with PDF,
tarballs and Elisp code anyway.

> GM> emacs -Q -f url-handler-mode
> GM> C-x C-f ftp://ftp.gnu.org
> GM> C-x C-f http://www.gnu.org
> Yup.  The necessary changes to make this usable IMHO are:
> 1) make it call `eww' by default and provide for a way to instead look
> at file contents (current behavior, right?)

Why would you want to use eww for all URLs, since it only handles HTML
in a useful way, AFAIU?

> 2) enable `url-handler-mode' by default

Fine by me (BTW, I've been using the hack below to ape completion
on http URLs).


        Stefan


Using submit branch file:///home/monnier/src/emacs/bzr/trunk/
=== modified file 'lisp/url/url-handlers.el'
--- lisp/url/url-handlers.el    2013-05-22 07:30:44 +0000
+++ lisp/url/url-handlers.el    2013-05-24 19:52:40 +0000
@@ -311,11 +311,45 @@
 (put 'insert-file-contents 'url-file-handlers 'url-insert-file-contents)
 
 (defun url-file-name-completion (url directory &optional predicate)
-  (error "Unimplemented"))
+  (let ((all (url-file-name-all-completions url directory)))
+    (if (null all)
+        ;; If `url' is the empty string, don't return nil, so as to prevent
+        ;; partial-completion from recursing into the parent directory.
+        (if (equal url "") url)
+      (try-completion url all predicate))))
 (put 'file-name-completion 'url-file-handlers 'url-file-name-completion)
 
 (defun url-file-name-all-completions (file directory)
-  (error "Unimplemented"))
+  ;; FIXME: Cache the "directory" buffers between completion requests.
+  (let ((buf (get-file-buffer directory)))
+    (unless buf
+      (setq buf (ignore-errors (find-file-noselect directory)))
+      (when buf
+        (with-current-buffer buf
+          (set (make-local-variable 'url-handler-temp-buf) t))))
+    (when buf
+      (unwind-protect
+          (with-current-buffer buf
+            (save-excursion
+              (let ((all ())
+                    (case-fold-search t)
+                    ;; FIXME: Handle URL-quoting.
+                    (regexp (format "<a href=\"\\(%s[^\"]+\\)\"" file)))
+                (goto-char (point-min))
+                (while (re-search-forward regexp nil t)
+                  (let ((url (match-string 1)))
+                    (unless (string-match
+                             "\\`\\(?:\\.\\.\\|[#?/]\\|[-a-z]+:/\\)\\|" url)
+                      ;; It's a relative URL.
+                      (when (string-match "[#?]\\|/\\(.\\)" url)
+                        (setq url (substring url (or (match-beginning 1)
+                                                     (match-beginning 0)))))
+                      ;; FIXME: Handle URL-unquoting.
+                      (push url all))))
+                all)))
+        (and (buffer-live-p buf)
+             (buffer-local-value 'url-handler-temp-buf buf)
+             (kill-buffer buf))))))
 (put 'file-name-all-completions
      'url-file-handlers 'url-file-name-all-completions)
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]