图文混排:Emacs Org中显示图片

软件平台:Windows 7 + Emacs23.2

1 在Emacs中显示图片

想要在Emacs Org中显示图片,你首先得

1.1 开启图片显示功能

通过下列语句开启,把它写入“.emacs”中:

(auto-image-file-mode t) 

 

1.2 还是不能显示

看看链接的图片能不能显示了!如果不能的话,你的Emacs可能少了一些dll文件,因为Windows上的Emacs默认编译时没带这几个DLL文件(来源)。你可以运行C-h v image-library-alist,看看你的Emacs显示了什么,我的Emacs显示:

image-library-alist is a variable defined in `C source code'. Its value is shown below.

This variable is potentially risky when used as a file local variable.

Documentation: Alist of image types vs external libraries needed to display them.

Each element is a list (IMAGE-TYPE LIBRARY…), where the car is a symbol representing a supported image type, and the rest are strings giving alternate filenames for the corresponding external libraries.

Emacs tries to load the libraries in the order they appear on the list; if none is loaded, the running session of Emacs won't support the image type. Types 'pbm and 'xbm don't need to be listed; they are always supported.

Value: ((xpm "libxpm.dll" "xpm4.dll" "libXpm-nox4.dll") 

    (png "libpng12d.dll" "libpng12.dll" "libpng.dll" "libpng13d.dll" "libpng13.dll") 

    (jpeg "jpeg62.dll" "libjpeg.dll" "jpeg-62.dll" "jpeg.dll")

    (tiff "libtiff3.dll" "libtiff.dll")

    (gif "giflib4.dll" "libungif4.dll" "libungif.dll")

    (svg "librsvg-2-2.dll") 

    (gdk-pixbuf "libgdkpixbuf-2.0-0.dll") 

    (glib "libglib-2.0-0.dll")

    (gobject "libgobject-2.0-0.dll")) 

 

Google后得出它的大致意思是,Emacs会按上面的顺序加载一些动态链接库(dll),如果没有这些dll,Emacs就不会支持相应的图片格式(.pbm与.xbm默认支持)。同时,这也指示了哪种格式的图片,需要哪些dll文件,这样你需要显示哪种格式图片,就下对应的dll。

更进一步,你还可以测试一下到底是不是缺少这些dll,而不是由其他原因引起图片无法显示:

1.3 测试到底是不是缺少dll文件

把下列代码拷贝到任何一个Lisp模式的Buffer里(如果不知道怎么办的话:)。

(image-type-available-p 'gif)

(image-type-available-p 'jpeg)

(image-type-available-p 'tiff)

(image-type-available-p 'xpm)

(image-type-available-p 'xbm)

(image-type-available-p 'pbm) 

 

在每一行的行尾按下C-j,就可以在下一行看到函数的运行结果,返回t证明是支持的格式;返回nil则是不支持的格式,即没有dll文件。你可以发现xpm和pbm返回t,其他的就看你的Emacs带不带相应的dll了!其他格式的测试只要把最后一个参数改成要测格式的后缀就行了,注意,单引号别忘了!

1.4 在哪下DLL文件

好了,已经知道是怎么回事了,也确定了该下哪个dll了,怎么获得呢?下面两个地址:

地址1:GnuWin Packages

地址2:winterTTr's github

1.5 DLL有了,然后呢

你可以任选一个下载,下载后把dll文件扔进Emacs的bin目录里即可。

这时候你在图片链接上单击,就会新出现一个显示着图片的Buffer。

好吧,你可能想在文字中直接显示图片,下面再讲解怎么图文混排:

 

 

2 图文混排

 

2.1 启用iimage模式

其实,你离图文混排已经很近了,按M-x iimage-mode RET试试看,是不是图文混排了!!

想要图文混排需要iimage.el的支持,而emacs23.2以上的版本已自带iimage了。它会为Emacs增加一种Minor Mode,上面的语句就是启用该模式。

2.2 在Org中启动iimage模式

如果你想在Emacs Org模式动启用iimage模式,你可以把下列代码放到.emacs文件中

(defun org-toggle-iimage-in-org () 

  "display images in your org file"

  (interactive) 

  (if (face-underline-p 'org-link) 

    (set-face-underline-p 'org-link nil)

    (set-face-underline-p 'org-link t)) 

    (iimage-mode)) 

 

以后你只要输入M-x org-toggle-iimage-in-org RET或M-x iimage-mode RET就可以了。

 

 

Author: skyfire <tianyuhuo@foxmail.com>

Date: 2012-09-12 15:05:14

HTML generated by org-mode 6.33x in emacs 23

posted on 2012-09-12 15:10  天与火  阅读(3438)  评论(1编辑  收藏  举报