2015-02-11 163 views
2

我配置的Emacs開在EWW新的鏈接,像這樣:Emacs和eww,在新窗口中打開鏈接?

(setq browse-url-browser-function 'eww-browse-url) 

現在,當我點擊一個鏈接,它在同一個緩衝區打開。

我想打開一個新窗口(即垂直分割,如C - x 3),並在右側新創建的框架中打開頁面。所以我仍然在左邊有原始的組織模式筆記。

[編輯]

我砍死在一起的東西。但它只在激活熱鍵時才起作用,而不是在另一個功能打開鏈接時起作用。

理想情況下,我想要類似下面的內容,但每當我打開一個鏈接(例如在helm-google)時。

(defun my/open-in-right-window() 
    "Open the selected link on the right window plane" 
    (interactive) 
    (delete-other-windows nil) 
    (split-window-right nil) 
    (other-window 1) 
    (org-return nil) 
) 

(defun my/eww-quitAndSingleWin() 
    "Quit the current browser session and activate single window mode." 
    (interactive) 
    (quit-window nil) 
    (delete-other-windows nil) 
) 

(defun my/eww-split-right() 
    "Splits the Window. Moves eww to the right and underlying content on the left." 
    (interactive) 
    (split-window-right nil) 
    (quit-window nil) 
    (other-window 1) 
) 

(global-set-key (kbd "H-r") 'my/open-in-right-window)  

(add-hook 'eww-mode-hook ;no impact. 
     (lambda() 
     (local-set-key (kbd "s") 'my/eww-split-right) 
     (local-set-key (kbd "Q") 'my/eww-quitAndSingleWin) 
    )) 

它殺死其他窗口,打開新窗口,切換到新窗口,然後按回車[配置爲打開我的配置中的鏈接]。
此外,在eww模式中,'Q'(大寫)退出會話並殺死另一個窗口,以避免打開太多的窗口。

這不是最優雅的解決方案。我對更好的想法持開放態度?

回答

2

儘管羅素的答案可能已經在過去的正確,eww-current-titleeww-current-url一直贊成緩衝區局部的plist的廢棄稱爲eww-data

當前的eww實現還包括我們需要插入一個緩衝區後插入的鉤子,從而避免需要做「雜亂」的東西,如defadvice

按照2015年8月和this Git-commit,以下elisp的工作對我來說:

(defun my-set-eww-buffer-title() 
    (let* ((title (plist-get eww-data :title)) 
     (url (plist-get eww-data :url)) 
     (result (concat "*eww-" (or title 
           (if (string-match "://" url) 
            (substring url (match-beginning 0)) 
           url)) "*"))) 
    (rename-buffer result t))) 

(add-hook 'eww-after-render-hook 'my-set-eww-buffer-title) 

你或許可以用這個鉤子來添加所需的鍵綁定了。

+0

未經測試,但看起來合法。 – 2015-08-10 14:07:39

+0

不適用於GNU Emacs 24.5.1(x86_64-unknown-linux-gnu,GTK +版本2.18.9) russell的版本不錯。 – hajovonta 2016-03-22 09:47:11

+0

我的評論是針對那些Emacs git master以及Emacs 25中將會發布的內容的。對於目前發佈的Emacs版本,在那裏發現初步的和不完整的eww實現,羅塞爾的建議仍然適用。 – 2016-04-01 12:01:40

3

我有類似的問題想要有多個eww緩衝區打開,並通過建議eww-render。你可能會把你的代碼放在那裏以使其始終運行。

(defadvice eww-render (after set-eww-buffer-name activate) 
    (rename-buffer (concat "*eww-" (or eww-current-title 
            (if (string-match "://" eww-current-url) 
             (substring eww-current-url (match-beginning 0)) 
             eww-current-url)) "*") t))