问题
With just the few lines in a file file.adoc
////
-*-iimage-mode-*-
////
.A PNG smiley
image::smiley.png[]
I can generate HTML using asciidoctor
and MS-word .doc
using pandoc
.
This toolchain doesn't handle SVG, and so it's not perfect, but it works well, and
it's free.
file.html
There is a snag though:
I'd like iimage-mode to be enabled when I load file.adoc
. My attempt (the first three lines in the source above) doesn't work. Can you think of a way that will?
.emacs
(set-foreground-color "white")
(set-background-color "black")
(require 'adoc-mode)
(setq auto-mode-alist (cons '("\\.adoc\\'" . adoc-mode) auto-mode-alist))
Comments
I am writing these comments here to be able to typeset.
Asciidoctor (I'm using to the superior implementation of the asciidoc syntax written in Ruby) does have (now?) line comments in addition to block comments.
Using
// -- mode: iimage --
on the first line works (thanks, Nick). But it replaces the adoc major mode (thanks, phils).
- Adding at the bottom of the file:
//// Local Variables:
eval: (iimage-mode 1)
End:
////
switches to minor mode iimage while the major mode remains adoc.
- phils's suggestion to use
my-adoc-mode-hook
works well.
I'm forking the second part to a separate question. This discussion is already long enough for one question.
Update
Using asciidoctor + pandoc may produce a .doc
file that is handled correctly with a recent version of MS-Word. Comments welcome. MS-Word 2011 on OS X opens the resulting .doc
file fine, but shows an error message in the place of SVG images.
If this works, it will (finally) be a way to send a .doc
file to all those people who insist on them, while editing in an environment as flexible as Emacs.
回答1:
Nick's answer is mostly correct, but iimage-mode
is a minor mode, and using mode:...
in local variables is (nowadays) intended for major modes only. Using it to enable minor modes is deprecated (even if it still works in some situations1).
Instead use eval:...
to call the minor mode function like so2:
//// -*- eval: (iimage-mode 1); -*-
or
//// Local Variables:
//// eval: (iimage-mode 1)
//// End:
Note also that -*- iimage -*-
is equivalent to -*- mode: iimage -*-
, and that for both forms Emacs appends a -mode
suffix to get the actual mode name.
Hence -*-iimage-mode-*-
is asking to use iimage-mode-mode
-- and in fact Emacs should have produced a message "Ignoring unknown mode `iimage-mode-mode'".
Finally, if you want iimage-mode
enabled for all adoc-mode
files, then you can use a mode hook in your init file instead of using file-local variables:
(add-hook 'adoc-mode-hook 'my-adoc-mode-hook)
(defun my-adoc-mode-hook ()
"Custom `adoc-mode' behaviours."
(iimage-mode 1))
1 In this case, if you had used -*-iimage-*-
or -*-mode: iimage-*-
as the only local variable mode spec, Emacs would treat it as a major mode, and your intended adoc-mode
major mode would not be used.
2 I'm following Nick's answer in assuming that ////
is the correct line-comment prefix, but the question makes it look more like a block comment syntax, so I don't know if it's correct.
回答2:
- I tried with a JPG that I had lying around and I don't get any artifacts at all.
- The spec is
-*- mode: iimage -*-
and it's got to be on the first line of the file (it can be on the second if the first line specifies an interpreter, e.g. #! /bin bash).
If that does not work for you, you can use a file variable at the end of the file:
//// Local Variables:
//// mode: iimage
//// End:
See File Variables.
EDIT: See @phils's answer for a more correct description of how to handle minor modes.
来源:https://stackoverflow.com/questions/43077371/pseudo-wysiwyg-emacs