使用iimage-mode可以在buffer里面显示图片,改了一个lisp函数来实现截屏、保存文件并插入到buffer中的功能。参考了这个: http://dreamrunner.org/wiki/public_html/Emacs/org-mode.html#sec-2-3
安装起来很简单:
安装scrot,会用这个工具来截图
创建一个文件夹 ~/.emacs.img ,截屏产生的图片会保存到这里
把下面的lisp放到emacs的配置文件中(我把截屏的快捷键绑定到了C-p上面)
;;; image for org-mode
; 1. suspend current emacs window
; 2. call scrot to capture the screen and save as a file in $HOME/.emacs.img/
; 3. put the png file reference in current buffer, like this: [[/home/path/.emacs.img/1q2w3e.png]]
(add-hook 'org-mode-hook 'iimage-mode) ; enable iimage-mode for org-mode
(defun my-screenshot ()
"Take a screenshot into a unique-named file in the current buffer file
directory and insert a link to this file."
(interactive)
(setq filename
(concat (make-temp-name
(concat (getenv "HOME") "/.emacs.img/" ) ) ".png"))
(suspend-frame)
(call-process-shell-command "scrot" nil nil nil nil " -s " (concat
"\"" filename "\"" ))
(insert (concat "[[" filename "]]"))
(org-display-inline-images)
)
(global-set-key (kbd "C-p") 'my-screenshot)
相关代码已经提交到了github上,欢迎fork https://github.com/Chengming/org-screenshot
来源:oschina
链接:https://my.oschina.net/u/575122/blog/124113