Updated Emacs package, syntax highlighting, new name

Michael Smith <[email protected]>
Newsgroups gmane.text.refdb.devel
Message-ID <20031212114717.GA2440@theThirdPoliceman>
Attached is an update of the Emacs package, renamed it "refdb-mode".
You'll need to change the require statement in your .emacs to:

  (require 'refdb-mode)

And any variables you have set in your .emacs will need to be changed
to, or example:

  (setq refdb-database "DATABASE")

That is, just drop the "menu-" part from the variable name.

Syntax highlighting
-------------------
  The main change in this version is that it now indirectly does syntax
  highlighting. It works just by trying to put the output buffer into an
  appropriate mode based on output type. For example:

    - for XML output types, it puts the output buffer into nxml-mode if
      you have it, sgml-mode (psgml) otherwise

    - for HTML or DocBook SGML, sgml-mode (psgml)

    - for BibTeX, bibtex-mode

    - for RIS, ris-mode

      http://cvs.sourceforge.net/viewcvs.py/*checkout*/refdb/refdb/site-lisp/ris.el

Window splitting
----------------
  I added a new variable, refdb-split-for-getref-output-flag. Default it
  non-nil, meaning Emacs will split the current frame in order to show
  the output buffer; setting it to nil means Emacs will show the output
  buffer at full frame. You can either set it from the customization
  buffer, or manually in your .emacs like this:

    (setq refdb-split-for-getref-output-flag nil)

  QUESTION: Should I make the default value in the code non-nil instead?

Separate buffer for RefDB messages
----------------------------------
  stderr from refdbc now goes to a separate *refdb-messages* buffer,
  instead of getting mixed with output. I've added a "Show RefDB Message
  Log" menu and refdb-show-messages command you can use to see that.

Commands
--------
  Command equivalents for all menu items are now available.

    refdb-addref-on-region
    refdb-getref-by-author
    refdb-getref-by-title
    refdb-getref-by-keyword
    refdb-getref-by-id
    refdb-getref-by-citekey
    refdb-getref-by-advanced-search
    refdb-select-output-type
    refdb-select-database
    refdb-show-messages

  I guess we should maybe discuss coming up with a set of key bindings.

I've also added a little more code to have Emacs emit more messages
about what it's doing; e.g., 

    (message "Adding references in selected region to %s database..." refdb-database)
    (message (format "Getting datasets for author %s ..." author))

  etc.

I made a lot of changes, so it might have broken some things. Please try
and let me know.

Next up, I'll probably be trying out the data caching and completion
stuff I mentioned, and then on from there to dealing with processing
docs/generating output.

  --Mike
refdb-mode.el (text/plain, 26.2 KB)
;;; refdb-mode.el --- Minor mode for RefDB interaction
;; $Id: refdb-mode.el,v 1.1 2003/12/12 11:39:03 xmldoc Exp $

;; Copyright (C) 2003 Michael Smith

;; Author: Michael Smith <[email protected]>
;; Maintainer: Michael Smith <[email protected]>
;; Created: 2003-11-04
;; Version: 0.90
;; Revision: $Revision: 1.1 $
;; Date: $Date: 2003/12/12 11:39:03 $
;; RCS Id: $Id: refdb-mode.el,v 1.1 2003/12/12 11:39:03 xmldoc Exp $
;; X-URL: http://refdb.sf.net/
;; Keywords: xml docbook tei bibliography

;; This file is NOT part of GNU emacs.

;; This is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This software is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;; -------------------------------------------------------------------
;;; Compatibility
;; -------------------------------------------------------------------
;; 
;; -------------------------------------------------------------------
;;; Commentary
;;-------------------------------------------------------------------
;; This package provides a menu-driven Emacs front-end for
;; interacting with Markus Hoenicka's RefDB reference database and
;; bibliography tool for SGML, XML, and LaTeX/BibTeX documents.
;;
;;   http://refdb.sourceforge.net/
;;
;; -------------------------------------------------------------------
;;; Installation and Configuration
;; -------------------------------------------------------------------
;;
;; To install and use this package:
;;
;; 1. Either put this file into a directory that's already in your
;;    load path, or add whatever directory it's already in to your
;;    load path.  For example,
;;
;;      (add-to-list 'load-path "c:/my-xml-stuff/elisp/")
;;
;; 2. Add the following to the end of your .emacs file exactly as
;;    shown:
;;
;;      (require 'refdb-mode)
;;
;; 3. You should probably specify a database that will be used by
;;    default.  You can do that by adding the following to your .emacs,
;;    with DATABASE replaced by the name of the database to use.
;;
;;      (setq refdb-database "DATABASE")
;;
;; After you restart Emacs, to enter RefDB minor mode at any time,
;; either:
;;
;;   - choose RefDB Mode from your Emacs Tools menu
;;       or
;;   - type "¥M-x refdb-mode<return>" (on MS Windows, that's
;;     "Alt-x refdb-mode" and then hit <Enter>)
;;
;; Starting RefDB mode automatically
;; ---------------------------------
;; There are a couple of ways you can have Emacs put you into RefDB
;; mode automatically.
;; 
;;   - To show call up RefDB minor mode automatically depending on
;;     what major mode you're in, add something like the following
;;     example to you .emacs file.
;;
;;       (add-hook 'nxml-mode-hook 'refdb-mode)
;;       (add-hook 'sgml-mode-hook 'refdb-mode)
;;
;;     That example will call up RefDB mode automatically whenever you
;;     enter nXML mode or PSGML mode.
;;
;;   - To always have RefDB mode on, no matter what buffer/mode you're
;;     in, add the following to your .emacs file:
;;
;;       (add-hook 'find-file-hooks 'refdb-mode)
;;
;; To be able to show/hide the menu using a shorter keyboard shortcut,
;; you need to add something like the following to your .emacs file.
;;
;;   (define-key global-map "¥C-cb" 'refdb-mode)
;;
;; That example will enable you to use the 'Ctrl-c b' keyboard to
;; turn RefDB mode on or off.
;;
;; -------------------------------------------------------------------
;;; Customization
;; -------------------------------------------------------------------
;; To customize the behavior of RefDB mode and the contents of the
;; RefDB menu, either:
;;
;;   - choose Customize RefDB Mode from the RefDB menu
;;       or
;;   - type ¥M-x customize-group<return>refdb<return>
;;
;; -------------------------------------------------------------------
;;; Features
;; -------------------------------------------------------------------
;;
;; --------------------
;;  :: Menu contents ::
;; --------------------
;; By default, the RefDB menu provides the following submenus:
;;
;;   Add References
;;   Get References
;;   Select Output Type
;;   Select Database
;;   ----
;;   Show RefDB Message Log
;;   Customize RefDB Mode
;;
;; Here are brief descriptions of each submenu:
;;
;;   Add References
;;     Add references in the current region to the currently selected
;;     RefDB database.  (Runs 'refdbc -C addref' on current region.)
;;
;;   Get References
;;     Perform queries for data in the currently selected RefDB
;;     database.  (Provides submenus for performing various queries by
;;     passing parameters to 'refdbc -C getref'.)
;;
;;   Select Output Type
;;     Select the output type to use for data returned from RefDB
;;     queries.  (Passed as an argument to the -t option for the
;;     'refdbc -C getref' command.)
;;
;;   Select Database
;;     Select the database to use for RefDB interaction (passed via
;;     the -d option to refdbc commands).
;;
;;   Show RefDB Message Log
;;     Show the log of messages errors returned from RefDB
;;     commands.
;;
;;   Customize RefDB Mode
;;     User-friendly interface for setting RefDB options and
;;     adding/removing/rearranging submenus from the RefDB menu.
;; 
;;  ------------------------
;;;      :: Commands ::
;;  ------------------------
;;   refdb-addref-on-region
;;   refdb-getref-by-author
;;   refdb-getref-by-title
;;   refdb-getref-by-keyword
;;   refdb-getref-by-id
;;   refdb-getref-by-citekey
;;   refdb-getref-by-advanced-search
;;   refdb-select-output-type
;;   refdb-select-database
;;   refdb-show-messages
;;
;; -------------------------------------------------------------------
;;; Bugs
;; -------------------------------------------------------------------
;; Probably.  Still needs more testing.  Definitely seem to be some
;; compatibility issues on OS X (Panther), and maybe some problems
;; with interaction of RefDB commands on Cygwin.
;;
;; -------------------------------------------------------------------
;;; TODO
;; -------------------------------------------------------------------
;;
;;   - Creating documents
;;     Add a "Create Document" command and submenu, with menu items
;;     for each supported document type.  For example:
;;     
;;     Create Document
;;       DocBook SGML
;;       DocBook XML
;;       TEI XML
;;
;;     Selecting a document type calls refdbnd with the appropriate
;;     doctype value for that document type, then prompts for a
;;     basename, pubtype, and style.  Styles are selected via Emacs
;;     completion, based on query into database.  Current database
;;     named is also automatically passed as a param to refdbnd.
;;
;;   - Generating output
;;     Add a "Generate Output" command and submenu, with menu items
;;     for each supported output format.  For example:
;;
;;     Process Document
;;       HTML
;;       PDF
;;       RTF
;;
;;     Selecting a menu item calls 'make' and passes it the
;;     corresponding params.
;;
;;   - Caching data

;;      - run queries at RefDB startup to build an in-memory local
;;        cache of authors, titles, etc. data
;;
;;      - have a 'Refresh Data Cache' menu (`refdb-refresh-data-cache'
;;        command) that you can manually run to update the local cache
;;
;;   - Getting references using completion
;;     When getting references, should prompt user with completion;
;;     for example, if you select "Get References > Author...", Emacs
;;     will prompt you for completion against the current list of
;;     author names in its data cache.
;;     
;;
;; -------------------------------------------------------------------
;;; History:
;; -------------------------------------------------------------------
;;   2003-12-nn - first public release
;;
;; -------------------------------------------------------------------
;;; Acknowledgments
;; -------------------------------------------------------------------
;;

;;; Code:

;; *******************************************************************
;;; Initialization
;; *******************************************************************

(require 'easymenu)
(require 'easy-mmode)

(add-hook 'refdb-mode-hook
	  ;;create RefDB menu using easy-menu
	  '(lambda ()
	     (easy-menu-define
	       refdb-menu
	       refdb-mode-map
	       "Easy menu command/variable for `refdb-mode'."
	       refdb-menu-definition
	       )
	     )
	  )
(add-hook 'refdb-mode-hook 'refdb-initialize-all-menus)
(add-hook 'refdb-mode-hook 'refdb-make-selectdb-menu)
(add-hook 'refdb-mode-hook 'refdb-initialize-database-list)

(defvar refdb-input-type "ris")

;; *******************************************************************
;;; User-customizable options, part 1
;; *******************************************************************
;;
;; These are all needed at startup in order to build the
;; Select Database submenu.

(defcustom refdb-database ""
  "*Name of a RefDB database to use in RefDB commands.
Passed to RefDB commands as the parameter for the -d option."
  :type 'string
  :group 'refdb
  )

(defcustom refdb-listdb-sql-regexp "%"
  "Expression for limiting list of available databases.
Passed as the argument for the 'refdbc -C listdb' command.  Leave at
'%' to show all available databases.  Set to some other value to
narrow the list.  For example, set to 'refdb%' to list just those
databases whose names begin with the string 'refdb'."
  :type 'string
  :group 'refdb)

(defcustom refdb-refdbc-program "refdbc"
  "File name of the refdbc executable."
  :type 'string
  :group 'refdb)

(defcustom refdb-refdbc-options ""
  "RefDB global options; always included, regardless of subcommand."
  :set-after '(refdb-database-default)
  :type 'string
  :group 'refdb)

(defcustom refdb-refdbc-program-and-options
  (format "%s %s"
	  refdb-refdbc-program
	  refdb-refdbc-options
	  )
  "RefDB command along with global options."
  :type 'string
  :group 'refdb)

(defcustom refdb-addref-command
  (format "%s -C addref"
	  refdb-refdbc-program-and-options
	  )
  "Command for adding references to RefDB."
  :type 'string
  :group 'refdb)

(defcustom refdb-getref-command
  (format "%s -C getref"
	  refdb-refdbc-program-and-options
	  )
  "Command for getting references from RefDB."
  :type 'string
  :group 'refdb)

(defcustom refdb-listdb-command
  (format "%s -C listdb"
	  refdb-refdbc-program-and-options
	  )
  "Command for getting database list from RefDB."
  :type 'string
  :group 'refdb)

;; need to have this here to ensure that menu item will be in Tools
;; menu even if RefDB hasn't been loaded yet.
(defcustom refdb-menu-suppress-toggle-flag nil
  "*Non-nil means suppress 'RefDB Mode' menu item.
Set to non-nil ¥(on¥) to suppress, leave at nil ¥(off¥) to show."
  :type 'boolean
  :group 'refdb
  :require 'refdb
  )

(defcustom refdb-output-types
  '(scrn html db31 db31x teix bibtex ris risx)
  "List of supported output types for RefDB."
  :type '(list symbol symbol symbol symbol symbol symbol symbol symbol)
  :group 'refdb)

;; *******************************************************************
;; end of user-customizable options, part 1
;; *******************************************************************

(defun refdb-list-databases ()
  "List databases returned by 'refdb -C listdb'."
  (setq refdb-selectdb-submenu-contents nil)
  (message
   "Building list of databases using '%s %s' ..."
   refdb-listdb-command
   refdb-listdb-sql-regexp
   )
  (split-string
   (with-output-to-string
     (with-current-buffer
	 standard-output
       (call-process shell-file-name nil '(t nil) nil shell-command-switch
		     (format "%s %s"
			     refdb-listdb-command
			     refdb-listdb-sql-regexp
			     )
		     )
       )
     )
   )
  )

(defun refdb-initialize-database-list ()
  "Initialize list of RefDB databases."
  (message "Initializing RefDB database list...")
  (setq refdb-current-database-list (refdb-list-databases))
  
  )

(defun refdb-select-output-type (outputtype)
  "Set RefDB output type to OUTPUTTYPE.
Note that OUTPUTTYPE is a symbol, not a string."
  (interactive
   (list (intern
	  (completing-read
	   "Output Type: "
	   (refdb-make-alist-from-symbol-list refdb-output-types)
	   nil t
	   )
	  )
	 )
   )
  (setq refdb-output-type outputtype)
  (message (concat "Current output type is now " (symbol-name outputtype)))
  )

(defvar refdb-addref-menu-item
  ["Add References" (refdb-addref-on-region) t]
  "RefDB menu item for adding references."
  )

(defvar refdb-getref-by-author-menu-item
  ["Author..."
   (call-interactively 'refdb-getref-by-author)
   t]
  "RefDB getref-by-author menu item."
  )

(defvar refdb-getref-by-title-menu-item
  ["Title..."
   (call-interactively 'refdb-getref-by-title)
   t]
  "RefDB getref-by-title menu item."
  )

(defvar refdb-getref-by-keyword-menu-item
  ["Keyword..."
   (call-interactively 'refdb-getref-by-keyword)
   t]
  "RefDB getref-by-keyword menu item."
  )

(defvar refdb-getref-by-id-menu-item
  ["ID..."
   (call-interactively 'refdb-getref-by-id)
   t]
  "RefDB getref-by-id menu item."
  )

(defvar refdb-getref-by-citekey-menu-item
  ["Citation Key..."
   (call-interactively 'refdb-getref-by-citekey)
   t]
  "RefDB getref-by-citation-key menu item."
  )

(defvar refdb-getref-by-advanced-search-menu-item
  ["Advanced Search..."
   (call-interactively 'refdb-getref-by-advanced-search)
   t]
  "RefDB advanced-search menu item."
  )

(defvar refdb-select-output-type-submenu-contents
  (list "Select Output Type"
	["Screen"
	 (refdb-select-output-type 'scrn)
	 :style toggle
	 :selected (eq refdb-output-type 'scrn)]
	["HTML"
	 (refdb-select-output-type 'html)
	 :style toggle
	 :selected (eq refdb-output-type 'html)]
	["DocBook SGML"
	 (refdb-select-output-type 'db31)
	 :style toggle
	 :selected (eq refdb-output-type 'db31)]
	["DocBook XML"
	 (refdb-select-output-type 'db31x)
	 :style toggle
	 :selected (eq refdb-output-type 'db31x)
	 ]
	["TEI XML"
	 (refdb-select-output-type 'teix)
	 :style toggle
	 :selected (eq refdb-output-type 'teix)
	 ]
	["BibTeX"
	 (refdb-select-output-type 'bibtex)
	 :style toggle
	 :selected (eq refdb-output-type 'bibtex)
	 ]
	["RIS"
	 (refdb-select-output-type 'ris)
	 :style toggle
 	 :selected (eq refdb-output-type 'ris)
	 ]
	["RISX"
	 (refdb-select-output-type 'risx)
	 :style toggle
	 :selected (eq refdb-output-type 'risx)
	 ]
	)
  "RefDB 'Select Output Type' submenu.
FIXME: This probably should be generated from value of `refdb-output-types'."
  )

(defun refdb-show-messages ()
  "Show RefDB messages buffer (stderr output from RefDB apps)."
  (interactive)
  (pop-to-buffer "*refdb-messages*")
)

(defun refdb-determine-input-type ()
  "Set RefDB output type according to user prefs.
Unless user has specified that input type should never be RISX, or
specified that input type should always be RISX, check to see what the
name of the major mode is, and if the major mode name contains 'xml'
or 'sgml', set the input type to RISX.  Otherwise, set the input type
to RIS."
  (if (and refdb-input-type-risx
	   (not (eq refdb-input-type-risx t)))
      (if
	  (not (null
		(string-match
		 "sgml¥¥|xml"
		 (downcase (symbol-name major-mode)))))
	  (progn
	    (setq refdb-input-type "risx")
	    (message "Input type set to risx.")
	    )
	(progn
	  (setq refdb-input-type "ris")
	  (message "Input type set to ris.")
	  )
	)
    (setq refdb-input-type "ris")
    (message "Input type set to ris.")
    )
  refdb-input-type
  )

(defun refdb-addref-on-region ()
  "Add references in the current region to the current RefDB database."
  (interactive)
  (if (not (eq (length refdb-database) 0))
      (if (mark)
	  (progn
	    (refdb-determine-input-type)
	    (message "Adding references in selected region to %s database..." refdb-database)
	    (shell-command-on-region
	     (point) (mark)
	     (format
	      "%s -d %s -t %s"
	      refdb-addref-command
	      refdb-database
	      refdb-input-type
	      )
	     "*refdb-output*" nil "*refdb-messages*")
	    
	    )
	(message "Error: No region marked.
You must mark a region containing references to add.")
	)
    ;; else if no db specified, prompt to select from available dbs,
    ;; then re-call command
    (call-interactively 'refdb-select-database)
    (refdb-addref-on-region)
    )
  )

(defun refdb-getref-by-field (field value)
  "Display all RefDB datasets that match the specified FIELD and VALUE.
You shouldn't call this function directly.  Instead call, e.g.,
`refdb-getref-by-author'."
  (if (not (eq (length refdb-database) 0))
      (progn
	(shell-command
	 (format
	  "%s -d %s -t %s :%s:=%s"
	  refdb-getref-command
	  refdb-database
	  refdb-output-type
	  field
	  value)
	 "*refdb-output*" "*refdb-messages*")
	
	)
    ;; else if no db specified, prompt to select from available dbs and
    ;; then call `refdb-getref-by-field' with same values
    (progn
      (call-interactively 'refdb-select-database)
      (refdb-getref-by-field field value)
      )
    )
  (message
   (format
    "Displaying output for %s -d %s -t %s :%s:=%s"
    refdb-getref-command
    refdb-database
    refdb-output-type
    field
    value)
   )
  (pop-to-buffer "*refdb-output*")
  (if (not refdb-split-for-getref-output-flag)
      (delete-other-windows)
    )
  (refdb-output-buffer-choose-mode)
  )

(defun refdb-output-buffer-choose-mode ()
  "Choose appropriate major mode for RefDB output buffer."
  (if (or
       (eq refdb-output-type 'db31)
       (eq refdb-output-type 'db31x)
       (eq refdb-output-type 'teix)
       (eq refdb-output-type 'risx)
       )
      (if (functionp 'nxml-mode)
	  (nxml-mode)
	(if functionp 'xml-mode)
	(xml-mode)
	)
    (if	(and
	 (or
	  (eq refdb-output-type 'db31)
	  (eq refdb-output-type 'html)
	  )
	 (functionp 'sgml-mode)
	 )
	 (sgml-mode)
	 )
	(if (and
	     (eq refdb-output-type 'ris)
	     (functionp 'ris-mode)
	     )
	    (ris-mode)
	  )
      (if (eq refdb-output-type 'bibtex)
	  (bibtex-mode)
	)
      )
    )

(defun refdb-getref-by-author (author)
  "Display all RefDB datasets matching AUTHOR."
  (interactive (list (read-string (format "Author: "))))
  (message (format "Getting datasets for author %s ..." author))
  (refdb-getref-by-field "AU" author)
  )

(defun refdb-getref-by-title (title)
  "Display all RefDB datasets matching TITLE."
  (interactive (list (read-string (format "Title: "))))
  (message (format "Getting datasets for title %s ..." title))
  (refdb-getref-by-field "TI" title)
  )

(defun refdb-getref-by-keyword (keyword)
  "Display all RefDB datasets matching KEYWORD."
  (interactive (list (read-string (format "Keyword: "))))
  (message (format "Getting datasets for keyword %s ..." keyword))
  (refdb-getref-by-field "KW" keyword)
  )

(defun refdb-getref-by-id (id)
  "Display all RefDB datasets matching ID."
  (interactive (list (read-string (format "ID: "))))
  (message (format "Getting datasets for ID %s ..." ID))
  (refdb-getref-by-field "ID" id)
  )

(defun refdb-getref-by-citekey (citekey)
  "Display all RefDB datasets matching CITEKEY."
  (interactive (list (read-string (format "Citation Key: "))))
  (message (format "Getting datasets for citation key %s ..." citekey))
  (refdb-getref-by-field "CK" citekey)
  )

(defun refdb-getref-by-advanced-search (searchstring)
  "Display all RefDB datasets matching SEARCHSTRING."
  (interactive "sSearch string: ")
  (message (format "Getting datasets for search string %s ..." searchstring))
  (if (not (eq (length refdb-database) 0))
      (progn
	(shell-command
	 (format
	  "%s -d %s -t %s %s"
	  refdb-getref-command
	  refdb-database
	  refdb-output-type
	  searchstring)
	 "*refdb-output*" nil)
	
	)
    ;; else if no db specified, prompt to select from available dbs and
    ;; then call `refdb-getref-by-field' with same values
    (progn
      (call-interactively 'refdb-select-database)
      (refdb-getref-by-field field value)
      )
    )
  (message
   (format
    "Displaying output for %s -d %s -t %s %s"
    refdb-getref-command
    refdb-database
    refdb-output-type
    searchstring)
   )
  )

(defun refdb-make-alist-from-list (list)
  "Make an alist from LIST by cons'ing elements with themselves."
  (mapcar
   (lambda (atom)
     (cons atom nil))
   list)
  )

(defun refdb-make-alist-from-symbol-list (list)
  "Make an alist from LIST of symbols."
  (mapcar
   (lambda (atom)
     (cons (symbol-name atom) nil))
   list)
  )

(defun refdb-select-database (database)
  "Select DATABASE as the current RefDB database.
If called interactively, prompt user with completion list of available
databases."
  (interactive
   (list
    (completing-read
     "Database: "
     (refdb-make-alist-from-list refdb-current-database-list)
     nil t
     )
    )
   )
  (setq refdb-database database)
  (message (concat "Current database is now " database))
  )

(easy-mmode-define-minor-mode
 refdb-mode
 "Minor mode fore RefDB interaction."
 ;; Initial value is nil.
 nil
 ;; No indicator for the mode line.
 nil
 ;; Make empty default keymap;
 '( ("" . nil)))

(defvar refdb-menu-item-separator1
  ["--" t]
  "Separator between command `refdb-mode' menu items."
  )
(defvar refdb-menu-item-separator2
  ["---" t]
  "Separator between command `refdb-mode' menu items."
  )
(defvar refdb-menu-item-separator3
  ["----" t]
  "Separator between command `refdb-mode' menu items."
  )
(defvar refdb-menu-item-separator4
  ["-----" t]
  "Separator between command `refdb-mode' menu items."
  )

(defvar refdb-show-messages-menu-item
  ["Show RefDB Message Log"
   (refdb-show-messages) t]
  "RefDB menu item for showing message log."
  )

(defvar refdb-customize-menu-item
  ["Customize RefDB Menu..."
   (customize-group 'refdb) t]
  "Customize submenu for command `refdb-mode'."
  )

(defgroup refdb nil
  "RefDB menu."
  :group 'help
  :link '(emacs-commentary-link "refdb-mode.el")
  :link '(url-link "http://refdb.sf.net/")
  :prefix "refdb-"
  )

(defun refdb-make-selectdb-menu ()
  "Build the Select Database submenu."
  (setq refdb-selectdb-submenu-contents
	(cons "Select Database"
	      (progn
		(setq my-database-list refdb-current-database-list)
		(setq refdb-selectdb-submenu-items nil)
		(while my-database-list
		  (setq current-database (car my-database-list))
		  (setq refdb-selectdb-submenu-items
			(nconc refdb-selectdb-submenu-items
			       (list
				(vector
				 current-database
				 `(refdb-select-database ,current-database)
				 :style 'toggle
				 :selected `(equal refdb-database ,current-database)
				 )
				)
			       )
			)
		  (setq my-database-list (cdr my-database-list))
		  )
		refdb-selectdb-submenu-items
		)
	      )
	)
  )

;; *******************************************************************
;;; User-customizable options, part 2
;; *******************************************************************

(defun refdb-initialize-all-menus ()
  "Build all menus."

  (defcustom refdb-input-type-risx 'use-mode-name
    "*Indicates whether RISX is used as the input type.
Passed to the 'refdbc -C addref' command as the argument for the -t
option.  If t, RISX is always used.  If nil, RISX is never used.  If
non-t and non-nil, use RISX if the name of the buffer's major mode
contains 'xml' or 'sgml'."
    :type '(choice (const :tag "always" t) (const :tag "never" nil)
		   (const :tag "use-mode-name" use-mode-name))
    :group 'refdb
    )

(defcustom refdb-split-for-getref-output-flag t
  "*Non-nil means split window for 'Get References' output.
If nil ¥(off¥), show 'Get References' output window at full
frame.  Keep at non-nil ¥(on¥) to cause current frame to be split to
show output."
    :type 'boolean
    :group 'refdb)

  (defcustom refdb-output-type 'scrn
    "*Specifies the default output type.
Passed to the 'refdbc -C getref' command as the argument for the -t
option. FIXME: Should be generated from output-types list."
    :type '(choice (const :tag "Screen      "  scrn)
		   (const :tag "HTML        "  html)
		   (const :tag "DocBook SGML"  db31)
		   (const :tag "DocBook XML "  db31x)
		   (const :tag "TEX XML     "  teix)
		   (const :tag "BibTeX      "  bibtex)
		   (const :tag "RIS         "  ris)
		   (const :tag "RISX        "  risx)
		   )
    :group 'refdb
    )

  (defcustom refdb-getref-submenu-contents
    '(
      refdb-getref-by-author-menu-item
      refdb-getref-by-title-menu-item
      refdb-getref-by-keyword-menu-item
      refdb-getref-by-id-menu-item
      refdb-getref-by-citekey-menu-item
      refdb-getref-by-advanced-search-menu-item
      )
    "*Contents of 'Get References' submenu for RefDB mode.
Customize this to add/remove/rearrange submenus."
    :set (lambda (sym val)
	   (setq refdb-getref-submenu-contents val)
	   (setq refdb-getref-submenu-definition
		 (cons "Get References"
		       ;; turn quoted contents value back into a real list
		       ;; thanks, sachac :)
		       (mapcar (lambda (item) (if (symbolp item) (eval item) item)) val)
		       )
		 )
	   )
    :group 'refdb
    :type '(repeat variable)
    )

  (defcustom refdb-menu-contents
    '(
      refdb-addref-menu-item
      refdb-getref-submenu-definition
      refdb-select-output-type-submenu-contents
      refdb-selectdb-submenu-contents
      refdb-menu-item-separator4
      refdb-show-messages-menu-item
      refdb-customize-menu-item
      )
    "*Contents of command `refdb-mode' menu.
Customize this to add/remove/rearrange submenus."
    :set (lambda (sym val)
	   (setq refdb-menu-contents val)
	   (setq refdb-menu-definition
		 (cons "RefDB"
		       (mapcar (lambda (item) (if (symbolp item) (eval item) item)) val)
		       )
		 )
	   )
    :group 'refdb
    :type '(repeat variable)
    )

  )
;; *******************************************************************
;; end of user-customizable options, part 2
;; *******************************************************************

(define-key-after menu-bar-tools-menu [refdb-mode-toggle]
  ;; add "RefDB Mode" item to Tools menu
     '(menu-item "RefDB Mode" refdb-mode
		 :help "Toggle RefDB Mode"
		 :button (:toggle . (and (boundp 'refdb-mode) refdb-mode))
		 ;; hide if 'suppress' flag is set
		 :visible (not refdb-menu-suppress-toggle-flag)
		 )
     nil)

(provide 'refdb-mode)

;;; refdb-mode.el ends here
signature.asc (application/pgp-signature, 155 B)
-----BEGIN PGP SIGNATURE-----

iD8DBQE/2arFsGCNMsnBsxkRAmVIAJ0YoqbXTB1VdDaNSbdYTOEZmVI3GwCeKr4t
1Td/oj2tcPkMu6zto6Hprrg=
=Pto+
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.