7

An idea has just came to my mind. Is there any methods to insert a picture in code comment to help explain our code? After all, a picture is worth a thousand words.

Since I use Emacs, is there any implementations for Emacs so far?

wilbeibi
  • 3,403
  • 4
  • 25
  • 44
  • People have used ASCII art since the beginning of coding to help explain the architecture of their software. But most text-editors don't have much in the way of support for graphics... – deed02392 Apr 02 '13 at 08:57
  • Emacs provides low-level tools for displaying graphics inline, however, I'm not aware of any package that lets you do this for code comments -- sounds like a nice project for someone with more free time than I have... – Lindydancer Apr 02 '13 at 09:07
  • 3
    This is an interesting idea, but the logistics of it are a problem. Pictures would have to be fairly large to be of any use, so it would be a bad idea to store them inline (base64). If you store them outside the file, then you have to remember to move the pictures along with the source file. The biggest problem is that you cannot edit the pictures in the text editor, you have to use an outside tool. The whole point of a *source* file is that it is editable, "the preferred form of the work for making modifications to it." Pictures other than ASCII art don't fit the concept. – user4815162342 Apr 02 '13 at 09:32
  • 1
    @user4815162342, nevertheless, dragging around images along with source code files *is* done for javadoc and doxygen, and some IDEs even render such comments to some nice representation (including drawing images). It does fill like a fuss to me, too, but it is doable and even done — just not for emacs (apparently). – shakurov Apr 02 '13 at 10:12
  • 1
    Here is a related SO question: [insert image into text buffer](http://stackoverflow.com/q/9780124/1225607) – François Févotte Apr 02 '13 at 12:09
  • @shakurov Good point. If the pictures are externally stored and specified by easily identifiable markup, it would be almost trivial to write an Emacs minor mode that auto-inserted them into the buffer. The folks that frequence the emacs SO tag would probably do it in 5 minutes, given the right question. – user4815162342 Apr 02 '13 at 12:37

3 Answers3

8

Take a look at iimage-mode: it is a standard solution to display an image in a text buffer.

For example, given the following file:

/* an image is worth a thousand words:
 * <path/to/image.png>
 */
int main (int argc, char **argv) {
  return 0;
}

then running M-xturn-on-iimage-mode should display image.png in place of its path.


However, I agree with @user4815162342's comment that you need to distribute images along with source files and to remember updating them when needed (it is sometimes hard to update code comments when they are text only; it will IMO be harder to update image comments)

François Févotte
  • 19,520
  • 4
  • 51
  • 74
3

Are you talking about ASCII graphics or actual images?

For ASCII art, there's the M-x artist-mode that allows you to draw simple (or not very simple) images. Also, if you need to draw ASCII-based UML diagrams, CEDET can do it for you.

For inserting actual images, there's a bunch of functions like create-image and insert-image, so writing a minor mode for inserting images to comments should be straightforward. I'm not aware of any ready-made solutions, though.

shakurov
  • 2,358
  • 24
  • 27
0

If you want to paste online images also, cacoo.el will be very useful. It caches online images and resize it wisely. So, showing the image from the second time is much fast. It also works with local images.

It was first developed for web service called cacco, but it work for any online images.

tkf
  • 2,990
  • 18
  • 32