Thread: [Refdb-cvs] CVS: elisp refdb-mode.el,1.14,1.15
Status: Beta
Brought to you by:
mhoenicka
From: Markus H. <mho...@us...> - 2005-06-25 21:53:02
|
Update of /cvsroot/refdb/elisp In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13113 Modified Files: refdb-mode.el Log Message: added support for full-style citations;added function to normalize endterms and linkends in full-style citations Index: refdb-mode.el =================================================================== RCS file: /cvsroot/refdb/elisp/refdb-mode.el,v retrieving revision 1.14 retrieving revision 1.15 diff -u -U2 -r1.14 -r1.15 --- refdb-mode.el 22 Jun 2005 19:36:39 -0000 1.14 +++ refdb-mode.el 25 Jun 2005 21:52:53 -0000 1.15 @@ -2,9 +2,8 @@ ;; $Id$ -;; Copyright (C) 2003-2005 Michael Smith ;; Copyright (C) 2005 Markus Hoenicka -;; Author: Michael Smith <sm...@si...> -;; Maintainer: (1.10-current) Markus Hoenicka <ma...@mh...> +;; Authors: (-1.9) Michael Smith <sm...@si...> +;; (1.10-current) Markus Hoenicka <ma...@mh...> ;; Created: 2003-11-04 ;; Revision: $Revision$ @@ -44,7 +43,8 @@ ;;; Compatibility ;; ------------------------------------------------------------------- -;; `refdb-mode' requires RefDB version 0.9.4 or later. It has been -;; tested and found to work with the Linux (Debian), Cygwin/X-Windows, -;; and Win32-native "NTEmacs" versions of GNU Emacs 21.2 and 20.7. +;; `refdb-mode' requires RefDB version 0.9.6 or later. It has been +;; tested and found to work with the Linux, FreeBSD, Cygwin/X-Windows, +;; and Win32-native "NTEmacs" versions of GNU Emacs 21.3 (the shell +;; commands work best in the latter if you use Cygwin bash) ;; ;; It has also been tested with OSX (Panther) using a build compiled @@ -294,5 +294,5 @@ ;; RefDB queries (i.e., values passed as arguments to the -t and ;; -s options for the 'refdbc -C getref' and 'refdbc -C getnote' -;; commands.) +;; commands.) and for the citations. ;; ;; Select Database @@ -440,4 +440,6 @@ ;; ------------------------------------------------------------------- ;; +;; - define keyboard shortcuts for the most used commands +;; ;; - integrate RefDB's own data converters into the menu ;; @@ -618,5 +620,6 @@ (defcustom refdb-gnumake-program "make" - "File name of the GNU make utility." + "File name of the GNU make utility. On systems using their own +version of make the executable is often called 'gmake'." :type 'string :group 'refdb-external-programs) @@ -675,4 +678,19 @@ ) +(defcustom refdb-use-short-citations-document-flag nil + "Non-nil means that after creating a new document the file +for use with short-style citations will be loaded for editing. +Nil means that the file for use with full citations will be loaded." + :type 'boolean + :group 'refdb + ) + +(defcustom refdb-auto-normalize-linkends-flag t + "Non-nil means normalize the endterms and linkends of RefDB citations +before running a transformation." + :type 'boolean + :group 'refdb + ) + (defcustom refdb-data-output-types '( @@ -713,4 +731,13 @@ :group 'refdb-data-options) +(defcustom refdb-citation-types + '( + short + full + ) + "*List of supported citation formats for RefDB." + :type '(list symbol symbol) + :group 'refdb-data-options) + (defcustom refdb-data-output-additional-fields '(N1 N2 UR) @@ -812,5 +839,5 @@ ) -;; file viewers. (x)html files are handled via browse-url +;; file viewers. (x)html files are handled by browse-url (defcustom refdb-pdf-view-program "gv" "File name of the PDF file viewer." @@ -849,9 +876,4 @@ ;; other external programs -(defcustom refdb-gnumake-program "make" - "File name of the GNU make executable. It is usually called 'make' or 'gmake'." - :type 'string - :group 'refdb-external-programs) - (defcustom refdb-bibutils-bib2xml-program "bib2xml" "File name of the bibutils bib2xml executable." @@ -1396,4 +1418,21 @@ ) +(defun refdb-select-citation-type (citationtype) + "Set RefDB citation type to CITATIONTYPE. +Note that CITATIONTYPE is a symbol, not a string." + (interactive + (list (intern + (completing-read + "Citation Type: " + (refdb-make-alist-from-symbol-list refdb-citation-types) + nil t + ) + ) + ) + ) + (setq refdb-citation-type citationtype) + (message "Current citation type is now '%s'" (symbol-name citationtype)) + ) + (defvar refdb-addref-menu-item ["Add References" (refdb-addref-on-region) t] @@ -1825,4 +1864,18 @@ ) +(defvar refdb-select-citation-type-submenu-contents + (list "Select Citation Output Type" + ["Short" + (refdb-select-citation-type 'short) + :style toggle + :selected (eq refdb-citation-type 'short)] + ["Full" + (refdb-select-citation-type 'full) + :style toggle + :selected (eq refdb-citation-type 'full)] + ) + "RefDB 'Select Citation Type' submenu." + ) + (defvar refdb-whichdb-menu-item ["Show Database Info" (refdb-whichdb) t] @@ -3750,10 +3803,14 @@ (equal type "DocBook SGML 4.0") (equal type "DocBook SGML 4.1")) - ".short.sgml") + (if refdb-use-short-citations-document-flag + ".short.sgml" + ".sgml")) ((or (equal type "DocBook XML 4.1.2") (equal type "DocBook XML 4.2") (equal type "DocBook XML 4.3") (equal type "TEI XML P4")) - ".short.xml") + (if refdb-use-short-citations-document-flag + ".short.xml" + ".xml")) )) (document-root (completing-read "Document root element: " @@ -3801,5 +3858,6 @@ document-cssfile ) - "*refdb-output*" "*refdb-messages*") +; "*refdb-output*" "*refdb-messages*") + nil "*refdb-messages*") (find-file (format @@ -3822,8 +3880,21 @@ "Transform a document to an output format for printing or online browsing" (interactive) + (if refdb-auto-normalize-linkends-flag + (progn + (refdb-normalize-linkends) + (save-buffer) + (set-buffer-modified-p nil)) + ) + (if (buffer-modified-p) + (if (y-or-n-p "Save changes before transformation? ") + (progn + (save-buffer) + (set-buffer-modified-p nil)) + ) + ) (message "Transforming document to %s..." type) ;; todo: append filename to make process name buffer-unique (start-process - "refdb-transform" + (concat "refdb-transform-" (buffer-name)) (get-buffer-create "*refdb-messages*") refdb-gnumake-program @@ -3840,8 +3911,21 @@ ;; separately to start-process + (if refdb-auto-normalize-linkends-flag + (progn + (refdb-normalize-linkends) + (save-buffer) + (set-buffer-modified-p nil)) + ) + (if (buffer-modified-p) + (if (y-or-n-p "Save changes before transformation? ") + (progn + (save-buffer) + (set-buffer-modified-p nil)) + ) + ) (message "Transforming document to %s..." type) ;; todo: append filename to make process name buffer-unique (start-process - "refdb-transform" + (concat "refdb-transform-" (buffer-name)) (get-buffer-create "*refdb-messages*") refdb-gnumake-program @@ -3877,5 +3961,7 @@ buffer-file-name 0 - (string-match "\\.short\\." buffer-file-name)) + (if (string-match "\\.short\\." buffer-file-name) + (string-match "\\.short\\." buffer-file-name) + (string-match "\\.[^\\.]+$" buffer-file-name))) "." type)))) @@ -3989,9 +4075,35 @@ (while (re-search-forward "^ID - \\(.*\\)$" region-extended-end t) ; (message "match:%s" (match-string 1 nil)) - (setq id-string (concat id-string ";" (match-string 1 nil)))) - ;; remove leading semicolon - (if (not (string= id-string "")) - (substring id-string 1) - "") + (if (eq refdb-citation-type 'short) + (setq id-string (concat id-string ";" (match-string 1 nil))) + (setq id-string (concat id-string + (format + "<xref linkend=\"ID%s-X\"/>" + (match-string 1 nil)) + )) + ) + ) + ;; remove leading semicolon in short type strings + (cond ((and + (eq refdb-citation-type 'short) + (not (string= id-string ""))) + (substring id-string 1)) + ((and + (eq refdb-citation-type 'full) + (not (string= id-string ""))) + (let ((linkend + (progn + (string-match "linkend=\"\\([^-\"]*\\)" id-string) + (match-string 1 id-string)))) + (concat + (format + "<xref endterm=\"IM0\" linkend=\"%s\" role=\"MULTIXREF\"/>" + linkend + ) + id-string) + )) + (t + id-string) + ) ) ) @@ -4019,7 +4131,25 @@ (setq id-string (concat id-string ";" (match-string 1 nil)))) ;; remove leading semicolon - (if (not (string= id-string "")) - (substring id-string 1) - "") + (cond ((and + (eq refdb-citation-type 'short) + (not (string= id-string ""))) + (substring id-string 1)) + ((and + (eq refdb-citation-type 'full) + (not (string= id-string ""))) + (let ((linkend + (progn + (string-match "linkend=\"\\([^-\"]*\\)" id-string) + (match-string 1 id-string)))) + (concat + (format + "<xref endterm=\"IM0\" linkend=\"%s\" role=\"MULTIXREF\"/>" + linkend + ) + id-string) + )) + (t + id-string) + ) ) ) @@ -4072,5 +4202,9 @@ (re-search-backward "^TY - " nil t) (if (re-search-forward "^ID - \\(.*\\)$" eor t) - (match-string 1 nil) + (if (eq refdb-citation-type 'short) + (match-string 1 nil) + (format + "<xref linkend=\"ID%s-X\"/>" + (match-string 1 nil))) nil) ) @@ -4084,5 +4218,9 @@ (re-search-backward "<entry" nil t) (if (re-search-forward "citekey=\"\\(.*\\)\"" eor t) - (match-string 1 nil) + (if (eq refdb-citation-type 'short) + (match-string 1 nil) + (format + "<xref linkend=\"ID%s-X\"/>" + (match-string 1 nil))) nil) ) @@ -4090,4 +4228,31 @@ ) +(defun refdb-normalize-linkends () + (interactive) + (save-excursion + (let ((im-count 1) + (id-list)) + ;; replace full and author citations with the "subsequent" equivalents + ;; where appropriate + (goto-char (point-min)) + (while (re-search-forward "linkend=\"ID\\([^-\"]+\\)-\\([AQSXY]\\)\"" nil t) + (if (member (match-string 1 nil) id-list) + (cond ((equal (match-string 2 nil) "A") + (replace-match "Q" nil t nil 2)) + ((equal (match-string 2 nil) "X") + (replace-match "S" nil t nil 2))) + (setq id-list (append (list (match-string 1 nil)) id-list)) + ) + ) + ;; make the endterms of multiple citations unique + (goto-char (point-min)) + (while (re-search-forward "endterm=\"IM\\([^\"]+\\)\"" nil t) + (replace-match + (format "%s" im-count) + nil t nil 1) + (setq im-count (+ 1 im-count))) + ) + ) + ) (defun refdb-make-alist-from-list (list) @@ -5333,4 +5498,12 @@ ) +(defcustom refdb-citation-type 'short + "*Specifies the default citation type." + :type '(choice (const :tag "Short " short) + (const :tag "Full " full) + ) + :group 'refdb-data-options + ) + (defcustom refdb-data-output-submenu-contents '( @@ -5339,4 +5512,5 @@ refdb-select-data-output-format-submenu-contents refdb-select-additional-data-fields-menu-item + refdb-select-citation-type-submenu-contents ) "*Contents of 'Customize Data Output' submenu for RefDB mode. |