summaryrefslogtreecommitdiff
path: root/eww-conf.el
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-09-17 11:20:20 +0800
committerJSDurand <mmemmew@gmail.com>2021-09-17 11:20:20 +0800
commit97676b501c3c29874878ff7f87ec85051ed67572 (patch)
treeea6580442bb94802087f046795cc8b977da7357d /eww-conf.el
parentaeb1aefe743440c6f0000e740a89fc4076a66bad (diff)
eww-conf: use an advice to override pop-to-buffer
* eww-conf.el (durand-pop-to-buffer-advice, durand-eww-bookmark-jump): A temporary advice is better than a temporary re-definition: at least we don't have to do all those unnecessary extra work to load window.el now. But this approach is still risky, as we override the basic function `pop-to-buffer', which might lead to unpredictable consequences. For now, it seems to work, though.
Diffstat (limited to 'eww-conf.el')
-rw-r--r--eww-conf.el16
1 files changed, 12 insertions, 4 deletions
diff --git a/eww-conf.el b/eww-conf.el
index 2be4c9b..157dded 100644
--- a/eww-conf.el
+++ b/eww-conf.el
@@ -422,6 +422,14 @@ Intended for use with `eww-mode-hook'."
;;;; Jumping
+;; HACK: Use an advice to temporarily override the definition of
+;; pop-to-buffer.
+
+(defun durand-pop-to-buffer-advice (buffer &rest args)
+ "Set BUFFER and ignore ARGS.
+Just a temporary advice to override `pop-to-buffer'."
+ (set-buffer buffer))
+
;; NOTE: It works with jumping in another window.
;;;###autoload
@@ -486,15 +494,15 @@ Otherwise, fetch URL and afterwards try to restore the point."
(t
;; HACK, GIANT HACK!
- ;; I think I don't need to explain how hacky it is to define
- ;; a built-in function here. Haha.
- (defun pop-to-buffer (x &rest _args) (set-buffer x))
+ (advice-add #'pop-to-buffer :override
+ #'durand-pop-to-buffer-advice)
(eww location 4)
;; after the `set-buffer' in `eww', the current buffer is
;; the buffer we want
(setq buffer (current-buffer))
;; restore the definition of pop-to-buffer...
- (load "window.el" nil t)
+ (advice-remove
+ #'pop-to-buffer #'durand-pop-to-buffer-advice)
;; add a hook to restore the position
;; make sure each hook function is unique, so that different