From 97676b501c3c29874878ff7f87ec85051ed67572 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Fri, 17 Sep 2021 11:20:20 +0800 Subject: 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. --- eww-conf.el | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'eww-conf.el') 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 -- cgit v1.2.3-18-g5258