From: Fabian Braennstroem <f.braennstroem@gmx.de>
To: help-gnu-emacs@gnu.org
Subject: Re: Bibtex extract entries for year, title and author
Date: Wed, 26 Sep 2007 21:26:18 +0000 [thread overview]
Message-ID: <fdebne$9sd$1@sycamore.fernuni-hagen.de> (raw)
In-Reply-To: <m3lkat8mf5.fsf@tfkp07.physik.uni-erlangen.de>
Hi Roland
Roland Winkler schrieb am 09/26/2007 03:40 PM:
> Fabian Braennstroem <f.braennstroem@gmx.de> writes:
>> I would like to extract the values of the last entry of year,
>> title and author. Did anyone try to do something similar yet and
>> can give an advice how to do it using emacs-lisp?
>
> What do you mean by "last entry"? In Emacs 22, there is
> bibtex-copy-summary-as-kill (bound to C-c C-t in BibTeX mode) which
> can be adapted to your needs with respect to the fields it uses
> (though not customizable in the proper sense). Does it do what you
> have in mind?
Thanks for your help! I actually want to manage all my
electronic literature using emacs bibtex-mode. Therefore I
needed to know the last entries I just wrote; I could achive
it using the cleaning function from bibtex-mode.
I have now some 'working' code which renames and moves the
pdf file according to the bibtex-entry into the appropriate
directory and category.
These steps are needed to use the below stuff:
a) in a dired buffer run 'bibtex_pfm'
b) choose a category.bib file (bibtex-mode)
c) insert an entry
d) run 'bibtex-my-clean-entry
The managing does not work with doc-view somehow... so I use
an external xpdf. And the window splitting could work a bit
better... The ascii pdf view and the shortcuts.bib are just
some helping buffers, e.g. for copying long titles...
; Bibtex-Manage
;**************************************************************************************************************
(require 'doc-view)
(defun bibtex_pfm()
"Runs PFM_BIBTEX"
(interactive)
(setq filename (dired-get-filename))
(delete-other-windows)
(call-process "xpdf" nil 0 nil (dired-get-filename) )
;(doc-view-dired t) ; Open PDF
(split-window-horizontally)
(find-file filename) ; Open PDF as ascii
(split-window-vertically)
(find-file "~/BibTeX/shortcuts.bib")
(split-window-vertically)
(find-file "~/BibTeX/")
)
(defun rename-file-and-buffer (new-name)
"Renames both current buffer and file it's visiting to
NEW-NAME." (interactive "sNew name: ")
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not filename)
(message "Buffer '%s' is not visiting a file!" name)
(if (get-buffer new-name)
(message "A buffer named '%s' already exists!" new-name)
(progn (rename-file name new-name 1) (rename-buffer
new-name) (set-visited-file-name new-name)
(set-buffer-modified-p nil)))))) ;;
(defun bibtex-my-clean-entry (&optional new-key
called-by-reformat)
"Finish editing the current BibTeX entry and clean it up.
Check that no required fields are empty and formats entry
dependent
on the value of `bibtex-entry-format'.
If the reference key of the entry is empty or a prefix
argument is given,
calculate a new reference key. (Note: this works only if
fields in entry
begin on separate lines prior to calling
`bibtex-clean-entry' or if
'realign is contained in `bibtex-entry-format'.)
Don't call `bibtex-clean-entry' on @Preamble entries.
At end of the cleaning process, the functions in
`bibtex-clean-entry-hook' are called with region narrowed to
entry."
;; Opt. arg called-by-reformat is t if bibtex-clean-entry
;; is called by bibtex-reformat
(interactive "P")
(let ((case-fold-search t)
(start (bibtex-beginning-of-entry))
(_ (or (looking-at bibtex-any-entry-maybe-empty-head)
(error "Not inside a BibTeX entry")))
(entry-type (bibtex-type-in-head))
(key (bibtex-key-in-head)))
;; formatting
(cond ((bibtex-string= entry-type "preamble")
;; (bibtex-format-preamble)
(error "No clean up of @Preamble entries"))
((bibtex-string= entry-type "string")
(setq entry-type 'string))
;; (bibtex-format-string)
(t (bibtex-format-entry)))
;; set key
(when (or new-key (not key))
(setq key (bibtex-generate-autokey))
;; Sometimes bibtex-generate-autokey returns an empty
string
(if (or bibtex-autokey-edit-before-use (string= "" key))
(setq key (if (eq entry-type 'string)
(bibtex-read-string-key key)
(bibtex-read-key "New Filename: " key))))
(message "New Filename: %s" key))
; orig. bibtex-clean-entry
(bibtex-clean-entry)
(save-buffer)
(setq category (file-name-sans-extension
(file-name-nondirectory buffer-file-name)))
(other-window 1)
(other-window 1)
(setq new_name (concat "~/BibTeX/" category "/" key ".pdf"))
(message "New FILENAME: %s" new_name)
(rename-file-and-buffer new_name)
(dired-jump)
(delete-other-windows)
(split-window-horizontally)
))
;
shortcuts.bib---------------------------------------------------------------------
@string{theor = "Theoretical and Computational Fluid Dynamics"}
@string{nhtb = "Numerical Heat Transfer. Part B"}
@string{nhta = "Numerical Heat Transfer. Part A"}
@string{arfm = "Annual Review of Fluid Mechanics"}
@string{arfms = "Ann. Rev. Fluid Mech."}
@string{jfm = "Journal of Fluid Mechanics"}
@string{jfms = "J. Fluid Mech."}
@string{ihmt = "International Journal of Heat and Mass
Transfer"}
@string{ijnmf = "International Journal for Numerical Methods
in Fluids"}
@string{ihmts = "Int. J. Heat Mass Transfer"}
;~/BibTeX/:-----------------------------------------
/Category1
/Category2
Category1.bib
Category2.bib
Greetings!
Fabian
prev parent reply other threads:[~2007-09-26 21:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-25 0:06 Bibtex extract entries for year, title and author Fabian Braennstroem
2007-09-25 7:17 ` Fabian Braennstroem
2007-09-26 15:40 ` Roland Winkler
2007-09-26 21:26 ` Fabian Braennstroem [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='fdebne$9sd$1@sycamore.fernuni-hagen.de' \
--to=f.braennstroem@gmx.de \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).