Adding a submode to nXhtml - emacs

Having made the jump just recently from XEmacs to GNU Emacs, I'm really loving nXhtml mode for writing web code. I'd like to be able to add a sub mode to it, though, and I'm not sure how. There doesn't seem to be a good reference to do so.
I have a mode for Perl's Template Toolkit, loaded as tt-mode and the default for .tmpl files, and I'd like to use nXhtml for my .tmpl files, with tt-mode taking over only between the [% %] tags.

Well, it appears (after some digging), that modes are defined in util/mumamo-fun.el, and there is already a Template Toolkit mode defined.
EDIT: Took out my original notes about having a problem with automatically loading it, because I was doing something dumb. :P)
Setting it up automatically was pretty simple:
(require 'mumamo-fun)
(setq auto-mode-alist (append '(("\\.tmpl$" . tt-html-mumamo)) auto-mode-alist))
Voila!
It looks like setting up other new modes is a fairly simple process. util/mumamo-fun.el contains the templates for all of the submodes. Following that format, it defines functions for finding chunks of the buffer that define a certain submode, and then builds them with other chunks (like the inline css and javascript, etc) into something that mumamo understands. I haven't actually tried to build a different mode, though, so I'm not sure if there is any additional work that needs to be done, but once defined, they seem to be registered with mumamo automatically.

Related

temporary key binding in emacs

I am not particularly satisfied how the viper mode works in Emacs. I am trying to write my own viper mode. I do not have any good programming experience in Elisp except for the number of customizations I have done using the .emacs file.
I would like to know if I can change the key-bindings in Emacs temporarily and return them back to their original state as and when needed.
Well if I understand your question correctly one easy way to do this would be to create your own minor mode (in addition to your own specific mode I'd say), made only of your temporary key-bindings.
You give a name to that mode and then toggling all your temporary key-bindings on or off becomes as simple as calling your command:
M-x salsabear-minor-mode
You probably want to read scottfrazer's 45+ upvotes answer here on SO:
Globally override key binding in Emacs
where he explains how to create your own minor-mode containing your key-bindings.
Given that you explicitly only mention viper, it's probably worth asking whether you're aware of the other vi/vim-based libraries which exist? See the list under:
http://www.emacswiki.org/emacs/CategoryEmulation
I would suspect that re-inventing this particular wheel is probably not worthwhile.
I believe that Evil is the most active project, but if it doesn't work the way you want, your efforts might be better-spent enhancing that (if practical)?

Increasing the WYSIWYG-ness of Emacs

I have a question in need of an Emacs expert, perhaps someone who is knowledgeable additionally in HTML/LaTeX, but someone who is primarily an emacs expert.
While writing files to typeset documents (in HTML, LaTeX, ..) I would like to make sure that I am including the right images, in HTML whenever I use <img ...> and in LaTeX whenever I use \includegraphics{...}.
Is there a way to include an image within the emacs buffer, either automatically or when I hover over the tag/command?
For LaTex, you can use the AUCTeX package. After you install it you can toggle image previews with C-c C-p C-p.
More information about AUCTeX is available at:
http://www.gnu.org/s/auctex/
The preview mode is called preview-latex, User's Manual is located here:
http://www.gnu.org/s/auctex/manual/preview-latex.index.html
You can use the inline image mode:
https://github.com/Wilfred/remacs/blob/master/lisp/iimage.el
If you are doing a lot of TeXing, AUCTeX is awesome. However, for a little less syntax-heavy option, you can learn org-mode and then export to latex.
http://orgmode.org/
http://orgmode.org/manual/LaTeX_002fPDF-export-commands.html
http://floatsolutions.com/blog/2010/10/displaying-inline-images-in-emacs-org-mode/
I think that the org-mode + inline image + LaTeX export (a native feature of org-mode) will be the best way to go. Org-mode is quite easy to learn, extremely well supported, has a great community, and the LaTeX export works really well. Then, you can just tweak the latex that org-mode generates, but the org-mode export will do 99% of the work, effectively making it WYSIWYG for images, tables, etc.

How to make org syntax links in any emacs buffer look like in org-mode?

I am using emacs org-mode for managing my notes. Often I wish to use links to this notes from files, which I am editing in other modes, like AUCTeX.
See here for a descriptive screenshot. (I am not yet allowed to post images here.)
Storing and following this links works pretty well. But I find it disturbing to read the full org syntax of the links: [[file:notes.org::*note][Description]], which is obviously not folded outside of org-mode.
I wonder if there is any minor-mode which provides the folding of such links to a clickable Description, like it is done in org-mode.
You can use links outside Org-mode.
4.5 Using links outside Org
You can insert and follow links that have Org syntax not only in Org, but in any Emacs buffer. For this, you should create two global commands, like this (please select suitable global keys yourself):
(global-set-key "\C-c L" 'org-insert-link-global)
(global-set-key "\C-c o" 'org-open-at-point-global)
-- Source: Using-links-outside-Org
Edit (1 Nov 2012): As of October 2011 the minor mode enabling org-like links didn't exist, but there were discussions. Now the minor mode exists, it is called org-link-minor-mode and is included in org-contrib.
I think the standard answer would be to use the publishing methods within org-mode to publish to a different file type, and link to that instead. Publishing, once set up, is really easy and fast to use and can produce things like html files that you could safely link to from something else (that is hopefully HTML compliant). Since you didn't say what the other-thing(s) is that you're using it's hard to recommend a good publishing output.

Change Emacs modes within specific tags

OK, I know you're going to point me to EmacsWiki page, but here's the deal. I'd like to use the default Emacs mode for a given file type, and change mode after specific tag, say <% %>. By doing such, I can switch the mode inside the tags, and return to default mode when cursor is not inside tags.
And no, I don't need ASP/PHP mode, it just that I find boring M-x-ing all the time in order to change the mode. I'm using Emacs 23.2.1 on Arch Linux FWIW. Any ideas?
Have a look at mmm-mode: http://sourceforge.net/projects/mmm-mode/ or noweb-mode. Here are instructions for getting mmm-mode to work with literate Haskell documents. And here is the configuration I use for noweb-mode with literate (rst+python) Python documents.
nXhtml
nXhtml is an addon to Emacs for editing XHTML, PHP and similar things.
nXhtml comes with MuMaMo (Multiple Master Major Mode), which I think is a newer version of mmm-mode. I use it all the time when editing Django HTML files which combine CSS, JavaScript and Django-aware HTML modes.
Is it what are you looking for :
http://www.emacswiki.org/emacs/PhpMode#toc8
You probably want to adapt it to fit your need

How to change emacs config in Lisp In A Box

I have been a programmer for a decade now, but I believe this is the first time I've ever asked a question on a forum. I just can't figure this out and can't find the answer already online.
I am trying to turn on CUA mode so that emacs is more bearable for a windows user (normal copy paste functions). I am running Windows 7 and installed emacs through the Lisp In A Box package. I understand that I need to add a line to my .emacs file or init.el file. I'm not sure which, but I can't find either in my Lip In A Box install directory. The emacs package install also did not come with any tutorials or help files, so its really hard to pick this up.
I am stuck, any help is greatly appreciated!
The .emacs can be found by looking at the answers to this similar question.
Regarding documentation and tutorials, it looks like the link you provided for "Lisp in a Box" says:
If you are new to Emacs, it is
recommended that you read the Emacs
Tutorial which you can access from
with Emacs by going to the Help menu,
or by typing Control-h, letting go,
and hitting t. A more extensive manual
is also available from the Help menu,
or on the web at
http://www.gnu.org/software/emacs/manual/.
Which makes it sound like the manual is there, and certainly the tutorial (I made bold the directions to get to the tutorial).
As far as other places to get information, there is a collection of screencasts on the wiki.
Your question doesn't specify whether or not you what to add to your .emacs to activate CUA mode. You can check out the CUA mode documentation on the wiki (which has links to the manual). The minimal installation is just adding this to your .emacs: (cua-mode t).
For GNU/Emacs, you can choose to use any one of the following three file names as the start-up configuration file:
${HOME}/.emacs
${HOME}/.emacs.el
${HOME}/.emacs.d/init.el
It would probably be a good idea to decide on one of the three options and then stick to it - the first one seems to be the most widely used one. In any case, ${HOME} stands for your home directory -- which is likely to be different from the Lisp In A Box install directory!
Coming from a Unix tradition, Emacs understands ~ (tilde) as an abbreviation for your home directory, so you can visit the .emacs file by typing:
C-x C-f ~/.emacs [ENTER]
(Note that the capital C is Emacs standard notation for a combination of the CTRL key and a second key, i.e. here you press CTRL-x CTRL-f which stands for "find-file" and will then ask you for a file name in the bottom part of the Frame (aka mini-buffer).)
If these are your first customizations, you will just see an empty buffer. Enter
;; start CUA mode every time Emacs starts
(cua-mode t)
and save the buffer with C-x C-s.
Next time you start Emacs, CUA mode should be turned on automatically.
What the others have told you is true: Simply adding (cua-mode t) to your dotfile would be sufficient. HOWEVER: Lisp in a box' Emacs doesn't load this file by default.
Therefore, be sure to edit the shortcut so that it does load the dotfile. This is important, because otherwise you would get weird behavior, where you would add the correct line to the dotfile, start emacs, and then not get cua mode. That would suck.
The reason it does this is to ensure that it starts a vanilla emacs everytime, instead of finding, say C:/_emacs and loading that instead, giving you another user's customizations and confusing you.
The flag for not loading an init file is -q or --no-init-file. Also make sure that --no-site-file is not there.
(I realize that this is an old post, but I found this while looking for something related, and I don't want people walking away frustrated over something that doesn't work.)