[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bibtex extract entries for year, title and author
From: |
Fabian Braennstroem |
Subject: |
Re: Bibtex extract entries for year, title and author |
Date: |
Wed, 26 Sep 2007 21:26:18 +0000 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.6) Gecko/20070728 Thunderbird/2.0.0.6 Mnenhy/0.7.5.0 |
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