0

I am writing an e-lisp function in my .emacs file to help process Bibtex entries I copy from Google-Scholar. Let's consider this example:

@article{jacobsen2011full,
  title={A full hydro-and morphodynamic description of breaker bar development},
  author={Jacobsen, Niels Gj{\o}l},
  year={2011},
  publisher={DTU Mechanical Engineering}
}

I would like to extract the entry name "jacobsen2011full" that will always be between "{" and "," but the position from the start is not always constant.

So how to go on about that???

I do not process the text inside a buffer. As mentioned I want to write an e-lisp function.

  • This is a job for regular expressions. Have a look at the manual node and the wiki to get started. – Dan Dec 26 '16 at 21:59
  • Now that is really annoying. You have changed my question in a way that it is no longer what I am asking for. Please be careful when going around throwing assumptions and wasting everybody's time!! – Hisham Dec 26 '16 at 22:07
  • I did not change your question to something you were not asking, although I did try to clarify what you seem to want to do by removing some redundant information. You are, of course, free to roll back edits if you think they make the question less clear, but please be much more polite in your tone. Please actually read the links I posted on regular expressions. You will find that they explain how to use regular expressions in elisp. – Dan Dec 26 '16 at 22:15
  • I am polite. I was just stating an opinion. Thanks for your info! – Hisham Dec 26 '16 at 22:20
0

You should do something like this. Assuming your point is somewhere in the entry.

(let ((entry (save-excursion
             (bibtex-beginning-of-entry)
             (bibtex-parse-entry))))
      (cdr (assoc "=key=" entry))
0

I found the solution using the "s" package.

(require 's)
(setq entryName (s-chop-prefix "{" (car (cdr (s-slice-at "[{,]" string)))))

If you have a suggestion for a more elegant/better solution please share it. Thanks!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.