PhilTeX Forums » Text Editors

Emacs, changing the default reftex citation

(6 posts)
  1. Paul Broadbent
    Member

    This question maybe a bit too techie for this forum, but I thought I might as well give it a shot, perhaps there's some emacs wizards hidden away somewhere!

    I'd like to modify emacs' behaviour when using reftex, so that after pressing 'C-c [' and choosing a citation format the default regex that comes up is one that will give me the citation I used last (the normal behaviour is to default to the word before the cursor, which is rarely of any use). I often cite the same source many times in a row, particularly when making notes on a single paper, so this would be a nice way to save a few keystrokes, and that's what we're all using emacs for, right :)

    I know a little lisp, so I expect I'll end up working out a way to do this myself eventually, but I thought it'd be worth asking around to see if anyone else has done it first, no point re-inventing the wheel. (If you do want this feature, but also don't know how to achieve it, let me know and I'll drop you an email when I've done it.)

    Also, another question, easily solved by looking at the manual I'm sure, but hey, I'm here now. How do I stop emacs promoting me to "select a citation format" whenever I press 'C-c ]'? I never use anything other that '\cite', so it's a complete waste of time.

    Thanks

    Paul

    (Edit: removed backtricks! I'm too used to using latex!)

    Posted 1 year ago #
  2. I think this is a great question. As far as I know, I'm the PhilTeX contributor with the most experience of emacs, and I can't answer your question. You should consider asking it on SuperUser. Or, with your blessing, I will ask it on SU, if you don't want to bother registering. (I would recommend registering yourself, because it's a great site, and once registered, you can very easily also register for sister sites like the TeX and Friends StackExchange which I cannot recommend highly enough...

    Posted 1 year ago #
  3. Paul Broadbent
    Member

    Sounds like a good idea, feel free to ask it on SuperUser.

    (Sorry for the slow reply, was away on holidays!)

    Posted 1 year ago #
  4. Paul Broadbent
    Member

    I had a look around SuperUser and was directed toward Stack Overflow, which seems to have more emacs and reftex questions, so I thought I'd ask it there instead, here's the link: http://stackoverflow.com/questions/3627574/emacs-changing-the-default-reftex-citation

    Posted 1 year ago #
  5. Emacs questions sometimes get bounced between SO and SU as they could conceivably be asked on both, depending on the question. If it's a reftex specific question, the beta TeX stack exchange site might be worth a look.

    Posted 1 year ago #
  6. Paul Broadbent
    Member

    I eventually wrote some elisp code to do this myself. Just add this to .emacs and reftex will use the last citation you used as the default when you cite with C-c [ (i.e. when using the function reftex-citation).

    (defvar reftex-last-citation nil)

    (defadvice reftex-citation (after reftex-citation-and-remember-citation activate)
    "Save last citation to 'reftex-last-citation after running 'reftex-citation"
    (setq reftex-last-citation ad-return-value))

    (defadvice reftex-get-bibkey-default (around reftex-just-return-last-citation activate)
    "If there is a 'reftex-last-citation then just return that instead of running 'reftex-get-bibkey-default"
    (if reftex-last-citation
    (setq ad-return-value reftex-last-citation)
    ad-do-it))

    Warning: this is the first elisp code I've written which is more than just one line, so it could be terrible code! But it seems to work! If want me to attempt to describe how it works then feel free to ask.

    (To see the code without the terrible lack of spacing before lines (I can't seem to work out how to indent lines on this forum) have a look at the Stack Overflow page here.)

    Posted 1 year ago #

RSS feed for this topic

Reply

You must log in to post.