使用iimage-mode能夠在buffer裏面顯示圖片,改了一個lisp函數來實現截屏、保存文件並插入到buffer中的功能。參考了這個: http://dreamrunner.org/wiki/public_html/Emacs/org-mode.html#sec-2-3 html
安裝起來很簡單:git
安裝scrot,會用這個工具來截圖github
建立一個文件夾 ~/.emacs.img ,截屏產生的圖片會保存到這裏shell
把下面的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-screenshotthis