Another silly hack
occ <[email protected]> Mon, 27 Feb 2006 06:31:48 +0000
| Newsgroups | gmane.comp.gnome.apps.pybliographer |
|---|---|
| Message-ID | <[email protected]> |
I've been using snapshots of emacs 22 and i've noticed that emacslient
now supports the injection of arbitrary elisp expressions into the
current emacs instance, as a quick hack i've implemented a cite_emacs
method on the Document object based on cite_lyx to insert citations into
the current cursor position in the current emacs buffer.
I assume that emacs is already running the emacs server (M-x
server-start)
The hack works by:
making a latex citation string (\cite{xxx,xxx,xxx})
writing it into a temporary file and then invoking emacsclient -e
'(insert-file tmpfile)'
deleting the temporary file.
The method is attached, but this isn't supposed to be a proper patch as
it is not particularly robust and has a number of problems (not least
hanging on the invocation of emacslient when the command fails). It
might however form the basis for something in a future version(for
people who don't use kile or lyx).
owen
--
---------------------------------------------------------------------
owen cliffe (postgraduate) Email: [email protected]
Department of Computer Science Web: http://www.cs.bath.ac.uk/~occ
Univ. Bath, Bath, England BA2 7AY Tel: (+44) 1225 386183
emacs_cite.txt
(text/plain, 732 B)
def emacs_cite (self, * arg):
import locale
try:
enc = locale.getpreferredencoding ()
except AttributeError:
enc = locale.getdefaultlocale()[1]
entries = self.index.selection ()
if not entries: return
keys = string.join (map (lambda x: x.key.key, entries), ', ')
citation = "\cite{" + keys + "}\n"
fn = os.tmpnam();
f = file(fn,'w+',os.O_SYNC);
print "citing " + citation
f.write(citation + "\n");
f.flush()
f.close()
cmd= 'emacsclient.emacs-snapshot -e \'(insert-file \"' + fn + '\")\''
print "running " + cmd
os.system(cmd)
os.unlink(fn)