mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-03 22:20:52 -08:00
Add new option to rename eww buffers
* etc/NEWS: Document the new user options. * lisp/net/eww.el (eww-auto-rename-buffer, eww-buffer-name-length): Add new user options. (eww--rename-buffer): Introduce new function that performs the renaming of buffers. (eww--after-page-change): Add new wrapper function which calls 'eww-update-header-line-format' and 'eww--rename-buffer'. (eww, eww-render, eww-tag-title, eww-readable, eww-restore-history): Include eww--after-page-change. Fix bug#51176. Co-authored-by: Abhiseck Paira <abhiseckpaira@disroot.org> Co-authored-by: Protesilaos Stavrou <info@protesilaos.com>
This commit is contained in:
parent
7dedba1cc0
commit
171de3eee4
3 changed files with 78 additions and 5 deletions
|
|
@ -380,6 +380,14 @@ thus allowing for the use of the usual substitutions, such as
|
|||
@code{\[eww-reload]} for the current key binding of the
|
||||
@code{eww-reload} command.
|
||||
|
||||
@vindex eww-auto-rename-buffer
|
||||
If the @code{eww-auto-rename-buffer} user option is non-@code{nil},
|
||||
EWW buffers will be renamed after rendering a document. If this is
|
||||
@code{title}, rename based on the title of the document. If this is
|
||||
@code{url}, rename based on the @acronym{URL} of the document. This
|
||||
can also be a user-defined function, which is called with no
|
||||
parameters in the EWW buffer, and should return a string.
|
||||
|
||||
@node Command Line
|
||||
@chapter Command Line Usage
|
||||
|
||||
|
|
|
|||
10
etc/NEWS
10
etc/NEWS
|
|
@ -89,6 +89,16 @@ Customize this option to limit the amount of entries in the menu
|
|||
|
||||
* Changes in Specialized Modes and Packages in Emacs 29.1
|
||||
|
||||
** eww
|
||||
|
||||
+++
|
||||
*** New user option to automatically rename EWW buffers.
|
||||
The 'eww-auto-rename-buffer' user option can be configured to rename
|
||||
rendered web pages by using their title, URL, or a user-defined
|
||||
function which returns a string. For the first two cases, the length
|
||||
of the resulting name is controlled by 'eww-buffer-name-length'. By
|
||||
default, no automatic renaming is performed.
|
||||
|
||||
** image-dired
|
||||
|
||||
---
|
||||
|
|
|
|||
|
|
@ -178,6 +178,33 @@ the tab bar is enabled."
|
|||
:group 'eww
|
||||
:type 'hook)
|
||||
|
||||
(defcustom eww-auto-rename-buffer nil
|
||||
"Automatically rename EWW buffers once the page is rendered.
|
||||
|
||||
When nil, do not rename the buffer. With a non-nil value
|
||||
determine the renaming scheme, as follows:
|
||||
|
||||
- `title': Use the web page's title.
|
||||
- `url': Use the web page's URL.
|
||||
- a function's symbol: Run a user-defined function that returns a
|
||||
string with which to rename the buffer.
|
||||
|
||||
The string of `title' and `url' is always truncated to the value
|
||||
of `eww-buffer-name-length'."
|
||||
:version "29.1"
|
||||
:type '(choice
|
||||
(const :tag "Do not rename buffers (default)" nil)
|
||||
(const :tag "Rename buffer to web page title" title)
|
||||
(const :tag "Rename buffer to web page URL" url)
|
||||
(function :tag "A user-defined function to rename the buffer"))
|
||||
:group 'eww)
|
||||
|
||||
(defcustom eww-buffer-name-length 40
|
||||
"Length of renamed buffer name, per `eww-auto-rename-buffer'."
|
||||
:type 'natnum
|
||||
:version "29.1"
|
||||
:group 'eww)
|
||||
|
||||
(defcustom eww-form-checkbox-selected-symbol "[X]"
|
||||
"Symbol used to represent a selected checkbox.
|
||||
See also `eww-form-checkbox-symbol'."
|
||||
|
|
@ -353,7 +380,7 @@ killed after rendering."
|
|||
(setq url (url-recreate-url parsed)))
|
||||
(plist-put eww-data :url url)
|
||||
(plist-put eww-data :title "")
|
||||
(eww-update-header-line-format)
|
||||
(eww--after-page-change)
|
||||
(let ((inhibit-read-only t))
|
||||
(insert (format "Loading %s..." url))
|
||||
(goto-char (point-min)))
|
||||
|
|
@ -502,6 +529,30 @@ Currently this means either text/html or application/xhtml+xml."
|
|||
(member content-type '("text/html"
|
||||
"application/xhtml+xml")))
|
||||
|
||||
(defun eww--rename-buffer ()
|
||||
"Rename the current EWW buffer.
|
||||
The renaming scheme is performed in accordance with
|
||||
`eww-auto-rename-buffer'."
|
||||
(let ((rename-string)
|
||||
(formatter
|
||||
(lambda (string)
|
||||
(format "*%s # eww*" (truncate-string-to-width
|
||||
string eww-buffer-name-length))))
|
||||
(site-title (plist-get eww-data :title))
|
||||
(site-url (plist-get eww-data :url)))
|
||||
(cond ((null eww-auto-rename-buffer))
|
||||
((eq eww-auto-rename-buffer 'url)
|
||||
(setq rename-string (funcall formatter site-url)))
|
||||
((functionp eww-auto-rename-buffer)
|
||||
(setq rename-string (funcall eww-auto-rename-buffer)))
|
||||
(t (setq rename-string
|
||||
(funcall formatter (if (or (equal site-title "")
|
||||
(null site-title))
|
||||
"Untitled"
|
||||
site-title)))))
|
||||
(when rename-string
|
||||
(rename-buffer rename-string t))))
|
||||
|
||||
(defun eww-render (status url &optional point buffer encode)
|
||||
(let* ((headers (eww-parse-headers))
|
||||
(content-type
|
||||
|
|
@ -552,7 +603,7 @@ Currently this means either text/html or application/xhtml+xml."
|
|||
(eww-display-raw buffer (or encode charset 'utf-8))))
|
||||
(with-current-buffer buffer
|
||||
(plist-put eww-data :url url)
|
||||
(eww-update-header-line-format)
|
||||
(eww--after-page-change)
|
||||
(setq eww-history-position 0)
|
||||
(and last-coding-system-used
|
||||
(set-buffer-file-coding-system last-coding-system-used))
|
||||
|
|
@ -796,12 +847,16 @@ Currently this means either text/html or application/xhtml+xml."
|
|||
`((?u . ,(or url ""))
|
||||
(?t . ,title))))))))
|
||||
|
||||
(defun eww--after-page-change ()
|
||||
(eww-update-header-line-format)
|
||||
(eww--rename-buffer))
|
||||
|
||||
(defun eww-tag-title (dom)
|
||||
(plist-put eww-data :title
|
||||
(replace-regexp-in-string
|
||||
"^ \\| $" ""
|
||||
(replace-regexp-in-string "[ \t\r\n]+" " " (dom-text dom))))
|
||||
(eww-update-header-line-format))
|
||||
(eww--after-page-change))
|
||||
|
||||
(defun eww-display-raw (buffer &optional encode)
|
||||
(let ((data (buffer-substring (point) (point-max))))
|
||||
|
|
@ -929,7 +984,7 @@ the like."
|
|||
nil (current-buffer))
|
||||
(dolist (elem '(:source :url :title :next :previous :up))
|
||||
(plist-put eww-data elem (plist-get old-data elem)))
|
||||
(eww-update-header-line-format)))
|
||||
(eww--after-page-change)))
|
||||
|
||||
(defun eww-score-readability (node)
|
||||
(let ((score -1))
|
||||
|
|
@ -1161,7 +1216,7 @@ instead of `browse-url-new-window-flag'."
|
|||
(goto-char (plist-get elem :point))
|
||||
;; Make buffer listings more informative.
|
||||
(setq list-buffers-directory (plist-get elem :url))
|
||||
(eww-update-header-line-format))))
|
||||
(eww--after-page-change))))
|
||||
|
||||
(defun eww-next-url ()
|
||||
"Go to the page marked `next'.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue