【发布时间】:2019-08-17 00:37:06
【问题描述】:
我在 emacs 上已有 6 年的历史了,只是刚刚进入细节。我的 init 中有一个 hyrda 用于浏览器活动,使用引擎模式、浏览 URL 和浏览 URL 缓冲区。我编写了一个新函数“print-to-browser”,它将缓冲区html化并在默认浏览器中打开它。
当然,browse-url-of-buffer 作用于原始缓冲区,而不是 htlmizes 输出缓冲区。我使用的 ADD-HOOK 有一个 LOCAL 或 GLOBAL 参数,用于切换browse-url-of-buffer 作用于两个缓冲区或单独作用于原始缓冲区,而不是单独作用于新缓冲区。
htmlize 在那里的某个地方创建了一个新缓冲区,该缓冲区可能被添加到缓冲区列表的末尾。我想将last-buffer(它从选定的Windows缓冲区列表中调用最后一个缓冲区)传递给browse-url-of-buffer,或者将html化缓冲区的名称传递给switch-to-buffer,然后调用browse-缓冲区的 url。
有人知道怎么做吗?
这里是打印到浏览器:
(defun print-to-browser ()
"Depends Htmlize. Htmlize buffer, go there, send buffer to browser"
(interactive)
(add-hook 'htmlize-after-hook 'browse-url-of-buffer nil nil)
(htmlize-buffer)
(run-hook-with-args 'htmlize-after-hook)
) ; end print-to-browser
这是来自 myinit.org 的完整代码块:
#+BEGIN_SRC emacs-lisp
(use-package engine-mode
:after hydra
:commands hydra-search/body
:config
;(engine-mode t)
;engine mode configuration
(defengine duckduckgo
"https://duckduckgo.com/?q=%s"
;:keybinding "d"
)
(defengine github
"https://github.com/search?ref=simplesearch&q=%s"
;:keybinding "h"
)
(defengine google
"http://www.google.com/search?ie=utf-8&oe=utf-8&q=%s"
;:keybinding "g"
)
(defengine google-images
"http://www.google.com/images?hl=en&source=hp&biw=1440&bih=795&gbv=2&aq=f&aqi=&aql=&oq=&q=%s"
;:keybinding "i"
)
(defengine google-maps
"http://maps.google.com/maps?q=%s"
:docstring "Mappin' it up."
;:keybinding "m"
)
(defengine stack-overflow
"https://stackoverflow.com/search?q=%s"
;:keybinding "q"
)
(defengine wikipedia
"http://www.wikipedia.org/search-redirect.php?language=en&go=Go&search=%s"
;:keybinding "w"
:docstring "Searchin' the wikis.")
(defengine youtube
"http://www.youtube.com/results?aq=f&oq=&search_query=%s"
;:keybinding "y"
)
;custom function print buffer in browser
(defun print-to-browser ()
"Depends Htmlize. Htmlize buffer, go there, send buffer to browser"
(interactive)
(add-hook 'htmlize-after-hook 'browse-url-of-buffer nil nil)
(htmlize-buffer)
(run-hook-with-args 'htmlize-after-hook)
) ; end print-to-browser
:bind
("<C-m> i" . hydra-search/body)
:hydra
(hydra-search (:color blue :hint none)
"
^Browser Search or Print^
--------------------------------------------
_d_uck _g_oogle _i_mages _w_iki
_m_aps _y_outube _s_tack _h_ub
_u_rl _p_rint _h_tml
"
("w" engine/search-wikipedia "wikipedia")
("d" engine/search-duckduckgo "duckduckgo")
("h" engine/search-github "github")
("g" engine/search-google "google")
("i" engine/search-google-images "google-images")
("m" engine/search-google-maps "google-maps")
("y" engine/search-youtube "youtube")
("s" engine/search-stack-overflow "stack-overflow")
("u" browse-url "browse-url-at-point")
("p" print-to-browser "print-to-browser")
("h" browse-url-of-buffer "buffer-to-browser")
))
#+END_SRC
大概有多种简单的解决方案。
【问题讨论】: