2

There are many wonderful markup languages. For example here are some of their file extensions: nroff, md, tex, org, info, rtf, ps, html, etc. etc. We love them all.

In most cases I visit these files with no intention of editing their content. I'd prefer to see them rendered by the tools that handle them.

My question - Is there a lovely solution for this. For example, something that wraps advice around the existing modes for each of these (possibly using pandoc?).

Currently I'm slowly puzzling out how to add entries to auto-mode-alist. This is tedious and feels quite bogus. Some of these entries are just odd - for example (add-to-list 'auto-mode-alist '("\\.info\\'" . Info-on-current-buffer)).

For example your view of this question is rendered markdown, if you want to see it raw you can, but that's a rare desire. For example most markup formats are displayed rendered in github, if you want the source you can hit the raw button.

My question, desire?, is has somebody already assembled an library that enhances some or all the major modes for markup languages to default to a more human oriented view?

Kevin Wright
  • 359
  • 1
  • 16
Ben Hyde
  • 574
  • 3
  • 9
  • Your question isn't clear to me. Doesn't the default major mode load for .tex, .org, .html, etc files for you? – Kaushal Modi Sep 30 '15 at 02:44
  • We, of course they do. I would prefer to view these files as rendered into their output form. i.e. "I prefer to see them rendered." – Ben Hyde Sep 30 '15 at 03:00
  • By rendering, do you mean that in org mode, for example, you see the text ABC in bold without the asterisks if you have `*ABC*`? Something like [this](http://stackoverflow.com/q/10969617/1219634)? If so, you will need to be more specific about the major modes in which you want it because it needs to be implemented by that major mode. I fear there's no "one size fits all" solution in this case. – Kaushal Modi Sep 30 '15 at 03:08

1 Answers1

2

Partly for the purposes of clarification, and partly because it's built-in (to Emacs 24+) and therefore a trivial example, my impression is that you're after something roughly along these lines?

(defun my-html-render-current-buffer ()
  "Render HTML in current buffer using `shr-render-buffer'."
  (require 'shr)
  (shr-render-buffer (current-buffer)))

(add-to-list 'auto-mode-alist '("\\.html\\'" . my-html-render-current-buffer))

Can you elaborate on the question/requirement with reference to this?

Edit: Actually, I realise now that your Info line was already an example of what you were after. (I originally mistook that as a comment on existing auto-mode-alist entries.)

(add-to-list 'auto-mode-alist '("\\.info\\'" . Info-on-current-buffer))
phils
  • 48,657
  • 3
  • 76
  • 115
  • Yes, you've got it. I've taken a stab at rewriting the question in the hope it's more clear. I'm delighted that shr-render-buffer actually uses the term "render." Curious how a question who's answer is likely to involve touching many many modes is hard to phrase. You example is great, though creates a 2nd buffer. My hack for .info files doesn't, though that's pure luck. – Ben Hyde Sep 30 '15 at 12:35
  • 1
    I guess the ultimate example of what you want is the way the modern GUI Emacs treats images by default (provided it was compiled with the appropriate support libraries). If you open an image file, it displays the rendered image. Typing `C-c C-c` then toggles between that view and the raw file contents. – phils Sep 30 '15 at 20:00
  • :) indeed. And sometimes the markup generates diagrams, e.g. graphvis/dot, mscgen, the charting and javascript drawing schemes. The imaginary package I'm looking for would need to advise a lot of modes, cleverly :) ... anyhow I think the answer to my question, now that at least one person understand it is ... nope ... might be fun to write that. – Ben Hyde Oct 07 '15 at 13:01
  • It would be neat, for sure. I would think a single global minor mode using `after-change-major-mode-hook` might be the way to go. You could have a variable listing the modes which the user wants to be handled; another variable/alist mapping all supported modes to the functions which perform the relevant tasks; and I'm *guessing* some kind of text property or overlay trickery to handle the rendered view when that's toggled on? I'm unsure what that would look like, but expect that the image mode code would be a good place to start looking. – phils Oct 07 '15 at 13:31