* bug#41385: [PATCH] Show eww bookmarks buffer only if it's not empty
@ 2020-05-19 0:51 Stefan Kangas
2020-05-19 12:34 ` Lars Ingebrigtsen
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Kangas @ 2020-05-19 0:51 UTC (permalink / raw)
To: 41385; +Cc: larsi
[-- Attachment #1: Type: text/plain, Size: 160 bytes --]
Severity: minor
X-Debbugs-CC: larsi@gnus.org
Please see the attached patch which fixes a minor annoyance with
eww-list-bookmarks.
Best regards,
Stefan Kangas
[-- Attachment #2: 0001-Show-eww-bookmarks-buffer-only-if-it-s-not-empty.patch --]
[-- Type: text/x-diff, Size: 1014 bytes --]
From ff5c8120955a8c0a23cafe5e0cb6821dc154f72a Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Tue, 19 May 2020 02:43:16 +0200
Subject: [PATCH] Show eww bookmarks buffer only if it's not empty
* lisp/net/eww.el (eww-list-bookmarks): Don't show buffer if there
are no bookmarks.
---
lisp/net/eww.el | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index a6c1abdbb1..f24ada6287 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -1754,8 +1754,13 @@ eww-read-bookmarks
(defun eww-list-bookmarks ()
"Display the bookmarks."
(interactive)
- (pop-to-buffer "*eww bookmarks*")
- (eww-bookmark-prepare))
+ (let ((buf (get-buffer-create "*eww bookmarks*")) no-error)
+ (unwind-protect
+ (progn
+ (pop-to-buffer buf)
+ (eww-bookmark-prepare)
+ (setq no-error t))
+ (when (not no-error) (kill-buffer buf)))))
(defun eww-bookmark-prepare ()
(eww-read-bookmarks)
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* bug#41385: [PATCH] Show eww bookmarks buffer only if it's not empty
2020-05-19 0:51 bug#41385: [PATCH] Show eww bookmarks buffer only if it's not empty Stefan Kangas
@ 2020-05-19 12:34 ` Lars Ingebrigtsen
2020-05-20 3:44 ` Stefan Kangas
0 siblings, 1 reply; 6+ messages in thread
From: Lars Ingebrigtsen @ 2020-05-19 12:34 UTC (permalink / raw)
To: Stefan Kangas; +Cc: 41385
Stefan Kangas <stefan@marxist.se> writes:
> Please see the attached patch which fixes a minor annoyance with
> eww-list-bookmarks.
[...]
> - (pop-to-buffer "*eww bookmarks*")
> - (eww-bookmark-prepare))
> + (let ((buf (get-buffer-create "*eww bookmarks*")) no-error)
> + (unwind-protect
> + (progn
> + (pop-to-buffer buf)
> + (eww-bookmark-prepare)
> + (setq no-error t))
> + (when (not no-error) (kill-buffer buf)))))
I don't think this is an ideal way to fix this command -- using error
handling to do control flow is usually the wrong thing to do, and it
makes debugging difficult. What if there's a real bug in
eww-bookmark-prepare?
Instead eww-list-bookmarks should just do the
(eww-read-bookmarks)
(unless eww-bookmarks
(user-error "No bookmarks are defined"))
bit, I think. It might mean rearranging some stuff in eww-next-bookmark
etc, though.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#41385: [PATCH] Show eww bookmarks buffer only if it's not empty
2020-05-19 12:34 ` Lars Ingebrigtsen
@ 2020-05-20 3:44 ` Stefan Kangas
2020-06-10 15:25 ` Lars Ingebrigtsen
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Kangas @ 2020-05-20 3:44 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 41385
[-- Attachment #1: Type: text/plain, Size: 601 bytes --]
Lars Ingebrigtsen <larsi@gnus.org> writes:
> I don't think this is an ideal way to fix this command -- using error
> handling to do control flow is usually the wrong thing to do, and it
> makes debugging difficult. What if there's a real bug in
> eww-bookmark-prepare?
>
> Instead eww-list-bookmarks should just do the
>
> (eww-read-bookmarks)
> (unless eww-bookmarks
> (user-error "No bookmarks are defined"))
>
> bit, I think. It might mean rearranging some stuff in eww-next-bookmark
> etc, though.
Thanks, good point. Does the attached patch look better?
Best regards,
Stefan Kangas
[-- Attachment #2: 0001-Show-eww-bookmarks-buffer-only-if-it-s-not-empty.patch --]
[-- Type: text/x-diff, Size: 2489 bytes --]
From 18a6aec0c8c24250fcd105d538bddcdf907c0e5c Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Tue, 19 May 2020 02:43:16 +0200
Subject: [PATCH] Show eww bookmarks buffer only if it's not empty
* lisp/net/eww.el (eww-list-bookmarks): Don't show buffer if there
are no bookmarks. (Bug#41385)
(eww-bookmark-prepare): Move signalling an error if there are no
bookmarks from here...
(eww-read-bookmarks): ...to here. Add new argument `error-out' to
control this.
(eww-next-bookmark, eww-previous-bookmark): Call `eww-read-bookmarks'.
---
lisp/net/eww.el | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index a6c1abdbb1..84154c502d 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -1742,25 +1742,27 @@ eww-write-bookmarks
(insert ";; Auto-generated file; don't edit -*- mode: lisp-data -*-\n")
(pp eww-bookmarks (current-buffer))))
-(defun eww-read-bookmarks ()
+(defun eww-read-bookmarks (&optional error-out)
+ "Read bookmarks from `eww-bookmarks'.
+If ERROR-OUT, signal user-error if there are no bookmarks."
(let ((file (expand-file-name "eww-bookmarks" eww-bookmarks-directory)))
(setq eww-bookmarks
(unless (zerop (or (file-attribute-size (file-attributes file)) 0))
(with-temp-buffer
(insert-file-contents file)
- (read (current-buffer)))))))
+ (read (current-buffer)))))
+ (when (and error-out (not eww-bookmarks))
+ (user-error "No bookmarks are defined"))))
;;;###autoload
(defun eww-list-bookmarks ()
"Display the bookmarks."
(interactive)
+ (eww-read-bookmarks t)
(pop-to-buffer "*eww bookmarks*")
(eww-bookmark-prepare))
(defun eww-bookmark-prepare ()
- (eww-read-bookmarks)
- (unless eww-bookmarks
- (user-error "No bookmarks are defined"))
(set-buffer (get-buffer-create "*eww bookmarks*"))
(eww-bookmark-mode)
(let* ((width (/ (window-width) 2))
@@ -1828,6 +1830,7 @@ eww-next-bookmark
bookmark)
(unless (get-buffer "*eww bookmarks*")
(setq first t)
+ (eww-read-bookmarks t)
(eww-bookmark-prepare))
(with-current-buffer (get-buffer "*eww bookmarks*")
(when (and (not first)
@@ -1846,6 +1849,7 @@ eww-previous-bookmark
bookmark)
(unless (get-buffer "*eww bookmarks*")
(setq first t)
+ (eww-read-bookmarks t)
(eww-bookmark-prepare))
(with-current-buffer (get-buffer "*eww bookmarks*")
(if first
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-07-29 10:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-19 0:51 bug#41385: [PATCH] Show eww bookmarks buffer only if it's not empty Stefan Kangas
2020-05-19 12:34 ` Lars Ingebrigtsen
2020-05-20 3:44 ` Stefan Kangas
2020-06-10 15:25 ` Lars Ingebrigtsen
2020-07-17 1:24 ` Lars Ingebrigtsen
2020-07-29 10:29 ` Stefan Kangas
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).