Emacs working with big XML files - emacs

Often I need to read big XML files (> 100 MB) which have a fairly simple structure. I would like to use emacs, but it does not support big files very well. I am thinking maybe I can use a java application which can do SAX or StAX parsing for me and provide me with all necessary operations (e.g. search). What is the "right way" to communicate between emacs and an external java application?

You can try disable font-lock-mode for that particular buffer. I have opened much bigger files than that using emacs. I noticed slow down only when lines in the file are bigger than my screen and they start to wrap. Letting them go out of the screen and disabling font-lock accelerates performence.

I don't think there is a single "right way", but here are some ideas:
make your Java app present the XML document as a bunch of threaded articles in groups; have it speak NNTP and use Gnus, or come up with your own protocol and write a Gnus backend for it (see the Web-browsing backends for inspiration)
think of the XML document as a Lisp program (S-expressions, XML elements, what is the difference?) and write a Swank backend that communicates with SLIME in Emacs, then use SLIME commands to make queries
write a FUSE driver so you can mount your XML document as a file system and use Dired to explore it.

Related

Project switching in emacs

I would like to associate sets of buffers/files in emacs with different projects, and switch from one to other. This would involve closing all the buffers associated with the present project and open the files corresponding to the switched-to-project. I tried setting up desktops using bookmarks+ as suggested in https://emacs.stackexchange.com/questions/315/using-desktop-for-basic-project-management but all buffers remain open. I also tried setting up workgroups using workgroups2 (https://github.com/pashinin/workgroups2), but had similar issues. Is there an existing emacs package that could be used for this?
There is an excellent package called Projectile that does exactly what you describe and more.
Alternative suggestion
I recommend that you don't look to emacs to manage buffers, frames, and editor state separately across projects.
Instead, use a desktop manager and create separate desktops for each project. This works well because not only can you have separate emacs instances (that you can be sure are truly separated), but you can also have separate web browsers open to documentation or other project-specific applications that collectively get swapped in and out when you switch between projects.
You say, "I tried setting up desktops using bookmarks+ as suggested in using-desktop-for-basic-project-management but all buffers remain open.".
I guess you mean that switching to a desktop does not kill buffers that existed before the switch. Not by itself, it doesn't. How can it guess which such pre-existing buffers you want killed?
Clearly you do not want to kill all buffers that existed prior to the desktop switch.
To get the behavior it seems you want, you would need to somehow decide, and specify, which such buffers you would like killed. You could, for example, choose to kill all that have a certain mode (perhaps using desktop-buffer-mode-handlers).
With Bookmark+ you can have bookmarks that do more than one thing. In particular, here, you could create a sequence bookmark that chains together (1) a function bookmark that kills all of the buffers you want to kill and (2) a desktop bookmark.
Or you can perhaps make use of desktop-after-read-hook or desktop-buffer-mode-handlers to do some cleanup.
(But it sounds like you have not really thought through exactly what behavior you want with respect to buffers that you do not want to "remain open", so that you can specify it clearly. If you can specify it then you can probably implement it fairly easily, using either desktop hooks or bookmarks or both. Just a guess.)

Is there a reusable error-view like buffer in emacs?

I am developing a plugin for emacs that analyses files and reports errors on them. I would like to reuse an existing error-buffer (comparable to the eclipse error-view) that I would only have to feed with the error-data. Is there such a thing in emacs? I know there is a central error-buffer in vim.
compilation-mode and compilation-minor-mode can make many different forms of error messages (including the kind specified in the GNU Coding Standards) clickable.

Why use org-mobile-push/pull?

I have managed my todo-lists for some years with Emacs Org-mode and really like it.
The files are kept in a WebDAV folder on a server to keep them synced.
However, since I use more and more tablets and smartphones an app to access the files would be great - such as MobileOrg for Android.
But currently I do not understand why I have to use org-mobile-push and pull in emacs and cannot just parse and access my files with an app and edit them in a convenient way, especially when I am a few days not working with Emacs or at my Linux machine at all. Is there a reasonable explanation why the files can't be parsed and viewed without exporting them from Emacs?
MobileOrg needs to interact with Emacs through a directory on a server. The main reason for org-mobile.el to exist is for creating agenda views in a format that can be displayed by MobileOrg, and for integrating notes captured and changes made by MobileOrg back into your Emacs main system. That said, the functions org-mobile-push and org-mobile-pull are purely there to provide a sync mechanism between MobileOrg and your Emacs main system. There is nothing technically stopping you from doing your own parsing and editing the of the files. I suppose that you only have to ensure that the files remain valid Org-Mode file formats and they should work everywhere.

How can I use emacs to run xquery code on a Marklogic database?

Instead of having to switch between editing files in emacs and doing little tests in the Marklogic query console, I'd really like to be able to open a buffer, write a little XQuery, then run it against a Marklogic server I've got running on a virtual machine. In effect, I suppose the perfect solution would result in something similar to the scratch buffer, where you write some elisp, then hit C-j to execute it.
Mostly I just move my code into libraries, and import those libraries from cq. But you could write elisp that sends your query via HTTP to the cq or QueryConsole eval.xqy module, as an HTTP POST.
You could also use a textarea emacs interface for your browser, so that you can use cq via emacs.
https://chrome.google.com/webstore/detail/ljobjlafonikaiipfkggjbhkghgicgoh
https://addons.mozilla.org/en-US/firefox/addon/its-all-text/
https://github.com/marklogic/cq
Calling eval.xqy over HTTP as suggested by #mblakele is probably easiest. But if you want tighter integration, there is the XCC library (Java/.Net; http://developer.marklogic.com/products/xcc/5.0 ), and also the slightly older libmlcc library ( http://robbertbroersma.nl/blog/a-blog.html ). Perhaps those are useful to you..

Emacs inside of gedit?

After years of experimentation with editors, the fact is I prefer them as minimal as possible. I never use fancy features and the full-feature IDE's become bloated, heavy, and slow. Of course, when I do something that pretty much requires a specific IDE (like Android dev and Eclipse) I have no problems using it. But most of the time, I use gedit for programming.
However, I like many Emacs commands, and I want to use them occasionally. Is there a way to embed Emacs inside of gedit? For instance, I envision pressing alt-q (or whatever combo) and Emacs mode is enabled, and from then on all my key presses in the current tab do Emacs commands. I press alt-q again, and it turns off. This would allow me the best of both worlds. Anything like this exist, or do I need to write this plugin myself?
No.
I've seen discussion of embedding of Emacs in other applications in the past, and the consensus is that even that's not feasible, let alone what you're suggesting.
You'd be better off identifying what gedit does that makes you want to use it instead of Emacs, and extending Emacs to make it do that, too. (There can't be that much --- gedit doesn't do much.) The extra features can just sit there and wait for you, and you'll find it easier to locate and use them if you're comfortable in Emacs-mode already.
(On top of all the other advantages of Emacs, you gain the ability to use the same editor you use in a windowed environment on the terminal --- a huge advantage.)
Or maybe yes . . .
You can use the External Tools plugin of gedit (look for it in Preferences). Add a new command, bind it to the key you want, and use this script:
#!/bin/sh
FILE_NAME=$GEDIT_CURRENT_DOCUMENT_PATH
emacs $FILE_NAME
If you want it to open in the currently-running Emacs, replace emacs with emacsclient, and add the following to your .emacs:
(server-start)
This is kind of backward. Why don't you just use Emacs and stay away from all the extra bells and whistles? It'd probably be easier to coax emacs to emulate gedit than the other way around.
If gedit (a) can be scripted to launch another application with the current file as an argument, and (b) will notice if the file is modified on disk and offer to reload it, then you would have a workaround.