0

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

smiley in a rendered HTML file

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.

  1. 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.

  2. Using

    // -- mode: iimage --

on the first line works (thanks, Nick). But it replaces the adoc major mode (thanks, phils).

  1. 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.

  1. 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.

Community
  • 1
  • 1
Calaf
  • 10,113
  • 15
  • 57
  • 120
  • In general, Emacs does not create/depict lines through PNG images that are displayed in `image-mode`. Does this happen with `emacs -q`? I.e., just open the PNG in a buffer all by itself with zero user configuration -- it should default to `image-mode`. – lawlist Mar 28 '17 at 19:36
  • `adoc-mode` isn't standard, so tell us where it came from. – phils Mar 29 '17 at 09:08

2 Answers2

2
  1. I tried with a JPG that I had lying around and I don't get any artifacts at all.
  2. 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.

NickD
  • 5,937
  • 1
  • 21
  • 38
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.

phils
  • 71,335
  • 11
  • 153
  • 198
  • Thanks (again) for setting me right. The minor mode warning is right there on the page that I linked to and I'm sure I have seen it before, but I forgot all about it. – NickD Mar 29 '17 at 13:57