在emacs org-mode 中插入截图
使用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上面)
1 ;;; image for org-mode 2 ; 1. suspend current emacs window 3 ; 2. call scrot to capture the screen and save as a file in $HOME/.emacs.img/ 4 ; 3. put the png file reference in current buffer, like this: [[/home/path/.emacs.img/1q2w3e.png]] 5 6 (add-hook 'org-mode-hook 'iimage-mode) ; enable iimage-mode for org-mode 7 (defun my-screenshot () 8 "Take a screenshot into a unique-named file in the current buffer file 9 directory and insert a link to this file." 10 (interactive) 11 (setq filename 12 (concat (make-temp-name 13 (concat (getenv "HOME") "/.emacs.img/" ) ) ".png")) 14 (suspend-frame) 15 (call-process-shell-command "scrot" nil nil nil nil " -s " (concat 16 "\"" filename "\"" )) 17 (insert (concat "[[" filename "]]")) 18 (org-display-inline-images) 19 ) 20 21 (global-set-key (kbd "C-p") 'my-screenshot)