emacs-devel
[Top][All Lists]
Advanced

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

Re: [ELPA] New package: luwak


From: Stefan Monnier
Subject: Re: [ELPA] New package: luwak
Date: Tue, 25 Oct 2022 15:09:06 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

> It has been a while since Emacs won the Editor War^[Citations needed].
> Do you, like me, sometimes wake up in the middle of the night, feeling
> something is amiss, only to realise after M-x list-packages that there
> are not enough web browsers in ELPA for a Browser War (inside Emacs)?

It shouldn't take much work to resuscitate W3, if needed.

> luwak[1] is a simple web browser in Emacs, utilising the power of lynx
> -dump[2].  It is currently text-only and GET-only.

Sounds good.  Except I'd much prefer it tried to improve on EWW rather
than reinvent a wheel that's just as square but in a different way.

> Features:
>
> - Asynchronous loading
> - Some usual browser features: open, reload, search with a search
>   engine, follow links, go forward / backward in history, copy url of
>   the current page or link at point
> - Completion from persistent history in prompt to open a url
> - Multiple ways of rendering links: numbered, forward-sexp or hide
>   altogether
> - Quickly open a link on the page with completion for url / link id
> - imenu support, from all unindented strings (which look like
>   headings)
> - Support of storing and capturing for org mode, guessing the title
>   (first imenu item)
> - Write the dump of the current page to a file
> - Render a buffer containing a lynx dump in the luwak mode
> - Browse with or without torsocks

Many of those features seem independent from whether the rendering is
done by w3m, lynx, shr, ...
So could you try and merge this code with that of EWW.
More specifically:
- Divide your code into a "backend" part that deals with calling lynx, and
  a frontend part which provides features by analysing the rendered text.
- Add your frontend features to EWW.
- change EWW so it can call your backend instead of shr.  This last part
  may be more difficult depending on how easy it is to align the details
  of shr's rendering with those of lynx.

Admittedly, we'd then still suffer from "not enough web browsers", but
at least users wouldn't have to choose between incomparable sets
of features.

WDYT?

In the mean time I've added `luwak` to `elpa.git`.
You might want to install and/or look at the patch below as well.


        Stefan


diff --git a/.gitignore b/.gitignore
index 628aad4cc8..b3b5372679 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
 *~
-*.elc
\ No newline at end of file
+*.elc
+/luwak-autoloads.el
+/luwak-pkg.el
diff --git a/luwak.el b/luwak.el
index 236a25f42e..a283e13536 100644
--- a/luwak.el
+++ b/luwak.el
@@ -37,34 +37,39 @@
 (defvar luwak-history-file "~/.emacs.d/luwak-history")
 
 (defun luwak-lynx-buffer (url) (format "*luwak-lynx %s*" url))
+
+(defgroup luwak ()
+  "Web browser based on lynx -dump."
+  :group 'web)
+
 (defcustom luwak-search-engine "https://html.duckduckgo.com/html?q=%s";
   "Default search engine for use in 'luwak-search'."
-  :group 'luwak :type '(string))
+  :type '(string))
 (defcustom luwak-url-rewrite-function 'identity
   "Function to rewrite url before loading."
-  :group 'luwak :type '(function))
+  :type '(function))
 (defcustom luwak-tor-switch t
   "Switch behaviour of prefix arg concerning the use of tor.
 
 When nil, use tor by default (requires a tor daemon having been
 started in the system), and not use it with a prefix arg.  When
 non-nill, swap the tor-switch in prefix-arg effect."
-  :group 'luwak :type '(boolean))
+  :type '(boolean))
 (defcustom luwak-max-history-length 100
   "Maximum history length."
-  :group 'luwak :type '(natnum))
+  :type '(natnum))
 (defcustom luwak-render-link-function 'luwak-render-link-id
   "Function to render a link."
-  :group 'luwak :type '(choice (const luwak-render-link-id)
-                               (const luwak-render-link-forward-sexp)
-                               (const luwak-render-link-hide-link)))
+  :type '(choice (const luwak-render-link-id)
+          (const luwak-render-link-forward-sexp)
+          (const luwak-render-link-hide-link)))
 (defcustom luwak-keep-history t
   "If non-nil, will keep history in 'luwak-history-file'."
-  :group 'luwak :type '(boolean))
+  :type '(boolean))
 (defcustom luwak-use-history t
   "If non-nil, will use history from the 'luwak-history-file' when invoking
 'luwak-open'."
-  :group 'luwak :type '(boolean))
+  :type '(boolean))
 
 (put luwak-history 'history-length luwak-max-history-length)
 
@@ -81,18 +86,18 @@ non-nill, swap the tor-switch in prefix-arg effect."
 
 (defvar luwak-mode-map
   (let ((kmap (make-sparse-keymap)))
-    (define-key kmap "\t" 'forward-button)
-    (define-key kmap [backtab] 'backward-button)
-    (define-key kmap "g" 'luwak-reload)
-    (define-key kmap "l" 'luwak-history-backward)
-    (define-key kmap "r" 'luwak-history-forward)
-    (define-key kmap "w" 'luwak-copy-url)
-    (define-key kmap "o" 'luwak-open)
-    (define-key kmap "s" 'luwak-search)
-    (define-key kmap "d" 'luwak-save-dump)
-    (define-key kmap "j" 'imenu)
-    (define-key kmap "t" 'luwak-toggle-links)
-    (define-key kmap "a" 'luwak-follow-numbered-link)
+    (define-key kmap "\t" #'forward-button)
+    (define-key kmap [backtab] #'backward-button)
+    (define-key kmap "g" #'luwak-reload)
+    (define-key kmap "l" #'luwak-history-backward)
+    (define-key kmap "r" #'luwak-history-forward)
+    (define-key kmap "w" #'luwak-copy-url)
+    (define-key kmap "o" #'luwak-open)
+    (define-key kmap "s" #'luwak-search)
+    (define-key kmap "d" #'luwak-save-dump)
+    (define-key kmap "j" #'imenu)
+    (define-key kmap "t" #'luwak-toggle-links)
+    (define-key kmap "a" #'luwak-follow-numbered-link)
     kmap))
 
 (define-derived-mode luwak-mode special-mode (luwak-mode-name)
@@ -120,14 +125,15 @@ non-nill, swap the tor-switch in prefix-arg effect."
       (buffer-substring-no-properties (1- (point))
                                       (progn (end-of-line 1) (point))))))
 
-(when (require 'org nil t)
-  (defun luwak-org-store-link ()
-    (when (derived-mode-p 'luwak-mode)
-      (org-link-store-props
-       :type "luwak"
-       :link (plist-get luwak-data :url)
-       :description (luwak-guess-title))))
+(defun luwak-org-store-link ()
+  (when (derived-mode-p 'luwak-mode)
+    (org-link-store-props
+     :type "luwak"
+     :link (plist-get luwak-data :url)
+     :description (luwak-guess-title))))
 
+;; FIXME: `org' is always available, so this should never fail!
+(when (require 'org nil t)
   (org-link-set-parameters "luwak"
                            :follow #'luwak-open
                            :store #'luwak-org-store-link))
@@ -138,13 +144,14 @@ non-nill, swap the tor-switch in prefix-arg effect."
   (interactive
    (list
     (if luwak-use-history
-        (car
+        (car            ;FIXME: Why throw away everything after space?
          (split-string
-          (completing-read "Url to open: " 
(luwak-history-collection-from-file))))
+          (completing-read "Url to open: "
+                           (luwak-history-collection-from-file))))
       (read-string "Url to open: "))))
   (luwak-open-url
    (url-encode-url url)
-   (xor luwak-tor-switch current-prefix-arg) 'luwak-add-to-history))
+   (xor luwak-tor-switch current-prefix-arg) #'luwak-add-to-history))
 
 (defun luwak-history-collection-from-file ()
   (split-string
@@ -162,7 +169,7 @@ non-nill, swap the tor-switch in prefix-arg effect."
 
 ;;;###autoload
 (defun luwak-search (query)
-  "Search QUERY using 'luwak-search-engine'."
+  "Search QUERY using `luwak-search-engine'."
   (interactive "sLuwak search query: ")
   (luwak-open (format luwak-search-engine query)))
 
@@ -265,7 +272,7 @@ non-nill, swap the tor-switch in prefix-arg effect."
 (defun luwak-follow-link (marker)
   (let ((url (get-text-property marker 'url)))
     (luwak-open-url
-     url (plist-get luwak-data :no-tor) 'luwak-add-to-history)))
+     url (plist-get luwak-data :no-tor) #'luwak-add-to-history)))
 
 (defun luwak-render-links (urls)
   (with-current-buffer luwak-buffer
@@ -335,7 +342,7 @@ non-nill, swap the tor-switch in prefix-arg effect."
       (goto-char (point-min))
       (re-search-forward "^References\n\n\\(\\ *Visible links:\n\\)?" nil t)
       (delete-region (point-min) (match-end 0))
-      (seq-filter 'identity
+      (seq-filter #'identity            ;`delq nil' ?
        (mapcar (lambda (s)
                 (when (string-match "^\\ *\\([0-9]+\\)\\. \\(.*\\)" s)
                   (concat (match-string 1 s) " " (match-string 2 s))))
@@ -347,11 +354,9 @@ non-nill, swap the tor-switch in prefix-arg effect."
    (list (completing-read "Select link to open: " (luwak-collect-links) nil 
t)))
   (luwak-open (cadr (split-string link))))
 
-(defun luwak-start-process-with-torsocks (no-tor name buffer program &rest 
program-args)
-  (if no-tor
-      (apply 'start-process (append (list name buffer program) program-args))
-    (apply 'start-process
-           (append (list name buffer "torsocks" program) program-args))))
+(defun luwak-start-process-with-torsocks (no-tor name buffer &rest cmd)
+  (apply #'start-process name buffer
+         (if no-tor cmd `("torsocks" ,@cmd))))
 
 (defun luwak-save-dump (file-name)
   "Write dump of the current luwak buffer to FILE-NAME."




reply via email to

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